I’m pretty good at programming in Java but I’m new to jMonkeyEngine. I’ve gotten everything installed and the HelloPhysics example at the link below works great. My goal is to modify this example so that another class can call the “makeCannonBall()” method in the example code. I ultimately want an Arduino to send a serial message to this class when a button is pushed, and have the class fire the cannonball.
https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_physics.html
I got my new class to work over serial, when new data is received an event occurs causing this method to run.
This is the main method in the HelloPhysics example:
public static void main(String[] args)
{
Main app = new Main();
app.start();
SerialCommunication serialComm = new SerialCommunication(app);
serialComm.initialize();
}
In the second class the constructor is:
public SerialCommunication(Main app)
{
this.app = app;
}
In the second class this line is executed (in the event handler for new data received).
app.makeCannonBall();
The line above produces an error:
Uncaught exception thrown in Thread[jME3 Main,5,main]
IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!
Problem spatial name: Root Node
So my question is how am I supposed to accomplish this in jMonkey?
I tried creating another class that extended AbstractAppState but that didn’t work. In this class I tried to call makeCannonBall() and update the geometric state before/after but I couldn’t get it to do anything. I basically created this class object in main, had the new class create a SerialCommunication object serialComm, then had serialComm call a method in the AppState class that would fire the cannon ball and update. I’m not sure if this would or even could have worked. It’s possible I did it wrong but I unfortunately deleted the class so I can’t post it. If this is the route I have to go I’d appreciate code examples but I’ll take any advice I can get.
O and if your wondering what this is for its the start of my Doomsday box project. I want to make a really cool machined enclosure fit with controls, timer, keypad, buzzer, buttons, and more that basically controls a simple game that goes boom and resets. Its kind of stupid but I saw something like it online (link below) and figured I’d make my own new and improved version.
http://www.thegreenhead.com/2007/05/big-red-button-doomsday-device-usb-hub.php
Thanks ahead of time!
-Justin