Pārlūkot izejas kodu

Changed some of the matrix.getPosition() to vector.getPositionFromMatrix( matrix ). See #2967.

Mr.doob 12 gadi atpakaļ
vecāks
revīzija
e314cb059d

+ 2 - 2
examples/js/AudioObject.js

@@ -110,8 +110,8 @@ THREE.AudioObject = function ( url, volume, playbackRate, loop ) {
 		oldSoundPosition.copy( soundPosition );
 		oldCameraPosition.copy( cameraPosition );
 
-		soundPosition.copy( this.matrixWorld.getPosition() );
-		cameraPosition.copy( camera.matrixWorld.getPosition() );
+		soundPosition.getPositionFromMatrix( this.matrixWorld );
+		cameraPosition.getPositionFromMatrix( camera.matrixWorld );
 
 		soundDelta.subVectors( soundPosition, oldSoundPosition );
 		cameraDelta.subVectors( cameraPosition, oldCameraPosition );

+ 7 - 9
examples/js/renderers/SVGRenderer.js

@@ -230,18 +230,16 @@ THREE.SVGRenderer = function () {
 
 	function calculateLight( lights, position, normal, color ) {
 
-		var l, ll, light, lightColor, lightPosition, amount;
+		for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
 
-		for ( l = 0, ll = lights.length; l < ll; l ++ ) {
-
-			light = lights[ l ];
-			lightColor = light.color;
+			var light = lights[ l ];
+			var lightColor = light.color;
 
 			if ( light instanceof THREE.DirectionalLight ) {
 
-				lightPosition = light.matrixWorld.getPosition().normalize();
+				var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize();
 
-				amount = normal.dot( lightPosition );
+				var amount = normal.dot( lightPosition );
 
 				if ( amount <= 0 ) continue;
 
@@ -253,9 +251,9 @@ THREE.SVGRenderer = function () {
 
 			} else if ( light instanceof THREE.PointLight ) {
 
-				lightPosition = light.matrixWorld.getPosition();
+				var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld );
 
-				amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
+				var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );
 
 				if ( amount <= 0 ) continue;
 

+ 3 - 3
src/core/Projector.js

@@ -110,7 +110,7 @@ THREE.Projector = function () {
 
 						} else {
 
-							_vector3.copy( object.matrixWorld.getPosition() );
+							_vector3.getPositionFromMatrix( object.matrixWorld );
 							_vector3.applyProjection( _viewProjectionMatrix );
 							_object.z = _vector3.z;
 
@@ -133,7 +133,7 @@ THREE.Projector = function () {
 
 					} else {
 
-						_vector3.copy( object.matrixWorld.getPosition() );
+						_vector3.getPositionFromMatrix.copy( object.matrixWorld );
 						_vector3.applyProjection( _viewProjectionMatrix );
 						_object.z = _vector3.z;
 
@@ -152,7 +152,7 @@ THREE.Projector = function () {
 
 					} else {
 
-						_vector3.copy( object.matrixWorld.getPosition() );
+						_vector3.getPositionFromMatrix( object.matrixWorld );
 						_vector3.applyProjection( _viewProjectionMatrix );
 						_object.z = _vector3.z;
 

+ 6 - 6
src/core/Raycaster.js

@@ -60,7 +60,7 @@
 			// Checking boundingSphere distance to ray
 			sphere.set(
 				object.matrixWorld.getPosition(),
-				object.geometry.boundingSphere.radius* object.matrixWorld.getMaxScaleOnAxis() );
+				object.geometry.boundingSphere.radius * object.matrixWorld.getMaxScaleOnAxis() );
 
 			if ( ! raycaster.ray.isIntersectionSphere( sphere ) ) {
 
@@ -86,7 +86,7 @@
 			inverseMatrix.getInverse( object.matrixWorld );
 
 			localRay.copy( raycaster.ray ).transform( inverseMatrix );
-	
+
 			for ( var f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
 
 				var face = geometry.faces[ f ];
@@ -94,14 +94,14 @@
 				var material = isFaceMaterial === true ? objectMaterials[ face.materialIndex ] : object.material;
 
 				if ( material === undefined ) continue;
-				
+
 				facePlane.setFromNormalAndCoplanarPoint( face.normal, vertices[face.a] );
 
 				var planeDistance = localRay.distanceToPlane( facePlane );
-	
+
 				// bail if raycaster and plane are parallel
 				if ( Math.abs( planeDistance ) < precision ) continue;
-	
+
 				// if negative distance, then plane is behind raycaster
 				if ( planeDistance < 0 ) continue;
 
@@ -117,7 +117,7 @@
 
 				// this can be done using the planeDistance from localRay because localRay wasn't normalized, but ray was
 				if ( planeDistance < raycaster.near || planeDistance > raycaster.far ) continue;
-				
+
 				intersectPoint = localRay.at( planeDistance, intersectPoint ); // passing in intersectPoint avoids a copy
 
 				if ( face instanceof THREE.Face3 ) {

+ 1 - 1
src/extras/renderers/plugins/ShadowMapPlugin.js

@@ -196,7 +196,7 @@ THREE.ShadowMapPlugin = function () {
 			shadowMatrix = light.shadowMatrix;
 			shadowCamera = light.shadowCamera;
 
-			shadowCamera.position.copy( light.matrixWorld.getPosition() );
+			shadowCamera.position.getPositionFromMatrix( light.matrixWorld );
 			shadowCamera.lookAt( light.target.matrixWorld.getPosition() );
 			shadowCamera.updateMatrixWorld();
 

+ 24 - 16
src/math/Frustum.js

@@ -70,29 +70,37 @@ THREE.extend( THREE.Frustum.prototype, {
 
 	},
 
-	intersectsObject: function ( object ) {
+	intersectsObject: function () {
 
-		// this method is expanded inlined for performance reasons.
-		var matrix = object.matrixWorld;
-		var planes = this.planes;
-		var center = matrix.getPosition();
-		var negRadius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis();
+		var center = new THREE.Vector3();
 
-		for ( var i = 0; i < 6; i ++ ) {
+		return function ( object ) {
 
-			var distance = planes[ i ].distanceToPoint( center );
+			// this method is expanded inlined for performance reasons.
 
-			if( distance < negRadius ) {
+			var matrix = object.matrixWorld;
+			var planes = this.planes;
+			var negRadius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis();
 
-				return false;
+			center.getPositionFromMatrix( matrix );
+
+			for ( var i = 0; i < 6; i ++ ) {
+
+				var distance = planes[ i ].distanceToPoint( center );
+
+				if ( distance < negRadius ) {
+
+					return false;
+
+				}
 
 			}
 
-		}
+			return true;
 
-		return true;
+		};
 
-	},
+	}(),
 
 	intersectsSphere: function ( sphere ) {
 
@@ -104,7 +112,7 @@ THREE.extend( THREE.Frustum.prototype, {
 
 			var distance = planes[ i ].distanceToPoint( center );
 
-			if( distance < negRadius ) {
+			if ( distance < negRadius ) {
 
 				return false;
 
@@ -122,7 +130,7 @@ THREE.extend( THREE.Frustum.prototype, {
 
 		for ( var i = 0; i < 6; i ++ ) {
 
-			if( planes[ i ].distanceToPoint( point ) < 0 ) {
+			if ( planes[ i ].distanceToPoint( point ) < 0 ) {
 
 				return false;
 
@@ -140,4 +148,4 @@ THREE.extend( THREE.Frustum.prototype, {
 
 	}
 
-} );
+} );

+ 3 - 3
src/math/Vector3.js

@@ -265,7 +265,7 @@ THREE.extend( THREE.Vector3.prototype, {
 
 	},
 
-	applyEuler: function() {
+	applyEuler: function () {
 
 		var q1 = new THREE.Quaternion();
 
@@ -281,7 +281,7 @@ THREE.extend( THREE.Vector3.prototype, {
 
 	}(),
 
-	applyAxisAngle: function() {
+	applyAxisAngle: function () {
 
 		var q1 = new THREE.Quaternion();
 
@@ -432,7 +432,7 @@ THREE.extend( THREE.Vector3.prototype, {
 
 	},
 
-	negate: function() {
+	negate: function () {
 
 		return this.multiplyScalar( - 1 );
 

+ 2 - 2
src/renderers/CanvasRenderer.js

@@ -436,7 +436,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 				if ( light instanceof THREE.DirectionalLight ) {
 
-					var lightPosition = light.matrixWorld.getPosition().normalize();
+					var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize();
 
 					var amount = normal.dot( lightPosition );
 
@@ -448,7 +448,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 				} else if ( light instanceof THREE.PointLight ) {
 
-					var lightPosition = light.matrixWorld.getPosition();
+					var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld );
 
 					var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() );