Big skeletal animation update

Added MeshInfos demo
Added MD5Mesh/MD5Anim loader support
Added Node class
Fixed ResourceParams not being exported
Added support for skeletal animation
(Animation/Mesh/Joint/SkeletalMesh/Skeleton)
Meshes are now only stored with VertexStruct_XYZ_Normal_UV_Tangent type
Moved Sequence declaration to Sequence.hpp

-Animation:
Renamed Create to Create[Keyframe|Skeletal]

-AxisAlignedBox:
Added Contains method
Added GetCorner method
Added GetCube method
Added Transform method

-Cube/Rect:
Added GetPosition method
Added GetSize method
(Almost) Fixed ExtendTo method
Fixed GetCenter method

-File:
Added GetDirectory static function
Added GetPath method
Renamed GetDirectoryPath method to GetDirectory

-Math module:
Fixed constructor/methods taking a non-const array
GetNormal/Normalize methods now takes an optionnal integer pointer
(returning length)
Made all classes default constructor trivial
Inverse, MakeIdentity, MakeZero, Normalize, Set methods now returns
reference to object

-Matrix4:
Modified methods to avoid copies
Removed COW (Too much overhead)
Removed Concatenate[Affine] static function

-Mesh:
Renamed Create to Create[Keyframe|Skeletal|Static]
Renamed Skin to Material

-MeshParams:
No longer takes declaration argument
Renamed loadAnimations to animated
Storage default to BufferStorage_Hardware if supported and
BufferStorage_Software otherwise

-OpenGL:
Added glGetBooleanv function
Added glIsEnabled function

-Quaternion:
Added ComputeW method
Added Conjugate method

-Renderer:
Added IsEnabled static function
Fixed GetLineWidth function not being static
Removed SetVertexDeclaration

-RenderWindow:
Made CopyTo[Image|Texture] method constant

-Resource
Fixed RemoveResourceListener crash

-ResourceLoader:
Loaders are now used in a LIFO context

-Stream:
Renamed GetLine method to ReadLine

-String:
Fixed Simplified

-Utility module
Added configuration define for strict resource parsing

-VertexBuffer
Now takes a VertexDeclaration pointer

-VertexDeclaration
No longer throw an error when getting a non-existing element


Former-commit-id: f7358c1231d6af48b799d2f24f077a001e16785b
This commit is contained in:
Lynix
2012-11-21 17:23:50 +01:00
parent 84f73f2b6a
commit 70ef422950
99 changed files with 6270 additions and 1983 deletions

View File

@@ -7,7 +7,6 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <vector>
struct md2_header
{
@@ -51,14 +50,6 @@ struct md2_triangle
nzUInt16 texCoords[3];
};
struct md2_frame
{
NzVector3f scale;
NzVector3f translate;
char name[16];
std::vector<md2_vertex> vertices;
};
extern const nzUInt32 md2Ident;
extern const NzVector3f md2Normals[162];

View File

@@ -7,16 +7,18 @@
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Utility/KeyframeMesh.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/Loaders/MD2/Constants.hpp>
#include <Nazara/Utility/Loaders/MD2/Mesh.hpp>
#include <cstddef>
#include <cstring>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace
{
bool NzLoader_MD2_Check(NzInputStream& stream, const NzMeshParams& parameters)
bool Check(NzInputStream& stream, const NzMeshParams& parameters)
{
NazaraUnused(parameters);
@@ -24,7 +26,7 @@ namespace
if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32))
return false;
#if defined(NAZARA_BIG_ENDIAN)
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(&magic[0], sizeof(nzUInt32));
NzByteSwap(&magic[1], sizeof(nzUInt32));
#endif
@@ -32,7 +34,7 @@ namespace
return magic[0] == md2Ident && magic[1] == 8;
}
bool NzLoader_MD2_Load(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters)
bool Load(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters)
{
md2_header header;
if (stream.Read(&header, sizeof(md2_header)) != sizeof(md2_header))
@@ -41,7 +43,7 @@ namespace
return false;
}
#if defined(NAZARA_BIG_ENDIAN)
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(&header.skinwidth, sizeof(nzUInt32));
NzByteSwap(&header.skinheight, sizeof(nzUInt32));
NzByteSwap(&header.framesize, sizeof(nzUInt32));
@@ -67,16 +69,16 @@ namespace
/// Création du mesh
// Animé ou statique, c'est la question
bool animated;
unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast<unsigned int>(header.num_frames-1));
unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast<unsigned int>(header.num_frames-1));
if (parameters.loadAnimations && startFrame != endFrame)
animated = true;
bool animated = (parameters.animated && startFrame != endFrame);
if (animated)
mesh->CreateKeyframe();
else
animated = false;
mesh->CreateStatic();
if (!mesh->Create((animated) ? nzAnimationType_Keyframe : nzAnimationType_Static)) // Ne devrait jamais échouer
if (!mesh->IsValid()) // Ne devrait jamais échouer
{
NazaraInternalError("Failed to create mesh");
return false;
@@ -87,11 +89,12 @@ namespace
{
stream.SetCursorPos(header.offset_skins);
{
NzString baseDir = stream.GetDirectory();
char skin[68];
for (unsigned int i = 0; i < header.num_skins; ++i)
{
stream.Read(skin, 68*sizeof(char));
mesh->AddSkin(skin);
mesh->AddMaterial(baseDir + skin);
}
}
}
@@ -100,16 +103,13 @@ namespace
if (animated)
{
NzAnimation* animation = new NzAnimation;
if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1))
if (animation->CreateKeyframe(endFrame-startFrame+1))
{
// Décodage des séquences
NzString frameName;
///TODO: Optimiser le calcul
char last[16];
NzSequence sequence;
sequence.framePerSecond = 10; // Par défaut pour les animations MD2
char name[16], last[16];
stream.SetCursorPos(header.offset_frames + startFrame*header.framesize + offsetof(md2_frame, name));
stream.SetCursorPos(header.offset_frames + startFrame*header.framesize + 2*sizeof(NzVector3f));
stream.Read(last, 16*sizeof(char));
int pos = std::strlen(last)-1;
@@ -122,10 +122,16 @@ namespace
}
last[pos+1] = '\0';
unsigned int numFrames = 0;
NzSequence sequence;
sequence.firstFrame = startFrame;
sequence.frameCount = 0;
sequence.frameRate = 10; // Par défaut pour les animations MD2
sequence.name = last;
char name[16];
for (unsigned int i = startFrame; i <= endFrame; ++i)
{
stream.SetCursorPos(header.offset_frames + i*header.framesize + offsetof(md2_frame, name));
stream.SetCursorPos(header.offset_frames + i*header.framesize + 2*sizeof(NzVector3f));
stream.Read(name, 16*sizeof(char));
pos = std::strlen(name)-1;
@@ -140,24 +146,20 @@ namespace
if (std::strcmp(name, last) != 0) // Si les deux frames n'ont pas le même nom
{
// Alors on enregistre la séquence
sequence.firstFrame = i-numFrames;
sequence.lastFrame = i-1;
sequence.name = last;
animation->AddSequence(sequence);
std::strcpy(last, name);
numFrames = 0;
// Alors on enregistre la séquence actuelle
animation->AddSequence(sequence);
// Et on initialise la séquence suivante
sequence.firstFrame = i;
sequence.frameCount = 0;
sequence.name = last;
}
numFrames++;
sequence.frameCount++;
}
// On ajoute la dernière frame (Qui n'a pas été traitée par la boucle)
sequence.firstFrame = endFrame-numFrames;
sequence.lastFrame = endFrame;
sequence.name = last;
animation->AddSequence(sequence);
mesh->SetAnimation(animation);
@@ -169,15 +171,118 @@ namespace
/// Chargement des submesh
// Actuellement le loader ne charge qu'un submesh
// TODO: Utiliser les commandes OpenGL pour accélérer le rendu
NzMD2Mesh* subMesh = new NzMD2Mesh(mesh);
if (!subMesh->Create(header, stream, parameters))
// TODO: Utiliser les commandes OpenGL pour créer des indices et accélérer le rendu
unsigned int frameCount = endFrame - startFrame + 1;
unsigned int vertexCount = header.num_tris * 3;
std::unique_ptr<NzVertexBuffer> vertexBuffer(new NzVertexBuffer(NzMesh::GetDeclaration(), vertexCount, parameters.storage, nzBufferUsage_Dynamic));
std::unique_ptr<NzKeyframeMesh> subMesh(new NzKeyframeMesh(mesh));
if (!subMesh->Create(vertexBuffer.get(), frameCount))
{
NazaraError("Failed to create MD2 mesh");
NazaraError("Failed to create SubMesh");
return false;
}
mesh->AddSubMesh(subMesh);
vertexBuffer->SetPersistent(false);
vertexBuffer.release();
/// Lecture des triangles
std::vector<md2_triangle> triangles(header.num_tris);
stream.SetCursorPos(header.offset_tris);
stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle));
#ifdef NAZARA_BIG_ENDIAN
for (unsigned int i = 0; i < header.num_tris; ++i)
{
NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16));
NzByteSwap(&triangles[i].texCoords[0], sizeof(nzUInt16));
NzByteSwap(&triangles[i].vertices[1], sizeof(nzUInt16));
NzByteSwap(&triangles[i].texCoords[1], sizeof(nzUInt16));
NzByteSwap(&triangles[i].vertices[2], sizeof(nzUInt16));
NzByteSwap(&triangles[i].texCoords[2], sizeof(nzUInt16));
}
#endif
/// Lecture des coordonnées de texture
std::vector<md2_texCoord> texCoords(header.num_st);
// Lecture des coordonnées de texture
stream.SetCursorPos(header.offset_st);
stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord));
#ifdef NAZARA_BIG_ENDIAN
for (unsigned int i = 0; i < header.num_st; ++i)
{
NzByteSwap(&texCoords[i].u, sizeof(nzInt16));
NzByteSwap(&texCoords[i].v, sizeof(nzInt16));
}
#endif
/// Chargement des frames
stream.SetCursorPos(header.offset_frames + header.framesize*startFrame);
// Pour que le modèle soit correctement aligné, on génère un quaternion que nous appliquerons à chacune des vertices
NzQuaternionf rotationQuat = NzEulerAnglesf(-90.f, 90.f, 0.f);
md2_vertex* vertices = new md2_vertex[header.num_vertices];
for (unsigned int f = 0; f < frameCount; ++f)
{
NzVector3f scale, translate;
stream.Read(scale, sizeof(NzVector3f));
stream.Read(translate, sizeof(NzVector3f));
stream.Read(nullptr, 16*sizeof(char));
stream.Read(vertices, header.num_vertices*sizeof(md2_vertex));
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(&scale.x, sizeof(float));
NzByteSwap(&scale.y, sizeof(float));
NzByteSwap(&scale.z, sizeof(float));
NzByteSwap(&translate.x, sizeof(float));
NzByteSwap(&translate.y, sizeof(float));
NzByteSwap(&translate.z, sizeof(float));
#endif
NzAxisAlignedBox aabb;
for (unsigned int t = 0; t < header.num_tris; ++t)
{
for (unsigned int v = 0; v < 3; ++v)
{
const md2_vertex& vert = vertices[triangles[t].vertices[v]];
NzVector3f position = rotationQuat * NzVector3f(vert.x * scale.x + translate.x, vert.y * scale.y + translate.y, vert.z * scale.z + translate.z);
// On fait en sorte d'étendre l'AABB pour qu'il contienne ce sommet
aabb.ExtendTo(position);
// Et on finit par copier les éléments dans le buffer
NzMeshVertex vertex;
vertex.normal = md2Normals[vert.n];
vertex.position = position;
// On ne définit les coordonnées de texture que pour la première frame
bool firstFrame = (f == 0);
if (firstFrame)
{
const md2_texCoord& texC = texCoords[triangles[t].texCoords[v]];
vertex.uv.Set(texC.u / static_cast<float>(header.skinwidth), 1.f - texC.v / static_cast<float>(header.skinheight));
}
subMesh->SetVertex(vertex, f, vertexCount - (t*3 + v) - 1, firstFrame);
}
}
subMesh->SetAABB(f, aabb);
}
delete[] vertices;
subMesh->Unlock();
subMesh->SetMaterialIndex(0);
mesh->AddSubMesh(subMesh.release());
return true;
}
@@ -185,14 +290,10 @@ namespace
void NzLoaders_MD2_Register()
{
NzMD2Mesh::Initialize();
NzMeshLoader::RegisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load);
NzMeshLoader::RegisterLoader("md2", Check, Load);
}
void NzLoaders_MD2_Unregister()
{
NzMeshLoader::UnregisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load);
NzMD2Mesh::Uninitialize();
NzMeshLoader::UnregisterLoader("md2", Check, Load);
}

View File

@@ -1,292 +0,0 @@
// Copyright (C) 2012 Jérôme Leclercq
// 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/Loaders/MD2/Mesh.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/Debug.hpp>
NzMD2Mesh::NzMD2Mesh(const NzMesh* parent) :
NzKeyframeMesh(parent),
m_frames(nullptr),
m_indexBuffer(nullptr),
m_vertexBuffer(nullptr)
{
}
NzMD2Mesh::~NzMD2Mesh()
{
Destroy();
}
bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters)
{
Destroy();
unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast<unsigned int>(header.num_frames-1));
unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast<unsigned int>(header.num_frames-1));
m_frameCount = endFrame - startFrame + 1;
m_vertexCount = header.num_tris * 3;
/// Chargement des vertices
std::vector<md2_texCoord> texCoords(header.num_st);
std::vector<md2_triangle> triangles(header.num_tris);
// Lecture des coordonnées de texture
stream.SetCursorPos(header.offset_st);
stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord));
#if defined(NAZARA_BIG_ENDIAN)
for (unsigned int i = 0; i < header.num_st; ++i)
{
NzByteSwap(&texCoords[i].u, sizeof(nzInt16));
NzByteSwap(&texCoords[i].v, sizeof(nzInt16));
}
#endif
stream.SetCursorPos(header.offset_tris);
stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle));
#if defined(NAZARA_BIG_ENDIAN)
for (unsigned int i = 0; i < header.num_tris; ++i)
{
NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16));
NzByteSwap(&texCoords[i].texCoords[0], sizeof(nzUInt16));
NzByteSwap(&triangles[i].vertices[1], sizeof(nzUInt16));
NzByteSwap(&texCoords[i].texCoords[1], sizeof(nzUInt16));
NzByteSwap(&triangles[i].vertices[2], sizeof(nzUInt16));
NzByteSwap(&texCoords[i].texCoords[2], sizeof(nzUInt16));
}
#endif
stream.SetCursorPos(header.offset_frames + header.framesize*startFrame);
md2_frame frame;
frame.vertices.resize(header.num_vertices);
// Pour que le modèle soit correctement aligné, on génère un quaternion que nous appliquerons à chacune des vertices
NzQuaternionf rotationQuat = NzEulerAnglesf(-90.f, 90.f, 0.f);
//NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(-90.f, -90.f, 0.f));
unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData);
m_frames = new Frame[m_frameCount];
for (unsigned int i = 0; i < m_frameCount; ++i)
{
stream.Read(&frame.scale, sizeof(NzVector3f));
stream.Read(&frame.translate, sizeof(NzVector3f));
stream.Read(&frame.name, 16*sizeof(char));
stream.Read(&frame.vertices[0], header.num_vertices*sizeof(md2_vertex));
#if defined(NAZARA_BIG_ENDIAN)
NzByteSwap(&frame.scale.x, sizeof(float));
NzByteSwap(&frame.scale.y, sizeof(float));
NzByteSwap(&frame.scale.z, sizeof(float));
NzByteSwap(&frame.translate.x, sizeof(float));
NzByteSwap(&frame.translate.y, sizeof(float));
NzByteSwap(&frame.translate.z, sizeof(float));
#endif
m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice MD2 de la normale plutôt que la normale (gain d'espace)
m_frames[i].vertices = new NzVector3f[m_vertexCount];
NzVector3f max, min;
for (unsigned int t = 0; t < header.num_tris; ++t)
{
for (unsigned int v = 0; v < 3; ++v)
{
const md2_vertex& vert = frame.vertices[triangles[t].vertices[v]];
NzVector3f vertex = rotationQuat * NzVector3f(vert.x * frame.scale.x + frame.translate.x, vert.y * frame.scale.y + frame.translate.y, vert.z * frame.scale.z + frame.translate.z);
// On fait en sorte d'avoir deux vertices de délimitation, définissant un rectangle dans l'espace
max.Maximize(vertex);
min.Minimize(vertex);
// Le MD2 ne définit pas ses vertices dans le bon ordre, il nous faut donc les ajouter dans l'ordre inverse
unsigned int index = m_vertexCount - (t*3 + v) - 1;
m_frames[i].normal[index] = vert.n;
m_frames[i].vertices[index] = vertex;
}
}
m_frames[i].aabb.SetExtends(min, max);
}
m_indexBuffer = nullptr; // Pas d'indexbuffer pour l'instant
m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), parameters.storage, nzBufferUsage_Dynamic);
nzUInt8* ptr = reinterpret_cast<nzUInt8*>(m_vertexBuffer->Map(nzBufferAccess_WriteOnly));
if (!ptr)
{
NazaraError("Failed to map vertex buffer");
Destroy();
return false;
}
// On avance jusqu'aux dernières coordonnées de texture et on les définit dans l'ordre inverse
ptr += s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_TexCoord)->offset + stride * (m_vertexCount-1);
for (unsigned int t = 0; t < header.num_tris; ++t)
{
for (unsigned int v = 0; v < 3; ++v)
{
const md2_texCoord& texC = texCoords[triangles[t].texCoords[v]];
NzVector2f* coords = reinterpret_cast<NzVector2f*>(ptr);
coords->x = texC.u / static_cast<float>(header.skinwidth);
coords->y = 1.f - texC.v / static_cast<float>(header.skinheight);
ptr -= stride;
}
}
if (!m_vertexBuffer->Unmap())
{
NazaraError("Failed to unmap buffer");
Destroy();
return false;
}
m_vertexBuffer->AddResourceReference();
m_vertexBuffer->SetPersistent(false);
AnimateImpl(0, 0, 0.f);
return true;
}
void NzMD2Mesh::Destroy()
{
if (m_frames)
{
for (unsigned int i = 0; i < m_frameCount; ++i)
{
delete[] m_frames[i].normal;
delete[] m_frames[i].vertices;
}
delete[] m_frames;
m_frames = nullptr;
}
if (m_indexBuffer)
{
m_indexBuffer->RemoveResourceReference();
m_indexBuffer = nullptr;
}
if (m_vertexBuffer)
{
m_vertexBuffer->RemoveResourceReference();
m_vertexBuffer = nullptr;
}
}
const NzAxisAlignedBox& NzMD2Mesh::GetAABB() const
{
return m_aabb;
}
nzAnimationType NzMD2Mesh::GetAnimationType() const
{
if (m_frameCount > 1)
return nzAnimationType_Keyframe;
else
return nzAnimationType_Static;
}
unsigned int NzMD2Mesh::GetFrameCount() const
{
return m_frameCount;
}
const NzIndexBuffer* NzMD2Mesh::GetIndexBuffer() const
{
return nullptr;
//return m_indexBuffer;
}
nzPrimitiveType NzMD2Mesh::GetPrimitiveType() const
{
return nzPrimitiveType_TriangleList;
}
const NzVertexBuffer* NzMD2Mesh::GetVertexBuffer() const
{
return m_vertexBuffer;
}
const NzVertexDeclaration* NzMD2Mesh::GetVertexDeclaration() const
{
return &s_declaration;
}
void NzMD2Mesh::Initialize()
{
NzVertexElement elements[3];
elements[0].offset = 0;
elements[0].type = nzElementType_Float3;
elements[0].usage = nzElementUsage_Position;
elements[1].offset = 3*sizeof(float);
elements[1].type = nzElementType_Float3;
elements[1].usage = nzElementUsage_Normal;
elements[2].offset = 3*sizeof(float) + 3*sizeof(float);
elements[2].type = nzElementType_Float2;
elements[2].usage = nzElementUsage_TexCoord;
s_declaration.Create(elements, 3);
}
void NzMD2Mesh::Uninitialize()
{
s_declaration.Destroy();
}
void NzMD2Mesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation)
{
nzUInt8* ptr = reinterpret_cast<nzUInt8*>(m_vertexBuffer->Map(nzBufferAccess_WriteOnly));
if (!ptr)
{
NazaraError("Failed to map vertex buffer");
return;
}
unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData);
unsigned int positionOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Position)->offset;
unsigned int normalOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Normal)->offset;
Frame* fA = &m_frames[frameA];
Frame* fB = &m_frames[frameB];
for (unsigned int i = 0; i < m_vertexCount; ++i)
{
NzVector3f* position = reinterpret_cast<NzVector3f*>(ptr + positionOffset);
NzVector3f* normal = reinterpret_cast<NzVector3f*>(ptr + normalOffset);
*position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]);
*normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]);
ptr += stride;
}
if (!m_vertexBuffer->Unmap())
NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption");
// Interpolation de l'AABB
NzVector3f max1 = fA->aabb.GetMaximum();
NzVector3f min1 = fA->aabb.GetMinimum();
m_aabb.SetExtends(min1 + interpolation * (fB->aabb.GetMinimum() - min1), max1 + interpolation * (fB->aabb.GetMaximum() - max1));
}
NzVertexDeclaration NzMD2Mesh::s_declaration;

View File

@@ -1,65 +0,0 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LOADERS_MD2_MESH_HPP
#define NAZARA_LOADERS_MD2_MESH_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/KeyframeMesh.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/Loaders/MD2/Constants.hpp>
class NzIndexBuffer;
class NzInputStream;
class NzVertexBuffer;
struct NzMeshParams;
class NAZARA_API NzMD2Mesh : public NzKeyframeMesh
{
public:
NzMD2Mesh(const NzMesh* parent);
~NzMD2Mesh();
bool Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters);
void Destroy();
const NzAxisAlignedBox& GetAABB() const;
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
const NzIndexBuffer* GetIndexBuffer() const;
nzPrimitiveType GetPrimitiveType() const;
const NzVertexBuffer* GetVertexBuffer() const;
const NzVertexDeclaration* GetVertexDeclaration() const;
bool IsAnimated() const;
static void Initialize();
static void Uninitialize();
private:
void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation);
struct Frame
{
NzAxisAlignedBox aabb;
nzUInt8* normal;
NzVector3f* tangents;
NzVector3f* vertices;
char name[16];
};
NzAxisAlignedBox m_aabb;
Frame* m_frames;
NzIndexBuffer* m_indexBuffer;
NzVertexBuffer* m_vertexBuffer;
unsigned int m_frameCount;
unsigned int m_vertexCount;
static NzVertexDeclaration s_declaration;
};
#endif // NAZARA_LOADERS_MD2_MESH_HPP