Explorar el Código

Simplified normal matrix in GeometryUtils.merge.

Mr.doob hace 12 años
padre
commit
cfc73cc53d
Se han modificado 1 ficheros con 21 adiciones y 6 borrados
  1. 21 6
      src/extras/GeometryUtils.js

+ 21 - 6
src/extras/GeometryUtils.js

@@ -9,7 +9,7 @@ THREE.GeometryUtils = {
 
 
 	merge: function ( geometry1, object2 /* mesh | geometry */ ) {
 	merge: function ( geometry1, object2 /* mesh | geometry */ ) {
 
 
-		var matrix, matrixRotation,
+		var matrix, normalMatrix,
 		vertexOffset = geometry1.vertices.length,
 		vertexOffset = geometry1.vertices.length,
 		uvPosition = geometry1.faceVertexUvs[ 0 ].length,
 		uvPosition = geometry1.faceVertexUvs[ 0 ].length,
 		geometry2 = object2 instanceof THREE.Mesh ? object2.geometry : object2,
 		geometry2 = object2 instanceof THREE.Mesh ? object2.geometry : object2,
@@ -25,8 +25,10 @@ THREE.GeometryUtils = {
 			object2.matrixAutoUpdate && object2.updateMatrix();
 			object2.matrixAutoUpdate && object2.updateMatrix();
 
 
 			matrix = object2.matrix;
 			matrix = object2.matrix;
-			matrixRotation = new THREE.Matrix4();
-			matrixRotation.extractRotation( matrix, object2.scale );
+
+			normalMatrix = new THREE.Matrix3();
+			normalMatrix.getInverse( matrix );
+			normalMatrix.transpose();
 
 
 		}
 		}
 
 
@@ -64,13 +66,21 @@ THREE.GeometryUtils = {
 
 
 			faceCopy.normal.copy( face.normal );
 			faceCopy.normal.copy( face.normal );
 
 
-			if ( matrixRotation ) faceCopy.normal.multiplyMatrix4( matrixRotation );
+			if ( normalMatrix ) {
+
+				faceCopy.normal.multiplyMatrix3( normalMatrix ).normalize();
+
+			}
 
 
 			for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
 			for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
 
 
 				normal = faceVertexNormals[ j ].clone();
 				normal = faceVertexNormals[ j ].clone();
 
 
-				if ( matrixRotation ) normal.multiplyMatrix4( matrixRotation );
+				if ( normalMatrix ) {
+
+					normal.multiplyMatrix3( normalMatrix ).normalize();
+
+				}
 
 
 				faceCopy.vertexNormals.push( normal );
 				faceCopy.vertexNormals.push( normal );
 
 
@@ -88,7 +98,12 @@ THREE.GeometryUtils = {
 			faceCopy.materialIndex = face.materialIndex;
 			faceCopy.materialIndex = face.materialIndex;
 
 
 			faceCopy.centroid.copy( face.centroid );
 			faceCopy.centroid.copy( face.centroid );
-			if ( matrix ) faceCopy.centroid.multiplyMatrix4( matrix );
+
+			if ( matrix ) {
+
+				faceCopy.centroid.multiplyMatrix4( matrix );
+
+			}
 
 
 			faces1.push( faceCopy );
 			faces1.push( faceCopy );