From f5918228367a2160ecda9c36296d91ef7615987f Mon Sep 17 00:00:00 2001 From: Aleksei S Date: Fri, 22 Dec 2017 12:00:08 +0100 Subject: [PATCH] Set minimum distance between models CURA-4672 --- cura/PlatformPhysics.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cura/PlatformPhysics.py b/cura/PlatformPhysics.py index 471e54dba6..543eff0d4b 100755 --- a/cura/PlatformPhysics.py +++ b/cura/PlatformPhysics.py @@ -34,6 +34,7 @@ class PlatformPhysics: self._change_timer.timeout.connect(self._onChangeTimerFinished) self._move_factor = 1.1 # By how much should we multiply overlap to calculate a new spot? self._max_overlap_checks = 10 # How many times should we try to find a new spot per tick? + self._minimum_gap = 2 # It is a minimum distance between two models, applicable for small models Preferences.getInstance().addPreference("physics/automatic_push_free", True) Preferences.getInstance().addPreference("physics/automatic_drop_down", True) @@ -128,8 +129,23 @@ class PlatformPhysics: if own_convex_hull and other_convex_hull: overlap = own_convex_hull.translate(move_vector.x, move_vector.z).intersectsPolygon(other_convex_hull) if overlap: # Moving ensured that overlap was still there. Try anew! - move_vector = move_vector.set(x=move_vector.x + overlap[0] * self._move_factor, + temp_move_vector = move_vector.set(x=move_vector.x + overlap[0] * self._move_factor, z=move_vector.z + overlap[1] * self._move_factor) + + # if the distance between two models less than 2mm then try to find a new factor + if abs(temp_move_vector.x - overlap[0]) < self._minimum_gap and abs(temp_move_vector.y - overlap[1]) < self._minimum_gap: + temp_scale_factor = self._move_factor + temp_x_factor = (abs(overlap[0]) + self._minimum_gap) / overlap[0] # find x move_factor, like (3.4 + 2) / 3.4 = 1.58 + temp_y_factor = (abs(overlap[1]) + self._minimum_gap) / overlap[1] # find y move_factor + if temp_x_factor > temp_y_factor: + temp_scale_factor = temp_x_factor + else: + temp_scale_factor = temp_y_factor + + move_vector = move_vector.set(x=move_vector.x + overlap[0] * temp_scale_factor, + z=move_vector.z + overlap[1] * temp_scale_factor) + else: + move_vector = temp_move_vector else: # This can happen in some cases if the object is not yet done with being loaded. # Simply waiting for the next tick seems to resolve this correctly.