Posts RSS Comments RSS Del.icio.us Digg Technorati Blinklist Furl reddit 73 Posts and Comments till now
This wordpress theme is downloaded from wordpress themes website.

Adding some 3D models with Open Asset Import Library (assimp)

The build setup for assimp turned out to be a little more effort than I’d expected.  My goal was cross-platform support most likely by building assimp from source, but I was hoping to focus on getting a proof of concept working first using a Windows binary release.  Unfortunately, assimp-3.1.1 released 2014-06-14 was not as easy to setup as the assimp-3.0 releases from 2012-07-10, so I ended up using assimp-3.0 (for first pass).  The assimp-3.1.1 Windows release binaries only worked with older visual studio (not with 2012), and assimp-3.1.1 code release did not include a vcxproj, and running cmake gave me an error.  assimp-3.0 came with a vcxproj file, so I started from that.

I imported this vcxproj into my solution.  To build assimp as a static library, I also needed to download boost.  Using the static library caused link errors relating to C++ standard library, see ( http://assimp.sourceforge.net/lib_html/install.html ).  So I built assimp as a dll (instead of a lib).  (“There’s no STL used in the binary DLL/SO interface, so it doesn’t care whether your application uses the same STL settings or not”).  I also added to assimp -> properties -> Configuration -> C/C++ -> Preprocessor -> ASSIMP_BUILD_DLL_EXPORT.  This enabled __decclspec(dllexport)’s needed when building the dll.  Without ASSIMP_BUILD_DLL_EXPORT, I was able to build assimp.dll but there was no corresponding assimp.lib (which I need to statically load, aka implicitly link to assimp.dll).

image image image

Once I got the build working, the real fun began.  I skimmed a few assimp tutorials and some of the official assimp documentation, but I found this one ( http://nickthecoder.wordpress.com/2013/01/20/mesh-loading-with-assimp/ ) to be a great starting point.  I used that as a guide along with my existing shadow map objects (class Entity extends HelloWorldBox).  I started with a Cube.obj model file for debugging.  I started by printing (SDL_Log()) the values that I read (using assimp) from Cube.obj file.  From there, it was easy to use those values (position, normal) in the same manner.  Once I got Cube.obj working, I verified an obj model with more verts would work (utah teapot) (wt_teapot.obj).  Then I created a scene with a few different imported models.  The model files I used had normals, but my current shadow mapping example has shadows without lighting (eg no Phong Illumination), so I used the normals as colors.

image image image image image

In modern graphics (API’s and GPU’s), each vertex has a position and 0 to N parameters, and is drawn using (shaders, textures, primitive assembly & other graphics modes).  So a 3d model file format would at least need some way to specify vertex data.  Additional data needed for a model may include textures, mesh hierarchies, animations, deformations.

One simple plan text file format is Wavefront OBJ (.obj), see ( https://en.wikipedia.org/wiki/Wavefront_.obj_file ).  OBJ specifies vertex positions, specific types of attributes (texture UV, normals), and primitives (eg faces).  OBJ only specifies geometry, but you could have separate files for other things like textures and materials (Material Template Library).  More details on OBJ here ( http://www.martinreddy.net/gfx/3d/OBJ.spec ).

For some applications (certain games), it might make more sense to design a custom file format (or choose one that matches your needs), then write an export plugin (such as for Blender), and an importer (for your application).  OBJ might be a good choice for an educational project, since it’s standard and simple and plain text.  But for a commercial project, you probably want to use a more optimized format.  For some applications (such as tools for 3d modeling), there is a genuine need to load lots of different 3D model file formats – which is why assimp supports a list ( http://assimp.sourceforge.net/main_features_formats.html ).

Trackback this post | Feed on Comments to this post

Leave a Reply