Search in sources :

Example 96 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class TestWalkingChar 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));
    terrainPhysicsNode = new RigidBodyControl(CollisionShapeFactory.createMeshShape(terrain), 0);
    terrain.addControl(terrainPhysicsNode);
    rootNode.attachChild(terrain);
    getPhysicsSpace().add(terrainPhysicsNode);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) Vector3f(com.jme3.math.Vector3f) 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 97 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class TestMousePick method makeCube.

/** A cube object for target practice */
protected Geometry makeCube(String name, float x, float y, float z) {
    Box box = new Box(1, 1, 1);
    Geometry cube = new Geometry(name, box);
    cube.setLocalTranslation(x, y, z);
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.randomColor());
    cube.setMaterial(mat1);
    return cube;
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 98 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class TestMousePick method makeFloor.

/** A floor to show that the "shot" can go through several objects. */
protected Geometry makeFloor() {
    Box box = new Box(15, .2f, 15);
    Geometry floor = new Geometry("the Floor", box);
    floor.setLocalTranslation(0, -4, -5);
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.Gray);
    floor.setMaterial(mat1);
    return floor;
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 99 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class TestWalkingChar method setupFilter.

private void setupFilter() {
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Objects);
    fpp.addFilter(bloom);
    viewPort.addProcessor(fpp);
}
Also used : FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 100 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class FbxImage method createImage.

private Image createImage() {
    AssetManager assetManager = scene.assetManager;
    Image image = null;
    if (filename != null) {
        // Try load by absolute path
        File file = new File(filename);
        if (file.exists() && file.isFile()) {
            File dir = new File(file.getParent());
            String locatorPath = dir.getAbsolutePath();
            Texture tex = null;
            try {
                assetManager.registerLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
                tex = assetManager.loadTexture(file.getName());
            } catch (Exception e) {
            } finally {
                assetManager.unregisterLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null && relativeFilename != null) {
        // Try load by relative path
        File dir = new File(scene.sceneFolderName);
        String locatorPath = dir.getAbsolutePath();
        Texture tex = null;
        try {
            assetManager.registerLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
            tex = assetManager.loadTexture(relativeFilename);
        } catch (Exception e) {
        } finally {
            assetManager.unregisterLocator(locatorPath, com.jme3.asset.plugins.FileLocator.class);
        }
        if (tex != null)
            image = tex.getImage();
    }
    if (image == null && content != null) {
        // Try load from content
        String filename = null;
        if (this.filename != null)
            filename = new File(this.filename).getName();
        if (filename != null && this.relativeFilename != null)
            filename = this.relativeFilename;
        // Filename is required to aquire asset loader by extension
        if (filename != null) {
            String locatorPath = scene.sceneFilename;
            // Unique path
            filename = scene.sceneFilename + File.separatorChar + filename;
            Texture tex = null;
            try {
                assetManager.registerLocator(locatorPath, ContentTextureLocator.class);
                tex = assetManager.loadTexture(new ContentTextureKey(filename, content));
            } catch (Exception e) {
            } finally {
                assetManager.unregisterLocator(locatorPath, ContentTextureLocator.class);
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null) {
        // Try to load from files near
        if (relativeFilename != null) {
            String[] split = relativeFilename.split("[\\\\/]");
            String filename = split[split.length - 1];
            Texture tex = null;
            try {
                tex = assetManager.loadTexture(new ContentTextureKey(scene.currentAssetInfo.getKey().getFolder() + filename, content));
            } catch (Exception e) {
            }
            if (tex != null)
                image = tex.getImage();
        }
    }
    if (image == null)
        return new Image(Image.Format.RGB8, 1, 1, BufferUtils.createByteBuffer((int) ((long) 1 * (long) 1 * (long) Image.Format.RGB8.getBitsPerPixel() / 8L)), ColorSpace.Linear);
    return image;
}
Also used : AssetManager(com.jme3.asset.AssetManager) ContentTextureKey(com.jme3.scene.plugins.fbx.ContentTextureKey) Image(com.jme3.texture.Image) File(java.io.File) Texture(com.jme3.texture.Texture)

Aggregations

Material (com.jme3.material.Material)213 Geometry (com.jme3.scene.Geometry)138 Vector3f (com.jme3.math.Vector3f)137 Box (com.jme3.scene.shape.Box)73 Texture (com.jme3.texture.Texture)73 DirectionalLight (com.jme3.light.DirectionalLight)66 Node (com.jme3.scene.Node)52 Sphere (com.jme3.scene.shape.Sphere)47 Quaternion (com.jme3.math.Quaternion)46 Spatial (com.jme3.scene.Spatial)43 FilterPostProcessor (com.jme3.post.FilterPostProcessor)38 ColorRGBA (com.jme3.math.ColorRGBA)37 KeyTrigger (com.jme3.input.controls.KeyTrigger)31 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)27 BulletAppState (com.jme3.bullet.BulletAppState)26 Quad (com.jme3.scene.shape.Quad)23 TextureKey (com.jme3.asset.TextureKey)22 ActionListener (com.jme3.input.controls.ActionListener)21 AmbientLight (com.jme3.light.AmbientLight)20 Texture2D (com.jme3.texture.Texture2D)20