def castRays(obj: Object, point: Vector, direction: Vector, miniDist: float, roundType: str = "CEILING", edgeLen: int = 0): """ obj -- source object to test intersections for point -- origin point for ray casting direction -- cast ray in this direction miniDist -- Vector with miniscule amount to add after intersection roundType -- round final intersection location Vector with this type edgeLen -- distance to test for intersections """ # initialize variables firstDirection = False firstIntersection = None nextIntersection = None lastIntersection = None edgeIntersects = False edgeLen2 = edgeLen * 1.00001 orig = point intersections = 0 # cast rays until no more rays to cast while True: _, location, normal, index = obj.ray_cast( orig, direction) #distance=edgeLen*1.00000000001) if index == -1: break if intersections == 0: firstDirection = direction.dot(normal) if edgeLen != 0: dist = (location - point).length # get first and last intersection (used when getting materials of nearest (first or last intersected) face) if dist <= edgeLen2: if intersections == 0: edgeIntersects = True firstIntersection = { "idx": index, "dist": dist, "loc": location, "normal": normal } lastIntersection = { "idx": index, "dist": edgeLen - dist, "loc": location, "normal": normal } # set nextIntersection if nextIntersection is None: nextIntersection = location.copy() intersections += 1 location = VectorRound(location, 5, roundType=roundType) orig = location + miniDist if edgeLen != 0: return intersections, firstDirection, firstIntersection, nextIntersection, lastIntersection, edgeIntersects else: return intersections, firstDirection
def cast_rays(obj_eval: Object, point: Vector, direction: Vector, mini_dist: float, round_type: str = "CEILING", edge_len: int = 0): """ obj_eval -- source object to test intersections for point -- starting point for ray casting direction -- cast ray in this direction mini_dist -- Vector with miniscule amount to add after intersection round_type -- round final intersection location Vector with this type edge_len -- distance to test for intersections """ # initialize variables first_direction = False first_intersection = None next_intersection_loc = None last_intersection = None edge_intersects = False edge_len2 = round(edge_len + 0.000001, 6) starting_point = point intersections = 0 # cast rays until no more rays to cast while True: _, location, normal, index = obj_eval.ray_cast( starting_point, direction) #distance=edge_len*1.00000000001) if index == -1: break if intersections == 0: first_direction = direction.dot(normal) if edge_len != 0: dist = (location - point).length # get first and last intersection (used when getting materials of nearest (first or last intersected) face) if dist <= edge_len2: if intersections == 0: edge_intersects = True first_intersection = { "idx": index, "dist": dist, "loc": location, "normal": normal } last_intersection = { "idx": index, "dist": edge_len - dist, "loc": location, "normal": normal } # set next_intersection_loc if next_intersection_loc is None: next_intersection_loc = location.copy() intersections += 1 location = vec_round(location, precision=6, round_type=round_type) starting_point = location + mini_dist if edge_len != 0: return intersections, first_direction, first_intersection, next_intersection_loc, last_intersection, edge_intersects else: return intersections, first_direction