From 355434eb8f0bf2fc6ad9a391cc4590ccf2764f19 Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Thu, 20 Aug 2015 11:06:40 -0400 Subject: [PATCH] allow for automatic detection of AnimationClip lengths. --- src/animation/AnimationClip.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/animation/AnimationClip.js b/src/animation/AnimationClip.js index 2cb39d145e..c7ae9d58c1 100644 --- a/src/animation/AnimationClip.js +++ b/src/animation/AnimationClip.js @@ -10,7 +10,15 @@ THREE.AnimationClip = function ( name, duration, tracks ) { this.name = name; this.tracks = tracks; - this.duration = duration || 1; + this.duration = duration; + + // 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.keys[ track.keys.length - 1 ].time ); + } + } // maybe only do these on demand, as doing them here could potentially slow down loading // but leaving these here during development as this ensures a lot of testing of these functions -- GitLab