Level of Detail for models

Hello

I’m trying to set LoD for all objects/models at .j3o scene.

Here’s my code of building which I’m trying to set LoD. The path to node is correct but LoD doesn’t work.
[java] Node house = (Node) rootNode.getChild(“Blacksmith”);
Geometry geo = (Geometry) house.getChild(“geo”);
LodGenerator lodGenerator = new LodGenerator(geo);
lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, 0.10f);
geo.setLodLevel(1);[/java]

You have to add a LodControl to the geometry too

Added:

[java] LodControl lodCtrl = new LodControl();
lodCtrl.setSpatial(geo);
lodCtrl.setEnabled(true);[/java]

Still nothing.

I also tried that code:

[java] for (Spatial spatial : map.getChildren()) {
if (spatial instanceof Geometry) {
listGeoms.add((Geometry) spatial);
}
}
reductionvalue = 0.80f;
lodLevel = 1;
for (final Geometry geometry : listGeoms) {
LodGenerator lodGenerator = new LodGenerator(geometry);
lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue);
geometry.setLodLevel(lodLevel);

    }[/java] but still 0 effect lol
@Skatty said: Added:

[java]
LodControl lodCtrl = new LodControl();
lodCtrl.setSpatial(geo);
lodCtrl.setEnabled(true);[/java]

Still nothing.

You didn’t add the control to the geo controls list…setSpatial is automatically called when you add it but not sufficient to make it work…your control isn’t registered in the controls to update…update(float tpf) can’t be called…

[java]geo.addControl(lodCtrl);[/java]

Reading the doc should be usefull…
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:level_of_detail
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_controls

=> Activate the LOD Control

After generating the LODs for the geometry, you create and add a com.jme3.scene.control.LodControl to the geometry. Adding the LodControl activates the LOD optimizaton for this geometry.

LodControl lc = new LodControl();
myPrettyGeo.addControl(lc);
rootNode.attachChild(myPrettyGeo);

1 Like