Appearance
@tmrw-realityos/charm • Docs
@tmrw-realityos/charm / WebGPUMeshPicker
Class: WebGPUMeshPicker
Class for picking a mesh on click events
Example
Setup
typescript
const renderer = new WebGPURenderer(device, canvas)
const picker = new WebGPUMeshPicker(renderer)
renderer.onRenderInFinalBuffer = (outputTexture: GPUTexture, encoder: GPUCommandEncoder) => {
picker.renderOutlineOverlay(outputTexture, encoder)
}
Constructors
new WebGPUMeshPicker()
new WebGPUMeshPicker(
renderer
,skipBindingEvents
):WebGPUMeshPicker
Parameters
• renderer: WebGPURenderer
Rendering context containing renderables and camera uniforms
• skipBindingEvents: boolean
= false
by default it binds touch events to the canvas, this will disable it
Returns
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:75
Properties
ready
ready:
boolean
=true
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:68
Accessors
highlightColor
set
highlightColor(color
):void
Parameters
• color: ReadonlyVec4
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:363
outlineColor
set
outlineColor(color
):void
Parameters
• color: ReadonlyVec4
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:356
Methods
addSelected()
addSelected(
id
):void
Parameters
• id: number
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:663
decodeMeshID()
decodeMeshID(
x
,y
,renderables
):Promise
<undefined
|RenderableDescriptor
>
Parameters
• x: number
• y: number
• renderables: RenderableDescriptor
[]
Returns
Promise
<undefined
| RenderableDescriptor
>
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:596
destroy()
destroy():
void
Remove event listeners and free GPU resources.
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:801
hasSelection()
hasSelection():
boolean
Returns
boolean
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:335
isWithinShortDistanceOfPointerDown()
isWithinShortDistanceOfPointerDown(
ev
):boolean
Parameters
• ev: PointerEvent
Returns
boolean
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:346
pickRenderable()
pickRenderable(
x
,y
,layers
,encoder
?):Promise
<undefined
|RenderableDescriptor
>
Pick mesh from screen pixel coordinates
Parameters
• x: number
Pixel x coordinate
• y: number
Pixel y coordinate
• layers: number
= 0xff
• encoder?: GPUCommandEncoder
Returns
Promise
<undefined
| RenderableDescriptor
>
Renderable ID: index inside the renderables array
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:483
renderOutlineOverlay()
renderOutlineOverlay(
outputTexture
,existingCommandEncoder
?):void
Render outline of the selected mesh. By default a separate command encoder is created for recording draw commands.
Parameters
• outputTexture: GPUTexture
Texture to draw to. Must be view compatible with rgba8unorm-srgb.
• existingCommandEncoder?: GPUCommandEncoder
Optional existing command encoder to record to.
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:718
reset()
reset():
void
Clear the current selection
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:659
resize()
resize(
width
,height
):void
Resize picking framebuffers. Must be called whenever the canvas is resized.
Parameters
• width: number
• height: number
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:684
setObjectPickedCallback()
setObjectPickedCallback(
callback
):void
Parameters
• callback
Callback to be executed when a mesh was picked
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:641
setSelectionClearedCallback()
setSelectionClearedCallback(
callback
):void
Parameters
• callback
Callback to be executed when the user clicked outside a mesh, clearing any prior selection
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUMeshPicker.ts:652
updateSize()
updateSize():
void
Check if internal buffer size matches canvas size
Returns
void