mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-18 14:21:12 -06:00
Fix some rotation-related issues (#3890)
* Fix issue with max_z after rotation * Don't use `object.bounding_box()`, use `bounding_box_exact()` instead. * Fix auto-orient --------- Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
parent
d1eea4c677
commit
73ab032e82
12 changed files with 186 additions and 137 deletions
|
@ -160,7 +160,8 @@ void GLCanvas3D::LayersEditing::select_object(const Model& model, int object_id)
|
|||
// Maximum height of an object changes when the object gets rotated or scaled.
|
||||
// Changing maximum height of an object will invalidate the layer heigth editing profile.
|
||||
// m_model_object->bounding_box() is cached, therefore it is cheap even if this method is called frequently.
|
||||
const float new_max_z = (model_object_new == nullptr) ? 0.0f : static_cast<float>(model_object_new->bounding_box().max.z());
|
||||
const float new_max_z = (model_object_new == nullptr) ? 0.0f : static_cast<float>(model_object_new->max_z());
|
||||
|
||||
if (m_model_object != model_object_new || this->last_object_id != object_id || m_object_max_z != new_max_z ||
|
||||
(model_object_new != nullptr && m_model_object->id() != model_object_new->id())) {
|
||||
m_layer_height_profile.clear();
|
||||
|
|
|
@ -238,6 +238,7 @@ orientation::OrientMesh OrientJob::get_orient_mesh(ModelInstance* instance)
|
|||
|
||||
om.setter = [instance](const OrientMesh& p) {
|
||||
instance->rotate(p.rotation_matrix);
|
||||
instance->get_object()->invalidate_bounding_box();
|
||||
instance->get_object()->ensure_on_bed();
|
||||
};
|
||||
return om;
|
||||
|
|
|
@ -1601,7 +1601,7 @@ Vec3d PartPlate::estimate_wipe_tower_size(const DynamicPrintConfig & config, con
|
|||
if (!use_global_objects && !contain_instance_totally(obj_idx, 0))
|
||||
continue;
|
||||
|
||||
BoundingBoxf3 bbox = m_model->objects[obj_idx]->bounding_box();
|
||||
BoundingBoxf3 bbox = m_model->objects[obj_idx]->bounding_box_exact();
|
||||
max_height = std::max(bbox.size().z(), max_height);
|
||||
}
|
||||
wipe_tower_size(2) = max_height;
|
||||
|
|
|
@ -5295,7 +5295,7 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const
|
|||
ModelObject* old_model_object = model.objects[object_idx];
|
||||
ModelVolume* old_volume = old_model_object->volumes[volume_idx];
|
||||
|
||||
bool sinking = old_model_object->bounding_box().min.z() < SINKING_Z_THRESHOLD;
|
||||
bool sinking = old_model_object->min_z() < SINKING_Z_THRESHOLD;
|
||||
|
||||
ModelObject* new_model_object = new_model.objects.front();
|
||||
old_model_object->add_volume(*new_model_object->volumes.front());
|
||||
|
@ -5616,7 +5616,7 @@ void Plater::priv::reload_from_disk()
|
|||
ModelObject *old_model_object = model.objects[obj_idx];
|
||||
ModelVolume *old_volume = old_model_object->volumes[vol_idx];
|
||||
|
||||
bool sinking = old_model_object->bounding_box().min.z() < SINKING_Z_THRESHOLD;
|
||||
bool sinking = old_model_object->min_z() < SINKING_Z_THRESHOLD;
|
||||
|
||||
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());
|
||||
|
@ -7846,7 +7846,7 @@ bool Plater::priv::layers_height_allowed() const
|
|||
return false;
|
||||
|
||||
int obj_idx = get_selected_object_idx();
|
||||
return 0 <= obj_idx && obj_idx < (int)model.objects.size() && model.objects[obj_idx]->bounding_box().max.z() > SINKING_Z_THRESHOLD && view3D->is_layers_editing_allowed();
|
||||
return 0 <= obj_idx && obj_idx < (int)model.objects.size() && model.objects[obj_idx]->max_z() > SINKING_Z_THRESHOLD && view3D->is_layers_editing_allowed();
|
||||
}
|
||||
|
||||
bool Plater::priv::can_layers_editing() const
|
||||
|
@ -9104,7 +9104,7 @@ void Plater::_calib_pa_tower(const Calib_Params& params) {
|
|||
wxGetApp().get_tab(Preset::TYPE_PRINTER)->reload_config();
|
||||
|
||||
auto new_height = std::ceil((params.end - params.start) / params.step) + 1;
|
||||
auto obj_bb = model().objects[0]->bounding_box();
|
||||
auto obj_bb = model().objects[0]->bounding_box_exact();
|
||||
if (new_height < obj_bb.size().z()) {
|
||||
cut_horizontal(0, 0, new_height, ModelObjectCutAttribute::KeepLower);
|
||||
}
|
||||
|
@ -9245,7 +9245,7 @@ void Plater::calib_temp(const Calib_Params& params) {
|
|||
wxGetApp().get_tab(Preset::TYPE_FILAMENT)->reload_config();
|
||||
|
||||
// cut upper
|
||||
auto obj_bb = model().objects[0]->bounding_box();
|
||||
auto obj_bb = model().objects[0]->bounding_box_exact();
|
||||
auto block_count = lround((350 - params.end) / 5 + 1);
|
||||
if(block_count > 0){
|
||||
// add EPSILON offset to avoid cutting at the exact location where the flat surface is
|
||||
|
@ -9256,7 +9256,7 @@ void Plater::calib_temp(const Calib_Params& params) {
|
|||
}
|
||||
|
||||
// cut bottom
|
||||
obj_bb = model().objects[0]->bounding_box();
|
||||
obj_bb = model().objects[0]->bounding_box_exact();
|
||||
block_count = lround((350 - params.start) / 5);
|
||||
if(block_count > 0){
|
||||
auto new_height = block_count * 10.0 + EPSILON;
|
||||
|
@ -9285,7 +9285,7 @@ void Plater::calib_max_vol_speed(const Calib_Params& params)
|
|||
|
||||
auto bed_shape = printer_config->option<ConfigOptionPoints>("printable_area")->values;
|
||||
BoundingBoxf bed_ext = get_extents(bed_shape);
|
||||
auto scale_obj = (bed_ext.size().x() - 10) / obj->bounding_box().size().x();
|
||||
auto scale_obj = (bed_ext.size().x() - 10) / obj->bounding_box_exact().size().x();
|
||||
if (scale_obj < 1.0)
|
||||
obj->scale(scale_obj, 1, 1);
|
||||
|
||||
|
@ -9327,7 +9327,7 @@ void Plater::calib_max_vol_speed(const Calib_Params& params)
|
|||
wxGetApp().get_tab(Preset::TYPE_PRINTER)->reload_config();
|
||||
|
||||
// cut upper
|
||||
auto obj_bb = obj->bounding_box();
|
||||
auto obj_bb = obj->bounding_box_exact();
|
||||
auto height = (params.end - params.start + 1) / params.step;
|
||||
if (height < obj_bb.size().z()) {
|
||||
cut_horizontal(0, 0, height, ModelObjectCutAttribute::KeepLower);
|
||||
|
@ -9376,7 +9376,7 @@ void Plater::calib_retraction(const Calib_Params& params)
|
|||
changed_objects({ 0 });
|
||||
|
||||
// cut upper
|
||||
auto obj_bb = obj->bounding_box();
|
||||
auto obj_bb = obj->bounding_box_exact();
|
||||
auto height = 1.0 + 0.4 + ((params.end - params.start)) / params.step;
|
||||
if (height < obj_bb.size().z()) {
|
||||
cut_horizontal(0, 0, height, ModelObjectCutAttribute::KeepLower);
|
||||
|
@ -9419,7 +9419,7 @@ void Plater::calib_VFA(const Calib_Params& params)
|
|||
wxGetApp().get_tab(Preset::TYPE_FILAMENT)->update_ui_from_settings();
|
||||
|
||||
// cut upper
|
||||
auto obj_bb = model().objects[0]->bounding_box();
|
||||
auto obj_bb = model().objects[0]->bounding_box_exact();
|
||||
auto height = 5 * ((params.end - params.start) / params.step + 1);
|
||||
if (height < obj_bb.size().z()) {
|
||||
cut_horizontal(0, 0, height, ModelObjectCutAttribute::KeepLower);
|
||||
|
@ -12432,7 +12432,7 @@ void Plater::changed_objects(const std::vector<size_t>& object_idxs)
|
|||
|
||||
for (size_t obj_idx : object_idxs) {
|
||||
if (obj_idx < p->model.objects.size()) {
|
||||
if (p->model.objects[obj_idx]->bounding_box().min.z() >= SINKING_Z_THRESHOLD)
|
||||
if (p->model.objects[obj_idx]->min_z() >= SINKING_Z_THRESHOLD)
|
||||
// re - align to Z = 0
|
||||
p->model.objects[obj_idx]->ensure_on_bed();
|
||||
}
|
||||
|
|
|
@ -662,7 +662,7 @@ void CalibUtils::calib_temptue(const CalibInfo &calib_info, wxString &error_mess
|
|||
read_model_from_file(input_file, model);
|
||||
|
||||
// cut upper
|
||||
auto obj_bb = model.objects[0]->bounding_box();
|
||||
auto obj_bb = model.objects[0]->bounding_box_exact();
|
||||
auto block_count = lround((350 - params.start) / 5 + 1);
|
||||
if (block_count > 0) {
|
||||
// add EPSILON offset to avoid cutting at the exact location where the flat surface is
|
||||
|
@ -673,7 +673,7 @@ void CalibUtils::calib_temptue(const CalibInfo &calib_info, wxString &error_mess
|
|||
}
|
||||
|
||||
// cut bottom
|
||||
obj_bb = model.objects[0]->bounding_box();
|
||||
obj_bb = model.objects[0]->bounding_box_exact();
|
||||
block_count = lround((350 - params.end) / 5);
|
||||
if (block_count > 0) {
|
||||
auto new_height = block_count * 10.0 + EPSILON;
|
||||
|
@ -728,7 +728,7 @@ void CalibUtils::calib_max_vol_speed(const CalibInfo &calib_info, wxString &erro
|
|||
auto obj = model.objects[0];
|
||||
auto bed_shape = printer_config.option<ConfigOptionPoints>("printable_area")->values;
|
||||
BoundingBoxf bed_ext = get_extents(bed_shape);
|
||||
auto scale_obj = (bed_ext.size().x() - 10) / obj->bounding_box().size().x();
|
||||
auto scale_obj = (bed_ext.size().x() - 10) / obj->bounding_box_exact().size().x();
|
||||
if (scale_obj < 1.0)
|
||||
obj->scale(scale_obj, 1, 1);
|
||||
|
||||
|
@ -762,7 +762,7 @@ void CalibUtils::calib_max_vol_speed(const CalibInfo &calib_info, wxString &erro
|
|||
obj->config.set_key_value("brim_object_gap", new ConfigOptionFloat(0.0));
|
||||
|
||||
// cut upper
|
||||
auto obj_bb = obj->bounding_box();
|
||||
auto obj_bb = obj->bounding_box_exact();
|
||||
double height = (params.end - params.start + 1) / params.step;
|
||||
if (height < obj_bb.size().z()) {
|
||||
cut_model(model, height, ModelObjectCutAttribute::KeepLower);
|
||||
|
@ -820,7 +820,7 @@ void CalibUtils::calib_VFA(const CalibInfo &calib_info, wxString &error_message)
|
|||
model.objects[0]->config.set_key_value("brim_object_gap", new ConfigOptionFloat(0.0));
|
||||
|
||||
// cut upper
|
||||
auto obj_bb = model.objects[0]->bounding_box();
|
||||
auto obj_bb = model.objects[0]->bounding_box_exact();
|
||||
auto height = 5 * ((params.end - params.start) / params.step + 1);
|
||||
if (height < obj_bb.size().z()) {
|
||||
cut_model(model, height, ModelObjectCutAttribute::KeepLower);
|
||||
|
@ -875,7 +875,7 @@ void CalibUtils::calib_retraction(const CalibInfo &calib_info, wxString &error_m
|
|||
obj->config.set_key_value("layer_height", new ConfigOptionFloat(layer_height));
|
||||
|
||||
// cut upper
|
||||
auto obj_bb = obj->bounding_box();
|
||||
auto obj_bb = obj->bounding_box_exact();
|
||||
auto height = 1.0 + 0.4 + ((params.end - params.start)) / params.step;
|
||||
if (height < obj_bb.size().z()) {
|
||||
cut_model(model, height, ModelObjectCutAttribute::KeepLower);
|
||||
|
@ -947,7 +947,7 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f
|
|||
ModelInstance *instance = model->objects[0]->instances[0];
|
||||
instance->set_offset(instance->get_offset() + Vec3d(current_width / 2, current_depth / 2, 0));
|
||||
} else {
|
||||
BoundingBoxf3 bbox = model->bounding_box();
|
||||
BoundingBoxf3 bbox = model->bounding_box_exact();
|
||||
Vec3d bbox_center = bbox.center();
|
||||
for (auto object : model->objects) {
|
||||
ModelInstance *instance = object->instances[0];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue