浏览代码

Updated example for r69; added Object3D#raycast docs

Casey Grun 10 年之前
父节点
当前提交
6c3d0f6d17

+ 5 - 0
docs/api/core/Object3D.html

@@ -276,6 +276,11 @@
 		Rotate an object along an axis in object space. The axis is assumed to be normalized.
 		Rotate an object along an axis in object space. The axis is assumed to be normalized.
 		</div>
 		</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>
 		<h2>Source</h2>
 
 
 		[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]

+ 31 - 13
docs/api/core/Raycaster.html

@@ -15,28 +15,46 @@
 
 
 		<h2>Example</h2>
 		<h2>Example</h2>
 		<code>
 		<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 );
 		window.addEventListener( 'mousemove', onMouseMove, false );
 
 
 		function render() {
 		function render() {
+			pickingRay( raycaster, camera, mouse );	
 
 
-			var raycaster = projector.pickingRay( mouse2D.clone(), camera );
 			var intersects = raycaster.intersectObjects( scene.children );
 			var intersects = raycaster.intersectObjects( scene.children );
 
 
 			for ( var intersect in intersects ) {
 			for ( var intersect in intersects ) {
 				intersect.object.material.color = new THREE.Color( 0xff0000 );
 				intersect.object.material.color = new THREE.Color( 0xff0000 );
 			}
 			}
-
+			renderer.render( scene, camera );
 		}
 		}
+		
+		window.requestAnimationFrame(render);
+
 		</code>
 		</code>
 
 
+		<!-- http://jsfiddle.net/7hfaoeo7/3/ -->
+
 		<h2>Constructor</h2>
 		<h2>Constructor</h2>
 
 
 		<h3>[name]( [page:Vector3 origin], [page:Vector3 direction], [page:Float near], [page:Float far] ) {</h3>
 		<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.
 		[page:Boolean recursive] — If set, it also checks all descendants. Otherwise it only checks intersecton with the object.
 		</p>
 		</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>
 		<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>
         <code>
             [ { distance, point, face, faceIndex, indices, object }, ... ]
             [ { distance, point, face, faceIndex, indices, object }, ... ]
         </code>
         </code>
@@ -116,8 +131,11 @@
         [page:Object3D object] – the intersected object
         [page:Object3D object] – the intersected object
     	</p>
     	</p>
         <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>
+		<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>
 
 
 		<h3>[method:Array intersectObjects]( [page:Array objects], [page:Boolean recursive] )</h3>
 		<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.
 		[page:Boolean recursive] — If set, it also checks all descendants of the objects. Otherwise it only checks intersecton with the objects.
 		</div>
 		</div>
 		<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>
 		</div>
 
 
 
 

+ 5 - 0
docs/api/objects/Line.html

@@ -70,6 +70,11 @@
 
 
 		<h2>Methods</h2>
 		<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>
 		<h2>Source</h2>
 
 
 		[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]

+ 6 - 0
docs/api/objects/Mesh.html

@@ -60,6 +60,12 @@
 		Updates the morphtargets to have no influence on the object.
 		Updates the morphtargets to have no influence on the object.
 		</div>
 		</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>
 		<h2>Source</h2>
 
 
 		[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]

+ 6 - 0
docs/api/objects/PointCloud.html

@@ -46,6 +46,12 @@
 		This creates a clone of the particle system.
 		This creates a clone of the particle system.
 		</div>
 		</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>
 		<h2>Source</h2>
 
 
 		[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]