Ejemplo n.º 1
0
    /// <summary>
    /// 异步效率测试代码,后期删掉
    /// </summary>
    /// <param name="terrain"></param>
    /// <param name="heightMap"></param>
    /// <param name="mapIndex"></param>
    /// <param name="dev"></param>
    /// <param name="level"></param>
    private async static void BatchSmoothAsync(Terrain terrain, float[,] heightMap, Vector2Int mapIndex, float dev, int level = 1)
    {
        if (terrain != null)
        {
            await Task.Run(() =>
            {
                Math2d.GaussianBlur(heightMap, dev, level);
                //Debug.Log(Test.TimeStr);
            });

            //Debug.Log(System.DateTime.Now.Millisecond + " :: " + Test.time);
            SetHeightMap(terrain, heightMap, mapIndex.x, mapIndex.y, false);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 平滑地形
    /// </summary>
    /// <param name="center">中心点</param>
    /// <param name="radius">半径</param>
    /// <param name="dev">这是高斯模糊的一个参数,会影响平滑的程度</param>
    /// <param name="level">构建高斯核的半径</param>
    public static void Smooth(Vector3 center, float radius, float dev, int level = 3)
    {
        center.x -= terrainSize.x / (heightMapRes - 1) * level;
        center.z -= terrainSize.z / (heightMapRes - 1) * level;
        radius   += terrainSize.x / (heightMapRes - 1) * level;
        HMArg   arg;
        Terrain terrain = InitHMArg(center, radius, out arg);

        if (terrain == null)
        {
            return;
        }
        // 利用高斯模糊做平滑处理
        Math2d.GaussianBlur(arg.heightMap, dev, level, false);
        SetHeightMap(terrain, arg.heightMap, arg.startMapIndex.x, arg.startMapIndex.y, false);
    }
Ejemplo n.º 3
0
 private static void BatchSmooth(Terrain terrain, float[,] heightMap, Vector2Int mapIndex, float dev, int level = 1)
 {
     if (terrain != null)
     {
         LoomA.RunAsync(() =>
         {
             for (int i = 0; i < 10; i++)
             {
                 Math2d.GaussianBlur(heightMap, dev, level);
             }
             LoomA.QueueOnMainThread(() =>
             {
                 SetHeightMap(terrain, heightMap, mapIndex.x, mapIndex.y, false);
             });
         });
     }
 }
        /// <summary>
        /// 平滑地形
        /// </summary>
        /// <param name="center">中心点</param>
        /// <param name="radius">半径</param>
        /// <param name="dev">这是高斯模糊的一个参数,会影响平滑的程度</param>
        /// <param name="level">构建高斯核的半径</param>
        private void InternalSmooth(Vector3 center, float radius, float dev, int level, bool regesterUndo, bool immediate)
        {
            center.x -= terrainSize.x / (heightMapRes - 1) * level;
            center.z -= terrainSize.z / (heightMapRes - 1) * level;
            radius   += terrainSize.x / (heightMapRes - 1) * level;

            if (!TryGetHeightMapCmd(center, radius, out HeightCmdData arg))
            {
                return;
            }

            if (regesterUndo)
            {
                RegisterUndo(new HeightCmd(new HeightCmdData(arg)));
            }

            // 利用高斯模糊做平滑处理
            Math2d.GaussianBlur(arg.heightMap, dev, level, false);
            SetHeightMap(arg.terrain, arg.heightMap, arg.startMapIndex.x, arg.startMapIndex.y, immediate);
        }