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.
@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.