فهرست منبع

prevent animation from searching forever for next key. When next key has lower index than prev, we have looped, and expect the time value to be less then the current

rchadwic 11 سال پیش
والد
کامیت
ac28e886f4
2فایلهای تغییر یافته به همراه18 افزوده شده و 5 حذف شده
  1. 4 1
      examples/webgl_loader_collada_skinning.html
  2. 14 4
      src/extras/animation/Animation.js

+ 4 - 1
examples/webgl_loader_collada_skinning.html

@@ -39,7 +39,10 @@
 
 		<script src="../build/three.min.js"></script>
 		<script src="./js/loaders/ColladaLoader.js"></script>
-
+		<script src="../src/extras/animation/Animation.js"></script>
+		<script src="../src/extras/animation/AnimationHandler.js"></script>
+		<script src="../src/extras/animation/AnimationMorphTarget.js"></script>
+		<script src="../src/extras/animation/KeyFrameAnimation.js"></script>
 		<script src="js/Detector.js"></script>
 		<script src="js/libs/stats.min.js"></script>
 

+ 14 - 4
src/extras/animation/Animation.js

@@ -128,7 +128,14 @@ THREE.Animation.prototype.update = function ( deltaTimeMS ) {
 	this.currentTime += deltaTimeMS * this.timeScale;
 
 	unloopedCurrentTime = this.currentTime;
+
+	//Mod operation fails on floats
+	//was this supposed to be in frames?
+	while (this.currentTime > this.data.length)
+		this.currentTime -= this.data.length;
 	currentTime = this.currentTime = this.currentTime % this.data.length;
+
+	
 	frame = parseInt( Math.min( currentTime * this.data.fps, this.data.length * this.data.fps ), 10 );
 
 
@@ -148,19 +155,20 @@ THREE.Animation.prototype.update = function ( deltaTimeMS ) {
 			nextKey = animationCache.nextKey[ type ];
 
 			// switch keys?
-
+			if(!nextKey) debugger;
 			if ( nextKey.time <= unloopedCurrentTime ) {
 
 				// did we loop?
 
-				if ( currentTime < unloopedCurrentTime ) {
+				if ( currentTime <= unloopedCurrentTime ) {
 
 					if ( this.loop ) {
 
 						prevKey = this.data.hierarchy[ h ].keys[ 0 ];
 						nextKey = this.getNextKeyWith( type, h, 1 );
 
-						while( nextKey.time < currentTime ) {
+						//if(nextKey.index < prevKey.index ) then we have wrapped over the end, and nextKey.time < currentTime will loop forever
+						while( nextKey && nextKey.time < currentTime  && nextKey.index > prevKey.index) {
 
 							prevKey = nextKey;
 							nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
@@ -181,7 +189,8 @@ THREE.Animation.prototype.update = function ( deltaTimeMS ) {
 						prevKey = nextKey;
 						nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
 
-					} while( nextKey.time < currentTime )
+					} while( nextKey && nextKey.time < currentTime && nextKey.index > prevKey.index )
+					//if(nextKey.index < prevKey.index ) then we have wrapped over the end, and nextKey.time < currentTime will loop forever
 
 				}
 
@@ -322,6 +331,7 @@ THREE.Animation.prototype.getNextKeyWith = function ( type, h, key ) {
 
 	var keys = this.data.hierarchy[ h ].keys;
 
+	if(keys.length === undefined) debugger;
 	if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
 		 this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {