Appearance
CameraPlugin
High-level camera control: animated transitions, saved camera states, and command registration for the command runner.
Usage
CameraPlugin is a core plugin and is loaded automatically by ViewerCore on startup. You typically only need to grab the instance to call its API.
ts
import { ViewerCore, CameraPlugin } from "@optellix/xviewr-sdk";
const viewer = new ViewerCore(container, config);
await viewer.ready();
const camera = viewer.pluginManager.getPlugin("camera") as CameraPlugin;
await camera.flyTo(new THREE.Vector3(10, 5, 10), new THREE.Vector3(0, 0, 0), 1500);To register manually (e.g. after unloadPlugin):
ts
await viewer.loadPlugin(new CameraPlugin());Service dependencies: camera, commands, animation. All three are registered as built-ins by ViewerCore.
Public API
| Method | Description |
|---|---|
flyTo(position, lookAt?, duration?) | Smoothly animate the camera to a position, optionally retargeting. Default duration 1000 ms. |
orbitAround(angleDegrees, duration?) | Orbit around the current controls target by angleDegrees. |
panCamera(horizontal, vertical, duration?) | Pan along screen-right/world-up axes. |
zoomCamera(factor, duration?) | Dolly toward (positive) or away from (negative) the target. factor should be in roughly (-1, 1). |
setViewAnimated(preset, duration?) | Animate to a ViewPreset (top, bottom, left, right, front, back, iso). |
saveCamera(name) | Capture current position, target, rotation under a name. Returns the saved state. |
restoreCamera(name, animated?, duration?) | Restore a saved state. Throws if name is unknown. |
getCameraInfo() | Returns { position, rotation, target, type, fov?, zoom }. |
Events
Emitted on the viewer event bus:
| Event | Payload |
|---|---|
camera:fly-complete | { position, lookAt } |
camera:orbit-complete | { angle } |
camera:saved | { name, state } |
camera:restored | { name, state } |
Registered Commands
When the commands service is present, the plugin declares these commands via getCommands() and BasePlugin registers them. They are removed on deactivate.
move-camera, pan-camera, zoom-camera, fly-to, orbit-camera, set-view, fit-to-view, save-camera, restore-camera, get-camera-info, set-controls, set-camera-type, wait.
Command handlers are thin: each calls the plugin's public methods. The command bodies live in src/plugins/camera/commands.ts.
Example
ts
const camera = viewer.pluginManager.getPlugin("camera") as CameraPlugin;
camera.saveCamera("home");
await camera.setViewAnimated("iso", 800);
await camera.orbitAround(90, 1200);
await camera.restoreCamera("home", true, 1000);