[Solved] Need help with LOD generation on xbuf models


I tried to generate lod on a model imported with xbuf. but it did not generate.(tried both in SDK and code). it generate OK if i import it directly from .blend —> .j3o

So i decided to generate LOD in blender using “Decimate” modifier.
I generated two LODs then imported them along with my main model to JME.
And set them using mainGeometry.getMesh().setLodLevels(vertexBuffer);

but the result is strange :

here is main model with lod_0 (model’s original index buffer)

wit lod_1

with lod_2

here is how it looks like in blender

here is code :

public static Node loadModel(ModelKey key, AssetManager assetmgr) {

        Node model = (Node) assetmgr.loadModel(key);
        if(model.getChild("LOD") != null){
            System.out.println("found LOD");
            //This is the node i have all lods for my model loaded from blender
            Node modelLODsNode=(Node) model.getChild("LOD");
            SceneGraphVisitor visitor = new SceneGraphVisitor() {
                public void visit(Spatial spatial) {
                    if (spatial instanceof Geometry) {
                        Geometry geometry=(Geometry) spatial;
                        //Create an array of buffer to save LODs
                        VertexBuffer vbuf[]=new VertexBuffer[3]; //mode has 2 lods with it's main mesh
                        //vbuf[0] keeps model's main index buffer
                        for(int i=1;i<3;i++){
                            //Getting lod levels from modelLODsNode
                            Spatial lod= modelLODsNode.getChild(geometry.getParent().getName()+"lod"+i);
                                Geometry lodMesh=(Geometry) ((Node)lod).getChild(0);
                                //Getting lod index buffer
                                System.out.println("set lod level"+i+"to: "+spatial.getName());
                        //setting lods to main geometry 

        return model;

Model download link :

Can you please help

To make it simple, I tested it on a simple sphere.
This time JME SDK could generate LOD but the same problem happens:

for sure something goes wrong with xbuf importer in the case of VertexBuffers.
So i decided to update the whole mesh instead of setting LodLevels.
So i changed this :

VertexBuffer vbuf[]=new VertexBuffer[3];

to this:

Mesh lodMeshes[]=new Mesh[3];

And everything goes fine.
But i need to write my own LODControl then.

Is it possible to just copy the code from the “normal” LodControl to your own control and change those 2 lines?

Yes, i think.
normal control calculate level based on how many pixels on the screen the spatial is taking up.[Javadoc] .
I created my simple and light control which select lod based on distance from camera.

Could be interesting to dump the data from the position and index buffer of the model imported with blender and the model imported with xbuf.

here you are :

Quick info :

xbuf    Index Buffer State:VertexBuffer[fmt=UnsignedInt, type=Index, usage=Dynamic, elements=37827]
Xbuf    Position Buffer State:VertexBuffer[fmt=Float, type=Position, usage=Dynamic, elements=113481]

Blender Index Buffer State:VertexBuffer[fmt=UnsignedInt, type=Index, usage=Dynamic, elements=37827]
Blender Position Buffer State:VertexBuffer[fmt=Float, type=Position, usage=Static, elements=27282]

** Note to Position buffer “Usage” (one is Static the other is Dynamic)

Buffer data was too long to put here. I uploaded it here:

Buffer data printed in one long row for better comparison. So you may turn off wrap text mode in your text editor.


Well…xbuf has almost 4 times the vertex number that’s really strange…
It’s just right after importing right?

@david_bernard_31 do you do some special operation on vertices?

Yes, right after importing
first i converted both to .j3o then directly loaded j3o and got the above information.
if you want I can try directly load them without converting to .j3o

  • tesselation is run on blender side before export (to only export triangle)
  • the exporter don’t de-duplicate vertices

Maybe a bug in xbuf, I’ll investigate (when back to home)

ok so the mesh is already triangulated… maybe the lod generator doesn’t like that…

The Blender Importer also performs triangulation.
Maybe the Generator doesn’t like duplicated vertices, though.

Edit: Does the Engine even support other Geometries than Triangles?

I did a quick test (in the train) export the default blender cube:
blender: 8 vertex, 6 faces
import .blend: 12 triangles (6 quad faces x 2), 36 vertex (12 triangles x 3 vertex)
import .xbuf: 12 triangles (6 quad faces x 2), 24 vertex (8 vertex x 3 quad faces)

So I have the opposite result xbuf vertex < import .blend vertex. So I need to do more test (eg with the sphere/mesh provided by @Ali_RS)

Maybe the issue is caused by the a trick I used:
xbuf use the blender mesh tesselation (not triangulation), it generates mesh with triangles or quads, in the case of quad the xbuf exporter export the 4 vertices but it generate 2 triangles only via indexes:

# xbuf
|\ |
| \|

indexes: 1,2,3,1,3,4
# import blend (hypothesis)
5  |
|\ |
| \|
|  3

indexes: 1,2,3,5,6,4

mhhh you mean the blender loader splits all the quads? that seems very strange…
Also, from what you say, I would expect the opposite result with LOD… and with the number of vertices of the character model.