Set Up Papervision 2.0 for Flex 3 in 3 Minutes Flat
Sep 18
Technology 3d, actionscript, flex, papervision 24 Comments
Anybody who knows me knows that I’m all about quick and dirty, get it done, up and running and worry about it later. I don’t like to waste time and I’m sure you don’t either. If you want to set up Papervision Great White for Flex fast, you’ve come to the right place. You got your timer ready? Here we go:
- Create a new Flex project, called it FlexPapervision Base. Time elapsed: 20 seconds.
- Drop the Papervision library into your libs folder. You can download the Papervision library at the Google Code repository, but that’s too messy and going to take too much time. I’ve taken the liberty of downloading it and compiling it into an easy to consume swc right here. Time elapsed: 15 seconds. [If you are using Eclipse, create a libs folder in your project. You'll also need to add the libs folder to your build path - Go to Project -> Properties -> Flex Build Path -> Library Path, and add the libs folder]
- Assuming you have some Flex basics and Papervision basics, here’s the essential code:
// these 3 lines are key to putting Papervision in Flex
var uicomp:UIComponent = new UIComponent();
canvasPv3D.addChild( uicomp );
uicomp.addChild( viewport );
canvasPv3D is just a regular Flex Canvas. You add a Papervision viewport to a UIComponent which can then be added to a Flex Canvas. That’s it. Here’s the complete FlexPapervisionBase.mxml file
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onInit(event);">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.primitives.Plane;private var renderer:BasicRenderEngine = new BasicRenderEngine();
private var scene:Scene3D = new Scene3D();
private var camera:Camera3D = new Camera3D;
private var viewport:Viewport3D;private var plane:Plane;
private var angle:int = 0;
protected function onInit( event:Event ) : void {viewport = new Viewport3D(canvasPv3D.width, canvasPv3D.height, true, true);
// these 3 lines are key to putting Papervision in Flex
var uicomp:UIComponent = new UIComponent();
canvasPv3D.addChild( uicomp );
uicomp.addChild( viewport );
camera.z = -500;
var mat:ColorMaterial = new ColorMaterial();
mat.doubleSided = true;
plane = new Plane(mat, 200, 200, 4, 4);
scene.addChild(plane);
// update the scene every frame
canvasPv3D.addEventListener(Event.ENTER_FRAME,onEnterFrame);
}private function onEnterFrame( event : Event ):void {
angle = angle+=1%360;
plane.rotationY = angle;
// render the scene on every frame
renderer.renderScene(scene,camera,viewport);
}
]]>
</mx:Script>
<mx:Canvas id="canvasPv3D" width="100%" height="100%"/>
</mx:Application>
All this project does is put a 3D plane in the scene and rotates it 1 degree every frame.
Time to read this bullet point and copy paste this piece of code into your project: 40 seconds.
If you’re feeling super lazy and can’t even be bothered to create a project of your own, here’s the project: FlexPapervisionBase.zip
This is what the end product looks like:

Your welcome.
Popularity: 33% [?]
Related posts:







Oct 15, 2008 @ 00:00:54
Thanks a lot for this. I was trying to set up something simple in “flash develop”, but could not make it work. Now having this in Flex is a good starting point for me to try and crasp the concept.
Kind regards, Robert
Oct 16, 2008 @ 20:01:39
Hey Robert.
I’m glad this was useful to someone. Good luck with Papervision3D. Also, look into Away3D as well. Setting it up in Flex is pretty much the same.
Nov 08, 2008 @ 08:47:18
Thanks a lot!
I was trying to put pv3D working into Flex last night.. i wish i read your post 10 hours ago haha
Dec 10, 2008 @ 21:18:56
You are awesome. thank you. In addition to being lazy and ignorant, I am cheap, so am compiling using just the sdk (plus, using linux so why not try for fully free anyway). luckily, with your zip file it’s super easy, just add the papervision sources to the directory with the .mxml file and run your build file. charms. so awesome, thanks again.
Dec 10, 2008 @ 21:22:24
Glad it was helpful. Did you do it in under 3 minutes?
Dec 10, 2008 @ 21:32:12
ha, that depends… slow reader… so it probably took me 3 minutes to read up to “if you’re super lazy”, at which point I realized that I needed to give this a try. after than, under 3 minutes for sure!
I’ve bashed my head on trying to do this with just the sdk, and what has been frustrating is (in addition to the paucity of non-.fla examples) wading through overly complex set-ups. there are some good tutorials that work, but for a beginner this is a perfect starting point upon which to “build by doing”.
Dec 15, 2008 @ 23:42:11
The first example which worked for me, thx a lot! But I have one question:
How do I add a UIComponent, let’s say a TextField or a HBox, to the whole 3D scene (or plane, I don’t know where to add), so that it appears on the plane, or, what would even be better, it appears instead of the plane.
Dec 15, 2008 @ 23:59:36
Hmm, it’s a great question. That’s a good topic for a possible next tutorial.
Dec 16, 2008 @ 00:22:23
yep, looking for something like this since yesterday now ^^
Dec 16, 2008 @ 01:19:47
finally I figured something out based on your code here, I will post an example as soon as I debugged it.
Dec 16, 2008 @ 05:34:37
Here is a very simple example. I’ve tried to add some more functionality (like adding a HBox and then adding a Button to the box in runtime), but couldn’t get them to work properly yet.
http://wet-media.de/dev/papervision/simple/Papervision.html
Dec 16, 2008 @ 10:13:43
Nicely done Sheik. My first question after reading this post was “Where do I go from here?” You’ve answered it.
Mar 13, 2009 @ 02:20:59
Hi, Pek!
Good job!
I tried to set the position of the purple square to the top left of the application window but didn’t succeed. Any ideas?
Mar 25, 2009 @ 23:11:20
Hi mozz,
There are many ways to do it. You can either move the camera by setting its coordinates (x, y, z), you can move the plane by setting its coordinates, or you can specify the size of the canvas and position that canvas wherever you want.
Apr 18, 2009 @ 13:01:14
Hi,
i’ve got a question, that i couldn’t answer, since i’m new to Flex even though i searched around for couple weeks.
is it possible to instantiate the papervision code from an external file, meaning not in the ?
i think it’s not elegant to put the logic programming code in the middle of the block just below the MXML code.
I would like to use a this mxml code as a base, and depending on the class i instantiate, have different papervision projects open.
Is there anyway to do this?
Thanks,
Andre
Apr 18, 2009 @ 21:00:38
Hi Andre
You can absolutely instantiate papervision code from an external file not in an MXML. You can create different MXML components (each w/ their own papervision scenes/models that the main MXML loads or have separate Papervision classes that the main MXML instantiates depending on parameters.
P
May 26, 2009 @ 02:05:37
nice sample. Its actually 1min. if you used the zip
Jun 10, 2009 @ 06:33:12
Hellooo ! I’m working with augmented reality and i want to create a plane with a movie but i have a problem. could it be possible to send you the code?
Aug 10, 2009 @ 07:55:26
Thanks bro – good tut.
Sep 25, 2009 @ 07:04:29
Bloody marvelous! Getting PV3D running has been driving me to the edge of sanity for the past 48hrs – thank-you one thousand times thank-you – Huzzah!
Oct 15, 2009 @ 04:15:06
Thanks ; I was using a book ‘papervision essentials’ but it has errors in the downloaded examples . With your help I am good to go, very good of you to help us.
Feb 11, 2010 @ 16:19:27
<30secs.
I wish there were more like you around, I truly do.