Optimize memory allocation when reading animated model pose by cloth

This commit is contained in:
Wojtek Figat
2025-06-06 22:41:48 +02:00
parent d95cd2f0be
commit 462f75abd0
3 changed files with 15 additions and 4 deletions

View File

@@ -140,6 +140,13 @@ void AnimatedModel::GetCurrentPose(Array<Matrix>& nodesTransformation, bool worl
}
}
void AnimatedModel::GetCurrentPose(Span<Matrix>& nodesTransformation) const
{
if (GraphInstance.NodesPose.IsEmpty())
const_cast<AnimatedModel*>(this)->PreInitSkinningData(); // Ensure to have valid nodes pose to return
nodesTransformation = ToSpan(GraphInstance.NodesPose);
}
void AnimatedModel::SetCurrentPose(const Array<Matrix>& nodesTransformation, bool worldSpace)
{
if (GraphInstance.NodesPose.IsEmpty())

View File

@@ -213,6 +213,12 @@ public:
/// <param name="worldSpace">True if convert matrices into world-space, otherwise returned values will be in local-space of the actor.</param>
API_FUNCTION() void GetCurrentPose(API_PARAM(Out) Array<Matrix>& nodesTransformation, bool worldSpace = false) const;
/// <summary>
/// Gets the per-node final transformations (skeleton pose).
/// </summary>
/// <param name="nodesTransformation">The output per-node final transformation matrices.</param>
void GetCurrentPose(Span<Matrix>& nodesTransformation) const;
/// <summary>
/// Sets the per-node final transformations (skeleton pose).
/// </summary>

View File

@@ -815,8 +815,7 @@ bool Cloth::OnPreUpdate()
Array<Float4> particlesSkinned;
particlesSkinned.Set(particles.Get(), particles.Length());
// TODO: optimize memory allocs (eg. get pose as Span<Matrix> for readonly)
Array<Matrix> pose;
Span<Matrix> 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<Matrix> for readonly)
Array<Matrix> pose;
Span<Matrix> pose;
animatedModel->GetCurrentPose(pose);
const SkeletonData& skeleton = animatedModel->SkinnedModel->Skeleton;