From 3b8d9e01d5da94f2c66010c831a38f373f34697a Mon Sep 17 00:00:00 2001 From: Aaron <aaron.kreuzberg@rwth-aachen.de> Date: Thu, 17 Jun 2021 00:03:05 +0200 Subject: [PATCH] changes in extern/glow-extras --- extern/glow-extras | 2 +- samples/basic/viewer/main.cc | 120 +++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 34 deletions(-) diff --git a/extern/glow-extras b/extern/glow-extras index 7bd27e7..438e6c0 160000 --- a/extern/glow-extras +++ b/extern/glow-extras @@ -1 +1 @@ -Subproject commit 7bd27e7e229d16008e3c926b614c5a2165a83e7e +Subproject commit 438e6c078c1952c3bcb1efd3d801da23d96dea55 diff --git a/samples/basic/viewer/main.cc b/samples/basic/viewer/main.cc index 26ce1cc..9d4f26a 100644 --- a/samples/basic/viewer/main.cc +++ b/samples/basic/viewer/main.cc @@ -15,8 +15,8 @@ #include <glow-extras/viewer/canvas.hh> #include <glow-extras/viewer/view.hh> -#include <typed-geometry/tg.hh> #include <polymesh/objects/cube.hh> +#include <typed-geometry/tg.hh> // path to sample files std::string const dataPath = glow::util::pathOf(__FILE__) + "/../../../data/"; @@ -96,12 +96,90 @@ void simple_picking(pm::vertex_attribute<tg::pos3> const& pos, pm::face_attribut })); }*/ - // simple picking functionality, primitive IDs defined internally - { + // 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; + 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()); + } + + { + // Only on_left_click callback defined + gv::view(pos, col, gv::pick().on_left_click([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { + std::cout << "Something has been picked! ON_LEFT_CLICK" + << "ID: " << face_id << std::endl; + return; + })); + } + + { + // Only on_right_click callback defined + gv::view(pos, col, gv::pick().on_right_click([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { + std::cout << "Something has been picked! ON_RIGHT_CLICK" + << "ID: " << face_id << std::endl; + return; + })); + } + + { + // Only on_hover callback defined + gv::view(pos, col, gv::pick().on_hover([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { + std::cout << "Something has been picked! ON_HOVER" + << "ID: " << face_id << std::endl; + return; + })); + } + + { + // On_hover, on_right_click, and on_left_click callbacks defined simultaneously + gv::view(pos, col, + gv::pick() + .on_left_click([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { + std::cout << "Something has been picked! ON_LEFT_CLICK" + << "ID: " << face_id << std::endl; + return; + }) + .on_right_click([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { + std::cout << "Something has been picked! ON_RIGHT_CLICK" + << "ID: " << face_id << std::endl; + return; + }) + .on_hover([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { + std::cout << "Something has been picked! ON_HOVER" + << "ID: " << face_id << std::endl; + return; + }) + + ); + } + + { + //User defined IDs check + auto id_f = pm::face_attribute<int>(pos.mesh()); + int32_t id = 0; + std::vector<pick_id> ids; + + for (auto f : pos.mesh().all_faces()) + { + pick_id pid; + pid.id = id; + ids.push_back(pid); + id++; + } + + gv::view(pos, col, ids, gv::pick().on_left_click([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) { + std::cout << "Something has been picked! ON_LEFT_CLICK" + << "ID: " << face_id << std::endl; + return; + })); } } @@ -1055,42 +1133,18 @@ int main() // load a sample polymesh mesh pm::Mesh m; auto pos = m.vertices().make_attribute<tg::pos3>(); - //load(dataPath + "suzanne.obj", m, pos); + // load(dataPath + "suzanne.obj", m, pos); pm::objects::add_cube(m, pos); - //normalize(pos); // make it -1..1*/ + // normalize(pos); // make it -1..1*/ auto col = pm::face_attribute<tg::color3>(m); int it = 0; auto r = tg::rng(); - for (auto x : m.faces()) + for (auto x : m.faces()) { - tg::color3 color; + tg::color3 color; color = tg::uniform<tg::color3>(r); - /*switch (it % 6) - { - case 0: - color = tg::color3::blue; - break; - case 1: - color = tg::color3::black; - break; - case 2: - color = tg::color3::cyan; - break; - case 3: - color = tg::color3::magenta; - break; - case 4: - color = tg::color3::red; - break; - case 5: - color = tg::color3::yellow; - break; - default: - color = tg::color3::white; - }*/ - it++; - col[x] = color; + col[x] = color; } pm::Mesh m_2; -- GitLab