Skip to content

Commit

Permalink
Avoid accidental removal of last keyframe.
Browse files Browse the repository at this point in the history
  • Loading branch information
tschw committed Aug 28, 2016
1 parent ddb9a5e commit 9d2f0aa
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions src/animation/KeyframeTrackPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

}

Expand All @@ -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;
Expand All @@ -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 );
Expand All @@ -342,4 +356,4 @@ KeyframeTrackPrototype = {

}

export { KeyframeTrackPrototype };
export { KeyframeTrackPrototype };

0 comments on commit 9d2f0aa

Please sign in to comment.