X-Git-Url: https://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=model.cpp;fp=model.cpp;h=345309a211e30232e2bd0c50a3945ccf74b43542;hp=5302df06238038d32a686e8bffb2c62881f19a91;hb=d26c67a51e58c3f70d1689e265e9bebe578b50ad;hpb=5e2b8438a1600a790dc105d25b7d5cd2278864aa diff --git a/model.cpp b/model.cpp index 5302df0..345309a 100644 --- a/model.cpp +++ b/model.cpp @@ -115,13 +115,13 @@ Model::Mesh::Mesh(const aiMesh *aiMesh, GLuint progId) { glVertexAttribPointer(boneWeightLoc, 4, GL_FLOAT, GL_FALSE, sizeof(VertBones), (const GLvoid *)sizeof(VertBones::ids)); } -Model::Node::Node(const aiNode &node, GLuint progId, AnimMap *am): ai(node), progId(progId), animMap(am) { +Model::Node::Node(aiNode &node, GLuint progId, AnimMap *am, std::set allBones, Node *p): ai(node), parent(p), progId(progId), animMap(am), isBone(allBones.count(std::string(node.mName.C_Str())) > 0) { for (int i = 0; i < node.mNumMeshes; i++) { meshIndices.push_back(node.mMeshes[i]); } for (int i = 0; i < node.mNumChildren; i++) { - const aiNode *child = node.mChildren[i]; - children.push_back(new Node(*child, progId, am)); + aiNode *child = node.mChildren[i]; + children.push_back(new Node(*child, progId, am, allBones, this)); } } @@ -235,6 +235,9 @@ void Model::Node::draw( const std::vector &meshes, glm::mat4 m = totalTrans(parentTrans, tick); #ifdef DEBUG_NODES + if (isBone) + drawDebugNode(m, {0, 0.5, 1, 1}); + else drawDebugNode(m); #endif @@ -291,13 +294,6 @@ void Model::Node::draw( const std::vector &meshes, for (Node *child: children) child->draw(meshes, materials, skybox, tick, boneTransforms, m); } -void printMatrix4x4(aiMatrix4x4 m) { - fprintf(stderr, "%f, %f, %f, %f\n", m.a1, m.a2, m.a3, m.a4); - fprintf(stderr, "%f, %f, %f, %f\n", m.b1, m.b2, m.b3, m.b4); - fprintf(stderr, "%f, %f, %f, %f\n", m.c1, m.c2, m.c3, m.c4); - fprintf(stderr, "%f, %f, %f, %f\n", m.d1, m.d2, m.d3, m.d4); -} - void printHierarchy(aiNode *n, int indent = 0) { for (int i = 0; i < indent; i++) fprintf(stderr, "\t"); @@ -310,9 +306,12 @@ void printHierarchy(aiNode *n, int indent = 0) { Model::Model(const aiScene *scene, Program p): program(p) { glUseProgram(p.progId); + std::set allBones; for (int i = 0; i < scene->mNumMeshes; i++) { const aiMesh *mesh = scene->mMeshes[i]; meshes.push_back(Mesh(mesh, p.progId)); + for (int j = 0; j < mesh->mNumBones; j++) + allBones.insert(std::string(mesh->mBones[j]->mName.C_Str())); } for (unsigned int i = 0; i < scene->mNumMaterials; i++) { @@ -342,7 +341,9 @@ Model::Model(const aiScene *scene, Program p): program(p) { } } - root = new Node(*(scene->mRootNode), p.progId, &animMap); + printHierarchy(scene->mRootNode); + + root = new Node(*(scene->mRootNode), p.progId, &animMap, allBones, nullptr); } @@ -393,3 +394,7 @@ Model::Node* Model::Node::findNode(const aiNode &aiNode) { } return nullptr; } + +bool Model::Node::operator==(const Model::Node &rhs) const { + return &ai == &rhs.ai; +}