How to export a blender file and open it in PyOpenGL? - pyopengl

I have a 3-D object I created in blender. I would like to export it from blender and be able to import it into OpenGL. Is there a method or specific file extension recommended for this process?

From Here:
Use obj files. Simple text files that describe a 3d model. Then in opengl load the data into vertex arrays, and display using openGL. There is also window management to take care of.
Try python SDL and/or pygame to get you started.
Here is a link to jump start you:
http://www.pygame.org/wiki/OBJFileLoader

Related

Make a model in Blender and load in opengl

I want to make a 3D model in Blender and load it in OpenGL. Can someone give a step-by-step approach on how to do so. I tried to google but did not get any proper results.
Programming language: C++,
Tools: GLFW + GLAD + GLM
Its a 3 step process, using external libraries.
Model in blender. Export from Blender to .obj format (also containing .mtl file with reference to textures used).
Refer to
https://blender.stackexchange.com/questions/121/how-do-i-export-a-model-to-obj-format
Use a library like Assimp to produce vertices and attributes.
Use the vertices and attributes in your OpenGL application, using a method like described in,
https://nickthecoder.wordpress.com/2013/01/20/mesh-loading-with-assimp/

How to import object in OpenGL and what file format to choose?

I want to create a robot and want to move it in OpenGL. I will create the model in 3DsMax.
I was wondering about importing and moving it in OpenGL.
In which format should I save my file in 3ds Max so that I can import it in OpenGL?
Should I use pivots or save each part of the robot as a seperate file?
Does OpenGL support pivots?
OpenGL has surprisingly little to do with the answer. OpenGL is only used to draw your geometry. It is not a rendering/game engine/scenegraph in itself. Therefore loading a mesh and animating it is something you should take care of, subsequently informing OpenGL what it has to draw.
You can however make your life a bit easier by looking for OpenGL based rendering/game engines/scenegraphs out there that already provide the support you desire. But you'll have to take a look at that yourself. Then export your mesh in whatever suitable format your engine supports. OpenGL itself holds no relevance to whatever file format you wish to use. If you or your engine can deal with it and get all the relevant information out of it, you can use it.

Loading meshes from .obj (or any other) File into DirectX9/C++ project

Currently I have a 3D Cube that I drew by writing coordinates, that can rotate and move on a black screen.
Now I have a Model that I created in "3Ds Max"(It's a little backyard with high stonewalls, so I'm trying to use it as my world object.) and I want to load this model into my DirectX9/C++ project.
As far as I see in DirectX SDK examples this code is for loading .X model (which needs a plugin for "3Ds Max" to export that kind of extension. I'm not sure of this.)
Code for loading .X files into DX9/C++:
D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL, &pD3DXMtrlBuffer, NULL,
&g_dwNumMaterials, &g_pMesh )
Is there a function like "D3DXLoadMeshFromOBJ(.....)" to load an Object? How do I load and render .OBJ files? 8(
Another question of mine is what is the difference between an .X file and an .OBJ file and which of them should I use?
AFAIK, DirectX does not support wavefront object files out of the box. You will need an external mesh loader for that purpose.
I can remember, that in the DX 10 SDK is a sample of how to load an .obj file, I think the sample is called MeshFromOBJ10. I don't know if it is of any use in DirectX 9.
As far as I know, the standard .x just supports basic meshes with no enhancements such as animation. If you want to try out graphical programming it is not bad, but if you are aiming for higher concepts you can later switch. I guess you can look up the advantages of the .obj files here.
It is always a good idea to create an abstraction for the input data you are using. For example, you could create a class AbstractMesh and an implementation XMesh deriving from it. Later on, you can than add other implementations like OBJMesh or anything similar.
I hope I could help you a bit :) Happy Coding!
Animation is full supported in x file format, and furthermore, it support fx files when you want to use shaders. A exporter plugin and samples you can download from this page:
http://www.cgdev.net/download.php

Importing 3D objects and its animation to iphone openGL

I am trying to develop a 3D game in openGL and i need to create many 3D objects.. I am a begginner in openGL.. I have tried with many 3D softwares like Blender , MODO, Unity 3D and Cheetah.
I am easily able to create my objects with these and exporting as Wavefront .OBJ, and converting it to a header file using a perl script. This header file is added to my openGL project..
The 3D objects are seen, but its not perfect. The script i used is to convert the .OBJ to .h using TRIANGLES.. And the object is seen with triangles. Its not full.. No way when i used TRIANGLE STRIP,FAN..? Problems with the vertices..
Is the problem with my Script or is it the wrong way i have gone..?? Or is there any other best ways to directly import 3D objects to openGL..??
The below link is the best one which you can get for 3D objects to openGL.. i got the scripts from these..
http://www.heikobehrens.net/2009/08/27/obj2opengl/
please help..
You don't want to go that way. Direct drawing mode (using TRIANGLE and friends) is extremely slow in OpenGL.
Instead, you should pick a decent format and write a loader for it (or use one found on the web). Good formats would be 3ds, obj if gzipped, collada.
Here's an example tutorial on loading from Milkshape files.
Once you load your objects programatically, you can use Vertex Arrays, or even better VBO's to display them. This is waaay faster.
Google for a mesh loader for your favorite format, or write one yourself.
I have written a reader/renderer for AC3D files that works fine on the iPhone (OpenGL ES)
Feel free to have a look at it here.
There is also an obj loader by Jeff Lamarche at google code.
AC3D can reduce the triangle count pretty good and as an alternative I ported QVis to the mac. My reader/renderer also tries to build tri-strips.
About VBO's. I have not seen any gained performance when using them in the iPhone. I'm not the only one.

3ds max object to opengl

I am trying to assemble a scene in opengl, using already made objects. The problem is that the object are in .max format and have no external textures. How could I import my objects in opengl, without retexturing them. I am thinking about exporting them to 3ds and using a 3ds file loader. Could you recommend one, and of course it has to work only with the 3ds file itself, no external texture files.
3ds max already allows me to export the file to obj. I have an object that has no external texture file, but it is already fully colored as a 3ds file. Is there any way to import in opengl and have the same colors, for the trunk, leaves?
You might want to check out lib3ds which will parse the 3ds binary format for you and give you access to all of the objects properties. I think Autodesk also has their own toolkit for doing this.
You should look at this link. It is a 3DS viewer with source code that renders using OpenGL. The code is simple.
Another option could be Assimp, an open source asset import library for C or C++, which seems like a pretty good way to get 3DS assets into an opengl program. It'd be especially useful if you want it for skeletal animations, and supports embedded textures. Though at this point, this answer may be less for you than it is for other people coming across this question.
If I remember correctly, the 3ds file does not store the vertex normals so you will probably have to calculate them yourself somehow or otherwise it will use the normal of the face itself which is will be quite ugly.