Browse Source

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.
nilsiism 8 months ago
parent
commit
be4d4d404f
1 changed files with 9 additions and 7 deletions
  1. 9 7
      plugins/3MFWriter/ThreeMFWriter.py

+ 9 - 7
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()