JAVA - JMonkeyEngine - getting scene info

424 views Asked by At

I'm working on JMonkeyEngine 3.0

I have my map in Scene.j3o

I would like to add Level of detail but i don't know how to get geometry of terrain. I found few codes but all are based on heightmap terrain, and using TerrainQuad.

Also I want to use simple grass system which create 2 quads, rotate them, set material and clone them and add to map, but I don't know how to get height of terrain, here's the line from tutorial:

  float y = myTerrainQuad.getHeight(new Vector2f(x, z));
1

There are 1 answers

0
Henrik Lindgren On

I was having the same problem as you, having followed the terrain tutorial in the official Beginner's Guide book for JME 3.0. It starts out helping you create a terrain with the IDE context menus on the Scene.j3o, but when they get to looking at heights on the terrain for tree placement they switch over to describing it with the TerrainQuad object, just as you say.

I'm very happy to say I managed to solve it just now by extracting the TerrainQuad from the .j3o like this:

Spatial terrainGeo = assetManager.loadModel("Scenes/bumpyScene.j3o");
TerrainQuad terrainQuad = ((TerrainQuad)((Node)terrainGeo).getChild("terrain-bumpyScene"));

Geometry someObject = new Geometry("SomeObject", new Box(.1f, .1f, .1f));

terrainQuad.getHeight( 
    new Vector2f(someObject.getLocalTranslation().x, someObject.getLocalTranslation().y) );

In the SceneExplorer you can see the structure and name of your scene. The editor wizard creates a TerrainQuad as you can see, in the example my TerrainQuad is under the node named "terrain-bumpyScene".

SceneExplorer Window in JME IDE

As a last note it can be helpful to use traverse the nodes through code to debug certain issues, this link was very helpful for me in solving the task: JME advanced docs, node traversal