Merge branch 'master' of github.com:nmfisher/polyvox_filament

This commit is contained in:
Nick Fisher
2023-02-26 12:22:14 +08:00
12 changed files with 172 additions and 106 deletions

View File

@@ -15,7 +15,7 @@ class AnimationBuilder {
List<BoneAnimation>? _boneAnimations = null;
Animation build() {
Animation build(String meshName, List<String> morphNames) {
if (_numMorphWeights == 0 || _duration == 0 || _frameLengthInMs == 0)
throw Exception();
@@ -36,8 +36,11 @@ class AnimationBuilder {
}
}
return Animation(morphData, _numMorphWeights, _boneAnimations, numFrames,
_frameLengthInMs);
var morphAnimation =
MorphAnimation(meshName, morphData, morphNames, _frameLengthInMs);
return Animation(
morphAnimation: morphAnimation, boneAnimations: _boneAnimations);
}
AnimationBuilder setFramerate(int framerate) {

View File

@@ -2,29 +2,6 @@ import 'dart:typed_data';
import 'package:vector_math/vector_math.dart';
// class Vec3 {
// final double x;
// final double y;
// final double z;
// Vec3({this.x = 0, this.y = 0, this.z = 0});
// factory Vec3.from(List<double> vals) =>
// Vec3(x: vals[0], y: vals[1], z: vals[2]);
// }
// class Quaternion {
// double x = 0;
// double y = 0;
// double z = 0;
// double w = 1;
// Quaternion({this.x = 0, this.y = 0, this.z = 0, this.w = 1.0});
// factory Quaternion.from(List<double> vals) =>
// Quaternion(x: vals[0], y: vals[1], z: vals[2], w: vals[3]);
// }
class BoneAnimation {
final List<String> boneNames;
final List<String> meshNames;
@@ -37,37 +14,33 @@ class BoneAnimation {
}
}
class Animation {
late final Float32List? morphData;
final int numMorphWeights;
//
// 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.
//
class MorphAnimation {
final String meshName;
final List<String> morphNames;
late final Float32List morphData;
MorphAnimation(
this.meshName, this.morphData, this.morphNames, this.frameLengthInMs);
int get numMorphWeights => morphNames.length;
int get numFrames => morphData.length ~/ numMorphWeights;
final int numFrames;
final double frameLengthInMs;
}
class Animation {
final MorphAnimation? morphAnimation;
final List<BoneAnimation>? boneAnimations;
Animation(this.morphData, this.numMorphWeights, this.boneAnimations,
this.numFrames, this.frameLengthInMs) {
if (morphData != null && morphData!.length != numFrames * numMorphWeights) {
throw Exception("Mismatched animation data with frame length");
}
}
Animation.from(
{required List<List<double>> morphData,
required this.numMorphWeights,
this.boneAnimations,
required this.numFrames,
required this.frameLengthInMs}) {
if (morphData.length != numFrames) {
throw Exception("Mismatched animation data with frame length");
}
this.morphData = Float32List(numMorphWeights * numFrames);
for (int i = 0; i < numFrames; i++) {
this.morphData!.setRange((i * numMorphWeights),
(i * numMorphWeights) + numMorphWeights, morphData[i]);
}
}
Animation({this.morphAnimation, this.boneAnimations});
}
class BoneTransformFrameData {
@@ -94,3 +67,18 @@ class BoneTransformFrameData {
yield quaternions[frame].w;
}
}
// Animation.from(
// {required this.meshName,
// required List<List<double>> morphData,
// required this.numMorphWeights,
// this.boneAnimations,
// required this.numFrames,
// required this.frameLengthInMs}) {
// if (morphData.length != numFrames) {
// throw Exception("Mismatched animation data with frame length");
// }
// }
// not directly used, the list of morph targets animated by this [Animation], and may be a subset of the actual morph targets in the asset (and may also be ordered differently).
// // When passed to a [FilamentController], these will be re-mapped appropriately (and any morph targets not provided will be set to zero at each frame).

View File

@@ -300,11 +300,12 @@ class PolyvoxFilamentController extends FilamentController {
Future setAnimation(FilamentAsset asset, Animation animation) async {
await _channel.invokeMethod("setAnimation", [
asset,
animation.morphData!,
animation.numMorphWeights,
animation.morphAnimation!.meshName,
animation.morphAnimation!.morphData,
animation.morphAnimation!.numMorphWeights,
animation.boneAnimations?.map((a) => a.toList()).toList() ?? [],
animation.numFrames,
animation.frameLengthInMs
animation.morphAnimation!.numFrames,
animation.morphAnimation!.frameLengthInMs
]);
}