TerrainTestModifyHeight but with TerrainGrid

I tried modifying TerrainTestModifyHeight.java and replaced TerrainQuad by TerrainGrid, and I was quite happy to see that it worked… until I go on any second tile in any direction, then I get





java.lang.NullPointerException

at com.jme3.terrain.geomipmap.TerrainQuad.getNormal(TerrainQuad.java:1167)

at com.jme3.terrain.geomipmap.TerrainQuad.getNormal(TerrainQuad.java:1142)

at com.mygame.Editor.simpleUpdate(Editor.java:101)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)

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)





This line 101 is the same as line 125 in the original source code :





Vector3f normal = terrain.getNormal(new Vector2f(intersection.x, intersection.z));





I understand the goal of the method, but I don’t understand why it would return null outside the initial 2x2 grid (or so it seams). I barely have a few days worth of learning with JME (and not so much more with OpenGL at all), so I’m hardly in a position to suggest a fix.

This kind of support for TerrainGrid is still in the works a bit and ties in with editing the TerrainGrid in the SDK as well… I guess for now you’ll have to pull out the actual TerrainQuads to modify them.

Well you don’t need to get the normal of the terrain, that is just to show a little arrow in that test case. But it should not be throwing an NPE. It appears that it is trying to calculate the normal when the terrain is being swapped in.

I will take a look at it this week.

This test was working a while ago, but some things in terrain have changed a bit since then causing this test case to break.

All good, thanks for the reply!



And, yes, when I comment the line, I can adjust the height of any other cell.