private void SingleLayerCalculationStart(BaseLayer layer)
        {
            switch (layer.LayerType)
            {
            // Elevation Layers
            case Layer.Height:
                HeightLayer heightLayer = layer as HeightLayer;
                heightLayer.StartHeight(TerrainSize, TerrainHeights);
                break;

            case Layer.Slope:
                SlopeLayer slopeLayer = layer as SlopeLayer;
                slopeLayer.StartSlope(TerrainSize, TerrainHeights);
                break;

            case Layer.Island:
                IslandLayer islandLayer = layer as IslandLayer;
                islandLayer.StartIsland(TerrainSize, TerrainHeights);
                break;

            case Layer.OpenSimplex:
                OpenSimplexNoiseLayer OSNLayer = layer as OpenSimplexNoiseLayer;
                OSNLayer.StartOpenSimplexNoise(TerrainSize, TerrainHeights);
                break;

            case Layer.CellNoise:
                CellNoiseLayer CellNoiseLayer = layer as CellNoiseLayer;
                CellNoiseLayer.StartCellNoise(TerrainSize, TerrainHeights);
                break;

            // Erosion Layers
            case Layer.Hydraulic:
                HydraulicErosionLayer hydraulicErosionLayer = layer as HydraulicErosionLayer;
                hydraulicErosionLayer.StartErosion(TerrainSize, TerrainHeights);
                break;

            // Colorization Layers
            case Layer.DetailColorization:
                DetailColorizationLayer detailColorizationLayer = layer as DetailColorizationLayer;
                detailColorizationLayer.StartColorization(TerrainSize, TerrainHeights);
                break;

            case Layer.HeightColorization:
                HeightColorizationLayer heightColorizationLayer = layer as HeightColorizationLayer;
                heightColorizationLayer.StartColorization(TerrainSize, TerrainHeights, PreviousTerrainColors);
                break;
            }
        }
Example #2
0
        public void AddNewLayer(Layer layerType)
        {
            BaseLayer newLayer = null;

            switch (layerType)
            {
            case Layer.Height:
                HeightLayer newHeightLayer = new HeightLayer(this, terrainEngine);
                newHeightLayer.Name      = GetName(Layer.Height, Layers.Count);
                newHeightLayer.ImagePath = "pack://application:,,,/Topographer3D;component/Assets/Icons/RaiseIcon.png";
                newHeightLayer.Position  = Layers.Count;
                Layers.Add(newHeightLayer);
                ShowLayerDetails(newHeightLayer);
                newLayer = newHeightLayer;
                break;

            case Layer.Slope:
                SlopeLayer newSlopeLayer = new SlopeLayer(this, terrainEngine);
                newSlopeLayer.Name      = GetName(Layer.Slope, Layers.Count);
                newSlopeLayer.ImagePath = "pack://application:,,,/Topographer3D;component/Assets/Icons/RaiseIcon.png";
                newSlopeLayer.Position  = Layers.Count;
                Layers.Add(newSlopeLayer);
                ShowLayerDetails(newSlopeLayer);
                newLayer = newSlopeLayer;
                break;

            case Layer.Island:
                IslandLayer newIslandLayer = new IslandLayer(this, terrainEngine);
                newIslandLayer.Name      = GetName(Layer.Island, Layers.Count);
                newIslandLayer.ImagePath = "pack://application:,,,/Topographer3D;component/Assets/Icons/RaiseIcon.png";
                newIslandLayer.Position  = Layers.Count;
                Layers.Add(newIslandLayer);
                ShowLayerDetails(newIslandLayer);
                newLayer = newIslandLayer;
                break;

            case Layer.OpenSimplex:
                OpenSimplexNoiseLayer newOSNLayer = new OpenSimplexNoiseLayer(this, terrainEngine);
                newOSNLayer.Name      = GetName(Layer.OpenSimplex, Layers.Count);
                newOSNLayer.ImagePath = "pack://application:,,,/Topographer3D;component/Assets/Icons/RaiseIcon.png";
                newOSNLayer.Position  = Layers.Count;
                Layers.Add(newOSNLayer);
                ShowLayerDetails(newOSNLayer);
                newLayer = newOSNLayer;
                break;

            case Layer.CellNoise:
                CellNoiseLayer newCellNoiseLayer = new CellNoiseLayer(this, terrainEngine);
                newCellNoiseLayer.Name      = GetName(Layer.CellNoise, Layers.Count);
                newCellNoiseLayer.ImagePath = "pack://application:,,,/Topographer3D;component/Assets/Icons/RaiseIcon.png";
                newCellNoiseLayer.Position  = Layers.Count;
                Layers.Add(newCellNoiseLayer);
                ShowLayerDetails(newCellNoiseLayer);
                newLayer = newCellNoiseLayer;
                break;

            case Layer.Hydraulic:
                HydraulicErosionLayer newHydrauliceErosionLayer = new HydraulicErosionLayer(this, terrainEngine);
                newHydrauliceErosionLayer.Name      = GetName(Layer.Hydraulic, Layers.Count);
                newHydrauliceErosionLayer.ImagePath = "pack://application:,,,/Topographer3D;component/Assets/Icons/ErodeIcon.png";
                newHydrauliceErosionLayer.Position  = Layers.Count;
                Layers.Add(newHydrauliceErosionLayer);
                ShowLayerDetails(newHydrauliceErosionLayer);
                newLayer = newHydrauliceErosionLayer;
                break;

            case Layer.DetailColorization:
                DetailColorizationLayer newDetailColorizationLayer = new DetailColorizationLayer(this, terrainEngine);
                newDetailColorizationLayer.Name      = GetName(Layer.DetailColorization, Layers.Count);
                newDetailColorizationLayer.ImagePath = "pack://application:,,,/Topographer3D;component/Assets/Icons/ColorizeIcon.png";
                newDetailColorizationLayer.Position  = Layers.Count;
                Layers.Add(newDetailColorizationLayer);
                ShowLayerDetails(newDetailColorizationLayer);
                newLayer = newDetailColorizationLayer;
                break;

            case Layer.HeightColorization:
                HeightColorizationLayer newHeightColorizationLayer = new HeightColorizationLayer(this, terrainEngine);
                newHeightColorizationLayer.Name      = GetName(Layer.HeightColorization, Layers.Count);
                newHeightColorizationLayer.ImagePath = "pack://application:,,,/Topographer3D;component/Assets/Icons/ColorizeIcon.png";
                newHeightColorizationLayer.Position  = Layers.Count;
                Layers.Add(newHeightColorizationLayer);
                ShowLayerDetails(newHeightColorizationLayer);
                newLayer = newHeightColorizationLayer;
                break;
            }

            if (newLayer.Position == 0)
            {
                newLayer.HasApplicationMode     = Visibility.Hidden;
                newLayer.CurrentApplicationMode = (ApplicationMode)100;
            }
        }
 private void GenerateHeightTexture(HeightLayer hLayer)
 {
     hLayer.SavedMap = MainAlgorithms.GeneratedSimplexTexture(Terrain, hLayer.LayerProperties);
 }
        protected void ShowHeightLayerVariables(HeightLayer _hLayer)
        {
            using (new GUILayout.HorizontalScope(baseSkin.FindStyle("LayerToolbar")))
            {
                GUIContent selectedContent;
                if (_hLayer.ExpandedInEditor)
                {
                    selectedContent = new GUIContent(baseSkin.FindStyle("OpenCloseSymbolsLight").hover.background);
                }
                else
                {
                    selectedContent = new GUIContent(baseSkin.FindStyle("OpenCloseSymbolsLight").normal.background);
                }
                if (GUILayout.Button(selectedContent, baseSkin.FindStyle("SymbolButton")))
                {
                    _hLayer.ExpandedInEditor = !_hLayer.ExpandedInEditor;
                }
                _hLayer.Name =
                    EditorGUILayout.TextField(_hLayer.Name, baseSkin.textField);
                //_hLayer.Randomized = GUISliderBoolField(_hLayer.Randomized, "Manual", "Random");
                //GUILayout.Space(25);
                EditorGUILayout.PrefixLabel("Preset:", baseSkin.FindStyle("Enum"), baseSkin.FindStyle("EnumLabel"));
                _hLayer.PlaceholderPreset = (HeightLayer.placeholderPresets)EditorGUILayout.EnumPopup(_hLayer.PlaceholderPreset, baseSkin.FindStyle("Enum"));
                GUILayout.FlexibleSpace();
            }
            GUIStyle layerStyle;

            if (_hLayer.ExpandedInEditor)
            {
                layerStyle = baseSkin.FindStyle("LayerValues");
            }
            else
            {
                layerStyle = baseSkin.FindStyle("LayerClosed");
            }
            using (new GUILayout.HorizontalScope(layerStyle))
            {
                using (new GUILayout.VerticalScope())
                {
                    if (_hLayer.ExpandedInEditor)
                    {
                        EditorGUI.indentLevel = 1;
                        if (_hLayer.LayerProperties.Frequency.Randomized)
                        {
                            DisplayHeightMinMaxIntFields("Frequency", -100, 100, _hLayer.LayerProperties.Frequency);
                        }
                        else
                        {
                            DisplayHeightPropertyFloat("Frequency", _hLayer.LayerProperties.Frequency);
                        }
                        DisplayHeightPropertyFloatMinMax("Amplitude", 0.1f, 2f, _hLayer.LayerProperties.Amplitude);
                        DisplayHeightPropertyIntMinMax("Octaves", 1, 8, _hLayer.LayerProperties.Octaves);
                        DisplayHeightPropertyFloatMinMax("Lacunarity", 1, 4, _hLayer.LayerProperties.Lacunarity);
                        DisplayHeightPropertyFloatMinMax("Persistance", 0, 1, _hLayer.LayerProperties.Persistance);
                        DisplayHeightPropertyVector3("Offset", _hLayer.LayerProperties.Offset);
                        using (new GUILayout.HorizontalScope(baseSkin.FindStyle("HeightLayerProperty")))
                            _hLayer.LayerProperties.Opacity = GUISliderField("Opacity", _hLayer.LayerProperties.Opacity, 0, 1, 100, false);
                        EditorGUI.indentLevel = 0;
                        GUILayout.Space(5);
                    }
                }
                if (_hLayer.ExpandedInEditor)
                {
                    using (new GUILayout.VerticalScope())
                    {
                        using (new GUILayout.VerticalScope(baseSkin.FindStyle("Image"), GUILayout.Width(220)))
                        {
                            if (_hLayer.SavedMap == null)
                            {
                                GenerateHeightTexture(_hLayer);
                            }

                            EditorGUILayout.LabelField("Layer Map", baseSkin.FindStyle("labelCenter"));
                            GUILayout.Space(210);
                            EditorGUI.DrawPreviewTexture(new Rect(EditorGUILayout.GetControlRect().position + new Vector2(6, -200)
                                                                  , new Vector2(200, 200)), _hLayer.SavedMap);
                        }
                        if (GUILayout.Button("Regenerate", baseSkin.FindStyle("CenteredButton")))
                        {
                            GenerateHeightTexture(_hLayer);
                            Debug.Log("Regenerating " + _hLayer.Name);
                            lastLayer = _hLayer;
                        }
                    }
                }
                //
            }
        }
        protected void ShowHeightLayerVariables(HeightLayer _hLayer)
        {
            using (new GUILayout.HorizontalScope(baseSkin.FindStyle("LayerToolbar")))
            {
                GUIContent selectedContent;
                if (_hLayer.ExpandedInEditor)
                {
                    selectedContent = new GUIContent(baseSkin.FindStyle("OpenCloseSymbolsLight").hover.background);
                }
                else
                {
                    selectedContent = new GUIContent(baseSkin.FindStyle("OpenCloseSymbolsLight").normal.background);
                }
                if (GUILayout.Button(selectedContent, baseSkin.FindStyle("SymbolButton")))
                {
                    _hLayer.ExpandedInEditor = !_hLayer.ExpandedInEditor;
                }
                _hLayer.Name =
                    EditorGUILayout.TextField(_hLayer.Name, baseSkin.textField);
                EditorGUILayout.PrefixLabel("Preset:", baseSkin.FindStyle("Enum"), baseSkin.FindStyle("EnumLabel"));
                _hLayer.PlaceholderPreset = (HeightLayer.placeholderPresets)EditorGUILayout.EnumPopup(_hLayer.PlaceholderPreset, baseSkin.FindStyle("Enum"));
                GUILayout.FlexibleSpace();
            }
            GUIStyle layerStyle;

            if (_hLayer.ExpandedInEditor)
            {
                layerStyle = baseSkin.FindStyle("LayerValues");
            }
            else
            {
                layerStyle = baseSkin.FindStyle("LayerClosed");
            }
            using (new GUILayout.HorizontalScope(layerStyle))
            {
                using (new GUILayout.VerticalScope())
                {
                    if (_hLayer.ExpandedInEditor)
                    {
                        EditorGUI.indentLevel = 1;
                        FloatPropertyDrawer.Draw(_hLayer.LayerProperties.Frequency, baseSkin, 0.01f, 100);
                        FloatPropertyDrawer.Draw(_hLayer.LayerProperties.Amplitude, baseSkin, 0.1f, 2f);
                        IntPropertyDrawer.Draw(_hLayer.LayerProperties.Octaves, baseSkin, 1, 8);
                        FloatPropertyDrawer.Draw(_hLayer.LayerProperties.Lacunarity, baseSkin, 1, 4);
                        FloatPropertyDrawer.Draw(_hLayer.LayerProperties.Persistance, baseSkin, 0, 1);
                        Vector3PropertyDrawer.Draw(_hLayer.LayerProperties.Offset, baseSkin, -100, 100);
                        using (new GUILayout.HorizontalScope(baseSkin.FindStyle("Property")))
                            _hLayer.LayerProperties.Opacity =
                                FloatSliderDrawer.Draw(new GUIContent("Opacity"), _hLayer.LayerProperties.Opacity, 0, 1, baseSkin, true, false, 200);
                        EditorGUI.indentLevel = 0;
                        GUILayout.Space(5);
                    }
                }
                if (_hLayer.ExpandedInEditor)
                {
                    using (new GUILayout.VerticalScope())
                    {
                        using (new GUILayout.VerticalScope(baseSkin.FindStyle("Image"), GUILayout.Width(220)))
                        {
                            if (_hLayer.SavedMap == null)
                            {
                                GenerateHeightTexture(_hLayer);
                            }

                            EditorGUILayout.LabelField("Layer Map", baseSkin.FindStyle("labelCenter"));
                            GUILayout.Space(210);
                            EditorGUI.DrawPreviewTexture(new Rect(EditorGUILayout.GetControlRect().position + new Vector2(6, -200)
                                                                  , new Vector2(200, 200)), _hLayer.SavedMap);
                        }
                        if (ButtonDrawer.Draw(new GUIContent("Regenerate",
                                                             "Regenerate this Layer's Map. WARNING: This will override the previous map if you are using randomized values."), baseSkin.FindStyle("CenteredButton")))
                        {
                            GenerateHeightTexture(_hLayer);
                            Debug.Log("Regenerating " + _hLayer.Name);
                            lastLayer = _hLayer;
                        }
                    }
                }
            }
        }