我想生成这样的东西:
我使用锐利曲线的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));
}
}
}
}
但它会产生飞行岛屿。 那么我该怎么做才能获得第一个截图结果?
答案 0 :(得分:0)
我无法说出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));
}
}
}
}