Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. void ColladaParser::GetMeshData(std::vector<float>& vertices, std::vector<unsigned short>& indices, bool hasAnimation)
  2. {
  3. std::vector<unsigned short> jointList; //ids
  4. std::vector<float> weightList; //vertexWeightData.
  5. GetVertexSkinning(weightList, jointList);
  6. if (hasAnimation) {
  7. //GetVertexSkinning(weightList, jointList);
  8. //jointList = GetVertexJoints();
  9. //weightList = GetVertexWeights();
  10. }
  11.  
  12. auto verticesCorrect = GetVertexPositions();
  13. auto normals = GetVertexNormals();
  14. auto uvs = GetVertexUVs();
  15.  
  16. std::vector<glm::vec3> glmVertices;
  17. std::vector<glm::vec3> glmNormals;
  18. std::vector<glm::vec2> glmUVs;
  19.  
  20. glmVertices.resize(verticesCorrect.size() / 3);
  21. glmNormals.resize(normals.size() / 3);
  22. glmUVs.resize(uvs.size() / 2);
  23.  
  24. size_t i = 0;
  25. for (i = 0; i < verticesCorrect.size() / 3; ++i)
  26. {
  27. float x = verticesCorrect[i * 3];
  28. float y = verticesCorrect[i * 3 + 1];
  29. float z = verticesCorrect[i * 3 + 2];
  30.  
  31. glmVertices[i] = glm::vec3(x, y, z);
  32. }
  33.  
  34. for (i = 0; i < normals.size() / 3; ++i)
  35. {
  36. float nx = normals[i * 3];
  37. float ny = normals[i * 3 + 1];
  38. float nz = normals[i * 3 + 2];
  39.  
  40. glmNormals[i] = glm::vec3(nx, ny, nz);
  41. }
  42.  
  43. for (i = 0; i < uvs.size() / 2; ++i)
  44. {
  45. float u = uvs[i * 2];
  46. float v = uvs[i * 2 + 1];
  47.  
  48. glmUVs[i] = glm::vec2(u, v);
  49. }
  50.  
  51. std::vector<unsigned short> newIndices;
  52. std::vector<glm::vec3> newVertices;
  53. std::vector<glm::vec2> newUVs;
  54. std::vector<glm::vec3> newNormals;
  55.  
  56. indexVBO(glmVertices, glmUVs, glmNormals, newIndices, newVertices, newUVs, newNormals);
  57.  
  58.  
  59. //if hasAnimation alternamos en 2 opciones.
  60. vertices.resize(newVertices.size() * 3 + newNormals.size() * 3 + newUVs.size() * 2);
  61. for (i = 0; i < vertices.size() / 8; ++i)
  62. {
  63. vertices[i * 8] = newVertices[i].x * 0.1f;
  64. vertices[i * 8 + 1] = newVertices[i].y * 0.1f;
  65. vertices[i * 8 + 2] = newVertices[i].z * 0.1f;
  66.  
  67. vertices[i * 8 + 3] = newNormals[i].x;
  68. vertices[i * 8 + 4] = newNormals[i].y;
  69. vertices[i * 8 + 5] = newNormals[i].z;
  70.  
  71. vertices[i * 8 + 6] = newUVs[i].x;
  72. vertices[i * 8 + 7] = 1.0f - newUVs[i].y;
  73. }
  74.  
  75. for (i = 0; i < newIndices.size() / 3; ++i)
  76. {
  77. indices.push_back(newIndices[i * 3 + 2]);
  78. indices.push_back(newIndices[i * 3 + 1]);
  79. indices.push_back(newIndices[i * 3 + 0]);
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement