Bright Hub
 
Matthew Casperson's Hubfolio

Away3D Programming Tutorials - Away3D Lite Terrain Demo

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

Find the limits of Away3D Lite by creating a highly detailed terrain demo.

Introduction

One of the main selling points of Away3D Lite is its performance. The Away3D team claim the Lite version of the engine is up to 4 times faster. Here we will look at building a simple demo that will put this claim to the test. This code is based off the last tutorial, so read that if you haven’t already done so.

Code Documentation

ApplicationManager.as

The demo will be made up of three models: two terrain models and one plane model. The terrain models will scroll down the z axis, and when they leave the screen they will move back up. By cycling the two models in this way we can get the look of an endless world. The plane model will simple move from side to side.

First we embed the models and their textures. The examples that come with Away3D Lite all load their models from external files, but here we will use a little workaround to use embedded files as the model data. [code]

In order to create a 3D model from a source file we need to create a new instance of a parser. The terrain (created with the awesome T2 program, which you can download here) was exported as a 3DS file, so to parse it we needs a new instance of the Max3DS class. [code]

The parseGeometry function takes a new instance of the embedded 3DS file and returns an ObjectContainer3D. [code]

The first child of the CobjectContainer3D is the terrain Mesh. We grab a reference to that mesh using the getChildAt function. [code]

The Mesh then needs to be textured with the embedded texture image. We create a new BitmapMaterial object and assign it to the Meshs material property. [code]

The terrain Mesh is then rotated and positioned. [code]

The scaleZ property is set to 0.5. This actually reduces the height of the terrain (because we rotated it, the height of the mesh is actually the z axis). [code]

The second terrain is created as a copy of the first using the clone function. [code]

Loading the plane model follows much the same process. This time we use the MQO class to parse the embedded model (because it is a Metesequoia model), and the ObjectContainer3D returned by the parseGeometry function contains a number of individual Meshs that make up the final plane model instead of just one. [code]

The camera is tilted down a little by rotating it around the x axis. [code]

The three models are then added to the scene. [code]

The moveLeft function is called to start the tweening actions on the plane. [code]

The two terrain Meshs are moved down the z axis and then placed back up the top in the onPreRender function. [code]

The moveLeft and moveRight functions setup tweening actions that move and roll the plane to make it look like it is moving left to right. [code]

Final Words

On my fairly modest laptop this demo, which displays around 17000 faces, runs at a steady 17 frames per second. That’s definitely faster than the standard Away3D engine. What Away3D Lite lacks in features, it makes up for in speed, which makes it the perfect option for simple 3D Flash applications.

Back to Away3D Tutorials

Related Files

Images

Screenshot

Next Article

Away3D Lite Target CameraAway3D Lite Programming Tutorials - Target Camera

Learn how to use the TargetCamera3D with the standard Away3D Lite application templates.

Related Article

Away3D Spring CameraAway3D Programming Tutorials - Spring Camera

Learn how to use a spring camera to create a 3rd person view in Away3D.

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