def isOccluded(self, pt1, pt2): vd = pt2 - pt1 tMax = Utils.norm2(vd) vd = Utils.normalize(vd) isIntersect, t = Utils.rayIntersectObjects(pt1, vd, self.facesList, self.pointsList, 0, tMax) return isIntersect
def readBBox(self, scene): ''' ReadBBox(self, scene): -> bbox, origin, vu, vv, vw, depth, width, height ''' (bboxName, topMatName, leftMatName, frontMatName) = self.getFixBBoxParams() # read the bbox from scene bbox = MXS.getObject(scene, bboxName) if bbox.isNull(): raise ("cannot find the object named {}".format(bboxName)) # hide the bbox MXS.setObjectInvisible(bbox) # read the top, left and right planes topTriIds = MXS.getObjectTrianglesByMat(bbox, topMatName) leftTriIds = MXS.getObjectTrianglesByMat(bbox, leftMatName) frontTriIds = MXS.getObjectTrianglesByMat(bbox, frontMatName) if len(topTriIds) ==0 or len(leftTriIds) == 0 or len(frontTriIds) == 0: raise ("cannot correct find min_box") # read the bbox geometry information points = MXS.getObjectVertices(bbox) triangles = MXS.getObjectTriangles(bbox) # make points set of three planes topPtsSet = set() for topTriId in topTriIds: vs = triangles[topTriId] topPtsSet.add(vs[0]) topPtsSet.add(vs[1]) topPtsSet.add(vs[2]) leftPtsSet = set() for leftTriId in leftTriIds: vs = triangles[leftTriId] leftPtsSet.add(vs[0]) leftPtsSet.add(vs[1]) leftPtsSet.add(vs[2]) frontPtsSet = set() for frontTriId in frontTriIds: vs = triangles[frontTriId] frontPtsSet.add(vs[0]) frontPtsSet.add(vs[1]) frontPtsSet.add(vs[2]) # find origin, u, v, w oPtId = topPtsSet & leftPtsSet & frontPtsSet uPtId = (topPtsSet & leftPtsSet ) - oPtId vPtId = (topPtsSet & frontPtsSet) - oPtId wPtId = (leftPtsSet& frontPtsSet) - oPtId oPtId = oPtId.pop() uPtId = uPtId.pop() vPtId = vPtId.pop() wPtId = wPtId.pop() # normalize the vector origin = points[oPtId] vu = points[uPtId] - origin vv = points[vPtId] - origin vw = points[wPtId] - origin depth = Utils.norm2(vu) width = Utils.norm2(vv) height = Utils.norm2(vw) vu = Utils.normalize(vu) vv = Utils.normalize(vv) vw = Utils.normalize(vw) print("box depth: "+str(depth)) print("box width: "+str(width)) print("box height: "+str(height)) return (bbox, points, triangles, origin, vu, vv, vw, depth, width, height)