[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39553] branches/soc-2008-mxcurioni: Stroke geometry modifiers

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Fri Aug 19 16:05:11 CEST 2011


Revision: 39553
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39553
Author:   kjym3
Date:     2011-08-19 14:05:11 +0000 (Fri, 19 Aug 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
    branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_render.py
    branches/soc-2008-mxcurioni/source/blender/blenkernel/BKE_linestyle.h
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/linestyle.c
    branches/soc-2008-mxcurioni/source/blender/blenloader/intern/readfile.c
    branches/soc-2008-mxcurioni/source/blender/blenloader/intern/writefile.c
    branches/soc-2008-mxcurioni/source/blender/editors/render/render_intern.h
    branches/soc-2008-mxcurioni/source/blender/editors/render/render_ops.c
    branches/soc-2008-mxcurioni/source/blender/editors/render/render_shading.c
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_linestyle_types.h
    branches/soc-2008-mxcurioni/source/blender/makesrna/RNA_access.h
    branches/soc-2008-mxcurioni/source/blender/makesrna/RNA_enum_types.h
    branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_linestyle.c

Modified: branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2011-08-19 13:41:11 UTC (rev 39552)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2011-08-19 14:05:11 UTC (rev 39553)
@@ -18,6 +18,7 @@
 
 import Freestyle
 import math
+import time
 
 from freestyle_init import *
 from logical_operators import *
@@ -387,6 +388,37 @@
             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 @@
         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 @@
     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 @@
             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)

Modified: branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_render.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_render.py	2011-08-19 13:41:11 UTC (rev 39552)
+++ branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_render.py	2011-08-19 14:05:11 UTC (rev 39553)
@@ -437,6 +437,51 @@
                 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 @@
         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:")

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list