Creating dynamic Custom Mesh


I followed this tutorial Custom Meshes and now I wanted to create a grid of dots(vertices) dynamically. Finally the vertices should then produce triangles, so that I get a shape.

My Questions:

-I always create a new Buffer (Type.Position) and set the Buffer of the Mesh instead of editing the existing Buffer. Is there any possibility for just editing the existing Buffer and Positions of the vertices?

-Is there a nice way to connect the dots/vertices and produce Quads without setting or calculating the Indices for the Type.Index Buffer?

Some Screenshots:

  1. The grid consisting of dots

  2. The same grid with Mesh.Mode = Triangles and without setting the Indices Buffer



You can just keep modifying the original buffer. (Use rewind/position and then start putting again). I then set the modified buffer into the mesh again and call updateBounds.

Okay, thanks. Can you give me an example of putting new vectors to the buffer (code)? And how can I modify one specific vertex, for example the vertex at the position [2, 3] in the grid?







It’s not rocket science :wink:

To modify the specific vertex you need to know its index. So lets say you lay them out in an x/z grid you would have:

[java]int pos = x+ywidth;

3); // *3 as 3 floats in each vertex





But really keeping track of the indexes is nothing to do with meshes, it’s all about how you organise your data.

Nice! Thanks for your advice! It’s working now for me:


FloatBuffer positionBuffer;

positionBuffer = geo.getMesh().getFloatBuffer(Type.Position);





geo.getMesh().setBuffer(Type.Position, 3, positionBuffer);[/java]

And now to my other question:

Do you have any hint how the triangles will be drawn correctly (Screenshot 2)? For example: I have 4 vertices and I want to have a square (2 triangles). Or any adivce on how to calculate the index of my new vertex, so that the connecting of the vertices is correctly?

Sorry but no. That’s way too situational and there is no one “correct” solution for all situations.

Just think about how you organise your data and as a result what the positions of the indexes in the mesh will be and then make appropriate connections.

You can always turn off back face culling (at least at first) to simplify things while you get the actual indexes correct - then once that is done turn on face culling and correct the direction of each triangle.