Merge branch 'master' into blender2.8
[blender-addons.git] / io_mesh_uv_layout / export_uv_eps.py
bloba15dc2662e4b860a39fc88727b769629e2edebf3
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 #####
19 # <pep8-80 compliant>
21 import bpy
24 def write(fw, mesh, image_width, image_height, opacity, face_iter_func):
25 fw("%!PS-Adobe-3.0 EPSF-3.0\n")
26 fw("%%%%Creator: Blender %s\n" % bpy.app.version_string)
27 fw("%%Pages: 1\n")
28 fw("%%Orientation: Portrait\n")
29 fw("%%%%BoundingBox: 0 0 %d %d\n" % (image_width, image_height))
30 fw("%%%%HiResBoundingBox: 0.0 0.0 %.4f %.4f\n" %
31 (image_width, image_height))
32 fw("%%EndComments\n")
33 fw("%%Page: 1 1\n")
34 fw("0 0 translate\n")
35 fw("1.0 1.0 scale\n")
36 fw("0 0 0 setrgbcolor\n")
37 fw("[] 0 setdash\n")
38 fw("1 setlinewidth\n")
39 fw("1 setlinejoin\n")
40 fw("1 setlinecap\n")
42 polys = mesh.polygons
44 if opacity > 0.0:
45 for i, mat in enumerate(mesh.materials if mesh.materials else [None]):
46 fw("/DRAW_%d {" % i)
47 fw("gsave\n")
48 if mat:
49 color = tuple((1.0 - ((1.0 - c) * opacity))
50 for c in mat.diffuse_color)
51 else:
52 color = 1.0, 1.0, 1.0
53 fw("%.3g %.3g %.3g setrgbcolor\n" % color)
54 fw("fill\n")
55 fw("grestore\n")
56 fw("0 setgray\n")
57 fw("} def\n")
59 # fill
60 for i, uvs in face_iter_func():
61 fw("newpath\n")
62 for j, uv in enumerate(uvs):
63 uv_scale = (uv[0] * image_width, uv[1] * image_height)
64 if j == 0:
65 fw("%.5f %.5f moveto\n" % uv_scale)
66 else:
67 fw("%.5f %.5f lineto\n" % uv_scale)
69 fw("closepath\n")
70 fw("DRAW_%d\n" % polys[i].material_index)
72 # stroke only
73 for i, uvs in face_iter_func():
74 fw("newpath\n")
75 for j, uv in enumerate(uvs):
76 uv_scale = (uv[0] * image_width, uv[1] * image_height)
77 if j == 0:
78 fw("%.5f %.5f moveto\n" % uv_scale)
79 else:
80 fw("%.5f %.5f lineto\n" % uv_scale)
82 fw("closepath\n")
83 fw("stroke\n")
85 fw("showpage\n")
86 fw("%%EOF\n")