Using the bend modifier with Collada objects
Papervision3D comes with a set of primitive 3d shapes - such as a plane, a cube and a sphere. It is possible to do quite a lot with those, but the real power lies in importing objects from 3d editors like Maya, 3dsmax or, in that case - Blender. In Papervision3D, the format of choice for importing meshes from 3d editors is Collada.
Some time ago I actually did export a Collada file from Blender and import it into Papervision3D. You can see the result in one of my early posts. Back then, it was like riding a bike, downhill, in a forest, blindfolded - you don't register much, and at the end you are just happy that you made it. This time I wanted to actually understand what is going on.
For my first experiment I decided to export only the geometry and not the texture. I wanted to see my bend modifier applied to such an object. The task turned out to be not difficult at all. The only thing I needed to understand was the way Collada files are represented in Papervision3D.
A Collada is basically an XML file (with a *.dae extension), so it is perfectly human readable. It contains a part that describes its contents. In my file it can be found somewhere towards the end, and it starts like this:
-
<library_visual_scenes>
-
<visual_scene id="Scene" name="Scene">
-
<node layer="L2" id="LadyDae" name="LadyDae">
-
[...]
The first interesting point is that a Collada file represents a scene, not a single 3d object. In my case the scene has only one object, but it is still a scene. That is why Papervision3D will first create a DisplayObject3D that represents this scene, and only then it will add a child that represents the 3d object itself. So in the code, once the Collada is loaded, I can access the object "LadyDae" like that:
-
var mesh:DisplayObject3D = dae.getChildByName("COLLADA_Scene").getChildByName("LadyDae");
Note that the scene is named "COLLADA_Scene" not "Scene" as you could expect from the XML. It's because this name is hard coded and it will always be the same, no matter what the name is in your file. Also note that the attribute you need to refer too is the 'name' attribute, not 'id'.
Now, that the 'mesh' variable contains a reference to the object holding the geometry applying the Bend modifier is pretty simple:
-
var b:Bend = new Bend(mesh);
-
b.quickBend(1, .5);
So, I'd love to tell you stories on how, after a many sleepless nights, I finally made a breakthrough and now the Bend modifier works with Collada... but the fact is it always did. The thing I failed to grasp so far was the structure of the Collada object itself.
This unexpected success left me some time and energy to play a bit with another topic from my must-explore-soon list - ShadedMaterials. I did not do much. Basically I just followed some of Ralph Hauwerts old demos, but it resulted in some effects that are nice to look at.
Credits. The model of the girl is a very simplified version of the original made by Tiziana. The background tile comes, as usual, from SquidFingers.
Source. The source code is available here. In the example, I load a ZIP containing the Collada file. A class called KMZ is able to load and unpack it correctly, and it saves a lot of bandwidth. I got this tip on the Pv3d forum (thanks!)



August 26th, 2008 at 4:04 am
Very nice example…just seen Andy’s reflection demo aswel. You guys keep posting really quality stuff. This type of usage for bend modifier could save a lot of CPU cycles… Just a wacky thought, could you make a plane mesh imitate a walking like motion.
cheers, tim
August 26th, 2008 at 2:42 pm
Aloha Bartek,
Very nice work !
I want to add that getChildByName has a recursive boolean which can be handy for big scenes. So i your case dae.getChildByName(LadyDae,true) should work aswell.
Pay a visit are irc server freenode #papervision and meet more pv3d developers or use the webirc chat at:
http://www.flashbookmarks.com/pv3dchat/
Hope to see you soon :)
August 26th, 2008 at 2:56 pm
@FlashBookmarks right! I missed the second argument in getChildByName, thanks.
August 27th, 2008 at 8:26 am
private function onResize(e:Event=null):void {
topBar.resize();
blogLink.resize();
pattern.graphics.clear(); //********************** 2x lower CPU usage while scaling
pattern.graphics.beginBitmapFill((new Pattern() as Bitmap).bitmapData, null, true);
pattern.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
pattern.graphics.endFill();
}
Fajny blog ;-)
August 27th, 2008 at 11:32 am
Great one Bartek! Keep it up!
August 29th, 2008 at 12:49 pm
Bartok, this is very interesting.
September 2nd, 2008 at 1:41 pm
Excellent learning material.
Works fine but just to give you a heads up of an initial error on load.
[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference. Fault, bendToMouse() at LadyDae.as:212
Using current FlashDevelop3 + Flex3SDK + pv3d revision714
Thanks for all your examples
September 2nd, 2008 at 2:58 pm
Actually scratch that. It only happens when FD set to “Play in pop up” and not present when viewed by other methods like “Play in external player” so it is not to do with your code.
November 4th, 2008 at 6:14 am
Are you able to use the bend modifier on collada animations… or perhaps on instances of Fabrice’s Away3d Animator class?
November 4th, 2008 at 10:20 am
@mark I did not do any tests with those formats yet, but I plan to work more on integrating Bend and the other AS3Dmod modifiers with Away3D so I might be posting something on that subject.