forked from leukbaars/DreamUV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
346 lines (305 loc) · 15.2 KB
/
__init__.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#this script is dedicated to the public domain under CC0 (https://creativecommons.org/publicdomain/zero/1.0/)
#do whatever you want with it!
bl_info = {
"name": "DreamUV",
"category": "UV",
"author": "Bram Eulaers",
"description": "Edit selected faces'UVs directly inside the 3D Viewport. WIP. Check for updates @leukbaars",
"blender": (2, 90, 0),
"version": (0, 9)
}
import bpy
from bpy.props import EnumProperty, BoolProperty, FloatProperty, IntProperty, PointerProperty
from . import DUV_UVTranslate
from . import DUV_UVRotate
from . import DUV_UVScale
from . import DUV_UVExtend
from . import DUV_UVStitch
from . import DUV_UVTransfer
from . import DUV_UVCycle
from . import DUV_UVMirror
from . import DUV_UVMoveToEdge
from . import DUV_Utils
from . import DUV_HotSpot
from . import DUV_UVProject
from . import DUV_UVUnwrap
from . import DUV_UVInset
from . import DUV_UVTrim
from . import DUV_ApplyMaterial
import importlib
if 'bpy' in locals():
importlib.reload(DUV_UVTranslate)
importlib.reload(DUV_UVRotate)
importlib.reload(DUV_UVScale)
importlib.reload(DUV_UVExtend)
importlib.reload(DUV_UVStitch)
importlib.reload(DUV_UVTransfer)
importlib.reload(DUV_UVCycle)
importlib.reload(DUV_UVMirror)
importlib.reload(DUV_UVMoveToEdge)
importlib.reload(DUV_Utils)
importlib.reload(DUV_HotSpot)
importlib.reload(DUV_UVProject)
importlib.reload(DUV_UVUnwrap)
importlib.reload(DUV_UVInset)
importlib.reload(DUV_UVTrim)
importlib.reload(DUV_ApplyMaterial)
class DUVUVToolsPreferences(bpy.types.AddonPreferences):
bl_idname = __name__
pixel_snap : BoolProperty(
name="UV Pixel Snap",
description="Translate Pixel Snapping",
default=False
)
move_snap : FloatProperty(
name="UV Move Snap",
description="Translate Scale Subdivision Snap Size",
default=0.25
)
scale_snap : FloatProperty(
name="UV Scale Snap",
description="Scale Snap Size",
default=2
)
rotate_snap : FloatProperty(
name="UV Rotate Snap",
description="Rotate Angle Snap Size",
default=45
)
# This should get its own py file
class DREAMUV_PT_uv(bpy.types.Panel):
"""DreamUV Tools Panel Test!"""
bl_label = "DreamUV"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'DreamUV'
#@classmethod
#def poll(cls, context):
# prefs = bpy.context.preferences.addons[__name__].preferences
# return prefs.show_panel_tools
def draw(self, context):
addon_prefs = prefs()
layout = self.layout
box = layout.box()
if bpy.context.object.mode != 'EDIT':
box.enabled = False
col = box.column(align=True)
col.label(text="Viewport UV Tools:")
row = col.row(align = True)
row.operator("view3d.dreamuv_uvtranslate", text="Move", icon="UV_SYNC_SELECT")
row = row.row(align = True)
row.prop(addon_prefs, 'move_snap', text="")
row = col.row(align = True)
op = row.operator("view3d.dreamuv_uvtranslatestep", text=" ", icon="TRIA_UP")
op.direction = "up"
op = row.operator("view3d.dreamuv_uvtranslatestep", text=" ", icon="TRIA_DOWN")
op.direction = "down"
op = row.operator("view3d.dreamuv_uvtranslatestep", text=" ", icon="TRIA_LEFT")
op.direction = "left"
op = row.operator("view3d.dreamuv_uvtranslatestep", text=" ", icon="TRIA_RIGHT")
op.direction = "right"
col.separator()
row = col.row(align = True)
row.operator("view3d.dreamuv_uvscale", text="Scale", icon="FULLSCREEN_ENTER")
row = row.row(align = True)
row.prop(addon_prefs, 'scale_snap', text="")
row = col.row(align = True)
op = row.operator("view3d.dreamuv_uvscalestep", text=" ", icon="ADD")
op.direction="+XY"
op = row.operator("view3d.dreamuv_uvscalestep", text=" ", icon="REMOVE")
op.direction="-XY"
op = row.operator("view3d.dreamuv_uvscalestep", text="+X")
op.direction = "+X"
op = row.operator("view3d.dreamuv_uvscalestep", text="-X")
op.direction = "-X"
op = row.operator("view3d.dreamuv_uvscalestep", text="+Y")
op.direction = "+Y"
op = row.operator("view3d.dreamuv_uvscalestep", text="-Y")
op.direction = "-Y"
col.separator()
row = col.row(align = True)
row.operator("view3d.dreamuv_uvrotate", text="Rotate", icon="FILE_REFRESH")
row = row.row(align = True)
row.prop(addon_prefs, 'rotate_snap', text="")
row = col.row(align = True)
op = row.operator("view3d.dreamuv_uvrotatestep", text=" ", icon="LOOP_FORWARDS")
op.direction="forward"
op = row.operator("view3d.dreamuv_uvrotatestep", text=" ", icon="LOOP_BACK")
op.direction="reverse"
col.separator()
col.operator("view3d.dreamuv_uvextend", text="Extend", icon="MOD_TRIANGULATE")
col.operator("view3d.dreamuv_uvstitch", text="Stitch", icon="UV_EDGESEL")
col.operator("view3d.dreamuv_uvcycle", text="Cycle", icon="FILE_REFRESH")
row = col.row(align = True)
op = row.operator("view3d.dreamuv_uvmirror", text="Mirror X", icon="MOD_MIRROR")
op.direction = "x"
op = row.operator("view3d.dreamuv_uvmirror", text="Mirror Y")
op.direction = "y"
col.separator()
row = col.row(align = True)
op = row.operator("view3d.dreamuv_uvinsetstep", text="Inset", icon="FULLSCREEN_EXIT")
op.direction = "in"
op = row.operator("view3d.dreamuv_uvinsetstep", text="Expand", icon="FULLSCREEN_ENTER")
op.direction = "out"
row.prop(context.scene, "uvinsetpixels", text="")
row.prop(context.scene, "uvinsettexsize", text="")
col.label(text="Move to UV Edge:")
row = col.row(align = True)
op = row.operator("view3d.dreamuv_uvmovetoedge", text=" ", icon="TRIA_UP_BAR")
op.direction="up"
op = row.operator("view3d.dreamuv_uvmovetoedge", text=" ", icon="TRIA_DOWN_BAR")
op.direction="down"
op = row.operator("view3d.dreamuv_uvmovetoedge", text=" ", icon="TRIA_LEFT_BAR")
op.direction = "left"
op = row.operator("view3d.dreamuv_uvmovetoedge", text=" ", icon="TRIA_RIGHT_BAR")
op.direction = "right"
box = layout.box()
if bpy.context.object.mode != 'EDIT':
box.enabled = False
col = box.column(align=True)
col.label(text="Unwrapping Tools:")
col.operator("view3d.dreamuv_uvunwrapsquare", text="Square Fit Unwrap", icon="OUTLINER_OB_LATTICE")
unwraptool=col.operator("uv.unwrap", text="Blender Unwrap", icon='UV')
unwraptool.method='CONFORMAL'
unwraptool.margin=0.001
col.separator()
box = layout.box()
if bpy.context.object.mode != 'EDIT':
box.enabled = False
col = box.column(align=True)
col.label(text="UV Transfer Tool:")
row = col.row(align = True)
row.prop(context.scene, "uvtransferxmin", text="")
row.prop(context.scene, "uvtransferymin", text="")
row.prop(context.scene, "uvtransferxmax", text="")
row.prop(context.scene, "uvtransferymax", text="")
col.operator("view3d.dreamuv_uvtransfergrab", text="Grab UV from selection", icon="FILE_TICK")
row = col.row(align = True)
row.operator("view3d.dreamuv_uvtransfer", text="Transfer to selection", icon="MOD_UVPROJECT")
col.separator()
box = layout.box()
col = box.column(align=True)
col.label(text="HotSpot Tool:")
row = col.row(align = True)
row.label(text="Atlas Object:")
row.prop_search(context.scene, "subrect_atlas", context.scene, "objects", text="", icon="MOD_MULTIRES")
row = col.row(align = True)
row.label(text="Atlas Scale:")
row.prop(context.scene, "duvhotspotscale", text="")
row = col.row(align = True)
row.label(text="Hotspot material:")
row.prop_search(context.scene, "duv_hotspotmaterial", bpy.data, "materials", text="")
row = col.row(align = True)
row.prop(context.scene, "duv_hotspotuseinset", icon="FULLSCREEN_EXIT", text="use inset")
row.separator()
row.prop(context.scene, "hotspotinsetpixels", text="")
row.prop(context.scene, "hotspotinsettexsize", text="")
col.separator()
row = col.row(align = True)
row.operator("view3d.dreamuv_hotspotter", text="HotSpot", icon="SHADERFX")
row.prop(context.scene, "duv_useorientation", icon="EVENT_W", text="")
row.prop(context.scene, "duv_usemirrorx", icon="EVENT_X", text="")
row.prop(context.scene, "duv_usemirrory", icon="EVENT_Y", text="")
if context.scene.duv_experimentaltools is True:
col.separator()
box = layout.box()
col = box.column(align=True)
col.label(text="Trim Tool:")
row = col.row(align = True)
row.operator("view3d.dreamuv_uvtrim", text="TRIM", icon="MOD_UVPROJECT")
row.prop_search(context.scene, "trim_atlas", context.scene, "objects", text="", icon="MOD_MULTIRES")
row = col.row(align = True)
row.prop(context.scene, "trim_index", text="")
row = col.row(align = True)
op = row.operator("view3d.dreamuv_uvtrimnext", text="previous", icon="MOD_UVPROJECT")
op.reverse = True
op = row.operator("view3d.dreamuv_uvtrimnext", text="next", icon="MOD_UVPROJECT")
op.reverse = False
col.separator()
row = col.row(align = True)
row.operator("view3d.dreamuv_uvcap", text="CAP", icon="MOD_UVPROJECT")
row = col.row(align = True)
row.prop(context.scene, "cap_index", text="")
row = col.row(align = True)
op = row.operator("view3d.dreamuv_uvcapnext", text="previous", icon="MOD_UVPROJECT")
op.reverse = True
op = row.operator("view3d.dreamuv_uvcapnext", text="next", icon="MOD_UVPROJECT")
op.reverse = False
col.separator()
row = col.row(align = True)
row.prop(context.scene, "duv_trimuseinset", icon="FULLSCREEN_EXIT", text="use inset")
row.separator()
row.prop(context.scene, "hotspotinsetpixels", text="")
row.prop(context.scene, "hotspotinsettexsize", text="")
col.separator()
box = layout.box()
col = box.column(align=True)
row = col.row(align = True)
op = row.operator("view3d.dreamuv_apply_material", text="apply material", icon="MOD_UVPROJECT")
row = col.row(align = True)
row.prop_search(context.scene, "duv_hotspotmaterial", bpy.data, "materials", )
col = self.layout.column(align = True)
col2= self.layout.column(align = True)
col2.label(text="DreamUV Beta")
row = col2.row(align = True)
row.label(text="send feedback to @leukbaars!")
#row.prop(context.scene, "duv_experimentaltools", icon="HEART", text="")
def prefs():
return bpy.context.preferences.addons[__name__].preferences
classes = (
DUVUVToolsPreferences,
DREAMUV_PT_uv,
DUV_UVTranslate.DREAMUV_OT_uv_translate,
DUV_UVTranslate.DREAMUV_OT_uv_translate_step,
DUV_UVRotate.DREAMUV_OT_uv_rotate,
DUV_UVRotate.DREAMUV_OT_uv_rotate_step,
DUV_UVScale.DREAMUV_OT_uv_scale,
DUV_UVScale.DREAMUV_OT_uv_scale_step,
DUV_UVExtend.DREAMUV_OT_uv_extend,
DUV_UVStitch.DREAMUV_OT_uv_stitch,
DUV_UVTransfer.DREAMUV_OT_uv_transfer,
DUV_UVTransfer.DREAMUV_OT_uv_transfer_grab,
DUV_UVCycle.DREAMUV_OT_uv_cycle,
DUV_UVMirror.DREAMUV_OT_uv_mirror,
DUV_UVMoveToEdge.DREAMUV_OT_uv_move_to_edge,
DUV_UVProject.DREAMUV_OT_uv_project,
DUV_UVUnwrap.DREAMUV_OT_uv_unwrap_square,
DUV_HotSpot.DREAMUV_OT_hotspotter,
DUV_UVInset.DREAMUV_OT_uv_inset,
DUV_UVInset.DREAMUV_OT_uv_inset_step,
DUV_UVTrim.DREAMUV_OT_uv_trim,
DUV_UVTrim.DREAMUV_OT_uv_cap,
DUV_UVTrim.DREAMUV_OT_uv_trimnext,
DUV_UVTrim.DREAMUV_OT_uv_capnext,
DUV_ApplyMaterial.DREAMUV_OT_apply_material,
)
def poll_material(self, material):
return not material.is_grease_pencil
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.subrect_atlas = bpy.props.PointerProperty (name="atlas",type=bpy.types.Object,description="atlas object")
bpy.types.Scene.trim_atlas = bpy.props.PointerProperty (name="trim_atlas",type=bpy.types.Object,description="trim atlas")
bpy.types.Scene.trim_index = bpy.props.IntProperty (name = "trim_index",default = 0,description = "trim index")
bpy.types.Scene.cap_index = bpy.props.IntProperty (name = "cap_index",default = 0,description = "cap index")
bpy.types.Scene.duv_trimuseinset = bpy.props.BoolProperty (name = "duv_trimuseinset",default = False,description = "Use inset when trimming")
bpy.types.Scene.uvinsetpixels = bpy.props.FloatProperty (name = "uv inset pixel amount",default = 1.0,description = "")
bpy.types.Scene.uvinsettexsize = bpy.props.FloatProperty (name = "uv inset texture size",default = 1024.0,description = "")
bpy.types.Scene.uvtransferxmin = bpy.props.FloatProperty (name = "uvtransferxmin",default = 0.0,description = "uv left bottom corner X")
bpy.types.Scene.uvtransferymin = bpy.props.FloatProperty (name = "uvtransferymin",default = 0.0,description = "uv left bottom corner Y")
bpy.types.Scene.uvtransferxmax = bpy.props.FloatProperty (name = "uvtransferxmax",default = 1.0,description = "uv right top corner X")
bpy.types.Scene.uvtransferymax = bpy.props.FloatProperty (name = "uvtransferymax",default = 1.0,description = "uv right top corner Y")
bpy.types.Scene.duv_useorientation = bpy.props.BoolProperty (name = "duv_useorientation",default = False,description = "Align UVs with world orientation")
bpy.types.Scene.duv_usemirrorx = bpy.props.BoolProperty (name = "duv_usemirrorx",default = True,description = "Randomly mirror faces on the x-axis")
bpy.types.Scene.duv_usemirrory = bpy.props.BoolProperty (name = "duv_usemirrory",default = True,description = "Randomly mirror faces on the y-axis")
bpy.types.Scene.duvhotspotscale = bpy.props.FloatProperty (name = "duvhotspotscale",default = 1.0,description = "hotspotting scale multiplier")
bpy.types.Scene.duv_hotspotmaterial = bpy.props.PointerProperty (name="duv_hotspotmaterial",type=bpy.types.Material,poll=poll_material,description="hotspot material")
bpy.types.Scene.duv_hotspotuseinset = bpy.props.BoolProperty (name = "duv_hotspotuseinset",default = False,description = "Use inset when hotspotting")
bpy.types.Scene.hotspotinsetpixels = bpy.props.FloatProperty (name = "hotspot inset pixel amount",default = 1.0,description = "")
bpy.types.Scene.hotspotinsettexsize = bpy.props.FloatProperty (name = "hotspot texture size",default = 1024.0,description = "")
bpy.types.Scene.duv_experimentaltools = bpy.props.BoolProperty (name = "duv_experimentaltools",default = False,description = "Show experimental tools")
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()