From 026abb5a7466c8b5335cf8f7c5b0755ade04ac93 Mon Sep 17 00:00:00 2001 From: "ant..om" Date: Mon, 11 Jul 2011 09:54:03 +0000 Subject: [PATCH] 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 --- .../jme3/terrain/geomipmap/TerrainGrid.java | 6 +- .../geomipmap/TerrainGridListener.java | 2 - .../terrain/TerrainFractalGridTest.java | 4 +- .../terrain/TerrainGridAlphaMapTest.java | 63 +++++++++++-------- 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java index db6d6c508..f5e83ad23 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java @@ -87,11 +87,7 @@ public class TerrainGrid extends TerrainQuad { // create the new Quad since it doesn't exist HeightMap heightMapAt = heightMapGrid.getHeightMapAt(temp); q = new TerrainQuad(getName() + "Quad" + temp, patchSize, quadSize, totalSize, heightMapAt == null ? null : heightMapAt.getHeightMap(), lodCalculatorFactory); - Material mat = material.clone(); - for (TerrainGridListener l : listeners.values()) { - mat = l.tileLoaded(mat, temp); - } - q.setMaterial(mat); + q.setMaterial(material.clone()); log.log(Level.FINE, "Loaded TerrainQuad {0}", q.getName()); } cache.put(temp, q); diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGridListener.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGridListener.java index 593e5052a..38e0001fd 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGridListener.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGridListener.java @@ -42,8 +42,6 @@ public interface TerrainGridListener { public void gridMoved(Vector3f newCenter); - public Material tileLoaded(Material material, Vector3f cell); - public void tileAttached( Vector3f cell, TerrainQuad quad ); public void tileDetached( Vector3f cell, TerrainQuad quad ); diff --git a/engine/src/test/jme3test/terrain/TerrainFractalGridTest.java b/engine/src/test/jme3test/terrain/TerrainFractalGridTest.java index 5dd2e6373..c82798cce 100644 --- a/engine/src/test/jme3test/terrain/TerrainFractalGridTest.java +++ b/engine/src/test/jme3test/terrain/TerrainFractalGridTest.java @@ -41,7 +41,7 @@ public class TerrainFractalGridTest extends SimpleApplication { private float grassScale = 64; private float dirtScale = 16; private float rockScale = 128; - private boolean usePhysics = true; + private boolean usePhysics = false; private boolean physicsAdded = false; public static void main(final String[] args) { @@ -136,7 +136,7 @@ public class TerrainFractalGridTest extends SimpleApplication { 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.setLocalTranslation(0, 0, 0); diff --git a/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java b/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java index b6473cda5..8a0261bb0 100644 --- a/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java +++ b/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java @@ -15,14 +15,18 @@ import com.jme3.bullet.control.RigidBodyControl; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; +import com.jme3.light.AmbientLight; +import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; +import com.jme3.shader.VarType; import com.jme3.terrain.geomipmap.TerrainGrid; import com.jme3.terrain.geomipmap.TerrainGridListener; import com.jme3.terrain.geomipmap.TerrainLodControl; import com.jme3.terrain.geomipmap.TerrainQuad; +import com.jme3.terrain.heightmap.FractalHeightMapGrid; import com.jme3.terrain.heightmap.ImageBasedHeightMapGrid; import com.jme3.terrain.heightmap.Namer; import com.jme3.texture.Texture; @@ -60,10 +64,19 @@ public class TerrainGridAlphaMapTest extends SimpleApplication { @Override 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"); if (!file.exists()) { assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/mountains.zip", HttpZipLocator.class); - }else{ + } else { assetManager.registerLocator("mountains.zip", ZipLocator.class); } @@ -72,26 +85,26 @@ public class TerrainGridAlphaMapTest extends SimpleApplication { this.stateManager.attach(state); // 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); // GRASS texture Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); grass.setWrap(WrapMode.Repeat); - matRock.setTexture("Tex1", grass); - matRock.setFloat("Tex1Scale", grassScale); + matRock.setTexture("DiffuseMap", grass); + matRock.setFloat("DiffuseMap_0_scale", grassScale); // DIRT texture Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg"); dirt.setWrap(WrapMode.Repeat); - matRock.setTexture("Tex2", dirt); - matRock.setFloat("Tex2Scale", dirtScale); + matRock.setTexture("DiffuseMap_1", dirt); + matRock.setFloat("DiffuseMap_1_scale", dirtScale); // ROCK texture Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); rock.setWrap(WrapMode.Repeat); - matRock.setTexture("Tex3", rock); - matRock.setFloat("Tex3Scale", rockScale); + matRock.setTexture("DiffuseMap_2", rock); + matRock.setFloat("DiffuseMap_2_scale", rockScale); // WIREFRAME material matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -134,11 +147,7 @@ public class TerrainGridAlphaMapTest extends SimpleApplication { ground.addPreFilter(this.iterate); - this.terrain = new TerrainGrid("terrain", 65, 1025, new ImageBasedHeightMapGrid(assetManager, new Namer() { - public String getName(int x, int y) { - return "Scenes/TerrainAlphaTest/terrain_" + x + "_" + y + ".png"; - } - })); + this.terrain = new TerrainGrid("terrain", 33, 257, new FractalHeightMapGrid(ground, null, 256)); this.terrain.setMaterial(this.matRock); this.terrain.setLocalTranslation(0, 0, 0); @@ -169,27 +178,32 @@ public class TerrainGridAlphaMapTest extends SimpleApplication { 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) { - return material; - } + public Material tileLoaded(Material material, Vector3f cell) { + 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)); bulletAppState.getPhysicsSpace().add(quad); } + } - public void tileDetached(Vector3f cell, TerrainQuad quad) { + public void tileDetached(Vector3f cell, TerrainQuad quad) { + if (usePhysics) { bulletAppState.getPhysicsSpace().remove(quad); quad.removeControl(RigidBodyControl.class); } - - }); - } + } + }); this.terrain.initialize(cam.getLocation()); this.initKeys(); } @@ -207,7 +221,6 @@ public class TerrainGridAlphaMapTest extends SimpleApplication { this.inputManager.addListener(this.actionListener, "Downs"); this.inputManager.addListener(this.actionListener, "Jumps"); } - private boolean left; private boolean right; private boolean up;