Просмотр исходного кода

Reset entire scene around center for UCP.

Since we can't rely on the build-volume --because we can't know on which printer we open-- the safest bet (and the thing alowed by 3mf if I recall) is to just center the entire scene on the buildplate for Universal Cura Project files.

CURA-11703
Remco Burema 11 месяцев назад
Родитель
Сommit
0d585f367f
1 измененных файлов с 20 добавлено и 0 удалено
  1. 20 0
      plugins/3MFReader/ThreeMFWorkspaceReader.py

+ 20 - 0
plugins/3MFReader/ThreeMFWorkspaceReader.py

@@ -10,6 +10,8 @@ from typing import cast, Dict, List, Optional, Tuple, Any, Set
 
 import xml.etree.ElementTree as ET
 
+from UM.Math.AxisAlignedBox import AxisAlignedBox
+from UM.Math.Vector import Vector
 from UM.Util import parseBool
 from UM.Workspace.WorkspaceReader import WorkspaceReader
 from UM.Application import Application
@@ -936,6 +938,24 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
         if nodes is None:
             nodes = []
 
+        if self._is_ucp:
+            # We might be on a different printer than the one this project was made on.
+            # The offset to the printers' center isn't saved; instead, try to just fit everything on the buildplate.
+            full_extents = None  # Don't initialize to 'Null'!
+            for node in nodes:
+                extents = node.getMeshData().getExtents() if node.getMeshData() else None
+                if extents is not None:
+                    pos = node.getPosition()
+                    node_box = AxisAlignedBox(extents.minimum + pos, extents.maximum + pos)
+                    if full_extents is None:
+                        full_extents = node_box
+                    else:
+                        full_extents = full_extents + node_box
+            if full_extents.isValid():
+                for node in nodes:
+                    pos = node.getPosition()
+                    node.setPosition(Vector(pos.x - full_extents.center.x, pos.y, pos.z - full_extents.center.z))
+
         base_file_name = os.path.basename(file_name)
         self.setWorkspaceName(base_file_name)