Package com.jme3.terrain.geomipmap
Class TerrainLodControl
java.lang.Object
com.jme3.scene.control.AbstractControl
com.jme3.terrain.geomipmap.TerrainLodControl
- All Implemented Interfaces:
Savable
,Control
,JmeCloneable
,Cloneable
- Direct Known Subclasses:
MultiTerrainLodControl
,TerrainGridLodControl
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Calculates the LOD of all child terrain patches. -
Field Summary
Modifier and TypeFieldDescriptionprotected Camera
The camera from render view port.protected SafeArrayList<Vector3f>
protected SafeArrayList<Camera>
The list of cameras for when terrain supports multiple cameras (ie split screen)protected boolean
protected boolean
protected Future<HashMap<String,
UpdatedTerrainPatch>> protected SafeArrayList<Vector3f>
protected AtomicBoolean
protected LodCalculator
protected Vector3f
The previous location ofcamera
.protected Terrain
protected boolean
The flag of using a camera from render viewport instead cameras fromcameras
.Fields inherited from class com.jme3.scene.control.AbstractControl
enabled, spatial
-
Constructor Summary
ConstructorDescriptionTerrainLodControl
(Camera camera) TerrainLodControl
(Terrain terrain) TerrainLodControl
(Terrain terrain, Camera camera) TerrainLodControl
(Terrain terrain, List<Camera> cameras) Only uses the first camera right now. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cloneFields
(Cloner cloner, Object original) Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner.protected void
controlRender
(RenderManager rm, ViewPort vp) To be implemented in subclass.protected void
controlUpdate
(float tpf) To be implemented in subclass.protected TerrainLodControl.UpdateLOD
createLodUpdateTask
(List<Vector3f> locations, LodCalculator lodCalculator) void
Call this when you remove the terrain or this control from the scene.void
Force the LOD to update instantly, does not wait for the camera to move.boolean
jmeClone()
Performs a regular shallow clone of the object.protected DistanceLodCalculator
protected void
void
read
(JmeImporter im) void
void
setCameras
(List<Camera> cameras) void
setEnabled
(boolean enabled) void
setLodCalculator
(LodCalculator lodCalculator) void
setSpatial
(Spatial spatial) void
setTerrain
(Terrain terrain) void
setUseRenderCamera
(boolean useRenderCamera) protected void
updateLOD
(LodCalculator lodCalculator) protected void
updateLOD
(SafeArrayList<Vector3f> locations, LodCalculator lodCalculator) protected boolean
updateLodOffCount
(LodCalculator lodCalculator) void
write
(JmeExporter ex) Methods inherited from class com.jme3.scene.control.AbstractControl
cloneForSpatial, getSpatial, isEnabled, render, update
-
Field Details
-
cameras
The list of cameras for when terrain supports multiple cameras (ie split screen) -
cameraLocations
-
lastCameraLocations
-
lodCalcRunning
-
previousCameraLocation
The previous location ofcamera
. -
camera
The camera from render view port. -
terrain
-
lodCalculator
-
indexer
-
useRenderCamera
protected boolean useRenderCameraThe flag of using a camera from render viewport instead cameras fromcameras
. -
forceUpdate
protected boolean forceUpdate -
hasResetLod
protected boolean hasResetLod
-
-
Constructor Details
-
TerrainLodControl
public TerrainLodControl() -
TerrainLodControl
-
TerrainLodControl
-
TerrainLodControl
-
TerrainLodControl
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
-
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
Description copied from class:AbstractControl
To be implemented in subclass.- Specified by:
controlRender
in classAbstractControl
- Parameters:
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 classAbstractControl
- Parameters:
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
-
updateLOD
-
updateLodOffCount
-
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
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 interfaceJmeCloneable
- Overrides:
jmeClone
in classAbstractControl
- Returns:
- a new instance
-
cloneFields
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 interfaceJmeCloneable
- Overrides:
cloneFields
in classAbstractControl
- Parameters:
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
-
setCameras
-
setSpatial
- Specified by:
setSpatial
in interfaceControl
- Overrides:
setSpatial
in classAbstractControl
- Parameters:
spatial
- the spatial to be controlled. This should not be called from user code.
-
setTerrain
-
getLodCalculator
-
setLodCalculator
-
setEnabled
public void setEnabled(boolean enabled) - Overrides:
setEnabled
in classAbstractControl
-
write
- Specified by:
write
in interfaceSavable
- Overrides:
write
in classAbstractControl
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Overrides:
read
in classAbstractControl
- Throws:
IOException
-