提交 3b2c721f 编写于 作者: T tschw

Animation: Let KeyframeTrack not require values.

上级 f3a9598a
......@@ -22,7 +22,8 @@ THREE.AnimationUtils = {
// converts an array to a specific type
convertArray: function( array, type, forceClone ) {
if ( ! forceClone && array.constructor === type ) return array;
if ( ! array ||
! forceClone && array.constructor === type ) return array;
if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
......@@ -36,6 +37,13 @@ THREE.AnimationUtils = {
},
isTypedArray: function( object ) {
return ArrayBuffer.isView( object ) &&
! ( object instanceof DataView );
},
// returns an array by which times and values can be sorted
getKeyframeOrder: function( times ) {
......
......@@ -12,8 +12,7 @@ THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
if( name === undefined ) throw new Error( "track name is undefined" );
if( times === undefined || times.length === 0 ||
values === undefined || values.length === 0 ) {
if( times === undefined || times.length === 0 ) {
throw new Error( "no keyframes in track named " + name );
......@@ -221,25 +220,27 @@ THREE.KeyframeTrack.prototype = {
},
// ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
// One could eventually ensure that all key.values in a track are all of the same type (otherwise interpolation makes no sense.)
validate: function() {
if ( this.getValueSize() % 1 !== 0 ) {
var valid = true;
throw new Error( "invalid value size for track named " + this.name );
var valueSize = this.getValueSize();
if ( valueSize - Math.floor( valueSize ) !== 0 ) {
console.error( "invalid value size in track", this );
valid = false;
}
var times = this.times;
var values = this.values;
var stride = this.getValueSize();
var times = this.times,
values = this.values,
var nKeys = times.length;
nKeys = times.length;
if( nKeys === 0 ) {
console.error( " track is empty, no keys", this );
return;
console.error( "track is empty", this );
valid = false;
}
......@@ -249,46 +250,49 @@ THREE.KeyframeTrack.prototype = {
var currTime = times[ i ];
if( currTime === undefined || currTime === null ) {
if ( Number.isNaN( currTime ) ) {
console.error( " time is null in track", this, i );
return;
console.error( "time is not a valid number", this, i, currTime );
valid = false;
break;
}
if( ( typeof currTime ) !== 'number' || Number.isNaN( currTime ) ) {
if( prevTime !== null && prevTime > currTime ) {
console.error( " time is not a valid number", this, i, currTime );
return;
console.error( "out of order keys", this, i, currTime, prevTime );
valid = false;
break;
}
var offset = i * stride;
for ( var j = offset, e = offset + stride; j !== e; ++ j ) {
prevTime = currTime;
}
var value = values[ j ];
if ( values !== undefined ) {
if( value === undefined || value === null) {
if ( THREE.AnimationUtils.isTypedArray( values ) ) {
console.error( " value is null in track", this, j, value );
return;
for ( var i = 0, n = values.length; i !== n; ++ i ) {
}
var value = values[ i ];
}
if ( Number.isNaN( value ) ) {
if( prevTime !== null && prevTime > currTime ) {
console.error( "value is not a valid number", this, i, value );
valid = false;
break;
console.error( " time is less than previous key time, out of order keys", this, i, currTime, prevTime );
return;
}
}
}
prevTime = currTime;
}
}
return this;
return valid;
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册