Material Color in jme3 - Java Game

Java examples for Game:JME3

Description

Material Color 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;

/**/*  w  ww.j  a v a 2 s  . c  o m*/
 * test
 *
 * @author normenhansen
 */
public class MaterialColor extends SimpleApplication {

    public static void main(String[] args) {
        MaterialColor app = new MaterialColor();
        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 sphereGeo = new Geometry("Colored lit sphere", sphereMesh);
        Material sphereMat = new Material(assetManager,
                "Common/MatDefs/Light/Lighting.j3md");
        sphereMat.setBoolean("UseMaterialColors", true);
        sphereMat.setColor("Diffuse", ColorRGBA.Blue);
        sphereMat.setColor("Ambient", ColorRGBA.Gray);
        sphereGeo.setMaterial(sphereMat);
        rootNode.attachChild(sphereGeo);
    }

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

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

Related Tutorials