11#include <assimp/Importer.hpp>
12#include <assimp/scene.h>
13#include <assimp/postprocess.h>
27 for (
u32 i = 0; i < Node->mNumMeshes; i++)
29 aiMesh *
mesh = Scene->mMeshes[Node->mMeshes[i]];
31 GenerateSubmesh(
mesh, generating_submesh_props);
32 OutSubmeshes.push_back(generating_submesh_props);
36 for (
u32 i = 0; i < Node->mNumChildren; i++)
43 for (
u32 i = 0; i < Mesh->mNumVertices; i++)
46 v.
Position = { Mesh->mVertices[i].x, Mesh->mVertices[i].y, Mesh->mVertices[i].z };
47 v.
TexCoords = Mesh->mTextureCoords[0] ?
vec2 { Mesh->mTextureCoords[0][i].x, Mesh->mTextureCoords[0][i].y } :
vec2 {};
51 for (
u32 i = 0; i < Mesh->mNumFaces; i++)
53 const aiFace &face = Mesh->mFaces[i];
54 for (
u32 j = 0; j < face.mNumIndices; j++)
60 OutSubmeshProps.
Material = GenerateSubmeshMaterial(Mesh);
66 if (Mesh->mMaterialIndex < 0)
return mat;
68 aiMaterial *ai_mat = Scene->mMaterials[Mesh->mMaterialIndex];
70 if (ai_mat->GetTextureCount(aiTextureType_DIFFUSE) > 0)
72 ai_mat->GetTexture(aiTextureType_DIFFUSE, 0, &path);
75 if (ai_mat->GetTextureCount(aiTextureType_SPECULAR) > 0)
77 ai_mat->GetTexture(aiTextureType_SPECULAR, 0, &path);
80 if (ai_mat->GetTextureCount(aiTextureType_EMISSIVE) > 0)
82 ai_mat->GetTexture(aiTextureType_EMISSIVE, 0, &path);
85 if (ai_mat->GetTextureCount(aiTextureType_NORMALS) > 0)
87 ai_mat->GetTexture(aiTextureType_NORMALS, 0, &path);
95 const std::string &DirectoryPath,
97 Scene(Scene), DirectoryPath(DirectoryPath), OutSubmeshes(OutSubmeshes) {}
101 SCL_CORE_INFO(
"Mesh creation from file \"{}\" started (this may take time).", ModelFilePath.string());
103 u32 flags = aiProcess_Triangulate
104 | aiProcess_OptimizeMeshes
105 | aiProcess_GenNormals
106 | aiProcess_CalcTangentSpace;
107 Assimp::Importer importer {};
108 const aiScene *
scene = importer.ReadFile(ModelFilePath.string(), flags);
110 "Error while loading model: {}", importer.GetErrorString());
112 std::vector<submesh_props<vertex>> out_submeshes;
117 loaded_mesh->FileName = ModelFilePath.string();
#define SCL_CORE_ASSERT(expr,...)
void ProcessNode(aiNode *Node)
mesh_loader_phong(const aiScene *Scene, const std::string &DirectoryPath, std::vector< submesh_props< vertex > > &OutSubmeshes)
static shared< material_phong > Create(const vec3 &Diffuse, const vec3 &Specular, float Shininess)
static shared< mesh > Create(const Ttopology &TopologyObject, shared< material > Material)
std::vector< Tvertex > Vertices
std::vector< u32 > Indices
virtual void EvaluateNormals()
virtual void EvaluateTangentSpace()
#define SCL_CORE_INFO(...)
Mesh material for bling-phone lighting model class deinition module.
Mesh interfaces definition module. Mesh stores vertex and index buffer and implement their binding du...
shared< texture_2d > LoadTexture(const std::filesystem::path &TextureImageFilePath)
shared< mesh > LoadMeshes(const std::filesystem::path &ModelFilePath)
std::shared_ptr< T > shared
Base, abstract, backend render api independent render context class implementation module.
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.
shared< material > Material
topology::trimesh Topology
Assets manager texture load function defintion modulule.
Topology object triangles mesh class declaration module.
Vertex description and storage classes definition module.