1 # SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
8 def export(filepath
, tile
, face_data
, colors
, width
, height
, opacity
):
9 with
open(filepath
, 'w', encoding
='utf-8') as file:
10 for text
in get_file_parts(tile
, face_data
, colors
, width
, height
, opacity
):
14 def get_file_parts(tile
, face_data
, colors
, width
, height
, opacity
):
15 yield from header(width
, height
)
18 yield from prepare_colors(colors
, name_by_color
)
19 yield from draw_colored_polygons(tile
, face_data
, name_by_color
, width
, height
)
20 yield from draw_lines(tile
, face_data
, width
, height
)
24 def header(width
, height
):
25 yield "%!PS-Adobe-3.0 EPSF-3.0\n"
26 yield f
"%%Creator: Blender {bpy.app.version_string}\n"
28 yield "%%Orientation: Portrait\n"
29 yield f
"%%BoundingBox: 0 0 {width} {height}\n"
30 yield f
"%%HiResBoundingBox: 0.0 0.0 {width:.4f} {height:.4f}\n"
31 yield "%%EndComments\n"
33 yield "0 0 translate\n"
34 yield "1.0 1.0 scale\n"
35 yield "0 0 0 setrgbcolor\n"
36 yield "[] 0 setdash\n"
37 yield "1 setlinewidth\n"
38 yield "1 setlinejoin\n"
39 yield "1 setlinecap\n"
42 def prepare_colors(colors
, out_name_by_color
):
43 for i
, color
in enumerate(colors
):
46 out_name_by_color
[color
] = name
49 yield "%.3g %.3g %.3g setrgbcolor\n" % color
56 def draw_colored_polygons(tile
, face_data
, name_by_color
, width
, height
):
57 for uvs
, color
in face_data
:
58 yield from draw_polygon_path(tile
, uvs
, width
, height
)
60 yield "%s\n" % name_by_color
[color
]
63 def draw_lines(tile
, face_data
, width
, height
):
64 for uvs
, _
in face_data
:
65 yield from draw_polygon_path(tile
, uvs
, width
, height
)
70 def draw_polygon_path(tile
, uvs
, width
, height
):
72 for j
, uv
in enumerate(uvs
):
73 uv_scale
= ((uv
[0] - tile
[0]) * width
, (uv
[1] - tile
[1]) * height
)
75 yield "%.5f %.5f moveto\n" % uv_scale
77 yield "%.5f %.5f lineto\n" % uv_scale