Skip to content
Snippets Groups Projects
Commit fd3182a6 authored by Aaron Kreuzberg's avatar Aaron Kreuzberg
Browse files

picking in interactive mode including face removal. PointRenderable picking...

picking in interactive mode including face removal. PointRenderable picking visualization implementation. Samples extended.
parent 0bff61ed
Branches
No related tags found
No related merge requests found
glow-extras @ 5e1e1b78
Subproject commit 333713c0306c75a84b1d0e6417e107c47421aa7e
Subproject commit 5e1e1b78112ea28f6f0d402306f47c54b981dafe
......@@ -18,6 +18,9 @@
#include <polymesh/objects/cube.hh>
#include <typed-geometry/tg.hh>
#include <polymesh/copy.hh>
// path to sample files
std::string const dataPath = glow::util::pathOf(__FILE__) + "/../../../data/";
......@@ -43,7 +46,7 @@ void picking_concept(pm::vertex_attribute<tg::pos3> const& pos)
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;
// r.picked_color = tg::color3::red;
return r;
}));
......@@ -51,7 +54,7 @@ void picking_concept(pm::vertex_attribute<tg::pos3> const& pos)
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;
// r.picked_color = tg::color3::red;
return r;
}));
......@@ -108,79 +111,156 @@ void simple_picking(pm::vertex_attribute<tg::pos3> const& pos, pm::face_attribut
// 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());
gv::view(pos, col, gv::pick(), "Picker defined without callback");
}
{
// 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) {
gv::view(pos, 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: " << face_id << std::endl;
<< "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");
}
{
// Only on_left_click callback defined - PointRenderable
gv::view(gv::points(pos), gv::pick().on_left_click([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) {
/* 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);
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) {
std::cout << "Something has been picked! ON_LEFT_CLICK"
<< "ID: " << face_id << std::endl;
<< "ID: " << int(face_id.f_id.value()) << std::endl;
std::cout << "World_Position" << world_pos << std::endl;
std::cout << "Normal" << normal << std::endl;
face_index_i = face_id.f_id.value();
world_pos_i = world_pos;
normal_i = normal;
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);
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 face"))
{
//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();
});
}
{
gv::view(gv::points(pos)); // ONLY FOR COMPARISON
}
{
// Only on_left_click callback defined - PointRenderable - uncolored
gv::view(gv::points(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 PointRenderable - callback on left click - spheres");
}
{
// Only on_left_click callback defined - PointRenderable - uncolored - square billboards - NOT WORKING APPROPRIATELY
gv::view(gv::points(pos).point_size_world(0.03f).camera_facing().square(),
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 PointRenderables - callback on left click - billboards");
}
{
// 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) {
gv::view(pos, col, gv::pick().on_right_click([&](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) {
std::cout << "Something has been picked! ON_RIGHT_CLICK"
<< "ID: " << face_id << std::endl;
<< "ID: " << face_id.id << std::endl;
return;
}));
}), "picking MeshRenderable - callback on right click");
}
{
// Only on_hover callback defined
gv::view(pos, col, gv::pick().on_hover([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) {
gv::view(pos, col, gv::pick().on_hover([&](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) {
std::cout << "Something has been picked! ON_HOVER"
<< "ID: " << face_id << std::endl;
<< "ID: " << face_id.id << std::endl;
return;
}));
}), "picking MeshRenderable - callback on hover");
}
{ //DOES NOT WORK RIGHT NOW - NEEDS TO BE FIXED
/*{ // 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 r;
//Picking_result r;
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) {
.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 << std::endl;
<< "ID: " << face_id.id << std::endl;
return;
})
.on_right_click([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) {
.on_right_click([&](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) {
std::cout << "Something has been picked! ON_RIGHT_CLICK"
<< "ID: " << face_id << std::endl;
<< "ID: " << face_id.id << std::endl;
return;
})
.on_hover([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) {
.on_hover([&](pick_id face_id, tg::pos3 world_pos, tg::vec3 normal) {
std::cout << "Something has been picked! ON_HOVER"
<< "ID: " << face_id << std::endl;
<< "ID: " << face_id.id << std::endl;
return;
})
}),
"picking MeshRenderable - multiple callbacks: on left click, on right click, on hover"
);
}
......@@ -199,11 +279,11 @@ void simple_picking(pm::vertex_attribute<tg::pos3> const& pos, pm::face_attribut
id++;
}
gv::view(pos, col, ids, gv::pick().on_left_click([&](uint32_t face_id, tg::pos3 world_pos, tg::vec3 normal) {
gv::view(pos, col, ids, 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 << std::endl;
<< "ID: " << face_id.id << std::endl;
return;
}));
}), "picking MeshRenderable - user defined primitive IDs");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment