public void AddTerrain(GameObject go)
        {
            //TODO only add terrains that overlap area if automatic calculation is disabled
            IVegetationStudioTerrain vegetationStudioTerrain = VegetationStudioTerrain.GetIVegetationStudioTerrain(go);

            if (vegetationStudioTerrain != null)
            {
                if (!VegetationStudioTerrainObjectList.Contains(go))
                {
                    VegetationStudioTerrainObjectList.Add(go);
                }

                RefreshVegetationStudioTerrains();

                if (AutomaticBoundsCalculation)
                {
                    CalculateVegetationSystemBounds();
                }
                else
                {
                    RefreshTerrainArea(vegetationStudioTerrain.TerrainBounds);
                }
            }

            VerifyVegetationStudioTerrains();
        }
        public void CalculateVegetationSystemBounds()
        {
            for (int i = 0; i <= VegetationStudioTerrainObjectList.Count - 1; i++)
            {
                IVegetationStudioTerrain vegetationStudioTerrain =
                    VegetationStudioTerrain.GetIVegetationStudioTerrain(VegetationStudioTerrainObjectList[i]);
                vegetationStudioTerrain?.RefreshTerrainData();
            }

            Bounds newBounds = new Bounds(Vector3.zero, Vector3.zero);

            if (AutomaticBoundsCalculation)
            {
                for (int i = 0; i <= VegetationStudioTerrainObjectList.Count - 1; i++)
                {
                    IVegetationStudioTerrain vegetationStudioTerrain = VegetationStudioTerrain.GetIVegetationStudioTerrain(VegetationStudioTerrainObjectList[i]);
                    if (vegetationStudioTerrain != null)
                    {
                        if (i == 0)
                        {
                            newBounds = vegetationStudioTerrain.TerrainBounds;
                        }
                        else
                        {
                            newBounds.Encapsulate(vegetationStudioTerrain.TerrainBounds);
                        }
                    }
                }
            }
            VegetationSystemBounds = newBounds;
            SetupVegetationSystem();
        }
Example #3
0
 public Texture2D GetTerrainTexture(int index)
 {
     for (int i = 0; i <= VegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
     {
         IVegetationStudioTerrain iVegetationStudioTerrain = VegetationSystemPro.VegetationStudioTerrainList[i];
         if (iVegetationStudioTerrain.HasTerrainTextures())
         {
             return(iVegetationStudioTerrain.GetTerrainTexture(index));
         }
     }
     return(null);
 }
 void RefreshVegetationStudioTerrains()
 {
     VerifyVegetationStudioTerrains();
     VegetationStudioTerrainList.Clear();
     for (int i = 0; i <= VegetationStudioTerrainObjectList.Count - 1; i++)
     {
         IVegetationStudioTerrain vegetationStudioTerrain = VegetationStudioTerrain.GetIVegetationStudioTerrain(VegetationStudioTerrainObjectList[i]);
         if (vegetationStudioTerrain != null)
         {
             VegetationStudioTerrainList.Add(vegetationStudioTerrain);
         }
     }
 }
        public void AddTerrains(List <GameObject> terrainList)
        {
            Bounds combinedBounds = new Bounds();

            for (int i = 0; i <= terrainList.Count - 1; i++)
            {
                IVegetationStudioTerrain vegetationStudioTerrain = VegetationStudioTerrain.GetIVegetationStudioTerrain(terrainList[i]);
                if (vegetationStudioTerrain != null)
                {
                    if (!VegetationStudioTerrainObjectList.Contains(terrainList[i]))
                    {
                        VegetationStudioTerrainObjectList.Add(terrainList[i]);
                    }
                }

                if (i == 0)
                {
                    if (vegetationStudioTerrain != null)
                    {
                        combinedBounds = vegetationStudioTerrain.TerrainBounds;
                    }
                }
                else
                {
                    if (vegetationStudioTerrain != null)
                    {
                        combinedBounds.Encapsulate(vegetationStudioTerrain.TerrainBounds);
                    }
                }
            }

            RefreshVegetationStudioTerrains();

            if (AutomaticBoundsCalculation)
            {
                CalculateVegetationSystemBounds();
            }
            else
            {
                RefreshTerrainArea(combinedBounds);
            }

            VerifyVegetationStudioTerrains();
        }
Example #6
0
        public void GetSplatPrototypesFromTerrain(VegetationPackagePro vegetationPackage)
        {
            for (int i = 0; i <= VegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
            {
                IVegetationStudioTerrain iVegetationStudioTerrain = VegetationSystemPro.VegetationStudioTerrainList[i];
                if (iVegetationStudioTerrain.HasTerrainTextures())
                {
#if UNITY_2018_3_OR_NEWER
                    TerrainLayer[] terrainLayers = iVegetationStudioTerrain.GetTerrainLayers();

                    for (int j = 0; j <= vegetationPackage.TerrainTextureList.Count - 1; j++)
                    {
                        if (j < terrainLayers.Length)
                        {
                            vegetationPackage.TerrainTextureList[j].Texture        = terrainLayers[j].diffuseTexture;
                            vegetationPackage.TerrainTextureList[j].TextureNormals = terrainLayers[j].normalMapTexture;
                            vegetationPackage.TerrainTextureList[j].Offset         = terrainLayers[j].tileOffset;
                            vegetationPackage.TerrainTextureList[j].TileSize       = terrainLayers[j].tileSize;
                        }
                    }

                    break;
#else
                    SplatPrototype[] splatPrototypes = iVegetationStudioTerrain.GetSplatPrototypes();

                    for (int j = 0; j <= vegetationPackage.TerrainTextureList.Count - 1; j++)
                    {
                        if (j < splatPrototypes.Length)
                        {
                            vegetationPackage.TerrainTextureList[j].Texture        = splatPrototypes[j].texture;
                            vegetationPackage.TerrainTextureList[j].TextureNormals = splatPrototypes[j].normalMap;
                            vegetationPackage.TerrainTextureList[j].Offset         = splatPrototypes[j].tileOffset;
                            vegetationPackage.TerrainTextureList[j].TileSize       = splatPrototypes[j].tileSize;
                        }
                    }
                    break;
#endif
                }
            }
        }
        public void RemoveTerrain(GameObject go)
        {
            if (VegetationStudioTerrainObjectList.Contains(go))
            {
                VegetationStudioTerrainObjectList.Remove(go);
            }
            RefreshVegetationStudioTerrains();

            IVegetationStudioTerrain vegetationStudioTerrain = VegetationStudioTerrain.GetIVegetationStudioTerrain(go);

            if (AutomaticBoundsCalculation)
            {
                CalculateVegetationSystemBounds();
            }
            else
            {
                if (vegetationStudioTerrain != null)
                {
                    RefreshTerrainArea(vegetationStudioTerrain.TerrainBounds);
                }
            }

            VerifyVegetationStudioTerrains();
        }
Example #8
0
        public override void OnInspectorGUI()
        {
            base.ShowLogo = false;
            HelpTopic     = "background-mask-creator";
            base.OnInspectorGUI();

            MaskBackgroundCreator maskBackgroundCreator = (MaskBackgroundCreator)target;
            VegetationSystemPro   vegetationSystemPro   =
                maskBackgroundCreator.gameObject.GetComponent <VegetationSystemPro>();

            if (vegetationSystemPro)
            {
                GUILayout.BeginVertical("box");
                maskBackgroundCreator.AreaRect = EditorGUILayout.RectField("Area", maskBackgroundCreator.AreaRect);
                EditorGUILayout.HelpBox(
                    "You can snap the area to any added terrain, total world area or manually setting the area for generation.",
                    MessageType.Info);
                GUILayout.EndVertical();


                GUILayout.BeginVertical("box");
                GUILayout.BeginHorizontal();
                string[] terrains = new string[vegetationSystemPro.VegetationStudioTerrainList.Count];
                for (int i = 0; i <= vegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
                {
                    terrains[i] = vegetationSystemPro.VegetationStudioTerrainObjectList[i].name;
                }

                _selectedTerrainIndex = EditorGUILayout.Popup("Select terrain", _selectedTerrainIndex, terrains);
                if (GUILayout.Button("Snap to terrain", GUILayout.Width(120)))
                {
                    IVegetationStudioTerrain iVegetationStudioTerrain =
                        vegetationSystemPro.VegetationStudioTerrainList[_selectedTerrainIndex];
                    Bounds bounds = iVegetationStudioTerrain.TerrainBounds;
                    maskBackgroundCreator.AreaRect = RectExtension.CreateRectFromBounds(bounds);
                }

                GUILayout.EndHorizontal();

                if (GUILayout.Button("Snap to world area"))
                {
                    maskBackgroundCreator.AreaRect =
                        RectExtension.CreateRectFromBounds(vegetationSystemPro.VegetationSystemBounds);
                }

                EditorGUILayout.HelpBox(
                    "You can snap the area to any added terrain, total world area or manually setting the rect.",
                    MessageType.Info);

                GUILayout.EndVertical();

                maskBackgroundCreator.BackgroundMaskQuality =
                    (BackgroundMaskQuality)EditorGUILayout.EnumPopup("Mask resolution",
                                                                     maskBackgroundCreator.BackgroundMaskQuality);
                EditorGUILayout.HelpBox(
                    "Pixel resolution of the mask background. Low = 1024x1024, Normal = 2048x2048 and High =4096x4096",
                    MessageType.Info);

                if (GUILayout.Button("Generate mask background/template"))
                {
                    GenerateMaskBackground(maskBackgroundCreator.AreaRect);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Add this component to a GameObject with a VegetationSystemPro component.",
                                        MessageType.Error);
            }
        }
Example #9
0
        public void GenerateSplatMap(bool clearLockedTextures, IVegetationStudioTerrain iVegetationStudioTerrain)
        {
            if (!VegetationSystemPro)
            {
                return;
            }

            VegetationSystemPro.ClearCache(iVegetationStudioTerrain.TerrainBounds);
            PrepareTextureCurves();

            float worldspaceMinHeight = VegetationSystemPro.VegetationSystemBounds.center.y -
                                        VegetationSystemPro.VegetationSystemBounds.extents.y;
            float worldspaceSeaLevel  = worldspaceMinHeight + VegetationSystemPro.SeaLevel;
            float worldspaceMaxHeight = VegetationSystemPro.VegetationSystemBounds.center.y +
                                        VegetationSystemPro.VegetationSystemBounds.extents.y;
            float heightCurveSampleHeight = worldspaceMaxHeight - worldspaceSeaLevel;

            VegetationPackagePro defaultBiomeVegetationPackagePro =
                VegetationSystemPro.GetVegetationPackageFromBiome(BiomeType.Default);

            if (defaultBiomeVegetationPackagePro == null)
            {
                Debug.LogWarning("You need a default biome in order to generate splatmaps. ");
                return;
            }

            iVegetationStudioTerrain.PrepareSplatmapGeneration(clearLockedTextures);

            iVegetationStudioTerrain.GenerateSplatMapBiome(VegetationSystemPro.VegetationSystemBounds,
                                                           BiomeType.Default, null, defaultBiomeVegetationPackagePro.TerrainTextureSettingsList,
                                                           heightCurveSampleHeight, worldspaceSeaLevel, clearLockedTextures);

            List <BiomeType> additionalBiomeList = VegetationSystemPro.GetAdditionalBiomeList();

            List <VegetationPackagePro> additionalVegetationPackageList = new List <VegetationPackagePro>();

            for (int i = 0; i <= additionalBiomeList.Count - 1; i++)
            {
                additionalVegetationPackageList.Add(
                    VegetationSystemPro.GetVegetationPackageFromBiome(additionalBiomeList[i]));
            }
            BiomeSortOrderComparer biomeSortOrderComparer = new BiomeSortOrderComparer();

            additionalVegetationPackageList.Sort(biomeSortOrderComparer);

            for (int i = 0; i <= additionalVegetationPackageList.Count - 1; i++)
            {
                VegetationPackagePro currentVegetationPackagePro = additionalVegetationPackageList[i];
                if (!currentVegetationPackagePro.GenerateBiomeSplamap)
                {
                    continue;
                }

                List <PolygonBiomeMask> biomeMaskList = VegetationStudioManager.GetBiomeMasks(currentVegetationPackagePro.BiomeType);
                iVegetationStudioTerrain.GenerateSplatMapBiome(VegetationSystemPro.VegetationSystemBounds,
                                                               currentVegetationPackagePro.BiomeType, biomeMaskList, currentVegetationPackagePro.TerrainTextureSettingsList, heightCurveSampleHeight, worldspaceSeaLevel, clearLockedTextures);
            }

            JobHandle.ScheduleBatchedJobs();
            iVegetationStudioTerrain.CompleteSplatmapGeneration();
            DisposeTextureCurves();
        }
Example #10
0
        public void SetSplatPrototypes(VegetationPackagePro vegetationPackage)
        {
#if UNITY_2018_3_OR_NEWER
            TerrainLayer[] terrainLayers = new TerrainLayer[vegetationPackage.TerrainTextureList.Count];
            for (int i = 0; i <= vegetationPackage.TerrainTextureList.Count - 1; i++)
            {
                TerrainTextureInfo terrainTextureInfo = vegetationPackage.TerrainTextureList[i];
                TerrainLayer       terrainLayer       = terrainTextureInfo.TerrainLayer;

                if (terrainLayer == null)
                {
                    terrainLayer = new TerrainLayer
                    {
                        diffuseTexture   = terrainTextureInfo.Texture,
                        normalMapTexture = terrainTextureInfo.TextureNormals,
                        tileSize         = terrainTextureInfo.TileSize,
                        tileOffset       = terrainTextureInfo.Offset
                    };
#if UNITY_EDITOR
                    if (!Application.isPlaying)
                    {
                        terrainLayer = SaveTerrainLayer(terrainLayer, vegetationPackage);
                    }
                    EditorUtility.SetDirty(vegetationPackage);
#endif
                    terrainTextureInfo.TerrainLayer = terrainLayer;
                }
                else
                {
                    terrainLayer.diffuseTexture   = terrainTextureInfo.Texture;
                    terrainLayer.normalMapTexture = terrainTextureInfo.TextureNormals;
                    terrainLayer.tileSize         = terrainTextureInfo.TileSize;
                    terrainLayer.tileOffset       = terrainTextureInfo.Offset;
#if UNITY_EDITOR
                    EditorUtility.SetDirty(terrainLayer);
#endif
                }
                terrainLayers[i] = terrainLayer;
            }

            for (int i = 0; i <= VegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
            {
                IVegetationStudioTerrain iVegetationStudioTerrain = VegetationSystemPro.VegetationStudioTerrainList[i];
                if (iVegetationStudioTerrain.HasTerrainTextures())
                {
                    iVegetationStudioTerrain.SetTerrainLayers(terrainLayers);
                }
            }
#else
            SplatPrototype[] splatPrototypes = new SplatPrototype[vegetationPackage.TerrainTextureList.Count];
            for (int i = 0; i <= vegetationPackage.TerrainTextureList.Count - 1; i++)
            {
                TerrainTextureInfo terrainTextureInfo = vegetationPackage.TerrainTextureList[i];

                SplatPrototype splatPrototype = new SplatPrototype
                {
                    texture    = terrainTextureInfo.Texture,
                    normalMap  = terrainTextureInfo.TextureNormals,
                    tileSize   = terrainTextureInfo.TileSize,
                    tileOffset = terrainTextureInfo.Offset
                };
                splatPrototypes[i] = splatPrototype;
            }

            for (int i = 0; i <= VegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
            {
                IVegetationStudioTerrain iVegetationStudioTerrain = VegetationSystemPro.VegetationStudioTerrainList[i];
                if (iVegetationStudioTerrain.HasTerrainTextures())
                {
                    iVegetationStudioTerrain.SetSplatPrototypes(splatPrototypes);
                }
            }
#endif
        }
        /// <summary>
        /// Create a list of bounds to process. Either all terrains combined or individually
        /// </summary>
        /// <returns></returns>
        public List <Bounds> GetBoundsToProcess()
        {
            List <Bounds> boundsList = new List <Bounds>();

            List <VegetationSystemPro> VegetationSystemList = VegetationStudioInstance.VegetationSystemList;

            for (int i = 0; i <= VegetationSystemList.Count - 1; i++)
            {
                VegetationSystemPro vegetationSystemPro = VegetationSystemList[i];

                switch (extension.boundsSettings.boundsProcessing)
                {
                case BoundsProcessing.CombinedTerrains:

                    // get combined bounds
                    Bounds bounds = vegetationSystemPro.VegetationSystemBounds;

                    // use these bounds
                    boundsList.Add(bounds);

                    break;

                case BoundsProcessing.IndividualTerrains:
                    for (int t = 0; t < vegetationSystemPro.VegetationStudioTerrainObjectList.Count; t++)
                    {
                        // get individual terrain bounds
                        GameObject terrain = vegetationSystemPro.VegetationStudioTerrainObjectList[t];

                        IVegetationStudioTerrain vegetationStudioTerrain = VegetationStudioTerrain.GetIVegetationStudioTerrain(terrain);
                        bounds = vegetationStudioTerrain.TerrainBounds;

                        // use these bounds
                        boundsList.Add(bounds);
                    }
                    break;

                case BoundsProcessing.Biome:

                    Bounds biomeBounds;

                    // get biome mask area
                    Vector2[] biomeClipPolygonXY = GetBiomeClipPolygon();

                    // use mask to get bounds
                    if (biomeClipPolygonXY != null)
                    {
                        Vector3[] biomeClipPolygonXZ = biomeClipPolygonXY.Select(item => new Vector3(item.x, 0, item.y)).ToArray();

                        biomeBounds = PolygonUtils.GetBounds(biomeClipPolygonXZ);
                    }
                    // fall back to the vegetation system mask
                    else
                    {
                        biomeBounds = vegetationSystemPro.VegetationSystemBounds;
                        Debug.LogError("Invalid biome clip polygon. Using vegetation system bounds");
                    }

                    // use these bounds
                    boundsList.Add(biomeBounds);

                    break;

                default:
                    throw new System.ArgumentException("Unsupported TerrainProcessing " + extension.boundsSettings.boundsProcessing);
                }
            }

            return(boundsList);
        }
Example #12
0
        public override void OnInspectorGUI()
        {
            HelpTopic = "obstacle-mask-creator";
            ShowLogo  = false;

            ObstacleMaskCreator obstacleMaskCreator = (ObstacleMaskCreator)target;
            VegetationSystemPro vegetationSystem    = obstacleMaskCreator.gameObject.GetComponent <VegetationSystemPro>();

            if (!vegetationSystem)
            {
                EditorGUILayout.HelpBox("Add this component to a GameObject with a VegetationSystem component.",
                                        MessageType.Error);
                return;
            }

            base.OnInspectorGUI();

            if (vegetationSystem)
            {
                GUILayout.BeginVertical("box");
                obstacleMaskCreator.AreaRect = EditorGUILayout.RectField("Area", obstacleMaskCreator.AreaRect);
                EditorGUILayout.HelpBox(
                    "You can snap the area to any added terrain, total world area or manually setting the area for generation.",
                    MessageType.Info);
                GUILayout.EndVertical();


                GUILayout.BeginVertical("box");
                GUILayout.BeginHorizontal();
                string[] terrains = new string[vegetationSystem.VegetationStudioTerrainList.Count];
                for (int i = 0; i <= vegetationSystem.VegetationStudioTerrainList.Count - 1; i++)
                {
                    terrains[i] = vegetationSystem.VegetationStudioTerrainObjectList[i].name;
                }

                _selectedTerrainIndex = EditorGUILayout.Popup("Select terrain", _selectedTerrainIndex, terrains);
                if (GUILayout.Button("Snap to terrain", GUILayout.Width(120)))
                {
                    IVegetationStudioTerrain iVegetationStudioTerrain =
                        vegetationSystem.VegetationStudioTerrainList[_selectedTerrainIndex];
                    Bounds bounds = iVegetationStudioTerrain.TerrainBounds;
                    obstacleMaskCreator.AreaRect = RectExtension.CreateRectFromBounds(bounds);
                }

                GUILayout.EndHorizontal();

                if (GUILayout.Button("Snap to world area"))
                {
                    obstacleMaskCreator.AreaRect =
                        RectExtension.CreateRectFromBounds(vegetationSystem.VegetationSystemBounds);
                }

                EditorGUILayout.HelpBox(
                    "You can snap the area to any added terrain, total world area or manually setting the rect.",
                    MessageType.Info);

                GUILayout.EndVertical();

                GUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("Settings", LabelStyle);
                obstacleMaskCreator.ObstacleMaskQuality =
                    (ObstacleMaskQuality)EditorGUILayout.EnumPopup("Mask resolution",
                                                                   obstacleMaskCreator.ObstacleMaskQuality);
                EditorGUILayout.HelpBox(
                    "Pixel resolution of the obstacle mask. Low = 1024x1024, Normal = 2048x2048, High = 4096x4096 and Ultra = 8192x8192",
                    MessageType.Info);
                obstacleMaskCreator.LayerMask       = LayerMaskField("Obstacle layers", obstacleMaskCreator.LayerMask);
                obstacleMaskCreator.MinimumDistance =
                    EditorGUILayout.Slider("Minimum distance", obstacleMaskCreator.MinimumDistance, 0, 10);

                GUILayout.EndVertical();


                GUILayout.BeginVertical("box");
                if (GUILayout.Button("Generate obstacle mask"))
                {
                    GenerateObstacleMask();
                }

                GUILayout.EndVertical();
            }
        }
Example #13
0
        public override void OnInspectorGUI()
        {
            HelpTopic = "vegetation-color-mask-creator";
            ShowLogo  = false;

            VegetationColorMaskCreator colorMaskCreator    = (VegetationColorMaskCreator)target;
            VegetationSystemPro        vegetationSystemPro = colorMaskCreator.gameObject.GetComponent <VegetationSystemPro>();

            if (!vegetationSystemPro)
            {
                {
                    EditorGUILayout.HelpBox("Add this component to a GameObject with a VegetationSystemPro component.",
                                            MessageType.Error);
                    return;
                }
            }

            base.OnInspectorGUI();

            if (vegetationSystemPro)
            {
                GUILayout.BeginVertical("box");
                colorMaskCreator.AreaRect = EditorGUILayout.RectField("Area", colorMaskCreator.AreaRect);
                EditorGUILayout.HelpBox(
                    "You can snap the area to any added terrain, total world area or manually setting the area for generation.",
                    MessageType.Info);
                GUILayout.EndVertical();


                GUILayout.BeginVertical("box");
                GUILayout.BeginHorizontal();
                string[] terrains = new string[vegetationSystemPro.VegetationStudioTerrainList.Count];
                for (int i = 0; i <= vegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
                {
                    terrains[i] = vegetationSystemPro.VegetationStudioTerrainObjectList[i].name;
                }

                _selectedTerrainIndex = EditorGUILayout.Popup("Select terrain", _selectedTerrainIndex, terrains);
                if (GUILayout.Button("Snap to terrain", GUILayout.Width(120)))
                {
                    IVegetationStudioTerrain iVegetationStudioTerrain =
                        vegetationSystemPro.VegetationStudioTerrainList[_selectedTerrainIndex];
                    Bounds bounds = iVegetationStudioTerrain.TerrainBounds;
                    colorMaskCreator.AreaRect = RectExtension.CreateRectFromBounds(bounds);
                }

                GUILayout.EndHorizontal();

                if (GUILayout.Button("Snap to world area"))
                {
                    colorMaskCreator.AreaRect =
                        RectExtension.CreateRectFromBounds(vegetationSystemPro.VegetationSystemBounds);
                }

                EditorGUILayout.HelpBox(
                    "You can snap the area to any added terrain, total world area or manually setting the rect.",
                    MessageType.Info);

                GUILayout.EndVertical();

                GUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("Settings", LabelStyle);
                colorMaskCreator.VegetationColorMaskQuality =
                    (VegetationColorMaskQuality)EditorGUILayout.EnumPopup("Mask resolution",
                                                                          colorMaskCreator.VegetationColorMaskQuality);
                EditorGUILayout.HelpBox(
                    "Pixel resolution of the mask background. Low = 1024x1024, Normal = 2048x2048, High = 4096x4096 and Ultra = 8192x8192",
                    MessageType.Info);

                colorMaskCreator.InvisibleLayer =
                    EditorGUILayout.IntSlider("Mask render layer", colorMaskCreator.InvisibleLayer, 0, 30);
                EditorGUILayout.HelpBox(
                    "Select a empty layer with no scene objects. This is used to render the color mask.",
                    MessageType.Info);

                colorMaskCreator.VegetationScale =
                    EditorGUILayout.Slider("Grass/Plant scale", colorMaskCreator.VegetationScale, 1f, 3f);
                EditorGUILayout.HelpBox(
                    "This will increase the scale of each individual grass/plant patch to compensate for grass plane orientation",
                    MessageType.Info);
                GUILayout.EndVertical();

                GUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("Included vegetation", LabelStyle);
                colorMaskCreator.IncludeGrass  = EditorGUILayout.Toggle("Include Grass", colorMaskCreator.IncludeGrass);
                colorMaskCreator.IncludePlants =
                    EditorGUILayout.Toggle("Include Plants", colorMaskCreator.IncludePlants);
                colorMaskCreator.IncludeTrees   = EditorGUILayout.Toggle("Include Trees", colorMaskCreator.IncludeTrees);
                colorMaskCreator.IncludeObjects =
                    EditorGUILayout.Toggle("Include Objects", colorMaskCreator.IncludeObjects);
                colorMaskCreator.IncludeLargeObjects =
                    EditorGUILayout.Toggle("Include Large Objects", colorMaskCreator.IncludeLargeObjects);
                GUILayout.EndVertical();

                if (GUILayout.Button("Generate vegetation color mask"))
                {
                    GenerateVegetationColorMask(vegetationSystemPro);
                }
            }
        }
Example #14
0
        public override void OnInspectorGUI()
        {
            HelpTopic = "vegetation-shadow-mask-creator";
            ShowLogo  = false;

            ShadowMaskCreator   shadowMaskCreator   = (ShadowMaskCreator)target;
            VegetationSystemPro vegetationSystemPro = shadowMaskCreator.gameObject.GetComponent <VegetationSystemPro>();

            if (!vegetationSystemPro)
            {
                {
                    EditorGUILayout.HelpBox("Add this component to a GameObject with a VegetationSystemPro component.",
                                            MessageType.Error);
                    return;
                }
            }

            base.OnInspectorGUI();

            if (vegetationSystemPro)
            {
                GUILayout.BeginVertical("box");
                shadowMaskCreator.AreaRect = EditorGUILayout.RectField("Area", shadowMaskCreator.AreaRect);
                EditorGUILayout.HelpBox(
                    "You can snap the area to any added terrain, total world area or manually setting the area for generation.",
                    MessageType.Info);
                GUILayout.EndVertical();


                GUILayout.BeginVertical("box");
                GUILayout.BeginHorizontal();
                string[] terrains = new string[vegetationSystemPro.VegetationStudioTerrainList.Count];
                for (int i = 0; i <= vegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
                {
                    terrains[i] = vegetationSystemPro.VegetationStudioTerrainObjectList[i].name;
                }

                _selectedTerrainIndex = EditorGUILayout.Popup("Select terrain", _selectedTerrainIndex, terrains);
                if (GUILayout.Button("Snap to terrain", GUILayout.Width(120)))
                {
                    IVegetationStudioTerrain iVegetationStudioTerrain =
                        vegetationSystemPro.VegetationStudioTerrainList[_selectedTerrainIndex];
                    Bounds bounds = iVegetationStudioTerrain.TerrainBounds;
                    shadowMaskCreator.AreaRect = RectExtension.CreateRectFromBounds(bounds);
                }

                GUILayout.EndHorizontal();

                if (GUILayout.Button("Snap to world area"))
                {
                    shadowMaskCreator.AreaRect =
                        RectExtension.CreateRectFromBounds(vegetationSystemPro.VegetationSystemBounds);
                }

                EditorGUILayout.HelpBox(
                    "You can snap the area to any added terrain, total world area or manually setting the rect.",
                    MessageType.Info);

                GUILayout.EndVertical();

                GUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("Settings", LabelStyle);
                shadowMaskCreator.ShadowMaskQuality =
                    (ShadowMaskQuality)EditorGUILayout.EnumPopup("Mask resolution",
                                                                 shadowMaskCreator.ShadowMaskQuality);
                EditorGUILayout.HelpBox(
                    "Pixel resolution of the shadow mask. Low = 1024x1024, Normal = 2048x2048, High = 4096x4096 and Ultra = 8192x8192",
                    MessageType.Info);

                GUILayout.EndVertical();

                GUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("Included vegetation", LabelStyle);
                shadowMaskCreator.IncludeTrees        = EditorGUILayout.Toggle("Include Trees", shadowMaskCreator.IncludeTrees);
                shadowMaskCreator.IncludeLargeObjects = EditorGUILayout.Toggle("Include Large Objects", shadowMaskCreator.IncludeLargeObjects);
                GUILayout.EndVertical();

                if (GUILayout.Button("Generate shadow mask"))
                {
                    GenerateVegetationShadowMask(vegetationSystemPro);
                }
            }
        }