提交 276e9da1 编写于 作者: B Ben Houston

add THREE.Rotation and remove Object3D.useQuaternion (as we always use...

add THREE.Rotation and remove Object3D.useQuaternion (as we always use quaternion now.)  Following recommendation discussed here: https://github.com/mrdoob/three.js/issues/3404#issuecomment-17262516
上级 5edec359
......@@ -19,8 +19,6 @@ THREE.FlyControls = function ( object, domElement ) {
// disable default target object behavior
this.object.useQuaternion = true;
// internals
this.tmpQuaternion = new THREE.Quaternion();
......
......@@ -868,7 +868,6 @@ THREE.ColladaLoader = function () {
var props = node.matrix.decompose();
obj.position = props[ 0 ];
obj.quaternion = props[ 1 ];
obj.useQuaternion = true;
obj.scale = props[ 2 ];
if ( options.centerGeometry && obj.geometry ) {
......
......@@ -27,15 +27,7 @@ THREE.Camera.prototype.lookAt = function () {
m1.lookAt( this.position, vector, this.up );
if ( this.useQuaternion === true ) {
this.quaternion.setFromRotationMatrix( m1 );
} else {
this.rotation.setFromRotationMatrix( m1, this.rotation.Order );
}
this.quaternion.setFromRotationMatrix( m1 );
};
......
......@@ -17,9 +17,12 @@ THREE.Object3D = function () {
this.up = new THREE.Vector3( 0, 1, 0 );
this.position = new THREE.Vector3();
this.rotation = new THREE.Euler();
this.quaternion = new THREE.Quaternion();
this.scale = new THREE.Vector3( 1, 1, 1 );
// for backwards compatibility (maps changes to this.rotation onto this.quaternion)
this.rotation = new THREE.Rotation( this.quaternion );
this.renderDepth = null;
this.rotationAutoUpdate = true;
......@@ -30,9 +33,6 @@ THREE.Object3D = function () {
this.matrixAutoUpdate = true;
this.matrixWorldNeedsUpdate = true;
this.quaternion = new THREE.Quaternion();
this.useQuaternion = false;
this.visible = true;
this.castShadow = false;
......@@ -68,15 +68,7 @@ THREE.Object3D.prototype = {
m1.extractRotation( this.matrix );
if ( this.useQuaternion === true ) {
this.quaternion.setFromRotationMatrix( m1 );
} else {
this.rotation.setFromRotationMatrix( m1, this.rotation.order );
}
this.quaternion.setFromRotationMatrix( m1 );
}
......@@ -94,18 +86,7 @@ THREE.Object3D.prototype = {
q1.setFromAxisAngle( axis, angle );
if ( this.useQuaternion === true ) {
this.quaternion.multiply( q1 );
} else {
q2.setFromEuler( this.rotation );
q2.multiply( q1 );
this.rotation.setFromQuaternion( q2, this.rotation.order );
}
this.quaternion.multiply( q1 );
return this;
......@@ -124,15 +105,7 @@ THREE.Object3D.prototype = {
v1.copy( axis );
if ( this.useQuaternion === true ) {
v1.applyQuaternion( this.quaternion );
} else {
v1.applyEuler( this.rotation );
}
v1.applyQuaternion( this.quaternion );
this.position.add( v1.multiplyScalar( distance ) );
......@@ -213,15 +186,7 @@ THREE.Object3D.prototype = {
m1.lookAt( vector, this.position, this.up );
if ( this.useQuaternion === true ) {
this.quaternion.setFromRotationMatrix( m1 );
} else {
this.rotation.setFromRotationMatrix( m1, this.rotation.order );
}
this.quaternion.setFromRotationMatrix( m1 );
};
......@@ -393,17 +358,7 @@ THREE.Object3D.prototype = {
updateMatrix: function () {
// if we are not using a quaternion directly, convert Euler rotation to this.quaternion.
if ( this.useQuaternion === false ) {
this.matrix.makeFromPositionEulerScale( this.position, this.rotation, this.scale );
} else {
this.matrix.makeFromPositionQuaternionScale( this.position, this.quaternion, this.scale );
}
this.matrix.makeFromPositionQuaternionScale( this.position, this.quaternion, this.scale );
this.matrixWorldNeedsUpdate = true;
......@@ -450,7 +405,8 @@ THREE.Object3D.prototype = {
object.up.copy( this.up );
object.position.copy( this.position );
if ( object.rotation instanceof THREE.Euler ) object.rotation.copy( this.rotation ); // because of Sprite madness
object.quaternion.copy( this.quaternion );
object.rotation = new THREE.Rotation( object.quaternion );
object.scale.copy( this.scale );
object.renderDepth = this.renderDepth;
......@@ -463,9 +419,6 @@ THREE.Object3D.prototype = {
object.matrixAutoUpdate = this.matrixAutoUpdate;
object.matrixWorldNeedsUpdate = this.matrixWorldNeedsUpdate;
object.quaternion.copy( this.quaternion );
object.useQuaternion = this.useQuaternion;
object.visible = this.visible;
object.castShadow = this.castShadow;
......
......@@ -41,12 +41,6 @@ THREE.Animation.prototype.play = function ( loop, startTimeMS ) {
object = this.hierarchy[ h ];
if ( this.interpolationType !== THREE.AnimationHandler.CATMULLROM_FORWARD ) {
object.useQuaternion = true;
}
object.matrixAutoUpdate = true;
if ( object.animationCache === undefined ) {
......
......@@ -75,7 +75,6 @@ THREE.KeyFrameAnimation.prototype.play = function( loop, startTimeMS ) {
object = this.hierarchy[ h ];
node = this.data.hierarchy[ h ];
object.useQuaternion = true;
if ( node.animationCache === undefined ) {
......
......@@ -23,8 +23,6 @@ THREE.ArrowHelper = function ( dir, origin, length, hex ) {
this.position = origin;
this.useQuaternion = true;
var lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ) );
lineGeometry.vertices.push( new THREE.Vector3( 0, 1, 0 ) );
......
......@@ -346,7 +346,6 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( quat ) {
object.quaternion.fromArray( quat );
object.useQuaternion = true;
} else {
......@@ -437,8 +436,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( quat !== undefined ) {
camera.quaternion.fromArray( quat );
camera.useQuaternion = true;
} else if ( rot !== undefined ) {
camera.rotation.fromArray( rot );
......@@ -466,8 +464,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( quat ) {
object.quaternion.fromArray( quat );
object.useQuaternion = true;
} else {
object.rotation.fromArray( rot );
......@@ -549,8 +546,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( q ) {
node.quaternion.fromArray( q );
node.useQuaternion = true;
} else {
node.rotation.fromArray( r );
......
/**
* @author mrdoob / http://mrdoob.com/
* @author bhouston / http://exocortex.com/
*/
THREE.Rotation = function ( quaternion ) {
this.euler = new THREE.Euler();
this.quaternion = quaternion;
};
THREE.Rotation.prototype = {
get x () {
return this.euler.x;
},
set x ( value ) {
this.euler.x = value;
this.quaternion.setFromEuler( this.euler );
},
get y () {
return this.euler.y;
},
set y ( value ) {
this.euler.y = value;
this.quaternion.setFromEuler( this.euler );
},
get z () {
return this.euler.z;
},
set z ( value ) {
this.euler.z = value;
this.quaternion.setFromEuler( this.euler );
},
set: function ( x, y, z ) {
this.euler.x = x;
this.euler.y = y;
this.euler.z = z;
this.quaternion.setFromEuler( this.euler );
},
copy: function ( rotation ) {
this.quaternion.copy( rotation.quaternion );
},
fromArray: function() {
this.euler.fromArray( array );
this.quaternion.setFromEuler( this.euler );
},
toArray: function () {
return this.euler.toArray();
}
};
\ No newline at end of file
......@@ -35,8 +35,7 @@ THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
bone.name = gbone.name;
bone.position.set( p[0], p[1], p[2] );
bone.quaternion.set( q[0], q[1], q[2], q[3] );
bone.useQuaternion = true;
if ( s !== undefined ) {
bone.scale.set( s[0], s[1], s[2] );
......
......@@ -6,6 +6,7 @@
"src/math/Vector3.js",
"src/math/Vector4.js",
"src/math/Euler.js",
"src/math/Rotation.js",
"src/math/Line3.js",
"src/math/Box2.js",
"src/math/Box3.js",
......
......@@ -5,6 +5,8 @@
"src/math/Vector2.js",
"src/math/Vector3.js",
"src/math/Vector4.js",
"src/math/Euler.js",
"src/math/Rotation.js",
"src/math/Box2.js",
"src/math/Box3.js",
"src/math/Matrix3.js",
......
......@@ -6,6 +6,7 @@
"src/math/Vector3.js",
"src/math/Vector4.js",
"src/math/Euler.js",
"src/math/Rotation.js",
"src/math/Line3.js",
"src/math/Box2.js",
"src/math/Box3.js",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册