1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
24 def write(fw
, mesh
, image_width
, image_height
, opacity
, face_iter_func
):
25 # for making an XML compatible string
26 from xml
.sax
.saxutils
import escape
27 from os
.path
import basename
29 fw('<?xml version="1.0" standalone="no"?>\n')
30 fw('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" \n')
31 fw(' "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')
32 fw('<svg width="%d" height="%d" viewBox="0 0 %d %d"\n' %
33 (image_width
, image_height
, image_width
, image_height
))
34 fw(' xmlns="http://www.w3.org/2000/svg" version="1.1">\n')
35 desc
= ("%r, %s, (Blender %s)" %
36 (basename(bpy
.data
.filepath
), mesh
.name
, bpy
.app
.version_string
))
37 fw('<desc>%s</desc>\n' % escape(desc
))
41 fill_default
= 'fill="grey"'
42 for mat
in mesh
.materials
if mesh
.materials
else [None]:
44 fill_settings
.append('fill="rgb(%d, %d, %d)"' %
46 for c
in mat
.diffuse_color
))
48 fill_settings
.append(fill_default
)
51 for i
, uvs
in face_iter_func():
52 try: # rare cases material index is invalid.
53 fill
= fill_settings
[polys
[i
].material_index
]
57 fw('<polygon stroke="black" stroke-width="1"')
59 fw(' %s fill-opacity="%.2g"' % (fill
, opacity
))
63 for j
, uv
in enumerate(uvs
):
64 x
, y
= uv
[0], 1.0 - uv
[1]
65 fw('%.3f,%.3f ' % (x
* image_width
, y
* image_height
))