[Solved] How to properly update mesh buffer?

I have a mesh and wanted to reassign its texture coordinates so I started with something like this:

  1. create new float buffer (2 floats for every vertex)
  2. assign (“put” method) floats to the new float buffer
  3. mesh.setBuffer(Type.TexCoord, 2, newFloatBuffer)

    Is this the appropriate way to do it? I ask because I have a problem with the mesh not showing the way I want it to sometimes, and thought this might be the problem.

There is a method you need to call to tell the engine that the buffer has changed, either it is in vertexbuffer or it was in mesh not sure.

(also you would be faster and not producing garbage by getting the old buffer, and just rewind, and write your new values over the old)


@Empire Phoenix I took your advice and used mesh.getFloatBuffer(…) and wrote over the it. I don’t think the rewind is necessary though, since it worked without it. I used the “put” method to write into the FloatBuffer.

@nehon updateModelBound() didn’t seem to do anything.

After many failed attempts, I finally used mesh.getBuffer(Type.TexCoord).setUpdateNeeded(), which seemed to solve some of the problem. The model always changes the right way, but I’ve ran into another issue. It affects all of the same models. For example, if I change the buffer of a rock model, it also changes a different cloned rock model.

The mesh is shared by default for , you need to explicitly clone it if you dont want that behaviour.

I used geom.deepClone() instead of geom.clone() and everything worked. Awesome :smiley: , thanks.