|
@@ -22,7 +22,6 @@ package jme3test.helloworld;
|
|
|
|
|
|
import com.jme3.app.SimpleApplication;
|
|
import com.jme3.app.SimpleApplication;
|
|
import com.jme3.material.Material;
|
|
import com.jme3.material.Material;
|
|
-import com.jme3.renderer.Camera;
|
|
|
|
import com.jme3.terrain.geomipmap.TerrainLodControl;
|
|
import com.jme3.terrain.geomipmap.TerrainLodControl;
|
|
import com.jme3.terrain.heightmap.AbstractHeightMap;
|
|
import com.jme3.terrain.heightmap.AbstractHeightMap;
|
|
import com.jme3.terrain.geomipmap.TerrainQuad;
|
|
import com.jme3.terrain.geomipmap.TerrainQuad;
|
|
@@ -31,16 +30,11 @@ import com.jme3.terrain.heightmap.HillHeightMap; // for exercise 2
|
|
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
|
|
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
|
|
import com.jme3.texture.Texture;
|
|
import com.jme3.texture.Texture;
|
|
import com.jme3.texture.Texture.WrapMode;
|
|
import com.jme3.texture.Texture.WrapMode;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
|
/** Sample 10 - How to create fast-rendering terrains from heightmaps,
|
|
/** Sample 10 - How to create fast-rendering terrains from heightmaps,
|
|
and how to use texture splatting to make the terrain look good. */
|
|
and how to use texture splatting to make the terrain look good. */
|
|
public class HelloTerrain extends SimpleApplication {
|
|
public class HelloTerrain extends SimpleApplication {
|
|
|
|
|
|
- private TerrainQuad terrain;
|
|
|
|
- Material mat_terrain;
|
|
|
|
-
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
HelloTerrain app = new HelloTerrain();
|
|
HelloTerrain app = new HelloTerrain();
|
|
app.start();
|
|
app.start();
|
|
@@ -51,7 +45,7 @@ public class HelloTerrain extends SimpleApplication {
|
|
flyCam.setMoveSpeed(50);
|
|
flyCam.setMoveSpeed(50);
|
|
|
|
|
|
/** 1. Create terrain material and load four textures into it. */
|
|
/** 1. Create terrain material and load four textures into it. */
|
|
- mat_terrain = new Material(assetManager,
|
|
|
|
|
|
+ Material mat_terrain = new Material(assetManager,
|
|
"Common/MatDefs/Terrain/Terrain.j3md");
|
|
"Common/MatDefs/Terrain/Terrain.j3md");
|
|
|
|
|
|
/** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
|
|
/** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
|
|
@@ -79,11 +73,21 @@ public class HelloTerrain extends SimpleApplication {
|
|
mat_terrain.setTexture("Tex3", rock);
|
|
mat_terrain.setTexture("Tex3", rock);
|
|
mat_terrain.setFloat("Tex3Scale", 128f);
|
|
mat_terrain.setFloat("Tex3Scale", 128f);
|
|
|
|
|
|
- /** 2. Create the height map */
|
|
|
|
|
|
+ /* 2.a Create a custom height map from an image */
|
|
AbstractHeightMap heightmap = null;
|
|
AbstractHeightMap heightmap = null;
|
|
Texture heightMapImage = assetManager.loadTexture(
|
|
Texture heightMapImage = assetManager.loadTexture(
|
|
"Textures/Terrain/splat/mountains512.png");
|
|
"Textures/Terrain/splat/mountains512.png");
|
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
|
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
|
|
|
|
+
|
|
|
|
+ /* 2.b Create a random height map */
|
|
|
|
+// HillHeightMap heightmap = null;
|
|
|
|
+// HillHeightMap.NORMALIZE_RANGE = 100;
|
|
|
|
+// try {
|
|
|
|
+// heightmap = new HillHeightMap(513, 1000, 50, 100, (byte) 3);
|
|
|
|
+// } catch (Exception ex) {
|
|
|
|
+// ex.printStackTrace();
|
|
|
|
+// }
|
|
|
|
+
|
|
heightmap.load();
|
|
heightmap.load();
|
|
|
|
|
|
/** 3. We have prepared material and heightmap.
|
|
/** 3. We have prepared material and heightmap.
|
|
@@ -95,7 +99,7 @@ public class HelloTerrain extends SimpleApplication {
|
|
* 3.5) We supply the prepared heightmap itself.
|
|
* 3.5) We supply the prepared heightmap itself.
|
|
*/
|
|
*/
|
|
int patchSize = 65;
|
|
int patchSize = 65;
|
|
- terrain = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap());
|
|
|
|
|
|
+ TerrainQuad terrain = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap());
|
|
|
|
|
|
/** 4. We give the terrain its material, position & scale it, and attach it. */
|
|
/** 4. We give the terrain its material, position & scale it, and attach it. */
|
|
terrain.setMaterial(mat_terrain);
|
|
terrain.setMaterial(mat_terrain);
|
|
@@ -105,6 +109,7 @@ public class HelloTerrain extends SimpleApplication {
|
|
|
|
|
|
/** 5. The LOD (level of detail) depends on were the camera is: */
|
|
/** 5. The LOD (level of detail) depends on were the camera is: */
|
|
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
|
|
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
|
|
|
|
+ control.setLodCalculator( new DistanceLodCalculator(patchSize, 2.7f) ); // patch size, and a multiplier
|
|
terrain.addControl(control);
|
|
terrain.addControl(control);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -228,8 +233,8 @@ Load four textures into this material. The first one, `Alpha`, is the alphamap t
|
|
|
|
|
|
[source,java]
|
|
[source,java]
|
|
----
|
|
----
|
|
-mat_terrain.setTexture("Alpha",
|
|
|
|
- assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
|
|
|
|
|
|
+mat_terrain.setTexture("Alpha", assetManager.loadTexture(
|
|
|
|
+ "Textures/Terrain/splat/alphamap.png"));
|
|
----
|
|
----
|
|
|
|
|
|
The three other textures are the layers that you have previously decided to paint: grass, dirt, and road. You create texture objects and load the three textures as usual. Note how you assign them to their respective texture layers (Tex1, Tex2, and Tex3) inside the Material!
|
|
The three other textures are the layers that you have previously decided to paint: grass, dirt, and road. You create texture objects and load the three textures as usual. Note how you assign them to their respective texture layers (Tex1, Tex2, and Tex3) inside the Material!
|
|
@@ -290,9 +295,9 @@ Here's the code:
|
|
|
|
|
|
[source]
|
|
[source]
|
|
----
|
|
----
|
|
-terrain = new TerrainQuad(
|
|
|
|
|
|
+TerrainQuad terrain = new TerrainQuad(
|
|
"my terrain", // name
|
|
"my terrain", // name
|
|
- 65, // tile size
|
|
|
|
|
|
+ patchSize, // tile size
|
|
513, // block size
|
|
513, // block size
|
|
heightmap.getHeightMap()); // heightmap
|
|
heightmap.getHeightMap()); // heightmap
|
|
|
|
|
|
@@ -331,6 +336,7 @@ JME3 includes an optimization that adjusts the level of detail (LOD) of the rend
|
|
----
|
|
----
|
|
|
|
|
|
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
|
|
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
|
|
|
|
+ control.setLodCalculator( new DistanceLodCalculator(patchSize, 2.7f) ); // patch size, and a multiplier
|
|
terrain.addControl(control);
|
|
terrain.addControl(control);
|
|
|
|
|
|
----
|
|
----
|