コード例 #1
0
        public override void Apply()
        {
            if (SplineCreator == null)
            {
                return;
            }
            if (falloffTexture != null)
            {
                Object.DestroyImmediate(falloffTexture);
            }
            Internal_UpdateFalloffTexture();
            int groupId = SplineCreator.GroupId;
            IEnumerator <GStylizedTerrain> terrains = GStylizedTerrain.ActiveTerrains.GetEnumerator();

            while (terrains.MoveNext())
            {
                GStylizedTerrain t = terrains.Current;
                if (groupId < 0 ||
                    (groupId >= 0 && groupId == t.GroupId))
                {
                    Apply(t);
                }
            }
            GStylizedTerrain.MatchEdges(groupId);
        }
コード例 #2
0
        public static void Restore(string backupName)
        {
            List <GStylizedTerrain> terrains = new List <GStylizedTerrain>(GStylizedTerrain.ActiveTerrains);

            for (int i = 0; i < terrains.Count; ++i)
            {
                GStylizedTerrain t = terrains[i];
                if (t.TerrainData == null)
                {
                    continue;
                }
                try
                {
#if UNITY_EDITOR
                    GCommonGUI.ProgressBar("Restoring", "Restoring " + t.name + " data...", 1f);
#endif
                    RestoreTerrain(t, backupName);
                }
                catch (System.Exception e)
                {
                    Debug.LogError(string.Format("Error on restoring {0}: {1}", e.ToString(), t.name));
                }
                finally
                {
#if UNITY_EDITOR
                    GCommonGUI.ClearProgressBar();
#endif
                }
            }
            GStylizedTerrain.MatchEdges(-1);
            GUndoCompatibleBuffer.Instance.CurrentBackupName = backupName;
        }
コード例 #3
0
        private void FinishingUp()
        {
#if UNITY_EDITOR
            GCommonGUI.ProgressBar("Finishing Up", "Matching geometry...", 1f);
#endif
            GStylizedTerrain.ConnectAdjacentTiles();
            GStylizedTerrain.MatchEdges(-1);
            Root.gameObject.SetActive(false);
#if UNITY_EDITOR
            GCommonGUI.ClearProgressBar();
#endif
        }
コード例 #4
0
        private void DoBulkImport()
        {
            string[]         guid     = AssetDatabase.FindAssets("t:Texture2D", new string[] { Directory });
            List <Texture2D> textures = new List <Texture2D>();

            for (int i = 0; i < guid.Length; ++i)
            {
                string    path = AssetDatabase.GUIDToAssetPath(guid[i]);
                Texture2D tex  = AssetDatabase.LoadAssetAtPath <Texture2D>(path);
                textures.Add(tex);
            }

            GCommon.ForEachTerrain(
                BulkImportGroupId,
                (t) =>
            {
                if (t == null || t.TerrainData == null)
                {
                    return;
                }

                GBackup.TryCreateInitialBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);

                Texture2D hm   = textures.Find(tex => tex.name.StartsWith("HeightMap") && tex.name.EndsWith(t.TerrainData.Id));
                Texture2D mkm  = textures.Find(tex => tex.name.StartsWith("MaskMap") && tex.name.EndsWith(t.TerrainData.Id));
                Texture2D vm   = textures.Find(tex => tex.name.StartsWith("VisibilityMap") && tex.name.EndsWith(t.TerrainData.Id));
                Texture2D am   = textures.Find(tex => tex.name.StartsWith("AlbedoMap") && tex.name.EndsWith(t.TerrainData.Id));
                Texture2D mm   = textures.Find(tex => tex.name.StartsWith("MetallicMap") && tex.name.EndsWith(t.TerrainData.Id));
                Texture2D[] cm = new Texture2D[t.TerrainData.Shading.SplatControlMapCount];
                for (int i = 0; i < cm.Length; ++i)
                {
                    cm[i] = textures.Find(tex => tex.name.StartsWith("ControlMap" + i.ToString()) && tex.name.EndsWith(t.TerrainData.Id));
                }

                GTextureImporter importer = new GTextureImporter();
                importer.Terrain          = t;
                importer.DesData          = t.TerrainData;
                importer.HeightMap        = hm;
                importer.MaskMap          = mkm;
                importer.VisibilityMap    = vm;
                importer.AlbedoMap        = am;
                importer.MetallicMap      = mm;
                importer.SplatControlMaps = cm;
                importer.Import();

                GBackup.TryCreateBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);
            });

            GStylizedTerrain.MatchEdges(BulkImportGroupId);
        }
コード例 #5
0
        private void DrawMatchEdgeGUI()
        {
            string label = "Match Edge";
            string id    = "match-edge" + instance.GetInstanceID();

            GEditorCommon.Foldout(label, false, id, () =>
            {
                if (GUILayout.Button("Match"))
                {
                    GAnalytics.Record(GAnalytics.GROUP_MATCH_EDGE);
                    GStylizedTerrain.MatchEdges(instance.GroupId);
                    GUtilities.MarkCurrentSceneDirty();
                }
            });
        }
コード例 #6
0
ファイル: GTerrainGroup.cs プロジェクト: ComradeCrunchy/Ranch
        public void OverrideGeometry()
        {
            IEnumerator <GStylizedTerrain> terrains = GStylizedTerrain.ActiveTerrains.GetEnumerator();

            while (terrains.MoveNext())
            {
                if (terrains.Current.TerrainData != null &&
                    (terrains.Current.GroupId == GroupId || GroupId < 0))
                {
                    GeometryOverride.Override(terrains.Current.TerrainData.Geometry);
                    terrains.Current.TerrainData.Geometry.SetRegionDirty(new Rect(0, 0, 1, 1));
                    terrains.Current.TerrainData.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced);
                }
            }
            GStylizedTerrain.MatchEdges(GroupId);
        }
コード例 #7
0
        private void DoBulkImport()
        {
            string        ext   = BitDepth == GBitDepth.Bit8 ? "raw" : "r16";
            List <string> files = new List <string>(Directory.GetFiles(DataDirectory));

            files.RemoveAll(f => !f.EndsWith(ext));

            GCommon.ForEachTerrain(
                BulkImportGroupId,
                (t) =>
            {
                if (t == null || t.TerrainData == null)
                {
                    return;
                }

                string file = files.Find(
                    s =>
                {
                    string f = Path.GetFileNameWithoutExtension(s);
                    return(f.StartsWith(BitDepth == GBitDepth.Bit8 ? "RAW8" : "RAW16") && f.EndsWith(t.TerrainData.Id));
                });
                if (string.IsNullOrEmpty(file))
                {
                    return;
                }

                GBackup.TryCreateInitialBackup(HISTORY_PREFIX, t, GCommon.HeightMapAndFoliageResourceFlags);

                GRawImporter importer     = new GRawImporter();
                importer.Terrain          = t;
                importer.DesData          = t.TerrainData;
                importer.BitDepth         = BitDepth;
                importer.UseRawResolution = UseRawResolution;
                importer.FilePath         = file;
                importer.Import();

                GBackup.TryCreateBackup(HISTORY_PREFIX, t, GCommon.HeightMapAndFoliageResourceFlags);
            });
            GStylizedTerrain.MatchEdges(BulkImportGroupId);
        }
コード例 #8
0
        private void DrawGeometryGUI()
        {
            string label = "Geometry";
            string id    = "geometry" + data.Id;

            bool deferredUpdate = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(DEFERRED_UPDATE_KEY), false);

            GenericMenu menu = new GenericMenu();

            menu.AddItem(
                new GUIContent("Reset"),
                false,
                () => { ConfirmAndResetGeometry(); });
            menu.AddItem(
                new GUIContent("Update"),
                false,
                () => { data.Geometry.SetRegionDirty(GCommon.UnitRect); data.SetDirty(GTerrainData.DirtyFlags.Geometry); });
            menu.AddItem(
                new GUIContent("Match Edges"),
                false,
                () => { terrain.MatchEdges(); });
            menu.AddItem(
                new GUIContent("Clean Up"),
                false,
                () => { data.Geometry.CleanUp(); });

            if (geometryAdditionalContextAction != null && geometryAdditionalContextAction.Count > 0)
            {
                menu.AddSeparator(null);
                for (int i = 0; i < geometryAdditionalContextAction.Count; ++i)
                {
                    GGenericMenuItem item = geometryAdditionalContextAction[i];
                    menu.AddItem(
                        new GUIContent(item.Name),
                        item.IsOn,
                        item.Action);
                }
            }

            menu.AddSeparator(null);
            menu.AddItem(
                new GUIContent("Toggle Deferred Update"),
                deferredUpdate,
                () =>
            {
                deferredUpdate = !deferredUpdate;
                EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(DEFERRED_UPDATE_KEY), deferredUpdate);
            });
            menu.AddSeparator(null);
            menu.AddItem(
                new GUIContent("Advanced/Remove Height Map"),
                false,
                () => { ConfirmAndRemoveHeightMap(); });
            List <string> warnings = new List <string>();

            if (terrain != null &&
                terrain.geometryVersion < GStylizedTerrain.GEOMETRY_VERSION_CHUNK_POSITION_AT_CHUNK_CENTER)
            {
                warnings.Add("- Chunk position placement has been changed for better level streaming and baking. Go to CONTEXT>Update to re-generate the terrain.");
            }

#if !GRIFFIN_BURST
            warnings.Add("- Install Burst Compiler (com.unity.burst) to speed up generation.");
#endif
#if !GRIFFIN_EDITOR_COROUTINES
            if (data.Geometry.AllowTimeSlicedGeneration == true)
            {
                warnings.Add("- Install Editor Coroutines (com.unity.editorcoroutines) to enable time-sliced generation in editor.");
            }
#endif

            string headerWarning = GUtilities.ListElementsToString(warnings, "\n");

            GEditorCommon.Foldout(label, false, id, () =>
            {
                GGeometry settings = data.Geometry;
                EditorGUI.BeginChangeCheck();

                GEditorCommon.Header("Dimension");
                settings.Width  = EditorGUILayout.DelayedFloatField("Width", settings.Width);
                settings.Height = EditorGUILayout.DelayedFloatField("Height", settings.Height);
                settings.Length = EditorGUILayout.DelayedFloatField("Length", settings.Length);

                GEditorCommon.Header("Height Map");
                settings.HeightMapResolution = EditorGUILayout.DelayedIntField("Height Map Resolution", settings.HeightMapResolution);

                GEditorCommon.Header("Mesh Generation");
                settings.MeshBaseResolution      = EditorGUILayout.DelayedIntField("Mesh Base Resolution", settings.MeshBaseResolution);
                settings.MeshResolution          = EditorGUILayout.DelayedIntField("Mesh Resolution", settings.MeshResolution);
                settings.ChunkGridSize           = EditorGUILayout.DelayedIntField("Grid Size", settings.ChunkGridSize);
                settings.LODCount                = EditorGUILayout.DelayedIntField("LOD Count", settings.LODCount);
                settings.DisplacementSeed        = EditorGUILayout.DelayedIntField("Displacement Seed", settings.DisplacementSeed);
                settings.DisplacementStrength    = EditorGUILayout.DelayedFloatField("Displacement Strength", settings.DisplacementStrength);
                settings.AlbedoToVertexColorMode = (GAlbedoToVertexColorMode)EditorGUILayout.EnumPopup("Albedo To Vertex Color", settings.AlbedoToVertexColorMode);
                settings.SmoothNormal            = EditorGUILayout.Toggle("Smooth Normal", settings.SmoothNormal);
                if (settings.SmoothNormal)
                {
                    settings.UseSmoothNormalMask = EditorGUILayout.Toggle("Smooth Normal Use Mask (G)", settings.UseSmoothNormalMask);
                }
                GEditorCommon.Header("Utilities");
                settings.StorageMode = (GGeometry.GStorageMode)EditorGUILayout.EnumPopup("Storage", settings.StorageMode);
                settings.AllowTimeSlicedGeneration = EditorGUILayout.Toggle("Time Sliced", settings.AllowTimeSlicedGeneration);

                if (EditorGUI.EndChangeCheck() && !deferredUpdate)
                {
                    data.Geometry.SetRegionDirty(new Rect(0, 0, 1, 1));
                    data.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced);
                }

                if (deferredUpdate)
                {
                    GEditorCommon.Separator();
                    if (GUILayout.Button("Update Immediately"))
                    {
                        data.Geometry.SetRegionDirty(new Rect(0, 0, 1, 1));
                        data.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced);
                    }
                }
            },
                                  menu,
                                  headerWarning.ToString());
        }
        private void DoBulkImport()
        {
            string[]           guid         = AssetDatabase.FindAssets("t:TerrainData", new string[] { Directory });
            List <TerrainData> terrainDatas = new List <TerrainData>();

            for (int i = 0; i < guid.Length; ++i)
            {
                string      path = AssetDatabase.GUIDToAssetPath(guid[i]);
                TerrainData data = AssetDatabase.LoadAssetAtPath <TerrainData>(path);
                terrainDatas.Add(data);
            }

            GCommon.ForEachTerrain(
                BulkImportGroupId,
                (t) =>
            {
                if (t == null || t.TerrainData == null)
                {
                    return;
                }
                TerrainData srcData = terrainDatas.Find(d => d.name.StartsWith("TerrainData") && d.name.EndsWith(t.TerrainData.Id));
                if (srcData == null)
                {
                    return;
                }

                GBackup.TryCreateInitialBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);

                GUnityTerrainDataImporter importer = new GUnityTerrainDataImporter();
                importer.SrcTerrain          = null;
                importer.SrcData             = srcData;
                importer.DesData             = t.TerrainData;
                importer.DesTerrain          = t;
                importer.ImportGeometry      = ImportGeometry;
                importer.UseUnityTerrainSize = UseUnityTerrainSize;

                importer.ImportSplats         = ImportSplats;
                importer.ImportSplatsAsAlbedo = ImportSplatsAsAlbedo;
                bool createNewSplatGroup      = CreateNewSplatPrototypesGroup;
                if (t.TerrainData.Shading.Splats == null ||
                    t.TerrainData.Shading.Splats == GGriffinSettings.Instance.TerrainDataDefault.Shading.Splats)
                {
                    createNewSplatGroup = true;
                }
                importer.CreateNewSplatPrototypesGroup = createNewSplatGroup;

                importer.ImportTrees    = ImportTrees;
                bool createNewTreeGroup = CreateNewTreePrototypesGroup;
                if (t.TerrainData.Foliage.Trees == null ||
                    t.TerrainData.Foliage.Trees == GGriffinSettings.Instance.TerrainDataDefault.Foliage.Trees)
                {
                    createNewTreeGroup = true;
                }
                importer.CreateNewTreePrototypesGroup = createNewTreeGroup;

                importer.ImportGrasses   = ImportGrasses;
                bool createNewGrassGroup = CreateNewGrassPrototypesGroup;
                if (t.TerrainData.Foliage.Grasses == null ||
                    t.TerrainData.Foliage.Grasses == GGriffinSettings.Instance.TerrainDataDefault.Foliage.Grasses)
                {
                    createNewGrassGroup = true;
                }
                importer.CreateNewGrassPrototypesGroup = createNewGrassGroup;

                GrassDensity          = GUnityTerrainDataImporter.GetAdjustedGrassDensity(srcData);
                importer.GrassDensity = GrassDensity;
                importer.Import();

                GBackup.TryCreateBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);
            });

            GStylizedTerrain.MatchEdges(BulkImportGroupId);
        }
コード例 #10
0
        private void DrawGeometryOverrideGUI()
        {
            string label = "Geometry Override";
            string id    = "geometryoverride" + instance.GetInstanceID();

            GenericMenu context = new GenericMenu();

            context.AddItem(
                new GUIContent("Default"),
                false,
                () => { instance.ResetGeometry(); });
            context.AddSeparator(null);
            context.AddItem(
                new GUIContent("Reset"),
                false,
                () =>
            {
                if (EditorUtility.DisplayDialog(
                        "Confirm",
                        "Reset geometry data on this terrain group? This action cannot be undone!",
                        "OK", "Cancel"))
                {
                    GCommon.ForEachTerrain(
                        instance.GroupId,
                        (t) =>
                    {
                        if (t.TerrainData == null)
                        {
                            return;
                        }
                        t.TerrainData.Geometry.ResetFull();
                    });
                    GStylizedTerrain.MatchEdges(instance.GroupId);
                }
            });
            context.AddItem(
                new GUIContent("Update"),
                false,
                () =>
            {
                GCommon.ForEachTerrain(
                    instance.GroupId,
                    (t) =>
                {
                    if (t.TerrainData == null)
                    {
                        return;
                    }
                    t.TerrainData.Geometry.SetRegionDirty(GCommon.UnitRect);
                    t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Geometry);
                });
            });
            context.AddItem(
                new GUIContent("Clean Up"),
                false,
                () =>
            {
                GCommon.ForEachTerrain(
                    instance.GroupId,
                    (t) =>
                {
                    if (t.TerrainData == null)
                    {
                        return;
                    }
                    t.TerrainData.Geometry.CleanUp();
                });
            });

            GEditorCommon.Foldout(label, false, id, () =>
            {
                EditorGUILayout.LabelField("Use with cause, this section takes time to process. You may want to use Deferred Update.", GEditorCommon.WordWrapItalicLabel);

                EditorGUI.indentLevel -= 1;
                GGeometryOverride g    = instance.GeometryOverride;
                EditorGUI.BeginChangeCheck();
                float labelWidth            = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = labelWidth - TOGGLE_WIDTH;

                EditorGUI.indentLevel += 1;
                GEditorCommon.Header("Dimension");
                EditorGUI.indentLevel -= 1;

                EditorGUILayout.BeginHorizontal();
                g.OverrideWidth = EditorGUILayout.Toggle(g.OverrideWidth, GUILayout.Width(TOGGLE_WIDTH));
                g.Width         = EditorGUILayout.DelayedFloatField("Width", g.Width);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideHeight = EditorGUILayout.Toggle(g.OverrideHeight, GUILayout.Width(TOGGLE_WIDTH));
                g.Height         = EditorGUILayout.DelayedFloatField("Height", g.Height);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideLength = EditorGUILayout.Toggle(g.OverrideLength, GUILayout.Width(TOGGLE_WIDTH));
                g.Length         = EditorGUILayout.DelayedFloatField("Length", g.Length);
                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel += 1;
                GEditorCommon.Header("Height Map");
                EditorGUI.indentLevel -= 1;

                EditorGUILayout.BeginHorizontal();
                g.OverrideHeightMapResolution = EditorGUILayout.Toggle(g.OverrideHeightMapResolution, GUILayout.Width(TOGGLE_WIDTH));
                g.HeightMapResolution         = EditorGUILayout.DelayedIntField("Height Map Resolution", g.HeightMapResolution);
                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel += 1;
                GEditorCommon.Header("Mesh Generation");
                EditorGUI.indentLevel -= 1;

                EditorGUILayout.BeginHorizontal();
                g.OverrideMeshBaseResolution = EditorGUILayout.Toggle(g.OverrideMeshBaseResolution, GUILayout.Width(TOGGLE_WIDTH));
                g.MeshBaseResolution         = EditorGUILayout.DelayedIntField("Mesh Base Resolution", g.MeshBaseResolution);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideMeshResolution = EditorGUILayout.Toggle(g.OverrideMeshResolution, GUILayout.Width(TOGGLE_WIDTH));
                g.MeshResolution         = EditorGUILayout.DelayedIntField("Mesh Resolution", g.MeshResolution);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideChunkGridSize = EditorGUILayout.Toggle(g.OverrideChunkGridSize, GUILayout.Width(TOGGLE_WIDTH));
                g.ChunkGridSize         = EditorGUILayout.DelayedIntField("Chunk Grid Size", g.ChunkGridSize);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideLodCount = EditorGUILayout.Toggle(g.OverrideLodCount, GUILayout.Width(TOGGLE_WIDTH));
                g.LODCount         = EditorGUILayout.DelayedIntField("LOD Count", g.LODCount);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideDisplacementSeed = EditorGUILayout.Toggle(g.OverrideDisplacementSeed, GUILayout.Width(TOGGLE_WIDTH));
                g.DisplacementSeed         = EditorGUILayout.DelayedIntField("Displacement Seed", g.DisplacementSeed);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideDisplacementStrength = EditorGUILayout.Toggle(g.OverrideDisplacementStrength, GUILayout.Width(TOGGLE_WIDTH));
                g.DisplacementStrength         = EditorGUILayout.DelayedFloatField("Displacement Strength", g.DisplacementStrength);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideAlbedoToVertexColorMode = EditorGUILayout.Toggle(g.OverrideAlbedoToVertexColorMode, GUILayout.Width(TOGGLE_WIDTH));
                g.AlbedoToVertexColorMode         = (GAlbedoToVertexColorMode)EditorGUILayout.EnumPopup("Albedo To Vertex Color", g.AlbedoToVertexColorMode);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideStorageMode = EditorGUILayout.Toggle(g.OverrideStorageMode, GUILayout.Width(TOGGLE_WIDTH));
                g.StorageMode         = (GGeometry.GStorageMode)EditorGUILayout.EnumPopup("Storage", g.StorageMode);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                g.OverrideAllowTimeSlicedGeneration = EditorGUILayout.Toggle(g.OverrideAllowTimeSlicedGeneration, GUILayout.Width(TOGGLE_WIDTH));
                g.AllowTimeSlicedGeneration         = EditorGUILayout.Toggle("Time Sliced", g.AllowTimeSlicedGeneration);
                EditorGUILayout.EndHorizontal();

                EditorGUIUtility.labelWidth = labelWidth;

                if (EditorGUI.EndChangeCheck())
                {
                    instance.GeometryOverride = g;
                    if (!instance.DeferredUpdate)
                    {
                        GAnalytics.Record(GAnalytics.GROUP_OVERRIDE_GEOMETRY);
                        EditorUtility.DisplayProgressBar("Overriding", "Re-generating terrains geometry", 1);
                        instance.OverrideGeometry();
                        EditorUtility.ClearProgressBar();
                    }
                }
                EditorGUI.indentLevel += 1;
            }, context);
        }