From 7af0f6f00da91245f0cfafbe054187e6cc71d4af Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Mon, 3 Jun 2024 22:30:45 +0800 Subject: [PATCH] don't add multiple component instances and interpolate between gltf and dynamic bone animation --- .../components/AnimationComponentManager.hpp | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dart_filament/native/include/components/AnimationComponentManager.hpp b/dart_filament/native/include/components/AnimationComponentManager.hpp index 81d8adb0..0ce6e6dc 100644 --- a/dart_filament/native/include/components/AnimationComponentManager.hpp +++ b/dart_filament/native/include/components/AnimationComponentManager.hpp @@ -105,20 +105,26 @@ namespace flutter_filament void addAnimationComponent(std::variant target) { + AnimationComponent animationComponent; animationComponent.target = target; EntityInstanceBase::Type componentInstance; if (std::holds_alternative(target)) { auto instance = std::get(target); - componentInstance = addComponent(instance->getRoot()); + if(!hasComponent(instance->getRoot())) { + componentInstance = addComponent(instance->getRoot()); + this->elementAt<0>(componentInstance) = animationComponent; + } } else { - componentInstance = addComponent(std::get(target)); + auto entity = std::get(target); + if(!hasComponent(entity)) { + componentInstance = addComponent(entity); + this->elementAt<0>(componentInstance) = animationComponent; + } } - - this->elementAt<0>(componentInstance) = animationComponent; } @@ -235,7 +241,7 @@ namespace flutter_filament } } - // simple linear interpolation + // linear interpolation for this animation math::mat4f curr = (1 - delta) * animationStatus.frameData[currFrame]; math::mat4f next = delta * animationStatus.frameData[nextFrame]; math::mat4f localTransform = curr + next; @@ -243,8 +249,14 @@ namespace flutter_filament const Entity joint = target->getJointsAt(animationStatus.skinIndex)[animationStatus.boneIndex]; auto jointTransform = _transformManager.getInstance(joint); + auto currentTransform = _transformManager.getTransform(jointTransform); - _transformManager.setTransform(jointTransform, localTransform); + // linear interpolation between the current transform (e.g. if set by the gltf frame) + math::mat4f curr2 = (1 - delta) * animationStatus.frameData[currFrame]; + math::mat4f next2 = delta * currentTransform; + math::mat4f localTransform2 = curr + next; + + _transformManager.setTransform(jointTransform, localTransform2); animator->updateBoneMatrices();