[Bf-extensions-cvs] [05cb3ae] master: Fixed bugs and added new feature.

Nutti noreply at git.blender.org
Sun Nov 13 01:25:43 CET 2016


Commit: 05cb3aec2748bf1dbba166932e8c83a665a1b9b5
Author: Nutti
Date:   Sun Nov 13 09:18:02 2016 +0900
Branches: master
https://developer.blender.org/rBAC05cb3aec2748bf1dbba166932e8c83a665a1b9b5

Fixed bugs and added new feature.

New feature:
  (1) Copy/Paste UV Coordinates (Among same objects)
  (2) Texture Lock
  (3) Mirror UV
  (4) World Scale UV
  (5) Unwrap Constraint

===================================================================

M	uv_magic_uv/__init__.py
M	uv_magic_uv/muv_common.py
M	uv_magic_uv/muv_cpuv_ops.py
M	uv_magic_uv/muv_cpuv_selseq_ops.py
M	uv_magic_uv/muv_fliprot_ops.py
M	uv_magic_uv/muv_menu.py
A	uv_magic_uv/muv_mirroruv_ops.py
M	uv_magic_uv/muv_mvuv_ops.py
M	uv_magic_uv/muv_packuv_ops.py
M	uv_magic_uv/muv_preferences.py
M	uv_magic_uv/muv_props.py
A	uv_magic_uv/muv_texlock_ops.py
M	uv_magic_uv/muv_texproj_ops.py
M	uv_magic_uv/muv_transuv_ops.py
A	uv_magic_uv/muv_unwrapconst_ops.py
M	uv_magic_uv/muv_uvbb_ops.py
A	uv_magic_uv/muv_wsuv_ops.py

===================================================================

diff --git a/uv_magic_uv/__init__.py b/uv_magic_uv/__init__.py
index e180b12..e13e11e 100644
--- a/uv_magic_uv/__init__.py
+++ b/uv_magic_uv/__init__.py
@@ -20,14 +20,14 @@
 
 __author__ = "Nutti <nutti.metro at gmail.com>"
 __status__ = "production"
-__version__ = "4.0"
-__date__ = "14 May 2016"
+__version__ = "4.1"
+__date__ = "13 Nov 2016"
 
 
 bl_info = {
     "name": "Magic UV",
     "author": "Nutti",
-    "version": (4, 0),
+    "version": (4, 1),
     "blender": (2, 77, 0),
     "location": "View3D > U, View3D > Property Panel, ImageEditor > Property Panel, ImageEditor > UVs",
     "description": "UV Manipulator Tools",
@@ -52,6 +52,10 @@ if "bpy" in locals():
     imp.reload(muv_mvuv_ops)
     imp.reload(muv_texproj_ops)
     imp.reload(muv_packuv_ops)
+    imp.reload(muv_texlock_ops)
+    imp.reload(muv_mirroruv_ops)
+    imp.reload(muv_wsuv_ops)
+    imp.reload(muv_unwrapconst_ops)
 else:
     from . import muv_preferences
     from . import muv_menu
@@ -65,6 +69,10 @@ else:
     from . import muv_mvuv_ops
     from . import muv_texproj_ops
     from . import muv_packuv_ops
+    from . import muv_texlock_ops
+    from . import muv_mirroruv_ops
+    from . import muv_wsuv_ops
+    from . import muv_unwrapconst_ops
 
 import bpy
 
@@ -75,6 +83,10 @@ def view3d_uvmap_menu_fn(self, context):
     self.layout.operator(muv_fliprot_ops.MUV_FlipRot.bl_idname, icon="PLUGIN")
     self.layout.menu(muv_menu.MUV_TransUVMenu.bl_idname, icon="PLUGIN")
     self.layout.operator(muv_mvuv_ops.MUV_MVUV.bl_idname, icon="PLUGIN")
+    self.layout.menu(muv_menu.MUV_TexLockMenu.bl_idname, icon="PLUGIN")
+    self.layout.operator(muv_mirroruv_ops.MUV_MirrorUV.bl_idname, icon="PLUGIN")
+    self.layout.menu(muv_menu.MUV_WSUVMenu.bl_idname, icon="PLUGIN")
+    self.layout.operator(muv_unwrapconst_ops.MUV_UnwrapConstraint.bl_idname, icon='PLUGIN')
 
 
 def image_uvs_menu_fn(self, context):
@@ -82,10 +94,16 @@ def image_uvs_menu_fn(self, context):
     self.layout.operator(muv_packuv_ops.MUV_PackUV.bl_idname, icon="PLUGIN")
 
 
+def view3d_object_menu_fn(self, context):
+    self.layout.separator()
+    self.layout.menu(muv_menu.MUV_CPUVObjMenu.bl_idname, icon="PLUGIN")
+
+
 def register():
     bpy.utils.register_module(__name__)
     bpy.types.VIEW3D_MT_uv_map.append(view3d_uvmap_menu_fn)
     bpy.types.IMAGE_MT_uvs.append(image_uvs_menu_fn)
+    bpy.types.VIEW3D_MT_object.append(view3d_object_menu_fn)
     muv_props.init_props(bpy.types.Scene)
 
 
@@ -93,9 +111,9 @@ def unregister():
     bpy.utils.unregister_module(__name__)
     bpy.types.VIEW3D_MT_uv_map.remove(view3d_uvmap_menu_fn)
     bpy.types.IMAGE_MT_uvs.remove(image_uvs_menu_fn)
+    bpy.types.VIEW3D_MT_object.remove(view3d_object_menu_fn)
     muv_props.clear_props(bpy.types.Scene)
 
 
 if __name__ == "__main__":
     register()
-
diff --git a/uv_magic_uv/muv_common.py b/uv_magic_uv/muv_common.py
index 3867bdf..83df367 100644
--- a/uv_magic_uv/muv_common.py
+++ b/uv_magic_uv/muv_common.py
@@ -20,14 +20,17 @@
 
 __author__ = "Nutti <nutti.metro at gmail.com>"
 __status__ = "production"
-__version__ = "4.0"
-__date__ = "14 May 2016"
+__version__ = "4.1"
+__date__ = "13 Nov 2016"
 
 
 import bpy
 from . import muv_props
 
 
+PHI = 3.1415926535
+
+
 def debug_print(*s):
     """
     Print message to console in debugging mode
@@ -78,4 +81,3 @@ def get_space(area_type, region_type, space_type):
             break
 
     return (area, region, space)
-
diff --git a/uv_magic_uv/muv_cpuv_ops.py b/uv_magic_uv/muv_cpuv_ops.py
index 6353854..7804a66 100644
--- a/uv_magic_uv/muv_cpuv_ops.py
+++ b/uv_magic_uv/muv_cpuv_ops.py
@@ -20,8 +20,8 @@
 
 __author__ = "Nutti <nutti.metro at gmail.com>"
 __status__ = "production"
-__version__ = "4.0"
-__date__ = "14 May 2016"
+__version__ = "4.1"
+__date__ = "13 Nov 2016"
 
 
 import bpy
@@ -30,6 +30,15 @@ from bpy.props import StringProperty, BoolProperty, IntProperty, EnumProperty
 from . import muv_common
 
 
+def memorize_view_3d_mode(fn):
+    def __memorize_view_3d_mode(self, context):
+        mode_orig = bpy.context.object.mode
+        result = fn(self, context)
+        bpy.ops.object.mode_set(mode=mode_orig)
+        return result
+    return __memorize_view_3d_mode
+
+
 class MUV_CPUVCopyUV(bpy.types.Operator):
     """
     Operation class: Copy UV coordinate
@@ -123,7 +132,7 @@ class MUV_CPUVPasteUV(bpy.types.Operator):
         items=[
             ('N_N', 'N:N', 'Number of faces must be equal to source'),
             ('N_M', 'N:M', 'Number of faces must not be equal to source')],
-        default="N_N")
+        default="N_M")
 
     flip_copied_uv = BoolProperty(
         name="Flip Copied UV",
@@ -160,7 +169,7 @@ class MUV_CPUVPasteUV(bpy.types.Operator):
             uv_layer = bm.loops.layers.uv.verify()
         else:
             uv_layer = bm.loops.layers.uv[self.uv_map]
-        
+
         # get selected face
         dest_uvs = []
         dest_pin_uvs = []
@@ -182,7 +191,7 @@ class MUV_CPUVPasteUV(bpy.types.Operator):
                 "(src:%d, dest:%d)" %
                 (len(props.src_uvs), len(dest_uvs)))
             return {'CANCELLED'}
- 
+
         # paste
         for i, idx in enumerate(dest_face_indices):
             suv = None
@@ -245,3 +254,196 @@ class MUV_CPUVPasteUVMenu(bpy.types.Menu):
                 MUV_CPUVPasteUV.bl_idname,
                 text=m, icon="PLUGIN").uv_map = m
 
+
+class MUV_CPUVObjCopyUV(bpy.types.Operator):
+    """
+    Operation class: Copy UV coordinate per object
+    """
+
+    bl_idname = "object.muv_cpuv_obj_copy_uv"
+    bl_label = "Copy UV"
+    bl_description = "Copy UV coordinate"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    uv_map = bpy.props.StringProperty(options={'HIDDEN'})
+
+    @memorize_view_3d_mode
+    def execute(self, context):
+        props = context.scene.muv_props.cpuv_obj
+        if self.uv_map == "":
+            self.report({'INFO'}, "Copy UV coordinate per object")
+        else:
+            self.report(
+                {'INFO'},
+                "Copy UV coordinate per object (UV map:" + self.uv_map + ")")
+
+        bpy.ops.object.mode_set(mode='EDIT')
+
+        obj = context.active_object
+        bm = bmesh.from_edit_mesh(obj.data)
+        if muv_common.check_version(2, 73, 0) >= 0:
+            bm.faces.ensure_lookup_table()
+
+        # get UV layer
+        if self.uv_map == "":
+            if not bm.loops.layers.uv:
+                self.report(
+                    {'WARNING'}, "Object must have more than one UV map")
+                return {'CANCELLED'}
+            uv_layer = bm.loops.layers.uv.verify()
+        else:
+            uv_layer = bm.loops.layers.uv[self.uv_map]
+
+        # get selected face
+        props.src_uvs = []
+        props.src_pin_uvs = []
+        for face in bm.faces:
+            uvs = [l[uv_layer].uv.copy() for l in face.loops]
+            pin_uvs = [l[uv_layer].pin_uv for l in face.loops]
+            props.src_uvs.append(uvs)
+            props.src_pin_uvs.append(pin_uvs)
+
+        self.report({'INFO'}, "%s's UV coordinates are copied" % (obj.name))
+
+        return {'FINISHED'}
+
+
+class MUV_CPUVObjCopyUVMenu(bpy.types.Menu):
+    """
+    Menu class: Copy UV coordinate per object
+    """
+
+    bl_idname = "object.muv_cpuv_obj_copy_uv_menu"
+    bl_label = "Copy UV"
+    bl_description = "Copy UV coordinate per object"
+
+    def draw(self, context):
+        layout = self.layout
+        # create sub menu
+        obj = context.active_object
+        uv_maps = bpy.context.active_object.data.uv_textures.keys()
+        layout.operator(
+            MUV_CPUVObjCopyUV.bl_idname,
+            text="[Default]", icon="PLUGIN").uv_map = ""
+        for m in uv_maps:
+            layout.operator(
+                MUV_CPUVObjCopyUV.bl_idname,
+                text=m, icon="PLUGIN").uv_map = m
+
+
+class MUV_CPUVObjPasteUV(bpy.types.Operator):
+    """
+    Operation class: Paste UV coordinate per object
+    """
+
+    bl_idname = "object.muv_cpuv_obj_paste_uv"
+    bl_label = "Paste UV"
+    bl_description = "Paste UV coordinate"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    uv_map = bpy.props.StringProperty(options={'HIDDEN'})
+
+    @memorize_view_3d_mode
+    def execute(self, context):
+        props = context.scene.muv_props.cpuv_obj
+        if len(props.src_uvs) == 0 or len(props.src_pin_uvs) == 0:
+            self.report({'WARNING'}, "Need copy UV at first")
+            return {'CANCELLED'}
+
+        obj_names = []
+
+        for o in bpy.data.objects:
+            if not hasattr(o.data, "uv_textures") or not o.select:
+                continue
+
+            bpy.ops.object.mode_set(mode='OBJECT')
+            bpy.context.scene.objects.active = o
+            bpy.ops.object.mode_set(mode='EDIT')
+
+            obj = context.active_object
+            bm = bmesh.from_edit_mesh(obj.data)
+            if muv_common.check_version(2, 73, 0) >= 0:
+                bm.faces.ensure_lookup_table()
+
+            if self.uv_map == "" or not self.uv_map in bm.loops.layers.uv.keys():
+                self.report({'INFO'}, "Paste UV coordinate per object")
+            else:
+                self.report(
+                    {'INFO'},
+                    "Paste UV coordinate per object (UV map: %s)" %
+                    (self.uv_map))
+
+            # get UV layer
+            if self.uv_map == "" or not self.uv_map in bm.loops.layers.uv.keys():
+                if not bm.loops.layers.uv:
+                    self.report({'WARNING'},
+                        "Object must have more than one UV map")
+                    return {'CANCELLED'}
+                uv_layer = bm.loops.layers.uv.verify()
+            else:
+                uv_layer = bm.loops.layers.uv[self.uv_map]
+
+            # get selected face
+            dest_uvs = []
+            dest_pin_uvs = []
+            dest_face_indices = []
+            for face in bm.faces:
+                dest_face_indices.append(face.index)
+                uvs = [l[uv_layer].uv.copy() for l in face.loops]
+                pin_uvs = [l[uv_layer].pin_uv for l in face.loops]
+                dest_uvs.append(uvs)
+                dest_pin_uvs.append(pin_uvs)
+            if len(props.src_uvs) 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list