From 01588b58ebc898f44ef1826408b9fba832e6660f Mon Sep 17 00:00:00 2001 From: cutealien Date: Mon, 15 May 2023 17:28:42 +0000 Subject: [PATCH] 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 --- include/CDynamicMeshBuffer.h | 57 ++++++++++++++++++++++++++++++++++-- include/CMeshBuffer.h | 31 ++++---------------- include/IMeshBuffer.h | 8 ++--- 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/include/CDynamicMeshBuffer.h b/include/CDynamicMeshBuffer.h index 4a707285..ba9db09f 100644 --- a/include/CDynamicMeshBuffer.h +++ b/include/CDynamicMeshBuffer.h @@ -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; ipush_back(static_cast(vertices)[i]); + BoundingBox.addInternalPoint(static_cast(vertices)[i].Pos); + } + break; + case video::EVT_2TCOORDS: + for (u32 i=0; ipush_back(static_cast(vertices)[i]); + BoundingBox.addInternalPoint(static_cast(vertices)[i].Pos); + } + break; + case video::EVT_TANGENTS: + for (u32 i=0; ipush_back(static_cast(vertices)[i]); + BoundingBox.addInternalPoint(static_cast(vertices)[i].Pos); + } + break; + } + + IndexBuffer->reallocate(getIndexCount()+numIndices); + switch ( IndexBuffer->getType() ) + { + case video::EIT_16BIT: + for (u32 i=0; ipush_back(indices[i]+vertexCount); + } + break; + case video::EIT_32BIT: + for (u32 i=0; ipush_back(reinterpret_cast(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()); } diff --git a/include/CMeshBuffer.h b/include/CMeshBuffer.h index 6f1ff368..531fcf0e 100644 --- a/include/CMeshBuffer.h +++ b/include/CMeshBuffer.h @@ -191,11 +191,11 @@ namespace scene //! Append the vertices and indices to the current buffer /** Only works for compatible types, i.e. either the same type or the main buffer is of standard type. Otherwise, behavior is - undefined. + undefined. Also can't append it's own vertices/indices to itself. */ virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE { - if (vertices == getVertices()) + if (vertices == getVertices() || indices == getIndices()) // can't do that because we're doing reallocations on those blocks return; const u32 vertexCount = getVertexCount(); @@ -213,37 +213,18 @@ namespace scene { Indices.push_back(indices[i]+vertexCount); } + + setDirty(); } //! Append the meshbuffer to the current buffer - /** Only works for compatible types, i.e. either the same type - or the main buffer is of standard type. Otherwise, behavior is - undefined. - \param other Meshbuffer to be appended to this one. - */ virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE { - /* - if (this==other) + if ( getVertexType() != other->getVertexType() ) return; - const u32 vertexCount = getVertexCount(); - u32 i; - - Vertices.reallocate(vertexCount+other->getVertexCount()); - for (i=0; igetVertexCount(); ++i) - { - Vertices.push_back(reinterpret_cast(other->getVertices())[i]); - } - - Indices.reallocate(getIndexCount()+other->getIndexCount()); - for (i=0; igetIndexCount(); ++i) - { - Indices.push_back(other->getIndices()[i]+vertexCount); - } - BoundingBox.addInternalBox(other->getBoundingBox()); - */ + append(other->getVertices(), other->getVertexCount(), other->getIndices(), other->getIndexCount()); } diff --git a/include/IMeshBuffer.h b/include/IMeshBuffer.h index 253d2712..fc32c369 100644 --- a/include/IMeshBuffer.h +++ b/include/IMeshBuffer.h @@ -126,17 +126,17 @@ namespace scene virtual const video::SColor& getColor(u32 i) const = 0; //! Append the vertices and indices to the current buffer - /** Only works for compatible vertex types - and not implemented for most buffers for now. + /** Only works for compatible vertex and index types + and not implemented for some buffers for now. \param vertices Pointer to a vertex array. \param numVertices Number of vertices in the array. \param indices Pointer to index array. \param numIndices Number of indices in array. */ virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) = 0; - //! Not supported right now by any meshbuffer + //! Not supported right now by all meshbuffer //! In theory: 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) = 0;