diff --git a/Source/Engine/Graphics/Models/SkinnedMeshDrawData.cpp b/Source/Engine/Graphics/Models/SkinnedMeshDrawData.cpp
index 2efe92181..8470facac 100644
--- a/Source/Engine/Graphics/Models/SkinnedMeshDrawData.cpp
+++ b/Source/Engine/Graphics/Models/SkinnedMeshDrawData.cpp
@@ -38,29 +38,6 @@ void SkinnedMeshDrawData::Setup(int32 bonesCount)
SAFE_DELETE_GPU_RESOURCE(PrevBoneMatrices);
}
-void SkinnedMeshDrawData::SetData(const Matrix* bones, bool dropHistory)
-{
- if (!bones)
- return;
- ANIM_GRAPH_PROFILE_EVENT("SetSkinnedMeshData");
-
- // Copy bones to the buffer
- const int32 count = BonesCount;
- const int32 preFetchStride = 2;
- const Matrix* input = bones;
- const auto output = (Matrix3x4*)Data.Get();
- ASSERT(Data.Count() == count * sizeof(Matrix3x4));
- for (int32 i = 0; i < count; i++)
- {
- Matrix3x4* bone = output + i;
- Platform::Prefetch(bone + preFetchStride);
- Platform::Prefetch((byte*)(bone + preFetchStride) + PLATFORM_CACHE_LINE_SIZE);
- bone->SetMatrixTranspose(input[i]);
- }
-
- OnDataChanged(dropHistory);
-}
-
void SkinnedMeshDrawData::OnDataChanged(bool dropHistory)
{
// Setup previous frame bone matrices if needed
diff --git a/Source/Engine/Graphics/Models/SkinnedMeshDrawData.h b/Source/Engine/Graphics/Models/SkinnedMeshDrawData.h
index e690100be..24d5ca230 100644
--- a/Source/Engine/Graphics/Models/SkinnedMeshDrawData.h
+++ b/Source/Engine/Graphics/Models/SkinnedMeshDrawData.h
@@ -69,13 +69,6 @@ public:
/// The bones count.
void Setup(int32 bonesCount);
- ///
- /// Sets the bone matrices data for the GPU buffer. Ensure to call Flush before rendering.
- ///
- /// The bones data.
- /// True if drop previous update bones used for motion blur, otherwise will keep them and do the update.
- void SetData(const Matrix* bones, bool dropHistory);
-
///
/// After bones Data has been modified externally. Updates the bone matrices data for the GPU buffer. Ensure to call Flush before rendering.
///
diff --git a/Source/Engine/Level/Actors/AnimatedModel.cpp b/Source/Engine/Level/Actors/AnimatedModel.cpp
index 7863578c6..1aad5f285 100644
--- a/Source/Engine/Level/Actors/AnimatedModel.cpp
+++ b/Source/Engine/Level/Actors/AnimatedModel.cpp
@@ -86,7 +86,8 @@ void AnimatedModel::PreInitSkinningData()
{
if (!SkinnedModel || !SkinnedModel->IsLoaded())
return;
-
+ PROFILE_CPU();
+ PROFILE_MEM(Animations);
ScopeLock lock(SkinnedModel->Locker);
SetupSkinningData();
@@ -96,28 +97,30 @@ void AnimatedModel::PreInitSkinningData()
// Get nodes global transformations for the initial pose
GraphInstance.NodesPose.Resize(nodesCount, false);
+ auto nodesPose = GraphInstance.NodesPose.Get();
for (int32 nodeIndex = 0; nodeIndex < nodesCount; nodeIndex++)
{
Matrix localTransform;
skeleton.Nodes[nodeIndex].LocalTransform.GetWorld(localTransform);
const int32 parentIndex = skeleton.Nodes[nodeIndex].ParentIndex;
if (parentIndex != -1)
- GraphInstance.NodesPose[nodeIndex] = localTransform * GraphInstance.NodesPose[parentIndex];
+ nodesPose[nodeIndex] = localTransform * nodesPose[parentIndex];
else
- GraphInstance.NodesPose[nodeIndex] = localTransform;
+ nodesPose[nodeIndex] = localTransform;
}
GraphInstance.Invalidate();
- GraphInstance.RootTransform = skeleton.Nodes[0].LocalTransform;
+ GraphInstance.RootTransform = nodesCount > 0 ? skeleton.Nodes[0].LocalTransform : Transform::Identity;
// Setup bones transformations including bone offset matrix
- Array identityMatrices; // TODO: use shared memory?
- identityMatrices.Resize(bonesCount, false);
+ Matrix3x4* output = (Matrix3x4*)_skinningData.Data.Get();
+ const SkeletonBone* bones = skeleton.Bones.Get();
for (int32 boneIndex = 0; boneIndex < bonesCount; boneIndex++)
{
- auto& bone = skeleton.Bones[boneIndex];
- identityMatrices.Get()[boneIndex] = bone.OffsetMatrix * GraphInstance.NodesPose[bone.NodeIndex];
+ auto& bone = bones[boneIndex];
+ Matrix identityMatrix = bone.OffsetMatrix * nodesPose[bone.NodeIndex];
+ output[boneIndex].SetMatrixTranspose(identityMatrix);
}
- _skinningData.SetData(identityMatrices.Get(), true);
+ _skinningData.OnDataChanged(true);
UpdateBounds();
UpdateSockets();
@@ -586,6 +589,7 @@ void AnimatedModel::SyncParameters()
}
else
{
+ PROFILE_MEM(Animations);
ScopeLock lock(AnimationGraph->Locker);
// Clone the parameters