Importing Models Into A OpenGL Project

梦想与她 提交于 2019-12-03 00:44:19

Blender can save files in .obj format, and a simple google search turns up several libraries for loading this into OpenGL. Here is one.

One of the simplest formats that can be used to export meshes is Wavefront OBJ (please search for it on Wikipedia as I'm only allowed to post one link at the moment). It's basically a text file that shouldn't be too hard to parse.

Or actually, if you're allowed to use GLUT, you could try and use its loader (as answered in OpenGL FAQ 24.040)

Don't worry about the object scale at the moment, you can always scale your object later. Just make sure you export it with local coordinates, not global (e.g. [0,0,0] should be the center of the object, not the world you're modelling).

I'd suggest not worrying about the scale of the objects for right now.

Now, the thing you're going to have to do is settle on a format for the 3D file. There are MANY options when exporting from a 3D program like Maya or Blender.

Might I recommend attempting a simple COLLADA importer. Specification information is here: http://www.khronos.org/files/collada_spec_1_4.pdf

Another spec I've been using lately would also probably be suitable for this is OBJ.

The specification for OBJ is located here: http://local.wasp.uwa.edu.au/~pbourke/dataformats/obj/

Also, there are several free sample 3D OBJ files located here. This will allow you to see the format of the files and really see how easy they can be to parse.

Keep in mind, OBJ can not support animation, and it is rather inefficient for rendering large scenes.

I'd say that the Obj format is a good balance for readability and functionality if you want to parse it yourself.

http://en.wikipedia.org/wiki/Obj

The easiest way would to be to find a library to do it for you but the possibilities would be limited to your chosen language.

You shouldn't be worrying about scale. OpenGL's matrices can easily rescale vertices.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!