Kaynağa Gözat

Simplified Matrix4.decompose() and moved out of THREE.extend pattern.
This THREE.extend pattern creates misterious issues in V8. Sometimes the methods aren't available for whatever reason. Probably easier to move away of the pattern rather than figuring out what's wong in V8 :/

Mr.doob 12 yıl önce
ebeveyn
işleme
f2eac438f7
2 değiştirilmiş dosya ile 46 ekleme ve 61 silme
  1. 1 5
      examples/js/loaders/ColladaLoader.js
  2. 45 56
      src/math/Matrix4.js

+ 1 - 5
examples/js/loaders/ColladaLoader.js

@@ -886,11 +886,7 @@ THREE.ColladaLoader = function () {
 
 		obj.name = node.name || node.id || "";
 		obj.matrix = node.matrix;
-
-		var props = node.matrix.decompose();
-		obj.position = props[ 0 ];
-		obj.quaternion = props[ 1 ];
-		obj.scale = props[ 2 ];
+		obj.matrix.decompose( obj.position, obj.quaternion, obj.scale );
 
 		if ( options.centerGeometry && obj.geometry ) {
 

+ 45 - 56
src/math/Matrix4.js

@@ -826,6 +826,51 @@ THREE.Matrix4.prototype = {
 
 	},
 
+	decompose: function () {
+
+		var vector = new THREE.Vector3();
+		var matrix = new THREE.Matrix4();
+
+		return function ( position, quaternion, scale ) {
+
+			var te = this.elements;
+
+			var sx = vector.set( te[0], te[1], te[2] ).length();
+			var sy = vector.set( te[4], te[5], te[6] ).length();
+			var sz = vector.set( te[8], te[9], te[10] ).length();
+
+			position.x = te[12];
+			position.y = te[13];
+			position.z = te[14];
+
+			// scale the rotation part
+
+			matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
+
+			matrix.elements[0] /= sx;
+			matrix.elements[1] /= sx;
+			matrix.elements[2] /= sx;
+
+			matrix.elements[4] /= sy;
+			matrix.elements[5] /= sy;
+			matrix.elements[6] /= sy;
+
+			matrix.elements[8] /= sz;
+			matrix.elements[9] /= sz;
+			matrix.elements[10] /= sz;
+
+			quaternion.setFromRotationMatrix( matrix );
+
+			scale.x = sx;
+			scale.y = sy;
+			scale.z = sz;
+
+			return this;
+
+		};
+
+	}(),
+
 	makeFrustum: function ( left, right, bottom, top, near, far ) {
 
 		var te = this.elements;
@@ -914,59 +959,3 @@ THREE.Matrix4.prototype = {
 	}
 
 };
-
-THREE.extend( THREE.Matrix4.prototype, {
-
-	decompose: function () {
-
-		var x = new THREE.Vector3();
-		var y = new THREE.Vector3();
-		var z = new THREE.Vector3();
-		var matrix = new THREE.Matrix4();
-
-		return function ( position, quaternion, scale ) {
-
-			var te = this.elements;
-
-			// grab the axis vectors
-			x.set( te[0], te[1], te[2] );
-			y.set( te[4], te[5], te[6] );
-			z.set( te[8], te[9], te[10] );
-
-			position = ( position instanceof THREE.Vector3 ) ? position : new THREE.Vector3();
-			quaternion = ( quaternion instanceof THREE.Quaternion ) ? quaternion : new THREE.Quaternion();
-			scale = ( scale instanceof THREE.Vector3 ) ? scale : new THREE.Vector3();
-
-			scale.x = x.length();
-			scale.y = y.length();
-			scale.z = z.length();
-
-			position.x = te[12];
-			position.y = te[13];
-			position.z = te[14];
-
-			// scale the rotation part
-
-			matrix.copy( this );
-
-			matrix.elements[0] /= scale.x;
-			matrix.elements[1] /= scale.x;
-			matrix.elements[2] /= scale.x;
-
-			matrix.elements[4] /= scale.y;
-			matrix.elements[5] /= scale.y;
-			matrix.elements[6] /= scale.y;
-
-			matrix.elements[8] /= scale.z;
-			matrix.elements[9] /= scale.z;
-			matrix.elements[10] /= scale.z;
-
-			quaternion.setFromRotationMatrix( matrix );
-
-			return [ position, quaternion, scale ];
-
-		};
-
-	}()
-
-} );