Scene Manager

Insert a model into a scene

You can insert a model into a scene by passing the model as the first argument into the insertModel method.
The optional second argument is an object which holds configurations, for example the pose of the model:

const pose = {
    position: { x: 100, y: 200, z: 300 },
    scale: { x: 10, y: 10, z: 10 },
    orientation: { x: 0, y: 0, z: 0, w: 1 }
};

const model = await modelManager.getModelFromRepository(20);
await sceneManager.insertModel(model, { pose });

Insert a container into a scene

A container is able to contain multiple models or other containers. To insert a new container use the statement bellow. The methods insertContainer and insertModel return the inserted instance, so you can use it later on. To add a model into a container you can use the insertModel method and pass the container instance as a parent property into the configuration object.

const pose = {
    position: { x: 100, y: 200, z: 300 }
};

const container = await sceneManager.insertContainer({ pose });

const model = await modelManager.getModelFromRepository(20);
const instance = await sceneManager.insertModel(model, { parent: container });

Remove a node from scene

A node can be a model or a container instance. To remove a node from a scene, you need to pass the instance into a removeNode method. You can access scene nodes by using the children property of the scene property.

const instance = sceneManager.scene.children[0];
await sceneManager.removeNode(instance);

Scene State

The Scene State holds all the information about the current setup of the scene such as inserted nodes and their current state e.g. pose and visibility. At any point during the runtime, it is possible to serialise the current scene state. Keep in mind that currently the animation state and tracking state are not getting serialised. The serialised state can than be stored and recovered later on, in order to provide save/load functionality. Furthermore, it is possible to synchronise scene states between devices.

Retrieve a Scene State

To retrieve the current Scene State, you can use the following statement:

const sceneState = sceneManager.getSceneState();
localStorage.setItem('sceneState', JSON.stringify(sceneState));

In this example we also save the scene state to local storage for later reuse.

There is also an asynchronous method getSceneStateSafe. This method will wait until other potential current scene manipulations are finished.

const sceneState = await sceneManager.getSceneStateSafe();
localStorage.setItem('sceneState', JSON.stringify(sceneState));

Set a Scene State

To set a Scene State you can use the setSceneState method and pass the sceneState object as the argument. In this example we load the scene state from the example above.

const sceneState = JSON.parse(localStorage.getItem('sceneState'));
await sceneManager.setSceneState(sceneState);