mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-19 19:09:09 +08:00
Implement build volume checks on objects
Currently using a dynamic property on SceneNode since I have not found a better solution yet.
This commit is contained in:
parent
e8dc563c46
commit
4801233728
@ -6,6 +6,7 @@ from UM.Mesh.MeshData import MeshData
|
|||||||
from UM.Mesh.MeshBuilder import MeshBuilder
|
from UM.Mesh.MeshBuilder import MeshBuilder
|
||||||
from UM.Math.Vector import Vector
|
from UM.Math.Vector import Vector
|
||||||
from UM.Math.Color import Color
|
from UM.Math.Color import Color
|
||||||
|
from UM.Math.AxisAlignedBox import AxisAlignedBox
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
@ -27,6 +28,8 @@ class BuildVolume(SceneNode):
|
|||||||
self._disallowed_areas = []
|
self._disallowed_areas = []
|
||||||
self._disallowed_area_mesh = None
|
self._disallowed_area_mesh = None
|
||||||
|
|
||||||
|
self._calculate_aabb = False
|
||||||
|
|
||||||
def setWidth(self, width):
|
def setWidth(self, width):
|
||||||
self._width = width
|
self._width = width
|
||||||
|
|
||||||
@ -117,3 +120,5 @@ class BuildVolume(SceneNode):
|
|||||||
self._disallowed_area_mesh = mb.getData()
|
self._disallowed_area_mesh = mb.getData()
|
||||||
else:
|
else:
|
||||||
self._disallowed_area_mesh = None
|
self._disallowed_area_mesh = None
|
||||||
|
|
||||||
|
self._aabb = AxisAlignedBox(minimum = Vector(minW, minH, minD), maximum = Vector(maxW, maxH, maxD))
|
||||||
|
@ -3,6 +3,7 @@ from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
|
|||||||
from UM.Operations.TranslateOperation import TranslateOperation
|
from UM.Operations.TranslateOperation import TranslateOperation
|
||||||
from UM.Math.Float import Float
|
from UM.Math.Float import Float
|
||||||
from UM.Math.Vector import Vector
|
from UM.Math.Vector import Vector
|
||||||
|
from UM.Math.AxisAlignedBox import AxisAlignedBox
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
|
|
||||||
from PlatformPhysicsOperation import PlatformPhysicsOperation
|
from PlatformPhysicsOperation import PlatformPhysicsOperation
|
||||||
@ -11,10 +12,11 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
class PlatformPhysics:
|
class PlatformPhysics:
|
||||||
def __init__(self, controller):
|
def __init__(self, controller, volume):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._controller = controller
|
self._controller = controller
|
||||||
self._controller.getScene().sceneChanged.connect(self._onSceneChanged)
|
self._controller.getScene().sceneChanged.connect(self._onSceneChanged)
|
||||||
|
self._build_volume = volume
|
||||||
self._signal_source = None
|
self._signal_source = None
|
||||||
|
|
||||||
def _onSceneChanged(self, source):
|
def _onSceneChanged(self, source):
|
||||||
@ -27,6 +29,11 @@ class PlatformPhysics:
|
|||||||
if not bbox or not bbox.isValid():
|
if not bbox or not bbox.isValid():
|
||||||
continue
|
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):
|
if not Float.fuzzyCompare(bbox.bottom, 0.0):
|
||||||
self._signal_source = node
|
self._signal_source = node
|
||||||
op = PlatformPhysicsOperation(node, Vector(0, -bbox.bottom, 0))
|
op = PlatformPhysicsOperation(node, Vector(0, -bbox.bottom, 0))
|
||||||
|
@ -87,8 +87,6 @@ class PrinterApplication(QtApplication):
|
|||||||
|
|
||||||
Selection.selectionChanged.connect(self.onSelectionChanged)
|
Selection.selectionChanged.connect(self.onSelectionChanged)
|
||||||
|
|
||||||
self._physics = PlatformPhysics(controller)
|
|
||||||
|
|
||||||
root = controller.getScene().getRoot()
|
root = controller.getScene().getRoot()
|
||||||
self._platform = Platform(root)
|
self._platform = Platform(root)
|
||||||
|
|
||||||
@ -97,6 +95,8 @@ class PrinterApplication(QtApplication):
|
|||||||
self.getRenderer().setLightPosition(Vector(0, 150, 0))
|
self.getRenderer().setLightPosition(Vector(0, 150, 0))
|
||||||
self.getRenderer().setBackgroundColor(QColor(245, 245, 245))
|
self.getRenderer().setBackgroundColor(QColor(245, 245, 245))
|
||||||
|
|
||||||
|
self._physics = PlatformPhysics(controller, self._volume)
|
||||||
|
|
||||||
camera = Camera('3d', root)
|
camera = Camera('3d', root)
|
||||||
camera.setPosition(Vector(-150, 150, 300))
|
camera.setPosition(Vector(-150, 150, 300))
|
||||||
camera.setPerspective(True)
|
camera.setPerspective(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user