Model Loading with Assimp Library
Assimp is an open-source library written in C++ used for importing 3D models in various file formats, offering advanced features like computing normal and tangent vectors. This guide covers installing Assimp on Ubuntu, including necessary modifications to the makefile, and usage instructions for loading models using the Assimp library in C++.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
CS 480/680 Part 1: Model Loading 1
Todays Topics What is Assimp? Installation Usage Recap Pseudocode Resources Questions 2
What is Assimp? Assimp (written in C++) is an Open Source library that is used by developers to import 3D models in a variety of file formats. Your model loader is only capable of loading .obj files. Assimp can handle .blend, .3ds, .obj, .lwo, .lws, .x, .cob, and more. 3
What is Assimp? Assimp will load all of these file formats into the same data structure which is used for further processing. Operations such as computing normal and tangent vectors are not only available, but also optimized. 4
Installation Install assimp3, which is compatible with Ubuntu 13.04 or higher. sudo apt-get install libassimp-dev Modifications to your makefile: In the LIBS section, you ll want to add -lassimp. 5
Includes Furthermore, you ll want to include the following in either your main.cpp file or your model loader class (recommended, develops abstraction in your code). #include <assimp/Importer.hpp> Includes the Assimp importer, which is used to read your .obj files. #include <assimp/scene.h> Includes the data structure that is used for further processing. 6
Includes More libraries to include: #include <assimp/postprocess.h> Includes flags for post processing (calculating tangents, normals, etc.). #include <assimp/color4.h> Includes the aiColor4 object, which is used to handle colors associated with your objects. 7
Usage First off, you ll want to declare an Assimp::Importer object and use it to read in the data from your .obj file, like so: Assimp::Importer importer; const aiScene *myScene = importer.ReadFile(yourObjFile, aiProcess_Triangulate); Triangles are a GPU s favorite shape. Your myScene variable is a pointer to an impressively large data structure that has everything you d ever want to know about your model. 8
Usage An aiScene object will consist of the following attributes (there s much more within the object; we re only covering the portion you need for your assignment): unsigned int mNumMeshes; Number of meshes in the scene (typically just one). aiMesh **mMeshes; This is an array of type aiMesh* and of size mNumMeshes, where each element of the array is pointing to a single aiMesh object, not an array of them. It s more like a 1D array, the elements of which are pointers to single object. 9
Usage What information can we get out of an aiMesh object? unsigned int mNumFaces; Number of primitives (can be triangles, polygons, or lines, but since we used the aiProcess_Triangulate flag, they re triangles). aiFace *mFaces; A pointer to an array of aiFace objects (of size mNumFaces), which are the faces that make up the mesh (same faces that you encountered in PA04). aiVector3D *mVertices; An array of vertex positions. This is the information we need for our model, but we have to do some further processing. 10
Usage We also just said that mFaces is a pointer to an array of aiFace objects, but what information can we get out of an aiFace object? unsigned int *mIndices; A pointer to the indices array. These are the same indices that were in the faces you encountered in PA04. Again, since we used the aiProcess_Triangulate flag, this array will have a size of three (because triangles). unsigned int mNumIndices; This value will be three (because triangles). 11
Putting It Together There s still one more issue to address: In PA04, you had to use the indices in the faces to actually obtain the coordinate info regarding each vertex. We have to do something similar in Assimp. To obtain the coordinate info of each vertex, we use the indices from the mIndices array to offset into our aiMesh s aiVector3D *mVertices attribute. In other words, we use the mIndices values to obtain the vertex coordinates from mVertices within the aiMesh object. 12
Summary Confused? We were too. To recap: An aiScene contains (usually one) aiMesh. An aiMesh has many aiFaces. Each aiFace contains three indices (located in mIndices). An aiMesh also contains a aiVector3D *mVertices attribute. This is the vertex coordinate info that the GPU needs to render our models, but we need the mIndices values to correctly obtain this data. 13
Pseudocode Initialize an Assimp::Importer object and use it to read in your .obj file. Find out how many aiMesh objects are in your aiScene. For the .obj files we use, there s usually only one aiMesh, so the following pseudocode will require modification if more than one aiMesh is present. What modifications would you make? Obtain the single aiMesh object from the aiScene. Iterate through each aiFace in the given aiMesh. Use the values found in the current aiFace s mIndices array to offset into the aiMesh s mVertices array and save these values to an array (of Vertex structs) that can be sent to the GPU. What about color? 14
Resources Assimp s documentation: http://assimp.sourceforge.net/lib_html/index.html A very detailed link: http://ogldev.atspace.co.uk/www/tutorial22/tutorial22 .html 15
Sample Screenshots The next few slides will have screenshots from the code section of the presentation. 16
Questions? 19