diff options
Diffstat (limited to 'io_mesh_uv_layout/export_uv_svg.py')
-rw-r--r-- | io_mesh_uv_layout/export_uv_svg.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/io_mesh_uv_layout/export_uv_svg.py b/io_mesh_uv_layout/export_uv_svg.py index d8e2b5a4..a4b6a3c3 100644 --- a/io_mesh_uv_layout/export_uv_svg.py +++ b/io_mesh_uv_layout/export_uv_svg.py @@ -4,16 +4,19 @@ import bpy from os.path import basename from xml.sax.saxutils import escape + def export(filepath, face_data, colors, width, height, opacity): with open(filepath, 'w', encoding='utf-8') as file: for text in get_file_parts(face_data, colors, width, height, opacity): file.write(text) + def get_file_parts(face_data, colors, width, height, opacity): yield from header(width, height) yield from draw_polygons(face_data, width, height, opacity) yield from footer() + def header(width, height): yield '<?xml version="1.0" standalone="no"?>\n' yield '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" \n' @@ -23,6 +26,7 @@ def header(width, height): desc = f"{basename(bpy.data.filepath)}, (Blender {bpy.app.version_string})" yield f'<desc>{escape(desc)}</desc>\n' + def draw_polygons(face_data, width, height, opacity): for uvs, color in face_data: fill = f'fill="{get_color_string(color)}"' @@ -37,10 +41,12 @@ def draw_polygons(face_data, width, height, opacity): yield f'{x*width:.3f},{y*height:.3f} ' yield '" />\n' + def get_color_string(color): r, g, b = color return f"rgb({round(r*255)}, {round(g*255)}, {round(b*255)})" + def footer(): yield '\n' yield '</svg>\n' |