diff --git a/editor/include/editor.hpp b/editor/include/editor.hpp index e054478..3eef8ca 100755 --- a/editor/include/editor.hpp +++ b/editor/include/editor.hpp @@ -1,6 +1,7 @@ #ifndef EDITOR_HPP #define EDITOR_HPP +#include #include #include "open_engine/renderer/renderer3d.hpp" @@ -285,6 +286,10 @@ namespace OpenEngine { guizmo_operation = ImGuizmo::OPERATION::SCALE; break; } + case KeyCode::T: { + guizmo_operation = ImGuizmo::OPERATION::UNIVERSAL; + break; + } case KeyCode::Delete: { scene->MarkEntityForDeletion(selected_entity); scene_hierarchy.ClearSelection(); diff --git a/editor/include/editor_component.hpp b/editor/include/editor_component.hpp index 7a3ecc7..48e6ff5 100644 --- a/editor/include/editor_component.hpp +++ b/editor/include/editor_component.hpp @@ -21,6 +21,7 @@ namespace OpenEngine { void BodyOnImGuiRender(entt::registry& registry, entt::entity entity); void SphereShapeOnImGuiRender(entt::registry& registry, entt::entity entity); void BoxShapeOnImGuiRender(entt::registry& registry, entt::entity entity); + void PlaneShapeOnImGuiRender(entt::registry& registry, entt::entity entity); } #endif // EDITOR_COMPONENT_HPP diff --git a/editor/src/editor_component.cpp b/editor/src/editor_component.cpp index 855ee08..333e0d7 100644 --- a/editor/src/editor_component.cpp +++ b/editor/src/editor_component.cpp @@ -283,4 +283,16 @@ namespace OpenEngine { "%.2f", ImGuiSliderFlags_AlwaysClamp); } + + void PlaneShapeOnImGuiRender(entt::registry& registry, entt::entity entity) + { + auto& planed_comp = registry.get(entity); + + ImGui::DragFloat("Size", + &planed_comp.extent, + 0.1f, + 0.01f, FLT_MAX, + "%.2f", + ImGuiSliderFlags_AlwaysClamp); + } } diff --git a/editor/src/panels/scene_hierarchy.cpp b/editor/src/panels/scene_hierarchy.cpp index 652febf..df755ee 100644 --- a/editor/src/panels/scene_hierarchy.cpp +++ b/editor/src/panels/scene_hierarchy.cpp @@ -1,3 +1,4 @@ +#include "open_engine/scene/components.hpp" #include "open_engine/scene/entity.hpp" #include "editor_component.hpp" @@ -26,6 +27,7 @@ namespace OpenEngine { RegisterDrawer("Physics Body", &BodyOnImGuiRender); RegisterDrawer("Sphere Shape", &SphereShapeOnImGuiRender); RegisterDrawer("Box Shape", &BoxShapeOnImGuiRender); + RegisterDrawer("Plane Shape", &PlaneShapeOnImGuiRender); scene = context; selected_context = {}; @@ -74,6 +76,11 @@ namespace OpenEngine { selected_context.AddComponent(); ImGui::CloseCurrentPopup(); } + if (!selected_context.HasComponent()) + if (ImGui::MenuItem("Plane shape")) { + selected_context.AddComponent(); + ImGui::CloseCurrentPopup(); + } } void EntityPopup(Ref& scene) diff --git a/imgui.ini b/imgui.ini index 9bfba42..a3d0252 100644 --- a/imgui.ini +++ b/imgui.ini @@ -1,6 +1,6 @@ [Window][WindowOverViewport_11111111] Pos=0,24 -Size=1272,1363 +Size=2560,1371 Collapsed=0 [Window][Debug##Default] @@ -10,31 +10,31 @@ Collapsed=0 [Window][Statistics] Pos=0,24 -Size=224,437 +Size=224,439 Collapsed=0 DockId=0x00000003,0 [Window][Properties] -Pos=822,24 -Size=450,805 +Pos=2110,24 +Size=450,810 Collapsed=0 DockId=0x00000007,0 [Window][Viewport] Pos=226,61 -Size=594,956 +Size=1882,964 Collapsed=0 DockId=0x00000012,0 [Window][Dear ImGui Demo] -Pos=822,831 -Size=450,556 +Pos=2110,836 +Size=450,559 Collapsed=0 DockId=0x00000008,0 [Window][Scene] -Pos=0,463 -Size=224,924 +Pos=0,465 +Size=224,930 Collapsed=0 DockId=0x00000004,0 @@ -143,8 +143,8 @@ Collapsed=0 DockId=0x00000012,1 [Window][Assets] -Pos=226,1019 -Size=594,368 +Pos=226,1027 +Size=1882,368 Collapsed=0 DockId=0x0000000C,0 @@ -156,12 +156,12 @@ DockId=0x0000000F,0 [Window][##play_state_bar] Pos=226,24 -Size=594,35 +Size=1882,35 Collapsed=0 DockId=0x00000011,0 [Docking][Data] -DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,24 Size=1272,1363 Split=X +DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,24 Size=2560,1371 Split=X DockNode ID=0x00000005 Parent=0x08BD597D SizeRef=820,1386 Split=X DockNode ID=0x00000001 Parent=0x00000005 SizeRef=224,1386 Split=Y Selected=0xE601B12F DockNode ID=0x00000003 Parent=0x00000001 SizeRef=255,417 Selected=0x553E127E diff --git a/open_engine/include/open_engine/scene/components.hpp b/open_engine/include/open_engine/scene/components.hpp index d5fe5cb..c5d4aa8 100644 --- a/open_engine/include/open_engine/scene/components.hpp +++ b/open_engine/include/open_engine/scene/components.hpp @@ -153,6 +153,11 @@ namespace OpenEngine { { float radius = 1.0f; }; + + struct PlaneShapeComponent + { + float extent = 1.0f; + }; } #endif // COMPONENTS_HPP diff --git a/open_engine/src/open_engine/scene/scene.cpp b/open_engine/src/open_engine/scene/scene.cpp index 75297ad..f691578 100755 --- a/open_engine/src/open_engine/scene/scene.cpp +++ b/open_engine/src/open_engine/scene/scene.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -34,8 +35,13 @@ namespace OpenEngine { auto& c = reg.get(e); return CreateRef(c.radius); } + if (reg.any_of(e)) { + auto& c = reg.get(e); + const Plane plane({ 0.0f, 1.0f, 0.0f }, 0); + return CreateRef(plane, nullptr, c.extent); + } - OE_CORE_ERROR("Entity has no shape component!"); + OE_CORE_ERROR("Entity {} has no shape component!", reg.get(e).tag); return nullptr; }; @@ -352,4 +358,9 @@ namespace OpenEngine { void Scene::OnComponentAdded(Entity entity, IDComponent& component) { } + + template<> + void Scene::OnComponentAdded(Entity entity, PlaneShapeComponent& component) + { + } } diff --git a/open_engine/src/open_engine/scene/scene_serializer.cpp b/open_engine/src/open_engine/scene/scene_serializer.cpp index 9733ea6..6213720 100644 --- a/open_engine/src/open_engine/scene/scene_serializer.cpp +++ b/open_engine/src/open_engine/scene/scene_serializer.cpp @@ -214,6 +214,16 @@ namespace OpenEngine { out << YAML::EndMap; //SphereShapeComponent } + if (entity.HasComponent()) { + out << YAML::Key << "PlaneShapeComponent"; + out << YAML::BeginMap; //PlaneShapeComponent + + auto& psc = entity.GetComponents(); + out << YAML::Key << "Extent" << YAML::Value << psc.extent; + + out << YAML::EndMap; //PlaneShapeComponent + } + out << YAML::EndMap; } @@ -366,6 +376,13 @@ namespace OpenEngine { ssc.radius = sphere_shape_component["Radius"].as(); } + + auto plane_shape_component = entity["PlaneShapeComponent"]; + if (sphere_shape_component) { + auto& psc = deserializedEntity.AddComponent(); + + psc.extent = plane_shape_component["Extent"].as(); + } } }