Utility/Mesh: Refactor Mesh & Submeshes

This commit is contained in:
Jérôme Leclercq
2018-05-03 13:32:17 +02:00
parent 03e976993f
commit d94baf133b
15 changed files with 250 additions and 224 deletions

View File

@@ -20,8 +20,12 @@
#include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <unordered_map>
#include <vector>
namespace Nz
{
@@ -56,7 +60,6 @@ namespace Nz
class Mesh;
struct Primitive;
class PrimitiveList;
class Skeleton;
class SubMesh;
using MeshVertex = VertexStruct_XYZ_Normal_UV_Tangent;
@@ -80,8 +83,10 @@ namespace Nz
friend class Utility;
public:
Mesh() = default;
~Mesh();
inline Mesh();
Mesh(const Mesh&) = delete;
Mesh(Mesh&&) = delete;
inline ~Mesh();
void AddSubMesh(SubMesh* subMesh);
void AddSubMesh(const String& identifier, SubMesh* subMesh);
@@ -141,14 +146,34 @@ namespace Nz
void Transform(const Matrix4f& matrix);
Mesh& operator=(const Mesh&) = delete;
Mesh& operator=(Mesh&&) = delete;
template<typename... Args> static MeshRef New(Args&&... args);
// Signals:
NazaraSignal(OnMeshDestroy, const Mesh* /*mesh*/);
NazaraSignal(OnMeshInvalidateAABB, const Mesh* /*mesh*/);
NazaraSignal(OnMeshRelease, const Mesh* /*mesh*/);
private:
MeshImpl* m_impl = nullptr;
struct SubMeshData
{
SubMeshRef subMesh;
NazaraSlot(SubMesh, OnSubMeshInvalidateAABB, onSubMeshInvalidated);
};
std::unordered_map<String, UInt32> m_subMeshMap;
std::vector<ParameterList> m_materialData;
std::vector<SubMeshData> m_subMeshes;
AnimationType m_animationType;
mutable Boxf m_aabb;
Skeleton m_skeleton; // Only used by skeletal meshes
String m_animationPath;
mutable bool m_aabbUpdated;
bool m_isValid;
UInt32 m_jointCount; // Only used by skeletal meshes
static bool Initialize();
static void Uninitialize();

View File

@@ -2,11 +2,25 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Mesh.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
Mesh::Mesh() :
m_materialData(1),
m_aabbUpdated(false)
{
}
Mesh::~Mesh()
{
OnMeshRelease(this);
Destroy();
}
template<typename... Args>
MeshRef Mesh::New(Args&&... args)
{

View File

@@ -24,9 +24,14 @@ namespace Nz
class NAZARA_UTILITY_API SkeletalMesh final : public SubMesh
{
public:
SkeletalMesh(VertexBuffer* vertexBuffer, const IndexBuffer* indexBuffer);
NAZARA_DEPRECATED("SkeletalMesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
SkeletalMesh(const Mesh* parent);
~SkeletalMesh();
NAZARA_DEPRECATED("SkeletalMesh create/destroy functions are deprecated, please use constructor")
bool Create(VertexBuffer* vertexBuffer);
void Destroy();
@@ -51,8 +56,8 @@ namespace Nz
private:
Boxf m_aabb;
IndexBufferConstRef m_indexBuffer = nullptr;
VertexBufferRef m_vertexBuffer = nullptr;
IndexBufferConstRef m_indexBuffer;
VertexBufferRef m_vertexBuffer;
};
}

View File

@@ -21,11 +21,16 @@ namespace Nz
class NAZARA_UTILITY_API StaticMesh final : public SubMesh
{
public:
StaticMesh(VertexBuffer* vertexBuffer, const IndexBuffer* indexBuffer);
NAZARA_DEPRECATED("StaticMesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
StaticMesh(const Mesh* parent);
~StaticMesh();
void Center();
NAZARA_DEPRECATED("StaticMesh create/destroy functions are deprecated, please use constructor")
bool Create(VertexBuffer* vertexBuffer);
void Destroy();
@@ -52,8 +57,8 @@ namespace Nz
private:
Boxf m_aabb;
IndexBufferConstRef m_indexBuffer = nullptr;
VertexBufferRef m_vertexBuffer = nullptr;
IndexBufferConstRef m_indexBuffer;
VertexBufferRef m_vertexBuffer;
};
}

View File

@@ -28,7 +28,13 @@ namespace Nz
friend Mesh;
public:
SubMesh();
NAZARA_DEPRECATED("Submesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
SubMesh(const Mesh* parent);
SubMesh(const SubMesh&) = delete;
SubMesh(SubMesh&&) = delete;
virtual ~SubMesh();
void GenerateNormals();
@@ -39,7 +45,6 @@ namespace Nz
virtual AnimationType GetAnimationType() const = 0;
virtual const IndexBuffer* GetIndexBuffer() const = 0;
UInt32 GetMaterialIndex() const;
const Mesh* GetParent() const;
PrimitiveMode GetPrimitiveMode() const;
UInt32 GetTriangleCount() const;
virtual UInt32 GetVertexCount() const = 0;
@@ -49,12 +54,15 @@ namespace Nz
void SetMaterialIndex(UInt32 matIndex);
void SetPrimitiveMode(PrimitiveMode mode);
SubMesh& operator=(const SubMesh&) = delete;
SubMesh& operator=(SubMesh&&) = delete;
// Signals:
NazaraSignal(OnSubMeshInvalidateAABB, const SubMesh* /*subMesh*/);
NazaraSignal(OnSubMeshRelease, const SubMesh* /*subMesh*/);
protected:
PrimitiveMode m_primitiveMode;
const Mesh* m_parent;
UInt32 m_matIndex;
};
}