Download

Copy animated skeletal mesh to procedural mesh at runtime

I have a character in my game with an animation blueprint and morph targets.

Is there a way to copy the animated skeletal mesh to a procedural mesh that updates at run time?

The result would be a procedural mesh clone of the animated skeletal mesh with collision (really it’s just the collision I’m interested in).

I found a few things that were interesting but I’m still a bit stuck. There is a way to get the skeletal mesh vertex locations and normals in C++ but so far I’ve had no luck with it.

This post on the answer hub is useful Can't seem to get USkeletalMeshComponent::GetSkinnedVertexPosition to return correct positions for 'rigid' verts - UE4 AnswerHub

But I’m having trouble getting this code to compile.

CalcBoneVertInfos is giving me “identifier is undefined”, although I am including MeshUtilities.h

I managed to get the animated vertex positions of the mesh, but I can’t find the triangles and normals needed for the procedural mesh generation. Been searching for aaaages for a solution, did anyone else manage to do this?

So I can get the normals now too!!! but the triangles are nowhere to be found!!! Agh!! help meeeee!!

Here is the code to get this to work
FSkeletalMeshRenderData* datarender = meshroot->GetSkeletalMeshRenderData();

FSkeletalMeshLODRenderData& dataarray = datarender->LODRenderData[0];
int32 a = dataarray.RenderSections[0].NumVertices;
for (int32 i = 0; i < a; i++)
{
    FVector b = dataarray.StaticVertexBuffers.PositionVertexBuffer.VertexPosition(i);
    VerticesArray.Add(b);
    FVector c = dataarray.StaticVertexBuffers.StaticMeshVertexBuffer.VertexTangentZ(i);
    normals.Add(c);
    FVector2D d = dataarray.StaticVertexBuffers.StaticMeshVertexBuffer.GetVertexUV(i, 0);
    UV.Add(d);
}



FMultiSizeIndexContainerData indicesData;
dataarray.MultiSizeIndexContainer.GetIndexBufferData(indicesData);
for (int32 i=0;i<indicesData.Indices.Num();i++)
{
    int32 a = 0; 
    UInt32ToInt32(indicesData.Indices*, &a);
    Tris.Add(a);
}

Wow thanks! I actually got this to work in the end, not sure if this is the same as my code though. Does it work with morph targets too?

My code above only got vert position of the static mesh version of the skeletal mesh, u should use loop for the number of vertices and use mesh->GetSkinnedVertexPosition to get the skinned position, i did not try with morph target but i think i should work :D.

Actually got round to trying this today and it doesn’t include morph targets unfortunately. I’m sure there’s a way to do it though so I’ll keep looking.