将 Wavefront .obj 的 vt 映射到 OpenGL 纹理坐标

发布于 2024-07-21 06:16:58 字数 267 浏览 3 评论 0原文

一位艺术家朋友给我发送了一个由 3DS Max 2009 导出的 .obj 文件,其中包含三个纹理坐标作为 vt 命令的参数。 根据 .obj 规范,这是正确的。 但是,我不确定如何映射为常规 2D .jpg 纹理提供的 UVW 坐标。

这对我来说相对重要,因为我尝试过使用 3DS Max 尝试找出如何强制它仅导出 UV 坐标,但似乎没有直接的方法。 在这种情况下,这只是一个天空盒,但在其他情况下,它可能会更复杂并且无法手动修复。

谢谢!

an artist friend has sent me an .obj file exported by 3DS Max 2009 which contains three texture coordinates as parameters to the vt command. And that's correct according to .obj specification. However, I'm not sure how to map U-V-W coordinates that are provided for a regular 2D .jpg texture.

This is relatively important for me, since I've played with 3DS Max trying to figure out how to force it to export just U-V coordinates, but there appears to be no straightfoward way. In this case this is just a skybox, but in other cases it might be something way more complex and not hand-fixable.

Thanks!

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

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

发布评论

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

评论(2

神魇的王 2024-07-28 06:16:59

文章 什么是 UVW 贴图? 中有一节解释了:

您可能会问为什么需要
深度坐标,如 2D 的 W
飞机。 原因之一是因为它是
有时能够翻转很有用
地图的方向,相对于
它的几何形状。 为此,您需要
第三个坐标。 W坐标
也有 3 维的意义
程序材料。

在您的情况下,您可以简单地忽略 W 坐标,只读取以 vt 开头的行的前两个浮点数。 这假设您不太担心 W 坐标占用的额外空间,因为 .obj 一开始就是一种效率很低的文件格式。

就我个人而言,我不喜欢在 OpenGL 中使用 .obj,因为它提供每个面而不是每个顶点的顶点法线。 要正确照亮对象,您必须复制顶点或通过平均面中周围顶点法线来计算法线。 如果您想探索更有效的替代方案,请查看二进制格式,例如完整记录的 .md2 格式。 如果您还没有使用 glDrawElements,也可以考虑使用它。

There's a section in the article What Is UVW Mapping? that explains:

You might question why you need a
depth coordinate like W for a 2D
plane. One reason is because it's
sometimes useful to be able to flip
the orientation of a map, relative to
its geometry. To do this, you need the
third coordinate. The W coordinate
also has a meaning for 3-dimensional
procedural materials.

In your case, you can simply ignore the W coordinate and only read the first two floats of lines that begin with vt. This assumes that you're not very worried about the extra space taken by the W coordinate since .obj is quite an inefficient file format to begin with.

Personally I don't like using .obj in OpenGL because it provides vertex normals per face instead of per vertex. To light an object properly you must either duplicate vertices or calculate normals by averaging the surrounding vertex normals in a face. If you want to explore more efficient alternatives, take a look at binary formats, such as the thoroughly documented .md2 format. Also consider using glDrawElements if you're not utilizing it already.

渔村楼浪 2024-07-28 06:16:59

抱歉,如果我误解了你的问题。 但是你不能简单地忽略第三个参数 w 吗?
据我了解,w只是与u和v描述的平面垂直的平面中的坐标,因此简单的2d纹理映射很少需要它。

希望这可以帮助。

sorry if I misunderstand your question. But could't you simply ignore the third parameter, w?
As I understand it, w is just a coordinate in a plane perpendicular to the plane described by u and v, so it is rarely needed for simple 2d texture mapping.

hope this helps.

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