Create a Mesh based on a DOMObject3D, which allow the Mesh to be scaled and positioned based on a HTMLElement bounding rectangle.

Example

// set our main GPUCurtains instance
const gpuCurtains = new GPUCurtains({
container: '#canvas' // selector of our WebGPU canvas container
})

// set the GPU device
// note this is asynchronous
await gpuCurtains.setDevice()

// create a DOMMesh with a box geometry,
// assuming there's a HTML element with the "mesh" ID in the DOM
// will use the normals colors as default shading
const domMesh = new DOMMesh(gpuCurtains, '#mesh', {
label: 'My DOM Mesh',
geometry: new BoxGeometry(),
})

Hierarchy (view full)

Constructors

Properties

Accessors

Methods

Constructors

Properties

type: string

The type of the MeshBaseClass

uuid: string

The universal unique id of the MeshBaseClass

index: number

Index of this MeshBaseClass, i.e. creation order

material: RenderMaterial

Geometry used by this MeshBaseClass

outputTarget: RenderTarget

RenderTarget to render this Mesh to instead of the canvas context, if any.

renderOrder: number

Controls the order in which this MeshBaseClass should be rendered by our Scene

_transparent: boolean

Whether this MeshBaseClass should be treated as transparent. Impacts the render pipeline blend properties

_visible: boolean

Flag indicating whether to draw this MeshBaseClass or not

_ready: boolean

Flag indicating whether this MeshBaseClass is ready to be drawn

userData: Record<string, unknown>

Empty object to store any additional data or custom properties into your Mesh.

_onReadyCallback: (() => void)

function assigned to the onReady callback

Type declaration

    • (): void
    • function assigned to the onReady callback

      Returns void

_onBeforeRenderCallback: (() => void)

function assigned to the onBeforeRender callback

Type declaration

_onRenderCallback: (() => void)

function assigned to the onRender callback

Type declaration

    • (): void
    • function assigned to the onRender callback

      Returns void

_onAfterRenderCallback: (() => void)

function assigned to the onAfterRender callback

Type declaration

    • (): void
    • function assigned to the onAfterRender callback

      Returns void

_onAfterResizeCallback: (() => void)

function assigned to the onAfterResize callback

Type declaration

    • (): void
    • function assigned to the onAfterResize callback

      Returns void

onReady: ((callback) => ProjectedMeshBaseClass | MeshBaseClass)

Callback to execute when a Mesh is ready - i.e. its material and geometry are ready.

Type declaration

Param: callback

callback to run when MeshBaseClass is ready

Returns

  • our Mesh
onBeforeRender: ((callback) => ProjectedMeshBaseClass | MeshBaseClass)

Callback to execute before updating the Scene matrix stack. This means it is called early and allows to update transformations values before actually setting the Mesh matrices (if any). This also means it won't be called if the Mesh has not been added to the Scene. The callback won't be called if the Renderer is not ready or the Mesh itself is neither ready nor visible.

Type declaration

    • (callback): ProjectedMeshBaseClass | MeshBaseClass
    • Callback to execute before updating the Scene matrix stack. This means it is called early and allows to update transformations values before actually setting the Mesh matrices (if any). This also means it won't be called if the Mesh has not been added to the Scene. The callback won't be called if the Renderer is not ready or the Mesh itself is neither ready nor visible.

      Parameters

      • callback: (() => void)

        callback to run just before updating the Scene matrix stack.

          • (): void
          • Returns void

      Returns ProjectedMeshBaseClass | MeshBaseClass

      • our Mesh

Param: callback

callback to run just before updating the Scene matrix stack.

Returns

  • our Mesh
onRender: ((callback) => ProjectedMeshBaseClass | MeshBaseClass)

Callback to execute right before actually rendering the Mesh. Useful to update uniforms for example. The callback won't be called if the Renderer is not ready or the Mesh itself is neither ready nor visible.

Type declaration

Param: callback

callback to run just before rendering the MeshBaseClass.

Returns

  • our Mesh
onAfterRender: ((callback) => ProjectedMeshBaseClass | MeshBaseClass)

Callback to execute just after a Mesh has been rendered. The callback won't be called if the Renderer is not ready or the Mesh itself is neither ready nor visible.

Type declaration

Param: callback

callback to run just after MeshBaseClass has been rendered

Returns

  • our Mesh
onAfterResize: ((callback) => ProjectedMeshBaseClass | MeshBaseClass)

Callback to execute just after a Mesh has been resized.

Type declaration

Param: callback

callback to run just after MeshBaseClass has been resized

Returns

  • our Mesh
domFrustum: DOMFrustum

The ProjectedMesh DOMFrustum class object

frustumCulling: FrustumCullingCheck

Frustum culling check to use. Accepts OBB, sphere or a boolean. Default to OBB. When set to true, OBB is used.

DOMFrustumMargins: RectCoords

Margins (in pixels) to applied to the DOM Frustum to determine if this ProjectedMesh should be frustum culled or not

Options used to create this ProjectedMeshBaseClass

_onReEnterViewCallback: (() => void)

function assigned to the onReEnterView callback

Type declaration

    • (): void
    • function assigned to the onReEnterView callback

      Returns void

_onLeaveViewCallback: (() => void)

function assigned to the onLeaveView callback

Type declaration

    • (): void
    • function assigned to the onLeaveView callback

      Returns void

onReEnterView: ((callback) => ProjectedMeshBaseClass)

Callback to execute when a Mesh is reentering the view frustum.

Type declaration

Param: callback

callback to run when ProjectedMeshBaseClass is reentering the view frustum

Returns

  • our Mesh
onLeaveView: ((callback) => ProjectedMeshBaseClass)

Callback to execute when a Mesh is leaving the view frustum.

Type declaration

Param: callback

callback to run when ProjectedMeshBaseClass is leaving the view frustum

Returns

  • our Mesh
children: Object3D[]

Children Object3D in the scene graph, used to compute their own world matrix

object3DIndex: number

Index (order of creation) of this Object3D. Used in the parent / children relation.

matricesNeedUpdate: boolean

Whether at least one of this Object3D matrix needs an update.

camera: Camera

Camera object used to compute model view and model view projection matrices

GPUCurtainsRenderer used to create this DOMObject3D

autoloadSources: boolean

Whether to automatically create a DOMTexture for all HTMLImageElement, HTMLVideoElement and HTMLCanvasElement child of the specified DOMMesh HTMLElement

_sourcesReady: boolean

Whether all the sources have been successfully loaded

Defines the DOMObject3D bounding boxes in both document and world spaces

domElement: DOMElement

DOMElement used to track the given HTMLElement size change

watchScroll: boolean

Whether to automatically update the DOMObject3D document and world positions on scroll

#DOMObjectWorldPosition: Vec3 = ...

Private vector used to keep track of the actual .world | world position accounting the .document | additional document translation converted into world space

#DOMObjectWorldScale: Vec3 = ...

Private vector used to keep track of the actual DOMObject3D world scale accounting the .world | DOMObject3D world size

#DOMObjectDepthScaleRatio: number = 1

Private number representing the scale ratio of the DOMObject3D along Z axis to apply. Since it can be difficult to guess the most accurate scale along the Z axis of an object mapped to 2D coordinates, this helps with adjusting the scale along the Z axis.

boundingBox: Box3 = ...

Helper bounding box used to map the 3D object onto the 2D DOM element.

_onAfterDOMElementResizeCallback: (() => void) = ...

function assigned to the onAfterDOMElementResize callback

Type declaration

Accessors

  • get clipSpaceBoundingSphere(): {
        center: Vec3;
        radius: number;
    }
  • Get the geometry bounding sphere in clip space.

    Returns {
        center: Vec3;
        radius: number;
    }

    • center: Vec3

      Center of the bounding sphere.

    • radius: number

      Radius of the bounding sphere.

  • set DOMObjectDepthScaleRatio(value): void
  • Set DOMObjectDepthScaleRatio. Since it can be difficult to guess the most accurate scale along the Z axis of an object mapped to 2D coordinates, this helps with adjusting the scale along the Z axis.

    Parameters

    • value: number

      depth scale ratio value to use

    Returns void

Methods

  • Called when the device has been lost to prepare everything for restoration. Basically set all the GPUBuffer to null so they will be reset next time we try to draw the Mesh

    Returns void

  • Set our Mesh geometry: create buffers and add attributes to material

    Returns void

  • Assign or remove a RenderTarget to this Mesh Since this manipulates the Scene stacks, it can be used to remove a RenderTarget as well.

    Parameters

    • outputTarget: RenderTarget

      the RenderTarget to assign or null if we want to remove the current RenderTarget

    Returns void

  • Only render the Mesh if it is in view frustum. Since render() is actually called before onRenderPass(), we are sure to have fresh frustum bounding rectangle values here.

    Parameters

    • pass: GPURenderPassEncoder

      current render pass

    Returns void

  • Check at each render whether we should update our matrices, and update them if needed

    Returns void

  • Set our projection matrices shouldUpdate flags to true (tell them to update)

    Returns void

  • When the world matrix update, tell our projection matrix to update as well

    Returns void

  • Reset/change the DOM Element

    Parameters

    • element: string | HTMLElement

      new HTMLElement or string representing an HTMLElement selector to use

    Returns void

  • Compute the Mesh geometry if needed

    Returns void

  • Set the DOM Element

    Parameters

    • element: string | Element

      HTMLElement or string representing an HTMLElement selector to use

    Returns void

  • Check whether at least one of the matrix should be updated

    Returns void

  • Compute the DOMObject3D world position using its world position and document translation converted to world space

    Returns void