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

    Class Cam3D

    Wraps a THREE.Camera and provides a structured interface for configuring and controlling camera settings.

    Hierarchy (View Summary)

    Index
    canvas: HTMLElement
    cfg: Cfg
    name: string
    obj: Camera

    The THREE.Camera instance used for rendering the scene. It can represent different camera types, such as perspective or orthographic.

    THREE.PerspectiveCamera

    objGltf: Camera | null = null

    Reference to the original THREE.Camera loaded from the GLTF scene.

    objs3D: Map<string, Obj3D> | null = null
    objTarget: Object3D

    Target object used as the camera look-at target.

    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.

    targetGltf: Object3D<Object3DEventMap> | null = null

    Reference to the original target THREE.Object3D loaded from the GLTF scene.

    • 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 once for a camera found while traversing a GLTF scene. Copies the traversed camera type, projection settings, and world transform to obj.

      Parameters

      • objGltf: Camera

        The GLTF THREE.Camera object.

        Example

        import { Object3D, PerspectiveCamera, Bone } from 'three';
        import { Cam3D } from 'illutions';

        export class DollyCamera extends Cam3D {
        private offsetGltf: Bone | null = null;

        public override onTraverse(objGltf: PerspectiveCamera): void {
        const dollyRig = this.scene.getObjectByName('Dolly_Rig');
        if (!dollyRig) { return; }

        dollyRig.traverse((child: Object3D) => {
        if (child instanceof Bone && child.isBone) {
        if (child.name === 'Camera_Offset') {
        this.offsetGltf = child;
        } else if (child.name === 'Aim') {
        this.targetGltf = child;
        }
        }
        });

        if (objGltf && this.offsetGltf && this.targetGltf) {
        objGltf.updateMatrixWorld(true);

        // near, far, fov, zoom, frustum,...
        this.obj.copy(objGltf);

        // Override local with world pose
        this.offsetGltf.getWorldPosition(this.obj.position);
        this.targetGltf.getWorldPosition(this.objTarget.position);

        // Set FOV from GLTF camera
        if (this.obj instanceof PerspectiveCamera) {
        this.obj.updateProjectionMatrix();
        }

        // Camera looks at aim
        this.obj.lookAt(this.objTarget.position);
        }

        this.objGltf = objGltf;
        }
        }

      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