HariboTer’s question

Hello everyone,

I’m pretty new to the jMonkeyEngine (and 3D-programming in general), thus having a lot of questions which I thought would be better to ask in a single thread instead of spamming a new thread for each. About me, I have ~1 year programming experience with Java (which is my first, main (and only) programming language). In that time I have been snooping around in the Internet and the Minecraft code and finished a Minecraft Tetris ( http://minecraftjp.mi.funpic.de/craftris/ ) some weeks ago. Now I want to step on into 3d-games and I am willing to learn! :wink:



So here are my (probably pretty nooby beginner) questions (I’m sorry in case that they have already been asked and solved elsewhere (and ask for the link in that case :wink: ) :

  1. Before trying out SeaMonkey, I tried to simulate an ocean by placing lots of SimpleWater-Quads next to each other. Actually it would have looked pretty fine from “overwater” if the single quads weren’t processed each on its own, giving the ocean an overall asynchronous look. For oceans this is no problem (since SeaMonkey is of great use), but if I e.g. wanted to give a winded river water with the SimpleWater-option by accordingly placing named quads, what would I have to do to get rid of the asynchronous look?
  2. Is there a (more or less) convenient way to simulate underwater-graphics, or would one have to simulate them by themselves?
  3. Is there a possibility to set the “look” of the mouse cursor?
  4. The terrain editor is a very useful tool, but it’s often inconvenient to have to move the mouse cursor each time you want to create a little change on the terrain, which is becoming really painful if you want to make a mountain or generally change large parts of the terrain. Is there an option to change that so you only have to keep the mouse button pressed, but not to move the mouse cursor anymore?
  5. Is there an option to show a 3D-space coord grid in the scene/terrain editor? I often get confused when it comes to comparing the scale of a composed scene with the game scale (or even have to do fine-tuning of object positions) because I’m missing an orientation point or similar…
  6. In my “simple” test application, I have a MenuState for the main menu and a GameState for the game itself (both children of AbstractAppState). Now the problem is, when I want to switch from the game back to the main menu by listening to keyboard input (the stateManager detach()es the game state and attach()es the main menu state), the cleanup() method of the game appstate leads either to ConcurrentModificationExceptions, or Nullpointerexceptions, or more exceptions derived by the renderer. The corresponding code is:

    [java]public void cleanup()

    {

    super.cleanup();

    app.enqueue(new Callable<Object>() {

    //app is my SimpleApplication “child”

    public Object call() throws Exception {

    bulletAppState.getPhysicsSpace().removeAll(sceneNode); //the sceneNode is this states “rootNode”; everything used from this class is attached to it, while it itself is attached to the app’s rootNode

    sceneNode.detachAllChildren();

    rootNode.detachChild(sceneNode);

    return null;

    }



    }); //this Callable-action was a (successless) desperate attempt to fight those exceptions



    List<SceneProcessor> spl = viewPort.getProcessors();

    for(SceneProcessor sp : spl)

    viewPort.removeProcessor(sp);





    waves.setLooping(false); //just an audioNode, I didn’t run into any problems here

    waves.stop();

    inputManager.removeListener(this); //this shouldn’t be problematic at all too

    }[/java]

    So, what would be the correct approach in such a case?


  7. A totally other kind of question, after having gone through the “Documentation and Tutorials”, my actual plan is to create a little RPG (just a linear story with around half a dozen of quests, built step-by-step). Do you have any advice you can give me (maybe about community-based project I should use, more jME3 tutorials (if there are even more out there) or specific systems of application logic)? I must admit I am sort of clueless about the implementations of NPCs, drivable means of transportation or similar …



    Any answers are much appreciated, thanks in advance :wink:

Unless you are somehow calling the cleanup() method yourself, it should already be called on the render thread and you should not get concurrent mod issues or null pointer issues. We might be able to help if we actually had stack traces.

@hariboter said:
[java]public void cleanup()
{
List&lt;SceneProcessor&gt; spl = viewPort.getProcessors();
for(SceneProcessor sp : spl)
viewPort.removeProcessor(sp);
}[/java]


On second thought, the above may cause ConcurrentModificationExceptions depending on how the getProcessors() list is implemented. Iterating over a regular ArrayList, for example, and trying to remove from it will cause problems.

It might be better to specifically remove the processors that you know you added when the state was initialized. It's way less dangerous, too.
1 Like

For things like rivers take a look at the biomonkey stuff - there is a nice river implementation being worked on there complete with flow maps, forks, etc.

1 Like
@pspeed said:
On second thought, the above may cause ConcurrentModificationExceptions depending on how the getProcessors() list is implemented. Iterating over a regular ArrayList, for example, and trying to remove from it will cause problems.

It might be better to specifically remove the processors that you know you added when the state was initialized. It's way less dangerous, too.


That actually was the issue, thanks a lot! :)
I ran into another issue though, every time I switch from the main menu to a new game the light seems to become more intensive until every texture is white. I add the lights by the following:
[java]private void setUpLight() //called by the AppState's initialize()-method
{
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(1.3f));
sceneNode.addLight(al);

DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(new Vector3f(lightDir).normalizeLocal());
sceneNode.addLight(dl);
initAudio();
}
[/java]
Since they are attached to the sceneNode, the sceneNode.detachAllChildren()-call in cleanup() should remove them, but it seems like it doesn't, maybe someone can explain this to me?

@zarch said:
For things like rivers take a look at the biomonkey stuff - there is a nice river implementation being worked on there complete with flow maps, forks, etc.


I browsed BioMonkey in the forums, but I only found the Forester-part of it (which is really neat btw), the river-thing seems to be hiding from my eyes^^ Do you have a direct link to it?

Lights are not children of the node (they aren’t directly part of the scene graph).



http://hub.jmonkeyengine.org/groups/user-code-projects/forum/topic/running-water-early-video/?topic_page=5&num=15#post-177874

1 Like
@zarch said:
Lights are not children of the node (they aren't directly part of the scene graph).

http://hub.jmonkeyengine.org/groups/user-code-projects/forum/topic/running-water-early-video/?topic_page=5&num=15#post-177874


Thanks, I got it right now :)
Also thanks for the link, I'll try to keep an eye on that project. It seems to me like BioMonkey has good chances to make it in the default SDK :)
@hariboter said:
Since they are attached to the sceneNode, the sceneNode.detachAllChildren()-call in cleanup() should remove them, but it seems like it doesn't, maybe someone can explain this to me?


Just a note: this is one of the many downsides to using the "attach specific things but remove all things" approach. It's better to remove the specific things you add... so if you added a light then specifically remove a light, and so on. Alternately, you can put everything on a node that you then attach or detach and then don't have to worry about the specific things. But calling "dettachAll" and hoping for the best is a road fraught with peril.
1 Like
@pspeed said:
Just a note: this is one of the many downsides to using the "attach specific things but remove all things" approach. It's better to remove the specific things you add... so if you added a light then specifically remove a light, and so on. Alternately, you can put everything on a node that you then attach or detach and then don't have to worry about the specific things. But calling "dettachAll" and hoping for the best is a road fraught with peril.


Thanks for the advice, I'll consider it in future coding :)

Atm I'm trying to get the import of blender models done, and I seem to fail in it. I made a simple mesh in blender, applied a material which I set to a red color and exported it. Then I threw the created .mesh.xml file and the .material file in the asset's Models folder and tried to add it to the scene with
[java]Spatial test = assetManager.loadModel("Models/test/blob.mesh.xml");
test.setLocalTranslation(0, 80, 0);
sceneNode.attachChild(test);[/java]
which throws
[java]java.lang.NullPointerException
at com.jme3.scene.plugins.ogre.MeshLoader.applyMaterial(MeshLoader.java:215)
at com.jme3.scene.plugins.ogre.MeshLoader.startSubMesh(MeshLoader.java:284)
at com.jme3.scene.plugins.ogre.MeshLoader.startElement(MeshLoader.java:652)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at com.jme3.scene.plugins.ogre.MeshLoader.load(MeshLoader.java:872)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:282)
at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:410)
at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:420)
at main.MainGameState.initialize(MainGameState.java:158)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:219)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:249)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:241)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)
at java.lang.Thread.run(Thread.java:662)[/java]

What did I do wrong?
  1. nope but I will probably change that
1 Like

Looks like an old version of jME3. Update to RC2?

@hariboter for your next questions, please open them in new individual threads with proper titles. When you create threads like “my questions” with a string of loosely related questions inside, other users will have a hard time searching for it.

2 Likes