Trouble loading in .obj's

Hi all,



now that i've gotten jME2 compiled, I'm working through the various tutorials around the site, however, I'm having trouble getting a Wavefront OBJ into the engine.  My code is almost a line for line duplicate of this: http://www.jmonkeyengine.com/wiki/doku.php?id=howto_jme2_and_blender2.48



My Code:


package objImport;
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.bounding.BoundingBox;
import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.CameraNode;
import com.jme.scene.Spatial;


import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.ObjToJme;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author skyebook
 */
public class objImport extends SimpleGame
{
    private Spatial map;
    public static void main(String[] args)
    {
        objImport modelLoader = new objImport();
        //modelLoader.setConfigShowMode(ConfigShowMode.AlwaysShow);
        Logger.getLogger("").setLevel(Level.SEVERE);
        modelLoader.start();
    }

    protected void simpleInitGame()
    {
        display.setTitle("Importing OBJ's!");
        URL folder = objImport.class.getClassLoader().getResource("3D/canon");
        URL model = objImport.class.getClassLoader().getResource("3D/canon/canon.obj");
        FormatConverter converter = new ObjToJme();
        converter.setProperty("mtllib", folder);
        converter.setProperty("texdir", folder);

        ByteArrayOutputStream BO = new ByteArrayOutputStream();
        try
        {
            converter.convert(model.openStream(), BO);
            map=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            map.setLocalScale(4f);
            map.setModelBound(new BoundingBox());
            map.updateModelBound();
            rootNode.attachChild(map);
        }
        catch (Exception e)
        {
            System.out.println("Exceptions!!!!! : " + e);
            e.printStackTrace();
            System.exit(0);
        }

        PointLight light = new PointLight();
        light.setDiffuse(new ColorRGBA(.75f,.75f,.75f,.75f));
        light.setAmbient(new ColorRGBA(200f,200f,200f,1.0f));
        light.setLocation(new Vector3f(0, 0, 0));
        light.setEnabled(true);
        lightState = display.getRenderer().createLightState();
        lightState.setEnabled(true);
        lightState.attach(light);
        rootNode.setRenderState(lightState);

        KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
        CameraNode camNode = new CameraNode("", cam);
        camNode.setLocalTranslation(0, 1.5f, 0);
    }

    protected void simpleUpdate()
    {
        if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit", true))
        {
            System.exit(0);
        }
    }
}



I'm getting a NullPointerException (I've got the 3D/canon folder in the root of my netbeans project folder):

run:
Exceptions!!!!! : java.lang.NullPointerException
java.lang.NullPointerException
        at objImport.objImport.simpleInitGame(objImport.java:55)
        at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:544)
        at com.jme.app.BaseGame.start(BaseGame.java:74)
        at objImport.objImport.main(objImport.java:40)
BUILD SUCCESSFUL (total time: 3 seconds)


Thanks for taking a look :)
I've got the 3D/canon folder in the root of my netbeans project folder

The getResource() method depends on the classpath. Usually netbeans adds the folder /build/classes as the primary classpath. By default all files under /src will be included in /build/classes so you can just put 3D/canon under /src. Otherwise you can set the working directory to your project folder (it's in netbeans project settings), then you can access your directory with new File("3D/canon").toURI().toURL(). But the ideal way to use this is with ResourceLocatorTool; see here for more info: http://www.jmonkeyengine.com/jmeforum/index.php?topic=5707.0.

thank you! that did the trick…  any idea why I'd be getting 4 fps with a 24kb texture file?

Depends on some things… Video card, type of texture, resolution of texture, model poly count, locking methods used, etc. Try using a different model for example.

Also, make sure the texture is power of 2 sized; some vcards slow down quite a bit if they are not…

What are you using for the UP direction in blender? (blender's default is (0,0,1) while jME's is (0,1,0))

so… what is it? :smiley:



nevermind, managed to get this the correct position :smiley:

i did this exactly tutorial a while ago, and wow, i though i would never get a .OBJ onto JMe with a texture. but there is a silly problem. since i used a Grind object from Blender instead of a cube, for some reason it gets upside down when i import to JME T.T



anyone know why and the solution? i don't want to make averything upside down on blender for now on T.T