#include "mesh.hpp" #include #include #include #include "constraints.hpp" Mesh::Mesh(const std::string &fileName) { Assimp::Importer importer; auto scene = importer.ReadFile(fileName, aiProcess_Triangulate); auto mesh = scene->mMeshes[0]; for (size_t i = 0; i < mesh->mNumVertices; i++){ glm::vec3 pos = *reinterpret_cast(&mesh->mVertices[i]); glm::vec3 color = {0, 0, 0}; glm::vec2 uv = {0, 0}; if (mesh->mNumUVComponents[0] == 2) uv = *reinterpret_cast(&mesh->mTextureCoords[0][i]); glm::vec3 normal = {0, 0, 0}; if (mesh->mNormals != nullptr) normal = *reinterpret_cast(&mesh->mNormals[i]); vertices.push_back({pos, color, uv, normal}); } for (size_t i = 0; i < mesh->mNumFaces; i++){ faces.push_back(*reinterpret_cast(mesh->mFaces[i].mIndices)); } }