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"
24 __date__
= "24 Feb 2018"
27 from bpy
.props
import (
34 from mathutils
import Vector
39 def get_loaded_texture_name(_
, __
):
40 items
= [(key
, key
, "") for key
in bpy
.data
.images
.keys()]
41 items
.append(("None", "None", ""))
45 # Properties used in this add-on.
46 class MUV_Properties():
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():
79 class MUV_CPUVSelSeqProps():
85 class MUV_TransUVProps():
89 class MUV_TexProjProps():
93 class MUV_UVBBProps():
100 class MUV_TexLockProps():
102 intr_verts_orig
= None
106 class MUV_TexWrapProps():
111 class MUV_MVUVProps():
115 class MUV_UVInspProps():
116 display_running
= False
121 class MUV_UVSculptProps():
125 def init_props(scene
):
126 scene
.muv_props
= MUV_Properties()
129 scene
.muv_uvsculpt_enabled
= BoolProperty(
131 description
="UV Sculpt is enabled",
134 scene
.muv_uvsculpt_radius
= IntProperty(
136 description
="Radius of the brush",
141 scene
.muv_uvsculpt_strength
= FloatProperty(
143 description
="How powerful the effect of the brush when applied",
148 scene
.muv_uvsculpt_tools
= EnumProperty(
150 description
="Select Tools for the UV sculpt brushes",
152 ('GRAB', "Grab", "Grab UVs"),
153 ('RELAX', "Relax", "Relax UVs"),
154 ('PINCH', "Pinch", "Pinch UVs")
158 scene
.muv_uvsculpt_show_brush
= BoolProperty(
160 description
="Show Brush",
163 scene
.muv_uvsculpt_pinch_invert
= BoolProperty(
165 description
="Pinch UV to invert direction",
168 scene
.muv_uvsculpt_relax_method
= EnumProperty(
170 description
="Algorithm used for relaxation",
172 ('HC', "HC", "Use HC method for relaxation"),
173 ('LAPLACIAN', "Laplacian", "Use laplacian method for relaxation")
179 scene
.muv_texwrap_enabled
= BoolProperty(
181 description
="Texture Wrap is enabled",
184 scene
.muv_texwrap_set_and_refer
= BoolProperty(
185 name
="Set and Refer",
186 description
="Refer and set UV",
189 scene
.muv_texwrap_selseq
= BoolProperty(
190 name
="Selection Sequence",
191 description
="Set UV sequentially",
196 scene
.muv_seluv_enabled
= BoolProperty(
197 name
="Select UV Enabled",
198 description
="Select UV is enabled",
201 scene
.muv_uvinsp_enabled
= BoolProperty(
202 name
="UV Inspection Enabled",
203 description
="UV Inspection is enabled",
206 scene
.muv_uvinsp_show_overlapped
= BoolProperty(
208 description
="Show overlapped UVs",
211 scene
.muv_uvinsp_show_flipped
= BoolProperty(
213 description
="Show flipped UVs",
216 scene
.muv_uvinsp_show_mode
= EnumProperty(
218 description
="Show mode",
220 ('PART', "Part", "Show only overlapped/flipped part"),
221 ('FACE', "Face", "Show overlapped/flipped face")
227 scene
.muv_auv_enabled
= BoolProperty(
228 name
="Aline UV Enabled",
229 description
="Align UV is enabled",
232 scene
.muv_auv_transmission
= BoolProperty(
234 description
="Align linked UVs",
237 scene
.muv_auv_select
= BoolProperty(
239 description
="Select UVs which are aligned",
242 scene
.muv_auv_vertical
= BoolProperty(
243 name
="Vert-Infl (Vertical)",
244 description
="Align vertical direction influenced "
245 "by mesh vertex proportion",
248 scene
.muv_auv_horizontal
= BoolProperty(
249 name
="Vert-Infl (Horizontal)",
250 description
="Align horizontal direction influenced "
251 "by mesh vertex proportion",
254 scene
.muv_auv_location
= EnumProperty(
256 description
="Align location",
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")
266 scene
.muv_smuv_enabled
= BoolProperty(
267 name
="Smooth UV Enabled",
268 description
="Smooth UV is enabled",
271 scene
.muv_smuv_transmission
= BoolProperty(
273 description
="Smooth linked UVs",
276 scene
.muv_smuv_mesh_infl
= FloatProperty(
277 name
="Mesh Influence",
278 description
="Influence rate of mesh vertex",
283 scene
.muv_smuv_select
= BoolProperty(
285 description
="Select UVs which are smoothed",
290 scene
.muv_uvbb_enabled
= BoolProperty(
291 name
="UV Bounding Box Enabled",
292 description
="UV Bounding Box is enabled",
295 scene
.muv_uvbb_uniform_scaling
= BoolProperty(
296 name
="Uniform Scaling",
297 description
="Enable Uniform Scaling",
300 scene
.muv_uvbb_boundary
= EnumProperty(
302 description
="Boundary",
305 ('UV', "UV", "Boundary is decided by UV"),
306 ('UV_SEL', "UV (Selected)", "Boundary is decided by Selected UV")
311 scene
.muv_packuv_enabled
= BoolProperty(
312 name
="Pack UV Enabled",
313 description
="Pack UV is enabled",
316 scene
.muv_packuv_allowable_center_deviation
= FloatVectorProperty(
317 name
="Allowable Center Deviation",
318 description
="Allowable center deviation to judge same UV island",
321 default
=(0.001, 0.001),
324 scene
.muv_packuv_allowable_size_deviation
= FloatVectorProperty(
325 name
="Allowable Size Deviation",
326 description
="Allowable sizse deviation to judge same UV island",
329 default
=(0.001, 0.001),
334 scene
.muv_mvuv_enabled
= BoolProperty(
335 name
="Move UV Enabled",
336 description
="Move UV is enabled",
341 scene
.muv_uvw_enabled
= BoolProperty(
343 description
="UVW is enabled",
346 scene
.muv_uvw_assign_uvmap
= BoolProperty(
348 description
="Assign UVMap when no UVmaps are available",
353 scene
.muv_texproj_enabled
= BoolProperty(
354 name
="Texture Projection Enabled",
355 description
="Texture Projection is enabled",
358 scene
.muv_texproj_tex_magnitude
= FloatProperty(
360 description
="Texture Magnitude",
365 scene
.muv_texproj_tex_image
= EnumProperty(
367 description
="Texture Image",
368 items
=get_loaded_texture_name
370 scene
.muv_texproj_tex_transparency
= FloatProperty(
372 description
="Texture Transparency",
377 scene
.muv_texproj_adjust_window
= BoolProperty(
378 name
="Adjust Window",
379 description
="Size of renderered texture is fitted to window",
382 scene
.muv_texproj_apply_tex_aspect
= BoolProperty(
383 name
="Texture Aspect Ratio",
384 description
="Apply Texture Aspect ratio to displayed texture",
387 scene
.muv_texproj_assign_uvmap
= BoolProperty(
389 description
="Assign UVMap when no UVmaps are available",
394 scene
.muv_texlock_enabled
= BoolProperty(
395 name
="Texture Lock Enabled",
396 description
="Texture Lock is enabled",
399 scene
.muv_texlock_connect
= BoolProperty(
405 scene
.muv_wsuv_enabled
= BoolProperty(
406 name
="World Scale UV Enabled",
407 description
="World Scale UV is enabled",
410 scene
.muv_wsuv_src_mesh_area
= FloatProperty(
412 description
="Source Mesh Area",
416 scene
.muv_wsuv_src_uv_area
= FloatProperty(
418 description
="Source UV Area",
422 scene
.muv_wsuv_src_density
= FloatProperty(
424 description
="Source Texel Density",
428 scene
.muv_wsuv_tgt_density
= FloatProperty(
430 description
="Target Texel Density",
434 scene
.muv_wsuv_mode
= EnumProperty(
436 description
="Density calculation mode",
438 ('PROPORTIONAL', 'Proportional', 'Scale proportionally by mesh'),
439 ('SCALING', 'Scaling', 'Specify scale factor'),
440 ('USER', 'User', 'Specify density'),
441 ('CONSTANT', 'Constant', 'Constant density')
445 scene
.muv_wsuv_scaling_factor
= FloatProperty(
446 name
="Scaling Factor",
451 scene
.muv_wsuv_origin
= EnumProperty(
453 description
="Aspect Origin",
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')
470 scene
.muv_unwrapconst_enabled
= BoolProperty(
471 name
="Unwrap Constraint Enabled",
472 description
="Unwrap Constraint is enabled",
475 scene
.muv_unwrapconst_u_const
= BoolProperty(
477 description
="Keep UV U-axis coordinate",
480 scene
.muv_unwrapconst_v_const
= BoolProperty(
482 description
="Keep UV V-axis coordinate",
487 scene
.muv_preserve_uv_enabled
= BoolProperty(
488 name
="Preserve UV Aspect Enabled",
489 description
="Preserve UV Aspect is enabled",
492 scene
.muv_preserve_uv_tex_image
= EnumProperty(
494 description
="Texture Image",
495 items
=get_loaded_texture_name
497 scene
.muv_preserve_uv_origin
= EnumProperty(
499 description
="Aspect Origin",
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')
516 scene
.muv_fliprot_enabled
= BoolProperty(
517 name
="Flip/Rotate UV Enabled",
518 description
="Flip/Rotate UV is enabled",
521 scene
.muv_fliprot_seams
= BoolProperty(
528 scene
.muv_mirroruv_enabled
= BoolProperty(
529 name
="Mirror UV Enabled",
530 description
="Mirror UV is enabled",
533 scene
.muv_mirroruv_axis
= EnumProperty(
535 ('X', "X", "Mirror Along X axis"),
536 ('Y', "Y", "Mirror Along Y axis"),
537 ('Z', "Z", "Mirror Along Z axis")
540 description
="Mirror Axis",
545 scene
.muv_cpuv_enabled
= BoolProperty(
546 name
="Copy/Paste UV Enabled",
547 description
="Copy/Paste UV is enabled",
550 scene
.muv_cpuv_copy_seams
= BoolProperty(
552 description
="Copy Seams",
555 scene
.muv_cpuv_mode
= EnumProperty(
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",
564 scene
.muv_cpuv_strategy
= EnumProperty(
566 description
="Paste Strategy",
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')
575 scene
.muv_transuv_enabled
= BoolProperty(
576 name
="Transfer UV Enabled",
577 description
="Transfer UV is enabled",
580 scene
.muv_transuv_invert_normals
= BoolProperty(
581 name
="Invert Normals",
582 description
="Invert Normals",
585 scene
.muv_transuv_copy_seams
= BoolProperty(
587 description
="Copy Seams",
592 def auvc_get_cursor_loc(self
):
593 area
, _
, space
= common
.get_space('IMAGE_EDITOR', 'WINDOW',
595 bd_size
= common
.get_uvimg_editor_board_size(area
)
596 loc
= space
.cursor_location
597 if bd_size
[0] < 0.000001:
600 cx
= loc
[0] / bd_size
[0]
601 if bd_size
[1] < 0.000001:
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',
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",
622 scene
.muv_auvc_cursor_loc
= FloatVectorProperty(
623 name
="UV Cursor Location",
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(
635 description
="Align Method",
638 ('TEXTURE', "Texture", "Align to texture"),
639 ('UV', "UV", "Align to UV"),
640 ('UV_SEL', "UV (Selected)", "Align to Selected UV")
645 scene
.muv_uvcloc_enabled
= BoolProperty(
646 name
="UV Cursor Location Enabled",
647 description
="UV Cursor Location is enabled",
652 def clear_props(scene
):
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
665 del scene
.muv_texwrap_enabled
666 del scene
.muv_texwrap_set_and_refer
667 del scene
.muv_texwrap_selseq
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
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
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
691 del scene
.muv_uvbb_enabled
692 del scene
.muv_uvbb_uniform_scaling
693 del scene
.muv_uvbb_boundary
696 del scene
.muv_packuv_enabled
697 del scene
.muv_packuv_allowable_center_deviation
698 del scene
.muv_packuv_allowable_size_deviation
701 del scene
.muv_mvuv_enabled
704 del scene
.muv_uvw_enabled
705 del scene
.muv_uvw_assign_uvmap
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
717 del scene
.muv_texlock_enabled
718 del scene
.muv_texlock_connect
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
731 del scene
.muv_unwrapconst_enabled
732 del scene
.muv_unwrapconst_u_const
733 del scene
.muv_unwrapconst_v_const
736 del scene
.muv_preserve_uv_enabled
737 del scene
.muv_preserve_uv_tex_image
738 del scene
.muv_preserve_uv_origin
741 del scene
.muv_fliprot_enabled
742 del scene
.muv_fliprot_seams
745 del scene
.muv_mirroruv_enabled
746 del scene
.muv_mirroruv_axis
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
755 del scene
.muv_transuv_enabled
756 del scene
.muv_transuv_invert_normals
757 del scene
.muv_transuv_copy_seams
760 del scene
.muv_auvc_enabled
761 del scene
.muv_auvc_cursor_loc
762 del scene
.muv_auvc_align_menu
765 del scene
.muv_uvcloc_enabled