简体   繁体   English

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

[英]Mapping Wavefront .obj's vt to OpenGL texture coordinates

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. 一位艺术家朋友发给我一个由3DS Max 2009导出的.obj文件,该文件包含三个纹理坐标作为vt命令的参数。 And that's correct according to .obj specification. 根据.obj规范,这是正确的。 However, I'm not sure how to map UVW coordinates that are provided for a regular 2D .jpg texture. 但是,我不确定如何映射为常规2D .jpg纹理提供的UVW坐标。

This is relatively important for me, since I've played with 3DS Max trying to figure out how to force it to export just UV coordinates, but there appears to be no straightfoward way. 这对我来说相对重要,因为我玩3DS Max试图弄清楚如何强制它只导出UV坐标,但似乎没有直接的方式。 In this case this is just a skybox, but in other cases it might be something way more complex and not hand-fixable. 在这种情况下,这只是一个天空盒,但在其他情况下,它可能更复杂,而不是手动固定。

Thanks! 谢谢!

There's a section in the article What Is UVW Mapping? 文章“ 什么是UVW映射”中有一节 that explains: 这解释了:

You might question why you need a depth coordinate like W for a 2D plane. 您可能会质疑为什么需要像2D平面那样的深度坐标。 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. W坐标对三维程序材料也有意义。

In your case, you can simply ignore the W coordinate and only read the first two floats of lines that begin with vt . 在您的情况下,您可以简单地忽略W坐标,只读取以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. 这假设您并不十分担心W坐标占用的额外空间,因为.obj是一种非常低效的文件格式。

Personally I don't like using .obj in OpenGL because it provides vertex normals per face instead of per vertex. 我个人不喜欢在OpenGL中使用.obj,因为它提供了每个面而不是每个顶点的顶点法线。 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. 如果您想探索更有效的替代方案,请查看二进制格式,例如完整记录的.md2格式。 Also consider using glDrawElements if you're not utilizing it already. 如果你还没有使用它,也可以考虑使用glDrawElements。

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. 据我了解,w只是垂直于u和v描述的平面的平面中的坐标,因此简单的2d纹理映射很少需要它。

hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM