Papervision3D is an incredible open-source library for building 3D applications in Flash. You can create basic 3D objects and animate them with Actionscript, but if you really want to create something cool, you need to import a 3D model made with a program like 3D Studio Max, Maya, or Blender.
Several different 3D file formats can be imported into Papervision – the most popular format seems to be Collada (*.DAE), which is an XML format. However, I recently noticed that *.3DS files could also be imported to Papervision using the Max3DS class. 3DS is an old file format for 3D Studio Max, but many 3D programs will still export this format. Since it is a binary format, it creates much smaller files than Collada, which can significantly decrease model load times, but I was curious if there was any noticeable performance difference once the models were imported. In theory, the models should perform identically once they are imported. So I created a test to see if this was true.
I created a quick model of a 57 Chevy station wagon in 3D Studio Max 9 for my test. The finished model has 1833 vertices and 1802 faces. Please note that I’m a noob when it comes to 3D modeling and I know that this model has some issues, but I really only cared that it imported correctly to PV3D. Anyway, I exported the model to both Collada and 3DS formats. The exported file stats are:
wagon5.3DS = 103 KB
wagon5.DAE = 488 KB
I then created 2 Flash files that are identical except for the type of model that is imported for rendering. Click one of the images below to view the results in Papervision.
As you can see, they look essentially identical. Each SWF loads the model 5 times and renders it to the screen with a FlatShadeMaterial. How did they perform? Well, that depends…
When I first created these SWFs, I tested them on my work computer. It’s a pretty fast Dell desktop PC with lots of RAM running Windows Vista and Flash Player 10. The 3DS format performed noticeably better on my work machine. The frame rates were similar for both models, but the memory usage was much lower than the Collada format. The 3DS model rotation also looked smoother than the Collada model and the 3DS file had much quicker file load time. It looked like a clear winner.
Then I spent some time cleaning up the files on my laptop at home and the performance tests didn’t show the same results. My laptop is a Lenovo PC that isn’t as fast as my work computer and I run Windows XP with Flash Player 9. While testing at home, the 3DS file still had lower memory usage and the animations both looked the same. The frame rate difference was still marginal.
So, which one performs better? It may be dependent on the machine, the operating system, and the version of Flash you are running. I still give the 3DS format the advantage for it’s lower file size and memory usage. It may be a good idea to build a toggle into your Papervision project that allows you to import either format and do a lot of testing as you go before deciding on one format or the other. As always, keep your target audience (and their computers) in mind.
Feel free to use the Flash and Actionscript files to run your own tests or simply steal the code for your project. The methods that I used for loading and initializing the models may save you some time and frustration when dealing with the quirks of both the Collada and Max3DS parsers in Papervision. For example, the Max3DS parser would not allow me to initialize the model with a FlatShadeMaterial, so I had to use a ColorMaterial. But, once it was loaded, it would allow me to replace the ColorMaterial with a FlatShadeMaterial.
Please do not use the 3D model I have provided for production work. I have provided the model for you to use in these experiments, but it is copyrighted and I would really appreciate you not using it for anything else.
As always, you can download the source files here.
Pablo Cabana
Very nice post Andy. Here, at my QuadCore, 4GB, XP 64 bits, the performance is the same for both. The memory usage is different, but both have 11 FPS.
The problem with 3DS class, I think, is that it only supports old 3Ds files. You cannot use a 3Dmax 10 3ds file, or even a Google Sketchup 3ds file.
Anyway, thanks a lot for the investigation.
Best wishes from Brazil.
Remi Arnaud
There is a memory leak problem with the COLLADA model.
Memory starts at 70MB and keeps growing and growing.
On the 3DS model memory starts at 60M, growing to 70MB and then drop to 60M.
Performance wise the COLLADA model runs a bit faster on my system (13-14 fps) compared to 11-12 fps for the 3ds model. I bet that if you measure the performance across a large number of systems you’ll find that the performances are quite the same. (should be anyways!)
admin
Remi:
I noticed that memory leak too. The memory usage for the collada slowly creeps upward for a while. If you let it run long enough, it seems to level out, but not before using much more memory than the 3DS model.
Since the code between the 2 SWFs is identical except for the type of model used, I have to assume that the problem is with Collada handling in Papervision. Otherwise, the 3DS model would act the same way. If the memory leak in the Collada class was fixed, Then I think the Collada would have the edge over the 3DS format.
pete
I cannot get the source files to publish the Max3ds example… I get 76 compile errors.. using flash cs4.. any thoughts? are there any additional settings or anything? I get the same thing whenever I try using the Max3ds parser, with code pretty similar to yours, was wondering if you could help point me in the right direction.
thanks
-pete
admin
@pete
Hey pete,
I just checked the files again and they compile fine. My guess is that you have a global classpath set up for Papervision inside of Flash. This project is set up using packages – that means that you do not need an AS3 classpath for PV3D (I included the papervision trunk classes with the download). If you have set a classpath in Flash, it will conflict with the packages and throw a lot of errors. Go to Edit>Preferences>Actionscript and hit the “Actionscript 3.0 Settings” button – if you have a link to the PV3D library there, delete it and recompile. Also, if you rearrange the folder structure in the example, it may have a hard time finding the classes and throw a lot of compiler errors.
Thanks,
Andy
Ali Raza
Nice post , Could you please tell me which version of 3ds max you used for this file?
Thanks
admin
@Ali Raza
Hi Ali,
I used 3DS Max version 9 to make the model.
Ali Raza
Thanks for the reply 🙂
Let me try it too
Delcasda
@pete the errors you get are because Max3ds parser does not compile on CS4 but on CS3. To fix it just separate the 3 little classes at the end of the .as file and it will work. Still you need to have your class path pointed to fixed class
mcjomar
Heya – I’m trying to use this as a reference so I can learn how to import 3ds max files (I’m currently using the 2010 version) into papervision – however, your code mentions a bug with the MAX3ds class, which I’ve confirmed with one of my models, but my searches through google are coming up empty. It seems to be a “flip” around one axis, but I’m unsure how to correct this properly, or find a tutorial or page ( including a forum page where I found a link to this one) that would clear this up. Help?
mcjomar
@mcjomar
http://papervision3d.758870.n4.nabble.com/3DS-Model-flipped-on-the-Y-axis-td779175.html
The bottom of this (but putting the -1* in the Y co-ord rather than the Z) solved my problem – increased visibility of this fix for newbs like me might be a useful article?
I’ll go back to learning this now.
mcjomar
@mcjomar
Actually, the useRighthanded to true also works (and is simpler). Fun investigating though!