Object3D

Base class for scene graph objects.

Constructor

Object3D()

The constructor takes no arguments.

Properties

[property:Integer id]

readonly Unique number for this object instance.

[property:String uuid]

[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] UUID of this object instance. This gets automatically assigned, so this shouldn't be edited.

[property:String name]

Optional name of the object (doesn't need to be unique).

[property:Object3D parent]

Object's parent in the scene graph.

[property:Object3D children]

Array with object's children.

[property:Vector3 position]

Object's local position.

[property:Euler rotation]

Object's local rotation, in radians.

[property:Vector3 scale]

Object's local scale.

[property:Vector3 up]

Up direction.

[property:Matrix4 matrix]

Local transform.

[property:Quaternion quaternion]

Object's local rotation as [page:Quaternion Quaternion].

[property:Boolean visible]

Object gets rendered if *true*.
default true

[property:Boolean castShadow]

Gets rendered into shadow map.
default false

[property:Boolean receiveShadow]

Material gets baked in shadow receiving.
default false

[property:Boolean frustumCulled]

When this is set, it checks every frame if the object is in the frustum of the camera. Otherwise the object gets drawn every frame even if it isn't visible.
default true

[property:Boolean matrixAutoUpdate]

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

[property:Boolean matrixWorldNeedsUpdate]

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

[property:Boolean rotationAutoUpdate]

When this is set, then the rotationMatrix gets calculated every frame.
default true

[property:object userData]

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.

[property:Matrix4 matrixWorld]

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

Methods

[page:EventDispatcher EventDispatcher] methods are available on this class.

[method:null applyMatrix]( [page:Matrix4 matrix])

matrix - matrix
.applyMatrix ( matrix) This updates the position, rotation and scale with the matrix.

[method:null translateX]( [page:Float distance] )

.translateX ( distance ) distance - Distance.
Translates object along x axis by distance.

[method:null translateY]( [page:Float distance] )

.translateY ( distance ) distance - Distance.
Translates object along y axis by distance.

[method:null translateZ]( [page:Float distance] )

.translateZ ( distance ) distance - Distance.
Translates object along z axis by distance.

[method:Vector3 localToWorld]( [page:Vector3 vector] )

.localToWorld ( vector ) vector - A local vector.
Updates the vector from local space to world space.

[method:Vector3 worldToLocal]( [page:Vector3 vector] )

.worldToLocal ( vector ) vector - A world vector.
Updates the vector from world space to local space.

[method:null lookAt]( [page:Vector3 vector] )

.lookAt ( vector ) vector - A world vector to look at.
Rotates object to face point in space.

[method:null add]( [page:Object3D object], ... )

object - An object.
.add ( object, ... ) Adds *object* as child of this object. An arbitrary number of objects may be added.

[method:null remove]( [page:Object3D object], ... )

object - An object.
.remove ( object, ... ) Removes *object* as child of this object. An arbitrary number of objects may be removed.

[method:null traverse]( [page:Function callback] )

.traverse ( callback ) callback - A function with as first argument an object3D object.
Executes the callback on this object and all descendants.

[method:null traverseVisible]( [page:Function callback] )

callback - A function with as first argument an object3D object.
.traverseVisible ( callback ) Like traverse, but the callback will only be executed for visible objects. Descendants of invisible objects are not traversed.

[method:null traverseAncestors]( [page:Function callback] )

.traverseAncestors ( callback ) callback - A function with as first argument an object3D object.
Executes the callback on this object and all ancestors.

[method:null updateMatrix]()

.updateMatrix () Updates local transform.

[method:null updateMatrixWorld]( [page:Boolean force] )

.updateMatrixWorld ( force ) Updates global transform of the object and its children.

[method:Object3D clone]()

.clone () Creates a new clone of this object and all descendants.

[method:Object3D getObjectByName]([page:String name])

.getObjectByName (name) name -- String to match to the children's Object3d.name property.
Searches through the object's children and returns the first with a matching name.

[method:Object3D getObjectById]([page:Integer id])

.getObjectById (id) id -- Unique number of the object instance
Searches through the object's children and returns the first with a matching id.

[method:Object3D translateOnAxis]([page:Vector3 axis], [page:Float distance])

axis -- A normalized vector in object space.
distance -- The distance to translate.
.translateOnAxis (axis, distance) Translate an object by distance along an axis in object space. The axis is assumed to be normalized.

[method:Object3D rotateOnAxis]([page:Vector3 axis], [page:Float angle])

.rotateOnAxis (axis, angle) 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.

[method:Array raycast]([page:Raycaster raycaster], [page:Array intersects])

.raycast (raycaster, intersects) Abstract method to get intersections between a casted ray and this object. Subclasses such as [page:Mesh], [page:Line], and [page:PointCloud] implement this method in order to participate in raycasting.

Geometry

Base class for geometries.
A geometry holds all data necessary to describe a 3D model.

Example

var geometry = new THREE.Geometry(); geometry.vertices.push( new THREE.Vector3( -10, 10, 0 ), new THREE.Vector3( -10, -10, 0 ), new THREE.Vector3( 10, -10, 0 ) ); geometry.faces.push( new THREE.Face3( 0, 1, 2 ) ); geometry.computeBoundingSphere();

Constructor

Geometry()

The constructor takes no arguments.

Properties

[property:Integer id]

Unique number for this geometry instance.

[property:String name]

Name for this geometry. Default is an empty string.

[property:Array vertices]

Array of [page:Vector3 vertices].
The array of vertices holds every position of points in the model.
To signal an update in this array, [page:Geometry Geometry.verticesNeedUpdate] needs to be set to true.

[property:Array colors]

Array of vertex [page:Color colors], matching number and order of vertices.
Used in [page:PointCloud] and [page:Line].
[page:Mesh Meshes] use per-face-use-of-vertex colors embedded directly in faces.
To signal an update in this array, [page:Geometry Geometry.colorsNeedUpdate] needs to be set to true.

[property:Array faces]

Array of [page:Face3 triangles].
The array of faces describe how each vertex in the model is connected with each other.
To signal an update in this array, [page:Geometry Geometry.elementsNeedUpdate] needs to be set to true.

[property:Array faceVertexUvs]

Array of face [page:UV] layers.
Each UV layer is an array of [page:UV]s matching the order and number of vertices in faces.
To signal an update in this array, [page:Geometry Geometry.uvsNeedUpdate] needs to be set to true.

[property:Array morphTargets]

Array of morph targets. Each morph target is a Javascript object: { name: "targetName", vertices: [ new THREE.Vector3(), ... ] } Morph vertices match number and order of primary vertices.

[property:Array morphColors]

Array of morph colors. Morph colors have similar structure as morph targets, each color set is a Javascript object: morphColor = { name: "colorName", colors: [ new THREE.Color(), ... ] } Morph colors can match either the number and order of faces (face colors) or the number of vertices (vertex colors).

[property:Array morphNormals]

Array of morph normals. Morph normals have similar structure as morph targets, each normal set is a Javascript object: morphNormal = { name: "NormalName", normals: [ new THREE.Vector3(), ... ] }

[property:Array skinWeights]

Array of skinning weights, matching number and order of vertices.

[property:Array skinIndices]

Array of skinning indices, matching number and order of vertices.

[property:Object boundingBox]

Bounding box. { min: new THREE.Vector3(), max: new THREE.Vector3() }

[property:Object boundingSphere]

Bounding sphere. { radius: float }

[property:Boolean hasTangents]

True if geometry has tangents. Set in [page:Geometry Geometry.computeTangents].

[property:Boolean dynamic]

Set to *true* if attribute buffers will need to change in runtime (using "dirty" flags).
Unless set to true internal typed arrays corresponding to buffers will be deleted once sent to GPU.
Defaults to true.

[property:Boolean verticesNeedUpdate]

Set to *true* if the vertices array has been updated.

[property:Boolean elementsNeedUpdate]

Set to *true* if the faces array has been updated.

[property:Boolean uvsNeedUpdate]

Set to *true* if the uvs array has been updated.

[property:Boolean normalsNeedUpdate]

Set to *true* if the normals array has been updated.

[property:Boolean tangentsNeedUpdate]

Set to *true* if the tangents in the faces has been updated.

[property:Boolean colorsNeedUpdate]

Set to *true* if the colors array has been updated.

[property:Boolean lineDistancesNeedUpdate]

Set to *true* if the linedistances array has been updated.

[property:array lineDistances]

An array containing distances between vertices for Line geometries. This is required for LinePieces/LineDashedMaterial to render correctly. Line distances can also be generated with computeLineDistances.

Methods

[page:EventDispatcher EventDispatcher] methods are available on this class.

[method:null applyMatrix]( [page:Matrix4 matrix] )

.applyMatrix ( matrix ) Bakes matrix transform directly into vertex coordinates.

[method:null computeFaceNormals]()

.computeFaceNormals () Computes face normals.

[method:null computeVertexNormals]()

.computeVertexNormals () Computes vertex normals by averaging face normals.
Face normals must be existing / computed beforehand.

[method:null computeMorphNormals]()

.computeMorphNormals () Computes morph normals.

[method:null computeTangents]()

.computeTangents () Computes vertex tangents.
Based on [link:http://www.terathon.com/code/tangent.html]
Geometry must have vertex [page:UV UVs] (layer 0 will be used).

[method:null computeBoundingBox]()

.computeBoundingBox () Computes bounding box of the geometry, updating [page:Geometry Geometry.boundingBox] attribute.

[method:null computeBoundingSphere]()

.computeBoundingSphere () Computes bounding sphere of the geometry, updating [page:Geometry Geometry.boundingSphere] attribute.
Neither bounding boxes or bounding spheres are computed by default. They need to be explicitly computed, otherwise they are *null*.

[method:null merge]( [page:Geometry geometry], [page:Matrix4 matrix], [page:Integer materialIndexOffset] )

.merge ( geometry, matrix, materialIndexOffset ) Merge two geometries or geometry and geometry from object (using object's transform)

[method:null mergeVertices]()

.mergeVertices () Checks for duplicate vertices using hashmap.
Duplicated vertices are removed and faces' vertices are updated.

[method:Geometry clone]()

.clone () Creates a new clone of the Geometry.

[method:null dispose]()

.dispose () Removes The object from memory.
Don't forget to call this method when you remove a geometry because it can cause memory leaks.

[method:null computeLineDistances]()

.computeLineDistances () Compute distances between vertices for Line geometries.

BufferGeometry

This class is an efficient alternative to [page:Geometry], because it stores all data, including vertex positions, face indices, normals, colors, UVs, and custom attributes within buffers; this reduces the cost of passing all this data to the GPU. This also makes BufferGeometry harder to work with than [page:Geometry]; rather than accessing position data as [page:Vector3] objects, color data as [page:Color] objects, and so on, you have to access the raw data from the appropriate [page:BufferAttribute attribute] buffer. This makes BufferGeometry best-suited for static objects where you don't need to manipulate the geometry much after instantiating it. This class is used to store builtin attributes such as vertex position, normals, color, etc., but can also be used in your code to store custom attributes in a [page:BufferGeometry].

Example

var geometry = new THREE.BufferGeometry(); // create a simple square shape. We duplicate the top left and bottom right // vertices because each vertex needs to appear once per triangle. var vertexPositions = [ [-1.0, -1.0, 1.0], [ 1.0, -1.0, 1.0], [ 1.0, 1.0, 1.0], [ 1.0, 1.0, 1.0], [-1.0, 1.0, 1.0], [-1.0, -1.0, 1.0] ]; var vertices = new Float32Array( vertexPositions.length * 3 ); // three components per vertex // components of the position vector for each vertex are stored // contiguously in the buffer. for ( var i = 0; i < vertexPositions.length; i++ ) { vertices[ i*3 + 0 ] = vertexPositions[i][0]; vertices[ i*3 + 1 ] = vertexPositions[i][1]; vertices[ i*3 + 2 ] = vertexPositions[i][2]; } // itemSize = 3 because there are 3 values (components) per vertex geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) ); var material = new THREE.MeshBasicMaterial( { color: 0xff0000 } ); var mesh = new THREE.Mesh( geometry, material );

More examples: [example:webgl_buffergeometry Complex mesh with non-indexed faces], [example:webgl_buffergeometry_uint Complex mesh with indexed faces], [example:webgl_buffergeometry_lines Lines], [example:webgl_buffergeometry_lines_indexed Indexed Lines], [example:webgl_buffergeometry_particles Particles], and [example:webgl_buffergeometry_rawshader Raw Shaders].

Accessing attributes

WebGL stores data associated with individual vertices of a geometry in attributes. Examples include the position of the vertex, the normal vector for the vertex, the vertex color,and so on. When using [page:Geometry], the [page:WebGLRenderer renderer] takes care of wrapping up this information into typed array buffers and sending this data to the shader. With BufferGeometry, all of this data is stored in buffers associated with an individual attributes. This means that to get the position data associated with a vertex (for instance), you must call [page:.getAttribute] to access the 'position' [page:BufferAttribute attribute], then access the individual x, y, and z coordinates of the position.

The following attributes are set by various members of this class:

[page:BufferAttribute position] (itemSize: 3)

Stores the x, y, and z coordinates of each vertex in this geometry. Set by [page:.fromGeometry]().

[page:BufferAttribute normal] (itemSize: 3)

Stores the x, y, and z components of the face or vertex normal vector of each vertex in this geometry. Set by [page:.fromGeometry]().

[page:BufferAttribute color] (itemSize: 3)

Stores the red, green, and blue channels of vertex color of each vertex in this geometry. Set by [page:.fromGeometry]().

[page:BufferAttribute tangent] (itemSize: 3)

Stores the x, y, and z components of the tangent vector of each vertex in this geometry. Set by [page:.computeTangents]().

[page:BufferAttribute index] (itemSize: 3)

Allows for vertices to be re-used across multiple triangles; this is called using "indexed triangles," and works much the same as it does in [page:Geometry]: each triangle is associated with the index of three vertices. This attribute therefore stores the index of each vertex for each triangular face. If this attribute is not set, the [page:WebGLRenderer renderer] assumes that each three contiguous positions represent a single triangle.

In addition to the the built-in attributes, you can set your own custom attributes using the addAttribute method. With [page:Geometry], these attributes are set and stored on the [page:Material]. In BufferGeometry, the attributes are stored with the geometry itself. Note that you still need to set the attributes information on the material as well, but the value of each attribute is stored in the BufferGeometry.

Constructor

BufferGeometry()

This creates a new BufferGeometry. It also sets several properties to a default value.

Properties

[property:Integer id]

Unique number for this buffergeometry instance.

[property:Hashmap attributes]

This hashmap has as id the name of the attribute to be set and as value the [page:BufferAttribute buffer] to set it to. Rather than accessing this property directly, use addAttribute and getAttribute to access attributes of this geometry.

[property:Array drawCalls] (previously [property:Array offsets])

For geometries that use indexed triangles, this Array can be used to split the object into multiple WebGL draw calls. Each draw call will draw some subset of the vertices in this geometry using the configured [page:Material shader]. This may be necessary if, for instance, you have more than 65535 vertices in your object. Each element is an object of the form: { start: Integer, count: Integer, index: Integer } where start specifies the index of the first vertex in this draw call, count specifies how many vertices are included, and index specifies an optional offset. Use addDrawCall to add draw calls, rather than modifying this array directly.

[property:Box3 boundingBox]

Bounding box. { min: new THREE.Vector3(), max: new THREE.Vector3() }

[property:Sphere boundingSphere]

Bounding sphere. { radius: float }

[property:Array morphTargets]

Array of morph targets. Each morph target is a Javascript object: { name: "targetName", vertices: [ new THREE.Vertex(), ... ] } Morph vertices match number and order of primary vertices.

[property:boolean hasTangents]

True if BufferGeometry has tangents. Set in [page:.computeTangents].

Methods

[page:EventDispatcher EventDispatcher] methods are available on this class.

[property:null addAttribute]( [page:String name], [page:BufferAttribute attribute] )

Adds an attribute to this geometry. Use this rather than the attributes property, because an internal array of attributes is maintained to speed up iterating over attributes.

[method:null addDrawCall]( [page:Integer start], [page:Integer count], [page:Integer indexOffset] )

Adds a draw call to this geometry; see the drawcalls property for details.

[method:null applyMatrix]( [page:Matrix4 matrix] )

Bakes matrix transform directly into vertex coordinates.

[method:null computeVertexNormals]()

Computes vertex normals by averaging face normals.

[method:null computeTangents]()

Computes vertex tangents.
Based on [link:http://www.terathon.com/code/tangent.html]
Geometry must have vertex [page:UV UVs] (layer 0 will be used).

[method:null computeBoundingBox]()

Computes bounding box of the geometry, updating [page:Geometry Geometry.boundingBox] attribute.
Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are *null*.

[method:null computeBoundingSphere]()

Computes bounding sphere of the geometry, updating [page:Geometry Geometry.boundingSphere] attribute.
Bounding spheres aren't computed by default. They need to be explicitly computed, otherwise they are *null*.

[method:null dispose]()

Disposes the object from memory.
You need to call this when you want the bufferGeometry removed while the application is running.

[method:null fromGeometry]( [page:Geometry] )

Populates this BufferGeometry with data from a [page:Geometry] object.

[method:BufferAttribute getAttribute]( [page:String name] )

Returns the [page:BufferAttribute attribute] with the specified name.

[method:null normalizeNormals]()

Every normal vector in a geometry will have a magnitude of 1. This will correct lighting on the geometry surfaces.

BufferAttribute

This class stores data for an attribute associated with a [page:BufferGeometry].

Constructor

[BufferAttribute]([page:Array array], [page:Integer itemSize])

BufferAttribute(array, itemSize) Instantiates this attibute with data from the associated buffer. The array can either be a regular Array or a Typed Array. itemSize gives the number of values of the array that should be associated with a particular vertex.

Properties

[property:Array array]

Stores the data associated with this attribute; can be an Array or a Typed Array. This element should have itemSize * numVertices elements, where numVertices is the number of vertices in the associated [page:BufferGeometry geometry].

[property:Integer itemSize]

Records how many items of the array are associated with a particular vertex. For instance, if this attribute is storing a 3-component vector (such as a position, normal, or color), then itemSize should be 3.

[property:Integer length]

Gives the total number of elements in the array.

[property:Boolean needsUpdate]

Flag to indicate that this attribute has changed and should be re-send to the GPU. Set this to true when you modify the value of the array.

Methods

[method:null copyAt] ( [page:Integer index1], attribute, [page:Integer index2] )

.copyAt ( index1, attribute, index2 ) Copies itemSize values in the array from the vertex at index2 to the vertex at index1.

[method:null set] ( [page:Array value] )

.set ( value ) Sets the associated array with values from the passed array.

[method:null setX]( index, x )

.setX ( index, x ) Sets the value of the array at index * itemSize to x

[method:null setY]( index, y )

.setY ( index, y ) Sets the value of the array at index * itemSize + 1 to y

[method:null setZ]( index, z )

.setZ ( index, z ) Sets the value of the array at index * itemSize + 2 to z

[method:null setXY]( index, x, y )

.setXY ( index, x, y ) Sets the value of the array at index * itemSize to x and sets the value of the array at index * itemSize + 1 to y

[method:null setXYZ]( index, x, y, z )

.setXYZ ( index, x, y, z ) Sets the value of the array at index * itemSize to x, the value of the array at index * itemSize + 1 to y, and the value of the array at index * itemSize + 2 to z.

[method:null setXYZW]( index, x, y, z, w )

.setXYZW ( index, x, y, z, w ) Sets the value of the array at index * itemSize to x, the value of the array at index * itemSize + 1 to y, the value of the array at index * itemSize + 2 to z, and the value of the array at index * itemSize + 3 to w.

[method:BufferAttribute clone]()

.clone () Copies this attribute.

Face3

Triangle face.

Example

var normal = new THREE.Vector3( 0, 1, 0 ); var color = new THREE.Color( 0xffaa00 ); var face = new THREE.Face3( 0, 1, 2, normal, color, 0 );

Constructor

Face3( [page:Integer a], [page:Integer b], [page:Integer c], [page:Vector3 normal], [page:Color color], [page:Integer materialIndex] )

Face3( a, b, c, normal, color, materialIndex ) a Vertex A index.
b Vertex B index.
c Vertex C index.
normal Face normal or array of vertex normals.
color Face color or array of vertex colors.
materialIndex Material index.

Properties

[property:Integer a]

Vertex A index.

[property:Integer b]

Vertex B index.

[property:Integer c]

Vertex C index.

[property:Vector3 normal]

Face normal.

[property:Color color]

Face color.

[property:Array vertexNormals]

Array of 3 vertex normals.

[property:Array vertexColors]

Array of 3 vertex colors.

[property:Array vertexTangents]

Array of 3 vertex tangents.

[property:Integer materialIndex]

Material index (points to [page:MeshFaceMaterial MeshFaceMaterial.materials]).

Methods

[method:Face3 clone]()

.clone () Creates a new clone of the Face3 object.

Source: src/core/Face3.js

Clock

Object for keeping track of time.

Constructor

Clock( [page:Boolean autoStart] )

autoStart Automatically start the clock.

Properties

[property:Boolean autoStart]

If set, starts the clock automatically when the first update is called.

[property:Float startTime]

When the clock is running, It holds the start time of the clock.
This counted from the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.

[property:Float oldTime]

When the clock is running, It holds the previous time from a update.
This counted from the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.

[property:Float elapsedTime]

When the clock is running, It holds the time elapsed between the start of the clock to the previous update.
This counted from the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.

[property:Boolean running]

This property keeps track whether the clock is running or not.

Methods

[method:null start]()

.start () Starts clock.

[method:null stop]()

.stop () Stops clock.

[method:Float getElapsedTime]()

.getElapsedTime () Get the seconds passed since the clock started.

[method:Float getDelta]()

.getDelta () Get the seconds passed since the last call to this method.
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

Source:src/core/Clock.js

EventDispatcher

JavaScript events for custom objects.
https://github.com/mrdoob/eventdispatcher.js

Constructor

EventDispatcher()

Creates EventDispatcher object.

Methods

[method:null addEventListener]( [page:String type], [page:Function listener] )

.addEventListener ( type, listener ) type - The type of event to listen to.
listener - The function that gets called when the event is fired.
Adds a listener to an event type.

[method:Boolean hasEventListener]( [page:String type], [page:Function listener] )

.hasEventListener ( type, listener ) type - The type of event to listen to.
listener - The function that gets called when the event is fired.
Checks if listener is added to an event type.

[method:null removeEventListener]( [page:String type], [page:Function listener] )

.removeEventListener ( type, listener ) type - The type of the listener that gets removed.
listener - The listener function that gets removed.
Removes a listener from an event type.

[method:null dispatchEvent]( [page:String type] )

type - The type of event that gets fired.
.dispatchEvent ( type ) Fire an event type.
Source src/core/EventDispatcher.js

Raycaster

This class makes raycasting easier. Raycasting is used for picking and more.

Example

var raycaster = new THREE.Raycaster(); var mouse = new THREE.Vector2(); function onMouseMove( event ) { // calculate mouse position in normalized device coordinates // (-1 to +1) for both components mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; } function render() { // update the picking ray with the camera and mouse position raycaster.setFromCamera( mouse, camera ); // calculate objects intersecting the picking ray var intersects = raycaster.intersectObjects( scene.children ); for ( var i = 0; i < intersects.length; i++ ) { intersects[ i ].object.material.color.set( 0xff0000 ); } renderer.render( scene, camera ); } window.addEventListener( 'mousemove', onMouseMove, false ); window.requestAnimationFrame(render);
Examples: [example:webgl_interactive_cubes Raycasting to a Mesh], [example:webgl_interactive_cubes_ortho Raycasting to a Mesh in using an OrthographicCamera], [example:webgl_interactive_buffergeometry Raycasting to a Mesh with BufferGeometry], [example:webgl_interactive_lines Raycasting to a Line], [example:webgl_interactive_raycasting_pointcloud Raycasting to a PointCloud], [example:webgl_geometry_terrain_raycast Terrain raycasting], [example:webgl_octree_raycasting Raycasting using an octree], [example:webgl_interactive_voxelpainter Raycasting to paint voxels] Examples: Raycasting to a Mesh, Raycasting to a Mesh in using an OrthographicCamera, Raycasting to a Mesh with BufferGeometry, Raycasting to a Line, Raycasting to a PointCloud, Terrain raycasting, Raycasting using an octree, Raycasting to paint voxels

Constructor

[name]( [page:Vector3 origin], [page:Vector3 direction], [page:Float near], [page:Float far] ) {

Raycaster( origin, direction, near, far ) [page:Vector3 origin] The origin vector where the ray casts from.
[page:Vector3 direction] The direction vector that gives direction to the ray.
[page:Float near] All results returned are further away than near. Near can't be negative. Default value is 0.
[page:Float far] All results returned are closer then far. Far can't be lower then near . Default value is Infinity.
This creates a new raycaster object.

Properties

[property:Ray ray]

The Ray used for the raycasting.

[property:float near]

The near factor of the raycaster. This value indicates which objects can be discarded based on the distance.
This value shouldn't be negative and should be smaller than the far property.

[property:float far]

The far factor of the raycaster. This value indicates which objects can be discarded based on the distance.
This value shouldn't be negative and should be larger than the near property.

[property:float precision]

The precision factor of the raycaster when intersecting [page:Mesh] objects.

.[page:float linePrecision]

The precision factor of the raycaster when intersecting [page:Line] objects.

Methods

[method:null set]( [page:Vector3 origin], [page:Vector3 direction] )

[page:Vector3 origin] The origin vector where the ray casts from.
[page:Vector3 direction] The direction vector that gives direction to the ray.
.set ( origin, direction ) Updates the ray with a new origin and direction.

[method:null setFromCamera]( [page:Vector2 coords], [page:Camera camera] )

[page:Vector2 coords] 2D coordinates of the mouse, in normalized device coordinates (NDC)---X and Y components should be between -1 and 1.
[page:Camera camera] camera from which the ray should originate
.setFromCamera ( coords, camera ) Updates the ray with a new origin and direction.

[method:Array intersectObject]( [page:Object3D object], [page:Boolean recursive] )

[page:Object3D object] The object to check for intersection with the ray.
[page:Boolean recursive] If set, it also checks all descendants. Otherwise it only checks intersecton with the object.

.intersectObject ( object, recursive ) Checks all intersection between the ray and the object with or without the descendants. Intersections are returned sorted by distance, closest first. An array of intersections is returned... [ { distance, point, face, faceIndex, indices, object }, ... ]

[page:Float distance] distance between the origin of the ray and the intersection
[page:Vector3 point] point of intersection, in world coordinates
[page:Face3 face] intersected face
[page:Integer faceIndex] index of the intersected face
[page:Array indices] indices of vertices comprising the intersected face
[page:Object3D object] the intersected object

When intersecting a [page:Mesh] with a [page:BufferGeometry], the *faceIndex* will be *undefined*, and *indices* will be set; when intersecting a [page:Mesh] with a [page:Geometry], *indices* will be *undefined*.

*Raycaster* delegates to the [page:Object3D.raycast raycast] method of the passed object, when evaluating whether the ray intersects the object or not. This allows [page:Mesh meshes] to respond differently to ray casting than [page:Line lines] and [page:PointCloud pointclouds].

*Note* that for meshes, faces must be pointed towards the origin of the [page:.ray ray] in order to be detected; intersections of the ray passing through the back of a face will not be detected. To raycast against both faces of an object, you'll want to set the [page:Mesh.material material]'s [page:Material.side side] property to *THREE.DoubleSide*.

[method:Array intersectObjects]( [page:Array objects], [page:Boolean recursive] )

[page:Array objects] The objects to check for intersection with the ray.
[page:Boolean recursive] If set, it also checks all descendants of the objects. Otherwise it only checks intersecton with the objects.
.intersectObjects ( objects, recursive ) Checks all intersection between the ray and the objects with or without the descendants. Intersections are returned sorted by distance, closest first. Intersections are of the same form as those returned by [page:.intersectObject].

Source:src/core/Raycaster.js

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]