使用 C++ 导入 3ds Max OBJ
我创建了一个 OBJ 加载器,可以将从 3DS Max 导出的 .OBJ 文件导入到我的简单 OpenGL 查看器/应用程序中。它的核心是在一些教程的帮助下编写的 Vector3.h。
它在我使用的几个模型上运行得很好,但我想要使用的模型有一些不同的东西没有被考虑在内。它的顶点有 4 个点,而不是 3 个。这是我正在使用的一条线的示例:
g Box02
usemtl Wood_Bark
s 4
f 1/1/1 2/2/1 3/3/1 4/4/2
f 4/1/3 3/2/3 5/3/3
第一个“f”线有 4 个我感兴趣的顶点。我的 Vertex3.h 采用 X、Y、Z。我的其他模型,所有行都像第二个“f”行,只有 3 个元素。我得到一个顶点超出范围,所以当我去检查它发生的位置时,我看到它在这条线上,所以我假设是因为线上有更多可以处理的数据。这是整个 Vertex3.h
这是失败的代码行。顶点是一个 Vector3。
tempVertices.push_back ( vertices[--vertex] );
我的问题是,第四点是什么?您如何在我的 Vector3.h 文件中解释这一点?似乎我需要创建一个 Vector4.h,如果线上只有 3 个变量,则忽略第 4 个变量。但我想更多地了解我正在处理的事情,以及有关如何做到这一点的任何提示。第四个元素是阿尔法还是其他什么?应该如何使用它,或者应该在 Vector3.h 的计算中使用它?
I have created a an OBJ loader that can import .OBJ files that were exported from 3DS Max into my simple OpenGL viewer / app. At the heart of this was a Vector3.h written with the help of some tutorials.
It worked great on a couple models I used, but the one I want to work with has something different that wasn't accounted for. It has 4 points in its vertices instead of 3. Here is a sample of a line I am working with:
g Box02
usemtl Wood_Bark
s 4
f 1/1/1 2/2/1 3/3/1 4/4/2
f 4/1/3 3/2/3 5/3/3
The first 'f' line has 4 vertices I am interested in. My Vertex3.h takes X, Y, Z. In the other models I had, all lines were like the second 'f' line, with only 3 elements. I am getting a vertex out of range, so when I went to check where it was happening, I saw it was on this line, so I assumed because there is more data on the line that can be handled. Here is the entire Vertex3.h
And this is the line of code that fails. vertices is a Vector3.
tempVertices.push_back ( vertices[--vertex] );
My question is, what is the 4th point? How would you account for that in something like my Vector3.h file? Seems like I need to create a Vector4.h, and ignore the 4th var if there is only 3 on the line. But I would like to know more about what I am dealing with, and any tips on how to do it. Is the 4th element an alpha or something? How should it be used, or should it be used at all in my calculations in Vector3.h?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不只导出为三角形?在 3ds max 中转换为 EMesh,使所有边缘可见,然后导出。或者只需使用适当的 OBJ 导出选项。
Why don't you export as triangles only? Convert to EMesh in 3ds max, make all edges visible, export. Or simply use the appropriate OBJ export option.
具有四个点的面称为四边形。通常,如果你想渲染它,你应该将它分成两个三角形。
例如,你有这样的:
你需要把它变成这样:
假设顶点逆时针旋转(OpenGL 中的默认值),从左上角开始,你可以制作两个三角形。第一个三角形的顶点将是四边形的第一个、第二个和第三个顶点。第二个三角形的顶点将是四边形的第三个、第四个和第一个顶点。
A face with four points is called a quad. Usually if you want to render it you should break it up into two triangles.
So for example, you have this:
You need to turn it into this:
Assuming the vertices go counter-clockwise (the default in OpenGL), starting from the upper left, you could make two triangles. The first triangle's vertices would be the quad's first, second, and third vertices. The second triangle's vertices would be the quad's third, fourth, and first vertices.