From 37aad4940654b04f2ade8f24afb66d0c42c01ed4 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Tue, 15 Nov 2022 21:09:24 +0800 Subject: [PATCH] Added requested rigidbody component view with debug information Changed DragVec controls to not push commands if ImGuiSliderFlags_ReadOnly is enabled --- .../Inspector/SHEditorComponentView.hpp | 93 ++++++++++++++++--- SHADE_Engine/src/Editor/SHEditorWidgets.hpp | 6 +- 2 files changed, 85 insertions(+), 14 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 146e36c3..f8cec296 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -220,6 +220,86 @@ namespace SHADE } + template<> + static void DrawComponent(SHRigidBodyComponent* component) + { + if(!component) + return; + ImGui::PushID(SHFamilyID::GetID()); + + const auto componentType = rttr::type::get(); + SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); + ImGui::SameLine(); + if (ImGui::CollapsingHeader(componentType.get_name().data())) + { + DrawContextMenu(component); + + SHRigidBodyComponent::Type rbType = component->GetType(); + + auto enumAlign = rttr::type::get().get_enumeration(); + auto names = enumAlign.get_names(); + std::vector list; + for (auto const& name : names) + list.push_back(name.data()); + SHEditorWidgets::ComboBox("Type", list, [component] {return static_cast(component->GetType()); }, [component, enumAlign](int const& idx) + { + auto values = enumAlign.get_values(); + auto it = std::next(values.begin(), idx); + component->SetType((*it).convert()); + }, "RigidBody Type"); + + + if(rbType == SHRigidBodyComponent::Type::DYNAMIC) //Dynamic only fields + { + SHEditorWidgets::DragFloat("Mass", [component] {return component->GetMass(); }, [component](float const& value) {component->SetMass(value); }, "Mass"); + SHEditorWidgets::DragFloat("Drag", [component] {return component->GetDrag(); }, [component](float const& value) {component->SetDrag(value); }, "Drag"); + SHEditorWidgets::DragFloat("Angular Drag", [component] {return component->GetAngularDrag(); }, [component](float const& value) {component->SetAngularDrag(value); }, "Angular Drag"); + SHEditorWidgets::CheckBox("Use Gravity", [component]{return component->IsGravityEnabled();}, [component](bool const& value){component->SetGravityEnabled(value);}, "Gravity"); + } + if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields + { + SHEditorWidgets::CheckBox("Interpolate", [component] {return component->IsInterpolating(); }, [component](bool const& value) {component->SetInterpolate(value); }, "Interpolate"); + + SHEditorWidgets::BeginPanel(std::format("{} Constraints", ICON_FA_LOCK).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); + + SHEditorWidgets::TextLabel("Freeze Position"); + SHEditorWidgets::CheckBox("X", [component] {return component->GetFreezePositionX(); }, [component](bool const& value) {component->SetFreezePositionX(value); }, "Freeze Position - X"); ImGui::SameLine(); + SHEditorWidgets::CheckBox("Y", [component] {return component->GetFreezePositionY(); }, [component](bool const& value) {component->SetFreezePositionY(value); }, "Freeze Position - Y"); ImGui::SameLine(); + SHEditorWidgets::CheckBox("Z", [component] {return component->GetFreezePositionZ(); }, [component](bool const& value) {component->SetFreezePositionZ(value); }, "Freeze Position - Z"); + + SHEditorWidgets::TextLabel("Freeze Rotation"); + SHEditorWidgets::CheckBox("X", [component] {return component->GetFreezeRotationX(); }, [component](bool const& value) {component->SetFreezeRotationX(value); }, "Freeze Rotation - X"); ImGui::SameLine(); + SHEditorWidgets::CheckBox("Y", [component] {return component->GetFreezeRotationY(); }, [component](bool const& value) {component->SetFreezeRotationY(value); }, "Freeze Rotation - Y"); ImGui::SameLine(); + SHEditorWidgets::CheckBox("Z", [component] {return component->GetFreezeRotationZ(); }, [component](bool const& value) {component->SetFreezeRotationZ(value); }, "Freeze Rotation - Z"); + + SHEditorWidgets::EndPanel(); + } + + //Debug Info (Read-Only) + if(ImGui::CollapsingHeader("Debug Information", ImGuiTreeNodeFlags_DefaultOpen))//Dynamic or Kinematic only fields + { + SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [component] {return component->GetPosition(); }, [](SHVec3 const& value) {}, false, "Position", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); + SHEditorWidgets::DragVec3("Rotation", { "X", "Y", "Z" }, [component] {return component->GetRotation(); }, [](SHVec3 const& value) {}, false, "Rotation", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); + if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields + { + SHEditorWidgets::DragVec3("Velocity", { "X", "Y", "Z" }, [component] {return component->GetLinearVelocity(); }, [](SHVec3 const& value) {}, false, "Linear Velocity", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); + SHEditorWidgets::DragVec3("Angular Velocity", { "X", "Y", "Z" }, [component] {return component->GetAngularVelocity(); }, [](SHVec3 const& value) {}, false, "Angular Velocity", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); + } + if (rbType == SHRigidBodyComponent::Type::DYNAMIC) //Dynamic only fields + { + SHEditorWidgets::DragVec3("Force", { "X", "Y", "Z" }, [component] {return component->GetForce(); }, [](SHVec3 const& value) {}, false, "Force", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); + SHEditorWidgets::DragVec3("Torque", { "X", "Y", "Z" }, [component] {return component->GetTorque(); }, [](SHVec3 const& value) {}, false, "Torque", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); + } + } + + } + else + { + DrawContextMenu(component); + } + ImGui::PopID(); + } + template<> static void DrawComponent(SHColliderComponent* component) { @@ -278,21 +358,12 @@ namespace SHADE [&collider] { auto offset = collider->GetRotationOffset(); - offset.x = SHMath::RadiansToDegrees(offset.x); - offset.y = SHMath::RadiansToDegrees(offset.y); - offset.z = SHMath::RadiansToDegrees(offset.z); return offset; }, [&collider](SHVec3 const& vec) { - const SHVec3 vecInRad - { - SHMath::DegreesToRadians(vec.x) - , SHMath::DegreesToRadians(vec.y) - , SHMath::DegreesToRadians(vec.z) - }; - collider->SetRotationOffset(vecInRad); - }); + collider->SetRotationOffset(vec); + }, true); SHEditorWidgets::EndPanel(); } diff --git a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp index 0855d68d..11b35cfc 100644 --- a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp +++ b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp @@ -219,7 +219,7 @@ namespace SHADE } bool const changed = DragN(label, componentLabels, { &values.x, &values.y }, speed, displayFormat, valueMin, valueMax, flags); static bool startRecording = false; - if (changed) + if (!(flags & ImGuiSliderFlags_ReadOnly) && changed) { if(isAnAngleInRad) { @@ -255,7 +255,7 @@ namespace SHADE bool isHovered = false; bool const changed = DragN(label, componentLabels, { &values.x, &values.y, &values.z }, speed, displayFormat, valueMin, valueMax, flags, &isHovered); static bool startRecording = false; - if (changed) + if (!(flags & ImGuiSliderFlags_ReadOnly) && changed) { SHVec3 old = get(); if(isAnAngleInRad) @@ -293,7 +293,7 @@ namespace SHADE } bool const changed = DragN(label, componentLabels, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags); static bool startRecording = false; - if (changed) + if (!(flags & ImGuiSliderFlags_ReadOnly) && changed) { if(isAnAngleInRad) {