import {ModelMemento} from '@xeokit/xeokit-sdk/src/viewer/scene/mementos/ModelMemento.js'
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
- CameraMemento - Saves and restores the state of a Scene's Camera.
- ObjectsMemento - Saves and restores a snapshot of the visual state of the Entity's that represent objects within a Scene.
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 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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
scene | Scene | The scene. |
|
metaModel | MetaModel | Represents the model. Corresponds with an Entity that represents the model in the scene. |
|
mask | Object |
|
Masks what state gets saved. Saves all state when not supplied. |
mask.visible | boolean |
|
Saves Entity#visible values when |
mask.visible | boolean |
|
Saves Entity#visible values when |
mask.edges | boolean |
|
Saves Entity#edges values when |
mask.xrayed | boolean |
|
Saves Entity#xrayed values when |
mask.highlighted | boolean |
|
Saves Entity#highlighted values when |
mask.selected | boolean |
|
Saves Entity#selected values when |
mask.clippable | boolean |
|
Saves Entity#clippable values when |
mask.pickable | boolean |
|
Saves Entity#pickable values when |
mask.colorize | boolean |
|
Saves Entity#colorize values when |
mask.opacity | boolean |
|
Saves Entity#opacity values when |