Merge branch 'dynamic_property_display'
This commit is contained in:
@@ -3,12 +3,6 @@
|
||||
|
||||
#include <open_engine.hpp>
|
||||
|
||||
#include "open_engine/events/mouse_event.hpp"
|
||||
#include "open_engine/input/input_system.hpp"
|
||||
#include "open_engine/input/mouse_codes.hpp"
|
||||
#include "open_engine/renderer/render_command.hpp"
|
||||
#include "open_engine/renderer/renderer2d.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include "panels/scene_hierarchy.hpp"
|
||||
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
@@ -20,7 +14,6 @@
|
||||
#include <ImGuizmo.h>
|
||||
#include <cstdint>
|
||||
#include <imgui.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@@ -94,7 +87,7 @@ namespace OpenEngine {
|
||||
}
|
||||
*/
|
||||
|
||||
scene_hierarchy.SetContext(scene);
|
||||
scene_hierarchy.Init(scene);
|
||||
}
|
||||
|
||||
void OnDetach() override
|
||||
@@ -154,6 +147,7 @@ namespace OpenEngine {
|
||||
clicked = true;
|
||||
} else {
|
||||
clicked = false;
|
||||
selected_entity = scene_hierarchy.GetSelectedEntity();
|
||||
}
|
||||
|
||||
framebuffer->Unbind();
|
||||
@@ -316,7 +310,7 @@ namespace OpenEngine {
|
||||
glm::mat4 camera_view = editor_camera.GetViewMatrix();
|
||||
|
||||
auto& transform_comp = selected_entity.GetComponents<TransformComponent>();
|
||||
glm::mat4 transform = transform_comp.GetTransform();
|
||||
glm::mat4 transform = GetTransformFromComp(transform_comp);
|
||||
|
||||
bool snap = Input::IsKeyPressed(KeyCode::LeftControl);
|
||||
float snap_value = 0.1f;
|
||||
@@ -339,7 +333,8 @@ namespace OpenEngine {
|
||||
transform_comp.rotation += delta_rotation;
|
||||
transform_comp.scale = scale;
|
||||
}
|
||||
}
|
||||
} else
|
||||
guizmo_operation = -1;
|
||||
};
|
||||
|
||||
void OnImGuiRender() override
|
||||
@@ -364,7 +359,7 @@ namespace OpenEngine {
|
||||
if (!file.empty()) {
|
||||
scene = CreateRef<Scene>();
|
||||
scene->OnViewportResize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
|
||||
scene_hierarchy.SetContext(scene);
|
||||
scene_hierarchy.Init(scene);
|
||||
|
||||
SceneSerializer serializer(scene);
|
||||
serializer.Deserialize(file);
|
||||
@@ -373,7 +368,7 @@ namespace OpenEngine {
|
||||
if (ImGui::MenuItem("New Scene", "Ctrl+N")) {
|
||||
scene = CreateRef<Scene>();
|
||||
scene->OnViewportResize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
|
||||
scene_hierarchy.SetContext(scene);
|
||||
scene_hierarchy.Init(scene);
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Exit"))
|
||||
|
||||
24
editor/include/editor_component.hpp
Normal file
24
editor/include/editor_component.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef EDITOR_COMPONENT_HPP
|
||||
#define EDITOR_COMPONENT_HPP
|
||||
|
||||
#include <array>
|
||||
#include <entt/entity/fwd.hpp>
|
||||
#include <glm/fwd.hpp>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
void DrawVec3Control(const char* label, glm::vec3& values,
|
||||
float reset_value = 0.0f, float column_width = 100.0f,
|
||||
const std::array<const char*, 3> labels = {"x", "y", "z"});
|
||||
|
||||
void TagOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
|
||||
void TransformOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
|
||||
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
|
||||
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity);
|
||||
}
|
||||
|
||||
#endif // EDITOR_COMPONENT_HPP
|
||||
@@ -1,17 +1,27 @@
|
||||
#ifndef SCENE_HIERARCHY_HPP
|
||||
#define SCENE_HIERARCHY_HPP
|
||||
|
||||
#include "imgui.h"
|
||||
#include <entt/core/fwd.hpp>
|
||||
#include <entt/entity/fwd.hpp>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
using ComponentDrawer = std::function<void(entt::registry&, entt::entity)>;
|
||||
|
||||
struct ComponentUI {
|
||||
std::string name;
|
||||
std::function<void(entt::registry&, entt::entity)> draw_func;
|
||||
std::function<void(entt::registry&, entt::entity)> remove_func;
|
||||
};
|
||||
|
||||
class SceneHierarchy
|
||||
{
|
||||
public:
|
||||
SceneHierarchy() = default;
|
||||
SceneHierarchy(const Ref<Scene>& scene);
|
||||
|
||||
void SetContext(const Ref<Scene>& scene);
|
||||
void Init(const Ref<Scene>& scene);
|
||||
|
||||
void OnImGuiRender();
|
||||
|
||||
@@ -22,48 +32,17 @@ namespace OpenEngine {
|
||||
void DrawEntityNode(Entity& entity);
|
||||
void DrawComponents(Entity& entity);
|
||||
|
||||
template <typename T>
|
||||
void DrawComponentDrawer(Entity& entity, const char* header)
|
||||
{
|
||||
bool component_marked_deletion = false;
|
||||
ImVec2 region_available = ImGui::GetContentRegionAvail();
|
||||
ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_DefaultOpen
|
||||
| ImGuiTreeNodeFlags_Framed
|
||||
| ImGuiTreeNodeFlags_AllowOverlap;
|
||||
if (entity.HasComponent<T>()) {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 4, 4 });
|
||||
float line_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
|
||||
|
||||
bool opened = ImGui::TreeNodeEx((void*)typeid(T).hash_code(), tree_node_flags, "%s", header);
|
||||
ImGui::SameLine(region_available.x - line_height * 0.5f);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, { 0.290f, 0.301f, 0.388f, 1.0f });
|
||||
if (ImGui::Button("...", ImVec2{ line_height, line_height }))
|
||||
ImGui::OpenPopup("component_settings");
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (ImGui::BeginPopup("component_settings")) {
|
||||
if (ImGui::MenuItem("Remove component"))
|
||||
component_marked_deletion = true;
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (opened) {
|
||||
entity.GetComponents<T>().OnImGuiRender(entity);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
}
|
||||
if (component_marked_deletion)
|
||||
entity.RemoveComponents<T>();
|
||||
private:
|
||||
template<typename T>
|
||||
static void RegisterDrawer(const std::string& name, std::function<void(entt::registry&, entt::entity)> func) {
|
||||
drawers[entt::type_id<T>().hash()] = {
|
||||
name,
|
||||
func,
|
||||
[](entt::registry& reg, entt::entity ent) { reg.remove<T>(ent); }
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
inline static std::map<entt::id_type, ComponentUI> drawers;
|
||||
Ref<Scene> scene;
|
||||
Entity selected_context, renamed_entity;
|
||||
double last_selected_time = 10.0;
|
||||
|
||||
162
editor/src/editor_component.cpp
Normal file
162
editor/src/editor_component.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
#include <editor_component.hpp>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
void DrawVec3Control(const char* label, glm::vec3& values,
|
||||
float reset_value, float column_width,
|
||||
const std::array<const char*, 3> labels)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
auto bold_font = io.Fonts->Fonts[0];
|
||||
|
||||
ImGui::PushID(label);
|
||||
ImVec2 item_spacing = { 15.0f, 0.0f };
|
||||
ImGui::Columns(2);
|
||||
ImGui::SetColumnWidth(0, column_width);
|
||||
ImGui::Text("%s", label);
|
||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered())
|
||||
values = glm::vec3(reset_value);
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||
|
||||
float line_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
|
||||
ImVec2 button_size = { line_height + 3.0f, line_height };
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 1.0f, 0.8f, 0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[0], button_size))
|
||||
values.x = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##X", &values.x, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f, 1.0f, 0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[1], button_size))
|
||||
values.y = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Y", &values.y, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.7f, 0.9f, 1.0f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[2], button_size))
|
||||
values.z = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
ImGui::PopStyleVar(1);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Z", &values.z, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::Columns(1);
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
void TagOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
char buffer[256];
|
||||
|
||||
auto& tag = registry.get<TagComponent>(entity).tag;
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
std::strncpy(buffer, tag.c_str(), sizeof(buffer));
|
||||
|
||||
if (ImGui::InputText("##tagEditor", buffer, sizeof(buffer), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)
|
||||
|| (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)))
|
||||
tag = buffer;
|
||||
};
|
||||
|
||||
void TransformOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
auto& transform = registry.get<TransformComponent>(entity);
|
||||
DrawVec3Control("Position", transform.translation);
|
||||
glm::vec3 rotation_comp = glm::degrees(transform.rotation);
|
||||
DrawVec3Control("Rotation", rotation_comp);
|
||||
transform.rotation = glm::radians(rotation_comp);
|
||||
DrawVec3Control("Scale", transform.scale);
|
||||
};
|
||||
|
||||
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
auto& sprite = registry.get<SpriteRendererComponent>(entity);
|
||||
ImGui::ColorEdit4("color", glm::value_ptr(sprite.color));
|
||||
};
|
||||
|
||||
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
auto& camera_comp = registry.get<CameraComponent>(entity);
|
||||
auto& camera = camera_comp.camera;
|
||||
ImGui::Checkbox("Is primary", &camera_comp.primary);
|
||||
const char* projection_type_strings[] = {"Perspective", "Orthographic"};
|
||||
const char* current_projection_type = projection_type_strings[(int)camera.GetProjectionType()];
|
||||
|
||||
if (ImGui::BeginCombo("Projection", current_projection_type)) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
bool is_selected = current_projection_type == projection_type_strings[i];
|
||||
if (ImGui::Selectable(projection_type_strings[i], is_selected)) {
|
||||
current_projection_type = projection_type_strings[i];
|
||||
camera.SetProjectionType((SceneCamera::ProjectionType)i);
|
||||
}
|
||||
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
if (camera.GetProjectionType() == SceneCamera::ProjectionType::Perspective) {
|
||||
float fov = camera.GetVerticalFov();
|
||||
if (ImGui::DragFloat("Fov", &fov, 0.1f))
|
||||
camera.SetVerticalFov(fov);
|
||||
|
||||
float near_clip = camera.GetPerspectiveNearClip();
|
||||
if (ImGui::DragFloat("Near clip", &near_clip, 0.1f))
|
||||
camera.SetPerspectiveNearClip(near_clip);
|
||||
|
||||
float far_clip = camera.GetPerspectiveFarClip();
|
||||
if (ImGui::DragFloat("Far clip", &far_clip, 0.1f))
|
||||
camera.SetPerspectiveFarClip(far_clip);
|
||||
}
|
||||
else if (camera.GetProjectionType() == SceneCamera::ProjectionType::Orthographic) {
|
||||
ImGui::Checkbox("Has fixed aspect ratio", &camera_comp.fixed_aspect_ratio);
|
||||
float ortho_size = camera.GetOrthographicSize();
|
||||
if (ImGui::DragFloat("Orthographic size", &ortho_size, 0.1f))
|
||||
camera.SetOrthographicSize(ortho_size);
|
||||
|
||||
float near_clip = camera.GetOrthographicNearClip();
|
||||
if (ImGui::DragFloat("Near clip", &near_clip, 0.1f))
|
||||
camera.SetOrthographicNearClip(near_clip);
|
||||
|
||||
float far_clip = camera.GetOrthographicFarClip();
|
||||
if (ImGui::DragFloat("Far clip", &far_clip, 0.1f))
|
||||
camera.SetOrthographicFarClip(far_clip);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include "open_engine/scene/entity.hpp"
|
||||
#include "editor_component.hpp"
|
||||
|
||||
#include <panels/scene_hierarchy.hpp>
|
||||
|
||||
#include <cstring>
|
||||
@@ -7,13 +9,20 @@
|
||||
#include <imgui.h>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
using ComponentDrawer = std::function<void(entt::registry&, entt::entity)>;
|
||||
|
||||
SceneHierarchy::SceneHierarchy(const Ref<Scene>& scene)
|
||||
: scene(scene)
|
||||
{
|
||||
}
|
||||
|
||||
void SceneHierarchy::SetContext(const Ref<Scene>& context)
|
||||
void SceneHierarchy::Init(const Ref<Scene>& context)
|
||||
{
|
||||
RegisterDrawer<TransformComponent>("Transform", &TransformOnImGuiRender);
|
||||
RegisterDrawer<SpriteRendererComponent>("Sprite Renderer", &SpriteOnImGuiRender);
|
||||
RegisterDrawer<CameraComponent>("Camera", &CameraOnImGuiRender);
|
||||
|
||||
scene = context;
|
||||
selected_context = {};
|
||||
}
|
||||
@@ -184,11 +193,53 @@ namespace OpenEngine {
|
||||
|
||||
void SceneHierarchy::DrawComponents(Entity& entity)
|
||||
{
|
||||
if (entity.HasComponent<TagComponent>())
|
||||
entity.GetComponents<TagComponent>().OnImGuiRender(entity);
|
||||
auto& reg = scene->GetRegistry();
|
||||
entt::entity handle = selected_context;
|
||||
|
||||
DrawComponentDrawer<TransformComponent>(entity, "Transform");
|
||||
DrawComponentDrawer<SpriteRendererComponent>(entity, "Sprite");
|
||||
DrawComponentDrawer<CameraComponent>(entity, "Camera");
|
||||
if (!selected_context || !entity)
|
||||
return;
|
||||
|
||||
entity.GetComponents<TagComponent>();
|
||||
TagOnImGuiRender(reg, entity);
|
||||
|
||||
std::vector<entt::id_type> component_to_delete; // 0 is null/invalid in entt usually
|
||||
// Iterate through every component type entt knows about
|
||||
for (auto [id, storage] : reg.storage()) {
|
||||
if (storage.contains(handle)) {
|
||||
if (drawers.contains(id)) {
|
||||
bool component_marked_deletion = false;
|
||||
ImVec2 region_available = ImGui::GetContentRegionAvail();
|
||||
ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_DefaultOpen
|
||||
| ImGuiTreeNodeFlags_Framed
|
||||
| ImGuiTreeNodeFlags_AllowOverlap;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 4, 4 });
|
||||
float line_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
|
||||
|
||||
bool opened = ImGui::TreeNodeEx((void*)(intptr_t)id, tree_node_flags, "%s", drawers[id].name.c_str());
|
||||
ImGui::SameLine(region_available.x - line_height * 0.5f);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, { 0.290f, 0.301f, 0.388f, 1.0f });
|
||||
if (ImGui::Button("...", ImVec2{ line_height, line_height }))
|
||||
ImGui::OpenPopup("component_settings");
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (ImGui::BeginPopup("component_settings")) {
|
||||
if (ImGui::MenuItem("Remove component"))
|
||||
component_to_delete.emplace_back(id);
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (opened) {
|
||||
drawers[id].draw_func(reg, handle);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& id : component_to_delete)
|
||||
drawers[id].remove_func(reg, entity);
|
||||
}
|
||||
}
|
||||
|
||||
26
imgui.ini
26
imgui.ini
@@ -1,40 +1,40 @@
|
||||
[Window][WindowOverViewport_11111111]
|
||||
Pos=0,24
|
||||
Size=2560,1371
|
||||
Size=1272,1363
|
||||
Collapsed=0
|
||||
|
||||
[Window][Debug##Default]
|
||||
Pos=-32,513
|
||||
Pos=-32,370
|
||||
Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][Statistics]
|
||||
Pos=0,24
|
||||
Size=409,228
|
||||
Size=409,300
|
||||
Collapsed=0
|
||||
DockId=0x00000003,0
|
||||
|
||||
[Window][Properties]
|
||||
Pos=2110,24
|
||||
Size=450,743
|
||||
Pos=822,24
|
||||
Size=450,739
|
||||
Collapsed=0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=411,24
|
||||
Size=1697,1371
|
||||
Size=409,1363
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
|
||||
[Window][Dear ImGui Demo]
|
||||
Pos=2110,769
|
||||
Size=450,626
|
||||
Pos=822,765
|
||||
Size=450,622
|
||||
Collapsed=0
|
||||
DockId=0x00000008,0
|
||||
|
||||
[Window][Scene]
|
||||
Pos=0,254
|
||||
Size=409,1141
|
||||
Pos=0,326
|
||||
Size=409,1061
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
@@ -142,11 +142,11 @@ Collapsed=0
|
||||
DockId=0x00000009,1
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,24 Size=2560,1371 Split=X
|
||||
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,24 Size=1272,1363 Split=X
|
||||
DockNode ID=0x00000005 Parent=0x08BD597D SizeRef=820,1386 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=409,1386 Split=Y Selected=0xE601B12F
|
||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=255,231 Selected=0x553E127E
|
||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=255,1153 Selected=0xE601B12F
|
||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=255,300 Selected=0x553E127E
|
||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=255,1061 Selected=0xE601B12F
|
||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1697,1386 Split=Y Selected=0xC450F867
|
||||
DockNode ID=0x00000009 Parent=0x00000002 SizeRef=483,784 CentralNode=1 Selected=0xC450F867
|
||||
DockNode ID=0x0000000A Parent=0x00000002 SizeRef=483,600 Selected=0x1BCA3180
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "open_engine/scene/native_scriptable_entity.hpp"
|
||||
#include "open_engine/scene/scene_serializer.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
|
||||
#include "open_engine/core/file_dialogs.hpp"
|
||||
#include "open_engine/core/time.hpp"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "open_engine/scene/native_scriptable_entity.hpp"
|
||||
#include "open_engine/scene/scene_camera.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/fwd.hpp>
|
||||
@@ -19,10 +18,6 @@
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
void DrawVec3Control(const char* label, glm::vec3& values,
|
||||
float reset_value = 0.0f, float column_width = 100.0f,
|
||||
const std::array<const char*, 3> labels = {"x", "y", "z"});
|
||||
|
||||
struct TagComponent
|
||||
{
|
||||
std::string tag;
|
||||
@@ -31,20 +26,9 @@ namespace OpenEngine {
|
||||
TagComponent(const TagComponent&) = default;
|
||||
TagComponent(const std::string& tag)
|
||||
: tag(tag) {}
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
char buffer[256];
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
std::strncpy(buffer, tag.c_str(), sizeof(buffer));
|
||||
|
||||
if (ImGui::InputText("##tagEditor", buffer, sizeof(buffer), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)
|
||||
|| (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)))
|
||||
tag = buffer;
|
||||
};
|
||||
};
|
||||
|
||||
struct TransformComponent
|
||||
struct TransformComponent
|
||||
{
|
||||
glm::vec3 translation = { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 rotation = { 0.0f, 0.0f, 0.0f };
|
||||
@@ -54,28 +38,11 @@ namespace OpenEngine {
|
||||
TransformComponent(const TransformComponent&) = default;
|
||||
TransformComponent(const glm::vec3& position)
|
||||
: translation(position) {}
|
||||
|
||||
glm::mat4 GetTransform() const
|
||||
{
|
||||
glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation);
|
||||
|
||||
transform *= glm::toMat4(glm::quat(rotation));
|
||||
transform *= glm::scale(glm::mat4(1.0f), scale);
|
||||
|
||||
return transform;
|
||||
};
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
DrawVec3Control("Position", translation);
|
||||
glm::vec3 rotation_comp = glm::degrees(rotation);
|
||||
DrawVec3Control("Rotation", rotation_comp);
|
||||
rotation = glm::radians(rotation_comp);
|
||||
DrawVec3Control("Scale", scale);
|
||||
};
|
||||
};
|
||||
|
||||
struct SpriteRendererComponent
|
||||
glm::mat4 GetTransformFromComp(TransformComponent& transform_comp);
|
||||
|
||||
struct SpriteRendererComponent
|
||||
{
|
||||
glm::vec4 color{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
@@ -83,14 +50,9 @@ namespace OpenEngine {
|
||||
SpriteRendererComponent(const SpriteRendererComponent&) = default;
|
||||
SpriteRendererComponent(const glm::vec4& color)
|
||||
: color(color) {}
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
ImGui::ColorEdit4("color", glm::value_ptr(color));
|
||||
};
|
||||
};
|
||||
|
||||
struct CameraComponent
|
||||
struct CameraComponent
|
||||
{
|
||||
SceneCamera camera;
|
||||
bool primary = true;
|
||||
@@ -98,65 +60,18 @@ namespace OpenEngine {
|
||||
|
||||
CameraComponent() = default;
|
||||
CameraComponent(const CameraComponent&) = default;
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
ImGui::Checkbox("Is primary", &primary);
|
||||
const char* projection_type_strings[] = {"Perspective", "Orthographic"};
|
||||
const char* current_projection_type = projection_type_strings[(int)camera.GetProjectionType()];
|
||||
|
||||
if (ImGui::BeginCombo("Projection", current_projection_type)) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
bool is_selected = current_projection_type == projection_type_strings[i];
|
||||
if (ImGui::Selectable(projection_type_strings[i], is_selected)) {
|
||||
current_projection_type = projection_type_strings[i];
|
||||
camera.SetProjectionType((SceneCamera::ProjectionType)i);
|
||||
}
|
||||
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
if (camera.GetProjectionType() == SceneCamera::ProjectionType::Perspective) {
|
||||
float fov = camera.GetVerticalFov();
|
||||
if (ImGui::DragFloat("Fov", &fov, 0.1f))
|
||||
camera.SetVerticalFov(fov);
|
||||
|
||||
float near_clip = camera.GetPerspectiveNearClip();
|
||||
if (ImGui::DragFloat("Near clip", &near_clip, 0.1f))
|
||||
camera.SetPerspectiveNearClip(near_clip);
|
||||
|
||||
float far_clip = camera.GetPerspectiveFarClip();
|
||||
if (ImGui::DragFloat("Far clip", &far_clip, 0.1f))
|
||||
camera.SetPerspectiveFarClip(far_clip);
|
||||
}
|
||||
else if (camera.GetProjectionType() == SceneCamera::ProjectionType::Orthographic) {
|
||||
ImGui::Checkbox("Has fixed aspect ratio", &fixed_aspect_ratio);
|
||||
float ortho_size = camera.GetOrthographicSize();
|
||||
if (ImGui::DragFloat("Orthographic size", &ortho_size, 0.1f))
|
||||
camera.SetOrthographicSize(ortho_size);
|
||||
|
||||
float near_clip = camera.GetOrthographicNearClip();
|
||||
if (ImGui::DragFloat("Near clip", &near_clip, 0.1f))
|
||||
camera.SetOrthographicNearClip(near_clip);
|
||||
|
||||
float far_clip = camera.GetOrthographicFarClip();
|
||||
if (ImGui::DragFloat("Far clip", &far_clip, 0.1f))
|
||||
camera.SetOrthographicFarClip(far_clip);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
struct NativeScriptComponent
|
||||
struct NativeScriptComponent
|
||||
{
|
||||
NativeScriptableEntity* instance = nullptr;
|
||||
|
||||
NativeScriptableEntity* (*InstanciateScript)();
|
||||
void (*DestroyInstanceScript)(NativeScriptComponent*);
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{};
|
||||
|
||||
template <typename T>
|
||||
void Bind()
|
||||
{
|
||||
|
||||
@@ -1,83 +1,16 @@
|
||||
#include "imgui.h"
|
||||
#include <pch.hpp>
|
||||
|
||||
#include <scene/components.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
void DrawVec3Control(const char* label, glm::vec3& values,
|
||||
float reset_value, float column_width,
|
||||
const std::array<const char*, 3> labels)
|
||||
glm::mat4 GetTransformFromComp(TransformComponent& transform_comp)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
auto bold_font = io.Fonts->Fonts[0];
|
||||
glm::mat4 transform = glm::translate(glm::mat4(1.0f), transform_comp.translation);
|
||||
|
||||
ImGui::PushID(label);
|
||||
ImVec2 item_spacing = { 15.0f, 0.0f };
|
||||
ImGui::Columns(2);
|
||||
ImGui::SetColumnWidth(0, column_width);
|
||||
ImGui::Text("%s", label);
|
||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered())
|
||||
values = glm::vec3(reset_value);
|
||||
ImGui::NextColumn();
|
||||
transform *= glm::toMat4(glm::quat(transform_comp.rotation));
|
||||
transform *= glm::scale(glm::mat4(1.0f), transform_comp.scale);
|
||||
|
||||
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||
|
||||
float line_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
|
||||
ImVec2 button_size = { line_height + 3.0f, line_height };
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 1.0f, 0.8f, 0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[0], button_size))
|
||||
values.x = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##X", &values.x, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f, 1.0f, 0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[1], button_size))
|
||||
values.y = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Y", &values.y, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.7f, 0.9f, 1.0f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[2], button_size))
|
||||
values.z = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
ImGui::PopStyleVar(1);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Z", &values.z, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::Columns(1);
|
||||
ImGui::PopID();
|
||||
}
|
||||
return transform;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "logging.hpp"
|
||||
#include <pch.hpp>
|
||||
|
||||
#include <scene/scene.hpp>
|
||||
#include <renderer/renderer2d.hpp>
|
||||
|
||||
#include <scene/entity.hpp>
|
||||
#include <scene/components.hpp>
|
||||
#include <scene/entity.hpp>
|
||||
#include <scene/scene.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
Entity Scene::CreateEntity(const std::string& name)
|
||||
@@ -49,7 +47,7 @@ namespace OpenEngine {
|
||||
|
||||
if (camera_component.primary) {
|
||||
main_camera = &camera_component.camera;
|
||||
main_transform = transform.GetTransform();
|
||||
main_transform = GetTransformFromComp(transform);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +59,7 @@ namespace OpenEngine {
|
||||
|
||||
for (const auto& entity : view) {
|
||||
auto [transform, sprite] = view.get<TransformComponent, SpriteRendererComponent>(entity);
|
||||
Renderer2D::DrawQuad(transform.GetTransform(), sprite.color, (int)entity);
|
||||
Renderer2D::DrawQuad(GetTransformFromComp(transform), sprite.color, (int)entity);
|
||||
}
|
||||
|
||||
Renderer2D::EndScene();
|
||||
@@ -78,7 +76,7 @@ namespace OpenEngine {
|
||||
{
|
||||
auto [transform, sprite] = group.get<TransformComponent, SpriteRendererComponent>(entity);
|
||||
|
||||
Renderer2D::DrawQuad(transform.GetTransform(), sprite.color, (int)entity);
|
||||
Renderer2D::DrawQuad(GetTransformFromComp(transform), sprite.color, (int)entity);
|
||||
}
|
||||
|
||||
Renderer2D::EndScene();
|
||||
|
||||
Reference in New Issue
Block a user