Class TerrainLodControl

java.lang.Object
com.jme3.scene.control.AbstractControl
com.jme3.terrain.geomipmap.TerrainLodControl
All Implemented Interfaces:
com.jme3.export.Savable, com.jme3.scene.control.Control, com.jme3.util.clone.JmeCloneable, Cloneable
Direct Known Subclasses:
MultiTerrainLodControl, TerrainGridLodControl

public class TerrainLodControl extends com.jme3.scene.control.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.
Author:
Brent Owens
  • Field Details

    • cameras

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

      protected com.jme3.util.SafeArrayList<com.jme3.math.Vector3f> cameraLocations
    • lastCameraLocations

      protected com.jme3.util.SafeArrayList<com.jme3.math.Vector3f> lastCameraLocations
    • lodCalcRunning

      protected AtomicBoolean lodCalcRunning
    • previousCameraLocation

      protected com.jme3.math.Vector3f previousCameraLocation
      The previous location of camera.
    • camera

      protected com.jme3.renderer.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(com.jme3.renderer.Camera camera)
    • TerrainLodControl

      public TerrainLodControl(Terrain terrain, com.jme3.renderer.Camera camera)
    • TerrainLodControl

      public TerrainLodControl(Terrain terrain, List<com.jme3.renderer.Camera> cameras)
      Only uses the first camera right now.
      Parameters:
      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)
      Parameters:
      useRenderCamera - true to use camera from the render viewport
    • isUseRenderCamera

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

      protected void controlRender(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp)
      Specified by:
      controlRender in class com.jme3.scene.control.AbstractControl
    • controlUpdate

      protected void controlUpdate(float tpf)
      Specified by:
      controlUpdate in class com.jme3.scene.control.AbstractControl
    • 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(com.jme3.util.SafeArrayList<com.jme3.math.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<com.jme3.math.Vector3f> locations, LodCalculator lodCalculator)
    • jmeClone

      public Object jmeClone()
      Specified by:
      jmeClone in interface com.jme3.util.clone.JmeCloneable
      Overrides:
      jmeClone in class com.jme3.scene.control.AbstractControl
    • cloneFields

      public void cloneFields(com.jme3.util.clone.Cloner cloner, Object original)
      Specified by:
      cloneFields in interface com.jme3.util.clone.JmeCloneable
      Overrides:
      cloneFields in class com.jme3.scene.control.AbstractControl
    • setCamera

      public void setCamera(com.jme3.renderer.Camera camera)
    • setCameras

      public void setCameras(List<com.jme3.renderer.Camera> cameras)
    • setSpatial

      public void setSpatial(com.jme3.scene.Spatial spatial)
      Specified by:
      setSpatial in interface com.jme3.scene.control.Control
      Overrides:
      setSpatial in class com.jme3.scene.control.AbstractControl
    • setTerrain

      public void setTerrain(Terrain terrain)
    • getLodCalculator

      public LodCalculator getLodCalculator()
    • setLodCalculator

      public void setLodCalculator(LodCalculator lodCalculator)
    • setEnabled

      public void setEnabled(boolean enabled)
      Overrides:
      setEnabled in class com.jme3.scene.control.AbstractControl
    • write

      public void write(com.jme3.export.JmeExporter ex) throws IOException
      Specified by:
      write in interface com.jme3.export.Savable
      Overrides:
      write in class com.jme3.scene.control.AbstractControl
      Throws:
      IOException
    • read

      public void read(com.jme3.export.JmeImporter im) throws IOException
      Specified by:
      read in interface com.jme3.export.Savable
      Overrides:
      read in class com.jme3.scene.control.AbstractControl
      Throws:
      IOException