Reflect transform component

This commit is contained in:
Sri Sham Haran 2022-09-26 15:53:54 +08:00
parent 247930ea68
commit 2c16eb4393
4 changed files with 33 additions and 22 deletions

View File

@ -33,7 +33,8 @@ project "SHADE_Application"
"%{IncludeDir.spdlog}/include", "%{IncludeDir.spdlog}/include",
"%{IncludeDir.VULKAN}/include", "%{IncludeDir.VULKAN}/include",
"%{IncludeDir.VMA}/include", "%{IncludeDir.VMA}/include",
"%{IncludeDir.VULKAN}/Source/SPIRV-Reflect" "%{IncludeDir.VULKAN}/Source/SPIRV-Reflect",
"%{IncludeDir.RTTR}/include"
} }
externalwarnings "Off" externalwarnings "Off"

View File

@ -182,3 +182,14 @@ namespace SHADE
} }
} // namespace SHADE } // namespace SHADE
RTTR_REGISTRATION
{
using namespace SHADE;
using namespace rttr;
registration::class_<SHTransformComponent>("Transform Component")
.property("Translate", &SHTransformComponent::GetLocalPosition, &SHTransformComponent::SetLocalPosition)
.property("Rotate", &SHTransformComponent::GetLocalRotation, select_overload<void(SHVec3 const&)>(&SHTransformComponent::SetLocalRotation))
.property("Scale", &SHTransformComponent::GetLocalScale, &SHTransformComponent::SetLocalScale);
}

View File

@ -12,6 +12,7 @@
#include <queue> #include <queue>
#include <rttr/registration>
// Project Headers // Project Headers
#include "SH_API.h" #include "SH_API.h"
#include "ECS_Base/Components/SHComponent.h" #include "ECS_Base/Components/SHComponent.h"
@ -116,6 +117,8 @@ namespace SHADE
SHTransform world; SHTransform world;
UpdateQueue updateQueue; UpdateQueue updateQueue;
RTTR_ENABLE()
}; };

View File

@ -66,15 +66,9 @@ namespace SHADE
for (const auto* child : node->GetChildren()) for (const auto* child : node->GetChildren())
{ {
auto* childTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(child->GetEntityID());
if (childTransform)
{
const bool HAS_TRANSFORM = SHComponentManager::HasComponent<SHTransformComponent>(child->GetEntityID());
if (!HAS_TRANSFORM)
continue;
auto* childTransform = SHComponentManager::GetComponent<SHTransformComponent>(child->GetEntityID());
// Only update if node in hierarchy and component are both active // Only update if node in hierarchy and component are both active
const bool IS_NODE_ACTIVE = child->IsActive(); const bool IS_NODE_ACTIVE = child->IsActive();
if (IS_NODE_ACTIVE && childTransform->isActive) if (IS_NODE_ACTIVE && childTransform->isActive)
@ -82,10 +76,12 @@ namespace SHADE
if (childTransform->dirty || HAS_PARENT_CHANGED) if (childTransform->dirty || HAS_PARENT_CHANGED)
UpdateTransform(*childTransform, NODE_TRANSFORM); UpdateTransform(*childTransform, NODE_TRANSFORM);
} }
}
UpdateEntity(child); UpdateEntity(child);
// Clear dirty flag after all children are updated // Clear dirty flag after all children are updated
if (childTransform)
childTransform->dirty = false; childTransform->dirty = false;
} }
} }
@ -144,8 +140,8 @@ namespace SHADE
tf.world.ComputeTRS(); tf.world.ComputeTRS();
// Transpose TRS to column major // Transpose TRS to column major
tf.local.trs.Transpose(); //tf.local.trs.Transpose();
tf.world.trs.Transpose(); //tf.world.trs.Transpose();
} }
} // namespace SHADE } // namespace SHADE