Game Development Reference
In-Depth Information
The initData function parses the animation object from the JSON file. The
hierarchy object simply maintains the key frames ( time , position , scale , and
rotation ) for each bone, eliminates any repeated animation data (key frames at the
same time), and also updates the time to 0 if the time of the key frame is negative.
Basically, it sanitizes the data and sees that it is not processed again using the
initialized property.
var initData = function( data ) {
if( data.initialized === true )
return;
for( var h = 0; h < data.hierarchy.length; h ++ ) {
for( var k = 0; k < data.hierarchy[ h ].keys.length;
k ++ ) {
// remove minus times
if( data.hierarchy[ h ].keys[ k ].time < 0 )
data.hierarchy[ h ].keys[ k ].time = 0;
// create quaternions
var quater = data.hierarchy[ h ].keys[ k ].rot;
data.hierarchy[ h ].keys[ k ].rot = quat.fromValues(
quater[0], quater[1], quater[2], quater[3] );
}
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 --;
}
}
for ( var k = 0; k < data.hierarchy[ h ].keys.length;
k ++ ) {
data.hierarchy[ h ].keys[ k ].index = k;
}
}
data.initialized = true;
};
return that;
}());
Open primitive/Animation.js in your text editor.
 
Search WWH ::




Custom Search