未验证 提交 bc44c95d 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #14044 from mquander/updatematrixworld-microoptimize

Make Matrix4.compose more efficient
...@@ -263,12 +263,12 @@ Object.assign( Matrix4.prototype, { ...@@ -263,12 +263,12 @@ Object.assign( Matrix4.prototype, {
} }
// last column // bottom row
te[ 3 ] = 0; te[ 3 ] = 0;
te[ 7 ] = 0; te[ 7 ] = 0;
te[ 11 ] = 0; te[ 11 ] = 0;
// bottom row // last column
te[ 12 ] = 0; te[ 12 ] = 0;
te[ 13 ] = 0; te[ 13 ] = 0;
te[ 14 ] = 0; te[ 14 ] = 0;
...@@ -278,42 +278,18 @@ Object.assign( Matrix4.prototype, { ...@@ -278,42 +278,18 @@ Object.assign( Matrix4.prototype, {
}, },
makeRotationFromQuaternion: function ( q ) { makeRotationFromQuaternion: function () {
var te = this.elements;
var x = q._x, y = q._y, z = q._z, w = q._w;
var x2 = x + x, y2 = y + y, z2 = z + z;
var xx = x * x2, xy = x * y2, xz = x * z2;
var yy = y * y2, yz = y * z2, zz = z * z2;
var wx = w * x2, wy = w * y2, wz = w * z2;
te[ 0 ] = 1 - ( yy + zz );
te[ 4 ] = xy - wz;
te[ 8 ] = xz + wy;
te[ 1 ] = xy + wz; var zero = new Vector3( 0, 0, 0 );
te[ 5 ] = 1 - ( xx + zz ); var one = new Vector3( 1, 1, 1 );
te[ 9 ] = yz - wx;
te[ 2 ] = xz - wy; return function makeRotationFromQuaternion( q ) {
te[ 6 ] = yz + wx;
te[ 10 ] = 1 - ( xx + yy );
// last column return this.compose( zero, q, one );
te[ 3 ] = 0;
te[ 7 ] = 0;
te[ 11 ] = 0;
// bottom row
te[ 12 ] = 0;
te[ 13 ] = 0;
te[ 14 ] = 0;
te[ 15 ] = 1;
return this; };
}, }(),
lookAt: function () { lookAt: function () {
...@@ -754,11 +730,37 @@ Object.assign( Matrix4.prototype, { ...@@ -754,11 +730,37 @@ Object.assign( Matrix4.prototype, {
compose: function ( position, quaternion, scale ) { compose: function ( position, quaternion, scale ) {
this.makeRotationFromQuaternion( quaternion ); var te = this.elements;
this.scale( scale );
this.setPosition( position );
return this; var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
var x2 = x + x, y2 = y + y, z2 = z + z;
var xx = x * x2, xy = x * y2, xz = x * z2;
var yy = y * y2, yz = y * z2, zz = z * z2;
var wx = w * x2, wy = w * y2, wz = w * z2;
var sx = scale.x, sy = scale.y, sz = scale.z;
te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
te[ 1 ] = ( xy + wz ) * sx;
te[ 2 ] = ( xz - wy ) * sx;
te[ 3 ] = 0;
te[ 4 ] = ( xy - wz ) * sy;
te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
te[ 6 ] = ( yz + wx ) * sy;
te[ 7 ] = 0;
te[ 8 ] = ( xz + wy ) * sz;
te[ 9 ] = ( yz - wx ) * sz;
te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
te[ 11 ] = 0;
te[ 12 ] = position.x;
te[ 13 ] = position.y;
te[ 14 ] = position.z;
te[ 15 ] = 1;
return this;
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册