Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tamito KAJIYAMA <19 August 2009>
- from freestyle_init import *
- from logical_operators import *
- from shaders import *
- import bpy
- import os
- _HEADER = """\
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
- "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
- <svg xml:space="default" width="%d" height="%d">
- """
- _PATH = """\
- <path fill="none" stroke="%s" stroke-width="%d" d="M %s" />
- """
- _FOOTER = """\
- </svg>
- """
- class SVGWriter(StrokeShader):
- def __init__(self, f, w, h):
- StrokeShader.__init__(self)
- self.width, self.height = w, h
- self.file = f
- self.file.write(_HEADER % (w, h))
- def close(self):
- self.file.write(_FOOTER)
- self.file.close()
- def shade(self, stroke):
- points = []
- for v in stroke:
- x, y = v.getPoint2D()
- points.append("%.3f,%.3f" % (x, self.height - y))
- points = " ".join(points)
- attr = v.attribute()
- r, g, b = attr.getColorRGB() * 255
- color = "#%02x%02x%02x" % (r, g, b)
- width = attr.getThicknessRL()
- width = width[0] + width[1]
- self.file.write(_PATH % (color, width, points))
- import Freestyle
- scene = Freestyle.getCurrentScene()
- start_frame = scene.frame_start
- current_frame = scene.frame_current
- frame_step = scene.frame_step
- fps = scene.render.fps
- output_dir = bpy.path.abspath(scene.render.filepath)
- if not os.path.exists(output_dir):
- os.makedirs(output_dir)
- path = os.path.join(output_dir, "output%06d.svg" % current_frame)
- f = open(path, "wt")
- w = scene.render.resolution_x
- h = scene.render.resolution_y
- upred = QuantitativeInvisibilityUP1D(0)
- Operators.select(upred)
- Operators.bidirectionalChain(ChainSilhouetteIterator(), NotUP1D(upred))
- writer = SVGWriter(f, w, h)
- shaders_list = [
- #ConstantThicknessShader(0.2),
- pyDepthDiscontinuityThicknessShader(1, 4),
- ConstantColorShader(0, 0, 0),
- #pyMaterialColorShader(0.5),
- writer,
- ]
- Operators.create(TrueUP1D(), shaders_list)
- writer.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement