def get_bl_crop_mesh_faces(verts, faces, verts_crop, faces_crop, mode, epsilon): """ Crop given faces by another set of faces by Blender internal function :param verts: list of Sv vertices :param faces: list of faces wich should be cropped :param verts_crop: list of Sv vertices :param faces_crop: list of faces by which mesh should be cropped :param mode: 'inner' or 'outer' :param epsilon: float, for nearness tests :return: list of Sv vertices, faces, indexes of old faces """ faces = [f if is_ccw_polygon([verts[i] for i in f], accuracy=epsilon) else f[::-1] for f in faces] faces_crop = [f if is_ccw_polygon([verts_crop[i] for i in f], accuracy=epsilon) else f[::-1] for f in faces_crop] merged_verts, merged_faces, faces_indexes, faces_crop_indexes = join_meshes(verts, faces, verts_crop, faces_crop) merged_verts = [Vector(co[:2]) for co in merged_verts] verts_new, _, faces_new, _, _, face_indexes = bl_crop_mesh(merged_verts, [], merged_faces, 3, epsilon) if mode == 'inner': faces_out = [] faces_index_out = [] for f, fi in zip(faces_new, face_indexes): if not fi: # it means new faces was generated continue in_1 = False in_2 = False for i in fi: if i in faces_indexes: in_1 = True else: in_2 = True if in_1 and in_2: faces_out.append(f) faces_index_out.append(min(fi)) break verts_out, faces_out = del_loose(verts_new, faces_out) return [v.to_3d()[:] for v in verts_out], faces_out, faces_index_out else: faces_out = [] faces_index_out = [] for f, fi in zip(faces_new, face_indexes): if not fi: # it means new faces was generated continue in_2 = False for i in fi: if i in faces_crop_indexes: in_2 = True break if not in_2: faces_out.append(f) faces_index_out.append(min(fi)) verts_out, faces_out = del_loose(verts_new, faces_out) return [v.to_3d()[:] for v in verts_out], faces_out, faces_index_out
def get_bl_merge_mesh(verts, faces, epsilon): """ Merge mesh into one with all intersection and overlapping information by Blender internal function :param verts: list of Sv vertices :param faces: list of Sv faces :param epsilon: For nearness tests :return: list of Sv Vertices, Faces, list of face old index, list of face overlapping """ faces = [ f if is_ccw_polygon([verts[i] for i in f], accuracy=epsilon) else f[::-1] for f in faces ] verts = [Vector(co[:2]) for co in verts] verts_new, _, faces_new, _, _, face_indexes = bl_merge_mesh( verts, [], faces, 3, epsilon) return [v.to_3d()[:] for v in verts_new], [f for f, fi in zip(faces_new, face_indexes) if fi], \ [min(fi) for fi in face_indexes if fi], [len(fi) - 1 for fi in face_indexes if fi]