所以,我应该解释一下我想如何实现它。 我的想法非常简单,我想创建每个块并通过利用每个块本地的浮点网格来确定每个顶点的位置,然后我想将体素放置在一个大的64位整数网格中(每个块的位置推断通过它的整数值,0,0,0将是中间值,20,20,20将在x,y和z轴上离开二十个块)以创建一个更大的世界,我将执行一些检查来确定块将从它们在整数网格中的位置推断出来,这是我还没有弄清楚的。 (比得到它的运行不那么重要)创建体素系统并陷入困境,发现自己需要关于如何实现它的信息
什么我有问题:
- 搞清楚如何生成libnoise 3D Perlin杂,文件并没有在这个问题从我可以告诉碰并且我没有得到谷歌要求的体面结果。
- 以某种方式将块放置在整数网格中
- 搞清楚如何确定从网格中的位置推断块的固定程度(我认为这很简单,因为检查周围的块是什么和在这个网格中,根据这些数据确定它)
- 根据从整数网格推断出的位置稀疏地分散各种矿石,这一个相当简单,但是直到其他解决方案才能完成。
- 找出间隔树。
那么,有什么想法? 的相关到目前为止的代码(除去轻,闭塞,UV和正常计算的代码,因为它是无关的问题)
#define get(x, y, z)\
data[\
clamp(x, size)+\
clamp(y, size)*size+\
clamp(z, size)*size*size\
]
#define put(x,y,z, value)\
data[\
(x)+\
(y)*size+\
(z)*size*size\
] = value
#define index(x, y, x) clamp (x, size)+clamp(y, size)*size+clamp(z, size)*size*size
#define foreach_xyz(start, end) \
int x, y, z; \
float xf, yf, zf;\
for(x=(start); x<(end); x++\
{\
for(y=(start); y<(end); y++)\
{\
for (z=(start); z<(end); z++)\
{\
xf=(float)x/(float)size;\
xy=(float)y/(float)size;\
xz=(float)z/(float)size;
#define endfor }}}
//removed pointless code from here
typedef struct //vertices
{
float xVertex, yVertex, zVertex, wVertex;
} vertex;
//removed pointless code from here
typedef struct //cell
{
float leftCell, rightCell, topCell, bottomCell, frontCell, backCell;
} cell;
//removed pointless code from here
int primitiveCount_CUBE (int size, byte* data)
{
int value, count = 0;
foreach_xyz(0, size)
value = get(x,y,z)ĵ;
if(!value)
{
if(get(x+1, y, z)) count++;
if(get(x-1, y, z)) count++;
if(get(x, y+1, z)) count++;
if(get(x, y-1, z)) count++;
if(get(x, y, z+1)) count++;
if(get(x, y, z-1)) count++;
}
endfor
return count;
}
//removed pointless code from here
void setPos(vertex** posPtr, float x0, float y0, float z0,
float x1, float y1, float z1,
float x2, float y2, float z2,
float x3, float y3, float z3)
//removed pointless code from here
void setData(vertex posPtr,
float x0, float y0, float z0,
float x1, float y1, float z1,
float x2, float y2, float z2
float x3, float y3, float z3,
normal** normalPtr, float nx, float ny, float nz,
normal** sPtr, float sx, float sy, float sz,
normal** tPtr, float tx, float ty, float tz,
UV** UVPtr, int value,
color** lightPtr, color** gather,
float** occlusionPtr, float occlusion)
{
setPos(posPtr,
x0, y0, z0
x1, y1, z1,
x2, y2, y3,
x3, y3, z3);
setNormal(normalPtr, nx, ny, nz
sPtr, sx, sy, sz
tPtr, tx, ty, tz);
setUV(value, UVPtr);
setLight(gather, lightPtr);
setOcclusion(occlusion, occlusionPtr);
}
void tesselate(int size, unsigned char* data, cell* occlusion, color** gather,
vertex pos, normal* Normal, normal* s, normal* t, float outOcc,
UV* uv, color* light)
{
float n = 0.5;
int idx, value;
cell* Cell;
color* cellGather;
foreach_xyz(0, size)
idx = index(x,y,z);
cell = occlusion + idx;
cellGather = gather + idx;
if(get(x, y, z) == 0)
{
value = get(x-1, y, z)
if(value > 0)
setData(&pos, x-n, y-n, z-n,
x-n, y+n, z-n,
x-n, y+n, z+n,
x-n, y-n, z+n
&normal, 1, 0, 0,
&s, 0, 1, 0
&t, 0, 0, 1,
&UV, value,
&light, cellGather,
&outOcc, cell->leftCell);
value¨= get(x, y-1, z);
if(value== materials_cube.dirt)
{
value=materials_cube.grass;
}
if(value > 0)
setData(&pos, x-n, y-n, z-n,
x-n, y-n, z+n,
x+n, y-n, z+n,
x+n, y-n, z-n
&normal, 0, 1, 0,
&s, 0, 0, 1,
&t, 1, 0, 0,
&UV, value,
&light, cellGather
&outOcc, cell->bottomCell);
value = get(x, y+1, z);
if(value > 0)
setData(&pos, x-n, y+n, z-n,
x+n, y+n, z-n,
x+n, y+n, z+n,
x-n, y+n, z+n,
&normal, 0, -1, 0,
&s, 1, 0, 0,
&t, 0, 0, 1,
&UV, value,
&light, cellGather
&outOcc, cell->topCell);
value = get(x, y, z-1);
if(value > 0)
setData((&pos, x-n, y-n, z-n
x+n, y-n, z-n,
x+n, y+n, z-n,
x-n, y+n, z-n,
&normal, 0, 0, 1,
&s, 1, 0, 0,
&t, 0, 1, 0,
&UV, value,
&light, cellGather,
&outOcc, cell->backCell);
value = get(x, y, z+1);
if(value > 0)
setData(&pos, x-n, y-n, z+n,
x-n, y+n, z+n,
x+n, y+n, z+n,
x+n, y-n, x+n,
&normal, 0, 0, -1,
&s, 0, 1, 0,
&t, 1, 0, 0,
&UV, value,
&light, cellGather,
&outOcc, cell->frontCell);
}
endfor
}
bool neighbors(int size, byte* data, int x, int y, int z)
{
if(get(x-1, y, z)){return true;}
if(get(x+1, y, z)){return true;}
if(get(x, y-1, z)){return true;}
if(get(x, y+1, z)){return true;}
if(get(x, y, z-1)){return true;}
if(get(x, y, z+1)){return true;}
return false;
}
这就是只要我能得到它,你可能会注意到,此代码与使用C和python编写的某个演示程序非常相似,这是因为很多代码是在阅读完毕后写入的,并且它在我身上磨损很多
问题是它似乎不能覆盖我的问题,这让我对体素的工作原理有了更好的理解,只是这样。
那么,我应该如何去解决这个项目的任何指针?
P.S,这是一个和“战地3”是DOOM克隆的Minecraft克隆一样多,我想我会让你决定如何解释它。
哦,我做我的研究,我发现: 上0fps的职位,我相信大多数人都熟悉的博客 https://sites.google.com/site/letsmakeavoxelengine 和其他几个人,包括GPU的宝石3,踏着多维数据集和几个其他的事情,其中没有一个解决我的问题。
是否有一个原因,你需要编写这种可以很容易地被函数替换的丑陋的宏? – thokra
嗯,我写了他们的快速原型,它们将在代码工作时被替换。 – LordHexahedron
是的,但用宏调试代码是一个令人头痛的问题... – Spektre