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;