Procházet zdrojové kódy

Avoid accidental removal of last keyframe. (#9592)

Fixes #9056.
tschw před 9 roky
rodič
revize
61bbbfa3d1
1 změnil soubory, kde provedl 32 přidání a 18 odebrání
  1. 32 18
      src/animation/KeyframeTrackPrototype.js

+ 32 - 18
src/animation/KeyframeTrackPrototype.js

@@ -269,9 +269,12 @@ KeyframeTrackPrototype = {
 			values = this.values,
 			stride = this.getValueSize(),
 
-			writeIndex = 1;
+			smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
 
-		for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
+			writeIndex = 1,
+			lastIndex = times.length - 1;
+
+		for( var i = 1; i < lastIndex; ++ i ) {
 
 			var keep = false;
 
@@ -282,24 +285,29 @@ KeyframeTrackPrototype = {
 
 			if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
 
-				// remove unnecessary keyframes same as their neighbors
-				var offset = i * stride,
-					offsetP = offset - stride,
-					offsetN = offset + stride;
+				if ( ! smoothInterpolation ) {
+
+					// remove unnecessary keyframes same as their neighbors
 
-				for ( var j = 0; j !== stride; ++ j ) {
+					var offset = i * stride,
+						offsetP = offset - stride,
+						offsetN = offset + stride;
 
-					var value = values[ offset + j ];
+					for ( var j = 0; j !== stride; ++ j ) {
 
-					if ( value !== values[ offsetP + j ] ||
-							value !== values[ offsetN + j ] ) {
+						var value = values[ offset + j ];
 
-						keep = true;
-						break;
+						if ( value !== values[ offsetP + j ] ||
+								value !== values[ offsetN + j ] ) {
+
+							keep = true;
+							break;
+
+						}
 
 					}
 
-				}
+				} else keep = true;
 
 			}
 
@@ -314,13 +322,10 @@ KeyframeTrackPrototype = {
 					var readOffset = i * stride,
 						writeOffset = writeIndex * stride;
 
-					for ( var j = 0; j !== stride; ++ j ) {
+					for ( var j = 0; j !== stride; ++ j )
 
 						values[ writeOffset + j ] = values[ readOffset + j ];
 
-					}
-
-
 				}
 
 				++ writeIndex;
@@ -329,6 +334,15 @@ KeyframeTrackPrototype = {
 
 		}
 
+		// flush last keyframe (compaction looks ahead)
+
+		times[ writeIndex ++ ] = times[ lastIndex ];
+
+		for ( var readOffset = lastIndex * stride, j = 0; j !== stride; ++ j )
+
+			values[ writeOffset + j ] = values[ readOffset + j ];
+
+
 		if ( writeIndex !== times.length ) {
 
 			this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
@@ -342,4 +356,4 @@ KeyframeTrackPrototype = {
 
 }
 
-export { KeyframeTrackPrototype };
+export { KeyframeTrackPrototype };