Level of Detail (LOD) is a general term for a technique that varies the amount of detail in a visual object based on some value from the virtual world. The typical application is to vary the level of detail based on the distance to the viewer.As the distance to a visual object increases, the fewer details will appear in the rendering.

The DistanceLOD Class provides LOD behavior based on distance to the viewer.

Here is the usage recipe for DistanceLOD class:

  1. create a target Switch object(s) with ALLOW_SWITCH_WRITE capability
  2. create list of distance thresholds array for the DistanceLOD object
  3. create DistanceLOD object using the distance thresholds array
  4. set the target switch object for the DistanceLOD object
  5. supply a scheduling bounds (or bounding leaf) for the DistanceLOD object
  6. assemble the scene graph, including adding children to target Switch object(s)
 public BranchGroup createSceneGraph() {

     BranchGroup objRoot = new BranchGroup();
     BoundingSphere bounds = new BoundingSphere();

     // create target TransformGroup with Capabilities
     TransformGroup objMove = new TransformGroup();
 
     // create DistanceLOD target object
     Switch targetSwitch = new Switch();
     targetSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

     // add visual objects to the target switch 
     targetSwitch.addChild(new Sphere(.40f, 0, 25));
     targetSwitch.addChild(new Sphere(.40f, 0, 15));
     targetSwitch.addChild(new Sphere(.40f, 0, 10));
     targetSwitch.addChild(new Sphere(.40f, 0, 4));

     // create DistanceLOD object
     float[] distances = { 5.0f, 10.0f, 20.0f};
     DistanceLOD dLOD = new DistanceLOD(distances, new Point3f());
     dLOD.addSwitch(targetSwitch);
     dLOD.setSchedulingBounds(bounds);
   
     // assemble scene graph
     objRoot.addChild(objMove);
     objMove.addChild(dLOD); // make the bounds move with object
     objMove.addChild(targetSwitch); // must add switch to scene graph
  
     return objRoot;
}