Ejemplo n.º 1
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var cfgs = AssetDatabase.FindAssets("t:TextureArrayConfig");

            for (int i = 0; i < cfgs.Length; ++i)
            {
                var asset = AssetDatabase.GUIDToAssetPath(cfgs[i]);
                var cfg   = AssetDatabase.LoadAssetAtPath <TextureArrayConfig>(asset);
                if (cfg != null)
                {
                    int hash = GetNewHash(cfg);
                    if (hash != cfg.hash)
                    {
                        cfg.hash = hash;
                        EditorUtility.SetDirty(cfg);
                        try
                        {
                            sIsPostProcessing = true;
                            TextureArrayConfigEditor.CompileConfig(cfg);
                        }
                        finally
                        {
                            sIsPostProcessing = false;
                            AssetDatabase.Refresh();
                            AssetDatabase.SaveAssets();
                            MicroSplatTerrain.SyncAll();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void Setup(HashSet <GStylizedTerrain> terrains)
        {
            GSplatPrototypeGroup           splats    = null;
            IEnumerator <GStylizedTerrain> iTerrains = terrains.GetEnumerator();

            while (iTerrains.MoveNext())
            {
                GStylizedTerrain t = iTerrains.Current;
                if (t == null)
                {
                    continue;
                }
                Setup(t);
                if (t.TerrainData != null && t.TerrainData.Shading.Splats != null)
                {
                    if (splats == null)
                    {
                        splats = t.TerrainData.Shading.Splats;
                    }
                }
            }

            if (GMicroSplatIntegrationSettings.Instance.InitTextureEntries)
            {
                if (splats != null && currentTAConfig != null)
                {
                    currentTAConfig.sourceTextures.Clear();
                    currentTAConfig.sourceTextures2.Clear();
                    currentTAConfig.sourceTextures3.Clear();
                    foreach (GSplatPrototype p in splats.Prototypes)
                    {
                        TextureArrayConfig.TextureEntry entry = new TextureArrayConfig.TextureEntry();
                        entry.diffuse = p.Texture;
                        entry.normal  = p.NormalMap;
                        currentTAConfig.sourceTextures.Add(entry);
                        currentTAConfig.sourceTextures2.Add(entry);
                        currentTAConfig.sourceTextures3.Add(entry);
                    }
                    TextureArrayConfigEditor.CompileConfig(currentTAConfig);
                }
            }

            iTerrains.Reset();
            while (iTerrains.MoveNext())
            {
                GStylizedTerrain t = iTerrains.Current;
                if (t == null)
                {
                    continue;
                }
                t.PushControlTexturesToMicroSplat();
            }
        }
Ejemplo n.º 3
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var cfgs = Resources.FindObjectsOfTypeAll <TextureArrayConfig>();

            for (int i = 0; i < cfgs.Length; ++i)
            {
                var cfg  = cfgs[i];
                int hash = cfg.GetNewHash();
                if (hash != cfg.hash)
                {
                    cfg.hash = hash;
                    Debug.Log("Rebuilding texture array");
                    TextureArrayConfigEditor.CompileConfig(cfg);
                    EditorUtility.SetDirty(cfg);
                }
            }
        }
    static void RegenAllArrays()
    {
        var configs = AssetDatabase.FindAssets("t:TextureArrayConfig");

        foreach (var c in configs)
        {
            var path = AssetDatabase.GUIDToAssetPath(c);
            TextureArrayConfig cfg = AssetDatabase.LoadAssetAtPath <TextureArrayConfig> (path);
            if (cfg != null)
            {
                Debug.Log("Recompressing " + path);
                TextureArrayConfigEditor.CompileConfig(cfg);
            }
            Resources.UnloadAsset(cfg);
            cfg = null;
        }
    }
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var cfgs = AssetDatabase.FindAssets("t:TextureArrayConfig");

            for (int i = 0; i < cfgs.Length; ++i)
            {
                var asset = AssetDatabase.GUIDToAssetPath(cfgs[i]);
                var cfg   = AssetDatabase.LoadAssetAtPath <TextureArrayConfig>(asset);
                if (cfg != null)
                {
                    int hash = GetNewHash(cfg);
                    if (hash != cfg.hash)
                    {
                        cfg.hash = hash;
                        TextureArrayConfigEditor.CompileConfig(cfg);
                        EditorUtility.SetDirty(cfg);
                    }
                }
            }
        }
        private static void CheckConfigForUpdates(TextureArrayConfig cfg)
        {
            int hash = GetNewHash(cfg);

            if (hash != cfg.hash)
            {
                cfg.hash = hash;
                EditorUtility.SetDirty(cfg);
                try
                {
                    sIsPostProcessing = true;
                    TextureArrayConfigEditor.CompileConfig(cfg);
                }
                finally
                {
                    sIsPostProcessing = false;
                    AssetDatabase.Refresh();
                    AssetDatabase.SaveAssets();
                    MicroSplatTerrain.SyncAll();
                }
            }
        }
Ejemplo n.º 7
0
        private static void InjectTerrainGUI(GStylizedTerrain terrain, int order)
        {
            if (order != 3)
            {
                return;
            }
            string label = "MicroSplat Integration";
            string id    = "terrain-gui-microsplat-integration";

            GEditorCommon.Foldout(label, false, id, () =>
            {
                bool useMS = terrain.TerrainData.Shading.ShadingSystem == GShadingSystem.MicroSplat;
                useMS      = EditorGUILayout.Toggle("Enable", useMS);
                terrain.TerrainData.Shading.ShadingSystem =
                    useMS ?
                    GShadingSystem.MicroSplat :
                    GShadingSystem.Polaris;

                GEditorCommon.Separator();
                EditorGUILayout.LabelField("Setup", EditorStyles.boldLabel);

                GMicroSplatIntegrationSettings settings = GMicroSplatIntegrationSettings.Instance;
                string dir = settings.DataDirectory;
                GEditorCommon.BrowseFolderMiniButton("Data Directory", ref dir);
                settings.DataDirectory    = dir;
                settings.ShaderNamePrefix = EditorGUILayout.TextField("Shader Name Prefix", settings.ShaderNamePrefix);
                if (GUILayout.Button("Setup"))
                {
                    MicroSplatPolarisMesh pm = terrain.gameObject.GetComponent <MicroSplatPolarisMesh>();
                    if (pm != null)
                    {
                        GUtilities.DestroyObject(pm);
                    }

                    MeshRenderer[] renderers         = terrain.Internal_ChunkRoot.GetComponentsInChildren <MeshRenderer>();
                    List <MeshRenderer> rendererList = new List <MeshRenderer>();
                    rendererList.AddRange(renderers);

                    MicroSplatPolarisMeshEditor.PolarisData data = new MicroSplatPolarisMeshEditor.PolarisData();
                    data.basePath           = settings.DataDirectory;
                    data.name               = string.Format("{0}_{1}", settings.ShaderNamePrefix, terrain.TerrainData.Id);
                    data.additionalKeywords = new string[0];
                    data.rootObject         = terrain.gameObject;
                    data.renderers          = rendererList;
                    MicroSplatPolarisMeshEditor.Setup(data);
                    terrain.PushControlTexturesToMicroSplat();

                    if (terrain.TerrainData.Shading.Splats == null ||
                        terrain.TerrainData.Shading.Splats.Prototypes.Count == 0)
                    {
                        return;
                    }

                    pm = terrain.gameObject.GetComponent <MicroSplatPolarisMesh>();
                    if (pm == null)
                    {
                        return;
                    }

                    string materialPath       = AssetDatabase.GetAssetPath(pm.templateMaterial);
                    string directory          = Path.GetDirectoryName(materialPath);
                    string configPath         = string.Format("{0}/MicroSplatConfig.asset", directory);
                    TextureArrayConfig config = AssetDatabase.LoadAssetAtPath <TextureArrayConfig>(configPath);
                    if (config != null)
                    {
                        terrain.TerrainData.Shading.MicroSplatTextureArrayConfig = config;

                        GSplatPrototypeGroup splats       = terrain.TerrainData.Shading.Splats;
                        List <GSplatPrototype> prototypes = splats.Prototypes;
                        for (int i = 0; i < prototypes.Count; ++i)
                        {
                            TextureArrayConfig.TextureEntry entry = new TextureArrayConfig.TextureEntry();
                            entry.diffuse           = prototypes[i].Texture;
                            entry.normal            = prototypes[i].NormalMap;
                            entry.aoChannel         = TextureArrayConfig.TextureChannel.G;
                            entry.heightChannel     = TextureArrayConfig.TextureChannel.G;
                            entry.smoothnessChannel = TextureArrayConfig.TextureChannel.G;
                            entry.alphaChannel      = TextureArrayConfig.TextureChannel.G;
                            config.sourceTextures.Add(entry);
                        }

                        TextureArrayConfigEditor.CompileConfig(config);
                        terrain.PullMaterialAndSplatMapsFromMicroSplat();
                    }
                }
            });
        }