Skip to content

Commit

Permalink
fix transform by instance, also make it take potentially different ad…
Browse files Browse the repository at this point in the history
…ditional trafos into account
  • Loading branch information
Oekn5w authored and lordofhyphens committed Dec 2, 2019
1 parent 794b3a1 commit 852fb80
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions xs/src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 852fb80

Please sign in to comment.