将基本 3D 模型导入 OpenGL 应用程序 [英] Getting basic 3D models into an OpenGL app

查看:34
本文介绍了将基本 3D 模型导入 OpenGL 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的...我正在做简单的 OpenGL ES 编程,当我说简单时,我所做的最复杂的事情只不过是美化的斜面立方体和 L 形.(非常像俄罗斯方块,但在 3D 中.)但是,将所有顶点数据放入应用程序是 a)手动编码(UGH!)或 b)第 3 方游戏引擎(双 UGH!!!)或者您使用一些第 3 方文件类型导入器.(部分呃!)

Ok... I'm doing simple OpenGL ES programming and when I say simple, the most complicated things I do aren't much more than glorified beveled cubes and L-shapes. (Think very Tetris but in 3D.) However, getting all that vertex data into an app is either a) hand-coded (UGH!) or b) 3rd-party game engine (double-UGH!!!) or you use some 3rd-party filetype importer. (Partial Ugh!)

有一个例外.

我一直在 Mac 上使用一个名为 Cheetah3D 的程序,它是一个非常好的建模器(不是很好,但很可靠……很好)而且我在其他地方没有看到的一件事是能够导出您的模型直接转换为 c-ready 头文件.它为您导出所有数组,甚至为您提供渲染它们的代码(尽管在注释掉的块中作为参考.)

I've been using a program on the Mac called Cheetah3D which is a pretty good modeler (not great, but solid... good) and the one thing it has that I haven't seen elsewhere is the ability to export your models directly to c-ready header files. It exports all the arrays for you and even gives you the code to render them (albeit in a commented out block as a reference.)

虽然这对于我们所做的 90% 的工作都很好,但有些事情建模师不能,比如允许我为两个不同的面指定相同的顶点,但对每个面使用不同的法线......甚至在同一模型中混合平面法线和弯曲法线(或者更确切地说它们是如何渲染的).

While this is great for 90% of what we do, there are some things the modeler can't, like allowing me to specify the same vertex for two different faces but using a different normal for each one... or even to mix flat and curved normals (or rather how they render) in the same model.

请注意,这些特征很容易在 .obj 文件中描述,因为您的法线和顶点位于不同的数组中,您可以轻松地将它们与面一起指定,但它们不会以这种方式出现在头文件中.

Note those features are easily described in an .obj file since your normals and vertices are in different arrays that you can easily specify together with faces but they don't come out in the header file that way.

SO... obj 文件(或任何其他适用于此问题的文件类型...)将其放入您的代码的最佳方式?

SO... obj files (or any other file type that will work for that matter...) best way to get it into your code?

想法?

推荐答案

OBJ 文件格式.

任何从事 3D 工作的人,都应该编写一个 obj 模型加载器.

它是一种非常简单的文件格式.

Its a very simple file format.

v
t
n
f

地点:

  • v 是顶点.
  • t 是纹理坐标.
  • n 是正常的.
  • f 是脸.

一个示例 obj 文件段:

An example obj file segment:

v 1.0 0.1 0.1
t 1.0 0.0
n 1.0 1.0
f 1/1/1 1/1/1 1/1/1

所需要的只是存储上述的四个集合,并且在渲染顶点的面时,使用索引并执行简单的查找.简单的文件 I/O 在任何语言中都很容易完成,所以总而言之,使用 obj 文件非常容易.

All it takes is storing four collections of the above, and when it comes to rendering the face of a vertex, use the index and perform simple look ups. Simple file I/O is very easy to do in any language, so all in all, using an obj file is quite easy.

当然,obj 文件的缺点是它们会变得非常大.就我个人而言,我从来没有发现这是一个问题,并且经常以 obj 文件格式为起点,并删除一些重复来创建一个专门为我的应用程序定制的文件格式.

Naturally, the downside to obj files is they can get quite big. Personally, I've never found this an issue, and often take the obj file format as a starting point and remove some of the duplication to create a custom file format specially for my application.

这篇关于将基本 3D 模型导入 OpenGL 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆