コード例 #1
0
        public void Export()
        {
            try
            {
#if UNITY_EDITOR
                GCommonGUI.ProgressBar("Working", "Exporting RAW file...", 1f);
#endif
                if (BitDepth == GBitDepth.Bit8)
                {
                    DoExportRaw8();
                }
                else if (BitDepth == GBitDepth.Bit16)
                {
                    DoExportRaw16();
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
#if UNITY_EDITOR
                GCommonGUI.ClearProgressBar();
#endif
            }
        }
コード例 #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
        public static bool TryCreateBackup(string namePrefix, GStylizedTerrain terrain, List <GTerrainResourceFlag> flags, bool showProgress = true)
        {
            bool success = false;

#if UNITY_EDITOR
            if (showProgress)
            {
                GCommonGUI.ProgressBar("Backing up", "Creating terrain backup...", 1f);
            }
#endif

            try
            {
                string historyPrefix = GBackupFile.GetHistoryPrefix(namePrefix);
                string backupName    = string.Format("{0}_{1}", historyPrefix, GBackupFile.GetBackupNameByTimeNow());
                GUndoCompatibleBuffer.Instance.RecordUndo();
                GBackup.Create(backupName, terrain, flags);
                success = true;
            }
            catch (System.Exception e)
            {
                Debug.Log("Fail to creating terrain backup: " + e.ToString());
            }
            finally
            {
#if UNITY_EDITOR
                GCommonGUI.ClearProgressBar();
#endif
            }

            return(success);
        }
コード例 #4
0
        private void SaveAssets()
        {
#if UNITY_EDITOR
            GCommonGUI.ProgressBar("Saving", "Saving unsaved assets...", 1f);
            AssetDatabase.SaveAssets();
            GCommonGUI.ClearProgressBar();
#endif
        }
コード例 #5
0
        public static bool TryCreateInitialBackup(string namePrefix, int terrainGroupId, List <GTerrainResourceFlag> flags, bool showProgress = true)
        {
            bool success = false;

#if UNITY_EDITOR
            if (showProgress)
            {
                GCommonGUI.ProgressBar("Backing up", "Creating terrain backup...", 1f);
            }
#endif

            try
            {
                List <string> createdBackup = new List <string>(GBackupFile.GetAllBackupNames());
                string        prefix        = GBackupFile.GetHistoryPrefix(namePrefix);
                string        initialPrefix = GBackupFile.GetInitialHistoryPrefix(namePrefix);

                bool willCreateInitialBackup = true;
                for (int i = createdBackup.Count - 1; i >= 0; --i)
                {
                    if (createdBackup[i].StartsWith(prefix))
                    {
                        continue;
                    }
                    else if (createdBackup[i].StartsWith(initialPrefix))
                    {
                        willCreateInitialBackup = false;
                        break;
                    }
                    else
                    {
                        willCreateInitialBackup = true;
                        break;
                    }
                }

                if (willCreateInitialBackup)
                {
                    string backupName = string.Format("{0}_{1}", initialPrefix, GBackupFile.GetBackupNameByTimeNow());
                    GUndoCompatibleBuffer.Instance.RecordUndo();
                    GBackup.Create(backupName, terrainGroupId, flags);
                    success = true;
                }
            }
            catch (System.Exception e)
            {
                Debug.Log("Fail to creating terrain backup: " + e.ToString());
            }
            finally
            {
#if UNITY_EDITOR
                GCommonGUI.ClearProgressBar();
#endif
            }
            return(success);
        }
コード例 #6
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
        }
コード例 #7
0
        public void Export()
        {
            try
            {
#if UNITY_EDITOR
                GCommonGUI.ProgressBar("Working", "Exporting terrain textures...", 1f);
#endif
                if (ExportHeightMap)
                {
                    DoExportHeightMap();
                }
                if (ExportVisibilityMap)
                {
                    DoExportVisibilityMap();
                }
                if (ExportAlbedoMap)
                {
                    DoExportAlbedoMap();
                }
                if (ExportMetallicMap)
                {
                    DoExportMetallicMap();
                }
                if (ExportGradientLookupMaps)
                {
                    DoExportGradientLookupMaps();
                }
                if (ExportSplatControlMaps)
                {
                    DoExportSplatControlMaps();
                }
#if UNITY_EDITOR
                AssetDatabase.Refresh();
#endif
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
#if UNITY_EDITOR
                GCommonGUI.ClearProgressBar();
#endif
            }
        }
コード例 #8
0
        private void FinishingUp()
        {
#if UNITY_EDITOR
            GCommonGUI.ProgressBar("Finishing Up", "Matching geometry...", 1f);
#endif

            for (int i = 0; i < ConvertedTerrains.Count; ++i)
            {
                ConvertedTerrains[i].ConnectNeighbor();
                ConvertedTerrains[i].MatchEdges();
            }

            Root.gameObject.SetActive(false);
#if UNITY_EDITOR
            GCommonGUI.ClearProgressBar();
#endif
        }
コード例 #9
0
        public void Export()
        {
            try
            {
#if UNITY_EDITOR
                GCommonGUI.ProgressBar("Working", "Saving unsaved assets...", 1f);
                SaveAssets();
                GCommonGUI.ProgressBar("Working", "Exporting", 1f);
#endif

                InitializeAssets();
                if (ExportGeometry)
                {
                    DoExportGeometry();
                }
                if (ExportSplats)
                {
                    DoExportSplats();
                }
                if (ExportTrees)
                {
                    DoExportTrees();
                }
                if (ExportGrasses)
                {
                    DoExportGrasses();
                }

#if UNITY_EDITOR
                GCommonGUI.ProgressBar("Working", "Saving unsaved assets...", 1f);
                SaveAssets();
#endif
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.ToString());
            }
            finally
            {
#if UNITY_EDITOR
                GCommonGUI.ClearProgressBar();
#endif
            }
        }
コード例 #10
0
ファイル: GRawImporter.cs プロジェクト: ComradeCrunchy/Ranch
        public void Import()
        {
            try
            {
#if UNITY_EDITOR
                GCommonGUI.ProgressBar("Working", "Importing RAW...", 1f);
#endif
                if (BitDepth == GBitDepth.Bit8)
                {
                    ImportRaw8();
                }
                else if (BitDepth == GBitDepth.Bit16)
                {
                    ImportRaw16();
                }
                if (Terrain != null)
                {
                    DesData.Foliage.SetTreeRegionDirty(GCommon.UnitRect);
                    DesData.Foliage.SetGrassRegionDirty(GCommon.UnitRect);
                    Terrain.UpdateTreesPosition(true);
                    Terrain.UpdateGrassPatches(-1, true);
                    DesData.Foliage.ClearTreeDirtyRegions();
                    DesData.Foliage.ClearGrassDirtyRegions();
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
#if UNITY_EDITOR
                GCommonGUI.ClearProgressBar();
#endif
            }
        }
コード例 #11
0
        private void Apply(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            if (Layers.Count == 0)
            {
                return;
            }

            GetQuad(worldPoints);
            GetUvPoints(t, worldPoints, uvPoints);
            Rect dirtyRect = GUtilities.GetRectContainsPoints(uvPoints);

            if (!dirtyRect.Overlaps(new Rect(0, 0, 1, 1)))
            {
                return;
            }

            RenderTexture[] brushes = new RenderTexture[Layers.Count];
            for (int i = 0; i < Layers.Count; ++i)
            {
                brushes[i] = GetRenderTexture("brush" + i.ToString());
            }
            Internal_RenderBrushes(brushes, t, uvPoints);

            for (int i = 0; i < Layers.Count; ++i)
            {
                StampLayer(t, brushes[i], i);
            }

            bool willUpdateTree  = Layers.Exists(l => l.StampTrees && l.TreeInstanceCount > 0);
            bool willUpdateGrass = Layers.Exists(l => l.StampGrasses && l.TreeInstanceCount > 0);

#if UNITY_EDITOR
            string title = "Stamping on " + t.name;
            string info  = "Finishing up...";
            GCommonGUI.ProgressBar(title, info, 1);
#endif

            try
            {
                t.TerrainData.Foliage.SetTreeRegionDirty(dirtyRect);
                t.TerrainData.Foliage.SetGrassRegionDirty(dirtyRect);
                if (willUpdateTree)
                {
                    t.UpdateTreesPosition();
                }
                if (willUpdateGrass)
                {
                    t.UpdateGrassPatches(-1, true);
                }
                t.TerrainData.Foliage.ClearTreeDirtyRegions();
                t.TerrainData.Foliage.ClearGrassDirtyRegions();
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }

#if UNITY_EDITOR
            GCommonGUI.ClearProgressBar();
#endif

            t.TerrainData.SetDirty(GTerrainData.DirtyFlags.Foliage);
        }
コード例 #12
0
        public void Import()
        {
            try
            {
#if UNITY_EDITOR
                GCommonGUI.ProgressBar("Working", "Importing textures...", 1f);
#endif
                if (HeightMap != null || VisibilityMap != null)
                {
                    Color[] oldHeightMapColors = DesData.Geometry.HeightMap.GetPixels();

                    Texture2D hm = null;
                    if (HeightMap != null)
                    {
                        hm = GCommon.CloneTexture(HeightMap);
                    }
                    Texture2D vm = null;
                    if (VisibilityMap != null)
                    {
                        vm = GCommon.CloneTexture(VisibilityMap);
                    }

                    int     desResolution = DesData.Geometry.HeightMapResolution;
                    Color[] newColor      = new Color[desResolution * desResolution];
                    Vector2 uv            = Vector2.zero;
                    Vector2 enc           = Vector2.zero;
                    for (int y = 0; y < desResolution; ++y)
                    {
                        for (int x = 0; x < desResolution; ++x)
                        {
                            uv.Set(
                                Mathf.InverseLerp(0, desResolution, x),
                                Mathf.InverseLerp(0, desResolution, y));

                            Color c = Color.clear;
                            if (hm != null)
                            {
                                enc = GCommon.EncodeTerrainHeight(hm.GetPixelBilinear(uv.x, uv.y).r);
                                c.r = enc.x;
                                c.g = enc.y;
                            }
                            else
                            {
                                c = DesData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y);
                            }

                            if (vm != null)
                            {
                                c.a = 1 - vm.GetPixelBilinear(uv.x, uv.y).r;
                            }
                            else
                            {
                                c.a = DesData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y).a;
                            }

                            newColor[GUtilities.To1DIndex(x, y, desResolution)] = c;
                        }
                    }

                    DesData.Geometry.HeightMap.SetPixels(newColor);
                    DesData.Geometry.HeightMap.Apply();

                    if (hm != null || vm != null)
                    {
                        Color[]            newHeightMapColors = DesData.Geometry.HeightMap.GetPixels();
                        IEnumerable <Rect> dirtyRects         = GCommon.CompareTerrainTexture(DesData.Geometry.ChunkGridSize, oldHeightMapColors, newHeightMapColors);
                        DesData.Geometry.SetRegionDirty(dirtyRects);
                        DesData.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced);

                        if (Terrain != null)
                        {
                            DesData.Foliage.SetTreeRegionDirty(GCommon.UnitRect);
                            DesData.Foliage.SetGrassRegionDirty(GCommon.UnitRect);
                            Terrain.UpdateTreesPosition(true);
                            Terrain.UpdateGrassPatches(-1, true);
                            DesData.Foliage.ClearTreeDirtyRegions();
                            DesData.Foliage.ClearGrassDirtyRegions();
                        }
                    }

                    if (hm != null)
                    {
                        GUtilities.DestroyObject(hm);
                    }
                    if (vm != null)
                    {
                        GUtilities.DestroyObject(vm);
                    }
                }

                if (MaskMap != null)
                {
                    GCommon.CopyTexture(MaskMap, DesData.Mask.MaskMap);
                }
                if (AlbedoMap != null)
                {
                    GCommon.CopyTexture(AlbedoMap, DesData.Shading.AlbedoMap);
                    DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
                }
                if (MetallicMap != null)
                {
                    GCommon.CopyTexture(MetallicMap, DesData.Shading.MetallicMap);
                    DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
                }
                if (SplatControlMaps != null)
                {
                    int count = Mathf.Min(SplatControlMaps.Length, DesData.Shading.SplatControlMapCount);
                    for (int i = 0; i < count; ++i)
                    {
                        if (SplatControlMaps[i] != null)
                        {
                            GCommon.CopyTexture(SplatControlMaps[i], DesData.Shading.GetSplatControl(i));
                        }
                    }
                    DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
#if UNITY_EDITOR
                GCommonGUI.ClearProgressBar();
#endif
            }
        }