This commit is contained in:
Nick Fisher
2023-04-19 18:06:48 +08:00
parent 7f4ca7e69b
commit a162ff2400
30 changed files with 3604 additions and 2293 deletions

View File

@@ -1,9 +1,11 @@
import 'animations.dart';
import 'package:polyvox_filament/animations/animations.dart';
import 'package:tuple/tuple.dart';
import 'package:flutter/foundation.dart';
import 'package:vector_math/vector_math.dart';
class AnimationBuilder {
BoneAnimation? boneAnimation;
DartBoneAnimation? dartBoneAnimation;
double _frameLengthInMs = 0;
double _duration = 0;
int _numMorphWeights = 0;
@@ -13,9 +15,10 @@ class AnimationBuilder {
double? _interpMorphStartValue;
double? _interpMorphEndValue;
List<BoneAnimation>? _boneAnimations = null;
List<DartBoneAnimation>? _dartBoneAnimations = null;
Animation build(String meshName, List<String> morphNames) {
Tuple2<MorphAnimation, List<DartBoneAnimation>> build(
String meshName, List<String> morphNames) {
if (_numMorphWeights == 0 || _duration == 0 || _frameLengthInMs == 0)
throw Exception();
@@ -39,8 +42,8 @@ class AnimationBuilder {
var morphAnimation =
MorphAnimation(meshName, morphData, morphNames, _frameLengthInMs);
return Animation(
morphAnimation: morphAnimation, boneAnimations: _boneAnimations);
return Tuple2<MorphAnimation, List<DartBoneAnimation>>(
morphAnimation, _dartBoneAnimations!);
}
AnimationBuilder setFramerate(int framerate) {
@@ -107,16 +110,18 @@ class AnimationBuilder {
}
}
var boneFrameData = BoneTransformFrameData(translations, quats);
throw Exception();
_boneAnimations ??= <BoneAnimation>[];
// var boneFrameData = BoneTransformFrameData(translations, quats);
var frameData = List<List<double>>.generate(
numFrames, (index) => boneFrameData.getFrameData(index).toList());
// _DartBoneAnimations ??= <DartBoneAnimation>[];
var animData = Float32List.fromList(frameData.expand((x) => x).toList());
// var frameData = List<List<double>>.generate(
// numFrames, (index) => boneFrameData.getFrameData(index).toList());
_boneAnimations!.add(BoneAnimation([boneName], [meshName], animData));
// var animData = Float32List.fromList(frameData.expand((x) => x).toList());
// _DartBoneAnimations!.add(DartDartBoneAnimation([boneName], [meshName], animData));
return this;
}

View File

@@ -2,16 +2,13 @@ import 'dart:typed_data';
import 'package:vector_math/vector_math.dart';
class BoneAnimation {
final List<String> boneNames;
final List<String> meshNames;
class DartBoneAnimation {
final String boneName;
final String meshName;
final Float32List frameData;
BoneAnimation(this.boneNames, this.meshNames, this.frameData);
List<List> toList() {
return [boneNames, meshNames, frameData];
}
double frameLengthInMs;
DartBoneAnimation(
this.boneName, this.meshName, this.frameData, this.frameLengthInMs);
}
//
@@ -24,25 +21,18 @@ class MorphAnimation {
final String meshName;
final List<String> morphNames;
late final Float32List morphData;
final Float32List data;
MorphAnimation(
this.meshName, this.morphData, this.morphNames, this.frameLengthInMs);
this.meshName, this.data, this.morphNames, this.frameLengthInMs);
int get numMorphWeights => morphNames.length;
int get numFrames => morphData.length ~/ numMorphWeights;
int get numFrames => data.length ~/ numMorphWeights;
final double frameLengthInMs;
}
class Animation {
final MorphAnimation? morphAnimation;
final List<BoneAnimation>? boneAnimations;
Animation({this.morphAnimation, this.boneAnimations});
}
class BoneTransformFrameData {
final List<Vector3> translations;
final List<Quaternion> quaternions;
@@ -67,18 +57,3 @@ 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).