Animating vertices in Papervision3D

Click to see the demo

Rotating cubes, planes and spheres in 3D is fun. However this time, I thought that I’d try something less basic when it comes to 3D animation. So here’s the idea: the Papervision3D universe is composed of triangles. Each object is a structure formed of one or more of them. The points where the triangles meet are called vertices (plural for vertex). A vertex, represented by the class Vertex3D, is basically a point in the 3D space with a ‘x’, ‘y’ and ‘z’ coordinates. The interesting part is that each of those vertices can be manipulated separately.

Click on the image above to view a demo. Once I grasped the basic idea that vertices can be manipulated, such effect was pretty simple to acheive. First I create a plane, I add a bitmap texture, and then I access the vertices of the plane one by one and manipulate their ‘z’ property.

For the animation I create a small bitmapData object and apply the perlinNoise on it at each frame with different settings to create this illusion of wavy movement. Then I translate the color value of each pixel to the ‘z’ property of each vertex in the 3D plane. Later I multiply this value by stage.mouseX, so the effect will vary in intensity depending on the mouse position… And voilà! I have a waving flag, a small piece of a stormy sea, a rodeo-style magic carpet or whatever.

Move your mouse cursor around from the right to the left side of the screen. Click anywhere to switch between a bitmap texture and a wireframe texture. In the wireframe mode the movement of the vertices is much easier to spot and understand.

BTW. I created a project on Google Code because I needed an SVN account for personal use, but I discovered that the code browser is also pretty cool for sharing stuff and it even formats AS3 in a nice way! So, if you are interested in the source for this example, it is here.

7 Responses to “Animating vertices in Papervision3D”

  1. Source | Animating vertices in Papervision3D « Flash Enabled Blog Says:

    […] The interesting part is that each of those vertices can be manipulated separately.” View the demo and download source file […]

  2. Dan Says:

    Very cool! I just happened across your site. This animation is very nice. It looks so fluid and beautiful. Now I’m going to have to see what else you got here…

  3. Mike Says:

    Hi Bartek,

    I can not thank you enough for putting this up. I was able to create a 3D plotter using this code. The address is below

    http://nkuflc.org/sincplot/

    I acknowledged your work at the bottom of the project and linked back to this site. When I get it up on Youtube and Google Code I will put the link here.

    Thank you so so much for your incredible work on this!!!

  4. bartek drozdz Says:

    @Dan. Thanks. The blog is pretty new so you won’t find much now, but I will try to post new stuff on a more-or-less-regular basis.

    @Mike. I am glad that my code was helpful to you, and thanks for the acknowledgement. I release all my sources under the MIT license, so you are free to use it anyway you want (just so you know…)

  5. Mike Says:

    Thanks so much!

    My Google Code is at

    http://code.google.com/p/flex3cookbook1/downloads/list

    and the YouTube videos are at

    3D Plotter in Papervison3D and Flex 3 (1 of 2)

    http://www.youtube.com/watch?v=YlFLT9YA444

    3D Plotter in Papervison3D and Flex 3 (2 of 2)

    http://www.youtube.com/watch?v=TvpIFLLLKp8

    Another application of this is to use it as a terrain builder for games.

    Once again, thanks so much - I didn’t have a clue on how to do this
    until your video.

    Best Regards,
    Mike Lively

  6. pv3d.org - Papervision3D Tutorials » Blog Archive » Other Resources Says:

    […] http://www.everydayflash.com/blog/index.php/2008/05/05/vertex-animation-papervision3d/ http://www.everydayflash.com/blog/index.php/2008/05/16/road-trip-papervision3d/ […]

  7. Richard Butler Says:

    Excellent work, Im not too bad on Papervision but this has saved me loads of time as youve already done it, and it runs nice. just what I needed to animate some flags, Hope I can help you out some day, thanks again.

Leave a Reply