diff --git a/BuildVolume.py b/BuildVolume.py index 82588d5916..1636cf9c00 100644 --- a/BuildVolume.py +++ b/BuildVolume.py @@ -6,6 +6,7 @@ from UM.Mesh.MeshData import MeshData from UM.Mesh.MeshBuilder import MeshBuilder from UM.Math.Vector import Vector from UM.Math.Color import Color +from UM.Math.AxisAlignedBox import AxisAlignedBox import numpy @@ -27,6 +28,8 @@ class BuildVolume(SceneNode): self._disallowed_areas = [] self._disallowed_area_mesh = None + self._calculate_aabb = False + def setWidth(self, width): self._width = width @@ -117,3 +120,5 @@ class BuildVolume(SceneNode): self._disallowed_area_mesh = mb.getData() else: self._disallowed_area_mesh = None + + self._aabb = AxisAlignedBox(minimum = Vector(minW, minH, minD), maximum = Vector(maxW, maxH, maxD)) diff --git a/PlatformPhysics.py b/PlatformPhysics.py index 4c76a035e9..5e1a1722ca 100644 --- a/PlatformPhysics.py +++ b/PlatformPhysics.py @@ -3,6 +3,7 @@ from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator from UM.Operations.TranslateOperation import TranslateOperation from UM.Math.Float import Float from UM.Math.Vector import Vector +from UM.Math.AxisAlignedBox import AxisAlignedBox from UM.Application import Application from PlatformPhysicsOperation import PlatformPhysicsOperation @@ -11,10 +12,11 @@ import time import threading class PlatformPhysics: - def __init__(self, controller): + def __init__(self, controller, volume): super().__init__() self._controller = controller self._controller.getScene().sceneChanged.connect(self._onSceneChanged) + self._build_volume = volume self._signal_source = None def _onSceneChanged(self, source): @@ -27,6 +29,11 @@ class PlatformPhysics: if not bbox or not bbox.isValid(): continue + if self._build_volume.getBoundingBox().intersectsBox(bbox) != AxisAlignedBox.IntersectionResult.FullIntersection: + node._outside_buildarea = True + else: + node._outside_buildarea = False + if not Float.fuzzyCompare(bbox.bottom, 0.0): self._signal_source = node op = PlatformPhysicsOperation(node, Vector(0, -bbox.bottom, 0)) diff --git a/PrinterApplication.py b/PrinterApplication.py index 8b1f0d7e1d..55918acb44 100644 --- a/PrinterApplication.py +++ b/PrinterApplication.py @@ -87,8 +87,6 @@ class PrinterApplication(QtApplication): Selection.selectionChanged.connect(self.onSelectionChanged) - self._physics = PlatformPhysics(controller) - root = controller.getScene().getRoot() self._platform = Platform(root) @@ -97,6 +95,8 @@ class PrinterApplication(QtApplication): self.getRenderer().setLightPosition(Vector(0, 150, 0)) self.getRenderer().setBackgroundColor(QColor(245, 245, 245)) + self._physics = PlatformPhysics(controller, self._volume) + camera = Camera('3d', root) camera.setPosition(Vector(-150, 150, 300)) camera.setPerspective(True)