Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

namespace
{
const float kDefaultMaxTranslationError = 0.000025f;
const float kDefaultMaxTranslationError = 0.00025f;
const float kDefaultMaxRotationError = 0.000025f;
const float kDefaultMaxScaleError = 0.0001f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ namespace EMotionFX
// get rid of shared data
ResetSharedData(sharedData);
sharedData.Clear();
sharedData.Shrink();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the clear/shrink needed since sharedData is going out of scope and will be destroyed?


return motion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace EMotionFX
//mPool->mFreeList.Reserve( numInstances * 2 );
if (mPool->mFreeList.GetMaxLength() < mPool->mNumInstances)
{
mPool->mFreeList.Reserve(mPool->mNumInstances);
mPool->mFreeList.Reserve(mPool->mNumInstances + mPool->mFreeList.GetMaxLength() / 2);
}

mPool->mFreeList.ResizeFast(startIndex + numInstances);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace EMotionFX
RenderBackend* renderBackend = AZ::Interface<RenderBackendManager>::Get()->GetRenderBackend();
assetData->m_renderActor.reset(renderBackend->CreateActor(assetData));

assetData->ReleaseEmotionFXData();
return static_cast<bool>(assetData->m_emfxActor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace EMotionFX
}
}

assetData->ReleaseEmotionFXData();
AZ_Error("EMotionFX", assetData->m_emfxAnimGraph, "Failed to initialize anim graph asset %s", asset.GetHint().c_str());
return static_cast<bool>(assetData->m_emfxAnimGraph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ namespace EMotionFX
AZ_RTTI(EMotionFXAsset, "{043F606A-A483-4910-8110-D8BC4B78922C}", AZ::Data::AssetData)
AZ_CLASS_ALLOCATOR(EMotionFXAsset, EMotionFXAllocator, 0)

void ReleaseEmotionFXData()
{
m_emfxNativeData.clear();
m_emfxNativeData.shrink_to_fit();
}

AZStd::vector<AZ::u8> m_emfxNativeData;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace EMotionFX
assetData->m_emfxMotion->SetIsOwnedByRuntime(true);
}

assetData->ReleaseEmotionFXData();
AZ_Error("EMotionFX", assetData->m_emfxMotion, "Failed to initialize motion asset %s", asset.GetHint().c_str());
return (assetData->m_emfxMotion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ namespace EMotionFX
// Set motion set's motion load callback, so if EMotion FX queries back for a motion,
// we can pull the one managed through an AZ::Asset.
assetData->m_emfxMotionSet->SetCallback(aznew CustomMotionSetCallback(asset));
assetData->ReleaseEmotionFXData();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,53 @@ namespace EMotionFX
// It's now safe to use this LOD.
lod.m_isReady = true;
}

//Cry rendering does skinning on the GPU, the goal is to remove all GPU deformed meshes and unused morph targets.
//We have to do it after the vertex buffers get created for the GPU, for CryRenderActor that is after the Finalize()
const uint32 numNodes = actor->GetNumNodes();
EMotionFX::Skeleton* skeleton = actor->GetSkeleton();
if (skeleton == nullptr)
{
AZ_Error("EMotionFX", false, "Skeleton couln't be null here! Will return");
return;
}

// iterate through all geometry LOD levels
for (uint32 lodLevel = 0; lodLevel < numLODs; ++lodLevel)
{
// iterate through all nodes
for (uint32 n = 0; n < numNodes; ++n)
{
// get the current node
EMotionFX::Node* node = skeleton->GetNode(n);
if (node == nullptr)
{
continue;
}

// get the mesh for the node, if there is any
EMotionFX::Mesh* mesh = actor->GetMesh(lodLevel, n);
if (mesh == nullptr)
{
continue;
}

// skip collision meshes
if (mesh->GetIsCollisionMesh())
{
continue;
}

// classify the mesh type
EMotionFX::Mesh::EMeshType meshType = mesh->ClassifyMeshType(lodLevel, actor, node->GetNodeIndex(), false, 4, 200);

// remove the meshes
if (meshType != EMotionFX::Mesh::MESHTYPE_CPU_DEFORMED)
{
actor->RemoveNodeMeshForLOD(lodLevel, n);
} // if mesh is cpu deformed
}
}
}
} // namespace Integration
} // namespace EMotionFX