Tech ENABLE_ALLOW_NEGATIVE_Z -> Added threshold to detect if an object is sinking
This commit is contained in:
parent
1f29a2593b
commit
1c35dfe591
6 changed files with 19 additions and 11 deletions
|
@ -963,7 +963,7 @@ void ModelObject::center_around_origin(bool include_modifiers)
|
|||
void ModelObject::ensure_on_bed(bool allow_negative_z)
|
||||
{
|
||||
const double min_z = get_min_z();
|
||||
if (!allow_negative_z || min_z > 0.0)
|
||||
if (!allow_negative_z || min_z > SINKING_Z_THRESHOLD)
|
||||
translate_instances({ 0.0, 0.0, -min_z });
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -1129,6 +1129,10 @@ void check_model_ids_validity(const Model &model);
|
|||
void check_model_ids_equal(const Model &model1, const Model &model2);
|
||||
#endif /* NDEBUG */
|
||||
|
||||
#if ENABLE_ALLOW_NEGATIVE_Z
|
||||
static const float SINKING_Z_THRESHOLD = -0.001f;
|
||||
#endif // ENABLE_ALLOW_NEGATIVE_Z
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
namespace cereal
|
||||
|
|
|
@ -536,7 +536,7 @@ bool GLVolume::is_sinking() const
|
|||
#endif // DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA
|
||||
return false;
|
||||
const BoundingBoxf3& box = transformed_convex_hull_bounding_box();
|
||||
return box.min(2) < -EPSILON && box.max(2) >= -EPSILON;
|
||||
return box.min.z() < SINKING_Z_THRESHOLD && box.max.z() >= SINKING_Z_THRESHOLD;
|
||||
}
|
||||
|
||||
bool GLVolume::is_below_printbed() const
|
||||
|
|
|
@ -3413,7 +3413,7 @@ void GLCanvas3D::do_move(const std::string& snapshot_type)
|
|||
#if ENABLE_ALLOW_NEGATIVE_Z
|
||||
const double shift_z = m->get_instance_min_z(i.second);
|
||||
#if DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA
|
||||
if (current_printer_technology() == ptSLA || shift_z > 0.0) {
|
||||
if (current_printer_technology() == ptSLA || shift_z > SINKING_Z_THRESHOLD) {
|
||||
#else
|
||||
if (shift_z > 0.0) {
|
||||
#endif // DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA
|
||||
|
@ -3463,7 +3463,7 @@ void GLCanvas3D::do_rotate(const std::string& snapshot_type)
|
|||
for (int i = 0; i < static_cast<int>(m_model->objects.size()); ++i) {
|
||||
const ModelObject* obj = m_model->objects[i];
|
||||
for (int j = 0; j < static_cast<int>(obj->instances.size()); ++j) {
|
||||
min_zs[{ i, j }] = obj->instance_bounding_box(j).min(2);
|
||||
min_zs[{ i, j }] = obj->instance_bounding_box(j).min.z();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3508,7 +3508,7 @@ void GLCanvas3D::do_rotate(const std::string& snapshot_type)
|
|||
#if ENABLE_ALLOW_NEGATIVE_Z
|
||||
double shift_z = m->get_instance_min_z(i.second);
|
||||
// leave sinking instances as sinking
|
||||
if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= 0.0 || shift_z > 0.0) {
|
||||
if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= SINKING_Z_THRESHOLD || shift_z > SINKING_Z_THRESHOLD) {
|
||||
Vec3d shift(0.0, 0.0, -shift_z);
|
||||
#else
|
||||
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
||||
|
@ -3541,7 +3541,7 @@ void GLCanvas3D::do_scale(const std::string& snapshot_type)
|
|||
for (int i = 0; i < static_cast<int>(m_model->objects.size()); ++i) {
|
||||
const ModelObject* obj = m_model->objects[i];
|
||||
for (int j = 0; j < static_cast<int>(obj->instances.size()); ++j) {
|
||||
min_zs[{ i, j }] = obj->instance_bounding_box(j).min(2);
|
||||
min_zs[{ i, j }] = obj->instance_bounding_box(j).min.z();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3583,7 +3583,7 @@ void GLCanvas3D::do_scale(const std::string& snapshot_type)
|
|||
#if ENABLE_ALLOW_NEGATIVE_Z
|
||||
double shift_z = m->get_instance_min_z(i.second);
|
||||
// leave sinking instances as sinking
|
||||
if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= 0.0 || shift_z > 0.0) {
|
||||
if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= SINKING_Z_THRESHOLD || shift_z > SINKING_Z_THRESHOLD) {
|
||||
Vec3d shift(0.0, 0.0, -shift_z);
|
||||
#else
|
||||
Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second));
|
||||
|
|
|
@ -360,7 +360,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
|
|||
if (0 <= idx && idx < static_cast<int>(objects.size())) {
|
||||
const ModelObject* mo = wxGetApp().model().objects[idx];
|
||||
const double min_z = mo->bounding_box().min.z();
|
||||
if (std::abs(min_z) > EPSILON) {
|
||||
if (std::abs(min_z) > SINKING_Z_THRESHOLD) {
|
||||
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Drop to bed"));
|
||||
change_position_value(2, m_cache.position.z() - min_z);
|
||||
}
|
||||
|
@ -702,7 +702,11 @@ void ObjectManipulation::update_reset_buttons_visibility()
|
|||
}
|
||||
show_rotation = !rotation.isApprox(Vec3d::Zero());
|
||||
show_scale = !scale.isApprox(Vec3d::Ones());
|
||||
#if ENABLE_ALLOW_NEGATIVE_Z
|
||||
show_drop_to_bed = std::abs(min_z) > SINKING_Z_THRESHOLD;
|
||||
#else
|
||||
show_drop_to_bed = (std::abs(min_z) > EPSILON);
|
||||
#endif // ENABLE_ALLOW_NEGATIVE_Z
|
||||
}
|
||||
|
||||
wxGetApp().CallAfter([this, show_rotation, show_scale, show_drop_to_bed] {
|
||||
|
|
|
@ -3247,7 +3247,7 @@ void Plater::priv::reload_from_disk()
|
|||
ModelVolume* old_volume = old_model_object->volumes[sel_v.volume_idx];
|
||||
|
||||
#if ENABLE_ALLOW_NEGATIVE_Z
|
||||
bool sinking = old_model_object->bounding_box().min.z() < 0.0;
|
||||
bool sinking = old_model_object->bounding_box().min.z() < SINKING_Z_THRESHOLD;
|
||||
#endif // ENABLE_ALLOW_NEGATIVE_Z
|
||||
|
||||
bool has_source = !old_volume->source.input_file.empty() && boost::algorithm::iequals(fs::path(old_volume->source.input_file).filename().string(), fs::path(path).filename().string());
|
||||
|
@ -4101,7 +4101,7 @@ bool Plater::priv::layers_height_allowed() const
|
|||
|
||||
int obj_idx = get_selected_object_idx();
|
||||
#if ENABLE_ALLOW_NEGATIVE_Z
|
||||
return 0 <= obj_idx && obj_idx < (int)model.objects.size() && model.objects[obj_idx]->bounding_box().max.z() > 0.0 &&
|
||||
return 0 <= obj_idx && obj_idx < (int)model.objects.size() && model.objects[obj_idx]->bounding_box().max.z() > SINKING_Z_THRESHOLD &&
|
||||
config->opt_bool("variable_layer_height") && view3D->is_layers_editing_allowed();
|
||||
#else
|
||||
return 0 <= obj_idx && obj_idx < (int)model.objects.size() && config->opt_bool("variable_layer_height") && view3D->is_layers_editing_allowed();
|
||||
|
@ -6051,7 +6051,7 @@ void Plater::changed_objects(const std::vector<size_t>& object_idxs)
|
|||
for (size_t obj_idx : object_idxs) {
|
||||
#if ENABLE_ALLOW_NEGATIVE_Z
|
||||
if (obj_idx < p->model.objects.size()) {
|
||||
if (p->model.objects[obj_idx]->bounding_box().min.z() >= 0.0)
|
||||
if (p->model.objects[obj_idx]->bounding_box().min.z() >= SINKING_Z_THRESHOLD)
|
||||
// re - align to Z = 0
|
||||
p->model.objects[obj_idx]->ensure_on_bed();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue