Skip to content
Snippets Groups Projects
Commit 31017e2d authored by Campbell Barton's avatar Campbell Barton
Browse files

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.
parent d4249fc7
No related branches found
No related tags found
No related merge requests found
......@@ -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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment