SHARE
TWEET

Untitled

a guest Jan 24th, 2020 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // даю рут ноду
  2. void Mesh::DrawNode(aiNode * node, glm::mat4 prtr)
  3. {
  4.     aiMatrix4x4 m = node->mTransformation;
  5.     aiTransposeMatrix4(&m);
  6.  
  7.     glm::mat4 node_tr = glm::make_mat4(&m.a1);
  8.     glm::mat4 new_node_tr = node_tr * prtr;
  9.  
  10.     glm::mat4 pMatrices[MAXBONES];
  11.     for (unsigned int i = 0; i < node->mNumMeshes; i++) {
  12.         const aiMesh* pCurrentMesh = m_scene->mMeshes[node->mMeshes[i]];
  13.         if ((pCurrentMesh->HasBones()) && (animController != nullptr)) {
  14.             const std::vector<aiMatrix4x4>& vBoneMatrices = animController->GetBoneMatrices(node, i);
  15.  
  16.             if (vBoneMatrices.size() != pCurrentMesh->mNumBones) {
  17.                 continue;
  18.             }
  19.  
  20.             for (unsigned int j = 0; j < pCurrentMesh->mNumBones; j++) {
  21.                 if (j < MAXBONES) {
  22.                     pMatrices[j][0][0] = vBoneMatrices[j].a1;
  23.                     pMatrices[j][0][1] = vBoneMatrices[j].b1;
  24.                     pMatrices[j][0][2] = vBoneMatrices[j].c1;
  25.                     pMatrices[j][0][3] = vBoneMatrices[j].d1;
  26.                     pMatrices[j][1][0] = vBoneMatrices[j].a2;
  27.                     pMatrices[j][1][1] = vBoneMatrices[j].b2;
  28.                     pMatrices[j][1][2] = vBoneMatrices[j].c2;
  29.                     pMatrices[j][1][3] = vBoneMatrices[j].d2;
  30.                     pMatrices[j][2][0] = vBoneMatrices[j].a3;
  31.                     pMatrices[j][2][1] = vBoneMatrices[j].b3;
  32.                     pMatrices[j][2][2] = vBoneMatrices[j].c3;
  33.                     pMatrices[j][2][3] = vBoneMatrices[j].d3;
  34.                     pMatrices[j][3][0] = vBoneMatrices[j].a4;
  35.                     pMatrices[j][3][1] = vBoneMatrices[j].b4;
  36.                     pMatrices[j][3][2] = vBoneMatrices[j].c4;
  37.                     pMatrices[j][3][3] = vBoneMatrices[j].d4;
  38.                 }
  39.             }
  40.         }
  41.  
  42.         GLCHECK(glUniformMatrix4fv(program->GetUniformLocation("bones"), pCurrentMesh->mNumBones, GL_FALSE, (float*)pMatrices));
  43.  
  44.         DrawChunk(node->mMeshes[i], new_node_tr);
  45.     }
  46.  
  47.     for (unsigned int i = 0; i < node->mNumChildren; i++)
  48.     {
  49.         DrawNode(node->mChildren[i], new_node_tr);
  50.     }
  51. }
  52.  
  53.  
  54.  
  55. void Mesh::DrawChunk(int index, glm::mat4 tr)
  56. {
  57.     //program->UseProgram();
  58.  
  59.     auto i = meshes[index];
  60.     tr = ModelMatrix * tr;
  61.     program->SetUniform("MVPm", tr);
  62. ................
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top