diff --git a/Editor/src/ComponentsPanel/MaterialEditor.cpp b/Editor/src/ComponentsPanel/MaterialEditor.cpp index 6e58d6e9..c63386cc 100644 --- a/Editor/src/ComponentsPanel/MaterialEditor.cpp +++ b/Editor/src/ComponentsPanel/MaterialEditor.cpp @@ -3,6 +3,7 @@ #include #include #include "../Misc/InterfaceFonts.h" +#include void MaterialEditor::Draw(Ref material) { @@ -19,6 +20,11 @@ void MaterialEditor::Draw(Ref material) UIFont boldfont = UIFont(Fonts::Icons); if (ImGui::Button(ICON_FA_SAVE)) { + if (ResourceManager::IsResourceLoaded(material->ID)) + { + ResourceManager::RegisterResource(material); + } + std::string fileData = material->Serialize().dump(4); FileSystem::BeginWriteFile(FileSystem::Root + material->Path); diff --git a/Nuake/src/Rendering/Textures/Material.h b/Nuake/src/Rendering/Textures/Material.h index 94f295d9..c829a638 100644 --- a/Nuake/src/Rendering/Textures/Material.h +++ b/Nuake/src/Rendering/Textures/Material.h @@ -116,9 +116,9 @@ namespace Nuake json Serialize() override { BEGIN_SERIALIZE(); - + + j["Path"] = Path; j["UUID"] = static_cast(ID); - j["HasAlbedo"] = this->HasAlbedo(); if (HasAlbedo()) { @@ -140,7 +140,7 @@ namespace Nuake } j["HasMetalness"] = this->HasMetalness(); - if(HasMetalness()) + if (HasMetalness()) { j["Metalness"] = m_Metalness->Serialize(); } @@ -164,90 +164,78 @@ namespace Nuake bool Deserialize(const json& j) override { - - if (j.contains("Path")) + + if (j.contains("Albedo")) { - Path = FileSystem::RelativeToAbsolute(j["Path"]); - if (FileSystem::FileExists(Path)) - { - std::string content = FileSystem::ReadFile(Path); - Deserialize(content); - } + const auto& texturePath = j["Albedo"]["Path"]; + const std::string absolutePath = FileSystem::RelativeToAbsolute(texturePath); + Ref albedoTexture = TextureManager::Get()->GetTexture(absolutePath); + SetAlbedo(albedoTexture); } - else + + if (j.contains("AlbedoColor")) { - if (j.contains("Albedo")) - { - const auto& texturePath = j["Albedo"]["Path"]; - const std::string absolutePath = FileSystem::RelativeToAbsolute(texturePath); - Ref albedoTexture = TextureManager::Get()->GetTexture(absolutePath); - SetAlbedo(albedoTexture); - } + DESERIALIZE_VEC3(j["AlbedoColor"], data.m_AlbedoColor); + } - if (j.contains("AlbedoColor")) - { - DESERIALIZE_VEC3(j["AlbedoColor"], data.m_AlbedoColor); - } + if (j.contains("Emissive")) + { + data.u_Emissive = j["Emissive"]; + } - if (j.contains("Emissive")) - { - data.u_Emissive = j["Emissive"]; - } + if (j.contains("MetalnessValue")) + { + data.u_MetalnessValue = j["MetalnessValue"]; + } - if (j.contains("MetalnessValue")) - { - data.u_MetalnessValue = j["MetalnessValue"]; - } + if (j.contains("RoughnessValue")) + { + data.u_RoughnessValue = j["RoughnessValue"]; + } - if (j.contains("RoughnessValue")) - { - data.u_RoughnessValue = j["RoughnessValue"]; - } + if (j.contains("AOValue")) + { + data.u_AOValue = j["AOValue"]; + } - if (j.contains("AOValue")) - { - data.u_AOValue = j["AOValue"]; - } + if (j.contains("Unlit")) + { + data.u_Unlit = j["Unlit"]; + } - if (j.contains("Unlit")) - { - data.u_Unlit = j["Unlit"]; - } + if (j.contains("Normal")) + { + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]); + Ref normalTexture = TextureManager::Get()->GetTexture(absolutePath); + SetMetalness(normalTexture); + } - if (j.contains("Normal")) - { - const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]); - Ref normalTexture = TextureManager::Get()->GetTexture(absolutePath); - SetMetalness(normalTexture); - } + if (j.contains("AO")) + { + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["AO"]["Path"]); + Ref aoTexture = TextureManager::Get()->GetTexture(absolutePath); + SetAO(aoTexture); + } - if (j.contains("AO")) - { - const std::string absolutePath = FileSystem::RelativeToAbsolute(j["AO"]["Path"]); - Ref aoTexture = TextureManager::Get()->GetTexture(absolutePath); - SetAO(aoTexture); - } + if (j.contains("Metalness")) + { + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Metalness"]["Path"]); + Ref metalTexture = TextureManager::Get()->GetTexture(absolutePath); + SetMetalness(metalTexture); + } - if (j.contains("Metalness")) - { - const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Metalness"]["Path"]); - Ref metalTexture = TextureManager::Get()->GetTexture(absolutePath); - SetMetalness(metalTexture); - } + if (j.contains("Roughness")) + { + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Roughness"]["Path"]); + Ref metalTexture = TextureManager::Get()->GetTexture(absolutePath); + SetRoughness(metalTexture); + } - if (j.contains("Roughness")) - { - const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Roughness"]["Path"]); - Ref metalTexture = TextureManager::Get()->GetTexture(absolutePath); - SetRoughness(metalTexture); - } - - if (j.contains("Displacement")) - { - const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]); - Ref displacementTexture = TextureManager::Get()->GetTexture(absolutePath); - SetDisplacement(displacementTexture); - } + if (j.contains("Displacement")) + { + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]); + Ref displacementTexture = TextureManager::Get()->GetTexture(absolutePath); + SetDisplacement(displacementTexture); } return true; diff --git a/Nuake/src/Scene/Components/ParticleEmitterComponent.cpp b/Nuake/src/Scene/Components/ParticleEmitterComponent.cpp index 1a04f189..27940e1c 100644 --- a/Nuake/src/Scene/Components/ParticleEmitterComponent.cpp +++ b/Nuake/src/Scene/Components/ParticleEmitterComponent.cpp @@ -1,5 +1,6 @@ #include "src/Scene/Components/ParticleEmitterComponent.h" - +#include +#include namespace Nuake { json ParticleEmitterComponent::Serialize() @@ -14,7 +15,6 @@ namespace Nuake SERIALIZE_VAL(GravityRandom); SERIALIZE_VAL(Radius); SERIALIZE_VAL(GlobalSpace); - SERIALIZE_OBJECT(ParticleMaterial); END_SERIALIZE(); @@ -40,9 +40,11 @@ namespace Nuake } if (j.contains("ParticleMaterial")) { - Ref newMaterial = CreateRef(); - newMaterial->Deserialize(j["ParticleMaterial"]); - ParticleMaterial = newMaterial; + if (j["ParticleMaterial"].contains("Path")) + { + Ref newMaterial = ResourceLoader::LoadMaterial(j["ParticleMaterial"]["Path"]); + ParticleMaterial = newMaterial; + } } GravityRandom = j["GravityRandom"]; Radius = j["Radius"];