Problems loading *.jme File outside of JMECanvasImplementor class

Hi,



i have a big problem trying to load a *.jme model file outside of my mane JMECanvasImplementor class. As you can guess I'm going to load a JmeCanvas into a Swing GUI.



I've tried two ways of loading the model, the first one loads the model in the class in which the JMECanvasImplementor is extended, in the second way i'm trying to load the model out of an supporting class called "Chassis_1" whichs implements the interface "Chassis".



When loading the model out of the first class everything works finde. But when I'm trying to load the model out of the supporting class "Chassis_1" i'm getting the following error:


Exception in thread "main" java.lang.NullPointerException
        at com.jme.util.export.binary.modules.BinaryMaterialStateModule.load(BinaryMaterialStateModule.java:48)
        at com.jme.util.export.binary.BinaryClassLoader.fromName(BinaryClassLoader.java:121)
        at com.jme.util.export.binary.BinaryImporter.readObject(BinaryImporter.java:251)
        at com.jme.util.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:472)
        at com.jme.util.export.binary.BinaryInputCapsule.readSavableArray(BinaryInputCapsule.java:460)
        at com.jme.scene.Spatial.read(Spatial.java:1067)
        at com.jme.scene.Geometry.read(Geometry.java:875)
        at com.jme.scene.TriMesh.read(TriMesh.java:628)
        at com.jme.util.export.binary.BinaryImporter.readObject(BinaryImporter.java:256)
        at com.jme.util.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:472)
        at com.jme.util.export.binary.BinaryInputCapsule.readSavableArray(BinaryInputCapsule.java:460)
        at com.jme.util.export.binary.BinaryInputCapsule.readSavableArrayList(BinaryInputCapsule.java:564)
        at com.jme.scene.Node.read(Node.java:673)
        at com.jme.util.export.binary.BinaryImporter.readObject(BinaryImporter.java:256)
        at com.jme.util.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:472)
        at com.jme.util.export.binary.BinaryInputCapsule.readSavableArray(BinaryInputCapsule.java:460)
        at com.jme.util.export.binary.BinaryInputCapsule.readSavableArrayList(BinaryInputCapsule.java:564)
        at com.jme.scene.Node.read(Node.java:673)
        at com.jme.util.export.binary.BinaryImporter.readObject(BinaryImporter.java:256)
        at com.jme.util.export.binary.BinaryImporter.load(BinaryImporter.java:164)
        at com.jme.util.export.binary.BinaryImporter.load(BinaryImporter.java:90)
        at com.jme.util.export.binary.BinaryImporter.load(BinaryImporter.java:181)
        at com.jme.util.export.binary.BinaryImporter.load(BinaryImporter.java:176)
        at komponenten.chassis.Chassis_1.buildChassis(Chassis_1.java:32)
        at komponenten.chassis.Chassis_1.<init>(Chassis_1.java:25)
        at jrobotarena.Robot.<init>(Robot.java:27)
        at jrobotarena.RobotMain.initRobot(RobotMain.java:229)
        at jrobotarena.RobotMain.<init>(RobotMain.java:63)
        at jrobotarena.RobotMain.main(RobotMain.java:72)



Here are the classes:

RobotVorschau (way 1):

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

package jrobotarena;


import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.system.canvas.JMECanvasImplementor;
import com.jme.util.export.binary.BinaryImporter;
import java.io.IOException;
import java.net.URL;


/**
 *
 * @author BaBene
 */
public class RobotVorschau extends JMECanvasImplementor {

    private Node rootNode, boxNode;
    private Camera cam;
    private DisplaySystem display;
    private int width, height;
    private Robot MyRobot;
    private Node Model;

    public RobotVorschau(int width, int height, Robot MyRobot){
        this.width = width;
        this.height = height;       
    }

    public void doSetup(){
        display = DisplaySystem.getDisplaySystem();

        renderer = display.getRenderer();
        width = renderer.getWidth();
        height = renderer.getHeight();
        cam = renderer.createCamera(width, height);
        cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1, 1000);
        Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
        Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
        Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
        Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
        cam.setFrame(loc, left, up, dir);

        cam.update();
        renderer.setCamera(cam);
        renderer.setBackgroundColor(ColorRGBA.black);

        rootNode = new Node("RootNode");
        ZBufferState buf = renderer.createZBufferState();
        buf.setEnabled(true);
        buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);

        rootNode.setRenderState(buf);

        initRobot();

        rootNode.updateGeometricState(0.0f, true);
        rootNode.updateRenderState();

        setup = true;
    }


    public void doUpdate() {
        rootNode.updateGeometricState(0, true);
    }

    public void spinIt(float angle){
       
    }

    @Override
    public void doRender() {
        renderer.clearBuffers();
        renderer.draw(rootNode);
        renderer.displayBackBuffer();
    }

    private void initRobot() {
        Model = new Node();
        try {
            URL maxFile = RobotVorschau.class.getClassLoader().getResource("komponenten/chassis/models/chassis_1.jme");
            Model = (Node) BinaryImporter.getInstance().load(maxFile);
            Model.setLocalScale(1f);
            Model.setModelBound(new BoundingBox());
            Model.updateModelBound();
        } catch (IOException e) {
            e.printStackTrace();
        }
        rootNode.attachChild(Model);
    }

    public Camera getCam(){
        return cam;
    }

}



This works!

But the second way:

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

package jrobotarena;

import com.jme.bounding.BoundingBox;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.system.canvas.JMECanvasImplementor;
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.io.IOException;
import java.net.URL;

/**
 *
 * @author BaBene
 */
public class RobotVorschau extends JMECanvasImplementor {

    private Node rootNode, boxNode;
    private Camera cam;
    private DisplaySystem display;
    private int width, height;
    private Robot MyRobot;
    private Node Model;

    public RobotVorschau(int width, int height, Robot MyRobot){
        this.width = width;
        this.height = height;       
    }

    public void doSetup(){
        display = DisplaySystem.getDisplaySystem();

        renderer = display.getRenderer();
        width = renderer.getWidth();
        height = renderer.getHeight();
        cam = renderer.createCamera(width, height);
        cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1, 1000);
        Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
        Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
        Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
        Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
        cam.setFrame(loc, left, up, dir);

        cam.update();
        renderer.setCamera(cam);
        renderer.setBackgroundColor(ColorRGBA.black);

        rootNode = new Node("RootNode");
        ZBufferState buf = renderer.createZBufferState();
        buf.setEnabled(true);
        buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);

        rootNode.setRenderState(buf);

        initRobot();

        rootNode.updateGeometricState(0.0f, true);
        rootNode.updateRenderState();

        setup = true;
    }


    public void doUpdate() {
        rootNode.updateGeometricState(0, true);
    }

    public void spinit(float angle){
       
    }

    @Override
    public void doRender() {
        renderer.clearBuffers();
        renderer.draw(rootNode);
        renderer.displayBackBuffer();
    }

    private void initRobot() {
        MyRobot = new Robot();
        rootNode.attachChild(MyRobot.getRobot());;
    }

    public Camera getCam(){
        return cam;
    }

}



Class Robot:

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

package jrobotarena;

import com.jme.scene.Node;
import komponenten.chassis.Chassis;
import komponenten.chassis.Chassis_1;
import komponenten.waffen.Waffe;



/**
 *
 * @author BaBene
 */
public class Robot {

    private Node RobotNode;
    private Waffe RobotWaffe;
    private Chassis RobotChassis;

    public Robot(){
        RobotNode = new Node("RobotNode");
        RobotChassis = new Chassis_1();

        buildRobot();
    }

    public void update(){
      
    }

    public Node getRobot(){
        return RobotNode;
    }

    private void buildRobot() {
        RobotNode.attachChild(RobotChassis.getNode());
        RobotNode.updateWorldBound();
    }

    public Waffe getWaffe(){
        return RobotWaffe;
    }
}



Class Chassis_1 :

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

package komponenten.chassis;

import com.jme.bounding.BoundingBox;
import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import java.io.IOException;
import java.net.URL;

/**
 *
 * @author BaBene
 */
public class Chassis_1 implements Chassis {

    private Node ChassisNode, Model;

    public Chassis_1(){
        ChassisNode = new Node("Chassis_1");

        buildChassis();
    }

    private void buildChassis(){
        Model = new Node();
        try {
            URL maxFile = Chassis_1.class.getClassLoader().getResource("komponenten/chassis/models/chassis_1.jme");
            Model = (Node) BinaryImporter.getInstance().load(maxFile);
            Model.setLocalScale(1f);
            Model.setModelBound(new BoundingBox());
            Model.updateModelBound();
        } catch (IOException e) {
            e.printStackTrace();
        }
        ChassisNode.attachChild(Model);
    }

    public Node getNode() {
        return ChassisNode;
    }

}



won't work. It's the same code but it won't work :(

Maybe someone knows an awnser :)

Excuse my bad english.

So long...

BaBene

No Ideas?