Added KeyframeMesh::Get/Set vertex components

Former-commit-id: ff51b02dfd5f0675c33c01f39418312834c5d8a9
This commit is contained in:
Lynix 2013-01-02 21:51:03 +01:00
parent 520643140c
commit c998a5c457
3 changed files with 191 additions and 13 deletions

View File

@ -30,7 +30,12 @@ class NAZARA_API NzKeyframeMesh final : public NzSubMesh
nzAnimationType GetAnimationType() const override;
unsigned int GetFrameCount() const;
const NzIndexBuffer* GetIndexBuffer() const override;
NzVector3f GetNormal(unsigned int frameIndex, unsigned int vertexIndex) const;
NzVector3f GetPosition(unsigned int frameIndex, unsigned int vertexIndex) const;
NzVector3f GetTangent(unsigned int frameIndex, unsigned int vertexIndex) const;
NzVector2f GetTexCoords(unsigned int vertexIndex) const;
void GetVertex(unsigned int frameIndex, unsigned int vertexIndex, NzMeshVertex* dest) const;
NzVertexBuffer* GetVertexBuffer() override;
const NzVertexBuffer* GetVertexBuffer() const override;
@ -41,8 +46,10 @@ class NAZARA_API NzKeyframeMesh final : public NzSubMesh
void SetAABB(unsigned int frameIndex, const NzAxisAlignedBox& aabb);
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
void SetVertex(unsigned int frameIndex, unsigned int vertexIndex, const NzMeshVertex& source);
void SetTexCoords(unsigned int vertexIndex, const NzVector2f& uv);
void SetNormal(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& normal);
void SetPosition(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& position);
void SetTangent(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& tangent);
void SetTexCoords(unsigned int vertexIndex, const NzVector2f& texCoords);
private:
void InterpolateImpl(unsigned int frameA, unsigned int frameB, float interpolation) const;

View File

@ -153,6 +153,118 @@ const NzIndexBuffer* NzKeyframeMesh::GetIndexBuffer() const
return m_impl->indexBuffer;
}
NzVector3f NzKeyframeMesh::GetNormal(unsigned int frameIndex, unsigned int vertexIndex) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Keyframe mesh not created");
return NzVector3f();
}
if (frameIndex >= m_impl->frameCount)
{
NazaraError("Frame index out of bounds (" + NzString::Number(frameIndex) + " >= " + NzString::Number(m_impl->frameCount) + ')');
return NzVector3f();
}
#endif
unsigned int vertexCount = m_impl->vertexBuffer->GetVertexCount();
#if NAZARA_UTILITY_SAFE
if (vertexIndex >= vertexCount)
{
NazaraError("Vertex index out of bounds (" + NzString::Number(vertexIndex) + " >= " + NzString::Number(vertexCount) + ')');
return NzVector3f();
}
#endif
unsigned int index = frameIndex*vertexCount + vertexIndex;
return m_impl->normals[index];
}
NzVector3f NzKeyframeMesh::GetPosition(unsigned int frameIndex, unsigned int vertexIndex) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Keyframe mesh not created");
return NzVector3f();
}
if (frameIndex >= m_impl->frameCount)
{
NazaraError("Frame index out of bounds (" + NzString::Number(frameIndex) + " >= " + NzString::Number(m_impl->frameCount) + ')');
return NzVector3f();
}
#endif
unsigned int vertexCount = m_impl->vertexBuffer->GetVertexCount();
#if NAZARA_UTILITY_SAFE
if (vertexIndex >= vertexCount)
{
NazaraError("Vertex index out of bounds (" + NzString::Number(vertexIndex) + " >= " + NzString::Number(vertexCount) + ')');
return NzVector3f();
}
#endif
unsigned int index = frameIndex*vertexCount + vertexIndex;
return m_impl->positions[index];
}
NzVector3f NzKeyframeMesh::GetTangent(unsigned int frameIndex, unsigned int vertexIndex) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Keyframe mesh not created");
return NzVector3f();
}
if (frameIndex >= m_impl->frameCount)
{
NazaraError("Frame index out of bounds (" + NzString::Number(frameIndex) + " >= " + NzString::Number(m_impl->frameCount) + ')');
return NzVector3f();
}
#endif
unsigned int vertexCount = m_impl->vertexBuffer->GetVertexCount();
#if NAZARA_UTILITY_SAFE
if (vertexIndex >= vertexCount)
{
NazaraError("Vertex index out of bounds (" + NzString::Number(vertexIndex) + " >= " + NzString::Number(vertexCount) + ')');
return NzVector3f();
}
#endif
unsigned int index = frameIndex*vertexCount + vertexIndex;
return m_impl->tangents[index];
}
NzVector2f NzKeyframeMesh::GetTexCoords(unsigned int vertexIndex) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Keyframe mesh not created");
return NzVector2f();
}
if (vertexIndex >= m_impl->vertexBuffer->GetVertexCount())
{
NazaraError("Vertex index out of bounds (" + NzString::Number(vertexIndex) + " >= " + NzString::Number(m_impl->vertexBuffer->GetVertexCount()) + ')');
return NzVector2f();
}
#endif
return m_impl->uv[vertexIndex];
}
void NzKeyframeMesh::GetVertex(unsigned int frameIndex, unsigned int vertexIndex, NzMeshVertex* dest) const
{
#if NAZARA_UTILITY_SAFE
@ -303,7 +415,7 @@ void NzKeyframeMesh::SetIndexBuffer(const NzIndexBuffer* indexBuffer)
m_impl->indexBuffer = indexBuffer;
}
void NzKeyframeMesh::SetVertex(unsigned int frameIndex, unsigned int vertexIndex, const NzMeshVertex& source)
void NzKeyframeMesh::SetNormal(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& normal)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
@ -331,9 +443,69 @@ void NzKeyframeMesh::SetVertex(unsigned int frameIndex, unsigned int vertexIndex
unsigned int index = frameIndex*vertexCount + vertexIndex;
m_impl->normals[index] = source.normal;
m_impl->positions[index] = source.position;
m_impl->tangents[index] = source.tangent;
m_impl->normals[index] = normal;
}
void NzKeyframeMesh::SetPosition(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& position)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Keyframe mesh not created");
return;
}
if (frameIndex >= m_impl->frameCount)
{
NazaraError("Frame index out of bounds (" + NzString::Number(frameIndex) + " >= " + NzString::Number(m_impl->frameCount) + ')');
return;
}
#endif
unsigned int vertexCount = m_impl->vertexBuffer->GetVertexCount();
#if NAZARA_UTILITY_SAFE
if (vertexIndex >= vertexCount)
{
NazaraError("Vertex index out of bounds (" + NzString::Number(vertexIndex) + " >= " + NzString::Number(vertexCount) + ')');
return;
}
#endif
unsigned int index = frameIndex*vertexCount + vertexIndex;
m_impl->positions[index] = position;
}
void NzKeyframeMesh::SetTangent(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& tangent)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Keyframe mesh not created");
return;
}
if (frameIndex >= m_impl->frameCount)
{
NazaraError("Frame index out of bounds (" + NzString::Number(frameIndex) + " >= " + NzString::Number(m_impl->frameCount) + ')');
return;
}
#endif
unsigned int vertexCount = m_impl->vertexBuffer->GetVertexCount();
#if NAZARA_UTILITY_SAFE
if (vertexIndex >= vertexCount)
{
NazaraError("Vertex index out of bounds (" + NzString::Number(vertexIndex) + " >= " + NzString::Number(vertexCount) + ')');
return;
}
#endif
unsigned int index = frameIndex*vertexCount + vertexIndex;
m_impl->tangents[index] = tangent;
}
void NzKeyframeMesh::SetTexCoords(unsigned int vertexIndex, const NzVector2f& uv)

View File

@ -189,20 +189,19 @@ namespace
// 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 calcule l'indice (On affecte dans le sens inverse)
unsigned int vertexIndex = vertexCount - (t*3 + v) - 1;
// Et on finit par copier les éléments dans le buffer
subMesh->SetNormal(f, vertexIndex, md2Normals[vert.n]);
subMesh->SetPosition(f, vertexIndex, position);
if (f == 0)
{
// On ne définit les coordonnées de texture que lors de la première frame
const md2_texCoord& texC = texCoords[triangles[t].texCoords[v]];
subMesh->SetTexCoords(vertexIndex, NzVector2f(texC.u / static_cast<float>(header.skinwidth), 1.f - texC.v / static_cast<float>(header.skinheight)));
}
subMesh->SetVertex(f, vertexIndex, vertex);
}
}