Browse Source

Merge remote-tracking branch 'upstream/dev' into dev33

Mugen87 6 years ago
parent
commit
bc5e51d4ba

+ 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
examples/js/shaders/TranslucentShader.js

@@ -61,6 +61,7 @@ THREE.TranslucentShader = {
 	].join( "\n" ),
 	].join( "\n" ),
 
 
 	fragmentShader: [
 	fragmentShader: [
+		"#define USE_UV",
 		"#define USE_MAP",
 		"#define USE_MAP",
 		"#define PHONG",
 		"#define PHONG",
 		"#define TRANSLUCENT",
 		"#define TRANSLUCENT",
@@ -137,7 +138,7 @@ THREE.TranslucentShader = {
 
 
 		"			RE_Direct( directLight, geometry, material, reflectedLight );",
 		"			RE_Direct( directLight, geometry, material, reflectedLight );",
 
 
-		"			#if defined( TRANSLUCENT ) && defined( USE_MAP )",
+		"			#if defined( TRANSLUCENT ) && defined( USE_UV )",
 		"			RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);",
 		"			RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);",
 		"			#endif",
 		"			#endif",
 		"		}",
 		"		}",
@@ -159,7 +160,7 @@ THREE.TranslucentShader = {
 
 
 		"			RE_Direct( directLight, geometry, material, reflectedLight );",
 		"			RE_Direct( directLight, geometry, material, reflectedLight );",
 
 
-		"			#if defined( TRANSLUCENT ) && defined( USE_MAP )",
+		"			#if defined( TRANSLUCENT ) && defined( USE_UV )",
 		"			RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);",
 		"			RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);",
 		"			#endif",
 		"			#endif",
 		"		}",
 		"		}",

+ 3 - 2
examples/jsm/shaders/TranslucentShader.js

@@ -68,6 +68,7 @@ var TranslucentShader = {
 	].join( "\n" ),
 	].join( "\n" ),
 
 
 	fragmentShader: [
 	fragmentShader: [
+		"#define USE_UV",
 		"#define USE_MAP",
 		"#define USE_MAP",
 		"#define PHONG",
 		"#define PHONG",
 		"#define TRANSLUCENT",
 		"#define TRANSLUCENT",
@@ -144,7 +145,7 @@ var TranslucentShader = {
 
 
 		"			RE_Direct( directLight, geometry, material, reflectedLight );",
 		"			RE_Direct( directLight, geometry, material, reflectedLight );",
 
 
-		"			#if defined( TRANSLUCENT ) && defined( USE_MAP )",
+		"			#if defined( TRANSLUCENT ) && defined( USE_UV )",
 		"			RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);",
 		"			RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);",
 		"			#endif",
 		"			#endif",
 		"		}",
 		"		}",
@@ -166,7 +167,7 @@ var TranslucentShader = {
 
 
 		"			RE_Direct( directLight, geometry, material, reflectedLight );",
 		"			RE_Direct( directLight, geometry, material, reflectedLight );",
 
 
-		"			#if defined( TRANSLUCENT ) && defined( USE_MAP )",
+		"			#if defined( TRANSLUCENT ) && defined( USE_UV )",
 		"			RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);",
 		"			RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);",
 		"			#endif",
 		"			#endif",
 		"		}",
 		"		}",

+ 6 - 0
src/core/Raycaster.d.ts

@@ -55,6 +55,12 @@ export class Raycaster {
 	 */
 	 */
 	far: number;
 	far: number;
 
 
+	/**
+	 * The camera to use when raycasting against view-dependent objects such as billboarded objects like Sprites. This field
+	 * can be set manually or is set when calling "setFromCamera".
+	 */
+	camera: Camera;
+
 	params: RaycasterParameters;
 	params: RaycasterParameters;
 
 
 	/**
 	/**

+ 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

@@ -71,14 +71,20 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	raycast: function ( raycaster, intersects ) {
 	raycast: function ( 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 );