As we’ve made great strides with the Babylon.js engine over the past few months, it was long past time to give our 3ds Max and Maya glTF exporter tools the same amount of love. Until recently, we’ve always operated under the assumption that the exporters shared a significant amount of code:
This isn’t a completely wrong assumption, as we currently share implementation of the Babylon and glTF file format entities. Our exporting logic is not so fortunate, as it is implemented and maintained completely independently; a sub-optimal implementation if put lightly.
A recent rash of issues highlighted the flaws in this implementation especially well. We would address a bug reported for the Maya glTF exporter, then immediately have to port the same fix to our 3ds Max glTF exporter implementation. Something needed to change to improve code quality and maintainability. After all, why write the same code twice?
We approached refactoring the exporters with the idea that the .Babylon exporter should be customized to the software package that we are exporting from. When we export to .Babylon, we need to use the given modeling software’s API to retrieve scene data, and at that point we should also handle software specific quirks such as the coordinate system used, unit scale, representation of rotations, “standard” materials, etc.
Using our .Babylon format as an abstraction layer now frees us to share our .Babylon to glTF exporter between both projects, since they’re essentially responsible for doing the same thing:
Which, like all things, was much easier said than done. We use a monolithic
BabylonExporter class to handle both the .Babylon and glTF export processes, which in turn caused the glTF exporter to contain an unhealthy amount references to internal functions of the
BabylonExporter and Max API references.
To rectify this, much of the referenced reusable code was moved to shared utilities in a separate project, and references to class member variables was instead replaced with an
ExportParameters structure passed to both export entry points.
The last part of this project is integrating the shared glTF exporter into the Maya exporter, and plenty of testing to ensure quality code. In the future we hope to provide consistent UI between programs as well, via a similar refactor of the UI layer.
The refactored 3ds Max exporter is available here.
Nick Barlow — Babylon.js Team