fix iOS implementation for set_animation

This commit is contained in:
Nick Fisher
2022-12-19 16:34:29 +08:00
parent 2647e5afdf
commit db25fb4bf3
9 changed files with 114 additions and 591 deletions

View File

@@ -1,21 +0,0 @@
// boneMatrices[1] = math::mat4f(1.0, 0.0, 0.0, 0.0, 0.0, 0.26, -0.97, 0.0, 0.0, 0.97, 0.26, 0.0, 0.0, 0.0, 0.0, 1.0);
// Log("Asset instance count : %d asset entity count %d, skin count %d skin name %s joint count @ 0 %d ",
// _asset->getAssetInstanceCount(),
// _asset->getEntityCount(),
// ,
// filamentInstance->getSkinNameAt(0), filamentInstance->getJointCountAt(0));
// for(int i =0; i < numJoints; i++) {
// auto nameInst = _ncm->getInstance(joints[i]);
// const char* jointName = _ncm->getName(nameInst);
// if(strcmp(jointName, boneName) == 0) {
// Log("Set transform for joint %s", jointName);
// // auto boneInst = rm.getInstance(joints[i]);
// }
// }
// bool transformed = false;
// if(!transformed) {
// Log("Failed to find bone %s", boneName);
// }
// Entity root = _asset->getRoot();

View File

@@ -1,6 +1,5 @@
import 'animations.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:vector_math/vector_math.dart';
class AnimationBuilder {
@@ -14,9 +13,7 @@ class AnimationBuilder {
double? _interpMorphStartValue;
double? _interpMorphEndValue;
final List<String> _boneNames = [];
final List<String> _meshNames = [];
final List<BoneTransformFrameData> _boneTransforms = [];
List<BoneAnimation>? _boneAnimations = null;
Animation build() {
if (_numMorphWeights == 0 || _duration == 0 || _frameLengthInMs == 0)
@@ -39,33 +36,7 @@ class AnimationBuilder {
}
}
print(
"Created morphWeights of size ${morphData.length} (${morphData.lengthInBytes} for ${numFrames} frames");
List<BoneAnimation>? boneAnimations;
if (_boneTransforms.isNotEmpty) {
throw Exception("TODO");
boneAnimations = <BoneAnimation>[];
final boneTransforms =
Float32List(numFrames * _boneTransforms.length * 7);
// print(
// "Creating bone transforms of size ${numFrames * _boneTransforms.length * 7}");
// for (int i = 0; i < numFrames; i++) {
// for (int j = 0; j < _boneTransforms.length; j++) {
// var frameData = _boneTransforms[j].getFrameData(i).toList();
// var rngStart = ((i * _boneTransforms.length) + j) * 7;
// var rngEnd = rngStart + 7;
// boneTransforms.setRange(rngStart, rngEnd, frameData);
// }
// print(
// "frameData for frame $i ${boneTransforms.sublist(i * _boneTransforms.length * 7, (i * _boneTransforms.length * 7) + 7)}");
// }
}
return Animation(morphData, _numMorphWeights, boneAnimations, numFrames,
return Animation(morphData, _numMorphWeights, _boneAnimations, numFrames,
_frameLengthInMs);
}
@@ -133,10 +104,16 @@ class AnimationBuilder {
}
}
_boneTransforms.add(BoneTransformFrameData(translations, quats));
var boneFrameData = BoneTransformFrameData(translations, quats);
_boneNames.add(boneName);
_meshNames.add(meshName);
_boneAnimations ??= <BoneAnimation>[];
var frameData = List<List<double>>.generate(
numFrames, (index) => boneFrameData.getFrameData(index).toList());
var animData = Float32List.fromList(frameData.expand((x) => x).toList());
_boneAnimations!.add(BoneAnimation([boneName], [meshName], animData));
return this;
}