removed old resourcepack
This commit is contained in:
parent
5ad3a94927
commit
00dc46be50
@ -3,7 +3,7 @@
|
|||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "tools/scenepicker.h"
|
#include "tools/scenepicker.h"
|
||||||
#include "scene/scenetree.h"
|
#include "scene/scenetree.h"
|
||||||
#include "tools/newresourcepack.h"
|
#include "tools/resourcepack.h"
|
||||||
#include "editor/objecteditor.h"
|
#include "editor/objecteditor.h"
|
||||||
#include "sparrowshell/sparrowshell.h"
|
#include "sparrowshell/sparrowshell.h"
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ void Editor::toggleRenderingPipelineGui()
|
|||||||
void Editor::toggleResourcePackGui()
|
void Editor::toggleResourcePackGui()
|
||||||
{
|
{
|
||||||
if(m_editedResourcePack == nullptr)
|
if(m_editedResourcePack == nullptr)
|
||||||
m_editedResourcePack = new NewResourcePack();
|
m_editedResourcePack = new ResourcePack();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete m_editedResourcePack;
|
delete m_editedResourcePack;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class Engine;
|
class Engine;
|
||||||
class ScenePicker;
|
class ScenePicker;
|
||||||
class NewResourcePack;
|
class ResourcePack;
|
||||||
class ObjectEditor;
|
class ObjectEditor;
|
||||||
class Mesh;
|
class Mesh;
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ class Editor : public SceneNode
|
|||||||
{
|
{
|
||||||
ScenePicker* m_pickerNode;
|
ScenePicker* m_pickerNode;
|
||||||
Mesh* m_selectedMesh;
|
Mesh* m_selectedMesh;
|
||||||
NewResourcePack* m_editedResourcePack;
|
ResourcePack* m_editedResourcePack;
|
||||||
ObjectEditor* m_objectEditor;
|
ObjectEditor* m_objectEditor;
|
||||||
bool m_materialEditorEnabled;
|
bool m_materialEditorEnabled;
|
||||||
bool m_editorEnabled;
|
bool m_editorEnabled;
|
||||||
|
@ -6,9 +6,8 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
//#include <SparrowSerializer/serializationmanager.h>
|
|
||||||
#include <cereal/archives/json.hpp>
|
#include <cereal/archives/json.hpp>
|
||||||
#include <cereal/types/array.hpp>
|
|
||||||
|
|
||||||
#include <SparrowRenderer/opengl.h>
|
#include <SparrowRenderer/opengl.h>
|
||||||
|
|
||||||
@ -82,37 +81,20 @@ const std::string& LoadingThread::getCurrentTaskName()
|
|||||||
|
|
||||||
void LoadingThread::loadResourcePack(const std::string& name)
|
void LoadingThread::loadResourcePack(const std::string& name)
|
||||||
{
|
{
|
||||||
/* std::fstream file;
|
|
||||||
file.open("data/" + name + ".pack", std::ios_base::in);
|
|
||||||
ObjectLoader loader;
|
|
||||||
loader.loadAscii(file);
|
|
||||||
file.close();
|
|
||||||
const std::vector<NewResourcePack*>& packVec = loader.getObjects<NewResourcePack>();
|
|
||||||
NewResourcePack* pack = packVec[0];
|
|
||||||
m_packs[name] = pack;
|
|
||||||
for(ResourceInterface* res : pack->m_resources)
|
|
||||||
{
|
|
||||||
if((m_references[res->m_name] += 1) == 1)
|
|
||||||
m_resourceQueue.push_back(res);
|
|
||||||
else
|
|
||||||
delete res;
|
|
||||||
}*/
|
|
||||||
std::ifstream inputStream("data/" + name + ".pack");
|
std::ifstream inputStream("data/" + name + ".pack");
|
||||||
cereal::JSONInputArchive input(inputStream);
|
cereal::JSONInputArchive input(inputStream);
|
||||||
NewResourcePack pack;
|
ResourcePack pack = ResourcePack();
|
||||||
// input(pack);
|
input(pack);
|
||||||
for(std::shared_ptr<ResourceInterface> res : pack.m_resources)
|
for(std::shared_ptr<ResourceInterface> res : pack.m_resources)
|
||||||
{
|
{
|
||||||
if((m_references[res->m_name] += 1) == 1)
|
if((m_references[res->m_name] += 1) == 1)
|
||||||
m_resourceQueue.push_back(res);
|
m_resourceQueue.push_back(res);
|
||||||
//else
|
|
||||||
//delete res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadingThread::freeResourcePack(const std::string& name)
|
void LoadingThread::freeResourcePack(const std::string& name)
|
||||||
{
|
{
|
||||||
NewResourcePack* pack = m_packs[name];
|
ResourcePack* pack = m_packs[name];
|
||||||
for(std::shared_ptr<ResourceInterface> res : pack->m_resources)
|
for(std::shared_ptr<ResourceInterface> res : pack->m_resources)
|
||||||
{
|
{
|
||||||
if((m_references[res->m_name] -= 1) == 0)
|
if((m_references[res->m_name] -= 1) == 0)
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "newresourcepack.h"
|
#include "resourcepack.h"
|
||||||
|
|
||||||
class LoadingThread
|
class LoadingThread
|
||||||
{
|
{
|
||||||
@ -13,7 +13,7 @@ class LoadingThread
|
|||||||
static std::thread* thread;
|
static std::thread* thread;
|
||||||
|
|
||||||
std::deque<std::shared_ptr<ResourceInterface>> m_resourceQueue;
|
std::deque<std::shared_ptr<ResourceInterface>> m_resourceQueue;
|
||||||
std::unordered_map<std::string, NewResourcePack*> m_packs;
|
std::unordered_map<std::string, ResourcePack*> m_packs;
|
||||||
std::unordered_map<std::string, int> m_references;
|
std::unordered_map<std::string, int> m_references;
|
||||||
ResourceInterface* m_currentTask;
|
ResourceInterface* m_currentTask;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
|
@ -1,205 +0,0 @@
|
|||||||
#include "newresourcepack.h"
|
|
||||||
|
|
||||||
#include "loader.h"
|
|
||||||
#include "resourcemanager.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include <SparrowRenderer/texture.h>
|
|
||||||
#include <SparrowRenderer/image.h>
|
|
||||||
#include <SparrowRenderer/pbrmaterial.h>
|
|
||||||
|
|
||||||
#include <imgui/imgui.h>
|
|
||||||
#include <cereal/archives/json.hpp>
|
|
||||||
#include <cereal/types/memory.hpp>
|
|
||||||
#include <cereal/types/vector.hpp>
|
|
||||||
|
|
||||||
void NewResourcePack::gui()
|
|
||||||
{
|
|
||||||
static std::shared_ptr<ResourceInterface> 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<ResourceInterface> resource(new TextureResource());
|
|
||||||
m_resources.push_back(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ImGui::Button("Add a material"))
|
|
||||||
{
|
|
||||||
std::shared_ptr<ResourceInterface> resource(new MaterialResource());
|
|
||||||
// MaterialResource* resource = new MaterialResource();
|
|
||||||
m_resources.push_back(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(std::shared_ptr<ResourceInterface> 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; i<m_resources.size(); ++i)
|
|
||||||
{
|
|
||||||
if(m_resources[i] == currentResource)
|
|
||||||
{
|
|
||||||
m_resources.erase(m_resources.begin() + i);
|
|
||||||
//delete currentResource;
|
|
||||||
currentResource = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ImGui::End();
|
|
||||||
if(!opened)
|
|
||||||
currentResource = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TextureResource::TextureResource() :
|
|
||||||
m_texture(nullptr)
|
|
||||||
{
|
|
||||||
m_name = "new texture";
|
|
||||||
m_path = "myTexture.jpg";
|
|
||||||
m_bitsPerPixel = 24;
|
|
||||||
m_isVerticallyReversed = true;
|
|
||||||
m_needsMipMaps = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextureResource::~TextureResource()
|
|
||||||
{
|
|
||||||
destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureResource::loadResource(float &progress)
|
|
||||||
{
|
|
||||||
progress = 0;
|
|
||||||
Image* img = Loader::loadImage(m_path,m_bitsPerPixel,m_isVerticallyReversed);
|
|
||||||
progress = 0.5;
|
|
||||||
if (img == nullptr)
|
|
||||||
return;
|
|
||||||
m_texture = new Texture(img,m_needsMipMaps);
|
|
||||||
RESOURCE_ADD(m_texture,Texture,m_name);
|
|
||||||
delete img;
|
|
||||||
progress = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureResource::destroy()
|
|
||||||
{
|
|
||||||
if(m_texture != nullptr)
|
|
||||||
{
|
|
||||||
delete m_texture;
|
|
||||||
m_texture = nullptr;
|
|
||||||
RESOURCE_REMOVE(Texture,m_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
ImGui::InputInt("bits per pixel", &m_bitsPerPixel);
|
|
||||||
ImGui::Checkbox("is vertically reversed", &m_isVerticallyReversed);
|
|
||||||
ImGui::Checkbox("needs mipmaps", &m_needsMipMaps);
|
|
||||||
ImGui::Text(m_texture == nullptr ? "Texture not loaded" : "Texture loaded");
|
|
||||||
if(ImGui::Button(m_texture == nullptr ? "Load" : "Destroy"))
|
|
||||||
{
|
|
||||||
float temp;
|
|
||||||
if(m_texture == nullptr)
|
|
||||||
loadResource(temp);
|
|
||||||
else
|
|
||||||
destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MaterialResource::MaterialResource() :
|
|
||||||
m_material(nullptr)
|
|
||||||
{
|
|
||||||
m_name = "new material";
|
|
||||||
m_albedo = glm::vec3(0.9f);
|
|
||||||
m_metallic = 0.2f;
|
|
||||||
m_roughness = 0.8f;
|
|
||||||
m_emission = glm::vec3(0);
|
|
||||||
m_opacity = 1.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
MaterialResource::~MaterialResource()
|
|
||||||
{
|
|
||||||
destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaterialResource::loadResource(float &progress)
|
|
||||||
{
|
|
||||||
m_material = new PBRMaterial();
|
|
||||||
m_material->albedo = 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");
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
#ifndef NEWRESOURCEPACK_H
|
|
||||||
#define NEWRESOURCEPACK_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <glm/vec3.hpp>
|
|
||||||
|
|
||||||
#include <cereal/archives/json.hpp>
|
|
||||||
#include <cereal/types/array.hpp>
|
|
||||||
#include <cereal/types/memory.hpp>
|
|
||||||
|
|
||||||
class Texture;
|
|
||||||
class PBRMaterial;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The ResourceInterface struct holds a resource, it handles its loading and its destruction
|
|
||||||
*/
|
|
||||||
struct ResourceInterface
|
|
||||||
{
|
|
||||||
std::string m_name;
|
|
||||||
|
|
||||||
template<class Archive>
|
|
||||||
void serialize(Archive & archive){
|
|
||||||
archive(CEREAL_NVP(m_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void loadResource(float & progress) = 0;
|
|
||||||
|
|
||||||
virtual void destroy() = 0;
|
|
||||||
|
|
||||||
virtual void gui() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The ResourcePack class is just a container of LoadTask, it only exists for serialization purposes
|
|
||||||
*/
|
|
||||||
struct NewResourcePack
|
|
||||||
{
|
|
||||||
std::string m_name;
|
|
||||||
std::vector<std::shared_ptr<ResourceInterface>> m_resources;
|
|
||||||
|
|
||||||
NewResourcePack() {}
|
|
||||||
|
|
||||||
void gui();
|
|
||||||
|
|
||||||
template<class Archive>
|
|
||||||
void serialize(Archive & archive){
|
|
||||||
archive(cereal::make_nvp("ResourcePack",m_name),CEREAL_NVP(m_resources));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Some LoadTask implementations
|
|
||||||
*/
|
|
||||||
|
|
||||||
class TextureResource : public ResourceInterface
|
|
||||||
{
|
|
||||||
// std::string m_name;
|
|
||||||
std::string m_path;
|
|
||||||
int m_bitsPerPixel;
|
|
||||||
bool m_isVerticallyReversed;
|
|
||||||
bool m_needsMipMaps;
|
|
||||||
|
|
||||||
Texture* m_texture;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TextureResource();
|
|
||||||
virtual ~TextureResource();
|
|
||||||
|
|
||||||
template <class Archive>
|
|
||||||
void serialize(Archive & archive)
|
|
||||||
{
|
|
||||||
archive(CEREAL_NVP(m_name),
|
|
||||||
CEREAL_NVP(m_path),
|
|
||||||
CEREAL_NVP(m_bitsPerPixel),
|
|
||||||
CEREAL_NVP(m_isVerticallyReversed),
|
|
||||||
CEREAL_NVP(m_needsMipMaps));
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadResource(float & progress);
|
|
||||||
|
|
||||||
void destroy();
|
|
||||||
void gui();
|
|
||||||
};
|
|
||||||
|
|
||||||
CEREAL_REGISTER_TYPE(TextureResource)
|
|
||||||
CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,TextureResource)
|
|
||||||
|
|
||||||
class MaterialResource : public ResourceInterface
|
|
||||||
{
|
|
||||||
glm::vec3 m_albedo;
|
|
||||||
float m_metallic;
|
|
||||||
float m_roughness;
|
|
||||||
glm::vec3 m_emission;
|
|
||||||
float m_opacity;
|
|
||||||
std::string m_albedoTexture;
|
|
||||||
std::string m_metallicTexture;
|
|
||||||
std::string m_roughnessTexture;
|
|
||||||
std::string m_emissionTexture;
|
|
||||||
std::string m_normalTexture;
|
|
||||||
std::string m_alphaMaskTexture;
|
|
||||||
|
|
||||||
PBRMaterial* m_material;
|
|
||||||
|
|
||||||
public:
|
|
||||||
MaterialResource();
|
|
||||||
virtual ~MaterialResource();
|
|
||||||
|
|
||||||
template<class Archive>
|
|
||||||
void serialize(Archive & archive)
|
|
||||||
{
|
|
||||||
archive(CEREAL_NVP(m_name),
|
|
||||||
CEREAL_NVP(m_albedo),
|
|
||||||
CEREAL_NVP(m_metallic),
|
|
||||||
CEREAL_NVP(m_roughness),
|
|
||||||
CEREAL_NVP(m_emission),
|
|
||||||
CEREAL_NVP(m_opacity),
|
|
||||||
CEREAL_NVP(m_albedoTexture),
|
|
||||||
CEREAL_NVP(m_metallicTexture),
|
|
||||||
CEREAL_NVP(m_roughnessTexture),
|
|
||||||
CEREAL_NVP(m_emissionTexture),
|
|
||||||
CEREAL_NVP(m_normalTexture),
|
|
||||||
CEREAL_NVP(m_alphaMaskTexture));
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadResource(float & progress);
|
|
||||||
|
|
||||||
void destroy();
|
|
||||||
|
|
||||||
void gui();
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class Archive>
|
|
||||||
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
|
|
@ -9,15 +9,11 @@
|
|||||||
#include <SparrowRenderer/image.h>
|
#include <SparrowRenderer/image.h>
|
||||||
#include <SparrowRenderer/pbrmaterial.h>
|
#include <SparrowRenderer/pbrmaterial.h>
|
||||||
|
|
||||||
#include <SparrowSerializer/serializationmanager.h>
|
|
||||||
|
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
//INIT_SERIALIZABLE(ResourcePack)
|
void ResourcePack::gui()
|
||||||
|
|
||||||
/*void ResourcePack::gui()
|
|
||||||
{
|
{
|
||||||
static ResourceInterface* currentResource = nullptr;
|
static std::shared_ptr<ResourceInterface> currentResource = nullptr;
|
||||||
|
|
||||||
ImGui::Begin("ResourcePack");
|
ImGui::Begin("ResourcePack");
|
||||||
char buf[1024] = {0};
|
char buf[1024] = {0};
|
||||||
@ -27,40 +23,41 @@
|
|||||||
|
|
||||||
if(ImGui::Button("Save resource pack"))
|
if(ImGui::Button("Save resource pack"))
|
||||||
{
|
{
|
||||||
std::fstream file;
|
try{
|
||||||
ObjectSaver saver;
|
std::ofstream outputStream("data/"+m_name+".pack");
|
||||||
saver.addObject(this);
|
cereal::JSONOutputArchive output(outputStream);
|
||||||
file.open("data/" + m_name + ".pack", std::ios_base::out);
|
ResourcePack tmp;
|
||||||
saver.saveAscii(file);
|
tmp.m_name = this->m_name;
|
||||||
file.close();
|
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"))
|
if(ImGui::Button("Load resource pack"))
|
||||||
{
|
{
|
||||||
std::fstream file;
|
std::ifstream inputStream("data/"+m_name+".pack");
|
||||||
file.open("data/" + m_name + ".pack", std::ios_base::in);
|
cereal::JSONInputArchive input(inputStream);
|
||||||
ObjectLoader loader;
|
ResourcePack tmp = ResourcePack();
|
||||||
loader.loadAscii(file);
|
input(tmp);
|
||||||
file.close();
|
this->m_name = tmp.m_name;
|
||||||
const std::vector<ResourcePack*>& packVec = loader.getObjects<ResourcePack>();
|
this->m_resources = tmp.m_resources;
|
||||||
for(ResourceInterface* res : m_resources)
|
|
||||||
delete res;
|
|
||||||
m_resources = packVec[0]->m_resources;
|
|
||||||
delete packVec[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ImGui::Button("Add a texture"))
|
if(ImGui::Button("Add a texture"))
|
||||||
{
|
{
|
||||||
TextureResource* resource = new TextureResource();
|
std::shared_ptr<ResourceInterface> resource(new TextureResource());
|
||||||
m_resources.push_back(resource);
|
m_resources.push_back(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ImGui::Button("Add a material"))
|
if(ImGui::Button("Add a material"))
|
||||||
{
|
{
|
||||||
MaterialResource* resource = new MaterialResource();
|
std::shared_ptr<ResourceInterface> resource(new MaterialResource());
|
||||||
|
// MaterialResource* resource = new MaterialResource();
|
||||||
m_resources.push_back(resource);
|
m_resources.push_back(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ResourceInterface* res : m_resources)
|
for(std::shared_ptr<ResourceInterface> res : m_resources)
|
||||||
{
|
{
|
||||||
if(ImGui::Button(res->m_name.c_str()))
|
if(ImGui::Button(res->m_name.c_str()))
|
||||||
currentResource = res;
|
currentResource = res;
|
||||||
@ -85,7 +82,7 @@
|
|||||||
if(m_resources[i] == currentResource)
|
if(m_resources[i] == currentResource)
|
||||||
{
|
{
|
||||||
m_resources.erase(m_resources.begin() + i);
|
m_resources.erase(m_resources.begin() + i);
|
||||||
delete currentResource;
|
//delete currentResource;
|
||||||
currentResource = nullptr;
|
currentResource = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,11 +91,9 @@
|
|||||||
if(!opened)
|
if(!opened)
|
||||||
currentResource = nullptr;
|
currentResource = nullptr;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
//INIT_SERIALIZABLE(TextureResource)
|
TextureResource::TextureResource() :
|
||||||
|
|
||||||
/*TextureResource::TextureResource() :
|
|
||||||
m_texture(nullptr)
|
m_texture(nullptr)
|
||||||
{
|
{
|
||||||
m_name = "new texture";
|
m_name = "new texture";
|
||||||
@ -111,35 +106,35 @@
|
|||||||
TextureResource::~TextureResource()
|
TextureResource::~TextureResource()
|
||||||
{
|
{
|
||||||
destroy();
|
destroy();
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/* void TextureResource::load(float & progress)
|
void TextureResource::loadResource(float &progress)
|
||||||
{
|
{
|
||||||
progress = 0;
|
progress = 0;
|
||||||
Image* img = Loader::loadImage(m_path, m_bitsPerPixel, m_isVerticallyReversed);
|
Image* img = Loader::loadImage(m_path,m_bitsPerPixel,m_isVerticallyReversed);
|
||||||
progress = 0.5;
|
progress = 0.5;
|
||||||
if(img == nullptr)
|
if (img == nullptr)
|
||||||
return;
|
return;
|
||||||
m_texture = new Texture(img, m_needsMipMaps);
|
m_texture = new Texture(img,m_needsMipMaps);
|
||||||
RESOURCE_ADD(m_texture, Texture, m_name);
|
RESOURCE_ADD(m_texture,Texture,m_name);
|
||||||
delete img;
|
delete img;
|
||||||
progress = 1;
|
progress = 1;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/* void TextureResource::destroy()
|
void TextureResource::destroy()
|
||||||
{
|
{
|
||||||
if(m_texture != nullptr)
|
if(m_texture != nullptr)
|
||||||
{
|
{
|
||||||
delete m_texture;
|
delete m_texture;
|
||||||
m_texture = nullptr;
|
m_texture = nullptr;
|
||||||
RESOURCE_REMOVE(Texture, m_name);
|
RESOURCE_REMOVE(Texture,m_name);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/*void TextureResource::gui()
|
void TextureResource::gui()
|
||||||
{
|
{
|
||||||
char buf[1024] = {0};
|
char buf[1024] = {0};
|
||||||
|
// m_name = ResourceInterface::m_name;
|
||||||
strcpy(buf, m_path.c_str());
|
strcpy(buf, m_path.c_str());
|
||||||
if(ImGui::InputText("Image file", buf, 1024))
|
if(ImGui::InputText("Image file", buf, 1024))
|
||||||
m_path = buf;
|
m_path = buf;
|
||||||
@ -151,15 +146,12 @@ TextureResource::~TextureResource()
|
|||||||
{
|
{
|
||||||
float temp;
|
float temp;
|
||||||
if(m_texture == nullptr)
|
if(m_texture == nullptr)
|
||||||
load(temp);
|
loadResource(temp);
|
||||||
else
|
else
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
//INIT_SERIALIZABLE(MaterialResource)
|
|
||||||
|
|
||||||
/*
|
|
||||||
MaterialResource::MaterialResource() :
|
MaterialResource::MaterialResource() :
|
||||||
m_material(nullptr)
|
m_material(nullptr)
|
||||||
{
|
{
|
||||||
@ -176,7 +168,7 @@ MaterialResource::~MaterialResource()
|
|||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialResource::load(float & progress)
|
void MaterialResource::loadResource(float &progress)
|
||||||
{
|
{
|
||||||
m_material = new PBRMaterial();
|
m_material = new PBRMaterial();
|
||||||
m_material->albedo = m_albedo;
|
m_material->albedo = m_albedo;
|
||||||
@ -200,11 +192,11 @@ void MaterialResource::destroy()
|
|||||||
{
|
{
|
||||||
delete m_material;
|
delete m_material;
|
||||||
m_material = nullptr;
|
m_material = nullptr;
|
||||||
RESOURCE_REMOVE(PBRMaterial, m_name);
|
RESOURCE_REMOVE(PBRMaterial,m_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialResource::gui()
|
void MaterialResource::gui()
|
||||||
{
|
{
|
||||||
ImGui::Text("TODO");
|
ImGui::Text("TODO");
|
||||||
}*/
|
}
|
||||||
|
@ -1,50 +1,66 @@
|
|||||||
#ifndef RESOURCEPACK_H
|
#ifndef RESOURCEPACK_H
|
||||||
#define RESOURCEPACK_H
|
#define RESOURCEPACK_H
|
||||||
|
|
||||||
#include <SparrowSerializer/serializable.h>
|
#include <string>
|
||||||
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
|
#include <cereal/archives/json.hpp>
|
||||||
|
#include <cereal/types/array.hpp>
|
||||||
|
#include <cereal/types/memory.hpp>
|
||||||
|
#include <cereal/types/vector.hpp>
|
||||||
|
|
||||||
class Texture;
|
class Texture;
|
||||||
class PBRMaterial;
|
class PBRMaterial;
|
||||||
|
class Mesh;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ResourceInterface struct holds a resource, it handles its loading and its destruction
|
* @brief The ResourceInterface struct holds a resource, it handles its loading and its destruction
|
||||||
**/
|
*/
|
||||||
/*struct ResourceInterface : public Serializable
|
struct ResourceInterface
|
||||||
{
|
{
|
||||||
P_STRING(m_name)
|
std::string m_name;
|
||||||
|
|
||||||
virtual void load(float & progress) = 0;
|
template<class Archive>
|
||||||
|
void serialize(Archive & archive){
|
||||||
|
archive(CEREAL_NVP(m_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void loadResource(float & progress) = 0;
|
||||||
|
|
||||||
virtual void destroy() = 0;
|
virtual void destroy() = 0;
|
||||||
|
|
||||||
virtual void gui() {}
|
virtual void gui() = 0;
|
||||||
};*/
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ResourcePack class is just a container of LoadTask, it only exists for serialization purposes
|
* @brief The ResourcePack class is just a container of LoadTask, it only exists for serialization purposes
|
||||||
*/
|
*/
|
||||||
/*struct ResourcePack : public Serializable
|
struct ResourcePack
|
||||||
{
|
{
|
||||||
P_STRING(m_name)
|
std::string m_name;
|
||||||
P_VECTOR_REFERENCE(ResourceInterface, m_resources)
|
std::vector<std::shared_ptr<ResourceInterface>> m_resources;
|
||||||
|
|
||||||
ResourcePack() {}
|
ResourcePack() {}
|
||||||
|
|
||||||
void gui();
|
void gui();
|
||||||
|
|
||||||
SERIALIZABLE(ResourcePack, CAST(m_name), CAST(m_resources))
|
template<class Archive>
|
||||||
};*/
|
void serialize(Archive & archive){
|
||||||
|
archive(cereal::make_nvp("ResourcePack",m_name),CEREAL_NVP(m_resources));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Some LoadTask implementations
|
* Some LoadTask implementations
|
||||||
//
|
*/
|
||||||
|
|
||||||
/*class TextureResource : public ResourceInterface
|
class TextureResource : public ResourceInterface
|
||||||
{
|
{
|
||||||
P_STRING(m_path)
|
// std::string m_name;
|
||||||
P_INT(m_bitsPerPixel)
|
std::string m_path;
|
||||||
P_BOOL(m_isVerticallyReversed)
|
int m_bitsPerPixel;
|
||||||
P_BOOL(m_needsMipMaps)
|
bool m_isVerticallyReversed;
|
||||||
|
bool m_needsMipMaps;
|
||||||
|
|
||||||
Texture* m_texture;
|
Texture* m_texture;
|
||||||
|
|
||||||
@ -52,28 +68,38 @@ public:
|
|||||||
TextureResource();
|
TextureResource();
|
||||||
virtual ~TextureResource();
|
virtual ~TextureResource();
|
||||||
|
|
||||||
SERIALIZABLE(TextureResource, CAST(m_name), CAST(m_path), CAST(m_bitsPerPixel), CAST(m_isVerticallyReversed), CAST(m_needsMipMaps))
|
template <class Archive>
|
||||||
|
void serialize(Archive & archive)
|
||||||
|
{
|
||||||
|
archive(CEREAL_NVP(m_name),
|
||||||
|
CEREAL_NVP(m_path),
|
||||||
|
CEREAL_NVP(m_bitsPerPixel),
|
||||||
|
CEREAL_NVP(m_isVerticallyReversed),
|
||||||
|
CEREAL_NVP(m_needsMipMaps));
|
||||||
|
}
|
||||||
|
|
||||||
void load(float & progress);
|
void loadResource(float & progress);
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
void gui();
|
void gui();
|
||||||
};*/
|
};
|
||||||
|
|
||||||
/*class MaterialResource : public ResourceInterface
|
CEREAL_REGISTER_TYPE(TextureResource)
|
||||||
|
CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,TextureResource)
|
||||||
|
|
||||||
|
class MaterialResource : public ResourceInterface
|
||||||
{
|
{
|
||||||
P_VEC3(m_albedo)
|
glm::vec3 m_albedo;
|
||||||
P_FLOAT(m_metallic)
|
float m_metallic;
|
||||||
P_FLOAT(m_roughness)
|
float m_roughness;
|
||||||
P_VEC3(m_emission)
|
glm::vec3 m_emission;
|
||||||
P_FLOAT(m_opacity)
|
float m_opacity;
|
||||||
P_STRING(m_albedoTexture)
|
std::string m_albedoTexture;
|
||||||
P_STRING(m_metallicTexture)
|
std::string m_metallicTexture;
|
||||||
P_STRING(m_roughnessTexture)
|
std::string m_roughnessTexture;
|
||||||
P_STRING(m_emissionTexture)
|
std::string m_emissionTexture;
|
||||||
P_STRING(m_normalTexture)
|
std::string m_normalTexture;
|
||||||
P_STRING(m_alphaMaskTexture)
|
std::string m_alphaMaskTexture;
|
||||||
|
|
||||||
PBRMaterial* m_material;
|
PBRMaterial* m_material;
|
||||||
|
|
||||||
@ -81,25 +107,72 @@ public:
|
|||||||
MaterialResource();
|
MaterialResource();
|
||||||
virtual ~MaterialResource();
|
virtual ~MaterialResource();
|
||||||
|
|
||||||
SERIALIZABLE(MaterialResource,
|
template<class Archive>
|
||||||
CAST(m_name),
|
void serialize(Archive & archive)
|
||||||
CAST(m_albedo),
|
{
|
||||||
CAST(m_metallic),
|
archive(CEREAL_NVP(m_name),
|
||||||
CAST(m_roughness),
|
CEREAL_NVP(m_albedo),
|
||||||
CAST(m_emission),
|
CEREAL_NVP(m_metallic),
|
||||||
CAST(m_opacity),
|
CEREAL_NVP(m_roughness),
|
||||||
CAST(m_albedoTexture),
|
CEREAL_NVP(m_emission),
|
||||||
CAST(m_metallicTexture),
|
CEREAL_NVP(m_opacity),
|
||||||
CAST(m_roughnessTexture),
|
CEREAL_NVP(m_albedoTexture),
|
||||||
CAST(m_emissionTexture),
|
CEREAL_NVP(m_metallicTexture),
|
||||||
CAST(m_normalTexture),
|
CEREAL_NVP(m_roughnessTexture),
|
||||||
CAST(m_alphaMaskTexture))
|
CEREAL_NVP(m_emissionTexture),
|
||||||
|
CEREAL_NVP(m_normalTexture),
|
||||||
|
CEREAL_NVP(m_alphaMaskTexture));
|
||||||
|
}
|
||||||
|
|
||||||
void load(float & progress);
|
void loadResource(float & progress);
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
void gui();
|
void gui();
|
||||||
};*/
|
};
|
||||||
|
|
||||||
|
template<class Archive>
|
||||||
|
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)
|
||||||
|
|
||||||
|
class MeshResource : public ResourceInterface
|
||||||
|
{
|
||||||
|
//add metadata for mesh
|
||||||
|
|
||||||
|
Mesh* m_mesh;
|
||||||
|
public:
|
||||||
|
MeshResource();
|
||||||
|
virtual ~MeshResource();
|
||||||
|
|
||||||
|
|
||||||
|
// differentiate load and save ?
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive & archive)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadResource(float & progress);
|
||||||
|
|
||||||
|
void destroy();
|
||||||
|
|
||||||
|
void gui();
|
||||||
|
};
|
||||||
|
|
||||||
#endif // RESOURCEPACK_H
|
#endif // RESOURCEPACK_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user