mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
Added 2D gizmos and better editor styling
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <src/Resource/ModelLoader.h>
|
||||
#include <src/Rendering/RenderList.h>
|
||||
#include <src/Rendering/Renderer.h>
|
||||
|
||||
#include <dependencies/GLEW/include/GL/glew.h>
|
||||
|
||||
@@ -17,7 +18,7 @@
|
||||
#include <src/Scene/Components/MeshCollider.h>
|
||||
#include <src/Scene/Components/ModelComponent.h>
|
||||
#include <src/Scene/Components/ParticleEmitterComponent.h>
|
||||
|
||||
#include <src/Scene/Components/BoneComponent.h>
|
||||
|
||||
GizmoDrawer::GizmoDrawer()
|
||||
{
|
||||
@@ -275,44 +276,99 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> 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<TransformComponent, CameraComponent>();
|
||||
for (auto e : camView)
|
||||
{
|
||||
auto [transform, cam] = scene->m_Registry.get<TransformComponent, CameraComponent>(e);
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("resources/Gizmos/camera.png").get());
|
||||
auto [transform, camera] = scene->m_Registry.get<TransformComponent, CameraComponent>(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<TransformComponent, LightComponent>();
|
||||
for (auto e : lightView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("resources/Gizmos/light.png").get());
|
||||
auto [transform, light] = scene->m_Registry.get<TransformComponent, LightComponent>(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<TransformComponent, CharacterControllerComponent>();
|
||||
for (auto e : characterControllerView)
|
||||
{
|
||||
auto [transformComponent, characterControllerComponent] = scene->m_Registry.get<TransformComponent, CharacterControllerComponent>(e);
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("resources/Gizmos/player.png").get());
|
||||
auto [transform, characterControllerComponent] = scene->m_Registry.get<TransformComponent, CharacterControllerComponent>(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<TransformComponent, BoneComponent>();
|
||||
for (auto e : boneView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("resources/Gizmos/bone.png").get());
|
||||
auto [transform, boneComponent] = scene->m_Registry.get<TransformComponent, BoneComponent>(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);
|
||||
}
|
||||
@@ -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<NameComponent>();
|
||||
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<PrefabComponent>())
|
||||
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<VisibilityComponent>().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<Entity> 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<ParentComponent>().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<LightComponent>())
|
||||
{
|
||||
entityTypeName = "Light";
|
||||
}
|
||||
|
||||
if (entity.HasComponent<RigidBodyComponent>())
|
||||
{
|
||||
entityTypeName = "Rigidbody";
|
||||
}
|
||||
|
||||
if (entity.HasComponent<CharacterControllerComponent>())
|
||||
{
|
||||
entityTypeName = "Character Controller";
|
||||
}
|
||||
|
||||
if (entity.HasComponent<PrefabComponent>())
|
||||
{
|
||||
entityTypeName = "Prefab";
|
||||
}
|
||||
|
||||
return entityTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Nuake::File> currentFile;
|
||||
Ref<Nuake::Resource> selectedResource;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user