Allow materials to not have some properties
[opengl.git] / model.cpp
index f68db4b6407f2096c4313794e1bb3d1c00e569f1..3c1ecf4830c2ce95989a09bfb4935cfb7d21d767 100644 (file)
--- a/model.cpp
+++ b/model.cpp
@@ -1,16 +1,8 @@
 #include "model.hpp"
 #include <iostream>
-#include <assimp/postprocess.h>
 #include <assimp/quaternion.h>
 #include <glm/gtc/type_ptr.hpp>
 
-glm::mat4 aiMatrixToMat4(aiMatrix4x4 from) {
-       glm::mat4 to;
-       for (int i = 0; i < 4; i++)
-               for (int j = 0; j < 4; j++)
-                       to[i][j] = from[j][i];
-       return to;
-}
 
 Model::Mesh::Mesh(const aiMesh *aiMesh, GLuint progId) {
 
@@ -249,6 +241,9 @@ void Model::Node::draw(     const std::vector<Mesh> &meshes,
                for (std::pair<std::string, std::pair<unsigned int, glm::mat4>> pair: mesh.boneMap) {
 
                        std::string nodeName = pair.first;
+
+                       if (animMap->count(nodeName) <= 0) break;
+
                        unsigned int boneId = pair.second.first;
                        // This is actually an inverse-bind matrix
                        // i.e. position of the mesh in bone space
@@ -300,23 +295,16 @@ void Model::Node::draw(   const std::vector<Mesh> &meshes,
        for (Node *child: children) child->draw(meshes, materials, skybox, tick, m, boneTransforms);
 }
 
-Model::Model(const std::string &path, Program p): program(p) {
+Model::Model(const aiScene *scene, Program p): program(p) {
        glUseProgram(p.progId);
 
-       const aiScene *scene = importer.ReadFile(path, 
-                       aiProcess_Triangulate | aiProcess_CalcTangentSpace | aiProcess_GenNormals | aiProcess_FlipUVs);
-       if (!scene) {
-               std::cerr << importer.GetErrorString() << std::endl;
-               exit(1);
-       }
-
        for (int i = 0; i < scene->mNumMeshes; i++) {
                const aiMesh *mesh = scene->mMeshes[i];
                meshes.push_back(Mesh(mesh, p.progId));
        }
 
        // TODO: handle default material inserted at the end by assimp
-       for (unsigned int i = 0; i < scene->mNumMaterials - 1; i++) {
+       for (unsigned int i = 0; i < scene->mNumMaterials; i++) {
                const aiMaterial &material = *scene->mMaterials[i];
                materials.push_back(Material(material, *scene, p.progId));
        }