Bright Hub
 
Matthew Casperson's Hubfolio

Away3D Programming Tutorials - Terrain

Article by Matthew Casperson (227,413 pts )
Published on Sep 20, 2009

Learn how to create a terrain mesh in Away3D.

Introduction

Away3D includes a number of extrusion classes which can be used to create complex models at runtime from simple input. Two of these extrusion classes, Elevate and SkinExtrude, can be used in combination to create a terrain mesh.

ResourceManager.as

Each terrain mesh requires two images: the heightmap (a BitmapData) and the terrain material (usually a BitmapMaterial). Both of these are created by the ResourceManager.

ApplicationManger.as

First up we need to create a new instance of the Elevation class. This class takes a BitmapData and reads the value of a colour channel on each pixel to determine the height of a vertex in a mesh. [code]

Next we need to create a SkinExtrude object. This object takes the vertices generated by the Elevation generate function and uses them to generate a Mesh. [code]

The first parameter to the generate function is the height map BitmapData.

The second parameter is the colour channel that will be used to determine the height of the vertices. Since this is a greyscale image any of the colours could have been used.

The third and fourth parameters define that vertices will be generated for every 20th pixel in the height map along the x and y coordinates respectively.

The fifth and sixth paramaters define the scale of the resulting vertices will be 2 along the x and y coordinates respectively.

The last parameter defines that the height of the terrain will be scaled by 1.

The Mesh is then rotated so the terrain lays along the ground. [code]

It is then added to the scene via a new MeshObject instance. [code]

The camera is positioned above the terrain and the lookAt function is used to look across it. [code]

The terrain is rotated slowly in the enterFrame function. [code]

Final Words

The end result can be quite convincing if a good texture is applied to the terrain. The terrain in the demo was textured with T2, a free terrain texture generator.

Go back to Away3D Tutorials

Related Files

Images

Screenshot

Search More About:

 
Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2010 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape