mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-06 06:09:52 +03:00
Made material resource file editable from engine
This commit is contained in:
@@ -27,65 +27,22 @@
|
||||
#include <src/Scene/Components/BSPBrushComponent.h>
|
||||
#include "src/Actions/EditorSelection.h"
|
||||
|
||||
std::string WindowTitle = "Nuake Engine";
|
||||
#include "src/Misc/GizmoDrawer.h"
|
||||
|
||||
void OpenProject()
|
||||
{
|
||||
// Parse the project and load it.
|
||||
std::string projectPath = Nuake::FileDialog::OpenFile("Project file|*.project;");
|
||||
|
||||
Nuake::FileSystem::SetRootDirectory(projectPath + "/../");
|
||||
Ref<Nuake::Project> project = Nuake::Project::New();
|
||||
if (!project->Deserialize(Nuake::FileSystem::ReadFile(projectPath, true)))
|
||||
{
|
||||
Nuake::Logger::Log("Error loading project: " + projectPath, Nuake::CRITICAL);
|
||||
return;
|
||||
}
|
||||
|
||||
project->FullPath = projectPath;
|
||||
Nuake::Engine::LoadProject(project);
|
||||
}
|
||||
|
||||
std::vector<Nuake::LineVertex> vertices
|
||||
{
|
||||
Nuake::LineVertex {{10000.f, 0.0f, 0.0f}, {1.f, 0.f, 0.f, 1.f}},
|
||||
Nuake::LineVertex {{0.0f, 0.0f, 0.0f }, {1.f, 0.f, 0.f, 1.f}},
|
||||
Nuake::LineVertex {{0.f, 0.f, 10000.f }, {0.f, 1.f, 0.f, 1.f}},
|
||||
Nuake::LineVertex {{0.0f, 0.0f, 0.0f }, {0.f, 1.f, 0.f, 1.f}},
|
||||
Nuake::LineVertex {{0.f, 10000.f, 0.0f }, {0.f, 0.f, 1.f, 1.f}},
|
||||
Nuake::LineVertex {{0.0f, 0.0f, 0.0f }, {0.f, 0.f, 1.f, 1.f}}
|
||||
};
|
||||
const std::string WindowTitle = "Nuake Editor";
|
||||
|
||||
int main()
|
||||
{
|
||||
Nuake::Engine::Init();
|
||||
|
||||
Nuake::EditorInterface editor;
|
||||
editor.BuildFonts();
|
||||
|
||||
glLineWidth(2.0f);
|
||||
|
||||
Nuake::Shader* lineShader = Nuake::ShaderManager::GetShader("resources/Shaders/line.shader");
|
||||
|
||||
lineShader->Bind();
|
||||
|
||||
Nuake::VertexArray* lineVertexArray = new Nuake::VertexArray();
|
||||
lineVertexArray->Bind();
|
||||
Nuake::VertexBuffer* lineVertexBuffer = new Nuake::VertexBuffer(vertices.data(), vertices.size() * sizeof(Nuake::LineVertex));
|
||||
Nuake::VertexBufferLayout* vblayout = new Nuake::VertexBufferLayout();
|
||||
vblayout->Push<float>(3);
|
||||
vblayout->Push<float>(4);
|
||||
lineVertexArray->AddBuffer(*lineVertexBuffer, *vblayout);
|
||||
|
||||
// Register Gizmo textures
|
||||
Ref<Nuake::Texture> lightTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Light.png");
|
||||
Ref<Nuake::Texture> camTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Camera.png");
|
||||
Nuake::Shader* GuizmoShader = Nuake::ShaderManager::GetShader("resources/Shaders/gizmo.shader");
|
||||
Nuake::Shader* ditherShader = Nuake::ShaderManager::GetShader("resources/Shaders/dither.shader");
|
||||
|
||||
//Nuake::NewEditor newEditor = Nuake::NewEditor();
|
||||
Ref<Nuake::Window> window = Nuake::Engine::GetCurrentWindow();
|
||||
window->SetTitle("Nuake Editor");
|
||||
window->SetTitle(WindowTitle);
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
GizmoDrawer gizmoDrawer = GizmoDrawer();
|
||||
|
||||
while (!window->ShouldClose())
|
||||
{
|
||||
@@ -96,58 +53,26 @@ int main()
|
||||
glViewport(0, 0, WindowSize.x, WindowSize.y);
|
||||
Nuake::Renderer2D::BeginDraw(WindowSize);
|
||||
|
||||
//newEditor.Draw(WindowSize);
|
||||
|
||||
Ref<Nuake::FrameBuffer> sceneFramebuffer = window->GetFrameBuffer();
|
||||
auto sceneFramebuffer = window->GetFrameBuffer();
|
||||
sceneFramebuffer->Bind();
|
||||
|
||||
Ref<Nuake::Scene> currentScene = Nuake::Engine::GetCurrentScene();
|
||||
if (currentScene && !Nuake::Engine::IsPlayMode)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
Ref<Nuake::Scene> currentScene = Nuake::Engine::GetCurrentScene();
|
||||
Ref<EditorCamera> camera;
|
||||
if (currentScene)
|
||||
{
|
||||
camera = currentScene->m_EditorCamera;
|
||||
}
|
||||
|
||||
lineShader->Bind();
|
||||
lineShader->SetUniformMat4f("u_View", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetTransform());
|
||||
lineShader->SetUniformMat4f("u_Projection", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetPerspective());
|
||||
|
||||
lineVertexArray->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 6);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
ditherShader->Bind();
|
||||
ditherShader->SetUniformMat4f("u_View", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetTransform());
|
||||
ditherShader->SetUniformMat4f("u_Projection", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetPerspective());
|
||||
ditherShader->SetUniform1f("u_Time", Nuake::Engine::GetTime());
|
||||
ditherShader->SetUniform4f("u_Color", 252.0 / 255.0, 3.0 / 255.0, 65.0 / 255.0, 1.0);
|
||||
|
||||
if (editor.Selection.Type == EditorSelectionType::Entity && editor.Selection.Entity.HasComponent<Nuake::BSPBrushComponent>())
|
||||
{
|
||||
for (auto& m : editor.Selection.Entity.GetComponent<Nuake::BSPBrushComponent>().Meshes)
|
||||
Nuake::Renderer::SubmitMesh(m, editor.Selection.Entity.GetComponent<Nuake::TransformComponent>().GetGlobalTransform());
|
||||
|
||||
Nuake::Renderer::Flush(ditherShader, true);
|
||||
}
|
||||
|
||||
ditherShader->SetUniform1f("u_Time", Nuake::Engine::GetTime() / 10.0f);
|
||||
ditherShader->SetUniform4f("u_Color", 52.f / 255.f, 235.f / 255.f, 88.f / 255.f, 1);
|
||||
auto cubeCollidersView = currentScene->m_Registry.view<Nuake::TransformComponent, Nuake::BoxColliderComponent>();
|
||||
if (editor.Selection.Type == EditorSelectionType::Entity && editor.Selection.Entity.HasComponent<Nuake::BoxColliderComponent>())
|
||||
{
|
||||
auto transformComponent = editor.Selection.Entity.GetComponent<Nuake::TransformComponent>();
|
||||
auto colliderComponent = editor.Selection.Entity.GetComponent<Nuake::BoxColliderComponent>();
|
||||
Nuake::Matrix4 transform = transformComponent.GetGlobalTransform();
|
||||
transform = glm::scale(transform, colliderComponent.Size);
|
||||
Nuake::Renderer::SubmitCube(transform);
|
||||
|
||||
Nuake::Renderer::Flush(ditherShader, true);
|
||||
}
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
if (currentScene && !Nuake::Engine::IsPlayMode)
|
||||
{
|
||||
gizmoDrawer.DrawGizmos(currentScene);
|
||||
}
|
||||
}
|
||||
sceneFramebuffer->Unbind();
|
||||
|
||||
editor.Draw();
|
||||
|
||||
// Swap buffers.
|
||||
Nuake::Engine::EndDraw();
|
||||
}
|
||||
|
||||
|
||||
39
Editor/src/Misc/GizmoDrawer.cpp
Normal file
39
Editor/src/Misc/GizmoDrawer.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "GizmoDrawer.h"
|
||||
#include <src/Rendering/Buffers/VertexBuffer.h>
|
||||
|
||||
GizmoDrawer::GizmoDrawer()
|
||||
{
|
||||
mLineShader = Nuake::ShaderManager::GetShader("resources/Shaders/line.shader");
|
||||
|
||||
mAxisLineBuffer = CreateRef<Nuake::VertexArray>();
|
||||
mAxisLineBuffer->Bind();
|
||||
|
||||
mAxisLineVertexBuffer = CreateRef<VertexBuffer>(vertices.data(), vertices.size() * sizeof(Nuake::LineVertex));
|
||||
auto vblayout = CreateRef<VertexBufferLayout>();
|
||||
vblayout->Push<float>(3);
|
||||
vblayout->Push<float>(4);
|
||||
|
||||
mAxisLineBuffer->AddBuffer(*mAxisLineVertexBuffer, *vblayout);
|
||||
}
|
||||
|
||||
void GizmoDrawer::DrawGizmos(Ref<Scene> scene)
|
||||
{
|
||||
RenderCommand::Disable(RendererEnum::DEPTH_TEST);
|
||||
|
||||
// Draw Axis lignes.
|
||||
{
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", scene->m_EditorCamera->GetTransform());
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
mAxisLineBuffer->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 6);
|
||||
}
|
||||
|
||||
// Draw Cameras Frustum.
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RenderCommand::Enable(RendererEnum::DEPTH_TEST);
|
||||
}
|
||||
32
Editor/src/Misc/GizmoDrawer.h
Normal file
32
Editor/src/Misc/GizmoDrawer.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <src/Core/Core.h>
|
||||
#include <src/Rendering/Buffers/VertexArray.h>
|
||||
#include <src/Rendering/Buffers/VertexBuffer.h>
|
||||
#include <src/Rendering/Shaders/ShaderManager.h>
|
||||
#include <src/Rendering/Vertex.h>
|
||||
#include <src/Scene/Scene.h>
|
||||
using namespace Nuake;
|
||||
|
||||
class GizmoDrawer
|
||||
{
|
||||
private:
|
||||
const std::vector<LineVertex> vertices
|
||||
{
|
||||
LineVertex {{10000.f, 0.0f, 0.0f}, {1.f, 0.f, 0.f, 1.f}},
|
||||
LineVertex {{0.0f, 0.0f, 0.0f }, {1.f, 0.f, 0.f, 1.f}},
|
||||
LineVertex {{0.f, 0.f, 10000.f }, {0.f, 1.f, 0.f, 1.f}},
|
||||
LineVertex {{0.0f, 0.0f, 0.0f }, {0.f, 1.f, 0.f, 1.f}},
|
||||
LineVertex {{0.f, 10000.f, 0.0f }, {0.f, 0.f, 1.f, 1.f}},
|
||||
LineVertex {{0.0f, 0.0f, 0.0f }, {0.f, 0.f, 1.f, 1.f}}
|
||||
};
|
||||
|
||||
Ref<VertexArray> mAxisLineBuffer;
|
||||
Ref<VertexBuffer> mAxisLineVertexBuffer;
|
||||
Shader* mLineShader;
|
||||
|
||||
public:
|
||||
GizmoDrawer();
|
||||
~GizmoDrawer() = default;
|
||||
|
||||
void DrawGizmos(Ref<Scene> scene);
|
||||
};
|
||||
@@ -114,7 +114,6 @@ namespace Nuake {
|
||||
CurrentOperation, CurrentMode, glm::value_ptr(oldTransform), 0, 0
|
||||
);
|
||||
|
||||
if (ImGuizmo::IsUsing())
|
||||
if (ImGuizmo::IsUsing())
|
||||
{
|
||||
Vector3 globalPos = Vector3();
|
||||
@@ -1541,6 +1540,8 @@ namespace Nuake {
|
||||
return;
|
||||
}
|
||||
|
||||
pInterface.m_CurrentProject = Engine::GetProject();
|
||||
|
||||
if (ImGui::BeginMainMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
#include "../Misc/ImGuiTextHelper.h"
|
||||
#include <src/Scene/Components/Components.h>
|
||||
|
||||
#include <src/Rendering/Textures/Material.h>
|
||||
#include <src/Resource/ResourceLoader.h>
|
||||
#include <src/Resource/FontAwesome5.h>
|
||||
#include <Engine.h>
|
||||
|
||||
EditorSelectionPanel::EditorSelectionPanel()
|
||||
{
|
||||
mTransformPanel = TransformPanel();
|
||||
@@ -10,6 +15,24 @@ EditorSelectionPanel::EditorSelectionPanel()
|
||||
mQuakeMapPanel = QuakeMapPanel();
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::ResolveFile(Ref<Nuake::File> file)
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
currentFile = file;
|
||||
|
||||
if (currentFile->GetExtension() == ".project")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (currentFile->GetExtension() == ".material")
|
||||
{
|
||||
Ref<Material> material = ResourceLoader::LoadResource(currentFile->GetRelativePath());
|
||||
selectedResource = material;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::Draw(EditorSelection selection)
|
||||
{
|
||||
if (ImGui::Begin("Propreties"))
|
||||
@@ -29,6 +52,11 @@ void EditorSelectionPanel::Draw(EditorSelection selection)
|
||||
}
|
||||
case EditorSelectionType::File:
|
||||
{
|
||||
if (currentFile != selection.File)
|
||||
{
|
||||
ResolveFile(selection.File);
|
||||
}
|
||||
|
||||
DrawFile(selection.File.get());
|
||||
break;
|
||||
}
|
||||
@@ -345,9 +373,18 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity)
|
||||
|
||||
}
|
||||
|
||||
|
||||
void EditorSelectionPanel::DrawFile(Nuake::File* file)
|
||||
{
|
||||
|
||||
using namespace Nuake;
|
||||
if (file->GetExtension() == ".material")
|
||||
{
|
||||
DrawMaterialPanel(std::static_pointer_cast<Material>(selectedResource));
|
||||
}
|
||||
if (file->GetExtension() == ".project")
|
||||
{
|
||||
DrawProjectPanel(Nuake::Engine::GetProject());
|
||||
}
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::DrawResource(Nuake::Resource resource)
|
||||
@@ -355,3 +392,260 @@ void EditorSelectionPanel::DrawResource(Nuake::Resource resource)
|
||||
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::DrawMaterialPanel(Ref<Nuake::Material> material)
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
std::string materialTitle = material->Path;
|
||||
{
|
||||
UIFont boldfont = UIFont(Fonts::SubTitle);
|
||||
ImGui::Text(material->Path.c_str());
|
||||
|
||||
}
|
||||
ImGui::SameLine();
|
||||
{
|
||||
UIFont boldfont = UIFont(Fonts::Icons);
|
||||
if (ImGui::Button(ICON_FA_SAVE))
|
||||
{
|
||||
std::string fileData = material->Serialize().dump(4);
|
||||
|
||||
FileSystem::BeginWriteFile(FileSystem::Root + material->Path);
|
||||
FileSystem::WriteLine(fileData);
|
||||
FileSystem::EndWriteFile();
|
||||
}
|
||||
}
|
||||
|
||||
bool flagsHeaderOpened;
|
||||
{
|
||||
UIFont boldfont = UIFont(Fonts::Bold);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.f, 0.f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.f, 8.f));
|
||||
flagsHeaderOpened = ImGui::CollapsingHeader(" FLAGS", ImGuiTreeNodeFlags_DefaultOpen);
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
|
||||
if (flagsHeaderOpened)
|
||||
{
|
||||
ImGui::BeginTable("##Flags", 3, ImGuiTableFlags_BordersInner);
|
||||
{
|
||||
ImGui::TableSetupColumn("name", 0, 0.3f);
|
||||
ImGui::TableSetupColumn("set", 0, 0.6f);
|
||||
ImGui::TableSetupColumn("reset", 0, 0.1f);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Text("Unlit");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
bool unlit = material->data.u_Unlit == 1;
|
||||
ImGui::Checkbox("Unlit", &unlit);
|
||||
material->data.u_Unlit = (int)unlit;
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
const auto TexturePanelHeight = 100;
|
||||
const ImVec2 TexturePanelSize = ImVec2(0, TexturePanelHeight);
|
||||
bool AlbedoOpened;
|
||||
{
|
||||
UIFont boldfont = UIFont(Fonts::Bold);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.f, 0.f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.f, 8.f));
|
||||
AlbedoOpened = ImGui::CollapsingHeader("Albedo", ImGuiTreeNodeFlags_DefaultOpen);
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
|
||||
if (AlbedoOpened)
|
||||
{
|
||||
ImGui::BeginChild("##albedo", TexturePanelSize, true);
|
||||
{
|
||||
uint32_t textureID = 0;
|
||||
if (material->HasAlbedo())
|
||||
{
|
||||
textureID = material->m_Albedo->GetID();
|
||||
}
|
||||
else
|
||||
{
|
||||
textureID = TextureManager::Get()->GetTexture("default")->GetID();
|
||||
}
|
||||
|
||||
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#image1"), (void*)textureID, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec2(2, 2), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
|
||||
{
|
||||
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
|
||||
if (texture != "")
|
||||
{
|
||||
material->SetAlbedo(TextureManager::Get()->GetTexture(texture));
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::MenuItem("Clear Texture"))
|
||||
{
|
||||
material->m_Albedo = nullptr;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::ColorEdit3("Color", &material->data.m_AlbedoColor.r);
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Normal", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::BeginChild("##normal", TexturePanelSize, true);
|
||||
{
|
||||
uint32_t textureID = 0;
|
||||
if (material->HasNormal())
|
||||
{
|
||||
textureID = material->m_Normal->GetID();
|
||||
}
|
||||
else
|
||||
{
|
||||
textureID = TextureManager::Get()->GetTexture("default")->GetID();
|
||||
}
|
||||
|
||||
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#image3"), (void*)textureID, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec2(2, 2), ImVec4(0, 0, 0, 1), ImVec4(1, 1, 1, 1)))
|
||||
{
|
||||
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
|
||||
if (texture != "")
|
||||
{
|
||||
material->SetNormal(TextureManager::Get()->GetTexture(texture));
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::MenuItem("Clear Texture"))
|
||||
{
|
||||
material->m_Normal = nullptr;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("AO", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::BeginChild("##ao", TexturePanelSize, true);
|
||||
{
|
||||
uint32_t textureID = 0;
|
||||
if (material->HasAO())
|
||||
{
|
||||
textureID = material->m_AO->GetID();
|
||||
}
|
||||
else
|
||||
{
|
||||
textureID = TextureManager::Get()->GetTexture("default")->GetID();
|
||||
}
|
||||
|
||||
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#image2"), (void*)textureID, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec2(2, 2), ImVec4(1, 1, 1, 1), ImVec4(1, 1, 1, 1)))
|
||||
{
|
||||
std::string texture = FileDialog::OpenFile("Image files (*.png) | *.png | Image files (*.jpg) | *.jpg");
|
||||
if (texture != "")
|
||||
{
|
||||
material->SetAO(TextureManager::Get()->GetTexture(texture));
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::MenuItem("Clear Texture"))
|
||||
{
|
||||
material->m_AO = nullptr;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Metalness", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::BeginChild("##metalness", TexturePanelSize, true);
|
||||
{
|
||||
uint32_t textureID = 0;
|
||||
if (material->HasMetalness())
|
||||
{
|
||||
textureID = material->m_Metalness->GetID();
|
||||
}
|
||||
else
|
||||
{
|
||||
textureID = TextureManager::Get()->GetTexture("default")->GetID();
|
||||
}
|
||||
|
||||
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#image4"), (void*)textureID, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec2(2, 2), ImVec4(0, 0, 0, 1), ImVec4(1, 1, 1, 1)))
|
||||
{
|
||||
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
|
||||
if (texture != "")
|
||||
{
|
||||
material->SetMetalness(TextureManager::Get()->GetTexture(texture));
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::MenuItem("Clear Texture"))
|
||||
{
|
||||
material->m_Metalness = nullptr;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("Value##4", &material->data.u_MetalnessValue, 0.01f, 0.0f, 1.0f);
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Roughness", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::BeginChild("##roughness", TexturePanelSize, true);
|
||||
{
|
||||
uint32_t textureID = 0;
|
||||
if (material->HasRoughness())
|
||||
{
|
||||
textureID = material->m_Roughness->GetID();
|
||||
}
|
||||
else
|
||||
{
|
||||
textureID = TextureManager::Get()->GetTexture("default")->GetID();
|
||||
}
|
||||
|
||||
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#image5"), (void*)textureID, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec2(2, 2), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)))
|
||||
{
|
||||
std::string texture = FileDialog::OpenFile("*.png | *.jpg");
|
||||
if (texture != "")
|
||||
{
|
||||
material->SetRoughness(TextureManager::Get()->GetTexture(texture));
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::MenuItem("Clear Texture"))
|
||||
{
|
||||
material->m_Roughness = nullptr;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::DrawProjectPanel(Ref<Nuake::Project> project)
|
||||
{
|
||||
ImGui::InputText("Project Name", &project->Name);
|
||||
ImGui::InputTextMultiline("Project Description", &project->Description);
|
||||
|
||||
if (ImGui::Button("Locate"))
|
||||
{
|
||||
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::InputText("Trenchbroom Path", &project->TrenchbroomPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "../ComponentsPanel/ScriptPanel.h"
|
||||
#include "../ComponentsPanel/MeshPanel.h"
|
||||
#include "../ComponentsPanel/QuakeMapPanel.h"
|
||||
#include "../Actions/EditorSelection.h"
|
||||
#include <src/Resource/Project.h>
|
||||
|
||||
class EditorSelectionPanel {
|
||||
private:
|
||||
@@ -16,6 +18,9 @@ private:
|
||||
ScriptPanel mScriptPanel;
|
||||
MeshPanel mMeshPanel;
|
||||
QuakeMapPanel mQuakeMapPanel;
|
||||
|
||||
Ref<Nuake::File> currentFile;
|
||||
Ref<Nuake::Resource> selectedResource;
|
||||
public:
|
||||
EditorSelectionPanel();
|
||||
|
||||
@@ -27,4 +32,9 @@ public:
|
||||
|
||||
void DrawFile(Nuake::File* file);
|
||||
void DrawResource(Nuake::Resource resource);
|
||||
|
||||
private:
|
||||
void ResolveFile(Ref<Nuake::File> file);
|
||||
void DrawMaterialPanel(Ref<Nuake::Material> material);
|
||||
void DrawProjectPanel(Ref<Nuake::Project> project);
|
||||
};
|
||||
@@ -39,6 +39,8 @@ exit() {\
|
||||
}\
|
||||
}";
|
||||
|
||||
#include <src/Rendering/Textures/Material.h>
|
||||
|
||||
namespace Nuake {
|
||||
// TODO: add filetree in same panel
|
||||
void FileSystemUI::Draw()
|
||||
@@ -176,6 +178,49 @@ namespace Nuake {
|
||||
return SplitterBehavior(bb, id, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 0.0f);
|
||||
}
|
||||
|
||||
void FileSystemUI::DrawContextMenu()
|
||||
{
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::MenuItem("New folder"))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("New Scene"))
|
||||
{
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("New Resource"))
|
||||
{
|
||||
if (ImGui::MenuItem("Material"))
|
||||
{
|
||||
std::string path = FileDialog::SaveFile("*.material");
|
||||
if (!String::EndsWith(path, ".material"))
|
||||
{
|
||||
path += ".material";
|
||||
}
|
||||
|
||||
if (path != "")
|
||||
{
|
||||
Ref<Material> material = CreateRef<Material>();
|
||||
material->IsEmbedded = false;
|
||||
auto jsonData = material->Serialize();
|
||||
|
||||
FileSystem::BeginWriteFile(path);
|
||||
FileSystem::WriteLine(jsonData.dump(4));
|
||||
FileSystem::EndWriteFile();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float h = 200;
|
||||
static float sz1 = 300;
|
||||
static float sz2 = 300;
|
||||
@@ -230,7 +275,6 @@ namespace Nuake {
|
||||
currentParent = currentParent->Parent;
|
||||
}
|
||||
|
||||
|
||||
avail = ImGui::GetContentRegionAvail();
|
||||
if (ImGui::BeginChild("Wrapper", avail))
|
||||
{
|
||||
@@ -300,6 +344,7 @@ namespace Nuake {
|
||||
for (auto f : m_CurrentDirectory->Files)
|
||||
{
|
||||
DrawFile(f);
|
||||
|
||||
if (i - 1 % amount != 0)
|
||||
ImGui::TableNextColumn();
|
||||
else
|
||||
@@ -307,63 +352,8 @@ namespace Nuake {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::MenuItem("New Wren script"))
|
||||
{
|
||||
ImGui::OpenPopup("new_file");
|
||||
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("New interface script"))
|
||||
{
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("New Scene"))
|
||||
{
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("New folder"))
|
||||
{
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("New interface"))
|
||||
{
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("New stylesheet"))
|
||||
{
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopup("new_file"))
|
||||
{
|
||||
static char name[32] = "NewWrenScript";
|
||||
char buf[64];
|
||||
sprintf(buf, "Button: %s###Button", name); // ### operator override ID ignoring the preceding label
|
||||
|
||||
ImGui::Text("Edit name:");
|
||||
ImGui::InputText("##edit", name, IM_ARRAYSIZE(name));
|
||||
if (ImGui::Button("Close"))
|
||||
ImGui::CloseCurrentPopup();
|
||||
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)) && name != "")
|
||||
{
|
||||
FileSystem::BeginWriteFile(m_CurrentDirectory->fullPath + name + ".wren");
|
||||
|
||||
FileSystem::WriteLine(TEMPLATE_SCRIPT_BEGIN + name + TEMPLATE_SCRIPT_END);
|
||||
|
||||
FileSystem::EndWriteFile();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
DrawContextMenu();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,5 +25,6 @@ namespace Nuake {
|
||||
bool EntityContainsItself(Entity source, Entity target);
|
||||
void DrawFile(Ref<File> file);
|
||||
void DrawDirectoryExplorer();
|
||||
void DrawContextMenu();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace Nuake
|
||||
|
||||
void WelcomeWindow::ParseRecentFile()
|
||||
{
|
||||
if (!FileSystem::FileExists(_RecentProjectFilePath))
|
||||
if (!FileSystem::FileExists(_RecentProjectFilePath, true))
|
||||
{
|
||||
FileSystem::BeginWriteFile(_RecentProjectFilePath);
|
||||
FileSystem::WriteLine(_RecentProjectFileDefaultContent);
|
||||
|
||||
@@ -93,9 +93,11 @@ namespace Nuake
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileSystem::FileExists(const std::string path)
|
||||
bool FileSystem::FileExists(const std::string path, bool absolute)
|
||||
{
|
||||
std::ifstream f(path.c_str());
|
||||
std::string fullPath = absolute ? path : FileSystem::Root + path;
|
||||
|
||||
std::ifstream f(fullPath.c_str());
|
||||
return f.good();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Nuake
|
||||
static void GetDirectories();
|
||||
|
||||
static bool DirectoryExists(const std::string path);
|
||||
static bool FileExists(const std::string path);
|
||||
static bool FileExists(const std::string path, bool absolute = false);
|
||||
|
||||
static std::string ReadFile(const std::string& path, bool absolute = false);
|
||||
|
||||
@@ -61,6 +61,11 @@ namespace Nuake
|
||||
std::string GetAbsolutePath() { return AbsolutePath; }
|
||||
Ref<Directory> GetParent() { return Parent; }
|
||||
|
||||
std::string Read()
|
||||
{
|
||||
return FileSystem::ReadFile(AbsolutePath);
|
||||
}
|
||||
|
||||
File(Ref<Directory> parentDir, const std::string& absolutePath, const std::string& name, const std::string& type)
|
||||
{
|
||||
AbsolutePath = absolutePath;
|
||||
|
||||
@@ -144,8 +144,11 @@ namespace Nuake {
|
||||
for (auto e : meshView)
|
||||
{
|
||||
auto [transform, mesh] = meshView.get<TransformComponent, MeshComponent>(e);
|
||||
for (auto& m : mesh.ModelResource->GetMeshes())
|
||||
Renderer::SubmitMesh(m, transform.GetGlobalTransform());
|
||||
if (mesh.ModelResource != nullptr)
|
||||
{
|
||||
for (auto& m : mesh.ModelResource->GetMeshes())
|
||||
Renderer::SubmitMesh(m, transform.GetGlobalTransform());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto e : quakeView)
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace Nuake
|
||||
if (j.contains("Path"))
|
||||
{
|
||||
this->Path = j["Path"];
|
||||
if (FileSystem::FileExists(FileSystem::Root + Path))
|
||||
if (FileSystem::FileExists(Path))
|
||||
{
|
||||
std::string content = FileSystem::ReadFile(Path);
|
||||
Deserialize(content);
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace Nuake
|
||||
{
|
||||
private:
|
||||
std::vector<Ref<Mesh>> m_Meshes;
|
||||
|
||||
public:
|
||||
Model();
|
||||
Model(const std::string path);
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace Nuake
|
||||
}
|
||||
|
||||
std::string texturePath = FileSystem::Root + modelDir + path;
|
||||
if (!FileSystem::FileExists(texturePath))
|
||||
if (!FileSystem::FileExists(texturePath, true))
|
||||
{
|
||||
std::string textureNotFoundmsg = "Texture file couldn't be found: " + texturePath;
|
||||
Logger::Log(textureNotFoundmsg, Nuake::LOG_TYPE::WARNING);
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Nuake
|
||||
if (scenePath == "") // Not set correctly.
|
||||
return true;
|
||||
|
||||
if (!FileSystem::FileExists(FileSystem::Root + scenePath))
|
||||
if (!FileSystem::FileExists(scenePath))
|
||||
return true;
|
||||
|
||||
std::string sceneContent = FileSystem::ReadFile(scenePath, false);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Nuake
|
||||
class Resource
|
||||
{
|
||||
public:
|
||||
UUID Id;
|
||||
UUID ID;
|
||||
|
||||
bool IsEmbedded = false;
|
||||
std::string Path; // Only if embedded
|
||||
|
||||
70
Nuake/src/Resource/ResourceLoader.h
Normal file
70
Nuake/src/Resource/ResourceLoader.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Core/Logger.h"
|
||||
#include "src/Resource/Resource.h"
|
||||
#include "src/Resource/ResourceManager.h"
|
||||
#include "src/Rendering/Textures/Material.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class ResourceLoader
|
||||
{
|
||||
private:
|
||||
const std::string FILE_NOT_FOUND = "[Resource Loader] File doesn't exists. \n ";
|
||||
const std::string WRONG_EXTENSION = "[Resource Loader] Resource type mismatch file extension. \n expected: ";
|
||||
const std::string MATERIAL_EXT = ".material";
|
||||
|
||||
public:
|
||||
ResourceLoader() = default;
|
||||
~ResourceLoader() = default;
|
||||
|
||||
|
||||
static Ref<Material> LoadResource(const std::string& path)
|
||||
{
|
||||
const std::string FILE_NOT_FOUND = "[Resource Loader] File doesn't exists. \n ";
|
||||
const std::string WRONG_EXTENSION = "[Resource Loader] Resource type mismatch file extension. \n expected: ";
|
||||
const std::string MATERIAL_EXT = ".material";
|
||||
if (!FileSystem::FileExists(path))
|
||||
{
|
||||
Logger::Log(FILE_NOT_FOUND + path, LOG_TYPE::WARNING);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!String::EndsWith(path, MATERIAL_EXT))
|
||||
{
|
||||
std::string message = WRONG_EXTENSION + MATERIAL_EXT + " actual: " + path;
|
||||
Logger::Log(message, LOG_TYPE::WARNING);
|
||||
}
|
||||
|
||||
std::string content = FileSystem::ReadFile(path);
|
||||
json j = json::parse(content);
|
||||
|
||||
UUID uuid = ReadUUID(j);
|
||||
|
||||
// Check if resource is already loaded.
|
||||
if (ResourceManager::IsResourceLoaded(uuid))
|
||||
{
|
||||
return ResourceManager::GetResource<Material>(uuid);
|
||||
}
|
||||
|
||||
Ref<Material> material = CreateRef<Material>();
|
||||
material->ID = uuid;
|
||||
material->Path = path;
|
||||
material->Deserialize(j.dump());
|
||||
ResourceManager::RegisterResource(material);
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
private:
|
||||
static UUID ReadUUID(json j)
|
||||
{
|
||||
if (j.contains("UUID"))
|
||||
{
|
||||
return UUID(j["UUID"]);
|
||||
}
|
||||
|
||||
return UUID();
|
||||
}
|
||||
};
|
||||
}
|
||||
6
Nuake/src/Resource/ResourceManager.cpp
Normal file
6
Nuake/src/Resource/ResourceManager.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "ResourceManager.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
std::map<UUID, Ref<Resource>> ResourceManager::m_Resources;
|
||||
}
|
||||
@@ -16,15 +16,20 @@ namespace Nuake {
|
||||
template<typename R>
|
||||
static Ref<R> LoadResource(const std::string& path);
|
||||
|
||||
void RegisterResource(Ref<Resource> resource)
|
||||
static void RegisterResource(Ref<Resource> resource)
|
||||
{
|
||||
m_Resources[resource->Id] = resource;
|
||||
m_Resources[resource->ID] = resource;
|
||||
}
|
||||
|
||||
static bool IsResourceLoaded(const UUID& uuid)
|
||||
{
|
||||
return m_Resources.find(uuid) != m_Resources.end();
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
static Ref<R> GetResource(const UUID& uuid)
|
||||
{
|
||||
return reinterpret_pointer_cast<Ref<R>>(m_Resources[uuid]);
|
||||
return std::static_pointer_cast<R>(m_Resources[uuid]);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -157,7 +157,8 @@ namespace Nuake {
|
||||
{
|
||||
std::vector<Entity> allEntities;
|
||||
auto view = m_Registry.view<NameComponent>();
|
||||
for (auto e : view) {
|
||||
for (auto e : view)
|
||||
{
|
||||
Entity newEntity(e, this);
|
||||
|
||||
// Check if valid for deleted entities.
|
||||
@@ -177,6 +178,8 @@ namespace Nuake {
|
||||
if (namec.Name == name)
|
||||
return Entity{ e, this };
|
||||
}
|
||||
|
||||
return Entity();
|
||||
}
|
||||
|
||||
Entity Scene::CreateEntity(const std::string& name)
|
||||
@@ -314,6 +317,7 @@ namespace Nuake {
|
||||
sceneCopy->CreateEntity(name, id);
|
||||
}
|
||||
|
||||
CopyComponent<ParentComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<TransformComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<LightComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<MeshComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace Nuake {
|
||||
// In the scene constructor.
|
||||
std::vector<Ref<System>> m_Systems;
|
||||
Ref<Environment> m_Environement;
|
||||
std::map<UUID, Ref<Resource>> m_Resources;
|
||||
|
||||
public:
|
||||
Ref<EditorCamera> m_EditorCamera;
|
||||
|
||||
@@ -67,49 +67,41 @@ namespace Nuake {
|
||||
std::string name = wrenGetSlotString(vm, 2);
|
||||
Entity ent = Entity((entt::entity)handle, Engine::GetCurrentScene().get());
|
||||
|
||||
if (name == "Transform")
|
||||
bool result = false;
|
||||
if (handle == -1)
|
||||
{
|
||||
bool result = ent.HasComponent<TransformComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
if (name == "Light")
|
||||
{
|
||||
bool result = ent.HasComponent<LightComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
if (name == "QuakeMap")
|
||||
{
|
||||
bool result = ent.HasComponent<QuakeMapComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name == "Transform") result = ent.HasComponent<TransformComponent>();
|
||||
if (name == "Light") result = ent.HasComponent<LightComponent>();
|
||||
if (name == "QuakeMap") result = ent.HasComponent<QuakeMapComponent>();
|
||||
|
||||
if (name == "CharacterController")
|
||||
{
|
||||
bool result = ent.HasComponent<CharacterControllerComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
result = ent.HasComponent<CharacterControllerComponent>();
|
||||
}
|
||||
if (name == "Camera")
|
||||
{
|
||||
bool result = ent.HasComponent<CameraComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
result = ent.HasComponent<CameraComponent>();
|
||||
}
|
||||
if (name == "Script")
|
||||
{
|
||||
bool result = ent.HasComponent<CameraComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
result = ent.HasComponent<WrenScriptComponent>();
|
||||
}
|
||||
if (name == "Rigidbody")
|
||||
{
|
||||
bool result = ent.HasComponent<RigidBodyComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
result = ent.HasComponent<RigidBodyComponent>();
|
||||
}
|
||||
if (name == "Script") {
|
||||
bool result = ent.HasComponent<WrenScriptComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
result = ent.HasComponent<WrenScriptComponent>();
|
||||
}
|
||||
if (name == "Brush") {
|
||||
bool result = ent.HasComponent<BSPBrushComponent>();
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
result = ent.HasComponent<BSPBrushComponent>();
|
||||
}
|
||||
|
||||
wrenSetSlotBool(vm, 0, result);
|
||||
}
|
||||
|
||||
static void GetScript(WrenVM* vm)
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Nuake {
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.08f, 0.10f, 0.12f, 0.00f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.09f, 0.09f, 0.09f, 1.00f);
|
||||
|
||||
Reference in New Issue
Block a user