mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-13 21:25:58 +08:00
SetParent now correctly uses transformations
This is different from the old way of setting scale / rotation & position in sequence. The assumption in that case only held if all spaces had the same axis orientations (which is not the case for 3MF) Contributes to CURA-382
This commit is contained in:
parent
75be8080ec
commit
83315f13b3
@ -32,14 +32,20 @@ class SetParentOperation(Operation.Operation):
|
||||
# \param new_parent The new parent. Note: this argument can be None, which would hide the node from the scene.
|
||||
def _set_parent(self, new_parent):
|
||||
if new_parent:
|
||||
self._node.setPosition(self._node.getWorldPosition() - new_parent.getWorldPosition())
|
||||
current_parent = self._node.getParent()
|
||||
if current_parent:
|
||||
self._node.scale(current_parent.getScale() / new_parent.getScale())
|
||||
self._node.rotate(current_parent.getOrientation())
|
||||
# Based on the depth difference, we need to do something different.
|
||||
depth_difference = current_parent.getDepth() - new_parent.getDepth()
|
||||
child_transformation = self._node.getLocalTransformation()
|
||||
if depth_difference > 0:
|
||||
parent_transformation = current_parent.getLocalTransformation()
|
||||
# A node in the chain was removed, so we need to squash the parent info into all the nodes, so positions remain the same.
|
||||
self._node.setTransformation(parent_transformation.multiply(child_transformation))
|
||||
else:
|
||||
self._node.scale(Vector(1, 1, 1) / new_parent.getScale())
|
||||
self._node.rotate(new_parent.getOrientation().getInverse())
|
||||
# A node is inserted into the chain, so use the inverse of the parent to set the transformation of it's children.
|
||||
parent_transformation = new_parent.getLocalTransformation()
|
||||
result = parent_transformation.getInverse().multiply(child_transformation, copy = True)
|
||||
self._node.setTransformation(result)
|
||||
|
||||
self._node.setParent(new_parent)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user