Browse Source

Improved robustness of Platform physics by checking if the hulls are calculated before trying to intersect them.

fixes CURA-1827
Jaime van Kessel 8 years ago
parent
commit
19933cb4e7
2 changed files with 11 additions and 13 deletions
  1. 10 12
      cura/PlatformPhysics.py
  2. 1 1
      plugins/3MFReader/ThreeMFReader.py

+ 10 - 12
cura/PlatformPhysics.py

@@ -63,9 +63,6 @@ class PlatformPhysics:
                 elif bbox.bottom < z_offset:
                     move_vector = move_vector.set(y=(-bbox.bottom) - z_offset)
 
-            #if not Float.fuzzyCompare(bbox.bottom, 0.0):
-            #   pass#move_vector.setY(-bbox.bottom)
-
             # If there is no convex hull for the node, start calculating it and continue.
             if not node.getDecorator(ConvexHullDecorator):
                 node.addDecorator(ConvexHullDecorator())
@@ -78,24 +75,18 @@ class PlatformPhysics:
                     if other_node is root or type(other_node) is not SceneNode or other_node is node:
                         continue
                     
-                    # Ignore colissions of a group with it's own children
+                    # Ignore collisions of a group with it's own children
                     if other_node in node.getAllChildren() or node in other_node.getAllChildren():
                         continue
                     
-                    # Ignore colissions within a group
+                    # Ignore collisions within a group
                     if other_node.getParent().callDecoration("isGroup") is not None or node.getParent().callDecoration("isGroup") is not None:
                         continue
-                        #if node.getParent().callDecoration("isGroup") is other_node.getParent().callDecoration("isGroup"):
-                        #    continue
                     
                     # Ignore nodes that do not have the right properties set.
                     if not other_node.callDecoration("getConvexHull") or not other_node.getBoundingBox():
                         continue
 
-                    # Check to see if the bounding boxes intersect. If not, we can ignore the node as there is no way the hull intersects.
-                    #if node.getBoundingBox().intersectsBox(other_node.getBoundingBox()) == AxisAlignedBox.IntersectionResult.NoIntersection:
-                    #    continue
-
                     # Get the overlap distance for both convex hulls. If this returns None, there is no intersection.
                     head_hull = node.callDecoration("getConvexHullHead")
                     if head_hull:
@@ -105,7 +96,14 @@ class PlatformPhysics:
                             if other_head_hull:
                                 overlap = node.callDecoration("getConvexHull").intersectsPolygon(other_head_hull)
                     else:
-                        overlap = node.callDecoration("getConvexHull").intersectsPolygon(other_node.callDecoration("getConvexHull"))
+                        own_convex_hull = node.callDecoration("getConvexHull")
+                        other_convex_hull = other_node.callDecoration("getConvexHull")
+                        if own_convex_hull and other_convex_hull:
+                            overlap = own_convex_hull.intersectsPolygon(other_convex_hull)
+                        else:
+                            # This can happen in some cases if the object is not yet done with being loaded.
+                            #  Simply waiting for the next tick seems to resolve this correctly.
+                            overlap = None
 
                     if overlap is None:
                         continue

+ 1 - 1
plugins/3MFReader/ThreeMFReader.py

@@ -70,7 +70,7 @@ class ThreeMFReader(MeshReader):
 
                 # TODO: We currently do not check for normals and simply recalculate them.
                 mesh_builder.calculateNormals()
-
+                
                 node.setMeshData(mesh_builder.build().getTransformed(rotation))
                 node.setSelectable(True)