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

    Class Scene

    Scene represents the root container of the engine's hierarchical scene graph. It coordinates active camera properties, registered light sources, visible meshes, background clear colors, and manages the high-performance requestAnimationFrame render loop, integrating performance tracking and debugging panels.

    Hierarchy (View Summary)

    Index

    Accessors

    • get ambientGroundColor(): Color

      Gets the hemispherical ambient ground color (surfaces pointing downward).

      Returns Color

    • set ambientGroundColor(color: ColorLike): void

      Sets the hemispherical ambient ground color, parsing hex strings, arrays, or objects automatically.

      Parameters

      Returns void

    • get ambientSkyColor(): Color

      Gets the hemispherical ambient sky color (surfaces pointing upward).

      Returns Color

    • set ambientSkyColor(color: ColorLike): void

      Sets the hemispherical ambient sky color, parsing hex strings, arrays, or objects automatically.

      Parameters

      Returns void

    • get bloom(): {
          get enabled(): boolean;
          set enabled(value: boolean): void;
          get intensity(): number;
          set intensity(value: number): void;
          get knee(): number;
          set knee(value: number): void;
          get passes(): number;
          set passes(value: number): void;
          get threshold(): number;
          set threshold(value: number): void;
      }

      Access to the Bloom post-processing configuration system. Allows configuring bloom settings e.g. scene.bloom.enabled = true.

      Returns {
          get enabled(): boolean;
          set enabled(value: boolean): void;
          get intensity(): number;
          set intensity(value: number): void;
          get knee(): number;
          set knee(value: number): void;
          get passes(): number;
          set passes(value: number): void;
          get threshold(): number;
          set threshold(value: number): void;
      }

    • get canvas(): HTMLCanvasElement

      Gets the active HTMLCanvasElement swapchain presentation surface.

      Returns HTMLCanvasElement

    • get defaultDir(): string

      Gets the default asset base directory.

      Returns string

    • set defaultDir(dir: string): void

      Sets the default asset base directory, ensuring trailing slashes are appended.

      Parameters

      • dir: string

      Returns void

    • get enableFXAA(): boolean

      Gets the FXAA post-processing status.

      Returns boolean

    • set enableFXAA(value: boolean): void

      Sets the FXAA post-processing status, writing parameters to logical GPU uniform buffers.

      Parameters

      • value: boolean

      Returns void

    Constructors

    Methods

    • Overrides polymorphic hierarchy insertion to register Mesh children within the scene graph mesh arrays.

      Parameters

      • node: Node

        The node to add.

      Returns void

    • Instantiates a Plane mesh and appends it to the scene tree.

      Parameters

      • options: SceneGeometryOptions & { height?: number; width?: number } = {}

        Material parameters and width/depth dimensions.

      Returns Mesh

      The newly allocated Plane Mesh.

    • Instantiates a Sphere mesh and appends it to the scene tree.

      Parameters

      • options: SceneGeometryOptions & { radius?: number; segments?: number } = {}

        Material parameters and radius subdivisions options.

      Returns Mesh

      The newly allocated Sphere Mesh.

    • Releases scene resources, stops the render loop, disables debug panels, and cascades destruction to the renderer and context.

      Returns void

    • Asynchronously imports and displays an interactive, hardware-monitored performance debug panel.

      Parameters

      • options: any = {}

        Styling and anchor options.

      Returns Promise<DebugPanel>

      A promise resolving to the debug panel.

    • Gets the active HTMLCanvasElement presentation surface.

      Returns HTMLCanvasElement

    • Queries and returns all visible meshes whose world-space AABB bounding volumes intersect with the specified Node3D's world-space AABB. Utilized for broad-phase collision queries.

      Parameters

      • node: Node3D

        Target Node3D to test.

      Returns Mesh[]

      Meshes currently overlapping the query node.

    • Asynchronously fetches a 3D model asset (GLB, GLTF, or OBJ), compiles GPU resources, and appends the resulting nodes to the scene hierarchy.

      Parameters

      • url: string

        Relative or absolute address of the 3D model file.

      • options: SceneGeometryOptions = {}

        Material parameters and spatial transformations.

      Returns Promise<Node3D>

      A promise resolving to a container Node3D holding the loaded mesh segment nodes.

    • Detaches and removes an active Light node from the scene hierarchy and internal tracking.

      Parameters

      • light: Light

        The Light instance to remove.

      Returns void

    • Initiates the standard requestAnimationFrame render loop. Calls the provided update routine every frame while updating render statistics.

      Parameters

      • OptionalloopCallback: () => void

        Update callback hook.

      Returns void

    • Registers and configures the active Camera viewpoints driving render passes. Automatically appends the Camera to the scene tree if it is not already present.

      Parameters

      Returns Camera

      The resolved Camera node.

    • 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 node's local transformation matrix. Base Node does not define individual translation, rotation, or scale properties. This should be overridden in subclasses (e.g. Node3D) that maintain distinct components.

      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

    • High-level initialization routine that resolves a canvas element, requests WebGPU adapters, boots GPUDevice services, and returns a new Scene container.

      Parameters

      • selector: string | HTMLCanvasElement

        Target CSS selector string or direct HTMLCanvasElement reference.

      Returns Promise<Scene>

      A promise resolving to an initialized Scene.

    Properties

    children: Node[] = []

    List of child nodes belonging to this node.

    ctx: Context

    Active context reference.

    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.

    perfTracker: PerformanceTracker

    High-performance CPU profiling metrics recorder.

    renderer: Renderer

    High-performance WebGPU forward renderer.

    showHelpers: boolean = false

    Toggle debug visualization helpers for lights and collision bounds. Defaults to false.

    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.