[Bf-extensions-cvs] [31017e2d] blender2.8: io_mesh_uv_layout: minor edits on recent 2.8 port

Campbell Barton noreply at git.blender.org
Mon Oct 8 23:34:48 CEST 2018


Commit: 31017e2dc32c77612a44cc1f266e37928d7ed866
Author: Campbell Barton
Date:   Tue Oct 9 08:16:39 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBA31017e2dc32c77612a44cc1f266e37928d7ed866

io_mesh_uv_layout: minor edits on recent 2.8 port

- Use 0.25 opacity because front/back overlap can too easily hide wire.
- Avoid using Py builtin 'object' for naming.
- Checking a collection is true/false more efficient in RNA
  than check len(collection) > 0.
- Use staticmethods when self isn't needed.

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

M	io_mesh_uv_layout/__init__.py

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

diff --git a/io_mesh_uv_layout/__init__.py b/io_mesh_uv_layout/__init__.py
index 5d8d27da..1ebbb062 100644
--- a/io_mesh_uv_layout/__init__.py
+++ b/io_mesh_uv_layout/__init__.py
@@ -80,13 +80,14 @@ class ExportUVLayout(bpy.types.Operator):
         default=False,
     )
     mode: EnumProperty(
-        items=(('SVG', "Scalable Vector Graphic (.svg)",
-                "Export the UV layout to a vector SVG file"),
-                ('EPS', "Encapsulate PostScript (.eps)",
-                "Export the UV layout to a vector EPS file"),
-                ('PNG', "PNG Image (.png)",
-                "Export the UV layout to a bitmap image"),
-                ),
+        items=(
+            ('SVG', "Scalable Vector Graphic (.svg)",
+             "Export the UV layout to a vector SVG file"),
+            ('EPS', "Encapsulate PostScript (.eps)",
+             "Export the UV layout to a vector EPS file"),
+            ('PNG', "PNG Image (.png)",
+             "Export the UV layout to a bitmap image"),
+        ),
         name="Format",
         description="File format to export the UV layout to",
         default='PNG',
@@ -100,14 +101,14 @@ class ExportUVLayout(bpy.types.Operator):
     opacity: FloatProperty(
         name="Fill Opacity",
         min=0.0, max=1.0,
-        default=0.5,
-        description="Set amount of opacity for exported UV layout"
+        default=0.25,
+        description="Set amount of opacity for exported UV layout",
     )
 
     @classmethod
     def poll(cls, context):
         obj = context.active_object
-        return obj is not None and obj.type == 'MESH' and len(obj.data.uv_layers) > 0
+        return obj is not None and obj.type == 'MESH' and obj.data.uv_layers
 
     def invoke(self, context, event):
         self.size = self.get_image_size(context)
@@ -132,8 +133,8 @@ class ExportUVLayout(bpy.types.Operator):
         return True
 
     def execute(self, context):
-        object = context.active_object
-        is_editmode = (object.mode == 'EDIT')
+        obj = context.active_object
+        is_editmode = (obj.mode == 'EDIT')
         if is_editmode:
             bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
 
@@ -155,26 +156,29 @@ class ExportUVLayout(bpy.types.Operator):
         return {'FINISHED'}
 
     def iter_meshes_to_export(self, context):
-        for object in self.iter_objects_to_export(context):
+        for obj in self.iter_objects_to_export(context):
             if self.modified:
-                yield object.to_mesh(context.depsgraph, apply_modifiers=True)
+                yield obj.to_mesh(context.depsgraph, apply_modifiers=True)
             else:
-                yield object.data
+                yield obj.data
 
-    def iter_objects_to_export(self, context):
-        for object in context.selected_objects:
-            if object.type != "MESH":
+    @staticmethod
+    def iter_objects_to_export(context):
+        for obj in context.selected_objects:
+            if obj.type != "MESH":
                 continue
-            mesh = object.data
+            mesh = obj.data
             if mesh.uv_layers.active is None:
                 continue
-            yield object
+            yield obj
 
-    def free_meshes(self, meshes):
+    @staticmethod
+    def free_meshes(meshes):
         for mesh in meshes:
             bpy.data.meshes.remove(mesh)
 
-    def currently_image_image_editor(self, context):
+    @staticmethod
+    def currently_image_image_editor(context):
         return isinstance(context.space_data, bpy.types.SpaceImageEditor)
 
     def get_currently_opened_image(self, context):
@@ -207,7 +211,8 @@ class ExportUVLayout(bpy.types.Operator):
                     uvs = tuple(tuple(uv.uv) for uv in uv_layer[start:end])
                     yield (uvs, self.get_polygon_color(mesh, polygon))
 
-    def get_polygon_color(self, mesh, polygon, default = (0.8, 0.8, 0.8)):
+    @staticmethod
+    def get_polygon_color(mesh, polygon, default=(0.8, 0.8, 0.8)):
         if polygon.material_index < len(mesh.materials):
             material = mesh.materials[polygon.material_index]
             if material is not None:
@@ -233,9 +238,11 @@ def register():
     bpy.utils.register_class(ExportUVLayout)
     bpy.types.IMAGE_MT_uvs.append(menu_func)
 
+
 def unregister():
     bpy.utils.unregister_class(ExportUVLayout)
     bpy.types.IMAGE_MT_uvs.remove(menu_func)
 
+
 if __name__ == "__main__":
     register()



More information about the Bf-extensions-cvs mailing list