Search in sources :

Example 36 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TestBatchNode method simpleInitApp.

@Override
public void simpleInitApp() {
    timer = new NanoTimer();
    batch = new BatchNode("theBatchNode");
    /**
         * A cube with a color "bleeding" through transparent texture. Uses
         * Texture from jme3-test-data library!
         */
    Box boxshape4 = new Box(1f, 1f, 1f);
    cube = new Geometry("cube1", boxshape4);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    cube.setMaterial(mat);
    //        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");        
    //        mat.setColor("Diffuse", ColorRGBA.Blue);
    //        mat.setBoolean("UseMaterialColors", true);
    /**
         * A cube with a color "bleeding" through transparent texture. Uses
         * Texture from jme3-test-data library!
         */
    Box box = new Box(1f, 1f, 1f);
    cube2 = new Geometry("cube2", box);
    cube2.setMaterial(mat);
    TangentBinormalGenerator.generate(cube);
    TangentBinormalGenerator.generate(cube2);
    n = new Node("aNode");
    // n.attachChild(cube2);
    batch.attachChild(cube);
    //  batch.attachChild(cube2);
    //  batch.setMaterial(mat);
    batch.batch();
    rootNode.attachChild(batch);
    cube.setLocalTranslation(3, 0, 0);
    cube2.setLocalTranslation(0, 20, 0);
    updateBoindPoints(points);
    frustum = new WireFrustum(points);
    frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
    frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
    rootNode.attachChild(frustumMdl);
    dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White.mult(2));
    dl.setDirection(new Vector3f(1, -1, -1));
    rootNode.addLight(dl);
    flyCam.setMoveSpeed(10);
}
Also used : Geometry(com.jme3.scene.Geometry) NanoTimer(com.jme3.system.NanoTimer) WireFrustum(com.jme3.scene.debug.WireFrustum) Node(com.jme3.scene.Node) BatchNode(com.jme3.scene.BatchNode) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) BatchNode(com.jme3.scene.BatchNode)

Example 37 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TestBatchNodeCluster method simpleInitApp.

//protected
//    protected Geometry player;
@Override
public void simpleInitApp() {
    timer = new NanoTimer();
    batchNode = new SimpleBatchNode("BatchNode");
    xPosition.add(0);
    yPosition.add(0);
    zPosition.add(0);
    mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.White);
    mat1.setColor("GlowColor", ColorRGBA.Blue.mult(10));
    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.White);
    mat2.setColor("GlowColor", ColorRGBA.Red.mult(10));
    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat3.setColor("Color", ColorRGBA.White);
    mat3.setColor("GlowColor", ColorRGBA.Yellow.mult(10));
    mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat4.setColor("Color", ColorRGBA.White);
    mat4.setColor("GlowColor", ColorRGBA.Orange.mult(10));
    randomGenerator();
    //rootNode.attachChild(SkyFactory.createSky(
    //  assetManager, "Textures/SKY02.zip", false));
    inputManager.addMapping("Start Game", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addListener(al, new String[] { "Start Game" });
    cam.setLocation(new Vector3f(-34.403286f, 126.65158f, 434.791f));
    cam.setRotation(new Quaternion(0.022630932f, 0.9749435f, -0.18736298f, 0.11776358f));
    batchNode.batch();
    terrain = new Node("terrain");
    terrain.setLocalTranslation(50, 0, 50);
    terrain.attachChild(batchNode);
    flyCam.setMoveSpeed(100);
    rootNode.attachChild(terrain);
    Vector3f pos = new Vector3f(-40, 0, -40);
    batchNode.setLocalTranslation(pos);
    Arrow a = new Arrow(new Vector3f(0, 50, 0));
    Geometry g = new Geometry("a", a);
    g.setLocalTranslation(terrain.getLocalTranslation());
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.setColor("Color", ColorRGBA.Blue);
    g.setMaterial(m);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
    //        SSAOFilter ssao = new SSAOFilter(8.630104f,22.970434f,2.9299977f,0.2999997f);    
    //        fpp.addFilter(ssao);
    viewPort.addProcessor(fpp);
//   viewPort.setBackgroundColor(ColorRGBA.DarkGray);
}
Also used : Arrow(com.jme3.scene.debug.Arrow) NanoTimer(com.jme3.system.NanoTimer) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 38 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TestBatchNodeTower method initMaterial.

public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);
    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);
    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
Also used : TextureKey(com.jme3.asset.TextureKey) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 39 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class CollisionShapeFactory method createCompoundShape.

private static CompoundCollisionShape createCompoundShape(Node realRootNode, Node rootNode, CompoundCollisionShape shape, boolean meshAccurate, boolean dynamic) {
    for (Spatial spatial : rootNode.getChildren()) {
        if (spatial instanceof TerrainQuad) {
            Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
            if (bool != null && bool.booleanValue()) {
                // go to the next child in the loop
                continue;
            }
            TerrainQuad terrain = (TerrainQuad) spatial;
            Transform trans = getTransform(spatial, realRootNode);
            shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), trans.getScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix());
        } else if (spatial instanceof Node) {
            createCompoundShape(realRootNode, (Node) spatial, shape, meshAccurate, dynamic);
        } else if (spatial instanceof TerrainPatch) {
            Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
            if (bool != null && bool.booleanValue()) {
                // go to the next child in the loop
                continue;
            }
            TerrainPatch terrain = (TerrainPatch) spatial;
            Transform trans = getTransform(spatial, realRootNode);
            shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix());
        } else if (spatial instanceof Geometry) {
            Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
            if (bool != null && bool.booleanValue()) {
                // go to the next child in the loop
                continue;
            }
            if (meshAccurate) {
                CollisionShape childShape = dynamic ? createSingleDynamicMeshShape((Geometry) spatial, realRootNode) : createSingleMeshShape((Geometry) spatial, realRootNode);
                if (childShape != null) {
                    Transform trans = getTransform(spatial, realRootNode);
                    shape.addChildShape(childShape, trans.getTranslation(), trans.getRotation().toRotationMatrix());
                }
            } else {
                Transform trans = getTransform(spatial, realRootNode);
                shape.addChildShape(createSingleBoxShape(spatial, realRootNode), trans.getTranslation(), trans.getRotation().toRotationMatrix());
            }
        }
    }
    return shape;
}
Also used : ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) Transform(com.jme3.math.Transform) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) TerrainPatch(com.jme3.terrain.geomipmap.TerrainPatch)

Example 40 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class HelloAssets method simpleInitApp.

@Override
public void simpleInitApp() {
    /** Load a teapot model (OBJ file from test-data) */
    Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teapot.setMaterial(mat_default);
    rootNode.attachChild(teapot);
    /** Create a wall (Box with material and texture from test-data) */
    Box box = new Box(2.5f, 2.5f, 1.0f);
    Spatial wall = new Geometry("Box", box);
    Material mat_brick = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_brick.setTexture("ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
    wall.setMaterial(mat_brick);
    wall.setLocalTranslation(2.0f, -2.5f, 0.0f);
    rootNode.attachChild(wall);
    /** Display a line of text (default font from test-data) */
    setDisplayStatView(false);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("Hello World");
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);
    /** Load a Ninja model (OgreXML + material + texture from test_data) */
    Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    ninja.scale(0.05f, 0.05f, 0.05f);
    ninja.rotate(0.0f, -3.0f, 0.0f);
    ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
    rootNode.attachChild(ninja);
    /** You must add a light to make the model visible */
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    rootNode.addLight(sun);
}
Also used : Geometry(com.jme3.scene.Geometry) BitmapText(com.jme3.font.BitmapText) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box)

Aggregations

Material (com.jme3.material.Material)54 Vector3f (com.jme3.math.Vector3f)43 Texture (com.jme3.texture.Texture)38 Geometry (com.jme3.scene.Geometry)32 DirectionalLight (com.jme3.light.DirectionalLight)23 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)21 Box (com.jme3.scene.shape.Box)20 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)17 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)15 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)15 AmbientLight (com.jme3.light.AmbientLight)14 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)13 Node (com.jme3.scene.Node)12 Sphere (com.jme3.scene.shape.Sphere)11 Vector2f (com.jme3.math.Vector2f)10 Spatial (com.jme3.scene.Spatial)10 ArrayList (java.util.ArrayList)10 TextureKey (com.jme3.asset.TextureKey)9 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)9 ColorRGBA (com.jme3.math.ColorRGBA)8