You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
894 B
30 lines
894 B
#include "mesh.hpp"
|
|
#include <assimp/Importer.hpp>
|
|
#include <assimp/scene.h>
|
|
#include <assimp/postprocess.h>
|
|
#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<glm::vec3*>(&mesh->mVertices[i]);
|
|
glm::vec3 color = {0, 0, 0};
|
|
glm::vec2 uv = {0, 0};
|
|
if (mesh->mNumUVComponents[0] == 2)
|
|
uv = *reinterpret_cast<glm::vec2*>(&mesh->mTextureCoords[0][i]);
|
|
glm::vec3 normal = {0, 0, 0};
|
|
if (mesh->mNormals != nullptr)
|
|
normal = *reinterpret_cast<glm::vec3*>(&mesh->mNormals[i]);
|
|
vertices.push_back({pos, color, uv, normal});
|
|
}
|
|
|
|
for (size_t i = 0; i < mesh->mNumFaces; i++){
|
|
faces.push_back(*reinterpret_cast<Face*>(mesh->mFaces[i].mIndices));
|
|
}
|
|
|
|
}
|
|
|