6 Assimp::Importer importer;
7 const auto aiScene = importer.ReadFile(path,
8 aiProcess_CalcTangentSpace |
9 aiProcess_Triangulate |
10 aiProcess_JoinIdenticalVertices |
11 aiProcess_SortByPType);
13 auto ret = std::make_unique<ModelData>();
14 for (
unsigned int i = 0; i < aiScene->mNumMeshes; i++)
16 const auto aiMesh = aiScene->mMeshes[i];
18 mesh->name = aiMesh->mName.C_Str();
19 mesh->material =
nullptr;
21 mesh->vertices.resize(aiMesh->mNumVertices);
23 if (aiMesh->HasPositions())
25 for (
unsigned int j = 0; j < aiMesh->mNumVertices; j++) {
26 const auto& aiVertex = aiMesh->mVertices[j];
27 mesh->vertices[j].position = { aiVertex.x, aiVertex.y, aiVertex.z };
31 if (aiMesh->HasNormals())
33 for (
unsigned int j = 0; j < aiMesh->mNumVertices; j++) {
34 const auto& aiNormal = aiMesh->mNormals[j];
35 mesh->vertices[j].normal = { aiNormal.x, aiNormal.y, aiNormal.z };
39 for (
unsigned int texCoordSet = 0; texCoordSet < 8; texCoordSet++)
41 if (aiMesh->HasTextureCoords(texCoordSet))
43 for (
unsigned int j = 0; j < aiMesh->mNumVertices; j++) {
44 const auto& aiTexCoord = aiMesh->mTextureCoords[texCoordSet][j];
45 mesh->vertices[j].texCoords[texCoordSet] = { aiTexCoord.x, aiTexCoord.y };
50 if (aiMesh->HasTangentsAndBitangents())
52 for (
unsigned int j = 0; j < aiMesh->mNumVertices; j++) {
53 const auto& aiTangent = aiMesh->mTangents[j];
54 const auto& aiBitangent = aiMesh->mBitangents[j];
55 mesh->vertices[j].tangent = { aiTangent.x, aiTangent.y, aiTangent.z };
56 mesh->vertices[j].bitangent = { aiBitangent.x, aiBitangent.y, aiBitangent.z };
60 for (
unsigned int colorSet = 0; colorSet < 8; colorSet++)
62 if (aiMesh->HasVertexColors(colorSet))
64 for (
unsigned int j = 0; j < aiMesh->mNumVertices; j++) {
65 const auto& aiColor = aiMesh->mColors[colorSet][j];
66 mesh->vertices[j].colors[colorSet] = { aiColor.r, aiColor.g, aiColor.b, aiColor.a };
71 if (aiMesh->HasFaces())
73 mesh->indices.reserve(aiMesh->mNumFaces * 3);
74 for (
unsigned int j = 0; j < aiMesh->mNumFaces; j++)
76 const aiFace& face = aiMesh->mFaces[j];
77 for (
unsigned int k = 0; k < face.mNumIndices; k++)
79 mesh->indices.push_back(face.mIndices[k]);
84 ret->meshes.push_back(mesh);