Search in sources :

Example 61 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class TestBumpModel method simpleInitApp.

@Override
public void simpleInitApp() {
    Spatial signpost = (Spatial) assetManager.loadAsset(new OgreMeshKey("Models/Sign Post/Sign Post.mesh.xml"));
    signpost.setMaterial((Material) assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m"));
    TangentBinormalGenerator.generate(signpost);
    rootNode.attachChild(signpost);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial((Material) assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(lightMdl);
    // flourescent main light
    pl = new PointLight();
    pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f));
    rootNode.addLight(pl);
    // sunset light
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.44f, 0.30f, 0.20f, 1.0f));
    rootNode.addLight(dl);
    // skylight
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.6f, -1, -0.6f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.10f, 0.22f, 0.44f, 1.0f));
    rootNode.addLight(dl);
    // white ambient light
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
    rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) OgreMeshKey(com.jme3.scene.plugins.ogre.OgreMeshKey) PointLight(com.jme3.light.PointLight)

Example 62 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class TestColoredTexture method simpleInitApp.

@Override
public void simpleInitApp() {
    Quad quadMesh = new Quad(512, 512);
    Geometry quad = new Geometry("Quad", quadMesh);
    quad.setQueueBucket(Bucket.Gui);
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
    quad.setMaterial(mat);
    guiNode.attachChildAt(quad, 0);
    nextColor = ColorRGBA.randomColor();
    prevColor = ColorRGBA.Black;
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Material(com.jme3.material.Material)

Example 63 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class TestGeometryShader method simpleInitApp.

@Override
public void simpleInitApp() {
    Mesh mesh = new Mesh();
    mesh.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer(new int[] { 1 }));
    mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(new float[] { 0, 0, 0 }));
    mesh.setMode(Mesh.Mode.Points);
    mesh.setBound(new BoundingBox(new Vector3f(0, 0, 0), 10, 10, 10));
    mesh.updateCounts();
    Geometry geometry = new Geometry("Test", mesh);
    geometry.updateGeometricState();
    geometry.setMaterial(new Material(assetManager, "Materials/Geom/SimpleGeom.j3md"));
    //geometry.getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
    //geometry.setMaterial(assetManager.loadMaterial("Materials/Geom/SimpleTess.j3md"));
    rootNode.attachChild(geometry);
    Geometry geometry1 = new Geometry("T1", new Sphere(10, 10, 1));
    geometry1.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    rootNode.attachChild(geometry1);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material)

Example 64 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class TestMatParamOverride method createBox.

private void createBox(float location, ColorRGBA color) {
    Geometry geom = new Geometry("Box", box);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", color);
    geom.setMaterial(mat);
    geom.move(location, 0, 0);
    rootNode.attachChild(geom);
}
Also used : Geometry(com.jme3.scene.Geometry) Material(com.jme3.material.Material)

Example 65 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class HelloTerrain method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(50);
    /** 1. Create terrain material and load four textures into it. */
    mat_terrain = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
    /** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
    mat_terrain.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    /** 1.2) Add GRASS texture into the red layer (Tex1). */
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    mat_terrain.setTexture("Tex1", grass);
    mat_terrain.setFloat("Tex1Scale", 64f);
    /** 1.3) Add DIRT texture into the green layer (Tex2) */
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    mat_terrain.setTexture("Tex2", dirt);
    mat_terrain.setFloat("Tex2Scale", 32f);
    /** 1.4) Add ROAD texture into the blue layer (Tex3) */
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    mat_terrain.setTexture("Tex3", rock);
    mat_terrain.setFloat("Tex3Scale", 128f);
    /** 2.a Create a custom height map from an image */
    AbstractHeightMap heightmap = null;
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
    /** 2.b Create a random height map */
    //      HillHeightMap heightmap = null;
    //      HillHeightMap.NORMALIZE_RANGE = 100;
    //      try {
    //          heightmap = new HillHeightMap(513, 1000, 50, 100, (byte) 3);
    //      } catch (Exception ex) {
    //          ex.printStackTrace();
    //      }
    heightmap.load();
    /** 3. We have prepared material and heightmap. 
     * Now we create the actual terrain:
     * 3.1) Create a TerrainQuad and name it "my terrain".
     * 3.2) A good value for terrain tiles is 64x64 -- so we supply 64+1=65.
     * 3.3) We prepared a heightmap of size 512x512 -- so we supply 512+1=513.
     * 3.4) As LOD step scale we supply Vector3f(1,1,1).
     * 3.5) We supply the prepared heightmap itself.
     */
    int patchSize = 65;
    terrain = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap());
    /** 4. We give the terrain its material, position & scale it, and attach it. */
    terrain.setMaterial(mat_terrain);
    terrain.setLocalTranslation(0, -100, 0);
    terrain.setLocalScale(2f, 1f, 2f);
    rootNode.attachChild(terrain);
    /** 5. The LOD (level of detail) depends on were the camera is: */
    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    // patch size, and a multiplier
    control.setLodCalculator(new DistanceLodCalculator(patchSize, 2.7f));
    terrain.addControl(control);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) DistanceLodCalculator(com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

Aggregations

Material (com.jme3.material.Material)310 Geometry (com.jme3.scene.Geometry)191 Vector3f (com.jme3.math.Vector3f)120 Box (com.jme3.scene.shape.Box)81 Texture (com.jme3.texture.Texture)70 Spatial (com.jme3.scene.Spatial)53 DirectionalLight (com.jme3.light.DirectionalLight)49 ColorRGBA (com.jme3.math.ColorRGBA)47 Node (com.jme3.scene.Node)47 Sphere (com.jme3.scene.shape.Sphere)44 Quaternion (com.jme3.math.Quaternion)31 Quad (com.jme3.scene.shape.Quad)26 ArrayList (java.util.ArrayList)25 Texture2D (com.jme3.texture.Texture2D)21 KeyTrigger (com.jme3.input.controls.KeyTrigger)20 Mesh (com.jme3.scene.Mesh)20 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)19 TextureKey (com.jme3.asset.TextureKey)18 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)18 ParticleEmitter (com.jme3.effect.ParticleEmitter)17