Fixed painting gizmos with modifiers below the bed:

- When a modifier was below the bed and all the object parts above, it would clip
  the modifier but not triangulate the cut.
- When an object part was below, it would triangulate all modifiers with
  opaque orange color.

Both should now be fixed.
This commit is contained in:
Lukas Matena 2021-09-07 15:15:22 +02:00
parent 4f5dddbf11
commit 4ac013ec9c
4 changed files with 27 additions and 17 deletions

View File

@ -409,6 +409,11 @@ GLVolume::GLVolume(float r, float g, float b, float a)
set_render_color(color);
}
void GLVolume::set_color(const std::array<float, 4>& rgba)
{
color = rgba;
}
void GLVolume::set_render_color(float r, float g, float b, float a)
{
render_color = { r, g, b, a };
@ -458,8 +463,9 @@ void GLVolume::set_render_color()
render_color[3] = color[3];
}
void GLVolume::set_color_from_model_volume(const ModelVolume& model_volume)
std::array<float, 4> color_from_model_volume(const ModelVolume& model_volume)
{
std::array<float, 4> color;
if (model_volume.is_negative_volume()) {
color[0] = 0.2f;
color[1] = 0.2f;
@ -481,6 +487,7 @@ void GLVolume::set_color_from_model_volume(const ModelVolume& model_volume)
color[2] = 1.0f;
}
color[3] = model_volume.is_model_part() ? 1.f : 0.5f;
return color;
}
Transform3d GLVolume::world_matrix() const
@ -635,7 +642,7 @@ int GLVolumeCollection::load_object_volume(
color[3] = model_volume->is_model_part() ? 1.f : 0.5f;
this->volumes.emplace_back(new GLVolume(color));
GLVolume& v = *this->volumes.back();
v.set_color_from_model_volume(*model_volume);
v.set_color(color_from_model_volume(*model_volume));
#if ENABLE_SMOOTH_NORMALS
v.indexed_vertex_array.load_mesh(mesh, true);
#else

View File

@ -39,6 +39,10 @@ class ModelObject;
class ModelVolume;
enum ModelInstanceEPrintVolumeState : unsigned char;
// Return appropriate color based on the ModelVolume.
std::array<float, 4> color_from_model_volume(const ModelVolume& model_volume);
// A container for interleaved arrays of 3D vertices and normals,
// possibly indexed by triangles and / or quads.
class GLIndexedVertexArray {
@ -393,6 +397,7 @@ public:
return out;
}
void set_color(const std::array<float, 4>& rgba);
void set_render_color(float r, float g, float b, float a);
void set_render_color(const std::array<float, 4>& rgba);
// Sets render color in dependence of current state

View File

@ -1845,7 +1845,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
volume->extruder_id = extruder_id;
volume->is_modifier = !mvs->model_volume->is_model_part();
volume->set_color_from_model_volume(*mvs->model_volume);
volume->set_color(color_from_model_volume(*mvs->model_volume));
// updates volumes transformations
volume->set_instance_transformation(mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id]->get_transformation());

View File

@ -152,7 +152,7 @@ void InstancesHider::on_update()
canvas->toggle_sla_auxiliaries_visibility(m_show_supports, mo, active_inst);
canvas->set_use_clipping_planes(true);
// Some objects may be sinking, do not show whatever is below the bed.
canvas->set_clipping_plane(0, ClippingPlane(Vec3d::UnitZ(), 0.));
canvas->set_clipping_plane(0, ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD));
canvas->set_clipping_plane(1, ClippingPlane(-Vec3d::UnitZ(), std::numeric_limits<double>::max()));
@ -164,12 +164,7 @@ void InstancesHider::on_update()
m_clippers.clear();
for (const TriangleMesh* mesh : meshes) {
m_clippers.emplace_back(new MeshClipper);
if (mo->get_instance_min_z(active_inst) < SINKING_Z_THRESHOLD)
m_clippers.back()->set_plane(ClippingPlane(-Vec3d::UnitZ(), 0.));
else {
m_clippers.back()->set_plane(ClippingPlane::ClipsNothing());
m_clippers.back()->set_limiting_plane(ClippingPlane::ClipsNothing());
}
m_clippers.back()->set_plane(ClippingPlane(-Vec3d::UnitZ(), -SINKING_Z_THRESHOLD));
m_clippers.back()->set_mesh(*mesh);
}
m_old_meshes = meshes;
@ -218,8 +213,16 @@ void InstancesHider::render_cut() const
clipper->set_limiting_plane(ClippingPlane::ClipsNothing());
glsafe(::glPushMatrix());
glsafe(::glColor3f(0.8f, 0.3f, 0.0f));
if (mv->is_model_part())
glsafe(::glColor3f(0.8f, 0.3f, 0.0f));
else {
const std::array<float, 4>& c = color_from_model_volume(*mv);
glsafe(::glColor4f(c[0], c[1], c[2], c[3]));
}
glsafe(::glPushAttrib(GL_DEPTH_TEST));
glsafe(::glDisable(GL_DEPTH_TEST));
clipper->render_cut();
glsafe(::glPopAttrib());
glsafe(::glPopMatrix());
++clipper_id;
@ -385,8 +388,6 @@ void ObjectClipper::on_update()
m_active_inst_bb_radius =
mo->instance_bounding_box(get_pool()->selection_info()->get_active_instance()).radius();
//if (has_hollowed && m_clp_ratio != 0.)
// m_clp_ratio = 0.25;
}
}
@ -407,7 +408,6 @@ void ObjectClipper::render_cut() const
const SelectionInfo* sel_info = get_pool()->selection_info();
const ModelObject* mo = sel_info->model_object();
Geometry::Transformation inst_trafo = mo->instances[sel_info->get_active_instance()]->get_transformation();
const bool sinking = mo->bounding_box().min.z() < SINKING_Z_THRESHOLD;
size_t clipper_id = 0;
for (const ModelVolume* mv : mo->volumes) {
@ -418,9 +418,7 @@ void ObjectClipper::render_cut() const
auto& clipper = m_clippers[clipper_id];
clipper->set_plane(*m_clp);
clipper->set_transformation(trafo);
clipper->set_limiting_plane(sinking ?
ClippingPlane(Vec3d::UnitZ(), 0.)
: ClippingPlane::ClipsNothing());
clipper->set_limiting_plane(ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD));
glsafe(::glPushMatrix());
glsafe(::glColor3f(1.0f, 0.37f, 0.0f));
clipper->render_cut();