This commit is contained in:
Lendemor 2017-08-29 17:15:19 +02:00
commit c9050f5ea4
13 changed files with 195 additions and 36 deletions

View File

@ -1,4 +1,4 @@
#include "guitools.h" #include "editor.h"
#include "engine.h" #include "engine.h"
#include "tools/scenepicker.h" #include "tools/scenepicker.h"
@ -13,7 +13,7 @@
#include <glm/ext.hpp> #include <glm/ext.hpp>
GuiTools::GuiTools() : Editor::Editor() :
m_pickerNode(new ScenePicker()), m_pickerNode(new ScenePicker()),
m_selectedMesh(nullptr), m_selectedMesh(nullptr),
m_editedResourcePack(nullptr), m_editedResourcePack(nullptr),
@ -24,12 +24,12 @@ GuiTools::GuiTools() :
m_pickerNode->setVisible(false); m_pickerNode->setVisible(false);
} }
GuiTools::~GuiTools() Editor::~Editor()
{ {
delete m_pickerNode; delete m_pickerNode;
} }
void GuiTools::update() void Editor::update()
{ {
// no automatic update of children, we want to update them manually // no automatic update of children, we want to update them manually
// ContainerNode::update(); // ContainerNode::update();
@ -44,7 +44,7 @@ void GuiTools::update()
m_editedResourcePack->gui(); m_editedResourcePack->gui();
} }
void GuiTools::materialGui() void Editor::materialGui()
{ {
static int selectedOption = 0; static int selectedOption = 0;
@ -87,24 +87,24 @@ void GuiTools::materialGui()
ImGui::End(); ImGui::End();
} }
void GuiTools::togglePicker() void Editor::togglePicker()
{ {
m_pickerEnabled = !m_pickerEnabled; m_pickerEnabled = !m_pickerEnabled;
m_pickerNode->setVisible(m_pickerEnabled); m_pickerNode->setVisible(m_pickerEnabled);
} }
void GuiTools::toggleMaterialEditor() void Editor::toggleMaterialEditor()
{ {
m_materialEditorEnabled = !m_materialEditorEnabled; m_materialEditorEnabled = !m_materialEditorEnabled;
} }
void GuiTools::toggleRenderingPipelineGui() void Editor::toggleRenderingPipelineGui()
{ {
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(m_scene->getPipeline()); DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(m_scene->getPipeline());
pipeline->toggleDebugGui(); pipeline->toggleDebugGui();
} }
void GuiTools::toggleResourcePackGui() void Editor::toggleResourcePackGui()
{ {
if(m_editedResourcePack == nullptr) if(m_editedResourcePack == nullptr)
m_editedResourcePack = new ResourcePack(); m_editedResourcePack = new ResourcePack();

View File

@ -1,5 +1,5 @@
#ifndef GUITOOLS_H #ifndef EDITOR_H
#define GUITOOLS_H #define EDITOR_H
#include "scene/containernode.h" #include "scene/containernode.h"
@ -8,7 +8,7 @@ class ScenePicker;
class ResourcePack; class ResourcePack;
class Mesh; class Mesh;
class GuiTools : public ContainerNode class Editor : public ContainerNode
{ {
ScenePicker* m_pickerNode; ScenePicker* m_pickerNode;
Mesh* m_selectedMesh; Mesh* m_selectedMesh;
@ -16,8 +16,8 @@ class GuiTools : public ContainerNode
bool m_pickerEnabled; bool m_pickerEnabled;
bool m_materialEditorEnabled; bool m_materialEditorEnabled;
public: public:
GuiTools(); Editor();
~GuiTools(); ~Editor();
void update(); void update();
void materialGui(); void materialGui();
void togglePicker(); void togglePicker();
@ -26,4 +26,4 @@ public:
void toggleResourcePackGui(); void toggleResourcePackGui();
}; };
#endif // GUITOOLS_H #endif // EDITOR_H

View File

@ -13,7 +13,7 @@
#include "scene/physicsdebugnode.h" #include "scene/physicsdebugnode.h"
#include "imgui/imgui.h" #include "imgui/imgui.h"
#include "tools/loader.h" #include "tools/loader.h"
#include "guitools.h" #include "editor.h"
#include "tools/loadingthread.h" #include "tools/loadingthread.h"
Engine::Engine() : Engine::Engine() :
@ -66,7 +66,7 @@ void Engine::createWindow(std::string title,
m_input = new Input(m_window); m_input = new Input(m_window);
m_renderer->initGL(w, h); m_renderer->initGL(w, h);
m_sparrowshell = new SparrowShell(m_window); m_sparrowshell = new SparrowShell(m_window);
m_guiTools = new GuiTools(); m_editor = new Editor();
m_loadingThread = LoadingThread::init(); m_loadingThread = LoadingThread::init();
} }
@ -179,13 +179,13 @@ void Engine::setScene(std::string scene)
} }
previous_scene->getRootObject()->removeChild(m_sparrowshell); previous_scene->getRootObject()->removeChild(m_sparrowshell);
previous_scene->getRootObject()->removeChild(m_guiTools); previous_scene->getRootObject()->removeChild(m_editor);
m_renderer->setScene(new_scene); m_renderer->setScene(new_scene);
m_renderer->resizeGL(m_window->getSize().x, m_window->getSize().y); m_renderer->resizeGL(m_window->getSize().x, m_window->getSize().y);
new_scene->getRootObject()->addChild(m_sparrowshell); new_scene->getRootObject()->addChild(m_sparrowshell);
new_scene->getRootObject()->addChild(m_guiTools); new_scene->getRootObject()->addChild(m_editor);
} }
void Engine::enablePhysicsDebug() void Engine::enablePhysicsDebug()

View File

@ -8,7 +8,7 @@ class SparrowRenderer;
class SceneTree; class SceneTree;
class SparrowShell; class SparrowShell;
class PhysicsDebugNode; class PhysicsDebugNode;
class GuiTools; class Editor;
class LoadingThread; class LoadingThread;
namespace sf namespace sf
@ -53,7 +53,7 @@ public:
btDiscreteDynamicsWorld* getPhysics() const {return m_world;} btDiscreteDynamicsWorld* getPhysics() const {return m_world;}
SparrowShell* getShell() const {return m_sparrowshell;} SparrowShell* getShell() const {return m_sparrowshell;}
PhysicsDebugNode* getPhysicsDebug() const {return m_physicsDebugNode;} PhysicsDebugNode* getPhysicsDebug() const {return m_physicsDebugNode;}
GuiTools* getGuiTools() const {return m_guiTools;} Editor* getGuiTools() const {return m_editor;}
LoadingThread* getLoadingThread() const {return m_loadingThread;} LoadingThread* getLoadingThread() const {return m_loadingThread;}
SceneTree* getScene() const; SceneTree* getScene() const;
@ -80,7 +80,7 @@ private:
btDiscreteDynamicsWorld* m_world; btDiscreteDynamicsWorld* m_world;
PhysicsDebugNode *m_physicsDebugNode; PhysicsDebugNode *m_physicsDebugNode;
SparrowRenderer* m_renderer; SparrowRenderer* m_renderer;
GuiTools* m_guiTools; Editor* m_editor;
LoadingThread* m_loadingThread; LoadingThread* m_loadingThread;
void update(); void update();

View File

@ -1,12 +1,22 @@
#include "resourcemanager.h" #include "resourcemanager.h"
std::unordered_map<std::string, std::unordered_map<std::string, void*>> ResourceManager::data; std::unordered_map<std::string, std::unordered_map<std::string, void*>> data;
std::unordered_map<std::string, std::unordered_map<std::string, void*>> ResourceManager::getResourceMap()
{
return data;
}
void ResourceManager::add(void* resource, const std::string &type, const std::string name) void ResourceManager::add(void* resource, const std::string &type, const std::string name)
{ {
data[type][name] = resource; data[type][name] = resource;
} }
void ResourceManager::remove(const std::string &type, const std::string name)
{
data[type].erase(name);
}
void* ResourceManager::get(const std::string &type, const std::string name) void* ResourceManager::get(const std::string &type, const std::string name)
{ {
return check(type,name) ? data[type][name] : NULL; return check(type,name) ? data[type][name] : NULL;

View File

@ -8,16 +8,18 @@
#define RESOURCE_GET(type, name) ((type*)(ResourceManager::get(#type, name))) #define RESOURCE_GET(type, name) ((type*)(ResourceManager::get(#type, name)))
#define RESOURCE_CHECK(type,name) ResourceManager::check(#type, name) #define RESOURCE_CHECK(type, name) ResourceManager::check(#type, name)
class ResourceManager #define RESOURCE_REMOVE(type, name) ResourceManager::remove(#type, name)
namespace ResourceManager
{ {
private: std::unordered_map<std::string, std::unordered_map<std::string, void*>> getResourceMap();
static std::unordered_map<std::string, std::unordered_map<std::string, void*>> data;
public: void add(void* resource, const std::string &type, const std::string name);
static void add(void* resource, const std::string &type, const std::string name); void remove(const std::string &type, const std::string name);
static void* get(const std::string &type, const std::string name); void* get(const std::string &type, const std::string name);
static bool check(const std::string &type, const std::string name); bool check(const std::string &type, const std::string name);
}; }
#endif // RESOURCEMANAGER_H #endif // RESOURCEMANAGER_H

View File

@ -8,13 +8,18 @@
#include "SparrowInput/Version.h" #include "SparrowInput/Version.h"
#include "SparrowRenderer/Version.h" #include "SparrowRenderer/Version.h"
#include "SparrowSerializer/Version.h" #include "SparrowSerializer/Version.h"
#include "guitools.h" #include "tools/utils.h"
#include "editor.h"
#define LUA_DEFINE(var) S[#var]=var #define LUA_DEFINE(var) S[#var]=var
#define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var); #define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var);
ScriptNode::ScriptNode() ScriptNode::ScriptNode()
{ {
m_script.open_libraries(sol::lib::base);
m_script.open_libraries(sol::lib::math);
utils::initScriptingUtilsFunctions(this);
LUA_SET_FUN(getDeltaTime); LUA_SET_FUN(getDeltaTime);
LUA_SET_FUN(print); LUA_SET_FUN(print);
LUA_SET_FUN(version); LUA_SET_FUN(version);

View File

@ -6,7 +6,6 @@
class ScriptNode : public GraphicalNode class ScriptNode : public GraphicalNode
{ {
sol::state m_script; sol::state m_script;
std::vector<std::string> functions_name; std::vector<std::string> functions_name;
@ -15,7 +14,9 @@ public:
void update(); void update();
void execute(std::string); void execute(std::string);
std::vector<std::string> possibleCompletion(std::string); std::vector<std::string> possibleCompletion(std::string);
sol::state& getScriptEngine() { return m_script; }
void addAutoCompletionSymbol(const std::string& symbolName) { functions_name.push_back(symbolName); }
/* -- LUA function -- */ /* -- LUA function -- */
void print(std::string); void print(std::string);
void version(); void version();

View File

@ -7,6 +7,7 @@
#include <SparrowRenderer/texture.h> #include <SparrowRenderer/texture.h>
#include <SparrowRenderer/image.h> #include <SparrowRenderer/image.h>
#include <SparrowRenderer/pbrmaterial.h>
#include <SparrowSerializer/serializationmanager.h> #include <SparrowSerializer/serializationmanager.h>
@ -53,6 +54,12 @@ void ResourcePack::gui()
m_resources.push_back(resource); m_resources.push_back(resource);
} }
if(ImGui::Button("Add a material"))
{
MaterialResource* resource = new MaterialResource();
m_resources.push_back(resource);
}
for(ResourceInterface* res : m_resources) for(ResourceInterface* res : m_resources)
{ {
if(ImGui::Button(res->m_name.c_str())) if(ImGui::Button(res->m_name.c_str()))
@ -125,6 +132,7 @@ void TextureResource::destroy()
{ {
delete m_texture; delete m_texture;
m_texture = nullptr; m_texture = nullptr;
RESOURCE_REMOVE(Texture, m_name);
} }
} }
@ -147,3 +155,54 @@ void TextureResource::gui()
destroy(); destroy();
} }
} }
INIT_SERIALIZABLE(MaterialResource)
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::load(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");
}

View File

@ -4,6 +4,7 @@
#include <SparrowSerializer/serializable.h> #include <SparrowSerializer/serializable.h>
class Texture; class Texture;
class PBRMaterial;
/** /**
* @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
@ -60,4 +61,45 @@ public:
void gui(); void gui();
}; };
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)
PBRMaterial* m_material;
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))
void load(float & progress);
void destroy();
void gui();
};
#endif // RESOURCEPACK_H #endif // RESOURCEPACK_H

View File

@ -1,7 +1,7 @@
#include "scenepicker.h" #include "scenepicker.h"
#include "engine.h" #include "engine.h"
#include "guitools.h" #include "editor.h"
#include "scene/scenetree.h" #include "scene/scenetree.h"
#include "scene/playercharacternode.h" #include "scene/playercharacternode.h"
#include "scene/physicsdebugnode.h" #include "scene/physicsdebugnode.h"

View File

@ -3,6 +3,7 @@
//#include "scene/scenetree.h" //#include "scene/scenetree.h"
#include "scene/meshnode.h" #include "scene/meshnode.h"
#include "iostream" #include "iostream"
#include "sparrowshell/scriptnode.h"
std::vector<std::string> utils::split(const std::string &line, char sep){ std::vector<std::string> utils::split(const std::string &line, char sep){
std::vector<std::string> tokens; std::vector<std::string> tokens;
@ -14,6 +15,41 @@ std::vector<std::string> utils::split(const std::string &line, char sep){
tokens.push_back(line.substr(start)); tokens.push_back(line.substr(start));
return tokens; return tokens;
} }
void utils::initScriptingUtilsFunctions(ScriptNode* scriptNode)
{
}
void utils::initStandardScene()
{
/*
* GUI
*
* ENTITIES
* PLAYER
* MOBS
*
* OBJECTS
* ITEMS // the player can interact with it, it is permanent and is saved in the map
* GIBS // only for decorative purposes and ephemere
* PROJECTILES // ballistic object
*
* MAP
* ENVIRONMENT
* FOG
* SUN
* SKY
* GEOMETRY
* CHUNK_NODES // procedural geometry
* MODEL_NODES // modelized geometry
*
*
*
*
*/
}
/* /*
void utils::setPosition2D(MeshNode *mnode, glm::vec2 pos){ void utils::setPosition2D(MeshNode *mnode, glm::vec2 pos){
const glm::mat4 &tr = mnode->getTransform(); const glm::mat4 &tr = mnode->getTransform();
@ -42,3 +78,4 @@ void setDepth2D(MeshNode* mnode, float depth){
//mesh.setDepth(depth); //mesh.setDepth(depth);
} }
*/ */

View File

@ -6,10 +6,13 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
class MeshNode; class MeshNode;
class ScriptNode;
namespace utils namespace utils
{ {
std::vector<std::string> split(const std::string &line, char sep); std::vector<std::string> split(const std::string &line, char sep);
void initScriptingUtilsFunctions(ScriptNode* scriptNode);
void initStandardScene();
//void setPosition2D(MeshNode*, glm::vec2); //void setPosition2D(MeshNode*, glm::vec2);
//void resize2D(MeshNode*, glm::vec2, glm::vec2); //void resize2D(MeshNode*, glm::vec2, glm::vec2);
//void scale2D(MeshNode*, glm::vec2); //void scale2D(MeshNode*, glm::vec2);