Hello everyone! How i can modify vertex in static mesh using c++? I have c++ code to get the position of vertex, but i cant understand how modify vertex in realtime.
TArray<FVector> ADoorModify::MeshData(const UStaticMeshComponent* StaticMeshComponent)
{
TArray<FVector> vertices = TArray<FVector>();
// Vertex Buffer
if (!IsValidLowLevel()) return vertices;
if (!StaticMeshComponent) return vertices;
if (!StaticMeshComponent->GetStaticMesh()) return vertices;
if (!StaticMeshComponent->GetStaticMesh()->RenderData) return vertices;
if (StaticMeshComponent->GetStaticMesh()->RenderData->LODResources.Num() > 0)
{
//PositionVertexBuffer
FPositionVertexBuffer* VertexBuffer = &StaticMeshComponent->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers.PositionVertexBuffer;
FStaticMeshVertexBuffer* StaticMeshVertexBuffer = &StaticMeshComponent->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers.StaticMeshVertexBuffer;
FStaticMeshBuildVertex* StaticMeshBuildVertex;
StaticMeshBuildVertex->Position = FVector(0, 0, 0);
// StaticMeshVertexBuffer->AppendVertices(StaticMeshBuildVertex,1);
//&StaticMeshComponent->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers
if (VertexBuffer)
{
const int32 VertexCount = VertexBuffer->GetNumVertices();
for (int32 Index = 0; Index < VertexCount; Index++)
{
//This is in the Static Mesh Actor Class, so it is location and tranform of the SMActor
const FVector WorldSpaceVertexLocation = GetActorLocation() + GetTransform().TransformVector(VertexBuffer->VertexPosition(Index));
//add to output FVector array
vertices.Add(WorldSpaceVertexLocation);
const FVector test = FVector(0, 0, 0);
//WorldSpaceVertexLocation.
//GetActorLocation() + GetTransform().TransformVector()
VertexBuffer->VertexPosition(Index) = FVector(1100.0, -1100.0, 110);
UE_LOG(LogTemp, Warning, TEXT("My Location is: %s"), *VertexBuffer->VertexPosition(Index).ToString());
}
}
}
//StaticMeshComponent->GetStaticMesh()->PostEditChange();
// StaticMeshComponent->GetStaticMesh()->PostLoad();
// StaticMeshComponent = NULL;
return vertices;
}