diff --git a/extern/glow-extras b/extern/glow-extras index 0181516b1bc0be26d0599913dc1b1d93a9df85f4..4b01559cc666838552b11990693b9150bdcbdda8 160000 --- a/extern/glow-extras +++ b/extern/glow-extras @@ -1 +1 @@ -Subproject commit 0181516b1bc0be26d0599913dc1b1d93a9df85f4 +Subproject commit 4b01559cc666838552b11990693b9150bdcbdda8 diff --git a/samples/basic/viewer/main.cc b/samples/basic/viewer/main.cc index e24ce5bb7293023aeb64fd9433a5b42d655a622a..a93b2e5f08ff4c4e92bf5c2a882e39f2669d217f 100644 --- a/samples/basic/viewer/main.cc +++ b/samples/basic/viewer/main.cc @@ -20,6 +20,7 @@ #include <polymesh/copy.hh> +#include <glow-extras/viewer/picking.hh> #include <tuple> @@ -35,13 +36,16 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a { // Only on_left_click callback defined - gv::view(pos, col, gv::pick().on_left_click([&](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) { + gv::view(pos, col, gv::pick().on_left_click([&](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) -> picking_result { std::cout << "Something has been picked! ON_LEFT_CLICK" << "ID: " << face_id.id << std::endl; std::cout << "World_Position" << world_pos << std::endl; std::cout << "Normal" << normal << std::endl; - return; - }), "simple picking: callback on left click"); + picking_result res; + res.picking_color = tg::color3::cyan; + return res; + }), + "simple picking: callback on left click"); } { @@ -51,14 +55,13 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a << "ID: " << face_id.id << std::endl; std::cout << "World_Position" << world_pos << std::endl; std::cout << "Normal" << normal << std::endl; - return; }), "picking LineRenderable - callback on left click"); } - { + { /* Picking in interactive mode with ImGui example. Does only work for MeshRenderable in the given configuration because face_indices are not included in Point- or LineRenderables.*/ - pm::face_index face_index_i; + pm::face_index face_index_i; uint32_t face_id_i; tg::pos3 world_pos_i; tg::vec3 normal_i; @@ -68,101 +71,98 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a pm::vertex_attribute<tg::pos3> pos2(m2); pos2.copy_from(pos); - - //auto [m2,pos2] = pm::copy(m, pos); - gv::interactive([&](auto){ - gv::view(pos2, col, gv::pick().on_left_click([&](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) { + gv::interactive([&](auto) { + gv::view(pos2, col, gv::pick().on_left_click([&](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) { std::cout << "Something has been picked! ON_LEFT_CLICK" - << "ID: " << int(face_id.f_id.value()) << std::endl; + << "ID: " << int(face_id.f_id) << std::endl; std::cout << "World_Position" << world_pos << std::endl; std::cout << "Normal" << normal << std::endl; - face_index_i = face_id.f_id.value(); + face_index_i = face_id.f_id; world_pos_i = world_pos; normal_i = normal; + }), + "picking interactive mode"); - return; - }), "picking interactive mode"); + ImGui::Begin("Picking"); - ImGui::Begin("Picking"); - - ImGui::Value("pm::face_index", face_index_i.value); + ImGui::Value("pm::face_index", face_index_i.value); - ImGui::Value("WorldPos.x", world_pos_i.x); + ImGui::Value("WorldPos.x", world_pos_i.x); ImGui::Value("WorldPos.y", world_pos_i.y); ImGui::Value("WorldPos.z", world_pos_i.z); - ImGui::Value("Normal.x", normal_i.x); + ImGui::Value("Normal.x", normal_i.x); ImGui::Value("Normal.y", normal_i.y); ImGui::Value("Normal.z", normal_i.z); - if (ImGui::Button("Delete selected face")) + if (ImGui::Button("Delete selected face")) { - //delete selected face - after deleting one face another face has to be picked + // delete selected face - after deleting one face another face has to be picked std::cout << "DELETE FACE" << std::endl; m2.faces().remove(m2.faces()[face_index_i]); } - ImGui::End(); + ImGui::End(); }); - } + } - { - /* Picking in interactive mode with ImGui example. Does only work for MeshRenderable in the given configuration because face_indices are not included in Point- or LineRenderables.*/ + { + /* Picking in interactive mode with ImGui example. Does only work for MeshRenderable in the given configuration because face_indices are not included in Point- or LineRenderables.*/ - pm::vertex_index vertex_index_i; - uint32_t vertex_id_i; - tg::pos3 world_pos_i; - tg::vec3 normal_i; + pm::vertex_index vertex_index_i; + uint32_t vertex_id_i; + tg::pos3 world_pos_i; + tg::vec3 normal_i; - pm::Mesh m2; - m2.copy_from(m); + pm::Mesh m2; + m2.copy_from(m); - pm::vertex_attribute<tg::pos3> pos2(m2); - pos2.copy_from(pos); + pm::vertex_attribute<tg::pos3> pos2(m2); + pos2.copy_from(pos); - //auto copy = pm::copy(pos.mesh(), pos); - //auto m2 = copy._Myfirst._Val.get(); - //auto pos2 = copy._Get_rest()._Myfirst._Val; + // auto copy = pm::copy(pos.mesh(), pos); + // auto m2 = copy._Myfirst._Val.get(); + // auto pos2 = copy._Get_rest()._Myfirst._Val; - gv::interactive([&](auto) { - gv::view(gv::points(pos2), gv::pick().on_left_click([&vertex_index_i, &world_pos_i, &normal_i](pick_id vertex_id, tg::pos3 world_pos, tg::vec3 normal) { - std::cout << "Something has been picked! ON_LEFT_CLICK" - << "ID: " << int(vertex_id.v_id.value()) << std::endl; - std::cout << "World_Position" << world_pos << std::endl; - std::cout << "Normal" << normal << std::endl; + gv::interactive([&](auto) { + gv::view(gv::points(pos2), gv::pick().on_left_click([&vertex_index_i, &world_pos_i, &normal_i](pick_id vertex_id, tg::pos3 world_pos, tg::vec3 normal) { + std::cout << "Something has been picked! ON_LEFT_CLICK" + << "ID: " << int(vertex_id.v_id) << std::endl; + std::cout << "World_Position" << world_pos << std::endl; + std::cout << "Normal" << normal << std::endl; - vertex_index_i = vertex_id.v_id.value(); - world_pos_i = world_pos; - normal_i = normal; + vertex_index_i = vertex_id.v_id; + world_pos_i = world_pos; + normal_i = normal; - return; - }), - "picking interactive mode - PointRenderable"); + return; + }), + "picking interactive mode - PointRenderable"); - ImGui::Begin("Picking"); + ImGui::Begin("Picking"); - ImGui::Value("pm::vertex_index", vertex_index_i.value); + ImGui::Value("pm::vertex_index", vertex_index_i.value); - ImGui::Value("WorldPos.x", world_pos_i.x); - ImGui::Value("WorldPos.y", world_pos_i.y); - ImGui::Value("WorldPos.z", world_pos_i.z); + ImGui::Value("WorldPos.x", world_pos_i.x); + ImGui::Value("WorldPos.y", world_pos_i.y); + ImGui::Value("WorldPos.z", world_pos_i.z); - ImGui::Value("Normal.x", normal_i.x); - ImGui::Value("Normal.y", normal_i.y); - ImGui::Value("Normal.z", normal_i.z); + ImGui::Value("Normal.x", normal_i.x); + ImGui::Value("Normal.y", normal_i.y); + ImGui::Value("Normal.z", normal_i.z); - if (ImGui::Button("Delete selected vertex")) - { - // delete selected vertex - after deleting one vertex another vertex has to be picked - std::cout << "DELETE VERTEX" << std::endl; - m2.vertices().remove(m2.vertices()[vertex_index_i]); - } + if (ImGui::Button("Delete selected vertex")) + { + // delete selected vertex - after deleting one vertex another vertex has to be picked + std::cout << "DELETE VERTEX" << std::endl; + m2.vertices().remove(m2.vertices()[vertex_index_i]); + } - ImGui::End(); - }); - } + ImGui::End(); + }); + } { // Only on_left_click callback defined - PointRenderable - uncolored @@ -172,7 +172,8 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a std::cout << "World_Position" << world_pos << std::endl; std::cout << "Normal" << normal << std::endl; return; - }), "picking PointRenderable - callback on left click - spheres"); + }), + "picking PointRenderable - callback on left click - spheres"); } { @@ -184,7 +185,8 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a std::cout << "World_Position" << world_pos << std::endl; std::cout << "Normal" << normal << std::endl; return; - }), "picking PointRenderables - callback on left click - billboards"); + }), + "picking PointRenderables - callback on left click - billboards"); } { @@ -193,7 +195,8 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a std::cout << "Something has been picked! ON_RIGHT_CLICK" << "ID: " << face_id.id << std::endl; return; - }), "picking MeshRenderable - callback on right click"); + }), + "picking MeshRenderable - callback on right click"); } { @@ -202,7 +205,8 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a std::cout << "Something has been picked! ON_HOVER" << "ID: " << face_id.id << std::endl; return; - }), "picking MeshRenderable - callback on hover"); + }), + "picking MeshRenderable - callback on hover"); } { @@ -250,7 +254,6 @@ void simple_picking(pm::Mesh& m, pm::vertex_attribute<tg::pos3>& pos, pm::face_a }), "picking MeshRenderable - user defined primitive IDs"); } - } void simple_view(pm::vertex_attribute<tg::pos3> const& pos)