public void TryThis()
        {
            bool save = false;

            if (res == null)
            {
                save     = true;
                res      = ScriptableObject.CreateInstance <ClusterMatResources>();
                res.name = "SceneManager";
                res.clusterProperties = new List <SceneStreaming>();
            }

            SceneStreaming    property = new SceneStreaming();
            SceneStreamLoader loader   = new SceneStreamLoader();

            loader.fsm    = new FileStream(ClusterMatResources.infosPath + modelName + ".mpipe", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            property.name = modelName;
            int containIndex = -1;

            for (int i = 0; i < res.clusterProperties.Count; ++i)
            {
                if (property.name == res.clusterProperties[i].name)
                {
                    containIndex = i;
                    break;
                }
            }
            LODGroup[] groups = GetComponentsInChildren <LODGroup>();
            Dictionary <MeshRenderer, bool> lowLevelDict = new Dictionary <MeshRenderer, bool>();

            foreach (var i in groups)
            {
                LOD[] lods = i.GetLODs();
                for (int j = 1; j < lods.Length; ++j)
                {
                    foreach (var k in lods[j].renderers)
                    {
                        if (k.GetType() == typeof(MeshRenderer))
                        {
                            lowLevelDict.Add(k as MeshRenderer, true);
                        }
                    }
                }
            }
            CombinedModel model = ProcessCluster(GetComponentsInChildren <MeshRenderer>(false), ref loader, lowLevelDict);

            loader.clusterCount = ClusterGenerator.GenerateCluster(model.allPoints, model.allMatIndex, model.bound, voxelCount, containIndex < 0 ? res.clusterProperties.Count : containIndex, ref loader);

            res.maximumMaterialCount = Mathf.Max(1, res.maximumMaterialCount);
            res.maximumMaterialCount = Mathf.Max(res.maximumMaterialCount, loader.allProperties.Length);
            if (containIndex < 0)
            {
                res.clusterProperties.Add(property);
            }
            else
            {
                res.clusterProperties[containIndex] = property;
            }
            if (save)
            {
                AssetDatabase.CreateAsset(res, "Assets/SceneManager.asset");
            }
            else
            {
                EditorUtility.SetDirty(res);
            }
            loader.SaveAll();
            loader.Dispose();
        }
Exemple #2
0
        public void TryThis()
        {
            string fileName = ClusterMatResources.infosPath + modelName + ".mpipe";

            if (!property)
            {
                Debug.LogError("Property Empty!");
            }

            if (string.IsNullOrEmpty(modelName))
            {
                Debug.LogError("Name Empty!");
                return;
            }
            if (File.Exists(fileName))
            {
                Debug.LogError("File Already Exists!");
                return;
            }


            bool save = false;

            if (!res)
            {
                res = AssetDatabase.LoadAssetAtPath <ClusterMatResources>("Assets/SceneManager.asset");
            }
            if (!res)
            {
                save     = true;
                res      = ScriptableObject.CreateInstance <ClusterMatResources>();
                res.name = "SceneManager";
            }
            SceneStreamLoader loader = new SceneStreamLoader();

            loader.fsm        = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            property.fileName = modelName;
            LODGroup[] groups = GetComponentsInChildren <LODGroup>();
            Dictionary <MeshRenderer, bool> lowLevelDict = new Dictionary <MeshRenderer, bool>();

            foreach (var i in groups)
            {
                LOD[] lods = i.GetLODs();
                for (int j = 1; j < lods.Length; ++j)
                {
                    foreach (var k in lods[j].renderers)
                    {
                        if (k.GetType() == typeof(MeshRenderer))
                        {
                            lowLevelDict.Add(k as MeshRenderer, true);
                        }
                    }
                }
            }
            CombinedModel model = ProcessCluster(GetComponentsInChildren <MeshRenderer>(false), ref loader, lowLevelDict);

            loader.clusterCount = ClusterGenerator.GenerateCluster(model.allPoints, model.allMatIndex, model.bound, voxelCount, ref loader);

            res.maximumMaterialCount = Mathf.Max(1, res.maximumMaterialCount);
            res.maximumMaterialCount = Mathf.Max(res.maximumMaterialCount, loader.allProperties.Length);
            if (save)
            {
                AssetDatabase.CreateAsset(res, "Assets/SceneManager.asset");
            }
            else
            {
                EditorUtility.SetDirty(res);
            }
            loader.SaveAll();
            loader.Dispose();
        }