Skip to content

WasmGPU.createControls.navigation().setMode

Summary

WasmGPU.createControls.navigation().setMode switches interaction behavior between orbit and trackball. The method synchronizes internal state from the current camera pose before and after the mode change. Use it to expose runtime mode toggles in UI controls.

Syntax

WasmGPU.createControls.navigation().setMode(mode: NavigationMode): this
controls.setMode(mode);

Parameters

Name Type Required Description
mode NavigationMode Yes Requested controls mode: "orbit" or "trackball".

Returns

this - Returns the same controls instance.

Type Details

type NavigationMode = "orbit" | "trackball";

Example

const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const camera = wgpu.createCamera.perspective({ fov: 50, aspect: canvas.clientWidth / canvas.clientHeight, near: 0.1, far: 1000 });
const controls = wgpu.createControls.navigation(camera, canvas, { mode: "orbit" });

document.getElementById("mode").addEventListener("click", () => {
    controls.setMode(controls.mode === "orbit" ? "trackball" : "orbit");
});

See Also