diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 172de747f9..97f695e6aa 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -860,13 +860,31 @@ ModelObject::transform_by_instance(ModelInstance instance, bool dont_translate) { // We get instance by copy because we would alter it in the loop below, // causing inconsistent values in subsequent instances. - TransformationMatrix trafo = instance.get_trafo_matrix(dont_translate); + TransformationMatrix temp_trafo = instance.get_trafo_matrix(dont_translate); + + this->apply_transformation(temp_trafo); + + temp_trafo = temp_trafo.inverse(); + /* + Let: + * I1 be the trafo of the given instance, + * V the originial volume trafo and + * I2 the trafo of the instance to be updated + + Then: + previous: T = I2 * V + I1 has been applied to V: + Vnew = I1 * V + I1^-1 * I1 = eye + + T = I2 * I1^-1 * I1 * V + ---------- ------ + I2new Vnew + */ + for (ModelInstance* i : this->instances) { - i->rotation -= instance.rotation; - i->scaling_factor /= instance.scaling_factor; - if (!dont_translate) - i->offset.translate(-instance.offset.x, -instance.offset.y); + i->set_complete_trafo(i->get_trafo_matrix().multiplyRight(temp_trafo)); } this->origin_translation = Pointf3(0,0,0); this->invalidate_bounding_box();