Skip to main content

Class: BodypartPatchPlugin

@geenee/bodyrenderers-babylon.BodypartPatchPlugin

Body part patch plugin

Plugin conditionally patches (inpaints/erases) foreground regions of image defined by body segmentation mask from @geenee/bodyprocessors!PoseProcessor. There are 2 types of regions: "patch" and "keep", both are defined by corresponding sets of scene meshes. Plugin patches foreground/masked pixels that belong to "patch" regions but are not part of "keep" regions. This can be used in apparel virtual try to remove parts of a body that stick out of (not covered by) outfit. In this case, "patch" region is defined by outfit meshes and "keep" region is the reference body model that at the same time serves as occluder. BodypartPatchPlugin is compatible with BabylonUniRenderer derivatives. Evaluation of body segmentation mask must be enabled in @geenee/bodyprocessors!PoseProcessor#init setting @geenee/bodyprocessors!PoseParams#mask to true.

Hierarchy

Constructors

constructor

new BodypartPatchPlugin(dilationR?)

Constructor

Parameters

NameTypeDefault valueDescription
dilationRnumber2.0Radius of mask dilation

Overrides

ShaderPlugin.constructor

Properties

dilationR

Protected dilationR: number = 2.0

Radius of mask dilation


dilationShader

Protected Optional dilationShader: DilationShader

Image dilation shader


fragSrc

Protected Optional fragSrc: string

Code of fragment shader (copy shader by default)

Inherited from

ShaderPlugin.fragSrc


inputs

Protected Optional inputs: string[]

Shader texture inputs (names of sampler uniforms)

Inherited from

ShaderPlugin.inputs


loaded

loaded: boolean

Loaded state

Inherited from

ShaderPlugin.loaded


ordinal

ordinal: number

Ordinal number

Inherited from

ShaderPlugin.ordinal


renderer

Protected Optional renderer: Renderer<PoseResult>

Renderer loaded the plugin

Inherited from

ShaderPlugin.renderer


shader

Protected Optional shader: ShaderProgram

Rendering shader

Inherited from

ShaderPlugin.shader


size

Protected size: Size

Image size

Inherited from

ShaderPlugin.size


uniforms

Protected Optional uniforms: Object

Shader uniforms as name-type map object

Index signature

▪ [key: string]: UniformType

Inherited from

ShaderPlugin.uniforms


vertSrc

Protected Optional vertSrc: string

Vertex shader source (copy shader by default)

Inherited from

ShaderPlugin.vertSrc

Methods

dispose

dispose(): void

Dispose video plugin

Returns

void

Inherited from

ShaderPlugin.dispose


load

load(renderer): Promise<void>

Initialize plugin

Initializes resources required for conditional body patching.

Parameters

NameTypeDescription
rendererRenderer<PoseResult>Renderer this plugin is attached to

Returns

Promise<void>

Promise resolving when initialization is finished

Overrides

ShaderPlugin.load


process

process(result, input): Promise<boolean>

Process the image

Patches (inpaints) foreground image pixels according to the provided segmentation mask. Patched pixels must also belong to "patch" region and not be a part of "keep" region. Regions are defined by corresponding sets of scene meshes.

Parameters

NameTypeDescription
resultPoseResultResults of video processing
inputWebGLTextureCurrent image texture

Returns

Promise<boolean>

True on success, false otherwise

Overrides

ShaderPlugin.process


renderParts

Protected renderParts(): null | WebGLTexture

Render patch and keep meshes

Rendered meshes provide mask of patch/keep regions.

Returns

null | WebGLTexture

Mask texture


setParts

setParts(patchParts?, keepParts?): void

Set meshes defining patch regions

Parameters

NameTypeDefault valueDescription
patchPartsAbstractMesh[][]Meshes defining "patch" regions
keepPartsAbstractMesh[][]Meshes defining "keep" regions

Returns

void


setupCamera

setupCamera(ratio, angle): void

Set camera parameters

Could be overridden to adjust plugin's pipeline.

Parameters

NameTypeDescription
rationumberAspect ration of input video
anglenumberVertical field of view in radians

Returns

void

Inherited from

ShaderPlugin.setupCamera


setupVideo

setupVideo(size): void

Set video size

Adjusts shader and texture to a new size.

Parameters

NameTypeDescription
sizeSizeResolution of input video

Returns

void

Overrides

ShaderPlugin.setupVideo


unload

unload(): void

Reset plugin

Releases all resources and instances created in load().

Returns

void

Overrides

ShaderPlugin.unload


update

update(result, stream): Promise<void>

Update the image

Main method implementing webgl shader effect or filter. ShaderRenderer has current image texture that will be rendered. ShaderPlugin uses current texture as input and writes results to ShaderPlugin#output. ShaderPlugin#output becomes new current texture of ShaderRenderer. This way all ShaderPlugins attached to renderer organize a chain of effects applied on top of each other. Method process() implements shader effect itself, it's intended to be overridden by effect authors.

Parameters

NameTypeDescription
resultPoseResultResults of video processing
streamHTMLCanvasElementCaptured video frame

Returns

Promise<void>

Promise resolving when update is finished

Inherited from

ShaderPlugin.update