import {ObjectsMemento} from '@xeokit/xeokit-sdk/src/viewer/scene/mementos/ObjectsMemento.js'
ObjectsMemento
Saves and restores a snapshot of the visual state of the Entity's that represent objects within a Scene.
- An Entity represents an object when Entity#isObject is
true
. - Each object-Entity is registered by Entity#id in Scene#objects.
See Also
- CameraMemento - Saves and restores the state of a Scene's Camera.
- 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 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 |
restoreObjects(scene: Scene) Restores a Scene's Entity's to their state previously captured with ObjectsMemento#saveObjects. |
|
public |
saveObjects(scene: Scene, mask: Object) |
Public Constructors
Public Methods
public restoreObjects(scene: Scene) source
Restores a Scene's Entity's to their state previously captured with ObjectsMemento#saveObjects.
Params:
Name | Type | Attribute | Description |
scene | Scene | The scene. |
public saveObjects(scene: Scene, mask: Object) source
Params:
Name | Type | Attribute | Description |
scene | Scene | 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 |