Răsfoiți Sursa

More Rotation/Euler breakage fixed.

Mr.doob 12 ani în urmă
părinte
comite
6c49f3ce85
2 a modificat fișierele cu 44 adăugiri și 17 ștergeri
  1. 43 16
      src/math/Rotation.js
  2. 1 1
      src/math/Vector3.js

+ 43 - 16
src/math/Rotation.js

@@ -5,9 +5,11 @@
 
 
 THREE.Rotation = function ( quaternion ) {
 THREE.Rotation = function ( quaternion ) {
 
 
-	this.euler = new THREE.Euler().setFromQuaternion( quaternion );
+	this.euler = new THREE.Euler();
 	this.quaternion = quaternion;
 	this.quaternion = quaternion;
 
 
+	this.updateEuler();
+
 };
 };
 
 
 THREE.Rotation.prototype = {
 THREE.Rotation.prototype = {
@@ -21,7 +23,7 @@ THREE.Rotation.prototype = {
 	set x ( value ) {
 	set x ( value ) {
 
 
 		this.euler.x = value;
 		this.euler.x = value;
-		this.quaternion.setFromEuler( this.euler );
+		this.updateQuaternion();
 
 
 	},
 	},
 
 
@@ -34,7 +36,7 @@ THREE.Rotation.prototype = {
 	set y ( value ) {
 	set y ( value ) {
 
 
 		this.euler.y = value;
 		this.euler.y = value;
-		this.quaternion.setFromEuler( this.euler );
+		this.updateQuaternion();
 
 
 	},
 	},
 
 
@@ -47,7 +49,7 @@ THREE.Rotation.prototype = {
 	set z ( value ) {
 	set z ( value ) {
 
 
 		this.euler.z = value;
 		this.euler.z = value;
-		this.quaternion.setFromEuler( this.euler );
+		this.updateQuaternion();
 
 
 	},
 	},
 
 
@@ -59,7 +61,7 @@ THREE.Rotation.prototype = {
 		this.euler.y = y;
 		this.euler.y = y;
 		this.euler.z = z;
 		this.euler.z = z;
 
 
-		this.quaternion.setFromEuler( this.euler );
+		this.updateQuaternion();
 
 
 		return this;
 		return this;
 
 
@@ -67,7 +69,8 @@ THREE.Rotation.prototype = {
 
 
 	setX: function ( x ) {
 	setX: function ( x ) {
 
 
-		this.x = x;
+		this.euler.x = x;
+		this.updateQuaternion();
 
 
 		return this;
 		return this;
 
 
@@ -75,7 +78,8 @@ THREE.Rotation.prototype = {
 
 
 	setY: function ( y ) {
 	setY: function ( y ) {
 
 
-		this.y = y;
+		this.euler.y = y;
+		this.updateQuaternion();
 
 
 		return this;
 		return this;
 
 
@@ -83,25 +87,33 @@ THREE.Rotation.prototype = {
 
 
 	setZ: function ( z ) {
 	setZ: function ( z ) {
 
 
-		this.z = z;
+		this.euler.z = z;
+		this.updateQuaternion();
 
 
 		return this;
 		return this;
 
 
 	},
 	},
 
 
-	setFromRotationMatrix: function ( m, order ) {
+	setEulerFromRotationMatrix: function ( matrix, order ) {
 
 
-		this.euler.setFromRotationMatrix( m, order );
-		this.quaternion.setFromEuler( this.euler );
+		console.warn( 'DEPRECATED: Rotation\'s .setEulerFromRotationMatrix() has been renamed to .setFromRotationMatrix().' );
+		return this.setFromRotationMatrix( matrix, order );
+
+	},
+
+	setFromRotationMatrix: function ( matrix, order ) {
+
+		this.euler.setFromRotationMatrix( matrix, order );
+		this.updateQuaternion();
 
 
 		return this;
 		return this;
 
 
 	},
 	},
 
 
-	setFromQuaternion: function ( q, order ) {
+	setFromQuaternion: function ( quaternion, order ) {
 
 
-		this.euler.setFromQuaternion( q, order );
-		this.quaternion.copy( q );
+		this.euler.setFromQuaternion( quaternion, order );
+		this.quaternion.copy( quaternion );
 
 
 		return this;
 		return this;
 
 
@@ -110,7 +122,7 @@ THREE.Rotation.prototype = {
 	copy: function ( rotation ) {
 	copy: function ( rotation ) {
 
 
 		this.euler.copy( rotation.euler );
 		this.euler.copy( rotation.euler );
-		this.quaternion.setFromEuler( this.euler );
+		this.quaternion.copy( rotation.quaternion );
 
 
 		return this;
 		return this;
 
 
@@ -119,7 +131,6 @@ THREE.Rotation.prototype = {
 	fromArray: function ( array ) {
 	fromArray: function ( array ) {
 
 
 		this.euler.fromArray( array );
 		this.euler.fromArray( array );
-		this.quaternion.setFromEuler( this.euler );
 
 
 		return this;
 		return this;
 
 
@@ -129,6 +140,22 @@ THREE.Rotation.prototype = {
 
 
 		return this.euler.toArray();
 		return this.euler.toArray();
 
 
+	},
+
+	updateEuler: function () {
+
+		this.euler.setFromQuaternion( this.quaternion );
+
+		return this;
+
+	},
+
+	updateQuaternion: function () {
+
+		this.quaternion.setFromEuler( this.euler );
+
+		return this;
+
 	}
 	}
 
 
 };
 };

+ 1 - 1
src/math/Vector3.js

@@ -525,7 +525,7 @@ THREE.Vector3.prototype = {
 	setEulerFromQuaternion: function ( q, order ) {
 	setEulerFromQuaternion: function ( q, order ) {
 
 
 		console.error( "REMOVED: Vector3\'s setEulerFromQuaternion: has been removed in favor of Euler.setFromQuaternion(), please update your code.");
 		console.error( "REMOVED: Vector3\'s setEulerFromQuaternion: has been removed in favor of Euler.setFromQuaternion(), please update your code.");
-		
+
 	},
 	},
 
 
 	getPositionFromMatrix: function ( m ) {
 	getPositionFromMatrix: function ( m ) {