How to setup Papervision3D in FlashDevelop

In previous post I describe easy steps to simply setup Flashdevelop.
Now let’s setup papervision3D in Flashdevelop.

  • Download and install TortoiseSVN source control from
    http://tortoisesvn.net/downloads.

    You have to restart your computer after installation.

  • Create folder in your hard drive for papervsion3D source, for example “PV3D”, right click to folder >> SVN Checkout.
    Go to Papervision3D google code page:
    http://code.google.com/p/papervision3d/ >> source.
    Copy the SVN checkout address: http://papervision3d.googlecode.com/svn/trunk/.
    Back to the SVN checkout window u have opened, paste the address above in top(url of repository), click ok.
  • Once you finish download, open “PV3D” folder >> branches >> cs4 >> src >> select all files and folders(CTRL+A) >> drag them with right mouse button pressed to your library folder where you keep all external class libraries. If you don’t have one, you can create new folder, mine is: “C:\Library\Flash\pv3d\”. Once you drop them inside your library, from the menu choose: “SVN Export to here”.
  • Open FlashDevelop, Project >> new project >> as3 project
    Name it pv3dexample, open project properties (right click on project name in project panel >> properties).
    Output:  choose dimensions: 400x400, background color white, framerate 30.
    Classpaths: add Classpath >> choose your library folder where u copy  papaervision3D source(In my case it’s C:\Library\Flash\pv3d).
    Compiler options: Allow source path overlap >> true
    You are ready to use Papervision3D library inside your project.

We attach the library for the specific project, if you want to have in all your projects inside flashdevelop we have to add it in global classpath.
Tools >> global classpaths >> add classpath >> choose your library.

Copy the code to the Main.as Class, save and run the project. You should see red rotating cube .

Actionscript:
  1. package
  2. {
  3.     import flash.display.Sprite;
  4.     import flash.events.Event;
  5.     import org.papervision3d.materials.special.CompositeMaterial;
  6.     import org.papervision3d.view.Viewport3D;
  7.     import org.papervision3d.scenes.Scene3D;
  8.     import org.papervision3d.cameras.Camera3D;
  9.     import org.papervision3d.materials.ColorMaterial;
  10.     import org.papervision3d.materials.WireframeMaterial;
  11.     import org.papervision3d.materials.utils.MaterialsList;
  12.     import org.papervision3d.objects.primitives.Cube;
  13.     import org.papervision3d.render.BasicRenderEngine;
  14.     /**
  15.      * ...
  16.      * @author Armen Abrahamyan
  17.      */
  18.     public class Main extends Sprite
  19.     {
  20.         private var viewport:         Viewport3D;
  21.         private var scene:              Scene3D;
  22.         private var camera:    Camera3D;
  23.         private var colmaterial:        ColorMaterial;
  24.         private var wiremateral:        WireframeMaterial;
  25.         private var compmaterial:      CompositeMaterial;
  26.         private var primitive:      Cube;
  27.         private var renderer:         BasicRenderEngine;
  28.         public function Main():void
  29.         {
  30.             if (stage) init();
  31.             else addEventListener(Event.ADDED_TO_STAGE, init);
  32.         }
  33.        
  34.         private function init(e:Event = null):void
  35.         {
  36.             removeEventListener(Event.ADDED_TO_STAGE, init);
  37.             // entry point
  38.             init3D();
  39.         }
  40.         private function init3D():void
  41.         {
  42.             trace("init3D")
  43.             viewport = new Viewport3D(400, 400, false, true);
  44.             addChild(viewport);
  45.             scene = new Scene3D();
  46.             camera = new Camera3D();
  47.             renderer = new BasicRenderEngine();
  48.             colmaterial = new ColorMaterial(0xff0000);
  49.             wiremateral = new WireframeMaterial(0xffffff);
  50.             compmaterial = new CompositeMaterial();
  51.             compmaterial.addMaterial(colmaterial);
  52.             compmaterial.addMaterial(wiremateral);
  53.             var materiallist:MaterialsList = new MaterialsList();
  54.             materiallist.addMaterial(compmaterial, "front");
  55.             materiallist.addMaterial(compmaterial, "back");
  56.             materiallist.addMaterial(compmaterial, "left");
  57.             materiallist.addMaterial(compmaterial, "right");
  58.             materiallist.addMaterial(compmaterial, "top");
  59.             materiallist.addMaterial(compmaterial, "bottom");
  60.             primitive = new Cube(materiallist, 200, 200, 200, 3, 3, 3);
  61.             scene.addChild(primitive);
  62.             addEventListener(Event.ENTER_FRAME, onEnterFrameHandler,false,0,true);
  63.         }
  64.         private function onEnterFrameHandler(e:Event):void
  65.         {
  66.             primitive.rotationY += 2;
  67.             primitive.rotationX += 2;
  68.             primitive.rotationZ += 2;
  69.             renderer.renderScene(scene, camera, viewport);
  70.         }
  71.     }
  72.    
  73. }

Releated Posts


4 Responses to “How to setup Papervision3D in FlashDevelop”


  1. 1 Fred

    Hello,
    Thank you for this good tutorial!!

  2. 2 Albert

    great job , keep on…

  3. 3 Raj

    Thanks a lot, this tutorial was much more straightforward and effective than the others out their.

  4. 4 Bob

    Isn’t working for me. Not sure what I did wrong.

Leave a Reply