TexTools is a UV and Texture tool set for 3dsMax created several years ago. This open repository will port in time several of the UV tools to Blender in python. http://renderhjs.net/textools/blender
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.8 KiB

import bpy
import bmesh
import operator
from mathutils import Vector
from collections import defaultdict
from math import pi
from . import utilities_uv
from . import utilities_ui
class op(bpy.types.Operator):
bl_idname = "uv.textools_select_islands_outline"
bl_label = "Select Island outline"
bl_description = "Select island edge bounds"
bl_options = {'REGISTER', 'UNDO'}
def poll(cls, context):
if not bpy.context.active_object:
return False
if bpy.context.active_object.type != 'MESH':
return False
#Requires UV map
if not bpy.context.object.data.uv_layers:
return False
# #requires UV_sync
# if not bpy.context.scene.tool_settings.use_uv_select_sync:
# return False
return True
def execute(self, context):
return {'FINISHED'}
def select_outline(context):
#Only in Edit mode
if bpy.context.active_object.mode != 'EDIT':
bm = bmesh.from_edit_mesh(bpy.context.active_object.data);
uv_layers = bm.loops.layers.uv.verify();
pre_sync = bpy.context.scene.tool_settings.use_uv_select_sync
if bpy.context.scene.tool_settings.use_uv_select_sync:
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
bpy.context.scene.tool_settings.use_uv_select_sync = False
current_edit = tuple(bpy.context.tool_settings.mesh_select_mode)
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
current_select = [f for f in bm.faces if f.select]
islands = utilities_uv.getSelectionIslands()
faces_islands = [face for island in islands for face in island]
edges_islands = [edge for island in islands for face in island for edge in face.edges]
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
# Store previous edge seams
edges_seam = [edge for edge in bm.edges if edge.seam]
contextViewUV = utilities_ui.GetContextViewUV()
if not contextViewUV:
self.report({'ERROR_INVALID_INPUT'}, "This tool requires an available UV/Image view.")
# Create seams from islands
edges_seams_from_islands = [edge for edge in bm.edges if edge.seam]
# Clear seams
for edge in edges_seams_from_islands:
edge.seam = False
if pre_sync:
# Select seams from islands edges and edge boundaries
for edge in edges_islands:
if edge.is_boundary or edge in edges_seams_from_islands:
edge.select = True
for face in current_select:
face.select = True
bpy.context.tool_settings.mesh_select_mode = current_edit
edges = []
for edge in edges_islands:
if edge.is_boundary or edge in edges_seams_from_islands:
edges.extend([e for e in edge.verts[0].link_loops])
edges.extend([e for e in edge.verts[1].link_loops])
bpy.context.scene.tool_settings.uv_select_mode = 'EDGE'
for face in faces_islands:
for loop in face.loops:
if loop in edges:
loop[uv_layers].select = True
# Restore seam selection
for edge in edges_seam:
edge.seam = True
bpy.context.scene.tool_settings.use_uv_select_sync = pre_sync