【问题标题】:Cliffs terrain generation in minecraft-like game在类似我的世界的游戏中生成悬崖地形
【发布时间】:2014-06-25 19:37:56
【问题描述】:

我想生成这样的东西:
我使用带有尖锐曲线的 Perlin Noise,我的代码会产生这些悬崖: .

    for (int x = 0; x < sizeX; x++)
    {
        for (int z = 0; z < sizeZ; z++)
        {
            int floorY = map.GetMaxYNotWater(x, z);
            float n = hillsNoise.Noise(x, z);
            int hillY = (int)(curveHills.Evaluate(n) * 80f);
            if (hillY > floorY + 5)
            {
                for (int y = hillY; y > floorY; y--)
                {
                    map.SetBlock(GetBlock(y), new Vector3i(x, y, z));
                }
            }
        }
    }

我怎样才能“切割”它们来制作悬挂的东西?

我试着用额外的曲线来做这个:

    for (int x = 0; x < sizeX; x++)
    {
        for (int z = 0; z < sizeZ; z++)
        {
            int floorY = map.GetMaxYNotWater(x, z);
            float n = hillsNoise.Noise(x, z);
            int hillY = (int)(curveHills.Evaluate(n) * 80f);
            if (hillY > floorY + 5)
            {
                int c = 0;
                int max = hillY - floorY;
                max = (int)(max * curveHillsFull.Evaluate(n)) + 1;
                for (int y = hillY; y > floorY && c < max; y--, c++)
                {
                    map.SetBlock(GetBlock(y), new Vector3i(x, y, z));
                }
            }
        }
    }

但它会产生飞岛。 那么我该怎么做才能实现第一个截图结果呢?

【问题讨论】:

  • 如果将第二种算法的结果“减去”到第一种算法的结果会怎样?我猜这会造成一些漏洞
  • @BlackBear 不,它会从中心切开,但我需要从外面切开

标签: c# perlin-noise procedural-generation


【解决方案1】:

我不能说 Minecraft 是如何做到的,但根据我自己对体素地形的经验,处理它的最佳方法是将体素网格想象成云:每个体素都有一个密度,当那个时候密度足够高,它会成为云的“可见”部分,然后填充体素。

因此,与其计算最小和最大 Y 水平,不如计算密度值,如下所示:

    for (int x = 0; x < sizeX; x++)
    {
        for (int y = 0; y > sizeY; y--)
        {
            for (int z = 0; z < sizeZ; z++)
            {
                //This means less density at higher elevations, great for turning 
                //a uniform cloud into a terrain. Multiply this for flatter worlds
                float flatWorldDensity = y;

                //This calculates 3d Noise: you will probably have to tweak this 
                //heavily. Multiplying input co-ordinates will allow you to scale 
                //terrain features, while multiplying the noise itself will make the 
                //features stronger and more or less apparent
                float xNoise = hillsNoise.Noise(x, y);
                float yNoise = hillsNoise.Noise(x, z);
                float zNoise = hillsNoise.Noise(y, z);
                float 3dNoiseDensity = (xNoise + yNoise + zNoise) / 3;

                //And this adds them together. Change the constant "1" to get more or
                //less land material. Simple!
                float ActualDensity = flatWorldDensity + 3dNoiseDensity;
                if (ActualDensity > 1)
                {
                    map.SetBlock(GetBlock(y), new Vector3i(x, y, z));
                }
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多