@@ -1562,34 +1562,48 @@ long long int SurfaceMesh::selectVertex() {
15621562 // Make sure we can see edges
15631563 float oldEdgeWidth = getEdgeWidth ();
15641564 setEdgeWidth (1 .);
1565+
1566+ // Make sure we can see the mesh
15651567 this ->setEnabled (true );
15661568
1569+ // Allow picking vertices only
1570+ MeshSelectionMode oldSelectionMode = getSelectionMode ();
1571+ setSelectionMode (MeshSelectionMode::VerticesOnly);
1572+
15671573 long long int returnVertInd = -1 ;
15681574
1575+ // ImGui internally swaps cmd/ctrl on macOS
1576+ #ifdef __APPLE__
1577+ std::string selectMessage = " Hold cmd and left-click on the mesh to select a vertex" ;
1578+ #else
1579+ std::string selectMessage = " Hold ctrl and left-click on the mesh to select a vertex" ;
1580+ #endif
1581+
15691582 // Register the callback which creates the UI and does the hard work
15701583 auto focusedPopupUI = [&]() {
15711584 { // Create a window with instruction and a close button.
15721585 static bool showWindow = true ;
1573- ImGui::SetNextWindowSize (ImVec2 (300 , 0 ), ImGuiCond_Once);
1586+ ImGui::SetNextWindowSize (ImVec2 (400 , 0 ), ImGuiCond_Once);
15741587 ImGui::Begin (" Select vertex" , &showWindow);
15751588
15761589 ImGui::PushItemWidth (300 * options::uiScale);
1577- ImGui::TextUnformatted (" Hold ctrl and left-click to select a vertex " );
1578- ImGui::Separator ();
1590+ ImGui::TextUnformatted (selectMessage. c_str () );
1591+ ImGui::NewLine ();
15791592
15801593 // Choose by number
1581- ImGui::PushItemWidth (300 * options::uiScale);
1594+ ImGui::PushItemWidth (100 * options::uiScale);
1595+ ImGui::TextUnformatted (" Or, select by index" );
15821596 static int iV = -1 ;
1583- ImGui::InputInt (" index" , &iV);
1584- if (ImGui::Button (" Select by index " )) {
1597+ ImGui::InputInt (" vertex index" , &iV, 0 );
1598+ if (ImGui::Button (" Select" )) {
15851599 if (iV >= 0 && (size_t )iV < nVertices ()) {
15861600 returnVertInd = iV;
15871601 popContext ();
15881602 }
15891603 }
15901604 ImGui::PopItemWidth ();
15911605
1592- ImGui::Separator ();
1606+ ImGui::NewLine ();
15931607 if (ImGui::Button (" Abort" )) {
15941608 popContext ();
15951609 }
@@ -1600,17 +1614,15 @@ long long int SurfaceMesh::selectVertex() {
16001614 ImGuiIO& io = ImGui::GetIO ();
16011615 if (io.KeyCtrl && !io.WantCaptureMouse && ImGui::IsMouseClicked (0 )) {
16021616
1603- ImGuiIO& io = ImGui::GetIO ();
1604-
1605- // API is a giant mess..
1606- size_t pickInd;
16071617 ImVec2 p = ImGui::GetMousePos ();
1608- std::pair<Structure*, size_t > pickVal = pick::pickAtScreenCoords (glm::vec2{p.x , p.y });
1618+ PickResult pickResult = pickAtScreenCoords (glm::vec2{p.x , p.y });
1619+
1620+ if (pickResult.structure == this ) {
16091621
1610- if (pickVal. first == this ) {
1622+ SurfaceMeshPickResult surfacePickResult = interpretPickResult (pickResult);
16111623
1612- if (pickVal. second < nVertices () ) {
1613- returnVertInd = pickVal. second ;
1624+ if (surfacePickResult. elementType == MeshElement::VERTEX ) {
1625+ returnVertInd = surfacePickResult. index ;
16141626 popContext ();
16151627 }
16161628 }
@@ -1620,7 +1632,9 @@ long long int SurfaceMesh::selectVertex() {
16201632 // Pass control to the context we just created
16211633 pushContext (focusedPopupUI);
16221634
1623- setEdgeWidth (oldEdgeWidth); // restore edge setting
1635+ // Restore the old settings
1636+ setEdgeWidth (oldEdgeWidth);
1637+ setSelectionMode (oldSelectionMode);
16241638
16251639 return returnVertInd;
16261640}
0 commit comments