mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-19 04:37:51 -06:00
Move the combined object to the center of the group after a merge.
Contributes to CURA-2160 "Merging objects results in group jumping off the buildplate"
This commit is contained in:
parent
aa28ecca37
commit
d0cc37658a
1 changed files with 13 additions and 6 deletions
|
@ -794,11 +794,18 @@ class CuraApplication(QtApplication):
|
||||||
return
|
return
|
||||||
multi_material_decorator = MultiMaterialDecorator.MultiMaterialDecorator()
|
multi_material_decorator = MultiMaterialDecorator.MultiMaterialDecorator()
|
||||||
group_node.addDecorator(multi_material_decorator)
|
group_node.addDecorator(multi_material_decorator)
|
||||||
# Reset the position of each node
|
|
||||||
for node in group_node.getChildren():
|
# Compute the center of the objects when their origins are aligned.
|
||||||
new_position = node.getMeshData().getCenterPosition()
|
object_centers = [node.getMeshData().getCenterPosition().scale(node.getScale()) for node in group_node.getChildren()]
|
||||||
new_position = new_position.scale(node.getScale())
|
middle_x = sum([v.x for v in object_centers]) / len(object_centers)
|
||||||
node.setPosition(new_position)
|
middle_y = sum([v.y for v in object_centers]) / len(object_centers)
|
||||||
|
middle_z = sum([v.z for v in object_centers]) / len(object_centers)
|
||||||
|
offset = Vector(middle_x, middle_y, middle_z)
|
||||||
|
|
||||||
|
# Move each node to the same position.
|
||||||
|
for center, node in zip(object_centers, group_node.getChildren()):
|
||||||
|
# Align the object and also apply the offset to center it inside the group.
|
||||||
|
node.setPosition(center - offset)
|
||||||
|
|
||||||
# Use the previously found center of the group bounding box as the new location of the group
|
# Use the previously found center of the group bounding box as the new location of the group
|
||||||
group_node.setPosition(group_node.getBoundingBox().center)
|
group_node.setPosition(group_node.getBoundingBox().center)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue