User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

Combine at Runtime

Easy Combine could, of course, also be used at runtime. But because some the features are not accessible at runtime, such as lightmap unwrapping etc. one needs to write some lines of code to implement a custom mesh grouper that calls Easy Combine API methods.

To allow a grouping of large meshes one have to check the vertex pointer for overflows (values that exceed the range of the 16-bit integer):

private static List<List<GameObject>> GetCombineGroups(IList<GameObject> selectedObjects)
{
      List<List<GameObject>> groups = new List<List<GameObject>>();
      groups.Add(new List<GameObject>());
      List<GameObject> active = groups[0];

      int vertexCount = 0;

      foreach (GameObject obj in selectedObjects)
      {
           Mesh mesh = obj.GetMesh();

           if (mesh != null)
           {
                int count = mesh.vertexCount;
                if (vertexCount + count < UInt16.MaxValue)
                {
                    active.Add(obj);

                    vertexCount += count;
                }
                else
                {
                    active = new List<GameObject>();
                    active.Add(obj);

                    groups.Add(active);

                    vertexCount = count;
                }
            }
        }

        return groups;
   }

 

The combining can be started as follows:

    List<List<GameObject>> groups = GetCombineGroups(objectsToCombine);



    foreach(List<GameObject> group in groups)
    {
        GameObject combinedObject = EasyCombine.Combine(group, UV2Mode.Keep, false, false);
    } 

 

Copyright © 2020 by Sycoforge Technologies. All Rights Reserved.