From fab363493140a93c1786c7898424a73dd1ed2a2e Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 24 Jun 2019 12:43:18 +0200 Subject: [PATCH] #2395 - Reworked logic of method Model::convert_multipart_object() --- src/libslic3r/Model.cpp | 52 ++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 8e879a3e6..596f80671 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -489,21 +489,57 @@ void Model::convert_multipart_object(unsigned int max_extruders) reset_auto_extruder_id(); + bool is_single_object = (this->objects.size() == 1); + for (const ModelObject* o : this->objects) + { for (const ModelVolume* v : o->volumes) { - ModelVolume* new_v = object->add_volume(*v); - if (new_v != nullptr) + if (is_single_object) { - new_v->name = o->name; - new_v->config.set_deserialize("extruder", get_auto_extruder_id_as_string(max_extruders)); - new_v->translate(-o->origin_translation); + // If there is only one object, just copy the volumes + ModelVolume* new_v = object->add_volume(*v); + if (new_v != nullptr) + { + new_v->name = o->name; + new_v->config.set_deserialize("extruder", get_auto_extruder_id_as_string(max_extruders)); + new_v->translate(-o->origin_translation); + } + } + else + { + // If there are more than one object, put all volumes together + // Each object may contain any number of volumes and instances + // The volumes transformations are relative to the object containing them... + int counter = 1; + for (const ModelInstance* i : o->instances) + { + ModelVolume* new_v = object->add_volume(*v); + if (new_v != nullptr) + { + new_v->name = o->name + "_" + std::to_string(counter++); + new_v->config.set_deserialize("extruder", get_auto_extruder_id_as_string(max_extruders)); + new_v->translate(-o->origin_translation); + // ...so, transform everything to a common reference system (world) + new_v->set_transformation(i->get_transformation() * v->get_transformation()); + } + } } } + } + + if (is_single_object) + { + // If there is only one object, keep its instances + for (const ModelInstance* i : this->objects.front()->instances) + { + object->add_instance(*i); + } + } + else + // If there are more than one object, create a single instance + object->add_instance(); - for (const ModelInstance* i : this->objects.front()->instances) - object->add_instance(*i); - this->clear_objects(); this->objects.push_back(object); }