diff --git a/SDK/include/NDK/Components/GraphicsComponent.hpp b/SDK/include/NDK/Components/GraphicsComponent.hpp index 177dbbb1f..cd2900d7f 100644 --- a/SDK/include/NDK/Components/GraphicsComponent.hpp +++ b/SDK/include/NDK/Components/GraphicsComponent.hpp @@ -57,6 +57,8 @@ namespace Ndk inline std::size_t GetAttachedRenderableCount() const; inline const Nz::BoundingVolumef& GetBoundingVolume(std::size_t renderableIndex) const; + inline const Nz::Matrix4f& GetLocalMatrix(std::size_t renderableIndex) const; + inline const Nz::Matrix4f& GetTransformMatrix(std::size_t renderableIndex) const; inline void RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const; diff --git a/SDK/include/NDK/Components/GraphicsComponent.inl b/SDK/include/NDK/Components/GraphicsComponent.inl index 127be42f5..71adf64d4 100644 --- a/SDK/include/NDK/Components/GraphicsComponent.inl +++ b/SDK/include/NDK/Components/GraphicsComponent.inl @@ -176,6 +176,20 @@ namespace Ndk return m_renderables[renderableIndex].boundingVolume; } + inline const Nz::Matrix4f& GraphicsComponent::GetLocalMatrix(std::size_t renderableIndex) const + { + assert(renderableIndex < m_renderables.size()); + return m_renderables[renderableIndex].data.localMatrix; + } + + inline const Nz::Matrix4f& GraphicsComponent::GetTransformMatrix(std::size_t renderableIndex) const + { + EnsureBoundingVolumesUpdate(); + + assert(renderableIndex < m_renderables.size()); + return m_renderables[renderableIndex].data.transformMatrix; + } + /*! * \brief Calls a function for every renderable attached to this component * diff --git a/SDK/src/NDK/Systems/DebugSystem.cpp b/SDK/src/NDK/Systems/DebugSystem.cpp index 407267fcd..2354a799a 100644 --- a/SDK/src/NDK/Systems/DebugSystem.cpp +++ b/SDK/src/NDK/Systems/DebugSystem.cpp @@ -39,7 +39,9 @@ namespace Ndk void MakeBoundingVolume() const override { - m_boundingVolume.MakeNull(); + // We generate an infinite bounding volume so that we're always considered for rendering when culling does occurs + // (bounding volume culling happens only if GraphicsComponent AABB partially fail) + m_boundingVolume.MakeInfinite(); } protected: @@ -71,7 +73,9 @@ namespace Ndk renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), transformMatrix, scissorRect); }; + // Maybe we should draw the global AABB (using another color) //DrawBox(entityGfx.GetAABB()); + for (std::size_t i = 0; i < entityGfx.GetAttachedRenderableCount(); ++i) { const Nz::BoundingVolumef& boundingVolume = entityGfx.GetBoundingVolume(i); @@ -95,19 +99,25 @@ namespace Ndk { NazaraAssert(m_entityOwner, "DebugRenderable has no owner"); - // TODO - /*const DebugComponent& entityDebug = m_entityOwner->GetComponent(); + const DebugComponent& entityDebug = m_entityOwner->GetComponent(); const GraphicsComponent& entityGfx = m_entityOwner->GetComponent(); - Nz::Boxf obb = entityGfx.GetAABB().obb.localBox; + auto DrawBox = [&](const Nz::Boxf& box, const Nz::Matrix4f& transformMatrix) + { + Nz::Matrix4f boxMatrix = Nz::Matrix4f::Identity(); + boxMatrix.SetScale(box.GetLengths()); + boxMatrix.SetTranslation(box.GetCenter()); + boxMatrix.ConcatenateAffine(transformMatrix); - Nz::Matrix4f transformMatrix = instanceData.transformMatrix; - Nz::Vector3f obbCenter = transformMatrix.Transform(obb.GetCenter(), 0.f); //< Apply rotation/scale to obb center, to display it at a correct position + renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), boxMatrix, scissorRect); + }; - transformMatrix.ApplyScale(obb.GetLengths()); - transformMatrix.ApplyTranslation(obbCenter); - - renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), transformMatrix, scissorRect);*/ + for (std::size_t i = 0; i < entityGfx.GetAttachedRenderableCount(); ++i) + { + const Nz::BoundingVolumef& boundingVolume = entityGfx.GetBoundingVolume(i); + if (boundingVolume.IsFinite()) + DrawBox(boundingVolume.obb.localBox, entityGfx.GetTransformMatrix(i)); + } } std::unique_ptr Clone() const override