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.

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 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, XKTLoaderPlugin, ObjectsMemento} 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"
});

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);
});
`

Masking Saved State

We can optionally supply a mask to focus what state we save and restore.

For example, to save and restore only the Entity#visible and Entity#clippable states:

objectsMemento.saveObjects(viewer.scene, {
    visible: true,
    clippable: true
});

//...

// Restore the objects states again
objectsMemento.restoreObjects(viewer.scene);

Constructor Summary

Public Constructor
public

Creates an ObjectsMemento.

Method Summary

Public Methods
public

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

public

saveObjects(scene: Scene, mask: Object)

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

Public Constructors

public constructor() source

Creates an ObjectsMemento.

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, mask: Object) source

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

Params:

NameTypeAttributeDescription
scene Scene

The scene.

mask Object
  • optional

Masks what state gets saved. Saves all state when not supplied.

mask.visible boolean
  • optional

Saves Entity#visible values when true.

mask.visible boolean
  • optional

Saves Entity#visible values when true.

mask.edges boolean
  • optional

Saves Entity#edges values when true.

mask.xrayed boolean
  • optional

Saves Entity#xrayed values when true.

mask.highlighted boolean
  • optional

Saves Entity#highlighted values when true.

mask.selected boolean
  • optional

Saves Entity#selected values when true.

mask.clippable boolean
  • optional

Saves Entity#clippable values when true.

mask.pickable boolean
  • optional

Saves Entity#pickable values when true.

mask.colorize boolean
  • optional

Saves Entity#colorize values when true.

mask.opacity boolean
  • optional

Saves Entity#opacity values when true.