I tried to use the LodGenerator to reduce the number of vertices on my models on the fly because on Android I sometimes get (com.jme3.renderer.RendererException: OpenGL ES does not support 32-bit index buffers. Split your models to avoid going over 65536 vertices. ) errors and wanted to avoid them. I dont have influence over the models because the users pick them, so I cant just use smaller models ;)
Afaik the lod generator works on indices, not on vertices. So you always keep your amount of vertices but only a few of them are actually rendered.
Ok that explains why I only have to exchange the index buffer How hard would it be to implement the “cleanup” of the vertex buffer based on the new index buffer? I probably have to loop over all indices and remove the unused vertices (and which other buffers do I need to clean up then as well?) Or is there a better way?
You need to clean up all the buffers attached to the mesh actually, with no exception.
It’s not complicated but it’s tedious.
I recommend making another mesh compiled from the old one. For each index in the ne index buffer, you extract its data from all the buffers and copy it in the new mesh’s buffers.
What does mesh.getBuffer(VertexBuffer.Type.Index).getNumComponents() calculate ?
I thought it calculates the absolute entries in the index buffer. So the number of vertices.
But when i save all the entries in the indexbuffer and delete the duplicated entries , the number is different to the number mesh.getBuffer(VertexBuffer.Type.Index).getNumComponents() number.
Can someone explain?
The correspondence between vertices and indices is not 1:1, you may have vertices that are not used by any triangle, or vertices that are used by several.
In your case you have 39888 indices and 17768 vertices, so the vertices are shared by multiple triangles.
Let me cut out the irrelevant parts and see if it makes it clearer:
“i dont understand why my model has missing textures when i change the other buffers.”
Why do you change the other buffers? If you change one buffer (say moving items around) then you would have to change ALL of them (other than index) or they will not match anymore. But first, try not changing the other buffers to see if that fixes the problem.
Why do you tell me that you tried it without modifying the buffers and it still fails… then show me code where you modify the buffers? I’m not even sure why you are copying values or what returnarray has but it’s going to be hard to convince us that it doesn’t work even when not modifying the buffers if we only see an example where you still modify the buffers.
Make a simple test case where you do LOD as intended by running your mesh through the utility and then setting the LOD level on Geometry. If your model still looks messed up then we’ll have something to talk about otherwise the problem is in your vertex manipulation and a misunderstanding of how index buffers and LOD works. Because you can’t move vertexes around without also changing the individual index buffer values.