Example #1
0
    static Mesh MergeSubsets(List <Subset> aSubsets, int aLightmapID)
    {
        Mesh               result       = new Mesh();
        Subset             resultSubset = new Subset();
        List <List <int> > indices      = new List <List <int> >();

        for (int i = 0; i < aSubsets.Count; ++i)
        {
            if (aSubsets[i].mLightmapID != aLightmapID)
            {
                continue;
            }

            int startID = resultSubset.Count;
            resultSubset.Add(aSubsets[i]);

            List <int> subIndices = new List <int>();
            for (int t = 0; t < aSubsets[i].mIndices.Count; t += 1)
            {
                subIndices.Add(startID + aSubsets[i].mIndices[t]);
            }
            indices.Add(subIndices);
        }
        // cap it off if we used that category of data at all!
        resultSubset.CheckArrays();

        result.vertices = resultSubset.mPoints.ToArray();
        result.normals  = resultSubset.mNormals.ToArray();
        result.uv       = resultSubset.mUVs.ToArray();
        result.tangents = resultSubset.mTangents.ToArray();
        result.colors   = resultSubset.mColors.ToArray();
#if UNITY_5
        result.uv2 = resultSubset.mLightUVs.ToArray();
#else
        result.uv1 = resultSubset.mLightUVs.ToArray();
#endif

        result.subMeshCount = aSubsets.Count;
        for (int i = 0; i < indices.Count; ++i)
        {
            result.SetIndices(indices[i].ToArray(), MeshTopology.Triangles, i);
        }
        result.RecalculateBounds();

        return(result);
    }