From 49648f31e09e38ae4eb0d8ad5f6e2be84340c74c Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Sun, 8 Jan 2017 18:03:15 -0800 Subject: [PATCH] Remove intermediate interpolators. --- examples/js/loaders/GLTFLoader.js | 57 +++++++++---------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index e1064f55b3..5bafe920ef 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/examples/js/loaders/GLTFLoader.js @@ -254,36 +254,6 @@ THREE.GLTFLoader = ( function () { }; - function createAnimation( name, interps ) { - - var tracks = []; - - for ( var i = 0, len = interps.length; i < len; i ++ ) { - - var interp = interps[ i ]; - - // KeyframeTrack.optimize() will modify given 'times' and 'values' - // buffers before creating a truncated copy to keep. Because buffers may - // be reused by other tracks, make copies here. - interp.times = THREE.AnimationUtils.arraySlice( interp.times, 0 ); - interp.values = THREE.AnimationUtils.arraySlice( interp.values, 0 ); - - interp.target.updateMatrix(); - interp.target.matrixAutoUpdate = true; - - tracks.push( new THREE.KeyframeTrack( - interp.name, - interp.times, - interp.values, - interp.type - ) ); - - } - - return new THREE.AnimationClip( name, undefined, tracks ); - - } - /*********************************/ /********** INTERNALS ************/ /*********************************/ @@ -1372,7 +1342,7 @@ THREE.GLTFLoader = ( function () { return _each( json.animations, function ( animation, animationId ) { - var interps = []; + var tracks = []; for ( var channelId in animation.channels ) { @@ -1393,15 +1363,22 @@ THREE.GLTFLoader = ( function () { if ( node ) { - var interp = { - times: inputAccessor.array, - values: outputAccessor.array, - target: node, - type: INTERPOLATION[ sampler.interpolation ], - name: node.name + '.' + PATH_PROPERTIES[ target.path ] - }; + node.updateMatrix(); + node.matrixAutoUpdate = true; + + var TypedKeyframeTrack = PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.rotation + ? THREE.QuaternionKeyframeTrack + : THREE.VectorKeyframeTrack; - interps.push( interp ); + // KeyframeTrack.optimize() will modify given 'times' and 'values' + // buffers before creating a truncated copy to keep. Because buffers may + // be reused by other tracks, make copies here. + tracks.push( new TypedKeyframeTrack( + node.name + '.' + PATH_PROPERTIES[ target.path ], + THREE.AnimationUtils.arraySlice( inputAccessor.array, 0 ), + THREE.AnimationUtils.arraySlice( outputAccessor.array, 0 ), + INTERPOLATION[ sampler.interpolation ] + ) ); } @@ -1409,7 +1386,7 @@ THREE.GLTFLoader = ( function () { } - return createAnimation( "animation_" + animationId, interps ); + return new THREE.AnimationClip( "animation_" + animationId, undefined, tracks ); } ); -- GitLab