Class TerrainLodControl

All Implemented Interfaces:
Savable, Control, JmeCloneable, Cloneable
Direct Known Subclasses:
MultiTerrainLodControl, TerrainGridLodControl

public class TerrainLodControl extends AbstractControl
Tells the terrain to update its Level of Detail. It needs the cameras to do this, and there could possibly be several cameras in the scene, so it accepts a list of cameras. NOTE: right now it just uses the first camera passed in, in the future it will use all of them to determine what LOD to set. This control serializes, but it does not save the Camera reference. This camera reference has to be manually added in when you load the terrain to the scene! When the control or the terrain are removed from the scene, you should call TerrainLodControl.detachAndCleanUpControl() to remove any threads it created to handle the LOD processing. If you supply your own executor service, then you have to handle its thread termination yourself.
  • Field Details

    • cameras

      protected SafeArrayList<Camera> cameras
      The list of cameras for when terrain supports multiple cameras (ie split screen)
    • cameraLocations

      protected SafeArrayList<Vector3f> cameraLocations
    • lastCameraLocations

      protected SafeArrayList<Vector3f> lastCameraLocations
    • lodCalcRunning

      protected AtomicBoolean lodCalcRunning
    • previousCameraLocation

      protected Vector3f previousCameraLocation
      The previous location of camera.
    • camera

      protected Camera camera
      The camera from render view port.
    • terrain

      protected Terrain terrain
    • lodCalculator

      protected LodCalculator lodCalculator
    • indexer

    • useRenderCamera

      protected boolean useRenderCamera
      The flag of using a camera from render viewport instead cameras from cameras.
    • forceUpdate

      protected boolean forceUpdate
    • hasResetLod

      protected boolean hasResetLod
  • Constructor Details

    • TerrainLodControl

      public TerrainLodControl()
    • TerrainLodControl

      public TerrainLodControl(Terrain terrain)
    • TerrainLodControl

      public TerrainLodControl(Camera camera)
    • TerrainLodControl

      public TerrainLodControl(Terrain terrain, Camera camera)
    • TerrainLodControl

      public TerrainLodControl(Terrain terrain, List<Camera> cameras)
      Only uses the first camera right now.
      terrain - to act upon (must be a Spatial)
      cameras - one or more cameras to reference for LOD calc
  • Method Details

    • makeLodCalculator

      protected DistanceLodCalculator makeLodCalculator()
    • setUseRenderCamera

      public void setUseRenderCamera(boolean useRenderCamera)
      useRenderCamera - true to use camera from the render viewport
    • isUseRenderCamera

      public boolean isUseRenderCamera()
      true to use camera from the render viewport
    • controlRender

      protected void controlRender(RenderManager rm, ViewPort vp)
      Description copied from class: AbstractControl
      To be implemented in subclass.
      Specified by:
      controlRender in class AbstractControl
      rm - the RenderManager rendering the controlled Spatial (not null)
      vp - the ViewPort being rendered (not null)
    • controlUpdate

      protected void controlUpdate(float tpf)
      Description copied from class: AbstractControl
      To be implemented in subclass.
      Specified by:
      controlUpdate in class AbstractControl
      tpf - time per frame (in seconds)
    • detachAndCleanUpControl

      public void detachAndCleanUpControl()
      Call this when you remove the terrain or this control from the scene. It will clear up any threads it had.
    • updateLOD

      protected void updateLOD(LodCalculator lodCalculator)
    • updateLOD

      protected void updateLOD(SafeArrayList<Vector3f> locations, LodCalculator lodCalculator)
    • updateLodOffCount

      protected boolean updateLodOffCount(LodCalculator lodCalculator)
    • forceUpdate

      public void forceUpdate()
      Force the LOD to update instantly, does not wait for the camera to move. It will reset once it has updated.
    • prepareTerrain

      protected void prepareTerrain()
    • createLodUpdateTask

      protected TerrainLodControl.UpdateLOD createLodUpdateTask(List<Vector3f> locations, LodCalculator lodCalculator)
    • jmeClone

      public Object jmeClone()
      Description copied from interface: JmeCloneable
      Performs a regular shallow clone of the object. Some fields may also be cloned but generally only if they will never be shared with other objects. (For example, local Vector3fs and so on.)

      This method is separate from the regular clone() method so that objects might still maintain their own regular java clone() semantics (perhaps even using Cloner for those methods). However, because Java's clone() has specific features in the sense of Object's clone() implementation, it's usually best to have some path for subclasses to bypass the public clone() method that might be cloning fields and instead get at the superclass protected clone() methods. For example, through super.jmeClone() or another protected clone method that some base class eventually calls super.clone() in.

      Specified by:
      jmeClone in interface JmeCloneable
      jmeClone in class AbstractControl
      a new instance
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Description copied from interface: JmeCloneable
      Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner. The object can call cloner.clone(fieldValue) to deep clone any of its fields.

      Note: during normal clone operations the original object will not be needed as the clone has already had all of the fields shallow copied.

      Specified by:
      cloneFields in interface JmeCloneable
      cloneFields in class AbstractControl
      cloner - The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.
      original - The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
    • setCamera

      public void setCamera(Camera camera)
    • setCameras

      public void setCameras(List<Camera> cameras)
    • setSpatial

      public void setSpatial(Spatial spatial)
      Specified by:
      setSpatial in interface Control
      setSpatial in class AbstractControl
      spatial - the spatial to be controlled. This should not be called from user code.
    • setTerrain

      public void setTerrain(Terrain terrain)
    • getLodCalculator

      public LodCalculator getLodCalculator()
    • setLodCalculator

      public void setLodCalculator(LodCalculator lodCalculator)
    • setEnabled

      public void setEnabled(boolean enabled)
      setEnabled in class AbstractControl
    • write

      public void write(JmeExporter ex) throws IOException
      Specified by:
      write in interface Savable
      write in class AbstractControl
    • read

      public void read(JmeImporter im) throws IOException
      Specified by:
      read in interface Savable
      read in class AbstractControl