new Context(gameScriptClass, object3D)
Handle collisions, add/remove gameobject3D, process commands + trigger ScriptBase
event
Name | Type | Description |
---|---|---|
gameScriptClass | Object.<string, ScriptBase> | map of class extended |
object3D | Object3D | root game object3D |
- Source
Members
collisions :Collisions
Collisions system https://www.npmjs.com/package/detect-collisions
- Collisions
- Source
collisionsBuffer :Object.<string, string>
Buffer to handle collision events Context.EVENT
- Object.<string, string>
- Source
commands :Map.<string, Array>
commands buffer
- Map.<string, Array>
- Source
dt :number
delta time
- number
- Source
gameScriptClass :Object.<string, ScriptBase>
class that can be reference by GameScript
of an object3D
- Object.<string, ScriptBase>
- Source
listeners :Object.<string, Array.<ContextListener>>
Listeners of custom events
- Object.<string, Array.<ContextListener>>
- Source
object3D :Object3D
root game object3D
- Source
(static) EVENT :Object.<string, string>
Events triggered by context to ScriptBase
- Object.<string, string>
- Source
Methods
addObject3D(obj, parentUUIDopt) → {Promise}
Add an object3D in context. If a parentUUID is specifed it will be add to its, root otherwise
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
obj | Object3D | object3D to add | ||
parentUUID | string | <optional> | null | uuid of parent object3D |
- Source
- 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
Name | Type | Description |
---|---|---|
id | string | id of the class |
object3D | Object3D | object3D that is going to use this instance |
modelVariables | object | custom variables associated to this instance |
- Source
- instance of the class bind with object3D and modelVariables
- Type:
- ScriptBase
dispatch(eventID, args)
Dispatch custom event to listeners
Name | Type | Description |
---|---|---|
eventID | string | Id of the event to dispatch |
args | Array | Params to passed to listeners |
- Source
dispatchScriptEvent(object3D, event, params, recursiveopt)
It will dispatch an event to all ScriptBase
in object3D
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
object3D | Object3D | object3D that you want to dispatch the event to. | ||
event | string | name of the event to dispatch see possible value in | ||
params | Array.<any> | params to pass to | ||
recursive | boolean | <optional> | true | traverse object3D child if true |
- Source
findGameScriptWithID(id, object3Dopt) → {ScriptBase|null}
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
id | string | id of script | ||
object3D | Object3D | <optional> | this.object3D | object3D to traverse to find the game script (default is the root game object3D) |
- Source
- first game script with id or null if none are found
- Type:
- ScriptBase |
null
initComponentControllers(obj)
Initialize controllers used in context
Name | Type | Description |
---|---|---|
obj | Object3D | object3D to initialize controllers |
- Source
load() → {Promise}
Load its object3D
- Source
- promise resolving at the end of the load
- Type:
- Promise
loadObject3D(obj) → {Promise}
Load an object3D into context
Name | Type | Description |
---|---|---|
obj | Object3D | object3D to load |
- Source
- promise resolving at the end of the load
- Type:
- Promise
on(eventID, cb)
Register a custom event
Name | Type | Description |
---|---|---|
eventID | string | Id of the event |
cb | function | Callback to be called when the event is dispatched |
- Source
onCommands(cmds)
Pass new commands to apply at the next step
Name | Type | Description |
---|---|---|
cmds | Array.<Command> | new commands to apply at the next step |
- Source
registerObject3DCollision(object3D)
Add a object3D into the collision system
Name | Type | Description |
---|---|---|
object3D | Object3D | object3D to register |
- Source
removeObject3D(uuid)
Remove a object3D of context
Name | Type | Description |
---|---|---|
uuid | string | uuid of the object3D to remove |
- Source
step(dt)
Step context
Name | Type | Description |
---|---|---|
dt | number | new delta time of step |
- Source
toState(full) → {State}
Convert context root object3D to State
and reset outdated attributes of all object3D
Name | Type | Default | Description |
---|---|---|---|
full | boolean | true | model of object3D with controllers should be export |
- Source
- current state of context
- Type:
- State
unregisterObject3DCollision(object3D)
Remove a GameObject from the collision system
Name | Type | Description |
---|---|---|
object3D | Object3D | object3D to remove |
- Source
updateCollision(object3D)
Update object3D collider controller + update collisions system
Name | Type | Description |
---|---|---|
object3D | Object3D | object3D to update |
- Source
updateCollisionBuffer()
Update the collision buffer
- Source