Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests and refactored code for the Terrain package - Bas de Böck & Alexander Grooff #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
619 changes: 619 additions & 0 deletions Test Results - TerrainQuadTest.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 01 20:04:11 EST 2014
#Wed Mar 16 12:05:41 CET 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
15 changes: 8 additions & 7 deletions jme3-core/src/main/resources/com/jme3/system/version.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# THIS IS AN AUTO-GENERATED FILE..
# DO NOT MODIFY!
build.date=1900-01-01
git.revision=0
git.branch=unknown
git.hash=
git.hash.short=
git.tag=
name.full=jMonkeyEngine 3.1.0-UNKNOWN
build.date=2016-03-16
git.revision=5475
git.branch=refactorings
git.hash=10947e8b5096f6d7e2bf0e327faa43b275adeb34
git.hash.short=10947e8
git.tag=null
name.full=jMonkeyEngine 3.1-refactorings-5475
version.full=3.1-refactorings-5475
version.number=3.1.0
version.tag=SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ public void simpleInitApp() {
*/
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f)); // patch size, and a multiplier
terrain.addControl(control);
terrain.setMaterial(matRock);
terrain.setLocalTranslation(0, -100, 0);
terrain.setLocalScale(2f, 0.5f, 2f);
rootNode.attachChild(terrain);


DirectionalLight light = new DirectionalLight();
light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
Expand All @@ -187,6 +188,7 @@ private void setupKeys() {
inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
inputManager.addListener(actionListener, "triPlanar");
}

private ActionListener actionListener = new ActionListener() {

public void onAction(String name, boolean pressed, float tpf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@
import com.jme3.renderer.Camera;
import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* An extension of the TerrainLodControl that handles
* multiple terrains at once. This is to be used if you
* multiple terrains at once. This is to be used if you
* have your own tiling/paging terrain system, such as
* TerrainGrid.
*
*
* @author Brent Owens
*/
public class MultiTerrainLodControl extends TerrainLodControl {

List<TerrainQuad> terrains = new ArrayList<TerrainQuad>();
private List<TerrainQuad> addedTerrains = new ArrayList<TerrainQuad>();
private List<TerrainQuad> removedTerrains = new ArrayList<TerrainQuad>();
Expand All @@ -64,7 +65,7 @@ public MultiTerrainLodControl(Camera camera) {
this.cameras = cams;
lodCalculator = new DistanceLodCalculator(65, 2.7f);
}

/**
* Add a terrain that will have its LOD handled by this control.
* It will be added next update run. You should only call this from
Expand All @@ -73,7 +74,7 @@ public MultiTerrainLodControl(Camera camera) {
public void addTerrain(TerrainQuad tq) {
addedTerrains.add(tq);
}

/**
* Add a terrain that will no longer have its LOD handled by this control.
* It will be removed next update run. You should only call this from
Expand All @@ -82,12 +83,12 @@ public void addTerrain(TerrainQuad tq) {
public void removeTerrain(TerrainQuad tq) {
removedTerrains.add(tq);
}

@Override
protected UpdateLOD getLodThread(List<Vector3f> locations, LodCalculator lodCalculator) {
return new UpdateMultiLOD(locations, lodCalculator);
}

@Override
protected void prepareTerrain() {
if (!addedTerrains.isEmpty()) {
Expand All @@ -97,57 +98,57 @@ protected void prepareTerrain() {
}
addedTerrains.clear();
}

if (!removedTerrains.isEmpty()) {
terrains.removeAll(removedTerrains);
removedTerrains.clear();
}

for (TerrainQuad terrain : terrains)
terrain.cacheTerrainTransforms();// cache the terrain's world transforms so they can be accessed on the separate thread safely
}

/**
* Overrides the parent UpdateLOD runnable to process
* multiple terrains.
*/
protected class UpdateMultiLOD extends UpdateLOD {


protected UpdateMultiLOD(List<Vector3f> camLocations, LodCalculator lodCalculator) {
super(camLocations, lodCalculator);
}

@Override
public HashMap<String, UpdatedTerrainPatch> call() throws Exception {

setLodCalcRunning(true);
HashMap<String,UpdatedTerrainPatch> updated = new HashMap<String,UpdatedTerrainPatch>();

HashMap<String, UpdatedTerrainPatch> updated = new HashMap<String, UpdatedTerrainPatch>();

for (TerrainQuad terrainQuad : terrains) {
// go through each patch and calculate its LOD based on camera distance
terrainQuad.calculateLod(camLocations, updated, lodCalculator); // 'updated' gets populated here
terrainQuad.hasLodChanged(camLocations, updated, lodCalculator); // 'updated' gets populated here
}

for (TerrainQuad terrainQuad : terrains) {
// then calculate the neighbour LOD values for seaming
terrainQuad.findNeighboursLod(updated);
}

for (TerrainQuad terrainQuad : terrains) {
// check neighbour quads that need their edges seamed
terrainQuad.fixEdges(updated);
}

for (TerrainQuad terrainQuad : terrains) {
// perform the edge seaming, if it requires it
terrainQuad.reIndexPages(updated, lodCalculator.usesVariableLod());
}

//setUpdateQuadLODs(updated); // set back to main ogl thread
setLodCalcRunning(false);

return updated;
}
}
Expand Down
Loading