[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40134] branches/soc-2008-mxcurioni: Implemented a calligraphic thickness modifier in the Parameter Editor mode .

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sun Sep 11 21:57:40 CEST 2011


Revision: 40134
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40134
Author:   kjym3
Date:     2011-09-11 19:57:38 +0000 (Sun, 11 Sep 2011)
Log Message:
-----------
Implemented a calligraphic thickness modifier in the Parameter Editor mode.

Also fixed a typo in the docstring of the CalligraphicShader.

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/intern/linestyle.c
    branches/soc-2008-mxcurioni/source/blender/blenloader/intern/writefile.c
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp
    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/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-09-11 16:41:03 UTC (rev 40133)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2011-09-11 19:57:38 UTC (rev 40134)
@@ -18,6 +18,7 @@
 
 import Freestyle
 import math
+import mathutils
 import time
 
 from freestyle_init import *
@@ -38,24 +39,12 @@
     def blend_ramp(self, a, b):
         return Freestyle.blendRamp(self.__blend, a, self.__influence, b)
 
-class CurveMappingModifier(StrokeShader):
-    def __init__(self, blend, influence, mapping, invert, curve):
+class ScalarBlendModifier(StrokeShader):
+    def __init__(self, blend, influence):
         StrokeShader.__init__(self)
         self.__blend = blend
         self.__influence = influence
-        assert mapping in ("LINEAR", "CURVE")
-        self.__mapping = getattr(self, mapping)
-        self.__invert = invert
-        self.__curve = curve
-    def LINEAR(self, t):
-        if self.__invert:
-            return 1.0 - t
-        return t
-    def CURVE(self, t):
-        return Freestyle.evaluateCurveMappingF(self.__curve, 0, t)
-    def evaluate(self, t):
-        return self.__mapping(t)
-    def blend_curve(self, v1, v2):
+    def blend(self, v1, v2):
         fac = self.__influence
         facm = 1.0 - fac
         if self.__blend == "MIX":
@@ -83,6 +72,22 @@
             raise ValueError("unknown curve blend type: " + self.__blend)
         return v1
 
+class CurveMappingModifier(ScalarBlendModifier):
+    def __init__(self, blend, influence, mapping, invert, curve):
+        ScalarBlendModifier.__init__(self, blend, influence)
+        assert mapping in ("LINEAR", "CURVE")
+        self.__mapping = getattr(self, mapping)
+        self.__invert = invert
+        self.__curve = curve
+    def LINEAR(self, t):
+        if self.__invert:
+            return 1.0 - t
+        return t
+    def CURVE(self, t):
+        return Freestyle.evaluateCurveMappingF(self.__curve, 0, t)
+    def evaluate(self, t):
+        return self.__mapping(t)
+
 # Along Stroke modifiers
 
 def iter_t2d_along_stroke(stroke):
@@ -117,7 +122,7 @@
             attr = it.getObject().attribute()
             a = attr.getAlpha()
             b = self.evaluate(t)
-            c = self.blend_curve(a, b)
+            c = self.blend(a, b)
             attr.setAlpha(c)
 
 class ThicknessAlongStrokeShader(CurveMappingModifier):
@@ -133,7 +138,7 @@
             a = attr.getThicknessRL()
             a = a[0] + a[1]
             b = self.__value_min + self.evaluate(t) * (self.__value_max - self.__value_min)
-            c = self.blend_curve(a, b)
+            c = self.blend(a, b)
             attr.setThickness(c/2, c/2)
 
 # Distance from Camera modifiers
@@ -180,7 +185,7 @@
             attr = it.getObject().attribute()
             a = attr.getAlpha()
             b = self.evaluate(t)
-            c = self.blend_curve(a, b)
+            c = self.blend(a, b)
             attr.setAlpha(c)
 
 class ThicknessDistanceFromCameraShader(CurveMappingModifier):
@@ -198,7 +203,7 @@
             a = attr.getThicknessRL()
             a = a[0] + a[1]
             b = self.__value_min + self.evaluate(t) * (self.__value_max - self.__value_min)
-            c = self.blend_curve(a, b)
+            c = self.blend(a, b)
             attr.setThickness(c/2, c/2)
 
 # Distance from Object modifiers
@@ -255,7 +260,7 @@
             attr = it.getObject().attribute()
             a = attr.getAlpha()
             b = self.evaluate(t)
-            c = self.blend_curve(a, b)
+            c = self.blend(a, b)
             attr.setAlpha(c)
 
 class ThicknessDistanceFromObjectShader(CurveMappingModifier):
@@ -276,7 +281,7 @@
             a = attr.getThicknessRL()
             a = a[0] + a[1]
             b = self.__value_min + self.evaluate(t) * (self.__value_max - self.__value_min)
-            c = self.blend_curve(a, b)
+            c = self.blend(a, b)
             attr.setThickness(c/2, c/2)
 
 # Material modifiers
@@ -368,7 +373,7 @@
             attr = it.getObject().attribute()
             a = attr.getAlpha()
             b = self.evaluate(t)
-            c = self.blend_curve(a, b)
+            c = self.blend(a, b)
             attr.setAlpha(c)
 
 class ThicknessMaterialShader(CurveMappingModifier):
@@ -385,9 +390,35 @@
             a = attr.getThicknessRL()
             a = a[0] + a[1]
             b = self.__value_min + self.evaluate(t) * (self.__value_max - self.__value_min)
-            c = self.blend_curve(a, b)
+            c = self.blend(a, b)
             attr.setThickness(c/2, c/2)
 
+# Calligraphic thickness modifier
+
+class CalligraphicThicknessShader(ScalarBlendModifier):
+    def __init__(self, blend, influence, orientation, min_thickness, max_thickness):
+        ScalarBlendModifier.__init__(self, blend, influence)
+        rad = orientation / 180.0 * math.pi
+        self.__orientation = mathutils.Vector((math.cos(rad), math.sin(rad)))
+        self.__min_thickness = min_thickness
+        self.__max_thickness = max_thickness
+    def shade(self, stroke):
+        func = VertexOrientation2DF0D()
+        it = stroke.strokeVerticesBegin()
+        while not it.isEnd():
+            dir = func(it.castToInterface0DIterator())
+            orthDir = mathutils.Vector((-dir.y, dir.x))
+            orthDir.normalize()
+            fac = abs(orthDir * self.__orientation)
+            attr = it.getObject().attribute()
+            a = attr.getThicknessRL()
+            a = a[0] + a[1]
+            b = self.__min_thickness + fac * (self.__max_thickness - self.__min_thickness)
+            b = max(b, 0.0)
+            c = self.blend(a, b)
+            attr.setThickness(c/2, c/2)
+            it.increment()
+
 # Geometry modifiers
 
 def iter_distance_along_stroke(stroke):
@@ -945,6 +976,10 @@
             shaders_list.append(ThicknessMaterialShader(
                 m.blend, m.influence, m.mapping, m.invert, m.curve,
                 m.material_attr, m.value_min, m.value_max))
+        elif m.type == "CALLIGRAPHY":
+            shaders_list.append(CalligraphicThicknessShader(
+                m.blend, m.influence,
+                m.orientation, m.min_thickness, m.max_thickness))
     if linestyle.caps == "ROUND":
         shaders_list.append(RoundCapShader())
     elif linestyle.caps == "SQUARE":

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-09-11 16:41:03 UTC (rev 40133)
+++ branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_render.py	2011-09-11 19:57:38 UTC (rev 40134)
@@ -446,6 +446,12 @@
                 box.prop(modifier, "material_attr", text="")
                 self.draw_modifier_curve_common(box, modifier, False, True)
 
+            elif modifier.type == "CALLIGRAPHY":
+                col = box.column()
+                col.prop(modifier, "orientation")
+                col.prop(modifier, "min_thickness")
+                col.prop(modifier, "max_thickness")
+
     def draw_geometry_modifier(self, context, modifier):
         layout = self.layout
 

Modified: branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/linestyle.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/linestyle.c	2011-09-11 16:41:03 UTC (rev 40133)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/linestyle.c	2011-09-11 19:57:38 UTC (rev 40134)
@@ -60,7 +60,8 @@
 	"Perlin Noise 1D",
 	"Perlin Noise 2D",
 	"Backbone Stretcher",
-	"Tip Remover"};
+	"Tip Remover",
+	"Calligraphy"};
 
 static void default_linestyle_settings(FreestyleLineStyle *linestyle)
 {
@@ -286,6 +287,9 @@
 	case LS_MODIFIER_MATERIAL:
 		size = sizeof(LineStyleThicknessModifier_Material);
 		break;
+	case LS_MODIFIER_CALLIGRAPHY:
+		size = sizeof(LineStyleThicknessModifier_Calligraphy);
+		break;
 	default:
 		return -1; /* unknown modifier type */
 	}
@@ -320,6 +324,11 @@
 		((LineStyleThicknessModifier_Material *)m)->value_min = 0.0f;
 		((LineStyleThicknessModifier_Material *)m)->value_max = 1.0f;
 		break;
+	case LS_MODIFIER_CALLIGRAPHY:
+		((LineStyleThicknessModifier_Calligraphy *)m)->min_thickness = 1.0f;
+		((LineStyleThicknessModifier_Calligraphy *)m)->max_thickness = 10.0f;
+		((LineStyleThicknessModifier_Calligraphy *)m)->orientation = 60.0f;
+		break;
 	}
 	add_to_modifier_list(&linestyle->thickness_modifiers, m);
 
@@ -341,6 +350,8 @@
 	case LS_MODIFIER_MATERIAL:
 		curvemapping_free(((LineStyleThicknessModifier_Material *)m)->curve);
 		break;
+	case LS_MODIFIER_CALLIGRAPHY:
+		break;
 	}
 	BLI_freelinkN(&linestyle->thickness_modifiers, m);
 }

Modified: branches/soc-2008-mxcurioni/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenloader/intern/writefile.c	2011-09-11 16:41:03 UTC (rev 40133)
+++ branches/soc-2008-mxcurioni/source/blender/blenloader/intern/writefile.c	2011-09-11 19:57:38 UTC (rev 40134)
@@ -2621,6 +2621,9 @@
 		case LS_MODIFIER_MATERIAL:
 			struct_name = "LineStyleThicknessModifier_Material";
 			break;
+		case LS_MODIFIER_CALLIGRAPHY:
+			struct_name = "LineStyleThicknessModifier_Calligraphy";
+			break;
 		default:
 			struct_name = "LineStyleThicknessModifier"; // this should not happen
 		}

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp	2011-09-11 16:41:03 UTC (rev 40133)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp	2011-09-11 19:57:38 UTC (rev 40134)
@@ -21,7 +21,7 @@
 "   Builds a CalligraphicShader object.\n"
 "\n"
 "   :arg iMinThickness: The minimum thickness in the direction\n"
-"      perpandicular to the main direction.\n"
+"      perpendicular to the main direction.\n"
 "   :type iMinThickness: float\n"

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list