Search in sources :

Example 31 with Material

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

the class TestCustomMesh method simpleInitApp.

@Override
public void simpleInitApp() {
    Mesh m = new Mesh();
    // Vertex positions in space
    Vector3f[] vertices = new Vector3f[4];
    vertices[0] = new Vector3f(0, 0, 0);
    vertices[1] = new Vector3f(3, 0, 0);
    vertices[2] = new Vector3f(0, 3, 0);
    vertices[3] = new Vector3f(3, 3, 0);
    // Texture coordinates
    Vector2f[] texCoord = new Vector2f[4];
    texCoord[0] = new Vector2f(0, 0);
    texCoord[1] = new Vector2f(1, 0);
    texCoord[2] = new Vector2f(0, 1);
    texCoord[3] = new Vector2f(1, 1);
    // Indexes. We define the order in which mesh should be constructed
    short[] indexes = { 2, 0, 1, 1, 3, 2 };
    // Setting buffers
    m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
    m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
    m.setBuffer(Type.Index, 1, BufferUtils.createShortBuffer(indexes));
    m.updateBound();
    // *************************************************************************
    // First mesh uses one solid color
    // *************************************************************************
    // Creating a geometry, and apply a single color material to it
    Geometry geom = new Geometry("OurMesh", m);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    geom.setMaterial(mat);
    // Attaching our geometry to the root node.
    rootNode.attachChild(geom);
    // *************************************************************************
    // Second mesh uses vertex colors to color each vertex
    // *************************************************************************
    Mesh cMesh = m.clone();
    Geometry coloredMesh = new Geometry("ColoredMesh", cMesh);
    Material matVC = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matVC.setBoolean("VertexColor", true);
    //We have 4 vertices and 4 color values for each of them.
    //If you have more vertices, you need 'new float[yourVertexCount * 4]' here!
    float[] colorArray = new float[4 * 4];
    int colorIndex = 0;
    //Set custom RGBA value for each Vertex. Values range from 0.0f to 1.0f
    for (int i = 0; i < 4; i++) {
        // Red value (is increased by .2 on each next vertex here)
        colorArray[colorIndex++] = 0.1f + (.2f * i);
        // Green value (is reduced by .2 on each next vertex)
        colorArray[colorIndex++] = 0.9f - (0.2f * i);
        // Blue value (remains the same in our case)
        colorArray[colorIndex++] = 0.5f;
        // Alpha value (no transparency set here)
        colorArray[colorIndex++] = 1.0f;
    }
    // Set the color buffer
    cMesh.setBuffer(Type.Color, 4, colorArray);
    coloredMesh.setMaterial(matVC);
    // move mesh a bit so that it doesn't intersect with the first one
    coloredMesh.setLocalTranslation(4, 0, 0);
    rootNode.attachChild(coloredMesh);
    //        /** Alternatively, you can show the mesh vertixes as points
    //          * instead of coloring the faces. */
    //        cMesh.setMode(Mesh.Mode.Points);
    //        cMesh.setPointSize(10f);
    //        cMesh.updateBound();
    //        cMesh.setStatic();
    //        Geometry points = new Geometry("Points", m);
    //        points.setMaterial(mat);
    //        rootNode.attachChild(points);
    // *************************************************************************
    // Third mesh will use a wireframe shader to show wireframe
    // *************************************************************************
    Mesh wfMesh = m.clone();
    Geometry wfGeom = new Geometry("wireframeGeometry", wfMesh);
    Material matWireframe = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWireframe.setColor("Color", ColorRGBA.Green);
    matWireframe.getAdditionalRenderState().setWireframe(true);
    wfGeom.setMaterial(matWireframe);
    wfGeom.setLocalTranslation(4, 4, 0);
    rootNode.attachChild(wfGeom);
}
Also used : Geometry(com.jme3.scene.Geometry) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material)

Example 32 with Material

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

the class TestBloomAlphaThreshold method simpleInitApp.

@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -10));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
    // cam.setFrustumFar(1000);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));
    mat.setColor("GlowColor", ColorRGBA.Green);
    Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0, 0, 10);
    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);
    Geometry soil = new Geometry("soil", new Box(new Vector3f(0, -13, 550), 800, 10, 700));
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);
    Material matBox = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matBox.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
    matBox.setFloat("AlphaDiscardThreshold", 0.5f);
    Geometry box = new Geometry("box", new Box(new Vector3f(-3.5f, 10, -2), 2, 2, 2));
    box.setMaterial(matBox);
    box.setQueueBucket(RenderQueue.Bucket.Translucent);
    // box.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(box);
    DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);
    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);
    fpp = new FilterPostProcessor(assetManager);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    BloomFilter bloom = new BloomFilter(GlowMode.Objects);
    bloom.setDownSamplingFactor(2);
    bloom.setBlurScale(1.37f);
    bloom.setExposurePower(3.30f);
    bloom.setExposureCutOff(0.2f);
    bloom.setBloomIntensity(2.45f);
    BloomUI ui = new BloomUI(inputManager, bloom);
    viewPort.addProcessor(fpp);
    fpp.addFilter(bloom);
    initInputs();
}
Also used : Geometry(com.jme3.scene.Geometry) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 33 with Material

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

the class TestObjLoading method simpleInitApp.

public void simpleInitApp() {
    // create the geometry and attach it
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    // show normals as material
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teaGeom.setMaterial(mat);
    rootNode.attachChild(teaGeom);
}
Also used : Geometry(com.jme3.scene.Geometry) Material(com.jme3.material.Material)

Example 34 with Material

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

the class TestAnimBlendBug method simpleInitApp.

@Override
public void simpleInitApp() {
    inputManager.addMapping("One", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addListener(this, "One");
    flyCam.setMoveSpeed(100f);
    cam.setLocation(new Vector3f(0f, 150f, -325f));
    cam.lookAt(new Vector3f(0f, 100f, 0f), Vector3f.UNIT_Y);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
    Node model1 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    Node model2 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    //        Node model2 = model1.clone();
    model1.setLocalTranslation(-60, 0, 0);
    model2.setLocalTranslation(60, 0, 0);
    AnimControl control1 = model1.getControl(AnimControl.class);
    animNames = control1.getAnimationNames().toArray(new String[0]);
    channel1 = control1.createChannel();
    AnimControl control2 = model2.getControl(AnimControl.class);
    channel2 = control2.createChannel();
    SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton1", control1.getSkeleton());
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);
    mat.getAdditionalRenderState().setDepthTest(false);
    skeletonDebug.setMaterial(mat);
    model1.attachChild(skeletonDebug);
    skeletonDebug = new SkeletonDebugger("skeleton2", control2.getSkeleton());
    skeletonDebug.setMaterial(mat);
    model2.attachChild(skeletonDebug);
    rootNode.attachChild(model1);
    rootNode.attachChild(model2);
}
Also used : SkeletonDebugger(com.jme3.scene.debug.SkeletonDebugger) ColorRGBA(com.jme3.math.ColorRGBA) KeyTrigger(com.jme3.input.controls.KeyTrigger) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) AnimControl(com.jme3.animation.AnimControl)

Example 35 with Material

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

the class TestCylinder method simpleInitApp.

@Override
public void simpleInitApp() {
    Cylinder t = new Cylinder(20, 50, 1, 2, true);
    Geometry geom = new Geometry("Cylinder", t);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
Also used : Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) TextureKey(com.jme3.asset.TextureKey) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Aggregations

Material (com.jme3.material.Material)285 Geometry (com.jme3.scene.Geometry)165 Vector3f (com.jme3.math.Vector3f)110 Box (com.jme3.scene.shape.Box)79 Texture (com.jme3.texture.Texture)69 DirectionalLight (com.jme3.light.DirectionalLight)49 Sphere (com.jme3.scene.shape.Sphere)43 Node (com.jme3.scene.Node)39 ColorRGBA (com.jme3.math.ColorRGBA)38 Spatial (com.jme3.scene.Spatial)35 Quaternion (com.jme3.math.Quaternion)31 Quad (com.jme3.scene.shape.Quad)26 Texture2D (com.jme3.texture.Texture2D)21 KeyTrigger (com.jme3.input.controls.KeyTrigger)20 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)19 ArrayList (java.util.ArrayList)19 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)18 TextureKey (com.jme3.asset.TextureKey)17 ParticleEmitter (com.jme3.effect.ParticleEmitter)17 AmbientLight (com.jme3.light.AmbientLight)16