diff --git a/ChangeLog.md b/ChangeLog.md index 7242fbaf4..7e108fe9b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -98,6 +98,7 @@ Nazara Engine: - ⚠️ 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 - 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: - Added ImageWidget (#139) diff --git a/include/Nazara/Graphics/Model.hpp b/include/Nazara/Graphics/Model.hpp index b37d68a2e..dfdcc8ee2 100644 --- a/include/Nazara/Graphics/Model.hpp +++ b/include/Nazara/Graphics/Model.hpp @@ -41,8 +41,8 @@ namespace Nz public: inline Model(); - Model(const Model& model) = default; - Model(Model&& model) = default; + Model(const Model& model); + Model(Model&& model) = delete; virtual ~Model(); void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; @@ -66,7 +66,7 @@ namespace Nz virtual void SetMesh(Mesh* mesh); Model& operator=(const Model& node) = default; - Model& operator=(Model&& node) = default; + Model& operator=(Model&& node) = delete; template static ModelRef New(Args&&... args); @@ -75,6 +75,8 @@ namespace Nz MeshRef m_mesh; + NazaraSlot(Mesh, OnMeshInvalidateAABB, m_meshAABBInvalidationSlot); + static ModelLoader::LoaderList s_loaders; }; } diff --git a/include/Nazara/Graphics/Model.inl b/include/Nazara/Graphics/Model.inl index 486665f3a..9078b6de3 100644 --- a/include/Nazara/Graphics/Model.inl +++ b/include/Nazara/Graphics/Model.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Graphics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include @@ -10,11 +11,21 @@ namespace Nz /*! * \brief Constructs a Model object by default */ - Model::Model() + inline Model::Model() { 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 * @@ -25,8 +36,8 @@ namespace Nz * \param renderOrder Specify the render queue layer to be used * \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.renderOrder = renderOrder; instanceData.transformMatrix = transformMatrix; diff --git a/src/Nazara/Graphics/Model.cpp b/src/Nazara/Graphics/Model.cpp index 05b8bc909..a01199d32 100644 --- a/src/Nazara/Graphics/Model.cpp +++ b/src/Nazara/Graphics/Model.cpp @@ -252,9 +252,15 @@ namespace Nz m_mesh = mesh; if (m_mesh) + { ResetMaterials(mesh->GetMaterialCount()); + m_meshAABBInvalidationSlot.Connect(m_mesh->OnMeshInvalidateAABB, [this](const Nz::Mesh*) { InvalidateBoundingVolume(); }); + } else + { ResetMaterials(0); + m_meshAABBInvalidationSlot.Disconnect(); + } InvalidateBoundingVolume(); }