我想要一个3D模型,可以在Blender,Sketchup等模型中制作出来,然后离散化为3D矩阵。
您可能会说我想“我的世界”任意对象。(除了用于模拟)
一个例子:这是一个具有半球形末端的离散圆柱体:
我当前的想法是获取描述对象的顶点列表,并查看它们将占据矩阵中的哪些单元,然后将其标记为被对象占据。
1)这是一个好方法吗?
2)如果是,最简单的模型格式可以用来完成此任务,那么是否有一些标准的高质量库?
谢谢
create render engine for your model directly to 3D matrix not on screen (Volume rendering)
either use own soft render or OpenGL + GLSL or whatever...
clear matrix
with empty color
render your model to matrix
no CULL_FACE
removal, no Z buffer
and no PERSPECTIVE projection !!!
fill inside of mesh
cast ray for each row of the matrix and set as filled all those there are inside. At start of ray voxels are outside and when you hit any filled voxel then it is inside from that point. When you hit any filled voxel again then it is outside from that point and so on ...
In software render the write pixel is like this:
DWORD scr[ys][xs],DWORD zed[ys][xs]; // screen and Z buffers xs,ys is resolution
void setpixel(DWORD x,DWORD y,DWORD z,DWORD color) // x,y,z, are already projected
{
if ((x>=0)&&(x<xs)) // cut off out of screen pixels
if ((y>=0)&&(y<ys))
if (z<=zed[y][x]) // test Z buffer
scr[y][x]=color; // write color to pixel
}
So just change it to this:
DWORD vox[zs][ys][xs]; // voxel buffer (your 3D matrix)
void setpixel(DWORD x,DWORD y,DWORD z,DWORD color) // x,y,z, are already projected
{
if ((x>=0)&&(x<xs)) // cut off out of volume pixels
if ((y>=0)&&(y<ys))
if ((z>=0)&&(z<zs))
vox[z][y][x]=color; // write color to voxel
}
在OpenGL中,您可以绘制纹理阵列或使用3D纹理...我不使用DirectX,但我认为也可以在其中实现。这是我的GLSL示例:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句