Loading 3D Models using Assimp.Net and SlimDX

Published October 03, 2013
Advertisement
[font=Arial]

So far, we have either worked with procedurally generated meshes, like our boxes and cylinders, or loaded very simple text-based mesh formats. For any kind of real application, however, we will need to have the capability to load meshes created by artists using 3D modeling and animation programs, like Blender or 3DS Max. There are a number of potential solutions to this problem; we could write an importer to read the specific file format of the program we are most likely to use for our engine. This does present a new host of problems, however: unless we write another importer, we are limited to just using models created with that modeling software, or we will have to rely on or create plugins to our modeling software to reformat models created using different software. There is a myriad of different 3D model formats in more-or-less common use, some of which are open-source, some of which are proprietary; many of both are surprisingly hard to find good, authoritative documentation on. All this makes the prospects of creating a general-purpose, cross-format model importer a daunting task.

[/font]

[font=Arial]

Fortunately, there exists an open-source library with support for loading most of the commonly used model formats, ASSIMP, or Open Asset Import Library. Although Assimp is written in C++, there exists a port for .NET, AssimpNet, which we will be able to use directly in our code, without the hassle of wrapping the native Assimp library ourselves. I am not a lawyer, but it looks like both the Assimp and AssimpNet have very permissive licenses that should allow one to use them in any kind of hobby or professional project.

[/font]

[font=Arial]

While we can use Assimp to load our model data, we will need to create our own C# model class to manage and render the model. For that, I will be following the example of Chapter 23 of Frank Luna's Introduction to 3D Game Programming with Direct3D 11.0. This example will not be a straight conversion of his example code, since I will be ditching the m3d model format which he uses, and instead loading models from the standard old Microsoft DirectX X format. The models I will be using come from the example code for Chapter 4 of Carl Granberg's Programming an RTS Game with Direct3D, although you may use any of the supported Assimp model formats if you want to use other meshes instead. The full source for this example can be found on my GitHub repository, athttps://github.com/ericrrichards/dx11.git, under the AssimpModel project.

[/font]

[font=Arial]

image_thumb%25255B1%25255D.png?imgmax=800

[/font]

model2.JPG
A more complicated model with multiple subsets, from the Assimp test model collection.

[font=Arial]

Read More...

[/font]
0 likes 4 comments

Comments

215648

Can you post a screenshot with a complex model loaded from your code?

(I asked that because I doubt that your code too has some subset problem and the model you used in the tutorial is relatively simple i.e only 1 subset.)

February 04, 2014 12:49 PM
ericrrichards22

Yeah, you were right, I was doing something foolish when calculating the vertex offsets for my subsets, so subsets after the first wound up with some really crazy geometry. I'll add a new screenshot with one of the Assimp test meshes.

February 04, 2014 03:26 PM
215648

Yeah, you were right, I was doing something foolish when calculating the vertex offsets for my subsets, so subsets after the first wound up with some really crazy geometry. I'll add a new screenshot with one of the Assimp test meshes.

Thanks for reply but did you updated your code in your blog with this bug fixed?

EDIT: never mind, i got it. (i didn't add vertexStart to indices tongue.png )

thanks because your assimp.Net tutorial is very useful.

February 05, 2014 11:04 AM
ericrrichards22

Updated code should be live on my blog, as well as checked up to GitHub now.

February 05, 2014 12:05 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement