I used to be a great fan of XNA Game Studio as a framework to try new graphics techniques, those that needed a bit more support in the runtime than FX Composer or other shader editors could offer. It hasn’t been updated for quite some time now though, and it is becoming irrelevant in an age of advanced graphics APIs and next gen platforms.
In the past few months I noticed a promising framework, SharpDX, which seems to offer a similar level of abstraction of Direct3D as XNA, ideal for graphics demos, but updated to support D3D11 as well. There is another similar framework, SlimDX, but if I understand correctly it is not being as actively developed.
Indeed SharpDX handles and hides Direct3D 11 complexity nicely and, like XNA, allows the programmer to focus on the graphics technique not hindered as much by implementation details (I have had to fight with many pages of D3D samplers, shader views, rasteriser configs etc in other engines just to run a simple shader). I also find it a nice educational tool for learning D3D11, since you still have to use most D3D functionality and go through resource creation and pipeline configuration as normal, albeit at a higher level.
My main issue with SharpDX was its lack of a content pipeline. Although one can apply graphics techniques on procedurally generated spheres and cubes, it is more informative and representative to be able to load and use complex 3d models from files.
I already knew of Assimp, an open source C++ library that supports a large number of 3d model file formats. I looked around a bit and found a few .NET wrappers for Assimp and I gave one a go. This particular one talks to the C++ Assimp dll through P/Invoke to load a 3d model and exposes it as a hierarchy of nodes which contains meshes and materials.
The integration was fairly straightforward; all it needed was a conversion step from the Assimp.NET model hierarchy to a representation that can be used by SharpDX (containing vertex and index buffers, vertex declarations and shader views for textures). For my quick test I introduced a Model class which acts as a container of ModelMeshes each of which has all the information needed to render a mesh as well as a single texture. Assimp seems to support more detailed Material definitions but I didn’t go that far in this instance.
The result was pretty good, I managed to load both 3ds and obj files with no problem, with all textures involved (Sponza 3ds file available here):
I even managed to load the Stanford Dragon obj model that failed to load in FXComposer.
SharpDX seems like a capable alternative to the D3D11 C++ engine I’ve been using so far and I will be making the switch for my next demos.
I am sharing the model loading demo in case anyone is interested; it’s pretty basic but can be used as a template for more elaborate model loaders. The demo includes the Assimp library, .NET wrapper and models needed to run. It also only supports D3D11, it should be easy to convert to D3D9 if needed.