将 Wavefront .obj 的 vt 映射到 OpenGL 纹理坐标
一位艺术家朋友给我发送了一个由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文章 什么是 UVW 贴图? 中有一节解释了:
在您的情况下,您可以简单地忽略 W 坐标,只读取以
vt
开头的行的前两个浮点数。 这假设您不太担心 W 坐标占用的额外空间,因为 .obj 一开始就是一种效率很低的文件格式。就我个人而言,我不喜欢在 OpenGL 中使用 .obj,因为它提供每个面而不是每个顶点的顶点法线。 要正确照亮对象,您必须复制顶点或通过平均面中周围顶点法线来计算法线。 如果您想探索更有效的替代方案,请查看二进制格式,例如完整记录的 .md2 格式。 如果您还没有使用 glDrawElements,也可以考虑使用它。
There's a section in the article What Is UVW Mapping? that explains:
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.
抱歉,如果我误解了你的问题。 但是你不能简单地忽略第三个参数 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.