use of com.jme3.terrain.geomipmap.UpdatedTerrainPatch in project jmonkeyengine by jMonkeyEngine.
the class DistanceLodCalculator method calculateLod.
public boolean calculateLod(TerrainPatch terrainPatch, List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
if (locations == null || locations.isEmpty())
// no camera yet
return false;
float distance = getCenterLocation(terrainPatch).distance(locations.get(0));
if (turnOffLod) {
// set to full detail
int prevLOD = terrainPatch.getLod();
UpdatedTerrainPatch utp = updates.get(terrainPatch.getName());
if (utp == null) {
utp = new UpdatedTerrainPatch(terrainPatch);
updates.put(utp.getName(), utp);
}
utp.setNewLod(0);
utp.setPreviousLod(prevLOD);
//utp.setReIndexNeeded(true);
return true;
}
// go through each lod level to find the one we are in
for (int i = 0; i <= terrainPatch.getMaxLod(); i++) {
if (distance < getLodDistanceThreshold() * (i + 1) * terrainPatch.getWorldScaleCached().x || i == terrainPatch.getMaxLod()) {
boolean reIndexNeeded = false;
if (i != terrainPatch.getLod()) {
reIndexNeeded = true;
//System.out.println("lod change: "+lod+" > "+i+" dist: "+distance);
}
int prevLOD = terrainPatch.getLod();
UpdatedTerrainPatch utp = updates.get(terrainPatch.getName());
if (utp == null) {
//save in here, do not update actual variables
utp = new UpdatedTerrainPatch(terrainPatch);
updates.put(utp.getName(), utp);
}
utp.setNewLod(i);
utp.setPreviousLod(prevLOD);
return reIndexNeeded;
}
}
return false;
}
use of com.jme3.terrain.geomipmap.UpdatedTerrainPatch in project jmonkeyengine by jMonkeyEngine.
the class PerspectiveLodCalculator method calculateLod.
public boolean calculateLod(TerrainPatch patch, List<Vector3f> locations, HashMap<String, UpdatedTerrainPatch> updates) {
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
//Vector3f toPatchDir = locations.get(0).subtract(patchPos).normalizeLocal();
//float facing = cam.getDirection().dot(toPatchDir);
float distance = patchPos.distance(locations.get(0));
// go through each lod level to find the one we are in
for (int i = 0; i <= patch.getMaxLod(); i++) {
if (distance < lodEntropies[i] * cameraConstant || i == patch.getMaxLod()) {
boolean reIndexNeeded = false;
if (i != patch.getLod()) {
reIndexNeeded = true;
// System.out.println("lod change: "+lod+" > "+i+" dist: "+distance);
}
int prevLOD = patch.getLod();
UpdatedTerrainPatch utp = updates.get(patch.getName());
if (utp == null) {
//save in here, do not update actual variables
utp = new UpdatedTerrainPatch(patch);
updates.put(utp.getName(), utp);
}
utp.setNewLod(i);
utp.setPreviousLod(prevLOD);
//utp.setReIndexNeeded(reIndexNeeded);
return reIndexNeeded;
}
}
return false;
}
use of com.jme3.terrain.geomipmap.UpdatedTerrainPatch in project jmonkeyengine by jMonkeyEngine.
the class TerrainPatch method reIndexGeometry.
protected void reIndexGeometry(HashMap<String, UpdatedTerrainPatch> updated, boolean useVariableLod) {
UpdatedTerrainPatch utp = updated.get(getName());
if (utp != null && utp.isReIndexNeeded()) {
int pow = (int) Math.pow(2, utp.getNewLod());
boolean left = utp.getLeftLod() > utp.getNewLod();
boolean top = utp.getTopLod() > utp.getNewLod();
boolean right = utp.getRightLod() > utp.getNewLod();
boolean bottom = utp.getBottomLod() > utp.getNewLod();
IndexBuffer idxB;
if (useVariableLod)
idxB = geomap.writeIndexArrayLodVariable(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()), totalSize);
else
idxB = geomap.writeIndexArrayLodDiff(pow, right, top, left, bottom, totalSize);
Buffer b;
if (idxB.getBuffer() instanceof IntBuffer)
b = (IntBuffer) idxB.getBuffer();
else
b = (ShortBuffer) idxB.getBuffer();
utp.setNewIndexBuffer(b);
}
}
Aggregations