From 77cccd63be66d2e0991c29f5c3d1c0751bc06ff1 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 23 Sep 2022 16:41:44 +0800 Subject: [PATCH] Renderables now use TransformComponent's matrix --- SHADE_Application/src/Scenes/SBTestScene.cpp | 10 ++------ .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 24 +++++++++++++++++-- .../MiddleEnd/Interface/SHRenderable.cpp | 1 - .../MiddleEnd/Interface/SHRenderable.h | 1 - 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index c642aa67..1c4af3a7 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -45,11 +45,7 @@ namespace Sandbox renderable.Mesh = CUBE_MESH; renderable.SetMaterial(matInst); - // Create transform - auto& transform = *SHADE::SHComponentManager::GetComponent_s(testObj); - transform.SetLocalPosition(SHVec3{ 0.0f, 0.0f, 2.0f }); - renderable.TransformMatrix = SHMatrix::Translate(0.0f, 0.0f, 2.0f); SHADE::SHScriptEngine* scriptEngine = static_cast(SHADE::SHSystemManager::GetSystem()); scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript"); } @@ -58,11 +54,9 @@ namespace Sandbox { static float rotation = 0.0f; - auto& renderable = *SHADE::SHComponentManager::GetComponent_s(testObj); - SHTransform tf; - tf.rotation = SHVec3(rotation, 0.0f, 0.0f); - renderable.TransformMatrix = tf.ComputeTRS(); + auto& transform = *SHADE::SHComponentManager::GetComponent_s(testObj); + transform.SetLocalRotation(rotation, 0.0f, 0.0f); rotation += dt * 10.0f; // Destroy entity if space is pressed diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 1ac783e0..9d496821 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -22,6 +22,8 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Pipeline/SHVkPipeline.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" +#include "ECS_Base/Managers/SHComponentManager.h" +#include "Math/Transform/SHTransformComponent.h" namespace SHADE { @@ -115,7 +117,16 @@ namespace SHADE for (const SHRenderable* renderable : subBatch.Renderables) { // Transform - transformData.emplace_back(renderable->TransformMatrix); + auto transform = SHComponentManager::GetComponent_s(renderable->GetEID()); + if (!transform) + { + SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!"); + transformData.emplace_back(); + } + else + { + transformData.emplace_back(transform->GetTRS()); + } } // Transfer to GPU @@ -190,7 +201,16 @@ namespace SHADE for (const SHRenderable* renderable : subBatch.Renderables) { // Transform - transformData.emplace_back(renderable->TransformMatrix); + auto transform = SHComponentManager::GetComponent_s(renderable->GetEID()); + if (!transform) + { + SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!"); + transformData.emplace_back(); + } + else + { + transformData.emplace_back(transform->GetTRS()); + } // Material Properties if (!EMPTY_MAT_PROPS) { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index 32a6a99a..5199565c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -92,5 +92,4 @@ namespace SHADE materialChanged = false; oldMaterial = {}; } - } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h index 0d48b5cb..3bb7cfda 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h @@ -66,7 +66,6 @@ namespace SHADE /* Data Members */ /*-------------------------------------------------------------------------------*/ Handle Mesh; - SHMatrix TransformMatrix; // TODO: Replace with Transform component private: /*-------------------------------------------------------------------------------*/