-1

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?

Nick
  • 862
  • 12
  • 35

2 Answers2

2

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.

BrunoLevy
  • 2,495
  • 17
  • 30
1

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.

Francis Cugler
  • 7,788
  • 2
  • 28
  • 59