Using tetrahedron to model deformable objects in OpenGL - opengl

I want to render a mesh made up of tetrahedron in OpenGL because I am trying to implement animation which requires the use of the 'finite element method'. As a novice of OpenGL, I am not quite sure how to approach this.
So far, I have come across NETGEN which is supposed to generate a tetrahedral mesh from an object. From the example I downloaded, it takes a .geo file for input and outputs a .vol file.
The .vol file has a lot of data points and variables listed inside. Is this a standard file to read in? Or is it proprietary depending on which software generates it? In other words, are there standard methods for rendering this kind of file or do I need to manually parse the data from the file and then somehow render it as GL_LINES, etc?

it takes a .geo file for input and outputs a .vol file
The name suffixes are absolutely nontelling.
Anyway, OpenGL deals with providing drawing tools only. There's no functionality to read in files, be it geometry or images. And thus there is no "standard OpenGL file format".
Indeed it's your deed to read in those files, either with a parser you write, or some third party library, and pass the data to OpenGL, then issuing the right commands to make OpenGL draw a picture from the data.

Related

How to work with .obj files in CGAL

I am trying to build a simple first person shooter using openGL, SDL and CGAL. I would like to be able to load objects with textures I create in blender into the game and use CGAL to perform computation on the objects/textures (such as subdivision for example) but I can not figure out how to a .obj file into CGAL containers I can work with.
Just using openGL and glut I am able to load .obj files into the game and map the textures to the objects using a vector for each of the coordinates of the obj and its corresponding texture.
Using CGAL I can load the object from a .obj file into a Polyhedron mesh using code I found here: http://jamesgregson.blogspot.ca/2012/05/example-code-for-building.html
What is the best way to work with .obj files in CGAL?
You will need to extend CGAL's vertex class in order to be able to store texture coordinates in it. There is in CGAL a ParameterizationMesh class that does more or less what you need:
http://doc.cgal.org/latest/Surface_mesh_parameterization/classParameterizationMesh__3.html
Then you got two options: (1) use ParameterizationMesh directly if it fits your needs or (2) see how ParameterizationMesh works and extends the vertices of CGAL Polyhedron and do something similar.
I am not familiar with CGAL but I have worked with *.obj files a few times. It would be a tedious task but you would need a few things to achieve your goal.
A file parser to parse your *.obj file for all the elements: vertex data, index data, texture coordinates, material data etc., that you will need in your engine.
A custom user defined struct with an appropriate constructor to contain those elements.
You will then need either stand alone functions or a ManagerClass object that will allow you to use your user defined vector of structs to convert them to a struct object that the CGAL library - API is expecting.
It seems that 1/2 your work is done since you can read in and load the model data from blender into your GameEngine and render the models correctly. You may have to modify your user defined struct, functions or class object to work with CGAL.
A good way to test if your file loader / parser is working correctly is to log your data structures into a text file format for easy reading. This way when you read the text file you can then test if you are getting the correct data.
In order to incorporate this into CGAL to do data processing you will need to know the library - api and which function calls to use, what kind of data they are expecting, and when or which order to call the methods.
This is not a definitive or direct answer to your current problem but should serve as a helpful guideline.

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.

The best way to export 3d mesh animation in order to use it in OpenGL

Suppose that I have a 3d model with animation in, say, Blender. I need to export this model to some file and then use it in OpenGL app, i.e. without hardcoding animations, but reading them from file. What format is the best solution?
OpenGL doesn't support any format directly, but the classic OBJ file format lines up very well with drawing with vertex arrays. Basically, OBJ lists all vertices independently of the geometry. This way, several objects can share the same points. All kinds of groupings are also possible.
Also, it is one of the earliest formats to support a wide range of spline curves & surfaces, including Bezier, B-Splines & NURBS.
A basic decription can be found here:
http://en.wikipedia.org/wiki/Wavefront_.obj_file
The complete OBJ spec can be found here:
http://www.martinreddy.net/gfx/3d/OBJ.spec
It's not as modern as WebGL, but it's simple, human readable and widely supported.
What format is the best solution?
OpenGL doesn't care about file formats. So feel free to choose whatever suits your needs best. Due to the rise of WebGL I started dumping whole Blender scenes into collections of JSON formated files.

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.

Using Blender/SketchUp Models in OpenGL

I'm making a renderer using OpenGL. I have textured models in Blender / Sketchup (I can exchange between the two easily), and I'd like to be able to export those files into my renderer. My initial idea was to simply export the raw faces and render those triangles, but I'd like to easily slice my texture files into texture coordinates as well.
By that, I mean that my model faces get carved into triangles. You can see in this image (reproduced below) that my curve becomes 24 triangles. I would like to know what texture coordinates to use for each triangle.
Would a DAE file be the easiest way to do that? I've been reading the specs for the format and it looks easy enough. I think I could parse the XML and faithfully recreate the models in OpenGL. I'm wondering if there is an easier way (i.e. one that doesn't reinvent the wheel).
If you're comfortable with parsing the .dae-format, sure use it. However, if you're only interested in exporting textured triangle meshes I would consider using the .obj format which is much more simple to parse. From what I can tell both Sketchup and Blender can export this format.
If binary formats don't scare you, I'd suggest writing a Blender & Sketchup plug-in and exporting the geometry pre-baked into packed vertex arrays.
The beautiful thing about this method is that there's no parsing or type conversion in your app. Everything is ready to be sent to the GPU in simple contiguous memory copies. Great for static geometry.
A stripped down blender exporter looks something like this:
#!BPY
import bpy, struct
from Blender import *
self.fh = open("MyFileName", "w")
m = bpy.data.meshes["MyMeshName"]
faces = m.faces
for face in faces:
for (vertex, uv) in zip(face.verts, face.uv):
self.fh.write(struct.pack('<fff', *vertex.co)) # coords
self.fh.write(struct.pack('<fff', *vertex.no)) # normals
self.fh.write(struct.pack('<ff', uv.x, uv.y)) # uvs
self.fh.close()
If you wish to parse .dae files, i would suggest to look into Collada parsers.
.dae is actually the extension for Collada files, the latest effort from the Khronos group (maintainers of OpenGL) to have a single unified file format for 3D data exchange.
As for the existing parsers, here is what I've come across:
collada-dom, the reference implementation. As the name suggests, it is just an abstraction of the XML tree.
FCollada, a nicer abstraction. However, this project has been dead for almost two years, and, from what I've gathered, it is unlikely that we'll see any update in the future.
OpenCollada, a recent new effort. Haven't tried it, but there is an active community behind it.
That being said, if your only goal is loading a simple piece of geometry with vertices, normals and texture coordinates, going with the .obj file format might be a quicker way.
Any decent file format used by modeling programs (such as Blender or Sketchup) will include all information necessary to recreate the geometry you see. This should include the geometry type (e.g. triangle strips, individual triangles, etc), the vertices and normals for the geometry, the material properties used, and also the textures used along with the appropriate texture coordinates. If anything is lacking from a potential file format, choose another one.
If you think that parsing XML is simple, then I hope you're planning on using existing libraries to do this, such as expat, Xerces, or some other language specific implementation.
When considering import/export, first try to find an open source library that can handle the import for you and make the data available to your program in a reasonable format. If that's not available, and you must write your own importer, then try to find a simple ASCII (not XML-based) or binary format that fits your needs. PLY might be suitable. Only as a a last resort, would I recommend trying to implement an importer for an XML-based format.
There's also:
Lib3DS - http://www.lib3ds.org/
LibOBJ (won't let me post link)
You should take a look at:
http://sketchup.google.com/community/developers.html
The sketchup team provides a C++ COM server for free. Using this, you can get access to lots of information about a .skp file.
You should be able to use this COM server to write a .skp importer for your application.
You should try to get the .tlb file if you can. This will give you access to smart pointers, which will simplify your importer (COM client)
I used the version 6 SDK (which included the tlb file). The current version of the SDK does not appear to include this file.
Someone posted a solution (for the missing tlb file) on the developer forums:
http://groups.google.com/group/su-sdk-fileshare/topics