Hacking Plugin Media and PV3D.org

Intro

Seb Lee-Delisle is the technical director at Plug-in media and is famous world wide for his particle effects and his very entertaining presentations. During the Christmas season Seb usually releases a snow particle system to the open source community. You can download Seb’s snow systems and more from his blog at www.sebleedelisle.com.

In this post, you’ll take Seb’s snow-storm particle effect and combine it with another great blog release found on John Lindquist’s site at www.pv3d.org. John also releases tons of great PV3D examples and you should take the time to visit his site as well.

You’ll combine Seb and John’s work to produce a reflecting snowy Christmas scene shown below. This is a great example of hacking two different software apps to produce a superior one.

IT'S A SNOWY CHRISTMAS

IT'S A SNOWY CHRISTMAS

Demo

Download

YouTube

Discussion

If you haven’t guessed it yet, hacking in the open source community is a good thing, and the book emphasizes going beyond the surface of PV3D and making it better (or hacking the heck out of it)!

Making it Snow for Christmas

You’ll want to start by either going to Seb and John’s blogs and downloading the corresponding snow storm and Flint Christmas scene, or by downloading the Merry Christmas code from the book’s chapter code (or link above).

John uses this Christmas scene as an example of Flint particles. The problem is that his snow is just 2D and does not interact with the reflective surface. Seb has 3D snow that will interact with the surface. So you’re going to delete the FLINT particle snow system (you’ll learn about FLINT in a later post) and add Seb’s snow.

Here are the steps:

1. Delete the Flint Particle system from John’s code.
2. And import Seb’s snow storm package into to John’s code and instantiate it using the following code:

snowStorm=new SnowStorm(100, .4,2000);
// Also, make sure that you update the snow in your animation loop (enterFrameHandler) or it willnot show up.
snowStorm.update();

3. John uses planes for Christmas ornaments, you can “snaz” this up a bit by replacing the planes with spheres, and by reducing the segments to 2×2 you make your ornaments look like crystals.

for(var i:int = 0; i < total; i++)
{
var material:ColorMaterial;
if((i & 1) == 0) material = new ColorMaterial(0xaa0000);
else material = new ColorMaterial(0x00aa00);
material.doubleSided = true;
//Add a sphere instead
var sphere:Sphere = new Sphere(material, 10, 2,2);
sphere.x = Math.cos(i) * (radius – i * 3);
sphere.z = Math.sin(i) * (radius – i * 3);
sphere.y = i / total * height;

myHolder.addChild(sphere);

}

4. You now have 3D snow and cool looking ornaments, but the snow is out of wrack and at this point you’ll need to adjust a few parameters to make it look just right. In this case, we want the falling snow to disappear just as it touches the reflective surface . To accomplish this adjust the following parameters

snowStorm=new SnowStorm(100, .4,2000);
myHolder.addChild(snowStorm);
//Pull the snow up so it disappears when it hits the reflective surface
snowStorm.y=1000;

In addition to changing your particle parameters you raise your snow’s y-position so it just touches the reflective surface before being recycled. Next you have to go into the snow class itself and adjust the particle ratio. In the SnowStorm class in the update method make the following change:

if(particles.length/10 < maxFlakes)

This is what I call emotional (or intuitive) programming. You might not know completely how the code works but by changing a few parameters you bring everything into agreement. This can be both dangerous and fun! So make sure you keep back up copies in case you really mess something up.

This causes your particles to be regenerated more rapidly and close the gap that appears due to particle lag. Now matter what you create, you’ll always need to make adjustments. Get used to going down to sub classes and changing parameters.

Flex is a great tool for surfing logically to classes that you need to modify. Just roll over a method and hold down the command key (MAC) or alt key (PC) and when you do the method, class, or property will underscore and when you click on it you will automatically navigate to that method even if it is in another class.

5. Finally you want to change the words from MERRY CHRISTMAS to IT’S A SNOWY CHRISTMAS. You’ll need to play around with the spacing of the words a little to get it right (this is where a little knowledge of trig is helpful).

//IT’S A
var itsaMaterial:Letter3DMaterial = new Letter3DMaterial(0x00cc00);
var itsa:Text3D = new Text3D(“IT’S A”, rockwell, itsaMaterial);
//SNOWY
var snowyMaterial:Letter3DMaterial = new Letter3DMaterial(0xcc0000);
var snowy:Text3D = new Text3D(“SNOWY”, rockwell, snowyMaterial);
//CHRISTMAS
var christmasMaterial:Letter3DMaterial = new Letter3DMaterial(0x00cc00);
var christmas:Text3D = new Text3D(“CHRISTMAS”, rockwell, christmasMaterial);

The final results are shown below in the figure above. To see the entire code download it from the source or click the more button below:

Main Code

package
{
import flash.events.Event;
import flash.filters.BlurFilter;

import net.pluginmedia.pv3d.SnowStorm;

import org.papervision3d.core.effects.view.ReflectionView;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.special.Letter3DMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.typography.Text3D;

[SWF(width=”640″, height=”480″, backgroundColor=”#000000″, frameRate=”60″)]
public class MerryChristmas extends ReflectionView
{
private var myHolder:DisplayObject3D = new DisplayObject3D();
private var snowStorm:SnowStorm;
public function MerryChristmas()
{
viewportReflection.filters = [new BlurFilter(3,3,1)];
setReflectionColor(.5, .5, .5);
surfaceHeight = -80;

initText();
initSnow();
initTree();

addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}

private function initText():void
{
var rockwell:Rockwell = new Rockwell();

var itsaMaterial:Letter3DMaterial = new Letter3DMaterial(0x00cc00);
var itsa:Text3D = new Text3D(“IT’S A”, rockwell, itsaMaterial);

var snowyMaterial:Letter3DMaterial = new Letter3DMaterial(0xcc0000);
var snowy:Text3D = new Text3D(“SNOWY”, rockwell, snowyMaterial);

var christmasMaterial:Letter3DMaterial = new Letter3DMaterial(0x00cc00);
var christmas:Text3D = new Text3D(“CHRISTMAS”, rockwell, christmasMaterial);

itsa.z=-500;

snowy.z = 0;
snowy.x=500;
christmas.z = 500;
snowy.rotationY=-90;
christmas.rotationY = 180;

myHolder.addChild(itsa);
myHolder.addChild(snowy);
myHolder.addChild(christmas);

scene.addChild(myHolder);
}

private function initTree():void
{
var radius:Number = 300;
var height:Number = 500;
var total:uint = 100;

for(var i:int = 0; i < total; i++)
{
var material:ColorMaterial;
if((i & 1) == 0) material = new ColorMaterial(0xaa0000);
else material = new ColorMaterial(0x00aa00);
material.doubleSided = true;
var sphere:Sphere = new Sphere(material, 10, 2,2);
sphere.x = Math.cos(i) * (radius – i * 3);
sphere.z = Math.sin(i) * (radius – i * 3);
sphere.y = i / total * height;

myHolder.addChild(sphere);
}
}

private function initSnow():void
{
snowStorm=new SnowStorm(100, .4,2000);
myHolder.addChild(snowStorm);
snowStorm.y=1000;

}

private function enterFrameHandler(event:Event):void
{
myHolder.rotationY += (viewport.containerSprite.mouseX – myHolder.rotationY) * .01;

snowStorm.update();

singleRender();
}
}
}

Advertisements

3 Responses to Hacking Plugin Media and PV3D.org

  1. Wow really cool:

    for those who like flex heres a flex version:

    <![CDATA[
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import net.pluginmedia.pv3d.SnowStorm;
    import mx.core.UIComponent;
    import org.papervision3d.core.effects.view.ReflectionView;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.special.Letter3DMaterial;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.primitives.Sphere;
    import org.papervision3d.typography.Text3D;
    private var myHolder:DisplayObject3D=new DisplayObject3D();
    private var snowStorm:SnowStorm;
    private var reflectionView:ReflectionView=new ReflectionView;
    private var scene:UIComponent=new UIComponent;

    public function MerryChristmas():void
    {

    this.addChild(scene);
    reflectionView.viewportReflection.filters=[new BlurFilter(3, 3, 1)];
    reflectionView.setReflectionColor(.5, .5, .5);
    reflectionView.surfaceHeight=-80;
    initText();
    initSnow();
    initTree();
    addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    }

    private function initText():void
    {
    var rockwell:Rockwell=new Rockwell();
    var itsaMaterial:Letter3DMaterial=new Letter3DMaterial(0x00cc00);
    var itsa:Text3D=new Text3D(“IT’S A”, rockwell, itsaMaterial);
    var snowyMaterial:Letter3DMaterial=new Letter3DMaterial(0xcc0000);
    var snowy:Text3D=new Text3D(“SNOWY”, rockwell, snowyMaterial);
    var christmasMaterial:Letter3DMaterial=new Letter3DMaterial(0x00cc00);
    var christmas:Text3D=new Text3D(“CHRISTMAS”, rockwell, christmasMaterial);
    itsa.z=-500;
    snowy.z=0;
    snowy.x=500;
    christmas.z=500;
    snowy.rotationY=-90;
    christmas.rotationY=180;
    myHolder.addChild(itsa);
    myHolder.addChild(snowy);
    myHolder.addChild(christmas);
    reflectionView.scene.addChild(myHolder);
    scene.addChild(reflectionView);
    }

    private function initTree():void
    {
    var radius:Number=300;
    var height:Number=500;
    var total:uint=100;
    for(var i:int=0; i

  2. […] -https://professionalpapervision.wordpress.com/2009/04/11/hacking-plugin-media-and-pv3dorg/ […]

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: