提交 6c3d0f6d 编写于 作者: C Casey Grun

Updated example for r69; added Object3D#raycast docs

上级 614bb8da
......@@ -276,6 +276,11 @@
Rotate an object along an axis in object space. The axis is assumed to be normalized.
</div>
<h3>[method:Array raycast]([page:Raycaster raycaster], [page:Array intersects])</h3>
<div>
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.
</div>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
......
......@@ -15,28 +15,46 @@
<h2>Example</h2>
<code>
var projector = new THREE.Projector();
var mouse2D = new THREE.Vector3();
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
function onMouseMove(event) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1
}
function pickingRay( raycaster, camera, mouse ) {
var vector = new THREE.Vector3( mouse.x, mouse.y, -1 ); // z = - 1 important!
var end = new THREE.Vector3( vector.x, vector.y, 1.0 );
vector.unproject(camera);
end.unproject(camera);
end.sub( vector ).normalize();
raycaster.ray.set( vector, end );
function onMouseMove() {
mouse2D.x = 2 * ( e.clientX / window.innerWidth ) - 1;
mouse2D.y = 1 - 2 * ( e.clientY / window.innerHeight );
}
window.addEventListener( 'mousemove', onMouseMove, false );
function render() {
pickingRay( raycaster, camera, mouse );
var raycaster = projector.pickingRay( mouse2D.clone(), camera );
var intersects = raycaster.intersectObjects( scene.children );
for ( var intersect in intersects ) {
intersect.object.material.color = new THREE.Color( 0xff0000 );
}
renderer.render( scene, camera );
}
window.requestAnimationFrame(render);
</code>
<!-- http://jsfiddle.net/7hfaoeo7/3/ -->
<h2>Constructor</h2>
<h3>[name]( [page:Vector3 origin], [page:Vector3 direction], [page:Float near], [page:Float far] ) {</h3>
......@@ -98,12 +116,9 @@
[page:Boolean recursive] — If set, it also checks all descendants. Otherwise it only checks intersecton with the object.
</p>
<p>
*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 than [page:Line lines] to ray casting.
</p>
</div>
<div>
checks all intersection between the ray and the object with or without the descendants. Intersections are returned sorted by distance, closest first.
Checks all intersection between the ray and the object with or without the descendants. Intersections are returned sorted by distance, closest first.
<code>
[ { distance, point, face, faceIndex, indices, object }, ... ]
</code>
......@@ -116,8 +131,11 @@
[page:Object3D object] – the intersected object
</p>
<p>
Note that when intersecting a [page:Mesh] with a [page:BufferGeometry], the *face* and *faceIndex* will be *undefined*, and *indices* will be set; when intersecting a [page:Mesh] with a [page:Geometry], *indices* will be *undefined*.
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*.
</p>
<p>
*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 than [page:Line lines] to ray casting.
</p>
</div>
<h3>[method:Array intersectObjects]( [page:Array objects], [page:Boolean recursive] )</h3>
......@@ -126,7 +144,7 @@
[page:Boolean recursive] — If set, it also checks all descendants of the objects. Otherwise it only checks intersecton with the objects.
</div>
<div>
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].
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].
</div>
......
......@@ -70,6 +70,11 @@
<h2>Methods</h2>
<h3>[method:Array raycast]([page:Raycaster raycaster], [page:Array intersects])</h3>
<div>
Get intersections between a casted ray and this Line. [page:Raycaster.intersectObject] will call this method.
</div>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
......
......@@ -60,6 +60,12 @@
Updates the morphtargets to have no influence on the object.
</div>
<h3>[method:Array raycast]([page:Raycaster raycaster], [page:Array intersects])</h3>
<div>
Get intersections between a casted ray and this mesh. [page:Raycaster.intersectObject] will call this method.
</div>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
......
......@@ -46,6 +46,12 @@
This creates a clone of the particle system.
</div>
<h3>[method:Array raycast]([page:Raycaster raycaster], [page:Array intersects])</h3>
<div>
Get intersections between a casted ray and this PointCloud. [page:Raycaster.intersectObject] will call this method.
</div>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册