mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Reworked material serialization
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <src/Resource/FontAwesome5.h>
|
||||
#include <src/Vendors/imgui/imgui_internal.h>
|
||||
#include "../Misc/InterfaceFonts.h"
|
||||
#include <src/Resource/ResourceManager.h>
|
||||
|
||||
void MaterialEditor::Draw(Ref<Nuake::Material> material)
|
||||
{
|
||||
@@ -19,6 +20,11 @@ void MaterialEditor::Draw(Ref<Nuake::Material> 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);
|
||||
|
||||
@@ -116,9 +116,9 @@ namespace Nuake
|
||||
json Serialize() override
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
|
||||
|
||||
j["Path"] = Path;
|
||||
j["UUID"] = static_cast<uint64_t>(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<Texture> 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<Texture> 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<Texture> normalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetMetalness(normalTexture);
|
||||
}
|
||||
|
||||
if (j.contains("Normal"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]);
|
||||
Ref<Texture> normalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetMetalness(normalTexture);
|
||||
}
|
||||
if (j.contains("AO"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["AO"]["Path"]);
|
||||
Ref<Texture> aoTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetAO(aoTexture);
|
||||
}
|
||||
|
||||
if (j.contains("AO"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["AO"]["Path"]);
|
||||
Ref<Texture> aoTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetAO(aoTexture);
|
||||
}
|
||||
if (j.contains("Metalness"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Metalness"]["Path"]);
|
||||
Ref<Texture> metalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetMetalness(metalTexture);
|
||||
}
|
||||
|
||||
if (j.contains("Metalness"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Metalness"]["Path"]);
|
||||
Ref<Texture> metalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetMetalness(metalTexture);
|
||||
}
|
||||
if (j.contains("Roughness"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Roughness"]["Path"]);
|
||||
Ref<Texture> metalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetRoughness(metalTexture);
|
||||
}
|
||||
|
||||
if (j.contains("Roughness"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Roughness"]["Path"]);
|
||||
Ref<Texture> metalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetRoughness(metalTexture);
|
||||
}
|
||||
|
||||
if (j.contains("Displacement"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]);
|
||||
Ref<Texture> displacementTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetDisplacement(displacementTexture);
|
||||
}
|
||||
if (j.contains("Displacement"))
|
||||
{
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]);
|
||||
Ref<Texture> displacementTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetDisplacement(displacementTexture);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "src/Scene/Components/ParticleEmitterComponent.h"
|
||||
|
||||
#include <src/Resource/ResourceManager.h>
|
||||
#include <src/Resource/ResourceLoader.h>
|
||||
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<Material> newMaterial = CreateRef<Material>();
|
||||
newMaterial->Deserialize(j["ParticleMaterial"]);
|
||||
ParticleMaterial = newMaterial;
|
||||
if (j["ParticleMaterial"].contains("Path"))
|
||||
{
|
||||
Ref<Material> newMaterial = ResourceLoader::LoadMaterial(j["ParticleMaterial"]["Path"]);
|
||||
ParticleMaterial = newMaterial;
|
||||
}
|
||||
}
|
||||
GravityRandom = j["GravityRandom"];
|
||||
Radius = j["Radius"];
|
||||
|
||||
Reference in New Issue
Block a user