use of com.jme3.terrain.geomipmap.TerrainLodControl in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestAndroid method simpleInitApp.
@Override
public void simpleInitApp() {
setupKeys();
// First, we load up our textures and the heightmap texture for the terrain
// TERRAIN TEXTURE material
matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
matRock.setBoolean("useTriPlanarMapping", false);
// ALPHA map (for splat textures)
matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
// HEIGHTMAP image (for the terrain heightmap)
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains128.png");
// GRASS texture
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex1", grass);
matRock.setFloat("Tex1Scale", grassScale);
// DIRT texture
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex2", dirt);
matRock.setFloat("Tex2Scale", dirtScale);
// ROCK texture
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex3", rock);
matRock.setFloat("Tex3Scale", rockScale);
// WIREFRAME material
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
// CREATE HEIGHTMAP
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
heightmap.load();
} catch (Exception e) {
e.printStackTrace();
}
/*
* Here we create the actual terrain. The tiles will be 33x33, and the total size of the
* terrain will be 129x129. It uses the heightmap we created to generate the height values.
*/
terrain = new TerrainQuad("terrain", 33, 129, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
// patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(33, 2.7f));
terrain.addControl(control);
terrain.setMaterial(matRock);
terrain.setLocalTranslation(0, -100, 0);
terrain.setLocalScale(8f, 0.5f, 8f);
rootNode.attachChild(terrain);
DirectionalLight light = new DirectionalLight();
light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
cam.setLocation(new Vector3f(0, 10, -10));
cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
}
use of com.jme3.terrain.geomipmap.TerrainLodControl in project jmonkeyengine by jMonkeyEngine.
the class TerrainGridSerializationTest method simpleInitApp.
@Override
public void simpleInitApp() {
File file = new File("TerrainGridTestData.zip");
if (!file.exists()) {
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/TerrainGridTestData.zip", HttpZipLocator.class);
} else {
assetManager.registerLocator("TerrainGridTestData.zip", ZipLocator.class);
}
this.flyCam.setMoveSpeed(100f);
ScreenshotAppState state = new ScreenshotAppState();
this.stateManager.attach(state);
this.terrain = (TerrainGrid) assetManager.loadModel("TerrainGrid/TerrainGrid.j3o");
this.rootNode.attachChild(this.terrain);
TerrainLodControl control = new TerrainGridLodControl(this.terrain, getCamera());
// patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
this.terrain.addControl(control);
final BulletAppState bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
this.getCamera().setLocation(new Vector3f(0, 256, 0));
this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
if (usePhysics) {
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1);
player3 = new CharacterControl(capsuleShape, 0.5f);
player3.setJumpSpeed(20);
player3.setFallSpeed(10);
player3.setGravity(10);
player3.setPhysicsLocation(new Vector3f(cam.getLocation().x, 256, cam.getLocation().z));
bulletAppState.getPhysicsSpace().add(player3);
terrain.addListener(new TerrainGridListener() {
public void gridMoved(Vector3f newCenter) {
}
public void tileAttached(Vector3f cell, TerrainQuad quad) {
//workaround for bugged test j3o's
while (quad.getControl(RigidBodyControl.class) != null) {
quad.removeControl(RigidBodyControl.class);
}
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
bulletAppState.getPhysicsSpace().add(quad);
}
public void tileDetached(Vector3f cell, TerrainQuad quad) {
if (quad.getControl(RigidBodyControl.class) != null) {
bulletAppState.getPhysicsSpace().remove(quad);
quad.removeControl(RigidBodyControl.class);
}
}
});
}
this.initKeys();
}
use of com.jme3.terrain.geomipmap.TerrainLodControl in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestReadWrite method loadTerrain.
private void loadTerrain() {
FileInputStream fis = null;
try {
long start = System.currentTimeMillis();
// remove the existing terrain and detach it from the root node.
if (terrain != null) {
Node existingTerrain = (Node) terrain;
existingTerrain.removeFromParent();
existingTerrain.removeControl(TerrainLodControl.class);
existingTerrain.detachAllChildren();
terrain = null;
}
// import the saved terrain, and attach it back to the root node
File f = new File("terrainsave.jme");
fis = new FileInputStream(f);
BinaryImporter imp = BinaryImporter.getInstance();
imp.setAssetManager(assetManager);
terrain = (TerrainQuad) imp.load(new BufferedInputStream(fis));
rootNode.attachChild((Node) terrain);
float duration = (System.currentTimeMillis() - start) / 1000.0f;
System.out.println("Load took " + duration + " seconds");
// now we have to add back the camera to the LOD control
TerrainLodControl lodControl = ((Node) terrain).getControl(TerrainLodControl.class);
if (lodControl != null)
lodControl.setCamera(getCamera());
} catch (IOException ex) {
Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException ex) {
Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
use of com.jme3.terrain.geomipmap.TerrainLodControl in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestReadWrite method createMap.
private void createMap() {
matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setBoolean("WardIso", true);
// ALPHA map (for splat textures)
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
// HEIGHTMAP image (for the terrain heightmap)
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
// GRASS texture
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap", grass);
matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
// DIRT texture
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_1", dirt);
matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);
// ROCK texture
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_2", rock);
matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
normalMap0.setWrap(WrapMode.Repeat);
Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
normalMap1.setWrap(WrapMode.Repeat);
Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
normalMap2.setWrap(WrapMode.Repeat);
matTerrain.setTexture("NormalMap", normalMap0);
matTerrain.setTexture("NormalMap_1", normalMap2);
matTerrain.setTexture("NormalMap_2", normalMap2);
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
// CREATE HEIGHTMAP
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
heightmap.load();
} catch (Exception e) {
e.printStackTrace();
}
if (new File("terrainsave.jme").exists()) {
loadTerrain();
} else {
// create the terrain as normal, and give it a control for LOD management
//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
TerrainQuad terrainQuad = new TerrainQuad("terrain", 65, 129, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrainQuad, getCamera());
// patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
terrainQuad.addControl(control);
terrainQuad.setMaterial(matTerrain);
terrainQuad.setLocalTranslation(0, -100, 0);
terrainQuad.setLocalScale(4f, 0.25f, 4f);
rootNode.attachChild(terrainQuad);
this.terrain = terrainQuad;
}
DirectionalLight light = new DirectionalLight();
light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
}
use of com.jme3.terrain.geomipmap.TerrainLodControl in project jmonkeyengine by jMonkeyEngine.
the class TestSpotLightTerrain method makeTerrain.
private void makeTerrain() {
// TERRAIN TEXTURE material
matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setBoolean("WardIso", true);
// ALPHA map (for splat textures)
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.png"));
matTerrain.setTexture("AlphaMap_1", assetManager.loadTexture("Textures/Terrain/splat/alpha2.png"));
// HEIGHTMAP image (for the terrain heightmap)
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
// GRASS texture
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap", grass);
matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
// DIRT texture
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_1", dirt);
matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);
// ROCK texture
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_2", rock);
matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
// BRICK texture
Texture brick = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg");
brick.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_3", brick);
matTerrain.setFloat("DiffuseMap_3_scale", rockScale);
// RIVER ROCK texture
Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg");
riverRock.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_4", riverRock);
matTerrain.setFloat("DiffuseMap_4_scale", rockScale);
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
normalMap0.setWrap(WrapMode.Repeat);
Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
normalMap1.setWrap(WrapMode.Repeat);
Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
normalMap2.setWrap(WrapMode.Repeat);
matTerrain.setTexture("NormalMap", normalMap0);
matTerrain.setTexture("NormalMap_1", normalMap2);
matTerrain.setTexture("NormalMap_2", normalMap2);
matTerrain.setTexture("NormalMap_4", normalMap2);
// WIREFRAME material
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
createSky();
// CREATE HEIGHTMAP
AbstractHeightMap heightmap = null;
try {
//heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
heightmap.load();
} catch (Exception e) {
e.printStackTrace();
}
//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
terrain.addControl(control);
terrain.setMaterial(matTerrain);
terrain.setModelBound(new BoundingBox());
terrain.updateModelBound();
terrain.setLocalTranslation(0, -100, 0);
terrain.setLocalScale(1f, 1f, 1f);
rootNode.attachChild(terrain);
}
Aggregations