提交 84a94233 编写于 作者: B Ben Houston

improve keyframe track parsing to be more flexible.

上级 e39745f8
......@@ -8,6 +8,7 @@
THREE.KeyframeTrack = function ( name, keys ) {
if( name === undefined ) throw new Error( "track name is undefined" );
if( keys === undefined || keys.length === 0 ) throw new Error( "no keys in track named " + name );
this.name = name;
......@@ -16,7 +17,6 @@ THREE.KeyframeTrack = function ( name, keys ) {
// the index of the last result, used as a starting point for local search.
this.lastIndex = 0;
this.sort();
this.validate();
this.optimize();
};
......@@ -133,7 +133,8 @@ THREE.KeyframeTrack.prototype = {
},
// sort in ascending order
/* NOTE: This is commented out because we really shouldn't have to handle unsorted key lists
Tracks with out of order keys should be considered to be invalid. - bhouston
sort: function() {
function keyComparator(key0, key1) {
......@@ -148,8 +149,7 @@ 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.)
......@@ -238,33 +238,41 @@ THREE.KeyframeTrack.prototype = {
};
THREE.KeyframeTrack.parse( json ) {
THREE.KeyframeTrack.GetTrackTypeForValue = function( value ) {
switch( typeof value ) {
case "object": {
if( value.lerp ) {
if( json.type === undefined ) throw new Error( "track type undefined, can not parse" );
return THREE.VectorKeyframeTrack;
var trackType = THREE.KeyframeTrack.GetTrackTypeForTypeName( json.type );
}
if( value.slerp ) {
return trackType.parse( json );
return THREE.QuaternionKeyframeTrack;
};
}
break;
}
case "number": {
THREE.KeyframeTrack.GetTrackTypeForTypeName = function( typeName ) {
switch( typeName.toLower() ) {
case "vector":
case "vector2":
case "vector3":
case "vector4":
return THREE.VectorKeyframeTrack;
case "quaternion":
return THREE.QuaternionKeyframeTrack;
case "integer":
case "scalar":
case "double":
case "float":
case "number":
return THREE.NumberKeyframeTrack;
}
case "boolean": {
case "bool":
case "boolean":
return THREE.BooleanKeyframeTrack;
}
case "string": {
case "string":
return THREE.StringKeyframeTrack;
}
};
throw new Error( "Unsupported value type" );
throw new Error( "Unsupported typeName: " + typeName );
};
\ No newline at end of file
......@@ -56,9 +56,9 @@ THREE.BooleanKeyframeTrack.prototype.clone = function() {
};
THREE.BooleanKeyframeTrack.parse = function( name, jsonKeys ) {
THREE.BooleanKeyframeTrack.parse = function( json ) {
return new THREE.BooleanKeyframeTrack( name, jsonKeys );
return new THREE.BooleanKeyframeTrack( json.name, json.keys );
};
\ No newline at end of file
......@@ -56,20 +56,19 @@ THREE.ColorKeyframeTrack.prototype.clone = function() {
};
THREE.ColorKeyframeTrack.parse = function( name, jsonKeys ) {
THREE.ColorKeyframeTrack.parse = function( json ) {
var keys = [];
for( var i = 0; i < jsonKeys.length; i ++ ) {
var jsonKey = jsonKeys[i];
var key = {
for( var i = 0; i < json.keys.length; i ++ ) {
var jsonKey = json.keys[i];
keys.push( {
value: new THREE.Color().fromArray( jsonKey.value ),
time: jsonKey.time
};
keys.push( key );
} );
}
return new THREE.ColorKeyframeTrack( name, keys );
return new THREE.ColorKeyframeTrack( json.name, keys );
};
\ No newline at end of file
......@@ -56,9 +56,9 @@ THREE.NumberKeyframeTrack.prototype.clone = function() {
};
THREE.NumberKeyframeTrack.parse = function( name, jsonKeys ) {
THREE.NumberKeyframeTrack.parse = function( json ) {
return new THREE.NumberKeyframeTrack( name, jsonKeys );
return new THREE.NumberKeyframeTrack( json.name, json.keys );
};
\ No newline at end of file
......@@ -68,20 +68,19 @@ THREE.QuaternionKeyframeTrack.prototype.clone = function() {
};
THREE.QuaternionKeyframeTrack.parse = function( name, jsonKeys ) {
THREE.QuaternionKeyframeTrack.parse = function( json ) {
var keys = [];
for( var i = 0; i < jsonKeys.length; i ++ ) {
var jsonKey = jsonKeys[i];
var key = {
for( var i = 0; i < json.keys.length; i ++ ) {
var jsonKey = json.keys[i];
keys.push( {
value: new THREE.Quaternion().fromArray( jsonKey.value ),
time: jsonKey.time
};
keys.push( key );
} );
}
return new THREE.QuaternionKeyframeTrack( name, keys );
return new THREE.QuaternionKeyframeTrack( json.name, keys );
};
\ No newline at end of file
......@@ -56,9 +56,9 @@ THREE.StringKeyframeTrack.prototype.clone = function() {
};
THREE.StringKeyframeTrack.parse = function( name, jsonKeys ) {
THREE.StringKeyframeTrack.parse = function( json ) {
return new THREE.StringKeyframeTrack( name, jsonKeys );
return new THREE.StringKeyframeTrack( json.name, json.keys );
};
\ No newline at end of file
......@@ -56,23 +56,22 @@ THREE.VectorKeyframeTrack.prototype.clone = function() {
};
THREE.VectorKeyframeTrack.parse = function( name, jsonKeys ) {
THREE.VectorKeyframeTrack.parse = function( json ) {
var elementCount = jsonKeys[0].value.length;
var elementCount = json.keys[0].value.length;
var valueType = THREE[ 'Vector' + elementCount ];
var keys = [];
for( var i = 0; i < jsonKeys.length; i ++ ) {
var jsonKey = jsonKeys[i];
var key = {
for( var i = 0; i < json.keys.length; i ++ ) {
var jsonKey = json.keys[i];
keys.push( {
value: new valueType().fromArray( jsonKey.value ),
time: jsonKey.time
};
keys.push( key );
} );
}
return new THREE.VectorKeyframeTrack( name, keys );
return new THREE.VectorKeyframeTrack( json.keys, keys );
};
\ No newline at end of file
......@@ -633,28 +633,15 @@ THREE.ObjectLoader.prototype = {
var fpsToSeconds = ( data.animations.fps !== undefined ) ? ( 1.0 / data.animations.fps ) : 1.0;
if( dataTracks.position ) {
for( var i = 0; i < data.animations.tracks.length; i ++ ) {
tracks.push( THREE.VectorKeyframeTrack.parse( object.uuid + '.position', dataTracks.position ).scale( fpsToSeconds ) );
}
if( dataTracks.quaternion ) {
var trackQuaternion = THREE.QuaternionKeyframeTrack.parse( object.uuid + '.quaternion', dataTracks.quaternion ).scale( fpsToSeconds );
//trackQuaternion.multiply( trackQuaternion.keys[0].value.clone().inverse() );
//trackQuaternion.multiply( object.quaternion );
var track = THREE.KeyframeTrack.parse( data.animations.tracks[i] );
track.name = object.uuid + '.' + track.name;
track.scale( fpsToSeconds );
tracks.push( track );
tracks.push( trackQuaternion );
}
if( dataTracks.scale ) {
tracks.push( THREE.VectorKeyframeTrack.parse( object.uuid + '.scale', dataTracks.scale ).scale( fpsToSeconds ) );
}
}
return object;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册