Reference Source
public class | source

ObjectsMemento

Saves and restores a snapshot of the visual state of the Entity's that represent objects within a Scene.

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 hide a couple of Entitys and save a snapshot of the visual states of all the Entitys in an ObjectsMemento. Then we'll show all the Entitys again, and then we'll restore the visual states of all the Entitys again from the ObjectsMemento, which will hide those two Entitys again.

import {Viewer} from "../src/viewer/Viewer.js";
import {ObjectsMemento} from "../src/scene/mementos/ObjectsMemento.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"
});

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

     // Model has loaded

     // Hide a couple of objects
     viewer.scene.objects["0u4wgLe6n0ABVaiXyikbkA"].visible = false;
     viewer.scene.objects["3u4wgLe3n0AXVaiXyikbYO"].visible = false;

     // Save memento of all object states, which includes those two hidden objects
     const objectsMemento = new ObjectsMemento();

     objectsMemento.saveObjects(viewer.scene);

     // Show all objects
     viewer.scene.setObjectsVisible(viewer.scene.objectIds, true);

     // Restore the objects states again, which involves hiding those two objects again
     objectsMemento.restoreObjects(viewer.scene);
});
`

Constructor Summary

Public Constructor
public

constructor(scene: Scene)

Creates an ObjectsState.

Method Summary

Public Methods
public

Restores a Scene's Entity's to their state previously captured with ObjectsMemento#saveObjects.

public

saveObjects(scene: Scene)

Saves a snapshot of the visual state of the Entity's that represent objects within a Scene.

Public Constructors

public constructor(scene: Scene) source

Creates an ObjectsState.

Params:

NameTypeAttributeDescription
scene Scene
  • optional

When given, immediately saves the given Scene's Entity states to this ObjectsState.

Public Methods

public restoreObjects(scene: Scene) source

Restores a Scene's Entity's to their state previously captured with ObjectsMemento#saveObjects.

Params:

NameTypeAttributeDescription
scene Scene

The scene.

public saveObjects(scene: Scene) source

Saves a snapshot of the visual state of the Entity's that represent objects within a Scene.

Params:

NameTypeAttributeDescription
scene Scene

The scene.