gpt4 book ai didi

math - 带有行进立方体的隐式表面上的 CSG 操作

转载 作者:行者123 更新时间:2023-12-04 12:43:55 25 4
gpt4 key购买 nike

我使用行进立方体渲染等值面,(或者可能是 marching squares 因为这是 2D)并且我想做集合操作,例如集合差、交集和并集。我认为这很容易实现,只需在来自两个不同隐式曲面的两个顶点标量之间进行选择,但事实并非如此。

对于我的初始测试,我尝试了两个球体圆,以及设置操作差异。即 A - B。一个圆圈在移动,另一个圆圈是静止的。这是我在选择顶点标量和将角顶点分类为内部或外部时尝试的方法。代码是用 C++ 编写的。 OpenGL 用于渲染,但这并不重要。无任何正常渲染 CSG操作确实给出了预期的结果。

       void march(const vec2& cmin, //min x and y for the grid cell
const vec2& cmax, //max x and y for the grid cell
std::vector<vec2>& tri,
float iso,
float (*cmp1)(const vec2&), //distance from stationary circle
float (*cmp2)(const vec2&) //distance from moving circle
)
{
unsigned int squareindex = 0;
float scalar[4];
vec2 verts[8];
/* initial setup of the grid cell */
verts[0] = vec2(cmax.x, cmax.y);
verts[2] = vec2(cmin.x, cmax.y);
verts[4] = vec2(cmin.x, cmin.y);
verts[6] = vec2(cmax.x, cmin.y);

float s1,s2;
/**********************************
********For-loop of interest******
*******Set difference between ****
*******two implicit surfaces******
**********************************/
for(int i=0,j=0; i<4; ++i, j+=2){
s1 = cmp1(verts[j]);
s2 = cmp2(verts[j]);
if((s1 < iso)){ //if inside circle1
if((s2 < iso)){ //if inside circle2
scalar[i] = s2; //then set the scalar to the moving circle
} else {
scalar[i] = s1; //only inside circle1
squareindex |= (1<<i); //mark as inside
}
}
else {
scalar[i] = s1; //inside neither circle
}
}

if(squareindex == 0)
return;
/* Usual interpolation between edge points to compute
the new intersection points */
verts[1] = mix(iso, verts[0], verts[2], scalar[0], scalar[1]);
verts[3] = mix(iso, verts[2], verts[4], scalar[1], scalar[2]);
verts[5] = mix(iso, verts[4], verts[6], scalar[2], scalar[3]);
verts[7] = mix(iso, verts[6], verts[0], scalar[3], scalar[0]);

for(int i=0; i<10; ++i){ //10 = maxmimum 3 triangles, + one end token
int index = triTable[squareindex][i]; //look up our indices for triangulation
if(index == -1)
break;
tri.push_back(verts[index]);
}
}

这给了我奇怪的锯齿: here
(来源: mechcore.net)

看起来 CSG 操作是在没有插值的情况下完成的。它只是“丢弃”整个三角形。我是否需要以其他方式进行插值,或组合顶点标量值?我很想得到一些帮助。
完整的测试用例可以下载 HERE

编辑:基本上,我对行进方块的实现效果很好。这是我的标量场被破坏了,我想知道正确的方法会是什么样子。最好我正在寻找一种通用方法来实现我上面讨论的三个集合操作,对于通常的基元(圆形、矩形/正方形、平面)

编辑 2:以下是实现回答者白皮书后的一些新图像:

1.Difference
2.Intersection
3.Union

编辑 3:我也在 3D 中实现了这一点,并使用了适当的阴影/照明:

1.Difference between a greater sphere and a smaller sphere
2.Difference between a greater sphere and a smaller sphere in the center, clipped by two planes on both sides, and then union with a sphere in the center.
3.Union between two cylinders.

最佳答案

这不是混合标量场的方式。您的标量说的是一件事,但无论您是否在里面,您的旗帜都说另一件事。首先合并字段,然后渲染,就像你在做一个单一的复合对象:

for(int i=0,j=0; i<4; ++i, j+=2){
s1 = cmp1(verts[j]);
s2 = cmp2(verts[j]);
s = max(s1, iso-s2); // This is the secret sauce
if(s < iso) { // inside circle1, but not inside circle2
squareindex |= (1<<i);
}
scalar[i] = s;
}

这篇文章可能会有所帮助: Combining CSG modeling with soft blending usingLipschitz-based implicit surfaces .

关于math - 带有行进立方体的隐式表面上的 CSG 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2882008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com