API Docs for:
Show:

LS.SceneTree Class

Defined in: ../src/scene.js:1
Module: LS

The SceneTree contains all the info about the Scene and nodes

Constructor

LS.SceneTree

()

Defined in ../src/scene.js:1

Methods

addPreloadResource

(
  • fullpath
)

Adds a resource that must be loaded when the scene is loaded

Parameters:

  • fullpath String

    the name of the resource

clear

()

Defined in ../src/scene.js:170

Clears the scene using the init function and trigger a "clear" LEvent

collectData

()

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

configure

(
  • scene_info
)

Defined in ../src/scene.js:196

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 Object

    the object containing all the info about the nodes and config of the scene

createAnimation

() LS.Animation

Creates and returns an scene animation track

Returns:

LS.Animation:

the animation track

filterNodes

(
  • filter
)
Array

Defined in ../src/scene.js:946

retrieves a node array filtered by the filter function

Parameters:

  • filter Function

    a callback function that receives every node and must return true or false

Returns:

Array:

array containing the nodes that passes the filter

findComponentByUId

(
  • uid
)
Object

Defined in ../src/scene.js:962

searches the component with this uid, it iterates through all the nodes and components (slow)

Parameters:

  • uid String

    uid of the node

Returns:

Object:

component or null

findMaterialByUId

(
  • uid
)
Object

Defined in ../src/scene.js:980

searches the material with this uid, it iterates through all the nodes (slow)

Parameters:

  • uid String

    uid of the material

Returns:

Object:

Material or null

findNodeComponents

(
  • type
)
Array

returns an array with all the components in the scene and scenenodes that matches this class

Parameters:

  • type String | | Component

    the type of the components to search (could be a string with the name or the class itself)

Returns:

Array:

array with the components found

finish

(
  • dt
)

stop the scene (triggers an "finish" event)

Parameters:

  • dt Number

    delta time

generateUniqueNodeName

(
  • prefix
)
String

generate a unique node name given a prefix

Parameters:

  • prefix String

    the prefix, if not given then "node" is used

Returns:

String:

a node name that it is not in the scene

getActiveCameras

(
  • force
)
Array

Defined in ../src/scene.js:703

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:

Array:

cameras

getActiveLights

(
  • force
)
Array

Defined in ../src/scene.js:741

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:

Array:

lights

getAllCameras

() Array

Defined in ../src/scene.js:717

Returns an array with all the cameras in the scene (even if they are disabled)

Returns:

Array:

cameras

getLayerNames

(
  • layers
)
Array

returns an array with the name of all the layers given a layers mask

Parameters:

  • layers Number

    a number with the enabled layers in bit mask format, if ommited all layers are returned

Returns:

Array:

array of strings with the layer names

getNode

(
  • name
)
Object

Defined in ../src/scene.js:877

retrieves a Node based on the name, path ( name|childname|etc ) or uid

Parameters:

  • name String

    node name to search

Returns:

Object:

the node or null if it didnt find it

getNodeByIndex

(
  • node
)
Object

Defined in ../src/scene.js:931

retrieves a Node by its index

Parameters:

  • node Number

    index

Returns:

Object:

returns the node at the 'index' position in the nodes array

getNodeByName

(
  • name
)
Object

Defined in ../src/scene.js:906

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 String

    name of the node

Returns:

Object:

the node or null if it didnt find it

getNodeByUId

(
  • uid
)
Object

Defined in ../src/scene.js:919

retrieves a Node based on a given uid. It is fast because they are stored in an object

Parameters:

  • uid String

    uid of the node

Returns:

Object:

the node or null if it didnt find it

getNodes

(
  • recompute
)
Array

Defined in ../src/scene.js:863

Returns the array containing all the nodes in the scene

Parameters:

  • recompute Bool

    [optional] in case you want to rearrange the nodes

Returns:

Array:

array containing every SceneNode in the scene

getPropertyInfo

(
  • locator
)
Object

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 String

    locator of the property

Returns:

Object:

object with node, component, name, and value

getPropertyInfoFromPath

(
  • path
)
Object

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:

object with node, component, name, and value

getPropertyValue

(
  • locator
  • value
  • root
)
Component

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 String

    locator of the property

  • value

    the value to assign

  • root SceneNode

    [Optional] if you want to limit the locator to search inside a node

Returns:

Component:

the target where the action was performed

getResources

(
  • resources
  • as_array
  • skip_in_pack
  • skip_local
)
Object | Array

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:

Object | Array:

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:

Number:

scene time in seconds

init

() Boolean

Defined in ../src/scene.js:114

This initializes the content of the scene. Call it to clear the scene content

Returns:

Boolean:

Returns true on success

instantiate

(
  • prefab_url
  • position
  • rotation
  • parent
)
SceneNode

Allows to instantiate a prefab from the fullpath of the resource

Parameters:

  • prefab_url String

    the filename to the resource containing the prefab

  • position Vec3

    where to instantiate

  • rotation Quat

    the orientation

  • parent SceneNode

    [optional] if no parent then scene.root will be used

Returns:

SceneNode:

the resulting prefab node

load

(
  • url
  • [on_complete=null]
  • [on_error=null]
  • [on_progress=null]
  • [on_resources_loaded=null]
)

Defined in ../src/scene.js:399

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 String

    where the JSON object containing the scene is stored

  • [on_complete=null] Function optional

    the callback to call when the loading is complete

  • [on_error=null] Function optional

    the callback to call if there is a loading error

  • [on_progress=null] Function optional

    it is called while loading the scene info (not the associated resources)

  • [on_resources_loaded=null] Function optional

    it is called when all the resources had been loaded

loadFromResources

(
  • url
  • [on_complete=null]
  • [on_error=null]
  • [on_progress=null]
  • [on_resources_loaded=null]
)

Defined in ../src/scene.js:509

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 String

    where the JSON object containing the scene is stored

  • [on_complete=null] Function optional

    the callback to call when the loading is complete

  • [on_error=null] Function optional

    the callback to call if there is a loading error

  • [on_progress=null] Function optional

    it is called while loading the scene info (not the associated resources)

  • [on_resources_loaded=null] Function optional

    it 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 Function

    called when the load of all the resources is complete

pause

()

pauses the scene (triggers an "pause" event)

recomputeNodesArray

()

Defined in ../src/scene.js:829

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 String

    the name of the resource

render

()

renders the scene using the assigned renderer

requestFrame

()

Marks that this scene must be rendered again

SceneTree.getScriptsList

(
  • scene
  • allow_local
  • full_paths
)

Defined in ../src/scene.js:528

Static method, returns a list of all the scripts that must be loaded, in order and with the full path

Parameters:

  • scene SceneTree | Object

    the object containing info about the scripts (could be a scene or a JSON object)

  • allow_local Boolean

    if we allow local resources

  • full_paths Boolean

    if true it will return the full path to every resource

serialize

() Object

Defined in ../src/scene.js:269

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:

Object:

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]
)

Defined in ../src/scene.js:317

Assigns a scene from a JSON description (or WBIN,ZIP)

Parameters:

  • data String

    JSON object containing the scene

  • [on_complete=null] Function optional

    the callback to call when the scene is ready

  • [on_error=null] Function optional

    the callback to call if there is a loading error

  • [on_progress=null] Function optional

    it is called while loading the scene info (not the associated resources)

  • [on_resources_loaded=null] Function optional

    it is called when all the resources had been loaded

  • [on_scripts_loaded=null] Function optional

    the callback to call when the loading is complete but before assigning the scene

setPropertyValue

(
  • locator
  • value
  • root
)
Component

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 String

    locator of the property

  • value

    the value to assign

  • root SceneNode

    [Optional] if you want to limit the locator to search inside a node

Returns:

Component:

the target where the action was performed

setPropertyValueFromPath

(
  • path
  • value
  • root_node
  • offset
)
Component

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 Array

    a 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:

Component:

the target where the action was performed

start

(
  • dt
)

start the scene (triggers an "start" event)

Parameters:

  • dt Number

    delta time

toPack

(
  • fullpath
  • resources
)
LS.Pack

returns a pack containing all the scene and resources, used to save a scene to harddrive

Parameters:

  • fullpath String

    a 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:

LS.Pack:

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 String

    event type name

  • data Object

    data to send associated to the event

unpause

()

unpauses the scene (triggers an "unpause" event)

Events

afterUpdate

Fired after updating the scene

beforeLoad

Defined in ../src/scene.js:430

Fired before loading scene

beforeUpdate

Fired before doing an update

Event Payload:

change

Defined in ../src/scene.js:261

Fired when something changes in the scene

Event Payload:

  • scene_info Object

    contains all the info to do the configuration

clear

Defined in ../src/scene.js:187

Fired when the whole scene is cleared

configure

Defined in ../src/scene.js:255

Fired after the scene has been configured

Event Payload:

  • scene_info Object

    contains all the info to do the configuration

finish

Fired when the scene stops playing

Event Payload:

init

Fired when the nodes need to be initialized

Event Payload:

load

Defined in ../src/scene.js:478

Fired when the scene has been loaded but before the resources

load

Defined in ../src/scene.js:366

Fired when the scene has been loaded but before the resources

loadCompleted

Defined in ../src/scene.js:383

Fired after all resources have been loaded

loadCompleted

Defined in ../src/scene.js:492

Fired after all resources have been loaded

nodeAdded

Defined in ../src/scene.js:791

Fired when a new node is added to this scene

Event Payload:

nodeRemoved

Defined in ../src/scene.js:818

Fired after a node has been removed

Event Payload:

pause

Fired when the scene pauses (mostly in the editor)

Event Payload:

serialize

Defined in ../src/scene.js:306

Fired after the scene has been serialized to an object

Event Payload:

  • object Object

    to store the persistent info

start

Fired when the scene is starting to play

Event Payload:

unpause

Fired when the scene unpauses (mostly in the editor)

Event Payload:

update

Fired while updating

Event Payload:

  • dt Number