コード例 #1
0
        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();
        }
コード例 #2
0
        public void GenerateAsync()
        {
            var resources = ClusterMatResources.current;

            allStrings[0] = ClusterMatResources.infosPath;
            allStrings[1] = fileName;
            allStrings[2] = ".mpipe";
            sb.Combine(allStrings);
            loader.fsm = new FileStream(sb.str, FileMode.Open, FileAccess.Read);
            if (!loader.LoadAll(resources.maximumClusterCount - SceneController.baseBuffer.prepareClusterCount))
            {
                if (!waiting)
                {
                    loading = false;
                }
                state = State.Unloaded;
                int required = SceneController.baseBuffer.prepareClusterCount + loader.clusterCount;
                int actual   = resources.maximumClusterCount;
                Debug.LogError("No Enough Model Space! Required: " + required + " Actual: " + actual);
                loader.Dispose();
                return;
            }
            materialIndexBuffer = resources.vmManager.SetMaterials(loader.allProperties.Length);
            for (int i = 0; i < loader.cluster.Length; ++i)
            {
                loader.cluster[i].index = propertyCount;
            }
            materialProperties = new NativeArray <VirtualMaterial.MaterialProperties>(loader.allProperties.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            VirtualMaterial.MaterialProperties *propertiesPtr = materialProperties.Ptr();
            textureLoadingFlags.Clear();
            //Update Material
            for (int i = 0; i < materialProperties.Length; ++i)
            {
                ref var currProp = ref propertiesPtr[i];
                currProp = loader.allProperties[i];
                if (currProp._MainTex >= 0)
                {
                    currProp._MainTex = resources.rgbaPool.GetTex(loader.albedoGUIDs[currProp._MainTex], ref textureLoadingFlags);
                }
                if (currProp._SecondaryMainTex >= 0)
                {
                    currProp._SecondaryMainTex = resources.rgbaPool.GetTex(loader.secondAlbedoGUIDs[currProp._SecondaryMainTex], ref textureLoadingFlags);
                }
                if (currProp._BumpMap >= 0)
                {
                    currProp._BumpMap = resources.rgbaPool.GetTex(loader.normalGUIDs[currProp._BumpMap], ref textureLoadingFlags, true);
                }
                if (currProp._SecondaryBumpMap >= 0)
                {
                    currProp._SecondaryBumpMap = resources.rgbaPool.GetTex(loader.secondNormalGUIDs[currProp._SecondaryBumpMap], ref textureLoadingFlags, true);
                }

                if (currProp._SpecularMap >= 0)
                {
                    currProp._SpecularMap = resources.rgbaPool.GetTex(loader.smoGUIDs[currProp._SpecularMap], ref textureLoadingFlags);
                }
                if (currProp._SecondarySpecularMap >= 0)
                {
                    currProp._SecondarySpecularMap = resources.rgbaPool.GetTex(loader.secondSpecGUIDs[currProp._SecondarySpecularMap], ref textureLoadingFlags);
                }
                if (currProp._EmissionMap >= 0)
                {
                    currProp._EmissionMap = resources.emissionPool.GetTex(loader.emissionGUIDs[currProp._EmissionMap], ref textureLoadingFlags);
                }
                if (currProp._HeightMap >= 0)
                {
                    currProp._HeightMap = resources.heightPool.GetTex(loader.heightGUIDs[currProp._HeightMap], ref textureLoadingFlags);
                }
            }
コード例 #3
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();
        }