Dynamically create lists of triangles for complex 3D meshes

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 build vertex and index buffers for it.

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

I'm looking for something that will generate triangles given vertices, edges, and holes. Something like TetGen , although TetGen has no way to exclude triangles that fall inside the cabin / mesh.

+2


a source to share


3 answers


It looks like you need to create an array of vertices, and a list of triangles, each containing a list of 3 characters, into an array of vertices. There is no easy way to do this. To draw a box, you need 8 objects and 12 triangles (2 on each side). Some views will also use explicit boundary representations. I suspect this is more work than you want to do.

You need a mesh library that can do CSG (Composite Solid Geometry). So you should be able to specify the block sizes and then the cylinder sizes and tell him to cut them for you (CSG difference). All vertex and triangle management should be done for you. After all, such a library should be able to export the mesh in some common formats. The only problem 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 pretty good libraries out there.

Google actually brought me back to StackOverflow with this:



Nice 3D mesh library

Ultimately, you may need to programmatically create simple meshes and manipulate them using the library if they don't provide functions to create meshes (they all talk about mesh manipulation or CSG execution).

+1


a source


It depends a little on your requirements.

If you don't need to access the mesh after generation, but only need to render it, the fastest option is to create a vertex buffer with glGenBuffers

, map it to memory with glMapBuffer

, write your data to the buffer, then deselect it with glUnmapBuffer

. Drawing will be very fast because all data can be loaded into the graphics card's memory.

If you need to access the cell data after you create it, or if you plan on changing it regularly, you might be better off not building your vertex data in a regular array and using the vertex arrays with help glVertexPointer

and friends.



You can also use a combination: generate the cell data in main memory, then memcpy()

into the vertex mapped buffer.

Finally, if by "dimensions" you just mean scaling the entire object, you can create it offline in any 3D modeling program and use OpenGL transformations, for example glScale

, to apply dimensions to a mesh when rendering.

0


a source


I'm not sure if the Marching Cube algorithm would be any help ?.

0


a source







All Articles