diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-10-09 00:16:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-10-09 00:27:41 +0300 |
commit | 31017e2dc32c77612a44cc1f266e37928d7ed866 (patch) | |
tree | 807e72d303ebf2421307d5434ae36a85b95cdf15 /io_mesh_uv_layout | |
parent | d4249fc739b5c7d5563de66bd7d13568660d49a7 (diff) |
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.
Diffstat (limited to 'io_mesh_uv_layout')
-rw-r--r-- | io_mesh_uv_layout/__init__.py | 53 |
1 files changed, 30 insertions, 23 deletions
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() |