From 384c36ab0d8a0aad00204cc74dcb5e26d22a570e Mon Sep 17 00:00:00 2001 From: epiglottis Date: Wed, 12 Nov 2025 13:26:14 +0800 Subject: [PATCH] remove out of date assimp --- CMakeLists.txt | 3 +- Sources/Engine/RenderSystem/Model.hh | 86 ++++++------ Sources/Engine/RenderSystem/Texture.cc | 184 ++++++------------------- Sources/Engine/RenderSystem/Texture.hh | 16 +-- 4 files changed, 90 insertions(+), 199 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64294b1..b927ba1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) find_package(glm CONFIG REQUIRED) find_package(SDL2_image CONFIG REQUIRED) -find_package(assimp CONFIG REQUIRED) + find_package(yaml-cpp CONFIG REQUIRED) find_package(spdlog CONFIG REQUIRED) @@ -259,7 +259,6 @@ function(build_engine_stclib lib_name) SDL2::SDL2main SDL2_image::SDL2_image glm::glm - assimp::assimp yaml-cpp::yaml-cpp spdlog::spdlog EnTT::EnTT diff --git a/Sources/Engine/RenderSystem/Model.hh b/Sources/Engine/RenderSystem/Model.hh index 3e50d20..6a58773 100644 --- a/Sources/Engine/RenderSystem/Model.hh +++ b/Sources/Engine/RenderSystem/Model.hh @@ -2,7 +2,6 @@ #include - #define DEFAULT_TEXTURE_NAME "defaulttexture.png" #include @@ -11,16 +10,10 @@ #include #include - #include #include #include -#include -#include -#include -#include -#include - +#include #include #include @@ -33,8 +26,9 @@ using namespace std; NAMESPACE_BEGIN -enum class TextureType{ - BASE_COLOR=0, +enum class TextureType +{ + BASE_COLOR = 0, ROUGHNESS, METALIC, NORMAL, @@ -59,7 +53,8 @@ struct Texture class Model; -struct Primitive { +struct Primitive +{ int indicessizes = 0; int indexMaterial; GLuint VAO = 0, VBO = 0, EBO = 0; @@ -68,46 +63,49 @@ struct Primitive { vector vertices; vector indices; - - Primitive(vector vertices, vector indices, GLenum enumIndexMode, int indexMaterial) : - vertices(vertices), indices(indices), - indicessizes(indices.size()), enumIndexMode(enumIndexMode), - indexMaterial(indexMaterial) + Primitive(vector vertices, vector indices, GLenum enumIndexMode, int indexMaterial) : vertices(vertices), indices(indices), + indicessizes(indices.size()), enumIndexMode(enumIndexMode), + indexMaterial(indexMaterial) { this->setupPrimitive(); } void setupPrimitive(); void processPrimitive(); - void drawPrimitive(const Shader& shader, const glm::mat4 transform, const Model* parentmodel) const; + void drawPrimitive(const Shader &shader, const glm::mat4 transform, const Model *parentmodel) const; }; -class Model +class Model { public: - class Material{ + class Material + { public: vector textures; }; - class Mesh{ + class Mesh + { public: glm::mat4 localtransform; vector primitives; - Mesh(glm::mat4 transform, vector primitives) : - localtransform(transform), primitives(primitives){ + Mesh(glm::mat4 transform, vector primitives) : localtransform(transform), primitives(primitives) + { this->setupMesh(); }; + private: void setupMesh(); }; - Model(const fs::path path, bool flipuv=true){ + Model(const fs::path path, bool flipuv = true) + { ENGINE_VALIDLOCATION(path); this->modelnameandpath = path; - if(path.extension() != fs::path{".glb"} && path.extension() != fs::path{".gltf"}){ + if (path.extension() != fs::path{".glb"} && path.extension() != fs::path{".gltf"}) + { ENGINE_ERROR("you are loading a model file with non glb/gltf extension, make sure assimp support it\n"); return; } @@ -115,51 +113,49 @@ public: this->loadModel(path.string(), flipuv); } -// void Draw(const Shader& shader) const; - //vaos, render relative infos. + // void Draw(const Shader& shader) const; + // vaos, render relative infos. vector getMeshes() const { return meshes; } fs::path getDirectory() const { return directory; } glm::mat4 getTransform() const { return transform; } void setTransform(glm::mat4 transform) { this->transform = transform; } - Shader* getShader() const { return shader; } - void setShader(Shader* shader) { this->shader = shader; } + Shader *getShader() const { return shader; } + void setShader(Shader *shader) { this->shader = shader; } vector getMaterials() const { return materials; } - + protected: - std::unordered_map* loadedTextures; + std::unordered_map *loadedTextures; glm::mat4 transform = glm::mat4(1.0f); vector meshes; vector materials; fs::path directory; fs::path modelnameandpath; - - Shader* shader; - Material PBRload(tinygltf::Material& gltfmat, tinygltf::Model& gltfmodel); + Shader *shader; + + Material PBRload(tinygltf::Material &gltfmat, tinygltf::Model &gltfmodel); void loadModel(string path, bool flipUVy = false); - void loadMaterials(tinygltf::Model& model); - void processNode(tinygltf::Node* node, tinygltf::Model* model, glm::mat4 transformParent); - optional processMesh(const tinygltf::Node* node, const tinygltf::Model* model, glm::mat4 transform); - optional loadMaterialTextures(aiMaterial* mat, aiTextureType type, string typeName); + void loadMaterials(tinygltf::Model &model); + void processNode(tinygltf::Node *node, tinygltf::Model *model, glm::mat4 transformParent); + optional processMesh(const tinygltf::Node *node, const tinygltf::Model *model, glm::mat4 transform); Texture loadTexturefromGLB( - tinygltf::Model& gltfmodel, - tinygltf::Material& mat, + tinygltf::Model &gltfmodel, + tinygltf::Material &mat, int index, - TextureType textype - ); + TextureType textype); - static Texture loadDefaultTexture() { + static Texture loadDefaultTexture() + { Texture texture; ENGINE_DEBUG("loading default texture\n"); - texture.id = TextureSdlGl{ fs::path{fs::current_path() / DEFAULT_TEXTURE_NAME}.string() }.getTextureId(); + texture.id = TextureSdlGl{fs::path{fs::current_path() / DEFAULT_TEXTURE_NAME}.string()}.getTextureId(); texture.type = TextureType::COUNT; - texture.type_str = { DEFAULT_TEXTURE_NAME }; + texture.type_str = {DEFAULT_TEXTURE_NAME}; return texture; } - }; NAMESPACE_END \ No newline at end of file diff --git a/Sources/Engine/RenderSystem/Texture.cc b/Sources/Engine/RenderSystem/Texture.cc index 6cc5ba3..4cc6c93 100644 --- a/Sources/Engine/RenderSystem/Texture.cc +++ b/Sources/Engine/RenderSystem/Texture.cc @@ -2,155 +2,53 @@ NAMESPACE_BEGIN -TextureSdlGl::TextureSdlGl(string filepathTexture) { - SDL_Surface *surface = IMG_Load(filepathTexture.c_str()); - if(surface == NULL){ - ENGINE_ERROR("Creating SDL_Surface from filepath Error: %s\n", IMG_GetError()); - } - - //safely force convert into rgba32 format under sdl_surface - surface = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0); - if (surface == NULL){ - ENGINE_ERROR("Safely convert raw SDL_Surface into rgba32 SDL_Surface Error: %s\n", SDL_GetError()); - } - - - glGenTextures(1, &textureId); - glBindTexture(GL_TEXTURE_2D, textureId); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - - - glTexImage2D(GL_TEXTURE_2D, - 0, - GL_RGBA, - surface->w, - surface->h, - 0, - GL_RGBA, - GL_UNSIGNED_BYTE, - surface->pixels - ); - GLenum errorClass; - while((errorClass = glGetError()) != GL_NO_ERROR){ - ENGINE_ERROR("SDL surface to GL texture Error: %u\n", errorClass); - } - - glGenerateMipmap(GL_TEXTURE_2D); - - - while((errorClass = glGetError()) != GL_NO_ERROR){ - ENGINE_ERROR("GL generate Mipmap Error: %u\n", errorClass); - } - - - SDL_FreeSurface(surface); - glBindTexture(GL_TEXTURE_2D, 0); +TextureSdlGl::TextureSdlGl(string filepathTexture) +{ + SDL_Surface *surface = IMG_Load(filepathTexture.c_str()); + if (surface == NULL) + { + ENGINE_ERROR("Creating SDL_Surface from filepath Error: %s\n", IMG_GetError()); } + // safely force convert into rgba32 format under sdl_surface + surface = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0); + if (surface == NULL) + { + ENGINE_ERROR("Safely convert raw SDL_Surface into rgba32 SDL_Surface Error: %s\n", SDL_GetError()); + } - TextureSdlGl::TextureSdlGl(const aiTexture* inmemptr) { - SDL_RWops* rw = nullptr; - SDL_Surface* surface = nullptr; - if (inmemptr == nullptr) { - ENGINE_ERROR("Creating TextureSdlGl from aiTexture* Error: input pointer is null\n"); - return; - } - if (inmemptr->mHeight == 0) { - ENGINE_INFO("Creating TextureSDLGL from compressed file format"); - - rw = SDL_RWFromConstMem(inmemptr->pcData, inmemptr->mWidth); - surface = IMG_Load_RW(rw, 1); - } else { - ENGINE_INFO("Creating TextureSDLGL from uncompressed file format"); - surface = SDL_CreateRGBSurfaceFrom( - (void*)inmemptr->pcData, - inmemptr->mWidth, - inmemptr->mHeight, - 32, - inmemptr->mWidth * 4, - 0x000000FF, - 0x0000FF00, - 0x00FF0000, - 0xFF000000 - ); - - } - auto sdl_error = IMG_GetError(); - if (string{sdl_error} != "") { - ENGINE_ERROR("Creating SDL_Surface from aiTexture* Error: {}\n", string{sdl_error}); - } else { - ENGINE_DEBUG("SDL_Surface created from aiTexture* successfully\n"); - } -//what is this????? -// //load from compressed format -// if (inmemptr->mFormatHint != "rgba8888" && inmemptr->mFormatHint != "argb8888") { -// ENGINE_ERROR("Creating TextureSdlGl from aiTexture* Error: only support rgba8888 and argb8888 format, got {}\n", inmemptr->mFormatHint); -// return; -// } -// -// SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom( -// (void*)inmemptr->pcData, -// inmemptr->mWidth, -// inmemptr->mHeight, -// 32, -// inmemptr->mWidth * 4, -// SDL_PIXELFORMAT_RGBA32 -// ); - if(surface == NULL){ - ENGINE_ERROR("Creating SDL_Surface from aiTexture* Error: {}\n", SDL_GetError()); - return; - } - - glGenTextures(1, &textureId); - glBindTexture(GL_TEXTURE_2D, textureId); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - - //convert to rgba32 format - surface = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0); - if (surface == NULL){ - ENGINE_ERROR("Safely convert raw SDL_Surface into rgba32 SDL_Surface Error: {}\n", SDL_GetError()); - return; - } - - glTexImage2D(GL_TEXTURE_2D, - 0, - GL_RGBA, - surface->w, - surface->h, - 0, - GL_RGBA, - GL_UNSIGNED_BYTE, - surface->pixels - ); - - - GLenum errorClass; - while((errorClass = glGetError()) != GL_NO_ERROR){ - ENGINE_ERROR("SDL surface to GL texture Error: %u\n", errorClass); - } - - - glGenerateMipmap(GL_TEXTURE_2D); - - - while((errorClass = glGetError()) != GL_NO_ERROR){ - ENGINE_ERROR("GL generate Mipmap Error: {}\n", errorClass); - } - - - SDL_FreeSurface(surface); - glBindTexture(GL_TEXTURE_2D, 0); + glGenTextures(1, &textureId); + glBindTexture(GL_TEXTURE_2D, textureId); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGBA, + surface->w, + surface->h, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + surface->pixels); + GLenum errorClass; + while ((errorClass = glGetError()) != GL_NO_ERROR) + { + ENGINE_ERROR("SDL surface to GL texture Error: %u\n", errorClass); } + glGenerateMipmap(GL_TEXTURE_2D); + while ((errorClass = glGetError()) != GL_NO_ERROR) + { + ENGINE_ERROR("GL generate Mipmap Error: %u\n", errorClass); + } + SDL_FreeSurface(surface); + glBindTexture(GL_TEXTURE_2D, 0); +} NAMESPACE_END \ No newline at end of file diff --git a/Sources/Engine/RenderSystem/Texture.hh b/Sources/Engine/RenderSystem/Texture.hh index 666280e..3a38774 100644 --- a/Sources/Engine/RenderSystem/Texture.hh +++ b/Sources/Engine/RenderSystem/Texture.hh @@ -8,23 +8,23 @@ #include #include -//decoupling possible? -#include +// decoupling possible? using namespace std; NAMESPACE_BEGIN -class TextureSdlGl { +class TextureSdlGl +{ public: TextureSdlGl(string filepathTexture); - GLuint getTextureId() { + GLuint getTextureId() + { return textureId; } - TextureSdlGl(const aiTexture* inmemptr); - - ~TextureSdlGl() { + ~TextureSdlGl() + { } private: @@ -32,6 +32,4 @@ private: GLenum errorClass; }; - - NAMESPACE_END \ No newline at end of file