public void AddTerrainHeight()
        {
            int h = ScmapEditor.Current.Teren.terrainData.heightmapHeight;
            int w = ScmapEditor.Current.Teren.terrainData.heightmapWidth;

            ScmapEditor.GetAllHeights(ref beginHeights);
            MapLuaParser.Current.History.RegisterTerrainHeightmapChange(beginHeights);

            float Value = float.Parse(TerrainAdd.text) * 0.1f;

            Value /= ScmapEditor.TerrainHeight;

            float[,] heights = ScmapEditor.Current.Teren.terrainData.GetHeights(0, 0, ScmapEditor.Current.Teren.terrainData.heightmapWidth, ScmapEditor.Current.Teren.terrainData.heightmapHeight);

            for (int i = 0; i < ScmapEditor.Current.Teren.terrainData.heightmapWidth; i++)
            {
                for (int j = 0; j < ScmapEditor.Current.Teren.terrainData.heightmapWidth; j++)
                {
                    heights[i, j] += Value;
                }
            }
            ScmapEditor.SetAllHeights(heights);
            //ScmapEditor.Current.Teren.terrainData.SetHeights(0, 0, heights);
            RegenerateMaps();
            OnTerrainChanged();
        }
Esempio n. 2
0
        public void AddTerrainHeight()
        {
            int h = ScmapEditor.Current.Teren.terrainData.heightmapResolution;
            int w = ScmapEditor.Current.Teren.terrainData.heightmapResolution;

            ScmapEditor.GetAllHeights(ref beginHeights);
            Undo.RegisterUndo(new UndoHistory.HistoryTerrainHeight(), new UndoHistory.HistoryTerrainHeight.TerrainHeightHistoryParameter(beginHeights));

            float Value = float.Parse(TerrainAdd.text) * 0.1f;

            Value /= ScmapEditor.TerrainHeight;

            float[,] heights = ScmapEditor.Current.Teren.terrainData.GetHeights(0, 0, ScmapEditor.Current.Teren.terrainData.heightmapResolution, ScmapEditor.Current.Teren.terrainData.heightmapResolution);

            for (int i = 0; i < ScmapEditor.Current.Teren.terrainData.heightmapResolution; i++)
            {
                for (int j = 0; j < ScmapEditor.Current.Teren.terrainData.heightmapResolution; j++)
                {
                    heights[i, j] += Value;
                }
            }
            ScmapEditor.SetAllHeights(heights);
            //ScmapEditor.Current.Teren.terrainData.SetHeights(0, 0, heights);
            RegenerateMaps();
            OnTerrainChanged();
        }
Esempio n. 3
0
        public override void DoRedo()
        {
            Undo.Current.EditMenu.SetState(Editing.EditStates.TerrainStat);

            Undo.Current.EditMenu.EditTerrain.ChangePage(0);

            ScmapEditor.SetAllHeights(Pixels);

            Undo.Current.EditMenu.EditTerrain.OnTerrainChanged();
            Undo.Current.EditMenu.EditTerrain.RegenerateMaps();
        }
Esempio n. 4
0
    public override void DoRedo()
    {
        if (Undo.Current.EditMenu.State != Editing.EditStates.TerrainStat)
        {
            Undo.Current.EditMenu.State = Editing.EditStates.TerrainStat;
            Undo.Current.EditMenu.ChangeCategory(1);
        }

        Undo.Current.EditMenu.EditTerrain.ChangePage(0);

        //ScmapEditor.Current.Teren.terrainData.SetHeights(0, 0, Pixels);
        ScmapEditor.SetAllHeights(Pixels);

        //Markers.MarkersControler.UpdateMarkersHeights();
        Undo.Current.EditMenu.EditTerrain.OnTerrainChanged();
        Undo.Current.EditMenu.EditTerrain.RegenerateMaps();
    }
Esempio n. 5
0
        void LoadNeroxisHeightmap()
        {
            ScmapEditor.GetAllHeights(ref beginHeights);

            float[,] heights          = ScmapEditor.Current.Teren.terrainData.GetHeights(0, 0, ScmapEditor.Current.Teren.terrainData.heightmapResolution, ScmapEditor.Current.Teren.terrainData.heightmapResolution);
            float[,] generatedHeights = neroxis.GenerateMapTask.GetGeneratedHeightmap();

            for (int i = 0; i < ScmapEditor.Current.Teren.terrainData.heightmapResolution; i++)
            {
                for (int j = 0; j < ScmapEditor.Current.Teren.terrainData.heightmapResolution; j++)
                {
                    heights[i, j] = generatedHeights[i, j];
                }
            }

            Undo.RegisterUndo(new UndoHistory.HistoryTerrainHeight(), new UndoHistory.HistoryTerrainHeight.TerrainHeightHistoryParameter(beginHeights));

            ScmapEditor.SetAllHeights(heights);
        }
        public void ImportHeightmap()
        {
            var extensions = new[]
            {
                new ExtensionFilter("Heightmap", new string[] { "raw", "r16", "bmp" })
                //new ExtensionFilter("Stratum mask", "raw, bmp")
            };

            var paths = StandaloneFileBrowser.OpenFilePanel("Import stratum mask", EnvPaths.GetMapsPath() + MapLuaParser.Current.FolderName, extensions, false);


            if (paths == null || paths.Length == 0 || string.IsNullOrEmpty(paths[0]))
            {
                return;
            }


            int h = ScmapEditor.Current.Teren.terrainData.heightmapHeight;
            int w = ScmapEditor.Current.Teren.terrainData.heightmapWidth;

            ScmapEditor.GetAllHeights(ref beginHeights);
            MapLuaParser.Current.History.RegisterTerrainHeightmapChange(beginHeights);


            float[,] data = new float[h, w];
            //float[,] old = ScmapEditor.Current.Teren.terrainData.GetHeights(0, 0, w, h);

            if (paths[0].ToLower().EndsWith("bmp"))
            {
                BMPLoader loader = new BMPLoader();
                BMPImage  img    = loader.LoadBMP(paths[0]);
                Debug.Log(img.info.compressionMethod + ", " + img.info.nBitsPerPixel + ", " + img.rMask + ", " + img.imageData[0].r);
                Texture2D ImportedImage = img.ToTexture2D();


                if (ImportedImage.width != h || ImportedImage.height != w)
                {
                    Debug.Log("Wrong size");
                    TextureScale.Bilinear(ImportedImage, h, w);
                    ImportedImage.Apply(false);
                }

                Color[] ImportedColors = ImportedImage.GetPixels();

                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        data[y, x] = (float)ImportedColors[x + y * w].r / 0.567f;                         // 0.58
                    }
                }
            }
            else
            {
                using (var file = System.IO.File.OpenRead(paths[0]))
                    using (var reader = new System.IO.BinaryReader(file))
                    {
                        for (int y = 0; y < h; y++)
                        {
                            for (int x = 0; x < w; x++)
                            {
                                float v = (float)reader.ReadUInt16() / (float)HeightConversion;
                                data[h - (y + 1), x] = v;
                            }
                        }
                    }
            }
            //ScmapEditor.Current.Teren.terrainData.SetHeights(0, 0, data);
            ScmapEditor.SetAllHeights(data);
            RegenerateMaps();
            OnTerrainChanged();
        }
Esempio n. 7
0
        public void ImportHeightmap()
        {
            var extensions = new[]
            {
                new ExtensionFilter("Heightmap", new string[] { "raw", "r16", "bmp" })
            };

            var paths = StandaloneFileBrowser.OpenFilePanel("Import heightmap", DefaultPath, extensions, false);


            if (paths == null || paths.Length == 0 || string.IsNullOrEmpty(paths[0]))
            {
                return;
            }

            int h = ScmapEditor.Current.Teren.terrainData.heightmapResolution;
            int w = ScmapEditor.Current.Teren.terrainData.heightmapResolution;

            ScmapEditor.GetAllHeights(ref beginHeights);
            Undo.RegisterUndo(new UndoHistory.HistoryTerrainHeight(), new UndoHistory.HistoryTerrainHeight.TerrainHeightHistoryParameter(beginHeights));


            float[,] data = new float[h, w];
            //float[,] old = ScmapEditor.Current.Teren.terrainData.GetHeights(0, 0, w, h);

            if (paths[0].ToLower().EndsWith("bmp"))
            {
                BMPLoader loader = new BMPLoader();
                BMPImage  img    = loader.LoadBMP(paths[0]);
                Debug.Log(img.info.compressionMethod + ", " + img.info.nBitsPerPixel + ", " + img.rMask + ", " + img.imageData[0].r);
                Texture2D ImportedImage = img.ToTexture2D();


                if (ImportedImage.width != h || ImportedImage.height != w)
                {
                    Debug.Log("Wrong size");
                    TextureScale.Bilinear(ImportedImage, h, w);
                    ImportedImage.Apply(false);
                }

                Color[] ImportedColors = ImportedImage.GetPixels();

                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        data[y, x] = (float)ImportedColors[x + y * w].r / 0.567f;                         // 0.58
                    }
                }
            }
            else
            {
                using (var file = System.IO.File.OpenRead(paths[0]))
                    using (var reader = new System.IO.BinaryReader(file))
                    {
                        long CheckValue = 2;
                        CheckValue *= (long)(w);
                        CheckValue *= (long)(h);
                        long FileLength = file.Length;

                        if (FileLength != CheckValue)
                        {
                            reader.Dispose();
                            file.Dispose();
                            GenericPopup.ShowPopup(GenericPopup.PopupTypes.Error, "Error", "Selected heightmap is in wrong size.\nIs: " + FileLength + "B, should be: " + CheckValue + "B", "OK", null);
                            return;
                        }

                        for (int y = 0; y < h; y++)
                        {
                            for (int x = 0; x < w; x++)
                            {
                                float v = (float)(reader.ReadUInt16() / ScmapEditor.HeightResize);
                                data[h - (y + 1), x] = v;
                            }
                        }
                    }
            }

            //ScmapEditor.Current.Teren.terrainData.SetHeights(0, 0, data);
            ScmapEditor.SetAllHeights(data);
            RegenerateMaps();
            OnTerrainChanged();
            EnvPaths.SetLastPath(ExportPathKey, Path.GetDirectoryName(paths[0]));
            GenericInfoPopup.ShowInfo("Heightmap import success!\n" + Path.GetFileName(paths[0]));


            if (ScmapEditor.IsOverMinMaxDistance())
            {
                GenericPopup.ShowPopup(GenericPopup.PopupTypes.TriButton, "Importing heightmap", "Distance between lowest and highest point is higher than 50.\nClamp it?", "Clamp Top", ClampTop, "Clamp Bottom", ClampBottom, "Ignore", null);
            }
        }