Papervision3D in 5 minutes

Having had Ralph over to our user group last Thursday was a real inspiration to get experimenting with Papervision3D again. Last night I decided to try out John Grdn’s new PV3D components for the Flash IDE — I was stunned.

Its been ages since I last played around with the API but its ridiculously quick and easy to get a Collada model loaded in and apply your custom materials. Just a couple of lines of code and you get it animating. Thought I’d share my little experiment here, if you’ve got a couple of minutes to spare during a coffee break be sure to give it a try.

 

1. Download and install PV3DComponents_v1.0.mxp from the following URL:
http://www.rockonflash.com/blog/?p=54

2. Launch Flash CS3 and create a blank FLA

3. Drag an instance of the Collada Scene component from the components panel to the stage, resize it to fit the stage and give it the instance name “scene3D”

4. Download cube.dae (created by Alessandro Crugnola for this experiment)

5. Go to Window > Other Panels > PV3D Panel

6. In the PV3D Panel point to your working folder and specify cube.dae you just downloaded as its Collada source file

7. In the model tab of the PV3D Panel set up the zoom and rotation of the 3D object

 

Notice the live preview in the component on stage. Now, lets add a material to this cube —

 

8. Import an image file into you’d like to use as a material, set up its linkage ID in the Library panel to “cubeSkin”

9. In the Parameters panel click on Materials list and set it up to read as the screenshot below:

Papervision3D component material dialog

 

The materialName property refers to the name of the material as specified in the Collada file, in this case its “CubeMaterial”. Interesting to know if you’re not sure what material names where used in a specific file you can just open it with your favourite text editor and look for the library_materials node — Collada files are XML based so easily readable.

The materialLinkageID property is set to the Linkage ID we gave that bitmap image that was imported i.e. “cubeSkin”

 

10. Add a new layer to your timeline and add the following code (if you feel dirty doing this, simply create an AS3 class and set it as the document class for the FLA).

 

1
2
3
4
5
6
7
8
9
import flash.events.Event;
  
function rotateCube(evt:Event):void {
  scene3D.collada.rotationX += 1;
  scene3D.collada.rotationY += 1;
  scene3D.collada.rotationZ += 1;
}
  
addEventListener(Event.ENTER_FRAME, rotateCube);

Pretty easy, right? It just increments the x, y and z rotation of the 3D object by 1 every frame. Now save this FLA in your working folder and run Control > Test Movie which should give you a result something like this:

[flash]/blog/wp-content/uploads/2007/07/pv3d.swf,350,300[/flash]

Download the source files

31 Comments

  • July 7, 2007 - 4:34 pm | Permalink

    Nice article Peter! I want to try this out. Looks like it takes some of the work out of loading the model and mapping the material in code… (Rock on John!)

    Sean

  • Pingback: reintroducing.com Blogging Receptacle » Blog Archive » PE Does PV3D In 5

  • Pingback: Hebi Flash Blog » Et encore Papervision...

  • July 8, 2007 - 5:33 am | Permalink

    Thanks for posting about this Peter!

    I thought it worth mentioning that you could also use yaw(), pitch() and roll() methods to do the incremental rotation

    scene3d.collada.yaw(1)
    is the same as:
    scene3d.collada.rotationY += 1;

    Thanks again, this looks great!

    John

  • July 25, 2007 - 12:25 am | Permalink

    Very cool!!

  • Jeff
    August 24, 2007 - 2:23 am | Permalink

    Wish I could get this working right. I’m fine until step 9 where it says “In the Parameters panel click on Materials list and set it up to read as the screenshot below:” When I click on the Materials list it is totally blank. When I hit the “+” icon nothing happens, so I’m not sure how to populate the list with data. I have installed all of the AS3 classes and can’t figure out what the problem is. Any help is appreciated.

    Thanks,
    Jeff

  • August 24, 2007 - 1:29 pm | Permalink

    If you click the + icon you should see the dialog getting populated with values like animated, singleSided etc. (see screenshot). Then you just click the space on the right of each value and type in its value.

    Hope this helps!

  • Paradox
    August 25, 2007 - 6:25 pm | Permalink

    MXP File installed correctly, I can see the PV3D Panel and all but I don’t have any new components in the components panel

    Using Flash CS3 with latest Player 9 Beta on OSX 10.4.10

    Any help is appreciated

    Thanks

  • August 27, 2007 - 8:17 pm | Permalink

    thx, i like ur work, bedankt alweer, ik maakte er dit van ..cubes

  • Jeff
    August 30, 2007 - 6:48 pm | Permalink

    I’ve figured out my problem: The papervision component is not functioning properly under Mac OS X. I tried installing it on a Windows PC and all of my material list problems went away. Apparently clicking the + icon on the Materials list will only work under a Windows installation of papervision. Hope this helps.

    Jeff

  • August 30, 2007 - 7:06 pm | Permalink

    Good to hear you’ve got it working Jeff — I’ve got no problems using it on Mac OSX though.

  • Jase
    September 24, 2007 - 4:50 pm | Permalink

    Hi Jeff,
    I was only able to reproduce that issue in Windows if the publish setting was set to ‘ActionScript 2.0′ and the ‘Identifier’ field in the linkage properties, was filled in instead of the ‘Class’ field.

    Thanks Peter. Great tutorial.

  • Pingback: Papervision3D components « Change the Script

  • Pingback: Christopher M. Dickens » Papervision3d

  • October 15, 2007 - 5:22 pm | Permalink

    great tutorial, but i am not able to activate the linkage ID with AS3, says has to be AS2 an when publishing i get the message the papervision needs AS3.. hmmm, so what can i do??

    os: mac 10.4.10

    The code in the outputwindow is:

    DisplayObject3D: null
    Papervision3D Beta 1.7 (20.08.07)

    DisplayObject3D: null
    DisplayObject3D: null
    Papervision3D Beta 1.7 (20.08.07)

    DisplayObject3D: null
    DisplayObject3D: null
    DisplayObject3D: Box01
    Collada material CubeMaterial not found.

  • Warren mackenzie
    January 1, 2008 - 12:57 am | Permalink

    hi, ive been looking for articles and source for a while,
    i downloaded SVN turtle thing,set it all up and i tried variuos other ‘basic’ tutorials, including the Computer ats one which usually works, and nada!

    yours did work however!!!! so thanks a lot!

    do you know of any sites that have utorials that, like yours, do what they say, and start simple working up slowly, im ok at scripting and 3d, but this thing has me perplexed.

    want to make an interactive 3d worldy thing for a site im on at work, this is how i gotta do it it seems, but im lost.

    wish there was a clearly illustrated easy to follow book that included source files for tuts.

    help me flash god.
    MSN me

    waz

  • Carl
    February 24, 2008 - 8:17 pm | Permalink

    Hi Peter,

    Awesome tutorial, as a person who plays around with Flash and 3DS Max (.NET developer by trade), I found all the previous tutorials ‘skipped’ out important bits!

    Now I finally have a base working example I can finally start playing around with my own models in PV3D (Ikept getting to the materials bit’s in other tutorials, but non explained how to setup the parameters).

    Great tutorial, thanks,

    Carl

  • March 7, 2008 - 8:45 pm | Permalink

    hi!
    i’m using flash CS3 on WinXP and when i’ve installed PV3ComponentsV1.0 there was no any new components in components panel even thou PV3Com works, well… lets say well.
    same problem as “Paradox” posted few months ago.
    have anybody figured it out in meanwhile?
    tnx!

  • March 12, 2008 - 8:37 pm | Permalink

    I got it all done on my end…Hey i just wanted to mention to your other viewers that &nbsp didnt work in the actions of my .fla [i just deleted them] Here is how it would look like.

    1
    2
    3
    4
    5
    6
    7
    import flash.events.Event;
    function rotateCube(evt:Event):void {
    scene3D.collada.rotationX += 1;
    scene3D.collada.rotationY += 1;
    scene3D.collada.rotationZ += 1;
    }
    addEventListener(Event.ENTER_FRAME, rotateCube);

    Also viewers should note to give the component (on the stage) an instance name of scene3D.

    Keep up the good work Peter and thanks for the quick tutorial, to RockonFlash and to the owner of the Google code .mxp (neOriley). Yeah it was a stunner and it took just about 5 minutes!!

  • Pingback: Papervision 3D - A first for me but not the last!!

  • Pingback: Installing Papervision3D on Flash and Flex | fabianvercuiel.com

  • Pingback: OpenRIA » Blog Archive » Papervision3D上手教程

  • Pingback: 火柴工作坊 » Blog Archive » Papervision3D入门教程

  • samsara
    May 28, 2008 - 7:02 am | Permalink

    Thank you for your tutorial.
    I downloaded your source code, unzipped it, remedied path of the cube.dae, then published, but there were 2 compiler errors come up:
    Vertices3D.as, Line 163 1000: Ambiguous reference to Vertex3D.
    Vertices3D.as, Line 222 1000: Ambiguous reference to Vertex3D.

    Do you have any idea why this happened?
    Thanks in advance!!

  • samsara
    May 28, 2008 - 8:40 am | Permalink

    Oh, Sorry!
    Your source file works perfectly after I re-download the Papervision3D.
    Thank you for your nice tutorial!

    Good day!

  • cryzto
    June 20, 2008 - 6:05 pm | Permalink

    Hi there!
    Awesome turorial, just what I was looking for…
    simple but efficient…

    But I have one problem:
    If I place my cube.dae elsewhere before I load it in the PV3-Component…everything’s fine until I run it.
    The it says “COLLADA file load Error #2032: ……”
    -> it looks for the collada-file in the same place like the fla…

    If now I put a copy of my collada-object in the same path like my fla, but still having the link in the PV3-Component pointing to the original one, it works…

    why???… is that a PV3-Bug?

  • cryzto
    June 20, 2008 - 6:18 pm | Permalink

    added: I think the local directory has to point to the fla-path!

    PV3-localdirectory-path -> where the fla is!
    PV3-collada-path -> where the collada is (+subdirectory)

    then it works! but still a lil buggy… the component takes the subdirectory with the collada file as one name -> assetscube.dae

    …so I think its the component which is lil buggy…

    Can you confirm that?

    Greetz

  • Matt
    June 28, 2008 - 3:57 am | Permalink

    Mine simply repeats “Please select a collada component to edit” no matter how many times i set the local path and collada path.

    When I select “cube.dae” it does say “COLLADA File: cube.dae” but then continues with its complaining:

    Please select a collada component to edit
    Please select a collada component to edit
    Please select a collada component to edit
    Please select a collada component to edit
    COLLADA File: cube.dae
    Please select a collada component to edit
    Please select a collada component to edit
    Please select a collada component to edit
    Please select a collada component to edit
    Please select a collada component to edit

    Weird.

  • ShutterBun
    July 4, 2008 - 6:24 am | Permalink

    I had that same problem myself, but seem to have figured it out. Basically, you have to have the “Collada Scene” that you’ve placed on your stage *selected* while you are fiddling with the controls.

  • george
    August 2, 2008 - 4:19 pm | Permalink

    how do you preload the 1.5 component? so its just not a blank screen until the dae and material loads?

  • Alex Novik
    December 3, 2008 - 5:41 pm | Permalink

    Finally! Just read about 20 tutorials and only this one helped me to understand PV3D basic vision. Thanks, man!

  • Comments are closed.

    .