我正在实施一个基于Paul Bourke实施的行进立方体算法,并做了一些重大调整:
基本上我改变了近80%的代码。我生成的网格有一些丑陋的terrasses,我不知道如何避免它们。我假设使用标量字段的浮点数就可以完成这项工作。这是一种常见的影响吗?你怎么能避免它?
计算边缘上的顶点位置。 (cell.val [p1]包含给定顶点的标量值):
//if there is an intersection on this edge
if (cell.iEdgeFlags & (1 << iEdge))
{
const int* edge = a2iEdgeConnection[iEdge];
int p1 = edge[0];
int p2 = edge[1];
//find the approx intersection point by linear interpolation between the two edges and the density value
float length = cell.val[p1] / (cell.val[p2] + cell.val[p1]);
asEdgeVertex[iEdge] = cell.p[p1] + length * (cell.p[p2] - cell.p[p1]);
}
您可以在此处找到完整的源代码:https://github.com/DieOptimistin/MarchingCubes 我在这个例子中使用Ogre3D作为库。
答案 0 :(得分:0)
正如Andy Newmann所说,魔鬼在线性插值。正确的是:
float offset;
float delta = cell.val[p2] - cell.val[p1];
if (delta == 0) offset = 0.5;
else offset = (mTargetValue - cell.val[p1]) / delta;
asEdgeVertex[iEdge] = cell.p[p1] + offset* (cell.p[p2] - cell.p[p1]);