Path: first experiments with collision detect

This commit is contained in:
sliptonic
2017-06-02 12:09:06 -05:00
committed by Yorik van Havre
parent c97724ef30
commit 0766a7387f
4 changed files with 92 additions and 3 deletions

View File

@@ -726,3 +726,44 @@ class depth_params:
return depths.tolist()
else:
return [stop] + depths.tolist()
class CollisionTester:
def compareBBSpace(self, bb1, bb2):
if ( bb1.XMin == bb2.XMin and
bb1.XMax == bb2.XMax and
bb1.YMin == bb2.YMin and
bb1.YMax == bb2.YMax and
bb1.ZMin == bb2.ZMin and
bb1.ZMax == bb2.ZMax ) :
return True
return False
def getCollisionSim(self, baseobject, cutterPath):
baseColor = (0.800000011920929, 0.800000011920929, 0.800000011920929, 00.0)
intersecColor = (1.0, 0.0, 0.0, 0.0)
cVol = baseobject.common(cutterPath)
if cVol.Volume > 1e-12:
colorassignment = []
gougedShape = baseobject.cut(cutterPath)
# gougeSim = FreeCAD.ActiveDocument.addObject("Part::Feature","Gouge")
# gougeSim.Shape = gougedShape
for idx, i in enumerate(gougedShape.Faces):
match = False
for jdx, j in enumerate(cVol.Faces):
if self.compareBBSpace(i.BoundBox, j.BoundBox):
match = True
if match is True:
#print ("Need to highlight Face{}".format(idx+1))
colorassignment.append(intersecColor)
else:
colorassignment.append(baseColor)
collisionSim = FreeCAD.ActiveDocument.addObject("Part::Feature","Collision")
collisionSim.Shape = gougedShape
collisionSim.ViewObject.DiffuseColor=colorassignment
return collisionSim
else:
return None