Level: Beginner Version : 1.0 author : Thomas PFEIFFER aka Kiroukou date : May 25th 2006
Sandy is a library written in AS2 which allows you to manipulate and display 3D objects in Flash.
Flash does not natively support operations on 3D objects. This is really a lack of functionality that Adobe ought to fix in the near future.
For the present, we are unable to take advantage of the acceleration provided by graphics cards, so we have to be satisfied with the performance of the Flash player.
Sandy is an object-oriented library strongly influenced by the Java3D library. Although its API resembles that of Java3D, I have never referred to Java3D's source code for the simple reason that Flash is a special environment, and I wished to optimize the library as much as possible while taking into account the Flash player's possibilities.
To create a 3D scene with Sandy you need to understand the concept of a tree. This concept is quite natural; the world is the root of the tree, then all the computational elements are nodes, and finally all the displayable elements (except for the interpolators, see below) are leaves.
To start getting into the library, let's talk in detail about what I'll call the root, nodes, and leaves:
Only one class has the role of root in our representation of a 3D scene. This is the World3D class. World3D is thus the point of entry into our 3D scene. We will be able to add children to it; these have to be Groups.
The Group node is a node in the true sense. It's an element that has a parent and a list of children which are also nodes. The group object is used as the connection between the World3D and the 3D scene. All the children of this connection node will be rendered.
The TransformGroup node is a special kind of Group. In fact this is the only node that can (or at least should) have leaves ! Also this node manages a transformation operation that will be applied to all its children.
A displayable object is a leaf. Therefore the following classes are considered leaves: Object3D, Sprite2D, Sprite3D.
A data structure which supports the display of a true 3D object. This means that when this object is displayed on the screen we get the exact rendering of its projection from 3D space to 2D space. This object is rendered on every frame of the movie.
A false 3D object. Sprites allow us to include pre-rendered graphical elements (images) in a true 3D space and to produce a simple prespective effect on them. As a result a Sprite always shows the same face no matter what position the camera is in. Its image always faces us.
Another false 3D object. Like the Sprite2D it allows us to display a pre-rendered element. But this object can render more interesting things since it comprises a skin (details later on) containing 360 images, which allows it to reproduce a true 3D effect with pre-rendered elements. A perspective effect is applied just as with the Sprite, but the Clip3D shows different images depending on the camera's angle of view.
They are objects that let us manipulate TransformGroup nodes. They used to be considered as leaves (versions ⇐ 1.0 BETA) but they are not anymore.
You can use the following objects :
A Skin determines the appearance of a 3D object. In order to modify an object's appearance we can change its skin and thus vary its display characteristics (such as edges, faces, alpha, color, lighting, etc.).
The user may add to the available skins at will.
So to start a Sandy application right you have to:
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // screen creation, the object where objects will be displayed. var ecran:ClipScreen = new ClipScreen( this.createEmptyMovieClip('ecran', 1), 600, 600 ); // we create our camera var cam:Camera3D = new Camera3D( 700, ecran); // we add the camera to the world World3D.getInstance().addCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { ;// make you implementation here } // We lauch the animation creation. init();
The system might be still hard to get, but it will be better in the next toturials where you will discover the API more precisely.