Reference Source
public class | source

CameraMemento

Saves and restores the state of a Scene's Camera.

See Also

Usage

In the example below, we'll create a Viewer and use an XKTLoaderPlugin to load an .xkt model. When the model has loaded, we'll save a snapshot of the Camera state in an CameraMemento. Then we'll move the Camera, and then we'll restore its original state again from the CameraMemento.

import {Viewer, XKTLoaderPlugin, CameraMemento} from "xeokit-sdk.es.js";

const viewer = new Viewer({
    canvasId: "myCanvas"
});

// Load a model
const xktLoader = new XKTLoaderPlugin(viewer);

const model = xktLoader.load({
    id: "myModel",
    src: "./models/xkt/schependomlaan/schependomlaan.xkt"
});

// Set camera
viewer.camera.eye = [-2.56, 8.38, 8.27];
viewer.camera.look = [13.44, 3.31, -14.83];
viewer.camera.up = [0.10, 0.98, -0.14];

model.on("loaded", () => {

     // Model has loaded

     // Save memento of camera state
     const cameraMemento = new CameraMemento();

     cameraMemento.saveCamera(viewer.scene);

     // Move the camera
     viewer.camera.eye = [45.3, 2.00, 5.13];
     viewer.camera.look = [0.0, 5.5, 10.0];
     viewer.camera.up = [0.10, 0.98, -0.14];

     // Restore the camera state again
     objectsMemento.restoreCamera(viewer.scene);
});

Constructor Summary

Public Constructor
public

constructor(scene: Scene)

Creates a CameraState.

Method Summary

Public Methods
public

restoreCamera(scene: Scene, done: Function)

Restores a Scene's Camera to the state previously captured with CameraMemento#saveCamera.

public

saveCamera(scene: Scene)

Saves the state of the given Scene's Camera.

Public Constructors

public constructor(scene: Scene) source

Creates a CameraState.

Params:

NameTypeAttributeDescription
scene Scene
  • optional

When given, immediately saves the state of the given Scene's Camera.

Public Methods

public restoreCamera(scene: Scene, done: Function) source

Restores a Scene's Camera to the state previously captured with CameraMemento#saveCamera.

Params:

NameTypeAttributeDescription
scene Scene

The scene.

done Function
  • optional

When this callback is given, will fly the Camera to the saved state then fire the callback. Otherwise will just jump the Camera to the saved state.

public saveCamera(scene: Scene) source

Saves the state of the given Scene's Camera.

Params:

NameTypeAttributeDescription
scene Scene

The scene that contains the Camera.