From d38b92b8da6ba6ab590cb97379b4fce9789014e9 Mon Sep 17 00:00:00 2001 From: ternaryop8479 Date: Thu, 12 Feb 2026 00:00:48 +0800 Subject: [PATCH] =?UTF-8?q?remove=EF=BC=9A=E5=88=A0=E9=99=A4model=5Floader?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/resource/model_loader.h | 58 ---------- src/resource/model_loader.cpp | 187 -------------------------------- 2 files changed, 245 deletions(-) delete mode 100644 include/resource/model_loader.h delete mode 100644 src/resource/model_loader.cpp diff --git a/include/resource/model_loader.h b/include/resource/model_loader.h deleted file mode 100644 index 27e6994..0000000 --- a/include/resource/model_loader.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef ARE_INCLUDE_RESOURCE_MODEL_LOADER_H -#define ARE_INCLUDE_RESOURCE_MODEL_LOADER_H - -#include "basic/types.h" -#include "scene/mesh.h" -#include "scene/material.h" -#include -#include -#include - -namespace are { - -/// @brief Model loader using Assimp -class ModelLoader { -public: - /// @brief Load model from file - /// @param path Model file path - /// @param meshes Output mesh list - /// @param materials Output material list - /// @param flip_uvs Flip UV coordinates vertically - /// @return True if loading succeeded - static bool load(const std::string& path, - std::vector>& meshes, - std::vector>& materials, - bool flip_uvs = true); - - /// @brief Load model and automatically upload to GPU - /// @param path Model file path - /// @param meshes Output mesh list - /// @param materials Output material list - /// @param flip_uvs Flip UV coordinates vertically - /// @return True if loading succeeded - static bool load_and_upload(const std::string& path, - std::vector>& meshes, - std::vector>& materials, - bool flip_uvs = true); - -private: - /// @brief Process Assimp node recursively - static void process_node_(void* node, void* scene, - std::vector>& meshes, - std::vector>& materials, - const std::string& directory); - - /// @brief Process Assimp mesh - static std::shared_ptr process_mesh_(void* mesh, void* scene, - std::vector>& materials, - const std::string& directory); - - /// @brief Load material textures - static void load_material_textures_(void* material, int type, - std::shared_ptr& mat, - const std::string& directory); -}; - -} // namespace are - -#endif // ARE_INCLUDE_RESOURCE_MODEL_LOADER_H diff --git a/src/resource/model_loader.cpp b/src/resource/model_loader.cpp deleted file mode 100644 index b6c0424..0000000 --- a/src/resource/model_loader.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include "resource/model_loader.h" -#include "utils/logger.h" -#include "resource/texture.h" - -// Note: This is a simplified implementation without Assimp -// For full implementation, include Assimp and implement properly - -namespace are { - -bool ModelLoader::load(const std::string& path, - std::vector>& meshes, - std::vector>& materials, - bool flip_uvs) { - Logger::error("ModelLoader requires Assimp library (not implemented in this version)"); - Logger::info("To implement: include , , "); - - // Placeholder implementation - // TODO: Implement with Assimp - /* - Assimp::Importer importer; - const aiScene* scene = importer.ReadFile(path, - aiProcess_Triangulate | - aiProcess_GenNormals | - aiProcess_CalcTangentSpace | - (flip_uvs ? aiProcess_FlipUVs : 0)); - - if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) { - Logger::error("Failed to load model: " + std::string(importer.GetErrorString())); - return false; - } - - std::string directory = path.substr(0, path.find_last_of('/')); - process_node_(scene->mRootNode, scene, meshes, materials, directory); - - Logger::info("Model loaded: " + path); - return true; - */ - - return false; -} - -bool ModelLoader::load_and_upload(const std::string& path, - std::vector>& meshes, - std::vector>& materials, - bool flip_uvs) { - if (!load(path, meshes, materials, flip_uvs)) { - return false; - } - - // Upload all meshes to GPU - for (auto& mesh : meshes) { - if (!mesh->upload_to_gpu()) { - Logger::error("Failed to upload mesh to GPU"); - return false; - } - } - - return true; -} - -void ModelLoader::process_node_(void* node, void* scene, - std::vector>& meshes, - std::vector>& materials, - const std::string& directory) { - // TODO: Implement with Assimp - /* - aiNode* ai_node = static_cast(node); - const aiScene* ai_scene = static_cast(scene); - - // Process all meshes in this node - for (uint i = 0; i < ai_node->mNumMeshes; ++i) { - aiMesh* ai_mesh = ai_scene->mMeshes[ai_node->mMeshes[i]]; - meshes.push_back(process_mesh_(ai_mesh, ai_scene, materials, directory)); - } - - // Process children recursively - for (uint i = 0; i < ai_node->mNumChildren; ++i) { - process_node_(ai_node->mChildren[i], ai_scene, meshes, materials, directory); - } - */ -} - -std::shared_ptr ModelLoader::process_mesh_(void* mesh, void* scene, - std::vector>& materials, - const std::string& directory) { - // TODO: Implement with Assimp - /* - aiMesh* ai_mesh = static_cast(mesh); - const aiScene* ai_scene = static_cast(scene); - - std::vector vertices; - std::vector indices; - - // Process vertices - for (uint i = 0; i < ai_mesh->mNumVertices; ++i) { - Vertex vertex; - - vertex.position_ = Vec3(ai_mesh->mVertices[i].x, - ai_mesh->mVertices[i].y, - ai_mesh->mVertices[i].z); - - if (ai_mesh->HasNormals()) { - vertex.normal_ = Vec3(ai_mesh->mNormals[i].x, - ai_mesh->mNormals[i].y, - ai_mesh->mNormals[i].z); - } - - if (ai_mesh->mTextureCoords[0]) { - vertex.texcoord_ = Vec2(ai_mesh->mTextureCoords[0][i].x, - ai_mesh->mTextureCoords[0][i].y); - } - - if (ai_mesh->HasTangentsAndBitangents()) { - vertex.tangent_ = Vec3(ai_mesh->mTangents[i].x, - ai_mesh->mTangents[i].y, - ai_mesh->mTangents[i].z); - } - - vertices.push_back(vertex); - } - - // Process indices - for (uint i = 0; i < ai_mesh->mNumFaces; ++i) { - aiFace face = ai_mesh->mFaces[i]; - for (uint j = 0; j < face.mNumIndices; ++j) { - indices.push_back(face.mIndices[j]); - } - } - - // Process material - uint material_id = materials.size(); - if (ai_mesh->mMaterialIndex >= 0) { - aiMaterial* ai_material = ai_scene->mMaterials[ai_mesh->mMaterialIndex]; - - auto material = std::make_shared(); - - // Load diffuse color - aiColor3D color; - if (ai_material->Get(AI_MATKEY_COLOR_DIFFUSE, color) == AI_SUCCESS) { - material->set_albedo(Vec3(color.r, color.g, color.b)); - } - - // Load textures - load_material_textures_(ai_material, aiTextureType_DIFFUSE, material, directory); - load_material_textures_(ai_material, aiTextureType_NORMALS, material, directory); - - materials.push_back(material); - } - - auto mesh_obj = std::make_shared(); - mesh_obj->set_vertices(vertices); - mesh_obj->set_indices(indices); - mesh_obj->set_material(material_id); - - return mesh_obj; - */ - - return nullptr; -} - -void ModelLoader::load_material_textures_(void* material, int type, - std::shared_ptr& mat, - const std::string& directory) { - // TODO: Implement with Assimp - /* - aiMaterial* ai_material = static_cast(material); - aiTextureType ai_type = static_cast(type); - - for (uint i = 0; i < ai_material->GetTextureCount(ai_type); ++i) { - aiString str; - ai_material->GetTexture(ai_type, i, &str); - - std::string filename = directory + "/" + std::string(str.C_Str()); - - auto texture = std::make_shared(); - if (texture->load_from_file(filename)) { - if (ai_type == aiTextureType_DIFFUSE) { - mat->set_albedo_texture(texture); - } else if (ai_type == aiTextureType_NORMALS) { - mat->set_normal_texture(texture); - } - } - } - */ -} - -} // namespace are