Jump to content

  • Log In with Google      Sign In   
  • Create Account






Loading 3D Models using Assimp.Net and SlimDX

Posted by ericrrichards22, 03 October 2013 · 535 views

C# SlimDX DirectX 11 Models Assimp
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.

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.

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.

Posted Image

Posted Image
A more complicated model with multiple subsets, from the Assimp test model collection.

Read More...




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.)

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.

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.

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

July 2014 »

S M T W T F S
  12345
6789 10 1112
13141516171819
20212223242526
2728293031  

Latest Visitors

PARTNERS