Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/bpy_extras/mesh_utils.py
| # SPDX-License-Identifier: GPL-2.0-or-later | # SPDX-License-Identifier: GPL-2.0-or-later | ||||||||||||
| __all__ = ( | __all__ = ( | ||||||||||||
| "mesh_linked_uv_islands", | "mesh_linked_uv_islands", | ||||||||||||
| "mesh_linked_triangles", | "mesh_linked_triangles", | ||||||||||||
| "edge_face_count_dict", | "edge_face_count_dict", | ||||||||||||
| "edge_face_count", | "edge_face_count", | ||||||||||||
| "edge_loops_from_edges", | "edge_loops_from_edges", | ||||||||||||
| "ngon_tessellate", | "ngon_tessellate", | ||||||||||||
| "triangle_random_points", | "triangle_random_points", | ||||||||||||
| ) | ) | ||||||||||||
| def mesh_linked_uv_islands(mesh): | def mesh_linked_uv_islands(mesh): | ||||||||||||
| """ | """ | ||||||||||||
| Splits the mesh into connected polygons, use this for separating cubes from | Returns lists of polygon indices connected by UV islands. | ||||||||||||
| 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: list of lists containing polygon indices | ||||||||||||
| :rtype: list | :rtype: list | ||||||||||||
| """ | """ | ||||||||||||
| if mesh.polygons and not mesh.uv_layers.active.data: | |||||||||||||
campbellbarton: Check there are polygons first, otherwise this would happen for empty meshes (which will return… | |||||||||||||
Done Inline ActionsShould include a short commenting noting the layer data is always empty in edit-mode. campbellbarton: Should include a short commenting noting the layer data is always empty in edit-mode. | |||||||||||||
| # Currently, when in edit mode, UV Layer data will always be empty | |||||||||||||
| # when accessed though RNA. This may change in the future. | |||||||||||||
| raise ValueError("UV Layers are not currently available from python in Edit Mode. Use bmesh and bpy_extras.bmesh_utils.bmesh_linked_uv_islands instead.") | |||||||||||||
campbellbartonUnsubmitted Not Done Inline Actions
campbellbarton: | |||||||||||||
| uv_loops = [luv.uv[:] for luv in mesh.uv_layers.active.data] | uv_loops = [luv.uv[:] for luv in mesh.uv_layers.active.data] | ||||||||||||
| poly_loops = [poly.loop_indices for poly in mesh.polygons] | poly_loops = [poly.loop_indices for poly in mesh.polygons] | ||||||||||||
| luv_hash = {} | luv_hash = {} | ||||||||||||
| luv_hash_get = luv_hash.get | luv_hash_get = luv_hash.get | ||||||||||||
| luv_hash_ls = [None] * len(uv_loops) | luv_hash_ls = [None] * len(uv_loops) | ||||||||||||
| for pi, poly_indices in enumerate(poly_loops): | for pi, poly_indices in enumerate(poly_loops): | ||||||||||||
| for li in poly_indices: | for li in poly_indices: | ||||||||||||
| uv = uv_loops[li] | uv = uv_loops[li] | ||||||||||||
| ▲ Show 20 Lines • Show All 424 Lines • Show Last 20 Lines | |||||||||||||
Check there are polygons first, otherwise this would happen for empty meshes (which will return an empty list, but shouldn't error).