Last update: 2 September 2015

Tutorial 1: Import Assets

The tutorial  shows  how to use assimp to import and render assets. Assimp can load variaty of 3D models ( 3ds, obj, X, quake and doom models). In addition to vertices positions, normals, texture cooridnates, tangents, bones and their weights (used for character animation in a future tutorial), materials and diffuse texture are extracted from the model and stored in a CMeshBuffer, the CMeshBuffer holds all groups and materials of the mesh. Groups can share materials. When rendering the model, we go through all groups in the mesh buffer, we find the corresponding material for each group, we map the material properties to the shader and finally we draw the group.

Code walkthrough:

We use the CAssimpMesh class to load the mesh into OpenGL array as explained in the previous section. To render the CMeshBuffer we go through all groups of the mesh buffer, we get the corresponding material then we send the appropriate material informations to the shader and we draw the group. The code bellow shows how the CMeshEntity renders its mesh buffer.

    //get the mesh buffer
    CMeshBuffer* buffer = m_pMesh->GetMeshBuffer();
    //go through all groups in the mesh buffer
    for(uint32 g = 0; g < buffer->GroupsCount(); ++g)
        //render each group
        CMeshGroup* grp = buffer->GroupAtIndex(g);
        //get corresponding material for each group
        CMaterial* material = buffer->MaterialForGroup(grp);
        //map material properties to shader (we map only the diffuse texture bcoz there is no lighting)
        if(material != NULL )
            if( material->diffuseTexture != NULL && shader->texture0 != -1)
                glUniform1i(shader->texture0, 0);
        //enable vertex array object (vao)
        //perform GL draw for each group
        glDrawElements(grp->GetDrawingMode(), grp->GetIndices().size(), GL_UNSIGNED_SHORT, 0);