Explorar o código

simplify Object3D matrix construction via use of Matrix4.compose().

Ben Houston %!s(int64=12) %!d(string=hai) anos
pai
achega
36e9847200

+ 4 - 4
docs/api/math/Matrix4.html

@@ -175,19 +175,19 @@
 		Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm].
 		</div>
 
-		<h3>.setRotationFromEuler( [page:Vector3 v], [page:String order] ) [page:Matrix4]</h3>
+		<h3>.makeRotationFromEuler( [page:Vector3 v], [page:String order] ) [page:Matrix4]</h3>
 		<div>
 		v — Rotation vector.
 		order — The order of rotations. Eg. "XYZ".
 		</div>
 		<div>
-		Sets the rotation submatrix of this matrix to the rotation specified by Euler angles.<br />
+		Sets the rotation submatrix of this matrix to the rotation specified by Euler angles, the rest of the matrix is identity.<br />
 		Default order is *"XYZ"*.
 		</div>
 
-		<h3>.setRotationFromQuaternion( [page:Quaternion q] ) [page:Matrix4]</h3>
+		<h3>.makeRotationFromQuaternion( [page:Quaternion q] ) [page:Matrix4]</h3>
 		<div>
-		Sets the rotation submatrix of this matrix to the rotation specified by *q*.
+		Sets the rotation submatrix of this matrix to the rotation specified by *q*. The rest of the matrix is identity.
 		</div>
 
 		<h3>.scale( [page:Vector3 v] ) [page:Matrix4]</h3>

+ 1 - 1
examples/misc_lookat.html

@@ -68,7 +68,7 @@
 				scene.add( sphere );
 
 				var geometry = new THREE.CylinderGeometry( 0, 10, 100, 3 );
-				geometry.applyMatrix( new THREE.Matrix4().setRotationFromEuler( new THREE.Vector3( Math.PI / 2, Math.PI, 0 ) ) );
+				geometry.applyMatrix( new THREE.Matrix4().makeRotationFromEuler( new THREE.Vector3( Math.PI / 2, Math.PI, 0 ) ) );
 
 				var material = new THREE.MeshNormalMaterial();
 

+ 1 - 1
examples/webgl_ribbons.html

@@ -143,7 +143,7 @@
 					// manually create local matrix
 
 					ribbon.matrix.setPosition( ribbon.position );
-					ribbon.matrixRotationWorld.setRotationFromEuler( ribbon.rotation );
+					ribbon.matrixRotationWorld.makeRotationFromEuler( ribbon.rotation );
 
 					ribbon.matrix.elements[ 0 ] = ribbon.matrixRotationWorld.elements[ 0 ];
 					ribbon.matrix.elements[ 4 ] = ribbon.matrixRotationWorld.elements[ 4 ];

+ 5 - 14
src/core/Object3D.js

@@ -316,23 +316,14 @@ THREE.Object3D.prototype = {
 
 	updateMatrix: function () {
 
-		this.matrix.setPosition( this.position );
-
+		// if we are not using a quaternion directly, convert Euler rotation to this.quaternion.
 		if ( this.useQuaternion === false )  {
 
-			this.matrix.setRotationFromEuler( this.rotation, this.eulerOrder );
-
-		} else {
-
-			this.matrix.setRotationFromQuaternion( this.quaternion );
-
-		}
-
-		if ( this.scale.x !== 1 || this.scale.y !== 1 || this.scale.z !== 1 ) {
+			this.quaternion.setFromEuler( this.rotation, this.eulerOrder );
 
-			this.matrix.scale( this.scale );
-
-		}
+		} 
+		
+		this.matrix.compose( this.position, this.quaternion, this.scale );
 
 		this.matrixWorldNeedsUpdate = true;
 

+ 2 - 4
src/math/Matrix4.js

@@ -903,11 +903,9 @@ THREE.extend( THREE.Matrix4.prototype, {
 
 			var te = this.elements;
 
-			mRotation.identity();
-			mRotation.setRotationFromQuaternion( quaternion );
-
+			mRotation.makeRotationFromQuaternion( quaternion );
+		
 			mScale.makeScale( scale.x, scale.y, scale.z );
-
 			this.multiplyMatrices( mRotation, mScale );
 
 			te[12] = position.x;

+ 2 - 9
src/objects/Sprite.js

@@ -22,16 +22,9 @@ THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
 
 THREE.Sprite.prototype.updateMatrix = function () {
 
-	this.matrix.setPosition( this.position );
-
 	this.rotation3d.set( 0, 0, this.rotation );
-	this.matrix.setRotationFromEuler( this.rotation3d );
-
-	if ( this.scale.x !== 1 || this.scale.y !== 1 ) {
-
-		this.matrix.scale( this.scale );
-
-	}
+	this.quaterion.setFromEuler( this.rotation3d, this.eulerOrder );
+	this.matrix.compose( this.position, this.quaternion, this.scale );
 
 	this.matrixWorldNeedsUpdate = true;
 

+ 5 - 5
test/unit/math/Quaternion.js

@@ -111,7 +111,7 @@ test( "setFromEuler/setFromRotationMatrix", function() {
 	// ensure euler conversion for Quaternion matches that of Matrix4
 	for( var i = 0; i < orders.length; i ++ ) {
 		var q = new THREE.Quaternion().setFromEuler( eulerAngles, orders[i] );
-		var m = new THREE.Matrix4().setRotationFromEuler( eulerAngles, orders[i] );
+		var m = new THREE.Matrix4().makeRotationFromEuler( eulerAngles, orders[i] );
 		var q2 = new THREE.Quaternion().setFromRotationMatrix( m );
 
 		ok( qSub( q, q2 ).length() < 0.001, "Passed!" );
@@ -161,9 +161,9 @@ test( "multiplyQuaternions/multiply", function() {
 
 	var q = new THREE.Quaternion().multiplyQuaternions( q1, q2 ).multiply( q3 );
 
-	var m1 = new THREE.Matrix4().setRotationFromEuler( angles[0], "XYZ" );
-	var m2 = new THREE.Matrix4().setRotationFromEuler( angles[1], "XYZ" );
-	var m3 = new THREE.Matrix4().setRotationFromEuler( angles[2], "XYZ" );
+	var m1 = new THREE.Matrix4().makeRotationFromEuler( angles[0], "XYZ" );
+	var m2 = new THREE.Matrix4().makeRotationFromEuler( angles[1], "XYZ" );
+	var m3 = new THREE.Matrix4().makeRotationFromEuler( angles[2], "XYZ" );
 
 	var m = new THREE.Matrix4().multiplyMatrices( m1, m2 ).multiply( m3 );
 
@@ -180,7 +180,7 @@ test( "multiplyVector3", function() {
 	for( var i = 0; i < orders.length; i ++ ) {
 		for( var j = 0; j < angles.length; j ++ ) {
 			var q = new THREE.Quaternion().setFromEuler( angles[j], orders[i] );
-			var m = new THREE.Matrix4().setRotationFromEuler( angles[j], orders[i] );
+			var m = new THREE.Matrix4().makeRotationFromEuler( angles[j], orders[i] );
 
 			var v0 = new THREE.Vector3(1, 0, 0);
 			var qv = v0.clone().applyQuaternion( q );