API Reference

Class List

SceneRegistry

Container for storing and loading of scenes. An instance of the registry is created on the AppBase object as AppBase#scenes.

Summary

Methods

add

Add a new item to the scene registry.

changeScene

Change to a new scene.

find

Find a Scene by name and return the SceneRegistryItem.

findByUrl

Find a scene by the URL and return the SceneRegistryItem.

list

Return the list of scene.

loadScene

Load the scene hierarchy and scene settings.

loadSceneData

Loads and stores the scene data to reduce the number of the network requests when the same scenes are loaded multiple times.

loadSceneHierarchy

Load a scene file, create and initialize the Entity hierarchy and add the hierarchy to the application root Entity.

loadSceneSettings

Load a scene file and apply the scene settings to the current scene.

remove

Remove an item from the scene registry.

unloadSceneData

Unloads scene data that has been loaded previously using SceneRegistry#loadSceneData.

Details

Constructor

SceneRegistry(app)

Create a new SceneRegistry instance.

Parameters

appAppBase

The application.

Methods

add(name, url)

Add a new item to the scene registry.

Parameters

namestring

The name of the scene.

urlstring

The url of the scene file.

Returns

boolean

Returns true if the scene was successfully added to the registry, false otherwise.

changeScene(sceneItem, [callback])

Change to a new scene. Calling this function will load the scene data, delete all entities and graph nodes under app.root and load the scene settings and hierarchy.

app.scenes.changeScene("Scene Name", function (err, entity) {
    if (!err) {
        // success
    } else {
        // error
    }
});

Parameters

sceneItemSceneRegistryItem, string

The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

callbackChangeSceneCallback

The function to call after loading, passed (err, entity) where err is null if no errors occurred.

find(name)

Find a Scene by name and return the SceneRegistryItem.

Parameters

namestring

The name of the scene.

Returns

SceneRegistryItem, null

The stored data about a scene or null if no scene with that name exists.

findByUrl(url)

Find a scene by the URL and return the SceneRegistryItem.

Parameters

urlstring

The URL to search by.

Returns

SceneRegistryItem, null

The stored data about a scene or null if no scene with that URL exists.

list()

Return the list of scene.

Returns

SceneRegistryItem[]

All items in the registry.

loadScene(url, callback)

Load the scene hierarchy and scene settings. This is an internal method used by the AppBase.

Parameters

urlstring

The URL of the scene file.

callbackLoadSceneCallback

The function called after the settings are applied. Passed (err, scene) where err is null if no error occurred and scene is the Scene.

loadSceneData(sceneItem, callback)

Loads and stores the scene data to reduce the number of the network requests when the same scenes are loaded multiple times. Can also be used to load data before calling SceneRegistry#loadSceneHierarchy and SceneRegistry#loadSceneSettings to make scene loading quicker for the user.

const sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneData(sceneItem, function (err, sceneItem) {
    if (err) {
        // error
    }
});

Parameters

sceneItemSceneRegistryItem, string

The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

callbackLoadSceneDataCallback

The function to call after loading, passed (err, sceneItem) where err is null if no errors occurred.

loadSceneHierarchy(sceneItem, callback)

Load a scene file, create and initialize the Entity hierarchy and add the hierarchy to the application root Entity.

const sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneHierarchy(sceneItem, function (err, entity) {
    if (!err) {
        const e = app.root.find("My New Entity");
    } else {
        // error
    }
});

Parameters

sceneItemSceneRegistryItem, string

The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

callbackLoadHierarchyCallback

The function to call after loading, passed (err, entity) where err is null if no errors occurred.

loadSceneSettings(sceneItem, callback)

Load a scene file and apply the scene settings to the current scene.

const sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneSettings(sceneItem, function (err) {
    if (!err) {
        // success
    } else {
        // error
    }
});

Parameters

sceneItemSceneRegistryItem, string

The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

callbackLoadSettingsCallback

The function called after the settings are applied. Passed (err) where err is null if no error occurred.

remove(name)

Remove an item from the scene registry.

Parameters

namestring

The name of the scene.

unloadSceneData(sceneItem)

Unloads scene data that has been loaded previously using SceneRegistry#loadSceneData.

const sceneItem = app.scenes.find("Scene Name");
app.scenes.unloadSceneData(sceneItem);

Parameters

sceneItemSceneRegistryItem, string

The scene item (which can be found with SceneRegistry#find or URL of the scene file. Usually this will be "scene_id.json".