Mesh wont get drawn after setting lod levels

Hi,

I created a custom mesh after this tutorial: Custom Mesh Shapes. When I call setLodLevels on a mesh object it wont get drawn anymore. This how I build the VertexBuffer array:

lods[index] = new VertexBuffer(Type.Index); lods[index].setupData(Usage.Static, 3, Format.Int, BufferUtils.createIntBuffer(indBuffer));

Then I set all buffers:

mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertBuffer)); mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indBuffer)); mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normBuffer)); mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texBuffer)); // When comment out this line, the mesh gets drawn fine. mesh.setLodLevels(lods); mesh.updateBound(); mesh.updateCounts();

Then I creat the LodControl and add it to the formerly created geometry object.

LodControl lodControl = new LodControl(); planetGeo[i].addControl(lodControl);

Did I forget anything?

How are you actually generating the LOD levels? You have to fill those buffers with index data otherwise nothing will be visible …

Consider using the new LodGenerator class to generate your LOD levels instead:
http://hub.jmonkeyengine.org/forum/topic/brand-new-lod-generator/

1 Like

Ah thanks for the link. I’ll give it a try.

The LOD levels are okay. I debugged into the index buffers (int arrays) and the data seemed fine. I create them by dividing triangles into 4 new. So every lod step increases the amount of triangles by factor 4.

just as a sidetip in case you dont know about
http://hub.jmonkeyengine.org/forum/topic/brand-new-lod-generator/

I tried to further debug the issue. This should actually work, shouldn’t it?

mesh.setBuffer(Type.Index, 3, Format.Int, getLods()[5].getData());

At least it doesn’t work. getLods() returns the array with VerterBuffer objects. So I guess that there must be something wrong with them. The indBuffer int arrays I apply to setupData are okay:

lods[index].setupData(Usage.Static, 3, Format.Int, BufferUtils.createIntBuffer(indBuffer));

How could I debug the VertexBuffer objects? At a break point I can’t look onto its actual data and their buffers are not backed up by an array.

Problem solved, the format parameter of the VertexBuffer has to be UnsignedInt.