|
@@ -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 ];
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- }()
|
|
|
-
|
|
|
-} );
|