Merge branch 'master' into application
Former-commit-id: 02d073ae79490d0ac38e56c90bf7d8ff57ae94c4
This commit is contained in:
commit
12968c73fe
|
|
@ -26,11 +26,15 @@ namespace Ndk
|
||||||
|
|
||||||
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||||
|
|
||||||
|
inline void EnsureBoundingVolumeUpdate() const;
|
||||||
inline void EnsureTransformMatrixUpdate() const;
|
inline void EnsureTransformMatrixUpdate() const;
|
||||||
|
|
||||||
|
inline const Nz::BoundingVolumef& GetBoundingVolume() const;
|
||||||
|
|
||||||
static ComponentIndex componentIndex;
|
static ComponentIndex componentIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline void InvalidateBoundingVolume();
|
||||||
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index);
|
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index);
|
||||||
inline void InvalidateRenderables();
|
inline void InvalidateRenderables();
|
||||||
inline void InvalidateTransformMatrix();
|
inline void InvalidateTransformMatrix();
|
||||||
|
|
@ -41,6 +45,7 @@ namespace Ndk
|
||||||
void OnDetached() override;
|
void OnDetached() override;
|
||||||
void OnNodeInvalidated(const Nz::Node* node);
|
void OnNodeInvalidated(const Nz::Node* node);
|
||||||
|
|
||||||
|
void UpdateBoundingVolume() const;
|
||||||
void UpdateTransformMatrix() const;
|
void UpdateTransformMatrix() const;
|
||||||
|
|
||||||
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
||||||
|
|
@ -61,7 +66,9 @@ namespace Ndk
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<Renderable> m_renderables;
|
std::vector<Renderable> m_renderables;
|
||||||
|
mutable Nz::BoundingVolumef m_boundingVolume;
|
||||||
mutable Nz::Matrix4f m_transformMatrix;
|
mutable Nz::Matrix4f m_transformMatrix;
|
||||||
|
mutable bool m_boundingVolumeUpdated;
|
||||||
mutable bool m_transformMatrixUpdated;
|
mutable bool m_transformMatrixUpdated;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) :
|
inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) :
|
||||||
Component(graphicsComponent),
|
Component(graphicsComponent),
|
||||||
|
m_boundingVolume(graphicsComponent.m_boundingVolume),
|
||||||
m_transformMatrix(graphicsComponent.m_transformMatrix),
|
m_transformMatrix(graphicsComponent.m_transformMatrix),
|
||||||
|
m_boundingVolumeUpdated(graphicsComponent.m_boundingVolumeUpdated),
|
||||||
m_transformMatrixUpdated(graphicsComponent.m_transformMatrixUpdated)
|
m_transformMatrixUpdated(graphicsComponent.m_transformMatrixUpdated)
|
||||||
{
|
{
|
||||||
m_renderables.reserve(graphicsComponent.m_renderables.size());
|
m_renderables.reserve(graphicsComponent.m_renderables.size());
|
||||||
|
|
@ -39,6 +41,14 @@ namespace Ndk
|
||||||
r.data.renderOrder = renderOrder;
|
r.data.renderOrder = renderOrder;
|
||||||
r.renderable = std::move(renderable);
|
r.renderable = std::move(renderable);
|
||||||
r.renderableInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
|
r.renderableInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
|
||||||
|
|
||||||
|
InvalidateBoundingVolume();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void GraphicsComponent::EnsureBoundingVolumeUpdate() const
|
||||||
|
{
|
||||||
|
if (!m_boundingVolumeUpdated)
|
||||||
|
UpdateBoundingVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const
|
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const
|
||||||
|
|
@ -47,6 +57,18 @@ namespace Ndk
|
||||||
UpdateTransformMatrix();
|
UpdateTransformMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume() const
|
||||||
|
{
|
||||||
|
EnsureBoundingVolumeUpdate();
|
||||||
|
|
||||||
|
return m_boundingVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void GraphicsComponent::InvalidateBoundingVolume()
|
||||||
|
{
|
||||||
|
m_boundingVolumeUpdated = false;
|
||||||
|
}
|
||||||
|
|
||||||
inline void GraphicsComponent::InvalidateRenderables()
|
inline void GraphicsComponent::InvalidateRenderables()
|
||||||
{
|
{
|
||||||
for (Renderable& r : m_renderables)
|
for (Renderable& r : m_renderables)
|
||||||
|
|
@ -55,6 +77,7 @@ namespace Ndk
|
||||||
|
|
||||||
inline void GraphicsComponent::InvalidateTransformMatrix()
|
inline void GraphicsComponent::InvalidateTransformMatrix()
|
||||||
{
|
{
|
||||||
|
m_boundingVolumeUpdated = false;
|
||||||
m_transformMatrixUpdated = false;
|
m_transformMatrixUpdated = false;
|
||||||
|
|
||||||
InvalidateRenderables();
|
InvalidateRenderables();
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,18 @@ namespace Ndk
|
||||||
InvalidateTransformMatrix();
|
InvalidateTransformMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GraphicsComponent::UpdateBoundingVolume() const
|
||||||
|
{
|
||||||
|
EnsureTransformMatrixUpdate();
|
||||||
|
|
||||||
|
m_boundingVolume.MakeNull();
|
||||||
|
for (const Renderable& r : m_renderables)
|
||||||
|
m_boundingVolume.ExtendTo(r.renderable->GetBoundingVolume());
|
||||||
|
|
||||||
|
m_boundingVolume.Update(m_transformMatrix);
|
||||||
|
m_boundingVolumeUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
void GraphicsComponent::UpdateTransformMatrix() const
|
void GraphicsComponent::UpdateTransformMatrix() const
|
||||||
{
|
{
|
||||||
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "GraphicsComponent requires NodeComponent");
|
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "GraphicsComponent requires NodeComponent");
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ namespace Nz
|
||||||
* \remark Extending to a null bounding volume has no effect while extending to a infinite bounding volume will set it as infinite
|
* \remark Extending to a null bounding volume has no effect while extending to a infinite bounding volume will set it as infinite
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
BoundingVolume<T>& BoundingVolume<T>::BoundingVolume<T>::ExtendTo(const BoundingVolume& volume)
|
BoundingVolume<T>& BoundingVolume<T>::ExtendTo(const BoundingVolume& volume)
|
||||||
{
|
{
|
||||||
switch (extend)
|
switch (extend)
|
||||||
{
|
{
|
||||||
|
|
@ -145,7 +145,7 @@ namespace Nz
|
||||||
case Extend_Finite:
|
case Extend_Finite:
|
||||||
{
|
{
|
||||||
// Extend the OBB local box
|
// Extend the OBB local box
|
||||||
obb.localBox.ExtendTo(volume.localBox);
|
obb.localBox.ExtendTo(volume.obb.localBox);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue