Triangle Index Update issue

I am removing triangles from a mesh by updating the buffers. I remove the indexes/positions/normals and texture mapping of the selected triangle, set the buffers and the triangle disappears. All good except trying to remove a second triangle doesn’t work or causes one that I did not select to disappear.
I soon realized that if I click on the blank area where the triangle used to be I can still get the triangle Index?? How is that area even responding to my actionlistener?

When I call this I can see that the triangle count is decreasing:
int triCount = resultsGame.getClosestCollision().getGeometry().getTriangleCount();

When I call this after clicking on a blank area where the triangle used to be it returns the index of that dead and gone triangle:
int triIDX = resultsGame.getClosestCollision().getTriangleIndex() ;

It seems as if there is a discrepancy in the indexes where there is a ghost copy that refuses to update. I looked up the ‘getTriangle’ function in and can see that it is using the index buffer to find the Triangle vertices. Is the index that gets passed into that function in any way related to the Index returned by getIndex on the Triangle object?

I’m updating the buffers as follows - nothing earth shattering. I added the clear buffer and .updateCounts to see if I could somehow get the deleted triangle to go away.

                       m.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createShortBuffer(ibNewarray));
                       m.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vbNewarray));
                       m.setBuffer(VertexBuffer.Type.Normal, 3, BufferUtils.createFloatBuffer(normNewarray));

1 Like

That’s actually good to know and maybe should’ve been called automatically when you invalidate buffers. Is it mentioned on the wiki section about custom meshes, @mitm?

Except you may change buffers but not alter the collision data.

JME leaves it up to you. It can’t hold everyone’s hand for every little thing and if it did then everyone would complain about how rigid and inflexible everything was.

Ah ok, I didn’t make the connection there that triangle count and index are properties of Collisionresults. Thanks for clearing it up!

You mentioned performing collisions… that uses collision data. Collision data is built from the position+index data the first time you try a collideWith() with that mesh.

…so if you remove/add triangles then you need to clear the collision data so it will get created again.

1 Like