提交 8a9b4ab4 编写于 作者: M Mr.doob

Merge remote branch 'empaempa/master'

此差异已折叠。
......@@ -162,12 +162,11 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
// use JIT?
if ( JIThierarchy[ h ][ frame ] !== undefined ) {
if ( this.JITCompile && JIThierarchy[ h ][ frame ] !== undefined ) {
if( object instanceof THREE.Bone ) {
object.skinMatrix = JIThierarchy[ h ][ frame ];
object.skinMatrix.flattenToArrayOffset( this.root.boneMatrices, h * 16 );
object.matrixAutoUpdate = false;
object.matrixWorldNeedsUpdate = false;
......@@ -186,14 +185,18 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
// make sure so original matrix and not JIT matrix is set
if( object instanceof THREE.Bone ) {
object.skinMatrix = object.animationCache.originalMatrix;
} else {
object.matrix = object.animationCache.originalMatrix;
if ( this.JITCompile ) {
if( object instanceof THREE.Bone ) {
object.skinMatrix = object.animationCache.originalMatrix;
} else {
object.matrix = object.animationCache.originalMatrix;
}
}
......@@ -209,17 +212,24 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
// switch keys?
if ( nextKey.time < unloopedCurrentTime ) {
if ( nextKey.time <= unloopedCurrentTime ) {
// did we loop?
if ( currentTime < unloopedCurrentTime ) {
if ( currentTime <= unloopedCurrentTime ) {
if ( this.loop ) {
prevKey = this.data.hierarchy[ h ].keys[ 0 ];
nextKey = this.getNextKeyWith( type, h, 1 );
while( nextKey.time < currentTime ) {
prevKey = nextKey;
nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
}
} else {
this.stop();
......@@ -256,7 +266,7 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
if ( scale < 0 || scale > 1 ) {
console.log( "THREE.Animation.update: Warning! Scale out of bounds:" + scale );
console.log( "THREE.Animation.update: Warning! Scale out of bounds:" + scale + " on bone " + h );
scale = scale < 0 ? 0 : 1;
}
......
......@@ -118,8 +118,8 @@ THREE.AnimationHandler = (function() {
return;
// THIS SHOULD BE REMOVED WHEN LENGTH IS UPDATED TO MS IN EXPORT FORMAT!
data.length = parseInt( data.length * 1000, 10 );
data.fps *= 0.001;
//data.length = parseInt( data.length * 1000, 10 );
//data.fps *= 0.001;
// loop through all keys
......@@ -135,11 +135,7 @@ THREE.AnimationHandler = (function() {
// THIS SHOULD BE REMOVED WHEN LENGTH IS UPDATED TO MS IN EXPORT FORMAT!
data.hierarchy[ h ].keys[ k ].time = parseInt( data.hierarchy[ h ].keys[ k ].time * 1000, 10 );
// set index
data.hierarchy[ h ].keys[ k ].index = k;
//data.hierarchy[ h ].keys[ k ].time = parseInt( data.hierarchy[ h ].keys[ k ].time * 1000, 10 );
// create quaternions
......@@ -151,13 +147,37 @@ THREE.AnimationHandler = (function() {
data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion( quat[0], quat[1], quat[2], quat[3] );
}
}
// remove all keys that are on the same time
for( var k = 1; k < data.hierarchy[ h ].keys.length; k++ ) {
if( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
data.hierarchy[ h ].keys.splice( k, 1 );
k--;
}
}
// set index
for( var k = 1; k < data.hierarchy[ h ].keys.length; k++ ) {
data.hierarchy[ h ].keys[ k ].index = k;
}
}
// JIT
var lengthInFrames = parseInt( data.length * data.fps * 0.001, 10 );
var lengthInFrames = parseInt( data.length * data.fps, 10 );
data.JIT = {};
data.JIT.hierarchy = [];
......
......@@ -72,9 +72,24 @@ THREE.Matrix4.prototype = {
var x = THREE.Matrix4.__v1, y = THREE.Matrix4.__v2, z = THREE.Matrix4.__v3;
z.sub( eye, center ).normalize();
if ( z.length() === 0 ) {
z.z = 1;
}
x.cross( up, z ).normalize();
if ( x.length() === 0 ) {
z.x += 0.0001;
x.cross( up, z ).normalize();
}
y.cross( z, x ).normalize();
this.n11 = x.x; this.n12 = y.x; this.n13 = z.x;
this.n21 = x.y; this.n22 = y.y; this.n23 = z.y;
this.n31 = x.z; this.n32 = y.z; this.n33 = z.z;
......@@ -604,8 +619,10 @@ THREE.Matrix4.makeInvert3x3 = function ( m1 ) {
idet;
// no inverse
if (det == 0) throw "matrix not invertible";
if (det == 0) {
throw "matrix not invertible";
}
idet = 1.0 / det;
m33m[ 0 ] = idet * a11; m33m[ 1 ] = idet * a21; m33m[ 2 ] = idet * a31;
......
......@@ -17,7 +17,6 @@ THREE.SkinnedMesh = function( geometry, materials ) {
// init bones
this.identityMatrix = new THREE.Matrix4();
this.bones = [];
this.boneMatrices = [];
......@@ -38,6 +37,7 @@ THREE.SkinnedMesh = function( geometry, materials ) {
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 ) {
......@@ -139,6 +139,19 @@ THREE.SkinnedMesh.prototype.update = function ( parentMatrixWorld, forceUpdate,
}
// flatten to array
var b, bl = this.bones.length;
ba = this.bones;
bm = this.boneMatrices;
for ( b = 0; b < bl; b++ ) {
ba[ b ].skinMatrix.flattenToArrayOffset( bm, b * 16 );
}
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册