LoD in JME

I saw tutorial: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:level_of_detail
and set up LoD for geometry in Scene Composer, it works fine but it doesn’t work in game.

Did you add the LodControl to the geometry?

I have to write that? or there is code somewhere

Read the entire doc, don’t stop half way
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:level_of_detail
hint “Activate the LOD Control”

Oh yeah, thanks :slight_smile:

How I can get correct child from nodes in 1 line? I mean using only 1 node variable?
On example I wanna get Stone_03 from Rock6 from Rocks and later create geometry variable for it’s geometry.

Geometry g = (Geometry) rootNode.getChild(“Stone_031”);
It should work unless you have several geometries called Stone_031 but I guess you wouldn’t have that kind of naming scheme if so.

@nehon said: Geometry g = (Geometry) rootNode.getChild("Stone_031"); It should work unless you have several geometries called Stone_031 but I guess you wouldn't have that kind of naming scheme if so.

Nope, it return me a null.

“Stone_031” refers to the name you gave it, not the name it is saved as. If it returns null, it’s because the rootNode does not contain a spatial with that name.

Spatial#SetName(java.lang.string)

If you do have multiple instances of “Stone_031” (and I guess Rock6 too) - you can use ray casting to pick the item instead. For example, fire a ray from the player in the direction of the camera.

@jayfella said: "Stone_031" refers to the name you gave it, not the name it is saved as. If it returns null, it's because the rootNode does not contain a spatial with that name.

Spatial#SetName(java.lang.string)

Lol, so I have call .setName for 10000 nodes to get all them working properly? Shouldn’t it all be saved in scene.j3o? WTF.

@Skatty said: Lol, so I have call .setName for 10000 nodes to get all them working properly? Shouldn't it all be saved in scene.j3o? WTF.

No you don’t and yes it is, you just seem to get the name or the node wrong. You only tell us what you think you do but obviously you don’t do it.

So it should work when calling: Geometry g = (Geometry) rootNode.getChild(“Stone_031″); but it isn’t

@Skatty said: So it should work when calling: Geometry g = (Geometry) rootNode.getChild(“Stone_031″); but it isn't

As I said, you think that you call this on a root node with the model from the screenshot attached, we have no way of saying if that is true or not but we can say that if we load a model with a geometry and access it by its name it does work.

Oh, sorry for the problem. My bad, I call it for map (which is scene.j3o) and it works fine now. Thanks

Ok I set few levels in Scene Composer for geometry and here’s my code:
[java]
Geometry geo = (Geometry) map.getChild(“Stone_031”);
LodControl control = new LodControl();
geo.addControl(control);[/java]

but lod doesn’t work. I also tried:
[java]
Geometry geo = (Geometry) map.getChild(“Stone_031”);
LodGenerator lodGenerator = new LodGenerator(geo);
lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, 0.10f);
// geo.setLodLevel(8);
LodControl control = new LodControl();
geo.addControl(control);[/java]