I recently did a client project in AIR that had a location map section. They created the map in 3D Studio Max and wanted the user to be able to control the camera using a touch screen. I used Prefab3D to parse the 3D file into an .awd file and then used Away3D to load and render the map model.
I’m never happier than when making little game landscapes using perlin noise so I decided to do one in 3D. I started with a BitmapData object to which I applied perlin noise using the BitmapData.perlinNoise() method. Then I translated each pixel into a world tile object. I used the pixel’s red value to define the height of the tile (i.e the terrain elevation). The pixel’s blue value became a terrain type (e.g. forest, desert, snow). I used the green value to represent temperature (which i skewed to be colder for high and low values of y to mimic the icey poles of my world).
Using the resultant tile data I created a height map BitmapData which I needed to create the 3D mesh for my world and a texture map BitmapData which I’d apply to the mesh.
Away3D has a great elevation mesh object which takes a height map BitmapData and returns a mesh based on the brightness of each pixel in the height map. I used this to create a mesh and applied my texture map to it.
I added a directional light to represent sunlight. I updated the light direction based on a ‘time of day’ variable to achieve a day/night cycle type effect. A flat plane with a water texture became the surface of the sea.
I exposed a load of setup variables in a debug panel to let me play with tile generation, lighting and the 3D camera.
Check it out (you’ll need an up-to-date version of Flash Player) because Stage3D is a relatively new feature.