gpu-curtains
    Preparing search index...

    Class used to create a Mesh with built-in lighting. Shading types include 'Unlit' (no lighting), 'Lambert', 'Phong' and 'PBR'. For a better 'PBR' shading result, you should always use an associated EnvironmentMap.

    Since the shaders are automatically generated based on the material parameter passed, it is more difficult to tweak them, even tho a few options exist. If you want full control over your shading, consider using a regular Mesh and writing your own shaders.

    // assume 'renderer' is a valid camera renderer

    const ambientLight = new AmbientLight(renderer, {
    intensity: 0.1,
    })

    const directionalLight = new DirectionalLight(renderer, {
    position: new Vec3(10),
    })

    // A mesh with 'Lambert' shading
    const lambertMesh = new LitMesh(renderer, {
    label: 'Mesh with lambert shading',
    geometry: new BoxGeometry(),
    material: {
    shading: 'Lambert',
    color: new Vec3(1),
    },
    })

    // A mesh with a base color texture, 'Phong' shading
    // and where we modify the output color before the lighting calculations

    // create a base color texture
    baseColorTexture = new MediaTexture(renderer, {
    label: 'Base color texture',
    name: 'baseColorTexture',
    format: 'rgba8unorm-srgb',
    visibility: ['fragment'],
    })

    // load the image
    baseColorTexture.loadImage('./path/to/texture.jpg')

    // create the mesh
    const phongMesh = new LitMesh(renderer, {
    label: 'Mesh with phong shading',
    geometry: new BoxGeometry(),
    material: {
    shading: 'Phong',
    fragmentChunks: {
    // applied after having set the color and baseColorTexture to outputColor
    // but before lighting calculations
    preliminaryContribution: 'outputColor = mix(outputColor, vec4(vec3(modifiedMaterial.color), 1.0), modifiedMaterial.mixValue);'
    },
    color: new Vec3(1),
    shininess: 60,
    baseColorTexture: {
    texture: baseColorTexture,
    },
    },
    uniforms: {
    modifiedMaterial: {
    visibility: ['fragment'],
    struct: {
    color: {
    type: 'vec3f',
    value: sRGBToLinear(new Vec3(0.5)), // colors need to be in linear space
    },
    mixValue: {
    type: 'f32',
    value: 0.5,
    }
    },
    },
    },
    })

    Hierarchy (View Summary)

    Index

    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.

    additionalOutputTargets?: RenderTarget[]

    Additional output RenderTarget onto which render this Mesh, besides the main outputTarget or screen. Useful for some effects that might need to render the same Mesh twice or more. Beware tho that the Mesh pipeline has to exactly fit the provided RenderTarget render passes descriptors as no checks will be performed here.

    renderBundle: RenderBundle

    RenderBundle used to render this Mesh, 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

    _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

    _onBeforeRenderCallback: () => void

    function assigned to the onBeforeRender callback

    _onRenderCallback: () => void

    function assigned to the onRender callback

    _onAfterRenderCallback: () => void

    function assigned to the onAfterRender callback

    _onAfterResizeCallback: () => void

    function assigned to the onAfterResize callback

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

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

    Type Declaration

    onBeforeRender: (callback: () => void) => 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

    onRender: (callback: () => void) => 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

    onAfterRender: (callback: () => void) => 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

    onAfterResize: (callback: () => void) => ProjectedMeshBaseClass | MeshBaseClass

    Callback to execute just after a Mesh has been resized.

    Type Declaration

    renderer: CameraRenderer

    The CameraRenderer used

    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

    _onLeaveViewCallback: () => void

    function assigned to the onLeaveView callback

    onReEnterView: (callback: () => void) => ProjectedMeshBaseClass

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

    Type Declaration

    onLeaveView: (callback: () => void) => ProjectedMeshBaseClass

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

    Type Declaration

    transforms: Object3DTransforms
    up: Vec3

    Vec3 used by the lookAt method, to determine the orientation of the result. Default to new Vec3(0, 1, 0).

    actualPosition: Vec3

    Vec3 holding the actual position of this Object3D from its worldMatrix.

    children: Object3D[]

    Children Object3D in the scene graph, used to compute their own worldMatrix.

    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

    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.

    • get parentVisibility(): boolean

      Get whether all this Object3D parents are visible or not. Should not be used directly.

      Returns boolean

    • set parentVisibility(value: boolean): void

      Set to false if at least one of this Object3D parent is not visible, true otherwise. Should not be used directly.

      Parameters

      • value: boolean

        New parent visibility value.

      Returns void

    Methods