Capítulo 10 de 859

Chapter 10: Object3D

Core Idea

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.

Key Concepts

  • animations : Array.<AnimationClip>: An array holding the animation clips of the 3D object.
  • castShadow : boolean: When set to true, the 3D object gets rendered into shadow maps.
  • children : Array.<Object3D>: An array holding the child 3D objects of this instance.
  • customDepthMaterial : Material | undefined: 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 [Direct…
  • customDistanceMaterial : Material | undefined: Same as Object3D#customDepthMaterial, but used with PointLight.
  • frustumCulled : boolean: When set to true, the 3D object is honored by view frustum culling.
  • id : number (readonly): The ID of the 3D object.
  • isObject3D : boolean (readonly): This flag can be used for type testing.
  • layers : Layers: The layer membership of the 3D object. The 3D object is only visible if it has at least one layer in common with the camera in use. This pr…
  • matrix : Matrix4: Represents the object's transformation matrix in local space.

Reference Tables

Constructor

Signature
new Object3D()

Properties

PropertyDescription
.animations : Array.<AnimationClip>An array holding the animation clips of the 3D object.
.castShadow : booleanWhen set to true, the 3D object gets rendered into shadow maps.
.children : Array.<Object3D>An array holding the child 3D objects of this instance.
`.customDepthMaterial : Materialundefined`
`.customDistanceMaterial : Materialundefined`
.frustumCulled : booleanWhen set to true, the 3D object is honored by view frustum culling.
.id : number (readonly)The ID of the 3D object.
.isObject3D : boolean (readonly)This flag can be used for type testing.
.layers : LayersThe layer membership of the 3D object. The 3D 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 ra…
.matrix : Matrix4Represents the object's transformation matrix in local space.
.matrixAutoUpdate : booleanWhen set to true, the engine automatically computes the local matrix from position, rotation and scale every frame. If set to false, the app is responsible for recomputing the local matrix by cal…
.matrixWorld : Matrix4Represents the object's transformation matrix in world space. If the 3D object has no parent, then it's identical to the local transformation matrix
.matrixWorldAutoUpdate : booleanWhen set to true, the engine automatically computes the world matrix from the current local matrix and the object's transformation hierarchy. If set to false, the app is responsible for recomputi…
.matrixWorldNeedsUpdate : booleanWhen set to true, it calculates the world matrix in that frame and resets this property to false.
.modelViewMatrix : Matrix4Represents the object's model-view matrix.
.name : stringThe name of the 3D object.
.normalMatrix : Matrix3Represents the object's normal matrix.
.parent : Object3DA reference to the parent object.
.pivot : Vector3The pivot point for rotation and scale transformations. When set, rotation and scale are applied around this point instead of the object's origin.
.position : Vector3Represents the object's local position.
.quaternion : QuaternionRepresents the object's local rotation as Quaternions.
.receiveShadow : booleanWhen set to true, the 3D object is affected by shadows in the scene.
.renderOrder : numberThis 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…
.rotation : EulerRepresents the object's local rotation as Euler angles, in radians.
.scale : Vector3Represents the object's local scale.
.static : booleanWhether the 3D object is supposed to be static or not. If set to true, it means the 3D object is not going to be changed after the initial renderer. This includes geometry and material settings. A …
.type : string (readonly)The type property is used for detecting the object type in context of serialization/deserialization.
.up : Vector3Defines the up direction of the 3D object which influences the orientation via methods like Object3D#lookAt.
.userData : ObjectAn object that can be used to store custom data about the 3D object. It should not hold references to functions as these will not be cloned.
.uuid : string (readonly)The UUID of the 3D object.
.visible : booleanWhen set to true, the 3D object gets rendered.
.DEFAULT_MATRIX_AUTO_UPDATE : booleanThe default setting for Object3D#matrixAutoUpdate for newly created 3D objects.
.DEFAULT_MATRIX_WORLD_AUTO_UPDATE : booleanThe default setting for Object3D#matrixWorldAutoUpdate for newly created 3D objects.
.DEFAULT_UP : Vector3The default up direction for objects, also used as the default position for DirectionalLight and HemisphereLight.

Methods

MethodDescription
.add( object : Object3D ) : Object3DAdds the given 3D object as a child to this 3D 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 on…
.applyMatrix4( matrix : Matrix4 )Applies the given transformation matrix to the object and updates the object's position, rotation and scale.
.applyQuaternion( q : Quaternion ) : Object3DApplies a rotation represented by given the quaternion to the 3D object.
.attach( object : Object3D ) : Object3DAdds the given 3D object as a child of this 3D object, while maintaining the object's world transform. This method does not support scene graphs having non-uniformly-scaled nodes(s).
.clear() : Object3DRemoves all child objects.
.clone( recursive : boolean ) : Object3DReturns a new 3D object with copied values from this instance.
.copy( source : Object3D, recursive : boolean ) : Object3DCopies the values of the given 3D object to this instance.
`.getObjectById( id : number ) : Object3Dundefined`
`.getObjectByName( name : string ) : Object3Dundefined`
`.getObjectByProperty( name : string, value : any ) : Object3Dundefined`
.getObjectsByProperty( name : string, value : any, result : Array.<Object3D> ) : Array.<Object3D>Searches through the 3D object and its children, starting with the 3D object itself, and returns all 3D objects with a matching property value.
.getWorldDirection( target : Vector3 ) : Vector3Returns a vector representing the ("look") direction of the 3D object in world space.
.getWorldPosition( target : Vector3 ) : Vector3Returns a vector representing the position of the 3D object in world space.
.getWorldQuaternion( target : Quaternion ) : QuaternionReturns a Quaternion representing the position of the 3D object in world space.
.getWorldScale( target : Vector3 ) : Vector3Returns a vector representing the scale of the 3D object in world space.
.localToWorld( vector : Vector3 ) : Vector3Converts the given vector from this 3D object's local space to world space.
`.lookAt( x : numberVector3, y : number, z : number )`
`.onAfterRender( renderer : RendererWebGLRenderer, object : Object3D, camera : Camera, geometry : BufferGeometry, material : Material, group : Object )`
`.onAfterShadow( renderer : RendererWebGLRenderer, object : Object3D, camera : Camera, shadowCamera : Camera, geometry : BufferGeometry, depthMaterial : Material, group : Object )`
`.onBeforeRender( renderer : RendererWebGLRenderer, object : Object3D, camera : Camera, geometry : BufferGeometry, material : Material, group : Object )`
`.onBeforeShadow( renderer : RendererWebGLRenderer, object : Object3D, camera : Camera, shadowCamera : Camera, geometry : BufferGeometry, depthMaterial : Material, group : Object )`
.raycast( raycaster : Raycaster, intersects : Array.<Object> ) (abstract)Abstract method to get intersections between a casted ray and this 3D object. Renderable 3D objects such as Mesh, Line or Points implement this method in orde…
.remove( object : Object3D ) : Object3DRemoves the given 3D object as child from this 3D object. An arbitrary number of objects may be removed.
.removeFromParent() : Object3DRemoves this 3D object from its current parent.
.rotateOnAxis( axis : Vector3, angle : number ) : Object3DRotates the 3D object along an axis in local space.
.rotateOnWorldAxis( axis : Vector3, angle : number ) : Object3DRotates the 3D object along an axis in world space.
.rotateX( angle : number ) : Object3DRotates the 3D object around its X axis in local space.
.rotateY( angle : number ) : Object3DRotates the 3D object around its Y axis in local space.
.rotateZ( angle : number ) : Object3DRotates the 3D object around its Z axis in local space.
.setRotationFromAxisAngle( axis : Vector3, angle : number )Sets the given rotation represented as an axis/angle couple to the 3D object.
.setRotationFromEuler( euler : Euler )Sets the given rotation represented as Euler angles to the 3D object.
.setRotationFromMatrix( m : Matrix4 )Sets the given rotation represented as rotation matrix to the 3D object.
.setRotationFromQuaternion( q : Quaternion )Sets the given rotation represented as a Quaternion to the 3D object.
`.toJSON( meta : Objectstring ) : Object`
.translateOnAxis( axis : Vector3, distance : number ) : Object3DTranslate the 3D object by a distance along the given axis in local space.
.translateX( distance : number ) : Object3DTranslate the 3D object by a distance along its X-axis in local space.
.translateY( distance : number ) : Object3DTranslate the 3D object by a distance along its Y-axis in local space.
.translateZ( distance : number ) : Object3DTranslate the 3D object by a distance along its Z-axis in local space.
.traverse( callback : function )Executes the callback on this 3D object and all descendants.
.traverseAncestors( callback : function )Like Object3D#traverse, but the callback will only be executed for all ancestors.
.traverseVisible( callback : function )Like Object3D#traverse, but the callback will only be executed for visible 3D objects. Descendants of invisible 3D objects are not traversed.
.updateMatrix()Updates the transformation matrix in local space by computing it from the current position, rotation and scale values.
.updateMatrixWorld( force : boolean )Updates the transformation matrix in world space of this 3D objects and its descendants.
.updateWorldMatrix( updateParents : boolean, updateChildren : boolean, force : boolean )An alternative version of Object3D#updateMatrixWorld with more control over the update of ancestor and descendant nodes.
.worldToLocal( vector : Vector3 ) : Vector3Converts the given vector from this 3D object's world space to local space.

Key Takeaways

  1. Object3D extends: EventDispatcher
  2. Most relevant properties: animations, castShadow, children, customDepthMaterial.
  3. Key methods: add, applyMatrix4, applyQuaternion, attach.

Connects To