# SPDX-License-Identifier: GPL-2.0-or-later 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 '\n' yield '\n' yield f'\n' desc = f"{basename(bpy.data.filepath)}, (Blender {bpy.app.version_string})" yield f'{escape(desc)}\n' def draw_polygons(face_data, width, height, opacity): for uvs, color in face_data: fill = f'fill="{get_color_string(color)}"' 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 '\n'