[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43109] branches/soc-2008-mxcurioni: Added two stroke geometry modifiers:

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Wed Jan 4 01:23:41 CET 2012


Revision: 43109
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43109
Author:   kjym3
Date:     2012-01-04 00:23:34 +0000 (Wed, 04 Jan 2012)
Log Message:
-----------
Added two stroke geometry modifiers:
- 2D Offset: Adds two-dimensional offsets to stroke backbone geometry.
- 2D Transform: Applies two-dimensional scaling and rotation to stroke backbone geometry.

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/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	2012-01-03 22:27:30 UTC (rev 43108)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/parameter_editor.py	2012-01-04 00:23:34 UTC (rev 43109)
@@ -493,6 +493,94 @@
             it.increment()
         stroke.UpdateLength()
 
+class Offset2DShader(StrokeShader):
+    def __init__(self, start, end, x, y):
+        StrokeShader.__init__(self)
+        self.__start = start
+        self.__end = end
+        self.__xy = Vector([x, y])
+        self.__getNormal = Normal2DF0D()
+    def getName(self):
+        return "Offset2DShader"
+    def shade(self, stroke):
+        it = stroke.strokeVerticesBegin()
+        while not it.isEnd():
+            v = it.getObject()
+            u = v.u()
+            a = self.__start + u * (self.__end - self.__start)
+            n = self.__getNormal(it.castToInterface0DIterator())
+            n = n * a
+            p = v.getPoint()
+            v.setPoint(p + n + self.__xy)
+            it.increment()
+        stroke.UpdateLength()
+
+class Transform2DShader(StrokeShader):
+    def __init__(self, pivot, scale_x, scale_y, angle, pivot_u, pivot_x, pivot_y):
+        StrokeShader.__init__(self)
+        self.__pivot = pivot
+        self.__scale_x = scale_x
+        self.__scale_y = scale_y
+        self.__angle = angle
+        self.__pivot_u = pivot_u
+        self.__pivot_x = pivot_x
+        self.__pivot_y = pivot_y
+    def getName(self):
+        return "Transform2DShader"
+    def shade(self, stroke):
+        # determine the pivot of scaling and rotation operations
+        if self.__pivot == "START":
+            it = stroke.strokeVerticesBegin()
+            pivot = it.getObject().getPoint()
+        elif self.__pivot == "END":
+            it = stroke.strokeVerticesEnd()
+            it.decrement()
+            pivot = it.getObject().getPoint()
+        elif self.__pivot == "PARAM":
+            p = None
+            it = stroke.strokeVerticesBegin()
+            while not it.isEnd():
+                prev = p
+                v = it.getObject()
+                p = v.getPoint()
+                u = v.u()
+                if self.__pivot_u < u:
+                    break
+                it.increment()
+            if prev is None:
+                pivot = p
+            else:
+                delta = u - self.__pivot_u
+                pivot = p + delta * (prev - p)
+        elif self.__pivot == "CENTER":
+            pivot = Vector([0.0, 0.0])
+            n = 0
+            it = stroke.strokeVerticesBegin()
+            while not it.isEnd():
+                p = it.getObject().getPoint()
+                pivot = pivot + p
+                n = n + 1
+                it.increment()
+            pivot.x = pivot.x / n
+            pivot.y = pivot.y / n
+        elif self.__pivot == "ABSOLUTE":
+            pivot = Vector([self.__pivot_x, self.__pivot_y])
+        # apply scaling and rotation operations
+        cos_theta = math.cos(math.pi * self.__angle / 180.0)
+        sin_theta = math.sin(math.pi * self.__angle / 180.0)
+        it = stroke.strokeVerticesBegin()
+        while not it.isEnd():
+            v = it.getObject()
+            p = v.getPoint()
+            p = p - pivot
+            x = p.x * self.__scale_x
+            y = p.y * self.__scale_y
+            p.x = x * cos_theta - y * sin_theta
+            p.y = x * sin_theta + y * cos_theta
+            v.setPoint(p + pivot)
+            it.increment()
+        stroke.UpdateLength()
+
 # Predicates and helper functions
 
 class QuantitativeInvisibilityRangeUP1D(UnaryPredicate1D):
@@ -1035,6 +1123,12 @@
             elif m.shape == "SQUARES":
                 shaders_list.append(pyBluePrintSquaresShader(
                     m.rounds, m.backbone_length, m.random_backbone))
+        elif m.type == "2D_OFFSET":
+            shaders_list.append(Offset2DShader(
+                m.start, m.end, m.x, m.y))
+        elif m.type == "2D_TRANSFORM":
+            shaders_list.append(Transform2DShader(
+                m.pivot, m.scale_x, m.scale_y, m.angle, m.pivot_u, m.pivot_x, m.pivot_y))
     color = linestyle.color
     shaders_list.append(ConstantColorShader(color.r, color.g, color.b, linestyle.alpha))
     shaders_list.append(ConstantThicknessShader(linestyle.thickness))

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	2012-01-03 22:27:30 UTC (rev 43108)
+++ branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_render.py	2012-01-04 00:23:34 UTC (rev 43109)
@@ -571,6 +571,27 @@
                     box.prop(modifier, "backbone_length")
                     box.prop(modifier, "random_backbone")
 
+            elif modifier.type == "2D_OFFSET":
+                row = box.row(align=True)
+                row.prop(modifier, "start")
+                row.prop(modifier, "end")
+                row = box.row(align=True)
+                row.prop(modifier, "x")
+                row.prop(modifier, "y")
+
+            elif modifier.type == "2D_TRANSFORM":
+                box.prop(modifier, "pivot")
+                if modifier.pivot == "PARAM":
+                    box.prop(modifier, "pivot_u")
+                elif modifier.pivot == "ABSOLUTE":
+                    row = box.row(align=True)
+                    row.prop(modifier, "pivot_x")
+                    row.prop(modifier, "pivot_y")
+                row = box.row(align=True)
+                row.prop(modifier, "scale_x")
+                row.prop(modifier, "scale_y")
+                box.prop(modifier, "angle")
+
     def draw(self, context):
         layout = self.layout
 

Modified: branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/linestyle.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/linestyle.c	2012-01-03 22:27:30 UTC (rev 43108)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/linestyle.c	2012-01-04 00:23:34 UTC (rev 43109)
@@ -65,7 +65,9 @@
 	"Calligraphy",
 	"Polygonalization",
 	"Guiding Lines",
-	"Blueprint"};
+	"Blueprint",
+	"2D Offset",
+	"2D Transform"};
 
 static void default_linestyle_settings(FreestyleLineStyle *linestyle)
 {
@@ -636,6 +638,12 @@
 	case LS_MODIFIER_BLUEPRINT:
 		size = sizeof(LineStyleGeometryModifier_Blueprint);
 		break;
+	case LS_MODIFIER_2D_OFFSET:
+		size = sizeof(LineStyleGeometryModifier_2DOffset);
+		break;
+	case LS_MODIFIER_2D_TRANSFORM:
+		size = sizeof(LineStyleGeometryModifier_2DTransform);
+		break;
 	default:
 		return NULL; /* unknown modifier type */
 	}
@@ -699,6 +707,21 @@
 		((LineStyleGeometryModifier_Blueprint *)m)->random_center = 5;
 		((LineStyleGeometryModifier_Blueprint *)m)->random_backbone = 5;
 		break;
+	case LS_MODIFIER_2D_OFFSET:
+		((LineStyleGeometryModifier_2DOffset *)m)->start = 0.f;
+		((LineStyleGeometryModifier_2DOffset *)m)->end = 0.f;
+		((LineStyleGeometryModifier_2DOffset *)m)->x = 0.f;
+		((LineStyleGeometryModifier_2DOffset *)m)->y = 0.f;
+		break;
+	case LS_MODIFIER_2D_TRANSFORM:
+		((LineStyleGeometryModifier_2DTransform *)m)->pivot = LS_MODIFIER_2D_TRANSFORM_PIVOT_CENTER;
+		((LineStyleGeometryModifier_2DTransform *)m)->scale_x = 1.f;
+		((LineStyleGeometryModifier_2DTransform *)m)->scale_y = 1.f;
+		((LineStyleGeometryModifier_2DTransform *)m)->angle = 0.f;
+		((LineStyleGeometryModifier_2DTransform *)m)->pivot_u = 0.5f;
+		((LineStyleGeometryModifier_2DTransform *)m)->pivot_x = 0.f;
+		((LineStyleGeometryModifier_2DTransform *)m)->pivot_y = 0.f;
+		break;
 	default:
 		return NULL; /* unknown modifier type */
 	}
@@ -798,6 +821,27 @@
 			((LineStyleGeometryModifier_Blueprint *)new_m)->random_backbone = p->random_backbone;
 		}
 		break;
+	case LS_MODIFIER_2D_OFFSET:
+		{
+			LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m;
+			((LineStyleGeometryModifier_2DOffset *)new_m)->start = p->start;
+			((LineStyleGeometryModifier_2DOffset *)new_m)->end = p->end;
+			((LineStyleGeometryModifier_2DOffset *)new_m)->x = p->x;
+			((LineStyleGeometryModifier_2DOffset *)new_m)->y = p->y;
+		}
+		break;
+	case LS_MODIFIER_2D_TRANSFORM:
+		{
+			LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m;
+			((LineStyleGeometryModifier_2DTransform *)new_m)->pivot = p->pivot;
+			((LineStyleGeometryModifier_2DTransform *)new_m)->scale_x = p->scale_x;
+			((LineStyleGeometryModifier_2DTransform *)new_m)->scale_y = p->scale_y;
+			((LineStyleGeometryModifier_2DTransform *)new_m)->angle = p->angle;
+			((LineStyleGeometryModifier_2DTransform *)new_m)->pivot_u = p->pivot_u;
+			((LineStyleGeometryModifier_2DTransform *)new_m)->pivot_x = p->pivot_x;
+			((LineStyleGeometryModifier_2DTransform *)new_m)->pivot_y = p->pivot_y;
+		}
+		break;
 	default:
 		return NULL; /* unknown modifier type */
 	}
@@ -831,6 +875,10 @@
 		break;
 	case LS_MODIFIER_BLUEPRINT:
 		break;
+	case LS_MODIFIER_2D_OFFSET:
+		break;
+	case LS_MODIFIER_2D_TRANSFORM:
+		break;
 	}
 	BLI_freelinkN(&linestyle->geometry_modifiers, m);
 }

Modified: branches/soc-2008-mxcurioni/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenloader/intern/writefile.c	2012-01-03 22:27:30 UTC (rev 43108)
+++ branches/soc-2008-mxcurioni/source/blender/blenloader/intern/writefile.c	2012-01-04 00:23:34 UTC (rev 43109)
@@ -2761,6 +2761,12 @@
 		case LS_MODIFIER_BLUEPRINT:
 			struct_name = "LineStyleGeometryModifier_Blueprint";
 			break;
+		case LS_MODIFIER_2D_OFFSET:
+			struct_name = "LineStyleGeometryModifier_2DOffset";
+			break;
+		case LS_MODIFIER_2D_TRANSFORM:
+			struct_name = "LineStyleGeometryModifier_2DTransform";
+			break;
 		default:
 			struct_name = "LineStyleGeometryModifier"; // this should not happen
 		}

Modified: branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_linestyle_types.h
===================================================================

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list