3DS, OBJ, and NFF content importers for XNA 4.0
I'd like to preface this by saying that I've acted as an aggregator; most of this code was ported from somebody else's work, as I have acknowledged below. If there are any bugs, they are almost certainly my fault, and if you find one please log an issue.
- 3DS - Lots of free 3D models on the web are in this format. My code was ported from MRI3DS, a Java 3DS importer.
- OBJ - Again, this is a common format. My code was ported from OBJ_IMPORT, a Java OBJ importer. I'm aware that there is an OBJ importer on App Hub, that may well be better than this one - the more choice the better, right?
- NFF - Actually, it's generous to call this an NFF importer. All I really wanted was a simple file format to create primitives, and NFF was the closest I could find. I have implemented a tiny amount of the specification, and then bolted on my own additions. Have a look in the ModelsDemo content project for some examples. Just because it will break up the monotony of this post, I'll include one of the NFF files here:
# A material f 0.3 0.3 0.3 0.8 0.2 16 0 # A plane at 0 0 0 with a 'width' of 50 and 'height' of 40 x-plane 0 0 0 50 40 # A red material f 0.8 0.1 0.1 0.8 0.2 16 0 # A cube at -50 0 0 with a 'size' of 50 x-cube -50 0 0 50 # A green material f 0.1 0.8 0.1 0.8 0.2 16 0 # A teapot at 50 0 0 with a 'size' of 50, with a tessellation level of 10 tess 10 x-teapot 50 0 0 50
The available primitives are:
- Teapot (every good primitive library needs one of these)
And before you ask, yes, the code for these is adapted from the Primitives3D sample on App Hub. Like I said, most of what I've done with these importers is package up other people's work, in a hopefully easy to use way.
As with all the software in my recent posts, this code is open source and hosted on GitHub. If you dig through the code, you might notice that it calls out to two other libraries called Meshellator and Nexus. These are two other open source projects I'm working on, but I'm not ready to talk about them in any great detail. The reason I've abstracted the mesh importing away from XNA is that I use the same library for a nascent software rasterizer.
On a tangential note, I have three reasons for releasing this software as open source: