Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions src/animation/AnimationUtils.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import { Quaternion } from '../math/Quaternion.js';
import { AdditiveAnimationBlendMode } from '../constants.js';

// same as Array.prototype.slice, but also works on typed arrays
function arraySlice( array, from, to ) {

if ( isTypedArray( array ) ) {

// in ios9 array.subarray(from, undefined) will return empty array
// but array.subarray(from) or array.subarray(from, len) is correct
return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );

}

return array.slice( from, to );

}

// converts an array to a specific type
function convertArray( array, type, forceClone ) {

Expand Down Expand Up @@ -279,14 +264,14 @@ function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targe
// Reference frame is earlier than the first keyframe, so just use the first keyframe
const startIndex = referenceOffset;
const endIndex = referenceValueSize - referenceOffset;
referenceValue = arraySlice( referenceTrack.values, startIndex, endIndex );
referenceValue = referenceTrack.values.slice( startIndex, endIndex );

} else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {

// Reference frame is after the last keyframe, so just use the last keyframe
const startIndex = lastIndex * referenceValueSize + referenceOffset;
const endIndex = startIndex + referenceValueSize - referenceOffset;
referenceValue = arraySlice( referenceTrack.values, startIndex, endIndex );
referenceValue = referenceTrack.values.slice( startIndex, endIndex );

} else {

Expand All @@ -295,7 +280,7 @@ function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targe
const startIndex = referenceOffset;
const endIndex = referenceValueSize - referenceOffset;
interpolant.evaluate( referenceTime );
referenceValue = arraySlice( interpolant.resultBuffer, startIndex, endIndex );
referenceValue = interpolant.resultBuffer.slice( startIndex, endIndex );

}

Expand Down Expand Up @@ -350,7 +335,6 @@ function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targe
}

const AnimationUtils = {
arraySlice: arraySlice,
convertArray: convertArray,
isTypedArray: isTypedArray,
getKeyframeOrder: getKeyframeOrder,
Expand All @@ -361,7 +345,6 @@ const AnimationUtils = {
};

export {
arraySlice,
convertArray,
isTypedArray,
getKeyframeOrder,
Expand Down
16 changes: 8 additions & 8 deletions src/animation/KeyframeTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ class KeyframeTrack {
}

const stride = this.getValueSize();
this.times = AnimationUtils.arraySlice( times, from, to );
this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
this.times = times.slice( from, to );
this.values = this.values.slice( from * stride, to * stride );

}

Expand Down Expand Up @@ -330,8 +330,8 @@ class KeyframeTrack {
optimize() {

// times or values may be shared with other tracks, so overwriting is unsafe
const times = AnimationUtils.arraySlice( this.times ),
values = AnimationUtils.arraySlice( this.values ),
const times = this.times.slice(),
values = this.values.slice(),
stride = this.getValueSize(),

smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
Expand Down Expand Up @@ -424,8 +424,8 @@ class KeyframeTrack {

if ( writeIndex !== times.length ) {

this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
this.times = times.slice( 0, writeIndex );
this.values = values.slice( 0, writeIndex * stride );

} else {

Expand All @@ -440,8 +440,8 @@ class KeyframeTrack {

clone() {

const times = AnimationUtils.arraySlice( this.times, 0 );
const values = AnimationUtils.arraySlice( this.values, 0 );
const times = this.times.slice();
const values = this.values.slice();

const TypedKeyframeTrack = this.constructor;
const track = new TypedKeyframeTrack( this.name, times, values );
Expand Down