Explorar el Código

Expose Raycaster.camera

Garrett Johnson hace 6 años
padre
commit
765acdcd3d
Se han modificado 3 ficheros con 20 adiciones y 5 borrados
  1. 8 0
      docs/api/en/core/Raycaster.html
  2. 3 2
      src/core/Raycaster.js
  3. 9 3
      src/objects/Sprite.js

+ 8 - 0
docs/api/en/core/Raycaster.html

@@ -103,6 +103,14 @@
 		This value shouldn't be negative and should be smaller than the far property.
 		This value shouldn't be negative and should be smaller than the far property.
 		</p>
 		</p>
 
 
+		<h3>[property:Camera camera]</h3>
+		<p>
+		The camera to use when raycasting against view-dependent objects such as billboarded objects like [page:Sprites]. This field
+		can be set manually or is set when calling "setFromCamera".
+
+		Defaults to null.
+		</p>
+
 		<h3>[property:Object params]</h3>
 		<h3>[property:Object params]</h3>
 		<p>
 		<p>
 		An object with the following properties:
 		An object with the following properties:

+ 3 - 2
src/core/Raycaster.js

@@ -13,6 +13,7 @@ function Raycaster( origin, direction, near, far ) {
 
 
 	this.near = near || 0;
 	this.near = near || 0;
 	this.far = far || Infinity;
 	this.far = far || Infinity;
+	this.camera = null;
 
 
 	this.params = {
 	this.params = {
 		Mesh: {},
 		Mesh: {},
@@ -79,13 +80,13 @@ Object.assign( Raycaster.prototype, {
 
 
 			this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
 			this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
 			this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
 			this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
-			this._camera = camera;
+			this.camera = camera;
 
 
 		} else if ( ( camera && camera.isOrthographicCamera ) ) {
 		} else if ( ( camera && camera.isOrthographicCamera ) ) {
 
 
 			this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
 			this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
 			this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
 			this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
-			this._camera = camera;
+			this.camera = camera;
 
 
 		} else {
 		} else {
 
 

+ 9 - 3
src/objects/Sprite.js

@@ -100,14 +100,20 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 		return function raycast( raycaster, intersects ) {
 		return function raycast( raycaster, intersects ) {
 
 
+			if ( raycaster.camera === null ) {
+
+				console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
+
+			}
+
 			worldScale.setFromMatrixScale( this.matrixWorld );
 			worldScale.setFromMatrixScale( this.matrixWorld );
 
 
-			viewWorldMatrix.copy( raycaster._camera.matrixWorld );
-			this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, this.matrixWorld );
+			viewWorldMatrix.copy( raycaster.camera.matrixWorld );
+			this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
 
 
 			mvPosition.setFromMatrixPosition( this.modelViewMatrix );
 			mvPosition.setFromMatrixPosition( this.modelViewMatrix );
 
 
-			if ( raycaster._camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
+			if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
 
 
 				worldScale.multiplyScalar( - mvPosition.z );
 				worldScale.multiplyScalar( - mvPosition.z );