예제 #1
0
def populate_mesh(verts, faces, count, seed, all_triangles, safe_check):

    bvh = bvh_tree_from_polygons(verts,
                                 faces,
                                 all_triangles=all_triangles,
                                 epsilon=0.0,
                                 safe_check=safe_check)
    np.random.seed(seed)
    x_min, x_max, y_min, y_max, z_min, z_max = calc_bounds(verts)
    low = np.array([x_min, y_min, z_min])
    high = np.array([x_max, y_max, z_max])
    result = []
    done = 0
    iterations = 0
    while True:
        if iterations > MAX_ITERATIONS:
            raise Exception("Iterations limit is reached")
        max_pts = max(count, count - done)
        points = np.random.uniform(low, high, size=(max_pts, 3)).tolist()
        points = [p for p in points if point_inside_mesh(bvh, p)]
        n = len(points)
        result.extend(points)
        done += n
        iterations += 1
        if done >= count:
            break
    return result, []
예제 #2
0
 def restrict(points):
     result = []
     for p in points:
         if point_inside_mesh(bvh, p):
             result.append(p)
         else:
             loc, normal, index, distance = bvh.find_nearest(p)
             if loc is not None:
                 result.append(tuple(loc))
     return result