Tutorial Java Monkey Engine-Load Terain- PART-2

setelah lama tidak croding karena sakitnya cintaku(Kompi)…ne gw share cara load terain di JME..langsung aja dech…

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

package MY_TUTORIAL_USING_JME;


import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.NodeHandler;
import com.jme.light.DirectionalLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.CameraNode;
import com.jme.scene.state.FogState;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jmex.terrain.TerrainPage;
import com.jmex.terrain.util.FaultFractalHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;
import javax.swing.ImageIcon;

/**
 *
 * @author 
 */
public class Tutorial_1_LoadTexture extends SimpleGame {
    private TerrainPage page;
    private CameraNode RuteCamera;

    @Override
    protected void simpleInitGame() {
         display.setTitle("TEST LOAD TEXTURE TERRAIN");
         CallTerrain();
         CameraSett();
    }

    //call all
    public static void main(String[] args){
        Tutorial_1_LoadTexture test = new Tutorial_1_LoadTexture();
        test.setConfigShowMode(ConfigShowMode.AlwaysShow);
        test.start();
    }

    private void CallTerrain() {
        rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
        //mengatur warna background
        display.getRenderer().setBackgroundColor(new ColorRGBA(0.3f, 0.2f, 0.2f, 1));

        //setting directional lighting...:
        DirectionalLight dim = new DirectionalLight();
        dim.setEnabled(true);
        dim.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        //mengatur lighting to texture
        dim.setAmbient(new ColorRGBA(0.1f, 0.3f, 0.22f, 1.0f));
        dim.setDirection(new Vector3f(1f, -0.5f, 0));

        // UNTUK MENYETTING CAHAYA
        lightState.detachAll();
        lightState.attach(dim);

        //membuat height map 
        FaultFractalHeightMap heightMap = new FaultFractalHeightMap(257, 32, 0,255, 0.75f);
        Vector3f terrainScale = new Vector3f(10, 1, 10);
        heightMap.setHeightScale(0.001f);
        page = new TerrainPage("Terrain", 33, heightMap.getSize(),
                terrainScale, heightMap.getHeightMap());

        page.setDetailTexture(1, 16);
        rootNode.attachChild(page);

        ProceduralTextureGenerator pt = new ProceduralTextureGenerator(heightMap);
        pt.addTexture(new ImageIcon(Tutorial_1_LoadTexture.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME/grass.jpg")), -128, 0, 256);
        pt.addTexture(new ImageIcon(Tutorial_1_LoadTexture.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME/dirt.jpg")), 0, 128, 255);
        pt.addTexture(new ImageIcon(Tutorial_1_LoadTexture.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME/highest.jpg")), 128, 255,384);

        pt.createTexture(512);

        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        //melakukkan pengabungan texture agar terbentuk solid soil
        Texture texture1 = TextureManager.loadTexture(pt.getImageIcon().getImage(),Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear, true);
        ts.setTexture(texture1, 0);


        Texture texture2 = TextureManager.loadTexture(Tutorial_1_LoadTexture.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME/Detail.jpg"),Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear);
        ts.setTexture(texture2, 1);
        texture2.setWrap(Texture.WrapMode.Repeat);

        texture1.setApply(Texture.ApplyMode.Combine);
        texture1.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
        texture1.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
        texture1.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
        texture1.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
        texture1.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);

        texture2.setApply(Texture.ApplyMode.Combine);
        texture2.setCombineFuncRGB(Texture.CombinerFunctionRGB.AddSigned);
        texture2.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
        texture2.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
        texture2.setCombineSrc1RGB(Texture.CombinerSource.Previous);
        texture2.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
        rootNode.setRenderState(ts);
   }
private void CameraSett() {
    RuteCamera = new CameraNode("Camera Setting", cam);
    //setting tinggi camera
    RuteCamera.setLocalTranslation(new Vector3f(100, 300, -200));
    RuteCamera.updateWorldData(0);
    //mengatur pergerakan dari camera
    input = new NodeHandler(RuteCamera, 150, 1);
    rootNode.attachChild(RuteCamera);
    }


}

nanti hasilnya seperti ini:

ok jika kalian pengen nambah effect kabut atau effect jauh tambahkan saja code berikut:

private void Kabut(){
    //        MENCIPTAKAN EFECT KABUT...:d
        FogState kabut = display.getRenderer().createFogState();
        kabut.setDensity(0.5f);
        kabut.setEnabled(true);
        kabut.setColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f));
        kabut.setEnd(1000);
        kabut.setStart(500);
        kabut.setDensityFunction(FogState.DensityFunction.Linear);
        kabut.setQuality(FogState.Quality.PerVertex);
        rootNode.setRenderState(kabut);
}

nah tinggal dipanggil di initSampleGame..jadi nanti kayak gini:

untuk kali sekian dulu adzan subuh sudah berkumandang…

3 thoughts on “Tutorial Java Monkey Engine-Load Terain- PART-2

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