I am working on transferring my Unity soft-body physics project to Unreal 4. I need to be able to modify the position of vertices on an existing mesh. I know I can’t use the static mesh component since my mesh will be constantly deforming during runtime. Any suggestions?
Hi,
I was looking at the same question, here is what I found, if you still need it of for future searcher:
I use a UProceduralMeshComponent.
The creation:
VisualMesh::createMesh()
{
mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedMesh"));
RootComponent = mesh;
// Create buffers
TArray<FVector> vertices;
TArray<int32> Triangles;
TArray<FVector> normals;
TArray<FVector2D> UV0;
TArray<FProcMeshTangent> tangents;
TArray<FLinearColor> vertexColors;
// Fill buffers
...
// Create mesh
mesh->CreateMeshSection_LinearColor(0, vertices, Triangles, normals, UV0, vertexColors, tangents, true);
}
The update:
TArray<FVector> vertices;
TArray<FVector> normals;
for (int i = 0; i < nbrV; i++)
{
vertices.Add(FVector(newX, newY, newZ));
normals.Add(FVector(newX, newY, newZ));
}
mesh->UpdateMeshSection(0, vertices, normals, TArray<FVector2D>(), TArray<FColor>(), TArray<FProcMeshTangent>());