x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Create procedural mesh from animated skeletal mesh?

Is there a way to do this in C++?

I've found a couple of things that explain something similar but can't quite work it out.

Basically I want to have a procedural mesh that is an exact copy of the skeletal mesh, including animations and morphs, and have it updating at runtime.

It should also have collision.

I don't mind if this will be expensive, it will only be used for one or 2 meshes.

Product Version: UE 4.19
Tags:
more ▼

asked Jul 15 '18 at 05:30 PM in C++ Programming

avatar image

anti_zer0
65 10 16 20

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

This should help, however it doesn't work with morph targets.

 void CopySkeletalMeshToProcedural(USkeletalMeshComponent* SkeletalMeshComponent, int32 LODIndex, UProceduralMeshComponent* ProcMeshComponent)
 {
 
     FSkeletalMeshRenderData* SkMeshRenderData = SkeletalMeshComponent->GetSkeletalMeshRenderData();
     const FSkeletalMeshLODRenderData& DataArray = SkMeshRenderData->LODRenderData[LODIndex];
     FSkinWeightVertexBuffer& SkinWeights = *SkeletalMeshComponent->GetSkinWeightBuffer(LODIndex);
 
     TArray<FVector> VerticesArray;
     TArray<FVector> Normals;
     TArray<FVector2D> UV;
     TArray<int32> Tris;
     TArray<FColor> Colors;
     TArray<FProcMeshTangent> Tangents;
 
     
     //get num vertices
     int32 NumSourceVertices = DataArray.RenderSections[0].NumVertices;
 
     for (int32 i = 0; i < NumSourceVertices; i++)
     {
         //get skinned vector positions
         FVector SkinnedVectorPos = USkeletalMeshComponent::GetSkinnedVertexPosition(SkeletalMeshComponent, i, DataArray, SkinWeights);
         VerticesArray.Add(SkinnedVectorPos);
 
         //Calc normals and tangents from the static version instead of the skeletal one
         FVector ZTangentStatic = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.VertexTangentZ(i);
         FVector XTangentStatic = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.VertexTangentX(i);
 
         //add normals from the static mesh version instead because using the skeletal one doesn't work right.
         Normals.Add(ZTangentStatic);
 
         //add tangents
         Tangents.Add(FProcMeshTangent(XTangentStatic, false));
 
         //get UVs
         FVector2D uvs = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.GetVertexUV(i, 0);
         UV.Add(uvs);
 
         //dummy vertex colors
         Colors.Add(FColor(0, 0, 0, 255));
     }
 
 
     //get index buffer
     FMultiSizeIndexContainerData indicesData;
     DataArray.MultiSizeIndexContainer.GetIndexBuffer(indicesData.Indices);
 
     //iterate over num indices and add traingles
     for (int32 i = 0; i < indicesData.Indices.Num(); i++)
     {
         uint32 a = 0;
         a = indicesData.Indices[i];
         Tris.Add(a);
     }
 
     //Create the procedural mesh
     ProcMeshComponent->CreateMeshSection(0, VerticesArray, Tris, Normals, UV, Colors, Tangents, true);
 }


more ▼

answered Jun 07 '19 at 08:57 PM

avatar image

tofmedPOST
1 1 2

avatar image SimplestWay Jun 11 '19 at 03:52 AM

Hi, tofmedPOST: thank you so much for your greatest work done here, but there is a little problem in your code: error C2065: 'SkinWeights': undeclared identifier, how can I get the value of the SkinWeights variable?

avatar image SimplestWay Jun 11 '19 at 04:04 AM

Oh, I figure it out now: add FSkinWeightVertexBuffer* SkinWeights = SkeletalMeshComponent->GetSkinWeightBuffer(LODIndex); before line 21 and it works fine. thanks a lot for your amazing work!

avatar image tofmedPOST Jun 11 '19 at 05:32 PM

Oops, looks like i forgot a line - I've updated my answer, so you shouldn't be seeing errors now :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question