migrate some animation helper classes

This commit is contained in:
Nick Fisher
2023-04-26 17:49:44 +08:00
parent 6ec9fc2988
commit fae619feb8
7 changed files with 326 additions and 72 deletions

View File

@@ -0,0 +1,31 @@
//
// Frame weights for the morph targets specified in [morphNames] attached to mesh [meshName].
// morphData is laid out as numFrames x numMorphTargets
// where the weights are in the same order as [morphNames].
// [morphNames] must be provided but is not used directly; this is only used to check that the eventual asset being animated contains the same morph targets in the same order.
//
import 'dart:typed_data';
class MorphAnimationData {
final String meshName;
final List<String> morphNames;
final Float32List data;
MorphAnimationData(
this.meshName, this.data, this.morphNames, this.frameLengthInMs) {
assert(data.length == morphNames.length * numFrames);
}
int get numMorphWeights => morphNames.length;
int get numFrames => data.length ~/ numMorphWeights;
final double frameLengthInMs;
Iterable<double> getData(String morphName) sync* {
for (int i = 0; i < numFrames; i++) {
yield data[i * numMorphWeights];
}
}
}