From ff4c38e20ac6dd9987f65757d78bf8cbc467a84a Mon Sep 17 00:00:00 2001 From: "bre..om" Date: Thu, 18 Apr 2013 15:19:43 +0000 Subject: [PATCH] TerrainLodControl now refreshes when first added to the scene git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10557 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../terrain/geomipmap/TerrainLodControl.java | 32 +++++++------------ .../jme3test/terrain/TerrainTestAdvanced.java | 6 ++++ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java index 314bc4c10..183c2d660 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java @@ -92,6 +92,7 @@ public class TerrainLodControl extends AbstractControl { protected ExecutorService executor; protected Future> indexer; + private boolean forceUpdate = true; public TerrainLodControl() { } @@ -175,10 +176,11 @@ public class TerrainLodControl extends AbstractControl { lodOffCount = 0; if (lastCameraLocations != null) { - if (lastCameraLocationsTheSame(locations) && !lodCalculator.isLodOff()) + if (!forceUpdate && lastCameraLocationsTheSame(locations) && !lodCalculator.isLodOff()) return; // don't update if in same spot else lastCameraLocations = cloneVectorList(locations); + forceUpdate = false; } else { lastCameraLocations = cloneVectorList(locations); @@ -190,10 +192,6 @@ public class TerrainLodControl extends AbstractControl { } setLodCalcRunning(true); - //if (getParent() instanceof TerrainQuad) { - // return; // we just want the root quad to perform this. - //} - if (executor == null) executor = createExecutorService(); @@ -202,6 +200,14 @@ public class TerrainLodControl extends AbstractControl { UpdateLOD updateLodThread = getLodThread(locations, lodCalculator); indexer = executor.submit(updateLodThread); } + + /** + * Force the LOD to update instantly, does not wait for the camera to move. + * It will reset once it has updated. + */ + public void forceUpdate() { + this.forceUpdate = true; + } protected void prepareTerrain() { TerrainQuad terrain = (TerrainQuad)getSpatial(); @@ -237,24 +243,8 @@ public class TerrainLodControl extends AbstractControl { } } } - /*synchronized (updatePatchesLock) { - - if (updatedPatches == null || updatedPatches.isEmpty()) - return; - - // do the actual geometry update here - for (UpdatedTerrainPatch utp : updatedPatches.values()) { - utp.updateAll(); - } - - updatedPatches = null; - }*/ } - //public boolean hasPatchesToUpdate() { - // return updatedPatches != null && !updatedPatches.isEmpty(); - //} - private boolean lastCameraLocationsTheSame(List locations) { boolean theSame = true; for (Vector3f l : locations) { diff --git a/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java b/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java index f615cecad..05cd0cabe 100644 --- a/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java +++ b/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java @@ -151,6 +151,12 @@ public class TerrainTestAdvanced extends SimpleApplication { matTerrain.setTexture("NormalMap_2", normalMap2); matTerrain.setTexture("NormalMap_4", normalMap2); + + // WIREFRAME material (used to debug the terrain, only useful for this test case) + matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + matWire.getAdditionalRenderState().setWireframe(true); + matWire.setColor("Color", ColorRGBA.Green); + createSky(); // CREATE HEIGHTMAP