Papervision 2.0 – Getting started from a simple starting example

At first when trying to create my first few Papervision projects it seemed a bit overwhelming. As you work with it more and more you notice that there are really only a few elements for creating a simple Papervision project. Then you can forget about the code and just think about what cool things you can do.

For any Papervision 2.0 project you need:

Actionscript:
  1. //As always your imports
  2. import flash.display.*;
  3. import flash.events.Event;
  4. import org.papervision3d.scenes.Scene3D;
  5. import org.papervision3d.view.Viewport3D;
  6. import org.papervision3d.cameras.Camera3D;
  7. import org.papervision3d.materials.ColorMaterial;
  8. import org.papervision3d.objects.primitives.Plane;
  9. import org.papervision3d.render.BasicRenderEngine;
  10.  
  11. //1) A Scene
  12. var scene:Scene3D = new Scene3D()
  13.  
  14. //2) A Camera
  15. var camera = new Camera3D()
  16. //Setting the camera zoom to 11 will make sure your objects are rendered at 100%
  17. camera.zoom = 11;
  18.  
  19. //3) A view area "viewport" - think of this as your canvas or stage for your 3D objects
  20. var viewport:Viewport3D = new Viewport3D(500,300,false,true,true)
  21.  
  22. //4) A render engine
  23. var renderer:BasicRenderEngine = new BasicRenderEngine();
  24.  
  25. //5) add the viewport to the stage
  26. addChild(viewport);
  27.  
  28. //6) Something in your scene such as a Plane, Cube, Sphere, etc - in this case a plane with a black color material
  29. var plane:Plane = new Plane(new ColorMaterial(0x000000),100,100)
  30. //add your object to your scene
  31. scene.addChild(plane)
  32.  
  33. //7) Create a loop for rendering your animation
  34. this.addEventListener(Event.ENTER_FRAME,render);
  35. function render(e:Event):void
  36. {
  37. //Add some simple animation
  38. plane.rotationY += 2; //Could also be plane.yaw(2);
  39. //Render the scene
  40. renderer.renderScene(scene,camera,viewport,true);
  41. }

Don't forget to download the latest Papervision code

The great thing is that if you build this once into a nice clean class, you can just keep re-using that class as your papervision starting place. Then you can do what you do best, create and have fun!

Start with this and add a cube or different materials and animations. Then toss in some Tweener code to get some cool movement effects. In a few days you'll have some amazing things.

9 Responses to “Papervision 2.0 – Getting started from a simple starting example”


  • Thank you so much for this post, it’s really helpful! I’m trying to create a page turning effect using
    papervision3d 2.0 and have the basic AS for an interactive book. What I can’t seem to figure out is how to create an unfolding effect where as it would open like the top of a box. Any suggestions? Thank you so much again!

  • Hey Jen,

    For the papervision page curl effect the only things I have seen on the internet have been these posts:

    http://www.zeropointnine.com/blog/3d-page-curl-effect-using-papervision3d

    http://danro.net/2007/11/08/pv3d-pageflip-demo/

    I think one of those would get you on track.

    Charlie

  • thanks so much for getting back to me so quickly! that’s definitely a start.

  • hey there, i’m a flash designer/developer but am new to papervision and learn through trial and error – hence lots of exporting, tweaking, and reexporting. papervision always drives me nuts because it takes soooo long to export (like 1 minute on average), and i’m running a fairly fast machine. what’s the deal here?

  • Hey Luke,

    Do you find this with even just a very simple papervision project? Such as just creating a single rotating cube?

    What are the specs on your computer? How much ram? I run a Core 2 Duo with 4 gigs of ram. I usually only run into those types of issues when I have lots of Exported clips or models.

    Charlie

  • This is great, first simple example for Papervision 2.0 I found!
    However, for me, it does not work…

    I get these errors…

    **Error** I:\papervision\as3\trunk\src\org\papervision3d\core\ns\pv3dview.as, Line 1: 1004: Namespace was not found or is not a compile-time constant.
    package org.papervision3d.core.ns

    **Error** I:\papervision\as3\trunk\src\org\papervision3d\core\ns\pv3dview.as, Line 1: 1004: Namespace was not found or is not a compile-time constant.
    package org.papervision3d.core.ns

    I try to delete ASO files and before testing, does not help…

  • Hey Jesper,

    What version of papervision branch are you using? From what I remember this was using the great white branch. If you let me know which you are using I can post an update to match your branch.

    Charlie

  • I copy and pasted the text above and I get this error:

    1004: Namespace was not found or is not a compile-time constant.

    I keep getting this annoying error. Can someone please tell me what this means.

    Also, how do I know what papervision branch I’m using. If I don’t have great white, where can I go to download it?

    Thanks.

  • i am looking for help on what should be simple(!)–i submitted this on “nabble’ but no answers yet, so if anyone can help w/ suggestions, i really appreciate it!!
    the code below represents my attempts at trying to create a simple grid of cubes that rotate on entertng the frame/unfortunately i’m not sure how to target this array via papervision. thanks …

    import org.papervision3d.materials.*
    import org.papervision3d.materials.utils.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.objects.primitives.*
    import org.papervision3d.view.BasicView;
    import org.papervision3d.view.stats.StatsView;
    import org.papervision3d.events.InteractiveScene3DEvent;

    // BasicView (viewportWidth:Number = 640, viewportHeight:Number = 320, scaleToStage:Boolean = true, interactive:Boolean = false, cameraType:String = “CAMERA3D”)

    var w:BasicView = new BasicView(600,400, false, true);
    //w=world/w/camera,viewport,render,scene,

    addChild(w);
    w.buttonMode=true;

    for (var px:Number = 0; px<3; px++) {

    for (var py:Number = 0; py<3; py++) {

    var mone:MovieMaterial = new MovieMaterial(face1,true);
    mone.interactive = true;

    var mtwo:MovieMaterial = new MovieMaterial(face2,true);
    mtwo.interactive = true;

    var mthree:MovieMaterial = new MovieMaterial(face3,true);
    mthree.interactive = true;

    var mfour:MovieMaterial = new MovieMaterial(face4,true);
    mfour.interactive = true;

    var mfive:MovieMaterial = new MovieMaterial(face5,true);
    mfive.interactive = true;

    var msix:MovieMaterial = new MovieMaterial(face6,true);
    msix.interactive = true;

    var cube :Cube = new Cube(new MaterialsList({front:mone, back:mtwo, left:mthree,right:mfour,top:mfive, bottom:msix}),100,100, 100, 10,10,10)

    w.scene.addChild(cube);

    cube.x = -350+px*350;
    cube.y= -280+py*285;
    cube.rotationX=cube.rotationY;

    cube.addEventListener(Event.ENTER_FRAME, onStart);

    }

    }

    w.addEventListener(Event.ENTER_FRAME,onEnter);

    var numCubes:Number=px*py;

    function onStart(evt:Event):void{
    //cube.rotationX+=33;

    for (var i:Number = 1; i <= numCubes; i++) {

    this["cube"+i].rotationY +=33;

    this["cube"+i].rotationX=this["cube"+i].rotationY;

    }
    }

    function onEnter(evt:Event):void{

    w.singleRender();
    }

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word


Follow papervision2 on Twitter

RSS Feed