| 15 | ModelLoader::~ModelLoader() {} |
| 16 | |
| 17 | Ref<Model> ModelLoader::LoadModel(const std::string& path, bool absolute) |
| 18 | { |
| 19 | m_Meshes.clear(); |
| 20 | Ref<Model> model = CreateRef<Model>(path); |
| 21 | |
| 22 | Assimp::Importer importer; |
| 23 | importer.SetPropertyFloat("PP_GSN_MAX_SMOOTHING_ANGLE", 90); |
| 24 | |
| 25 | auto importFlags = |
| 26 | aiProcess_Triangulate | |
| 27 | aiProcess_GenSmoothNormals | |
| 28 | aiProcess_FixInfacingNormals | |
| 29 | aiProcess_CalcTangentSpace; |
| 30 | |
| 31 | modelDir = absolute ? path + "/../" : FileSystem::Root + path + "/../"; |
| 32 | const std::string filePath = absolute ? path : FileSystem::Root + path; |
| 33 | const aiScene* scene = importer.ReadFile(filePath, importFlags); |
| 34 | if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) |
| 35 | { |
| 36 | std::string assimpErrorMsg = std::string(importer.GetErrorString()); |
| 37 | std::string logMsg = "[Failed to load model] - " + assimpErrorMsg; |
| 38 | Logger::Log(logMsg, "model", WARNING); |
| 39 | |
| 40 | return model; |
| 41 | } |
| 42 | |
| 43 | ProcessNode(scene->mRootNode, scene); |
| 44 | |
| 45 | for (const auto& mesh : m_Meshes) |
| 46 | { |
| 47 | model->AddMesh(mesh); |
| 48 | } |
| 49 | |
| 50 | importer.FreeScene(); |
| 51 | |
| 52 | return model; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | std::unordered_map<std::string, uint32_t> bonesNameIDMap; |
no test coverage detected