Scripting 3D in Flash
      by senocular

Shapes and Fills
Wire frame, though cool and very 3D in effect, has its limitations. It is just a Wire frame and can only go so far for you depending on what you want to do or make. A way to really add a 3 dimensional feel to your shape, whatever it is, is to make it have solid sides and not just lines outlining them. Luckily, the drawing API in Flash also allows us to create those lovely sides with fills as well as draw lines. Using these fills we can add some real plasticity to our 3D shapes. The addition of fills in the drawings is initially, and in its basics, not too difficult to include. After all, its just a matter of correctly throwing in the beginFill and endFill commands within the drawing operations. You do, however, have to be careful of fills drawing through themselves. When fills do that, they un-fill for the overlapping areas. Here's an example.

[ overlapping dynamic fills ]

This means filling a 3D object is not just a matter of surrounding the line calls with beginFill and endFill as the fills will end up overlapping each other. The shape will need to be divided and separate fills are needed for each flat area of the shape or each 3D side or face. Having separate fills for each face means no single fill will ever be in a position to overlap itself preventing that un-fill effect. Separate fills will overlap each other, but they wont make the fills dropout. Because of that, however, without adding further complications for correction, fills here will need to be semi-transparent so that all the fills can be seen and none of that overlapping will hide sides that should be seen.

Filled Pyramid
We'll start off simple making a filled pyramid. Each side, or face, is given its own fill. You can see here how the fills are transparent enough to show each other even though some may be on top of others.

[ drawn filled pyramid ]

Steps to Create Animation (partial)

  1. Again, all the dirty work was created in the balloon-based cube example. Here you just need to define the pyramid and assign fills. There are 4 fills total for each of the 4 faces of the pyramid and each are set to a different color to at least somewhat separate them visually. With this kind of drawing, though, there will be some redrawing of lines not necessary in Wire frame renditions. This is because the triangle faces share the same edges, so in drawing each face, some lines will have to be re-drawn to complete the next face. It seems a little wasteful, but its needed to draw each face. Here is what the main onEnterFrame function looks like:

 

 WARNING! Curves and Fills Don't Always Play Well Together
Because of the nature of curves, when dealing with solid filled shapes in Flash, their use can cause undesirable effects with uncontrollable crossovers. For clean, solid 3D shapes with fills, you should stick with lines and filled triangles. Curves can be used in regulation on flat objects such as flat circular discs however. There, you don't have to worry about crossover in 3D.

The following tutorials will build-upon what you learned and introduce some advanced fill techniques.

 




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.