How to know when the Physics are fully loaded?

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.

why can’t you just call it in simpleInitApp()?

I am trying to write kind of a library that wraps JME, so I want the programmer to be able to add a model without having to change anything in the source code of the World extends SimpleApplication…
Is that possible?

Well the most simple case

in simpleInit do a callback to whatever you use and tell it thats its ready.

I am a physics teaching assistant, and I want to introduce my students to simulation programming with as few programming knowledge as possible. I want to use the Bullet library as a starting point before teaching the hardcore equations.

So I need to simplify JME and wrap it.

Seems like you just make it more complicated… simpleInitApp is the answer, how you heed it is your choice. You are aware of threading issues when you “just call stuff” from outside, right?

Thanks everyone.
I learnt how to make a callback (never had to do one before) and I included it in the simpleInitApp() and it works just fine.

PS: @normen, yeah I know about threading issues, that was why I was suspecting a “synchronization” problem in my previous code.

“synchronization” is not the solution, you need to do things on the gl thread.