diff --git a/Source/Engine/Level/Actors/AnimatedModel.cpp b/Source/Engine/Level/Actors/AnimatedModel.cpp index 1aad5f285..ee95d6233 100644 --- a/Source/Engine/Level/Actors/AnimatedModel.cpp +++ b/Source/Engine/Level/Actors/AnimatedModel.cpp @@ -140,6 +140,13 @@ void AnimatedModel::GetCurrentPose(Array& nodesTransformation, bool worl } } +void AnimatedModel::GetCurrentPose(Span& nodesTransformation) const +{ + if (GraphInstance.NodesPose.IsEmpty()) + const_cast(this)->PreInitSkinningData(); // Ensure to have valid nodes pose to return + nodesTransformation = ToSpan(GraphInstance.NodesPose); +} + void AnimatedModel::SetCurrentPose(const Array& nodesTransformation, bool worldSpace) { if (GraphInstance.NodesPose.IsEmpty()) diff --git a/Source/Engine/Level/Actors/AnimatedModel.h b/Source/Engine/Level/Actors/AnimatedModel.h index 89124cb87..e13e515d9 100644 --- a/Source/Engine/Level/Actors/AnimatedModel.h +++ b/Source/Engine/Level/Actors/AnimatedModel.h @@ -213,6 +213,12 @@ public: /// True if convert matrices into world-space, otherwise returned values will be in local-space of the actor. API_FUNCTION() void GetCurrentPose(API_PARAM(Out) Array& nodesTransformation, bool worldSpace = false) const; + /// + /// Gets the per-node final transformations (skeleton pose). + /// + /// The output per-node final transformation matrices. + void GetCurrentPose(Span& nodesTransformation) const; + /// /// Sets the per-node final transformations (skeleton pose). /// diff --git a/Source/Engine/Physics/Actors/Cloth.cpp b/Source/Engine/Physics/Actors/Cloth.cpp index da7823517..a55cddd2a 100644 --- a/Source/Engine/Physics/Actors/Cloth.cpp +++ b/Source/Engine/Physics/Actors/Cloth.cpp @@ -815,8 +815,7 @@ bool Cloth::OnPreUpdate() Array particlesSkinned; particlesSkinned.Set(particles.Get(), particles.Length()); - // TODO: optimize memory allocs (eg. get pose as Span for readonly) - Array pose; + Span pose; animatedModel->GetCurrentPose(pose); const SkeletonData& skeleton = animatedModel->SkinnedModel->Skeleton; const SkeletonBone* bones = skeleton.Bones.Get(); @@ -999,8 +998,7 @@ void Cloth::RunClothDeformer(const MeshBase* mesh, MeshDeformationData& deformat return; } - // TODO: optimize memory allocs (eg. get pose as Span for readonly) - Array pose; + Span pose; animatedModel->GetCurrentPose(pose); const SkeletonData& skeleton = animatedModel->SkinnedModel->Skeleton;