use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.
the class TestMultiPostWater method createTerrain.
private void createTerrain(Node rootNode) {
matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matRock.setBoolean("useTriPlanarMapping", false);
matRock.setBoolean("WardIso", true);
matRock.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/pools.png");
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matRock.setTexture("DiffuseMap", grass);
matRock.setFloat("DiffuseMap_0_scale", 64);
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matRock.setTexture("DiffuseMap_1", dirt);
matRock.setFloat("DiffuseMap_1_scale", 16);
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
matRock.setTexture("DiffuseMap_2", rock);
matRock.setFloat("DiffuseMap_2_scale", 128);
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);
matRock.setTexture("NormalMap", normalMap0);
matRock.setTexture("NormalMap_1", normalMap2);
matRock.setTexture("NormalMap_2", normalMap2);
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
heightmap.load();
} catch (Exception e) {
e.printStackTrace();
}
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
List<Camera> cameras = new ArrayList<Camera>();
cameras.add(getCamera());
terrain.setMaterial(matRock);
terrain.setLocalScale(new Vector3f(5, 5, 5));
terrain.setLocalTranslation(new Vector3f(0, -30, 0));
// unlock it so we can edit the height
terrain.setLocked(false);
terrain.setShadowMode(ShadowMode.Receive);
rootNode.attachChild(terrain);
}
use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestModifyHeight method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
Vector3f intersection = getWorldIntersection();
updateHintText(intersection);
if (raiseTerrain) {
if (intersection != null) {
adjustHeight(intersection, 64, tpf * 60);
}
} else if (lowerTerrain) {
if (intersection != null) {
adjustHeight(intersection, 64, -tpf * 60);
}
}
if (terrain != null && intersection != null) {
float h = terrain.getHeight(new Vector2f(intersection.x, intersection.z));
Vector3f tl = terrain.getWorldTranslation();
marker.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
markerNormal.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
Vector3f normal = terrain.getNormal(new Vector2f(intersection.x, intersection.z));
((Arrow) markerNormal.getMesh()).setArrowExtent(normal);
}
}
use of com.jme3.terrain.Terrain 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.Terrain 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.Terrain in project jmonkeyengine by jMonkeyEngine.
the class TestAbsoluteLocators method main.
public static void main(String[] args) {
AssetManager am = JmeSystem.newAssetManager();
am.registerLoader(AWTLoader.class, "jpg");
am.registerLoader(WAVLoader.class, "wav");
// register absolute locator
am.registerLocator("/", ClasspathLocator.class);
// find a sound
AudioData audio = am.loadAudio("Sound/Effects/Gun.wav");
// find a texture
Texture tex = am.loadTexture("Textures/Terrain/Pond/Pond.jpg");
if (audio == null)
throw new RuntimeException("Cannot find audio!");
else
System.out.println("Audio loaded from Sounds/Effects/Gun.wav");
if (tex == null)
throw new RuntimeException("Cannot find texture!");
else
System.out.println("Texture loaded from Textures/Terrain/Pond/Pond.jpg");
System.out.println("Success!");
}
Aggregations