openglgraphics3ddirect3dtetgen

Dynamically generate Triangle Lists for a Complex 3D Mesh


In my application, I have the shape and dimensions of a complex 3D solid (say a Cylinder Block) taken from user input. I need to construct vertex and index buffers for it.

Since the dimensions are taken from user input, I cannot user Blender or 3D Max to manually create my model. What is the textbook method to dynamically generate such a mesh?

I am looking for something that will generate the triangles given the vertices, edges and holes. Something like TetGen, though TetGen has no way of excluding the triangles which fall on the interior of the solid/mesh.


Solution

  • Sounds like you need to create an array of verticies, and a list of triangles each of which contains a list of 3 indicies into the vertex array. There is no easy way to do this. To draw a box, you need 8 veticies and 12 triangles (2 per side). Some representations will use explicit edge representations too. I suspect this is way more work than you want to do so.....

    What you need is a mesh library that can do CSG (composite solid geometry). This way you should be able to specify the dimensions of the block, and then the dimensions of the cylinders and tell it to cut them out for you (CSG difference). All the vertex and triangle management should be done for you. In the end, such a library should be able to export the mesh to some common formats. Only problem here is that I don't know the name of such a library. Something tells me that Blender can actually do all of this if you know how to script it. I also suspect there are 1 or 2 fairly good libraries out there.

    Google actually brought me back to StackOverflow with this:

    A Good 3D mesh library

    You may ultimately need to generate simple meshes programatically and manipulate them with a library if they don't provide functions for creating meshes (they all talk about manipulating a mesh or doing CSG).