Documentation - v20.0.0-dev
    Preparing search index...

    Draws a Scene, given at its creation, into the caller's canvas from a camera, frame after frame, with a WebGL2 or a WebGPU backend, chosen at its creation and used inside. The scene is the same for both, its settings the renderer's:

    const scene = new Scene(settings);
    const renderer = await Renderer.create({ canvas, scene });
    renderer.setCamera(camera);
    renderer.start();

    It draws the three.js scene of its scene (Scene.threeScene), and holds the size and the frames. It draws on demand, as TeiaViewer's viewport: requestFrame asks for one, the requests before the next display refresh giving one frame. The caller asks after its changes: the camera moved (e.g. camera controls that moved, damping included), the objects changed, the size changed (e.g. at the end of a command). The engine asks for the frames of its own work, which the caller does not see: a culling result arrived, the occlusion settles, a buffer grew, the BoxTree or a setting changed (Scene.signals.changed). At a frame, it reads what changed since the last one. start draws every display refresh instead, until stop. Once nothing changes, it draws settings.postProcessing.antialiasing.accumulatedFrames more frames by itself, shown averaged: any frame asked for starts over.

    A frame: onBeforeFrame, then the backend uploads what changed, culls and draws. Its settings (culling, antialiasing...) hold across backends. The camera belongs to the caller. Its backend is kept: at a change of settings.renderer.backend, it reloads the page (a canvas keeps the backend it first drew with), the application saving its settings then. The depth is reversed (1 near, 0 far, float): its precision follows the distance.

    Index

    Properties

    onBeforeFrame: Signal<() => void> = ...

    At the start of every frame, before the upload and the draw.

    scene: Scene

    The objects drawn, given at its creation.

    Accessors

    • get backend(): Backend

      The backend drawing.

      Returns Backend

    • get canvas(): HTMLCanvasElement

      Where it draws.

      Returns HTMLCanvasElement

    • get frameTime(): number

      Average time between the frames over the last second, in ms, while frames follow one another (a pause of a quarter second starts it over); 0 before the first second.

      Returns number

    • get info(): RenderInfo

      What the last frame drew.

      Returns RenderInfo

    • get running(): boolean

      Whether the animation loop runs (start): a frame every display refresh.

      Returns boolean

    • get settings(): EngineSettings

      The engine's settings: its scene's (Scene.settings), the drawing ones applied live.

      Returns EngineSettings

    Methods

    • Stops the loop, frees the GPU resources and stops following the settings (its scene's). The canvas stays the caller's.

      Returns void

    • Draws one frame now: called by the loop, or alone to draw on demand. Then asks for the next accumulated frame, unless another frame was asked for meanwhile, the loop runs or the settings.postProcessing.antialiasing.accumulatedFrames are drawn.

      Returns void

    • Asks for a frame at the next display refresh: the requests until then give one frame. Nothing more while the animation loop runs. The frames accumulated start over.

      Returns void

    • Draws from camera from now on, perspective or orthographic; its aspect follows the canvas (see setSize).

      Parameters

      Returns void

    • Sizes the canvas's drawing buffer, from its size on the page in CSS pixels (the caller's, set by its CSS), and fits the camera to its aspect: a perspective camera's aspect; an orthographic camera's left and right, around their centre, its top and bottom kept. The frames accumulated start over: the next frame is a whole one, not a sample blended into an average of the former size.

      Parameters

      • width: number
      • height: number

      Returns void

    • Starts the animation loop: one frame per display refresh, until stop.

      Returns void

    • Stops the animation loop, and a frame asked for: frames are drawn on demand again.

      Returns void

    • Creates a renderer of the backend wanted. Asynchronous: a WebGPU adapter and device are asked for.

      Parameters

      • options: RendererOptions

        The scene drawn, where to draw, the backend wanted.

      Returns Promise<Renderer>

      The renderer, without a camera, its loop not started.