July 19, 2007

Papervision3D planets

I’ve been looking at the Papervision3D libraries recently. A while ago we had a request for a planets animation in Flash, and no amount of z-axis trickery would make it look realistic enough for me, so we moved the job into Director, which proved difficult (learning curves being what they are) and I ran out of time and gave up.

Papervision3D has achieved what many Flash developers have been waiting for – a proper 3D engine. It has support for primitives, but also allows import of 3D models via collada XML files. With a few simple commands you can set up a scene and instantiate some 3D objects:

private var planet:DisplayObject3D = rootNode.addChild(new Sphere(null ,50, 20, 20), "Planet" );

And there’s your wireframed primitive sphere. Next job is to start it spinning:


Easy isn’t it? Now all we have to do is make it travel around a centre point. In this case we’ll make the vector a simple circle. Flash talks in radians, so we need to convert degrees to radians when calculating the angle.

private function deg2rad(degree) {
    return degree * (Math.PI / 180);
private var originX:Number = 0;
private var originY:Number = 0;
private var radius:Number  = 400;
private var radian:Number = deg2rad(angle);
planet.x = originX + radius * Math.cos(radian);
planet.z = originY + radius * Math.sin(radian);

So once you’ve created a couple of those, and made a simple ‘sun’ for them to travel around, here’s the resulting Flash movie. I’ve added some simple controls to allow the mouse to move around the scene:

- 2 comments by 2 or more people Not publicly viewable

  1. Robert O'Toole


    19 Jul 2007, 15:00

  2. Cool!

    19 Jul 2007, 15:22

Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.


MXNA link



    Other blogs I like...

    Black Pepper Software

    Eismann-sf Go to 'Comments on: Design News for Web, Graphic Designers'

    Ted On Flex Go to 'Ted On Flash'



    Not signed in
    Sign in

    Powered by BlogBuilder
    © MMXXI