Everyday3d
Posted on 2008-08-26

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!)

Back
More posts

Everyday3D is a blog by Bartek Drozdz

I started Everyday3d in 2007 with a focus web development. Over the years, I wrote about technology, graphics programming, Virtual Reality and 360 photography. In 2016, I co-founded Kuula - a virtual tour software and I work on it ever since.

Recently, I post about my travels and other topics that I am curious about. If you want to be notified about future posts, subscribe via Substack below.