removed old resourcepack
This commit is contained in:
parent
5ad3a94927
commit
00dc46be50
@ -3,7 +3,7 @@
|
||||
#include "engine.h"
|
||||
#include "tools/scenepicker.h"
|
||||
#include "scene/scenetree.h"
|
||||
#include "tools/newresourcepack.h"
|
||||
#include "tools/resourcepack.h"
|
||||
#include "editor/objecteditor.h"
|
||||
#include "sparrowshell/sparrowshell.h"
|
||||
|
||||
@ -185,7 +185,7 @@ void Editor::toggleRenderingPipelineGui()
|
||||
void Editor::toggleResourcePackGui()
|
||||
{
|
||||
if(m_editedResourcePack == nullptr)
|
||||
m_editedResourcePack = new NewResourcePack();
|
||||
m_editedResourcePack = new ResourcePack();
|
||||
else
|
||||
{
|
||||
delete m_editedResourcePack;
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
class Engine;
|
||||
class ScenePicker;
|
||||
class NewResourcePack;
|
||||
class ResourcePack;
|
||||
class ObjectEditor;
|
||||
class Mesh;
|
||||
|
||||
@ -13,7 +13,7 @@ class Editor : public SceneNode
|
||||
{
|
||||
ScenePicker* m_pickerNode;
|
||||
Mesh* m_selectedMesh;
|
||||
NewResourcePack* m_editedResourcePack;
|
||||
ResourcePack* m_editedResourcePack;
|
||||
ObjectEditor* m_objectEditor;
|
||||
bool m_materialEditorEnabled;
|
||||
bool m_editorEnabled;
|
||||
|
@ -6,9 +6,8 @@
|
||||
#include <fstream>
|
||||
#include <cstdio>
|
||||
|
||||
//#include <SparrowSerializer/serializationmanager.h>
|
||||
|
||||
#include <cereal/archives/json.hpp>
|
||||
#include <cereal/types/array.hpp>
|
||||
|
||||
#include <SparrowRenderer/opengl.h>
|
||||
|
||||
@ -82,37 +81,20 @@ const std::string& LoadingThread::getCurrentTaskName()
|
||||
|
||||
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");
|
||||
cereal::JSONInputArchive input(inputStream);
|
||||
NewResourcePack pack;
|
||||
// input(pack);
|
||||
ResourcePack pack = ResourcePack();
|
||||
input(pack);
|
||||
for(std::shared_ptr<ResourceInterface> res : pack.m_resources)
|
||||
{
|
||||
if((m_references[res->m_name] += 1) == 1)
|
||||
m_resourceQueue.push_back(res);
|
||||
//else
|
||||
//delete res;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if((m_references[res->m_name] -= 1) == 0)
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <deque>
|
||||
#include <thread>
|
||||
|
||||
#include "newresourcepack.h"
|
||||
#include "resourcepack.h"
|
||||
|
||||
class LoadingThread
|
||||
{
|
||||
@ -13,7 +13,7 @@ class LoadingThread
|
||||
static std::thread* thread;
|
||||
|
||||
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;
|
||||
ResourceInterface* m_currentTask;
|
||||
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/pbrmaterial.h>
|
||||
|
||||
#include <SparrowSerializer/serializationmanager.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");
|
||||
char buf[1024] = {0};
|
||||
@ -27,40 +23,41 @@
|
||||
|
||||
if(ImGui::Button("Save resource pack"))
|
||||
{
|
||||
std::fstream file;
|
||||
ObjectSaver saver;
|
||||
saver.addObject(this);
|
||||
file.open("data/" + m_name + ".pack", std::ios_base::out);
|
||||
saver.saveAscii(file);
|
||||
file.close();
|
||||
try{
|
||||
std::ofstream outputStream("data/"+m_name+".pack");
|
||||
cereal::JSONOutputArchive output(outputStream);
|
||||
ResourcePack 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::fstream file;
|
||||
file.open("data/" + m_name + ".pack", std::ios_base::in);
|
||||
ObjectLoader loader;
|
||||
loader.loadAscii(file);
|
||||
file.close();
|
||||
const std::vector<ResourcePack*>& packVec = loader.getObjects<ResourcePack>();
|
||||
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);
|
||||
ResourcePack tmp = ResourcePack();
|
||||
input(tmp);
|
||||
this->m_name = tmp.m_name;
|
||||
this->m_resources = tmp.m_resources;
|
||||
}
|
||||
|
||||
if(ImGui::Button("Add a texture"))
|
||||
{
|
||||
TextureResource* resource = new TextureResource();
|
||||
std::shared_ptr<ResourceInterface> resource(new TextureResource());
|
||||
m_resources.push_back(resource);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
for(ResourceInterface* res : m_resources)
|
||||
for(std::shared_ptr<ResourceInterface> res : m_resources)
|
||||
{
|
||||
if(ImGui::Button(res->m_name.c_str()))
|
||||
currentResource = res;
|
||||
@ -85,7 +82,7 @@
|
||||
if(m_resources[i] == currentResource)
|
||||
{
|
||||
m_resources.erase(m_resources.begin() + i);
|
||||
delete currentResource;
|
||||
//delete currentResource;
|
||||
currentResource = nullptr;
|
||||
}
|
||||
}
|
||||
@ -94,11 +91,9 @@
|
||||
if(!opened)
|
||||
currentResource = nullptr;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//INIT_SERIALIZABLE(TextureResource)
|
||||
|
||||
/*TextureResource::TextureResource() :
|
||||
TextureResource::TextureResource() :
|
||||
m_texture(nullptr)
|
||||
{
|
||||
m_name = "new texture";
|
||||
@ -111,9 +106,9 @@
|
||||
TextureResource::~TextureResource()
|
||||
{
|
||||
destroy();
|
||||
}*/
|
||||
}
|
||||
|
||||
/* void TextureResource::load(float & progress)
|
||||
void TextureResource::loadResource(float &progress)
|
||||
{
|
||||
progress = 0;
|
||||
Image* img = Loader::loadImage(m_path,m_bitsPerPixel,m_isVerticallyReversed);
|
||||
@ -125,9 +120,8 @@ TextureResource::~TextureResource()
|
||||
delete img;
|
||||
progress = 1;
|
||||
}
|
||||
*/
|
||||
|
||||
/* void TextureResource::destroy()
|
||||
void TextureResource::destroy()
|
||||
{
|
||||
if(m_texture != nullptr)
|
||||
{
|
||||
@ -135,11 +129,12 @@ TextureResource::~TextureResource()
|
||||
m_texture = nullptr;
|
||||
RESOURCE_REMOVE(Texture,m_name);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/*void TextureResource::gui()
|
||||
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;
|
||||
@ -151,15 +146,12 @@ TextureResource::~TextureResource()
|
||||
{
|
||||
float temp;
|
||||
if(m_texture == nullptr)
|
||||
load(temp);
|
||||
loadResource(temp);
|
||||
else
|
||||
destroy();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//INIT_SERIALIZABLE(MaterialResource)
|
||||
|
||||
/*
|
||||
MaterialResource::MaterialResource() :
|
||||
m_material(nullptr)
|
||||
{
|
||||
@ -176,7 +168,7 @@ MaterialResource::~MaterialResource()
|
||||
destroy();
|
||||
}
|
||||
|
||||
void MaterialResource::load(float & progress)
|
||||
void MaterialResource::loadResource(float &progress)
|
||||
{
|
||||
m_material = new PBRMaterial();
|
||||
m_material->albedo = m_albedo;
|
||||
@ -207,4 +199,4 @@ void MaterialResource::destroy()
|
||||
void MaterialResource::gui()
|
||||
{
|
||||
ImGui::Text("TODO");
|
||||
}*/
|
||||
}
|
||||
|
@ -1,50 +1,66 @@
|
||||
#ifndef 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 PBRMaterial;
|
||||
class Mesh;
|
||||
|
||||
/**
|
||||
* @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 gui() {}
|
||||
};*/
|
||||
virtual void gui() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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)
|
||||
P_VECTOR_REFERENCE(ResourceInterface, m_resources)
|
||||
std::string m_name;
|
||||
std::vector<std::shared_ptr<ResourceInterface>> m_resources;
|
||||
|
||||
ResourcePack() {}
|
||||
|
||||
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)
|
||||
P_INT(m_bitsPerPixel)
|
||||
P_BOOL(m_isVerticallyReversed)
|
||||
P_BOOL(m_needsMipMaps)
|
||||
// std::string m_name;
|
||||
std::string m_path;
|
||||
int m_bitsPerPixel;
|
||||
bool m_isVerticallyReversed;
|
||||
bool m_needsMipMaps;
|
||||
|
||||
Texture* m_texture;
|
||||
|
||||
@ -52,28 +68,38 @@ public:
|
||||
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 gui();
|
||||
};*/
|
||||
};
|
||||
|
||||
/*class MaterialResource : public ResourceInterface
|
||||
CEREAL_REGISTER_TYPE(TextureResource)
|
||||
CEREAL_REGISTER_POLYMORPHIC_RELATION(ResourceInterface,TextureResource)
|
||||
|
||||
class MaterialResource : public ResourceInterface
|
||||
{
|
||||
P_VEC3(m_albedo)
|
||||
P_FLOAT(m_metallic)
|
||||
P_FLOAT(m_roughness)
|
||||
P_VEC3(m_emission)
|
||||
P_FLOAT(m_opacity)
|
||||
P_STRING(m_albedoTexture)
|
||||
P_STRING(m_metallicTexture)
|
||||
P_STRING(m_roughnessTexture)
|
||||
P_STRING(m_emissionTexture)
|
||||
P_STRING(m_normalTexture)
|
||||
P_STRING(m_alphaMaskTexture)
|
||||
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;
|
||||
|
||||
@ -81,25 +107,72 @@ public:
|
||||
MaterialResource();
|
||||
virtual ~MaterialResource();
|
||||
|
||||
SERIALIZABLE(MaterialResource,
|
||||
CAST(m_name),
|
||||
CAST(m_albedo),
|
||||
CAST(m_metallic),
|
||||
CAST(m_roughness),
|
||||
CAST(m_emission),
|
||||
CAST(m_opacity),
|
||||
CAST(m_albedoTexture),
|
||||
CAST(m_metallicTexture),
|
||||
CAST(m_roughnessTexture),
|
||||
CAST(m_emissionTexture),
|
||||
CAST(m_normalTexture),
|
||||
CAST(m_alphaMaskTexture))
|
||||
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 load(float & progress);
|
||||
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)
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user