![](/img/trans.png)
[英]Making a procedural terrain with Transvoxel/Marching cubes and 3D perlin noise
[英]Using noise to generate marching cube terrain?
我已經在C#XNA中成功創建了行進多維數據集類,並且正在使用Lib噪聲生成3d Perlin噪聲,但是當我嘗試使用perlin噪聲的值作為行進多維數據集的密度來生成地形時,它會生成很大的行進其中具有看似隨機三角形的多維數據集。 我分離了行進的多維數據集,並給它分配了任意的3d密度數組,以便可以確保一切正常,並且看起來還不錯,並且我讓Terrain生成代碼生成了正常的多維數據集,並且得到了具有正常外觀的terrain,但是問題是是每個多維數據集的拐角從噪聲中獲取的值總是從負向正轉換得如此之快,以至於行進的多維數據集看起來像是混亂的混亂。
這是我用來生成地形的代碼:
public MarchingCube[, ,] getTerrainChunk(int size, int stepsize)
{
MarchingCube[, ,] temp = new MarchingCube[size / stepsize, size / stepsize, size / stepsize];
for (int x = 0; x < size; x += stepsize)
{
for (int y = 0; y <size; y += stepsize)
{
for (int z = 0; z < size; z += stepsize)
{
Vector3[] corners = { new Vector3(x,y,z), new Vector3(x,y+stepsize,z),new Vector3(x+stepsize,y+stepsize,z),new Vector3(x+stepsize,y,z), new Vector3(x,y,z+stepsize), new Vector3(x,y+stepsize,z+stepsize),
new Vector3(x+stepsize,y+stepsize,z+stepsize), new Vector3(x+stepsize,y,z+stepsize)};
float[] densities = { GetDensity(corners[0]),GetDensity(corners[1]),GetDensity(corners[2]),GetDensity(corners[3]),GetDensity(corners[4]),
GetDensity(corners[5]),GetDensity(corners[6]),GetDensity(corners[7])};
if (x == 0 && y == 0 && z == 0)
{
temp[x / stepsize, y / stepsize, z / stepsize] = new MarchingCube(densities, corners, device);
}
else
temp[x / stepsize, y / stepsize, z / stepsize] = new MarchingCube(densities, corners);
}
}
}
return temp;
}
GetDensity方法如下:
private float GetDensity(Vector3 point)
{
return (float)terrain.GetValue(point));
}
我認為問題是我沒有正確使用噪聲來獲取行進的多維數據集角的密度,但是到目前為止,我的Google搜索結果根本沒有太大幫助。 那么,有誰知道如何正確使用噪聲來生成平滑的地形? 還是其他原因導致此問題?
我在http://imgur.com/a/D1uMC上發布了屏幕截圖,其中前兩個是使用行進立方體顯示的,最后一個是普通立方體。
編輯:因此,從圖片中我發現行進的多維數據集實際上正在按照給定的值正常工作,問題出在我的噪音和我的使用方式上。有人知道任何好的資源嗎?用於基於噪聲的3d地形生成?
問題是我如何讀取噪音,默認情況下,我被令人難以置信地“縮小”,因此通過將步長更改為浮點數,然后使用較小的增量,我可以獲得所需的結果。 基本上“放大”了噪音區域。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.