From 48c4cad2c4211c52f71f5ab39b94538608ecd90e Mon Sep 17 00:00:00 2001 From: Nutti Date: Sun, 20 Jan 2019 22:45:34 +0900 Subject: Magic UV: Fix error and cleanup codes --- uv_magic_uv/__init__.py | 25 +-- uv_magic_uv/common.py | 3 +- uv_magic_uv/lib/bglx.py | 15 ++ uv_magic_uv/op/align_uv.py | 46 ++-- uv_magic_uv/op/align_uv_cursor.py | 14 +- uv_magic_uv/op/copy_paste_uv.py | 48 ++--- uv_magic_uv/op/copy_paste_uv_object.py | 27 ++- uv_magic_uv/op/copy_paste_uv_uvedit.py | 7 +- uv_magic_uv/op/flip_rotate_uv.py | 12 +- uv_magic_uv/op/mirror_uv.py | 30 +-- uv_magic_uv/op/move_uv.py | 4 +- uv_magic_uv/op/pack_uv.py | 16 +- uv_magic_uv/op/preserve_uv_aspect.py | 12 +- uv_magic_uv/op/select_uv.py | 6 +- uv_magic_uv/op/smooth_uv.py | 16 +- uv_magic_uv/op/texture_lock.py | 16 +- uv_magic_uv/op/texture_projection.py | 64 +++--- uv_magic_uv/op/texture_wrap.py | 10 +- uv_magic_uv/op/transfer_uv.py | 18 +- uv_magic_uv/op/unwrap_constraint.py | 22 +- uv_magic_uv/op/uv_bounding_box.py | 22 +- uv_magic_uv/op/uv_inspection.py | 19 +- uv_magic_uv/op/uv_sculpt.py | 23 +- uv_magic_uv/op/uvw.py | 34 ++- uv_magic_uv/op/world_scale_uv.py | 55 ++--- uv_magic_uv/preferences.py | 246 +++++++++------------- uv_magic_uv/properites.py | 18 +- uv_magic_uv/ui/IMAGE_MT_uvs.py | 33 ++- uv_magic_uv/ui/VIEW3D_MT_object.py | 15 +- uv_magic_uv/ui/VIEW3D_MT_uv_map.py | 56 ++--- uv_magic_uv/ui/uvedit_copy_paste_uv.py | 13 +- uv_magic_uv/ui/uvedit_editor_enhancement.py | 3 +- uv_magic_uv/ui/view3d_copy_paste_uv_editmode.py | 31 +-- uv_magic_uv/ui/view3d_copy_paste_uv_objectmode.py | 13 +- uv_magic_uv/ui/view3d_uv_mapping.py | 9 +- uv_magic_uv/updater.py | 136 ++++++++++++ uv_magic_uv/utils/addon_updator.py | 21 +- 37 files changed, 626 insertions(+), 532 deletions(-) create mode 100644 uv_magic_uv/updater.py (limited to 'uv_magic_uv') diff --git a/uv_magic_uv/__init__.py b/uv_magic_uv/__init__.py index ae0317ed..094c7989 100644 --- a/uv_magic_uv/__init__.py +++ b/uv_magic_uv/__init__.py @@ -51,6 +51,7 @@ if "bpy" in locals(): importlib.reload(ui) importlib.reload(properites) importlib.reload(preferences) + importlib.reload(updater) else: import bpy from . import common @@ -59,36 +60,24 @@ else: from . import ui from . import properites from . import preferences - -import os + from . import updater import bpy -def register_updater(bl_info): - config = utils.addon_updator.AddonUpdatorConfig() - config.owner = "nutti" - config.repository = "Magic-UV" - config.current_addon_path = os.path.dirname(os.path.realpath(__file__)) - config.branches = ["master", "develop"] - config.addon_directory = config.current_addon_path[:config.current_addon_path.rfind("/")] - config.min_release_version = bl_info["version"] - config.target_addon_path = "src/uv_magic_uv" - updater = utils.addon_updator.AddonUpdatorManager.get_instance() - updater.init(bl_info, config) - - def register(): - register_updater(bl_info) + updater.register_updater(bl_info) utils.bl_class_registry.BlClassRegistry.register() properites.init_props(bpy.types.Scene) - if utils.compatibility.get_user_preferences(bpy.context).addons['uv_magic_uv'].preferences.enable_builtin_menu: + user_prefs = utils.compatibility.get_user_preferences(bpy.context) + if user_prefs.addons['uv_magic_uv'].preferences.enable_builtin_menu: preferences.add_builtin_menu() def unregister(): - if utils.compatibility.get_user_preferences(bpy.context).addons['uv_magic_uv'].preferences.enable_builtin_menu: + user_prefs = utils.compatibility.get_user_preferences(bpy.context) + if user_prefs.addons['uv_magic_uv'].preferences.enable_builtin_menu: preferences.remove_builtin_menu() properites.clear_props(bpy.types.Scene) utils.bl_class_registry.BlClassRegistry.unregister() diff --git a/uv_magic_uv/common.py b/uv_magic_uv/common.py index 961ce447..5e4fd486 100644 --- a/uv_magic_uv/common.py +++ b/uv_magic_uv/common.py @@ -409,7 +409,8 @@ def find_image(obj, face=None, tex_layer=None): nodes = find_texture_nodes(obj) if len(nodes) >= 2: raise RuntimeError("Find more than 2 texture nodes") - img = nodes[0].image + if len(nodes) == 1: + img = nodes[0].image return img diff --git a/uv_magic_uv/lib/bglx.py b/uv_magic_uv/lib/bglx.py index 72e030fa..5abde12c 100644 --- a/uv_magic_uv/lib/bglx.py +++ b/uv_magic_uv/lib/bglx.py @@ -235,6 +235,12 @@ GL_SCISSOR_BOX = bgl.GL_SCISSOR_BOX GL_TEXTURE_2D = bgl.GL_TEXTURE_2D GL_TEXTURE0 = bgl.GL_TEXTURE0 +GL_TEXTURE_MIN_FILTER = 0 +GL_TEXTURE_MAG_FILTER = 0 +GL_LINEAR = 0 +GL_TEXTURE_ENV = 0 +GL_TEXTURE_ENV_MODE = 0 +GL_MODULATE = 0 def glEnable(cap): bgl.glEnable(cap) @@ -258,3 +264,12 @@ def glActiveTexture(texture): def glBindTexture(target, texture): bgl.glBindTexture(target, texture) + + +def glTexParameteri(target, pname, param): + pass + + +def glTexEnvi(target, pname, param): + pass + diff --git a/uv_magic_uv/op/align_uv.py b/uv_magic_uv/op/align_uv.py index 5420c33f..3b0fa221 100644 --- a/uv_magic_uv/op/align_uv.py +++ b/uv_magic_uv/op/align_uv.py @@ -296,41 +296,41 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_align_uv_enabled: BoolProperty( + scene.muv_align_uv_enabled = BoolProperty( name="Align UV Enabled", description="Align UV is enabled", default=False ) - scene.muv_align_uv_transmission: BoolProperty( + scene.muv_align_uv_transmission = BoolProperty( name="Transmission", description="Align linked UVs", default=False ) - scene.muv_align_uv_select: BoolProperty( + scene.muv_align_uv_select = BoolProperty( name="Select", description="Select UVs which are aligned", default=False ) - scene.muv_align_uv_vertical: BoolProperty( + scene.muv_align_uv_vertical = BoolProperty( name="Vert-Infl (Vertical)", description="Align vertical direction influenced " "by mesh vertex proportion", default=False ) - scene.muv_align_uv_horizontal: BoolProperty( + scene.muv_align_uv_horizontal = BoolProperty( name="Vert-Infl (Horizontal)", description="Align horizontal direction influenced " "by mesh vertex proportion", default=False ) - scene.muv_align_uv_mesh_infl: FloatProperty( + scene.muv_align_uv_mesh_infl = FloatProperty( name="Mesh Influence", description="Influence rate of mesh vertex", min=0.0, max=1.0, default=0.0 ) - scene.muv_align_uv_location: EnumProperty( + scene.muv_align_uv_location = EnumProperty( name="Location", description="Align location", items=[ @@ -356,17 +356,17 @@ class _Properties: @compat.make_annotations class MUV_OT_AlignUV_Circle(bpy.types.Operator): - bl_idname = "uv.muv_align_uv_operator_circle" + bl_idname = "uv.muv_ot_align_uv_circle" bl_label = "Align UV (Circle)" bl_description = "Align UV coordinates to Circle" bl_options = {'REGISTER', 'UNDO'} - transmission: BoolProperty( + transmission = BoolProperty( name="Transmission", description="Align linked UVs", default=False ) - select: BoolProperty( + select = BoolProperty( name="Select", description="Select UVs which are aligned", default=False @@ -442,34 +442,34 @@ class MUV_OT_AlignUV_Circle(bpy.types.Operator): @compat.make_annotations class MUV_OT_AlignUV_Straighten(bpy.types.Operator): - bl_idname = "uv.muv_align_uv_operator_straighten" + bl_idname = "uv.muv_ot_align_uv_straighten" bl_label = "Align UV (Straighten)" bl_description = "Straighten UV coordinates" bl_options = {'REGISTER', 'UNDO'} - transmission: BoolProperty( + transmission = BoolProperty( name="Transmission", description="Align linked UVs", default=False ) - select: BoolProperty( + select = BoolProperty( name="Select", description="Select UVs which are aligned", default=False ) - vertical: BoolProperty( + vertical = BoolProperty( name="Vert-Infl (Vertical)", description="Align vertical direction influenced " "by mesh vertex proportion", default=False ) - horizontal: BoolProperty( + horizontal = BoolProperty( name="Vert-Infl (Horizontal)", description="Align horizontal direction influenced " "by mesh vertex proportion", default=False ) - mesh_infl: FloatProperty( + mesh_infl = FloatProperty( name="Mesh Influence", description="Influence rate of mesh vertex", min=0.0, @@ -594,34 +594,34 @@ class MUV_OT_AlignUV_Straighten(bpy.types.Operator): @compat.make_annotations class MUV_OT_AlignUV_Axis(bpy.types.Operator): - bl_idname = "uv.muv_align_uv_operator_axis" + bl_idname = "uv.muv_ot_align_uv_axis" bl_label = "Align UV (XY-Axis)" bl_description = "Align UV to XY-axis" bl_options = {'REGISTER', 'UNDO'} - transmission: BoolProperty( + transmission = BoolProperty( name="Transmission", description="Align linked UVs", default=False ) - select: BoolProperty( + select = BoolProperty( name="Select", description="Select UVs which are aligned", default=False ) - vertical: BoolProperty( + vertical = BoolProperty( name="Vert-Infl (Vertical)", description="Align vertical direction influenced " "by mesh vertex proportion", default=False ) - horizontal: BoolProperty( + horizontal = BoolProperty( name="Vert-Infl (Horizontal)", description="Align horizontal direction influenced " "by mesh vertex proportion", default=False ) - location: EnumProperty( + location = EnumProperty( name="Location", description="Align location", items=[ @@ -631,7 +631,7 @@ class MUV_OT_AlignUV_Axis(bpy.types.Operator): ], default='MIDDLE' ) - mesh_infl: FloatProperty( + mesh_infl = FloatProperty( name="Mesh Influence", description="Influence rate of mesh vertex", min=0.0, diff --git a/uv_magic_uv/op/align_uv_cursor.py b/uv_magic_uv/op/align_uv_cursor.py index bd92cf81..326814eb 100644 --- a/uv_magic_uv/op/align_uv_cursor.py +++ b/uv_magic_uv/op/align_uv_cursor.py @@ -86,13 +86,13 @@ class _Properties: cy = bd_size[1] * value[1] space.cursor_location = Vector((cx, cy)) - scene.muv_align_uv_cursor_enabled: BoolProperty( + scene.muv_align_uv_cursor_enabled = BoolProperty( name="Align UV Cursor Enabled", description="Align UV Cursor is enabled", default=False ) - scene.muv_align_uv_cursor_cursor_loc: FloatVectorProperty( + scene.muv_align_uv_cursor_cursor_loc = FloatVectorProperty( name="UV Cursor Location", size=2, precision=4, @@ -103,7 +103,7 @@ class _Properties: get=auvc_get_cursor_loc, set=auvc_set_cursor_loc ) - scene.muv_align_uv_cursor_align_method: EnumProperty( + scene.muv_align_uv_cursor_align_method = EnumProperty( name="Align Method", description="Align Method", default='TEXTURE', @@ -114,7 +114,7 @@ class _Properties: ] ) - scene.muv_uv_cursor_location_enabled: BoolProperty( + scene.muv_uv_cursor_location_enabled = BoolProperty( name="UV Cursor Location Enabled", description="UV Cursor Location is enabled", default=False @@ -133,12 +133,12 @@ class _Properties: @compat.make_annotations class MUV_OT_AlignUVCursor(bpy.types.Operator): - bl_idname = "uv.muv_align_uv_cursor_operator" + bl_idname = "uv.muv_ot_align_uv_cursor" bl_label = "Align UV Cursor" bl_description = "Align cursor to the center of UV island" bl_options = {'REGISTER', 'UNDO'} - position: EnumProperty( + position = EnumProperty( items=( ('CENTER', "Center", "Align to Center"), ('LEFT_TOP', "Left Top", "Align to Left Top"), @@ -154,7 +154,7 @@ class MUV_OT_AlignUVCursor(bpy.types.Operator): description="Align position", default='CENTER' ) - base: EnumProperty( + base = EnumProperty( items=( ('TEXTURE', "Texture", "Align based on Texture"), ('UV', "UV", "Align to UV"), diff --git a/uv_magic_uv/op/copy_paste_uv.py b/uv_magic_uv/op/copy_paste_uv.py index 11489f8c..d1070d90 100644 --- a/uv_magic_uv/op/copy_paste_uv.py +++ b/uv_magic_uv/op/copy_paste_uv.py @@ -280,17 +280,17 @@ class _Properties: scene.muv_props.copy_paste_uv = Props() scene.muv_props.copy_paste_uv_selseq = Props() - scene.muv_copy_paste_uv_enabled: BoolProperty( + scene.muv_copy_paste_uv_enabled = BoolProperty( name="Copy/Paste UV Enabled", description="Copy/Paste UV is enabled", default=False ) - scene.muv_copy_paste_uv_copy_seams: BoolProperty( + scene.muv_copy_paste_uv_copy_seams = BoolProperty( name="Seams", description="Copy Seams", default=True ) - scene.muv_copy_paste_uv_mode: EnumProperty( + scene.muv_copy_paste_uv_mode = EnumProperty( items=[ ('DEFAULT', "Default", "Default Mode"), ('SEL_SEQ', "Selection Sequence", "Selection Sequence Mode") @@ -299,7 +299,7 @@ class _Properties: description="Copy/Paste UV Mode", default='DEFAULT' ) - scene.muv_copy_paste_uv_strategy: EnumProperty( + scene.muv_copy_paste_uv_strategy = EnumProperty( name="Strategy", description="Paste Strategy", items=[ @@ -326,12 +326,12 @@ class MUV_OT_CopyPasteUV_CopyUV(bpy.types.Operator): Operation class: Copy UV coordinate """ - bl_idname = "uv.muv_copy_paste_uv_operator_copy_uv" + bl_idname = "uv.muv_ot_copy_paste_uv_copy_uv" bl_label = "Copy UV" bl_description = "Copy UV coordinate" bl_options = {'REGISTER', 'UNDO'} - uv_map: StringProperty(default="__default", options={'HIDDEN'}) + uv_map = StringProperty(default="__default", options={'HIDDEN'}) @classmethod def poll(cls, context): @@ -368,7 +368,7 @@ class MUV_MT_CopyPasteUV_CopyUV(bpy.types.Menu): Menu class: Copy UV coordinate """ - bl_idname = "uv.muv_copy_paste_uv_menu_copy_uv" + bl_idname = "uv.muv_mt_copy_paste_uv_copy_uv" bl_label = "Copy UV (Menu)" bl_description = "Menu of Copy UV coordinate" @@ -403,13 +403,13 @@ class MUV_OT_CopyPasteUV_PasteUV(bpy.types.Operator): Operation class: Paste UV coordinate """ - bl_idname = "uv.muv_copy_paste_uv_operator_paste_uv" + bl_idname = "uv.muv_ot_copy_paste_uv_paste_uv" bl_label = "Paste UV" bl_description = "Paste UV coordinate" bl_options = {'REGISTER', 'UNDO'} - uv_map: StringProperty(default="__default", options={'HIDDEN'}) - strategy: EnumProperty( + uv_map = StringProperty(default="__default", options={'HIDDEN'}) + strategy = EnumProperty( name="Strategy", description="Paste Strategy", items=[ @@ -418,18 +418,18 @@ class MUV_OT_CopyPasteUV_PasteUV(bpy.types.Operator): ], default="N_M" ) - flip_copied_uv: BoolProperty( + flip_copied_uv = BoolProperty( name="Flip Copied UV", description="Flip Copied UV...", default=False ) - rotate_copied_uv: IntProperty( + rotate_copied_uv = IntProperty( default=0, name="Rotate Copied UV", min=0, max=30 ) - copy_seams: BoolProperty( + copy_seams = BoolProperty( name="Seams", description="Copy Seams", default=True @@ -491,7 +491,7 @@ class MUV_MT_CopyPasteUV_PasteUV(bpy.types.Menu): Menu class: Paste UV coordinate """ - bl_idname = "uv.muv_copy_paste_uv_menu_paste_uv" + bl_idname = "uv.muv_mt_copy_paste_uv_paste_uv" bl_label = "Paste UV (Menu)" bl_description = "Menu of Paste UV coordinate" @@ -543,12 +543,12 @@ class MUV_OT_CopyPasteUV_SelSeqCopyUV(bpy.types.Operator): Operation class: Copy UV coordinate by selection sequence """ - bl_idname = "uv.muv_copy_paste_uv_operator_selseq_copy_uv" + bl_idname = "uv.muv_ot_copy_paste_uv_selseq_copy_uv" bl_label = "Copy UV (Selection Sequence)" bl_description = "Copy UV data by selection sequence" bl_options = {'REGISTER', 'UNDO'} - uv_map: StringProperty(default="__default", options={'HIDDEN'}) + uv_map = StringProperty(default="__default", options={'HIDDEN'}) @classmethod def poll(cls, context): @@ -585,7 +585,7 @@ class MUV_MT_CopyPasteUV_SelSeqCopyUV(bpy.types.Menu): Menu class: Copy UV coordinate by selection sequence """ - bl_idname = "uv.muv_copy_paste_uv_menu_selseq_copy_uv" + bl_idname = "uv.muv_mt_copy_paste_uv_selseq_copy_uv" bl_label = "Copy UV (Selection Sequence) (Menu)" bl_description = "Menu of Copy UV coordinate by selection sequence" @@ -620,13 +620,13 @@ class MUV_OT_CopyPasteUV_SelSeqPasteUV(bpy.types.Operator): Operation class: Paste UV coordinate by selection sequence """ - bl_idname = "uv.muv_copy_paste_uv_operator_selseq_paste_uv" + bl_idname = "uv.muv_ot_copy_paste_uv_selseq_paste_uv" bl_label = "Paste UV (Selection Sequence)" bl_description = "Paste UV coordinate by selection sequence" bl_options = {'REGISTER', 'UNDO'} - uv_map: StringProperty(default="__default", options={'HIDDEN'}) - strategy: EnumProperty( + uv_map = StringProperty(default="__default", options={'HIDDEN'}) + strategy = EnumProperty( name="Strategy", description="Paste Strategy", items=[ @@ -635,18 +635,18 @@ class MUV_OT_CopyPasteUV_SelSeqPasteUV(bpy.types.Operator): ], default="N_M" ) - flip_copied_uv: BoolProperty( + flip_copied_uv = BoolProperty( name="Flip Copied UV", description="Flip Copied UV...", default=False ) - rotate_copied_uv: IntProperty( + rotate_copied_uv = IntProperty( default=0, name="Rotate Copied UV", min=0, max=30 ) - copy_seams: BoolProperty( + copy_seams = BoolProperty( name="Seams", description="Copy Seams", default=True @@ -709,7 +709,7 @@ class MUV_MT_CopyPasteUV_SelSeqPasteUV(bpy.types.Menu): Menu class: Paste UV coordinate by selection sequence """ - bl_idname = "uv.muv_copy_paste_uv_menu_selseq_paste_uv" + bl_idname = "uv.muv_mt_copy_paste_uv_selseq_paste_uv" bl_label = "Paste UV (Selection Sequence) (Menu)" bl_description = "Menu of Paste UV coordinate by selection sequence" diff --git a/uv_magic_uv/op/copy_paste_uv_object.py b/uv_magic_uv/op/copy_paste_uv_object.py index 691ca42a..cd1a504f 100644 --- a/uv_magic_uv/op/copy_paste_uv_object.py +++ b/uv_magic_uv/op/copy_paste_uv_object.py @@ -75,7 +75,7 @@ class _Properties: scene.muv_props.copy_paste_uv_object = Props() - scene.muv_copy_paste_uv_object_copy_seams: BoolProperty( + scene.muv_copy_paste_uv_object_copy_seams = BoolProperty( name="Seams", description="Copy Seams", default=True @@ -103,12 +103,12 @@ class MUV_OT_CopyPasteUVObject_CopyUV(bpy.types.Operator): Operation class: Copy UV coordinate among objects """ - bl_idname = "object.muv_copy_paste_uv_object_operator_copy_uv" + bl_idname = "object.muv_ot_copy_paste_uv_object_copy_uv" bl_label = "Copy UV (Among Objects)" bl_description = "Copy UV coordinate (Among Objects)" bl_options = {'REGISTER', 'UNDO'} - uv_map: StringProperty(default="__default", options={'HIDDEN'}) + uv_map = StringProperty(default="__default", options={'HIDDEN'}) @classmethod def poll(cls, context): @@ -147,7 +147,7 @@ class MUV_MT_CopyPasteUVObject_CopyUV(bpy.types.Menu): Menu class: Copy UV coordinate among objects """ - bl_idname = "object.muv_copy_paste_uv_object_menu_copy_uv" + bl_idname = "object.muv_mt_copy_paste_uv_object_copy_uv" bl_label = "Copy UV (Among Objects) (Menu)" bl_description = "Menu of Copy UV coordinate (Among Objects)" @@ -181,13 +181,13 @@ class MUV_OT_CopyPasteUVObject_PasteUV(bpy.types.Operator): Operation class: Paste UV coordinate among objects """ - bl_idname = "object.muv_copy_paste_uv_object_operator_paste_uv" + bl_idname = "object.muv_ot_copy_paste_uv_object_paste_uv" bl_label = "Paste UV (Among Objects)" bl_description = "Paste UV coordinate (Among Objects)" bl_options = {'REGISTER', 'UNDO'} - uv_map: StringProperty(default="__default", options={'HIDDEN'}) - copy_seams: BoolProperty( + uv_map = StringProperty(default="__default", options={'HIDDEN'}) + copy_seams = BoolProperty( name="Seams", description="Copy Seams", default=True @@ -212,7 +212,9 @@ class MUV_OT_CopyPasteUVObject_PasteUV(bpy.types.Operator): return {'CANCELLED'} for o in bpy.data.objects: - if not compat.object_has_uv_layers(o) or not compat.get_object_select(o): + if not compat.object_has_uv_layers(o): + continue + if not compat.get_object_select(o): continue bpy.ops.object.mode_set(mode='OBJECT') @@ -258,7 +260,7 @@ class MUV_MT_CopyPasteUVObject_PasteUV(bpy.types.Menu): Menu class: Paste UV coordinate among objects """ - bl_idname = "object.muv_copy_paste_uv_object_menu_paste_uv" + bl_idname = "object.muv_mt_copy_paste_uv_object_paste_uv" bl_label = "Paste UV (Among Objects) (Menu)" bl_description = "Menu of Paste UV coordinate (Among Objects)" @@ -276,8 +278,11 @@ class MUV_MT_CopyPasteUVObject_PasteUV(bpy.types.Menu): # create sub menu uv_maps = [] for obj in bpy.data.objects: - if compat.object_has_uv_layers(obj) and compat.get_object_select(obj): - uv_maps.extend(compat.get_object_uv_layers(obj).keys()) + if not compat.object_has_uv_layers(obj): + continue + if not compat.get_object_select(obj): + continue + uv_maps.extend(compat.get_object_uv_layers(obj).keys()) ops = layout.operator(MUV_OT_CopyPasteUVObject_PasteUV.bl_idname, text="[Default]") diff --git a/uv_magic_uv/op/copy_paste_uv_uvedit.py b/uv_magic_uv/op/copy_paste_uv_uvedit.py index 16c0dfa5..c3557a3f 100644 --- a/uv_magic_uv/op/copy_paste_uv_uvedit.py +++ b/uv_magic_uv/op/copy_paste_uv_uvedit.py @@ -23,15 +23,14 @@ __status__ = "production" __version__ = "5.2" __date__ = "17 Nov 2018" -import bpy import math from math import atan2, sin, cos +import bpy import bmesh from mathutils import Vector from .. import common - from ..utils.bl_class_registry import BlClassRegistry from ..utils.property_class_registry import PropertyClassRegistry @@ -81,7 +80,7 @@ class MUV_OT_CopyPasteUVUVEdit_CopyUV(bpy.types.Operator): Operation class: Copy UV coordinate on UV/Image Editor """ - bl_idname = "uv.muv_copy_paste_uv_uvedit_operator_copy_uv" + bl_idname = "uv.muv_ot_copy_paste_uv_uvedit_copy_uv" bl_label = "Copy UV (UV/Image Editor)" bl_description = "Copy UV coordinate (only selected in UV/Image Editor)" bl_options = {'REGISTER', 'UNDO'} @@ -123,7 +122,7 @@ class MUV_OT_CopyPasteUVUVEdit_PasteUV(bpy.types.Operator): Operation class: Paste UV coordinate on UV/Image Editor """ - bl_idname = "uv.muv_copy_paste_uv_uvedit_operator_paste_uv" + bl_idname = "uv.muv_ot_copy_paste_uv_uvedit_paste_uv" bl_label = "Paste UV (UV/Image Editor)" bl_description = "Paste UV coordinate (only selected in UV/Image Editor)" bl_options = {'REGISTER', 'UNDO'} diff --git a/uv_magic_uv/op/flip_rotate_uv.py b/uv_magic_uv/op/flip_rotate_uv.py index 0ff38145..b289292e 100644 --- a/uv_magic_uv/op/flip_rotate_uv.py +++ b/uv_magic_uv/op/flip_rotate_uv.py @@ -144,12 +144,12 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_flip_rotate_uv_enabled: BoolProperty( + scene.muv_flip_rotate_uv_enabled = BoolProperty( name="Flip/Rotate UV Enabled", description="Flip/Rotate UV is enabled", default=False ) - scene.muv_flip_rotate_uv_seams: BoolProperty( + scene.muv_flip_rotate_uv_seams = BoolProperty( name="Seams", description="Seams", default=True @@ -168,23 +168,23 @@ class MUV_OT_FlipRotate(bpy.types.Operator): Operation class: Flip and Rotate UV coordinate """ - bl_idname = "uv.muv_flip_rotate_uv_operator" + bl_idname = "uv.muv_ot_flip_rotate_uv" bl_label = "Flip/Rotate UV" bl_description = "Flip/Rotate UV coordinate" bl_options = {'REGISTER', 'UNDO'} - flip: BoolProperty( + flip = BoolProperty( name="Flip UV", description="Flip UV...", default=False ) - rotate: IntProperty( + rotate = IntProperty( default=0, name="Rotate UV", min=0, max=30 ) - seams: BoolProperty( + seams = BoolProperty( name="Seams", description="Seams", default=True diff --git a/uv_magic_uv/op/mirror_uv.py b/uv_magic_uv/op/mirror_uv.py index bd71ee5f..112ba584 100644 --- a/uv_magic_uv/op/mirror_uv.py +++ b/uv_magic_uv/op/mirror_uv.py @@ -38,7 +38,7 @@ from ..utils import compatibility as compat from .. import common -def is_valid_context(context): +def _is_valid_context(context): obj = context.object # only edit mode is allowed to execute @@ -59,7 +59,7 @@ def is_valid_context(context): return True -def is_vector_similar(v1, v2, error): +def _is_vector_similar(v1, v2, error): """ Check if two vectors are similar, within an error threshold """ @@ -70,7 +70,7 @@ def is_vector_similar(v1, v2, error): return within_err_x and within_err_y and within_err_z -def mirror_uvs(uv_layer, src, dst, axis, error): +def _mirror_uvs(uv_layer, src, dst, axis, error): """ Copy UV coordinates from one UV face to another """ @@ -86,11 +86,11 @@ def mirror_uvs(uv_layer, src, dst, axis, error): elif axis == 'Z': dvco.z = -dvco.z - if is_vector_similar(svco, dvco, error): + if _is_vector_similar(svco, dvco, error): dl[uv_layer].uv = suv.copy() -def get_face_center(face): +def _get_face_center(face): """ Get center coordinate of the face """ @@ -107,12 +107,12 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_mirror_uv_enabled: BoolProperty( + scene.muv_mirror_uv_enabled = BoolProperty( name="Mirror UV Enabled", description="Mirror UV is enabled", default=False ) - scene.muv_mirror_uv_axis: EnumProperty( + scene.muv_mirror_uv_axis = EnumProperty( items=[ ('X', "X", "Mirror Along X axis"), ('Y', "Y", "Mirror Along Y axis"), @@ -136,11 +136,11 @@ class MUV_OT_MirrorUV(bpy.types.Operator): Operation class: Mirror UV """ - bl_idname = "uv.muv_mirror_uv_operator" + bl_idname = "uv.muv_ot_mirror_uv" bl_label = "Mirror UV" bl_options = {'REGISTER', 'UNDO'} - axis: EnumProperty( + axis = EnumProperty( items=( ('X', "X", "Mirror Along X axis"), ('Y', "Y", "Mirror Along Y axis"), @@ -150,7 +150,7 @@ class MUV_OT_MirrorUV(bpy.types.Operator): description="Mirror Axis", default='X' ) - error: FloatProperty( + error = FloatProperty( name="Error", description="Error threshold", default=0.001, @@ -165,7 +165,7 @@ class MUV_OT_MirrorUV(bpy.types.Operator): # we can not get area/space/region from console if common.is_console_mode(): return True - return is_valid_context(context) + return _is_valid_context(context) def execute(self, context): obj = context.active_object @@ -193,8 +193,8 @@ class MUV_OT_MirrorUV(bpy.types.Operator): continue # test if the vertices x values are the same sign - dst = get_face_center(f_dst) - src = get_face_center(f_src) + dst = _get_face_center(f_dst) + src = _get_face_center(f_src) if (dst.x > 0 and src.x > 0) or (dst.x < 0 and src.x < 0): continue @@ -207,8 +207,8 @@ class MUV_OT_MirrorUV(bpy.types.Operator): src.z = -src.z # do mirror UV - if is_vector_similar(dst, src, error): - mirror_uvs(uv_layer, f_src, f_dst, self.axis, self.error) + if _is_vector_similar(dst, src, error): + _mirror_uvs(uv_layer, f_src, f_dst, self.axis, self.error) bmesh.update_edit_mesh(obj.data) diff --git a/uv_magic_uv/op/move_uv.py b/uv_magic_uv/op/move_uv.py index 7f94edfb..1a8d6dd1 100644 --- a/uv_magic_uv/op/move_uv.py +++ b/uv_magic_uv/op/move_uv.py @@ -74,7 +74,7 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_move_uv_enabled: BoolProperty( + scene.muv_move_uv_enabled = BoolProperty( name="Move UV Enabled", description="Move UV is enabled", default=False @@ -91,7 +91,7 @@ class MUV_OT_MoveUV(bpy.types.Operator): Operator class: Move UV """ - bl_idname = "uv.muv_move_uv_operator" + bl_idname = "uv.muv_ot_move_uv" bl_label = "Move UV" bl_options = {'REGISTER', 'UNDO'} diff --git a/uv_magic_uv/op/pack_uv.py b/uv_magic_uv/op/pack_uv.py index 4c365f8b..ad40d049 100644 --- a/uv_magic_uv/op/pack_uv.py +++ b/uv_magic_uv/op/pack_uv.py @@ -147,12 +147,12 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_pack_uv_enabled: BoolProperty( + scene.muv_pack_uv_enabled = BoolProperty( name="Pack UV Enabled", description="Pack UV is enabled", default=False ) - scene.muv_pack_uv_allowable_center_deviation: FloatVectorProperty( + scene.muv_pack_uv_allowable_center_deviation = FloatVectorProperty( name="Allowable Center Deviation", description="Allowable center deviation to judge same UV island", min=0.000001, @@ -160,7 +160,7 @@ class _Properties: default=(0.001, 0.001), size=2 ) - scene.muv_pack_uv_allowable_size_deviation: FloatVectorProperty( + scene.muv_pack_uv_allowable_size_deviation = FloatVectorProperty( name="Allowable Size Deviation", description="Allowable sizse deviation to judge same UV island", min=0.000001, @@ -187,22 +187,22 @@ class MUV_OT_PackUV(bpy.types.Operator): - Same number of UV """ - bl_idname = "uv.muv_pack_uv_operator" + bl_idname = "uv.muv_ot_pack_uv" bl_label = "Pack UV" bl_description = "Pack UV (Same UV Islands are integrated)" bl_options = {'REGISTER', 'UNDO'} - rotate: BoolProperty( + rotate = BoolProperty( name="Rotate", description="Rotate option used by default pack UV function", default=False) - margin: FloatProperty( + margin = FloatProperty( name="Margin", description="Margin used by default pack UV function", min=0, max=1, default=0.001) - allowable_center_deviation: FloatVectorProperty( + allowable_center_deviation = FloatVectorProperty( name="Allowable Center Deviation", description="Allowable center deviation to judge same UV island", min=0.000001, @@ -210,7 +210,7 @@ class MUV_OT_PackUV(bpy.types.Operator): default=(0.001, 0.001), size=2 ) - allowable_size_deviation: FloatVectorProperty( + allowable_size_deviation = FloatVectorProperty( name="Allowable Size Deviation", description="Allowable sizse deviation to judge same UV island", min=0.000001, diff --git a/uv_magic_uv/op/preserve_uv_aspect.py b/uv_magic_uv/op/preserve_uv_aspect.py index 244deb89..591a0bf9 100644 --- a/uv_magic_uv/op/preserve_uv_aspect.py +++ b/uv_magic_uv/op/preserve_uv_aspect.py @@ -66,17 +66,17 @@ class _Properties: items.append(("None", "None", "")) return items - scene.muv_preserve_uv_aspect_enabled: BoolProperty( + scene.muv_preserve_uv_aspect_enabled = BoolProperty( name="Preserve UV Aspect Enabled", description="Preserve UV Aspect is enabled", default=False ) - scene.muv_preserve_uv_aspect_tex_image: EnumProperty( + scene.muv_preserve_uv_aspect_tex_image = EnumProperty( name="Image", description="Texture Image", items=get_loaded_texture_name ) - scene.muv_preserve_uv_aspect_origin: EnumProperty( + scene.muv_preserve_uv_aspect_origin = EnumProperty( name="Origin", description="Aspect Origin", items=[ @@ -108,13 +108,13 @@ class MUV_OT_PreserveUVAspect(bpy.types.Operator): Operation class: Preserve UV Aspect """ - bl_idname = "uv.muv_preserve_uv_aspect_operator" + bl_idname = "uv.muv_ot_preserve_uv_aspect" bl_label = "Preserve UV Aspect" bl_description = "Choose Image" bl_options = {'REGISTER', 'UNDO'} - dest_img_name: StringProperty(options={'HIDDEN'}) - origin: EnumProperty( + dest_img_name = StringProperty(options={'HIDDEN'}) + origin = EnumProperty( name="Origin", description="Aspect Origin", items=[ diff --git a/uv_magic_uv/op/select_uv.py b/uv_magic_uv/op/select_uv.py index 268843bf..6a39a9eb 100644 --- a/uv_magic_uv/op/select_uv.py +++ b/uv_magic_uv/op/select_uv.py @@ -61,7 +61,7 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_select_uv_enabled: BoolProperty( + scene.muv_select_uv_enabled = BoolProperty( name="Select UV Enabled", description="Select UV is enabled", default=False @@ -78,7 +78,7 @@ class MUV_OT_SelectUV_SelectOverlapped(bpy.types.Operator): Operation class: Select faces which have overlapped UVs """ - bl_idname = "uv.muv_select_uv_operator_select_overlapped" + bl_idname = "uv.muv_ot_select_uv_select_overlapped" bl_label = "Overlapped" bl_description = "Select faces which have overlapped UVs" bl_options = {'REGISTER', 'UNDO'} @@ -123,7 +123,7 @@ class MUV_OT_SelectUV_SelectFlipped(bpy.types.Operator): Operation class: Select faces which have flipped UVs """ - bl_idname = "uv.muv_select_uv_operator_select_flipped" + bl_idname = "uv.muv_ot_select_uv_select_flipped" bl_label = "Flipped" bl_description = "Select faces which have flipped UVs" bl_options = {'REGISTER', 'UNDO'} diff --git a/uv_magic_uv/op/smooth_uv.py b/uv_magic_uv/op/smooth_uv.py index 6b3cd36f..77a1e82f 100644 --- a/uv_magic_uv/op/smooth_uv.py +++ b/uv_magic_uv/op/smooth_uv.py @@ -62,24 +62,24 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_smooth_uv_enabled: BoolProperty( + scene.muv_smooth_uv_enabled = BoolProperty( name="Smooth UV Enabled", description="Smooth UV is enabled", default=False ) - scene.muv_smooth_uv_transmission: BoolProperty( + scene.muv_smooth_uv_transmission = BoolProperty( name="Transmission", description="Smooth linked UVs", default=False ) - scene.muv_smooth_uv_mesh_infl: FloatProperty( + scene.muv_smooth_uv_mesh_infl = FloatProperty( name="Mesh Influence", description="Influence rate of mesh vertex", min=0.0, max=1.0, default=0.0 ) - scene.muv_smooth_uv_select: BoolProperty( + scene.muv_smooth_uv_select = BoolProperty( name="Select", description="Select UVs which are smoothed", default=False @@ -97,24 +97,24 @@ class _Properties: @compat.make_annotations class MUV_OT_SmoothUV(bpy.types.Operator): - bl_idname = "uv.muv_smooth_uv_operator" + bl_idname = "uv.muv_ot_smooth_uv" bl_label = "Smooth" bl_description = "Smooth UV coordinates" bl_options = {'REGISTER', 'UNDO'} - transmission: BoolProperty( + transmission = BoolProperty( name="Transmission", description="Smooth linked UVs", default=False ) - mesh_infl: FloatProperty( + mesh_infl = FloatProperty( name="Mesh Influence", description="Influence rate of mesh vertex", min=0.0, max=1.0, default=0.0 ) - select: BoolProperty( + select = BoolProperty( name="Select", description="Select UVs which are smoothed", default=False diff --git a/uv_magic_uv/op/texture_lock.py b/uv_magic_uv/op/texture_lock.py index 6784cf54..146f5b78 100644 --- a/uv_magic_uv/op/texture_lock.py +++ b/uv_magic_uv/op/texture_lock.py @@ -226,14 +226,14 @@ class _Properties: pass def update_func(_, __): - bpy.ops.uv.muv_texture_lock_operator_intr('INVOKE_REGION_WIN') + bpy.ops.uv.muv_ot_texture_lock_intr('INVOKE_REGION_WIN') - scene.muv_texture_lock_enabled: BoolProperty( + scene.muv_texture_lock_enabled = BoolProperty( name="Texture Lock Enabled", description="Texture Lock is enabled", default=False ) - scene.muv_texture_lock_lock: BoolProperty( + scene.muv_texture_lock_lock = BoolProperty( name="Texture Lock Locked", description="Texture Lock is locked", default=False, @@ -241,7 +241,7 @@ class _Properties: set=set_func, update=update_func ) - scene.muv_texture_lock_connect: BoolProperty( + scene.muv_texture_lock_connect = BoolProperty( name="Connect UV", default=True ) @@ -260,7 +260,7 @@ class MUV_OT_TextureLock_Lock(bpy.types.Operator): Operation class: Lock Texture """ - bl_idname = "uv.muv_texture_lock_operator_lock" + bl_idname = "uv.muv_ot_texture_lock_lock" bl_label = "Lock Texture" bl_description = "Lock Texture" bl_options = {'REGISTER', 'UNDO'} @@ -307,12 +307,12 @@ class MUV_OT_TextureLock_Unlock(bpy.types.Operator): Operation class: Unlock Texture """ - bl_idname = "uv.muv_texture_lock_operator_unlock" + bl_idname = "uv.muv_ot_texture_lock_unlock" bl_label = "Unlock Texture" bl_description = "Unlock Texture" bl_options = {'REGISTER', 'UNDO'} - connect: BoolProperty( + connect = BoolProperty( name="Connect UV", default=True ) @@ -392,7 +392,7 @@ class MUV_OT_TextureLock_Intr(bpy.types.Operator): Operation class: Texture Lock (Interactive mode) """ - bl_idname = "uv.muv_texture_lock_operator_intr" + bl_idname = "uv.muv_ot_texture_lock_intr" bl_label = "Texture Lock (Interactive mode)" bl_description = "Internal operation for Texture Lock (Interactive mode)" diff --git a/uv_magic_uv/op/texture_projection.py b/uv_magic_uv/op/texture_projection.py index e807caee..b14e84b9 100644 --- a/uv_magic_uv/op/texture_projection.py +++ b/uv_magic_uv/op/texture_projection.py @@ -50,18 +50,19 @@ _Rect = namedtuple('Rect', 'x0 y0 x1 y1') _Rect2 = namedtuple('Rect2', 'x y width height') -def get_loaded_texture_name(_, __): +def _get_loaded_texture_name(_, __): items = [(key, key, "") for key in bpy.data.images.keys()] items.append(("None", "None", "")) return items -def get_canvas(context, magnitude): +def _get_canvas(context, magnitude): """ Get canvas to be renderred texture """ sc = context.scene - prefs = compat.get_user_preferences(context).addons["uv_magic_uv"].preferences + user_prefs = compat.get_user_preferences(context) + prefs = user_prefs.addons["uv_magic_uv"].preferences region_w = context.region.width region_h = context.region.height @@ -101,7 +102,7 @@ def get_canvas(context, magnitude): return _Rect(x0, y0, x1, y1) -def rect_to_rect2(rect): +def _rect_to_rect2(rect): """ Convert Rect1 to Rect2 """ @@ -109,12 +110,12 @@ def rect_to_rect2(rect): return _Rect2(rect.x0, rect.y0, rect.x1 - rect.x0, rect.y1 - rect.y0) -def region_to_canvas(rg_vec, canvas): +def _region_to_canvas(rg_vec, canvas): """ Convert screen region to canvas """ - cv_rect = rect_to_rect2(canvas) + cv_rect = _rect_to_rect2(canvas) cv_vec = mathutils.Vector() cv_vec.x = (rg_vec.x - cv_rect.x) / cv_rect.width cv_vec.y = (rg_vec.y - cv_rect.y) / cv_rect.height @@ -122,7 +123,7 @@ def region_to_canvas(rg_vec, canvas): return cv_vec -def is_valid_context(context): +def _is_valid_context(context): obj = context.object # only edit mode is allowed to execute @@ -156,14 +157,14 @@ class _Properties: pass def update_func(_, __): - bpy.ops.uv.muv_texture_projection_operator('INVOKE_REGION_WIN') + bpy.ops.uv.muv_ot_texture_projection('INVOKE_REGION_WIN') - scene.muv_texture_projection_enabled: BoolProperty( + scene.muv_texture_projection_enabled = BoolProperty( name="Texture Projection Enabled", description="Texture Projection is enabled", default=False ) - scene.muv_texture_projection_enable: BoolProperty( + scene.muv_texture_projection_enable = BoolProperty( name="Texture Projection Enabled", description="Texture Projection is enabled", default=False, @@ -171,36 +172,36 @@ class _Properties: set=set_func, update=update_func ) - scene.muv_texture_projection_tex_magnitude: FloatProperty( + scene.muv_texture_projection_tex_magnitude = FloatProperty( name="Magnitude", description="Texture Magnitude", default=0.5, min=0.0, max=100.0 ) - scene.muv_texture_projection_tex_image: EnumProperty( + scene.muv_texture_projection_tex_image = EnumProperty( name="Image", description="Texture Image", - items=get_loaded_texture_name + items=_get_loaded_texture_name ) - scene.muv_texture_projection_tex_transparency: FloatProperty( + scene.muv_texture_projection_tex_transparency = FloatProperty( name="Transparency", description="Texture Transparency", default=0.2, min=0.0, max=1.0 ) - scene.muv_texture_projection_adjust_window: BoolProperty( + scene.muv_texture_projection_adjust_window = BoolProperty( name="Adjust Window", description="Size of renderered texture is fitted to window", default=True ) - scene.muv_texture_projection_apply_tex_aspect: BoolProperty( + scene.muv_texture_projection_apply_tex_aspect = BoolProperty( name="Texture Aspect Ratio", description="Apply Texture Aspect ratio to displayed texture", default=True ) - scene.muv_texture_projection_assign_uvmap: BoolProperty( + scene.muv_texture_projection_assign_uvmap = BoolProperty( name="Assign UVMap", description="Assign UVMap when no UVmaps are available", default=True @@ -224,7 +225,7 @@ class MUV_OT_TextureProjection(bpy.types.Operator): Render texture """ - bl_idname = "uv.muv_texture_projection_operator" + bl_idname = "uv.muv_ot_texture_projection" bl_description = "Render selected texture" bl_label = "Texture renderer" @@ -235,7 +236,7 @@ class MUV_OT_TextureProjection(bpy.types.Operator): # we can not get area/space/region from console if common.is_console_mode(): return False - return is_valid_context(context) + return _is_valid_context(context) @classmethod def is_running(cls, _): @@ -268,7 +269,7 @@ class MUV_OT_TextureProjection(bpy.types.Operator): img = bpy.data.images[sc.muv_texture_projection_tex_image] # setup rendering region - rect = get_canvas(context, sc.muv_texture_projection_tex_magnitude) + rect = _get_canvas(context, sc.muv_texture_projection_tex_magnitude) positions = [ [rect.x0, rect.y0], [rect.x0, rect.y1], @@ -296,10 +297,10 @@ class MUV_OT_TextureProjection(bpy.types.Operator): if img.bindcode: bind = img.bindcode[0] bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind) - bgl.glTexParameteri( - bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR) - bgl.glTexParameteri( - bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR) + bgl.glTexParameteri(bgl.GL_TEXTURE_2D, + bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR) + bgl.glTexParameteri(bgl.GL_TEXTURE_2D, + bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR) bgl.glTexEnvi( bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE) @@ -307,7 +308,7 @@ class MUV_OT_TextureProjection(bpy.types.Operator): # render texture bgl.glBegin(bgl.GL_QUADS) bgl.glColor4f(1.0, 1.0, 1.0, - sc.muv_texture_projection_tex_transparency) + sc.muv_texture_projection_tex_transparency) for (v1, v2), (u, v) in zip(positions, tex_coords): bgl.glTexCoord2f(u, v) bgl.glVertex2f(v1, v2) @@ -331,7 +332,7 @@ class MUV_OT_TextureProjection_Project(bpy.types.Operator): Operation class: Project texture """ - bl_idname = "uv.muv_texture_projection_operator_project" + bl_idname = "uv.muv_ot_texture_projection_project" bl_label = "Project Texture" bl_description = "Project Texture" bl_options = {'REGISTER', 'UNDO'} @@ -343,7 +344,7 @@ class MUV_OT_TextureProjection_Project(bpy.types.Operator): return True if not MUV_OT_TextureProjection.is_running(context): return False - return is_valid_context(context) + return _is_valid_context(context) def execute(self, context): sc = context.scene @@ -387,17 +388,18 @@ class MUV_OT_TextureProjection_Project(bpy.types.Operator): # transform screen region to canvas v_canvas = [ - region_to_canvas( + _region_to_canvas( v, - get_canvas(bpy.context, - sc.muv_texture_projection_tex_magnitude) + _get_canvas(bpy.context, + sc.muv_texture_projection_tex_magnitude) ) for v in v_screen ] if compat.check_version(2, 80, 0) >= 0: # set texture nodes = common.find_texture_nodes(obj) - nodes[0].image = bpy.data.images[sc.muv_texture_projection_tex_image] + nodes[0].image = \ + bpy.data.images[sc.muv_texture_projection_tex_image] # project texture to object i = 0 diff --git a/uv_magic_uv/op/texture_wrap.py b/uv_magic_uv/op/texture_wrap.py index 2b4d5c2b..a0af5830 100644 --- a/uv_magic_uv/op/texture_wrap.py +++ b/uv_magic_uv/op/texture_wrap.py @@ -67,17 +67,17 @@ class _Properties: scene.muv_props.texture_wrap = Props() - scene.muv_texture_wrap_enabled: BoolProperty( + scene.muv_texture_wrap_enabled = BoolProperty( name="Texture Wrap", description="Texture Wrap is enabled", default=False ) - scene.muv_texture_wrap_set_and_refer: BoolProperty( + scene.muv_texture_wrap_set_and_refer = BoolProperty( name="Set and Refer", description="Refer and set UV", default=True ) - scene.muv_texture_wrap_selseq: BoolProperty( + scene.muv_texture_wrap_selseq = BoolProperty( name="Selection Sequence", description="Set UV sequentially", default=False @@ -97,7 +97,7 @@ class MUV_OT_TextureWrap_Refer(bpy.types.Operator): Operation class: Refer UV """ - bl_idname = "uv.muv_texture_wrap_operator_refer" + bl_idname = "uv.muv_ot_texture_wrap_refer" bl_label = "Refer" bl_description = "Refer UV" bl_options = {'REGISTER', 'UNDO'} @@ -137,7 +137,7 @@ class MUV_OT_TextureWrap_Set(bpy.types.Operator): Operation class: Set UV """ - bl_idname = "uv.muv_texture_wrap_operator_set" + bl_idname = "uv.muv_ot_texture_wrap_set" bl_label = "Set" bl_description = "Set UV" bl_options = {'REGISTER', 'UNDO'} diff --git a/uv_magic_uv/op/transfer_uv.py b/uv_magic_uv/op/transfer_uv.py index 079308ea..baad4dba 100644 --- a/uv_magic_uv/op/transfer_uv.py +++ b/uv_magic_uv/op/transfer_uv.py @@ -333,17 +333,17 @@ class _Properties: scene.muv_props.transfer_uv = Props() - scene.muv_transfer_uv_enabled: BoolProperty( + scene.muv_transfer_uv_enabled = BoolProperty( name="Transfer UV Enabled", description="Transfer UV is enabled", default=False ) - scene.muv_transfer_uv_invert_normals: BoolProperty( + scene.muv_transfer_uv_invert_normals = BoolProperty( name="Invert Normals", description="Invert Normals", default=False ) - scene.muv_transfer_uv_copy_seams: BoolProperty( + scene.muv_transfer_uv_copy_seams = BoolProperty( name="Copy Seams", description="Copy Seams", default=True @@ -363,7 +363,7 @@ class MUV_OT_TransferUV_CopyUV(bpy.types.Operator): Topological based copy """ - bl_idname = "uv.muv_transfer_uv_operator_copy_uv" + bl_idname = "uv.muv_ot_transfer_uv_copy_uv" bl_label = "Transfer UV Copy UV" bl_description = "Transfer UV Copy UV (Topological based copy)" bl_options = {'REGISTER', 'UNDO'} @@ -377,7 +377,7 @@ class MUV_OT_TransferUV_CopyUV(bpy.types.Operator): def execute(self, context): props = context.scene.muv_props.transfer_uv - active_obj = compat.get_active_object(context) + active_obj = context.active_object bm = bmesh.from_edit_mesh(active_obj.data) if compat.check_version(2, 73, 0) >= 0: bm.faces.ensure_lookup_table() @@ -404,17 +404,17 @@ class MUV_OT_TransferUV_PasteUV(bpy.types.Operator): Topological based paste """ - bl_idname = "uv.muv_transfer_uv_operator_paste_uv" + bl_idname = "uv.muv_ot_transfer_uv_paste_uv" bl_label = "Transfer UV Paste UV" bl_description = "Transfer UV Paste UV (Topological based paste)" bl_options = {'REGISTER', 'UNDO'} - invert_normals: BoolProperty( + invert_normals = BoolProperty( name="Invert Normals", description="Invert Normals", default=False ) - copy_seams: BoolProperty( + copy_seams = BoolProperty( name="Copy Seams", description="Copy Seams", default=True @@ -433,7 +433,7 @@ class MUV_OT_TransferUV_PasteUV(bpy.types.Operator): def execute(self, context): props = context.scene.muv_props.transfer_uv - active_obj = compat.get_active_object(context) + active_obj = context.active_object bm = bmesh.from_edit_mesh(active_obj.data) if compat.check_version(2, 73, 0) >= 0: bm.faces.ensure_lookup_table() diff --git a/uv_magic_uv/op/unwrap_constraint.py b/uv_magic_uv/op/unwrap_constraint.py index 62b829cf..ac157b28 100644 --- a/uv_magic_uv/op/unwrap_constraint.py +++ b/uv_magic_uv/op/unwrap_constraint.py @@ -62,17 +62,17 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_unwrap_constraint_enabled: BoolProperty( + scene.muv_unwrap_constraint_enabled = BoolProperty( name="Unwrap Constraint Enabled", description="Unwrap Constraint is enabled", default=False ) - scene.muv_unwrap_constraint_u_const: BoolProperty( + scene.muv_unwrap_constraint_u_const = BoolProperty( name="U-Constraint", description="Keep UV U-axis coordinate", default=False ) - scene.muv_unwrap_constraint_v_const: BoolProperty( + scene.muv_unwrap_constraint_v_const = BoolProperty( name="V-Constraint", description="Keep UV V-axis coordinate", default=False @@ -92,13 +92,13 @@ class MUV_OT_UnwrapConstraint(bpy.types.Operator): Operation class: Unwrap with constrain UV coordinate """ - bl_idname = "uv.muv_unwrap_constraint_operator" + bl_idname = "uv.muv_ot_unwrap_constraint" bl_label = "Unwrap Constraint" bl_description = "Unwrap while keeping uv coordinate" bl_options = {'REGISTER', 'UNDO'} # property for original unwrap - method: EnumProperty( + method = EnumProperty( name="Method", description="Unwrapping method", items=[ @@ -106,20 +106,20 @@ class MUV_OT_UnwrapConstraint(bpy.types.Operator): ('CONFORMAL', 'Conformal', 'Conformal') ], default='ANGLE_BASED') - fill_holes: BoolProperty( + fill_holes = BoolProperty( name="Fill Holes", description="Virtual fill holes in meshes before unwrapping", default=True) - correct_aspect: BoolProperty( + correct_aspect = BoolProperty( name="Correct Aspect", description="Map UVs taking image aspect ratio into account", default=True) - use_subsurf_data: BoolProperty( + use_subsurf_data = BoolProperty( name="Use Subsurf Modifier", description="""Map UVs taking vertex position after subsurf into account""", default=False) - margin: FloatProperty( + margin = FloatProperty( name="Margin", description="Space between islands", max=1.0, @@ -127,12 +127,12 @@ class MUV_OT_UnwrapConstraint(bpy.types.Operator): default=0.001) # property for this operation - u_const: BoolProperty( + u_const = BoolProperty( name="U-Constraint", description="Keep UV U-axis coordinate", default=False ) - v_const: BoolProperty( + v_const = BoolProperty( name="V-Constraint", description="Keep UV V-axis coordinate", default=False diff --git a/uv_magic_uv/op/uv_bounding_box.py b/uv_magic_uv/op/uv_bounding_box.py index be687b54..a4645325 100644 --- a/uv_magic_uv/op/uv_bounding_box.py +++ b/uv_magic_uv/op/uv_bounding_box.py @@ -88,14 +88,14 @@ class _Properties: pass def update_func(_, __): - bpy.ops.uv.muv_uv_bounding_box_operator('INVOKE_REGION_WIN') + bpy.ops.uv.muv_ot_uv_bounding_box('INVOKE_REGION_WIN') - scene.muv_uv_bounding_box_enabled: BoolProperty( + scene.muv_uv_bounding_box_enabled = BoolProperty( name="UV Bounding Box Enabled", description="UV Bounding Box is enabled", default=False ) - scene.muv_uv_bounding_box_show: BoolProperty( + scene.muv_uv_bounding_box_show = BoolProperty( name="UV Bounding Box Showed", description="UV Bounding Box is showed", default=False, @@ -103,12 +103,12 @@ class _Properties: set=set_func, update=update_func ) - scene.muv_uv_bounding_box_uniform_scaling: BoolProperty( + scene.muv_uv_bounding_box_uniform_scaling = BoolProperty( name="Uniform Scaling", description="Enable Uniform Scaling", default=False ) - scene.muv_uv_bounding_box_boundary: EnumProperty( + scene.muv_uv_bounding_box_boundary = EnumProperty( name="Boundary", description="Boundary", default='UV_SEL', @@ -243,7 +243,7 @@ class ScalingCommand(CommandBase): if self.__dir_y == 1: ms[1][1] = (ty - toy) * self.__dir_y / (tiy - toy) return compat.matmul(compat.matmul(compat.matmul( - compat.matmul(mi, mto), ms), mtoi), m) + compat.matmul(mi, mto), ms), mtoi), m) def set(self, x, y): self.__x = x @@ -308,7 +308,7 @@ class UniformScalingCommand(CommandBase): ms[1][1] = sr * self.__dir_y return compat.matmul(compat.matmul(compat.matmul( - compat.matmul(mi, mto), ms), mtoi), m) + compat.matmul(mi, mto), ms), mtoi), m) def set(self, x, y): self.__x = x @@ -429,7 +429,8 @@ class StateNone(StateBase): """ Update state """ - prefs = compat.get_user_preferences(context).addons["uv_magic_uv"].preferences + user_prefs = compat.get_user_preferences(context) + prefs = user_prefs.addons["uv_magic_uv"].preferences cp_react_size = prefs.uv_bounding_box_cp_react_size is_uscaling = context.scene.muv_uv_bounding_box_uniform_scaling if (event.type == 'LEFTMOUSE') and (event.value == 'PRESS'): @@ -611,7 +612,7 @@ class MUV_OT_UVBoundingBox(bpy.types.Operator): Operation class: UV Bounding Box """ - bl_idname = "uv.muv_uv_bounding_box_operator" + bl_idname = "uv.muv_ot_uv_bounding_box" bl_label = "UV Bounding Box" bl_description = "Internal operation for UV Bounding Box" bl_options = {'REGISTER', 'UNDO'} @@ -661,7 +662,8 @@ class MUV_OT_UVBoundingBox(bpy.types.Operator): """ Draw control point """ - prefs = compat.get_user_preferences(context).addons["uv_magic_uv"].preferences + user_prefs = compat.get_user_preferences(context) + prefs = user_prefs.addons["uv_magic_uv"].preferences cp_size = prefs.uv_bounding_box_cp_size offset = cp_size / 2 verts = [ diff --git a/uv_magic_uv/op/uv_inspection.py b/uv_magic_uv/op/uv_inspection.py index b7868978..461695b5 100644 --- a/uv_magic_uv/op/uv_inspection.py +++ b/uv_magic_uv/op/uv_inspection.py @@ -99,14 +99,14 @@ class _Properties: pass def update_func(_, __): - bpy.ops.uv.muv_uv_inspection_operator_render('INVOKE_REGION_WIN') + bpy.ops.uv.muv_ot_uv_inspection_render('INVOKE_REGION_WIN') - scene.muv_uv_inspection_enabled: BoolProperty( + scene.muv_uv_inspection_enabled = BoolProperty( name="UV Inspection Enabled", description="UV Inspection is enabled", default=False ) - scene.muv_uv_inspection_show: BoolProperty( + scene.muv_uv_inspection_show = BoolProperty( name="UV Inspection Showed", description="UV Inspection is showed", default=False, @@ -114,17 +114,17 @@ class _Properties: set=set_func, update=update_func ) - scene.muv_uv_inspection_show_overlapped: BoolProperty( + scene.muv_uv_inspection_show_overlapped = BoolProperty( name="Overlapped", description="Show overlapped UVs", default=False ) - scene.muv_uv_inspection_show_flipped: BoolProperty( + scene.muv_uv_inspection_show_flipped = BoolProperty( name="Flipped", description="Show flipped UVs", default=False ) - scene.muv_uv_inspection_show_mode: EnumProperty( + scene.muv_uv_inspection_show_mode = EnumProperty( name="Mode", description="Show mode", items=[ @@ -151,7 +151,7 @@ class MUV_OT_UVInspection_Render(bpy.types.Operator): No operation (only rendering) """ - bl_idname = "uv.muv_uv_inspection_operator_render" + bl_idname = "uv.muv_ot_uv_inspection_render" bl_description = "Render overlapped/flipped UVs" bl_label = "Overlapped/Flipped UV renderer" @@ -186,7 +186,8 @@ class MUV_OT_UVInspection_Render(bpy.types.Operator): def draw(_, context): sc = context.scene props = sc.muv_props.uv_inspection - prefs = compat.get_user_preferences(context).addons["uv_magic_uv"].preferences + user_prefs = compat.get_user_preferences(context) + prefs = user_prefs.addons["uv_magic_uv"].preferences if not MUV_OT_UVInspection_Render.is_running(context): return @@ -257,7 +258,7 @@ class MUV_OT_UVInspection_Update(bpy.types.Operator): Operation class: Update """ - bl_idname = "uv.muv_uv_inspection_operator_update" + bl_idname = "uv.muv_ot_uv_inspection_update" bl_label = "Update UV Inspection" bl_description = "Update UV Inspection" bl_options = {'REGISTER', 'UNDO'} diff --git a/uv_magic_uv/op/uv_sculpt.py b/uv_magic_uv/op/uv_sculpt.py index 0de6df97..923cb7f0 100644 --- a/uv_magic_uv/op/uv_sculpt.py +++ b/uv_magic_uv/op/uv_sculpt.py @@ -96,14 +96,14 @@ class _Properties: pass def update_func(_, __): - bpy.ops.uv.muv_uv_sculpt_operator('INVOKE_REGION_WIN') + bpy.ops.uv.muv_ot_uv_sculpt('INVOKE_REGION_WIN') - scene.muv_uv_sculpt_enabled: BoolProperty( + scene.muv_uv_sculpt_enabled = BoolProperty( name="UV Sculpt", description="UV Sculpt is enabled", default=False ) - scene.muv_uv_sculpt_enable: BoolProperty( + scene.muv_uv_sculpt_enable = BoolProperty( name="UV Sculpt Showed", description="UV Sculpt is enabled", default=False, @@ -111,21 +111,21 @@ class _Properties: set=set_func, update=update_func ) - scene.muv_uv_sculpt_radius: IntProperty( + scene.muv_uv_sculpt_radius = IntProperty( name="Radius", description="Radius of the brush", min=1, max=500, default=30 ) - scene.muv_uv_sculpt_strength: FloatProperty( + scene.muv_uv_sculpt_strength = FloatProperty( name="Strength", description="How powerful the effect of the brush when applied", min=0.0, max=1.0, default=0.03, ) - scene.muv_uv_sculpt_tools: EnumProperty( + scene.muv_uv_sculpt_tools = EnumProperty( name="Tools", description="Select Tools for the UV sculpt brushes", items=[ @@ -135,17 +135,17 @@ class _Properties: ], default='GRAB' ) - scene.muv_uv_sculpt_show_brush: BoolProperty( + scene.muv_uv_sculpt_show_brush = BoolProperty( name="Show Brush", description="Show Brush", default=True ) - scene.muv_uv_sculpt_pinch_invert: BoolProperty( + scene.muv_uv_sculpt_pinch_invert = BoolProperty( name="Invert", description="Pinch UV to invert direction", default=False ) - scene.muv_uv_sculpt_relax_method: EnumProperty( + scene.muv_uv_sculpt_relax_method = EnumProperty( name="Method", description="Algorithm used for relaxation", items=[ @@ -174,7 +174,7 @@ class MUV_OT_UVSculpt(bpy.types.Operator): Operation class: UV Sculpt in View3D """ - bl_idname = "uv.muv_uv_sculpt_operator" + bl_idname = "uv.muv_ot_uv_sculpt" bl_label = "UV Sculpt" bl_description = "UV Sculpt in View3D" bl_options = {'REGISTER'} @@ -217,7 +217,8 @@ class MUV_OT_UVSculpt(bpy.types.Operator): @classmethod def draw_brush(cls, obj, context): sc = context.scene - prefs = compat.get_user_preferences(context).addons["uv_magic_uv"].preferences + user_prefs = compat.get_user_preferences(context) + prefs = user_prefs.addons["uv_magic_uv"].preferences num_segment = 180 theta = 2 * pi / num_segment diff --git a/uv_magic_uv/op/uvw.py b/uv_magic_uv/op/uvw.py index 28011777..fe628bb3 100644 --- a/uv_magic_uv/op/uvw.py +++ b/uv_magic_uv/op/uvw.py @@ -155,11 +155,7 @@ def _apply_planer_map(bm, uv_layer, size, offset, rotation, tex_aspect): # update UV coordinate for f in sel_faces: for l in f.loops: - if common.check_version(2, 80, 0) >= 0: - # pylint: disable=E0001 - co = q @ l.vert.co - else: - co = q * l.vert.co + co = compat.matmul(q, l.vert.co) x = co.x * sx y = co.y * sy @@ -175,12 +171,12 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_uvw_enabled: BoolProperty( + scene.muv_uvw_enabled = BoolProperty( name="UVW Enabled", description="UVW is enabled", default=False ) - scene.muv_uvw_assign_uvmap: BoolProperty( + scene.muv_uvw_assign_uvmap = BoolProperty( name="Assign UVMap", description="Assign UVMap when no UVmaps are available", default=True @@ -195,31 +191,31 @@ class _Properties: @BlClassRegistry() @compat.make_annotations class MUV_OT_UVW_BoxMap(bpy.types.Operator): - bl_idname = "uv.muv_uvw_operator_box_map" + bl_idname = "uv.muv_ot_uvw_box_map" bl_label = "Box Map" bl_options = {'REGISTER', 'UNDO'} - size: FloatProperty( + size = FloatProperty( name="Size", default=1.0, precision=4 ) - rotation: FloatVectorProperty( + rotation = FloatVectorProperty( name="XYZ Rotation", size=3, default=(0.0, 0.0, 0.0) ) - offset: FloatVectorProperty( + offset = FloatVectorProperty( name="XYZ Offset", size=3, default=(0.0, 0.0, 0.0) ) - tex_aspect: FloatProperty( + tex_aspect = FloatProperty( name="Texture Aspect", default=1.0, precision=4 ) - assign_uvmap: BoolProperty( + assign_uvmap = BoolProperty( name="Assign UVMap", description="Assign UVMap when no UVmaps are available", default=True @@ -253,30 +249,30 @@ class MUV_OT_UVW_BoxMap(bpy.types.Operator): @BlClassRegistry() @compat.make_annotations class MUV_OT_UVW_BestPlanerMap(bpy.types.Operator): - bl_idname = "uv.muv_uvw_operator_best_planer_map" + bl_idname = "uv.muv_ot_uvw_best_planer_map" bl_label = "Best Planer Map" bl_options = {'REGISTER', 'UNDO'} - size: FloatProperty( + size = FloatProperty( name="Size", default=1.0, precision=4 ) - rotation: FloatProperty( + rotation = FloatProperty( name="XY Rotation", default=0.0 ) - offset: FloatVectorProperty( + offset = FloatVectorProperty( name="XY Offset", size=2, default=(0.0, 0.0) ) - tex_aspect: FloatProperty( + tex_aspect = FloatProperty( name="Texture Aspect", default=1.0, precision=4 ) - assign_uvmap: BoolProperty( + assign_uvmap = BoolProperty( name="Assign UVMap", description="Assign UVMap when no UVmaps are available", default=True diff --git a/uv_magic_uv/op/world_scale_uv.py b/uv_magic_uv/op/world_scale_uv.py index f060dad8..ef821633 100644 --- a/uv_magic_uv/op/world_scale_uv.py +++ b/uv_magic_uv/op/world_scale_uv.py @@ -183,36 +183,36 @@ class _Properties: @classmethod def init_props(cls, scene): - scene.muv_world_scale_uv_enabled: BoolProperty( + scene.muv_world_scale_uv_enabled = BoolProperty( name="World Scale UV Enabled", description="World Scale UV is enabled", default=False ) - scene.muv_world_scale_uv_src_mesh_area: FloatProperty( + scene.muv_world_scale_uv_src_mesh_area = FloatProperty( name="Mesh Area", description="Source Mesh Area", default=0.0, min=0.0 ) - scene.muv_world_scale_uv_src_uv_area: FloatProperty( + scene.muv_world_scale_uv_src_uv_area = FloatProperty( name="UV Area", description="Source UV Area", default=0.0, min=0.0 ) - scene.muv_world_scale_uv_src_density: FloatProperty( + scene.muv_world_scale_uv_src_density = FloatProperty( name="Density", description="Source Texel Density", default=0.0, min=0.0 ) - scene.muv_world_scale_uv_tgt_density: FloatProperty( + scene.muv_world_scale_uv_tgt_density = FloatProperty( name="Density", description="Target Texel Density", default=0.0, min=0.0 ) - scene.muv_world_scale_uv_tgt_scaling_factor: FloatProperty( + scene.muv_world_scale_uv_tgt_scaling_factor = FloatProperty( name="Scaling Factor", default=1.0, max=1000.0, @@ -225,7 +225,7 @@ class _Properties: soft_max=10240, default=(1024, 1024), ) - scene.muv_world_scale_uv_mode: EnumProperty( + scene.muv_world_scale_uv_mode = EnumProperty( name="Mode", description="Density calculation mode", items=[ @@ -239,7 +239,7 @@ class _Properties: ], default='MANUAL' ) - scene.muv_world_scale_uv_origin: EnumProperty( + scene.muv_world_scale_uv_origin = EnumProperty( name="Origin", description="Aspect Origin", items=[ @@ -275,7 +275,7 @@ class MUV_OT_WorldScaleUV_Measure(bpy.types.Operator): Operation class: Measure face size """ - bl_idname = "uv.muv_world_scale_uv_operator_measure" + bl_idname = "uv.muv_ot_world_scale_uv_measure" bl_label = "Measure World Scale UV" bl_description = "Measure face size for scale calculation" bl_options = {'REGISTER', 'UNDO'} @@ -301,8 +301,9 @@ class MUV_OT_WorldScaleUV_Measure(bpy.types.Operator): sc.muv_world_scale_uv_src_mesh_area = mesh_area sc.muv_world_scale_uv_src_density = density - self.report({'INFO'}, "UV Area: {0}, Mesh Area: {1}, Texel Density: {2}" - .format(uv_area, mesh_area, density)) + self.report({'INFO'}, + "UV Area: {0}, Mesh Area: {1}, Texel Density: {2}" + .format(uv_area, mesh_area, density)) return {'FINISHED'} @@ -314,12 +315,12 @@ class MUV_OT_WorldScaleUV_ApplyManual(bpy.types.Operator): Operation class: Apply scaled UV (Manual) """ - bl_idname = "uv.muv_world_scale_uv_operator_apply_manual" + bl_idname = "uv.muv_ot_world_scale_uv_apply_manual" bl_label = "Apply World Scale UV (Manual)" bl_description = "Apply scaled UV based on user specification" bl_options = {'REGISTER', 'UNDO'} - tgt_density: FloatProperty( + tgt_density = FloatProperty( name="Density", description="Target Texel Density", default=1.0, @@ -332,7 +333,7 @@ class MUV_OT_WorldScaleUV_ApplyManual(bpy.types.Operator): soft_max=10240, default=(1024, 1024), ) - origin: EnumProperty( + origin = EnumProperty( name="Origin", description="Aspect Origin", items=[ @@ -349,7 +350,7 @@ class MUV_OT_WorldScaleUV_ApplyManual(bpy.types.Operator): ], default='CENTER' ) - show_dialog: BoolProperty( + show_dialog = BoolProperty( name="Show Diaglog Menu", description="Show dialog menu if true", default=True, @@ -412,18 +413,18 @@ class MUV_OT_WorldScaleUV_ApplyScalingDensity(bpy.types.Operator): Operation class: Apply scaled UV (Scaling Density) """ - bl_idname = "uv.muv_world_scale_uv_operator_apply_scaling_density" + bl_idname = "uv.muv_ot_world_scale_uv_apply_scaling_density" bl_label = "Apply World Scale UV (Scaling Density)" bl_description = "Apply scaled UV with scaling density" bl_options = {'REGISTER', 'UNDO'} - tgt_scaling_factor: FloatProperty( + tgt_scaling_factor = FloatProperty( name="Scaling Factor", default=1.0, max=1000.0, min=0.00001 ) - origin: EnumProperty( + origin = EnumProperty( name="Origin", description="Aspect Origin", items=[ @@ -440,20 +441,20 @@ class MUV_OT_WorldScaleUV_ApplyScalingDensity(bpy.types.Operator): ], default='CENTER' ) - src_density: FloatProperty( + src_density = FloatProperty( name="Density", description="Source Texel Density", default=0.0, min=0.0, options={'HIDDEN'} ) - same_density: BoolProperty( + same_density = BoolProperty( name="Same Density", description="Apply same density", default=False, options={'HIDDEN'} ) - show_dialog: BoolProperty( + show_dialog = BoolProperty( name="Show Diaglog Menu", description="Show dialog menu if true", default=True, @@ -536,12 +537,12 @@ class MUV_OT_WorldScaleUV_ApplyProportionalToMesh(bpy.types.Operator): Operation class: Apply scaled UV (Proportional to mesh) """ - bl_idname = "uv.muv_world_scale_uv_operator_apply_proportional_to_mesh" + bl_idname = "uv.muv_ot_world_scale_uv_apply_proportional_to_mesh" bl_label = "Apply World Scale UV (Proportional to mesh)" bl_description = "Apply scaled UV proportionaled to mesh" bl_options = {'REGISTER', 'UNDO'} - origin: EnumProperty( + origin = EnumProperty( name="Origin", description="Aspect Origin", items=[ @@ -558,28 +559,28 @@ class MUV_OT_WorldScaleUV_ApplyProportionalToMesh(bpy.types.Operator): ], default='CENTER' ) - src_density: FloatProperty( + src_density = FloatProperty( name="Source Density", description="Source Texel Density", default=0.0, min=0.0, options={'HIDDEN'} ) - src_uv_area: FloatProperty( + src_uv_area = FloatProperty( name="Source UV Area", description="Source UV Area", default=0.0, min=0.0, options={'HIDDEN'} ) - src_mesh_area: FloatProperty( + src_mesh_area = FloatProperty( name="Source Mesh Area", description="Source Mesh Area", default=0.0, min=0.0, options={'HIDDEN'} ) - show_dialog: BoolProperty( + show_dialog = BoolProperty( name="Show Diaglog Menu", description="Show dialog menu if true", default=True, diff --git a/uv_magic_uv/preferences.py b/uv_magic_uv/preferences.py index 19715044..cfe3f4d7 100644 --- a/uv_magic_uv/preferences.py +++ b/uv_magic_uv/preferences.py @@ -29,15 +29,38 @@ from bpy.props import ( FloatVectorProperty, BoolProperty, EnumProperty, - StringProperty, ) from bpy.types import AddonPreferences -from . import op -from . import ui +from . import common +from .op.flip_rotate_uv import MUV_OT_FlipRotate +from .op.mirror_uv import MUV_OT_MirrorUV +from .op.move_uv import MUV_OT_MoveUV +from .op.unwrap_constraint import MUV_OT_UnwrapConstraint +from .op.pack_uv import MUV_OT_PackUV +from .op.smooth_uv import MUV_OT_SmoothUV +from .ui.VIEW3D_MT_uv_map import ( + MUV_MT_CopyPasteUV, + MUV_MT_TransferUV, + MUV_MT_WorldScaleUV, + MUV_MT_PreserveUVAspect, + MUV_MT_TextureLock, + MUV_MT_TextureWrap, + MUV_MT_TextureProjection, + MUV_MT_UVW, +) +from .ui.VIEW3D_MT_object import MUV_MT_CopyPasteUV_Object +from .ui.IMAGE_MT_uvs import ( + MUV_MT_CopyPasteUV_UVEdit, + MUV_MT_SelectUV, + MUV_MT_AlignUV, + MUV_MT_AlignUVCursor, + MUV_MT_UVInspection, +) from .utils.bl_class_registry import BlClassRegistry from .utils.addon_updator import AddonUpdatorManager from .utils import compatibility as compat +from . import updater def view3d_uvmap_menu_fn(self, context): @@ -47,52 +70,42 @@ def view3d_uvmap_menu_fn(self, context): layout.separator() layout.label(text="Copy/Paste UV", icon=compat.icon('IMAGE')) # Copy/Paste UV - layout.menu(ui.VIEW3D_MT_uv_map.MUV_MT_CopyPasteUV.bl_idname, - text="Copy/Paste UV") + layout.menu(MUV_MT_CopyPasteUV.bl_idname, text="Copy/Paste UV") # Transfer UV - layout.menu(ui.VIEW3D_MT_uv_map.MUV_MT_TransferUV.bl_idname, - text="Transfer UV") + layout.menu(MUV_MT_TransferUV.bl_idname, text="Transfer UV") layout.separator() layout.label(text="UV Manipulation", icon=compat.icon('IMAGE')) # Flip/Rotate UV - ops = layout.operator(op.flip_rotate_uv.MUV_OT_FlipRotate.bl_idname, - text="Flip/Rotate UV") + ops = layout.operator(MUV_OT_FlipRotate.bl_idname, text="Flip/Rotate UV") ops.seams = sc.muv_flip_rotate_uv_seams # Mirror UV - ops = layout.operator(op.mirror_uv.MUV_OT_MirrorUV.bl_idname, - text="Mirror UV") + ops = layout.operator(MUV_OT_MirrorUV.bl_idname, text="Mirror UV") ops.axis = sc.muv_mirror_uv_axis # Move UV - layout.operator(op.move_uv.MUV_OT_MoveUV.bl_idname, text="Move UV") + layout.operator(MUV_OT_MoveUV.bl_idname, text="Move UV") # World Scale UV - layout.menu(ui.VIEW3D_MT_uv_map.MUV_MT_WorldScaleUV.bl_idname, - text="World Scale UV") + layout.menu(MUV_MT_WorldScaleUV.bl_idname, text="World Scale UV") # Preserve UV - layout.menu(ui.VIEW3D_MT_uv_map.MUV_MT_PreserveUVAspect.bl_idname, - text="Preserve UV") + layout.menu(MUV_MT_PreserveUVAspect.bl_idname, text="Preserve UV") # Texture Lock - layout.menu(ui.VIEW3D_MT_uv_map.MUV_MT_TextureLock.bl_idname, - text="Texture Lock") + layout.menu(MUV_MT_TextureLock.bl_idname, text="Texture Lock") # Texture Wrap - layout.menu(ui.VIEW3D_MT_uv_map.MUV_MT_TextureWrap.bl_idname, - text="Texture Wrap") + layout.menu(MUV_MT_TextureWrap.bl_idname, text="Texture Wrap") # UV Sculpt layout.prop(sc, "muv_uv_sculpt_enable", text="UV Sculpt") layout.separator() layout.label(text="UV Mapping", icon=compat.icon('IMAGE')) # Unwrap Constraint - ops = layout.operator( - op.unwrap_constraint.MUV_OT_UnwrapConstraint.bl_idname, - text="Unwrap Constraint") + ops = layout.operator(MUV_OT_UnwrapConstraint.bl_idname, + text="Unwrap Constraint") ops.u_const = sc.muv_unwrap_constraint_u_const ops.v_const = sc.muv_unwrap_constraint_v_const # Texture Projection - layout.menu(ui.VIEW3D_MT_uv_map.MUV_MT_TextureProjection.bl_idname, - text="Texture Projection") + layout.menu(MUV_MT_TextureProjection.bl_idname, text="Texture Projection") # UVW - layout.menu(ui.VIEW3D_MT_uv_map.MUV_MT_UVW.bl_idname, text="UVW") + layout.menu(MUV_MT_UVW.bl_idname, text="UVW") def view3d_object_menu_fn(self, _): @@ -101,8 +114,7 @@ def view3d_object_menu_fn(self, _): layout.separator() layout.label(text="Copy/Paste UV", icon=compat.icon('IMAGE')) # Copy/Paste UV (Among Object) - layout.menu(ui.VIEW3D_MT_object.MUV_MT_CopyPasteUV_Object.bl_idname, - text="Copy/Paste UV") + layout.menu(MUV_MT_CopyPasteUV_Object.bl_idname, text="Copy/Paste UV") def image_uvs_menu_fn(self, context): @@ -112,36 +124,32 @@ def image_uvs_menu_fn(self, context): layout.separator() # Copy/Paste UV (on UV/Image Editor) layout.label(text="Copy/Paste UV", icon=compat.icon('IMAGE')) - layout.menu(ui.IMAGE_MT_uvs.MUV_MT_CopyPasteUV_UVEdit.bl_idname, - text="Copy/Paste UV") + layout.menu(MUV_MT_CopyPasteUV_UVEdit.bl_idname, text="Copy/Paste UV") layout.separator() # Pack UV layout.label(text="UV Manipulation", icon=compat.icon('IMAGE')) - ops = layout.operator(op.pack_uv.MUV_OT_PackUV.bl_idname, text="Pack UV") + ops = layout.operator(MUV_OT_PackUV.bl_idname, text="Pack UV") ops.allowable_center_deviation = sc.muv_pack_uv_allowable_center_deviation ops.allowable_size_deviation = sc.muv_pack_uv_allowable_size_deviation # Select UV - layout.menu(ui.IMAGE_MT_uvs.MUV_MT_SelectUV.bl_idname, text="Select UV") + layout.menu(MUV_MT_SelectUV.bl_idname, text="Select UV") # Smooth UV - ops = layout.operator(op.smooth_uv.MUV_OT_SmoothUV.bl_idname, - text="Smooth") + ops = layout.operator(MUV_OT_SmoothUV.bl_idname, text="Smooth") ops.transmission = sc.muv_smooth_uv_transmission ops.select = sc.muv_smooth_uv_select ops.mesh_infl = sc.muv_smooth_uv_mesh_infl # Align UV - layout.menu(ui.IMAGE_MT_uvs.MUV_MT_AlignUV.bl_idname, text="Align UV") + layout.menu(MUV_MT_AlignUV.bl_idname, text="Align UV") layout.separator() # Align UV Cursor layout.label(text="Editor Enhancement", icon=compat.icon('IMAGE')) - layout.menu(ui.IMAGE_MT_uvs.MUV_MT_AlignUVCursor.bl_idname, - text="Align UV Cursor") + layout.menu(MUV_MT_AlignUVCursor.bl_idname, text="Align UV Cursor") # UV Bounding Box layout.prop(sc, "muv_uv_bounding_box_show", text="UV Bounding Box") # UV Inspection - layout.menu(ui.IMAGE_MT_uvs.MUV_MT_UVInspection.bl_idname, - text="UV Inspection") + layout.menu(MUV_MT_UVInspection.bl_idname, text="UV Inspection") def add_builtin_menu(): @@ -156,47 +164,25 @@ def remove_builtin_menu(): bpy.types.VIEW3D_MT_uv_map.remove(view3d_uvmap_menu_fn) -@BlClassRegistry() -class MUV_OT_CheckAddonUpdate(bpy.types.Operator): - bl_idname = "uv.muv_check_addon_update" - bl_label = "Check Update" - bl_description = "Check Add-on Update" - bl_options = {'REGISTER', 'UNDO'} - - def execute(self, context): - updater = AddonUpdatorManager.get_instance() - updater.check_update_candidate() - - return {'FINISHED'} - +def get_update_candidate_branches(_, __): + manager = AddonUpdatorManager.get_instance() + if not manager.candidate_checked(): + return [] -@BlClassRegistry() -@compat.make_annotations -class MUV_OT_UpdateAddon(bpy.types.Operator): - bl_idname = "uv.muv_update_addon" - bl_label = "Update" - bl_description = "Update Add-on" - bl_options = {'REGISTER', 'UNDO'} - - branch_name: StringProperty( - name="Branch Name", - description="Branch name to update", - default="", - ) + return [(name, name, "") for name in manager.get_candidate_branch_names()] - def execute(self, context): - updater = AddonUpdatorManager.get_instance() - updater.update(self.branch_name) - return {'FINISHED'} +def set_debug_mode(self, value): + self['enable_debug_mode'] = value -def get_update_candidate_branches(_, __): - updater = AddonUpdatorManager.get_instance() - if not updater.candidate_checked(): - return [] - - return [(name, name, "") for name in updater.get_candidate_branch_names()] +def get_debug_mode(self): + enabled = self.get('enable_debug_mode', False) + if enabled: + common.enable_debugg_mode() + else: + common.disable_debug_mode() + return enabled @BlClassRegistry() @@ -213,15 +199,24 @@ class Preferences(AddonPreferences): remove_builtin_menu() # enable to add features to built-in menu - enable_builtin_menu: BoolProperty( + enable_builtin_menu = BoolProperty( name="Built-in Menu", description="Enable built-in menu", default=True, update=update_enable_builtin_menu, ) + # enable debug mode + enable_debug_mode = BoolProperty( + name="Debug Mode", + description="Enable debugging mode", + default=False, + set=set_debug_mode, + get=get_debug_mode, + ) + # for UV Sculpt - uv_sculpt_brush_color: FloatVectorProperty( + uv_sculpt_brush_color = FloatVectorProperty( name="Color", description="Color", default=(1.0, 0.4, 0.4, 1.0), @@ -232,7 +227,7 @@ class Preferences(AddonPreferences): ) # for Overlapped UV - uv_inspection_overlapped_color: FloatVectorProperty( + uv_inspection_overlapped_color = FloatVectorProperty( name="Color", description="Color", default=(0.0, 0.0, 1.0, 0.3), @@ -243,7 +238,7 @@ class Preferences(AddonPreferences): ) # for Flipped UV - uv_inspection_flipped_color: FloatVectorProperty( + uv_inspection_flipped_color = FloatVectorProperty( name="Color", description="Color", default=(1.0, 0.0, 0.0, 0.3), @@ -254,7 +249,7 @@ class Preferences(AddonPreferences): ) # for Texture Projection - texture_projection_canvas_padding: FloatVectorProperty( + texture_projection_canvas_padding = FloatVectorProperty( name="Canvas Padding", description="Canvas Padding", size=2, @@ -263,13 +258,13 @@ class Preferences(AddonPreferences): default=(20.0, 20.0)) # for UV Bounding Box - uv_bounding_box_cp_size: FloatProperty( + uv_bounding_box_cp_size = FloatProperty( name="Size", description="Control Point Size", default=6.0, min=3.0, max=100.0) - uv_bounding_box_cp_react_size: FloatProperty( + uv_bounding_box_cp_react_size = FloatProperty( name="React Size", description="Size event fired", default=10.0, @@ -277,7 +272,7 @@ class Preferences(AddonPreferences): max=100.0) # for UI - category: EnumProperty( + category = EnumProperty( name="Category", description="Preferences Category", items=[ @@ -287,45 +282,45 @@ class Preferences(AddonPreferences): ], default='INFO' ) - info_desc_expanded: BoolProperty( + info_desc_expanded = BoolProperty( name="Description", description="Description", default=False ) - info_loc_expanded: BoolProperty( + info_loc_expanded = BoolProperty( name="Location", description="Location", default=False ) - conf_uv_sculpt_expanded: BoolProperty( + conf_uv_sculpt_expanded = BoolProperty( name="UV Sculpt", description="UV Sculpt", default=False ) - conf_uv_inspection_expanded: BoolProperty( + conf_uv_inspection_expanded = BoolProperty( name="UV Inspection", description="UV Inspection", default=False ) - conf_texture_projection_expanded: BoolProperty( + conf_texture_projection_expanded = BoolProperty( name="Texture Projection", description="Texture Projection", default=False ) - conf_uv_bounding_box_expanded: BoolProperty( + conf_uv_bounding_box_expanded = BoolProperty( name="UV Bounding Box", description="UV Bounding Box", default=False ) # for add-on updater - updater_branch_to_update: EnumProperty( + updater_branch_to_update = EnumProperty( name="branch", description="Target branch to update add-on", items=get_update_candidate_branches ) - def draw(self, context): + def draw(self, _): layout = self.layout layout.row().prop(self, "category", expand=True) @@ -340,11 +335,11 @@ class Preferences(AddonPreferences): if self.info_desc_expanded: col = layout.column(align=True) col.label(text="Magic UV is composed of many UV editing" + - " features.") + " features.") col.label(text="See tutorial page if you are new to this" + - " add-on.") + " add-on.") col.label(text="https://github.com/nutti/Magic-UV" + - "/wiki/Tutorial") + "/wiki/Tutorial") layout.prop( self, "info_loc_expanded", text="Location", @@ -354,7 +349,7 @@ class Preferences(AddonPreferences): row = layout.row(align=True) sp = compat.layout_split(row, 0.5) sp.label(text="3D View > Tool shelf > " + - "Copy/Paste UV (Object mode)") + "Copy/Paste UV (Object mode)") sp = compat.layout_split(sp, 1.0) col = sp.column(align=True) col.label(text="Copy/Paste UV (Among objects)") @@ -362,7 +357,7 @@ class Preferences(AddonPreferences): row = layout.row(align=True) sp = compat.layout_split(row, 0.5) sp.label(text="3D View > Tool shelf > " + - "Copy/Paste UV (Edit mode)") + "Copy/Paste UV (Edit mode)") sp = compat.layout_split(sp, 1.0) col = sp.column(align=True) col.label(text="Copy/Paste UV (Among faces in 3D View)") @@ -371,7 +366,7 @@ class Preferences(AddonPreferences): row = layout.row(align=True) sp = compat.layout_split(row, 0.5) sp.label(text="3D View > Tool shelf > " + - "UV Manipulation (Edit mode)") + "UV Manipulation (Edit mode)") sp = compat.layout_split(sp, 1.0) col = sp.column(align=True) col.label(text="Flip/Rotate UV") @@ -386,7 +381,7 @@ class Preferences(AddonPreferences): row = layout.row(align=True) sp = compat.layout_split(row, 0.5) sp.label(text="3D View > Tool shelf > " + - "UV Manipulation (Edit mode)") + "UV Manipulation (Edit mode)") sp = compat.layout_split(sp, 1.0) col = sp.column(align=True) col.label(text="Unwrap Constraint") @@ -398,7 +393,8 @@ class Preferences(AddonPreferences): sp.label(text="UV/Image Editor > Tool shelf > Copy/Paste UV") sp = compat.layout_split(sp, 1.0) col = sp.column(align=True) - col.label(text="Copy/Paste UV (Among faces in UV/Image Editor)") + col.label(text="Copy/Paste UV " + + "(Among faces in UV/Image Editor)") row = layout.row(align=True) sp = compat.layout_split(row, 0.5) @@ -413,7 +409,7 @@ class Preferences(AddonPreferences): row = layout.row(align=True) sp = compat.layout_split(row, 0.5) sp.label(text="UV/Image Editor > Tool shelf > " + - "Editor Enhancement") + "Editor Enhancement") sp = compat.layout_split(sp, 1.0) col = sp.column(align=True) col.label(text="Align UV Cursor") @@ -425,6 +421,7 @@ class Preferences(AddonPreferences): layout.separator() layout.prop(self, "enable_builtin_menu", text="Built-in Menu") + layout.prop(self, "enable_debug_mode", text="Debug Mode") layout.separator() @@ -488,51 +485,4 @@ class Preferences(AddonPreferences): layout.separator() elif self.category == 'UPDATE': - updater = AddonUpdatorManager.get_instance() - - layout.separator() - - if not updater.candidate_checked(): - col = layout.column() - col.scale_y = 2 - row = col.row() - row.operator(MUV_OT_CheckAddonUpdate.bl_idname, - text="Check 'Magic UV' add-on update", - icon='FILE_REFRESH') - else: - row = layout.row(align=True) - row.scale_y = 2 - col = row.column() - col.operator(MUV_OT_CheckAddonUpdate.bl_idname, - text="Check 'Magic UV' add-on update", - icon='FILE_REFRESH') - col = row.column() - if updater.latest_version() != "": - col.enabled = True - ops = col.operator( - MUV_OT_UpdateAddon.bl_idname, - text="Update to the latest release version (version: {})" - .format(updater.latest_version()), - icon='TRIA_DOWN_BAR') - ops.branch_name = updater.latest_version() - else: - col.enabled = False - col.operator(MUV_OT_UpdateAddon.bl_idname, - text="No updates are available.") - - layout.separator() - layout.label(text="Manual Update:") - row = layout.row(align=True) - row.prop(self, "updater_branch_to_update", text="Target") - ops = row.operator( - MUV_OT_UpdateAddon.bl_idname, text="Update", - icon='TRIA_DOWN_BAR') - ops.branch_name = self.updater_branch_to_update - - layout.separator() - if updater.has_error(): - box = layout.box() - box.label(text=updater.error(), icon='CANCEL') - elif updater.has_info(): - box = layout.box() - box.label(text=updater.info(), icon='ERROR') + updater.draw_updater_ui(self) diff --git a/uv_magic_uv/properites.py b/uv_magic_uv/properites.py index 81ebbb4d..7a119bde 100644 --- a/uv_magic_uv/properites.py +++ b/uv_magic_uv/properites.py @@ -24,23 +24,13 @@ __version__ = "5.2" __date__ = "17 Nov 2018" +from .utils.property_class_registry import PropertyClassRegistry + + # Properties used in this add-on. # pylint: disable=W0612 class MUV_Properties(): - def __init__(self): - self.prefs = MUV_Prefs() - - -# TODO: delete this -class MUV_Prefs(): - expanded = { - "info_desc": False, - "info_loc": False, - "conf_uvsculpt": False, - "conf_uvinsp": False, - "conf_texproj": False, - "conf_uvbb": False - } + pass def init_props(scene): diff --git a/uv_magic_uv/ui/IMAGE_MT_uvs.py b/uv_magic_uv/ui/IMAGE_MT_uvs.py index 3881f547..65709f23 100644 --- a/uv_magic_uv/ui/IMAGE_MT_uvs.py +++ b/uv_magic_uv/ui/IMAGE_MT_uvs.py @@ -25,8 +25,9 @@ __date__ = "17 Nov 2018" import bpy -from ..op import ( - copy_paste_uv_uvedit, +from ..op.copy_paste_uv_uvedit import ( + MUV_OT_CopyPasteUVUVEdit_CopyUV, + MUV_OT_CopyPasteUVUVEdit_PasteUV, ) from ..op.align_uv_cursor import MUV_OT_AlignUVCursor from ..op.align_uv import ( @@ -48,19 +49,16 @@ class MUV_MT_CopyPasteUV_UVEdit(bpy.types.Menu): Menu class: Master menu of Copy/Paste UV coordinate on UV/ImageEditor """ - bl_idname = "uv.muv_copy_paste_uv_uvedit_menu" + bl_idname = "uv.muv_mt_copy_paste_uv_uvedit" bl_label = "Copy/Paste UV" bl_description = "Copy and Paste UV coordinate among object" def draw(self, _): layout = self.layout - layout.operator( - copy_paste_uv_uvedit.MUV_OT_CopyPasteUVUVEdit_CopyUV.bl_idname, - text="Copy") - layout.operator( - copy_paste_uv_uvedit.MUV_OT_CopyPasteUVUVEdit_PasteUV.bl_idname, - text="Paste") + layout.operator(MUV_OT_CopyPasteUVUVEdit_CopyUV.bl_idname, text="Copy") + layout.operator(MUV_OT_CopyPasteUVUVEdit_PasteUV.bl_idname, + text="Paste") @BlClassRegistry() @@ -69,7 +67,7 @@ class MUV_MT_AlignUV(bpy.types.Menu): Menu class: Master menu of Align UV """ - bl_idname = "uv.muv_align_uv_menu" + bl_idname = "uv.muv_mt_align_uv" bl_label = "Align UV" bl_description = "Align UV" @@ -102,7 +100,7 @@ class MUV_MT_SelectUV(bpy.types.Menu): Menu class: Master menu of Select UV """ - bl_idname = "uv.muv_select_uv_menu" + bl_idname = "uv.muv_mt_select_uv" bl_label = "Select UV" bl_description = "Select UV" @@ -121,7 +119,7 @@ class MUV_MT_AlignUVCursor(bpy.types.Menu): Menu class: Master menu of Align UV Cursor """ - bl_idname = "uv.muv_align_uv_cursor_menu" + bl_idname = "uv.muv_mt_align_uv_cursor" bl_label = "Align UV Cursor" bl_description = "Align UV cursor" @@ -129,8 +127,7 @@ class MUV_MT_AlignUVCursor(bpy.types.Menu): layout = self.layout sc = context.scene - ops = layout.operator(MUV_OT_AlignUVCursor.bl_idname, - text="Left Top") + ops = layout.operator(MUV_OT_AlignUVCursor.bl_idname, text="Left Top") ops.position = 'LEFT_TOP' ops.base = sc.muv_align_uv_cursor_align_method @@ -139,8 +136,7 @@ class MUV_MT_AlignUVCursor(bpy.types.Menu): ops.position = 'MIDDLE_TOP' ops.base = sc.muv_align_uv_cursor_align_method - ops = layout.operator(MUV_OT_AlignUVCursor.bl_idname, - text="Right Top") + ops = layout.operator(MUV_OT_AlignUVCursor.bl_idname, text="Right Top") ops.position = 'RIGHT_TOP' ops.base = sc.muv_align_uv_cursor_align_method @@ -149,8 +145,7 @@ class MUV_MT_AlignUVCursor(bpy.types.Menu): ops.position = 'LEFT_MIDDLE' ops.base = sc.muv_align_uv_cursor_align_method - ops = layout.operator(MUV_OT_AlignUVCursor.bl_idname, - text="Center") + ops = layout.operator(MUV_OT_AlignUVCursor.bl_idname, text="Center") ops.position = 'CENTER' ops.base = sc.muv_align_uv_cursor_align_method @@ -181,7 +176,7 @@ class MUV_MT_UVInspection(bpy.types.Menu): Menu class: Master menu of UV Inspection """ - bl_idname = "uv.muv_uv_inspection_menu" + bl_idname = "uv.muv_mt_uv_inspection" bl_label = "UV Inspection" bl_description = "UV Inspection" diff --git a/uv_magic_uv/ui/VIEW3D_MT_object.py b/uv_magic_uv/ui/VIEW3D_MT_object.py index 0d51a65b..20c621f9 100644 --- a/uv_magic_uv/ui/VIEW3D_MT_object.py +++ b/uv_magic_uv/ui/VIEW3D_MT_object.py @@ -25,7 +25,10 @@ __date__ = "17 Nov 2018" import bpy -from ..op import copy_paste_uv_object +from ..op.copy_paste_uv_object import ( + MUV_MT_CopyPasteUVObject_CopyUV, + MUV_MT_CopyPasteUVObject_PasteUV, +) from ..utils.bl_class_registry import BlClassRegistry @@ -35,16 +38,12 @@ class MUV_MT_CopyPasteUV_Object(bpy.types.Menu): Menu class: Master menu of Copy/Paste UV coordinate among object """ - bl_idname = "uv.muv_copy_paste_uv_object_menu" + bl_idname = "uv.muv_mt_copy_paste_uv_object" bl_label = "Copy/Paste UV" bl_description = "Copy and Paste UV coordinate among object" def draw(self, _): layout = self.layout - layout.menu( - copy_paste_uv_object.MUV_MT_CopyPasteUVObject_CopyUV.bl_idname, - text="Copy") - layout.menu( - copy_paste_uv_object.MUV_MT_CopyPasteUVObject_PasteUV.bl_idname, - text="Paste") + layout.menu(MUV_MT_CopyPasteUVObject_CopyUV.bl_idname, text="Copy") + layout.menu(MUV_MT_CopyPasteUVObject_PasteUV.bl_idname, text="Paste") diff --git a/uv_magic_uv/ui/VIEW3D_MT_uv_map.py b/uv_magic_uv/ui/VIEW3D_MT_uv_map.py index d673ed4d..0c2ca89a 100644 --- a/uv_magic_uv/ui/VIEW3D_MT_uv_map.py +++ b/uv_magic_uv/ui/VIEW3D_MT_uv_map.py @@ -25,10 +25,19 @@ __date__ = "17 Nov 2018" import bpy.utils -from ..op import ( - copy_paste_uv, - transfer_uv, - uvw, +from ..op.copy_paste_uv import ( + MUV_MT_CopyPasteUV_CopyUV, + MUV_MT_CopyPasteUV_PasteUV, + MUV_MT_CopyPasteUV_SelSeqCopyUV, + MUV_MT_CopyPasteUV_SelSeqPasteUV, +) +from ..op.transfer_uv import ( + MUV_OT_TransferUV_CopyUV, + MUV_OT_TransferUV_PasteUV, +) +from ..op.uvw import ( + MUV_OT_UVW_BoxMap, + MUV_OT_UVW_BestPlanerMap, ) from ..op.preserve_uv_aspect import MUV_OT_PreserveUVAspect from ..op.texture_lock import ( @@ -55,7 +64,7 @@ class MUV_MT_CopyPasteUV(bpy.types.Menu): Menu class: Master menu of Copy/Paste UV coordinate """ - bl_idname = "uv.muv_copy_paste_uv_menu" + bl_idname = "uv.muv_mt_copy_paste_uv" bl_label = "Copy/Paste UV" bl_description = "Copy and Paste UV coordinate" @@ -63,18 +72,14 @@ class MUV_MT_CopyPasteUV(bpy.types.Menu): layout = self.layout layout.label(text="Default") - layout.menu(copy_paste_uv.MUV_MT_CopyPasteUV_CopyUV.bl_idname, - text="Copy") - layout.menu(copy_paste_uv.MUV_MT_CopyPasteUV_PasteUV.bl_idname, - text="Paste") + layout.menu(MUV_MT_CopyPasteUV_CopyUV.bl_idname, text="Copy") + layout.menu(MUV_MT_CopyPasteUV_PasteUV.bl_idname, text="Paste") layout.separator() layout.label(text="Selection Sequence") - layout.menu(copy_paste_uv.MUV_MT_CopyPasteUV_SelSeqCopyUV.bl_idname, - text="Copy") - layout.menu(copy_paste_uv.MUV_MT_CopyPasteUV_SelSeqPasteUV.bl_idname, - text="Paste") + layout.menu(MUV_MT_CopyPasteUV_SelSeqCopyUV.bl_idname, text="Copy") + layout.menu(MUV_MT_CopyPasteUV_SelSeqPasteUV.bl_idname, text="Paste") @BlClassRegistry() @@ -83,7 +88,7 @@ class MUV_MT_TransferUV(bpy.types.Menu): Menu class: Master menu of Transfer UV coordinate """ - bl_idname = "uv.muv_transfer_uv_menu" + bl_idname = "uv.muv_mt_transfer_uv" bl_label = "Transfer UV" bl_description = "Transfer UV coordinate" @@ -91,9 +96,8 @@ class MUV_MT_TransferUV(bpy.types.Menu): layout = self.layout sc = context.scene - layout.operator(transfer_uv.MUV_OT_TransferUV_CopyUV.bl_idname, - text="Copy") - ops = layout.operator(transfer_uv.MUV_OT_TransferUV_PasteUV.bl_idname, + layout.operator(MUV_OT_TransferUV_CopyUV.bl_idname, text="Copy") + ops = layout.operator(MUV_OT_TransferUV_PasteUV.bl_idname, text="Paste") ops.invert_normals = sc.muv_transfer_uv_invert_normals ops.copy_seams = sc.muv_transfer_uv_copy_seams @@ -105,7 +109,7 @@ class MUV_MT_TextureLock(bpy.types.Menu): Menu class: Master menu of Texture Lock """ - bl_idname = "uv.muv_texture_lock_menu" + bl_idname = "uv.muv_mt_texture_lock" bl_label = "Texture Lock" bl_description = "Lock texture when vertices of mesh (Preserve UV)" @@ -135,7 +139,7 @@ class MUV_MT_WorldScaleUV(bpy.types.Menu): Menu class: Master menu of world scale UV """ - bl_idname = "uv.muv_world_scale_uv_menu" + bl_idname = "uv.muv_mt_world_scale_uv" bl_label = "World Scale UV" bl_description = "" @@ -177,7 +181,7 @@ class MUV_MT_TextureWrap(bpy.types.Menu): Menu class: Master menu of Texture Wrap """ - bl_idname = "uv.muv_texture_wrap_menu" + bl_idname = "uv.muv_mt_texture_wrap" bl_label = "Texture Wrap" bl_description = "" @@ -194,7 +198,7 @@ class MUV_MT_UVW(bpy.types.Menu): Menu class: Master menu of UVW """ - bl_idname = "uv.muv_uvw_menu" + bl_idname = "uv.muv_mt_uvw" bl_label = "UVW" bl_description = "" @@ -202,10 +206,10 @@ class MUV_MT_UVW(bpy.types.Menu): layout = self.layout sc = context.scene - ops = layout.operator(uvw.MUV_OT_UVW_BoxMap.bl_idname, text="Box") + ops = layout.operator(MUV_OT_UVW_BoxMap.bl_idname, text="Box") ops.assign_uvmap = sc.muv_uvw_assign_uvmap - ops = layout.operator(uvw.MUV_OT_UVW_BestPlanerMap.bl_idname, + ops = layout.operator(MUV_OT_UVW_BestPlanerMap.bl_idname, text="Best Planner") ops.assign_uvmap = sc.muv_uvw_assign_uvmap @@ -216,7 +220,7 @@ class MUV_MT_PreserveUVAspect(bpy.types.Menu): Menu class: Master menu of Preserve UV Aspect """ - bl_idname = "uv.muv_preserve_uv_aspect_menu" + bl_idname = "uv.muv_mt_preserve_uv_aspect" bl_label = "Preserve UV Aspect" bl_description = "" @@ -236,7 +240,7 @@ class MUV_MT_TextureProjection(bpy.types.Menu): Menu class: Master menu of Texture Projection """ - bl_idname = "uv.muv_texture_projection_menu" + bl_idname = "uv.muv_mt_texture_projection" bl_label = "Texture Projection" bl_description = "" @@ -247,4 +251,4 @@ class MUV_MT_TextureProjection(bpy.types.Menu): layout.prop(sc, "muv_texture_projection_enable", text="Texture Projection") layout.operator(MUV_OT_TextureProjection_Project.bl_idname, - text="Project") \ No newline at end of file + text="Project") diff --git a/uv_magic_uv/ui/uvedit_copy_paste_uv.py b/uv_magic_uv/ui/uvedit_copy_paste_uv.py index 7b8a1c52..25a43e3f 100644 --- a/uv_magic_uv/ui/uvedit_copy_paste_uv.py +++ b/uv_magic_uv/ui/uvedit_copy_paste_uv.py @@ -25,7 +25,10 @@ __date__ = "17 Nov 2018" import bpy -from ..op import copy_paste_uv_uvedit +from ..op.copy_paste_uv_uvedit import ( + MUV_OT_CopyPasteUVUVEdit_CopyUV, + MUV_OT_CopyPasteUVUVEdit_PasteUV, +) from ..utils.bl_class_registry import BlClassRegistry from ..utils import compatibility as compat @@ -52,9 +55,5 @@ class MUV_PT_UVEdit_CopyPasteUV(bpy.types.Panel): layout = self.layout row = layout.row(align=True) - row.operator( - copy_paste_uv_uvedit.MUV_OT_CopyPasteUVUVEdit_CopyUV.bl_idname, - text="Copy") - row.operator( - copy_paste_uv_uvedit.MUV_OT_CopyPasteUVUVEdit_PasteUV.bl_idname, - text="Paste") + row.operator(MUV_OT_CopyPasteUVUVEdit_CopyUV.bl_idname, text="Copy") + row.operator(MUV_OT_CopyPasteUVUVEdit_PasteUV.bl_idname, text="Paste") diff --git a/uv_magic_uv/ui/uvedit_editor_enhancement.py b/uv_magic_uv/ui/uvedit_editor_enhancement.py index 7c366aa7..afe4c1d1 100644 --- a/uv_magic_uv/ui/uvedit_editor_enhancement.py +++ b/uv_magic_uv/ui/uvedit_editor_enhancement.py @@ -84,8 +84,7 @@ class MUV_PT_UVEdit_EditorEnhancement(bpy.types.Panel): text="Left Middle") ops.position = 'LEFT_MIDDLE' ops.base = sc.muv_align_uv_cursor_align_method - ops = row.operator(MUV_OT_AlignUVCursor.bl_idname, - text="Center") + ops = row.operator(MUV_OT_AlignUVCursor.bl_idname, text="Center") ops.position = 'CENTER' ops.base = sc.muv_align_uv_cursor_align_method ops = row.operator(MUV_OT_AlignUVCursor.bl_idname, diff --git a/uv_magic_uv/ui/view3d_copy_paste_uv_editmode.py b/uv_magic_uv/ui/view3d_copy_paste_uv_editmode.py index 0fc4df14..cb1a6bf4 100644 --- a/uv_magic_uv/ui/view3d_copy_paste_uv_editmode.py +++ b/uv_magic_uv/ui/view3d_copy_paste_uv_editmode.py @@ -25,9 +25,15 @@ __date__ = "17 Nov 2018" import bpy -from ..op import ( - copy_paste_uv, - transfer_uv, +from ..op.copy_paste_uv import ( + MUV_MT_CopyPasteUV_CopyUV, + MUV_MT_CopyPasteUV_PasteUV, + MUV_MT_CopyPasteUV_SelSeqCopyUV, + MUV_MT_CopyPasteUV_SelSeqPasteUV, +) +from ..op.transfer_uv import ( + MUV_OT_TransferUV_CopyUV, + MUV_OT_TransferUV_PasteUV, ) from ..utils.bl_class_registry import BlClassRegistry from ..utils import compatibility as compat @@ -60,17 +66,13 @@ class MUV_PT_CopyPasteUVEditMode(bpy.types.Panel): if sc.muv_copy_paste_uv_enabled: row = box.row(align=True) if sc.muv_copy_paste_uv_mode == 'DEFAULT': - row.menu(copy_paste_uv.MUV_MT_CopyPasteUV_CopyUV.bl_idname, + row.menu(MUV_MT_CopyPasteUV_CopyUV.bl_idname, text="Copy") + row.menu(MUV_MT_CopyPasteUV_PasteUV.bl_idname, text="Paste") + elif sc.muv_copy_paste_uv_mode == 'SEL_SEQ': + row.menu(MUV_MT_CopyPasteUV_SelSeqCopyUV.bl_idname, text="Copy") - row.menu(copy_paste_uv.MUV_MT_CopyPasteUV_PasteUV.bl_idname, + row.menu(MUV_MT_CopyPasteUV_SelSeqPasteUV.bl_idname, text="Paste") - elif sc.muv_copy_paste_uv_mode == 'SEL_SEQ': - row.menu( - copy_paste_uv.MUV_MT_CopyPasteUV_SelSeqCopyUV.bl_idname, - text="Copy") - row.menu( - copy_paste_uv.MUV_MT_CopyPasteUV_SelSeqPasteUV.bl_idname, - text="Paste") box.prop(sc, "muv_copy_paste_uv_mode", expand=True) box.prop(sc, "muv_copy_paste_uv_copy_seams", text="Seams") box.prop(sc, "muv_copy_paste_uv_strategy", text="Strategy") @@ -79,9 +81,8 @@ class MUV_PT_CopyPasteUVEditMode(bpy.types.Panel): box.prop(sc, "muv_transfer_uv_enabled", text="Transfer UV") if sc.muv_transfer_uv_enabled: row = box.row(align=True) - row.operator(transfer_uv.MUV_OT_TransferUV_CopyUV.bl_idname, - text="Copy") - ops = row.operator(transfer_uv.MUV_OT_TransferUV_PasteUV.bl_idname, + row.operator(MUV_OT_TransferUV_CopyUV.bl_idname, text="Copy") + ops = row.operator(MUV_OT_TransferUV_PasteUV.bl_idname, text="Paste") ops.invert_normals = sc.muv_transfer_uv_invert_normals ops.copy_seams = sc.muv_transfer_uv_copy_seams diff --git a/uv_magic_uv/ui/view3d_copy_paste_uv_objectmode.py b/uv_magic_uv/ui/view3d_copy_paste_uv_objectmode.py index 36968ffb..0b7040bf 100644 --- a/uv_magic_uv/ui/view3d_copy_paste_uv_objectmode.py +++ b/uv_magic_uv/ui/view3d_copy_paste_uv_objectmode.py @@ -25,7 +25,10 @@ __date__ = "17 Nov 2018" import bpy -from ..op import copy_paste_uv_object +from ..op.copy_paste_uv_object import ( + MUV_MT_CopyPasteUVObject_CopyUV, + MUV_MT_CopyPasteUVObject_PasteUV, +) from ..utils.bl_class_registry import BlClassRegistry from ..utils import compatibility as compat @@ -53,11 +56,7 @@ class MUV_PT_View3D_Object_CopyPasteUV(bpy.types.Panel): layout = self.layout row = layout.row(align=True) - row.menu( - copy_paste_uv_object.MUV_MT_CopyPasteUVObject_CopyUV.bl_idname, - text="Copy") - row.menu( - copy_paste_uv_object.MUV_MT_CopyPasteUVObject_PasteUV.bl_idname, - text="Paste") + row.menu(MUV_MT_CopyPasteUVObject_CopyUV.bl_idname, text="Copy") + row.menu(MUV_MT_CopyPasteUVObject_PasteUV.bl_idname, text="Paste") layout.prop(sc, "muv_copy_paste_uv_object_copy_seams", text="Seams") diff --git a/uv_magic_uv/ui/view3d_uv_mapping.py b/uv_magic_uv/ui/view3d_uv_mapping.py index 9a75de49..e56f18f3 100644 --- a/uv_magic_uv/ui/view3d_uv_mapping.py +++ b/uv_magic_uv/ui/view3d_uv_mapping.py @@ -25,8 +25,9 @@ __date__ = "17 Nov 2018" import bpy -from ..op import ( - uvw, +from ..op.uvw import ( + MUV_OT_UVW_BoxMap, + MUV_OT_UVW_BestPlanerMap, ) from ..op.texture_projection import ( MUV_OT_TextureProjection, @@ -105,9 +106,9 @@ class MUV_PT_View3D_UVMapping(bpy.types.Panel): box.prop(sc, "muv_uvw_enabled", text="UVW") if sc.muv_uvw_enabled: row = box.row(align=True) - ops = row.operator(uvw.MUV_OT_UVW_BoxMap.bl_idname, text="Box") + ops = row.operator(MUV_OT_UVW_BoxMap.bl_idname, text="Box") ops.assign_uvmap = sc.muv_uvw_assign_uvmap - ops = row.operator(uvw.MUV_OT_UVW_BestPlanerMap.bl_idname, + ops = row.operator(MUV_OT_UVW_BestPlanerMap.bl_idname, text="Best Planner") ops.assign_uvmap = sc.muv_uvw_assign_uvmap box.prop(sc, "muv_uvw_assign_uvmap", text="Assign UVMap") diff --git a/uv_magic_uv/updater.py b/uv_magic_uv/updater.py new file mode 100644 index 00000000..41becfe7 --- /dev/null +++ b/uv_magic_uv/updater.py @@ -0,0 +1,136 @@ +# + +# ##### 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; either version 2 +# of the License, or (at your option) any later version. +# +# 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 ##### + +__author__ = "Nutti " +__status__ = "production" +__version__ = "5.2" +__date__ = "17 Nov 2018" + +import os + +import bpy +from bpy.props import ( + StringProperty, +) + +from .utils.bl_class_registry import BlClassRegistry +from .utils.addon_updator import AddonUpdatorManager, AddonUpdatorConfig +from .utils import compatibility as compat + + +@BlClassRegistry() +class MUV_OT_CheckAddonUpdate(bpy.types.Operator): + bl_idname = "uv.muv_ot_check_addon_update" + bl_label = "Check Update" + bl_description = "Check Add-on Update" + bl_options = {'REGISTER', 'UNDO'} + + def execute(self, _): + updater = AddonUpdatorManager.get_instance() + updater.check_update_candidate() + + return {'FINISHED'} + + +@BlClassRegistry() +@compat.make_annotations +class MUV_OT_UpdateAddon(bpy.types.Operator): + bl_idname = "uv.muv_ot_update_addon" + bl_label = "Update" + bl_description = "Update Add-on" + bl_options = {'REGISTER', 'UNDO'} + + branch_name = StringProperty( + name="Branch Name", + description="Branch name to update", + default="", + ) + + def execute(self, _): + updater = AddonUpdatorManager.get_instance() + updater.update(self.branch_name) + + return {'FINISHED'} + + +def draw_updater_ui(prefs_obj): + layout = prefs_obj.layout + updater = AddonUpdatorManager.get_instance() + + layout.separator() + + if not updater.candidate_checked(): + col = layout.column() + col.scale_y = 2 + row = col.row() + row.operator(MUV_OT_CheckAddonUpdate.bl_idname, + text="Check 'Magic UV' add-on update", + icon='FILE_REFRESH') + else: + row = layout.row(align=True) + row.scale_y = 2 + col = row.column() + col.operator(MUV_OT_CheckAddonUpdate.bl_idname, + text="Check 'Magic UV' add-on update", + icon='FILE_REFRESH') + col = row.column() + if updater.latest_version() != "": + col.enabled = True + ops = col.operator( + MUV_OT_UpdateAddon.bl_idname, + text="Update to the latest release version (version: {})" + .format(updater.latest_version()), + icon='TRIA_DOWN_BAR') + ops.branch_name = updater.latest_version() + else: + col.enabled = False + col.operator(MUV_OT_UpdateAddon.bl_idname, + text="No updates are available.") + + layout.separator() + layout.label(text="Manual Update:") + row = layout.row(align=True) + row.prop(prefs_obj, "updater_branch_to_update", text="Target") + ops = row.operator( + MUV_OT_UpdateAddon.bl_idname, text="Update", + icon='TRIA_DOWN_BAR') + ops.branch_name = prefs_obj.updater_branch_to_update + + layout.separator() + if updater.has_error(): + box = layout.box() + box.label(text=updater.error(), icon='CANCEL') + elif updater.has_info(): + box = layout.box() + box.label(text=updater.info(), icon='ERROR') + + +def register_updater(bl_info): + config = AddonUpdatorConfig() + config.owner = "nutti" + config.repository = "Magic-UV" + config.current_addon_path = os.path.dirname(os.path.realpath(__file__)) + config.branches = ["master", "develop"] + config.addon_directory = \ + config.current_addon_path[:config.current_addon_path.rfind("/")] + config.min_release_version = bl_info["version"] + config.target_addon_path = "src/uv_magic_uv" + updater = AddonUpdatorManager.get_instance() + updater.init(bl_info, config) diff --git a/uv_magic_uv/utils/addon_updator.py b/uv_magic_uv/utils/addon_updator.py index 42e4309e..ae4aa003 100644 --- a/uv_magic_uv/utils/addon_updator.py +++ b/uv_magic_uv/utils/addon_updator.py @@ -35,6 +35,7 @@ import datetime def _request(url, json_decode=True): + # pylint: disable=W0212 ssl._create_default_https_context = ssl._create_unverified_context req = urllib.request.Request(url) @@ -291,6 +292,7 @@ class AddonUpdatorManager: if not self.candidate_checked(): raise RuntimeError("Update candidate is not checked.") + info = None for info in self.__update_candidate: if info.name == version_name: break @@ -298,6 +300,9 @@ class AddonUpdatorManager: raise RuntimeError("{} is not found in update candidate" .format(version_name)) + if info is None: + raise RuntimeError("Not found any update candidates") + try: # create workspace _make_workspace(self.__config.addon_directory) @@ -307,9 +312,9 @@ class AddonUpdatorManager: # replace add-on offset_path = "" if info.group == 'BRANCH': - offset_path = "{}-{}/{}".format(self.__config.repository, - info.name, - self.__config.target_addon_path) + offset_path = "{}-{}/{}".format( + self.__config.repository, info.name, + self.__config.target_addon_path) elif info.group == 'RELEASE': offset_path = self.__config.target_addon_path _replace_addon(self.__config.addon_directory, @@ -334,12 +339,16 @@ class AddonUpdatorManager: return [info.name for info in self.__update_candidate] def latest_version(self): - release_versions = [info.name for info in self.__update_candidate if info.group == 'RELEASE'] + release_versions = [info.name + for info in self.__update_candidate + if info.group == 'RELEASE'] latest = "" for version in release_versions: - if latest == "" or _compare_version(_parse_release_version(version), - _parse_release_version(latest)) > 0: + if latest == "": + latest = version + elif _compare_version(_parse_release_version(version), + _parse_release_version(latest)) > 0: latest = version return latest -- cgit v1.2.3