Sandy extrusion class

Few days ago I have added simple yet powerful Extrusion class to Sandy. The decision was made soon after Away3D v2.2 release demo featuring PathExtrude class very similar to Pipe primitive I made a year ago. I mean, this feature is just too cool to not have it :)

Unlike Away3D that provides separate class for every extrusion type, Sandy will provide one general purpose Extrusion class that, together with Polygon2D, can be used to create any possible extrusion of concave polygon. Let’s take detailed look at its possibilities.

Basic use

For this example, we will make three-dimensional Q letter. First, we will need to create profile polygon; to do this, we need to pass array of corner coordinates to Polygon2D in the order of their appearance on Q perimeter. Note that we have to cut Q in order to make its inner hole a part of perimeter. In code, this is what it looks like:

var q:Polygon2D = new Polygon2D ([ new Point (-24, 78), ... ]);

The next step is to construct extrusion matrices. Extrusion class converts every Point instance into Vector with z=0 and then transforms it using supplied matrix to obtain a section. We do not need to transform front face at all, and to create back face we will push vertices 50 pixels backwards; in code, this reads

var m0:Matrix4 = new Matrix4; m0.identity ();
var m1:Matrix4 = new Matrix4; m1.translation (0, 0, 50);

Finally, we can create our extruded Q with

var ext:Extrusion = new Extrusion ("q", q, [m0, m1]); scene.root.addChild (ext);

Check out complete code and the result.

Advanced use

Let’s face it, nobody loves matrices. To simplify things a bit, I wrote Curve3D class. Curve3D allows you to specify a path in 3D using so called Frenet-Serret frame (vectors) and provides toSections() method that returns array of matrices to pass to Extrusion constructor.

The above drawing illustrates this use case (pencil tool ftw :). You pick points and set tangent and normal unit vectors at those points; this defines a curve in 3D to extrude along. Then Extrusion class places section profiles at given points and orients their Y and X axes using normal and binormal vectors, respectively. In code, it would look like

var curve:Curve3D = new Curve3D;
curve.v = [new Vector (...), ... ];
curve.t = [new Vector (...), ... ];
curve.n = [new Vector (...), ... ];
curve.s = [1, ... ];
var ext:Extrusion = new Extrusion ("thing", profile, curve.toSections ());

Check out complete code and the result.

Extending Curve3D

And yet, Curve3D class in itself is nothing more than nice wrapper for new Matrix4 fromVectors() method. The real deal is about extending it, therefore. Inspired by great Away3D Lathe class, I have made one for Sandy, too. With Lathe class, you are only required to specify vector to center point, axis of revolution and reference direction to count angles from; the rest of parameters are plain old numbers, such as start/end angle, etc. You can’t possibly go wrong with numbers, right? We have all got used to them outside of 3D programming. So, I bet none of readers will have any problems with understanding this Lathe example. As the two above examples, it comes with project files for FlashDevelop, cool free actionscript editor with context help that will… emm… help you (until Sandy docs are updated).

1 Response to “Sandy extrusion class”

  1. 1 Petit October 9, 2008 at 18:58

    Really useful and beautiful!


Ask a Question

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Old stuff

October 2008
    Nov »

Oh, btw…

%d bloggers like this: