* Fix PerspectiveLodCalculator by not caching entropies in object (since they vary per block)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10573 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..RD 12 years ago
parent cfb9c7e1a3
commit 199378ca2f
  1. 38
      engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/PerspectiveLodCalculator.java

@ -45,12 +45,12 @@ import java.util.List;
public class PerspectiveLodCalculator implements LodCalculator { public class PerspectiveLodCalculator implements LodCalculator {
private Camera cam; private Camera cam;
private float[] entropyDistances;
private float pixelError; private float pixelError;
private boolean turnOffLod = false;
public PerspectiveLodCalculator() {} public PerspectiveLodCalculator() {}
public PerspectiveLodCalculator(Camera cam, float pixelError){ public PerspectiveLodCalculator(Camera cam, float pixelError) {
this.cam = cam; this.cam = cam;
this.pixelError = pixelError; this.pixelError = pixelError;
} }
@ -73,16 +73,23 @@ public class PerspectiveLodCalculator implements LodCalculator {
} }
public boolean calculateLod(TerrainPatch patch, List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) { public boolean calculateLod(TerrainPatch patch, List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
if (entropyDistances == null){ if (turnOffLod) {
// compute entropy distances // set to full detail
float[] lodEntropies = patch.getLodEntropies(); int prevLOD = patch.getLod();
entropyDistances = new float[lodEntropies.length]; UpdatedTerrainPatch utp = updates.get(patch.getName());
float cameraConstant = getCameraConstant(cam, pixelError); if (utp == null) {
for (int i = 0; i < lodEntropies.length; i++){ utp = new UpdatedTerrainPatch(patch);
entropyDistances[i] = lodEntropies[i] * cameraConstant; updates.put(utp.getName(), utp);
} }
utp.setNewLod(0);
utp.setPreviousLod(prevLOD);
//utp.setReIndexNeeded(true);
return true;
} }
float[] lodEntropies = patch.getLodEntropies();
float cameraConstant = getCameraConstant(cam, pixelError);
Vector3f patchPos = getCenterLocation(patch); Vector3f patchPos = getCenterLocation(patch);
// vector from camera to patch // vector from camera to patch
@ -92,7 +99,7 @@ public class PerspectiveLodCalculator implements LodCalculator {
// go through each lod level to find the one we are in // go through each lod level to find the one we are in
for (int i = 0; i <= patch.getMaxLod(); i++) { for (int i = 0; i <= patch.getMaxLod(); i++) {
if (distance < entropyDistances[i] || i == patch.getMaxLod()){ if (distance < lodEntropies[i] * cameraConstant || i == patch.getMaxLod()){
boolean reIndexNeeded = false; boolean reIndexNeeded = false;
if (i != patch.getLod()) { if (i != patch.getLod()) {
reIndexNeeded = true; reIndexNeeded = true;
@ -133,6 +140,7 @@ public class PerspectiveLodCalculator implements LodCalculator {
} }
public void write(JmeExporter ex) throws IOException { public void write(JmeExporter ex) throws IOException {
} }
public void read(JmeImporter im) throws IOException { public void read(JmeImporter im) throws IOException {
@ -155,15 +163,15 @@ public class PerspectiveLodCalculator implements LodCalculator {
} }
public void turnOffLod() { public void turnOffLod() {
//TODO turnOffLod = true;
} }
public boolean isLodOff() { public boolean isLodOff() {
return false; //TODO return turnOffLod;
} }
public void turnOnLod() { public void turnOnLod() {
//TODO turnOffLod = false;
} }
} }

Loading…
Cancel
Save