From 0d585f367fe8f4304b8988cdbbe6ede02460cb42 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 28 Mar 2024 23:51:35 +0100 Subject: [PATCH] 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 --- plugins/3MFReader/ThreeMFWorkspaceReader.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/3MFReader/ThreeMFWorkspaceReader.py b/plugins/3MFReader/ThreeMFWorkspaceReader.py index 164952f9f1..6d7290cb9f 100755 --- a/plugins/3MFReader/ThreeMFWorkspaceReader.py +++ b/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)