By seapegasus on May 18, 2010
Do you remember jMonkeyEngine, the cool 3-D game framework from JavaOne? Yesterday, the first alpha of the upcoming jMonkeyEngine 3 has been released!Read More]
So yeah well... I didn't submit my tutorial to the jME documentation contest after all (I was on an island without wifi -- don't ask), and nobody else submitted anything either, quite sad. The whole event happened at quite short notice and over the winter break, maybe nobody felt inspired to work. ;)
Anyway, here is my Terrains, Heightmaps, and Texturing article. I haven't fully written the section about terrain texturing yet, I'm still looking for the optimal combination of settings (texture units + texture size + procedural textures). But the tutorial already covers heightmaps and terrain generation and loading.
When I worked with terrains the first time, I kept adding translation constants and shifted and scaled them, all to get an intuition for how big they were, and where they would be rendered, compared to smaller models I loaded. Some terrains ended up being rendered smaller than expected, others bigger; some looked clear and smooth, and others blurry and angular; some were floating "in mid air" and others stuck to the "floor" (the x/z plane) or in a faraway corner. No details in the javadoc either. How mysterious. (Note to self: Get developer permissions and add javadoc!)
So I sat down and tried to find out: How does the terrain's heightmap size map onto world units? I have to scale every terrain (you will notice that, by default, they are too steep), is there maybe one obvious factor I can apply that makes them look more natural? What is the default position and size for a freshly loaded terrain anyway? And what is it after scaling? And lastly, how do I calculate the right values for the texture intervals in a procedural texture?
Since it's impossible to judge distances in the empty space of a 3D-scenegraph, lots of trial and error ensued: I created long white boxes (1\*1\*256) around the origin, to mark the x/y/z axes. I also marked points such as (128,128,128), (255,255,255), (0,0,255), etc with AxisRod objects. Finally, when looking at the terrain rendered next to these markers, the pattern behind heightmap values and world units became clear. When I now create a landscape with a water surface, I can predict which part of the terrain will be under water, and adjust the procedural texture accordingly. No blooming meadows on the sea floor anymore! :)
Next stop: Decreasing the blurriness of my terrain textures. Am I supposed to use the same detail texture on the whole terrain, or can I have several? If you have any best practices regarding jME texturing, please leave a comment. :)
While taking a few days of vacation (before coming back in time for the release of NetBeans 6.7.1!) I finally got my jMonkeyEngine notes and files in order. If you don't know it yet: The jMonkeyEngine (jME) is a free and open-source 3D engine for creating 3D games and simulations in Java.
(I would have blogged about it earlier, but the project is moving servers in July... So if the links below should change again and break, search the web for "jmonkeyengine" and then search within the page...)
If you have never seen it before, these jME videos and demos show best what you can do with Java3D nowadays.
I had created a simple 3D world with jME 1.0 and started migrating useful elements to jME 2.0 -- which is well doable despite a few API changes, especially since NetBeans marks the broken lines, fixes the import statements, and I can get the new syntax from the code completion popup. Here are my notes that I shared on the jME wiki:
There is probably more to be said about distributable JAR files, but OneJar solves my current questions. If you figured out how to get native libraries into a webstartable JNLP file, leave a comment. This blogger here has some more tips regarding JNLP signing and where to place the native libraries, so this is my next lead to investigate. But first I need to get my rusty 3D app going again--taking into account the new stuff I've been reading about programming patterns lately, suddenly my old class structure looks quite... sub-optimal. ;)
PS: updated links to stable jmonkeyengine.com URLs.
NetBeans IDE, Java SE and ME, 3D Games, Linux, Mac, Cocoa, Prague, Linguistics.