Updating Mesh buffers from native code

Hello monkeys,

I am facing a problem trying to update the position Buffer (vertices) of a Mesh from a native c++ code (for softBody physics).

So the first attempt for updating the render was to create a new Mesh each frame with a given position (vertex) array. This work, but can we do better ? Maybe try to update only the buffer directly from the c++ side (JNI binding).


In the second choice the buffer is updated but theres are no changes in the render :confused:

what I already tried :

  • setting the geometry to setDynamic(); or setStreamed();
  • using geom.getMesh().updateBound(); and geom.updateModelBound();

I think @normen and @pspeed have plenty of tips to give.

Did you use VertexBuffer.setUpdateNeeded()?

Thank, using setUpdateNeeded() after updating the buffer worked !

1 Like

Note: you don’t have to do that if you call updateData() on the VertexBuffer.

Here is my general buffer handling approach:

    VertexBuffer pos = ...
    FloatBuffer pb = (FloatBuffer)pos.getData();
    pb.rewind();

    // do stuff with the buffer

    pb.rewind();
    pos.updateData(pb);

This way handles the case where you need to create a new buffer (say it grows or whatever) also.