diff --git a/Editor/src/ComponentsPanel/MaterialEditor.cpp b/Editor/src/ComponentsPanel/MaterialEditor.cpp new file mode 100644 index 00000000..8e51d6a3 --- /dev/null +++ b/Editor/src/ComponentsPanel/MaterialEditor.cpp @@ -0,0 +1,249 @@ +#include "MaterialEditor.h" +#include +#include +#include +#include "../Misc/InterfaceFonts.h" + +void MaterialEditor::Draw(Ref 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(); + } +} \ No newline at end of file diff --git a/Editor/src/ComponentsPanel/MaterialEditor.h b/Editor/src/ComponentsPanel/MaterialEditor.h new file mode 100644 index 00000000..e0e9d2b6 --- /dev/null +++ b/Editor/src/ComponentsPanel/MaterialEditor.h @@ -0,0 +1,12 @@ +#pragma once +#include +#include + +class MaterialEditor +{ +public: + MaterialEditor() = default; + ~MaterialEditor() = default; + + void Draw(Ref material); +}; \ No newline at end of file diff --git a/Editor/src/ComponentsPanel/MeshPanel.h b/Editor/src/ComponentsPanel/MeshPanel.h index 06f06c5c..5eaf50fd 100644 --- a/Editor/src/ComponentsPanel/MeshPanel.h +++ b/Editor/src/ComponentsPanel/MeshPanel.h @@ -4,7 +4,7 @@ #include "ModelResourceInspector.h" #include -#include +#include #include #include @@ -21,13 +21,14 @@ public: void Draw(Nuake::Entity entity) override { - if (!entity.HasComponent()) + using namespace Nuake; + if (!entity.HasComponent()) return; - Nuake::MeshComponent& component = entity.GetComponent(); - BeginComponentTable(MESH, Nuake::MeshComponent); + ModelComponent& component = entity.GetComponent(); + BeginComponentTable(MESH, ModelComponent); { - ImGui::Text("Mesh"); + ImGui::Text("Model"); ImGui::TableNextColumn(); std::string label = std::to_string(component.ModelResource->ID); diff --git a/Editor/src/ComponentsPanel/ModelResourceInspector.cpp b/Editor/src/ComponentsPanel/ModelResourceInspector.cpp index aab18ef0..ff5b2eb5 100644 --- a/Editor/src/ComponentsPanel/ModelResourceInspector.cpp +++ b/Editor/src/ComponentsPanel/ModelResourceInspector.cpp @@ -1,5 +1,6 @@ #include "ModelResourceInspector.h" #include +#include "MaterialEditor.h" ModelResourceInspector::ModelResourceInspector(Ref model) { @@ -8,16 +9,23 @@ ModelResourceInspector::ModelResourceInspector(Ref model) void ModelResourceInspector::Draw() { - ImGui::BeginChild("modelInspector",ImVec2(0,0), true); + ImGui::BeginChild("modelInspector", ImVec2(0, 0), true); { for (uint32_t i = 0; i < std::size(_model->GetMeshes()); i++) { std::string headerLabel = "Mesh " + std::to_string(i); if (ImGui::CollapsingHeader(headerLabel.c_str())) { - + std::string childId = "materialEditor" + std::to_string(i); + ImGui::BeginChild(childId.c_str(), ImVec2(0, 0), false); + { + MaterialEditor editor; + editor.Draw(_model->GetMeshes().at(i)->GetMaterial()); + } + ImGui::EndChild(); } } } + ImGui::EndChild(); } \ No newline at end of file diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 719506ce..89121a60 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -1196,10 +1196,10 @@ namespace Nuake { auto ent = Engine::GetCurrentScene()->CreateEntity("Trenchbroom map"); ent.AddComponent(); } - if (ImGui::MenuItem("Mesh")) + if (ImGui::MenuItem("Model")) { - auto ent = Engine::GetCurrentScene()->CreateEntity("Mesh"); - ent.AddComponent(); + auto ent = Engine::GetCurrentScene()->CreateEntity("Model"); + ent.AddComponent(); } ImGui::EndMenu(); } diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index d6e9f438..8bba9773 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -360,7 +360,7 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity) MenuItemComponent("Wren Script", Nuake::WrenScriptComponent); MenuItemComponent("Camera", Nuake::CameraComponent); MenuItemComponent("Light", Nuake::LightComponent); - MenuItemComponent("Mesh", Nuake::MeshComponent); + MenuItemComponent("Model", Nuake::ModelComponent); MenuItemComponent("Rigid body", Nuake::RigidBodyComponent); MenuItemComponent("Box collider", Nuake::BoxColliderComponent); MenuItemComponent("Sphere collider", Nuake::SphereColliderComponent); diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 7be16d47..00b5fbcc 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -123,7 +123,7 @@ namespace Nuake { RenderCommand::Disable(RendererEnum::FACE_CULL); glCullFace(GL_BACK); - auto meshView = scene.m_Registry.view(); + auto meshView = scene.m_Registry.view(); auto quakeView = scene.m_Registry.view(); auto view = scene.m_Registry.view(); for (auto l : view) @@ -142,7 +142,7 @@ namespace Nuake { shader->SetUniformMat4f("u_LightTransform", light.mViewProjections[i]); for (auto e : meshView) { - auto [transform, mesh] = meshView.get(e); + auto [transform, mesh] = meshView.get(e); if (mesh.ModelResource != nullptr) { for (auto& m : mesh.ModelResource->GetMeshes()) @@ -181,10 +181,10 @@ namespace Nuake { gBufferShader->SetUniformMat4f("u_Projection", mProjection); gBufferShader->SetUniformMat4f("u_View", mView); - auto view = scene.m_Registry.view(); + auto view = scene.m_Registry.view(); for (auto e : view) { - auto [transform, mesh, parent] = view.get(e); + auto [transform, mesh, parent] = view.get(e); if (mesh.ModelResource) { diff --git a/Nuake/src/Scene/Components/Components.h b/Nuake/src/Scene/Components/Components.h index 4713c059..2a6da9a7 100644 --- a/Nuake/src/Scene/Components/Components.h +++ b/Nuake/src/Scene/Components/Components.h @@ -6,7 +6,7 @@ #include "TransformComponent.h" #include "LightComponent.h" #include "CameraComponent.h" -#include "MeshComponent.h" +#include "ModelComponent.h" #include "QuakeMap.h" #include "RigidbodyComponent.h" #include "SphereCollider.h" diff --git a/Nuake/src/Scene/Components/MeshComponent.cpp b/Nuake/src/Scene/Components/ModelComponent.cpp similarity index 79% rename from Nuake/src/Scene/Components/MeshComponent.cpp rename to Nuake/src/Scene/Components/ModelComponent.cpp index 7d3f7159..e354fc5e 100644 --- a/Nuake/src/Scene/Components/MeshComponent.cpp +++ b/Nuake/src/Scene/Components/ModelComponent.cpp @@ -1,5 +1,5 @@ #include "src/Resource/ModelLoader.h" -#include "MeshComponent.h" +#include "ModelComponent.h" #include "src/Rendering/Mesh/Mesh.h" #include "src/Rendering/Textures/TextureManager.h" #include "src/Rendering/Textures/Material.h" @@ -7,12 +7,12 @@ #include namespace Nuake { - MeshComponent::MeshComponent() + ModelComponent::ModelComponent() { } - void MeshComponent::LoadModel() + void ModelComponent::LoadModel() { auto loader = ModelLoader(); this->ModelResource = loader.LoadModel(ModelPath); diff --git a/Nuake/src/Scene/Components/MeshComponent.h b/Nuake/src/Scene/Components/ModelComponent.h similarity index 94% rename from Nuake/src/Scene/Components/MeshComponent.h rename to Nuake/src/Scene/Components/ModelComponent.h index 1b9caa6e..3b44bfbb 100644 --- a/Nuake/src/Scene/Components/MeshComponent.h +++ b/Nuake/src/Scene/Components/ModelComponent.h @@ -8,12 +8,12 @@ namespace Nuake { - struct MeshComponent + struct ModelComponent { Ref ModelResource; std::string ModelPath; - MeshComponent(); + ModelComponent(); void LoadModel(); diff --git a/Nuake/src/Scene/Entities/Entity.cpp b/Nuake/src/Scene/Entities/Entity.cpp index a7cd773b..ba42b3b2 100644 --- a/Nuake/src/Scene/Entities/Entity.cpp +++ b/Nuake/src/Scene/Entities/Entity.cpp @@ -9,8 +9,8 @@ #include "../Components/WrenScriptComponent.h" #include "../Components/CharacterControllerComponent.h" +#include "src/Scene/Components/Components.h" #include -#include //#include #include "src/Scene/Components/BSPBrushComponent.h" @@ -47,8 +47,8 @@ namespace Nuake if (HasComponent()) SERIALIZE_OBJECT_REF_LBL("BoxColliderComponent", GetComponent()); - if (HasComponent()) - SERIALIZE_OBJECT_REF_LBL("MeshComponent", GetComponent()); + if (HasComponent()) + SERIALIZE_OBJECT_REF_LBL("ModelComponent", GetComponent()); if (HasComponent()) SERIALIZE_OBJECT_REF_LBL("BSPBrushComponent", GetComponent()); END_SERIALIZE(); @@ -63,7 +63,7 @@ namespace Nuake DESERIALIZE_COMPONENT(CameraComponent); DESERIALIZE_COMPONENT(QuakeMapComponent); DESERIALIZE_COMPONENT(LightComponent); - DESERIALIZE_COMPONENT(MeshComponent); + DESERIALIZE_COMPONENT(ModelComponent); DESERIALIZE_COMPONENT(WrenScriptComponent); DESERIALIZE_COMPONENT(CharacterControllerComponent); //DESERIALIZE_COMPONENT(BSPBrushComponent); diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 830890a8..c1d1f885 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -320,7 +320,7 @@ namespace Nuake { CopyComponent(sceneCopy->m_Registry, this->m_Registry); CopyComponent(sceneCopy->m_Registry, this->m_Registry); CopyComponent(sceneCopy->m_Registry, this->m_Registry); - CopyComponent(sceneCopy->m_Registry, this->m_Registry); + CopyComponent(sceneCopy->m_Registry, this->m_Registry); CopyComponent(sceneCopy->m_Registry, this->m_Registry); return sceneCopy; diff --git a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp index 4d556f59..fbe84dc7 100644 --- a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp +++ b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp @@ -23,7 +23,7 @@ extern "C" { #include "src/Resource/FGD/FGDClass.h" #include "src/Scene/Components/WrenScriptComponent.h" #include "src/Scene/Components/PrefabComponent.h" -#include "src/Scene/Components/MeshComponent.h" +#include "src/Scene/Components/ModelComponent.h" #include #include @@ -609,7 +609,7 @@ namespace Nuake { //bsp.Meshes.push_back(mesh); } - MeshComponent& modelComponent = brushEntity.AddComponent(); + ModelComponent& modelComponent = brushEntity.AddComponent(); modelComponent.ModelResource = model; }