Added KeyframeMesh::Get/Set vertex components
Former-commit-id: ff51b02dfd5f0675c33c01f39418312834c5d8a9
This commit is contained in:
parent
520643140c
commit
c998a5c457
|
|
@ -30,7 +30,12 @@ class NAZARA_API NzKeyframeMesh final : public NzSubMesh
|
||||||
nzAnimationType GetAnimationType() const override;
|
nzAnimationType GetAnimationType() const override;
|
||||||
unsigned int GetFrameCount() const;
|
unsigned int GetFrameCount() const;
|
||||||
const NzIndexBuffer* GetIndexBuffer() const override;
|
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;
|
void GetVertex(unsigned int frameIndex, unsigned int vertexIndex, NzMeshVertex* dest) const;
|
||||||
|
|
||||||
NzVertexBuffer* GetVertexBuffer() override;
|
NzVertexBuffer* GetVertexBuffer() override;
|
||||||
const NzVertexBuffer* GetVertexBuffer() const 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 SetAABB(unsigned int frameIndex, const NzAxisAlignedBox& aabb);
|
||||||
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
|
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
|
||||||
void SetVertex(unsigned int frameIndex, unsigned int vertexIndex, const NzMeshVertex& source);
|
void SetNormal(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& normal);
|
||||||
void SetTexCoords(unsigned int vertexIndex, const NzVector2f& uv);
|
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:
|
private:
|
||||||
void InterpolateImpl(unsigned int frameA, unsigned int frameB, float interpolation) const;
|
void InterpolateImpl(unsigned int frameA, unsigned int frameB, float interpolation) const;
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,118 @@ const NzIndexBuffer* NzKeyframeMesh::GetIndexBuffer() const
|
||||||
return m_impl->indexBuffer;
|
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
|
void NzKeyframeMesh::GetVertex(unsigned int frameIndex, unsigned int vertexIndex, NzMeshVertex* dest) const
|
||||||
{
|
{
|
||||||
#if NAZARA_UTILITY_SAFE
|
#if NAZARA_UTILITY_SAFE
|
||||||
|
|
@ -303,7 +415,7 @@ void NzKeyframeMesh::SetIndexBuffer(const NzIndexBuffer* indexBuffer)
|
||||||
m_impl->indexBuffer = 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 NAZARA_UTILITY_SAFE
|
||||||
if (!m_impl)
|
if (!m_impl)
|
||||||
|
|
@ -331,9 +443,69 @@ void NzKeyframeMesh::SetVertex(unsigned int frameIndex, unsigned int vertexIndex
|
||||||
|
|
||||||
unsigned int index = frameIndex*vertexCount + vertexIndex;
|
unsigned int index = frameIndex*vertexCount + vertexIndex;
|
||||||
|
|
||||||
m_impl->normals[index] = source.normal;
|
m_impl->normals[index] = normal;
|
||||||
m_impl->positions[index] = source.position;
|
}
|
||||||
m_impl->tangents[index] = source.tangent;
|
|
||||||
|
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)
|
void NzKeyframeMesh::SetTexCoords(unsigned int vertexIndex, const NzVector2f& uv)
|
||||||
|
|
|
||||||
|
|
@ -189,20 +189,19 @@ namespace
|
||||||
// On fait en sorte d'étendre l'AABB pour qu'il contienne ce sommet
|
// On fait en sorte d'étendre l'AABB pour qu'il contienne ce sommet
|
||||||
aabb.ExtendTo(position);
|
aabb.ExtendTo(position);
|
||||||
|
|
||||||
// Et on finit par copier les éléments dans le buffer
|
// On calcule l'indice (On affecte dans le sens inverse)
|
||||||
NzMeshVertex vertex;
|
|
||||||
vertex.normal = md2Normals[vert.n];
|
|
||||||
vertex.position = position;
|
|
||||||
|
|
||||||
unsigned int vertexIndex = vertexCount - (t*3 + v) - 1;
|
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)
|
if (f == 0)
|
||||||
{
|
{
|
||||||
// On ne définit les coordonnées de texture que lors de la première frame
|
// 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]];
|
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->SetTexCoords(vertexIndex, NzVector2f(texC.u / static_cast<float>(header.skinwidth), 1.f - texC.v / static_cast<float>(header.skinheight)));
|
||||||
}
|
}
|
||||||
|
|
||||||
subMesh->SetVertex(f, vertexIndex, vertex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue