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:

My Code:

package objImport;
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.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();

    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();
            converter.convert(model.openStream(), BO);
            map=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            map.setModelBound(new BoundingBox());
        catch (Exception e)
            System.out.println("Exceptions!!!!! : " + e);

        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));
        lightState = display.getRenderer().createLightState();

        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))

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

Exceptions!!!!! : java.lang.NullPointerException
        at objImport.objImport.simpleInitGame(
        at objImport.objImport.main(
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:

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