Exemple #1
0
void MeshBase::addAttribs(const MeshBase& other)
{
    int num = other.numAttribs();
    for (int i = 0; i < num; i++)
    {
        const AttribSpec& spec = other.attribSpec(i);
        addAttrib(spec.type, spec.format, spec.length);
    }
}
Exemple #2
0
bool MeshBase::isCompatible(const MeshBase& other) const
{
    if (numAttribs() != other.numAttribs())
        return false;

    for (int i = 0; i < numAttribs(); i++)
    {
        const AttribSpec& a = attribSpec(i);
        const AttribSpec& b = other.attribSpec(i);
        if (a.type != b.type || a.format != b.format || a.length != b.length)
            return false;
    }
    return true;
}
Exemple #3
0
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;
    }
}