Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import bpy_extras
- import bpy_extras.mesh_utils
- import bmesh
- def get_new_linked_faces(faces, isl_2):
- new_linked_faces = []
- for face in faces:
- for v in face.verts:
- for face2 in v.link_faces:
- face_id = face2.index
- if face_id in isl_2 and face2 not in new_linked_faces:
- new_linked_faces.append(face2)
- return new_linked_faces
- def parse_sub_islands(isl, bm):
- isl_2 = isl.copy()
- sub_isls = []
- linked_faces = []
- first_face = bm.faces[isl_2[0]]
- linked_faces.append(isl_2[0])
- parse_faces = [first_face]
- isl_2.remove(isl_2[0])
- while parse_faces:
- new_faces = get_new_linked_faces(parse_faces, isl_2)
- if new_faces:
- for face in new_faces:
- linked_faces.append(face.index)
- isl_2.remove(face.index)
- parse_faces = new_faces
- elif isl_2:
- if linked_faces:
- sub_isls.append(linked_faces.copy())
- linked_faces = []
- parse_faces = [bm.faces[isl_2[0]]]
- linked_faces.append(isl_2[0])
- isl_2.remove(isl_2[0])
- else:
- if linked_faces:
- sub_isls.append(linked_faces.copy())
- linked_faces = None
- new_faces = None
- parse_faces = None
- break
- return sub_isls
- if bpy.context.mode != 'OBJECT':
- bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
- active_obj = bpy.context.active_object
- context_mode = active_obj.mode
- bm = bmesh.new()
- bm.from_mesh(active_obj.data)
- bm.faces.ensure_lookup_table()
- bm.verts.ensure_lookup_table()
- islands = bpy_extras.mesh_utils.mesh_linked_uv_islands(active_obj.data)
- # decompose to sub-islands
- islands_dec = []
- for isl_id, isl in enumerate(islands):
- if isl:
- if len(isl) > 1:
- new_isl = parse_sub_islands(isl, bm)
- islands_dec += new_isl
- else:
- islands_dec.append(isl.copy())
- # Revert back
- bpy.ops.object.mode_set(mode=context_mode, toggle=False)
- print('Default mesh_linked_uv_islands ', islands)
- print('Improved mesh_linked_uv_islands ', islands_dec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement