2

Let's say I have 8 positions representing the vertices of a polyhedron:

(0, 0, 0), (1, 0, 0), (1, 0, 1), (0, 0, 1),
(0, 1, 0), (1, 1, 0), (1, 1, 1), (0, 1, 1),

How to efficiently generate a list of pairs of indices representing the edges of this mesh?

[
    (0, 1), (1, 2), ...
]

The main goal is to draw the mesh with OpenGL using the GL_LINES primitive.

enter image description here

gmagno
  • 1,770
  • 1
  • 19
  • 40
  • extract it from here [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) look for `pnt` and `fac` arrays in the code the faces are the QUADs of the cube so convert each 4 indexes into your lines: `(0,1,2,3) -> 0,1,1,2,2,3,3,0` and ignore duplicate lines ... Another example is here [See complete GL+GLSL+VAO/VBO C++ example](https://stackoverflow.com/a/31913542/2521214) see `vao_ix[]` its the same as `fac` in previous link ... beware your points must be in the same order as mine if you want the indexes to match ... – Spektre Mar 14 '19 at 09:58
  • Apologies, I should have been more clear. I am looking for a generic solution to the problem, not for the specific case of the cube. I am not entirely sure, but this seems like one of those problems with no solution. I could think of an algorithm that would traverse the positions, look for the closest neighbors and create edges between them. There would be some use cases this algorithm would fail though... – gmagno Mar 14 '19 at 11:44
  • search for convex hull ... – Spektre Mar 14 '19 at 13:01
  • 1
    If your are looking for something different than the convex hull, then your problem is ill-posed. There is no unique way to extract a non-convex polyhedron from just a set of points. – Nico Schertler Mar 14 '19 at 16:07
  • @Nico, I see. What would be the best approach to represent a mesh of vertices that can be fed to a renderer to be drawn as either GL_LINES or GL_TRIANGLES? Please correct me if I am wrong: I assume there would be a single list of positions, but two sets of indices that the renderer would pick from depending on rendering options (wireframe or solid). This is effectively the problem I am trying to solve. I am now trying to figure out if scipy convex hull can generate both sets of indices. – gmagno Mar 14 '19 at 18:07
  • Yes, two index sets are a good option. – Nico Schertler Mar 14 '19 at 19:48
  • @gmagno you can also use single set of indices (triangles) and configure rendering to eider render triangles or wireframe ... from the same data see [How do you render primitives as wireframes in OpenGL?](https://stackoverflow.com/a/137649/2521214) – Spektre Mar 15 '19 at 07:02
  • @Spektre, that was my initial idea as well, it would much nicer. I am using the nanogui lib (python bindings) and I am not sure I can just call pyopengl calls in my drawing routing. I guess I need somehow to tell pyopengl to use nanogui opengl context or vice-versa. – gmagno Mar 15 '19 at 12:31
  • Also, is that modern opengl? Won't that conflict with whatever my shaders are doing with the geometry and fragments? – gmagno Mar 15 '19 at 12:33
  • @gmagno pipeline settings is the same ... we still use stuf from GL 1.0 in modern age ... you know glEnable/glDisable etc ... this one is no exception I think – Spektre Mar 15 '19 at 12:41

0 Answers0