#include "newresourcepack.h" #include "loader.h" #include "resourcemanager.h" #include #include #include #include #include #include #include #include void NewResourcePack::gui() { static std::shared_ptr currentResource = nullptr; ImGui::Begin("ResourcePack"); char buf[1024] = {0}; strcpy(buf, m_name.c_str()); if(ImGui::InputText("Pack name", buf, 1024)) m_name = buf; if(ImGui::Button("Save resource pack")) { try{ std::ofstream outputStream("data/"+m_name+".pack"); cereal::JSONOutputArchive output(outputStream); NewResourcePack tmp; tmp.m_name = this->m_name; tmp.m_resources = this->m_resources; output(tmp); }catch(cereal::Exception e){ std::cerr << "Error while saving resource pack : " << e.what() << std::endl; } } if(ImGui::Button("Load resource pack")) { 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; } if(ImGui::Button("Add a texture")) { std::shared_ptr resource(new TextureResource()); m_resources.push_back(resource); } if(ImGui::Button("Add a material")) { std::shared_ptr resource(new MaterialResource()); // MaterialResource* resource = new MaterialResource(); m_resources.push_back(resource); } for(std::shared_ptr res : m_resources) { if(ImGui::Button(res->m_name.c_str())) currentResource = res; } ImGui::End(); if(currentResource != nullptr) { bool opened = true; ImGui::Begin("Resource Editor", &opened); char resBuf[1024] = {0}; strcpy(resBuf, currentResource->m_name.c_str()); if(ImGui::InputText("Name (should be unique)", resBuf, 1024)) currentResource->m_name = resBuf; currentResource->gui(); if(ImGui::Button("Delete resource")) { for(unsigned int i=0; ialbedo = m_albedo; m_material->metallic = m_metallic; m_material->roughness = m_roughness; m_material->emission = m_emission; m_material->opacity = m_opacity; m_material->setTexture(PBRMaterial::ALBEDO_SLOT, RESOURCE_GET(Texture, m_albedoTexture)); m_material->setTexture(PBRMaterial::METALLIC_SLOT, RESOURCE_GET(Texture, m_metallicTexture)); m_material->setTexture(PBRMaterial::ROUGHNESS_SLOT, RESOURCE_GET(Texture, m_roughnessTexture)); m_material->setTexture(PBRMaterial::EMISSION_SLOT, RESOURCE_GET(Texture, m_emissionTexture)); m_material->setTexture(PBRMaterial::NORMALS_SLOT, RESOURCE_GET(Texture, m_normalTexture)); m_material->setTexture(PBRMaterial::ALPHA_SLOT, RESOURCE_GET(Texture, m_alphaMaskTexture)); RESOURCE_ADD(m_material, PBRMaterial, m_name); progress = 1; } void MaterialResource::destroy() { if(m_material != nullptr) { delete m_material; m_material = nullptr; RESOURCE_REMOVE(PBRMaterial,m_name); } } void MaterialResource::gui() { ImGui::Text("TODO"); }