Interface component, Serialization of mesh components

This commit is contained in:
antopilo
2021-09-08 18:35:10 -04:00
parent 61e54c5a46
commit b1a1f4f063
14 changed files with 145 additions and 64 deletions

View File

@@ -33,6 +33,7 @@
#include <src/Scene/Components/PrefabComponent.h>
#include <src/Rendering/Shaders/ShaderManager.h>
#include "src/Rendering/Renderer.h"
#include <src/Scene/Components/InterfaceComponent.h>
namespace Nuake {
Ref<UI::UserInterface> userInterface;
@@ -503,6 +504,11 @@ namespace Nuake {
{
m_SelectedEntity.AddComponent<MeshColliderComponent>();
}
ImGui::Separator();
if (ImGui::MenuItem("Interface Component") && !m_SelectedEntity.HasComponent<InterfaceComponent>())
{
m_SelectedEntity.AddComponent< InterfaceComponent>();
}
// your popup code
ImGui::EndPopup();
@@ -523,6 +529,36 @@ namespace Nuake {
ImGui::Separator();
}
if (m_SelectedEntity.HasComponent<InterfaceComponent>())
{
if (ImGui::CollapsingHeader("Interface", ImGuiTreeNodeFlags_DefaultOpen))
{
InterfaceComponent& component = m_SelectedEntity.GetComponent<InterfaceComponent>();
std::string& path = component.Path;
char pathBuffer[256];
memset(pathBuffer, 0, sizeof(pathBuffer));
std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer));
ImGui::Text("Interface: ");
ImGui::SameLine();
if (ImGui::InputText("##InterfacePath", pathBuffer, sizeof(pathBuffer)))
path = FileSystem::AbsoluteToRelative(std::string(pathBuffer));
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Interface"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
path = FileSystem::AbsoluteToRelative(fullPath);
component.SetInterface(path);
}
ImGui::EndDragDropTarget();
}
}
}
if (m_SelectedEntity.HasComponent<MeshComponent>())
{
std::string icon = ICON_FA_MALE;

View File

@@ -121,6 +121,8 @@ namespace Nuake {
dragType = "_Map";
else if (file->Type == ".obj" || file->Type == ".mdl" || file->Type == ".gltf" || file->Type == ".md3" || file->Type == ".fbx")
dragType = "_Model";
else if (file->Type == ".interface")
dragType = "_Interface";
ImGui::SetDragDropPayload(dragType.c_str(), (void*)(pathBuffer), sizeof(pathBuffer));
ImGui::Text(file->name.c_str());

View File

@@ -180,7 +180,8 @@ namespace Nuake
void Renderer2D::EndDraw()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}
}

View File

@@ -1,8 +1,36 @@
#pragma once
#include "../Core/Core.h"
#include <src/UI/UserInterface.h>
#include "src/Core/Core.h"
#include "src/UI/UserInterface.h"
#include "src/Resource/Serializable.h"
class InterfaceComponent
{
Ref<UI::UserInterface> Interface;
};
namespace Nuake {
class InterfaceComponent
{
public:
std::string Path;
Ref<UI::UserInterface> Interface;
json Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL_LBL("Interface", Interface->GetPath())
END_SERIALIZE();
}
bool Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
if (j.contains("Interface"))
SetInterface(j["Interface"]);
return true;
}
void SetInterface(const std::string& path)
{
Path = path;
Interface = UI::UserInterface::New("No name", path);
}
};
}

View File

@@ -2,7 +2,7 @@
#include <glm\ext\matrix_float4x4.hpp>
#include <vector>
#include "src/Rendering/Mesh/Mesh.h"
#include "src/Resource/Serializable.h"
#include "assimp/Importer.hpp"
#include <assimp/scene.h>
#include <assimp/postprocess.h>
@@ -18,6 +18,7 @@ namespace Nuake
{
//loadModel(path);
}
void LoadModel();
void Draw();
std::vector<Ref<Mesh>> meshes;
@@ -26,5 +27,20 @@ namespace Nuake
void ProcessNode(aiNode* node, const aiScene* scene);
Ref<Mesh> ProcessMesh(aiMesh* mesh, const aiScene* scene);
std::vector<Texture*> LoadMaterialTextures(aiMaterial* mat, aiTextureType type);
json Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(ModelPath);
END_SERIALIZE();
}
bool Deserialize(const std::string str)
{
BEGIN_DESERIALIZE();
ModelPath = j["ModelPath"];
LoadModel();
return true;
}
};
}

View File

@@ -8,6 +8,7 @@
#include "../Components/QuakeMap.h"
#include "../Components/WrenScriptComponent.h"
#include "../Components/CharacterControllerComponent.h"
#include <src/Scene/Components/MeshComponent.h>
namespace Nuake
{
@@ -38,6 +39,8 @@ namespace Nuake
SERIALIZE_OBJECT_REF_LBL("WrenScriptComponent", GetComponent<WrenScriptComponent>());
if (HasComponent<CharacterControllerComponent>())
SERIALIZE_OBJECT_REF_LBL("CharacterControllerComponent", GetComponent<CharacterControllerComponent>());
if (HasComponent<MeshComponent>())
SERIALIZE_OBJECT_REF_LBL("MeshComponent", GetComponent<MeshComponent>());
END_SERIALIZE();
}
@@ -50,6 +53,7 @@ namespace Nuake
DESERIALIZE_COMPONENT(CameraComponent);
DESERIALIZE_COMPONENT(QuakeMapComponent);
DESERIALIZE_COMPONENT(LightComponent);
DESERIALIZE_COMPONENT(MeshComponent);
DESERIALIZE_COMPONENT(WrenScriptComponent);
DESERIALIZE_COMPONENT(CharacterControllerComponent);
return true;

View File

@@ -2,10 +2,7 @@
#include "src/Scene/Systems/ScriptingSystem.h"
#include "src/Scene/Systems/PhysicsSystem.h"
#include "src/Scene/Systems/TransformSystem.h"
#include "src/Scene/Systems/QuakeMapBuilder.h"
#include "src/Scene/Components/BSPBrushComponent.h"
#include "Scene.h"
#include "Entities/Entity.h"
@@ -18,10 +15,12 @@
#include "Engine.h"
#include "src/Core/FileSystem.h"
#include "Components/Components.h"
#include "Components/BoxCollider.h"
#include "Components/LuaScriptComponent.h"
#include "Components/WrenScriptComponent.h"
#include "src/Scene/Components/Components.h"
#include "src/Scene/Components/BoxCollider.h"
#include "src/Scene/Components/LuaScriptComponent.h"
#include "src/Scene/Components/WrenScriptComponent.h"
#include "src/Scene/Components/BSPBrushComponent.h"
#include "src/Scene/Components/InterfaceComponent.h"
#include <fstream>
#include <streambuf>
@@ -713,17 +712,20 @@ namespace Nuake {
void Scene::ReloadInterfaces()
{
for (auto& i : m_Interfaces)
i->Reload();
auto interfaceView = m_Registry.view<InterfaceComponent>();
for (auto i : interfaceView)
{
InterfaceComponent& uInterface = interfaceView.get<InterfaceComponent>(i);
if (uInterface.Interface)
uInterface.Interface->Reload();
}
}
void Scene::AddInterface(Ref<UI::UserInterface> interface)
{
this->m_Interfaces.push_back(interface);
}
json Scene::Serialize()
{
BEGIN_SERIALIZE();

View File

@@ -133,9 +133,9 @@ namespace Nuake
node->NormalStyle.BackgroundColor = GetColor(a.value());
if (name == "onclick")
{
std::string signature = a.value();
Root->Script->RegisterMethod(a.value());
node->OnClickSignature = a.value();
//std::string signature = a.value();
//Root->Script->RegisterMethod(a.value());
//node->OnClickSignature = a.value();
}
}
@@ -289,15 +289,14 @@ namespace Nuake
node->NormalStyle.BackgroundColor = GetColor(a.value());
if (name == "script")
{
auto s = split(a.value(), ' ');
std::string path = s[0];
std::string module = s[1];
node->Script = ScriptingEngine::RegisterScript(path, module);
auto scriptModule = String::Split(a.value(), ' ');
node->ScriptsToLoad.push_back({ scriptModule[0], scriptModule[1] });
//node->Script = ScriptingEngine::RegisterScript(FileSystem::Root + path, module);
}
if (name == "stylesheet")
{
std::string path = a.value();
node->StyleSheet = UI::StyleSheet::New(path);
node->StyleSheet = UI::StyleSheet::New(FileSystem::Root + path);
}
}

View File

@@ -1,9 +1,11 @@
#pragma once
#include "Node.h"
#include "../Core/Core.h"
#include "../Scripting/WrenScript.h"
#include <map>
#include "../Styling/Stylesheet.h"
#include "src/Core/Core.h"
#include "src/Scripting/WrenScript.h"
#include "src/UI/Styling/Stylesheet.h"
#include <vector>
#include <string>
namespace Nuake {
class Canvas : public Node
@@ -11,6 +13,8 @@ namespace Nuake {
private:
public:
std::vector<std::pair<std::string, std::string>> ScriptsToLoad;
Ref<WrenScript> Script;
Ref<UI::StyleSheet> StyleSheet;

View File

@@ -325,8 +325,6 @@ namespace Nuake
float height = YGNodeLayoutGetHeight(YogaNode);
float scrollRange = height;
float padding = YGNodeLayoutGetPadding(YogaNode, YGEdgeLeft);
float left = YGNodeLayoutGetLeft(YogaNode); //+ offset.x;
float top = YGNodeLayoutGetTop(YogaNode);// +offset.y;

View File

@@ -51,34 +51,8 @@ namespace Nuake
parentTop += YGNodeLayoutGetTop(parent);
parent = YGNodeGetParent(parent);
}
if (parent)
{
//parentLeft = YGNodeLayoutGetLeft(parent);
//parentTop = YGNodeLayoutGetTop(parent);
//float parentPaddingTop = YGNodeLayoutGetPadding(parent, YGEdgeTop);
//float parentPaddingLeft = YGNodeLayoutGetPadding(parent, YGEdgeTop);
// Overflow hidden.
//float parentwidth = YGNodeLayoutGetWidth(parent);
//if (parentwidth - YGNodeLayoutGetMargin(this->YogaNode, YGEdgeLeft) < width)
// width = parentwidth - parentPaddingLeft;
//float parentHeight = YGNodeLayoutGetHeight(parent);
//if (parentHeight < height)
// height = parentHeight - YGNodeLayoutGetMargin(this->YogaNode, YGEdgeTop) - parentPaddingTop;
}
transform = glm::translate(transform, Vector3(left + parentLeft, top + parentTop, 0.f));
//transform = glm::scale(transform, Vector3(width, height, 1.0));
//Renderer2D::UIShader->Bind();
//Renderer2D::UIShader->SetUniformMat4f("model", transform);
//Renderer2D::UIShader->SetUniform1f("u_BorderRadius", Border.Left.Value);
//Renderer2D::UIShader->SetUniform2f("u_Size", width, height);
//Renderer2D::DrawRect();
//Logger::Log("Left: " + std::to_string(left) + " Top:" + std::to_string(top));
Renderer2D::DrawString(content, textStyle, transform);
//Renderer2D::DrawString(content, style.font, Vector2(Position.Left, Position.Top), 2.0);
}
};
}

View File

@@ -15,7 +15,7 @@ namespace Nuake {
m_Path = path;
font = FontLoader::LoadFont("resources/Fonts/OpenSans-Regular.ttf");
Root = InterfaceParser::Parse(path);
Root = InterfaceParser::Parse(FileSystem::Root + path);
if (!Root)
{
@@ -37,7 +37,7 @@ namespace Nuake {
void UserInterface::Reload()
{
Root = InterfaceParser::Parse(this->m_Path);
Root = InterfaceParser::Parse(FileSystem::Root + this->m_Path);
if (!Root)
{
Logger::Log("Failed to generate interface structure", CRITICAL);
@@ -112,6 +112,7 @@ namespace Nuake {
Calculate(size.x, size.y);
Renderer2D::BeginDraw(size);
DrawRecursive(Root, 0);
Renderer2D::EndDraw();
Size = size;
}
@@ -129,9 +130,7 @@ namespace Nuake {
return;
for (auto& c : node->Childrens)
{
DrawRecursive(c, z + 1);
}
}
void UserInterface::Update(Timestep ts)

View File

@@ -8,6 +8,8 @@
#include "src/Core/Maths.h"
#include "Styling/Stylesheet.h"
#include "Font/Font.h"
#include <vector>
#include <string>
namespace Nuake {
namespace UI {
@@ -23,7 +25,9 @@ namespace Nuake {
YGConfigRef yoga_config;
YGNodeRef yoga_root;
std::vector<std::string> m_Scripts;
Ref<Node> GetNodeByIDRecurse(Ref<Node> node, const std::string& id);
void RecursiveHover(Ref<Node> node, Vector2 pos);
public:
@@ -53,6 +57,8 @@ namespace Nuake {
Ref<Node> GetNodeByID(const std::string& id);
void ConsumeMouseClick(Vector2 pos);
std::string GetPath() const { return m_Path; }
};
}
}

View File

@@ -18,6 +18,7 @@
#include <glm/gtx/matrix_decompose.hpp>
#include "Resource/FontAwesome5.h"
#include "Engine.h"
#include <src/Scene/Components/InterfaceComponent.h>
namespace Nuake {
// TODO: Use abstraction for vertex buffers
@@ -306,13 +307,24 @@ namespace Nuake {
m_GBuffer->GetTexture(GL_COLOR_ATTACHMENT1)->Bind(7);
m_GBuffer->GetTexture(GL_COLOR_ATTACHMENT2)->Bind(8);
glDisable(GL_CULL_FACE);
Ref<Shader> deferredShader = ShaderManager::GetShader("resources/Shaders/deferred.shader");
deferredShader->Bind();
deferredShader->SetUniform1i("m_Depth", 5);
deferredShader->SetUniform1i("m_Albedo", 6);
deferredShader->SetUniform1i("m_Normal", 7);
deferredShader->SetUniform1i("m_Material", 8);
Renderer::DrawQuad(Matrix4());
auto interfaceView = m_Scene->m_Registry.view<InterfaceComponent>();
for (auto i : interfaceView)
{
InterfaceComponent& uInterface = interfaceView.get<InterfaceComponent>(i);
if (uInterface.Interface)
uInterface.Interface->Draw(m_DeferredBuffer->GetSize());
}
}
m_DeferredBuffer->Unbind();
glEnable(GL_DEPTH_TEST);