I’m trying to get the vertex data from a skeletal mesh that has been changed using morph targets. Everything I’ve tried so far just gets me the original shape. GetCPUSkinnedVertices said that is would include morph targets, but it doesn’t. I’ve made sure it’s not doing the morphs on the GPU. Any help would be appreciated.
Code:
Mesh->GetCPUSkinnedVertices(VertData, 0);
for (int i = 0; i < VertData.Num(); i++)
{
Locations.Add(VertData[i].Position);
}
and to test I’m just looping through the results in BP and drawing a debug point.
I’ve also tried ComputeSkinnedPositions, but that seems to now need me to suspend the render thread, which I’m not sure how to do.
its a bug. in function USkinnedMeshComponent::GetCPUSkinnedVertices
// Recreate render state and flush the renderer
RecreateRenderState_Concurrent();
this would empty the active morph targets.
To slove this bug:
replace:
// Recreate render state and flush the renderer
RecreateRenderState_Concurrent();
with:
// Recreate render state and flush the renderer
// Cached the active morph targets, so that this function could work properly
TArray<FActiveMorphTarget> CachedActiveMorphTargets = ActiveMorphTargets;
TArray<float> CachedMorphTargetWeights = MorphTargetWeights;
if (bRenderStateCreated)
{
check(IsRegistered()); // Should never have render state unless registered
DestroyRenderState_Concurrent();
checkf(!bRenderStateCreated, TEXT("Failed to route DestroyRenderState_Concurrent (%s)"), *GetFullName());
}
if (IsRegistered() && GetWorld()->Scene)
{
ActiveMorphTargets = CachedActiveMorphTargets;
MorphTargetWeights = CachedMorphTargetWeights;
CreateRenderState_Concurrent();
checkf(bRenderStateCreated, TEXT("Failed to route CreateRenderState_Concurrent (%s)"), *GetFullName());
}