Model Import with Assimp

Here we go: I’ve decided to make the sample open source and host it on google code. Hopefully this step will raise public awareness and make it easier for other developers to download and reuse the code.

As a first step I’ve hijacked a DirectX 9 programming assignment I did a while ago and removed all assignment specific code. What I’m left with at this point is a bare bones program skeleton of a windowed DirectX 9 application, a frame rate timer and a very rudimentary display list implementation. I’ve also added Assimp to the project and the first test model import worked fine – well at least it didn’t throw any errors. I don’t have a renderer yet so there’s no way of verifying the imported data 🙂

The model import itself is surprisingly simple: Create an instance of Assmp::Importer and call Assimp::Importer::ReadFile() [The following code is mostly taken from the Assimp tutorial]

Assimp::Importer modelImporter;
const aiScene* scene = modelImporter.ReadFile( mFileName,
    aiProcess_CalcTangentSpace      |
    aiProcess_Triangulate           |
    aiProcess_JoinIdenticalVertices |
    aiProcess_ConvertToLeftHanded   |

// If the import failed, report it
if( !scene)
    std::cout << modelImporter.GetErrorString() << std::endl;
    MessageBox( NULL, modelImporter.GetErrorString(), "import failed", MB_OK );
    return false;

That’s it. Obviously there’s a million parameters you can pass to ReadFile() but they are mostly self explaining. The most important one in my setting would be aiProcess_ConvertToLeftHanded because Assimp assumes a Right Handed Coordinate System whereas DirectX uses a left hand coordinate system by default.

In case the import fails Assimp::ModelImporter returns a NULL pointer and you can get extended error information via Assimp::ModelImporter::GetErrorString().


Leave a Reply

Your email address will not be published. Required fields are marked *