Skip to content
Snippets Groups Projects
Select Git revision
  • ed8e7e5579fa49e1db71546b8ae5202de52edde6
  • master default protected
  • main
  • test-refactor-server-json
  • blender-v4.1-release
  • blender-v4.0-release
  • blender-v3.6-release
  • blender-v3.3-release
  • blender-v2.93-release
  • blender-v3.5-release
  • blender-v3.1-release
  • blender-v3.0-release
  • blender-v3.4-release
  • blender-v3.2-release
  • studio-sprite-fright
  • blender-v2.92-release
  • blender-v2.91-release
  • greasepencil-addon
  • blender-v2.90-release
  • blender-v2.83-release
  • blender-v2.82-release
  • v3.6.9
  • v3.3.16
  • v4.1.0
  • v4.1.1
  • v3.6.8
  • v3.3.15
  • v3.6.7
  • v3.3.14
  • v4.0.2
  • v4.0.1
  • v4.0.0
  • v3.6.5
  • v3.3.12
  • v3.6.4
  • v3.6.3
  • v3.3.11
  • v3.6.2
  • v3.3.10
  • v3.6.1
  • v3.3.9
41 results

mesh_face_info_select.py

Blame
  • export_uv_svg.py 2.39 KiB
    # ##### 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 #####
    
    # <pep8 compliant>
    
    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('<?xml version="1.0" standalone="no"?>\n')
        fw('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" \n')
        fw('  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')
        fw('<svg width="%dpx" height="%dpx" viewBox="0px 0px %dpx %dpx"\n' % (image_width, image_height, image_width, image_height))
        fw('     xmlns="http://www.w3.org/2000/svg" version="1.1">\n')
        desc = "%r, %s, (Blender %s)" % (basename(bpy.data.filepath), mesh.name, bpy.app.version_string)
        fw('<desc>%s</desc>\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('<polygon stroke="black" stroke-width="1px"')
            if opacity > 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('</svg>\n')