TerrainGrid no longer needs initialize() called, handled automatically now.

TG normal seams fixed

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8807 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 13 years ago
parent b736768b2d
commit 36453a919c
  1. 19
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java
  2. 9
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java
  3. 2
      engine/src/test/jme3test/terrain/TerrainFractalGridTest.java
  4. 11
      engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java
  5. 2
      engine/src/test/jme3test/terrain/TerrainGridSerializationTest.java
  6. 2
      engine/src/test/jme3test/terrain/TerrainGridTest.java
  7. 2
      engine/src/test/jme3test/terrain/TerrainGridTileLoaderTest.java
  8. 1
      engine/src/test/jme3test/terrain/TerrainTestAdvanced.java
  9. 2
      engine/src/test/jme3test/terrain/TerrainTestModifyHeight.java

@ -31,6 +31,7 @@
*/ */
package com.jme3.terrain.geomipmap; package com.jme3.terrain.geomipmap;
import com.jme3.bounding.BoundingBox;
import com.jme3.export.JmeExporter; import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.scene.control.UpdateControl; import com.jme3.scene.control.UpdateControl;
@ -50,6 +51,7 @@ import com.jme3.material.Material;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import com.jme3.terrain.Terrain; import com.jme3.terrain.Terrain;
import com.jme3.terrain.geomipmap.lodcalc.LodCalculator; import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;
import com.jme3.terrain.heightmap.HeightMapGrid; import com.jme3.terrain.heightmap.HeightMapGrid;
@ -118,6 +120,7 @@ public class TerrainGrid extends TerrainQuad {
protected PhysicsSpace space; protected PhysicsSpace space;
private int cellsLoaded = 0; private int cellsLoaded = 0;
private int[] gridOffset; private int[] gridOffset;
private boolean runOnce = false;
protected class UpdateQuadCache implements Runnable { protected class UpdateQuadCache implements Runnable {
@ -166,7 +169,7 @@ public class TerrainGrid extends TerrainQuad {
public Object call() throws Exception { public Object call() throws Exception {
attachQuadAt(newQuad, quadrant, quadCell); attachQuadAt(newQuad, quadrant, quadCell);
newQuad.resetCachedNeighbours(); //newQuad.resetCachedNeighbours();
return null; return null;
} }
}); });
@ -269,6 +272,9 @@ public class TerrainGrid extends TerrainQuad {
} }
/**
* @deprecated not needed to be called any more, handled automatically
*/
public void initialize(Vector3f location) { public void initialize(Vector3f location) {
if (this.material == null) { if (this.material == null) {
throw new RuntimeException("Material must be set prior to call of initialize"); throw new RuntimeException("Material must be set prior to call of initialize");
@ -293,13 +299,14 @@ public class TerrainGrid extends TerrainQuad {
gridOffset[1] = Math.round(camCell.z * (size / 2)); gridOffset[1] = Math.round(camCell.z * (size / 2));
cellsLoaded = 0; cellsLoaded = 0;
} }
if (camCell.x != this.currentCamCell.x || camCell.z != currentCamCell.z) { if (camCell.x != this.currentCamCell.x || camCell.z != currentCamCell.z || !runOnce) {
// if the camera has moved into a new cell, load new terrain into the visible 4 center quads // if the camera has moved into a new cell, load new terrain into the visible 4 center quads
this.updateChildren(camCell); this.updateChildren(camCell);
for (TerrainGridListener l : this.listeners) { for (TerrainGridListener l : this.listeners) {
l.gridMoved(camCell); l.gridMoved(camCell);
} }
} }
runOnce = true;
super.update(locations, lodCalculator); super.update(locations, lodCalculator);
} }
@ -353,6 +360,14 @@ public class TerrainGrid extends TerrainQuad {
l.tileAttached(quadCell, q); l.tileAttached(quadCell, q);
} }
updateModelBound(); updateModelBound();
for (Spatial s : getChildren()) {
if (s instanceof TerrainQuad) {
TerrainQuad tq = (TerrainQuad)s;
tq.resetCachedNeighbours();
tq.fixNormalEdges(new BoundingBox(tq.getWorldTranslation(), totalSize*2, Float.MAX_VALUE, totalSize*2));
}
}
} }
@Deprecated @Deprecated

@ -584,7 +584,7 @@ public class TerrainQuad extends Node implements Terrain {
TerrainPatch patch = (TerrainPatch) child; TerrainPatch patch = (TerrainPatch) child;
UpdatedTerrainPatch utp = updated.get(patch.getName()); UpdatedTerrainPatch utp = updated.get(patch.getName());
if(utp.lodChanged()) { if(utp != null && utp.lodChanged()) {
if (!patch.searchedForNeighboursAlready) { if (!patch.searchedForNeighboursAlready) {
// set the references to the neighbours // set the references to the neighbours
patch.rightNeighbour = findRightPatch(patch); patch.rightNeighbour = findRightPatch(patch);
@ -976,6 +976,13 @@ public class TerrainQuad extends Node implements Terrain {
return false; return false;
} }
/**
* This will cause all normals for this terrain quad to be recalculated
*/
protected void setNeedToRecalculateNormals() {
affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2);
}
public float getHeightmapHeight(Vector2f xz) { public float getHeightmapHeight(Vector2f xz) {
// offset // offset
int halfSize = totalSize / 2; int halfSize = totalSize / 2;

@ -138,7 +138,7 @@ public class TerrainFractalGridTest extends SimpleApplication {
this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f)); this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
this.terrain.initialize(cam.getLocation());
} }
@Override @Override

@ -92,6 +92,7 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
material = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md"); material = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
material.setBoolean("useTriPlanarMapping", false); material.setBoolean("useTriPlanarMapping", false);
//material.setBoolean("isTerrainGrid", true); //material.setBoolean("isTerrainGrid", true);
material.setFloat("Shininess", 0.0f);
// GRASS texture // GRASS texture
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
@ -192,11 +193,11 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
public void tileAttached(Vector3f cell, TerrainQuad quad) { public void tileAttached(Vector3f cell, TerrainQuad quad) {
Texture alpha = null; Texture alpha = null;
try { //try {
alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_" + (int)cell.x+ "_" + (int)cell.z + ".png"); // alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_" + (int)cell.x+ "_" + (int)cell.z + ".png");
} catch (Exception e) { //} catch (Exception e) {
alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_default.png"); alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_default.png");
} //}
quad.getMaterial().setTexture("AlphaMap", alpha); quad.getMaterial().setTexture("AlphaMap", alpha);
if (usePhysics) { if (usePhysics) {
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0)); quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
@ -213,7 +214,7 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
updateMarkerElevations(); updateMarkerElevations();
} }
}); });
this.terrain.initialize(cam.getLocation());
this.initKeys(); this.initKeys();
markers = new Node(); markers = new Node();

@ -97,7 +97,7 @@ public class TerrainGridSerializationTest extends SimpleApplication {
}); });
} }
this.terrain.initialize(cam.getLocation());
this.initKeys(); this.initKeys();
} }

@ -158,7 +158,7 @@ public class TerrainGridTest extends SimpleApplication {
}); });
} }
this.terrain.initialize(cam.getLocation());
this.initKeys(); this.initKeys();
} }

@ -154,7 +154,7 @@ public class TerrainGridTileLoaderTest extends SimpleApplication {
}); });
} }
this.terrain.initialize(cam.getLocation());
this.initKeys(); this.initKeys();
} }

@ -97,6 +97,7 @@ public class TerrainTestAdvanced extends SimpleApplication {
// TERRAIN TEXTURE material // TERRAIN TEXTURE material
matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md"); matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matTerrain.setBoolean("useTriPlanarMapping", false); matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setFloat("Shininess", 0.0f);
// ALPHA map (for splat textures) // ALPHA map (for splat textures)
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.png")); matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.png"));

@ -408,7 +408,7 @@ public class TerrainTestModifyHeight extends SimpleApplication {
terrain.setMaterial(matTerrain); terrain.setMaterial(matTerrain);
terrain.setLocalTranslation(0, 0, 0); terrain.setLocalTranslation(0, 0, 0);
terrain.setLocalScale(2f, 1f, 2f); terrain.setLocalScale(2f, 1f, 2f);
((TerrainGrid)terrain).initialize(Vector3f.ZERO);
rootNode.attachChild(this.terrain); rootNode.attachChild(this.terrain);
TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera()); TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera());

Loading…
Cancel
Save