render_freestyle_svg.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:bpy_lambda 作者: bcongdon 项目源码 文件源码
def pathgen(stroke, style, height, split_at_invisible, stroke_color_mode, f=lambda v: not v.attribute.visible):
        """Generator that creates SVG paths (as strings) from the current stroke """
        if len(stroke) <= 1:
            return ""

        if stroke_color_mode != 'BASE':
            # try to use the color of the first or last vertex
            try:
                index = 0 if stroke_color_mode == 'FIRST' else -1
                color = format_rgb(stroke[index].attribute.color)
                style["stroke"] = color
            except (ValueError, IndexError):
                # default is linestyle base color
                pass

        # put style attributes into a single svg path definition
        path = '\n<path ' + "".join('{}="{}" '.format(k, v) for k, v in style.items()) + 'd=" M '

        it = iter(stroke)
        # start first path
        yield path
        for v in it:
            x, y = v.point
            yield '{:.3f}, {:.3f} '.format(x, height - y)
            if split_at_invisible and v.attribute.visible is False:
                # end current and start new path;
                yield '" />' + path
                # fast-forward till the next visible vertex
                it = itertools.dropwhile(f, it)
                # yield next visible vertex
                svert = next(it, None)
                if svert is None:
                    break
                x, y = svert.point
                yield '{:.3f}, {:.3f} '.format(x, height - y)
        # close current path
        yield '" />'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号