Added scripting quality of life features #299
|
@ -0,0 +1,67 @@
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHColliderTagPanel.h"
|
||||||
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
|
#include "Physics/Collision/SHCollisionTagMatrix.h"
|
||||||
|
#include "Editor/SHEditorWidgets.hpp"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
|
||||||
|
void SHColliderTagPanel::Update()
|
||||||
|
{
|
||||||
|
if (Begin())
|
||||||
|
{
|
||||||
|
ImGui::BeginTable("CollisionMtxTable", SHCollisionTag::NUM_LAYERS + 1, ImGuiTableRowFlags_Headers);
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
ImGui::PushID("CollisionTagNames");
|
||||||
|
|
||||||
|
for (int i = SHCollisionTag::NUM_LAYERS; i >= 0; --i)
|
||||||
|
{
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
if(i == SHCollisionTag::NUM_LAYERS) continue;
|
||||||
|
std::string const& tagName = SHCollisionTagMatrix::GetTagName(i);
|
||||||
|
auto tag = SHCollisionTagMatrix::GetTag(i);
|
||||||
|
if (!tag)
|
||||||
|
continue;
|
||||||
|
//ImGui::Text(tagName.data());
|
||||||
|
ImGui::PushID(i);
|
||||||
|
SHEditorWidgets::InputText("##", [i]{return SHCollisionTagMatrix::GetTagName(i);}, [i](std::string const& value){SHCollisionTagMatrix::GetTag(i)->SetName(value);}, tagName.data(), ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
ImGui::PopID();
|
||||||
|
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i)
|
||||||
|
{
|
||||||
|
std::string tagName = SHCollisionTagMatrix::GetTagName(i);
|
||||||
|
auto tag = SHCollisionTagMatrix::GetTag(i);
|
||||||
|
if(!tag)
|
||||||
|
continue;
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text(tagName.data());
|
||||||
|
for (int j = (SHCollisionTag::NUM_LAYERS) - 1; j >= i; --j)
|
||||||
|
{
|
||||||
|
int idx = j;
|
||||||
|
std::string tagName2 = SHCollisionTagMatrix::GetTagName(idx);
|
||||||
|
auto tag2 = SHCollisionTagMatrix::GetTag(idx);
|
||||||
|
|
||||||
|
if(!tag2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(tagName.empty())
|
||||||
|
tagName = std::to_string(i);
|
||||||
|
if(tagName2.empty())
|
||||||
|
tagName2 = std::to_string(idx);
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
//if(i == idx)
|
||||||
|
// continue;
|
||||||
|
std::string label = std::format("##{} vs {}", tagName, tagName2);
|
||||||
|
SHEditorWidgets::CheckBox(label, [tag, &idx]{return tag->GetLayerState(idx);}, [tag, i, idx](bool const& value){tag->SetLayerState(idx, value); SHCollisionTagMatrix::GetTag(idx)->SetLayerState(i, value);}, label.substr(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndTable();
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Editor/EditorWindow/SHEditorWindow.h"
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
class SH_API SHColliderTagPanel final : public SHEditorWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SHColliderTagPanel():SHEditorWindow("Collider Tag Panel", ImGuiWindowFlags_MenuBar), isDirty(false){}
|
||||||
|
//void Init();
|
||||||
|
void Update() override;
|
||||||
|
//void Exit();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isDirty;
|
||||||
|
};
|
||||||
|
}
|
|
@ -18,7 +18,7 @@
|
||||||
#include "Physics/Interface/SHColliderComponent.h"
|
#include "Physics/Interface/SHColliderComponent.h"
|
||||||
#include "Reflection/SHReflectionMetadata.h"
|
#include "Reflection/SHReflectionMetadata.h"
|
||||||
#include "Resource/SHResourceManager.h"
|
#include "Resource/SHResourceManager.h"
|
||||||
|
#include "Physics/Collision/SHCollisionTagMatrix.h"
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -314,6 +314,12 @@ namespace SHADE
|
||||||
if (!component)
|
if (!component)
|
||||||
return;
|
return;
|
||||||
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHColliderComponent>());
|
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHColliderComponent>());
|
||||||
|
std::vector<const char*> collisionTagNames(SHCollisionTag::NUM_LAYERS);
|
||||||
|
//Fetch tag names
|
||||||
|
for(int i{}; i < SHCollisionTag::NUM_LAYERS; ++i)
|
||||||
|
{
|
||||||
|
collisionTagNames[i] = SHCollisionTagMatrix::GetTagName(i).c_str();
|
||||||
|
}
|
||||||
|
|
||||||
const auto componentType = rttr::type::get(*component);
|
const auto componentType = rttr::type::get(*component);
|
||||||
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active");
|
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active");
|
||||||
|
@ -332,7 +338,7 @@ namespace SHADE
|
||||||
SHCollisionShape* collider = &component->GetCollisionShape(i);
|
SHCollisionShape* collider = &component->GetCollisionShape(i);
|
||||||
auto cursorPos = ImGui::GetCursorPos();
|
auto cursorPos = ImGui::GetCursorPos();
|
||||||
|
|
||||||
//collider->IsTrigger
|
|
||||||
if (collider->GetType() == SHCollisionShape::Type::BOX)
|
if (collider->GetType() == SHCollisionShape::Type::BOX)
|
||||||
{
|
{
|
||||||
SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
|
SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
|
||||||
|
@ -361,7 +367,7 @@ namespace SHADE
|
||||||
|
|
||||||
{
|
{
|
||||||
SHEditorWidgets::CheckBox("Is Trigger", [collider] { return collider->IsTrigger(); }, [collider](bool value) { collider->SetIsTrigger(value); });
|
SHEditorWidgets::CheckBox("Is Trigger", [collider] { return collider->IsTrigger(); }, [collider](bool value) { collider->SetIsTrigger(value); });
|
||||||
|
SHEditorWidgets::ComboBox("Tag", collisionTagNames, [collider]{return SHCollisionTagMatrix::GetTagIndex(collider->GetCollisionTag().GetName());}, [collider](int const& value){collider->SetCollisionTag(SHCollisionTagMatrix::GetTag(value));});
|
||||||
if(ImGui::CollapsingHeader("Physics Material"))
|
if(ImGui::CollapsingHeader("Physics Material"))
|
||||||
{
|
{
|
||||||
SHEditorWidgets::DragFloat("Friction", [collider] { return collider->GetFriction(); }, [collider](float value) { collider->SetFriction(value); }, "Friction", 0.05f, 0.0f, 1.0f);
|
SHEditorWidgets::DragFloat("Friction", [collider] { return collider->GetFriction(); }, [collider](float value) { collider->SetFriction(value); }, "Friction", 0.05f, 0.0f, 1.0f);
|
||||||
|
@ -388,6 +394,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
colliderToDelete = i;
|
colliderToDelete = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHEditorWidgets::EndPanel();
|
SHEditorWidgets::EndPanel();
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
@ -399,14 +406,26 @@ namespace SHADE
|
||||||
|
|
||||||
if (ImGui::BeginMenu("Add Collider"))
|
if (ImGui::BeginMenu("Add Collider"))
|
||||||
{
|
{
|
||||||
|
int newColl = -1;
|
||||||
|
|
||||||
if (ImGui::Selectable("Box Collider"))
|
if (ImGui::Selectable("Box Collider"))
|
||||||
{
|
{
|
||||||
component->AddBoundingBox();
|
newColl = component->AddBoundingBox();
|
||||||
}
|
}
|
||||||
if (ImGui::Selectable("Sphere Collider"))
|
if (ImGui::Selectable("Sphere Collider"))
|
||||||
{
|
{
|
||||||
component->AddBoundingSphere();
|
newColl = component->AddBoundingSphere();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//No idea why this doesn't work
|
||||||
|
//if (newColl > 0)
|
||||||
|
//{
|
||||||
|
// auto newCollisionShape = component->GetCollisionShape(newColl);
|
||||||
|
// auto prevCollisionShapeInSeq = component->GetCollisionShape(newColl - 1);
|
||||||
|
// newCollisionShape.SetCollisionTag(SHCollisionTagMatrix::GetTag(prevCollisionShapeInSeq.GetCollisionTag().GetName()));
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,5 @@
|
||||||
#include "Profiling/SHEditorProfiler.h" //Profiler
|
#include "Profiling/SHEditorProfiler.h" //Profiler
|
||||||
#include "ViewportWindow/SHEditorViewport.h" //Editor Viewport
|
#include "ViewportWindow/SHEditorViewport.h" //Editor Viewport
|
||||||
#include "AssetBrowser/SHAssetBrowser.h" //Asset Browser
|
#include "AssetBrowser/SHAssetBrowser.h" //Asset Browser
|
||||||
#include "MaterialInspector/SHMaterialInspector.h" //Material Inspector
|
#include "MaterialInspector/SHMaterialInspector.h" //Material Inspector
|
||||||
|
#include "ColliderTagPanel/SHColliderTagPanel.h" //Collider Tag Panel
|
|
@ -101,6 +101,7 @@ namespace SHADE
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHEditorProfiler>();
|
SHEditorWindowManager::CreateEditorWindow<SHEditorProfiler>();
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHAssetBrowser>();
|
SHEditorWindowManager::CreateEditorWindow<SHAssetBrowser>();
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHMaterialInspector>();
|
SHEditorWindowManager::CreateEditorWindow<SHMaterialInspector>();
|
||||||
|
SHEditorWindowManager::CreateEditorWindow<SHColliderTagPanel>();
|
||||||
|
|
||||||
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
|
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
|
||||||
|
|
||||||
|
|
|
@ -443,4 +443,16 @@ namespace SHADE
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHQuaternion SHQuaternion::FromWXYZ(float w, float x, float y, float z) noexcept
|
||||||
|
{
|
||||||
|
return SHQuaternion{ x, y, z, w };
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHQuaternion::ToWXYZ(const SHQuaternion& from, float& w, float& x, float& y, float& z) noexcept
|
||||||
|
{
|
||||||
|
x = from.x;
|
||||||
|
y = from.y;
|
||||||
|
z = from.z;
|
||||||
|
w = from.w;
|
||||||
|
}
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
|
@ -125,9 +125,12 @@ namespace SHADE
|
||||||
[[nodiscard]] static SHQuaternion ClampedLerp (const SHQuaternion& q1, const SHQuaternion& q2, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept;
|
[[nodiscard]] static SHQuaternion ClampedLerp (const SHQuaternion& q1, const SHQuaternion& q2, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept;
|
||||||
[[nodiscard]] static SHQuaternion ClampedSlerp (const SHQuaternion& q1, const SHQuaternion& q2, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept;
|
[[nodiscard]] static SHQuaternion ClampedSlerp (const SHQuaternion& q1, const SHQuaternion& q2, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept;
|
||||||
|
|
||||||
[[nodiscard]] static SHQuaternion FromToRotation (const SHVec3& from, const SHVec3& to) noexcept;
|
[[nodiscard]] static SHQuaternion FromToRotation (const SHVec3& from, const SHVec3& to) noexcept;
|
||||||
[[nodiscard]] static SHQuaternion LookRotation (const SHVec3& forward, const SHVec3& up) noexcept;
|
[[nodiscard]] static SHQuaternion LookRotation (const SHVec3& forward, const SHVec3& up) noexcept;
|
||||||
[[nodiscard]] static SHQuaternion RotateTowards (const SHQuaternion& from, const SHQuaternion& to, float maxAngleInRad) noexcept;
|
[[nodiscard]] static SHQuaternion RotateTowards (const SHQuaternion& from, const SHQuaternion& to, float maxAngleInRad) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]] static SHQuaternion FromWXYZ (float w, float x, float y, float z) noexcept;
|
||||||
|
static void ToWXYZ (const SHQuaternion& from, float& w, float& x, float& y, float& z) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
SHQuaternion operator*(float lhs, const SHQuaternion& rhs) noexcept;
|
SHQuaternion operator*(float lhs, const SHQuaternion& rhs) noexcept;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "Physics/Interface/SHColliderComponent.h"
|
#include "Physics/Interface/SHColliderComponent.h"
|
||||||
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
|
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
|
||||||
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
|
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
|
||||||
|
#include "Physics/Collision/SHCollisionTagMatrix.h"
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
|
@ -117,13 +118,14 @@ namespace YAML
|
||||||
static constexpr const char* Density = "Density";
|
static constexpr const char* Density = "Density";
|
||||||
static constexpr const char* PositionOffset = "Position Offset";
|
static constexpr const char* PositionOffset = "Position Offset";
|
||||||
static constexpr const char* RotationOffset = "Rotation Offset";
|
static constexpr const char* RotationOffset = "Rotation Offset";
|
||||||
|
static constexpr const char* CollisionTag = "Collision Tag";
|
||||||
|
|
||||||
static Node encode(SHCollisionShape& rhs)
|
static Node encode(SHCollisionShape& rhs)
|
||||||
{
|
{
|
||||||
Node node;
|
Node node;
|
||||||
|
|
||||||
node[IsTrigger] = rhs.IsTrigger();
|
node[IsTrigger] = rhs.IsTrigger();
|
||||||
|
node[CollisionTag] = rhs.GetCollisionTag().GetName();
|
||||||
rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
|
rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
|
||||||
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
|
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
|
||||||
SHCollisionShape::Type colliderType = rhs.GetType();
|
SHCollisionShape::Type colliderType = rhs.GetType();
|
||||||
|
@ -160,6 +162,10 @@ namespace YAML
|
||||||
{
|
{
|
||||||
if (node[IsTrigger].IsDefined())
|
if (node[IsTrigger].IsDefined())
|
||||||
rhs.SetIsTrigger(node[IsTrigger].as<bool>());
|
rhs.SetIsTrigger(node[IsTrigger].as<bool>());
|
||||||
|
|
||||||
|
if(node[CollisionTag].IsDefined())
|
||||||
|
rhs.SetCollisionTag(SHCollisionTagMatrix::GetTag(node[CollisionTag].as<std::string>()));
|
||||||
|
|
||||||
if (!node[Type].IsDefined())
|
if (!node[Type].IsDefined())
|
||||||
return false;
|
return false;
|
||||||
rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
|
rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
|
||||||
|
|
Loading…
Reference in New Issue