Reworked retrieval of the model extents

This commit is contained in:
Patryk Skowroński 2024-10-11 16:54:13 +02:00
parent 49988b53e9
commit b9935d4dbb

View file

@ -1,6 +1,9 @@
import pynavlib.pynavlib_interface as pynav
from UM.Math.Matrix import Matrix, Vector
from UM.Math.Matrix import Matrix
from UM.Math.Vector import Vector
from UM.Math.AxisAlignedBox import AxisAlignedBox
from cura.PickingPass import PickingPass
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
class NavlibClient(pynav.NavlibNavigationModel):
@ -109,7 +112,6 @@ class NavlibClient(pynav.NavlibNavigationModel):
pt_min = pynav.NavlibVector(bounding_box.minimum.x, bounding_box.minimum.y, bounding_box.minimum.z)
pt_max = pynav.NavlibVector(bounding_box.maximum.x, bounding_box.maximum.y, bounding_box.maximum.z)
return pynav.NavlibBox(pt_min, pt_max)
pass
def get_selection_transform(self)->pynav.NavlibMatrix:
return pynav.NavlibMatrix()
@ -138,32 +140,24 @@ class NavlibClient(pynav.NavlibNavigationModel):
def get_model_extents(self)->pynav.NavlibBox:
# Why does running getCalculateBoundingBox on scene
# root always takes into accont all of the objects, no matter
# of their __calculate_aabb settings?
from UM.Scene.SceneNode import SceneNode
result_bbox = AxisAlignedBox()
build_volume_bbox = None
objects_tree_root = SceneNode()
objects_tree_root.setCalculateBoundingBox(True)
for node in self._scene.getRoot().getChildren() :
if node.__class__.__qualname__ == "CuraSceneNode" :
objects_tree_root.addChild(node)
for node in objects_tree_root.getAllChildren():
for node in DepthFirstIterator(self._scene.getRoot()):
node.setCalculateBoundingBox(True)
if node.__class__.__qualname__ == "CuraSceneNode" :
result_bbox = result_bbox + node.getBoundingBox()
elif node.__class__.__qualname__ == "BuildVolume":
build_volume_bbox = node.getBoundingBox()
if objects_tree_root.getAllChildren().__len__() > 0 :
bounding_box = objects_tree_root.getBoundingBox()
else :
self._scene.getRoot().setCalculateBoundingBox(True)
bounding_box = self._scene.getRoot().getBoundingBox()
if not result_bbox.isValid():
result_bbox = build_volume_bbox
if bounding_box is not None:
pt_min = pynav.NavlibVector(bounding_box.minimum.x, bounding_box.minimum.y, bounding_box.minimum.z)
pt_max = pynav.NavlibVector(bounding_box.maximum.x, bounding_box.maximum.y, bounding_box.maximum.z)
self._scene_center = bounding_box.center
self._scene_radius = (bounding_box.maximum - self._scene_center).length()
if result_bbox is not None:
pt_min = pynav.NavlibVector(result_bbox.minimum.x, result_bbox.minimum.y, result_bbox.minimum.z)
pt_max = pynav.NavlibVector(result_bbox.maximum.x, result_bbox.maximum.y, result_bbox.maximum.z)
self._scene_center = result_bbox.center
self._scene_radius = (result_bbox.maximum - self._scene_center).length()
return pynav.NavlibBox(pt_min, pt_max)
def get_pivot_position(self)->pynav.NavlibVector:
@ -183,8 +177,6 @@ class NavlibClient(pynav.NavlibNavigationModel):
if picked_position is not None:
return pynav.NavlibVector(picked_position.x, picked_position.y, picked_position.z)
pass
def get_units_to_meters(self)->float:
return 0.05
@ -229,10 +221,6 @@ class NavlibClient(pynav.NavlibNavigationModel):
def set_hit_selection_only(self, onlySelection : bool):
self._hit_selection_only = onlySelection
pass
def set_active_command(self, commandId : str):
pass
def set_motion_flag(self, motion : bool):
if motion: