trying lighting at JavaMonkeyEngine

still trying lighting..look this:

simple code with spotlight class.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MY_TUTORIAL_USING_JME_3_2_2;

import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.light.DirectionalLight;
import com.jme.light.SpotLight;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Skybox;
import com.jme.scene.shape.Box;
import com.jme.scene.state.CullState;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.MaxToJme;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.util.logging.Logger;


/**
 *
 * @author me
 */
public class Load3DandSkyBox extends SimpleGame{
    private static final Logger logger = Logger.getLogger(Load3DandSkyBox.class.getName());
    Node node;
    Skybox sky;//load sky 
    ColorRGBA LightColor = ColorRGBA.blue;
    ColorRGBA LightColor2 = ColorRGBA.yellow;
    ColorRGBA LightColor3 = ColorRGBA.orange;
    ColorRGBA LightColor4 = ColorRGBA.red;
    ColorRGBA LightColor5 = ColorRGBA.green;

    @Override
    protected void simpleInitGame() {
        display.setTitle("Load 3D and Terrain");
        lahan(); //load lahan 
        lightState.detachAll();
        Catherdal(); // the rusian building at red square
        Mosque();
        WallSkybox();
        //HighBuilding();
        setLight();
    }
    public void lahan(){
        //create box
        Box bidang = new Box("lantai", new Vector3f(), 200, 1, 200);
        bidang.setModelBound(new BoundingBox());
        bidang.updateModelBound();
        bidang.getLocalTranslation().y = -20;
        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(TextureManager.loadTexture(
                Load3DandSkyBox.class.getClassLoader().getResource(
                        "MY_TUTORIAL_USING_JME_3_2/road.jpg"), Texture.MinificationFilter.Trilinear,
                Texture.MagnificationFilter.Bilinear));
        bidang.setRenderState(ts);
        rootNode.attachChild(bidang);
    }
    public void Catherdal(){
        node = null;
        try{
            //call Max file on JMEs
            MaxToJme model = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            //model location loaded
            URL maxFile = Load3DandSkyBox.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3_2/75Cathedral-model.3DS");
            model.convert(new BufferedInputStream(maxFile.openStream()),BO);
            node = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            Quaternion temp = new Quaternion();
            //rotating model to stand
            temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
            //location model
            node.setLocalTranslation(new Vector3f(2.0f,-15,80));
            node.setLocalRotation(temp);
            node.setLocalScale(.1f);
            node.setModelBound(new BoundingBox());
            node.updateModelBound();
        }catch(Exception e){
            logger.throwing(this.getClass().toString(), "Catherdal()",e);
        }
        node.updateRenderState();
        rootNode.attachChild(node);
    }
    public void Mosque(){
        node = null;
        try{
            //call Max file on JMEs
            MaxToJme model = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            //model location loaded
            URL maxFile = Load3DandSkyBox.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3_2/84mosque-ciro.3DS");
            model.convert(new BufferedInputStream(maxFile.openStream()),BO);
            node = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            Quaternion temp = new Quaternion();
            //rotating model to stand
            temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
            //location model
            node.setLocalTranslation(new Vector3f(50.0f,-20,0));
            node.setLocalRotation(temp);
            node.setLocalScale(.1f);
            node.setModelBound(new BoundingBox());
            node.updateModelBound();
        }catch(Exception e){
            logger.throwing(this.getClass().toString(), "Mosque()",e);
        }
        node.updateRenderState();
        rootNode.attachChild(node);
    }

    public void WallSkybox(){
        sky = new Skybox("skydome", 250, 250, 250);
        //load texture for north,south,east,west,up skybox
        Texture north = TextureManager.loadTexture(Load3DandSkyBox.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3_2/north.jpg"),
        Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);
        Texture east = TextureManager.loadTexture(Load3DandSkyBox.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3_2/east.jpg"),
        Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);
        Texture south = TextureManager.loadTexture(Load3DandSkyBox.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3_2/south.jpg"),
        Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);        
        Texture up = TextureManager.loadTexture(Load3DandSkyBox.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3_2/up.jpg"),
        Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);        
        Texture west = TextureManager.loadTexture(Load3DandSkyBox.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3_2/west.jpg"),
        Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);
        Texture bottom = TextureManager.loadTexture(Load3DandSkyBox.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3_2/bottom.jpg"),
        Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);

        //setting texture
        sky.setTexture(Skybox.Face.East, east);
        sky.setTexture(Skybox.Face.North, north);
        sky.setTexture(Skybox.Face.West, west);
        sky.setTexture(Skybox.Face.Up, up);
        sky.setTexture(Skybox.Face.South, south);
        sky.setTexture(Skybox.Face.Down, bottom);

        sky.preloadTextures();
        // give you transparent skybox
        CullState cs = display.getRenderer().createCullState();
        cs.setCullFace(CullState.Face.None);
        cs.setEnabled(true);
        sky.setRenderState(cs);

//        ZBufferState zState = display.getRenderer().createZBufferState();
//        zState.setEnabled(true);
//        sky.setRenderState(zState);

//        FogState fs = display.getRenderer().createFogState();
//        fs.setEnabled(false);
//        sky.setRenderState(fs);

//        sky.setLightCombineMode(Spatial.LightCombineMode.Off);
//        sky.setCullHint(Spatial.CullHint.Never);
//        sky.setTextureCombineMode(TextureCombineMode.Replace);
        sky.updateRenderState();

//        sky.lockBounds();
//        sky.lockMeshes();

        rootNode.attachChild(sky);
        
    }
    public void setLight(){
        SpotLight LightFront = new SpotLight();
        LightFront.setDiffuse(LightColor);
        LightFront.setAmbient(LightColor);
        LightFront.setDirection(new Vector3f(1, 0.5f, 0));
        LightFront.setLocation(new Vector3f(-25, 10, 0));
        LightFront.setAngle(15);
        LightFront.setEnabled(true);

        
        SpotLight LightBack= new SpotLight();
        LightBack.setDiffuse(LightColor2);
        LightBack.setAmbient(LightColor2);
        LightBack.setDirection(new Vector3f(1, 0.5f, 0));
        LightBack.setLocation(new Vector3f(25, 60, 0));
        LightBack.setAngle(15);
        LightBack.setEnabled(true);

        SpotLight LightRight= new SpotLight();
        LightRight.setDiffuse(LightColor3);
        LightRight.setAmbient(LightColor3);
        LightRight.setDirection(new Vector3f(1, 0.5f, 0f));
        LightRight.setLocation(new Vector3f(-25, -30, 0));
        LightRight.setAngle(10);
        LightRight.setEnabled(true);

        SpotLight LightLeft= new SpotLight();
        LightLeft.setDiffuse(LightColor4);
        LightLeft.setAmbient(LightColor4);
        LightLeft.setDirection(new Vector3f(25, 15f, 3f));
        LightLeft.setLocation(new Vector3f(-40,-55,20));
        LightLeft.setAngle(10);
        //LightLeft.setLinear(tpf);dw
        LightLeft.setEnabled(true);
//LightLeft.setDirection(new Vector3f(1, 1.5f, -0.5f));
//        LightLeft.setLocation(new Vector3f(20, -20, 25));



        SpotLight Lightbehind= new SpotLight();
        Lightbehind.setDiffuse(LightColor5);
        Lightbehind.setAmbient(LightColor5);      
        //Lightbehind.setDirection(new Vector3f(10f, 10f,10f));
        Lightbehind.setDirection(new Vector3f(30, 25f, 3f));
        Lightbehind.setLocation(new Vector3f(-40,-55,-50));
        Lightbehind.setAngle(10);
        //LightLeft.setLinear(tpf);
        Lightbehind.setEnabled(true);



        lightState.attach(LightFront);//biru
        lightState.attach(LightBack);
        lightState.attach(LightRight);
        lightState.attach(LightLeft);//merah
        lightState.attach(Lightbehind);//hijau

        //lightState.attach(dr);
    }


    public static void main(String[] args){
        Load3DandSkyBox s = new Load3DandSkyBox();
        s.setConfigShowMode(ConfigShowMode.AlwaysShow);
        s.start();
    }
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s