diff --git a/Editor/resources/Shaders/flat.shader b/Editor/resources/Shaders/flat.shader index c191336d..8f6cb3d8 100644 --- a/Editor/resources/Shaders/flat.shader +++ b/Editor/resources/Shaders/flat.shader @@ -41,5 +41,5 @@ void main() vec3 diffuse = diff * lightDiffuse; scolor = scolor * diffuse; - FragColor = vec4(scolor, 1.0); + FragColor = vec4(u_Color.rgb, 1.0); } \ No newline at end of file diff --git a/Editor/resources/Shaders/gizmo.shader b/Editor/resources/Shaders/gizmo.shader index db6cb6ef..2d4bb2ea 100644 --- a/Editor/resources/Shaders/gizmo.shader +++ b/Editor/resources/Shaders/gizmo.shader @@ -1,18 +1,19 @@ #shader vertex #version 460 core layout(location = 0) in vec3 Position; +layout(location = 1) in vec3 Normal; layout(location = 1) in vec2 UV; -uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; +uniform mat4 u_Model; +uniform mat4 u_View; +uniform mat4 u_Projection; out sample vec2 a_UV; void main() { a_UV = UV; - gl_Position = projection * view * model * vec4(Position, 1.0); + gl_Position = u_Projection * u_View * u_Model * vec4(Position, 1.0); } #shader fragment @@ -27,5 +28,6 @@ uniform sampler2D gizmo_texture; void main() { vec4 px_color = texture(gizmo_texture, a_UV).rgba; - FragColor = px_color; + FragColor = px_color * vec4(1, 1, 1, 0.5); + } \ No newline at end of file diff --git a/Editor/src/Misc/GizmoDrawer.cpp b/Editor/src/Misc/GizmoDrawer.cpp index 66f993a9..48268b8e 100644 --- a/Editor/src/Misc/GizmoDrawer.cpp +++ b/Editor/src/Misc/GizmoDrawer.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -17,7 +18,7 @@ #include #include #include - +#include GizmoDrawer::GizmoDrawer() { @@ -275,44 +276,99 @@ void GizmoDrawer::DrawGizmos(Ref scene) glLineWidth(1.0f); RenderList renderList; + auto gizmoShader = ShaderManager::GetShader("resources/Shaders/gizmo.shader"); + gizmoShader->Bind(); + gizmoShader->SetUniformMat4f("u_View", scene->m_EditorCamera->GetTransform()); + gizmoShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective()); + + RenderCommand::Disable(RendererEnum::FACE_CULL); + // Camera auto camView = scene->m_Registry.view(); for (auto e : camView) { - auto [transform, cam] = scene->m_Registry.get(e); + gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("resources/Gizmos/camera.png").get()); + auto [transform, camera] = scene->m_Registry.get(e); - renderList.AddToRenderList(_gizmos["cam"]->GetMeshes()[0], transform.GetGlobalTransform()); + auto initialTransform = transform.GetGlobalTransform(); + Matrix4 particleTransform = initialTransform; + particleTransform = glm::inverse(scene->m_EditorCamera->GetTransform()); + + // Translation + const Vector3& particleGlobalPosition = transform.GetGlobalPosition(); + particleTransform[3] = Vector4(particleGlobalPosition, 1.0f); + + particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5)); + + renderList.AddToRenderList(Renderer::QuadMesh, particleTransform); } - renderList.Flush(flatShader, true); + renderList.Flush(gizmoShader, true); // Lights auto lightView = scene->m_Registry.view(); for (auto e : lightView) { + gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("resources/Gizmos/light.png").get()); auto [transform, light] = scene->m_Registry.get(e); - flatShader->SetUniformVec4("u_Color", Vector4(light.Color, 1.0f)); - renderList.AddToRenderList(_gizmos["light"]->GetMeshes()[0], transform.GetGlobalTransform()); - renderList.Flush(flatShader, true); - } - renderList.Flush(flatShader, true); + auto initialTransform = transform.GetGlobalTransform(); + Matrix4 particleTransform = initialTransform; + particleTransform = glm::inverse(scene->m_EditorCamera->GetTransform()); + // Translation + const Vector3& particleGlobalPosition = transform.GetGlobalPosition(); + particleTransform[3] = Vector4(particleGlobalPosition, 1.0f); + + particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5)); + + renderList.AddToRenderList(Renderer::QuadMesh, particleTransform); + } + + renderList.Flush(gizmoShader, true); // Player auto characterControllerView = scene->m_Registry.view(); for (auto e : characterControllerView) { - auto [transformComponent, characterControllerComponent] = scene->m_Registry.get(e); + gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("resources/Gizmos/player.png").get()); + auto [transform, characterControllerComponent] = scene->m_Registry.get(e); - flatShader->SetUniformVec4("u_Color", Vector4(0.0f, 1.0f, 0.4f, 1.0f)); + auto initialTransform = transform.GetGlobalTransform(); + Matrix4 particleTransform = initialTransform; + particleTransform = glm::inverse(scene->m_EditorCamera->GetTransform()); - const auto scaledTransform = glm::scale(transformComponent.GetGlobalTransform(), Vector3(0.25f, 0.25f, 0.25f)); - renderList.AddToRenderList(_gizmos["player"]->GetMeshes()[0], scaledTransform); - renderList.Flush(flatShader, true); + // Translation + const Vector3& particleGlobalPosition = transform.GetGlobalPosition(); + particleTransform[3] = Vector4(particleGlobalPosition, 1.0f); + + particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5)); + + renderList.AddToRenderList(Renderer::QuadMesh, particleTransform); } - renderList.Flush(flatShader, true); + renderList.Flush(gizmoShader, true); - RenderCommand::Disable(RendererEnum::FACE_CULL); + // Bones + auto boneView = scene->m_Registry.view(); + for (auto e : boneView) + { + gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("resources/Gizmos/bone.png").get()); + auto [transform, boneComponent] = scene->m_Registry.get(e); + + auto initialTransform = transform.GetGlobalTransform(); + Matrix4 particleTransform = initialTransform; + particleTransform = glm::inverse(scene->m_EditorCamera->GetTransform()); + + // Translation + const Vector3& particleGlobalPosition = transform.GetGlobalPosition(); + particleTransform[3] = Vector4(particleGlobalPosition, 1.0f); + + particleTransform = glm::scale(particleTransform, Vector3(0.25, 0.25, 0.25)); + + renderList.AddToRenderList(Renderer::QuadMesh, particleTransform); + } + + renderList.Flush(gizmoShader, true); + RenderCommand::Enable(RendererEnum::DEPTH_TEST); } \ No newline at end of file diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index d6acdcb4..67f42993 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -289,7 +289,9 @@ namespace Nuake { Entity QueueDeletion; void EditorInterface::DrawEntityTree(Entity e) { - ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_FramePadding | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth; + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{ 0.0f, 0.0f }); + + ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_FramePadding | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanFullWidth; NameComponent& nameComponent = e.GetComponent(); std::string name = nameComponent.Name; @@ -298,8 +300,6 @@ namespace Nuake { if (Selection.Type == EditorSelectionType::Entity && Selection.Entity == e) base_flags |= ImGuiTreeNodeFlags_Selected; - - ImGui::TableNextColumn(); // Write in normal font. @@ -315,10 +315,8 @@ namespace Nuake { { ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255)); } - - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8, 8)); + bool open = ImGui::TreeNodeEx(name.c_str(), base_flags); - ImGui::PopStyleVar(); if(nameComponent.IsPrefab && e.HasComponent()) ImGui::PopStyleColor(); @@ -414,21 +412,20 @@ namespace Nuake { ImGui::TableNextColumn(); - ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{ 0.0f, 0.0f }); + ImGui::TextColored(ImVec4(0.5, 0.5, 0.5, 1.0), GetEntityTypeName(e).c_str()); + + ImGui::TableNextColumn(); { bool& isVisible = e.GetComponent().Visible; char* visibilityIcon = isVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH; - ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 }); - if (ImGui::Button(visibilityIcon, { 40, 36 })) + if (ImGui::Button(visibilityIcon, { 40, 0 })) { isVisible = !isVisible; } ImGui::PopStyleColor(); } - - ImGui::PopStyleVar(); - + if (open) { // Caching list to prevent deletion while iterating. @@ -438,7 +435,8 @@ namespace Nuake { ImGui::TreePop(); } - + + ImGui::PopStyleVar(); ImGui::PopFont(); } @@ -1017,6 +1015,7 @@ namespace Nuake { std::string title = ICON_FA_TREE + std::string(" Hierarchy"); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(4, 0)); if (ImGui::Begin(title.c_str())) { // Buttons to add and remove entity. @@ -1038,16 +1037,18 @@ namespace Nuake { ImGui::EndChild(); // Draw a tree of entities. ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(26.f / 255.0f, 26.f / 255.0f, 26.f / 255.0f, 1)); + if (ImGui::BeginChild("Scene tree", ImGui::GetContentRegionAvail(), false)) { - if (ImGui::BeginTable("entity_table", 2, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_SizingStretchProp)) + if (ImGui::BeginTable("entity_table", 3, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_SizingStretchProp)) { - ImGui::TableSetupColumn(" Label", ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_IndentEnable); - std::string icon = ICON_FA_EYE; - ImGui::TableSetupColumn((" " + icon).c_str(), ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_IndentDisable | ImGuiTableColumnFlags_WidthFixed, 32); + ImGui::TableSetupColumn("Label", ImGuiTableColumnFlags_IndentEnable); + ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_IndentEnable); + ImGui::TableSetupColumn("Visibility", ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_IndentDisable | ImGuiTableColumnFlags_WidthFixed); ImGui::TableHeadersRow(); ImGui::TableNextRow(); + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0, 0)); std::vector entities = scene->GetAllEntities(); for (Entity e : entities) { @@ -1060,16 +1061,11 @@ namespace Nuake { // Write in normal font. ImGui::PushFont(normalFont); - // Small icons + name. - std::string label = ICON_FA_CIRCLE + std::string(" ") + name; - // Draw all entity without parents. if (!e.GetComponent().HasParent) { - ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{ 0.0f, 0.0f }); // Recursively draw childrens. DrawEntityTree(e); - ImGui::PopStyleVar(); } // Pop font. @@ -1079,6 +1075,7 @@ namespace Nuake { //if (ImGui::BeginPopupContextItem()) // ImGui::EndPopup(); } + ImGui::PopStyleVar(); } ImGui::EndTable(); @@ -1110,9 +1107,9 @@ namespace Nuake { QueueDeletion = Entity{ (entt::entity)-1, scene.get() }; } } - ImGui::End(); ImGui::PopStyleVar(); + ImGui::PopStyleVar(); } bool EditorInterface::EntityContainsItself(Entity source, Entity target) @@ -1632,4 +1629,31 @@ namespace Nuake { ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.5f, 0.5f)); FontManager::LoadFonts(); } + + std::string EditorInterface::GetEntityTypeName(const Entity& entity) const + { + std::string entityTypeName = ""; + + if (entity.HasComponent()) + { + entityTypeName = "Light"; + } + + if (entity.HasComponent()) + { + entityTypeName = "Rigidbody"; + } + + if (entity.HasComponent()) + { + entityTypeName = "Character Controller"; + } + + if (entity.HasComponent()) + { + entityTypeName = "Prefab"; + } + + return entityTypeName; + } } diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index f71a9f8c..46b1dacb 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -61,5 +61,8 @@ namespace Nuake bool ShouldDrawAxis() const { return m_DrawAxis; } bool ShouldDrawCollision() const { return m_DebugCollisions; } + + private: + std::string GetEntityTypeName(const Entity& entity) const; }; } diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index bb77a732..addbb26a 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -104,6 +104,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) mSpritePanel.Draw(entity); mMeshPanel.Draw(entity); mSkinnedModelPanel.Draw(entity); + mBonePanel.Draw(entity); mQuakeMapPanel.Draw(entity); mCameraPanel.Draw(entity); mRigidbodyPanel.Draw(entity); @@ -131,8 +132,11 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity) MenuItemComponent("Wren Script", Nuake::WrenScriptComponent) MenuItemComponent("Camera", Nuake::CameraComponent) MenuItemComponent("Light", Nuake::LightComponent) + ImGui::Separator(); MenuItemComponent("Model", Nuake::ModelComponent) MenuItemComponent("Skinned Model", Nuake::SkinnedModelComponent) + MenuItemComponent("Bone", Nuake::BoneComponent) + ImGui::Separator(); MenuItemComponent("Sprite", Nuake::SpriteComponent) MenuItemComponent("Particle Emitter", Nuake::ParticleEmitterComponent) ImGui::Separator(); diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 03f71bc2..1e608200 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -21,7 +21,7 @@ #include "../ComponentsPanel/SpritePanel.h" #include "../ComponentsPanel/ParticleEmitterPanel.h" #include "../ComponentsPanel/SkinnedModelPanel.h" - +#include "../ComponentsPanel/BonePanel.h" class EditorSelectionPanel { @@ -42,6 +42,7 @@ private: SpritePanel mSpritePanel; CharacterControllerPanel mCharacterControllerPanel; ParticleEmitterPanel mParticleEmitterPanel; + BonePanel mBonePanel; Ref currentFile; Ref selectedResource; diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 3593cbf3..5b6a9a48 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -228,7 +228,7 @@ namespace Nuake { dragType = "_Map"; } - else if (fileExtension == ".obj" || fileExtension == ".mdl" || fileExtension == ".gltf" || fileExtension == ".md3" || fileExtension == ".fbx") + else if (fileExtension == ".obj" || fileExtension == ".mdl" || fileExtension == ".gltf" || fileExtension == ".md3" || fileExtension == ".fbx" || fileExtension == ".glb") { dragType = "_Model"; } diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 87f61caa..03cf1ea3 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -117,8 +117,6 @@ namespace Nuake finalOutput = framebuffer.GetTexture(); - - // Copy final output to target framebuffer mToneMapBuffer->QueueResize(framebuffer.GetSize()); mToneMapBuffer->Bind(); @@ -170,7 +168,9 @@ namespace Nuake { auto [lightTransform, light, visibility] = view.get(l); if (light.Type != LightType::Directional || !light.CastShadows || !visibility.Visible) + { continue; + } light.CalculateViewProjection(mView, mProjection); diff --git a/Nuake/src/Scene/Entities/Entity.h b/Nuake/src/Scene/Entities/Entity.h index f51a0837..461b84ed 100644 --- a/Nuake/src/Scene/Entities/Entity.h +++ b/Nuake/src/Scene/Entities/Entity.h @@ -18,7 +18,7 @@ namespace Nuake void AddChild(Entity ent); int GetHandle() const { return (int)m_EntityHandle; } - int GetID() { return GetComponent().ID; } + int GetID() const { return GetComponent().ID; } template bool HasComponent() const @@ -51,6 +51,13 @@ namespace Nuake return component; } + template + T GetComponent() const + { + T component = m_Scene->m_Registry.get(m_EntityHandle); + return component; + } + void Destroy() { m_Scene->m_Registry.destroy(m_EntityHandle); diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index 70ae8a97..07af332e 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -67,7 +67,7 @@ namespace Nuake SetWindowIcon("resources/Images/nuake-logo.png"); glfwMakeContextCurrent(m_Window); - SetVSync(true); + SetVSync(false); Logger::Log("Driver detected " + std::string(((char*)glGetString(GL_VERSION))), "renderer"); @@ -267,7 +267,6 @@ namespace Nuake ImGuiStyle& s = ImGui::GetStyle(); s.WindowMenuButtonPosition = ImGuiDir_None; - s.FrameRounding = 2.0f; s.GrabRounding = 2.0f; s.CellPadding = ImVec2(8, 8); s.WindowPadding = ImVec2(2, 2); @@ -277,7 +276,7 @@ namespace Nuake s.TabRounding = 0; s.WindowRounding = 0; s.ChildRounding = 0; - s.FrameRounding = 0; + s.FrameRounding = 4.0f; s.GrabRounding = 0; s.FramePadding = ImVec2(8, 4); s.ItemSpacing = ImVec2(8, 4); @@ -287,6 +286,7 @@ namespace Nuake s.IndentSpacing = 12.0f; s.ChildBorderSize = 0.0f; s.PopupRounding = 4.0f; + s.FrameBorderSize = 1.0f; ImVec4* colors = ImGui::GetStyle().Colors; colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);