[Bf-extensions-cvs] [8049697] temp-freestyle-svg: remove annotations (not really standardized yet)
Campbell Barton
noreply at git.blender.org
Mon Nov 24 23:22:04 CET 2014
Commit: 804969703c4286c73bb0e985fb774f16e087682d
Author: Campbell Barton
Date: Mon Nov 24 23:21:43 2014 +0100
Branches: temp-freestyle-svg
https://developer.blender.org/rBA804969703c4286c73bb0e985fb774f16e087682d
remove annotations (not really standardized yet)
===================================================================
M render_freestyle_svg.py
===================================================================
diff --git a/render_freestyle_svg.py b/render_freestyle_svg.py
index 31e29f8..32c63c9 100644
--- a/render_freestyle_svg.py
+++ b/render_freestyle_svg.py
@@ -32,6 +32,7 @@ bl_info = {
import bpy
import parameter_editor
+import itertools
import xml.etree.cElementTree as et
@@ -55,22 +56,14 @@ from freestyle.chainingiterators import ChainPredicateIterator
from parameter_editor import get_dashed_pattern
from bpy.props import (
- StringProperty,
BoolProperty,
EnumProperty,
PointerProperty,
)
from bpy.app.handlers import persistent
-
-from itertools import repeat, dropwhile
from collections import OrderedDict
from mathutils import Vector
-# register namespaces
-et.register_namespace("", "http://www.w3.org/2000/svg")
-et.register_namespace("inkscape", "http://www.inkscape.org/namespaces/inkscape")
-et.register_namespace("sodipodi", "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd")
-
# use utf-8 here to keep ElementTree happy, end result is utf-16
svg_primitive = """<?xml version="1.0" encoding="ascii" standalone="no"?>
@@ -84,12 +77,16 @@ namespaces = {
"svg": "http://www.w3.org/2000/svg",
}
-def render_height(scene) -> int:
- """Calculates the scene height in pixels"""
+
+def render_height(scene):
return int(scene.render.resolution_y * scene.render.resolution_percentage / 100)
-def create_path(scene) -> str:
+def render_width(scene):
+ return int(scene.render.resolution_x * scene.render.resolution_percentage / 100)
+
+
+def create_path(scene):
"""Creates the output path for the svg file"""
# current frame if rendering a single frame
# start frame when rendering an animation
@@ -121,7 +118,7 @@ class SVGExport(bpy.types.PropertyGroup):
),
default='FRAME',
)
- linejoin = EnumProperty(
+ line_join_type = EnumProperty(
name="Linejoin",
items=(
('MITTER', "Mitter", "Corners are sharp", 0),
@@ -150,7 +147,7 @@ class SVGExporterPanel(bpy.types.Panel):
svg = scene.svg_export
freestyle = scene.render.layers.active.freestyle_settings
- layout.active = svg.use_svg_export and freestyle.mode != 'SCRIPT'
+ layout.active = (svg.use_svg_export and freestyle.mode != 'SCRIPT')
row = layout.row()
row.prop(svg, "mode", expand=True)
@@ -160,7 +157,7 @@ class SVGExporterPanel(bpy.types.Panel):
row.prop(svg, "object_fill")
row = layout.row()
- row.prop(svg, "linejoin", expand=True)
+ row.prop(svg, "line_join_type", expand=True)
@persistent
@@ -171,11 +168,9 @@ def svg_export_header(scene):
if not (render.use_freestyle and scene.svg_export.use_svg_export):
return
- width, height = Vector((render.resolution_x, render.resolution_y)) * render.resolution_percentage / 100
-
# this may fail still. The error is printed to the console.
with open(create_path(scene), "w") as f:
- f.write(svg_primitive.format(int(width), int(height)))
+ f.write(svg_primitive.format(render_width(scene), render_height(scene)))
@persistent
@@ -188,7 +183,7 @@ def svg_export_animation(scene):
write_animation(create_path(scene), scene.frame_start, render.fps)
-def write_animation(filepath, frame_begin, fps=25):
+def write_animation(filepath, frame_begin, fps):
"""Adds animate tags to the specified file."""
tree = et.parse(filepath)
root = tree.getroot()
@@ -198,7 +193,7 @@ def write_animation(filepath, frame_begin, fps=25):
name = lineset.get('id')
frames = lineset.findall(".//svg:g[@inkscape:groupmode='frame']", namespaces=namespaces)
fills = lineset.findall(".//svg:g[@inkscape:groupmode='fills']", namespaces=namespaces)
- fills = reversed(fills) if fills else repeat(None, len(frames))
+ fills = reversed(fills) if fills else itertools.repeat(None, len(frames))
print("-" * 10, "animate", "-" * 10)
@@ -261,7 +256,7 @@ class SVGPathShader(StrokeShader):
'stroke-linecap': linestyle.caps.lower(),
'stroke-opacity': linestyle.alpha,
'stroke': 'rgb({}, {}, {})'.format(*(int(c * 255) for c in linestyle.color)),
- 'stroke-linejoin': svg.linejoin.lower(),
+ 'stroke-linejoin': svg.line_join_type.lower(),
}
# get dashed line pattern (if specified)
if linestyle.use_dashed_line:
@@ -282,7 +277,7 @@ class SVGPathShader(StrokeShader):
# end current and start new path;
yield '" />' + path
# fast-forward till the next visible vertex
- it = dropwhile(f, it)
+ it = itertools.dropwhile(f, it)
# yield next visible vertex
svert = next(it, None)
if svert is None:
@@ -403,19 +398,19 @@ class SVGFillShader(StrokeShader):
# - Callbacks - #
class ParameterEditorCallback(object):
"""Object to store callbacks for the Parameter Editor in"""
- def lineset_pre(self, scene, layer, lineset) -> None:
+ def lineset_pre(self, scene, layer, lineset):
raise NotImplementedError()
- def modifier_post(self, scene, layer, lineset) -> [StrokeShader, ]:
+ def modifier_post(self, scene, layer, lineset):
raise NotImplementedError()
- def lineset_post(self, scene, layer, lineset) -> None:
+ def lineset_post(self, scene, layer, lineset):
raise NotImplementedError()
class SVGPathShaderCallback(ParameterEditorCallback):
@classmethod
- def modifier_post(cls, scene, layer, lineset) -> [StrokeShader, ]:
+ def modifier_post(cls, scene, layer, lineset):
if not (scene.render.use_freestyle and scene.svg_export.use_svg_export):
return
@@ -435,7 +430,7 @@ class SVGPathShaderCallback(ParameterEditorCallback):
class SVGFillShaderCallback(ParameterEditorCallback):
@staticmethod
- def lineset_post(scene, layer, lineset) -> None:
+ def lineset_post(scene, layer, lineset):
if not (scene.render.use_freestyle and scene.svg_export.use_svg_export and scene.svg_export.object_fill):
return
@@ -492,6 +487,11 @@ def register():
parameter_editor.callbacks_lineset_post.append(SVGPathShaderCallback.lineset_post)
parameter_editor.callbacks_lineset_post.append(SVGFillShaderCallback.lineset_post)
+ # register namespaces
+ et.register_namespace("", "http://www.w3.org/2000/svg")
+ et.register_namespace("inkscape", "http://www.inkscape.org/namespaces/inkscape")
+ et.register_namespace("sodipodi", "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd")
+
def unregister():
More information about the Bf-extensions-cvs
mailing list