예제 #1
0
        /// <summary>
        /// Smooth the active terrain - needs to be extended to all and to handle edges
        /// </summary>
        /// <param name="iterations">Number of smoothing iterations</param>
        public static void Smooth(int iterations)
        {
            UnityHeightMap hm = new UnityHeightMap(Terrain.activeTerrain);

            hm.Smooth(iterations);
            hm.SaveToTerrain(Terrain.activeTerrain);
        }
        /// <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");
        }
예제 #3
0
 public MaskedMeshParamters(UnityHeightMap heightMap, UnityHeightMap maskMap, float maskThreshold, int meshResolution, Vector3 meshScale, int meshType, WindingOrder winding)
 {
     Heightmap      = heightMap;
     Maskmap        = maskMap;
     MaskThreshold  = maskThreshold;
     MeshResolution = meshResolution;
     MeshScale      = meshScale;
     MeshType       = meshType;
     Winding        = winding;
 }
예제 #4
0
        /// <summary>
        /// Returns a heightmap that only contains the single color channel info of the original map
        /// </summary>
        /// <param name="channel">The color channel to return</param>
        /// <returns></returns>
        public UnityHeightMap GetColorChannelHeightMap()
        {
            UnityHeightMap returnMap = new UnityHeightMap(this);

            for (int hmX = 0; hmX < m_widthX; hmX++)
            {
                for (int hmZ = 0; hmZ < m_depthZ; hmZ++)
                {
                    returnMap.m_heights[hmX, hmZ] = this.m_heights[hmX, hmZ] / 3f;
                }
            }
            return(returnMap);
        }
 /// <summary>
 /// Initialise the extension
 /// </summary>
 public override void Initialise()
 {
     m_textureHM = new UnityHeightMap(m_grassMask);
     if (m_normaliseMask && m_textureHM.HasData())
     {
         m_textureHM.Normalise();
     }
     if (m_invertMask && m_textureHM.HasData())
     {
         m_textureHM.Invert();
     }
     if (m_flipMask && m_textureHM.HasData())
     {
         m_textureHM.Flip();
     }
 }
예제 #6
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);
        }
예제 #7
0
 /// <summary>
 /// Create a unity heightmap by replicating a source file
 /// </summary>
 /// <param name="source">Source heightmap</param>
 public UnityHeightMap(UnityHeightMap source) : base(source)
 {
     m_boundsWU = source.m_boundsWU;
     m_isDirty  = false;
 }
예제 #8
0
 /// <summary>
 /// Pick up latest terrain information
 /// </summary>
 public void Visualise()
 {
     m_terrainHeightMap = new UnityHeightMap(Gaia.TerrainHelper.GetActiveTerrain());
 }