Friday, October 16, 2009

Papervision3D

I've been using Papervision3D to do all of the augmented reality stuff lately, but when it comes to using 3DS Max (or models generated in any other software for that matter) the Collada / DAE formats are... extremely tricky. Or buggy. Hopefully things I've learned will save people headaches in the future:

1) Do I use Collada or DAE?
Depends, really. Most examples I've seen around the net have a tendency to use the Collada Class when importing static models. But if you have animation, then you'll definately want to use the DAE Class instead; as it has a lot more methods/properties for controlling animation.

I used to use one or the other, but lately I've switched to just using DAE all the time, whether there is animation or not. It's easier.

2) Texture Maps
There seem to be a few ways to handle mapping your textures onto your models. If your texture maps aren't too big, you can generally get away with using the BitmapFileMaterial Class to load your image file externally. If you start running into problems where your model loads before your texture and you get a flatshaded or wireframe model then a few seconds later your material shows up, you'll need to use the FileLoadEvent to create a "preloader" for your material and halt loading your model until the texture is ready.

When you start getting more and more models in the scene, though, trying to handle a bunch of preload events for textures and models is going to get annoying, though. For the purposes of what I've been doing, I've found it to be more efficient just to embed the materials in the Library, assign them a class name, then use the BitmapAssetMaterial to reference the material, load it into a MaterialList, then assign it to the DAE. Then, if you have a classic preloader for your swf, you can just include the library bitmaps in the stuff that gets preloaded.

3) Exporting DAE from 3DS Max
For the sake of ease, I've started using 3DS Max 9 to do all of my DAE exports. The Collada NextGen Exporter for it seems to be the better of the ones between it, 2009 and 2010. That said, it's not perfect. But generally, if you keep these things in mind, you shouldn't have any problems getting your DAEs exported:
  • Name your material in the Material Editor. Nothing complicated, but something you can easily remember.
  • Initial coordinate keyframes. I've consistently run into issues where, for instance, I will animate something, then get it into Flash, and the animation will be running at the 0,0 origin, when in Max, it was up in the air somewhere. Not sure why it happens, it might be an exporter issue. But I've found that if I turn on auto key and set keys for each axis, then it exports fine.
  • DAE Export options.  You should only need 2 - 4. Normals and Triangulate Always. If you have animation, then also check 'Enable Export' and 'Sample Animation' for a set number of frames.
  • Manually tweak the .DAE file.  Once you've exported the .dae, you'll need to open it in a Text Editor. Do a Ctrl+f and search for "_1".  This is appended to the end of all of your material files for some reason. Not sure why. So I go in and kill 'em.  If you have animations in your file, then also search for "animation" and you should see a node called "Library_Animation" and an "Animation" node under that.  You need to add an id attribute to the animation tag, so just add in id="whatever" and then save and close.

If I come across something else that annoys me, I'll post. :)

7 comments:

  1. yes, keep us posted. tough to find such solid info on the 3dsmax to PV3D work flow. Have you looked into Unity3D?

    ReplyDelete
  2. Indeed I have, and I will likely be getting it sometime soon. If only for its application on the iPhone.

    Also, in the forseeable future, I don't think I'll be fighting with PV3D workflows anymore; I've switched over to using Away3D and find it much more agreeable. :)

    ReplyDelete
  3. What exporter are you using?
    [feeling software? openCollada?]

    ReplyDelete
  4. Now I'm using ColladaMAX 3.05 C. At the time I wrote this post, I was using Collada NextGen.

    You can get ColladaMAX here:
    http://sourceforge.net/projects/colladamaya/files/

    ReplyDelete
  5. We had a lot of problems trying to use a simple collada model in an augmented reality (flartoolkit) example. It seemed almost impossible to position our model to the marker. It looked like every time we exported our model the pivot point was put randomly and most of the time not even close to the models registration point. Did you experience the same, and could you give us any tips on this subject?

    ReplyDelete
  6. I noticed that alot when I used Papervision, but with Away3D I don't have nearly as much trouble positioning things.

    Not sure where PV3D pulls its registration point, but if it is like A3D, now, the best thing to do is position your model where you want it in relation to the 0,0,0 grid plane in Max, then edit the pivot point of the object and 'Center to world', so that the pivot point is right at 0,0,0.
    Then, when you import it into your flash engine, the .x and .y properties should be based from that.
    One other posibility is that whatever you use for a 'modelContainer', a root node that handles the transforms from the FLARManager, could be offset.

    ReplyDelete
  7. I have some issues on Z-sorting. Probably it will be solved by increasing the number of polygons.

    ReplyDelete