提交 7504c8a0 编写于 作者: W WestLangley

Object3D.lookAt(): support rotated parents

上级 b059cd9a
......@@ -303,35 +303,51 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
lookAt: function () {
// This method does not support objects with rotated and/or translated parent(s)
// This method does not support objects having non-uniformly-scaled parent(s)
var q1 = new Quaternion();
var m1 = new Matrix4();
var vector = new Vector3();
var target = new Vector3();
var position = new Vector3();
return function lookAt( x, y, z ) {
if ( x.isVector3 ) {
vector.copy( x );
target.copy( x );
} else {
vector.set( x, y, z );
target.set( x, y, z );
}
var parent = this.parent;
this.updateWorldMatrix( true, false );
position.setFromMatrixPosition( this.matrixWorld );
if ( this.isCamera ) {
m1.lookAt( this.position, vector, this.up );
m1.lookAt( position, target, this.up );
} else {
m1.lookAt( vector, this.position, this.up );
m1.lookAt( target, position, this.up );
}
this.quaternion.setFromRotationMatrix( m1 );
if ( parent ) {
m1.extractRotation( parent.matrixWorld );
q1.setFromRotationMatrix( m1 );
this.quaternion.premultiply( q1.inverse() );
}
};
}(),
......@@ -615,6 +631,44 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
},
updateWorldMatrix: function ( updateParents, updateChildren ) {
var parent = this.parent;
if ( updateParents === true && parent !== null ) {
parent.updateWorldMatrix( true, false );
}
if ( this.matrixAutoUpdate ) this.updateMatrix();
if ( this.parent === null ) {
this.matrixWorld.copy( this.matrix );
} else {
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
}
// update children
if ( updateChildren === true ) {
var children = this.children;
for ( var i = 0, l = children.length; i < l; i ++ ) {
children[ i ].updateWorldMatrix( false, true );
}
}
},
toJSON: function ( meta ) {
// meta is a string when called from JSON.stringify
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册