Home > Flash, Flex, Open Source > Papervision3D in 5 minutes

Papervision3D in 5 minutes

July 7th, 2007

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).

 

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

No TweetBacks yet. (Be the first to Tweet this post)

 
Creative Commons License This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.0 Belgium License.

 

Related posts:

  1. Papervision3D for everyone
  2. Flashforward Boston – Carlos Ulloa
  3. Papervision3D tutorial
  4. URL in a File Browse Dialog
  5. Using the Databinding API


 

Flash, Flex, Open Source

  1. July 7th, 2007 at 16:34 | #1

    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

  2. July 8th, 2007 at 05:33 | #2

    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

  3. July 25th, 2007 at 00:25 | #3

    Very cool!!

  4. Jeff
    August 24th, 2007 at 02:23 | #4

    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

  5. August 24th, 2007 at 13:29 | #5

    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!

  6. Paradox
    August 25th, 2007 at 18:25 | #6

    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

  7. August 27th, 2007 at 20:17 | #7

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

  8. Jeff
    August 30th, 2007 at 18:48 | #8

    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

  9. August 30th, 2007 at 19:06 | #9

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

  10. Jase
    September 24th, 2007 at 16:50 | #10

    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.

  11. October 15th, 2007 at 17:22 | #11

    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.

  12. Warren mackenzie
    January 1st, 2008 at 00:57 | #12

    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

  13. Carl
    February 24th, 2008 at 20:17 | #13

    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

  14. March 7th, 2008 at 20:45 | #14

    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!

  15. March 12th, 2008 at 20:37 | #15

    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.

    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!!

  16. samsara
    May 28th, 2008 at 07:02 | #16

    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!!

  17. samsara
    May 28th, 2008 at 08:40 | #17

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

    Good day!

  18. cryzto
    June 20th, 2008 at 18:05 | #18

    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?

  19. cryzto
    June 20th, 2008 at 18:18 | #19

    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

  20. Matt
    June 28th, 2008 at 03:57 | #20

    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.

  21. ShutterBun
    July 4th, 2008 at 06:24 | #21

    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.

  22. george
    August 2nd, 2008 at 16:19 | #22

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

  23. Alex Novik
    December 3rd, 2008 at 17:41 | #23

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

  1. July 7th, 2007 at 17:46 | #1
  2. July 7th, 2007 at 18:01 | #2
  3. September 24th, 2007 at 17:27 | #3
  4. October 9th, 2007 at 18:35 | #4
  5. March 12th, 2008 at 21:20 | #5
  6. April 17th, 2008 at 21:23 | #6
  7. April 19th, 2008 at 17:25 | #7
  8. May 13th, 2008 at 07:43 | #8
Comments are closed.
"Schöne Harz Ferienwohnung im Herzen von Deutschland. Weitere Ferienwohnungen im Harz finden Sie auf der angegebenen Urlaubsseite.
Falls Sie einen Partner für erfolgreiche Suchmaschinenoptimierung suchen, sind Sie bei Bullz-Eye an der richtigen Adresse."