use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestModifyHeight method createTerrain.
private void createTerrain() {
// First, we load up our textures and the heightmap texture for the terrain
// TERRAIN TEXTURE material
matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setBoolean("WardIso", true);
matTerrain.setFloat("Shininess", 0);
// ALPHA map (for splat textures)
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.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);
// HEIGHTMAP image (for the terrain heightmap)
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f);
heightmap.load();
heightmap.smooth(0.9f, 1);
} catch (Exception e) {
e.printStackTrace();
}
// CREATE THE TERRAIN
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
// patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
terrain.addControl(control);
terrain.setMaterial(matTerrain);
terrain.setLocalTranslation(0, -100, 0);
terrain.setLocalScale(2.5f, 0.5f, 2.5f);
rootNode.attachChild(terrain);
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestModifyHeight method createTerrainGrid.
private void createTerrainGrid() {
// TERRAIN TEXTURE material
matTerrain = new Material(this.assetManager, "Common/MatDefs/Terrain/HeightBasedTerrain.j3md");
// Parameters to material:
// regionXColorMap: X = 1..4 the texture that should be appliad to state X
// regionX: a Vector3f containing the following information:
// regionX.x: the start height of the region
// regionX.y: the end height of the region
// regionX.z: the texture scale for the region
// it might not be the most elegant way for storing these 3 values, but it packs the data nicely :)
// slopeColorMap: the texture to be used for cliffs, and steep mountain sites
// slopeTileFactor: the texture scale for slopes
// terrainSize: the total size of the terrain (used for scaling the texture)
// GRASS texture
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matTerrain.setTexture("region1ColorMap", grass);
matTerrain.setVector3("region1", new Vector3f(88, 200, this.grassScale));
// DIRT texture
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matTerrain.setTexture("region2ColorMap", dirt);
matTerrain.setVector3("region2", new Vector3f(0, 90, this.dirtScale));
// ROCK texture
Texture rock = assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
rock.setWrap(WrapMode.Repeat);
matTerrain.setTexture("region3ColorMap", rock);
matTerrain.setVector3("region3", new Vector3f(198, 260, this.rockScale));
matTerrain.setTexture("region4ColorMap", rock);
matTerrain.setVector3("region4", new Vector3f(198, 260, this.rockScale));
matTerrain.setTexture("slopeColorMap", rock);
matTerrain.setFloat("slopeTileFactor", 32);
matTerrain.setFloat("terrainSize", 513);
FractalSum base = new FractalSum();
base.setRoughness(0.7f);
base.setFrequency(1.0f);
base.setAmplitude(1.0f);
base.setLacunarity(2.12f);
base.setOctaves(8);
base.setScale(0.02125f);
base.addModulator(new NoiseModulator() {
@Override
public float value(float... in) {
return ShaderUtils.clamp(in[0] * 0.5f + 0.5f, 0, 1);
}
});
FilteredBasis ground = new FilteredBasis(base);
PerturbFilter perturb = new PerturbFilter();
perturb.setMagnitude(0.119f);
OptimizedErode therm = new OptimizedErode();
therm.setRadius(5);
therm.setTalus(0.011f);
SmoothFilter smooth = new SmoothFilter();
smooth.setRadius(1);
smooth.setEffect(0.7f);
IterativeFilter iterate = new IterativeFilter();
iterate.addPreFilter(perturb);
iterate.addPostFilter(smooth);
iterate.setFilter(therm);
iterate.setIterations(1);
ground.addPreFilter(iterate);
this.terrain = new TerrainGrid("terrain", 65, 257, new FractalTileLoader(ground, 256f));
terrain.setMaterial(matTerrain);
terrain.setLocalTranslation(0, 0, 0);
terrain.setLocalScale(2f, 1f, 2f);
rootNode.attachChild(this.terrain);
TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera());
this.terrain.addControl(control);
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TestSceneStress method createOctSplit.
protected Spatial createOctSplit(String name, int size, int depth) {
if (depth == 0) {
// Done splitting
Geometry geom = new Geometry(name, BOX);
totalGeometry++;
geom.setMaterial(mat);
if (random.nextFloat() < 0.01) {
RotatorControl control = new RotatorControl(random.nextFloat(), random.nextFloat(), random.nextFloat());
geom.addControl(control);
totalControls++;
}
return geom;
}
Node root = new Node(name);
totalNodes++;
int half = size / 2;
float quarter = half * 0.5f;
for (int i = 0; i < 2; i++) {
float x = i * half - quarter;
for (int j = 0; j < 2; j++) {
float y = j * half - quarter;
for (int k = 0; k < 2; k++) {
float z = k * half - quarter;
Spatial child = createOctSplit(name + "(" + i + ", " + j + ", " + k + ")", half, depth - 1);
child.setLocalTranslation(x, y, z);
root.attachChild(child);
}
}
}
return root;
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TestBatchLod method simpleInitApp.
public void simpleInitApp() {
// inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
Geometry teapot = (Geometry) teapotNode.getChild(0);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setFloat("Shininess", 16f);
mat.setBoolean("VertexLighting", true);
teapot.setMaterial(mat);
// show normals as material
//Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
flyCam.setMoveSpeed(5);
for (int y = -5; y < 5; y++) {
for (int x = -5; x < 5; x++) {
Geometry clonePot = teapot.clone();
//clonePot.setMaterial(mat);
clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
clonePot.setLocalScale(.15f);
clonePot.setMaterial(mat);
rootNode.attachChild(clonePot);
}
}
GeometryBatchFactory.optimize(rootNode, true);
LodControl control = new LodControl();
rootNode.getChild(0).addControl(control);
cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TestLodStress method simpleInitApp.
public void simpleInitApp() {
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
Geometry teapot = (Geometry) teapotNode.getChild(0);
// Sphere sph = new Sphere(16, 16, 4);
// Geometry teapot = new Geometry("teapot", sph);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setFloat("Shininess", 16f);
mat.setBoolean("VertexLighting", true);
teapot.setMaterial(mat);
for (int y = -10; y < 10; y++) {
for (int x = -10; x < 10; x++) {
Geometry clonePot = teapot.clone();
//clonePot.setMaterial(mat);
clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
clonePot.setLocalScale(.15f);
LodControl control = new LodControl();
clonePot.addControl(control);
rootNode.attachChild(clonePot);
}
}
cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
}
Aggregations