~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons/io_mesh_uv_layout/export_uv_eps.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ##### BEGIN GPL LICENSE BLOCK #####
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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.
 
16
#
 
17
# ##### END GPL LICENSE BLOCK #####
 
18
 
 
19
# <pep8-80 compliant>
 
20
 
 
21
import bpy
 
22
 
 
23
 
 
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")
 
41
 
 
42
    polys = mesh.polygons
 
43
 
 
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")
 
58
 
 
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)
 
68
 
 
69
            fw("closepath\n")
 
70
            fw("DRAW_%d\n" % polys[i].material_index)
 
71
 
 
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)
 
81
 
 
82
        fw("closepath\n")
 
83
        fw("stroke\n")
 
84
 
 
85
    fw("showpage\n")
 
86
    fw("%%EOF\n")