Assets/Trismegistus/Core/Tools/CombineMesh.cs
/// <summary>
///     Combines meshes from specific renderers by main material
/// </summary>
/// <param name="renderers"></param>
/// <param name="settings"></param>
/// <param name="debug"></param>
Combines meshes from specific renderers by main material
Combines meshes from specific renderers by main material
public static void CombineGroup(Renderer[] renderers, CombineMeshSettings settings, bool debug = false) {
            if (renderers == null || renderers.Length < 1) {
                if (debug) Debug.Log("No renderers found");
                return;
            }
            if (debug) Debug.Log($"Found {renderers.Length} renderers");
            var uniqueMaterials = renderers.Select(x => x.sharedMaterial).Distinct();
            var enumerable = uniqueMaterials as Material[] ?? uniqueMaterials.ToArray();
            if (debug) Debug.Log($"Found {enumerable.Count()} unique materials");
            var matMeshes = enumerable.Select(mat => renderers.Where(x => x.sharedMaterial == mat)
                    .Select(x => x.GetComponent<MeshFilter>())
                    .ToArray())
                .ToList();
            foreach (var meshFilters in matMeshes) Combine(meshFilters.Where(mf => mf != null).ToArray(), settings, debug);
        }
public static void CombineGroup ( Renderer [ ] renderers , CombineMeshSettings settings , bool debug = false ) { if ( renderers == null || renderers . Length < 1 ) { if ( debug ) Debug . Log ( " " ) ; return ; } if ( debug ) Debug . Log ( $" Found  { renderers . Length }  renderers " ) ; var uniqueMaterials = renderers . Select ( x => x . sharedMaterial ) . Distinct ( ) ; var enumerable = uniqueMaterials as Material [ ] ?? uniqueMaterials . ToArray ( ) ; if ( debug ) Debug . Log ( $" Found  { enumerable . Count ( ) }  unique materials " ) ; var matMeshes = enumerable . Select ( mat => renderers . Where ( x => x . sharedMaterial == mat ) . Select ( x => x . GetComponent < MeshFilter > ( ) ) . ToArray ( ) ) . ToList ( ) ; foreach ( var meshFilters in matMeshes ) Combine ( meshFilters . Where ( mf => mf != null ) . ToArray ( ) , settings , debug ) ; }
Combines meshes from specific renderers by main material
Combines meshes from specific renderers by main material
renderers
Renderer[]
None
settings
CombineMeshSettings
None
debug
bool
None