Reference Source
public class | source

ModelMemento

Saves and restores a snapshot of the visual state of the Entity's of a model 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 its Entitys in an ModelMemento. Then we'll show all the Entitys again, and then we'll restore the visual states of all the Entitys again from the ModelMemento, which will hide those two Entitys again.

See Also

import {Viewer, XKTLoaderPlugin,  ModelMemento} 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 ModelMemento = new ModelMemento();

const metaModel = viewer.metaScene.metaModels
     ModelMemento.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
     ModelMemento.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:

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

//...

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

Constructor Summary

Public Constructor
public

constructor(metaModel: MetaModel)

Creates a ModelMemento.

Method Summary

Public Methods
public

restoreObjects(scene: Scene, metaModel: MetaModel)

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

public

saveObjects(scene: Scene, metaModel: MetaModel, mask: Object)

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

Public Constructors

public constructor(metaModel: MetaModel) source

Creates a ModelMemento.

Params:

NameTypeAttributeDescription
metaModel MetaModel
  • optional

When given, immediately saves the model's Entity states to this ModelMemento.

Public Methods

public restoreObjects(scene: Scene, metaModel: MetaModel) source

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

Assumes that the model has not been destroyed or modified since saving.

Params:

NameTypeAttributeDescription
scene Scene

The scene that was given to ModelMemento#saveObjects.

metaModel MetaModel

The metamodel that was given to ModelMemento#saveObjects.

public saveObjects(scene: Scene, metaModel: MetaModel, mask: Object) source

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

Params:

NameTypeAttributeDescription
scene Scene

The scene.

metaModel MetaModel

Represents the model. Corresponds with an Entity that represents the model in 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.