Add objects to jmonkey scene at runtime

616 views Asked by At

I would like to build a simple graphical editor using JMonkey, where the user can add and modify simple shapes using a swing interface with the right buttons. Is it possible to add the shapes to the existing scene while JMonkey is running in a different way than using simpleUpdate method of SimpleApplication? And if so, how to do that?

1

There are 1 answers

0
1000ml On BEST ANSWER

FYI: There are already projects that can do that using JMonkeyEngine. Take a look at the forum. The jMonkeyEngine SDK also comes with an integrated scene composer.


As long as you have a reference to the Node you can manipulate it from wherever you want. But you have to ensure that you don't modify the scenegraph from outside the jME thread. Once you added a node to the scene this will apply to rotating, translating, scaling, modifying materials, attaching/detaching subnodes etc.

You can use Callable objects to move the execution of code from the Swing thread to the jME thread: http://hub.jmonkeyengine.org/wiki/doku.php/jme3:advanced:multithreading?s[]=threading

The first example in that article shows how to enqueue code to the jME Application. Use SimpleApplication.getRootNode() to get the root node from outside. Alternatively you can also use UpdateControl for the same purpose.