Efficient way of editing vertex positions during runtime

Hi

I’m looking for a way to update the vertex positions of every vertex of a mesh with 65536 vertices from C++ code. It needs to be updated every few frames with values calculated in code, so it needs to be somewhat efficient.

I tried this, with no effect:


if (NewElement->GetStaticMeshComponent()->GetStaticMesh()->RenderData->LODResources.Num() > 0)
{
    FPositionVertexBuffer* VertexBuffer = &NewElement->GetStaticMeshComponent()->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers.PositionVertexBuffer;
    if (VertexBuffer)
    {
        const int32 VertexCount = VertexBuffer->GetNumVertices();
        for (int32 Index = 0; Index < VertexCount; Index++)
        {
            VertexBuffer->VertexPosition(Index) += FVector(float(Index), float(100* Index), float(10000 * Index));
        }
    }
}

I’ll appreciate help with finding a working solution.

As for now, I’m looking for a simple solution, just to start with something. But I know, that updating the mesh CPU side is not the most efficient way, so maybe it would be easier/faster to calculate the position for every vertex and then pass it to Vertex shader? Or generate some pseudo-texture, upload it to GPU and use it in the vertex shader? Does anyone have an example of such a mechanism in UE?

Regards

1 Like

Mother of god what? Why do you want to do this? :joy:

To perform some experiments, this is not a production usage.

1 Like

In that case, I think the rendering portion of the form might be able to help you better - they’ll have more insight into the storage of complex per vertex information.