-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.py
223 lines (168 loc) · 8.08 KB
/
ui.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import math
import bpy
import bmesh
from bpy.props import (IntProperty,
BoolProperty,
StringProperty,
CollectionProperty,
PointerProperty)
from bpy.types import (Operator,
Panel,
PropertyGroup,
UIList)
#region UI
class IMAGE_MT_uvkit_imageList(bpy.types.Menu):
# heavily copied from Reinier Goijvaerts
bl_idname = "IMAGE_MT_uvkit_imageList"
bl_label = "Textures from material"
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
def draw(self, context):
layout = self.layout
obj = bpy.context.active_object
materials = []
if obj.type == 'MESH' and obj.mode == 'EDIT':
mesh = bmesh.from_edit_mesh(obj.data)
material_indices = [face.material_index for face in mesh.faces if face.select]
if len(material_indices) and len(obj.material_slots):
for index in material_indices:
slot = obj.material_slots[index]
if not slot.material:
continue
mat = slot.material
if mat.use_nodes and mat not in materials:
materials.append(mat)
else:
active_mat = bpy.context.active_object.active_material
if active_mat and active_mat.use_nodes:
materials.append(active_mat)
texture_usage_found = False
for mat in materials:
if not mat:
continue
for node in mat.node_tree.nodes:
if node.type != 'TEX_IMAGE':
continue
if not node.image:
continue
texture_usage_found = True
button = layout.operator("view2d.uvkit_show_image", text=node.image.name, icon_value=layout.icon(node.image))
button.image_name = node.image.name
if not texture_usage_found:
layout.label(text='No textures used')
class IMAGE_PT_uvkit_main(Panel):
bl_idname = "IMAGE_PT_uvkit_main"
bl_label = "UV kit"
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
bl_category = "Tool"
def draw(self, context):
layout = self.layout
sima = context.space_data
show_uvedit = sima.show_uvedit
if context.preferences.view.show_developer_ui:
col = layout.column()
col.separator()
col.operator("script.reload", text="Reload Scripts", icon="NONE")
layout.menu(IMAGE_MT_uvkit_imageList.bl_idname)
#if not show_uvedit:
# return
box = layout.box()
box.enabled = show_uvedit
box.label(text="UV and Cursor align")
row = box.column(align=True).row(align=True)
col = row.column(align=True)
col = row.column(align=True)
col.operator("view2d.uvkit_align", text="↖").direction = "topleft"
col.operator("view2d.uvkit_align", text="← ").direction = "left"
col.operator("view2d.uvkit_align", text="↙").direction = "bottomleft"
col = row.column(align=True)
col.operator("view2d.uvkit_align", text="↑").direction = "top"
col.operator("view2d.uvkit_align", text="+").direction = "center"
col.operator("view2d.uvkit_align", text="↓").direction = "bottom"
col = row.column(align=True)
col.operator("view2d.uvkit_align", text="↗").direction = "topright"
col.operator("view2d.uvkit_align", text=" →").direction = "right"
col.operator("view2d.uvkit_align", text="↘").direction = "bottomright"
row = box.row(align=True)
row.operator("view2d.uvkit_align", text="—").direction = "horizontal"
row.operator("view2d.uvkit_align", text="|").direction = "vertical"
row = box.row(align=True)
row.operator("view2d.uvkit_rotate_shell", text="Turn Left").angle = -math.pi / 2
row.operator("view2d.uvkit_rotate_shell", text="Turn Right").angle = math.pi / 2
box = layout.box()
box.enabled = show_uvedit
box.label(text="UV edgeloop tools")
col = box.column()
split = col.split(factor=0.2, align=True)
split.operator("view2d.uvkit_select_uv_edgering", text="-").mode = "SHRINK"
row = split.split(factor=0.8, align=True)
row.operator("view2d.uvkit_select_uv_edgering", text="Select Ring").mode = "CONTINUOS"
row.operator("view2d.uvkit_select_uv_edgering", text="+").mode = "EXPAND"
split = col.split(factor=0.2, align=True)
split.operator("view2d.uvkit_select_uv_edgeloop", text="-").mode = "SHRINK"
row = split.split(factor=0.8, align=True)
row.operator("view2d.uvkit_select_uv_edgeloop", text="Select Loop").mode = "CONTINUOS"
row.operator("view2d.uvkit_select_uv_edgeloop", text="+").mode = "EXPAND"
split = col.split(factor=0.33, align=True)
split.label(text="Align:")
split.operator("view2d.uvkit_align_uv_edgeloops", text="X").direction = "X"
# row = split.split(factor=0.66, align=True)
split.operator("view2d.uvkit_align_uv_edgeloops", text="Y").direction = "Y"
split.operator("view2d.uvkit_align_uv_edgeloops", text="Auto").direction = "AUTO"
split = col.split(factor=0.33, align=True)
split.label(text="Straighten:")
split.operator("view2d.uvkit_spread_loop", text="Even").mode = "EVEN"
#row = split.split(factor=0.66, align=True)
split.operator("view2d.uvkit_spread_loop", text="Geo").mode = "GEOMETRY"
split.operator("view2d.uvkit_spread_loop", text="Project").mode = "PROJECT"
col = layout.column()
col.operator("view2d.uvkit_constrained_unwrap", text="Constrained Unwrap")
col.enabled = show_uvedit
#col.operator("view2d.uvkit_trim_unwrap", text="Trim Unwrap")
#col.enabled = show_uvedit
class IMAGE_MT_uvkit_align_PIE(bpy.types.Menu):
bl_label = 'UV kit Align'
bl_idname = 'IMAGE_MT_uvkit_align_pie'
def draw(self, context):
layout = self.layout
pie = layout.menu_pie()
# left
pie.operator("view2d.uvkit_align", text="Left").direction = "left"
pie.operator("view2d.uvkit_align", text="Right").direction = "right"
pie.operator("view2d.uvkit_align", text="Bottom").direction = "bottom"
pie.operator("view2d.uvkit_align", text="Top").direction = "top"
pie.operator("view2d.uvkit_align", text="Top Left").direction = "topleft"
pie.operator("view2d.uvkit_align", text="Top Right").direction = "topright"
pie.operator("view2d.uvkit_align", text="Bottom Left").direction = "bottomleft"
pie.operator("view2d.uvkit_align", text="Bottom Right").direction = "bottomright"
def uvcontext_menu_draw_func(self, context):
layout = self.layout
layout.separator()
layout.menu(IMAGE_MT_uvkit_imageList.bl_idname)
#endregion UI
#region REGISTER / UNREGISTER
classes = [
IMAGE_PT_uvkit_main,
IMAGE_MT_uvkit_imageList,
IMAGE_MT_uvkit_align_PIE,
]
addon_keymaps = []
def register():
for c in classes:
bpy.utils.register_class(c)
wm = bpy.context.window_manager
if wm.keyconfigs.addon:
keymap = wm.keyconfigs.addon.keymaps.new(name='UV Editor', space_type='EMPTY', region_type="WINDOW")
keymap_item = keymap.keymap_items.new("wm.call_menu_pie", type="NONE", value='PRESS', ctrl=False)
keymap_item.properties.name = IMAGE_MT_uvkit_align_PIE.bl_idname
addon_keymaps.append((keymap, keymap_item))
bpy.types.IMAGE_MT_uvs_context_menu.append(uvcontext_menu_draw_func)
def unregister():
for keymap, keymap_item in addon_keymaps:
keymap.keymap_items.remove(keymap_item)
addon_keymaps.clear()
for c in reversed(classes):
bpy.utils.unregister_class(c)
bpy.types.IMAGE_MT_uvs_context_menu.remove(uvcontext_menu_draw_func)
#endregion REGISTER / UNREGISTER