Merge pull request #213 from SHADE-DP/SP3-4-Editor
Added Custom RigidBody Component View in Editor
This commit is contained in:
commit
690ebef77d
|
@ -220,6 +220,87 @@ namespace SHADE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
static void DrawComponent(SHRigidBodyComponent* component)
|
||||||
|
{
|
||||||
|
if(!component)
|
||||||
|
return;
|
||||||
|
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHRigidBodyComponent>());
|
||||||
|
|
||||||
|
const auto componentType = rttr::type::get<SHRigidBodyComponent>();
|
||||||
|
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<SHRigidBodyComponent::Type>().get_enumeration();
|
||||||
|
auto names = enumAlign.get_names();
|
||||||
|
std::vector<const char*> list;
|
||||||
|
for (auto const& name : names)
|
||||||
|
list.push_back(name.data());
|
||||||
|
SHEditorWidgets::ComboBox("Type", list, [component] {return static_cast<int>(component->GetType()); }, [component, enumAlign](int const& idx)
|
||||||
|
{
|
||||||
|
auto values = enumAlign.get_values();
|
||||||
|
auto it = std::next(values.begin(), idx);
|
||||||
|
component->SetType((*it).convert<SHRigidBodyComponent::Type>());
|
||||||
|
}, "RigidBody Type");
|
||||||
|
|
||||||
|
|
||||||
|
if(rbType == SHRigidBodyComponent::Type::DYNAMIC) //Dynamic only fields
|
||||||
|
{
|
||||||
|
SHEditorWidgets::CheckBox("Use Gravity", [component]{return component->IsGravityEnabled();}, [component](bool const& value){component->SetGravityEnabled(value);}, "Gravity");
|
||||||
|
SHEditorWidgets::DragFloat("Mass", [component] {return component->GetMass(); }, [component](float const& value) {component->SetMass(value); }, "Mass");
|
||||||
|
}
|
||||||
|
if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields
|
||||||
|
{
|
||||||
|
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("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\nVelocity", { "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<>
|
template<>
|
||||||
static void DrawComponent(SHColliderComponent* component)
|
static void DrawComponent(SHColliderComponent* component)
|
||||||
{
|
{
|
||||||
|
@ -278,21 +359,12 @@ namespace SHADE
|
||||||
[&collider]
|
[&collider]
|
||||||
{
|
{
|
||||||
auto offset = collider->GetRotationOffset();
|
auto offset = collider->GetRotationOffset();
|
||||||
offset.x = SHMath::RadiansToDegrees(offset.x);
|
|
||||||
offset.y = SHMath::RadiansToDegrees(offset.y);
|
|
||||||
offset.z = SHMath::RadiansToDegrees(offset.z);
|
|
||||||
return offset;
|
return offset;
|
||||||
},
|
},
|
||||||
[&collider](SHVec3 const& vec)
|
[&collider](SHVec3 const& vec)
|
||||||
{
|
{
|
||||||
const SHVec3 vecInRad
|
collider->SetRotationOffset(vec);
|
||||||
{
|
}, true);
|
||||||
SHMath::DegreesToRadians(vec.x)
|
|
||||||
, SHMath::DegreesToRadians(vec.y)
|
|
||||||
, SHMath::DegreesToRadians(vec.z)
|
|
||||||
};
|
|
||||||
collider->SetRotationOffset(vecInRad);
|
|
||||||
});
|
|
||||||
SHEditorWidgets::EndPanel();
|
SHEditorWidgets::EndPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,14 +166,14 @@ namespace SHADE
|
||||||
const ImGuiWindow* const window = ImGui::GetCurrentWindow();
|
const ImGuiWindow* const window = ImGui::GetCurrentWindow();
|
||||||
if (window->SkipItems)
|
if (window->SkipItems)
|
||||||
return false;
|
return false;
|
||||||
|
static constexpr float defaultLabelColWidth = 80.0f;
|
||||||
const ImGuiContext& g = *GImGui;
|
const ImGuiContext& g = *GImGui;
|
||||||
bool valueChanged = false;
|
bool valueChanged = false;
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
ImGui::PushID(label.c_str());
|
ImGui::PushID(label.c_str());
|
||||||
PushMultiItemsWidthsAndLabels(componentLabels, 0.0f);
|
PushMultiItemsWidthsAndLabels(componentLabels, 0.0f);
|
||||||
ImGui::BeginColumns("DragVecCol", 2, ImGuiOldColumnFlags_NoBorder | ImGuiOldColumnFlags_NoResize);
|
ImGui::BeginColumns("DragVecCol", 2, ImGuiOldColumnFlags_NoBorder | ImGuiOldColumnFlags_NoResize);
|
||||||
ImGui::SetColumnWidth(-1, 80.0f);
|
ImGui::SetColumnWidth(-1, defaultLabelColWidth);
|
||||||
ImGui::Text(label.c_str());
|
ImGui::Text(label.c_str());
|
||||||
if (isHovered)
|
if (isHovered)
|
||||||
*isHovered |= ImGui::IsItemHovered();
|
*isHovered |= ImGui::IsItemHovered();
|
||||||
|
@ -219,7 +219,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
bool const changed = DragN<float, 2>(label, componentLabels, { &values.x, &values.y }, speed, displayFormat, valueMin, valueMax, flags);
|
bool const changed = DragN<float, 2>(label, componentLabels, { &values.x, &values.y }, speed, displayFormat, valueMin, valueMax, flags);
|
||||||
static bool startRecording = false;
|
static bool startRecording = false;
|
||||||
if (changed)
|
if (!(flags & ImGuiSliderFlags_ReadOnly) && changed)
|
||||||
{
|
{
|
||||||
if(isAnAngleInRad)
|
if(isAnAngleInRad)
|
||||||
{
|
{
|
||||||
|
@ -255,7 +255,7 @@ namespace SHADE
|
||||||
bool isHovered = false;
|
bool isHovered = false;
|
||||||
bool const changed = DragN<float, 3>(label, componentLabels, { &values.x, &values.y, &values.z }, speed, displayFormat, valueMin, valueMax, flags, &isHovered);
|
bool const changed = DragN<float, 3>(label, componentLabels, { &values.x, &values.y, &values.z }, speed, displayFormat, valueMin, valueMax, flags, &isHovered);
|
||||||
static bool startRecording = false;
|
static bool startRecording = false;
|
||||||
if (changed)
|
if (!(flags & ImGuiSliderFlags_ReadOnly) && changed)
|
||||||
{
|
{
|
||||||
SHVec3 old = get();
|
SHVec3 old = get();
|
||||||
if(isAnAngleInRad)
|
if(isAnAngleInRad)
|
||||||
|
@ -293,7 +293,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
bool const changed = DragN<float, 4>(label, componentLabels, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags);
|
bool const changed = DragN<float, 4>(label, componentLabels, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags);
|
||||||
static bool startRecording = false;
|
static bool startRecording = false;
|
||||||
if (changed)
|
if (!(flags & ImGuiSliderFlags_ReadOnly) && changed)
|
||||||
{
|
{
|
||||||
if(isAnAngleInRad)
|
if(isAnAngleInRad)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue