SceneHierarchyPanel
- Added Panel - Added SceneHierarchyPanel
This commit is contained in:
parent
8367150145
commit
fb4ba5c8bc
6 changed files with 122 additions and 10 deletions
|
@ -29,6 +29,8 @@ namespace Light {
|
||||||
{
|
{
|
||||||
return m_Scene->m_Registry.get<T>(m_Handle);
|
return m_Scene->m_Registry.get<T>(m_Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator uint32_t() { return (uint32_t)m_Handle; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@ namespace Light {
|
||||||
class Scene
|
class Scene
|
||||||
{
|
{
|
||||||
friend class Entity;
|
friend class Entity;
|
||||||
|
friend class SceneHierarchyPanel;
|
||||||
private:
|
private:
|
||||||
entt::registry m_Registry;
|
entt::registry m_Registry;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include <LightEngine.h>
|
#include <LightEngine.h>
|
||||||
|
|
||||||
|
#include "Panels/SceneHierarchyPanel.h"
|
||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
@ -14,7 +16,9 @@ namespace Light {
|
||||||
|
|
||||||
Ref<Framebuffer> m_Framebuffer;
|
Ref<Framebuffer> m_Framebuffer;
|
||||||
|
|
||||||
Scene m_Scene;
|
Ref<Scene> m_Scene;
|
||||||
|
SceneHierarchyPanel m_SceneHierarchyPanel;
|
||||||
|
|
||||||
Entity m_CameraEntity;
|
Entity m_CameraEntity;
|
||||||
Entity m_NativeScriptEntity;
|
Entity m_NativeScriptEntity;
|
||||||
|
|
||||||
|
@ -27,20 +31,27 @@ namespace Light {
|
||||||
|
|
||||||
m_Framebuffer = std::shared_ptr<Framebuffer>(Framebuffer::Create({ 800u, 600u, 1u }, GraphicsContext::GetSharedContext()));
|
m_Framebuffer = std::shared_ptr<Framebuffer>(Framebuffer::Create({ 800u, 600u, 1u }, GraphicsContext::GetSharedContext()));
|
||||||
|
|
||||||
m_CameraEntity = m_Scene.CreateEntity("camera", glm::mat4(1.0f));
|
m_Scene = CreateRef<Scene>();
|
||||||
m_CameraEntity.AddComponent<CameraComponent>(SceneCamera(), true);
|
|
||||||
|
|
||||||
for (int i = 0; i < 250; i++)
|
for (int i = 0; i < 250; i++)
|
||||||
{
|
{
|
||||||
glm::vec3 position = glm::vec3(rand() % 3000 - 1400.0f, rand() % 3000 - 1400.0f, 0.0f);
|
glm::vec3 position = glm::vec3(rand() % 3000 - 1400.0f, rand() % 3000 - 1400.0f, 0.0f);
|
||||||
glm::vec2 size = glm::vec2(250.0f, 250.0f);
|
glm::vec2 size = glm::vec2(250.0f, 250.0f);
|
||||||
|
|
||||||
m_Scene.CreateEntity("quad", glm::translate(glm::mat4(1.0f), { position.x, position.y, 0.0f }) *
|
Entity quad = m_Scene->CreateEntity("quad", glm::translate(glm::mat4(1.0f), { position.x, position.y, 0.0f }) *
|
||||||
glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f})).AddComponent<SpriteRendererComponent>(m_AwesomefaceTexture);
|
glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f}));
|
||||||
|
quad.AddComponent<SpriteRendererComponent>(m_AwesomefaceTexture);
|
||||||
|
quad.AddComponent<TagComponent>("quad");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_NativeScriptEntity = m_Scene.CreateEntity("nsc", glm::translate(glm::mat4(1.0f), glm::vec3(0.0f)) * glm::scale(glm::mat4(1.0f), glm::vec3(250.0f, 250.0f, 1.0f)));
|
m_CameraEntity = m_Scene->CreateEntity("camera", glm::mat4(1.0f));
|
||||||
|
m_CameraEntity.AddComponent<CameraComponent>(SceneCamera(), true);
|
||||||
|
m_CameraEntity.AddComponent<TagComponent>("Camera");
|
||||||
|
|
||||||
|
m_NativeScriptEntity = m_Scene->CreateEntity("nsc", glm::translate(glm::mat4(1.0f), glm::vec3(0.0f)) * glm::scale(glm::mat4(1.0f), glm::vec3(250.0f, 250.0f, 1.0f)));
|
||||||
m_NativeScriptEntity.AddComponent<SpriteRendererComponent>(m_AwesomefaceTexture);
|
m_NativeScriptEntity.AddComponent<SpriteRendererComponent>(m_AwesomefaceTexture);
|
||||||
|
m_NativeScriptEntity.AddComponent<TagComponent>("NativeScript");
|
||||||
|
|
||||||
class SampleNativeScript : public Light::NativeScript
|
class SampleNativeScript : public Light::NativeScript
|
||||||
{
|
{
|
||||||
|
@ -54,7 +65,8 @@ namespace Light {
|
||||||
|
|
||||||
|
|
||||||
// create native scripts
|
// create native scripts
|
||||||
m_Scene.OnCreate();
|
m_Scene->OnCreate();
|
||||||
|
m_SceneHierarchyPanel.SetContext(m_Scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnUpdate(float deltaTime) override
|
void OnUpdate(float deltaTime) override
|
||||||
|
@ -76,12 +88,12 @@ namespace Light {
|
||||||
auto& transform = m_CameraEntity.GetComponent<TransformComponent>();
|
auto& transform = m_CameraEntity.GetComponent<TransformComponent>();
|
||||||
transform = glm::translate(transform.transform, glm::vec3(m_Direction * m_Speed * deltaTime, 0.0));
|
transform = glm::translate(transform.transform, glm::vec3(m_Direction * m_Speed * deltaTime, 0.0));
|
||||||
|
|
||||||
m_Scene.OnUpdate(deltaTime);
|
m_Scene->OnUpdate(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnRender() override
|
void OnRender() override
|
||||||
{
|
{
|
||||||
m_Scene.OnRender(m_Framebuffer);
|
m_Scene->OnRender(m_Framebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnUserInterfaceUpdate()
|
void OnUserInterfaceUpdate()
|
||||||
|
@ -111,6 +123,8 @@ namespace Light {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
m_SceneHierarchyPanel.OnUserInterfaceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
12
Mirror/src/Panels/Panel.h
Normal file
12
Mirror/src/Panels/Panel.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Panel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Panel() = default;
|
||||||
|
virtual ~Panel() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
53
Mirror/src/Panels/SceneHierarchyPanel.cpp
Normal file
53
Mirror/src/Panels/SceneHierarchyPanel.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#include "SceneHierarchyPanel.h"
|
||||||
|
|
||||||
|
#include "Scene/Components.h"
|
||||||
|
|
||||||
|
#include <entt.hpp>
|
||||||
|
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context)
|
||||||
|
: m_Context(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneHierarchyPanel::SetContext(Ref<Scene> context)
|
||||||
|
{
|
||||||
|
m_Context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneHierarchyPanel::OnUserInterfaceUpdate()
|
||||||
|
{
|
||||||
|
ImGui::Begin("Hierarchy");
|
||||||
|
|
||||||
|
m_Context->m_Registry.
|
||||||
|
each([&](auto& entityID)
|
||||||
|
{
|
||||||
|
Entity entity(entityID, m_Context.get());
|
||||||
|
const std::string& tag = entity.GetComponent<TagComponent>();
|
||||||
|
|
||||||
|
DrawNode(entity, tag);
|
||||||
|
});
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneHierarchyPanel::DrawNode(Entity entity, const std::string& label)
|
||||||
|
{
|
||||||
|
ImGuiTreeNodeFlags flags = (m_SelectionContext == entity ? ImGuiTreeNodeFlags_Selected : NULL) | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
|
||||||
|
|
||||||
|
bool expanded = ImGui::TreeNodeEx((void*)(uint64_t)(uint32_t)(entity), flags, label.c_str());
|
||||||
|
|
||||||
|
if (ImGui::IsItemClicked())
|
||||||
|
m_SelectionContext = entity;
|
||||||
|
|
||||||
|
if(expanded)
|
||||||
|
{
|
||||||
|
ImGui::Text("TEST_OPENED_TREE!");
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
Mirror/src/Panels/SceneHierarchyPanel.h
Normal file
30
Mirror/src/Panels/SceneHierarchyPanel.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Panel.h"
|
||||||
|
|
||||||
|
#include "Base/Base.h"
|
||||||
|
|
||||||
|
#include "Scene/Entity.h"
|
||||||
|
#include "Scene/Scene.h"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SceneHierarchyPanel : public Panel
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Ref<Scene> m_Context;
|
||||||
|
Entity m_SelectionContext;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SceneHierarchyPanel() = default;
|
||||||
|
SceneHierarchyPanel(Ref<Scene> context);
|
||||||
|
|
||||||
|
void SetContext(Ref<Scene> context);
|
||||||
|
|
||||||
|
void OnUserInterfaceUpdate();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void DrawNode(Entity entity, const std::string& label);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue