Assets/Trismegistus/Core/Tools/CombineMesh.cs
/// <summary>
///     Combines all meshes by unique main material for each LOD (if exists)
/// </summary>
/// <param name="root">Parent gameObject</param>
/// <param name="settings"></param>
/// <param name="debug"></param>
Combines all meshes by unique main material for each LOD (if exists)
Combines all meshes by unique main material for each LOD ( if exists )
public static void CombineAll(GameObject root, CombineMeshSettings settings, bool debug = false) {
            var lodGroup = root.GetComponent<LODGroup>();
            var gameObjects = new List<Renderer[]>();
            if (lodGroup != null) {
                if (debug) Debug.Log($"Found {lodGroup.lodCount} LODs, adding renderers for for separate combining");
                gameObjects.AddRange(lodGroup.GetLODs()
                    .Select(loD => loD.renderers));
            }
            else {
                if (debug) Debug.Log("No LODGroup found, adding all renderers");
                gameObjects.Add(root.GetComponentsInChildren<Renderer>());
            }
            foreach (var meshRenderers in gameObjects) {
                var renderers = meshRenderers
                    .Where(r => r != null)
                    .Where(r => r.sharedMaterial != null)
                    .ToArray();
                if (settings.SkipMultiMaterials) {
                    var size = renderers.Length;
                    renderers = renderers.Where(r => r.sharedMaterials.Count() == 1).ToArray();
                    if (debug) Debug.Log($"Excluding {size-renderers.Length} renderers with multiple materials");
                }
                CombineGroup(
                    renderers,
                    settings , debug);
            }
        }
public static void CombineAll ( GameObject root , CombineMeshSettings settings , bool debug = false ) { var lodGroup = root . GetComponent < LODGroup > ( ) ; var gameObjects = new List < Renderer [ ] > ( ) ; if ( lodGroup != null ) { if ( debug ) Debug . Log ( $" Found  { lodGroup . lodCount }  LODs, adding renderers for for separate combining " ) ; gameObjects . AddRange ( lodGroup . GetLODs ( ) . Select ( loD => loD . renderers ) ) ; } else { if ( debug ) Debug . Log ( " " ) ; gameObjects . Add ( root . GetComponentsInChildren < Renderer > ( ) ) ; } foreach ( var meshRenderers in gameObjects ) { var renderers = meshRenderers . Where ( r => r != null ) . Where ( r => r . sharedMaterial != null ) . ToArray ( ) ; if ( settings . SkipMultiMaterials ) { var size = renderers . Length ; renderers = renderers . Where ( r => r . sharedMaterials . Count ( ) == 1 ) . ToArray ( ) ; if ( debug ) Debug . Log ( $" Excluding  { size - renderers . Length }  renderers with multiple materials " ) ; } CombineGroup ( renderers , settings , debug ) ; } }
Combines all meshes by unique main material for each LOD (if exists)
Combines all meshes by unique main material for each LOD ( if exists )
root
GameObject
None
settings
CombineMeshSettings
None
debug
bool
None