forked from drewcassidy/TexTools-Blender
-
Notifications
You must be signed in to change notification settings - Fork 1
/
op_select_islands_outline.py
78 lines (55 loc) · 2.03 KB
/
op_select_islands_outline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 Overlap"
bl_description = "Select island edge bounds"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
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
return True
def execute(self, context):
select_outline(context)
return {'FINISHED'}
def select_outline(context):
#Only in Edit mode
if bpy.context.active_object.mode != 'EDIT':
bpy.ops.object.mode_set(mode='EDIT')
bpy.context.scene.tool_settings.use_uv_select_sync = False
bm = bmesh.from_edit_mesh(bpy.context.active_object.data);
uv_layers = bm.loops.layers.uv.verify();
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
bpy.ops.mesh.select_all(action='DESELECT')
# 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.")
return
# Create seams from islands
bpy.ops.uv.seams_from_islands(contextViewUV)
edges_islands = [edge for edge in bm.edges if edge.seam]
# Clear seams
for edge in edges_islands:
edge.seam = False
# Select island edges
bpy.ops.mesh.select_all(action='DESELECT')
for edge in edges_islands:
edge.select = True
# Restore seam selection
for edge in edges_seam:
edge.seam = True
bpy.utils.register_class(op)