Hi,
I am using the tutorial for embedding JMonkeyEngine in an Applet.
My problem is that I want to be able to create Physics objects from the applet itself and they cannot be added immediately
Basically, I have a helper class Helper that associates the canvas from a SimpleApplication to the Applet.
In the Applet, I would like to be able to do the following:
[java]
Helper helper=new Helper(this); // creates my JMonkey World (extends SimpleApplication) in a canvas added to the Applet
World world=helper.getApp(); // returns the World , that extends SimpleApplication
world.addModel(“Sinbad”);
[/java]
And then, in World, I would have something like:
[java]
public void addModel(String name){
Node model = (Node) assetManager.loadModel(“Models/” +name + “/” + modelName + “.mesh.xml”);
model.lookAt(new Vector3f(0, 0, -1), Vector3f.UNIT_Y);
model.setLocalTranslation(4, 0, -7f);
getPhysicsSpace().add(model);
rootNode.attachChild(model);
}
[/java]
But then, I have a NullPointerException because either assetManager, the PhysicsSpace or rootNode is not yet instantiated…
But if I perform some operations (about 2 to 3 seconds) before calling world.addModel(), it works perfectly…
Any thought?
I think that I have a problem of synchronization between the threads that create all my JMonkey stuff and my Applet drawing thread, but I am not sure how to solve this, I am quite a newbie…
Thank you.
Best,
Yohan.