mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-18 04:07:57 -06:00
Set minimum distance between models
CURA-4672
This commit is contained in:
parent
c3954c40ac
commit
f591822836
1 changed files with 17 additions and 1 deletions
|
@ -34,6 +34,7 @@ class PlatformPhysics:
|
||||||
self._change_timer.timeout.connect(self._onChangeTimerFinished)
|
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._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._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_push_free", True)
|
||||||
Preferences.getInstance().addPreference("physics/automatic_drop_down", True)
|
Preferences.getInstance().addPreference("physics/automatic_drop_down", True)
|
||||||
|
@ -128,8 +129,23 @@ class PlatformPhysics:
|
||||||
if own_convex_hull and other_convex_hull:
|
if own_convex_hull and other_convex_hull:
|
||||||
overlap = own_convex_hull.translate(move_vector.x, move_vector.z).intersectsPolygon(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!
|
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)
|
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:
|
else:
|
||||||
# This can happen in some cases if the object is not yet done with being loaded.
|
# 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.
|
# Simply waiting for the next tick seems to resolve this correctly.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue