moved terrainGrid normal recalculations out of the tile loading loop to run after all tiles have loaded

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9788 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..om 13 years ago
parent cbafa1852b
commit 77a1ec09f8
  1. 29
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java
  2. 20
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java

@ -196,6 +196,22 @@ public class TerrainGrid extends TerrainQuad {
} }
} }
getControl(UpdateControl.class).enqueue(new Callable() {
// back on the OpenGL thread:
public Object call() throws Exception {
for (Spatial s : getChildren()) {
if (s instanceof TerrainQuad) {
TerrainQuad tq = (TerrainQuad)s;
tq.resetCachedNeighbours();
}
}
System.out.println("fixed normals "+location.clone().mult(size));
setNeedToRecalculateNormals();
//fixNormalEdges(new BoundingBox(location.clone().mult(size), size*2, Float.MAX_VALUE, size*2));
// the edges are fixed once, but not with lod change
return null;
}
});
} }
} }
@ -229,6 +245,9 @@ public class TerrainGrid extends TerrainQuad {
terrainQuadGrid.setPatchSize(this.patchSize); terrainQuadGrid.setPatchSize(this.patchSize);
terrainQuadGrid.setQuadSize(this.quadSize); terrainQuadGrid.setQuadSize(this.quadSize);
addControl(new UpdateControl()); addControl(new UpdateControl());
fixNormalEdges(new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2));
addControl(new NormalRecalcControl(this));
} }
public TerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, TerrainGridTileLoader terrainQuadGrid) { public TerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, TerrainGridTileLoader terrainQuadGrid) {
@ -252,6 +271,9 @@ public class TerrainGrid extends TerrainQuad {
this.heightMapGrid = heightMapGrid; this.heightMapGrid = heightMapGrid;
heightMapGrid.setSize(this.quadSize); heightMapGrid.setSize(this.quadSize);
addControl(new UpdateControl()); addControl(new UpdateControl());
fixNormalEdges(new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2));
addControl(new NormalRecalcControl(this));
} }
@Deprecated @Deprecated
@ -343,13 +365,16 @@ public class TerrainGrid extends TerrainQuad {
} }
updateModelBound(); updateModelBound();
for (Spatial s : getChildren()) { /*for (Spatial s : getChildren()) {
if (s instanceof TerrainQuad) { if (s instanceof TerrainQuad) {
TerrainQuad tq = (TerrainQuad)s; TerrainQuad tq = (TerrainQuad)s;
tq.resetCachedNeighbours(); tq.resetCachedNeighbours();
tq.fixNormalEdges(new BoundingBox(tq.getWorldTranslation(), totalSize*2, Float.MAX_VALUE, totalSize*2));
} }
} }
System.out.println("fix normals "+loc);
fixNormalEdges(new BoundingBox(loc, totalSize*6, Float.MAX_VALUE, totalSize*6));
*/
} }

@ -123,6 +123,10 @@ public class TerrainQuad extends Node implements Terrain {
*/ */
public TerrainQuad(String name, int patchSize, int totalSize, float[] heightMap) { public TerrainQuad(String name, int patchSize, int totalSize, float[] heightMap) {
this(name, patchSize, totalSize, Vector3f.UNIT_XYZ, heightMap); this(name, patchSize, totalSize, Vector3f.UNIT_XYZ, heightMap);
affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2);
fixNormalEdges(affectedAreaBBox);
addControl(new NormalRecalcControl(this));
} }
/** /**
@ -153,9 +157,9 @@ public class TerrainQuad extends Node implements Terrain {
@Deprecated @Deprecated
public TerrainQuad(String name, int patchSize, int size, Vector3f scale, float[] heightMap) { public TerrainQuad(String name, int patchSize, int size, Vector3f scale, float[] heightMap) {
this(name, patchSize, size, scale, heightMap, size, new Vector2f(), 0); this(name, patchSize, size, scale, heightMap, size, new Vector2f(), 0);
affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2); //affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2);
fixNormalEdges(affectedAreaBBox); //fixNormalEdges(affectedAreaBBox);
addControl(new NormalRecalcControl(this)); //addControl(new NormalRecalcControl(this));
} }
/** /**
@ -172,9 +176,9 @@ public class TerrainQuad extends Node implements Terrain {
@Deprecated @Deprecated
public TerrainQuad(String name, int patchSize, int totalSize, int quadSize, Vector3f scale, float[] heightMap) { public TerrainQuad(String name, int patchSize, int totalSize, int quadSize, Vector3f scale, float[] heightMap) {
this(name, patchSize, quadSize, scale, heightMap, totalSize, new Vector2f(), 0); this(name, patchSize, quadSize, scale, heightMap, totalSize, new Vector2f(), 0);
affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), totalSize*2, Float.MAX_VALUE, totalSize*2); //affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), totalSize*2, Float.MAX_VALUE, totalSize*2);
fixNormalEdges(affectedAreaBBox); //fixNormalEdges(affectedAreaBBox);
addControl(new NormalRecalcControl(this)); //addControl(new NormalRecalcControl(this));
} }
protected TerrainQuad(String name, int patchSize, int quadSize, protected TerrainQuad(String name, int patchSize, int quadSize,
@ -851,7 +855,7 @@ public class TerrainQuad extends Node implements Terrain {
if (affectedAreaBBox != null) if (affectedAreaBBox != null)
return true; return true;
if (!lastScale.equals(getWorldScale())) { if (!lastScale.equals(getWorldScale())) {
affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size, Float.MAX_VALUE, size); affectedAreaBBox = new BoundingBox(getWorldTranslation(), Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
lastScale = getWorldScale(); lastScale = getWorldScale();
return true; return true;
} }
@ -862,7 +866,7 @@ public class TerrainQuad extends Node implements Terrain {
* This will cause all normals for this terrain quad to be recalculated * This will cause all normals for this terrain quad to be recalculated
*/ */
protected void setNeedToRecalculateNormals() { protected void setNeedToRecalculateNormals() {
affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2); affectedAreaBBox = new BoundingBox(getWorldTranslation(), Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
} }
public float getHeightmapHeight(Vector2f xz) { public float getHeightmapHeight(Vector2f xz) {

Loading…
Cancel
Save