-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuv_utility.py
249 lines (182 loc) · 7.24 KB
/
uv_utility.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# END GPL LICENSE BLOCK #####
bl_info = {
"name": "UV Utility",
"author": "Paul Geraskin",
"version": (0, 1),
"blender": (2, 70, 0),
"location": "View3D > ToolBar",
"description": "Change Index Of UVMap.",
"wiki_url": "",
"tracker_url": "",
"category": "UV"}
import bpy
from bpy.types import (Operator,
Panel,
PropertyGroup,
)
from bpy.props import (IntProperty,
StringProperty,
BoolProperty,
)
class UV_IC_Panel():
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = 'Tools'
bl_label = "UV Utility"
bl_context = "objectmode"
bl_options = {'DEFAULT_CLOSED'}
class UV_IC_TexIndex(PropertyGroup):
bpy.types.Scene.UVTexIndex = IntProperty(
name="UVIndexToGet",
description="get UVIndex of selected objects",
min=1,
max=8,
default=1)
bpy.types.Scene.UVTexGetName = StringProperty(
name="UVNameToGet",
description="get new UVName of selected objects",
default="UVMap")
bpy.types.Scene.UVTexRenderActive = BoolProperty(
name="Set Render Active",
description="Set Render Active...",
default=False
)
class UV_IC_Base(UV_IC_Panel, Panel):
bl_context = "objectmode"
bl_label = "UV Utility"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
scene = context.scene
ob = context.object
col = layout.column(align=True)
row = layout.row(align=True)
row.operator("uvutil.change_index", text="Drop Active UV Back")
row = layout.row(align=True)
col = layout.column()
col.prop(scene, "UVTexRenderActive")
row = layout.row(align=True)
col = layout.column()
col.operator("uvutil.select_index", text="Select UVTexCoord")
col.prop(scene, "UVTexIndex", text="UVTexCoord")
row = layout.row(align=True)
row = layout.row(align=True)
col = layout.column()
col.operator("uvutil.select_name", text="SelectUVName")
col.operator("uvutil.rename_active", text="RenameActiveName")
col.operator("uvutil.remove_uv_by_name", text="RemoveUVByName")
col.prop(scene, "UVTexGetName", text="")
row = layout.row(align=True)
col = layout.column()
col.operator("uvutil.remove_active", text="Remove Active UV")
class UV_IC_ChangeIndex(Operator):
bl_idname = "uvutil.change_index"
bl_label = "Change Index"
def execute(self, context):
scene = context.scene
for theObj in context.selected_objects:
meshData = theObj.data
if theObj.type == 'MESH':
if len(meshData.uv_textures) > meshData.uv_textures.active_index and meshData.uv_textures:
# meshData.uv_textures.active_index = 0
tmpuvmap = meshData.uv_textures.active
tmpuvmap_name = tmpuvmap.name
newuvmap = meshData.uv_textures.new()
meshData.uv_textures.remove(tmpuvmap)
droppedUV = meshData.uv_textures[
len(meshData.uv_textures) - 1]
droppedUV.name = tmpuvmap_name
# droppedUV.active = True
# if scene.UVTexRenderActive == True:
# droppedUV.active_render = True
return{'FINISHED'}
class UV_IC_SelectIndex(Operator):
bl_idname = "uvutil.select_index"
bl_label = "Select Index"
def execute(self, context):
scene = context.scene
for theObj in context.selected_objects:
meshData = theObj.data
indexNew = scene.UVTexIndex - 1
if theObj.type == 'MESH':
if len(meshData.uv_textures) > indexNew and meshData.uv_textures:
meshData.uv_textures.active_index = indexNew
if scene.UVTexRenderActive:
meshData.uv_textures[indexNew].active_render = True
return{'FINISHED'}
class UV_IC_RenameActiveUV(Operator):
bl_idname = "uvutil.rename_active"
bl_label = "Rename Active UV"
def execute(self, context):
scene = context.scene
for theObj in context.selected_objects:
meshData = theObj.data
if theObj.type == 'MESH':
if meshData.uv_textures:
activeIndex = meshData.uv_textures.active_index
meshData.uv_textures[activeIndex].name = scene.UVTexGetName
return{'FINISHED'}
class UV_IC_RemoveUVByName(Operator):
bl_idname = "uvutil.remove_uv_by_name"
bl_label = "Remove UV By Name"
def execute(self, context):
scene = context.scene
for theObj in context.selected_objects:
meshData = theObj.data
if theObj.type == 'MESH':
if meshData.uv_textures and scene.UVTexGetName in meshData.uv_textures:
tmpuvmap = meshData.uv_textures[scene.UVTexGetName]
meshData.uv_textures.remove(tmpuvmap)
return{'FINISHED'}
class UV_IC_SelectName(Operator):
bl_idname = "uvutil.select_name"
bl_label = "Select Name"
def execute(self, context):
scene = context.scene
for theObj in context.selected_objects:
meshData = theObj.data
uvName = scene.UVTexGetName
if theObj.type == 'MESH':
if meshData.uv_textures:
uvToGet = meshData.uv_textures.get(uvName)
if uvToGet is not None:
uvToGet.active = True
if scene.UVTexRenderActive:
uvToGet.active_render = True
return{'FINISHED'}
class UV_IC_RemoveActiveUV(Operator):
bl_idname = "uvutil.remove_active"
bl_label = "Remove Active UV"
def execute(self, context):
scene = context.scene
for theObj in context.selected_objects:
meshData = theObj.data
if theObj.type == 'MESH':
if meshData.uv_textures:
activeIndex = meshData.uv_textures.active_index
if len(meshData.uv_textures) > activeIndex:
meshData.uv_textures.remove(
meshData.uv_textures[activeIndex])
return{'FINISHED'}
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()