Object3D

This is the base class for most objects in Verge3D and provides a set of properties and methods for manipulating objects in 3D space.

Note that this can be used for grouping objects via the .add(object) method which adds the object as a child, however it is better to use Group for this.

Constructor

Object3D()

The constructor takes no arguments.

Properties

.animations : Array

Array with object's animation clips.

.castShadow : Boolean

Whether the object gets rendered into shadow map. Default is false.

.children : Array

Array with object's children. See Group for info on manually grouping objects.

.constraints : Array

Array with object's constraints.

.customDepthMaterial : Material

Custom depth material to be used when rendering to the depth map. Can only be used in context of meshes. When shadow-casting with a DirectionalLight or SpotLight, if you are modifying vertex positions in the vertex shader you must specify a customDepthMaterial for proper shadows. Default is undefined.

.customDistanceMaterial : Material

Same as customDepthMaterial, but used with PointLight. Default is undefined.

.disableChildRendering : Boolean

Object children won't be rendered if true. Default is false.

.frustumCulled : Boolean

When this is set, it checks every frame if the object is in the frustum of the camera before rendering the object. If set to false the object gets rendered every frame even if it is not in the frustum of the camera. Default is true.

.hidpiCompositing : Boolean

Whether the object will be rendered using the special HiDPI compositing pass. Default is false.

.id : Integer

readonly – Unique number for this object instance.

.isObject3D : Boolean

Read-only flag to check if a given object is of type Object3D.

.groupNames : Array

An array specifying groups this object belongs to. Used for grouping/referencing collections of objects.

.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. This property can also be used to filter out unwanted objects in ray-intersection tests when using Raycaster.

.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 is Object3D.DefaultMatrixAutoUpdate (true).

.matrixWorld : Matrix4

The global transform of the object. If the Object3D has no parent, then it's identical to the local transform .matrix.

.matrixWorldAutoUpdate : Boolean

Default is true. If set, then the renderer checks every frame if the object and its children need matrix updates. When it isn't, then you have to maintain all matrices in the object and its children yourself.

.matrixWorldNeedsUpdate : Boolean

When this is set, it calculates the matrixWorld in that frame and resets this property to false. Default is false.

.modelViewMatrix : Matrix4

This is passed to the shader and used to calculate the position of the object.

.name : String

Optional name of the object (doesn't need to be unique). Default is an empty string.

.normalMatrix : Matrix3

This is passed to the shader and used to calculate lighting for the object. It is the transpose of the inverse of the upper left 3x3 sub-matrix of this object's modelViewMatrix.

The reason for this special matrix is that simply using the modelViewMatrix could result in a non-unit length of normals (on scaling) or in a non-perpendicular direction (on non-uniform scaling).

On the other hand the translation part of the modelViewMatrix is not relevant for the calculation of normals. Thus a Matrix3 is sufficient.

.objectAlpha : Float

Object alpha. Used to define the corresponding output in the Blender's object info node.

.objectColor : Color

Object color. Used to define the corresponding output in the Blender's object info node.

.objectIndex : Integer

Object index. Used to define the corresponding output in the Blender's object info node.

.onAfterRender : Function

An optional callback that is executed immediately after a 3D object is rendered. This function is called with the following parameters: renderer, scene, camera, geometry, material, group.

Please notice that this callback is only executed for renderable 3D objects. Meaning 3D objects which define their visual appearance with geometries and materials like instances of Mesh, Line, Points or Sprite. Instances of Object3D, Group or Bone are not renderable and thus this callback is not executed for such objects.

.onBeforeRender : Function

An optional callback that is executed immediately before a 3D object is rendered. This function is called with the following parameters: renderer, scene, camera, geometry, material, group.

Please notice that this callback is only executed for renderable 3D objects. Meaning 3D objects which define their visual appearance with geometries and materials like instances of Mesh, Line, Points or Sprite. Instances of Object3D, Group or Bone are not renderable and thus this callback is not executed for such objects.

.parent : Object3D

Object's parent in the scene graph. An object can have at most one parent.

.position : Vector3

A Vector3 representing the object's local position. Default is (0, 0, 0).

.quaternion : Quaternion

Object's local rotation as a Quaternion.

.receiveShadow : Boolean

Whether the material receives shadows. Default is false.

.renderOrder : Float

This value allows the default rendering order of scene graph objects to be overridden although opaque and transparent objects remain sorted independently. When this property is set for an instance of Group, all descendants objects will be sorted and rendered together. Sorting is from lowest to highest renderOrder. Default value is 0.

.rotation : Euler

Object's local rotation (see Euler angles), in radians.

.scale : Vector3

The object's local scale. Default is Vector3(1, 1, 1).

.up : Vector3

This is used by the lookAt method, for example, to determine the orientation of the result.
Default is Object3D.DefaultUp — that is, (0, 1, 0).

.userData : Object

An object that can be used to store custom data about the Object3D. It should not hold references to functions as these will not be cloned.

.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 is true.

Static Properties

Static properties and methods are defined per class rather than per instance of that class. This means that changing Object3D.DefaultUp or Object3D.DefaultMatrixAutoUpdate will change the values of up and matrixAutoUpdate for every instance of Object3D (or derived classes) created after the change has been made (already created Object3Ds will not be affected).

.DefaultUp : Vector3

The default up direction for objects, also used as the default position for DirectionalLight, HemisphereLight and Spotlight (which creates lights shining from the top down).
Set to (0, 1, 0) by default.

.DefaultMatrixAutoUpdate : Boolean

The default setting for matrixAutoUpdate for newly created Object3Ds.

Methods

EventDispatcher methods are available on this class.

.add(object : Object3D, ...) → this

Adds object as child of this object. An arbitrary number of objects may be added. Any current parent on an object passed in here will be removed, since an object can have at most one parent.

See Group for info on manually grouping objects.

.applyMatrix4(matrix : Matrix4)

Applies the matrix transform to the object and updates the object's position, rotation and scale.

.applyQuaternion(quaternion : Quaternion) → this

Applies the rotation represented by the quaternion to the object.

.attach(object : Object3D) → this

Adds object as a child of this, while maintaining the object's world transform.

This method does not support scene graphs having non-uniformly-scaled nodes(s).

.clone(recursive : Boolean) → Object3D

recursive — if true, descendants of the object are also cloned. Default is true.

Returns a clone of this object and optionally all descendants.

.copy(object : Object3D, recursive : Boolean) → this

recursive — if true, descendants of the object are also copied. Default is true.

Copy the given object into this object.

Note: event listeners and user-defined callbacks (.onAfterRender and .onBeforeRender) are not copied.

.getObjectById(id : Integer) → Object3D

id — Unique number of the object instance

Searches through an object and its children, starting with the object itself, and returns the first with a matching id. Note that ids are assigned in chronological order: 1, 2, 3, ..., incrementing by one for each new object.

.getObjectByName(name : String) → Object3D

name — String to match to the children's Object3D.name property.

Searches through an object and its children, starting with the object itself, and returns the first with a matching name. Note that for most objects the name is an empty string by default. You will have to set it manually to make use of this method.

.getObjectByProperty(name : String, value : Any) → Object3D

name — the property name to search for.
value — value of the given property.

Searches through an object and its children, starting with the object itself, and returns the first with a property that matches the value given.

.getObjectsByProperty(name : String, value : Any) → Object3D

name — the property name to search for.
value — value of the given property.

Searches through an object and its children, starting with the object itself, and returns all the objects with a property that matches the value given.

.getWorldPosition(target : Vector3) → Vector3

target — the result will be copied into this Vector3.

Returns a vector representing the position of the object in world space.

.getWorldQuaternion(target : Quaternion) → Quaternion

target — the result will be copied into this Quaternion.

Returns a quaternion representing the rotation of the object in world space.

.getWorldEuler(target : Euler, order : String) → Euler

target — the result will be copied into this Euler.
order — the rotation order in which target will be copied. Default is target._order.

Returns an euler representing the rotation of the object in world space.

.getWorldScale(target : Vector3) → Vector3

target — the result will be copied into this Vector3.

Returns a vector of the scaling factors applied to the object for each axis in world space.

.getWorldDirection(target : Vector3) → Vector3

target — the result will be copied into this Vector3.

Returns a vector representing the direction of object's positive z-axis in world space.

.localToWorld(vector : Vector3) → Vector3

vector — A vector representing a position in this object's local space.

Converts the vector from this object's local space to world space.

.lookAt(vector : Vector3)
.lookAt(x : Float, y : Float, z : Float)

vector - A vector representing a position in world space.
Optionally, the x, y and z components of the world space position.

Rotates the object to face a point in world space.

This method does not support objects having non-uniformly-scaled parent(s).

.raycast(raycaster : Raycaster, intersects : Array)

Abstract (empty) method to get intersections between a casted ray and this object. Subclasses such as Mesh, Line, and Points implement this method in order to use raycasting.

.remove(object : Object3D, ...) → this

Removes object as child of this object. An arbitrary number of objects may be removed.

.removeFromParent() → this

Removes this object from its current parent.

.clear() → this

Removes all child objects.

.rotateOnAxis(axis : Vector3, angle : Float) → this

axis — A normalized vector in object space.
angle — The angle in radians.

Rotate an object along an axis in object space. The axis is assumed to be normalized.

.rotateOnWorldAxis(axis : Vector3, angle : Float) → this

axis — A normalized vector in world space.
angle — The angle in radians.

Rotate an object along an axis in world space. The axis is assumed to be normalized. Method Assumes no rotated parent.

.rotateX(rad : Float) → this

rad — the angle to rotate in radians.

Rotates the object around x axis in local space.

.rotateY(rad : Float) → this

rad — the angle to rotate in radians.

Rotates the object around y axis in local space.

.rotateZ(rad : Float) → this

rad — the angle to rotate in radians.

Rotates the object around z axis in local space.

.setRotationFromAxisAngle(axis : Vector3, angle : Float)

axis — A normalized vector in object space.
angle — angle in radians

Calls setFromAxisAngle(axis, angle) on the .quaternion.

.setRotationFromEuler(euler : Euler)

euler — Euler angle specifying rotation amount.

Calls setRotationFromEuler(euler) on the .quaternion.

.setRotationFromMatrix(m : Matrix4)

m — rotate the quaternion by the rotation component of the matrix.

Calls setFromRotationMatrix(m) on the .quaternion.

Note that this assumes that the upper 3x3 of m is a pure rotation matrix (i.e, unscaled).

.setRotationFromQuaternion(q : Quaternion)

q — normalized Quaternion.

Copy the given quaternion into .quaternion.

.translateOnAxis(axis : Vector3, distance : Float) → this

axis — A normalized vector in object space.
distance — The distance to translate.

Translate an object by distance along an axis in object space. The axis is assumed to be normalized.

.translateX(distance : Float) → this

Translates object along x axis in object space by distance units.

.translateY(distance : Float) → this

Translates object along y axis in object space by distance units.

.translateZ(distance : Float) → this

Translates object along z axis in object space by distance units.

.traverse(callback : Function)

callback — A function with as first argument an object3D object.

Executes the callback on this object and all descendants.
Note: Modifying the scene graph inside the callback is discouraged.

.traverseVisible(callback : Function)

callback — A function with as first argument an object3D object.

Like traverse, but the callback will only be executed for visible objects. Descendants of invisible objects are not traversed.
Note: Modifying the scene graph inside the callback is discouraged.

.traverseAncestors(callback : Function)

callback — A function with as first argument an object3D object.

Executes the callback on all ancestors.
Note: Modifying the scene graph inside the callback is discouraged.

.updateMatrix()

Updates the local transform.

.updateMatrixWorld(force : Boolean)

force — A boolean that can be used to bypass .matrixWorldAutoUpdate, to recalculate the world matrix of the object and descendants on the current frame. Useful if you cannot wait for the renderer to update it on the next frame (assuming .matrixWorldAutoUpdate set to true).

Updates the global transform of the object and its descendants if the world matrix needs update (.matrixWorldNeedsUpdate set to true) or if the force parameter is set to true.

.updateWorldMatrix(updateParents : Boolean, updateChildren : Boolean)

updateParents — recursively updates global transform of ancestors.
updateChildren — recursively updates global transform of descendants.

Updates the global transform of the object.

.worldToLocal(vector : Vector3) → Vector3

vector — A vector representing a position in world space.

Converts the vector from world space to this object's local space.

Puzzles

There are numerous object puzzles which simplify working with 3D objects.

Source

For more info on how to obtain the source code of this module see this page.