Changing TriMesh geometry on the fly

Hi,



How do I change the geometry of a TriMesh on the fly?



After I have set the new vertex positions with   


public void reconstruct(FloatBuffer vertices, FloatBuffer normal,
            FloatBuffer color, FloatBuffer texture, IntBuffer indices)



what should I call so that the geometry is updated?

Currently I'm just calling updateModelBound();

Also, is there some other way than calling reconstruct to do this?

You can acces the buffers directly too, that's all it takes. Make sure you don't use any locking or VBO though!

Ok, cool. 



Are locks or VBO:s automatically activated somehow?  Do I need to turn them off?  If so, how?

Not if you just use your own trimesh. Some jME classes use it though (eg TerrainBlock)

Ok, thanks.



The reason things don't show up must be some bug in my own code then :slight_smile:

I use terrainblocks - but I have to call .updateFromHeightMap() on my TB each time I modify it - I suspect trimesh has something similar after you modify the underlying height array?

Terrainblocks use VBO, as mentioned.



Really, for a regular trimesh, all updates should be taken into account for the next rendering.

I figured out the problem (unrelated to this, had forgot to initialize something).



I'm doing a TriMesh that changes number of used vertexes (it's a brush stroke in a painting application).  To get it to ignore the vertexes that are not yet used from the buffers, I had to set the limit of the vertex, index, etc. buffers, and then call the reconstruct method of TriMesh, passing in always the same buffers.  This way I can vary the number of vertexes I'm using in the TriMesh (up to the maximum size of the buffers I have allocated).  Setting the limit is a bit tricky (first set position, then call flip…  the buffers have a weird API).



I also called updateModelBound(), as I guess that is needed to recalculate the bounds whenever changing the geometry manually.