Following on from my previous post about the new 3D features of Flash Player 10, I decided to take a look at a more advanced way of drawing 3D graphics in AS3, using the new drawTriangles method of the updated Graphics class.
This demo was my attempt at creating a version of Soulwire’s Papervision3D Ribbon class using native Flash Player 10 code, and while the demo doesn’t support the more advanced features of the Papervision version, the final result does look quite similar. In fact, if you take a look at the code you’ll see just how simple 3D can be when using Flash 10.
Using drawTriangles to render 3D graphics is fairly straight forward, requiring you to pass in a number of different Vectors to describe the geometry of a 3D mesh. A Vector is Flash 10’s new typed array class, and is very useful for making sure that an array contains only one type of data. The drawTriangles method accepts four parameters, three of them Vectors, but I won’t go into this in detail here as there are many good articles that explain it far better than I can, such as this excellent introduction to drawTriangles by Ryan Taylor.
What I will note is that from my tests and what what I have read, it seems that drawTriangles (while very useful) is best suited to quick and simple 3D effects. If you’re looking to render light sourced materials with proper z-sorting, or more than one texture map per object, then you will probably need to write your own classes to do just that, much as this post by Neuro Productions explains.
In fact, what really makes 3D in Flash 10 shine are the new utility classes such as Matrix3D, Vector3D and Utils3D. If you look at the code for the demo below you will see that there is really not much complex maths being used, instead it is mostly taken care of with these new classes. And it is these classes which new engines like PapervisionX or Away3DLite will most likely be using to boost speed and improve visual quality in Flash Player 10.