Guide to Getting Started in Papervision 3D
Building your First Papervision Application
What goes into a Papervision Scene?
At first it can be a little bit overwhelming when looking at the sheer number of classes that come with Papervision. But fear not, these are of no concern to you (yet).
Think of a Papervision world as a movie set, there are actors, props, cameras, costumes, and a ton of other things. You as a director just have to look/ask around to see who and what you need for this particular scene. There are always the basic necessities though: a camera and a stage.
Fortunately, the developers of Papervision thought of that for you and set up some basic classes that you can use to get started with all the necessities in them already; the most common of them being the BasicView.
Setting up the Basics
Let’s start off by taking advantage of the BasicView class by extending it, because BasicView extends Sprite we can make it our document class in Flash.
We will create a main class for our application and call it HelloPapervision.as and enter the following:
-
import org.papervision3d.view.BasicView;
-
public class HelloPapervision extends BasicView {
-
public function HelloPapervision() {
-
trace("hello papervision");
-
}
-
}
-
}
That is all well and good, but it didn’t do anything other than set up a scene and trace a couple things to the output window. So now we will work on adding some content to the scene.
Working with Primitives
The first thing that we need to do is figure out what we want to add, here I will show you how to add some basic shapes (primitives). You can take a look at the documentation for the included primitives here: http://www.papervision3d.org/docs/as3/org/papervision3d/objects/package-detail.html
Adding primitives is simple, it is just like creating an instance of anything else on the stage. You simply import the correct class, create an instance and add it to the scene.
-
import org.papervision3d.objects.primitives.PaperPlane;
-
import org.papervision3d.objects.primitives.Sphere;
-
import org.papervision3d.view.BasicView;
-
-
public class HelloPrimitives extends BasicView {
-
-
// create a sphere and a paper airplane
-
// create these at class level in case they are to be used in other functions later
-
var myFirstSphere:Sphere;
-
var myFirstPlane:PaperPlane;
-
-
public function HelloPrimitives() {
-
-
myFirstSphere = new Sphere();
-
myFirstPlane = new PaperPlane(null, 3);
-
// move the plane in 3d space
-
myFirstPlane.x = 150;
-
myFirstPlane.y = 150;
-
myFirstPlane.z = -50;
-
// add the objects to the Papervision scene
-
scene.addChild(myFirstSphere);
-
scene.addChild(myFirstPlane);
-
// this is an inherited method (onRenderTick) that starts an
-
// enterframe event to render the scene
-
startRendering();
-
}
-
}
-
}
Hopefully this little addition didn’t scare you off. All that I have done is created a Sphere and a Paper Plane, moved the plane and added the items to the scene. Simple, right? But what are shapes without materials? Boring !
Working with Materials
It is possible to get away without using materials on most objects, but it because a very confusing scene if everything is sitting there without proper textures. Papervision allows for numerous types of materials that you can apply to different parts (or all) of your objects. You can take a look at the documentation for the materials here: http://www.papervision3d.org/docs/as3/org/papervision3d/materials/package-detail.html
Creating a material is much like creating a primitive, just instead of adding the material to the scene, you apply it to the object.
-
import org.papervision3d.materials.ColorMaterial;
-
import org.papervision3d.materials.MovieAssetMaterial;
-
import org.papervision3d.objects.primitives.PaperPlane;
-
import org.papervision3d.objects.primitives.Sphere;
-
import org.papervision3d.view.BasicView;
-
-
public class HelloMaterials extends BasicView {
-
// create a sphere and a paper airplane
-
var myFirstSphere:Sphere;
-
var myFirstPlane:PaperPlane;
-
-
public function HelloMaterials() {
-
// create a movie material for the sphere from the library
-
var sphereMaterial:MovieAssetMaterial = new MovieAssetMaterial("sphereMaterial");
-
// create a color material for the plane
-
var planeMaterial:ColorMaterial = new ColorMaterial(0×55FF11);
-
// set the properties of the sphere instance
-
// set material, radius and segements
-
myFirstSphere = new Sphere(sphereMaterial, 100, 12, 12);
-
// set the properties of the paper plane instance
-
// set the material and the scale
-
myFirstPlane = new PaperPlane(planeMaterial, 3);
-
// move the plane in 3d space
-
myFirstPlane.x = 150;
-
myFirstPlane.y = 150;
-
myFirstPlane.z = -50;
-
// add the objects to the Papervision scene
-
scene.addChild(myFirstSphere);
-
scene.addChild(myFirstPlane);
-
// this is an inherited method (onRenderTick) that starts an
-
// enterframe event to render the scene
-
startRendering();
-
}
-
}
-
}
All that we did here was we took what we did in the HelloPrimitives class and brought in a couple of materials. One thing to note is the use of the MovieAssetMaterial, for this I had to create a MovieClip in the Flash library and export it for actionscript (Linkage). Once defined, the materials can be used on any object, over and over again. You can even compound materials if you want to, but that is beyond the scope of this tutorial.
Playing in 3D Space
So now you know how to create objects and make them look half-way decent. But what about animation? I am sure that you don’t want to stop with static objects on your stage, what a boring movie that would be.
Well, little do you know, you have already started the animation when you wrote startRendering. That told Papervision to call its renderer and renders the scene every frame that passes.
-
import flash.events.Event;
-
import org.papervision3d.materials.ColorMaterial;
-
import org.papervision3d.materials.MovieAssetMaterial;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.objects.primitives.PaperPlane;
-
import org.papervision3d.objects.primitives.Sphere;
-
import org.papervision3d.view.BasicView;
-
-
public class HelloAnimation extends BasicView {
-
-
// move the definitions out here so the whole class can get them
-
private var myFirstSphere:Sphere;
-
private var myFirstPlane:PaperPlane;
-
private var pivotContainer:DisplayObject3D;
-
-
public function HelloAnimation() {
-
// create a movie material for the sphere from the library
-
var sphereMaterial:MovieAssetMaterial = new MovieAssetMaterial("sphereMaterial");
-
// create a color material for the plane
-
var planeMaterial:ColorMaterial = new ColorMaterial(0×55FF11);
-
planeMaterial.doubleSided = true;
-
// create a sphere and a paper airplane, increase the triangles on the sphere
-
myFirstSphere = new Sphere(sphereMaterial, 100, 12, 12);
-
myFirstPlane = new PaperPlane(planeMaterial, 3);
-
// move the plane in 3d space
-
myFirstPlane.x = 150;
-
myFirstPlane.y = 150;
-
myFirstPlane.z = -50;
-
// set an initial rotation for the plane
-
myFirstPlane.rotationY = -135;
-
// add the sphere to the scene
-
scene.addChild(myFirstSphere);
-
// add a container to use for pivoting the plane rotation
-
pivotContainer = new DisplayObject3D();
-
// add the plane to the container
-
pivotContainer.addChild(myFirstPlane);
-
// add the container to the scene
-
scene.addChild(pivotContainer);
-
// this is an inherited method (onRenderTick) that starts an
-
// enterframe event to render the scene
-
startRendering();
-
}
-
-
override protected function onRenderTick(event:Event = null):void {
-
// rotate the pivot container (will offset the plane rotation)
-
pivotContainer.rotationY += 1;
-
// rotate the sphere
-
myFirstSphere.rotationY -= 1;
-
// make sure that it is calling the renderer
-
super.onRenderTick();
-
}
-
}
-
}
Now things are getting interesting ! Lets break down what happened here. In an attempt to make the paperplane orbit around the sphere, we had to create a container for it to act as a pivot point. To do this, we created a DisplayObject3D (do3d) object in the scene which is basically like a blank MovieClip. The reason we use the do3d is because it is empty but it can have children and maintains properties that we can then animate (just like in this example).
This is our first time using the onRenderTick method. Since the method is protected, we had to override it and we eventually call the super at the end. This method is what that startRendering call starts. It is just an onEnterFrame that tells the renderer to render the scene, overriding and using this method is helpful for many types of animation and interactivity in the Papervision world. We have added two lines of code here that simply rotate our object. Notice that the Plane isn’t listed, but it is animating. That is because it is a child of the pivotContainer and the pivotContainer is set to rotate.











June 19th, 2008 at 3:38 am
This is amazing. Can’t wait to study it. Thanks! Keep it up
July 2nd, 2008 at 2:45 am
Sweet. Nice work.
July 22nd, 2008 at 11:38 am
Good site I “Stumbledupon” it today and gave it a stumble for you.. looking forward to seeing what else you have..later
August 12th, 2008 at 10:24 am
I always read your blog in high spirits. Thanks
August 19th, 2008 at 3:23 pm
That’s the writing style that tickles me.
August 22nd, 2008 at 1:15 pm
Awesome. I’m getting a spot in line to get a look at the source code.
October 16th, 2008 at 5:05 pm
nice picture
November 2nd, 2008 at 11:22 pm
yes, keen to see the source code as I had a similar idea… what res is the camera running at? perhaps it might be better to use coloured paper or LED’s mounted on saftey goggles like your wimote head tracking… you could then easily track the location of the two coloured LED’s as you would infra-red leds.
heres an experiment I made a while ago with flash webcam… nothing to do with headtracking (yet)
http://hydroplain.blogspot.com/2008/10/this-is-as3-time-slicing-demo-i-was.html
November 6th, 2008 at 5:05 pm
Wowww realy great flash animation
I want to Macromedia flash for my new Güvenlik ve kamera sistemleri web pages. but havent got time
November 12th, 2008 at 3:07 pm
http://www.marcpelland.com/motion3dController.zip
January 19th, 2009 at 7:01 am
Wow. Super!
March 9th, 2009 at 11:38 am
this could prolly be applied to an IR camera and IR leds. just a thought
March 9th, 2009 at 12:15 pm
I was thinking about using IR LEDs but I wanted to try and make it work with just a user and a webcam. I am trying to find more time to play with the idea, have been thinking about connecting Processing and Flash and using the OpenCV Face Detection Library to track the motion. So far, I have been unsuccessful but I am getting there
April 18th, 2009 at 11:17 am
Thanks for these great tutorials!
May 2nd, 2009 at 8:36 am
its would be nice to show a way without always using he document class in the flash IDE. I find just using the document class is limiting in real world projects. Most times there are other elements in a flash website and this approach limits you.
May 7th, 2009 at 1:19 am
thanks for this. I appreciate it! it’s a great orientation!
May 8th, 2009 at 1:04 pm
“its would be nice to show a way without always using he document class in the flash IDE. I find just using the document class is limiting in real world projects. Most times there are other elements in a flash website and this approach limits you.”
I agree, and even more difficult when you have to work with a team of flash timeline only designers
still, great tutorial!
May 8th, 2009 at 1:09 pm
it would be very easy to port most of the tutorial files over to pure AS3 (no document class). the only instance where it would become an issue is with the movieassetmaterial. however, i believe you could do something along the following:
[Embed(source = "/materials.swf", symbol="sphereMaterial")]
private var sphereMaterial:Class;
from there you could just create an instance of that class as a clip and use it as a material.
May 8th, 2009 at 5:22 pm
Hi again, on Flash CS4, I got the “1084: Syntax error: expecting rightparen before 55
May 8th, 2009 at 6:17 pm
can’t help much without seeing the code that you are using or knowing which file you are working with.
can you send me an email with a more detailed description of your issue?
May 20th, 2009 at 11:54 pm
“Hi again, on Flash CS4, I got the “1084: Syntax error: expecting rightparen before 55″
Got the same. This is the line causing the problem:
var planeMaterial:ColorMaterial = new ColorMaterial(0×55FF11);
If you copy and paste the code I get an error because of the little ‘x’. Just retype the x and that should fix it.
May 22nd, 2009 at 12:53 pm
Coot tutorial! Tenx!
May 25th, 2009 at 1:30 pm
Thank you so much. This was the first tutorial on Papervision that actually compiled. Not even the offical website’s sample code worked properly. You did a great job covering the essentials.
A few suggestions:
-Copying your sample code on the webpages inserted extra lines and “#” symbols. Oops.
-A couple screenshots and trace messages from your compiled samples would have helped reaffirm my progress.
May 28th, 2009 at 4:22 pm
Anyone else get this error?
ReferenceError: Error #1065: Variable sphereMaterial is not defined.
I am using Flex Builder 3 and I am using the code in a new action script project.. am I missing an import?
any help would be great
thanks.
Love the Tutorial
June 1st, 2009 at 10:05 am
I’m also getting
ReferenceError: Error #1065: Variable sphereMaterial is not defined.
Dunno what to do with it.
June 1st, 2009 at 10:11 am
using Flash CS4 with Papervision3D Public Alpha 3.0 - PapervisionX (18.09.08)
June 1st, 2009 at 10:19 am
FCX have you created the sphereMaterial clip in your library? or created a bindable instance of it in your source if you are not in flash IDE? that needs to be created in order to avoid that error…
June 1st, 2009 at 10:33 am
No, I didn’t. Now works great!
Amazing tutorial!
June 1st, 2009 at 8:28 pm
I know this is an old post, but I just wanted to say THANK YOU! This tutorial was so easy to follow, and I’m really excited to have my first Papervision demo working
Thanks again!
June 2nd, 2009 at 2:10 pm
Awesome tutorial. I have a question though, I uploaded the source code and it loads great in firefox but not in IE6, do you know why? I can’t figure it out. Thanks!
June 4th, 2009 at 8:29 am
I’m a 3D animator who’s just been briefed in a hurry to create with Papervision, it’s crash course of note! I’m using FlashMX ver6 and have no Actionscript 3.0 settings in Flash EDIT/PREFERENCES as mentioned in the tut above?:
‘Once you are synced up with the repository I would recommend loading Flash and going to Edit > Preferences. Go to the ActionScript category and select ActionScript 3.0 Settings’.
any help most appreciated?!
June 5th, 2009 at 2:52 am
Can anyone please help me. How to draw the bar chart using Papervision with 3D effects(Multi dimension). Please give me some guidance and sample.
Thanks
June 16th, 2009 at 12:34 am
thanks for guiding my first pv3d steps
June 20th, 2009 at 5:15 pm
I very much appreciate the tutorial! I didn’t know I needed to make an .fla file of that class to compile it until I downloaded the source. Now I know. And so does everyone else ;^)
June 25th, 2009 at 11:31 am
Nice work, i’m waiting for a next Chapter. I like ur portfolio, some many interesting projects.
Dom, to run actionscript u need flash cs3. Older version only works with actionscript 1.0 and 2.0.
Bye
July 25th, 2009 at 12:14 am
As well as how to harness tools that have been created for you to build your own 3D experiences.For you, we are providing cheap age of conan power leveling for you, enjoy it.
July 31st, 2009 at 9:17 am
Hello, I’m having an issue with the step two. FlashDevelop & Flash says: The Type HelloPrimitives does not match the file name:…
August 24th, 2009 at 8:16 am
this could prolly be applied to an IR camera and IR leds. just a thought
August 24th, 2009 at 8:22 am
I always read your blog in high spirits. Thanks
August 24th, 2009 at 8:24 am
Dom, to run actionscript u need flash cs3. Older version only works with actionscript 1.0 and 2.0.
August 28th, 2009 at 7:03 am
How Can I work just with Adobe Flash Cs4?
All tutorials worlks with Flex and I’m not freanly with this aplicattion,
Need I change to these aplicattion?
thanks!
August 28th, 2009 at 7:05 am
I always have the same error:
“5008: El nombre de la definición ‘HelloPapervision’ no contiene la ubicación de este archivo. Cambie el nombre de la definición en este archivo, o cambie el nombre del archivo. K:\Documents and Settings\Cris\Escritorio\As3\Papervision3D_2.1.920\e01.as”
ups, ! is in spanish! I hope the error number can show you whats going on?
August 28th, 2009 at 7:20 am
ok! done!
I have to undestand more acurate AS3!
Congratulations fot this tutorial,
September 12th, 2009 at 7:26 am
Thank you for sharing really worked to my jobs
September 17th, 2009 at 8:06 am
hello
cud you make a tutorial teach how to usin flartoolkit (wich webcam) and show a maya collada object in swf…
tks!!!!
September 24th, 2009 at 12:22 pm
Awesome tutorial, this is something I was looking for to get me started with Papervision. One thing though: I get a “lookAt error” with the HelloClickability code…
October 5th, 2009 at 7:15 am
Hey.. nice work..
I get the cam feed and such, but when I run I get error
1017: the definition of base class ObjectContainer3D was not found..
Any help…
November 5th, 2009 at 9:30 am
Hi;
I really like your papervision tutorial; it’s one of the few understandable beginners guides I could find!
Anyway, I guess I have my FlashDevelop setup wrong. All I get when playing / publishing is a white background, instead of the primitives and stuff. FlashDevelop says “Build Succeeded”, but I’m not sure though.. Could you help me out?
thanks in advance;
Ruben
November 21st, 2009 at 4:40 pm
Nicely done!
Finally a tutorial for us mere mortals…
Papervision3D is no joke…you’d better eat your Wheaties…
Thanks much!
November 24th, 2009 at 10:34 pm
Hi,
Thanks for uploading a great primer to Papervision3D! Really helped me get started on it =)
Thanks!
November 30th, 2009 at 12:59 pm
ReferenceError: Error #1065: Variable sphereMaterial is not defined.
This was a headache for me. I was hunting down trying to add the MovieAssetMaterial class into the library, trying to figure out the PV3D component to see if i can drag something to the library, etc. Nothing worked, till i went to the MovieAssetMaterial documentations.
So,
To clarify to noobish users such as myself, you’d need to create a new MovieClip in the Flash IDE library, name it sphereMaterial, then click on “Export for Actionscript”….
It should now work fine.
I have never worked with flashdevelop or flex before, i have been working with the Flash IDE itself, so i wish more things had been spelled out for me, like the jump from setting up FlashDevelop to actually making a new document. I didnt know Flash IDE had to be up and running for FlashDevelop to run, and I didnt know I had to create a .fla file like usual, set the HelloPapervision document class in Flash IDE so that i can run the HelloPapervision.as code.
I came into this completely new to FlashDevelop or Flex, so the unspelled things provided me with hours of consulting other guides.
I appreciate the guide so far, it has carried me further than any other ones online. Just my input so its more newbie friendly :). Especially since i am not stuck in the actual coding part…but the actual setup of paths/classes/libraries part.
thanks for the efforts!
December 16th, 2009 at 12:57 pm
Yeah - that “Error #1065: Variable sphereMaterial is not defined” threw me a bit too. I work in a combination of Flash IDE and Flex Builder 3, but unlike with FlashDevelop I can use Flex Builder to compile.
MovieAssetMaterial needs to be passed the name of a MovieClip object in order to instantiate properly. So here’s how I did it…
Drag a jpg into Flash (mine was of bricks) and create a MovieClip from it. Tick “Export for Actionscript” (if you don’t know where that is then learning Papervision is probably trying to run before you can walk), call the Class “Bricks” and subclass (”Base Class” they call it there) MovieClip - which should be the default.
Now that you’ve created your MovieClip, publish the fla (ensuring you have “Generate SWC” ticked in your publish settings to create a SWC library along with the SWF.
In Flex Builder > Project > Properties > Actionscript Build Path > Library Path, hit “Add SWC” and add your SWC in order to access your MovieClip with a jpg in it.
You can then instantiate it using var bricks:Bricks = new Bricks() or whatever you called it. And then “sphereMaterial = new MovieAssetMaterial(”Bricks”)” will work.
Anyway - that’s one way of doing it in Flex Builder 3, the important thing as far as I can see is that MovieAssetMaterial is passed a MovieClip object that it can use.
January 2nd, 2010 at 6:58 am
Great tutorial, no “have you seen me” coding and great explanations!
Thanks
January 25th, 2010 at 4:44 pm
Thanks for this!!!
February 15th, 2010 at 2:20 pm
awesome tutorial.. thanks for your hard work!!
March 1st, 2010 at 7:54 am
Thanks for the tutorial, mate. It is excellent: smooth to follow and right-to-the-point.
We’ll be using papervision3D for nice projects at the university of Espírito Santo, Brazil, as part of the graphic design lab group.
Thanks again!