Best way to update mesh

What is the best way to update a mesh which has changed?
Currently I have only been able to add a new mesh and haven’t been able to remove the old one.

I am pretty sure there is no way to update the mesh without creating a new one and destroying the other. So I recalculate the vertices normals and texcoords and put that into a mesh. Personally turning it into a geometry seems wasteful since its the same geometry specific settings each time (but I’m new so I’ll deal with it). I then attach that to the rootNode and call rootNode.detatchChildNamed(“BlockMesh”); which is what I name my geometry. This is showing both the new and old mesh.
I have even tried rootNode.getChild(“BlockMesh”) checking if that exists (which my debugging shows that it does) and then calling .removeFromParent() on that (which is returning true) so is something not being updated that I am missing?

Also a small side question, do you think updating the mesh should be done in a separate thread? Because I’m thinking it should be to prevent framerate lag from it being updated rapidly. But thats just me thinking without any testing done.

There is a BufferUtil class which allows you to access the buffers of a mesh in the graphics card.Then you can update those, you shouldn’t be creating new buffers each frame. I’ve posted examples of it before, should be able to search nd find them.

If you detach a mesh and it is still there then one of two things happened:

  1. it wasn’t really detached
  2. there was more than one mesh there.

You’ve sort of ruled out (1)… but we haven’t because the code looks fine from here. But 2 could be a possibility… again the code looks fine from here.

Maybe post a simple test case illustrating the problem. My guess is that the simple test case will work fine and then you can track down what is different about your real code.

@wezrule I’m looking into BufferUtils, would it be possible to clear the entire buffer and reapply one? I can’t seem to find anything that deals with the entire buffer instead of indexes. Using specific indexes wouldn’t be a problem when adding points but would be when removing them.

@pspeed you’re right, although it wasnt either it was that my mesh was actually drawing the old and new mesh on top of each other by accident. I didn’t account for removing parts yet. But thats easy to fix.

Just looking at your original post, you can definitely update a mesh without creating a new one. For example, you can resize a quad at runtime… I do it all the time. All the while it is in a Geometry and part of the scene… no issues if you do it right.

oh wow! its as easy as changing the buffer for the mesh. I was way overcomplicating things…