HODGEDEV FLASH BLOG

Papervision3D

Papervision 3D: Great White and MD2

by Brian Hodge on Feb.27, 2009, under Papervision3D

The studio that I am working at, Streetwise, has had me checking out the various 3D engines available to Actionscript3.  I played with Papervision3D first and was immediately disappointed with the lack of tutorials.  I then moved onto Away3D because it appeared to have an abundance of tutorials all delivered on an easy to navigate, well constructed website.  After a few projects in Away3D it became apparent to me that Away3D is a “PORT” of Papervision3D, meaning it borrows from, or ” EXTENDS”, from Papervision3D.  After asking some other developers on stackoverflow.com, I came to the conclusion that I needed to give Papervision3D another shot.  Thanks to google, I found more tutorials and a strong backing behind Papervision3D.  When I was looking around at was being done out there, I stumbled upon http://www.saveyoursensible.com, a neat little site that utilizes a 3D character that you can interact with.  I was reading somewhere where people were discussing this mixture of Papervision3D and an md2 for light-wieght, low poly, character animations.  I found a quake model that I like, downloaded the md2 and used the following to produce it in the flash runtime.  The following shows how to render and md2 in the flash runtime using the Papervision3D API.

  1.  
  2. package com.streetwise.ui
  3. {
  4. import flash.display.Sprite;
  5. import flash.events.Event;
  6. import org.papervision3d.view.Viewport3D;
  7. import org.papervision3d.scenes.Scene3D;
  8. import org.papervision3d.cameras.Camera3D;
  9. import org.papervision3d.events.FileLoadEvent;
  10. import org.papervision3d.materials.BitmapFileMaterial;
  11. import org.papervision3d.objects.parsers.MD2;
  12. import org.papervision3d.render.BasicRenderEngine;
  13. public class Main extends Sprite
  14. {
  15. private var viewport:Viewport3D;
  16. private var scene:Scene3D;
  17. private var camera:Camera3D;
  18. private var _quakeGuy:MD2;
  19. private var renderer:BasicRenderEngine;
  20. public function Main():void
  21. {
  22. if(stage) init();
  23. else addEventListener(Event.ADDED_TO_STAGE, init);
  24. }
  25. private function init(e:Event = null):void
  26. {
  27. viewport = new Viewport3D(550, 400, false, true);
  28. addChild(viewport);
  29. scene = new Scene3D();
  30. camera = new Camera3D();
  31. renderer = new BasicRenderEngine();
  32. camera.zoom = 400;
  33. camera.focus = 12;
  34. _quakeGuy = new MD2(false);
  35. _quakeGuy.rotationX = -90;
  36. _quakeGuy.rotationY = -90;
  37. _quakeGuy.addEventListener( FileLoadEvent.ANIMATIONS_COMPLETE, onAnimationsComplete );
  38. _quakeGuy.load("assets/quakeguy/tris.md2 " , new BitmapFileMaterial("assets/quakeguy/quake.png"));
  39. scene.addChild( _quakeGuy );
  40. addEventListener(Event.ENTER_FRAME, _onEnterFrame);
  41. }
  42. private function onAnimationsComplete( event:FileLoadEvent ) : void
  43. {
  44. _quakeGuy.play();
  45. }
  46. private function _onEnterFrame(e:Event):void
  47. {
  48. renderer.renderScene(scene, camera, viewport);
  49. }
  50. }
  51. }

It is important to try things, play with functionality, learn how to dig into the docs make something new.  The more you experiment, the better you get at experimenting.  I was in no way the first to do this, but I now have a great understanding.

The next step is to purchase QTiP, a plugin for 3D Studio Max, which enables you to create your own md2 files complete with animation.  This is how the developers of the sensibles project above achieved their goal.

View Demo

2 Comments :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...