A recent client has seen fit to open source some of the work I did for them in the area of 3D graphics. They had a holographic display system that expected users to supply 3D models for display in the form of Ogre3D mesh files. Ogre is a hardware- (and rendering layer-) independent open source library for doing 3D graphics, and was my own introduction to the field. The “mesh” files it uses are an Ogre-specific format that corresponds closely to the hardware data structures used, for example, in OpenGL. Unfortunately the largest sources of public 3D models (e.g., 3D Warehouse) use a different format known as Collada; this format is nearly universally accepted as input or generated as output by popular 3D rendering tools (with varying degrees of standard conformance and interpretation).
At some point it became clear that we would benefit from having our own Collada to Ogre mesh converter, so I investigated implementation options and existing code. The only high-level open source Collada parser library that is currently being maintained is OpenCollada; it does purport to have an Ogre mesh converter, but I found that instead of converting the contents of an entire Collada file (consisting of numerous geometries and instances arranged in a scene hierarchy) it would simply output the most recent geometry it found, as-is. Nevertheless it seemed like a good starting point, and so I began there.
After thinking about what my client would want to do with Collada data, it seemed to me that there were two general cases:
Treating an entire Collada file as a single selectable/movable object. This would apply in cases where the object was a “leaf” element of a scene and the internal hierarchy was uninteresting. For this we would need to build a single mesh from the scene hierarchy present in the file, copying and transforming the geometry elements as appropriate.
Replicating the scene hierarchy from Collada inside Ogre. Perhaps the hierarchy carried some information, or we wanted to reduce memory use (since individual geometries/meshes might be repeated). In that case loading the scene graph “live” within Ogre made the most sense.
It seemed to me that a lot of the tricky code, especially in mesh generation, could be shared between these two approaches, and I managed to implement it accordingly. In the heart of the code I rely on the Ogre ManualObject class to build up a mesh one vertex at a time; ManualObject has a method to convert itself to a Mesh which can then be written to disk. Unfortunately this approach requires a window system; I haven’t found a way around this yet, and so the mesh conversion process pops up a small window each time it converts a file. Nevertheless it offers both command-line conversion of Collada to mesh files and a scene loader you can use from within an Ogre application.
No graphics-related post would be complete without a picture, so here is a screen capture of running the scene loader on the rubber duck model supplied as part of GLGE:
The code may be found here. I think there are probably a lot of improvements that could be made and I look forward to receiving bug reports and pull requests. Please send them!