纹理映射 NGon?

发布于 2024-09-01 01:53:51 字数 93 浏览 5 评论 0原文

我不知道如何去弄清楚如何映射 2D NGon(N 边多边形)的纹理坐标,这是如何做到的?

我想要实现的效果是让纹理适合多边形并相应地拉伸,以便整个纹理适合它。

I'm not sure how to go about figuring out how to map texture coordinates for a 2D NGon (N sided polygon) How can this be done?

The effect I'm trying to achieve is for the texture to fit on the polygon and stretch out accordingly so the whole texture fits on it.

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

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

发布评论

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

评论(1

寄居者 2024-09-08 01:53:51

请记住,在 OpenGL 中渲染 ngon 时,它只是一堆三角形。另外,您正在采用某种形状并尝试将其映射到矩形,因此您必须对如何执行此操作非常挑剔,因为从任何形状到矩形纹理都有许多不同的映射。

例如,如果我有一个形状像正方形且两个角之间有一个点的 5 边形,则很容易映射到纹理。当我把这个点拿出来时会发生什么?当我移动顶点时纹理坐标会改变吗?

一种方法是将 ngon 的周长映射到矩形的周长,其中 ngon 上从一个顶点到另一个顶点的距离被映射到围绕纹理圆周的 UV 坐标。例如,在它周围的 1/4 处,给它一个 UV 坐标 (1,0),在 ngon 周围的一半处,给顶点一个 UV 坐标 (1,1) 和 3/4 处在它周围,给它一个 UV 为 (0,1)——当然,你需要在点之间进行插值,因为 ngon 不会在每个顶点完美地对齐。

Remember that when rendering an ngon in OpenGL, it's just a whole bunch of triangles. Also, you're taking some shape and trying to map it to a rectangle, so you have to be extremely critical of how you wish to do this as there many different mappings going from any shape to a rectangular texture.

For example, if I have a 5-gon that is shaped like a square with a point in between two corners, it's easy to map to a texture. What happens when I pull that point out? Do the texture coordinates change when I move vertices around?

One way to do it is to map the circumference of the ngon to the circumference of the rectangle, where the distance traveled from vertex to vertex on the ngon is mapped to a UV coordinate around the circumference of the texture. For example, at 1/4 of the way around it, give it a UV coordinate of (1,0), at half way around the ngon, give the vertex a UV coordinate of (1,1) and 3/4 the way around it, give it a UV of (0,1)--you'll need to interpolate between points, of course, since an ngon won't line up perfectly at every vertex.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文