Mouse Highlighting of Faces, Edges and Vertices

CAD systems allow users to select faces, edges and vertices with the mouse like the following (taken in FreeCAD).

face_edge_vertex_selection

I’m able to display a model without trouble, but am unsure how to replicate this mouse interaction functionality with Panda3D. I’ll also need to keep track of what’s highlighted, but I’m assuming that will flow out of the solution for how to select things with the mouse.

Should I:

  1. Try to use the collision system, such as what’s mentioned here: Drag-dropping NodePaths
  2. Keep track of the mouse position and map it on the 3D object manually, a partial solution seems to be mentioned here: Tooltips and selecting actors
  3. Something entirely different

I knew this functionality was going to be needed at some point, but in searching and thinking about it I don’t have a clear path forward yet. Any help would be appreciated.

I think you should understand that the system intended for rendering does not have this data to manage. You must program this data yourself and build a geometry based on it.

A collision system is the first thing you need. You must store all the vertices as collision objects, faces and polygons.

I think that the Bullet physics system can report a triangle-index in its ray-test results–but I’m not sure of how useful its data might be. Still, it could be worth looking into.

I’m not sure that you can rely on the Bullet triangle index corresponding to the index on the Panda side.

You could probably create a separate vertex column with a mesh number coupled with a vertex index number that you assign, then use render-to-texture to render a (possibly lower-resolution) version of the model using a shader that writes this index to the output channel. Then you can look up the pixel value at the mouse X, Y position and get the desired index values that way.
By rendering a thick-wireframed version and thick-points version of the mesh (using the setRenderMode* functions) on top of it to the same buffer, using different index values, you can determine whether you’re selecting something close to an edge or a point.

It may also be worth asking or looking into how @Epihaius’ Panda3D-based modelling program works.

2 Likes