3D GRAPHICS ENGINES are not a ubiquitous technology in programming. However, if a developer understands the principles, 3D capability can be built from the ground up in Flash to run nearly as smoothly as in Processing.

IN THE PREVIOIUS LESSON, we looked at what was involved in creating 3D effects. You should be familiar with the scale propeties of the movieclip class in flash: _xscale, _yscale the position properties: _x, _y and the Color object. How does a designer create a program that handles these properties in a convincing 3D way? The answer is in a user-defined 3D engine. The theory behind the programming, is to define new properties representing 3d coordinates, and have your code present your elements in a way that appears visually correct. Looking back at the layer analogy of programming languages, we can see how your 3D code will operate in Flash versus Processing.


Processing already features a 3D engine, so it is only necessary to define your 3D-coordinates and the desired translations and transformations to move elements around in 3D.


In Flash, we will need to add 3D functionality on top of the built-in Flash methods. While this requires a few lines of heavy math, it will allow you to stay in Flash, were your existing movieclip objects are easily accessible.

THE RESULT:

download source files

This example uses an AS 2.0 Class to add dynamic positioning, scaling and opacity to movieclips based on randomly-generated 3d coordinates. One major difference with this type of engine and the more full-featured implimentation in Processing is that this engine cannot, as it is, rotate 3d solid objects. The example only repositions 2d movieclip objects in 3d space. However, this Class method for expanding movieclips is very versatile and can be expanded to feature solid objects and even texture-mapped 3d surfaces.

If your project requires the representation of mass over volume, there are lots of online resources for delving further into creating more advanced engines:

Resources
Flash Super Samurai Chapter 2: 3D and Flash (PDF Download) Available here are the nitty-gritty mathematical concepts behind what is happening in actionscript-based 3d-engines as well as some alternative methods for creating 3d effects.
Creating real-time 3D objects with Macromedia Flash MX dynamic drawing tools This tutorial explains the finite mathematics behind the 3d-globe rotation in the example above. Also discussed is a method for generating solid planes in 3d using the drawing API.
Illogicz 3D Engine This extremely versatile 3d Engine features AS 1.0 Classes for generating object primitives in a navigable 3d environment as well as interactive scripted motion.
ThomasGlyn.com Thomas Glyn is one of the few people experimenting with 3d texture mapping in Flash. His method involves slicing a dynamically-loaded image into triangles with masks and skewing the triangles to simulate perspective. Extremely tedious but with impressive results.