Graphics/Model: Fix model not invalidating their bounding volume when their mesh AABB got updated

This commit is contained in:
Jérôme Leclercq 2018-05-03 13:32:53 +02:00
parent d94baf133b
commit d53c245c78
4 changed files with 26 additions and 6 deletions

View File

@ -98,6 +98,7 @@ Nazara Engine:
- ⚠️ Refactored Mesh/SubMesh, allowing a submesh to be attached to multiple meshes, deprecating Create/Destroy methods - ⚠️ Refactored Mesh/SubMesh, allowing a submesh to be attached to multiple meshes, deprecating Create/Destroy methods
- SubMesh class now has a OnSubMeshInvalidateAABB signal, triggered when a new AABB is set to the submesh - SubMesh class now has a OnSubMeshInvalidateAABB signal, triggered when a new AABB is set to the submesh
- Mesh class now has a OnMeshInvalidateAABB signal, triggered when a mesh invalidates its AABB, which is also submesh updates its AABB - Mesh class now has a OnMeshInvalidateAABB signal, triggered when a mesh invalidates its AABB, which is also submesh updates its AABB
- Model now invalidate properly their bounding volume when their mesh AABB is updated
Nazara Development Kit: Nazara Development Kit:
- Added ImageWidget (#139) - Added ImageWidget (#139)

View File

@ -41,8 +41,8 @@ namespace Nz
public: public:
inline Model(); inline Model();
Model(const Model& model) = default; Model(const Model& model);
Model(Model&& model) = default; Model(Model&& model) = delete;
virtual ~Model(); virtual ~Model();
void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override;
@ -66,7 +66,7 @@ namespace Nz
virtual void SetMesh(Mesh* mesh); virtual void SetMesh(Mesh* mesh);
Model& operator=(const Model& node) = default; Model& operator=(const Model& node) = default;
Model& operator=(Model&& node) = default; Model& operator=(Model&& node) = delete;
template<typename... Args> static ModelRef New(Args&&... args); template<typename... Args> static ModelRef New(Args&&... args);
@ -75,6 +75,8 @@ namespace Nz
MeshRef m_mesh; MeshRef m_mesh;
NazaraSlot(Mesh, OnMeshInvalidateAABB, m_meshAABBInvalidationSlot);
static ModelLoader::LoaderList s_loaders; static ModelLoader::LoaderList s_loaders;
}; };
} }

View File

@ -2,6 +2,7 @@
// This file is part of the "Nazara Engine - Graphics module" // This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/Model.hpp>
#include <memory> #include <memory>
#include <Nazara/Graphics/Debug.hpp> #include <Nazara/Graphics/Debug.hpp>
@ -10,11 +11,21 @@ namespace Nz
/*! /*!
* \brief Constructs a Model object by default * \brief Constructs a Model object by default
*/ */
Model::Model() inline Model::Model()
{ {
ResetMaterials(0); ResetMaterials(0);
} }
/*!
* \brief Constructs a Model object by copying another
*
* \param model Model to copy
*/
inline Model::Model(const Model& model)
{
SetMesh(model.m_mesh);
}
/*! /*!
* \brief Adds this model to a render queue, using user-specified transform matrix and render order * \brief Adds this model to a render queue, using user-specified transform matrix and render order
* *
@ -25,8 +36,8 @@ namespace Nz
* \param renderOrder Specify the render queue layer to be used * \param renderOrder Specify the render queue layer to be used
* \param scissorRect The Scissor rect to uses for rendering * \param scissorRect The Scissor rect to uses for rendering
*/ */
void Model::AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder, const Recti& scissorRect) const inline void Model::AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder, const Recti& scissorRect) const
{ {
InstanceData instanceData(Nz::Matrix4f::Identity()); InstanceData instanceData(Nz::Matrix4f::Identity());
instanceData.renderOrder = renderOrder; instanceData.renderOrder = renderOrder;
instanceData.transformMatrix = transformMatrix; instanceData.transformMatrix = transformMatrix;

View File

@ -252,9 +252,15 @@ namespace Nz
m_mesh = mesh; m_mesh = mesh;
if (m_mesh) if (m_mesh)
{
ResetMaterials(mesh->GetMaterialCount()); ResetMaterials(mesh->GetMaterialCount());
m_meshAABBInvalidationSlot.Connect(m_mesh->OnMeshInvalidateAABB, [this](const Nz::Mesh*) { InvalidateBoundingVolume(); });
}
else else
{
ResetMaterials(0); ResetMaterials(0);
m_meshAABBInvalidationSlot.Disconnect();
}
InvalidateBoundingVolume(); InvalidateBoundingVolume();
} }