From b7d068ccaa910edfef25893b1e616715e661bf63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Wed, 15 May 2024 15:21:47 +0200 Subject: [PATCH] feat: updateBoneMatricesForInstance Added a method to control to which instance to apply the bone matrices updates of an animator. This is particularly useful if you want to apply the animation from one master asset to other instances that are different assets but share the same skeleton as the master asset. A common example for this is e.g. clothing. --- libs/gltfio/include/gltfio/Animator.h | 12 ++++++++++++ libs/gltfio/src/Animator.cpp | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/libs/gltfio/include/gltfio/Animator.h b/libs/gltfio/include/gltfio/Animator.h index 199555a40d3..25416a13a10 100644 --- a/libs/gltfio/include/gltfio/Animator.h +++ b/libs/gltfio/include/gltfio/Animator.h @@ -56,6 +56,18 @@ class UTILS_PUBLIC Animator { */ void updateBoneMatrices(); + /** + * Updates the bone matrices of the specified instance using the state of this animatior. + * This is useful if you have another instance that has the same skeleton as the asset of this animator, + * and you wish to apply the same animation to those instances (e.g. clothing). + * + * NOTE: In most cases, you only need to use the updateBoneMatrices() method. This method is necessary + * only when you need to synchronize animations across multiple instances with the same skeleton. + * + * @param instance The instance to update. + */ + void updateBoneMatricesForInstance(FilamentInstance* instance); + /** * Applies a blended transform to the union of nodes affected by two animations. * Used for cross-fading from a previous skinning-based animation or rigid body animation. diff --git a/libs/gltfio/src/Animator.cpp b/libs/gltfio/src/Animator.cpp index 6e53b705c60..ff41bdf599c 100644 --- a/libs/gltfio/src/Animator.cpp +++ b/libs/gltfio/src/Animator.cpp @@ -336,6 +336,10 @@ void Animator::updateBoneMatrices() { } } +void Animator::updateBoneMatricesForInstance(FilamentInstance* instance) { + mImpl->updateBoneMatrices(downcast(instance)); +} + float Animator::getAnimationDuration(size_t animationIndex) const { return mImpl->animations[animationIndex].duration; }