/// <summary>
        /// Create the mask and put it in the root assets directory
        /// </summary>
        public void CreateMask()
        {
            // Check to see if we have an active terrain
            if (Terrain.activeTerrain == null)
            {
                Debug.LogError("You need an active terrain!");
                return;
            }

            // Get the terrain
            UnityHeightMap hm = new UnityHeightMap(Terrain.activeTerrain);

            // Create a heightmap for the mask
            HeightMap maskHm = new HeightMap(hm.Width(), hm.Depth());

            //Iterate though our terrain, at the resolution of the heightmap and pick up the height
            float testHeight;
            float nrmSeaLevel = m_seaLevel / Terrain.activeTerrain.terrainData.size.y;

            for (int x = 0; x < hm.Width(); x++)
            {
                for (int z = 0; z < hm.Depth(); z++)
                {
                    testHeight = hm[x, z];
                    if (testHeight < nrmSeaLevel)
                    {
                        continue;
                    }
                    else if (Gaia.GaiaUtils.Math_ApproximatelyEqual(testHeight, nrmSeaLevel))
                    {
                        //We have a shoreline, lets mask it
                        maskHm[x, z] = m_aboveWaterStrength;
                        MakeMask(x, z, nrmSeaLevel, m_maskSize, hm, maskHm);
                    }
                    else
                    {
                        maskHm[x, z] = m_aboveWaterStrength;
                    }
                }
            }

            maskHm.Flip();
            //maskHm.Smooth(1);


            string path = "Assets/GaiaMasks/";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            path = Path.Combine(path, GaiaCommon1.Utils.FixFileName(string.Format("TerrainShoreLineMask-{0:yyyyMMdd-HHmmss}", DateTime.Now)));
            Gaia.GaiaUtils.CompressToSingleChannelFileImage(maskHm.Heights(), path, TextureFormat.RGBA32, false, true);

            EditorUtility.DisplayDialog("Shoreline Masker", "Your shorline mask has been created at " + path, "OK");
        }
예제 #2
0
        /// <summary>
        /// Create a waterflow map from the terrain
        /// </summary>
        /// <param name="terrain">Terrain to create the waterflow map from</param>
        public void CreateWaterFlowMap(Terrain terrain)
        {
            m_heightMap = new UnityHeightMap(terrain);
            int width = m_heightMap.Width();
            int depth = m_heightMap.Depth();

            m_waterFlowMap = new HeightMap(width, depth);

            //Avoid edges for now
            for (int x = 1; x < (width - 1); x++)
            {
                for (int z = 1; z < (depth - 1); z++)
                {
                    TraceWaterFlow(x, z, width, depth);
                }
            }

            //Flip it so it matches the terrain
            m_waterFlowMap.Flip();

            //Smooth the water map
            m_waterFlowMap.Smooth(m_waterflowSmoothIterations);
        }