行进立方体 Terrassing/Ridge 效果

Marching Cubes Terrassing/Ridge Effect

我正在实施一个行进立方体算法,该算法通常基于 Paul Bourke 的实施,并进行了一些重大调整:

基本上我改了他近80%的代码。我生成的网格有一些丑陋的梯田,我不确定如何避免它们。我假设对标量场使用浮点数就可以完成这项工作。这是一个普遍的影响吗?如何避免?

计算边上的顶点位置。 (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 作为这个例子的库。

正如 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]);