diff --git a/Editor/src/Misc/ThumbnailManager.cpp b/Editor/src/Misc/ThumbnailManager.cpp index c40a259e..55991109 100644 --- a/Editor/src/Misc/ThumbnailManager.cpp +++ b/Editor/src/Misc/ThumbnailManager.cpp @@ -194,10 +194,6 @@ Ref ThumbnailManager::GenerateThumbnail(const std::string& path, ModelComponent& modelComp = scene->CreateEntity("Mesh").AddComponent(); modelComp.ModelResource = ResourceLoader::LoadModel(file->GetRelativePath()); - - AABB aabb = modelComp.ModelResource->GetMeshes()[0]->GetAABB(); - Vector3 middlePoint = aabb.Max / 2.0f; - scene->Update(0.01f); scene->Draw(*m_ShadedFramebuffer.get()); } diff --git a/Nuake/src/FileSystem/File.cpp b/Nuake/src/FileSystem/File.cpp index 577ceed8..32bbaec0 100644 --- a/Nuake/src/FileSystem/File.cpp +++ b/Nuake/src/FileSystem/File.cpp @@ -16,7 +16,7 @@ File::File(Ref parentDir, const std::string& fullPath, const std::str FileType File::GetFileType() const { const std::string ext = GetExtension(); - if (ext == ".png" || ext == ".jpg") + if (ext == ".png" || ext == ".jpg" || ext == ".dds") { return FileType::Image; } @@ -79,7 +79,7 @@ FileType File::GetFileType() const return FileType::Mesh; } - if (ext == ".glb" || ext == ".gltf") + if (ext == ".glb" || ext == ".gltf" || ext == ".fbx") { return FileType::MeshAsset; } diff --git a/Nuake/src/Rendering/Textures/Texture.cpp b/Nuake/src/Rendering/Textures/Texture.cpp index ee60db60..b838ee13 100644 --- a/Nuake/src/Rendering/Textures/Texture.cpp +++ b/Nuake/src/Rendering/Textures/Texture.cpp @@ -1,10 +1,15 @@ #include "Texture.h" #include "src/Core/Logger.h" -#include #include "src/FileSystem/FileSystem.h" +#include "src/Core/String.h" + +#include "dds/dds.h" #include +#include +#include + namespace Nuake { @@ -17,8 +22,42 @@ namespace Nuake m_Height = 0; m_BPP = 0; - stbi_set_flip_vertically_on_load(1); - m_LocalBuffer = stbi_load((path).c_str(), &m_Width, &m_Height, &m_BPP, 4); + if (String::EndsWith(path, ".dds")) + { + std::ifstream file(path, std::ios::binary | std::ios::ate); + if (!file) + { + const std::string& msg = "Failed to load texture: " + path; + Logger::Log(msg, "texture", WARNING); + return; + } + + size_t fileSize = file.tellg(); + std::vector fileData(fileSize); + file.seekg(0); + file.read(reinterpret_cast(fileData.data()), fileSize); + file.close(); + + // Parse the DDS header + dds::Header header = dds::read_header(fileData.data(), fileSize); + if (!header.is_valid()) + { + const std::string& msg = "Invalid DDS texture: " + path; + Logger::Log(msg, "texture", WARNING); + return; + } + + // Set texture properties + m_Width = header.width(); + m_Height = header.height(); + + } + else + { + stbi_set_flip_vertically_on_load(1); + m_LocalBuffer = stbi_load((path).c_str(), &m_Width, &m_Height, &m_BPP, 4); + } + glGenTextures(1, &m_RendererId); glBindTexture(GL_TEXTURE_2D, m_RendererId); diff --git a/Nuake/src/Resource/ModelLoader.cpp b/Nuake/src/Resource/ModelLoader.cpp index db713525..da726ef7 100644 --- a/Nuake/src/Resource/ModelLoader.cpp +++ b/Nuake/src/Resource/ModelLoader.cpp @@ -166,7 +166,7 @@ namespace Nuake for (uint32_t i = 0; i < node->mNumMeshes; i++) { aiMesh* mesh = scene->mMeshes[node->mMeshes[i]]; - m_Meshes.push_back(ProcessMesh(mesh, scene)); + m_Meshes.push_back(ProcessMesh(mesh, node, scene)); } for (uint32_t i = 0; i < node->mNumChildren; i++) @@ -255,11 +255,16 @@ namespace Nuake return mesh; } - Ref ModelLoader::ProcessMesh(aiMesh* node, const aiScene* scene) + Ref ModelLoader::ProcessMesh(aiMesh* meshNode, aiNode* node, const aiScene* scene) { - auto vertices = ProcessVertices(node); - auto indices = ProcessIndices(node); - auto material = ProcessMaterials(scene, node); + auto vertices = ProcessVertices(meshNode); + auto indices = ProcessIndices(meshNode); + auto material = ProcessMaterials(scene, meshNode); + + for(auto& vert : vertices) + { + vert.position = ConvertMatrixToGLMFormat(node->mTransformation) * Vector4(vert.position, 1.0f); + } Ref mesh = CreateRef(); mesh->AddSurface(vertices, indices); @@ -502,7 +507,7 @@ namespace Nuake { materialNode->GetTexture(aiTextureType_DIFFUSE_ROUGHNESS, 0, &str); Ref albedoTexture = ProcessTextures(scene, str.C_Str()); - material->SetRoughness(albedoTexture); + //material->SetRoughness(albedoTexture); } if (materialNode->GetTextureCount(aiTextureType_DISPLACEMENT) > 0) diff --git a/Nuake/src/Resource/ModelLoader.h b/Nuake/src/Resource/ModelLoader.h index 598be588..40ea7feb 100644 --- a/Nuake/src/Resource/ModelLoader.h +++ b/Nuake/src/Resource/ModelLoader.h @@ -37,7 +37,7 @@ namespace Nuake std::unordered_map m_BoneMap; void ProcessNode(aiNode* node, const aiScene* scene); - Ref ProcessMesh(aiMesh* node, const aiScene* scene); + Ref ProcessMesh(aiMesh* mesh, aiNode* node, const aiScene* scene); std::vector ProcessVertices(aiMesh* mesh); std::vector ProcessIndices(aiMesh* mesh);