Object
Object
Scene graph object
Node in the scene graph or “entity”. Consists of transformation and a reference to its parent object. Usually holds components and is accessible by components through object.
Objects are stored in a data oriented manner inside WebAssembly memory. This class is a JavaScript API wrapper around this memory for more convenient use in components.
Objects can be created and added to a scene through addObject on the main scene.
Kind: global class
- Object
- new Object(o)
- .name ⇒ string
- .name
- .parent ⇒ Object
- .children ⇒ Array.<Object>
- .parent
- .transformLocal ⇒ Float32Array
- .transformLocal
- .transformWorld ⇒ Float32Array
- .transformWorld
- .scalingLocal ⇒ Float32Array
- .scalingLocal
- .scalingWorld ⇒ Float32Array
- .scalingWorld
- .rotationLocal ⇒ Array.<number>
- .rotationWorld ⇒ Array.<number>
- .rotationLocal
- .rotationWorld
- .active
- .changed ⇒ boolean
- .resetTransform()
- .resetTranslationRotation()
- .resetRotation()
- .resetTranslation()
- .resetScaling()
- .translate(v)
- .translateObject(v)
- .translateWorld(v)
- .rotateAxisAngleDeg(a, d)
- .rotateAxisAngleRad(a, d)
- .rotateAxisAngleDegObject(a, d)
- .rotateAxisAngleRadObject(a, d)
- .rotate(q)
- .rotateObject(q)
- .scale(v)
- .getTranslationLocal(out) ⇒ Array.<number>
- .getTranslationWorld(out) ⇒ Array.<number>
- .setTranslationLocal(v)
- .setTranslationWorld(v)
- .getForward(out) ⇒ Array.<number>
- .getUp(out) ⇒ Array.<number>
- .getRight(out) ⇒ Array.<number>
- .transformVectorWorld(out, v) ⇒ Array.<number>
- .transformVectorLocal(out, v) ⇒ Array.<number>
- .transformPointWorld(out, v) ⇒ Array.<number>
- .transformPointLocal(out, v) ⇒ Array.<number>
- .transformVectorInverseWorld(out, v) ⇒ Array.<number>
- .transformVectorInverseLocal(out, v) ⇒ Array.<number>
- .transformPointInverseWorld(out, v) ⇒ Array.<number>
- .transformPointInverseLocal(out, p) ⇒ Array.<number>
- .toWorldSpaceTransform(out, q) ⇒ Array.<number>
- .toLocalSpaceTransform(out, q) ⇒ Array.<number>
- .toObjectSpaceTransform(out, q) ⇒ Array.<number>
- .lookAt(v, up)
- .destroy()
- .setDirty()
- .getComponent(typeOrClass, index) ⇒ Component | CollisionComponent | TextComponent | ViewComponent | MeshComponent | InputComponent | LightComponent | AnimationComponent | PhysXComponent
- .getComponents(typeOrClass) ⇒ Array.<Component>
- .addComponent(typeOrClass, [params]) ⇒ Component | CollisionComponent | TextComponent | ViewComponent | MeshComponent | InputComponent | LightComponent | AnimationComponent | PhysXComponent
- .equals(otherObject) ⇒ boolean
new Object (o)
Param | Type | Description |
---|---|---|
o | number | Object id to wrap |
.name ⇒ string
Useful for identifying objects during debugging.
Kind: instance property of Object
Returns: string - Name of the object
.name
Set the object’s name
Kind: instance property of Object
Param | Type | Description |
---|---|---|
newName | string | String to the the object’s name to |
.parent ⇒ Object
Kind: instance property of Object
Returns: Object - Parent of this object or null if parented to root
.children ⇒ Array.<Object>
Kind: instance property of Object
Returns: Array.<Object> - Children of this object
.parent
Reparent object to given object.
Kind: instance property of Object
Note: Reparenting is not trivial and might have a noticeable performance impact
Param | Type | Description |
---|---|---|
newParent | Object | New parent or null to parent to root |
.transformLocal ⇒ Float32Array
Kind: instance property of Object
Returns: Float32Array - Local / object space transformation
.transformLocal
Set local transform.
Kind: instance property of Object
0.8.5+
Param | Type | Description |
---|---|---|
t | number | Local space transformation |
.transformWorld ⇒ Float32Array
May recompute transformations of the hierarchy of this object, if they were changed by JavaScript components this frame.
Kind: instance property of Object
Returns: Float32Array - Global / world space transformation
.transformWorld
Set world transform.
Kind: instance property of Object
0.8.5+
Param | Type | Description |
---|---|---|
t | number | Global / world space transformation |
.scalingLocal ⇒ Float32Array
Kind: instance property of Object
Returns: Float32Array - Local / object space scaling
.scalingLocal
Set scaling local
Kind: instance property of Object
0.8.7+
Param | Type | Description |
---|---|---|
t | Array.<number> | Global / world space transformation |
.scalingWorld ⇒ Float32Array
Kind: instance property of Object
Returns: Float32Array - Global / world space scaling
May recompute transformations of the hierarchy of this object,
if they were changed by JavaScript components this frame.
.scalingWorld
Set scaling world
Kind: instance property of Object
0.8.7+
Param | Type | Description |
---|---|---|
t | Array.<number> | Global / world space transformation |
.rotationLocal ⇒ Array.<number>
Kind: instance property of Object
Returns: Array.<number> - Local space rotation
0.8.7+
.rotationWorld ⇒ Array.<number>
Kind: instance property of Object
Returns: Array.<number> - Global / world space rotation
0.8.7+
.rotationLocal
Set rotation local
Kind: instance property of Object
0.8.7+
Param | Type | Description |
---|---|---|
r | number | Local space rotation |
.rotationWorld
Set rotation world
Kind: instance property of Object
0.8.7+
Param | Type | Description |
---|---|---|
r | number | Global / world space rotation |
.active
Disable/enable all components of this object
Kind: instance property of Object
0.8.5+
Param | Type | Description |
---|---|---|
b | boolean | New state for the components |
.changed ⇒ boolean
Kind: instance property of Object
Returns: boolean - Whether given object’s transformation has changed.
.resetTransform ()
Reset local transformation (translation, rotation and scaling) to identity
Kind: instance method of Object
.resetTranslationRotation ()
Reset local translation and rotation to identity
Kind: instance method of Object
.resetRotation ()
Reset local rotation, keep translation.
Kind: instance method of Object
Note: To reset both rotation and translation, prefer
resetTranslationRotation.
.resetTranslation ()
Reset local translation, keep rotation.
Kind: instance method of Object
Note: To reset both rotation and translation, prefer
resetTranslationRotation.
.resetScaling ()
Reset local scaling to identity ([1.0, 1.0, 1.0]
)
Kind: instance method of Object
.translate (v)
Translate object by a vector in the parent’s space
Kind: instance method of Object
Param | Type | Description |
---|---|---|
v | Array.<number> | Vector to translate by |
.translateObject (v)
Translate object by a vector in object space
Kind: instance method of Object
Param | Type | Description |
---|---|---|
v | Array.<number> | Vector to translate by |
.translateWorld (v)
Translate object by a vector in world space
Kind: instance method of Object
Param | Type | Description |
---|---|---|
v | Array.<number> | Vector to translate by |
.rotateAxisAngleDeg (a, d)
Rotate around given axis by given angle (degrees) in local space
Kind: instance method of Object
Note: If the object is translated the rotation will be around
the parent. To rotate around the object origin, use
rotateAxisAngleDegObject
See: rotateAxisAngleRad
Param | Type | Description |
---|---|---|
a | Array.<number> | Vector representing the rotation axis |
d | number | Angle in degrees |
.rotateAxisAngleRad (a, d)
Rotate around given axis by given angle (radians) in local space
Kind: instance method of Object
Note: If the object is translated the rotation will be around
the parent. To rotate around the object origin, use
rotateAxisAngleDegObject
See: rotateAxisAngleDeg
Param | Type | Description |
---|---|---|
a | Array.<number> | Vector representing the rotation axis |
d | number | Angle in degrees |
.rotateAxisAngleDegObject (a, d)
Rotate around given axis by given angle (degrees) in object space
Kind: instance method of Object
See: rotateAxisAngleRadObject
Param | Type | Description |
---|---|---|
a | Array.<number> | Vector representing the rotation axis |
d | number | Angle in degrees Equivalent to prepending a rotation quaternion to the object’s local transformation. |
.rotateAxisAngleRadObject (a, d)
Rotate around given axis by given angle (radians) in object space Equivalent to prepending a rotation quaternion to the object’s local transformation.
Kind: instance method of Object
See: rotateAxisAngleDegObject
Param | Type | Description |
---|---|---|
a | Array.<number> | Vector representing the rotation axis |
d | number | Angle in degrees |
.rotate (q)
Rotate by a quaternion
Kind: instance method of Object
Param | Type | Description |
---|---|---|
q | Array.<number> | the Quaternion to rotate by |
.rotateObject (q)
Rotate by a quaternion in object space
Equivalent to prepending a rotation quaternion to the object’s local transformation.
Kind: instance method of Object
Param | Type | Description |
---|---|---|
q | Array.<number> | the Quaternion to rotate by |
.scale (v)
Scale object by a vector in object space
Kind: instance method of Object
Param | Type | Description |
---|---|---|
v | Array.<number> | Vector to scale by |
.getTranslationLocal (out) ⇒ Array.<number>
Compute local / object space translation from transformation
Kind: instance method of Object
Returns: Array.<number> - out
Param | Type | Description |
---|---|---|
out | Array.<number> | Destination array/vector, expected to have at least 3 elements. |
.getTranslationWorld (out) ⇒ Array.<number>
Compute local / object space translation from transformation
May recompute transformations of the hierarchy of this object, if they were changed by JavaScript components this frame.
Kind: instance method of Object
Returns: Array.<number> - out
Param | Type | Description |
---|---|---|
out | Array.<number> | Destination array/vector, expected to have at least 3 elements. |
.setTranslationLocal (v)
Set local / object space translation
Concatenates a new translation dual quaternion onto the existing rotation.
Kind: instance method of Object
Param | Type | Description |
---|---|---|
v | Array.<number> | New local translation array/vector, expected to have at least 3 elements. |
.setTranslationWorld (v)
Set world space translation
Applies the inverse parent transform with a new translation dual quaternion which is concatenated onto the existing rotation.
Kind: instance method of Object
Param | Type | Description |
---|---|---|
v | Array.<number> | New world translation array/vector, expected to have at least 3 elements. |
.getForward (out) ⇒ Array.<number>
Compute the object’s forward facing world space vector
Kind: instance method of Object
Returns: Array.<number> - out
Param | Type | Description |
---|---|---|
out | Array.<number> | Destination array/vector, expected to have at least 3 elements. |
.getUp (out) ⇒ Array.<number>
Compute the object’s up facing world space vector
Kind: instance method of Object
Returns: Array.<number> - out
Param | Type | Description |
---|---|---|
out | Array.<number> | Destination array/vector, expected to have at least 3 elements. |
.getRight (out) ⇒ Array.<number>
Compute the object’s right facing world space vector
Kind: instance method of Object
Returns: Array.<number> - out
Param | Type | Description |
---|---|---|
out | Array.<number> | Destination array/vector, expected to have at least 3 elements. |
.transformVectorWorld (out, v) ⇒ Array.<number>
Transform a vector by this object’s world transform
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out point |
v | Array.<number> | Point to transform, default out |
.transformVectorLocal (out, v) ⇒ Array.<number>
Transform a vector by this object’s local transform
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out point |
v | Array.<number> | Point to transform, default out |
.transformPointWorld (out, v) ⇒ Array.<number>
Transform a point by this object’s world transform
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out point |
v | Array.<number> | Point to transform, default out |
.transformPointLocal (out, v) ⇒ Array.<number>
Transform a point by this object’s local transform
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out point |
v | Array.<number> | Point to transform, default out |
.transformVectorInverseWorld (out, v) ⇒ Array.<number>
Transform a vector by this object’s inverse world transform
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out point |
v | Array.<number> | Point to transform, default out |
.transformVectorInverseLocal (out, v) ⇒ Array.<number>
Transform a point by this object’s inverse local transform
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out point |
v | Array.<number> | Point to transform, default out |
.transformPointInverseWorld (out, v) ⇒ Array.<number>
Transform a point by this object’s inverse world transform
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out point |
v | Array.<number> | Point to transform, default out |
.transformPointInverseLocal (out, p) ⇒ Array.<number>
Transform a point by this object’s inverse local transform
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out point |
p | Array.<number> | Point to transform, default out |
.toWorldSpaceTransform (out, q) ⇒ Array.<number>
Transform a object space dual quaternion into world space
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out transformation |
q | Array.<number> | Local space transformation, default out |
.toLocalSpaceTransform (out, q) ⇒ Array.<number>
Transform a world space dual quaternion into local space
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out transformation |
q | Array.<number> | World space transformation, default out |
.toObjectSpaceTransform (out, q) ⇒ Array.<number>
Transform a world space dual quaternion into object space
Kind: instance method of Object
Returns: Array.<number> - out
0.8.7+
Param | Type | Description |
---|---|---|
out | Array.<number> | Out transformation |
q | Array.<number> | World space transformation, default out |
.lookAt (v, up)
Turn towards / look at target
Kind: instance method of Object
Param | Type | Description |
---|---|---|
v | Array.<number> | Target vector to turn towards |
up | Array.<number> | Up vector of this object, default [0, 1, 0] |
.destroy ()
Destroy the object with all of its components and remove it from the scene
Kind: instance method of Object
.setDirty ()
Mark transformation dirty
Causes an eventual recalculation of transformWorld, either on next getTranslationWorld, transformWorld or scalingWorld or the beginning of next frame, whichever happens first.
Kind: instance method of Object
.getComponent (typeOrClass, index) ⇒ Component | CollisionComponent | TextComponent | ViewComponent | MeshComponent | InputComponent | LightComponent | AnimationComponent | PhysXComponent
Get a component attached to this object
Kind: instance method of Object
Returns: Component | CollisionComponent | TextComponent | ViewComponent | MeshComponent | InputComponent | LightComponent | AnimationComponent | PhysXComponent - The component or null if there is no such component on this object
Param | Type | Default | Description |
---|---|---|---|
typeOrClass | string | function | Type name. It’s also possible to give a class definition. In this case, the method will use the class.TypeName field to find the component. | |
index | number | 0 | Index for component of given type. This can be used to access specific components if the object has multiple components of the same type. |
.getComponents (typeOrClass) ⇒ Array.<Component>
Kind: instance method of Object
Returns: Array.<Component> - All components of given type attached to this object
Note: As this function is non-trivial, avoid using it in update()
repeatedly,
but rather store its result in init()
or start()
Warning: This method will currently return at most 341 components.
Param | Type | Description |
---|---|---|
typeOrClass | string | function | Type name, pass a falsey value (undefined or null) to retrieve all. It’s also possible to give a class definition. In this case, the method will use the class.TypeName field to find the components. |
.addComponent (typeOrClass, [params]) ⇒ Component | CollisionComponent | TextComponent | ViewComponent | MeshComponent | InputComponent | LightComponent | AnimationComponent | PhysXComponent
Add component of given type to the object
You can use this function to clone components, see the example below.
Kind: instance method of Object
Returns: Component | CollisionComponent | TextComponent | ViewComponent | MeshComponent | InputComponent | LightComponent | AnimationComponent | PhysXComponent - The component or null if the type was not found
Param | Type | Description |
---|---|---|
typeOrClass | string | function | Typename to create a component of. Can be native or custom JavaScript component type. It’s also possible to give a class definition. In this case, the method will use the class.TypeName field. |
[params] | object | Parameters to initialize properties of the new component, can be another component to copy properties from. |
Example
.equals (otherObject) ⇒ boolean
Checks equality by comparing whether the wrapped native component ids and component manager types are equal.
Kind: instance method of Object
Returns: boolean - Whether this object equals the given object
Param | Type | Description |
---|---|---|
otherObject | Object | Object to check equality with |