Fixed clipping plane in painter gizmos:

Obsolete variable m_clipping_plane was used instead of getting the clipping plane from
the common gizmo data pool. This means the clipped parts of objects captured hits and
could not be painted through.
The clipped_mesh_was_hit variable is obsolete now. It was a mistake to introduce it in the first place.
This commit is contained in:
Lukas Matena 2020-10-12 13:05:22 +02:00
parent 2854f753a6
commit fa74f50af1
2 changed files with 9 additions and 19 deletions

View File

@ -20,7 +20,6 @@ namespace GUI {
GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
: GLGizmoBase(parent, icon_filename, sprite_id)
{
m_clipping_plane.reset(new ClippingPlane());
// Make sphere and save it into a vertex buffer.
const TriangleMesh sphere_mesh = make_sphere(1., (2*M_PI)/24.);
for (size_t i=0; i<sphere_mesh.its.vertices.size(); ++i)
@ -332,21 +331,18 @@ bool GLGizmoPainterBase::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
bool dragging_while_painting = (action == SLAGizmoEventType::Dragging && m_button_down != Button::None);
// The mouse button click detection is enabled when there is a valid hit
// or when the user clicks the clipping plane. Missing the object entirely
// The mouse button click detection is enabled when there is a valid hit.
// Missing the object entirely
// shall not capture the mouse.
if (m_rr.mesh_id != -1 || m_rr.clipped_mesh_was_hit) {
if (m_rr.mesh_id != -1) {
if (m_button_down == Button::None)
m_button_down = ((action == SLAGizmoEventType::LeftDown) ? Button::Left : Button::Right);
}
if (m_rr.mesh_id == -1) {
// In case we have no valid hit, we can return. The event will
// be stopped in following two cases:
// 1. clicking the clipping plane
// 2. dragging while painting (to prevent scene rotations and moving the object)
return m_rr.clipped_mesh_was_hit
|| dragging_while_painting;
// In case we have no valid hit, we can return. The event will be stopped when
// dragging while painting (to prevent scene rotations and moving the object)
return dragging_while_painting;
}
const Transform3d& trafo_matrix = trafo_matrices[m_rr.mesh_id];
@ -411,7 +407,6 @@ void GLGizmoPainterBase::update_raycast_cache(const Vec2d& mouse_position,
return;
}
bool clipped_mesh_was_hit{false};
Vec3f normal = Vec3f::Zero();
Vec3f hit = Vec3f::Zero();
size_t facet = 0;
@ -429,14 +424,12 @@ void GLGizmoPainterBase::update_raycast_cache(const Vec2d& mouse_position,
camera,
hit,
normal,
m_clipping_plane.get(),
m_c->object_clipper()->get_clipping_plane(),
&facet))
{
// In case this hit is clipped, skip it.
if (is_mesh_point_clipped(hit.cast<double>(), trafo_matrices[mesh_id])) {
clipped_mesh_was_hit = true;
if (is_mesh_point_clipped(hit.cast<double>(), trafo_matrices[mesh_id]))
continue;
}
// Is this hit the closest to the camera so far?
double hit_squared_distance = (camera.get_position()-trafo_matrices[mesh_id]*hit.cast<double>()).squaredNorm();
@ -449,7 +442,7 @@ void GLGizmoPainterBase::update_raycast_cache(const Vec2d& mouse_position,
}
}
m_rr = {mouse_position, closest_hit_mesh_id, closest_hit, closest_facet, clipped_mesh_was_hit};
m_rr = {mouse_position, closest_hit_mesh_id, closest_hit, closest_facet};
}
bool GLGizmoPainterBase::on_is_activable() const

View File

@ -101,8 +101,6 @@ private:
const Camera& camera,
const std::vector<Transform3d>& trafo_matrices) const;
float m_clipping_plane_distance = 0.f;
std::unique_ptr<ClippingPlane> m_clipping_plane;
GLIndexedVertexArray m_vbo_sphere;
bool m_internal_stack_active = false;
@ -126,7 +124,6 @@ private:
int mesh_id;
Vec3f hit;
size_t facet;
bool clipped_mesh_was_hit;
};
mutable RaycastResult m_rr;