math_vis: remove use of register_module
[blender-addons.git] / uv_magic_uv / properites.py
blob3b61fcfcd8aae37fa885f2e4fab27b44bff22078
1 # <pep8-80 compliant>
3 # ##### BEGIN GPL LICENSE BLOCK #####
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # ##### END GPL LICENSE BLOCK #####
21 __author__ = "Nutti <nutti.metro@gmail.com>"
22 __status__ = "production"
23 __version__ = "5.1"
24 __date__ = "24 Feb 2018"
26 import bpy
27 from bpy.props import (
28 FloatProperty,
29 EnumProperty,
30 BoolProperty,
31 FloatVectorProperty,
32 IntProperty
34 from mathutils import Vector
36 from . import common
39 def get_loaded_texture_name(_, __):
40 items = [(key, key, "") for key in bpy.data.images.keys()]
41 items.append(("None", "None", ""))
42 return items
45 # Properties used in this add-on.
46 class MUV_Properties():
47 cpuv = None
48 cpuv_obj = None
49 cpuv_selseq = None
50 transuv = None
51 uvbb = None
52 texlock = None
53 texproj = None
54 texwrap = None
55 mvuv = None
56 uvinsp = None
57 uvsculpt = None
59 def __init__(self):
60 self.cpuv = MUV_CPUVProps()
61 self.cpuv_obj = MUV_CPUVProps()
62 self.cpuv_selseq = MUV_CPUVSelSeqProps()
63 self.transuv = MUV_TransUVProps()
64 self.uvbb = MUV_UVBBProps()
65 self.texlock = MUV_TexLockProps()
66 self.texproj = MUV_TexProjProps()
67 self.texwrap = MUV_TexWrapProps()
68 self.mvuv = MUV_MVUVProps()
69 self.uvinsp = MUV_UVInspProps()
70 self.uvsculpt = MUV_UVSculptProps()
73 class MUV_CPUVProps():
74 src_uvs = []
75 src_pin_uvs = []
76 src_seams = []
79 class MUV_CPUVSelSeqProps():
80 src_uvs = []
81 src_pin_uvs = []
82 src_seams = []
85 class MUV_TransUVProps():
86 topology_copied = []
89 class MUV_TexProjProps():
90 running = False
93 class MUV_UVBBProps():
94 uv_info_ini = []
95 ctrl_points_ini = []
96 ctrl_points = []
97 running = False
100 class MUV_TexLockProps():
101 verts_orig = None
102 intr_verts_orig = None
103 intr_running = False
106 class MUV_TexWrapProps():
107 ref_face_index = -1
108 ref_obj = None
111 class MUV_MVUVProps():
112 running = False
115 class MUV_UVInspProps():
116 display_running = False
117 overlapped_info = []
118 flipped_info = []
121 class MUV_UVSculptProps():
122 running = False
125 def init_props(scene):
126 scene.muv_props = MUV_Properties()
128 # UV Sculpt
129 scene.muv_uvsculpt_enabled = BoolProperty(
130 name="UV Sculpt",
131 description="UV Sculpt is enabled",
132 default=False
134 scene.muv_uvsculpt_radius = IntProperty(
135 name="Radius",
136 description="Radius of the brush",
137 min=1,
138 max=500,
139 default=30
141 scene.muv_uvsculpt_strength = FloatProperty(
142 name="Strength",
143 description="How powerful the effect of the brush when applied",
144 min=0.0,
145 max=1.0,
146 default=0.03,
148 scene.muv_uvsculpt_tools = EnumProperty(
149 name="Tools",
150 description="Select Tools for the UV sculpt brushes",
151 items=[
152 ('GRAB', "Grab", "Grab UVs"),
153 ('RELAX', "Relax", "Relax UVs"),
154 ('PINCH', "Pinch", "Pinch UVs")
156 default='GRAB'
158 scene.muv_uvsculpt_show_brush = BoolProperty(
159 name="Show Brush",
160 description="Show Brush",
161 default=True
163 scene.muv_uvsculpt_pinch_invert = BoolProperty(
164 name="Invert",
165 description="Pinch UV to invert direction",
166 default=False
168 scene.muv_uvsculpt_relax_method = EnumProperty(
169 name="Method",
170 description="Algorithm used for relaxation",
171 items=[
172 ('HC', "HC", "Use HC method for relaxation"),
173 ('LAPLACIAN', "Laplacian", "Use laplacian method for relaxation")
175 default='HC'
178 # Texture Wrap
179 scene.muv_texwrap_enabled = BoolProperty(
180 name="Texture Wrap",
181 description="Texture Wrap is enabled",
182 default=False
184 scene.muv_texwrap_set_and_refer = BoolProperty(
185 name="Set and Refer",
186 description="Refer and set UV",
187 default=True
189 scene.muv_texwrap_selseq = BoolProperty(
190 name="Selection Sequence",
191 description="Set UV sequentially",
192 default=False
195 # UV inspection
196 scene.muv_seluv_enabled = BoolProperty(
197 name="Select UV Enabled",
198 description="Select UV is enabled",
199 default=False
201 scene.muv_uvinsp_enabled = BoolProperty(
202 name="UV Inspection Enabled",
203 description="UV Inspection is enabled",
204 default=False
206 scene.muv_uvinsp_show_overlapped = BoolProperty(
207 name="Overlapped",
208 description="Show overlapped UVs",
209 default=False
211 scene.muv_uvinsp_show_flipped = BoolProperty(
212 name="Flipped",
213 description="Show flipped UVs",
214 default=False
216 scene.muv_uvinsp_show_mode = EnumProperty(
217 name="Mode",
218 description="Show mode",
219 items=[
220 ('PART', "Part", "Show only overlapped/flipped part"),
221 ('FACE', "Face", "Show overlapped/flipped face")
223 default='PART'
226 # Align UV
227 scene.muv_auv_enabled = BoolProperty(
228 name="Aline UV Enabled",
229 description="Align UV is enabled",
230 default=False
232 scene.muv_auv_transmission = BoolProperty(
233 name="Transmission",
234 description="Align linked UVs",
235 default=False
237 scene.muv_auv_select = BoolProperty(
238 name="Select",
239 description="Select UVs which are aligned",
240 default=False
242 scene.muv_auv_vertical = BoolProperty(
243 name="Vert-Infl (Vertical)",
244 description="Align vertical direction influenced "
245 "by mesh vertex proportion",
246 default=False
248 scene.muv_auv_horizontal = BoolProperty(
249 name="Vert-Infl (Horizontal)",
250 description="Align horizontal direction influenced "
251 "by mesh vertex proportion",
252 default=False
254 scene.muv_auv_location = EnumProperty(
255 name="Location",
256 description="Align location",
257 items=[
258 ('LEFT_TOP', "Left/Top", "Align to Left or Top"),
259 ('MIDDLE', "Middle", "Align to middle"),
260 ('RIGHT_BOTTOM', "Right/Bottom", "Align to Right or Bottom")
262 default='MIDDLE'
265 # Smooth UV
266 scene.muv_smuv_enabled = BoolProperty(
267 name="Smooth UV Enabled",
268 description="Smooth UV is enabled",
269 default=False
271 scene.muv_smuv_transmission = BoolProperty(
272 name="Transmission",
273 description="Smooth linked UVs",
274 default=False
276 scene.muv_smuv_mesh_infl = FloatProperty(
277 name="Mesh Influence",
278 description="Influence rate of mesh vertex",
279 min=0.0,
280 max=1.0,
281 default=0.0
283 scene.muv_smuv_select = BoolProperty(
284 name="Select",
285 description="Select UVs which are smoothed",
286 default=False
289 # UV Bounding Box
290 scene.muv_uvbb_enabled = BoolProperty(
291 name="UV Bounding Box Enabled",
292 description="UV Bounding Box is enabled",
293 default=False
295 scene.muv_uvbb_uniform_scaling = BoolProperty(
296 name="Uniform Scaling",
297 description="Enable Uniform Scaling",
298 default=False
300 scene.muv_uvbb_boundary = EnumProperty(
301 name="Boundary",
302 description="Boundary",
303 default='UV_SEL',
304 items=[
305 ('UV', "UV", "Boundary is decided by UV"),
306 ('UV_SEL', "UV (Selected)", "Boundary is decided by Selected UV")
310 # Pack UV
311 scene.muv_packuv_enabled = BoolProperty(
312 name="Pack UV Enabled",
313 description="Pack UV is enabled",
314 default=False
316 scene.muv_packuv_allowable_center_deviation = FloatVectorProperty(
317 name="Allowable Center Deviation",
318 description="Allowable center deviation to judge same UV island",
319 min=0.000001,
320 max=0.1,
321 default=(0.001, 0.001),
322 size=2
324 scene.muv_packuv_allowable_size_deviation = FloatVectorProperty(
325 name="Allowable Size Deviation",
326 description="Allowable sizse deviation to judge same UV island",
327 min=0.000001,
328 max=0.1,
329 default=(0.001, 0.001),
330 size=2
333 # Move UV
334 scene.muv_mvuv_enabled = BoolProperty(
335 name="Move UV Enabled",
336 description="Move UV is enabled",
337 default=False
340 # UVW
341 scene.muv_uvw_enabled = BoolProperty(
342 name="UVW Enabled",
343 description="UVW is enabled",
344 default=False
346 scene.muv_uvw_assign_uvmap = BoolProperty(
347 name="Assign UVMap",
348 description="Assign UVMap when no UVmaps are available",
349 default=True
352 # Texture Projection
353 scene.muv_texproj_enabled = BoolProperty(
354 name="Texture Projection Enabled",
355 description="Texture Projection is enabled",
356 default=False
358 scene.muv_texproj_tex_magnitude = FloatProperty(
359 name="Magnitude",
360 description="Texture Magnitude",
361 default=0.5,
362 min=0.0,
363 max=100.0
365 scene.muv_texproj_tex_image = EnumProperty(
366 name="Image",
367 description="Texture Image",
368 items=get_loaded_texture_name
370 scene.muv_texproj_tex_transparency = FloatProperty(
371 name="Transparency",
372 description="Texture Transparency",
373 default=0.2,
374 min=0.0,
375 max=1.0
377 scene.muv_texproj_adjust_window = BoolProperty(
378 name="Adjust Window",
379 description="Size of renderered texture is fitted to window",
380 default=True
382 scene.muv_texproj_apply_tex_aspect = BoolProperty(
383 name="Texture Aspect Ratio",
384 description="Apply Texture Aspect ratio to displayed texture",
385 default=True
387 scene.muv_texproj_assign_uvmap = BoolProperty(
388 name="Assign UVMap",
389 description="Assign UVMap when no UVmaps are available",
390 default=True
393 # Texture Lock
394 scene.muv_texlock_enabled = BoolProperty(
395 name="Texture Lock Enabled",
396 description="Texture Lock is enabled",
397 default=False
399 scene.muv_texlock_connect = BoolProperty(
400 name="Connect UV",
401 default=True
404 # World Scale UV
405 scene.muv_wsuv_enabled = BoolProperty(
406 name="World Scale UV Enabled",
407 description="World Scale UV is enabled",
408 default=False
410 scene.muv_wsuv_src_mesh_area = FloatProperty(
411 name="Mesh Area",
412 description="Source Mesh Area",
413 default=0.0,
414 min=0.0
416 scene.muv_wsuv_src_uv_area = FloatProperty(
417 name="UV Area",
418 description="Source UV Area",
419 default=0.0,
420 min=0.0
422 scene.muv_wsuv_src_density = FloatProperty(
423 name="Density",
424 description="Source Texel Density",
425 default=0.0,
426 min=0.0
428 scene.muv_wsuv_tgt_density = FloatProperty(
429 name="Density",
430 description="Target Texel Density",
431 default=0.0,
432 min=0.0
434 scene.muv_wsuv_mode = EnumProperty(
435 name="Mode",
436 description="Density calculation mode",
437 items=[
438 ('PROPORTIONAL', 'Proportional', 'Scale proportionally by mesh'),
439 ('SCALING', 'Scaling', 'Specify scale factor'),
440 ('USER', 'User', 'Specify density'),
441 ('CONSTANT', 'Constant', 'Constant density')
443 default='CONSTANT'
445 scene.muv_wsuv_scaling_factor = FloatProperty(
446 name="Scaling Factor",
447 default=1.0,
448 max=1000.0,
449 min=0.00001
451 scene.muv_wsuv_origin = EnumProperty(
452 name="Origin",
453 description="Aspect Origin",
454 items=[
455 ('CENTER', 'Center', 'Center'),
456 ('LEFT_TOP', 'Left Top', 'Left Bottom'),
457 ('LEFT_CENTER', 'Left Center', 'Left Center'),
458 ('LEFT_BOTTOM', 'Left Bottom', 'Left Bottom'),
459 ('CENTER_TOP', 'Center Top', 'Center Top'),
460 ('CENTER_BOTTOM', 'Center Bottom', 'Center Bottom'),
461 ('RIGHT_TOP', 'Right Top', 'Right Top'),
462 ('RIGHT_CENTER', 'Right Center', 'Right Center'),
463 ('RIGHT_BOTTOM', 'Right Bottom', 'Right Bottom')
466 default='CENTER'
469 # Unwrap Constraint
470 scene.muv_unwrapconst_enabled = BoolProperty(
471 name="Unwrap Constraint Enabled",
472 description="Unwrap Constraint is enabled",
473 default=False
475 scene.muv_unwrapconst_u_const = BoolProperty(
476 name="U-Constraint",
477 description="Keep UV U-axis coordinate",
478 default=False
480 scene.muv_unwrapconst_v_const = BoolProperty(
481 name="V-Constraint",
482 description="Keep UV V-axis coordinate",
483 default=False
486 # Preserve UV Aspect
487 scene.muv_preserve_uv_enabled = BoolProperty(
488 name="Preserve UV Aspect Enabled",
489 description="Preserve UV Aspect is enabled",
490 default=False
492 scene.muv_preserve_uv_tex_image = EnumProperty(
493 name="Image",
494 description="Texture Image",
495 items=get_loaded_texture_name
497 scene.muv_preserve_uv_origin = EnumProperty(
498 name="Origin",
499 description="Aspect Origin",
500 items=[
501 ('CENTER', 'Center', 'Center'),
502 ('LEFT_TOP', 'Left Top', 'Left Bottom'),
503 ('LEFT_CENTER', 'Left Center', 'Left Center'),
504 ('LEFT_BOTTOM', 'Left Bottom', 'Left Bottom'),
505 ('CENTER_TOP', 'Center Top', 'Center Top'),
506 ('CENTER_BOTTOM', 'Center Bottom', 'Center Bottom'),
507 ('RIGHT_TOP', 'Right Top', 'Right Top'),
508 ('RIGHT_CENTER', 'Right Center', 'Right Center'),
509 ('RIGHT_BOTTOM', 'Right Bottom', 'Right Bottom')
512 default="CENTER"
515 # Flip/Rotate UV
516 scene.muv_fliprot_enabled = BoolProperty(
517 name="Flip/Rotate UV Enabled",
518 description="Flip/Rotate UV is enabled",
519 default=False
521 scene.muv_fliprot_seams = BoolProperty(
522 name="Seams",
523 description="Seams",
524 default=True
527 # Mirror UV
528 scene.muv_mirroruv_enabled = BoolProperty(
529 name="Mirror UV Enabled",
530 description="Mirror UV is enabled",
531 default=False
533 scene.muv_mirroruv_axis = EnumProperty(
534 items=[
535 ('X', "X", "Mirror Along X axis"),
536 ('Y', "Y", "Mirror Along Y axis"),
537 ('Z', "Z", "Mirror Along Z axis")
539 name="Axis",
540 description="Mirror Axis",
541 default='X'
544 # Copy/Paste UV
545 scene.muv_cpuv_enabled = BoolProperty(
546 name="Copy/Paste UV Enabled",
547 description="Copy/Paste UV is enabled",
548 default=False
550 scene.muv_cpuv_copy_seams = BoolProperty(
551 name="Copy Seams",
552 description="Copy Seams",
553 default=True
555 scene.muv_cpuv_mode = EnumProperty(
556 items=[
557 ('DEFAULT', "Default", "Default Mode"),
558 ('SEL_SEQ', "Selection Sequence", "Selection Sequence Mode")
560 name="Copy/Paste UV Mode",
561 description="Copy/Paste UV Mode",
562 default='DEFAULT'
564 scene.muv_cpuv_strategy = EnumProperty(
565 name="Strategy",
566 description="Paste Strategy",
567 items=[
568 ('N_N', 'N:N', 'Number of faces must be equal to source'),
569 ('N_M', 'N:M', 'Number of faces must not be equal to source')
571 default='N_M'
574 # Transfer UV
575 scene.muv_transuv_enabled = BoolProperty(
576 name="Transfer UV Enabled",
577 description="Transfer UV is enabled",
578 default=False
580 scene.muv_transuv_invert_normals = BoolProperty(
581 name="Invert Normals",
582 description="Invert Normals",
583 default=False
585 scene.muv_transuv_copy_seams = BoolProperty(
586 name="Copy Seams",
587 description="Copy Seams",
588 default=True
591 # Align UV Cursor
592 def auvc_get_cursor_loc(self):
593 area, _, space = common.get_space('IMAGE_EDITOR', 'WINDOW',
594 'IMAGE_EDITOR')
595 bd_size = common.get_uvimg_editor_board_size(area)
596 loc = space.cursor_location
597 if bd_size[0] < 0.000001:
598 cx = 0.0
599 else:
600 cx = loc[0] / bd_size[0]
601 if bd_size[1] < 0.000001:
602 cy = 0.0
603 else:
604 cy = loc[1] / bd_size[1]
605 self['muv_auvc_cursor_loc'] = Vector((cx, cy))
606 return self.get('muv_auvc_cursor_loc', (0.0, 0.0))
608 def auvc_set_cursor_loc(self, value):
609 self['muv_auvc_cursor_loc'] = value
610 area, _, space = common.get_space('IMAGE_EDITOR', 'WINDOW',
611 'IMAGE_EDITOR')
612 bd_size = common.get_uvimg_editor_board_size(area)
613 cx = bd_size[0] * value[0]
614 cy = bd_size[1] * value[1]
615 space.cursor_location = Vector((cx, cy))
617 scene.muv_auvc_enabled = BoolProperty(
618 name="Align UV Cursor Enabled",
619 description="Align UV Cursor is enabled",
620 default=False
622 scene.muv_auvc_cursor_loc = FloatVectorProperty(
623 name="UV Cursor Location",
624 size=2,
625 precision=4,
626 soft_min=-1.0,
627 soft_max=1.0,
628 step=1,
629 default=(0.000, 0.000),
630 get=auvc_get_cursor_loc,
631 set=auvc_set_cursor_loc
633 scene.muv_auvc_align_menu = EnumProperty(
634 name="Align Method",
635 description="Align Method",
636 default='TEXTURE',
637 items=[
638 ('TEXTURE', "Texture", "Align to texture"),
639 ('UV', "UV", "Align to UV"),
640 ('UV_SEL', "UV (Selected)", "Align to Selected UV")
644 # UV Cursor Location
645 scene.muv_uvcloc_enabled = BoolProperty(
646 name="UV Cursor Location Enabled",
647 description="UV Cursor Location is enabled",
648 default=False
652 def clear_props(scene):
653 del scene.muv_props
655 # UV Sculpt
656 del scene.muv_uvsculpt_enabled
657 del scene.muv_uvsculpt_radius
658 del scene.muv_uvsculpt_strength
659 del scene.muv_uvsculpt_tools
660 del scene.muv_uvsculpt_show_brush
661 del scene.muv_uvsculpt_pinch_invert
662 del scene.muv_uvsculpt_relax_method
664 # Texture Wrap
665 del scene.muv_texwrap_enabled
666 del scene.muv_texwrap_set_and_refer
667 del scene.muv_texwrap_selseq
669 # UV Inspection
670 del scene.muv_seluv_enabled
671 del scene.muv_uvinsp_enabled
672 del scene.muv_uvinsp_show_overlapped
673 del scene.muv_uvinsp_show_flipped
674 del scene.muv_uvinsp_show_mode
676 # Align UV
677 del scene.muv_auv_enabled
678 del scene.muv_auv_transmission
679 del scene.muv_auv_select
680 del scene.muv_auv_vertical
681 del scene.muv_auv_horizontal
682 del scene.muv_auv_location
684 # Smooth UV
685 del scene.muv_smuv_enabled
686 del scene.muv_smuv_transmission
687 del scene.muv_smuv_mesh_infl
688 del scene.muv_smuv_select
690 # UV Bounding Box
691 del scene.muv_uvbb_enabled
692 del scene.muv_uvbb_uniform_scaling
693 del scene.muv_uvbb_boundary
695 # Pack UV
696 del scene.muv_packuv_enabled
697 del scene.muv_packuv_allowable_center_deviation
698 del scene.muv_packuv_allowable_size_deviation
700 # Move UV
701 del scene.muv_mvuv_enabled
703 # UVW
704 del scene.muv_uvw_enabled
705 del scene.muv_uvw_assign_uvmap
707 # Texture Projection
708 del scene.muv_texproj_enabled
709 del scene.muv_texproj_tex_magnitude
710 del scene.muv_texproj_tex_image
711 del scene.muv_texproj_tex_transparency
712 del scene.muv_texproj_adjust_window
713 del scene.muv_texproj_apply_tex_aspect
714 del scene.muv_texproj_assign_uvmap
716 # Texture Lock
717 del scene.muv_texlock_enabled
718 del scene.muv_texlock_connect
720 # World Scale UV
721 del scene.muv_wsuv_enabled
722 del scene.muv_wsuv_src_mesh_area
723 del scene.muv_wsuv_src_uv_area
724 del scene.muv_wsuv_src_density
725 del scene.muv_wsuv_tgt_density
726 del scene.muv_wsuv_mode
727 del scene.muv_wsuv_scaling_factor
728 del scene.muv_wsuv_origin
730 # Unwrap Constraint
731 del scene.muv_unwrapconst_enabled
732 del scene.muv_unwrapconst_u_const
733 del scene.muv_unwrapconst_v_const
735 # Preserve UV Aspect
736 del scene.muv_preserve_uv_enabled
737 del scene.muv_preserve_uv_tex_image
738 del scene.muv_preserve_uv_origin
740 # Flip/Rotate UV
741 del scene.muv_fliprot_enabled
742 del scene.muv_fliprot_seams
744 # Mirror UV
745 del scene.muv_mirroruv_enabled
746 del scene.muv_mirroruv_axis
748 # Copy/Paste UV
749 del scene.muv_cpuv_enabled
750 del scene.muv_cpuv_copy_seams
751 del scene.muv_cpuv_mode
752 del scene.muv_cpuv_strategy
754 # Transfer UV
755 del scene.muv_transuv_enabled
756 del scene.muv_transuv_invert_normals
757 del scene.muv_transuv_copy_seams
759 # Align UV Cursor
760 del scene.muv_auvc_enabled
761 del scene.muv_auvc_cursor_loc
762 del scene.muv_auvc_align_menu
764 # UV Cursor Location
765 del scene.muv_uvcloc_enabled