Brand new Lod Generator

i dont understand why my model has missing textures when i set the new indexbuffer and change the other buffers. :frowning:

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.

Thanks for your answer.
When i just set the new indexbuffer the same problem appears . I think triangles are missing.

Here my code:

Generate new index buffer :

                    LodGenerator lodGenerator = new LodGenerator(geometry);
                    VertexBuffer[] reducedMesh = lodGenerator.computeLods( LodGenerator.TriangleReductionMethod.PROPORTIONAL, 0.5f);
                    VertexBuffer newIndexBuffer = reducedMesh[1];

Set new index buffer :

mesh.clearBuffer(VertexBuffer.Type.Index);
mesh.setBuffer(newIndexBuffer);

Generate new position buffer :

        VertexBuffer buffer = mesh.getBuffer(VertexBuffer.Type.Position);
        Vector3f[] newPosArray = new Vector3f[buffer.getNumElements()];
       
  for(int index : returnArray){
      newPosArray[index] = new Vector3f();
      newPosArray[index].setX((Float) buffer.getElementComponent(index, 0));   
      newPosArray[index].setY((Float) buffer.getElementComponent(index, 1));
      newPosArray[index].setZ((Float) buffer.getElementComponent(index, 2));
     }

The same method I used for the normal buffer and the TexCoord buffer.

And at the end :

 mesh.clearBuffer(VertexBuffer.Type.TexCoord);
 mesh.clearBuffer(VertexBuffer.Type.Normal);
 mesh.clearBuffer(VertexBuffer.Type.Position);
 mesh.setBuffer(VertexBuffer.Type.TexCoord , 2 , BufferUtils.createFloatBuffer(newTextureCArray));     
 mesh.setBuffer(VertexBuffer.Type.Normal , 1 , BufferUtils.createFloatBuffer(newNormalArray));
 mesh.setBuffer(VertexBuffer.Type.Position , 3 , BufferUtils.createFloatBuffer(newPosArray));
 mesh.getBuffer(VertexBuffer.Type.TexCoord).setUpdateNeeded();
 mesh.getBuffer(VertexBuffer.Type.Normal).setUpdateNeeded();
 mesh.getBuffer(VertexBuffer.Type.Position).setUpdateNeeded();
 mesh.updateCounts(); 
 mesh.updateBound();

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. :wink:

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.

:blush:

Do you mean:

    LodGenerator lodGenerator = new LodGenerator(geometry);
    VertexBuffer[] reducedMesh = lodGenerator.computeLods(
    LodGenerator.TriangleReductionMethod.PROPORTIONAL, 0.5f);
    VertexBuffer newIndexBuffer = reducedMesh[1];

       
    mesh.clearBuffer(VertexBuffer.Type.Index); 
    mesh.setBuffer(newIndexBuffer);

and then :

  geometry.setLodLevel(1);

No

The intended way to make it work is

    LodGenerator lodGenerator = new LodGenerator(geometry);
    VertexBuffer[] reducedMesh = lodGenerator.computeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, 0.5f);
    mesh.setLodLevels(reducedMesh);

...
   geometry.setLodLevel(1);

Else you can even use the bakeLods method fo the generator that will assign them for you to the mesh.

See

No, I meant what I said:

Not once did I mention funky buffer manipulations that would break LOD.

When i make it like nehon said , some triangles are still missing.

Well it’s not magic. 50% reduction maybe a bit too hardcore to expect keeping the mesh integrity.
Keep in mind that LoD is not meant to reduce the number of polygon of a too much detailed mesh, it’s supposed to reduce number of polygons when the objects gets far away from the camera when less details are needed to keep the object appearance realistic.
Looking for a reduced lod level up close will almost always look bad.

Look at the original post, Jaime does have similar missing polygons, but it’s unnoticeable when it’s far away from the camera.

1 Like

ok thanks for your help :slight_smile: