diff --git a/extern/glow-extras b/extern/glow-extras index 5e1e1b78112ea28f6f0d402306f47c54b981dafe..e2c77eabecbde62e9c24dd8570e0d6452e7df63b 160000 --- a/extern/glow-extras +++ b/extern/glow-extras @@ -1 +1 @@ -Subproject commit 5e1e1b78112ea28f6f0d402306f47c54b981dafe +Subproject commit e2c77eabecbde62e9c24dd8570e0d6452e7df63b diff --git a/extern/typed-geometry b/extern/typed-geometry index 323e4ce1ad9385dcb6cb44358fedb63e42438901..36314b73b45aba62252fabfc142bd18b21d21acf 160000 --- a/extern/typed-geometry +++ b/extern/typed-geometry @@ -1 +1 @@ -Subproject commit 323e4ce1ad9385dcb6cb44358fedb63e42438901 +Subproject commit 36314b73b45aba62252fabfc142bd18b21d21acf diff --git a/samples/basic/viewer/main.cc b/samples/basic/viewer/main.cc index 0ef650b37b0e781ecef0456707c5321aa66c98c8..b52b9dc96e0da1face5eb1f141b6012abe8751a9 100644 --- a/samples/basic/viewer/main.cc +++ b/samples/basic/viewer/main.cc @@ -24,91 +24,9 @@ // path to sample files std::string const dataPath = glow::util::pathOf(__FILE__) + "/../../../data/"; -void picking_concept(pm::vertex_attribute<tg::pos3> const& pos) -{ - /*Picking concept that will be implemented first: User gives a list of ids (std::vector<uint_32t>) that will be stored in Picker. Number od ids - has to match the number of faces in the mesh. At first: Only implement for Triangle_Meshes!*/ - std::vector<uint32_t> col_ids = {1, 2}; - - // gv::view(pos, gv::pick(col_ids, [&](pm::face_index f, tg::pos3 world_pos, tg::dir3 normal) { std::cout << "face: " << std::endl; })); - - - /*gv::view(pos, gv::pick() - .on_hover([&](pm::face_index f, tg::pos3 world_pos, tg::dir3 normal){ - // std::cout << "face: " << f.idx << std::endl; - picking_result r; - r.picked_color = tg::color3::red; - - return r; - }) - .on_right_mouse_button([&](...) { ... }));*/ - - gv::view(pos, gv::pick([&](pm::face_index f, tg::pos3 world_pos, tg::dir3 normal) { - // std::cout << "face: " << f.idx << std::endl; - Picking_result r; - // r.picked_color = tg::color3::red; - - return r; - })); - - gv::view(pos, gv::pick([&](uint32_t f, tg::pos3 world_pos, tg::dir3 normal) { - // std::cout << "face: " << f.idx << std::endl; - Picking_result r; - // r.picked_color = tg::color3::red; - - return r; - })); - - // pm::face_attribute<pick_id> ids = ...; - // gv::view(pos, gv::pick(ids, [&](pm::face_handle f, tg::pos3 world_pos, tg::dir3 normal) { std::cout << "face: " << f.idx << std::endl; })); - - { - auto v = gv::view(); - auto picker = gv::pick([&](pick_id id) { - // do stuff with id - }); - pm::vertex_attribute<pick_id> point_ids; - pm::face_attribute<pick_id> face_ids; - pm::edge_attribute<pick_id> line_ids; - - gv::view(pos, picker); - gv::view(gv::points(pos)); - } - - { - auto v = gv::view(); - gv::view(pos, gv::pick([&](pm::face_handle f, tg::pos3 p) {})); - gv::view(gv::points(pos), gv::pick([&](pm::vertex_handle f, tg::pos3 p) {})); - gv::view(gv::lines(pos), gv::pick([&](pm::edge_handle f, tg::pos3 p) {})); - } -} - void simple_picking(pm::vertex_attribute<tg::pos3> const& pos, pm::face_attribute<tg::color3> const& col) { - // simple picking functionality, user-defined ids for primitives (i.e. triangles) + user-defined callback-function - /*{ - std::vector<uint32_t> col_ids = {1, 2}; - pick_id a; - a.id = 0; - pick_id b; - b.id = 1; - const std::vector<pick_id> col_ids_p = {a, b}; - gv::view(pos, col, col_ids_p, gv::pick([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { - std::cout << "Something has been picked! " << "ID: " << face_id << std::endl; - return; - })); - }*/ - - // simple picking functionality, primitive IDs defined internally | OLD VERSION - /*{ - gv::view(pos, col, gv::pick([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { - std::cout << "Something has been picked! " - << "ID: " << face_id << std::endl; - return; - })); - }*/ - - // NEW SPEC + { // In this case a Picker is defined for the Renderable (Picking Texture filled) but no callback will be executed. gv::view(pos, col, gv::pick(), "Picker defined without callback"); @@ -125,26 +43,31 @@ void simple_picking(pm::vertex_attribute<tg::pos3> const& pos, pm::face_attribut }), "simple picking: callback on left click"); } + { + // Only on_left_click callback defined - LineRenderable - uncolored + gv::view(gv::lines(pos), 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: " << 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; uint32_t face_id_i; tg::pos3 world_pos_i; tg::vec3 normal_i; - - //pm::Mesh m2; - //auto pos2 = m2.vertices().make_attribute<tg::pos3>(); - - bool changed = false; - auto [m2, pos2] = pm::copy(pos.mesh(), pos); - - //auto r = gv::make_renderable(pos); + + auto copy = pm::copy(pos.mesh(), pos); + auto m2 = copy._Myfirst._Val.get(); + auto pos2 = copy._Get_rest()._Myfirst._Val; gv::interactive([&](auto){ - - //auto const r = gv::make_renderable(pos); // need access to "to_primitive_index" at renderable->mPicker - gv::view(pos2, col, gv::pick().on_left_click([&face_index_i, &world_pos_i, &normal_i](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) { + 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; std::cout << "World_Position" << world_pos << std::endl; @@ -157,11 +80,6 @@ void simple_picking(pm::vertex_attribute<tg::pos3> const& pos, pm::face_attribut return; }), "picking interactive mode"); - /*if (r->hasPicker() && r->mPicker->to_primitive_index.has_value()) - { - face_index_i = r->mPicker.value().to_primitive_index->at(face_id_i); - }*/ - ImGui::Begin("Picking"); ImGui::Value("pm::face_index", face_index_i.value); @@ -185,9 +103,55 @@ void simple_picking(pm::vertex_attribute<tg::pos3> const& pos, pm::face_attribut }); } - { - gv::view(gv::points(pos)); // ONLY FOR COMPARISON - } + { + /* 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; + + 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; + + vertex_index_i = vertex_id.v_id.value(); + world_pos_i = world_pos; + normal_i = normal; + + return; + }), + "picking interactive mode - PointRenderable"); + + ImGui::Begin("Picking"); + + 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("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]); + } + + ImGui::End(); + }); + } { // Only on_left_click callback defined - PointRenderable - uncolored @@ -230,17 +194,6 @@ void simple_picking(pm::vertex_attribute<tg::pos3> const& pos, pm::face_attribut }), "picking MeshRenderable - callback on hover"); } - /*{ // DOES NOT WORK RIGHT NOW - NEEDS TO BE FIXED - // Access of according face_indices while picking. Enable mesh access. WARNING: Does only work when Picking IDs are automatically generated and NOT user-defined - gv::view(pos, col, gv::pick().on_left_click([&](pm::face_index id, tg::pos3 world_pos, tg::vec3 normal) { - // std::cout << "Something has been picked! ON_LEFT_CLICK" - // << "Face_index achieved" << id.value << std::endl; - // Mesh access at this point? - //Picking_result r; - return; - })); - }*/ - { // On_hover, on_right_click, and on_left_click callbacks defined simultaneously gv::view(pos, col,