Nano WebGPU API - v0.11.0
    Preparing search index...

    Class Camera

    Camera represents a viewpoint node within the 3D scene. It manages projection, view, and concatenated view-projection matrices, and maintains dedicated WebGPU uniform buffers describing camera matrices and spatial positions to fragment shaders.

    Hierarchy (View Summary)

    Index

    Accessors

    • get aspect(): number

      Gets the projection aspect ratio.

      Returns number

    • set aspect(val: number): void

      Sets the projection aspect ratio and recomputes the projection matrix.

      Parameters

      • val: number

      Returns void

    • get far(): number

      Gets the far clipping plane distance.

      Returns number

    • set far(val: number): void

      Sets the far clipping plane distance and recomputes the projection matrix.

      Parameters

      • val: number

      Returns void

    • get fov(): number

      Gets the Field of View angle in radians.

      Returns number

    • set fov(val: number): void

      Sets the Field of View angle in radians and recomputes the projection matrix.

      Parameters

      • val: number

      Returns void

    • get material(): Material | null

      Gets the material associated with this node if it is a Mesh, or recursively searches descendants and returns the material of the first child Mesh found.

      Returns Material | null

      The Material instance, or null if none was found.

    • set material(value: Material | null): void

      Sets the material for this node (if it is a Mesh) or recursively applies it to all descendant Mesh nodes.

      Parameters

      • value: Material | null

        The Material instance to assign.

      Returns void

    • get materials(): Material[]

      Gets all unique materials associated with this node and its descendants.

      Returns Material[]

      An array of Material instances.

    • set materials(value: Material | Material[] | null): void

      Sets materials for this node and its descendants. If value is a single Material, it is applied to all meshes. If value is an array of Materials, they are applied to the descendant meshes in order.

      Parameters

      Returns void

    • get near(): number

      Gets the near clipping plane distance.

      Returns number

    • set near(val: number): void

      Sets the near clipping plane distance and recomputes the projection matrix.

      Parameters

      • val: number

      Returns void

    • get position(): Vec3

      Gets the spatial 3D position vector of this node. Modifying individual components of this vector will automatically flag the node as dirty.

      Returns Vec3

    • set position(val: Vec3): void

      Sets the spatial 3D position vector of this node. Copies the components of the incoming vector and flags the node as dirty.

      Parameters

      Returns void

    • get rotation(): Vec3

      Gets the spatial Euler rotation vector (pitch, yaw, roll) in radians. Modifying individual components of this vector will automatically flag the node as dirty.

      Returns Vec3

    • set rotation(val: Vec3): void

      Sets the spatial Euler rotation vector (pitch, yaw, roll) in radians. Copies the components of the incoming vector and flags the node as dirty.

      Parameters

      Returns void

    • get rotationDegrees(): Vec3

      Gets the spatial Euler rotation vector in degrees. Accessing or mutating components of this proxy converts automatically to/from radians.

      Returns Vec3

    • set rotationDegrees(val: Vec3 | number[]): void

      Sets the spatial Euler rotation vector in degrees. Converts the incoming components to radians and flags the node as dirty.

      Parameters

      • val: Vec3 | number[]

      Returns void

    • get scale(): Vec3

      Gets the spatial 3D scale vector of this node. Modifying individual components of this vector will automatically flag the node as dirty.

      Returns Vec3

    • set scale(val: Vec3): void

      Sets the spatial 3D scale vector of this node. Copies the components of the incoming vector and flags the node as dirty.

      Parameters

      Returns void

    Constructors

    Methods

    • Adds a child node to this node's hierarchy. If the child already has a parent, it is automatically removed from that parent first. Sets the child's dirty flag to true to force transform updates.

      Parameters

      • child: Node

        The Node instance to append as a child.

      Returns void

    • Spawns and registers an interactive CameraController of the designated operational mode.

      Parameters

      • mode: "third-person"

        Orbit, first-person orbital, or target third-person camera controls.

      • options: ThirdPersonOptions

        Custom configurations matching parameters of the specific mode.

      Returns CameraController

      The newly allocated CameraController instance.

    • Spawns and registers an interactive CameraController of the designated operational mode.

      Parameters

      • mode: "first-person"

        Orbit, first-person orbital, or target third-person camera controls.

      • options: FirstPersonOptions

        Custom configurations matching parameters of the specific mode.

      Returns CameraController

      The newly allocated CameraController instance.

    • Spawns and registers an interactive CameraController of the designated operational mode.

      Parameters

      • mode: "orbit"

        Orbit, first-person orbital, or target third-person camera controls.

      • Optionaloptions: OrbitOptions

        Custom configurations matching parameters of the specific mode.

      Returns CameraController

      The newly allocated CameraController instance.

    • Computes and returns the world-space bounding box (AABB) of this node's collision shape. Transform the local shape bounds by the node's current world-space transformation matrix.

      Returns AABB | null

      The transformed AABB bounding box, or null if no collision shape is set.

    • Allocates logical GPUBuffers and registers camera memory tracking within the VRAM tracker.

      Parameters

      • ctx: Context

        Shared framework context.

      Returns void

    • Determines if this node's world-space collision bounds overlap with another node's bounds. Both nodes must have active collision shapes; returns false otherwise.

      Parameters

      • other: Node3D

        The other Node3D instance to test against.

      Returns boolean

      True if the world-space AABBs intersect, false otherwise.

    • Removes a child node from this node's hierarchy. Clears the parent reference of the child node and sets its dirty flag.

      Parameters

      • child: Node

        The Node instance to detach.

      Returns void

    • Helper method to set position, rotation, and scale components simultaneously. Copies existing components from provided vectors and marks the node transform as dirty.

      Parameters

      • Optionalposition: Vec3

        Optional new position vector.

      • Optionalrotation: Vec3

        Optional new Euler rotation vector in radians.

      • Optionalscale: Vec3

        Optional new scale vector.

      Returns void

    • Performs a depth-first traversal of the node hierarchy starting from this node, executing the provided callback on each visited node.

      Parameters

      • callback: (node: Node) => void

        The function to invoke for each node.

      Returns void

    • Recomputes the view matrix (lookAt transformation) and propagates view-projection matrices directly into GPU uniform buffer buffers.

      Returns void

    • Forces recomputation of the perspective projection matrix based on fov, aspect, near, and far.

      Returns void

    • Updates the global world matrix of this node and recursively propagates the updates down the hierarchy to all child nodes.

      Parameters

      • force: boolean = false

        If true, forces transformation matrices to be recomputed even if they are not flagged as dirty.

      Returns void

    Properties

    bindGroup?: GPUBindGroup

    Shared resource GPUBindGroup layout mapping.

    children: Node[] = []

    List of child nodes belonging to this node.

    collisionShape: CollisionShape | null = null

    Optional collision shape representing the physical bounds of this node. Utilized for standard AABB intersection tests and spatial overlap checks.

    controller: CameraController | null = null

    Attached interactive controller handling standard input orbital, first-person, or third-person cameras.

    isDirty: boolean = true

    Whether the local transform has changed and needs to be recomputed and propagated.

    localMatrix: Mat4 = ...

    Local transformation matrix relative to the parent node.

    name: string = ""

    Unique identifier or friendly name for the node.

    parent: Node | null = null

    Parent node in the scene graph. Null if this is the root node.

    projectionMatrix: Mat4 = ...

    Mathematical perspective projection matrix.

    uniformBuffer?: GPUBuffer

    Dedicated WebGPU GPUBuffer holding camera matrices.

    viewMatrix: Mat4 = ...

    Mathematical view matrix representing inverse coordinate space transformations.

    viewProjMatrix: Mat4 = ...

    Combined view-projection matrix representing global clip-space transforms.

    visible: boolean = true

    Visibility flag. If false, this node and its descendants are typically skipped in rendering.

    worldMatrix: Mat4 = ...

    Global world transformation matrix relative to the scene origin.