diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2011-08-19 18:05:11 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2011-08-19 18:05:11 +0400 |
commit | 6bc5d5258f78963bdefe10a5ed9124b552d6be6c (patch) | |
tree | a415cecaec9946e69154134d6121de7f2afb0d9a /release | |
parent | aece060cbff344083a4bea01c480ed891cefdd7e (diff) |
Stroke geometry modifiers
Added a set of stroke geometry modifiers to the Geometry tab of line styles
in the Parameter Editor mode. Now the following stroke geometry modifiers are
available, each with a set of animateable parameters:
- Sampling: changes the resolution of stroke backbone polylines.
- Bezier Curve: replace stroke backbone with a Bezier approximation of the
stroke backbone.
- Sinus Displacement: add sinus displacement to stroke backbone.
- Spatial Noise: add spatial noise to stroke backbone.
- Perlin Noise 1D: add one-dimensional Perlin noise to stroke backbone.
- Perlin Noise 2D: add two-dimensional Perlin noise to stroke backbone.
- Backbone Stretcher: stretch the beginning and the end of strokes.
- Tip Remover: remove a piece of stroke at the beginning and the end of strokes.
To branch users: When you have a .blend file with Freestyle options specified,
you may want to add a Sampling modifier with the 'sampling' value set to 5.
This value specifies a resolution of polylines for line drawing in Freestyle.
If no sampling modifier is specified, your line drawing will result in coarse
polylines. Before geometry modifiers were introduced, this initial sampling
was automatically done. Now the initial sampling is a tunable parameter that
can be omitted, allowing better control on polyline resolution.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/freestyle/style_modules/parameter_editor.py | 88 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/properties_render.py | 145 |
2 files changed, 178 insertions, 55 deletions
diff --git a/release/scripts/freestyle/style_modules/parameter_editor.py b/release/scripts/freestyle/style_modules/parameter_editor.py index c86ed2fab33..ef53f363b10 100644 --- a/release/scripts/freestyle/style_modules/parameter_editor.py +++ b/release/scripts/freestyle/style_modules/parameter_editor.py @@ -18,6 +18,7 @@ import Freestyle import math +import time from freestyle_init import * from logical_operators import * @@ -387,6 +388,37 @@ class ThicknessMaterialShader(CurveMappingModifier): c = self.blend_curve(a, b) attr.setThickness(c/2, c/2) +# Geometry modifiers + +def iter_distance_along_stroke(stroke): + distance = 0.0 + it = stroke.strokeVerticesBegin() + while not it.isEnd(): + p = it.getObject().getPoint() + if not it.isBegin(): + distance += (prev - p).length + prev = p + yield it, distance + it.increment() + +class SinusDisplacementShader(StrokeShader): + def __init__(self, wavelength, amplitude, phase): + StrokeShader.__init__(self) + self._wavelength = wavelength + self._amplitude = amplitude + self._phase = phase / wavelength * 2 * math.pi + self._getNormal = Normal2DF0D() + def getName(self): + return "SinusDisplacementShader" + def shade(self, stroke): + for it, distance in iter_distance_along_stroke(stroke): + v = it.getObject() + n = self._getNormal(it.castToInterface0DIterator()) + p = v.getPoint() + u = v.u() + n = n * self._amplitude * math.cos(distance / self._wavelength * 2 * math.pi + self._phase) + v.setPoint(p + n) + # Predicates and helper functions class QuantitativeInvisibilityRangeUP1D(UnaryPredicate1D): @@ -653,6 +685,20 @@ class MaterialBoundaryUP0D(UnaryPredicate0D): idx2 = fe.materialIndex() if fe.isSmooth() else fe.bMaterialIndex() return idx1 != idx2 +# Seed for random number generation + +class Seed: + def __init__(self): + self.t_max = 2 ** 15 + self.t = int(time.time()) % self.t_max + def get(self, seed): + if seed < 0: + self.t = (self.t + 1) % self.t_max + return self.t + return seed + +_seed = Seed() + # main function for parameter processing def process(layer_name, lineset_name): @@ -773,11 +819,41 @@ def process(layer_name, lineset_name): if linestyle.material_boundary: Operators.sequentialSplit(MaterialBoundaryUP0D()) # prepare a list of stroke shaders + shaders_list = [] + for m in linestyle.geometry_modifiers: + if not m.use: + continue + if m.type == "SAMPLING": + shaders_list.append(SamplingShader( + m.sampling)) + elif m.type == "BEZIER_CURVE": + shaders_list.append(BezierCurveShader( + m.error)) + elif m.type == "SINUS_DISPLACEMENT": + shaders_list.append(SinusDisplacementShader( + m.wavelength, m.amplitude, m.phase)) + elif m.type == "SPATIAL_NOISE": + shaders_list.append(SpatialNoiseShader( + m.amplitude, m.scale, m.octaves, m.smooth, m.pure_random)) + elif m.type == "PERLIN_NOISE_1D": + shaders_list.append(pyPerlinNoise1DShader( + m.frequency, m.amplitude, m.octaves, _seed.get(m.seed))) + elif m.type == "PERLIN_NOISE_2D": + shaders_list.append(pyPerlinNoise2DShader( + m.frequency, m.amplitude, m.octaves, _seed.get(m.seed))) + elif m.type == "BACKBONE_STRETCHER": + shaders_list.append(BackboneStretcherShader( + m.amount)) + elif m.type == "TIP_REMOVER": + shaders_list.append(TipRemoverShader( + m.tip_length)) + if linestyle.caps == "ROUND": + shaders_list.append(RoundCapShader()) + elif linestyle.caps == "SQUARE": + shaders_list.append(SquareCapShader()) color = linestyle.color - shaders_list = [ - SamplingShader(5.0), - ConstantThicknessShader(linestyle.thickness), - ConstantColorShader(color.r, color.g, color.b, linestyle.alpha)] + shaders_list.append(ConstantColorShader(color.r, color.g, color.b, linestyle.alpha)) + shaders_list.append(ConstantThicknessShader(linestyle.thickness)) for m in linestyle.color_modifiers: if not m.use: continue @@ -833,9 +909,5 @@ def process(layer_name, lineset_name): shaders_list.append(ThicknessMaterialShader( m.blend, m.influence, m.mapping, m.invert, m.curve, m.material_attr, m.value_min, m.value_max)) - if linestyle.caps == "ROUND": - shaders_list.append(RoundCapShader()) - elif linestyle.caps == "SQUARE": - shaders_list.append(SquareCapShader()) # create strokes using the shaders list Operators.create(TrueUP1D(), shaders_list) diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py index 647455af03c..2c0ded20672 100644 --- a/release/scripts/startup/bl_ui/properties_render.py +++ b/release/scripts/startup/bl_ui/properties_render.py @@ -437,6 +437,51 @@ class RENDER_PT_freestyle_linestyle(RenderButtonsPanel, Panel): box.prop(modifier, "material_attr", text="") self.draw_modifier_curve_common(box, modifier, False, True) + def draw_geometry_modifier(self, context, modifier): + layout = self.layout + + col = layout.column(align=True) + self.draw_modifier_box_header(col.box(), modifier) + if modifier.expanded: + box = col.box() + + if modifier.type == "SAMPLING": + box.prop(modifier, "sampling") + + elif modifier.type == "BEZIER_CURVE": + box.prop(modifier, "error") + + elif modifier.type == "SINUS_DISPLACEMENT": + box.prop(modifier, "wavelength") + box.prop(modifier, "amplitude") + box.prop(modifier, "phase") + + elif modifier.type == "SPATIAL_NOISE": + box.prop(modifier, "amplitude") + box.prop(modifier, "scale") + box.prop(modifier, "octaves") + sub = box.row() + sub.prop(modifier, "smooth") + sub.prop(modifier, "pure_random") + + elif modifier.type == "PERLIN_NOISE_1D": + box.prop(modifier, "frequency") + box.prop(modifier, "amplitude") + box.prop(modifier, "octaves") + box.prop(modifier, "seed") + + elif modifier.type == "PERLIN_NOISE_2D": + box.prop(modifier, "frequency") + box.prop(modifier, "amplitude") + box.prop(modifier, "octaves") + box.prop(modifier, "seed") + + elif modifier.type == "BACKBONE_STRETCHER": + box.prop(modifier, "amount") + + elif modifier.type == "TIP_REMOVER": + box.prop(modifier, "tip_length") + def draw(self, context): layout = self.layout @@ -445,70 +490,76 @@ class RENDER_PT_freestyle_linestyle(RenderButtonsPanel, Panel): lineset = rl.freestyle_settings.linesets.active linestyle = lineset.linestyle - split = layout.split() - col = split.column() - col.template_ID(lineset, "linestyle", new="scene.freestyle_linestyle_new") - - col.separator() - sub = col.row(align=True) - sub.prop(linestyle, "panel", expand=True) - - if linestyle.panel == "COLOR": + layout.template_ID(lineset, "linestyle", new="scene.freestyle_linestyle_new") + row = layout.row(align=True) + row.prop(linestyle, "panel", expand=True) + if linestyle.panel == "STROKES": + col = layout.column() + col.label(text="Chaining:") + col.prop(linestyle, "same_object") + col = layout.column() + col.label(text="Splitting:") + row = col.row(align=True) + row.prop(linestyle, "material_boundary") + col = layout.column() + col.label(text="Caps:") + row = col.row(align=True) + row.prop(linestyle, "caps", expand=True) + col = layout.column() + col.prop(linestyle, "use_dashed_line") + split = col.split() + split.enabled = linestyle.use_dashed_line + sub = split.column() + sub.label(text="Dash") + sub.prop(linestyle, "dash1", text="") + sub = split.column() + sub.label(text="Gap") + sub.prop(linestyle, "gap1", text="") + sub = split.column() + sub.label(text="Dash") + sub.prop(linestyle, "dash2", text="") + sub = split.column() + sub.label(text="Gap") + sub.prop(linestyle, "gap2", text="") + sub = split.column() + sub.label(text="Dash") + sub.prop(linestyle, "dash3", text="") + sub = split.column() + sub.label(text="Gap") + sub.prop(linestyle, "gap3", text="") + elif linestyle.panel == "COLOR": + col = layout.column() col.label(text="Base Color:") col.prop(linestyle, "color", text="") + col = layout.column() col.label(text="Modifiers:") - layout.operator_menu_enum("scene.freestyle_color_modifier_add", "type", text="Add Modifier") + col.operator_menu_enum("scene.freestyle_color_modifier_add", "type", text="Add Modifier") for modifier in linestyle.color_modifiers: self.draw_color_modifier(context, modifier) elif linestyle.panel == "ALPHA": + col = layout.column() col.label(text="Base Transparency:") col.prop(linestyle, "alpha") + col = layout.column() col.label(text="Modifiers:") - layout.operator_menu_enum("scene.freestyle_alpha_modifier_add", "type", text="Add Modifier") + col.operator_menu_enum("scene.freestyle_alpha_modifier_add", "type", text="Add Modifier") for modifier in linestyle.alpha_modifiers: self.draw_alpha_modifier(context, modifier) elif linestyle.panel == "THICKNESS": + col = layout.column() col.label(text="Base Thickness:") col.prop(linestyle, "thickness") + col = layout.column() col.label(text="Modifiers:") - layout.operator_menu_enum("scene.freestyle_thickness_modifier_add", "type", text="Add Modifier") + col.operator_menu_enum("scene.freestyle_thickness_modifier_add", "type", text="Add Modifier") for modifier in linestyle.thickness_modifiers: self.draw_thickness_modifier(context, modifier) - elif linestyle.panel == "STROKES": - col.label(text="Chaining:") - col.prop(linestyle, "same_object") - col.separator() - col.label(text="Splitting:") - sub = col.row(align=True) - sub.prop(linestyle, "material_boundary") - col.separator() - col.label(text="Caps:") - sub = col.row(align=True) - sub.prop(linestyle, "caps", expand=True) - col.separator() - col.prop(linestyle, "use_dashed_line") - sub = col.row() - sub.enabled = linestyle.use_dashed_line - subsub = sub.column() - subsub.label(text="Dash") - subsub.prop(linestyle, "dash1", text="") - subsub = sub.column() - subsub.label(text="Gap") - subsub.prop(linestyle, "gap1", text="") - subsub = sub.column() - subsub.label(text="Dash") - subsub.prop(linestyle, "dash2", text="") - subsub = sub.column() - subsub.label(text="Gap") - subsub.prop(linestyle, "gap2", text="") - subsub = sub.column() - subsub.label(text="Dash") - subsub.prop(linestyle, "dash3", text="") - subsub = sub.column() - subsub.label(text="Gap") - subsub.prop(linestyle, "gap3", text="") - elif linestyle.panel == "DISTORT": - pass + elif linestyle.panel == "GEOMETRY": + col = layout.column() + col.label(text="Modifiers:") + col.operator_menu_enum("scene.freestyle_geometry_modifier_add", "type", text="Add Modifier") + for modifier in linestyle.geometry_modifiers: + self.draw_geometry_modifier(context, modifier) elif linestyle.panel == "MISC": pass |