From 842a96b34c9e7532572a42c5629be49f751348af Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 9 Mar 2011 02:13:09 +0000 Subject: move UV layout from trunk to addons. --- io_mesh_uv_layout/export_uv_svg.py | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 io_mesh_uv_layout/export_uv_svg.py (limited to 'io_mesh_uv_layout/export_uv_svg.py') diff --git a/io_mesh_uv_layout/export_uv_svg.py b/io_mesh_uv_layout/export_uv_svg.py new file mode 100644 index 00000000..260c49e5 --- /dev/null +++ b/io_mesh_uv_layout/export_uv_svg.py @@ -0,0 +1,63 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# + +import bpy + +def write(fw, mesh, image_width, image_height, opacity, face_iter_func): + # for making an XML compatible string + from xml.sax.saxutils import escape + from os.path import basename + + fw('\n') + fw('\n') + fw('\n') + desc = "%r, %s, (Blender %s)" % (basename(bpy.data.filepath), mesh.name, bpy.app.version_string) + fw('%s\n' % escape(desc)) + + # svg colors + fill_settings = [] + fill_default = 'fill="grey"' + for mat in mesh.materials if mesh.materials else [None]: + if mat: + fill_settings.append('fill="rgb(%d, %d, %d)"' % tuple(int(c * 255) for c in mat.diffuse_color)) + else: + fill_settings.append(fill_default) + + faces = mesh.faces + for i, uvs in face_iter_func(): + try: # rare cases material index is invalid. + fill = fill_settings[faces[i].material_index] + except IndexError: + fill = fill_default + + fw(' 0.0: + fw(' %s fill-opacity="%.2g"' % (fill, opacity)) + + fw(' points="') + + for j, uv in enumerate(uvs): + x, y = uv[0], 1.0 - uv[1] + fw('%.3f,%.3f ' % (x * image_width, y * image_height)) + fw('" />\n') + fw('\n') + fw('\n') \ No newline at end of file -- cgit v1.2.3