• 3D
  • How to efficiently change a few vertices in a big mesh?

Hi,

I am trying to make a map editor for my game. A medium sized map would have around 320k triagnles.

Two ways I found to modify the mesh at runtime are: 1) Get the ArrayMesh from the MeshInstance, modify it, delete the old surface, add the new one and assign the modified ArrayMesh to the MeshInstance. 2) Create a MeshDataTool from the surface, modify the mesh and commit to surface.

In both cases the final step of assigning/commiting the modified mesh takes most of the total time, close to a hundred ms. I tried running the modify methods in separate threads so it won't block/lag the UI, but that leads to weird glitches where the map flashes in and out of existence or the material is removed from the mesh all of a sudden.

Is there a way to do in place changes to meshes at runtime without having to reload the entire mesh every time?

Create a new MeshInstance and don't remove the old MeshInstance until the new one is ready? Just a thought.

Thanks, this did indeed help me to get my UI to run smooth, but the whole solution is far from clean imo. I have to do so much work for every simple change. What if I want to change the position of a single vertex, do I really have to go through the process om copying and adding/committing the entire mesh ? Is there no way to just alter one or more vertices without having to reload the entire mesh? I'm pretty new to computer graphics but character models move all the time which means (hundreds of) thousands of vertices change position every frame. How come that can happen very smoothly while changing a few vertices manually takes so much effort?

You mean update one or two vertices in the GPU memory? That is what Geometry Shaders would be for, but alas we don't have access to them as of yet. Vulkan renderer might enable that, though I'm not sure if we will get that on the initial release.

In the meanwhile if you need to just move a few vertices you might be able to maybe do that via the vertex shader. But you wont be editing the mesh topology via vertex shaders.

To be fair, afaik if you have access to compute and tessellation shaders, they can probably do the same that you could do with geometry shaders but faster. So I wouldn't be surprised if we never see geometry shaders at all.

edit: hmm, interestingly intels HW is better at GS than nvidias or amds according to this, though it's an old article at this point: http://www.joshbarczak.com/blog/?p=667