Context

new Context(gameScriptClass, object3D)

Handle collisions, add/remove gameobject3D, process commands + trigger ScriptBase event

Parameters:
NameTypeDescription
gameScriptClassObject.<string, ScriptBase>

map of class extended ScriptBase

object3DObject3D

root game object3D

Members

collisions :Collisions

Type:
  • Collisions

collisionsBuffer :Object.<string, string>

Buffer to handle collision events Context.EVENT

Type:
  • Object.<string, string>

commands :Map.<string, Array>

commands buffer

Type:
  • Map.<string, Array>

dt :number

delta time

Type:
  • number

gameScriptClass :Object.<string, ScriptBase>

class that can be reference by GameScript of an object3D

Type:

listeners :Object.<string, Array.<ContextListener>>

Listeners of custom events

Type:

object3D :Object3D

root game object3D

(static) EVENT :Object.<string, string>

Events triggered by context to ScriptBase

Type:
  • Object.<string, string>

Methods

addObject3D(obj, parentUUIDopt) → {Promise}

Add an object3D in context. If a parentUUID is specifed it will be add to its, root otherwise

Parameters:
NameTypeAttributesDefaultDescription
objObject3D

object3D to add

parentUUIDstring<optional>
null

uuid of parent object3D

Returns:
  • promise resolving when add
Type: 
Promise

createInstanceOf(id, object3D, modelVariables) → {ScriptBase}

Create a class instance of game script class for an object3D given an id

Parameters:
NameTypeDescription
idstring

id of the class

object3DObject3D

object3D that is going to use this instance

modelVariablesobject

custom variables associated to this instance

Returns:
  • instance of the class bind with object3D and modelVariables
Type: 
ScriptBase

dispatch(eventID, args)

Dispatch custom event to listeners

Parameters:
NameTypeDescription
eventIDstring

Id of the event to dispatch

argsArray

Params to passed to listeners

dispatchScriptEvent(object3D, event, params, recursiveopt)

It will dispatch an event to all ScriptBase in object3D

Parameters:
NameTypeAttributesDefaultDescription
object3DObject3D

object3D that you want to dispatch the event to.

eventstring

name of the event to dispatch see possible value in Context.EVENT

paramsArray.<any>

params to pass to ScriptBase

recursiveboolean<optional>
true

traverse object3D child if true

findGameScriptWithID(id, object3Dopt) → {ScriptBase|null}

Parameters:
NameTypeAttributesDefaultDescription
idstring

id of script

object3DObject3D<optional>
this.object3D

object3D to traverse to find the game script (default is the root game object3D)

Returns:
  • first game script with id or null if none are found
Type: 
ScriptBase | null

initComponentControllers(obj)

Initialize controllers used in context

Parameters:
NameTypeDescription
objObject3D

object3D to initialize controllers

load() → {Promise}

Load its object3D

Returns:
  • promise resolving at the end of the load
Type: 
Promise

loadObject3D(obj) → {Promise}

Load an object3D into context

Parameters:
NameTypeDescription
objObject3D

object3D to load

Returns:
  • promise resolving at the end of the load
Type: 
Promise

on(eventID, cb)

Register a custom event

Parameters:
NameTypeDescription
eventIDstring

Id of the event

cbfunction

Callback to be called when the event is dispatched

onCommands(cmds)

Pass new commands to apply at the next step

Parameters:
NameTypeDescription
cmdsArray.<Command>

new commands to apply at the next step

registerObject3DCollision(object3D)

Add a object3D into the collision system

Parameters:
NameTypeDescription
object3DObject3D

object3D to register

removeObject3D(uuid)

Remove a object3D of context

Parameters:
NameTypeDescription
uuidstring

uuid of the object3D to remove

step(dt)

Step context

Parameters:
NameTypeDescription
dtnumber

new delta time of step

toState(full) → {State}

Convert context root object3D to State and reset outdated attributes of all object3D

Parameters:
NameTypeDefaultDescription
fullbooleantrue

model of object3D with controllers should be export

Returns:
  • current state of context
Type: 
State

unregisterObject3DCollision(object3D)

Remove a GameObject from the collision system

Parameters:
NameTypeDescription
object3DObject3D

object3D to remove

updateCollision(object3D)

Update object3D collider controller + update collisions system

Parameters:
NameTypeDescription
object3DObject3D

object3D to update

updateCollisionBuffer()

Update the collision buffer