Illutions Engine API - v0.26.0
    Preparing search index...

    Class Mesh3D

    Manages 3D meshes in illutions. Wraps a THREE.Mesh and provides support for scene integration and optional screen-space reflection (SSR) features.

    Hierarchy (View Summary)

    Index
    canvas: HTMLElement
    cfg: Cfg
    groundReflector:
        | ReflectorForSSRPass<
            BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>,
        >
        | null = null

    ReflectorForSSRPass surface used for screen-space reflections (SSR). When set, it renders dynamic reflections on a ground plane.

    name: string
    obj: Mesh

    The underlying THREE.Mesh used for rendering. It can be replaced with a custom mesh that uses different geometry or material settings.

    THREE.BoxGeometry, THREE.MeshPhysicalMaterial

    objs3D: Map<string, Obj3D> | null = null
    reflectivesSSR: Object3D<Object3DEventMap>[] = []

    Objects that participate in the screen-space reflection (SSR) effect. These objects are used for reflective rendering in the scene.

    renderer: Readonly<WebGLRenderer> | Readonly<WebGPURenderer>

    The active Three.js renderer used by this object. It is exposed for advanced use cases that require renderer-dependent Three.js APIs, such as reading the canvas size, pixel ratio, drawing buffer size, or updating renderer-based helper objects like cube cameras.

    scene: Readonly<THREE_TYPE.Scene>

    The THREE.Scene instance this object belongs to.

    • Registers a listener that is called whenever the specified event occurs.

      Type Parameters

      • TType extends
            | "OBJ3D_POS_WORLD_CHANGED"
            | "OBJ3D_POS_SCREEN_CHANGED"
            | "OBJ3D_ROT_WORLD_CHANGED"
            | "OBJ3D_FRUSTUM_CHANGED"
            | "OBJ3D_VISIBLE_CHANGED"
            | "OBJ3D_CLICK"
            | "OBJ3D_POINTER_ENTER"
            | "OBJ3D_POINTER_DOWN"
            | "OBJ3D_POINTER_LEAVE"
            | "OBJ3D_POINTER_MOVE"
            | "OBJ3D_POINTER_UP"

      Parameters

      Returns Unsubscribe

      A function that unsubscribes the listener.

    • Returns the object's screen position in canvas coordinates.

      Parameters

      • cam3D: Cam3D

        Camera used for projection to canvas coordinates.

      Returns { x: number; y: number } | null

      The projected screen position in canvas coordinates, or null if no THREE.Object3D is assigned.

    • Called once after the THREE.Scene, the THREE.WebGLRenderer or THREE.WebGPURenderer, the EnvCtrls are initialized and an existing GLTF model has been loaded and traversed.

      Returns void

    • Called once after the THREE.Scene is initialized, before an existing GLTF model is loaded.

      Returns void

    • Called for each traversed mesh during GLTF parsing. Stores the current THREE.Mesh in this.obj.

      Parameters

      • objGltf: Mesh

        The currently traversed mesh.

        Example

        import { Mesh, MeshPhysicalMaterial } from 'three';
        import { Mesh3D } from 'illutions';

        export class Cube extends Mesh3D {
        // Called while illutions traverses the loaded 3D scene.
        // The matching Three.js mesh from the GLTF scene is passed in here.
        public override onTraverse(mesh: Mesh): void {
        // Access the mesh material as a physical material.
        const material = mesh.material as MeshPhysicalMaterial;

        // Enable depth writing so the mesh correctly affects depth-based rendering.
        material.depthWrite = true;

        // Enable shadow casting and receiving for this mesh.
        mesh.castShadow = true;
        mesh.receiveShadow = true;

        // Keep the mesh rendered even when Three.js thinks it is outside the camera frustum.
        mesh.frustumCulled = false;

        // Add the mesh to the SSR reflective objects list.
        this.reflectivesSSR.push(mesh);

        // Store the configured `THREE.Mesh` as the runtime object.
        this.obj = mesh;
        }
        }

      Returns void

    • Called on every animation frame update.

      Parameters

      • deltaTime: number

        Time elapsed since the previous frame in seconds.

      Returns void

    • Removes a previously registered listener for the specified event.

      Type Parameters

      • TType extends
            | "OBJ3D_POS_WORLD_CHANGED"
            | "OBJ3D_POS_SCREEN_CHANGED"
            | "OBJ3D_ROT_WORLD_CHANGED"
            | "OBJ3D_FRUSTUM_CHANGED"
            | "OBJ3D_VISIBLE_CHANGED"
            | "OBJ3D_CLICK"
            | "OBJ3D_POINTER_ENTER"
            | "OBJ3D_POINTER_DOWN"
            | "OBJ3D_POINTER_LEAVE"
            | "OBJ3D_POINTER_MOVE"
            | "OBJ3D_POINTER_UP"

      Parameters

      Returns void