Disappearing lighting

I’m coding an application to view astronomical data and I want the terrain to be an optional extra data set.



I have coded a flatten command that responds to the “F” key that removes the terrain as follows:



[java]

if (name.equals(“flat”) && !pressed) {

flat = !flat;

if (flat) {

terrain.setLocalScale(1f, 0.001f, 1f);

} else {

terrain.setLocalScale(1f, 1f, 1f);

}

}

[/java]



This works well except that when I restore the terrain the scene then has a fixed lighting scheme and the directional lighting no longer has any effect.



Is there another way to dynamically flatten and unflatten the terrain?



Alternately is there a way to force jMonkey to recalculate the lighting?



Is this a bug or just a reflection of the fact that setLocalScale is not intended to be used dynamically?



Kevin

So you only change the scale? I don’t think that is intended. @Sploreg?

Yes, changing the scale was a simple solution as I think that the alternative would be to display the texture on a flat plane with the same dimensions as the terrain. Bit of a pain as I would then need to restore the terrain the next time the F key was pressed.



Also, down the road I was hoping to code a cool animation showing the terrain mountains growing out of the flat image.

If you change the scale of the terrain the normals are not recalculated; only if you modify the actual height values. However, it would be useful to have that feature so I will add it in. You will have to manually call it after the scale change, and it will take time to recompute all the normals.

Alright, I just committed a new method to TerrainQuad:

recalculateAllNormals()



It is only on TerrainQuad and not on the higher-level Terrain interface. If you are using the nightly builds you will see the change tomorrow.

Wow - that was superfast. Thank you!



Kevin