mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-07-04 12:35:09 +08:00
Reworked retrieval of the model extents
This commit is contained in:
parent
49988b53e9
commit
b9935d4dbb
@ -1,6 +1,9 @@
|
|||||||
import pynavlib.pynavlib_interface as pynav
|
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 cura.PickingPass import PickingPass
|
||||||
|
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
||||||
|
|
||||||
class NavlibClient(pynav.NavlibNavigationModel):
|
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_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)
|
pt_max = pynav.NavlibVector(bounding_box.maximum.x, bounding_box.maximum.y, bounding_box.maximum.z)
|
||||||
return pynav.NavlibBox(pt_min, pt_max)
|
return pynav.NavlibBox(pt_min, pt_max)
|
||||||
pass
|
|
||||||
|
|
||||||
def get_selection_transform(self)->pynav.NavlibMatrix:
|
def get_selection_transform(self)->pynav.NavlibMatrix:
|
||||||
return pynav.NavlibMatrix()
|
return pynav.NavlibMatrix()
|
||||||
@ -138,32 +140,24 @@ class NavlibClient(pynav.NavlibNavigationModel):
|
|||||||
|
|
||||||
def get_model_extents(self)->pynav.NavlibBox:
|
def get_model_extents(self)->pynav.NavlibBox:
|
||||||
|
|
||||||
# Why does running getCalculateBoundingBox on scene
|
result_bbox = AxisAlignedBox()
|
||||||
# root always takes into accont all of the objects, no matter
|
build_volume_bbox = None
|
||||||
# of their __calculate_aabb settings?
|
|
||||||
from UM.Scene.SceneNode import SceneNode
|
|
||||||
|
|
||||||
objects_tree_root = SceneNode()
|
for node in DepthFirstIterator(self._scene.getRoot()):
|
||||||
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():
|
|
||||||
node.setCalculateBoundingBox(True)
|
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 :
|
if not result_bbox.isValid():
|
||||||
bounding_box = objects_tree_root.getBoundingBox()
|
result_bbox = build_volume_bbox
|
||||||
else :
|
|
||||||
self._scene.getRoot().setCalculateBoundingBox(True)
|
|
||||||
bounding_box = self._scene.getRoot().getBoundingBox()
|
|
||||||
|
|
||||||
if bounding_box is not None:
|
if result_bbox is not None:
|
||||||
pt_min = pynav.NavlibVector(bounding_box.minimum.x, bounding_box.minimum.y, bounding_box.minimum.z)
|
pt_min = pynav.NavlibVector(result_bbox.minimum.x, result_bbox.minimum.y, result_bbox.minimum.z)
|
||||||
pt_max = pynav.NavlibVector(bounding_box.maximum.x, bounding_box.maximum.y, bounding_box.maximum.z)
|
pt_max = pynav.NavlibVector(result_bbox.maximum.x, result_bbox.maximum.y, result_bbox.maximum.z)
|
||||||
self._scene_center = bounding_box.center
|
self._scene_center = result_bbox.center
|
||||||
self._scene_radius = (bounding_box.maximum - self._scene_center).length()
|
self._scene_radius = (result_bbox.maximum - self._scene_center).length()
|
||||||
return pynav.NavlibBox(pt_min, pt_max)
|
return pynav.NavlibBox(pt_min, pt_max)
|
||||||
|
|
||||||
def get_pivot_position(self)->pynav.NavlibVector:
|
def get_pivot_position(self)->pynav.NavlibVector:
|
||||||
@ -183,8 +177,6 @@ class NavlibClient(pynav.NavlibNavigationModel):
|
|||||||
if picked_position is not None:
|
if picked_position is not None:
|
||||||
return pynav.NavlibVector(picked_position.x, picked_position.y, picked_position.z)
|
return pynav.NavlibVector(picked_position.x, picked_position.y, picked_position.z)
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_units_to_meters(self)->float:
|
def get_units_to_meters(self)->float:
|
||||||
return 0.05
|
return 0.05
|
||||||
|
|
||||||
@ -229,10 +221,6 @@ class NavlibClient(pynav.NavlibNavigationModel):
|
|||||||
|
|
||||||
def set_hit_selection_only(self, onlySelection : bool):
|
def set_hit_selection_only(self, onlySelection : bool):
|
||||||
self._hit_selection_only = onlySelection
|
self._hit_selection_only = onlySelection
|
||||||
pass
|
|
||||||
|
|
||||||
def set_active_command(self, commandId : str):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def set_motion_flag(self, motion : bool):
|
def set_motion_flag(self, motion : bool):
|
||||||
if motion:
|
if motion:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user