Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ public void simpleInitApp() {
*/
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f)); // patch size, and a multiplier
terrain.addControl(control);
terrain.setMaterial(matRock);
terrain.setLocalTranslation(0, -100, 0);
terrain.setLocalScale(2f, 0.5f, 2f);
rootNode.attachChild(terrain);


DirectionalLight light = new DirectionalLight();
light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
Expand All @@ -187,6 +188,7 @@ private void setupKeys() {
inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
inputManager.addListener(actionListener, "triPlanar");
}

private ActionListener actionListener = new ActionListener() {

public void onAction(String name, boolean pressed, float tpf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@
import com.jme3.renderer.Camera;
import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* An extension of the TerrainLodControl that handles
* multiple terrains at once. This is to be used if you
* multiple terrains at once. This is to be used if you
* have your own tiling/paging terrain system, such as
* TerrainGrid.
*
*
* @author Brent Owens
*/
public class MultiTerrainLodControl extends TerrainLodControl {

List<TerrainQuad> terrains = new ArrayList<TerrainQuad>();
private List<TerrainQuad> addedTerrains = new ArrayList<TerrainQuad>();
private List<TerrainQuad> removedTerrains = new ArrayList<TerrainQuad>();
Expand All @@ -64,7 +65,7 @@ public MultiTerrainLodControl(Camera camera) {
this.cameras = cams;
lodCalculator = new DistanceLodCalculator(65, 2.7f);
}

/**
* Add a terrain that will have its LOD handled by this control.
* It will be added next update run. You should only call this from
Expand All @@ -73,7 +74,7 @@ public MultiTerrainLodControl(Camera camera) {
public void addTerrain(TerrainQuad tq) {
addedTerrains.add(tq);
}

/**
* Add a terrain that will no longer have its LOD handled by this control.
* It will be removed next update run. You should only call this from
Expand All @@ -82,12 +83,12 @@ public void addTerrain(TerrainQuad tq) {
public void removeTerrain(TerrainQuad tq) {
removedTerrains.add(tq);
}

@Override
protected UpdateLOD getLodThread(List<Vector3f> locations, LodCalculator lodCalculator) {
return new UpdateMultiLOD(locations, lodCalculator);
}

@Override
protected void prepareTerrain() {
if (!addedTerrains.isEmpty()) {
Expand All @@ -97,57 +98,57 @@ protected void prepareTerrain() {
}
addedTerrains.clear();
}

if (!removedTerrains.isEmpty()) {
terrains.removeAll(removedTerrains);
removedTerrains.clear();
}

for (TerrainQuad terrain : terrains)
terrain.cacheTerrainTransforms();// cache the terrain's world transforms so they can be accessed on the separate thread safely
}

/**
* Overrides the parent UpdateLOD runnable to process
* multiple terrains.
*/
protected class UpdateMultiLOD extends UpdateLOD {


protected UpdateMultiLOD(List<Vector3f> camLocations, LodCalculator lodCalculator) {
super(camLocations, lodCalculator);
}

@Override
public HashMap<String, UpdatedTerrainPatch> call() throws Exception {

setLodCalcRunning(true);
HashMap<String,UpdatedTerrainPatch> updated = new HashMap<String,UpdatedTerrainPatch>();

HashMap<String, UpdatedTerrainPatch> updated = new HashMap<String, UpdatedTerrainPatch>();

for (TerrainQuad terrainQuad : terrains) {
// go through each patch and calculate its LOD based on camera distance
terrainQuad.calculateLod(camLocations, updated, lodCalculator); // 'updated' gets populated here
terrainQuad.hasLodChanged(camLocations, updated, lodCalculator); // 'updated' gets populated here
}

for (TerrainQuad terrainQuad : terrains) {
// then calculate the neighbour LOD values for seaming
terrainQuad.findNeighboursLod(updated);
}

for (TerrainQuad terrainQuad : terrains) {
// check neighbour quads that need their edges seamed
terrainQuad.fixEdges(updated);
}

for (TerrainQuad terrainQuad : terrains) {
// perform the edge seaming, if it requires it
terrainQuad.reIndexPages(updated, lodCalculator.usesVariableLod());
}

//setUpdateQuadLODs(updated); // set back to main ogl thread
setLodCalcRunning(false);

return updated;
}
}
Expand Down
Loading