TriangleSelector paints continuously when dragging fast

Previously there would be distinct circles with gaps in between
This commit is contained in:
Lukas Matena 2020-08-18 15:18:00 +02:00
parent d3e7684a5a
commit 223eb6933c
2 changed files with 110 additions and 86 deletions

View File

@ -314,6 +314,30 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
const ModelInstance* mi = mo->instances[selection.get_instance_idx()];
const Transform3d& instance_trafo = mi->get_transformation().get_matrix();
// List of mouse positions that will be used as seeds for painting.
std::vector<Vec2d> mouse_positions{mouse_position};
// In case current mouse position is far from the last one,
// add several positions from between into the list, so there
// are no gaps in the painted region.
{
if (m_last_mouse_position == Vec2d::Zero())
m_last_mouse_position = mouse_position;
// resolution describes minimal distance limit using circle radius
// as a unit (e.g., 2 would mean the patches will be touching).
double resolution = 0.7;
double diameter_px = resolution * m_cursor_radius * camera.get_zoom();
int patches_in_between = int(((mouse_position - m_last_mouse_position).norm() - diameter_px) / diameter_px);
if (patches_in_between > 0) {
Vec2d diff = (mouse_position - m_last_mouse_position)/(patches_in_between+1);
for (int i=1; i<=patches_in_between; ++i)
mouse_positions.emplace_back(m_last_mouse_position + i*diff);
}
}
m_last_mouse_position = Vec2d::Zero(); // only actual hits should be saved
// Now "click" into all the prepared points and spill paint around them.
for (const Vec2d& mp : mouse_positions) {
std::vector<std::vector<std::pair<Vec3f, size_t>>> hit_positions_and_facet_ids;
bool clipped_mesh_was_hit = false;
@ -340,7 +364,7 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
hit_positions_and_facet_ids.push_back(std::vector<std::pair<Vec3f, size_t>>());
if (m_c->raycaster()->raycasters()[mesh_id]->unproject_on_mesh(
mouse_position,
mp,
trafo_matrices[mesh_id],
camera,
hit,
@ -385,18 +409,14 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
}
// Find respective mesh id.
// FIXME We need a separate TriangleSelector for each volume mesh.
mesh_id = -1;
//const TriangleMesh* mesh = nullptr;
for (const ModelVolume* mv : mo->volumes) {
if (! mv->is_model_part())
continue;
++mesh_id;
if (mesh_id == closest_hit_mesh_id) {
//mesh = &mv->mesh();
if (mesh_id == closest_hit_mesh_id)
break;
}
}
const Transform3d& trafo_matrix = trafo_matrices[mesh_id];
@ -413,6 +433,8 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
assert(mesh_id < int(m_triangle_selectors.size()));
m_triangle_selectors[mesh_id]->select_patch(closest_hit, closest_facet, camera_pos,
dir, limit, new_state);
m_last_mouse_position = mouse_position;
}
return true;
}
@ -430,6 +452,7 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
update_model_object();
m_button_down = Button::None;
m_last_mouse_position = Vec2d::Zero();
return true;
}

View File

@ -92,6 +92,7 @@ private:
bool m_setting_angle = false;
bool m_internal_stack_active = false;
bool m_schedule_update = false;
Vec2d m_last_mouse_position = Vec2d::Zero();
// This map holds all translated description texts, so they can be easily referenced during layout calculations
// etc. When language changes, GUI is recreated and this class constructed again, so the change takes effect.