Object3D Class
This is the base class for most objects in three.js and provides a set of properties and methods for manipulating objects in 3D space.
This page provides documentation for some of the main features of this class, the original documentation of this class can be found at https:// threejs.org/docs/index.html#Reference/Core/Object3D.
All nunuStudio objects extend the Object3D class of some other higher level class from three.js.
Item Index
Methods
- add
- addAbove
- addBellow
- applyMatrix
- clone
- contains
- copy
- destroy
- dispose
- getObjectByName
- getObjectByProperty
- getScene
- getWorldDirection
- getWorldPosition
- getWorldQuaternion
- getWorldScale
- initialize
- isEmpty
- localToWorld
- lookAt
- playAnimation
- remove
- removeAll
- resize
- rotateOnAxis
- rotateX
- rotateY
- rotateZ
- stopAnimation
- toJSON
- update
- worldToLocal
Methods
add
-
objects
Adds object as child of this object. An arbitrary number of objects may be added.
Parameters:
-
objects
Object3D
addAbove
-
object
-
index
Add object as children of this object above the indicated children
Parameters:
-
object
THREE.Object3D -
index
Number
addBellow
-
object
-
index
Add object as children of this object bellow the indicated children
Parameters:
-
object
THREE.Object3D -
index
Number
applyMatrix
-
matrix
This updates the position, rotation and scale with the matrix.
Parameters:
-
matrix
Matrix4
clone
-
recursive
Returns a clone of this object and optionaly all descendants.
Parameters:
-
recursive
BooleanIf true, descendants of the object are also cloned. Default is true.
contains
-
object
Check if this object contains a object.
Parameters:
-
object
THREE.Object3DObject to look for.
Returns:
True if this object contains the object.
copy
-
object
-
recursive
Copy the given object into this object.
Parameters:
-
object
Object3D -
recursive
BooleanIf true, descendants of the object are also copied. Default is true.
destroy
()
Destroy object, dispose and remove from its parent.
dispose
()
Disposes the object from memory.
Should be called when the object is no longer required to avoid memory leaks.
getObjectByName
-
name
Searches through the object's children and returns the first with a matching name.
Parameters:
-
name
StringString to match to the children's Object3D.name property.
getObjectByProperty
-
name
-
value
Searches through the object's children and returns the first with a property that matches the aclue given.
Parameters:
-
name
StringThe property name to search for.
-
value
ObjectValue of the given property.
getScene
()
THREE.Object3D
Get scene that contains this object.
Returns:
scene
getWorldDirection
-
optionalTarget
Returns a vector representing the direction of object's positive z-axis in world space.
Parameters:
-
optionalTarget
Vector3If specified, the result will be copied into this Vector3, otherwise a new Vector3 will be created.
getWorldPosition
-
optionalTarget
Parameters:
-
optionalTarget
Vector3Target to set the result. Otherwise, a new Vector3 is instantiated.
Returns:
Returns a vector representing the position of the object in world space.
getWorldQuaternion
-
optionalTarget
Returns a quaternion representing the rotation of the object in world space.
Parameters:
-
optionalTarget
QuaternionIf specified, the result will be copied into this Quaternion, otherwise a new Quaternion will be created.
getWorldScale
-
optionalTarget
Returns a vector of the scaling factors applied to the object for each axis in world space.
Parameters:
-
optionalTarget
Vector3If specified, the result will be copied into this Vector3, otherwise a new Vector3 will be created.
initialize
()
Initializes the object.
This method is calling one time on initialization.
isEmpty
()
Boolean
Check if object is empty (has no childrens).
Returns:
True is object is empty
localToWorld
-
vector
Converts the vector from local space to world space.
Parameters:
-
vector
Vector3vector representing a position in local (object) space.
lookAt
-
vector
Rotates the object to face a point in world space.
Parameters:
-
vector
Vector3A vector representing a position in world space.
playAnimation
()
Play animations attached to this object.
Animations rely on other objects, if some of these are missing the animation will have problems playing.
remove
-
objects
Remove children from this object
Parameters:
-
objects
Object3DRemoves object as child of this object. An arbitrary number of objects may be removed.
removeAll
()
Remove all children from the object.
resize
-
x
-
y
Resize this object, called everytime the window is resized.
Parameters:
-
x
NumberScreen width.
-
y
NumberScreen height.
rotateOnAxis
-
axis
-
angle
Rotate an object along an axis in object space. The axis is assumed to be normalized..
Parameters:
-
axis
Vector3A normalized vector in object space.
-
angle
NumberThe angle in radians.
rotateX
-
rad
Rotates the object around x axis in local space.
Parameters:
-
rad
NumberThe angle to rotate in radians.
rotateY
-
rad
Rotates the object around y axis in local space.
Parameters:
-
rad
NumberThe angle to rotate in radians.
rotateZ
-
rad
Rotates the object around z axis in local space.
Parameters:
-
rad
NumberThe angle to rotate in radians.
stopAnimation
()
Stop all animations playback.
toJSON
-
meta
-
resourceAccess
-
recursive
Serialize the object data to JSON. Should serialize all attributes and resources used by the object.
Parsing of the data serialized is performed using the ObjectLoader class.
The objects being serialized share a "meta" object where the resources can be stored to avoid repetition in the serialized data.
On the root object the meta object does not need to be initialized manually it is automatically created, to access resource the resourceAccess callback should be used.
Parameters:
-
meta
ObjectResource storage passed to all resources toJSON for self storage.
-
resourceAccess
FunctionCallback method used to access the resources receives (meta, object) as parameters, meta is the resource storage and object is the current serialized status of the object new attributes can be added here.
-
recursive
BooleanIf true the method will call toJSON for all available children and store the result in children attribute.
Returns:
json Output JSON will all data serialized, this can be stores in file or transfered to later be loaded using the ObjectLoader.
update
-
delta
Update the object state.
Called every time before rendering into the screen.
Parameters:
-
delta
NumberTime since last update call.
worldToLocal
-
vector
Updates the vector from world space to local space.
Parameters:
-
vector
Vector3A world vector
Properties
animations
Array
Array with the animations available in this object.
Each position contains an AnimationClip that has name, tracks, duration and uuid.
castShadow
Boolean
Whether the object gets rendered into shadow map.
Default: false
children
Array
Array with object's children.
folded
Boolean
Folded attribute is used only for editing, if true the object shows as folded in the object explorer.
frustumCulled
Boolean
When this is set, it checks every frame if the object is in the frustum of the camera before rendering the object. Otherwise the object gets renderered every frame even if it isn't visible.
Default: true
layers
Layers
The layer membership of the object. The object is only visible if it has at least one layer in common with the Camera in use.
locked
Boolean
Indicates if the object is locked. A locked object cannot be edited.
matrix
Matrix4
The local transform matrix
matrixAutoUpdate
Boolean
When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and also recalculates the matrixWorld property.
Default: true
matrixWorld
Matrix4
The global transform of the object. If the Object3D has no parent, then it's identical to the local transform.
name
String
Name of the object (doesn't need to be unique).
position
Vector3
The object's local position.
quaternion
Quaternion
Object's local rotation as a Quaternion.
receiveShadow
Boolean
Whether the material receives shadows.
Default: false
renderOrder
Number
This value allows the default rendering order of scene graph objects to be overridden although opaque and transparent objects remain sorted independently.
Default: 0
rotation
Euler
Object's local rotation (see Euler angles), in radians.
scale
Vector3
The object's local scale.
up
Vector3
This is used by the lookAt method, for example, to determine the orientation of the result.
userData
Object
Space reserved for user data, can be used for variables in runtime or can be used by scripts to store values on an object.
uuid
String
UUID of this object instance. This gets automatically assigned, so this shouldn't be edited.
visible
Boolean
Object gets rendered if true.
Default: true