Papervision3D Proximity Grid Example

Here is a little experiment that I created on the plane home from Switzerland. I am creating a grid of planes and then I’m using proximity to determine which planes align. If the mouse is a certain distance away it goes back into space at random positions and angles. I’m using Tweener to do the animation. Enjoy it!

[AS]import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
import caurina.transitions.*;

// Create the container sprite
var con:Sprite = new Sprite();
con.x = stage.stageWidth * 0.5 – 300;
con.y = stage.stageHeight * 0.5 + 250;
addChild(con);

// Setup the scene
var scene:Scene3D = new Scene3D(con);
var cam:Camera3D = new Camera3D();
cam.zoom = 11;
cam.x = 250;
cam.y = 250;

// Create the planes
var pa:Array = new Array();
for(var i:uint=0; i<10; i++)
{
for(var j:uint=0; j<10; j++)
{
var cm:ColorMaterial = new ColorMaterial(Math.random()*0xFFFFFF);
cm.oneSide = false;
var p:Plane = new Plane(cm, 50, 50);
p.x = j * 50 + 25;
p.y = i * 50 + 25;
scene.addChild(p);
pa.push({pl:p, rotY:Math.random() * 360, rotZ:Math.random() * 360, z:Math.random() * 30000});
p.rotationY = pa[i].rotY;
p.rotationZ = pa[i].rotZ;
p.z = pa[i].z;
}
}

// Create the render loop
addEventListener(Event.ENTER_FRAME, render);

function render(e:Event):void
{
for(var i:uint; i {
if(checkDist(pa[i].pl))
{
Tweener.addTween(pa[i].pl, {rotationY:0, rotationZ:0, z:0, time:0.3});
}
else
{
Tweener.addTween(pa[i].pl, {rotationY:pa[i].rotY, rotationZ:pa[i].rotZ, z:pa[i].z, time:3});
}
}
scene.renderCamera(cam);
}

function checkDist(p:Plane):Boolean
{
var p1:Point = new Point(p.x, p.y);
var p2:Point = new Point(con.mouseX, -con.mouseY);
if(Point.distance(p1, p2) < 150)
{
return true;
}
else return false;
}
[/as]


Commentary

  1. db says:

    very very nice :) another great example to get start with papervision

  2. bandar says:

    Wow !!!
    Very nice ..
    :)

  3. Michael says:

    Looks great! Wish I had thought of that! :)

  4. Joao says:

    What kind of class is ColorMaterial? (var cm:ColorMaterial = new ColorMaterial(Math.random()*0xFFFFFF);)

  5. angelo says:

    Stylish….
    Nice one.

  6. Dhaya says:

    That’s just awesome. Great idea !

  7. Dave Gamez says:

    Nice example of papervision 3D and nice example of Tweener too !!!

  8. Edward McIntyre says:

    Nice! That would make a great thumbnail menu.

  9. Greg Ferrell says:

    WOW! I have been waiting to see a real world example of papervision. Everything has usually been over the top or not practical, but this could be amazing!

    Thanks lee.

  10. LEE says:

    super sweetness Lee! Glad to see your visual math prototype skills are still strong!

  11. You will force me to leave Flash Sandy and use papervision :D

  12. oren says:

    wow…great concept and nice outcome as well :-) .
    Thanks for sharing.

  13. LEE says:

    Isnt the false hope in these type of pv3d prototypes that to give those planes interactive bitmapmaterial assets, and implement this into a typical Flash site, it chokes most users systems to unacceptable levels?

    Its really cool, and with interactive bitmap materials may perform well solo, but kill your fps as soon as you add some fancy buttons, logo animations, object transitions, etc?

    Its been quite awhile since Ive tried incorporating pv3d into our sites, maybe the newer releases perform faster?

    Either way this is very cool!

  14. stef says:

    Really nice ;)

  15. Tink says:

    Beautiful example

    “but kill your fps as soon as you add some fancy buttons, logo animations, object transitions, etc?”

    Most of the stuff we’ve done with PV3D we’ve seprated the stuff out. I.e. you get all the 3D stuff, then once you’d chosen an item, you’d seamlessly move to 2D for the interface with your animations and fancy buttons.

  16. Iain says:

    Mate – that rocks. Do we really need another demo with a black background though? ;)

    There’s so many colours to choose from!

  17. andrew says:

    adding tweens in an enterframe loop? does it make sense?

  18. Paul says:

    Lee, thanks for this. Would you be willing to do a tutorial on the APE api..? I’m a physics teacher an I’d love to learn more about that as I think I could work it into teaching.

    Just a thought.

    Paul

  19. Daniel says:

    Hey Lee!

    I just recently started following your site and this another great example of why I do. You provide great info and some awesome examples. Keep up the great work!

    -Dan

    On a side note, your web site (http://www.leebrimelow.com/) is just showing the default apache page.

  20. lee says:

    Andrew, I’ve never been known as someone who makes examples that make sense :)

  21. Dude that is a great idea and execution. You are a true Devigner.

  22. Rackdoll says:

    Nice work Lee!
    Thnx for sharing the code also!

  23. pixelmixer says:

    Carlos Ulloa did something almost identical to this a while back.
    Here’s an example of using this technique for a real life porfolio site.
    http://www.noventaynueve.com/portfolio/index.html

  24. LEE says:

    Wowly-moly! http://www.noventaynueve.com/portfolio/index.html

    That’s rad! My earlier question about performance is answered. This works really well.

  25. lee says:

    Yeah and I’m sure Carlos’ implementation is much cleaner than mine. using Tweener isn’t the most performant way of doing this kind of thing.

  26. Adam Moss says:

    Great work Lee, I like it.

  27. Ain says:

    FYI: broken on Papervision3D 2.1 rev920 (August 11th, 2009). Scene3D does not take a container clip there anymore.

Leave a Comment