From 5a2e309b411d38f2d488ab7035147ed885ec0a03 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Wed, 30 May 2018 21:06:57 +0200 Subject: [PATCH] small fix --- src/tools/newresourcepack.cpp | 15 ++------------- src/tools/newresourcepack.h | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/tools/newresourcepack.cpp b/src/tools/newresourcepack.cpp index e98bfd9..6939bd5 100644 --- a/src/tools/newresourcepack.cpp +++ b/src/tools/newresourcepack.cpp @@ -34,29 +34,17 @@ void NewResourcePack::gui() tmp.m_resources = this->m_resources; output(tmp); }catch(cereal::Exception e){ - std::cerr << "WUT : " << e.what() << std::endl; + std::cerr << "Error while saving resource pack : " << e.what() << std::endl; } } if(ImGui::Button("Load resource pack")) { -// std::fstream file; -// file.open("data/" + m_name + ".pack", std::ios_base::in); -// ObjectLoader loader; -// loader.loadAscii(file); -// file.close(); -// const std::vector& packVec = loader.getObjects(); -// for(ResourceInterface* res : m_resources) -// delete res; -// m_resources = packVec[0]->m_resources; -// delete packVec[0]; - std::ifstream inputStream("data/"+m_name+".pack"); cereal::JSONInputArchive input(inputStream); NewResourcePack tmp = NewResourcePack(); input(tmp); this->m_name = tmp.m_name; this->m_resources = tmp.m_resources; - inputStream.close(); } if(ImGui::Button("Add a texture")) @@ -149,6 +137,7 @@ void TextureResource::destroy() void TextureResource::gui() { char buf[1024] = {0}; + // m_name = ResourceInterface::m_name; strcpy(buf, m_path.c_str()); if(ImGui::InputText("Image file", buf, 1024)) m_path = buf; diff --git a/src/tools/newresourcepack.h b/src/tools/newresourcepack.h index 2c57282..a667d40 100644 --- a/src/tools/newresourcepack.h +++ b/src/tools/newresourcepack.h @@ -82,6 +82,9 @@ public: void gui(); }; +CEREAL_REGISTER_TYPE(TextureResource) +CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,TextureResource) + class MaterialResource : public ResourceInterface { glm::vec3 m_albedo; @@ -126,9 +129,25 @@ public: void gui(); }; -CEREAL_REGISTER_TYPE(TextureResource) -CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,TextureResource) -//CEREAL_REGISTER_TYPE(MaterialResource) -//CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,MaterialResource) +template +void serialize(Archive & archive,MaterialResource mat) +{ + archive(CEREAL_NVP(mat.m_name), + CEREAL_NVP(mat.m_albedo), + CEREAL_NVP(mat.m_metallic), + CEREAL_NVP(mat.m_roughness), + CEREAL_NVP(mat.m_emission), + CEREAL_NVP(mat.m_opacity), + CEREAL_NVP(mat.m_albedoTexture), + CEREAL_NVP(mat.m_metallicTexture), + CEREAL_NVP(mat.m_roughnessTexture), + CEREAL_NVP(mat.m_emissionTexture), + CEREAL_NVP(mat.m_normalTexture), + CEREAL_NVP(mat.m_alphaMaskTexture)); +} + +CEREAL_REGISTER_TYPE(MaterialResource) +CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,MaterialResource) + #endif // NEWRESOURCEPACK_H