Search in sources :

Example 21 with Terrain

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

the class TestBrickWall 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 22 with Terrain

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

the class PhysicsTestHelper method createBallShooter.

/**
     * creates the necessary inputlistener and action to shoot balls from teh camera
     * @param app
     * @param rootNode
     * @param space
     */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(10);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) TextureKey(com.jme3.asset.TextureKey) ActionListener(com.jme3.input.controls.ActionListener) Material(com.jme3.material.Material) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) Texture(com.jme3.texture.Texture) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 23 with Terrain

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

the class TestFancyCar method findGeom.

//    public void setupFloor() {
//        Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
//        mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
////        mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
////        mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
//
//        Box floor = new Box(Vector3f.ZERO, 140, 1f, 140);
//        floor.scaleTextureCoordinates(new Vector2f(112.0f, 112.0f));
//        Geometry floorGeom = new Geometry("Floor", floor);
//        floorGeom.setShadowMode(ShadowMode.Receive);
//        floorGeom.setMaterial(mat);
//
//        PhysicsNode tb = new PhysicsNode(floorGeom, new MeshCollisionShape(floorGeom.getMesh()), 0);
//        tb.setLocalTranslation(new Vector3f(0f, -6, 0f));
////        tb.attachDebugShape(assetManager);
//        rootNode.attachChild(tb);
//        getPhysicsSpace().add(tb);
//    }
private Geometry findGeom(Spatial spatial, String name) {
    if (spatial instanceof Node) {
        Node node = (Node) spatial;
        for (int i = 0; i < node.getQuantity(); i++) {
            Spatial child = node.getChild(i);
            Geometry result = findGeom(child, name);
            if (result != null) {
                return result;
            }
        }
    } else if (spatial instanceof Geometry) {
        if (spatial.getName().startsWith(name)) {
            return (Geometry) spatial;
        }
    }
    return null;
}
Also used : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Example 24 with Terrain

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

the class TestHoveringTank method createTerrain.

private void createTerrain() {
    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/mountains512.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());
    TerrainLodControl control = new TerrainLodControl(terrain, cameras);
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalScale(new Vector3f(2, 2, 2));
    // unlock it so we can edit the height
    terrain.setLocked(false);
    terrain.setShadowMode(ShadowMode.CastAndReceive);
    terrain.addControl(new RigidBodyControl(0));
    rootNode.attachChild(terrain);
    getPhysicsSpace().addAll(terrain);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) ArrayList(java.util.ArrayList) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) ChaseCamera(com.jme3.input.ChaseCamera) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

Example 25 with Terrain

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

the class CollisionShapeFactory method createSingleMeshShape.

/**
     * This type of collision shape is mesh-accurate and meant for immovable "world objects".
     * Examples include terrain, houses or whole shooter levels.<br>
     * Objects with "mesh" type collision shape will not collide with each other.
     */
private static MeshCollisionShape createSingleMeshShape(Geometry geom, Spatial parent) {
    Mesh mesh = geom.getMesh();
    Transform trans = getTransform(geom, parent);
    if (mesh != null && mesh.getMode() == Mesh.Mode.Triangles) {
        MeshCollisionShape mColl = new MeshCollisionShape(mesh);
        mColl.setScale(trans.getScale());
        return mColl;
    } else {
        return null;
    }
}
Also used : Transform(com.jme3.math.Transform)

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