1
0

Get (more) append functions working for CMeshBuffer and CDynamicMeshBuffer

Some in CMeshBuffer got disabled in svn r1515 (before Irrlicht 1.7) without comment.
I suspect reason might have been that they are a bit unsafe and it was meant to be reworked. 
Maybe was planned to put that into MeshManipulator?
And CDynamicMeshBuffer never had them.
Anyway, it's useful stuff and having functions do nothing doesn't help. So now they do at least basic work.
Meaning - as long as index and vertex types are identical it's possible to attach meshbuffers again.
While totally ignoring things like 16-bit index overflow for now (so could be improved).
It would probably be better if attach functions had info about vertex/index types, but just keeping interface as it is/was for now.
This also fixes Bug #310 reported by Gaz.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6493 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2023-05-15 17:28:42 +00:00
parent 31931b0455
commit 01588b58eb
3 changed files with 64 additions and 32 deletions

View File

@@ -110,15 +110,66 @@ namespace scene
\param numIndices Number of indices in array. */
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE
{
// TODO
if (vertices == getVertices() || indices == getIndices()) // can't do that because we're doing reallocations on those blocks
return;
const u32 vertexCount = getVertexCount();
VertexBuffer->reallocate(vertexCount+numVertices);
switch ( VertexBuffer->getType() )
{
case video::EVT_STANDARD:
for (u32 i=0; i<numVertices; ++i)
{
VertexBuffer->push_back(static_cast<const video::S3DVertex*>(vertices)[i]);
BoundingBox.addInternalPoint(static_cast<const video::S3DVertex*>(vertices)[i].Pos);
}
break;
case video::EVT_2TCOORDS:
for (u32 i=0; i<numVertices; ++i)
{
VertexBuffer->push_back(static_cast<const video::S3DVertex2TCoords*>(vertices)[i]);
BoundingBox.addInternalPoint(static_cast<const video::S3DVertex2TCoords*>(vertices)[i].Pos);
}
break;
case video::EVT_TANGENTS:
for (u32 i=0; i<numVertices; ++i)
{
VertexBuffer->push_back(static_cast<const video::S3DVertexTangents*>(vertices)[i]);
BoundingBox.addInternalPoint(static_cast<const video::S3DVertexTangents*>(vertices)[i].Pos);
}
break;
}
IndexBuffer->reallocate(getIndexCount()+numIndices);
switch ( IndexBuffer->getType() )
{
case video::EIT_16BIT:
for (u32 i=0; i<numIndices; ++i)
{
IndexBuffer->push_back(indices[i]+vertexCount);
}
break;
case video::EIT_32BIT:
for (u32 i=0; i<numIndices; ++i)
{
IndexBuffer->push_back(reinterpret_cast<const irr::u32*>(indices)[i]+vertexCount);
}
break;
}
setDirty();
}
//! Append the meshbuffer to the current buffer
/** Only works for compatible vertex types
/** Only works for compatible vertex and index types
\param other Buffer to append to this one. */
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
{
// TODO
if ( getVertexType() != other->getVertexType() )
return;
append(other->getVertices(), other->getVertexCount(), other->getIndices(), other->getIndexCount());
}