diff options
Diffstat (limited to 'release/scripts/modules/bpy_extras')
-rw-r--r-- | release/scripts/modules/bpy_extras/bmesh_utils.py | 56 | ||||
-rw-r--r-- | release/scripts/modules/bpy_extras/io_utils.py | 3 | ||||
-rw-r--r-- | release/scripts/modules/bpy_extras/mesh_utils.py | 14 |
3 files changed, 69 insertions, 4 deletions
diff --git a/release/scripts/modules/bpy_extras/bmesh_utils.py b/release/scripts/modules/bpy_extras/bmesh_utils.py new file mode 100644 index 00000000000..a24ea253f51 --- /dev/null +++ b/release/scripts/modules/bpy_extras/bmesh_utils.py @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +__all__ = ( + "bmesh_linked_uv_islands", +) + +import bmesh + + +def match_uv(face, vert, uv, uv_layer): + for loop in face.loops: + if loop.vert == vert: + return uv == loop[uv_layer].uv + return False + + +def bmesh_linked_uv_islands(bm, uv_layer): + """ + Returns lists of faces connected by UV islands. + + For meshes use :class:`bpy.types.Mesh.mesh_linked_uv_islands` instead. + + :arg bm: the bmesh used to group with. + :type bmesh: :class:`BMesh` + :arg uv_layer: the UV layer to source UVs from. + :type bmesh: :class:`BMLayerItem` + :return: list of lists containing polygon indices + :rtype: list + """ + + result = [] + used = set() + for seed_face in bm.faces: + if seed_face in used: + continue # Face has already been processed. + used.add(seed_face) + island = [seed_face] + stack = [seed_face] # Faces still to consider on this island. + while stack: + current_face = stack.pop() + for loop in current_face.loops: + v = loop.vert + uv = loop[uv_layer].uv + for f in v.link_faces: + if f is current_face or f in used: + continue + if not match_uv(f, v, uv, uv_layer): + continue + + # `f` is part of island, add to island and stack + used.add(f) + island.append(f) + stack.append(f) + result.append(island) + + return result diff --git a/release/scripts/modules/bpy_extras/io_utils.py b/release/scripts/modules/bpy_extras/io_utils.py index 0497d69162e..35b7d564a5e 100644 --- a/release/scripts/modules/bpy_extras/io_utils.py +++ b/release/scripts/modules/bpy_extras/io_utils.py @@ -21,6 +21,7 @@ from bpy.props import ( EnumProperty, StringProperty, ) +from bpy.app.translations import pgettext_data as data_ def _check_axis_conversion(op): @@ -56,7 +57,7 @@ class ExportHelper: if not self.filepath: blend_filepath = context.blend_data.filepath if not blend_filepath: - blend_filepath = "untitled" + blend_filepath = data_("untitled") else: blend_filepath = os.path.splitext(blend_filepath)[0] diff --git a/release/scripts/modules/bpy_extras/mesh_utils.py b/release/scripts/modules/bpy_extras/mesh_utils.py index f6dc33e4f02..d593ce6a1e4 100644 --- a/release/scripts/modules/bpy_extras/mesh_utils.py +++ b/release/scripts/modules/bpy_extras/mesh_utils.py @@ -13,14 +13,22 @@ __all__ = ( def mesh_linked_uv_islands(mesh): """ - Splits the mesh into connected polygons, use this for separating cubes from - other mesh elements within 1 mesh datablock. + Returns lists of polygon indices connected by UV islands. :arg mesh: the mesh used to group with. :type mesh: :class:`bpy.types.Mesh` - :return: lists of lists containing polygon indices + :return: list of lists containing polygon indices :rtype: list """ + + if mesh.polygons and not mesh.uv_layers.active.data: + # 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." + ) + uv_loops = [luv.uv[:] for luv in mesh.uv_layers.active.data] poly_loops = [poly.loop_indices for poly in mesh.polygons] luv_hash = {} |