LS.Scene Class
The Scene contains all the info about the Scene and nodes
Constructor
LS.Scene
()
Item Index
Methods
- addPreloadResource
- clear
- collectData
- configure
- createAnimation
- filterNodes
- findComponentByUId
- findMaterialByUId
- findNodeComponents
- finish
- generateUniqueNodeName
- getActiveCameras
- getActiveLights
- getAllCameras
- getLayerNames
- getNode
- getNodeByIndex
- getNodeByName
- getNodeByUId
- getNodes
- getPropertyInfo
- getPropertyInfoFromPath
- getPropertyValue
- getResources
- getTime
- init
- instantiate
- load
- loadFromResources
- loadResources
- pause
- recomputeNodesArray
- removePreloadResource
- render
- requestFrame
- Scene.getScriptsList
- serialize
- setFromJSON
- setPropertyValue
- setPropertyValueFromPath
- start
- toPack
- triggerInNodes
- unpause
- update
Methods
addPreloadResource
-
fullpath
Adds a resource that must be loaded when the scene is loaded
Parameters:
-
fullpath
Stringthe name of the resource
clear
()
Clears the scene using the init function and trigger a "clear" LEvent
collectData
-
cameras
This methods crawls the whole tree and collects all the useful info (cameras, lights, render instances, colliders, etc) Mostly rendering stuff but also some collision info. TO DO: refactor this so it doesnt redo the same task in every frame, only if changes are made
Parameters:
-
cameras
Array[optional] an array of cameras in case we want to force some viewpoint
configure
-
scene_info
Configure the Scene using an object (the object can be obtained from the function serialize) Inserts the nodes, configure them, and change the parameters ATTENTION: Destroys all previously existing info
Parameters:
-
scene_info
Objectthe object containing all the info about the nodes and config of the scene
createAnimation
()
LS.Animation
Creates and returns an scene animation track
Returns:
the animation track
filterNodes
-
filter
retrieves a node array filtered by the filter function
Parameters:
-
filter
Functiona callback function that receives every node and must return true or false
Returns:
array containing the nodes that passes the filter
findComponentByUId
-
uid
searches the component with this uid, it iterates through all the nodes and components (slow)
Parameters:
-
uid
Stringuid of the node
Returns:
component or null
findMaterialByUId
-
uid
searches the material with this uid, it iterates through all the nodes (slow)
Parameters:
-
uid
Stringuid of the material
Returns:
Material or null
findNodeComponents
-
type
returns an array with all the components in the scene and scenenodes that matches this class
Parameters:
-
type
String | | Componentthe type of the components to search (could be a string with the name or the class itself)
Returns:
array with the components found
finish
-
dt
stop the scene (triggers an "finish" event)
Parameters:
-
dt
Numberdelta time
generateUniqueNodeName
-
prefix
generate a unique node name given a prefix
Parameters:
-
prefix
Stringthe prefix, if not given then "node" is used
Returns:
a node name that it is not in the scene
getActiveCameras
-
force
Returns an array with all the cameras enabled in the scene
Parameters:
-
force
Boolean[optional] if you want to collect the cameras again, otherwise it returns the last ones collected
Returns:
cameras
getActiveLights
-
force
Returns an array with all the lights enabled in the scene
Parameters:
-
force
Boolean[optional] if you want to collect the lights again, otherwise it returns the last ones collected
Returns:
lights
getAllCameras
()
Array
Returns an array with all the cameras in the scene (even if they are disabled)
Returns:
cameras
getLayerNames
-
layers
returns an array with the name of all the layers given a layers mask
Parameters:
-
layers
Numbera number with the enabled layers in bit mask format, if ommited all layers are returned
Returns:
array of strings with the layer names
getNode
-
name
retrieves a Node based on the name, path ( name|childname|etc ) or uid
Parameters:
-
name
Stringnode name to search
Returns:
the node or null if it didnt find it
getNodeByIndex
-
node
retrieves a Node by its index
Parameters:
-
node
Numberindex
Returns:
returns the node at the 'index' position in the nodes array
getNodeByName
-
name
retrieves a Node that matches that name. It is fast because they are stored in an object. If more than one object has the same name, the first one added to the tree is returned
Parameters:
-
name
Stringname of the node
Returns:
the node or null if it didnt find it
getNodeByUId
-
uid
retrieves a Node based on a given uid. It is fast because they are stored in an object
Parameters:
-
uid
Stringuid of the node
Returns:
the node or null if it didnt find it
getNodes
-
recompute
Returns the array containing all the nodes in the scene
Parameters:
-
recompute
Bool[optional] in case you want to rearrange the nodes
Returns:
array containing every SceneNode in the scene
getPropertyInfo
-
locator
Returns information of a node component property based on the locator of that property Locators are in the form of "{NODE_UID}/{COMPONENT_UID}/{property_name}"
Parameters:
-
locator
Stringlocator of the property
Returns:
object with node, component, name, and value
getPropertyInfoFromPath
-
path
Returns information of a node component property based on the locator of that property Locators are in the form of "{NODE_UID}/{COMPONENT_UID}/{property_name}"
Parameters:
-
path
Array
Returns:
object with node, component, name, and value
getPropertyValue
-
locator
-
value
-
root
Assigns a value to the property of a component in a node based on the locator of that property Locators are in the form of "{NODE_UID}/{COMPONENT_UID}/{property_name}"
Parameters:
-
locator
Stringlocator of the property
-
value
the value to assign
-
root
SceneNode[Optional] if you want to limit the locator to search inside a node
Returns:
the target where the action was performed
getResources
-
resources
-
as_array
-
skip_in_pack
-
skip_local
Returns the resources used by the scene includes the nodes, components, preloads and global_scripts doesn't include external_scripts
Parameters:
-
resources
Object[optional] object with resources
-
as_array
Boolean[optional] returns data in array format instead of object format
-
skip_in_pack
Boolean[optional] skips resources that come from a pack
-
skip_local
Boolean[optional] skips resources whose name starts with ":" (considered local resources)
Returns:
the resources in object format (or if as_array is true, then an array)
getTime
()
Number
returns current scene time (remember that scene time remains freezed if the scene is not playing)
Returns:
scene time in seconds
init
()
Boolean
This initializes the content of the scene. Call it to clear the scene content
Returns:
Returns true on success
instantiate
-
prefab_url
-
position
-
rotation
-
parent
Allows to instantiate a prefab from the fullpath of the resource
Parameters:
-
prefab_url
Stringthe filename to the resource containing the prefab
-
position
Vec3where to instantiate
-
rotation
Quatthe orientation
-
parent
SceneNode[optional] if no parent then scene.root will be used
Returns:
the resulting prefab node
load
-
url
-
[on_complete=null]
-
[on_error=null]
-
[on_progress=null]
-
[on_resources_loaded=null]
Loads a scene from a relative url pointing to a JSON description (or WBIN,ZIP) Warning: this url is not passed through the LS.ResourcesManager so the url is absolute
Parameters:
-
url
Stringwhere the JSON object containing the scene is stored
-
[on_complete=null]
Function optionalthe callback to call when the loading is complete
-
[on_error=null]
Function optionalthe callback to call if there is a loading error
-
[on_progress=null]
Function optionalit is called while loading the scene info (not the associated resources)
-
[on_resources_loaded=null]
Function optionalit is called when all the resources had been loaded
loadFromResources
-
url
-
[on_complete=null]
-
[on_error=null]
-
[on_progress=null]
-
[on_resources_loaded=null]
Loads a scene from a relative url pointing to a JSON description (or WBIN,ZIP) It uses the resources folder as the root folder (in comparison with the regular load function)
Parameters:
-
url
Stringwhere the JSON object containing the scene is stored
-
[on_complete=null]
Function optionalthe callback to call when the loading is complete
-
[on_error=null]
Function optionalthe callback to call if there is a loading error
-
[on_progress=null]
Function optionalit is called while loading the scene info (not the associated resources)
-
[on_resources_loaded=null]
Function optionalit is called when all the resources had been loaded
loadResources
-
on_complete
Loads all the resources of all the nodes in this scene it sends a signal to every node to get all the resources info and load them in bulk using the ResourceManager
Parameters:
-
on_complete
Functioncalled when the load of all the resources is complete
pause
()
pauses the scene (triggers an "pause" event)
recomputeNodesArray
()
all nodes are stored in an array, this function recomputes the array so they are in the right order in case one has changed order
removePreloadResource
-
fullpath
Remove a resource from the list of resources to preload
Parameters:
-
fullpath
Stringthe name of the resource
render
()
renders the scene using the assigned renderer
requestFrame
()
Marks that this scene must be rendered again
Scene.getScriptsList
-
scene
-
allow_local
-
full_paths
Static method, returns a list of all the scripts that must be loaded, in order and with the full path
Parameters:
-
scene
Scene | Objectthe object containing info about the scripts (could be a scene or a JSON object)
-
allow_local
Booleanif we allow local resources
-
full_paths
Booleanif true it will return the full path to every resource
serialize
()
Object
Creates and object containing all the info about the scene and nodes. The oposite of configure. It calls the serialize method in every node
Returns:
return a JS Object with all the scene info
setFromJSON
-
data
-
[on_complete=null]
-
[on_error=null]
-
[on_progress=null]
-
[on_resources_loaded=null]
-
[on_scripts_loaded=null]
Assigns a scene from a JSON description (or WBIN,ZIP)
Parameters:
-
data
StringJSON object containing the scene
-
[on_complete=null]
Function optionalthe callback to call when the scene is ready
-
[on_error=null]
Function optionalthe callback to call if there is a loading error
-
[on_progress=null]
Function optionalit is called while loading the scene info (not the associated resources)
-
[on_resources_loaded=null]
Function optionalit is called when all the resources had been loaded
-
[on_scripts_loaded=null]
Function optionalthe callback to call when the loading is complete but before assigning the scene
setPropertyValue
-
locator
-
value
-
root
Assigns a value to the property of a component in a node based on the locator of that property Locators are in the form of "{NODE_UID}/{COMPONENT_UID}/{property_name}"
Parameters:
-
locator
Stringlocator of the property
-
value
the value to assign
-
root
SceneNode[Optional] if you want to limit the locator to search inside a node
Returns:
the target where the action was performed
setPropertyValueFromPath
-
path
-
value
-
root_node
-
offset
Assigns a value to the property of a component in a node based on the locator that property Locators are in the form of "{NODE_UID}/{COMPONENT_UID}/{property_name}"
Parameters:
-
path
Arraya property locator split by "/"
-
value
the value to assign
-
root_node
SceneNode[optional] the root node where you want to search the locator (this is to limit the locator to a branch of the scene tree)
-
offset
Number[optional] used to avoir generating garbage, instead of slicing the array every time, we pass the array index
Returns:
the target where the action was performed
start
-
dt
start the scene (triggers an "start" event)
Parameters:
-
dt
Numberdelta time
toPack
-
fullpath
-
resources
returns a pack containing all the scene and resources, used to save a scene to harddrive
Parameters:
-
fullpath
Stringa given fullpath name, it will be assigned to the scene with the appropiate extension
-
resources
Array[optional] array with all the resources to add, if no array is given it will get the active resources in this scene
Returns:
the pack
triggerInNodes
-
event_type
-
data
triggers an event to all nodes in the scene this is slow if the scene has too many nodes, thats why we use bindings
Parameters:
-
event_type
Stringevent type name
-
data
Objectdata to send associated to the event
unpause
()
unpauses the scene (triggers an "unpause" event)
update
-
dt
updates the scene (it handles variable update and fixedUpdate)
Parameters:
-
dt
Numberdelta time in seconds
Events
afterUpdate
Fired after updating the scene
beforeLoad
Fired before loading scene
change
Fired when something changes in the scene
Event Payload:
-
scene_info
Objectcontains all the info to do the configuration
clear
Fired when the whole scene is cleared
configure
Fired after the scene has been configured
Event Payload:
-
scene_info
Objectcontains all the info to do the configuration
fixedUpdate
Fired while updating but using a fixed timestep (1/60)
Event Payload:
-
dt
Number
load
Fired when the scene has been loaded but before the resources
loadCompleted
Fired after all resources have been loaded
serialize
Fired after the scene has been serialized to an object
Event Payload:
-
object
Objectto store the persistent info
update
Fired while updating
Event Payload:
-
dt
Number