Browse Source

optimize Matrix4.compose to remove temporaries and unnecessary matrix multiplication.

Ben Houston 12 years ago
parent
commit
2d5c5ca4d7
1 changed files with 12 additions and 16 deletions
  1. 12 16
      src/math/Matrix4.js

+ 12 - 16
src/math/Matrix4.js

@@ -894,29 +894,25 @@ THREE.Matrix4.prototype = {
 
 
 THREE.extend( THREE.Matrix4.prototype, {
 THREE.extend( THREE.Matrix4.prototype, {
 
 
-	compose: function() {
+	compose: function ( position, quaternion, scale ) {
 
 
-		var mRotation = new THREE.Matrix4();
-		var mScale = new THREE.Matrix4();
+		var te = this.elements;
 
 
-		return function ( position, quaternion, scale ) {
+		this.makeRotationFromQuaternion( quaternion );
+	
+		if ( scale.x !== 1 || scale.y !== 1 || scale.z !== 1 ) {
 
 
-			var te = this.elements;
+			this.scale( scale );
 
 
-			mRotation.makeRotationFromQuaternion( quaternion );
+		}
 		
 		
-			mScale.makeScale( scale.x, scale.y, scale.z );
-			this.multiplyMatrices( mRotation, mScale );
-
-			te[12] = position.x;
-			te[13] = position.y;
-			te[14] = position.z;
+		te[12] = position.x;
+		te[13] = position.y;
+		te[14] = position.z;
 
 
-			return this;
-
-		};
+		return this;
 
 
-	}(),
+	},
 
 
 	decompose: function() {
 	decompose: function() {