提交 b36cf734 编写于 作者: A alteredq

Removed dirty flag from Quaternion.

There don't seem to be any effects on performance (though I'm not sure this was actually used in any example/test code path - so far quaternions are used just for animation interpolation and even there they were always dirty, and also just updated during JIT baking).

Also some more code cleanup - no need for Mesh to have own "update" as now it was exactly the same as its parent Object3D.
上级 6c84868d
此差异已折叠。
此差异已折叠。
......@@ -28,10 +28,10 @@ THREE.Animation = function( root, data ) {
for( var b = 0; b < this.root.bones.length; b++ )
this.hierarchy.push( this.root.bones[ b ] );
}
else {
} else {
// parse hierarchy and match against animation (somehow)
}
}
......@@ -147,22 +147,21 @@ THREE.Animation.prototype.update = function( time ) {
}
frame = Math.min( parseInt( currentTime * this.data.fps ), parseInt( this.data.length * this.data.fps ));
frame = Math.min( parseInt( currentTime * this.data.fps ), parseInt( this.data.length * this.data.fps ) );
// update
for( var h = 0, hl = this.hierarchy.length; h < hl; h++ )
{
for( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
object = this.hierarchy[ h ];
if( JIThierarchy[ h ][ frame ] !== undefined ) {
object.skinMatrix = JIThierarchy[ h ][ frame ];
object.matrixAutoUpdate = false;
object.skinMatrix = JIThierarchy[ h ][ frame ];
object.matrixAutoUpdate = false;
object.matrixNeedsUpdate = false;
//object.skinMatrix.flattenToArray( this.root.boneMatrices[ h ] );
object.skinMatrix.flattenToArrayOffset( this.root.boneMatrices, h * 16 );
}
......@@ -177,7 +176,7 @@ THREE.Animation.prototype.update = function( time ) {
var nextKey = object.nextKey[ type ];
// switch keys?
if( nextKey.time < unloopedCurrentTime ) {
// did we loop?
......@@ -202,6 +201,7 @@ THREE.Animation.prototype.update = function( time ) {
prevKey = nextKey;
nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
}
while( nextKey.time < currentTime )
}
......@@ -244,8 +244,11 @@ THREE.Animation.prototype.update = function( time ) {
vector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
}
}
}
}
}
......@@ -272,8 +275,7 @@ THREE.Animation.prototype.updateObject = function( h, currentTime, unloopedCurre
}
THREE.Animation.prototype.getNextKeyWith = function( type, h, key ) {
......
......@@ -67,10 +67,11 @@ THREE.AnimationHandler = (function() {
// create quaternions
if( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
!(data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion )) {
!( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
var quat = data.hierarchy[ h ].keys[ k ].rot;
data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion( quat[0], quat[1], quat[2], quat[3] );
}
}
}
......
......@@ -2,46 +2,23 @@
* @author mikael emtinger / http://gomo.se/
*/
THREE.Quaternion = function( _x, _y, _z, _w ) {
THREE.Quaternion = function( x, y, z, w ) {
this.x = _x || 0;
this.y = _y || 0;
this.z = _z || 0;
this.w = _w !== undefined ? _w : 1;
this.api = {
isDirty: false,
that: this,
get x() { return this.that.x; },
get y() { return this.that.y; },
get z() { return this.that.z; },
get w() { return this.that.w; },
set x( value ) { this.that.x = value; this.isDirty = true; },
set y( value ) { this.that.y = value; this.isDirty = true; },
set z( value ) { this.that.z = value; this.isDirty = true; },
set w( value ) { this.that.w = value; this.isDirty = true; }
};
this.api.__proto__ = THREE.Quaternion.prototype;
return this.api;
this.x = x || 0;
this.y = y || 0;
this.z = z || 0;
this.w = w !== undefined ? w : 1;
};
THREE.Quaternion.prototype.set = function( x, y, z, w ) {
var quat = this.that;
quat.x = x;
quat.y = y;
quat.z = z;
quat.w = w;
this.x = x;
this.y = y;
this.z = z;
this.w = w;
this.isDirty = true;
return this;
};
......@@ -61,88 +38,67 @@ THREE.Quaternion.prototype.setFromEuler = function( vec3 ) {
c3 = Math.cos( x ),
s3 = Math.sin( x ),
c1c2 = c1 * c2,
s1s2 = s1 * s2,
quat = this.that;
s1s2 = s1 * s2;
quat.w = c1c2 * c3 - s1s2 * s3;
quat.x = c1c2 * s3 + s1s2 * c3;
quat.y = s1 * c2 * c3 + c1 * s2 * s3;
quat.z = c1 * s2 * c3 - s1 * c2 * s3;
this.w = c1c2 * c3 - s1s2 * s3;
this.x = c1c2 * s3 + s1s2 * c3;
this.y = s1 * c2 * c3 + c1 * s2 * s3;
this.z = c1 * s2 * c3 - s1 * c2 * s3;
this.isDirty = true;
return this;
};
THREE.Quaternion.prototype.calculateW = function() {
var quat = this.that,
x = quat.x,
y = quat.y,
z = quat.z;
THREE.Quaternion.prototype.calculateW = function() {
quat.w = -Math.sqrt( Math.abs( 1.0 - x*x - y*y - z*z ));
this.w = -Math.sqrt( Math.abs( 1.0 - this.x * this.x - this.y * this.y - this.z * this.z ) );
this.isDirty = true;
return this;
};
THREE.Quaternion.prototype.inverse = function() {
var quat = this.that;
quat.x *= -1;
quat.y *= -1;
quat.z *= -1;
this.isDirty = true;
this.x *= -1;
this.y *= -1;
this.z *= -1;
return this;
};
THREE.Quaternion.prototype.length = function() {
var quat = this.that;
return Math.sqrt( quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w );
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
};
THREE.Quaternion.prototype.normalize = function() {
var quat = this.that,
x = quat.x,
y = quat.y,
z = quat.z,
w = quat.w;
var len = Math.sqrt( x*x + y*y + z*z + w*w );
var len = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
if ( len == 0 ) {
quat.x = 0;
quat.y = 0;
quat.z = 0;
quat.w = 0;
this.x = 0;
this.y = 0;
this.z = 0;
this.w = 0;
this.isDirty = true;
return this;
} else {
len = 1 / len;
this.x = this.x * len;
this.y = this.y * len;
this.z = this.z * len;
this.w = this.w * len;
}
len = 1 / len;
quat.x = x * len;
quat.y = y * len;
quat.z = z * len;
quat.w = w * len;
this.isDirty = true;
return this;
};
......@@ -150,17 +106,14 @@ THREE.Quaternion.prototype.normalize = function() {
THREE.Quaternion.prototype.multiplySelf = function( quat2 ) {
var quat = this.that;
qax = quat.x, qay = quat.y, qaz = quat.z, qaw = quat.w,
var qax = this.x, qay = this.y, qaz = this.z, qaw = this.w,
qbx = quat2.x, qby = quat2.y, qbz = quat2.z, qbw = quat2.w;
quat.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
quat.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
quat.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
quat.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
this.isDirty = true;
return this;
};
......@@ -170,9 +123,8 @@ THREE.Quaternion.prototype.multiplyVector3 = function( vec, dest ) {
if( !dest ) { dest = vec; }
var quat = this.that,
x = vec.x, y = vec.y, z = vec.z,
qx = quat.x, qy = quat.y, qz = quat.z, qw = quat.w;
var x = vec.x, y = vec.y, z = vec.z,
qx = this.x, qy = this.y, qz = this.z, qw = this.w;
// calculate quat * vec
......
......@@ -33,44 +33,5 @@ THREE.Mesh.prototype = new THREE.Object3D();
THREE.Mesh.prototype.constructor = THREE.Mesh;
THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
/*
* Update
*/
THREE.Mesh.prototype.update = function( parentGlobalMatrix, forceUpdate, camera ) {
// visible?
if( this.visible ) {
// update local
if( this.matrixAutoUpdate )
forceUpdate |= this.updateMatrix();
// update global
if( forceUpdate || this.matrixNeedsUpdate ) {
if( parentGlobalMatrix )
this.globalMatrix.multiply( parentGlobalMatrix, this.localMatrix );
else
this.globalMatrix.copy( this.localMatrix );
this.matrixNeedsUpdate = false;
forceUpdate = true;
}
// update children
for( var i = 0; i < this.children.length; i++ )
this.children[ i ].update( this.globalMatrix, forceUpdate, camera );
}
}
......@@ -54,11 +54,16 @@ THREE.Object3D.prototype.update = function( parentGlobalMatrix, forceUpdate, cam
if( forceUpdate || this.matrixNeedsUpdate ) {
if( parentGlobalMatrix )
if( parentGlobalMatrix ) {
this.globalMatrix.multiply( parentGlobalMatrix, this.localMatrix );
else
} else {
this.globalMatrix.copy( this.localMatrix );
}
this.matrixNeedsUpdate = false;
forceUpdate = true;
......@@ -94,12 +99,7 @@ THREE.Object3D.prototype.updateMatrix = function() {
if( this.useQuaternion ) {
if( this.quaternion.isDirty ) {
this.localMatrix.setRotationFromQuaternion( this.quaternion );
this.quaternion.isDirty = false;
}
this.localMatrix.setRotationFromQuaternion( this.quaternion );
// update rotation
......
......@@ -1353,8 +1353,9 @@ THREE.WebGLRenderer = function ( parameters ) {
material.program = buildProgram( material.fragment_shader, material.vertex_shader, parameters );
identifiers = [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition',
'cameraInverseMatrix', 'uBoneGlobalMatrices'
'cameraInverseMatrix', 'boneGlobalMatrices'
];
for( u in material.uniforms ) {
identifiers.push(u);
......@@ -2471,18 +2472,7 @@ THREE.WebGLRenderer = function ( parameters ) {
function loadUniformsSkinning( uniforms, object ) {
_gl.uniformMatrix4fv( uniforms.cameraInverseMatrix, false, _cameraInverseMatrixArray );
/*
var i, l = object.boneMatrices.length;
for( i = 0; i < l; i++ ) {
//_gl.uniformMatrix4fv( uniforms[ "uBoneGlobalMatrices[" + i + "]" ], false, object.boneMatrices[ i ]() );
_gl.uniformMatrix4fv( uniforms[ "uBoneGlobalMatrices[" + i + "]" ], false, object.boneMatrices[ i ] );
}
*/
_gl.uniformMatrix4fv( uniforms[ "uBoneGlobalMatrices" ], false, object.boneMatrices );
_gl.uniformMatrix4fv( uniforms.boneGlobalMatrices, false, object.boneMatrices );
};
......@@ -3372,7 +3362,7 @@ THREE.Snippets = {
"#ifdef USE_SKINNING",
"uniform mat4 uBoneGlobalMatrices[20];",
"uniform mat4 boneGlobalMatrices[20];",
"#endif"
......@@ -3382,8 +3372,8 @@ THREE.Snippets = {
"#ifdef USE_SKINNING",
"gl_Position = ( uBoneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;",
"gl_Position += ( uBoneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;",
"gl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;",
"gl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;",
// this doesn't work, no idea why
//"gl_Position = projectionMatrix * cameraInverseMatrix * objectMatrix * gl_Position;",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册