我如何在粘性中摆脱球体表面上的锯齿ZAG伪像?

发布于 2025-01-21 06:12:58 字数 1004 浏览 1 评论 0原文

我正在研究太阳系中行星的3D可视化。当我要应用纹理时,我已经手动计算了纹理坐标(texcoords),但是,我得到图像中的锯齿形伪像

我相信我的计算可能是错误的。我已经附上了texcoords计算:

# Compute Texture Coordinates  
def get_texcoords(vertices):
    texcoords = []
    for v in vertices:
        #thresholding
        for i in range(3):
            if np.abs(v[i]) > 1e-6:
                v[i] = v[i]
            elif np.abs(v[i]) < 1e-6:
                v[i] = 0.0

        # Compute position in uv-space
        radius = np.sqrt(v[0]**2 + v[1]**2 + v[2]**2)
        
        latitude = np.arcsin(v[2]/radius)
        longitude = np.arctan2(v[1],v[0])
            
        # Convert to texture coordinates
        u = round(0.5 + longitude/(2*np.pi),5)
        v = round(0.5 + latitude/np.pi,5)

        texcoords.append([u,v])
            
    return np.array(texcoords)

有什么方法可以删除工件?还是在vispy中获得纹理坐标的智能方法?

I'm working on the 3D visualization of planets in the solar system. As I am going to apply texture, I have manually computed the texture coordinates (texcoords), however, I get zig-zag artefacts appeearing in the image.

I believe that my computation might be wrong. I have attached the texcoords computation below:

# Compute Texture Coordinates  
def get_texcoords(vertices):
    texcoords = []
    for v in vertices:
        #thresholding
        for i in range(3):
            if np.abs(v[i]) > 1e-6:
                v[i] = v[i]
            elif np.abs(v[i]) < 1e-6:
                v[i] = 0.0

        # Compute position in uv-space
        radius = np.sqrt(v[0]**2 + v[1]**2 + v[2]**2)
        
        latitude = np.arcsin(v[2]/radius)
        longitude = np.arctan2(v[1],v[0])
            
        # Convert to texture coordinates
        u = round(0.5 + longitude/(2*np.pi),5)
        v = round(0.5 + latitude/np.pi,5)

        texcoords.append([u,v])
            
    return np.array(texcoords)

Is there any way to remove the artefacts? Or is there a smarter way to obtain texture coordinates in vispy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情魔剑神 2025-01-28 06:12:58

也许使用“在顶点中的V for V:”与使用纹理脐带变量名称为“ u”和“ v”?我不确定它会产生该工件,但是绝对不建议在不谨慎的情况下修改迭代器内部的迭代器。实际上不建议以任何方式推荐。那是我的最初看法。我正在使用同样的算法,所以一旦我开始工作,我会知道这是否是您的问题的原因。

我刚刚找到了此链接,该链接解释了紫外线映射算法中潜伏的错误: https:https:// mft:// mft -dev.dk/uv-mapping-sphere/

简而言之,一些网状三角形越过纹理边界,其中一些最终被“翻转”(即他们的脸正常点向内而不是向外)) 。链接中的文章显示了如何找到这些流氓面孔并修复它们。

我一直在挠头,一天左右。

maybe using "for v in vertices:" in conjunction with using texture cordinate variable names to be "u" and "v" ?? I'm not sure it would produce that artifact, but it is definitely not recommended to modify your iterator inside its loop without being extremely cautious. Not recommended in any manner, actually. That's my initial take. I'm using this same algorithm so once I get mine working I'll know if it's the cause of your issue.

I just found this link which explains the error lurking in the uv mapping algorithm: https://mft-dev.dk/uv-mapping-sphere/

In a nutshell, some of the mesh triangles cross the texture boundary, and some of those end up getting 'flipped' (i.e. their face normal points inward rather then outward). The article in the link shows how do find these rogue faces and fixes them.

I have been scratching my head over this one for a day or so.

南烟 2025-01-28 06:12:58

这是一个代码段,它将在没有Zig-Zag伪像的情况下生成适当的网格:

代码来自: https://www.songho.ca/opengl/index.html

colstep = 2 * pi / cols
    rowstep = pi / rows
    num_v = -1  # these counters are for logging/debuging
    num_f = -1
    num_e = -1
    num_eh = -1
    num_ev = -1

    for row in range(0, rows + 1):

        phi = pi / 2 - row * rowstep
        xy = radius[1] * cos(phi)
        z = radius[2] * sin(phi)

        for col in range(0, cols + 1):
            theta = col * colstep
            x = xy * cos(theta)
            y = xy * sin(theta)
            vert = np.array([x, y, z])
            # print(vert)
            self._verts.append(vert)
            self._norms.append(vert / np.sqrt(vert.dot(vert)))
            self._txcds.append(np.array([(col / cols), (row / rows)]))
            num_v += 1
    logging.info('----->>> Generated %r vertices...', num_v)

    for i in range(0, rows):

        k1 = i * (cols + 1)
        k2 = k1 + cols + 1

        for j in range(0, cols):

            if i != 0:
                self._faces.append(np.array([k1, k2, k1 + 1]))
                self._edges.append(np.array([k1, k2]))
                self._edges.append(np.array([k2, k1 + 1]))
                self._edges.append(np.array([k1 + 1, k1]))
                self._edge_colors.append((0, 0, 0, 1))
                self._edge_colors.append((0, 0, 0, 0))
                self._edge_colors.append((0, 0, 0, 1))
                num_f += 1
                num_e += 3
            if i != (rows - 1):
                self._faces.append(np.array([k1 + 1, k2, k2 + 1]))
                self._edges.append(np.array([k1 + 1, k2]))
                self._edges.append(np.array([k2, k2 + 1]))
                self._edges.append(np.array([k2 + 1, k1 + 1]))
                self._edge_colors.append((0, 0, 0, 0))
                self._edge_colors.append((0, 0, 0, 0))
                self._edge_colors.append((0, 0, 0, 0))
                num_f += 1
                num_e += 3

            k1 += 1
            k2 += 1

            self._v_edges.append(np.array([k1, k2]))
            num_ev += 1
            if i != 0:
                self._h_edges.append(np.array([k1, k1 + 1]))
                num_eh += 1

Here is a code snippet that will generate a proper mesh without the zig-zag artefact:

Code sourced from from: https://www.songho.ca/opengl/index.html

colstep = 2 * pi / cols
    rowstep = pi / rows
    num_v = -1  # these counters are for logging/debuging
    num_f = -1
    num_e = -1
    num_eh = -1
    num_ev = -1

    for row in range(0, rows + 1):

        phi = pi / 2 - row * rowstep
        xy = radius[1] * cos(phi)
        z = radius[2] * sin(phi)

        for col in range(0, cols + 1):
            theta = col * colstep
            x = xy * cos(theta)
            y = xy * sin(theta)
            vert = np.array([x, y, z])
            # print(vert)
            self._verts.append(vert)
            self._norms.append(vert / np.sqrt(vert.dot(vert)))
            self._txcds.append(np.array([(col / cols), (row / rows)]))
            num_v += 1
    logging.info('----->>> Generated %r vertices...', num_v)

    for i in range(0, rows):

        k1 = i * (cols + 1)
        k2 = k1 + cols + 1

        for j in range(0, cols):

            if i != 0:
                self._faces.append(np.array([k1, k2, k1 + 1]))
                self._edges.append(np.array([k1, k2]))
                self._edges.append(np.array([k2, k1 + 1]))
                self._edges.append(np.array([k1 + 1, k1]))
                self._edge_colors.append((0, 0, 0, 1))
                self._edge_colors.append((0, 0, 0, 0))
                self._edge_colors.append((0, 0, 0, 1))
                num_f += 1
                num_e += 3
            if i != (rows - 1):
                self._faces.append(np.array([k1 + 1, k2, k2 + 1]))
                self._edges.append(np.array([k1 + 1, k2]))
                self._edges.append(np.array([k2, k2 + 1]))
                self._edges.append(np.array([k2 + 1, k1 + 1]))
                self._edge_colors.append((0, 0, 0, 0))
                self._edge_colors.append((0, 0, 0, 0))
                self._edge_colors.append((0, 0, 0, 0))
                num_f += 1
                num_e += 3

            k1 += 1
            k2 += 1

            self._v_edges.append(np.array([k1, k2]))
            num_ev += 1
            if i != 0:
                self._h_edges.append(np.array([k1, k1 + 1]))
                num_eh += 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文