从Blender中加载.obj文件

从Blender中加载.obj文件

问题描述:

我现在搜索了很长时间,找到了可以导入的内容 将Blender 3D .obj文件转换为xcode以便在iPhone应用程序上使用.

im searching now for a quite long time to find something working to import Blender 3D .obj files into xcode to use it on an iphone application.

我找不到描述如何在任何地方实现类似的东西!

i cant find a description how to implement something like that anywhere!

我不想使用任何引擎.我只想知道我必须采取的步骤 填充和基本操作.

i dont want to use any engine. i just want to know the steps i have to fullfill and the basic things to do.

www上实际上没有任何内容.您可以找到2005年-2008年的文章 但这还不是最新的,什么也没用.

there is really nothing on the www. you can find articles from 2005 - 2008 but thats all not up to date and nothing working.

那么,有人知道怎么做吗?

So, does anybody knows how to do that?

查看 libgdx 中的源代码>,然后看看objloader.他构建了可以加载obj文件的库,并且应该可以在多个平台(包括ios)上工作.通过阅读源代码,您将看到仅为顶点创建对象加载器确实很简单,但是当您开始关注法线和纹理坐标时,它会变得更加复杂.这是用于刮擦obj文件的简单算法(我将留待关联的tpl文件进行解析,以供读者自己研究):

take a look at the source in libgdx, and take a look at the objloader. He built the lib to be able to load obj files, and is supposed to work across multiple platforms (including ios). From reading the source you will see that creating an object loader for just the vertices is really simple, but becomes more complicated when you start caring about the normals and texture coords. Here is a simple algorithm for scraping an obj file (I will leave parsing the associated tpl file for the reader's own research):

  1. 读入文件的各行,并丢弃所有以#开头的行(注释)
  2. 顶点的外观如下:v 1.000 1.000 1.000,因此,如果行以'v '开头,请在空格处分割该行,然后将3个浮点作为顶点存储(并转换为浮点数).
  3. 法线看起来像:vn 1.000 1.000 1.000,因此,如果该行以'vn '开头,则与数字2相同,但将其存储为法线.
  4. 纹理坐标看起来像vt 1.000 1.000,具有可能的第三个[w]值,以相同的方式分割和存储线.
  5. 现在变得棘手,有些面部描述看起来像f 1/1/1 2/2/2 3/3/3,它们通过索引为形状的每个顶点(通常是三角形)描述了3个顶点/文本坐标/法线(按顺序).最困难的部分是obj文件类型使用三个索引,而不是像opengl或direct3d这样的索引.因此,您将不得不重新排列顶点/坐标/法线的顺序,以便可以在源代码上使用索引图.
  1. Read in the lines of the file, throwing out all lines that start with # (comments)
  2. Vertices look like: v 1.000 1.000 1.000, so, if line starts with 'v ' split the line on the spaces and store (and convert to float) the 3 floats as a vertice.
  3. Normals look like: vn 1.000 1.000 1.000, so, if the line starts with 'vn ' do the same as number 2, but store as a normal.
  4. Texture coords look like vt 1.000 1.000 with a possible 3rd [w] value, split and store the line in the same way.
  5. Now it gets tricky, there is the face descriptions that look like f 1/1/1 2/2/2 3/3/3 these are describing 3 vertices/textcoords/normals (in that order) for each of the vertices of a shape (normally they are triangles) by index. The hardest part about this is that the obj file type uses three indexes instead of one like opengl or direct3d. So you will have to shuffle around the order of your vertexes/coords/normals so that you can utilize indexed drawing on the sources.

例如基本上,您必须通过重新排列顺序使f 1/300/30 40/22/400 20/30/10变得更像f 1/1/1 2/2/2 40/40/40.

E.g. Basically you have to get the f 1/300/30 40/22/400 20/30/10 to become more like f 1/1/1 2/2/2 40/40/40 through reshuffling the order.

本网站使您对相同的算法,并向您展示了如何在高级算法中执行此操作的示例(在页面的中部向下移动),可以找到他引用的供您签出的源代码

This site gives you an idea of this same algorithm and shows you an example of how to go about this in a high level algorithm (go about midway down on the page), and the source code he references for you to check out can be found here.

无论如何,如果您需要其他帮助,请告诉我. :)

Anyways, let me know if you need anymore assistance. :)

顺便说一句,如果您看到类似这样的内容:f 1//4 2//5 3//7请勿惊慌,这是一个有效的预期文件,并且(在这种情况下)仅表示没有纹理坐标

By the way if you see something like this: f 1//4 2//5 3//7 don't be alarmed, this is a valid file as intended and just means (in this instance) that there are no texture coords