Sdk/GraphicsComponent: Remake bounding volume handling

GraphicsComponent now only have an AABB but their instanced renderable now have individual BoundingVolume
This commit is contained in:
Jérôme Leclercq
2018-08-31 17:32:48 +02:00
parent 7bb6c84752
commit e42ff5b18a
6 changed files with 118 additions and 100 deletions

View File

@@ -60,12 +60,12 @@ namespace Ndk
for (std::size_t i = 0; i < materialCount; ++i)
RegisterMaterial(entry.renderable->GetMaterial(i));
InvalidateBoundingVolume();
InvalidateAABB();
}
void GraphicsComponent::ConnectInstancedRenderableSignals(Renderable& entry)
{
entry.renderableBoundingVolumeInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateBoundingVolume, [this](const Nz::InstancedRenderable*) { InvalidateBoundingVolume(); });
entry.renderableBoundingVolumeInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateBoundingVolume, [this](const Nz::InstancedRenderable*) { InvalidateAABB(); });
entry.renderableDataInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size() - 1));
entry.renderableMaterialInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateMaterial, this, &GraphicsComponent::InvalidateRenderableMaterial);
entry.renderableReleaseSlot.Connect(entry.renderable->OnInstancedRenderableRelease, this, &GraphicsComponent::Detach);
@@ -82,7 +82,7 @@ namespace Ndk
r.dataUpdated = false;
r.renderable->InvalidateData(&r.data, flags);
for (VolumeCullingEntry& entry : m_volumeCullingEntries)
for (CullingBoxEntry& entry : m_cullingBoxEntries)
entry.listEntry.ForceInvalidation();
}
@@ -234,10 +234,10 @@ namespace Ndk
NazaraUnused(node);
// Our view matrix depends on NodeComponent position/rotation
InvalidateBoundingVolume();
InvalidateAABB();
InvalidateTransformMatrix();
for (VolumeCullingEntry& entry : m_volumeCullingEntries)
for (CullingBoxEntry& entry : m_cullingBoxEntries)
entry.listEntry.ForceInvalidation(); //< Force invalidation on movement
}
@@ -263,36 +263,32 @@ namespace Ndk
* \brief Updates the bounding volume
*/
void GraphicsComponent::UpdateBoundingVolume() const
void GraphicsComponent::UpdateBoundingVolumes() const
{
EnsureTransformMatrixUpdate();
m_boundingVolume.MakeNull();
for (const Renderable& r : m_renderables)
{
Nz::BoundingVolumef boundingVolume = r.renderable->GetBoundingVolume();
// Adjust renderable bounding volume by local matrix
if (boundingVolume.IsFinite())
{
Nz::Boxf localBox = boundingVolume.obb.localBox;
Nz::Vector3f newPos = r.data.localMatrix * localBox.GetPosition();
Nz::Vector3f newCorner = r.data.localMatrix * (localBox.GetPosition() + localBox.GetLengths());
Nz::Vector3f newLengths = newCorner - newPos;
boundingVolume.Set(Nz::Boxf(newPos.x, newPos.y, newPos.z, newLengths.x, newLengths.y, newLengths.z));
}
m_boundingVolume.ExtendTo(boundingVolume);
}
RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem<RenderSystem>();
m_boundingVolume.Update(Nz::Matrix4f::ConcatenateAffine(renderSystem.GetCoordinateSystemMatrix(), m_transformMatrix));
m_boundingVolumeUpdated = true;
m_aabb.MakeZero();
for (std::size_t i = 0; i < m_renderables.size(); ++i)
{
const Renderable& r = m_renderables[i];
r.boundingVolume = r.renderable->GetBoundingVolume();
if (r.boundingVolume.IsFinite())
{
r.boundingVolume.Update(Nz::Matrix4f::ConcatenateAffine(renderSystem.GetCoordinateSystemMatrix(), Nz::Matrix4f::ConcatenateAffine(r.data.localMatrix, m_transformMatrix)));
for (VolumeCullingEntry& entry : m_volumeCullingEntries)
entry.listEntry.UpdateVolume(m_boundingVolume);
if (i > 0)
m_aabb.ExtendTo(r.boundingVolume.aabb);
else
m_aabb.Set(r.boundingVolume.aabb);
}
}
m_boundingVolumesUpdated = true;
for (CullingBoxEntry& entry : m_cullingBoxEntries)
entry.listEntry.UpdateBox(m_aabb);
}
/*!