Skip to content

Commit

Permalink
feat(model): use track types to determine interpolation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Jan 31, 2024
1 parent 46ba589 commit 9026ae6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/model/ModelAnimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
new (...args: any[]): T;
Expand Down Expand Up @@ -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)));
}
}

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

Expand Down
18 changes: 18 additions & 0 deletions src/lib/model/util.ts
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit 9026ae6

Please sign in to comment.