Light Component Serialization & Inspector
This commit is contained in:
parent
f110f9b16b
commit
fa6e3cf1df
|
@ -1,62 +0,0 @@
|
|||
[Window][MainStatusBar]
|
||||
Pos=0,1060
|
||||
Size=1920,20
|
||||
Collapsed=0
|
||||
|
||||
[Window][SHEditorMenuBar]
|
||||
Pos=0,48
|
||||
Size=1920,1012
|
||||
Collapsed=0
|
||||
|
||||
[Window][Hierarchy Panel]
|
||||
Pos=0,142
|
||||
Size=382,690
|
||||
Collapsed=0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Window][Debug##Default]
|
||||
Pos=60,60
|
||||
Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][Inspector]
|
||||
Pos=1588,48
|
||||
Size=332,1012
|
||||
Collapsed=0
|
||||
DockId=0x00000006,0
|
||||
|
||||
[Window][Profiler]
|
||||
Pos=0,48
|
||||
Size=382,92
|
||||
Collapsed=0
|
||||
DockId=0x00000003,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=648,48
|
||||
Size=2519,1319
|
||||
Collapsed=0
|
||||
DockId=0x00000002,0
|
||||
|
||||
[Window][ Viewport]
|
||||
Pos=384,48
|
||||
Size=1202,1012
|
||||
Collapsed=0
|
||||
DockId=0x00000002,0
|
||||
|
||||
[Window][ Asset Browser]
|
||||
Pos=0,834
|
||||
Size=382,226
|
||||
Collapsed=0
|
||||
DockId=0x00000008,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X
|
||||
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1586,1036 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=382,1036 Split=Y Selected=0x1E6EB881
|
||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881
|
||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,940 Split=Y Selected=0xE096E5AE
|
||||
DockNode ID=0x00000007 Parent=0x00000004 SizeRef=494,690 Selected=0xE096E5AE
|
||||
DockNode ID=0x00000008 Parent=0x00000004 SizeRef=494,226 Selected=0xB128252A
|
||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1202,1036 CentralNode=1 Selected=0xB41284E7
|
||||
DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=332,1036 Selected=0xE7039252
|
||||
|
|
@ -13,10 +13,24 @@
|
|||
#include "Editor/IconsFontAwesome6.h"
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "Editor/SHEditorWidgets.hpp"
|
||||
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
|
||||
#include "Physics/Components/SHColliderComponent.h"
|
||||
#include "Reflection/SHReflectionMetadata.h"
|
||||
namespace SHADE
|
||||
{
|
||||
template<typename T>
|
||||
std::vector<const char*> GetRTTREnumNames()
|
||||
{
|
||||
auto const rttrType = rttr::type::get<T>();
|
||||
if(!rttrType.is_enumeration())
|
||||
return {};
|
||||
auto const enumAlign = rttrType.get_enumeration();
|
||||
auto const names = enumAlign.get_names();
|
||||
std::vector<const char*> result;
|
||||
std::transform(names.begin(), names.end(), std::back_inserter(result), [](rttr::string_view const& name){return name.data();});
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, std::enable_if_t<std::is_base_of<SHComponent, T>::value, bool> = true>
|
||||
static void DrawContextMenu(T* component)
|
||||
{
|
||||
|
@ -273,4 +287,34 @@ namespace SHADE
|
|||
}
|
||||
else DrawContextMenu(component);
|
||||
}
|
||||
|
||||
template<>
|
||||
static void DrawComponent(SHLightComponent* component)
|
||||
{
|
||||
if (!component)
|
||||
return;
|
||||
const auto componentType = rttr::type::get(*component);
|
||||
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; });
|
||||
ImGui::SameLine();
|
||||
if (ImGui::CollapsingHeader(componentType.get_name().data()))
|
||||
{
|
||||
DrawContextMenu(component);
|
||||
|
||||
static auto const enumAlign = rttr::type::get<SH_LIGHT_TYPE>().get_enumeration();
|
||||
static std::vector<const char*> list(GetRTTREnumNames<SH_LIGHT_TYPE>());
|
||||
|
||||
SHEditorWidgets::ComboBox("Type", list, [component] {return static_cast<int>(component->GetType()); }, [component](int const& idx)
|
||||
{
|
||||
component->SetType(static_cast<SH_LIGHT_TYPE>(idx));
|
||||
});
|
||||
SHEditorWidgets::DragVec3("Position", {"X", "Y", "Z"}, [component](){return component->GetPosition();}, [component](SHVec3 const& vec){component->SetPosition(vec);});
|
||||
SHEditorWidgets::DragVec3("Direction", {"X", "Y", "Z"}, [component](){return component->GetDirection();}, [component](SHVec3 const& vec){component->SetDirection(vec);});
|
||||
SHEditorWidgets::ColorPicker("Color", [component](){return component->GetColor();}, [component](SHVec4 const& rgba){component->SetColor(rgba);});
|
||||
SHEditorWidgets::DragFloat("Strength", [component](){return component->GetStrength();}, [component](float const& value){component->SetStrength(value);});
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawContextMenu(component);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -82,6 +82,10 @@ namespace SHADE
|
|||
{
|
||||
DrawComponent(rigidbodyComponent);
|
||||
}
|
||||
if(auto lightComponent = SHComponentManager::GetComponent_s<SHLightComponent>(eid))
|
||||
{
|
||||
DrawComponent(lightComponent);
|
||||
}
|
||||
ImGui::Separator();
|
||||
// Render Scripts
|
||||
SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
||||
|
@ -92,6 +96,7 @@ namespace SHADE
|
|||
DrawAddComponentButton<SHTransformComponent>(eid);
|
||||
DrawAddComponentButton<SHRenderable>(eid);
|
||||
DrawAddComponentButton<SHColliderComponent>(eid);
|
||||
DrawAddComponentButton<SHLightComponent>(eid);
|
||||
if(DrawAddComponentButton<SHRigidBodyComponent>(eid))
|
||||
{
|
||||
if(SHComponentManager::GetComponent_s<SHTransformComponent>(eid) == nullptr)
|
||||
|
|
|
@ -192,8 +192,8 @@ namespace SHADE
|
|||
ImGuiColors::colors[i], 4);
|
||||
|
||||
ImGui::SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
ImGui::PopID();
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::EndColumns();
|
||||
ImGui::PopID();
|
||||
|
@ -615,5 +615,43 @@ namespace SHADE
|
|||
}
|
||||
return edited;
|
||||
}
|
||||
|
||||
static bool ColorPicker(const std::string_view& label, std::function<SHVec4(void)> get, std::function<void(SHVec4 const&)> set, std::string_view const& tooltip = {}, float speed = 0.1f, const char* displayFormat = "%.3f", float valueMin = 0.0f, float valueMax = 0.0f,
|
||||
ImGuiSliderFlags flags = 0)
|
||||
{
|
||||
bool changed = false;
|
||||
ImGui::BeginGroup();
|
||||
ImGui::PushID(label.data());
|
||||
|
||||
SHVec4 values = get();
|
||||
//changed |= DragN<float, 4>(label.data(), {"R", "G", "B", "A"}, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags);
|
||||
//ImGui::SameLine();
|
||||
TextLabel(label);
|
||||
changed = ImGui::ColorEdit4("##Col4", &values.x, ImGuiColorEditFlags_AlphaPreviewHalf | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_DisplayRGB );
|
||||
static bool startRecording = false;
|
||||
if(changed)
|
||||
{
|
||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<SHVec4>>(get(), values, set)), startRecording);
|
||||
if(!startRecording)
|
||||
startRecording = true;
|
||||
}
|
||||
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||
{
|
||||
startRecording = false;
|
||||
}
|
||||
ImGui::PopID();
|
||||
ImGui::EndGroup();
|
||||
if (!tooltip.empty())
|
||||
{
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text(tooltip.data());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
};
|
||||
|
||||
}//namespace SHADE
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace SHADE
|
|||
|
||||
}
|
||||
|
||||
void SHLightComponent::SetPosition(SHVec3 position) noexcept
|
||||
void SHLightComponent::SetPosition(SHVec3 const& position) noexcept
|
||||
{
|
||||
lightData.position = position;
|
||||
MakeDirty();
|
||||
|
@ -34,14 +34,14 @@ namespace SHADE
|
|||
}
|
||||
|
||||
|
||||
void SHLightComponent::SetDirection(SHVec3 direction) noexcept
|
||||
void SHLightComponent::SetDirection(SHVec3 const& direction) noexcept
|
||||
{
|
||||
lightData.direction = direction;
|
||||
MakeDirty();
|
||||
}
|
||||
|
||||
|
||||
void SHLightComponent::SetColor(SHVec4 color) noexcept
|
||||
void SHLightComponent::SetColor(SHVec4 const& color) noexcept
|
||||
{
|
||||
lightData.color = color;
|
||||
MakeDirty();
|
||||
|
@ -57,8 +57,7 @@ namespace SHADE
|
|||
MakeDirty();
|
||||
}
|
||||
|
||||
|
||||
void SHLightComponent::SetCullingMask(uint32_t value) noexcept
|
||||
void SHLightComponent::SetCullingMask(uint32_t const& value) noexcept
|
||||
{
|
||||
lightData.cullingMask = value;
|
||||
}
|
||||
|
@ -151,4 +150,32 @@ namespace SHADE
|
|||
return indexInBuffer;
|
||||
}
|
||||
|
||||
float SHLightComponent::GetStrength(void) const noexcept
|
||||
{
|
||||
return lightData.strength;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RTTR_REGISTRATION
|
||||
{
|
||||
using namespace SHADE;
|
||||
using namespace rttr;
|
||||
|
||||
registration::enumeration<SH_LIGHT_TYPE>("Light Type")
|
||||
(
|
||||
value("Directional", SH_LIGHT_TYPE::DIRECTIONAL),
|
||||
value("Point", SH_LIGHT_TYPE::POINT),
|
||||
value("Spot", SH_LIGHT_TYPE::SPOT),
|
||||
value("Ambient", SH_LIGHT_TYPE::AMBIENT)
|
||||
);
|
||||
|
||||
registration::class_<SHLightComponent>("Light Component")
|
||||
.property("Position", &SHLightComponent::GetPosition, &SHLightComponent::SetPosition)
|
||||
.property("Type", &SHLightComponent::GetType, &SHLightComponent::SetType)
|
||||
.property("Direction", &SHLightComponent::GetDirection, &SHLightComponent::SetDirection)
|
||||
.property("Color", &SHLightComponent::GetColor, &SHLightComponent::SetColor)
|
||||
.property("Layer", &SHLightComponent::GetCullingMask, &SHLightComponent::SetCullingMask)
|
||||
.property("Strength", &SHLightComponent::GetStrength, &SHLightComponent::SetStrength)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <rttr/registration>
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "SHLightData.h"
|
||||
|
||||
|
@ -35,12 +36,12 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* SETTERS AND GETTERS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void SetPosition (SHVec3 position) noexcept; // serialized
|
||||
void SetPosition (SHVec3 const& position) noexcept; // serialized
|
||||
void SetType (SH_LIGHT_TYPE type) noexcept; // serialized
|
||||
void SetDirection (SHVec3 direction) noexcept; // serialized
|
||||
void SetColor (SHVec4 color) noexcept; // serialized
|
||||
void SetDirection (SHVec3 const& direction) noexcept; // serialized
|
||||
void SetColor (SHVec4 const& color) noexcept; // serialized
|
||||
void ModifyCullingMask (uint8_t layerIndex, bool value) noexcept; // serialized
|
||||
void SetCullingMask (uint32_t value) noexcept;
|
||||
void SetCullingMask (uint32_t const& value) noexcept;
|
||||
void SetAllLayers (void) noexcept; // serialized
|
||||
void ClearAllLayers (void) noexcept; // serialized
|
||||
void MakeDirty (void) noexcept;
|
||||
|
@ -59,6 +60,7 @@ namespace SHADE
|
|||
bool IsDirty (void) const noexcept;
|
||||
bool GetBound (void) const noexcept;
|
||||
uint32_t GetIndexInBuffer (void) const noexcept;
|
||||
|
||||
float GetStrength (void) const noexcept;
|
||||
RTTR_ENABLE()
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Math/Transform/SHTransformComponent.h"
|
||||
#include "Physics/Components/SHRigidBodyComponent.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
|
||||
#include "Scripting/SHScriptEngine.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -192,6 +193,10 @@ namespace SHADE
|
|||
{
|
||||
components[rttr::type::get<SHRigidBodyComponent>().get_name().data()] = SHSerializationHelper::SerializeComponentToNode(rigidbody);
|
||||
}
|
||||
if(const auto light = SHComponentManager::GetComponent_s<SHLightComponent>(eid))
|
||||
{
|
||||
components[rttr::type::get<SHLightComponent>().get_name().data()] = SHSerializationHelper::SerializeComponentToNode(light);
|
||||
}
|
||||
node[ComponentsNode] = components;
|
||||
|
||||
YAML::Node scripts;
|
||||
|
@ -250,6 +255,10 @@ namespace SHADE
|
|||
if (id.has_value())
|
||||
componentIDList.push_back(id.value());
|
||||
|
||||
id = GetComponentID<SHLightComponent>(componentsNode);
|
||||
if(id.has_value())
|
||||
componentIDList.push_back(id.value());
|
||||
|
||||
return componentIDList;
|
||||
}
|
||||
|
||||
|
@ -259,5 +268,6 @@ namespace SHADE
|
|||
if (!componentsNode)
|
||||
return;
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHTransformComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,12 +188,12 @@ namespace SHADE
|
|||
return;
|
||||
auto rttrType = rttr::type::get<ComponentType>();
|
||||
auto componentNode = componentsNode[rttrType.get_name().data()];
|
||||
if (componentsNode.IsNull())
|
||||
if(!componentNode.IsDefined())
|
||||
return;
|
||||
auto properties = rttrType.get_properties();
|
||||
for (auto const& prop : properties)
|
||||
{
|
||||
if (componentNode[prop.get_name().data()])
|
||||
if (componentNode[prop.get_name().data()].IsDefined())
|
||||
{
|
||||
InitializeProperty<ComponentType>(component, prop, componentNode[prop.get_name().data()]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue