How can I add a LODControl to a Spatial?

Hi,

I am attempting to generate LOD for the trees in my game. I have generated the levels of detail in the scenecomposer, and I can set the level of detail manually in-game by using spat.setLodLevel(SOME_LOD_LEVEL);

Obviously though I don’t want to keep manually setting the LOD, so I’m trying to attach a LodControl. It doesn’t seem to work though:

LodControl lc = new LodControl(); lc.setTrisPerPixel(1f); spat.addControl(lc);

This doesn’t seem to work though, as I can only attach a LODControl to Geometry, not Spatial.

So, I tried attaching it to the geometry:
Node n = new Node(); n.attachChild(spat); for (Spatial sp : n.getChildren()){ if (!(sp instanceof Geometry)) continue; Geometry geom = (Geometry) sp; LodControl lc = new LodControl(); lc.setTrisPerPixel(1f); geom.addControl(lc); }

However this seems to do absolutely nothing.

So, how can I attach a LODControl to the spatial?

Was the Geometry loaded from a .j3o file, which had the LODs included in it?

Yes. As I said, I can set the LOD manually, just not with the LODControl.

The LodControl needs a reference to the camera to tell how far it is from the camera. I think theres a constructor for that.

I’ve just had a look at the source and their doesn’t seem to be. However, it gets the camera from the viewport, which it gets a reference to in the controlRender() method.

I just use a single FlyCam that I’ve created, so I don’t think that should be a huge problem.

Does TestLodStress work?

Yep. About 400 FPS.

When you replace the teapot model with your own .j3o file in TestLodStress are you seeing the same issue?