Away3DLite haXe + Morphing
I recently started on a 3D Flash job and was chuffed to find that Cauê Waneck has been porting Away3DLite to haXe. Anyway, suffice to say I was super-happy that I didn't have to do any AS3.
What's there currently is a direct port of the Away3dLite library, but in haXe. It makes a big use of the AS3 (FP10) native Vector (Vectora<Float>) so it's quite fast, but not directly portable to platforms other than Flash 10 yet. As far as I can tell performance is the same as, or similar to the FP10 AS3 release, but Cauê has assured me that he's having fun optimizing it.
Away3DLite is missing some functionality that is in the full version, things that I need for my current project, including the Morpher and AnimatedBitmapMovieMaterial classes. The first I've ported myself and the second has been ported by Cauê (thanks mate!).
And the Morpher.hx class.
I had a lot of trouble getting it working to start with but it's pretty easy once you get the ideas down. The main problem I had was the fact that neither the Collada object, nor the Object3D you get from it when doing .parseGeometry() has any vertices, so I got nothing when I passed it to the Morpher. What I'd missed is that I need to get one of the children from the Object3D that I get from the Collada .parseGeometry(). This is because, as Bartek Drozdz points out, "a Collada file represents a scene, not a single 3d object".
The next thing to know is that you should wait for the ParserEvent.PARSE_SUCCESS events dispatched from your Collada objects. When these are done you can use .getChildAt(0) on your .parseGeometry(colladaData) object to get a Mesh which you can then parse to your Morpher. In my example I have:
m0 = cast c0.parseGeometry(daeData1); // used to restet Morpher to original state
m1 = cast c1.parseGeometry(daeData1); // the model that I scene.addChild(m1) to
m2 = cast c2.parseGeometry(daeData2); // the model to Morph to
As you should notice I'm using the same daeData for both m0 and m1. I make my new Morpher passing it m1, then on each enterFrame:
mp.mix(cast m2.getChildAt(0), (1 + Math.sin(Lib.getTimer() / 150)) / 3);
mp.mix(cast m2.getChildAt(0), (1 + Math.cos(Lib.getTimer() / 250)) / 3);
Hope that helps someone else, I was stuck for days
Yay my first post in months!
This entry was posted on Monday, February 22nd, 2010 at 6:21 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
March 12th, 2010 at 6:45 am
Thanks for posting, that's a neat little demo. I've played a fair bit with Haxe and I was thinking about doing some 3D stuff.
One question though - I notice from your demo's that you have what looks like a nice little pre-loader on your demo. I've done a bit of looking round and I thought getting preloaders to work in Haxe was a real pain. Could you explain on how you did it please?
January 7th, 2012 at 4:57 pm
Yes it's true, That is certainly beneficial