Papervision 3D Programming Tutorial - Loading and Displaying a 3D Model (Page 3 of 3)

Article by Matthew Casperson (4,880 pts ) , published Sep 28, 2009

Click here to see the Actionscript source code for ResourceManager.as

As you can see we have embedded two resources: the fighter1.dae file (which is the Collada XML mesh file) and the sf-02.jpg file (which will be the texture). The texture has been embedded because the Papervision Collada parser will try to load the texures from a separate file unless you supply the textures directly. The two embedded classes are paired up with two properties: Fighter1XML and SF02_Tex. Fighter1XML is an Actionscript XML object, and has been created via an anonymous function that instantiates a new instance of the Fighter1 class and then loads that object into an XML object. It’s a little messy, but does the job. SF02_Tex is an instance of the MovieMaterial class. The MovieMaterial class is a Papervision material class that takes a DisplayObject in its constructor – exactly the class that the embedded sf-02.jpg file results in.

The end result is that we embed two files inside the final SWF file, and then create two new objects that convert these embedded files into objects that can be used directly by Papervision. This alleviates the need to distribute multiple files when publishing you 3D flash program. We make use of these resources in the startup function of the EngineManager class (that was mentioned earlier) when we create a new MeshObject object.

A model can reference many separate materials to texture itself. When parsing the Collada mesh file Papervision will, by default, try and load these textures individually from external graphics files. We want to avoid this behaviour because we want to create one single self contained SWF file. By creating a MaterialsList and supplying it to the Collada constructor we can override this default behaviour and get Papervision to texture the model from our embedded resources. As you can see we take the MovieMaterial class we created in the ResourceManager (SF02_Tex) and assign it to a new MaterialsList collection, which in turn is passed to the Collada constructor.

The end result of all this code is a self contained SWF that displays and rotates a textured 3D model inside a web page.

Download the source code from here, and see the resulting 3D Flash program here.

Images

The final Papervision 3D Flash program

Related Article

Five3D ScreenshotFive3D Programming Tutorial - Photo Slide

See how to create a simple 3D photo album with Five3D.

Showing page 3 of 3

Comment

Nov 14, 2009 8:14 PM
Roberto
Problems emulating this demo
Hello, I´m trying to get into Papervision3D and found your tutorial. But after a few hours... I cannot init the sample. I suposse I need a Main.as to initialize everything, but I can´t do it..

Can you tell me how to make all this files work together?
 
Subscribe to Web Development
RSS
Get free weekly updates, directly to your inbox.
Browse Web Development