update: removed tileLoaded from TerrainGridListener, one should use tileAttached and tileDetached instead.
updated the tests as well git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7849 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
bf72c7975b
commit
026abb5a74
@ -87,11 +87,7 @@ public class TerrainGrid extends TerrainQuad {
|
|||||||
// create the new Quad since it doesn't exist
|
// create the new Quad since it doesn't exist
|
||||||
HeightMap heightMapAt = heightMapGrid.getHeightMapAt(temp);
|
HeightMap heightMapAt = heightMapGrid.getHeightMapAt(temp);
|
||||||
q = new TerrainQuad(getName() + "Quad" + temp, patchSize, quadSize, totalSize, heightMapAt == null ? null : heightMapAt.getHeightMap(), lodCalculatorFactory);
|
q = new TerrainQuad(getName() + "Quad" + temp, patchSize, quadSize, totalSize, heightMapAt == null ? null : heightMapAt.getHeightMap(), lodCalculatorFactory);
|
||||||
Material mat = material.clone();
|
q.setMaterial(material.clone());
|
||||||
for (TerrainGridListener l : listeners.values()) {
|
|
||||||
mat = l.tileLoaded(mat, temp);
|
|
||||||
}
|
|
||||||
q.setMaterial(mat);
|
|
||||||
log.log(Level.FINE, "Loaded TerrainQuad {0}", q.getName());
|
log.log(Level.FINE, "Loaded TerrainQuad {0}", q.getName());
|
||||||
}
|
}
|
||||||
cache.put(temp, q);
|
cache.put(temp, q);
|
||||||
|
|||||||
@ -42,8 +42,6 @@ public interface TerrainGridListener {
|
|||||||
|
|
||||||
public void gridMoved(Vector3f newCenter);
|
public void gridMoved(Vector3f newCenter);
|
||||||
|
|
||||||
public Material tileLoaded(Material material, Vector3f cell);
|
|
||||||
|
|
||||||
public void tileAttached( Vector3f cell, TerrainQuad quad );
|
public void tileAttached( Vector3f cell, TerrainQuad quad );
|
||||||
|
|
||||||
public void tileDetached( Vector3f cell, TerrainQuad quad );
|
public void tileDetached( Vector3f cell, TerrainQuad quad );
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public class TerrainFractalGridTest extends SimpleApplication {
|
|||||||
private float grassScale = 64;
|
private float grassScale = 64;
|
||||||
private float dirtScale = 16;
|
private float dirtScale = 16;
|
||||||
private float rockScale = 128;
|
private float rockScale = 128;
|
||||||
private boolean usePhysics = true;
|
private boolean usePhysics = false;
|
||||||
private boolean physicsAdded = false;
|
private boolean physicsAdded = false;
|
||||||
|
|
||||||
public static void main(final String[] args) {
|
public static void main(final String[] args) {
|
||||||
@ -136,7 +136,7 @@ public class TerrainFractalGridTest extends SimpleApplication {
|
|||||||
|
|
||||||
ground.addPreFilter(this.iterate);
|
ground.addPreFilter(this.iterate);
|
||||||
|
|
||||||
this.terrain = new TerrainGrid("terrain", 65, 257, new FractalHeightMapGrid(ground, null, 256f));
|
this.terrain = new TerrainGrid("terrain", 33, 129, new FractalHeightMapGrid(ground, null, 256f));
|
||||||
|
|
||||||
this.terrain.setMaterial(this.mat_terrain);
|
this.terrain.setMaterial(this.mat_terrain);
|
||||||
this.terrain.setLocalTranslation(0, 0, 0);
|
this.terrain.setLocalTranslation(0, 0, 0);
|
||||||
|
|||||||
@ -15,14 +15,18 @@ import com.jme3.bullet.control.RigidBodyControl;
|
|||||||
import com.jme3.input.KeyInput;
|
import com.jme3.input.KeyInput;
|
||||||
import com.jme3.input.controls.ActionListener;
|
import com.jme3.input.controls.ActionListener;
|
||||||
import com.jme3.input.controls.KeyTrigger;
|
import com.jme3.input.controls.KeyTrigger;
|
||||||
|
import com.jme3.light.AmbientLight;
|
||||||
|
import com.jme3.light.DirectionalLight;
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.renderer.Camera;
|
import com.jme3.renderer.Camera;
|
||||||
|
import com.jme3.shader.VarType;
|
||||||
import com.jme3.terrain.geomipmap.TerrainGrid;
|
import com.jme3.terrain.geomipmap.TerrainGrid;
|
||||||
import com.jme3.terrain.geomipmap.TerrainGridListener;
|
import com.jme3.terrain.geomipmap.TerrainGridListener;
|
||||||
import com.jme3.terrain.geomipmap.TerrainLodControl;
|
import com.jme3.terrain.geomipmap.TerrainLodControl;
|
||||||
import com.jme3.terrain.geomipmap.TerrainQuad;
|
import com.jme3.terrain.geomipmap.TerrainQuad;
|
||||||
|
import com.jme3.terrain.heightmap.FractalHeightMapGrid;
|
||||||
import com.jme3.terrain.heightmap.ImageBasedHeightMapGrid;
|
import com.jme3.terrain.heightmap.ImageBasedHeightMapGrid;
|
||||||
import com.jme3.terrain.heightmap.Namer;
|
import com.jme3.terrain.heightmap.Namer;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -60,10 +64,19 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
|
DirectionalLight sun = new DirectionalLight();
|
||||||
|
sun.setColor(ColorRGBA.White);
|
||||||
|
sun.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
|
||||||
|
rootNode.addLight(sun);
|
||||||
|
|
||||||
|
AmbientLight al = new AmbientLight();
|
||||||
|
al.setColor(ColorRGBA.White.mult(1.3f));
|
||||||
|
rootNode.addLight(al);
|
||||||
|
|
||||||
File file = new File("mountains.zip");
|
File file = new File("mountains.zip");
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/mountains.zip", HttpZipLocator.class);
|
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/mountains.zip", HttpZipLocator.class);
|
||||||
}else{
|
} else {
|
||||||
assetManager.registerLocator("mountains.zip", ZipLocator.class);
|
assetManager.registerLocator("mountains.zip", ZipLocator.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,26 +85,26 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
|
|||||||
this.stateManager.attach(state);
|
this.stateManager.attach(state);
|
||||||
|
|
||||||
// TERRAIN TEXTURE material
|
// TERRAIN TEXTURE material
|
||||||
matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
|
matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
|
||||||
matRock.setBoolean("useTriPlanarMapping", false);
|
matRock.setBoolean("useTriPlanarMapping", false);
|
||||||
|
|
||||||
// GRASS texture
|
// GRASS texture
|
||||||
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
|
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
|
||||||
grass.setWrap(WrapMode.Repeat);
|
grass.setWrap(WrapMode.Repeat);
|
||||||
matRock.setTexture("Tex1", grass);
|
matRock.setTexture("DiffuseMap", grass);
|
||||||
matRock.setFloat("Tex1Scale", grassScale);
|
matRock.setFloat("DiffuseMap_0_scale", grassScale);
|
||||||
|
|
||||||
// DIRT texture
|
// DIRT texture
|
||||||
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
|
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
|
||||||
dirt.setWrap(WrapMode.Repeat);
|
dirt.setWrap(WrapMode.Repeat);
|
||||||
matRock.setTexture("Tex2", dirt);
|
matRock.setTexture("DiffuseMap_1", dirt);
|
||||||
matRock.setFloat("Tex2Scale", dirtScale);
|
matRock.setFloat("DiffuseMap_1_scale", dirtScale);
|
||||||
|
|
||||||
// ROCK texture
|
// ROCK texture
|
||||||
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
|
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
|
||||||
rock.setWrap(WrapMode.Repeat);
|
rock.setWrap(WrapMode.Repeat);
|
||||||
matRock.setTexture("Tex3", rock);
|
matRock.setTexture("DiffuseMap_2", rock);
|
||||||
matRock.setFloat("Tex3Scale", rockScale);
|
matRock.setFloat("DiffuseMap_2_scale", rockScale);
|
||||||
|
|
||||||
// WIREFRAME material
|
// WIREFRAME material
|
||||||
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
@ -134,11 +147,7 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
|
|||||||
|
|
||||||
ground.addPreFilter(this.iterate);
|
ground.addPreFilter(this.iterate);
|
||||||
|
|
||||||
this.terrain = new TerrainGrid("terrain", 65, 1025, new ImageBasedHeightMapGrid(assetManager, new Namer() {
|
this.terrain = new TerrainGrid("terrain", 33, 257, new FractalHeightMapGrid(ground, null, 256));
|
||||||
public String getName(int x, int y) {
|
|
||||||
return "Scenes/TerrainAlphaTest/terrain_" + x + "_" + y + ".png";
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
this.terrain.setMaterial(this.matRock);
|
this.terrain.setMaterial(this.matRock);
|
||||||
|
|
||||||
this.terrain.setLocalTranslation(0, 0, 0);
|
this.terrain.setLocalTranslation(0, 0, 0);
|
||||||
@ -169,27 +178,32 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
|
|||||||
|
|
||||||
bulletAppState.getPhysicsSpace().add(player3);
|
bulletAppState.getPhysicsSpace().add(player3);
|
||||||
|
|
||||||
terrain.addListener("physicsStartListener", new TerrainGridListener() {
|
}
|
||||||
|
terrain.addListener("physicsStartListener", new TerrainGridListener() {
|
||||||
|
|
||||||
public void gridMoved(Vector3f newCenter) {
|
public void gridMoved(Vector3f newCenter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material tileLoaded(Material material, Vector3f cell) {
|
public Material tileLoaded(Material material, Vector3f cell) {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tileAttached(Vector3f cell, TerrainQuad quad) {
|
public void tileAttached(Vector3f cell, TerrainQuad quad) {
|
||||||
|
Texture alpha = assetManager.loadTexture("Scenes/TerrainAlphaTest/alphamap_" + Math.abs((int) (cell.x % 2)) * 512 + "_" + Math.abs((int) (cell.y % 2) * 512) + ".png");
|
||||||
|
quad.getMaterial().setTexture("AlphaMap", alpha);
|
||||||
|
if (usePhysics) {
|
||||||
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
|
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
|
||||||
bulletAppState.getPhysicsSpace().add(quad);
|
bulletAppState.getPhysicsSpace().add(quad);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void tileDetached(Vector3f cell, TerrainQuad quad) {
|
public void tileDetached(Vector3f cell, TerrainQuad quad) {
|
||||||
|
if (usePhysics) {
|
||||||
bulletAppState.getPhysicsSpace().remove(quad);
|
bulletAppState.getPhysicsSpace().remove(quad);
|
||||||
quad.removeControl(RigidBodyControl.class);
|
quad.removeControl(RigidBodyControl.class);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
this.terrain.initialize(cam.getLocation());
|
this.terrain.initialize(cam.getLocation());
|
||||||
this.initKeys();
|
this.initKeys();
|
||||||
}
|
}
|
||||||
@ -207,7 +221,6 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
|
|||||||
this.inputManager.addListener(this.actionListener, "Downs");
|
this.inputManager.addListener(this.actionListener, "Downs");
|
||||||
this.inputManager.addListener(this.actionListener, "Jumps");
|
this.inputManager.addListener(this.actionListener, "Jumps");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean left;
|
private boolean left;
|
||||||
private boolean right;
|
private boolean right;
|
||||||
private boolean up;
|
private boolean up;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user