mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Model loader now takes into account submeshes transform
This commit is contained in:
@@ -194,10 +194,6 @@ Ref<Nuake::Texture> ThumbnailManager::GenerateThumbnail(const std::string& path,
|
||||
|
||||
ModelComponent& modelComp = scene->CreateEntity("Mesh").AddComponent<ModelComponent>();
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ File::File(Ref<Directory> 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;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
#include "Texture.h"
|
||||
#include "src/Core/Logger.h"
|
||||
#include <iostream>
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include "src/Core/String.h"
|
||||
|
||||
#include "dds/dds.h"
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
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<unsigned char> fileData(fileSize);
|
||||
file.seekg(0);
|
||||
file.read(reinterpret_cast<char*>(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);
|
||||
|
||||
@@ -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<Mesh> ModelLoader::ProcessMesh(aiMesh* node, const aiScene* scene)
|
||||
Ref<Mesh> 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> mesh = CreateRef<Mesh>();
|
||||
mesh->AddSurface(vertices, indices);
|
||||
@@ -502,7 +507,7 @@ namespace Nuake
|
||||
{
|
||||
materialNode->GetTexture(aiTextureType_DIFFUSE_ROUGHNESS, 0, &str);
|
||||
Ref<Texture> albedoTexture = ProcessTextures(scene, str.C_Str());
|
||||
material->SetRoughness(albedoTexture);
|
||||
//material->SetRoughness(albedoTexture);
|
||||
}
|
||||
|
||||
if (materialNode->GetTextureCount(aiTextureType_DISPLACEMENT) > 0)
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Nuake
|
||||
std::unordered_map<std::string, Bone> m_BoneMap;
|
||||
|
||||
void ProcessNode(aiNode* node, const aiScene* scene);
|
||||
Ref<Mesh> ProcessMesh(aiMesh* node, const aiScene* scene);
|
||||
Ref<Mesh> ProcessMesh(aiMesh* mesh, aiNode* node, const aiScene* scene);
|
||||
|
||||
std::vector<Vertex> ProcessVertices(aiMesh* mesh);
|
||||
std::vector<uint32_t> ProcessIndices(aiMesh* mesh);
|
||||
|
||||
Reference in New Issue
Block a user