Custom lod mesh

Hi.

I’ve been battling this problem tonight. I’m trying to optimize my scenes by creating some lods on my already simple meshes. BUt i must be doing something wrong, because they don’t show up.

I’m using the TestLodStress as base, and is replacing the teapot with my simple, generated meshes.



If i understand correctly, the first lod (0) is the same as the indexBuffer (please correct me if i’m wrong), and i set it up like this:



[java]VertexBuffer v0 = new VertexBuffer(VertexBuffer.Type.Index);

v0.setupData(Usage.Dynamic, 1, Format.Int, BufferUtils.createIntBuffer(indexes) );



VertexBuffer v1 = new VertexBuffer(VertexBuffer.Type.Index);

v1.setupData(Usage.Dynamic, 1, Format.Int, BufferUtils.createIntBuffer(lod1) );

setLodLevels( new VertexBuffer[]{v0, v1} );[/java]



But like i said, it’s all black (and they work when i don’t set up the lods).

Any tips?

You need to set an index buffer even if you’re not using LOD. Also you have to be using LodControl since it manages changing the LOD level depending on # of vertices per pixel.

I do set the index buffer as well. I just use the same int[] to populate lod0 as well.

The thing is, it works when i comment out those lines, and comment out the LodControl in TestLodStress. Then my meshes show up correctly.

Even if i remove my lod1 indices and only create the lod0, it’s just black.

You need to set an index buffer even if you’re not using LOD



Opengl specifications cleary say that a index buffer is there to make rendering more efficient by reducing redundant vertices, but you don’t need to have one. Might be that JME requires them tho, not sure about that.

I know that topic is old, but today I faced a similar problem, though in my case I was generating mesh from a heightmap in TerrainPatch. First of all, the format must be UnsignedInt, UnsignedShort or UnsignedByte (it was written somewhere). In my case, the format was changing while the application was running, so here is a small example to show, how it works:

[java]
Format format = mPatch.getMesh().getBuffer(Type.Index).getFormat();

    VertexBuffer v0 = new VertexBuffer(VertexBuffer.Type.Index);
    VertexBuffer v1 = new VertexBuffer(VertexBuffer.Type.Index);
    VertexBuffer v2 = new VertexBuffer(VertexBuffer.Type.Index);
    
    if (format == Format.UnsignedShort)
    {
    	ShortBuffer buf = (ShortBuffer)mPatch.getMesh().getBuffer(Type.Index).getData();
        ShortBuffer buf2 = BufferUtils.createShortBuffer(buf.capacity()/3);
        
        for (int i = 0; i < buf2.capacity(); i++)
        {
        	buf2.put(i, buf.get(i*3));
        }
        
    	v0.setupData(Usage.Dynamic, 1, format, mPatch.getMesh().getBuffer(Type.Index).getData());
    	v1.setupData(Usage.Dynamic, 1, format, (Buffer)buf2);
    	v2.setupData(Usage.Dynamic, 1, format, BufferUtils.createShortBuffer(0));
    }
    else if (format == Format.UnsignedInt)
    {
    	IntBuffer buf = (IntBuffer)mPatch.getMesh().getBuffer(Type.Index).getData();
        IntBuffer buf2 = BufferUtils.createIntBuffer(buf.capacity()/3);
        
        for (int i = 0; i < buf2.capacity(); i++)
        {
        	buf2.put(i, buf.get(i*3));
        }
        
    	v0.setupData(Usage.Dynamic, 1, format, mPatch.getMesh().getBuffer(Type.Index).getData());
    	v1.setupData(Usage.Dynamic, 1, format, (Buffer)buf2);
    	v2.setupData(Usage.Dynamic, 1, format, BufferUtils.createIntBuffer(0));
    }
            
    VertexBuffer[] array = new VertexBuffer[3];
    array[0] = v0;
    array[1] = v1;
    array[2] = v2;
    
    mPatch.getMesh().setLodLevels(array);
    
    LodControl control = new LodControl();
    mPatch.addControl(control);

[/java]