// gets all materials and the labels on them in the project, compares them against a filter,
        // and then adds them to the list of materials to be used in this window
        public static void GetMaterials(ref List <ChiselMaterialBrowserTile> materials,
                                        ref List <ChiselMaterialBrowserTile> usedMaterials,
                                        ref List <string> labels,
                                        ref List <CSGModel> models,
                                        bool usingLabel,
                                        string searchLabel = "",
                                        string searchText  = "")
        {
            if (usingLabel && searchLabel == string.Empty)
            {
                Debug.LogError($"usingLabel set to true, but no search term was given. This may give undesired results.");
            }

            materials.ForEach(e =>
            {
                e.Dispose();
                e = null;
            });

            materials.Clear();

            // exclude the label search tag if we arent searching for a specific label right now
            string search = usingLabel ? $"l:{searchLabel} {searchText}" : $"{searchText}";

            string[] guids = AssetDatabase.FindAssets($"t:Material {search}");

            // assemble preview tiles
            foreach (string id in guids)
            {
                ChiselMaterialBrowserTile browserTile = new ChiselMaterialBrowserTile(id);   //, ref cache );

                if (labels != null)
                {
                    // add any used labels we arent currently storing
                    foreach (string label in browserTile.labels)
                    {
                        if (!labels.Contains(label))
                        {
                            labels.Add(label);
                        }
                    }
                }

                // check each entry against a filter to exclude certain entries
                if (IsValidEntry(browserTile))
                {
                    // if we have the material already, skip, else add it
                    materials.Add(browserTile);
                }
            }

            AssetPreview.SetPreviewTextureCacheSize(materials.Count + 1);

            models = Object.FindObjectsOfType <CSGModel>().ToList();

            PopulateUsedMaterials(ref usedMaterials, ref models, searchLabel, searchText);
        }
        // checks a path and returns true/false if a material is ignored or not
        public static bool IsValidEntry(ChiselMaterialBrowserTile tile)
        {
            // these are here to clean things up a little bit and make it easier to read

            bool PathContains(string path)
            {
                return(tile.path.ToLower().Contains(path));
            }

            // checks for any shaders we want to exclude
            bool HasInvalidShader()
            {
                string shader = tile.shaderName.ToLower();

                string[] excludedShaders = new string[]
                {
                    "skybox/"
                };

                return(shader.Contains(excludedShaders[0]));
            }

            string chiselPath = "packages/com.chisel.components/package resources/";

            string[] ignoredEntries = new string[]
            {
                "packages/com.unity.searcher/",        // 0, we ignore this to get rid of the built-in font materials
                "packages/com.unity.entities/",        // 1, we ignore this to get rid of the entities materials
                $"{chiselPath}preview materials/",     // 2, these are tool textures, so we are ignoring them
            };

            // if the path contains any of the ignored paths, then this will return false
            bool valid = !PathContains(ignoredEntries[0]) &&
                         !PathContains(ignoredEntries[1]) &&
                         !PathContains(ignoredEntries[2]) &&
                         !HasInvalidShader();    // also check the shader

            return(valid);
        }