void MeshBase::set(const MeshBase& other) { if (&other == this) return; FW_ASSERT(other.isInMemory()); clear(); if (!isCompatible(other)) { append(other); compact(); return; } m_stride = other.m_stride; m_numVertices = other.m_numVertices; m_attribs = other.m_attribs; m_vertices = other.m_vertices; resizeSubmeshes(other.m_submeshes.getSize()); for (int i = 0; i < m_submeshes.getSize(); i++) { *m_submeshes[i].indices = *other.m_submeshes[i].indices; m_submeshes[i].material = other.m_submeshes[i].material; } }
void MeshBase::append(const MeshBase& other) { FW_ASSERT(&other != this); FW_ASSERT(isInMemory()); FW_ASSERT(other.isInMemory()); Array<bool> dstAttribUsed(NULL, numAttribs()); for (int i = 0; i < numAttribs(); i++) dstAttribUsed[i] = false; Array<Vec2i> copy; Array<Vec2i> convert; for (int i = 0; i < other.numAttribs(); i++) { const AttribSpec& src = other.attribSpec(i); for (int j = 0; j < numAttribs(); j++) { const AttribSpec& dst = attribSpec(j); if (src.type != dst.type || dstAttribUsed[j]) continue; if (src.format != dst.format || src.length != dst.length) convert.add(Vec2i(i, j)); else { for (int k = 0; k < src.bytes; k++) copy.add(Vec2i(src.offset + k, dst.offset + k)); } dstAttribUsed[j] = true; break; } } int oldNumVertices = m_numVertices; resizeVertices(oldNumVertices + other.m_numVertices); for (int i = 0; i < other.m_numVertices; i++) { if (copy.getSize()) { const U8* src = &other.m_vertices[i * other.m_stride]; U8* dst = &m_vertices[(i + oldNumVertices) * m_stride]; for (int j = 0; j < copy.getSize(); j++) dst[copy[j].y] = src[copy[j].x]; } for (int j = 0; j < convert.getSize(); j++) setVertexAttrib(i + oldNumVertices, convert[j].y, other.getVertexAttrib(i, convert[j].x)); } int oldNumSubmeshes = numSubmeshes(); resizeSubmeshes(oldNumSubmeshes + other.numSubmeshes()); for (int i = 0; i < other.numSubmeshes(); i++) { const Submesh& src = other.m_submeshes[i]; Submesh& dst = m_submeshes[i + oldNumSubmeshes]; dst.indices->reset(src.indices->getSize()); for (int j = 0; j < src.indices->getSize(); j++) dst.indices->set(j, src.indices->get(j) + oldNumVertices); dst.material = src.material; } }