diff --git a/src/lib/model/ModelAnimator.ts b/src/lib/model/ModelAnimator.ts index 11f2f39..c5e1c13 100644 --- a/src/lib/model/ModelAnimator.ts +++ b/src/lib/model/ModelAnimator.ts @@ -3,6 +3,7 @@ import { M2Track } from '@wowserhq/format'; import { BoneSpec, SequenceSpec } from './loader/types.js'; import ModelAnimation from './ModelAnimation.js'; import Model from './Model.js'; +import { getTrackInterpolation } from './util.js'; interface Constructor { new (...args: any[]): T; @@ -152,7 +153,7 @@ class ModelAnimator { continue; } - clip.tracks.push(new TrackType(name, times, values)); + clip.tracks.push(new TrackType(name, times, values, getTrackInterpolation(track.trackType))); } } @@ -176,7 +177,7 @@ class ModelAnimator { continue; } - clip.tracks.push(new TrackType(name, times, values)); + clip.tracks.push(new TrackType(name, times, values, getTrackInterpolation(track.trackType))); } } diff --git a/src/lib/model/util.ts b/src/lib/model/util.ts new file mode 100644 index 0000000..e8abde2 --- /dev/null +++ b/src/lib/model/util.ts @@ -0,0 +1,18 @@ +import * as THREE from 'three'; + +const getTrackInterpolation = (trackType: number): THREE.InterpolationModes => { + switch (trackType) { + case 0: + return THREE.InterpolateDiscrete; + case 1: + return THREE.InterpolateLinear; + case 2: + case 3: + // TODO 2 - cubic bezier, 3 - cubic hermite + return THREE.InterpolateSmooth; + default: + return THREE.InterpolateLinear; + } +}; + +export { getTrackInterpolation };