From be4d4d404f67c202808b04880ae61dc6ba170d3d Mon Sep 17 00:00:00 2001 From: nilsiism <32297855+nilsiism@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:47:21 +0200 Subject: [PATCH] Fix transformation The transformation from UM to savitar in the 3MFWriter does not invert the transformation in the 3MFReader. This usually doesn't cause any problems as the center mesh extension is zero and the resulting matrix the identity. However if the extent is not zero the final transformation is incorrect. --- plugins/3MFWriter/ThreeMFWriter.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/3MFWriter/ThreeMFWriter.py b/plugins/3MFWriter/ThreeMFWriter.py index 5a9fa487fc..a3eb43ca32 100644 --- a/plugins/3MFWriter/ThreeMFWriter.py +++ b/plugins/3MFWriter/ThreeMFWriter.py @@ -114,22 +114,24 @@ class ThreeMFWriter(MeshWriter): mesh_data = um_node.getMeshData() + node_matrix = um_node.getLocalTransformation() + node_matrix.preMultiply(transformation) + if center_mesh: - node_matrix = Matrix() + center_matrix = Matrix() # compensate for original center position, if object(s) is/are not around its zero position if mesh_data is not None: extents = mesh_data.getExtents() if extents is not None: # We use a different coordinate space while writing, so flip Z and Y - center_vector = Vector(extents.center.x, extents.center.y, extents.center.z) - node_matrix.setByTranslation(center_vector) - node_matrix.multiply(um_node.getLocalTransformation()) - else: - node_matrix = um_node.getLocalTransformation() + center_vector = Vector(-extents.center.x, -extents.center.y, -extents.center.z) + center_matrix.setByTranslation(center_vector) + node_matrix.preMultiply(center_matrix) - matrix_string = ThreeMFWriter._convertMatrixToString(node_matrix.preMultiply(transformation)) + matrix_string = ThreeMFWriter._convertMatrixToString(node_matrix) savitar_node.setTransformation(matrix_string) + if mesh_data is not None: savitar_node.getMeshData().setVerticesFromBytes(mesh_data.getVerticesAsByteArray()) indices_array = mesh_data.getIndicesAsByteArray()