* 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. 32
      engine/src/terrain/com/jme3/terrain/geomipmap/lodcalc/PerspectiveLodCalculator.java

@ -45,8 +45,8 @@ import java.util.List;
public class PerspectiveLodCalculator implements LodCalculator {
private Camera cam;
private float[] entropyDistances;
private float pixelError;
private boolean turnOffLod = false;
public PerspectiveLodCalculator() {}
@ -73,16 +73,23 @@ public class PerspectiveLodCalculator implements LodCalculator {
}
public boolean calculateLod(TerrainPatch patch, List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
if (entropyDistances == null){
// compute entropy distances
float[] lodEntropies = patch.getLodEntropies();
entropyDistances = new float[lodEntropies.length];
float cameraConstant = getCameraConstant(cam, pixelError);
for (int i = 0; i < lodEntropies.length; i++){
entropyDistances[i] = lodEntropies[i] * cameraConstant;
if (turnOffLod) {
// set to full detail
int prevLOD = patch.getLod();
UpdatedTerrainPatch utp = updates.get(patch.getName());
if (utp == null) {
utp = new UpdatedTerrainPatch(patch);
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);
// 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
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;
if (i != patch.getLod()) {
reIndexNeeded = true;
@ -133,6 +140,7 @@ public class PerspectiveLodCalculator implements LodCalculator {
}
public void write(JmeExporter ex) throws IOException {
}
public void read(JmeImporter im) throws IOException {
@ -155,15 +163,15 @@ public class PerspectiveLodCalculator implements LodCalculator {
}
public void turnOffLod() {
//TODO
turnOffLod = true;
}
public boolean isLodOff() {
return false; //TODO
return turnOffLod;
}
public void turnOnLod() {
//TODO
turnOffLod = false;
}
}

Loading…
Cancel
Save