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
Methods
add(name, url)
Add a new item to the scene registry.
Parameters
name | string | The name of the scene. |
url | string | The url of the scene file. |
Returns
booleanReturns 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
sceneItem | SceneRegistryItem, 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. |
callback | ChangeSceneCallback | 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
name | string | The name of the scene. |
Returns
SceneRegistryItem, nullThe 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
url | string | The URL to search by. |
Returns
SceneRegistryItem, nullThe stored data about a scene or null if no scene with that URL exists.
loadScene(url, callback)
Load the scene hierarchy and scene settings. This is an internal method used by the AppBase.
Parameters
url | string | The URL of the scene file. |
callback | LoadSceneCallback | 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.
var sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneData(sceneItem, function (err, sceneItem) {
if (err) {
// error
}
});
Parameters
sceneItem | SceneRegistryItem, 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. |
callback | LoadSceneDataCallback | 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.
var sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneHierarchy(sceneItem, function (err, entity) {
if (!err) {
var e = app.root.find("My New Entity");
} else {
// error
}
});
Parameters
sceneItem | SceneRegistryItem, 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. |
callback | LoadHierarchyCallback | 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.
var sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneSettings(sceneItem, function (err) {
if (!err) {
// success
} else {
// error
}
});
Parameters
sceneItem | SceneRegistryItem, 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. |
callback | LoadSettingsCallback | The function called after the settings are applied. Passed (err) where err is null if no error occurred. |
unloadSceneData(sceneItem)
Unloads scene data that has been loaded previously using SceneRegistry#loadSceneData.
var sceneItem = app.scenes.find("Scene Name");
app.scenes.unloadSceneData(sceneItem);
Parameters
sceneItem | SceneRegistryItem, string | The scene item (which can be found with SceneRegistry#find or URL of the scene file. Usually this will be "scene_id.json". |