Datasheet

20
Part 1: Getting Started
Flint - Particle - System (at http://flintparticles.org/), a robust open source project found on Google Code,
which can be used to create impressive particle systems for Papervision3D.
However, the particle landscape is changing. Having a native 3D and pixel bender with the release of
CS4 greatly simplifies the process of building particle systems in 3D (as shown in the code above).
Depth Sorting
Shuffling Objects so that the ones closer to your viewpoint appear on top of objects farther away is called
depth sorting (or z - sorting). One big advantage that Papervision3D has over CS4 is automatic depth
sorting. In CS4, sorting algorithms must be written and unfortunately they re dependent on object
nesting.
When creating a 3D carousel for example you need to z - sort the objects as they spin to put the closest one
on top of the stack. The technical name is transposition and in AS2 it was easily accomplished using the
swapDepths method. But in AS3 it s a little more complicated.
Objects on the Stage
In AS3, the display list functions as an array and each display object has an index. The index starts at
zero and goes up to the number of objects on your stage where index zero is the bottom object. So since
the display object is a child you can change its position using the
setChildIndex method.
As all your objects are in an array, you can sort that array by z and then set the indices of your array
objects based on z. And that s how it s presently done! It uses the same code structure variables as the
torus worm. Here s a sort code snippet that illustrates the concept of sorting:
//Sorting
function sortParticles():void
{
particles_ary.sortOn(“z”, Array.DESCENDING|Array.NUMERIC);
for(var i:int = 0; i < particles_ary.length; i++)
{
addChildAt(particles_ary[i] as Sprite, i);
}
}
Using the pipe Array.DESCENDING|Array.NUMERIC forces the z value to be sorted in reverse numeric
order. Particles are sorted from high to low based on their z value. Thus, the objects further away from
your projection plane get a lower index value, placing them on the bottom of the stack.
This method needs to be called each time your 3D engine iterates the position of your objects. Typically
this occurs on an
onEnterFrame event. Unfortunately, you re stuck with manual sorting. But expect
sorting to be native to the next version of the Flash Player.
Objects in a Display Container
In many examples in this book, you won t render multiple objects directly to the stage, but inside a
display container. This approach works well when you rotate multiple objects. Instead of creating
a complex trig algorithm to rotate each individual object you can just rotate the display container.
c01.indd 20c01.indd 20 12/14/09 3:03:29 PM12/14/09 3:03:29 PM