OSDN Git Service

* refactored TerrainLOD Control and removed some legacy classes for it, made it easie...
authorbrentowens <brentowens@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Fri, 9 Sep 2011 23:34:15 +0000 (23:34 +0000)
committerbrentowens <brentowens@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Fri, 9 Sep 2011 23:34:15 +0000 (23:34 +0000)
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@8233 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

21 files changed:
engine/src/terrain/com/jme3/terrain/Terrain.java
engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java
engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java
engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java
engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java
engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/DistanceLodCalculator.java
engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/LodCalculator.java
engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/LodCalculatorFactory.java
engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/LodDistanceCalculatorFactory.java
engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/LodPerspectiveCalculatorFactory.java
engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/LodThreshold.java
engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/PerspectiveLodCalculator.java
engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/SimpleLodThreshold.java
engine/src/test/jme3test/terrain/TerrainFractalGridTest.java
engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java
engine/src/test/jme3test/terrain/TerrainGridTest.java
engine/src/test/jme3test/terrain/TerrainTest.java
engine/src/test/jme3test/terrain/TerrainTestAdvanced.java
engine/src/test/jme3test/terrain/TerrainTestCollision.java
engine/src/test/jme3test/terrain/TerrainTestModifyHeight.java
engine/src/test/jme3test/terrain/TerrainTestReadWrite.java

index 78a20ab..1fdbd78 100644 (file)
@@ -34,6 +34,7 @@ package com.jme3.terrain;
 import com.jme3.material.Material;\r
 import com.jme3.math.Vector2f;\r
 import com.jme3.math.Vector3f;\r
+import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;\r
 import java.util.List;\r
 \r
 /**\r
@@ -133,7 +134,7 @@ public interface Terrain {
      * @param location: the Camera's location. A list of one camera location is normal \r
      *  if you just have one camera in your scene.\r
      */\r
-    public void update(List<Vector3f> location);\r
+    public void update(List<Vector3f> location, LodCalculator lodCalculator);\r
 \r
     /**\r
      * Lock or unlock the meshes of this terrain.\r
index e2b0ee5..9357140 100644 (file)
@@ -46,6 +46,7 @@ import com.jme3.material.Material;
 import com.jme3.math.FastMath;
 import com.jme3.math.Vector2f;
 import com.jme3.math.Vector3f;
+import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;
 import com.jme3.terrain.geomipmap.lodcalc.LodCalculatorFactory;
 import com.jme3.terrain.geomipmap.lodcalc.LodDistanceCalculatorFactory;
 import com.jme3.terrain.heightmap.HeightMapGrid;
@@ -88,7 +89,7 @@ public class TerrainGrid extends TerrainQuad {
                     if (q == null) {
                         // create the new Quad since it doesn't exist
                         HeightMap heightMapAt = heightMapGrid.getHeightMapAt(temp);
-                        q = new TerrainQuad(getName() + "Quad" + temp, patchSize, quadSize, totalSize, heightMapAt == null ? null : heightMapAt.getHeightMap(), lodCalculatorFactory);
+                        q = new TerrainQuad(getName() + "Quad" + temp, patchSize, quadSize, totalSize, heightMapAt == null ? null : heightMapAt.getHeightMap());
                         q.setMaterial(material.clone());
                         log.log(Level.FINE, "Loaded TerrainQuad {0}", q.getName());
                     }
@@ -131,7 +132,7 @@ public class TerrainGrid extends TerrainQuad {
     }
 
     public TerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, HeightMapGrid heightMapGrid,
-            Vector2f offset, float offsetAmount, LodCalculatorFactory lodCalculatorFactory) {
+            Vector2f offset, float offsetAmount) {
         this.name = name;
         this.patchSize = patchSize;
         this.size = maxVisibleSize;
@@ -143,11 +144,11 @@ public class TerrainGrid extends TerrainQuad {
         this.totalSize = maxVisibleSize;
         this.offset = offset;
         this.offsetAmount = offsetAmount;
-        this.lodCalculatorFactory = lodCalculatorFactory;
+        //this.lodCalculatorFactory = lodCalculatorFactory;
         this.gridOffset = new int[]{0,0};
-        if (lodCalculatorFactory == null) {
-            lodCalculatorFactory = new LodDistanceCalculatorFactory();
-        }
+        //if (lodCalculatorFactory == null) {
+        //    lodCalculatorFactory = new LodDistanceCalculatorFactory();
+        //}
         this.quadIndex = new Vector3f[]{
         new Vector3f(-1, 0, 2), new Vector3f(0, 0, 2), new Vector3f(1, 0, 2), new Vector3f(2, 0, 2),
         new Vector3f(-1, 0, 1), new Vector3f(0, 0, 1), new Vector3f(1, 0, 1), new Vector3f(2, 0, 1),
@@ -157,17 +158,12 @@ public class TerrainGrid extends TerrainQuad {
         addControl(new UpdateControl());
     }
 
-    public TerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, HeightMapGrid heightMapGrid,
-            LodCalculatorFactory lodCalculatorFactory) {
-        this(name, patchSize, maxVisibleSize, scale, heightMapGrid, new Vector2f(), 0, lodCalculatorFactory);
-    }
-
-    public TerrainGrid(String name, int patchSize, int maxVisibleSize, HeightMapGrid heightMapGrid, LodCalculatorFactory lodCalculatorFactory) {
-        this(name, patchSize, maxVisibleSize, Vector3f.UNIT_XYZ, heightMapGrid, lodCalculatorFactory);
+    public TerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, HeightMapGrid heightMapGrid) {
+        this(name, patchSize, maxVisibleSize, scale, heightMapGrid, new Vector2f(), 0);
     }
 
     public TerrainGrid(String name, int patchSize, int maxVisibleSize, HeightMapGrid heightMapGrid) {
-        this(name, patchSize, maxVisibleSize, heightMapGrid, null);
+        this(name, patchSize, maxVisibleSize, Vector3f.UNIT_XYZ, heightMapGrid);
     }
 
     public TerrainGrid() {
@@ -185,7 +181,7 @@ public class TerrainGrid extends TerrainQuad {
     }
 
     @Override
-    public void update(List<Vector3f> locations) {
+    public void update(List<Vector3f> locations, LodCalculator lodCalculator) {
         // for now, only the first camera is handled.
         // to accept more, there are two ways:
         // 1: every camera has an associated grid, then the location is not enough to identify which camera location has changed
@@ -203,7 +199,7 @@ public class TerrainGrid extends TerrainQuad {
                 l.gridMoved(camCell);
             }
         }
-        super.update(locations);
+        super.update(locations, lodCalculator);
     }
 
     public Vector3f getCell(Vector3f location) {
index ab68ce0..bfc6275 100644 (file)
@@ -46,6 +46,8 @@ import com.jme3.scene.Spatial;
 import com.jme3.scene.control.AbstractControl;\r
 import com.jme3.scene.control.Control;\r
 import com.jme3.terrain.Terrain;\r
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;\r
+import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;\r
 import java.io.IOException;\r
 import java.util.ArrayList;\r
 \r
@@ -65,6 +67,7 @@ public class TerrainLodControl extends AbstractControl {
     private Terrain terrain;\r
     private List<Camera> cameras;\r
     private List<Vector3f> cameraLocations = new ArrayList<Vector3f>();\r
+    private LodCalculator lodCalculator;\r
 \r
     public TerrainLodControl() {\r
     }\r
@@ -74,6 +77,7 @@ public class TerrainLodControl extends AbstractControl {
         cams.add(camera);\r
         this.terrain = terrain;\r
         this.cameras = cams;\r
+        lodCalculator = new DistanceLodCalculator(); // a default calculator\r
     }\r
     \r
     /**\r
@@ -101,7 +105,7 @@ public class TerrainLodControl extends AbstractControl {
                     cameraLocations.add(c.getLocation());\r
                 }\r
             }\r
-            terrain.update(cameraLocations);\r
+            terrain.update(cameraLocations, lodCalculator);\r
         }\r
     }\r
 \r
@@ -144,11 +148,21 @@ public class TerrainLodControl extends AbstractControl {
         this.terrain = terrain;\r
     }\r
 \r
+    public LodCalculator getLodCalculator() {\r
+        return lodCalculator;\r
+    }\r
+\r
+    public void setLodCalculator(LodCalculator lodCalculator) {\r
+        this.lodCalculator = lodCalculator;\r
+    }\r
+    \r
+\r
     @Override\r
     public void write(JmeExporter ex) throws IOException {\r
         super.write(ex);\r
         OutputCapsule oc = ex.getCapsule(this);\r
         oc.write((Node)terrain, "terrain", null);\r
+        oc.write(lodCalculator, "lodCalculator", null);\r
     }\r
 \r
     @Override\r
@@ -156,5 +170,6 @@ public class TerrainLodControl extends AbstractControl {
         super.read(im);\r
         InputCapsule ic = im.getCapsule(this);\r
         terrain = (Terrain) ic.readSavable("terrain", null);\r
+        lodCalculator = (LodCalculator) ic.readSavable("lodCalculator", new DistanceLodCalculator());\r
     }\r
 }\r
index fab2efa..bd35fcc 100644 (file)
@@ -109,8 +109,8 @@ public class TerrainPatch extends Geometry {
     // amount the patch has been shifted.\r
     protected float offsetAmount;\r
 \r
-    protected LodCalculator lodCalculator;\r
-    protected LodCalculatorFactory lodCalculatorFactory;\r
+    //protected LodCalculator lodCalculator;\r
+    //protected LodCalculatorFactory lodCalculatorFactory;\r
 \r
     protected TerrainPatch leftNeighbour, topNeighbour, rightNeighbour, bottomNeighbour;\r
     protected boolean searchedForNeighboursAlready = false;\r
@@ -234,20 +234,7 @@ public class TerrainPatch extends Geometry {
         return maxLod;\r
     }\r
 \r
-    \r
-       \r
-\r
-    /**\r
-     * Delegates to the lodCalculator that was passed in.\r
-     * @param locations all possible camera locations\r
-     * @param updates update objects that may or may not contain this terrain patch\r
-     * @return true if the geometry needs re-indexing\r
-     */\r
-    protected boolean calculateLod(List<Vector3f> locations, HashMap<String,UpdatedTerrainPatch> updates) {\r
-        return lodCalculator.calculateLod(locations, updates);\r
-    }\r
-\r
-    protected void reIndexGeometry(HashMap<String,UpdatedTerrainPatch> updated) {\r
+    protected void reIndexGeometry(HashMap<String,UpdatedTerrainPatch> updated, boolean useVariableLod) {\r
 \r
         UpdatedTerrainPatch utp = updated.get(getName());\r
 \r
@@ -259,7 +246,7 @@ public class TerrainPatch extends Geometry {
             boolean bottom = utp.getBottomLod() > utp.getNewLod();\r
 \r
             IntBuffer ib = null;\r
-            if (lodCalculator.usesVariableLod())\r
+            if (useVariableLod)\r
                 ib = geomap.writeIndexArrayLodVariable(null, pow, (int) Math.pow(2, utp.getRightLod()), (int) Math.pow(2, utp.getTopLod()), (int) Math.pow(2, utp.getLeftLod()), (int) Math.pow(2, utp.getBottomLod()));\r
             else\r
                 ib = geomap.writeIndexArrayLodDiff(null, pow, right, top, left, bottom);\r
@@ -920,19 +907,11 @@ public class TerrainPatch extends Geometry {
     protected void setLodBottom(int lodBottom) {\r
         this.lodBottom = lodBottom;\r
     }\r
-\r
-    public LodCalculator getLodCalculator() {\r
-        return lodCalculator;\r
-    }\r
-\r
-    public void setLodCalculator(LodCalculator lodCalculator) {\r
-        this.lodCalculator = lodCalculator;\r
-    }\r
-\r
-    public void setLodCalculator(LodCalculatorFactory lodCalculatorFactory) {\r
+    \r
+    /*public void setLodCalculator(LodCalculatorFactory lodCalculatorFactory) {\r
         this.lodCalculatorFactory = lodCalculatorFactory;\r
         setLodCalculator(lodCalculatorFactory.createCalculator(this));\r
-    }\r
+    }*/\r
 \r
     @Override\r
     public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException {\r
@@ -1035,8 +1014,8 @@ public class TerrainPatch extends Geometry {
         oc.write(stepScale, "stepScale", Vector3f.UNIT_XYZ);\r
         oc.write(offset, "offset", Vector3f.UNIT_XYZ);\r
         oc.write(offsetAmount, "offsetAmount", 0);\r
-        oc.write(lodCalculator, "lodCalculator", null);\r
-        oc.write(lodCalculatorFactory, "lodCalculatorFactory", null);\r
+        //oc.write(lodCalculator, "lodCalculator", null);\r
+        //oc.write(lodCalculatorFactory, "lodCalculatorFactory", null);\r
         oc.write(lodEntropy, "lodEntropy", null);\r
         oc.write(geomap, "geomap", null);\r
         \r
@@ -1053,9 +1032,9 @@ public class TerrainPatch extends Geometry {
         stepScale = (Vector3f) ic.readSavable("stepScale", Vector3f.UNIT_XYZ);\r
         offset = (Vector2f) ic.readSavable("offset", Vector3f.UNIT_XYZ);\r
         offsetAmount = ic.readFloat("offsetAmount", 0);\r
-        lodCalculator = (LodCalculator) ic.readSavable("lodCalculator", new DistanceLodCalculator());\r
-        lodCalculator.setTerrainPatch(this);\r
-        lodCalculatorFactory = (LodCalculatorFactory) ic.readSavable("lodCalculatorFactory", null);\r
+        //lodCalculator = (LodCalculator) ic.readSavable("lodCalculator", new DistanceLodCalculator());\r
+        //lodCalculator.setTerrainPatch(this);\r
+        //lodCalculatorFactory = (LodCalculatorFactory) ic.readSavable("lodCalculatorFactory", null);\r
         lodEntropy = ic.readFloatArray("lodEntropy", null);\r
         geomap = (LODGeomap) ic.readSavable("geomap", null);\r
         \r
@@ -1077,7 +1056,7 @@ public class TerrainPatch extends Geometry {
         clone.offsetAmount = offsetAmount;\r
         //clone.lodCalculator = lodCalculator.clone();\r
         //clone.lodCalculator.setTerrainPatch(clone);\r
-        clone.setLodCalculator(lodCalculatorFactory.clone());\r
+        //clone.setLodCalculator(lodCalculatorFactory.clone());\r
         clone.geomap = new LODGeomap(size, geomap.getHeightData());\r
         clone.setLocalTranslation(getLocalTranslation().clone());\r
         Mesh m = clone.geomap.createMesh(clone.stepScale, Vector2f.UNIT_XY, clone.offset, clone.offsetAmount, clone.totalSize, false);\r
index 5ca0b39..c14f41c 100644 (file)
@@ -57,8 +57,9 @@ import com.jme3.scene.Spatial;
 import com.jme3.scene.debug.WireBox;\r
 import com.jme3.terrain.ProgressMonitor;\r
 import com.jme3.terrain.Terrain;\r
-import com.jme3.terrain.geomipmap.lodcalc.LodCalculatorFactory;\r
-import com.jme3.terrain.geomipmap.lodcalc.LodDistanceCalculatorFactory;\r
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;\r
+import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;\r
+import com.jme3.terrain.geomipmap.lodcalc.SimpleLodThreshold;\r
 import com.jme3.terrain.geomipmap.picking.BresenhamTerrainPicker;\r
 import com.jme3.terrain.geomipmap.picking.TerrainPickData;\r
 import com.jme3.terrain.geomipmap.picking.TerrainPicker;\r
@@ -109,7 +110,8 @@ public class TerrainQuad extends Node implements Terrain {
 \r
     protected int quadrant = 1; // 1=upper left, 2=lower left, 3=upper right, 4=lower right\r
 \r
-    protected LodCalculatorFactory lodCalculatorFactory;\r
+    //protected LodCalculatorFactory lodCalculatorFactory;\r
+    //protected LodCalculator lodCalculator;\r
     \r
     protected List<Vector3f> lastCameraLocations; // used for LOD calc\r
     private boolean lodCalcRunning = false;\r
@@ -139,55 +141,55 @@ public class TerrainQuad extends Node implements Terrain {
     }\r
 \r
     public TerrainQuad(String name, int patchSize, int totalSize, float[] heightMap) {\r
-        this(name, patchSize, totalSize, heightMap, null);\r
-    }\r
-\r
-    public TerrainQuad(String name, int patchSize, int totalSize, float[] heightMap, LodCalculatorFactory lodCalculatorFactory) {\r
-        this(name, patchSize, totalSize, Vector3f.UNIT_XYZ, heightMap, lodCalculatorFactory);\r
+        this(name, patchSize, totalSize, Vector3f.UNIT_XYZ, heightMap);\r
     }\r
     \r
-    public TerrainQuad(String name, int patchSize, int size, int totalSize, float[] heightMap, LodCalculatorFactory lodCalculatorFactory) {\r
-        this(name, patchSize, size, Vector3f.UNIT_XYZ, heightMap, totalSize, new Vector2f(), 0, lodCalculatorFactory);\r
+    public TerrainQuad(String name, int patchSize, int quadSize, int totalSize, float[] heightMap) {\r
+        this(name, patchSize, totalSize, Vector3f.UNIT_XYZ, heightMap);\r
+    }\r
+\r
+    public TerrainQuad(String name, int patchSize, int size, Vector3f scale, float[] heightMap) {\r
+        this(name, patchSize, size, scale, heightMap, size, new Vector2f(), 0);\r
         affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2);\r
         fixNormalEdges(affectedAreaBBox);\r
         addControl(new NormalRecalcControl(this));\r
     }\r
-\r
-    public TerrainQuad(String name, int patchSize, int size, Vector3f scale, float[] heightMap, LodCalculatorFactory lodCalculatorFactory) {\r
-        this(name, patchSize, size, scale, heightMap, size, new Vector2f(), 0, lodCalculatorFactory);\r
-        affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2);\r
+    \r
+    public TerrainQuad(String name, int patchSize, int totalSize, int quadSize, Vector3f scale, float[] heightMap) {\r
+        this(name, patchSize, quadSize, scale, heightMap, totalSize, new Vector2f(), 0);\r
+        affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), totalSize*2, Float.MAX_VALUE, totalSize*2);\r
         fixNormalEdges(affectedAreaBBox);\r
         addControl(new NormalRecalcControl(this));\r
     }\r
 \r
-    protected TerrainQuad(String name, int patchSize, int size,\r
+    protected TerrainQuad(String name, int patchSize, int quadSize,\r
                             Vector3f scale, float[] heightMap, int totalSize,\r
-                            Vector2f offset, float offsetAmount,\r
-                            LodCalculatorFactory lodCalculatorFactory)\r
+                            Vector2f offset, float offsetAmount)\r
     {\r
         super(name);\r
         \r
         if (heightMap == null)\r
-            heightMap = generateDefaultHeightMap(size);\r
+            heightMap = generateDefaultHeightMap(quadSize);\r
         \r
-        if (!FastMath.isPowerOfTwo(size - 1)) {\r
-            throw new RuntimeException("size given: " + size + "  Terrain quad sizes may only be (2^N + 1)");\r
+        if (!FastMath.isPowerOfTwo(quadSize - 1)) {\r
+            throw new RuntimeException("size given: " + quadSize + "  Terrain quad sizes may only be (2^N + 1)");\r
         }\r
-        if (FastMath.sqrt(heightMap.length) > size) {\r
+        if (FastMath.sqrt(heightMap.length) > quadSize) {\r
             Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Heightmap size is larger than the terrain size. Make sure your heightmap image is the same size as the terrain!");\r
         }\r
         \r
         this.offset = offset;\r
         this.offsetAmount = offsetAmount;\r
         this.totalSize = totalSize;\r
-        this.size = size;\r
+        this.size = quadSize;\r
         this.patchSize = patchSize;\r
         this.stepScale = scale;\r
-        this.lodCalculatorFactory = lodCalculatorFactory;\r
+        //this.lodCalculatorFactory = lodCalculatorFactory;\r
+        //this.lodCalculator = lodCalculator;\r
         split(patchSize, heightMap);\r
     }\r
 \r
-    public void setLodCalculatorFactory(LodCalculatorFactory lodCalculatorFactory) {\r
+    /*public void setLodCalculatorFactory(LodCalculatorFactory lodCalculatorFactory) {\r
         if (children != null) {\r
             for (int i = children.size(); --i >= 0;) {\r
                 Spatial child = children.get(i);\r
@@ -198,7 +200,7 @@ public class TerrainQuad extends Node implements Terrain {
                 }\r
             }\r
         }\r
-    }\r
+    }*/\r
 \r
 \r
     /**\r
@@ -215,8 +217,8 @@ public class TerrainQuad extends Node implements Terrain {
       * This will perform the geometry calculation in a background thread and\r
       * do the actual update on the opengl thread.\r
       */\r
-    public void update(List<Vector3f> locations) {\r
-        updateLOD(locations);\r
+    public void update(List<Vector3f> locations, LodCalculator lodCalculator) {\r
+        updateLOD(locations, lodCalculator);\r
     }\r
 \r
     /**\r
@@ -235,7 +237,7 @@ public class TerrainQuad extends Node implements Terrain {
     }\r
 \r
     // do all of the LOD calculations\r
-    protected void updateLOD(List<Vector3f> locations) {\r
+    protected void updateLOD(List<Vector3f> locations, LodCalculator lodCalculator) {\r
         // update any existing ones that need updating\r
         updateQuadLODs();\r
 \r
@@ -261,7 +263,7 @@ public class TerrainQuad extends Node implements Terrain {
         if (executor == null)\r
             executor = createExecutorService();\r
         \r
-        UpdateLOD updateLodThread = new UpdateLOD(locations);\r
+        UpdateLOD updateLodThread = new UpdateLOD(locations, lodCalculator);\r
         executor.execute(updateLodThread);\r
     }\r
 \r
@@ -359,9 +361,11 @@ public class TerrainQuad extends Node implements Terrain {
      */\r
     private class UpdateLOD implements Runnable {\r
         private List<Vector3f> camLocations;\r
+        private LodCalculator lodCalculator;\r
 \r
-        UpdateLOD(List<Vector3f> location) {\r
-            camLocations = location;\r
+        UpdateLOD(List<Vector3f> camLocations, LodCalculator lodCalculator) {\r
+            this.camLocations = camLocations;\r
+            this.lodCalculator = lodCalculator;\r
         }\r
 \r
         public void run() {\r
@@ -375,7 +379,7 @@ public class TerrainQuad extends Node implements Terrain {
 \r
             // go through each patch and calculate its LOD based on camera distance\r
             HashMap<String,UpdatedTerrainPatch> updated = new HashMap<String,UpdatedTerrainPatch>();\r
-            boolean lodChanged = calculateLod(camLocations, updated); // 'updated' gets populated here\r
+            boolean lodChanged = calculateLod(camLocations, updated, lodCalculator); // 'updated' gets populated here\r
 \r
             if (!lodChanged) {\r
                 // not worth updating anything else since no one's LOD changed\r
@@ -387,7 +391,7 @@ public class TerrainQuad extends Node implements Terrain {
 \r
             fixEdges(updated); // 'updated' can get added to here\r
 \r
-            reIndexPages(updated);\r
+            reIndexPages(updated, lodCalculator.usesVariableLod());\r
 \r
             setUpdateQuadLODs(updated); // set back to main ogl thread\r
 \r
@@ -422,7 +426,7 @@ public class TerrainQuad extends Node implements Terrain {
         }\r
     }\r
 \r
-    protected boolean calculateLod(List<Vector3f> location, HashMap<String,UpdatedTerrainPatch> updates) {\r
+    protected boolean calculateLod(List<Vector3f> location, HashMap<String,UpdatedTerrainPatch> updates, LodCalculator lodCalculator) {\r
 \r
         boolean lodChanged = false;\r
 \r
@@ -430,11 +434,11 @@ public class TerrainQuad extends Node implements Terrain {
             for (int i = children.size(); --i >= 0;) {\r
                 Spatial child = children.get(i);\r
                 if (child instanceof TerrainQuad) {\r
-                    boolean b = ((TerrainQuad) child).calculateLod(location, updates);\r
+                    boolean b = ((TerrainQuad) child).calculateLod(location, updates, lodCalculator);\r
                     if (b)\r
                         lodChanged = true;\r
                 } else if (child instanceof TerrainPatch) {\r
-                    boolean b = ((TerrainPatch) child).calculateLod(location, updates);\r
+                    boolean b = lodCalculator.calculateLod((TerrainPatch) child, location, updates);\r
                     if (b)\r
                         lodChanged = true;\r
                 }\r
@@ -561,14 +565,14 @@ public class TerrainQuad extends Node implements Terrain {
         }\r
     }\r
 \r
-    protected synchronized void reIndexPages(HashMap<String,UpdatedTerrainPatch> updated) {\r
+    protected synchronized void reIndexPages(HashMap<String,UpdatedTerrainPatch> updated, boolean usesVariableLod) {\r
         if (children != null) {\r
             for (int i = children.size(); --i >= 0;) {\r
                 Spatial child = children.get(i);\r
                 if (child instanceof TerrainQuad) {\r
-                    ((TerrainQuad) child).reIndexPages(updated);\r
+                    ((TerrainQuad) child).reIndexPages(updated, usesVariableLod);\r
                 } else if (child instanceof TerrainPatch) {\r
-                    ((TerrainPatch) child).reIndexGeometry(updated);\r
+                    ((TerrainPatch) child).reIndexGeometry(updated, usesVariableLod);\r
                 }\r
             }\r
         }\r
@@ -616,8 +620,8 @@ public class TerrainQuad extends Node implements Terrain {
         Vector2f tempOffset = new Vector2f();\r
         offsetAmount += quarterSize;\r
 \r
-        if (lodCalculatorFactory == null)\r
-            lodCalculatorFactory = new LodDistanceCalculatorFactory(); // set a default one\r
+        //if (lodCalculator == null)\r
+        //    lodCalculator = createDefaultLodCalculator(); // set a default one\r
 \r
         // 1 upper left of heightmap, lower left quad\r
         float[] heightBlock1 = createHeightSubBlock(heightMap, 0, 0, split);\r
@@ -632,7 +636,7 @@ public class TerrainQuad extends Node implements Terrain {
 \r
         TerrainQuad quad1 = new TerrainQuad(getName() + "Quad1", blockSize,\r
                         split, stepScale, heightBlock1, totalSize, tempOffset,\r
-                        offsetAmount, lodCalculatorFactory);\r
+                        offsetAmount);\r
         quad1.setLocalTranslation(origin1);\r
         quad1.quadrant = 1;\r
         this.attachChild(quad1);\r
@@ -652,7 +656,7 @@ public class TerrainQuad extends Node implements Terrain {
 \r
         TerrainQuad quad2 = new TerrainQuad(getName() + "Quad2", blockSize,\r
                         split, stepScale, heightBlock2, totalSize, tempOffset,\r
-                        offsetAmount, lodCalculatorFactory);\r
+                        offsetAmount);\r
         quad2.setLocalTranslation(origin2);\r
         quad2.quadrant = 2;\r
         this.attachChild(quad2);\r
@@ -672,7 +676,7 @@ public class TerrainQuad extends Node implements Terrain {
 \r
         TerrainQuad quad3 = new TerrainQuad(getName() + "Quad3", blockSize,\r
                         split, stepScale, heightBlock3, totalSize, tempOffset,\r
-                        offsetAmount, lodCalculatorFactory);\r
+                        offsetAmount);\r
         quad3.setLocalTranslation(origin3);\r
         quad3.quadrant = 3;\r
         this.attachChild(quad3);\r
@@ -692,7 +696,7 @@ public class TerrainQuad extends Node implements Terrain {
 \r
         TerrainQuad quad4 = new TerrainQuad(getName() + "Quad4", blockSize,\r
                         split, stepScale, heightBlock4, totalSize, tempOffset,\r
-                        offsetAmount, lodCalculatorFactory);\r
+                        offsetAmount);\r
         quad4.setLocalTranslation(origin4);\r
         quad4.quadrant = 4;\r
         this.attachChild(quad4);\r
@@ -724,8 +728,8 @@ public class TerrainQuad extends Node implements Terrain {
         int halfSize = size >> 1;\r
         int split = (size + 1) >> 1;\r
 \r
-        if (lodCalculatorFactory == null)\r
-            lodCalculatorFactory = new LodDistanceCalculatorFactory(); // set a default one\r
+        //if (lodCalculator == null)\r
+        //    lodCalculator = createDefaultLodCalculator(); // set a default one\r
 \r
         offsetAmount += quarterSize;\r
 \r
@@ -748,7 +752,7 @@ public class TerrainQuad extends Node implements Terrain {
         this.attachChild(patch1);\r
         patch1.setModelBound(new BoundingBox());\r
         patch1.updateModelBound();\r
-        patch1.setLodCalculator(lodCalculatorFactory);\r
+        //patch1.setLodCalculator(lodCalculator);\r
         //TangentBinormalGenerator.generate(patch1);\r
 \r
         // 2 lower left\r
@@ -770,7 +774,7 @@ public class TerrainQuad extends Node implements Terrain {
         this.attachChild(patch2);\r
         patch2.setModelBound(new BoundingBox());\r
         patch2.updateModelBound();\r
-        patch2.setLodCalculator(lodCalculatorFactory);\r
+        //patch2.setLodCalculator(lodCalculator);\r
         //TangentBinormalGenerator.generate(patch2);\r
 \r
         // 3 upper right\r
@@ -792,7 +796,7 @@ public class TerrainQuad extends Node implements Terrain {
         this.attachChild(patch3);\r
         patch3.setModelBound(new BoundingBox());\r
         patch3.updateModelBound();\r
-        patch3.setLodCalculator(lodCalculatorFactory);\r
+        //patch3.setLodCalculator(lodCalculator);\r
         //TangentBinormalGenerator.generate(patch3);\r
 \r
         // 4 lower right\r
@@ -814,7 +818,7 @@ public class TerrainQuad extends Node implements Terrain {
         this.attachChild(patch4);\r
         patch4.setModelBound(new BoundingBox());\r
         patch4.updateModelBound();\r
-        patch4.setLodCalculator(lodCalculatorFactory);\r
+        //patch4.setLodCalculator(lodCalculator);\r
         //TangentBinormalGenerator.generate(patch4);\r
     }\r
 \r
@@ -1634,7 +1638,8 @@ public class TerrainQuad extends Node implements Terrain {
         offsetAmount = c.readFloat("offsetAmount", 0);\r
         quadrant = c.readInt("quadrant", 0);\r
         totalSize = c.readInt("totalSize", 0);\r
-        lodCalculatorFactory = (LodCalculatorFactory) c.readSavable("lodCalculatorFactory", null);\r
+        //lodCalculator = (LodCalculator) c.readSavable("lodCalculator", createDefaultLodCalculator());\r
+        //lodCalculatorFactory = (LodCalculatorFactory) c.readSavable("lodCalculatorFactory", null);\r
         \r
         if ( !(getParent() instanceof TerrainQuad) ) {\r
             BoundingBox all = new BoundingBox(getWorldTranslation(), totalSize, totalSize, totalSize);\r
@@ -1653,7 +1658,8 @@ public class TerrainQuad extends Node implements Terrain {
         c.write(offset, "offset", new Vector2f(0,0));\r
         c.write(offsetAmount, "offsetAmount", 0);\r
         c.write(quadrant, "quadrant", 0);\r
-        c.write(lodCalculatorFactory, "lodCalculatorFactory", null);\r
+        //c.write(lodCalculatorFactory, "lodCalculatorFactory", null);\r
+        //c.write(lodCalculator, "lodCalculator", null);\r
     }\r
 \r
     @Override\r
@@ -1671,7 +1677,9 @@ public class TerrainQuad extends Node implements Terrain {
         quadClone.offset = offset.clone();\r
         quadClone.offsetAmount = offsetAmount;\r
         quadClone.quadrant = quadrant;\r
-        quadClone.lodCalculatorFactory = lodCalculatorFactory.clone();\r
+        //quadClone.lodCalculatorFactory = lodCalculatorFactory.clone();\r
+        //quadClone.lodCalculator = lodCalculator.clone();\r
+        \r
         TerrainLodControl lodControl = quadClone.getControl(TerrainLodControl.class);\r
         if (lodControl != null && !(getParent() instanceof TerrainQuad)) {\r
             lodControl.setTerrain(quadClone); // set println in controller update to see if it is updating\r
@@ -1682,8 +1690,7 @@ public class TerrainQuad extends Node implements Terrain {
 \r
         return quadClone;\r
     }\r
-\r
-\r
+    \r
     public int getMaxLod() {\r
         if (maxLod < 0)\r
             maxLod = Math.max(1, (int) (FastMath.log(size-1)/FastMath.log(2)) -1); // -1 forces our minimum of 4 triangles wide\r
@@ -1699,7 +1706,6 @@ public class TerrainQuad extends Node implements Terrain {
         return totalSize;\r
     }\r
 \r
-\r
     public float[] getHeightMap() {\r
 \r
         float[] hm = null;\r
index f058052..6ffb577 100644 (file)
@@ -50,27 +50,23 @@ import java.util.List;
  */
 public class DistanceLodCalculator implements LodCalculator {
 
-    private TerrainPatch terrainPatch;
-    private LodThreshold lodThresholdCalculator;
-
+    private int size; // size of a terrain patch
+    private float lodMultiplier = 2;
+    
     public DistanceLodCalculator() {
     }
-
-    public DistanceLodCalculator(LodThreshold lodThresholdCalculator) {
-        this.lodThresholdCalculator = lodThresholdCalculator;
+    
+    public DistanceLodCalculator(int patchSize, float multiplier) {
+        this.size = patchSize;
+        this.lodMultiplier = multiplier;
     }
-
-    public DistanceLodCalculator(TerrainPatch terrainPatch, LodThreshold lodThresholdCalculator) {
-        this.terrainPatch = terrainPatch;
-        this.lodThresholdCalculator = lodThresholdCalculator;
-    }
-
-    public boolean calculateLod(List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
-        float distance = getCenterLocation().distance(locations.get(0));
+    
+    public boolean calculateLod(TerrainPatch terrainPatch, List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
+        float distance = getCenterLocation(terrainPatch).distance(locations.get(0));
 
         // go through each lod level to find the one we are in
         for (int i = 0; i <= terrainPatch.getMaxLod(); i++) {
-            if (distance < lodThresholdCalculator.getLodDistanceThreshold() * (i + 1)*terrainPatch.getWorldScale().x || i == terrainPatch.getMaxLod()) {
+            if (distance < getLodDistanceThreshold() * (i + 1)*terrainPatch.getWorldScale().x || i == terrainPatch.getMaxLod()) {
                 boolean reIndexNeeded = false;
                 if (i != terrainPatch.getLod()) {
                     reIndexNeeded = true;
@@ -94,49 +90,67 @@ public class DistanceLodCalculator implements LodCalculator {
         return false;
     }
 
-    public Vector3f getCenterLocation() {
+    protected Vector3f getCenterLocation(TerrainPatch terrainPatch) {
         Vector3f loc = terrainPatch.getWorldTranslation().clone();
         loc.x += terrainPatch.getSize()*terrainPatch.getWorldScale().x / 2;
         loc.z += terrainPatch.getSize()*terrainPatch.getWorldScale().z / 2;
         return loc;
     }
 
-    public void setTerrainPatch(TerrainPatch terrainPatch) {
-        this.terrainPatch = terrainPatch;
-    }
-
-    protected LodThreshold getLodThreshold() {
-        return lodThresholdCalculator;
-    }
-
-    protected void setLodThreshold(LodThreshold lodThresholdCalculator) {
-        this.lodThresholdCalculator = lodThresholdCalculator;
-    }
-
     public void write(JmeExporter ex) throws IOException {
         OutputCapsule oc = ex.getCapsule(this);
-        oc.write(lodThresholdCalculator, "lodThresholdCalculator", null);
+        oc.write(size, "patchSize", 32);
+        oc.write(lodMultiplier, "lodMultiplier", 32);
     }
 
     public void read(JmeImporter im) throws IOException {
         InputCapsule ic = im.getCapsule(this);
-        lodThresholdCalculator = (LodThreshold) ic.readSavable("lodThresholdCalculator", null);
+        size = ic.readInt("patchSize", 32);
+        lodMultiplier = ic.readFloat("lodMultiplier", 2.7f);
     }
 
     @Override
     public LodCalculator clone() {
         DistanceLodCalculator clone = new DistanceLodCalculator();
-        clone.lodThresholdCalculator = lodThresholdCalculator.clone();
 
         return clone;
     }
 
     @Override
     public String toString() {
-        return "DistanceLodCalculator " + lodThresholdCalculator.toString();
+        return "DistanceLodCalculator "+size+"*"+lodMultiplier;
     }
 
+    /**
+     * Gets the camera distance where the LOD level will change
+     */
+    protected float getLodDistanceThreshold() {
+        return size*lodMultiplier;
+    }
+    
+    /**
+     * Does this calculator require the terrain to have the difference of 
+     * LOD levels of neighbours to be more than 1.
+     */
     public boolean usesVariableLod() {
         return false;
     }
+
+    public float getLodMultiplier() {
+        return lodMultiplier;
+    }
+
+    public void setLodMultiplier(float lodMultiplier) {
+        this.lodMultiplier = lodMultiplier;
+    }
+
+    public int getSize() {
+        return size;
+    }
+
+    public void setSize(int size) {
+        this.size = size;
+    }
+    
+    
 }
index 2f37c59..7372b04 100644 (file)
@@ -47,9 +47,8 @@ import java.util.List;
  */
 public interface LodCalculator extends Savable, Cloneable {
 
-    public void setTerrainPatch(TerrainPatch terrainPatch);
-    public boolean calculateLod(List<Vector3f> locations, HashMap<String,UpdatedTerrainPatch> updates);
-
+    public boolean calculateLod(TerrainPatch terrainPatch, List<Vector3f> locations, HashMap<String,UpdatedTerrainPatch> updates);
+    
     public LodCalculator clone();
 
     /**
index 7785a19..6d5f5b8 100644 (file)
@@ -39,6 +39,7 @@ import com.jme3.terrain.geomipmap.TerrainPatch;
  * Creates LOD Calculator objects for the terrain patches.
  *
  * @author Brent Owens
+ * @deprecated phasing this out
  */
 public interface LodCalculatorFactory extends Savable, Cloneable {
 
index f114a72..29d5c25 100644 (file)
@@ -42,6 +42,7 @@ import java.io.IOException;
 /**
  *
  * @author bowens
+ * @deprecated phasing out
  */
 public class LodDistanceCalculatorFactory implements LodCalculatorFactory {
 
@@ -61,9 +62,7 @@ public class LodDistanceCalculatorFactory implements LodCalculatorFactory {
     }
 
     public LodCalculator createCalculator(TerrainPatch terrainPatch) {
-        if (lodThreshold == null)
-            lodThreshold = new SimpleLodThreshold(terrainPatch.getSize(), lodThresholdSize);
-        return new DistanceLodCalculator(terrainPatch, lodThreshold);
+        return new DistanceLodCalculator();
     }
 
     public void write(JmeExporter ex) throws IOException {
index 3d8d855..b453e26 100644 (file)
@@ -42,6 +42,7 @@ import java.io.IOException;
  * TODO: Make it work with multiple cameras
  * TODO: Fix the cracks when the lod differences are greater than 1
  * for two adjacent blocks.
+ * @deprecated phasing out
  */
 public class LodPerspectiveCalculatorFactory implements LodCalculatorFactory {
 
@@ -59,7 +60,6 @@ public class LodPerspectiveCalculatorFactory implements LodCalculatorFactory {
 
     public LodCalculator createCalculator(TerrainPatch terrainPatch) {
         PerspectiveLodCalculator p = new PerspectiveLodCalculator(cam, pixelError);
-        p.setTerrainPatch(terrainPatch);
         return p;
     }
 
index bf09b00..73d5c35 100644 (file)
@@ -45,10 +45,10 @@ import com.jme3.export.Savable;
  */\r
 public interface LodThreshold extends Savable, Cloneable {\r
 \r
-       /**\r
-        * A distance of how far between each LOD threshold.\r
-        */\r
-       public float getLodDistanceThreshold();\r
+    /**\r
+     * A distance of how far between each LOD threshold.\r
+     */\r
+    public float getLodDistanceThreshold();\r
 \r
     public LodThreshold clone();\r
 }\r
index 15a743a..ceb999b 100644 (file)
@@ -50,6 +50,8 @@ public class PerspectiveLodCalculator implements LodCalculator {
     private float[] entropyDistances;
     private float pixelError;
 
+    public PerspectiveLodCalculator() {}
+    
     public PerspectiveLodCalculator(Camera cam, float pixelError){
         this.cam = cam;
         this.pixelError = pixelError;
@@ -71,12 +73,12 @@ public class PerspectiveLodCalculator implements LodCalculator {
         float T = (2f * pixelLimit) / v_res;
         return A / T;
     }
-
-    public void setTerrainPatch(TerrainPatch terrainPatch) {
-        patch = terrainPatch;
+    
+    public boolean calculateLod(List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
+        return calculateLod(patch, locations, updates);
     }
 
-    public boolean calculateLod(List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
+    public boolean calculateLod(TerrainPatch terrainPatch, List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
         if (entropyDistances == null){
             // compute entropy distances
             float[] lodEntropies = patch.getLodEntropies();
@@ -87,7 +89,7 @@ public class PerspectiveLodCalculator implements LodCalculator {
             }
         }
 
-        Vector3f patchPos = getCenterLocation();
+        Vector3f patchPos = getCenterLocation(patch);
 
         // vector from camera to patch
         //Vector3f toPatchDir = locations.get(0).subtract(patchPos).normalizeLocal();
@@ -120,7 +122,7 @@ public class PerspectiveLodCalculator implements LodCalculator {
         return false;
     }
 
-    public Vector3f getCenterLocation() {
+    public Vector3f getCenterLocation(TerrainPatch patch) {
         Vector3f loc = patch.getWorldTranslation().clone();
         loc.x += patch.getSize() / 2;
         loc.z += patch.getSize() / 2;
@@ -146,4 +148,18 @@ public class PerspectiveLodCalculator implements LodCalculator {
         return true;
     }
 
+    public float getPixelError() {
+        return pixelError;
+    }
+
+    public void setPixelError(float pixelError) {
+        this.pixelError = pixelError;
+    }
+
+    public void setCam(Camera cam) {
+        this.cam = cam;
+    }
+
+    
+    
 }
index 3dd92dd..bd512e5 100644 (file)
@@ -36,6 +36,8 @@ import com.jme3.export.InputCapsule;
 import com.jme3.export.JmeExporter;\r
 import com.jme3.export.JmeImporter;\r
 import com.jme3.export.OutputCapsule;\r
+import com.jme3.terrain.Terrain;\r
+import com.jme3.terrain.geomipmap.TerrainQuad;\r
 import java.io.IOException;\r
 \r
 \r
@@ -49,17 +51,21 @@ import java.io.IOException;
  */\r
 public class SimpleLodThreshold implements LodThreshold {\r
        \r
-       private int size; // size of a terrain patch\r
+    private int size; // size of a terrain patch\r
     private float lodMultiplier = 2;\r
 \r
     \r
     public SimpleLodThreshold() {\r
-\r
+    }\r
+    \r
+    public SimpleLodThreshold(Terrain terrain) {\r
+        if (terrain instanceof TerrainQuad)\r
+            this.size = ((TerrainQuad)terrain).getPatchSize();\r
     }\r
 \r
-       public SimpleLodThreshold(int patchSize, float lodMultiplier) {\r
-               this.size = patchSize;\r
-       }\r
+    public SimpleLodThreshold(int patchSize, float lodMultiplier) {\r
+        this.size = patchSize;\r
+    }\r
 \r
     public float getLodMultiplier() {\r
         return lodMultiplier;\r
@@ -78,9 +84,9 @@ public class SimpleLodThreshold implements LodThreshold {
     }\r
        \r
 \r
-       public float getLodDistanceThreshold() {\r
-               return size*lodMultiplier;\r
-       }\r
+    public float getLodDistanceThreshold() {\r
+        return size*lodMultiplier;\r
+    }\r
 \r
     public void write(JmeExporter ex) throws IOException {\r
         OutputCapsule oc = ex.getCapsule(this);\r
index d5e1c37..d49b9eb 100644 (file)
@@ -22,6 +22,7 @@ import com.jme3.renderer.Camera;
 import com.jme3.terrain.geomipmap.TerrainGrid;
 import com.jme3.terrain.geomipmap.TerrainGridListener;
 import com.jme3.terrain.geomipmap.TerrainLodControl;
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
 import com.jme3.terrain.heightmap.FractalHeightMapGrid;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture.WrapMode;
@@ -145,6 +146,7 @@ public class TerrainFractalGridTest extends SimpleApplication {
         List<Camera> cameras = new ArrayList<Camera>();
         cameras.add(this.getCamera());
         TerrainLodControl control = new TerrainLodControl(this.terrain, cameras);
+        control.setLodCalculator( new DistanceLodCalculator(33, 2.7f) ); // patch size, and a multiplier
         this.terrain.addControl(control);
 
         final BulletAppState bulletAppState = new BulletAppState();
index c662dd7..8715503 100644 (file)
@@ -26,6 +26,7 @@ import com.jme3.terrain.geomipmap.TerrainGrid;
 import com.jme3.terrain.geomipmap.TerrainGridListener;
 import com.jme3.terrain.geomipmap.TerrainLodControl;
 import com.jme3.terrain.geomipmap.TerrainQuad;
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
 import com.jme3.terrain.heightmap.FractalHeightMapGrid;
 import com.jme3.terrain.heightmap.ImageBasedHeightMapGrid;
 import com.jme3.terrain.heightmap.Namer;
@@ -158,6 +159,7 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
         List<Camera> cameras = new ArrayList<Camera>();
         cameras.add(this.getCamera());
         TerrainLodControl control = new TerrainLodControl(this.terrain, cameras);
+        control.setLodCalculator( new DistanceLodCalculator(33, 2.7f) ); // patch size, and a multiplier
         this.terrain.addControl(control);
 
         final BulletAppState bulletAppState = new BulletAppState();
index 2fb47d9..5bfd88c 100644 (file)
@@ -19,6 +19,7 @@ import com.jme3.terrain.geomipmap.TerrainGrid;
 import com.jme3.terrain.geomipmap.TerrainGridListener;
 import com.jme3.terrain.geomipmap.TerrainLodControl;
 import com.jme3.terrain.geomipmap.TerrainQuad;
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
 import com.jme3.terrain.heightmap.ImageBasedHeightMapGrid;
 import com.jme3.terrain.heightmap.Namer;
 import com.jme3.texture.Texture;
@@ -106,6 +107,7 @@ public class TerrainGridTest extends SimpleApplication {
         this.rootNode.attachChild(this.terrain);
 
         TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera());
+        control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
         this.terrain.addControl(control);
 
         final BulletAppState bulletAppState = new BulletAppState();
index 66a6388..b7e5fd0 100644 (file)
@@ -47,6 +47,8 @@ import com.jme3.terrain.geomipmap.TerrainLodControl;
 import com.jme3.terrain.heightmap.AbstractHeightMap;
 import com.jme3.terrain.heightmap.ImageBasedHeightMap;
 import com.jme3.terrain.geomipmap.TerrainQuad;
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
+import com.jme3.terrain.geomipmap.lodcalc.SimpleLodThreshold;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture.WrapMode;
 
@@ -155,8 +157,9 @@ public class TerrainTest extends SimpleApplication {
          * The total size is up to you. At 1025 it ran fine for me (200+FPS), however at
          * size=2049, it got really slow. But that is a jump from 2 million to 8 million triangles...
          */
-        terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
+        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
         terrain.addControl(control);
         terrain.setMaterial(matRock);
         terrain.setLocalTranslation(0, -100, 0);
index 0f2da81..533dce4 100644 (file)
@@ -50,6 +50,7 @@ import com.jme3.terrain.geomipmap.TerrainLodControl;
 import com.jme3.terrain.heightmap.AbstractHeightMap;
 import com.jme3.terrain.heightmap.ImageBasedHeightMap;
 import com.jme3.terrain.geomipmap.TerrainQuad;
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture.WrapMode;
 import com.jme3.util.SkyFactory;
@@ -96,7 +97,6 @@ public class TerrainTestAdvanced extends SimpleApplication {
         // TERRAIN TEXTURE material
         matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
         matTerrain.setBoolean("useTriPlanarMapping", false);
-        matTerrain.setBoolean("WardIso", true);
 
         // ALPHA map (for splat textures)
         matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.png"));
@@ -105,18 +105,17 @@ public class TerrainTestAdvanced extends SimpleApplication {
         // HEIGHTMAP image (for the terrain heightmap)
         Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
 
-
         // GRASS texture
         Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
         grass.setWrap(WrapMode.Repeat);
-        matTerrain.setTexture("DiffuseMap", grass);
-        matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
+        matTerrain.setTexture("DiffuseMap_1", grass);
+        matTerrain.setFloat("DiffuseMap_1_scale", grassScale);
 
         // DIRT texture
         Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
         dirt.setWrap(WrapMode.Repeat);
-        matTerrain.setTexture("DiffuseMap_1", dirt);
-        matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);
+        matTerrain.setTexture("DiffuseMap", dirt);
+        matTerrain.setFloat("DiffuseMap_0_scale", dirtScale);
 
         // ROCK texture
         Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
@@ -143,7 +142,7 @@ public class TerrainTestAdvanced extends SimpleApplication {
         normalMap1.setWrap(WrapMode.Repeat);
         Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
         normalMap2.setWrap(WrapMode.Repeat);
-        matTerrain.setTexture("NormalMap", normalMap0);
+        matTerrain.setTexture("NormalMap", normalMap2);
         matTerrain.setTexture("NormalMap_1", normalMap2);
         matTerrain.setTexture("NormalMap_2", normalMap2);
         matTerrain.setTexture("NormalMap_4", normalMap2);
@@ -158,10 +157,9 @@ public class TerrainTestAdvanced extends SimpleApplication {
         // CREATE HEIGHTMAP
         AbstractHeightMap heightmap = null;
         try {
-            //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
-
-            heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);
+            heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.5f);
             heightmap.load();
+            heightmap.smooth(0.9f, 1);
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -178,6 +176,7 @@ public class TerrainTestAdvanced extends SimpleApplication {
          */
         terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
         TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
+        control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
         terrain.addControl(control);
         terrain.setMaterial(matTerrain);
         terrain.setModelBound(new BoundingBox());
@@ -185,17 +184,17 @@ public class TerrainTestAdvanced extends SimpleApplication {
         terrain.setLocalTranslation(0, -100, 0);
         terrain.setLocalScale(1f, 1f, 1f);
         rootNode.attachChild(terrain);
+        
+        Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
+        //terrain.generateDebugTangents(debugMat);
 
         DirectionalLight light = new DirectionalLight();
-        light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
+        light.setDirection((new Vector3f(-0.25f, -1f, -0.25f)).normalize());
         rootNode.addLight(light);
 
-        AmbientLight ambLight = new AmbientLight();
-        ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
-        rootNode.addLight(ambLight);
-
         cam.setLocation(new Vector3f(0, 10, -10));
         cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
+        flyCam.setMoveSpeed(400);
     }
 
     public void loadHintText() {
index 4672b98..a408f71 100644 (file)
@@ -60,6 +60,7 @@ import com.jme3.terrain.geomipmap.TerrainLodControl;
 import com.jme3.terrain.heightmap.AbstractHeightMap;
 import com.jme3.terrain.heightmap.ImageBasedHeightMap;
 import com.jme3.terrain.geomipmap.TerrainQuad;
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture.WrapMode;
 
@@ -134,6 +135,7 @@ public class TerrainTestCollision extends SimpleApplication {
 
         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
         terrain.addControl(control);
         terrain.setMaterial(matRock);
         terrain.setLocalScale(new Vector3f(2, 2, 2));
index 1fe7253..0fe4a0c 100644 (file)
@@ -54,6 +54,7 @@ import com.jme3.scene.shape.Sphere;
 import com.jme3.terrain.geomipmap.TerrainGrid;
 import com.jme3.terrain.geomipmap.TerrainLodControl;
 import com.jme3.terrain.geomipmap.TerrainQuad;
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
 import com.jme3.terrain.heightmap.AbstractHeightMap;
 import com.jme3.terrain.heightmap.FractalHeightMapGrid;
 import com.jme3.terrain.heightmap.ImageBasedHeightMap;
@@ -317,6 +318,7 @@ public class TerrainTestModifyHeight extends SimpleApplication {
         // CREATE THE TERRAIN
         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
         terrain.addControl(control);
         terrain.setMaterial(matTerrain);
         terrain.setLocalTranslation(0, -100, 0);
index 9b40303..b8c6153 100644 (file)
@@ -47,6 +47,7 @@ import com.jme3.scene.Node;
 import com.jme3.terrain.Terrain;
 import com.jme3.terrain.geomipmap.TerrainLodControl;
 import com.jme3.terrain.geomipmap.TerrainQuad;
+import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
 import com.jme3.terrain.heightmap.AbstractHeightMap;
 import com.jme3.terrain.heightmap.ImageBasedHeightMap;
 import com.jme3.texture.Texture;
@@ -159,6 +160,7 @@ public class TerrainTestReadWrite extends SimpleApplication {
             // create the terrain as normal, and give it a control for LOD management
             TerrainQuad terrainQuad = new TerrainQuad("terrain", 65, 129, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
             TerrainLodControl control = new TerrainLodControl(terrainQuad, getCamera());
+            control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
             terrainQuad.addControl(control);
             terrainQuad.setMaterial(matTerrain);
             terrainQuad.setLocalTranslation(0, -100, 0);