diff --git a/src/animation/AnimationClip.js b/src/animation/AnimationClip.js index 4ba7f85f740212db4488b41ad969f97f72f79eeb..4aba8127ed2213cc770e10158295ec7c4c985551 100644 --- a/src/animation/AnimationClip.js +++ b/src/animation/AnimationClip.js @@ -15,12 +15,7 @@ THREE.AnimationClip = function ( name, duration, tracks ) { // this means it should figure out its duration by scanning the tracks if ( this.duration < 0 ) { - for ( var i = 0; i < this.tracks.length; i ++ ) { - - var track = this.tracks[i]; - this.duration = Math.max( track.times[ track.times.length - 1 ] ); - - } + this.resetDuration(); } @@ -35,6 +30,24 @@ THREE.AnimationClip.prototype = { constructor: THREE.AnimationClip, + resetDuration: function() { + + var tracks = this.tracks, + duration = 0; + + for ( var i = 0, n = tracks.length; i !== n; ++ i ) { + + var track = this.tracks[ i ]; + + duration = Math.max( + duration, track.times[ track.times.length - 1 ] ); + + } + + this.duration = duration; + + }, + trim: function() { for ( var i = 0; i < this.tracks.length; i ++ ) {