Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/bpy_extras/mesh_utils.py
| Show All 26 Lines | __all__ = ( | ||||
| "edge_loops_from_edges", | "edge_loops_from_edges", | ||||
| "ngon_tessellate", | "ngon_tessellate", | ||||
| "face_random_points", | "face_random_points", | ||||
| ) | ) | ||||
| def mesh_linked_uv_islands(mesh): | def mesh_linked_uv_islands(mesh): | ||||
| """ | """ | ||||
| Splits the mesh into connected polygons, use this for seperating cubes from | Splits the mesh into connected polygons, use this for separating cubes from | ||||
| other mesh elements within 1 mesh datablock. | other mesh elements within 1 mesh datablock. | ||||
| :arg mesh: the mesh used to group with. | :arg mesh: the mesh used to group with. | ||||
| :type mesh: :class:`bpy.types.Mesh` | :type mesh: :class:`bpy.types.Mesh` | ||||
| :return: lists of lists containing polygon indices | :return: lists of lists containing polygon indices | ||||
| :rtype: list | :rtype: list | ||||
| """ | """ | ||||
| uv_loops = [luv.uv[:] for luv in mesh.uv_layers.active.data] | uv_loops = [luv.uv[:] for luv in mesh.uv_layers.active.data] | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | while True: | ||||
| island.append(poly_index_shared) | island.append(poly_index_shared) | ||||
| poly_tag[poly_index] = 2 | poly_tag[poly_index] = 2 | ||||
| return poly_islands | return poly_islands | ||||
| def mesh_linked_tessfaces(mesh): | def mesh_linked_tessfaces(mesh): | ||||
| """ | """ | ||||
| Splits the mesh into connected faces, use this for seperating cubes from | Splits the mesh into connected faces, use this for separating cubes from | ||||
| other mesh elements within 1 mesh datablock. | other mesh elements within 1 mesh datablock. | ||||
| :arg mesh: the mesh used to group with. | :arg mesh: the mesh used to group with. | ||||
| :type mesh: :class:`bpy.types.Mesh` | :type mesh: :class:`bpy.types.Mesh` | ||||
| :return: lists of lists containing faces. | :return: lists of lists containing faces. | ||||
| :rtype: list | :rtype: list | ||||
| """ | """ | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | def edge_face_count(mesh): | ||||
| return [get(edge_face_count, ed.key, 0) for ed in mesh.edges] | return [get(edge_face_count, ed.key, 0) for ed in mesh.edges] | ||||
| def edge_loops_from_tessfaces(mesh, tessfaces=None, seams=()): | def edge_loops_from_tessfaces(mesh, tessfaces=None, seams=()): | ||||
| """ | """ | ||||
| Edge loops defined by faces | Edge loops defined by faces | ||||
| Takes me.tessfaces or a list of faces and returns the edge loops | Takes me.tessfaces or a list of faces and returns the edge loops | ||||
| These edge loops are the edges that sit between quads, so they dont touch | These edge loops are the edges that sit between quads, so they don't touch | ||||
| 1 quad, note: not connected will make 2 edge loops, | 1 quad, note: not connected will make 2 edge loops, | ||||
| both only containing 2 edges. | both only containing 2 edges. | ||||
| return a list of edge key lists | return a list of edge key lists | ||||
| [[(0, 1), (4, 8), (3, 8)], ...] | [[(0, 1), (4, 8), (3, 8)], ...] | ||||
| :arg mesh: the mesh used to get edge loops from. | :arg mesh: the mesh used to get edge loops from. | ||||
| :type mesh: :class:`bpy.types.Mesh` | :type mesh: :class:`bpy.types.Mesh` | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | for edkey, ed_adj in edges.items(): | ||||
| break | break | ||||
| else: | else: | ||||
| del ed_adj[:] | del ed_adj[:] | ||||
| break | break | ||||
| i = ed_adj.index(context_loop[-2]) | i = ed_adj.index(context_loop[-2]) | ||||
| context_loop.append(ed_adj[not i]) | context_loop.append(ed_adj[not i]) | ||||
| # Dont look at this again | # Don't look at this again | ||||
| del ed_adj[:] | del ed_adj[:] | ||||
| return edge_loops | return edge_loops | ||||
| def edge_loops_from_edges(mesh, edges=None): | def edge_loops_from_edges(mesh, edges=None): | ||||
| """ | """ | ||||
| Edge loops defined by edges | Edge loops defined by edges | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | if not fix_loops: | ||||
| for i in range(len(verts) - 1, 0, -1): | for i in range(len(verts) - 1, 0, -1): | ||||
| if verts[i][1] == verts[i - 1][0]: | if verts[i][1] == verts[i - 1][0]: | ||||
| verts.pop(i - 1) | verts.pop(i - 1) | ||||
| fill = tessellate_polygon([verts]) | fill = tessellate_polygon([verts]) | ||||
| else: | else: | ||||
| """ | """ | ||||
| Seperate this loop into multiple loops be finding edges that are | Separate this loop into multiple loops be finding edges that are | ||||
| used twice. This is used by lightwave LWO files a lot | used twice. This is used by lightwave LWO files a lot | ||||
| """ | """ | ||||
| if type(from_data) in {tuple, list}: | if type(from_data) in {tuple, list}: | ||||
| verts = [vert_treplet(Vector(from_data[i]), ii) | verts = [vert_treplet(Vector(from_data[i]), ii) | ||||
| for ii, i in enumerate(indices)] | for ii, i in enumerate(indices)] | ||||
| else: | else: | ||||
| verts = [vert_treplet(from_data.vertices[i].co, ii) | verts = [vert_treplet(from_data.vertices[i].co, ii) | ||||
| ▲ Show 20 Lines • Show All 190 Lines • Show Last 20 Lines | |||||