Tutorial Java Monkey Engine-Load 3DS model-Part 4

emm,,karena akhir2 ini masih tergila-gila ma namanya 3D jadi gini dech…ok langsung saja ke pokok permasalahan untuk meload 3DS model kedalam JME. langsung ke TKP

package MY_TUTORIAL_USING_JME_3;

import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
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 Load3Ds extends SimpleGame{
    private static final Logger logger = Logger.getLogger(Load3Ds.class.getName());
    Node node;
    public static void main(String[] args){
        Load3Ds app = new Load3Ds();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    }
    @Override
    protected void simpleInitGame() {
        display.setTitle("3DS load trying");
        build3D();
        //buildCamera();
        lightState.setEnabled(true);
    }
    public void build3D(){
        node = null;
        try{
            MaxToJme model = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            //lokasi modelnya
            URL maxFile = Load3Ds.class.getClassLoader().getResource("MY_TUTORIAL_USING_JME_3/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,0,0));
            node.setLocalRotation(temp);
            node.setLocalScale(.1f);
            node.setModelBound(new BoundingBox());
            node.updateModelBound();     
        }catch(Exception e){
            logger.throwing(this.getClass().toString(), "build3D()",e);
        }
        node.updateRenderState();
        rootNode.attachChild(node);
    }
}

setelah dicompile jadinya:

agar model presisi dengan camera kita setting cameranya :

    public void buildCamera(){
        //setLocation[sumbu x,sumbu y,sumbu z];
        cam.setLocation(new Vector3f(9.0f, 0.0f, 10.0f));
        cam.update();
    }

kemudian kita panggil di simpleinitGame method camera yang kita buat dan jadinya seperti ini:

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