Material Color Shiny in jme3 - Java Game

Java examples for Game:JME3

Description

Material Color Shiny in jme3

Demo Code

package material;

import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;

/**//from ww w.ja  v a  2s  .c  om
 * test
 *
 * @author normenhansen
 */
public class MaterialColorShiny extends SimpleApplication {

    public static void main(String[] args) {
        MaterialColorShiny app = new MaterialColorShiny();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(1, 0, -2));
        sun.setColor(ColorRGBA.White);
        rootNode.addLight(sun);
        AmbientLight ambient = new AmbientLight();
        ambient.setColor(ColorRGBA.White);
        rootNode.addLight(ambient);
        Sphere sphereMesh = new Sphere(32, 32, 1f);
        Geometry sphere1Geo = new Geometry("rough sphere", sphereMesh);
        Material sphere1Mat = new Material(assetManager,
                "Common/MatDefs/Light/Lighting.j3md");
        sphere1Mat.setBoolean("UseMaterialColors", true);
        sphere1Mat.setColor("Ambient", ColorRGBA.Gray);
        sphere1Mat.setColor("Diffuse", ColorRGBA.Cyan);
        sphere1Mat.setColor("Specular", ColorRGBA.White);
        sphere1Mat.setFloat("Shininess", 28f); // [1,128]
        sphere1Geo.setMaterial(sphere1Mat);
        sphere1Geo.move(-2.5f, 0, 0);
        rootNode.attachChild(sphere1Geo);
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}

Related Tutorials