Skip to content

Camera

Camera controls. Position the viewport camera, snap it to a standard orthographic/isometric view, toggle between the 2D (plan) and 3D modelling modes, and switch the 3D projection — mirrors the canvas view menu, the 2D/3D toggle, and the View Settings panel's Perspective/Orthographic control. Like Zoom, these are transient view-state changes: they are not model edits, so they are not write-gated and are not undoable. Accessed via snaptrude.core.camera.

Functions

lookFrom(eye, target)

Point the camera: place its eye at eye looking toward target (world coordinates, internal babylon units).

  • eye: Vec3Handle — camera position.
  • target: Vec3Handle — the point the camera looks at.
  • Returns: booleantrue once the camera has been positioned.
ts
const { vec3 } = snaptrude.core.math;
await snaptrude.core.camera.lookFrom(vec3.new(50, 30, 50), vec3.new(0, 0, 0));

setStandardView(view)

Snap the camera to a standard view — the five orthographic elevations (top / front / back / left / right) or the 3D iso (isometric perspective) view. The orthographic presets exit 2D mode first if needed.

  • view: "top" | "front" | "back" | "left" | "right" | "iso".
  • Returns: booleantrue once the view has been applied.
ts
await snaptrude.core.camera.setStandardView("top");

setMode(mode)

Toggle the modelling mode between 2d (plan) and 3d. 3d enters the isometric perspective view; 2d drops to the orthographic plan of the active storey.

  • mode: "2d" | "3d".
  • Returns: booleantrue once the mode switch has been requested.
ts
await snaptrude.core.camera.setMode("3d");

getProjection()

Read the camera's current projection: "perspective" (the default 3D view) or "orthographic". In 2D (plan) mode this always reports "orthographic" — a plan is an orthographic projection.

  • Returns: "perspective" | "orthographic".
ts
const projection = await snaptrude.core.camera.getProjection();
console.log(projection); // "perspective" | "orthographic"

setProjection(projection)

Switch the 3D camera between "perspective" and "orthographic" projection — the Perspective/Orthographic control in the Design tab's View Settings panel (the same toggle, and it keeps that panel's radio in sync). Like setMode, a transient view-state change: not write-gated, not undoable. Setting the projection it already has is a no-op.

In 2D (plan) mode the canvas is always an orthographic plan: "orthographic" is accepted as a no-op, while "perspective" rejects with PRECONDITION_FAILED — switch to 3D first via setMode("3d").

  • projection: "perspective" | "orthographic".
  • Returns: booleantrue once the projection has been applied.
ts
await snaptrude.core.camera.setProjection("orthographic");
const projection = await snaptrude.core.camera.getProjection(); // "orthographic"

Errors

Failed calls reject with a typed PluginError — see Error Handling. lookFrom rejects with PRECONDITION_FAILED if there is no active camera, and with HANDLE_INVALID if a vector handle is gone or forged. setStandardView / setMode / setProjection reject with VALIDATION on an unrecognized view/mode/projection. getProjection / setProjection reject with PRECONDITION_FAILED when there is no active camera, and setProjection("perspective") rejects with PRECONDITION_FAILED while in 2D mode; otherwise the methods are total.