[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55443] trunk/blender/source/blender: add option to convert grease pencil into poly line directly.

Campbell Barton ideasman42 at gmail.com
Wed Mar 20 16:01:16 CET 2013


Revision: 55443
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55443
Author:   campbellbarton
Date:     2013-03-20 15:01:15 +0000 (Wed, 20 Mar 2013)
Log Message:
-----------
add option to convert grease pencil into poly line directly.

Without this, bezier curves at 12 resolution are very high detail for many tasks when converted from freehand strokes.
so add the option to convert 1:1 grease pencil points to curve polygons.

also add use_handles option to curve conversion which is used when converting beziers to poly lines.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_curve.h
    trunk/blender/source/blender/blenkernel/intern/curve.c
    trunk/blender/source/blender/editors/curve/editcurve.c
    trunk/blender/source/blender/editors/gpencil/gpencil_edit.c
    trunk/blender/source/blender/editors/include/ED_curve.h
    trunk/blender/source/blender/makesrna/intern/rna_curve.c

Modified: trunk/blender/source/blender/blenkernel/BKE_curve.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_curve.h	2013-03-20 13:58:03 UTC (rev 55442)
+++ trunk/blender/source/blender/blenkernel/BKE_curve.h	2013-03-20 15:01:15 UTC (rev 55443)
@@ -124,6 +124,7 @@
 bool BKE_nurb_order_clamp_v(struct Nurb *nu);
 
 void BKE_nurb_direction_switch(struct Nurb *nu);
+bool BKE_nurb_type_convert(struct Nurb *nu, const short type, const bool use_handles);
 
 void BKE_nurb_points_add(struct Nurb *nu, int number);
 void BKE_nurb_bezierPoints_add(struct Nurb *nu, int number);

Modified: trunk/blender/source/blender/blenkernel/intern/curve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/curve.c	2013-03-20 13:58:03 UTC (rev 55442)
+++ trunk/blender/source/blender/blenkernel/intern/curve.c	2013-03-20 15:01:15 UTC (rev 55443)
@@ -3393,6 +3393,144 @@
 	return change;
 }
 
+bool BKE_nurb_type_convert(Nurb *nu, const short type, const bool use_handles)
+{
+	BezTriple *bezt;
+	BPoint *bp;
+	int a, c, nr;
+
+	if (nu->type == CU_POLY) {
+		if (type == CU_BEZIER) {  /* to Bezier with vecthandles  */
+			nr = nu->pntsu;
+			bezt = (BezTriple *)MEM_callocN(nr * sizeof(BezTriple), "setsplinetype2");
+			nu->bezt = bezt;
+			a = nr;
+			bp = nu->bp;
+			while (a--) {
+				copy_v3_v3(bezt->vec[1], bp->vec);
+				bezt->f1 = bezt->f2 = bezt->f3 = bp->f1;
+				bezt->h1 = bezt->h2 = HD_VECT;
+				bezt->weight = bp->weight;
+				bezt->radius = bp->radius;
+				bp++;
+				bezt++;
+			}
+			MEM_freeN(nu->bp);
+			nu->bp = NULL;
+			nu->pntsu = nr;
+			nu->type = CU_BEZIER;
+			BKE_nurb_handles_calc(nu);
+		}
+		else if (type == CU_NURBS) {
+			nu->type = CU_NURBS;
+			nu->orderu = 4;
+			nu->flagu &= CU_NURB_CYCLIC; /* disable all flags except for cyclic */
+			BKE_nurb_knot_calc_u(nu);
+			a = nu->pntsu * nu->pntsv;
+			bp = nu->bp;
+			while (a--) {
+				bp->vec[3] = 1.0;
+				bp++;
+			}
+		}
+	}
+	else if (nu->type == CU_BEZIER) {   /* Bezier */
+		if (type == CU_POLY || type == CU_NURBS) {
+			nr = use_handles ? (3 * nu->pntsu) : nu->pntsu;
+			nu->bp = MEM_callocN(nr * sizeof(BPoint), "setsplinetype");
+			a = nu->pntsu;
+			bezt = nu->bezt;
+			bp = nu->bp;
+			while (a--) {
+				if ((type == CU_POLY && bezt->h1 == HD_VECT && bezt->h2 == HD_VECT) || (use_handles == false)) {
+					/* vector handle becomes 1 poly vertice */
+					copy_v3_v3(bp->vec, bezt->vec[1]);
+					bp->vec[3] = 1.0;
+					bp->f1 = bezt->f2;
+					if (use_handles) nr -= 2;
+					bp->radius = bezt->radius;
+					bp->weight = bezt->weight;
+					bp++;
+				}
+				else {
+					char *f = &bezt->f1;
+					for (c = 0; c < 3; c++, f++) {
+						copy_v3_v3(bp->vec, bezt->vec[c]);
+						bp->vec[3] = 1.0;
+						bp->f1 = *f;
+						bp->radius = bezt->radius;
+						bp->weight = bezt->weight;
+						bp++;
+					}
+				}
+				bezt++;
+			}
+			MEM_freeN(nu->bezt);
+			nu->bezt = NULL;
+			nu->pntsu = nr;
+			nu->pntsv = 1;
+			nu->orderu = 4;
+			nu->orderv = 1;
+			nu->type = type;
+
+#if 0       /* UNUSED */
+			if (nu->flagu & CU_NURB_CYCLIC) c = nu->orderu - 1;
+			else c = 0;
+#endif
+
+			if (type == CU_NURBS) {
+				nu->flagu &= CU_NURB_CYCLIC; /* disable all flags except for cyclic */
+				nu->flagu |= CU_NURB_BEZIER;
+				BKE_nurb_knot_calc_u(nu);
+			}
+		}
+	}
+	else if (nu->type == CU_NURBS) {
+		if (type == CU_POLY) {
+			nu->type = CU_POLY;
+			if (nu->knotsu) MEM_freeN(nu->knotsu);  /* python created nurbs have a knotsu of zero */
+			nu->knotsu = NULL;
+			if (nu->knotsv) MEM_freeN(nu->knotsv);
+			nu->knotsv = NULL;
+		}
+		else if (type == CU_BEZIER) {     /* to Bezier */
+			nr = nu->pntsu / 3;
+
+			if (nr < 2) {
+				return false;  /* conversion impossible */
+			}
+			else {
+				bezt = MEM_callocN(nr * sizeof(BezTriple), "setsplinetype2");
+				nu->bezt = bezt;
+				a = nr;
+				bp = nu->bp;
+				while (a--) {
+					copy_v3_v3(bezt->vec[0], bp->vec);
+					bezt->f1 = bp->f1;
+					bp++;
+					copy_v3_v3(bezt->vec[1], bp->vec);
+					bezt->f2 = bp->f1;
+					bp++;
+					copy_v3_v3(bezt->vec[2], bp->vec);
+					bezt->f3 = bp->f1;
+					bezt->radius = bp->radius;
+					bezt->weight = bp->weight;
+					bp++;
+					bezt++;
+				}
+				MEM_freeN(nu->bp);
+				nu->bp = NULL;
+				MEM_freeN(nu->knotsu);
+				nu->knotsu = NULL;
+				nu->pntsu = nr;
+				nu->type = CU_BEZIER;
+			}
+		}
+	}
+
+	return true;
+}
+
 /* Get edit nurbs or normal nurbs list */
 ListBase *BKE_curve_nurbs_get(Curve *cu)
 {

Modified: trunk/blender/source/blender/editors/curve/editcurve.c
===================================================================
--- trunk/blender/source/blender/editors/curve/editcurve.c	2013-03-20 13:58:03 UTC (rev 55442)
+++ trunk/blender/source/blender/editors/curve/editcurve.c	2013-03-20 15:01:15 UTC (rev 55443)
@@ -3387,156 +3387,14 @@
 
 /***************** set spline type operator *******************/
 
-static int convertspline(short type, Nurb *nu)
-{
-	BezTriple *bezt;
-	BPoint *bp;
-	int a, c, nr;
-
-	if (nu->type == CU_POLY) {
-		if (type == CU_BEZIER) {  /* to Bezier with vecthandles  */
-			nr = nu->pntsu;
-			bezt = (BezTriple *)MEM_callocN(nr * sizeof(BezTriple), "setsplinetype2");
-			nu->bezt = bezt;
-			a = nr;
-			bp = nu->bp;
-			while (a--) {
-				copy_v3_v3(bezt->vec[1], bp->vec);
-				bezt->f1 = bezt->f2 = bezt->f3 = bp->f1;
-				bezt->h1 = bezt->h2 = HD_VECT;
-				bezt->weight = bp->weight;
-				bezt->radius = bp->radius;
-				bp++;
-				bezt++;
-			}
-			MEM_freeN(nu->bp);
-			nu->bp = NULL;
-			nu->pntsu = nr;
-			nu->type = CU_BEZIER;
-			BKE_nurb_handles_calc(nu);
-		}
-		else if (type == CU_NURBS) {
-			nu->type = CU_NURBS;
-			nu->orderu = 4;
-			nu->flagu &= CU_NURB_CYCLIC; /* disable all flags except for cyclic */
-			BKE_nurb_knot_calc_u(nu);
-			a = nu->pntsu * nu->pntsv;
-			bp = nu->bp;
-			while (a--) {
-				bp->vec[3] = 1.0;
-				bp++;
-			}
-		}
-	}
-	else if (nu->type == CU_BEZIER) {   /* Bezier */
-		if (type == CU_POLY || type == CU_NURBS) {
-			nr = 3 * nu->pntsu;
-			nu->bp = MEM_callocN(nr * sizeof(BPoint), "setsplinetype");
-			a = nu->pntsu;
-			bezt = nu->bezt;
-			bp = nu->bp;
-			while (a--) {
-				if (type == CU_POLY && bezt->h1 == HD_VECT && bezt->h2 == HD_VECT) {
-					/* vector handle becomes 1 poly vertice */
-					copy_v3_v3(bp->vec, bezt->vec[1]);
-					bp->vec[3] = 1.0;
-					bp->f1 = bezt->f2;
-					nr -= 2;
-					bp->radius = bezt->radius;
-					bp->weight = bezt->weight;
-					bp++;
-				}
-				else {
-					for (c = 0; c < 3; c++) {
-						copy_v3_v3(bp->vec, bezt->vec[c]);
-						bp->vec[3] = 1.0;
-						if (c == 0) bp->f1 = bezt->f1;
-						else if (c == 1) bp->f1 = bezt->f2;
-						else bp->f1 = bezt->f3;
-						bp->radius = bezt->radius;
-						bp->weight = bezt->weight;
-						bp++;
-					}
-				}
-				bezt++;
-			}
-			MEM_freeN(nu->bezt); 
-			nu->bezt = NULL;
-			nu->pntsu = nr;
-			nu->pntsv = 1;
-			nu->orderu = 4;
-			nu->orderv = 1;
-			nu->type = type;
-
-#if 0       /* UNUSED */
-			if (nu->flagu & CU_NURB_CYCLIC) c = nu->orderu - 1;
-			else c = 0;
-#endif
-
-			if (type == CU_NURBS) {
-				nu->flagu &= CU_NURB_CYCLIC; /* disable all flags except for cyclic */
-				nu->flagu |= CU_NURB_BEZIER;
-				BKE_nurb_knot_calc_u(nu);
-			}
-		}
-	}
-	else if (nu->type == CU_NURBS) {
-		if (type == CU_POLY) {
-			nu->type = CU_POLY;
-			if (nu->knotsu) MEM_freeN(nu->knotsu);  /* python created nurbs have a knotsu of zero */
-			nu->knotsu = NULL;
-			if (nu->knotsv) MEM_freeN(nu->knotsv);
-			nu->knotsv = NULL;
-		}
-		else if (type == CU_BEZIER) {     /* to Bezier */
-			nr = nu->pntsu / 3;
-
-			if (nr < 2) {
-				return 1;  /* conversion impossible */
-			}
-			else {
-				bezt = MEM_callocN(nr * sizeof(BezTriple), "setsplinetype2");
-				nu->bezt = bezt;
-				a = nr;
-				bp = nu->bp;
-				while (a--) {
-					copy_v3_v3(bezt->vec[0], bp->vec);
-					bezt->f1 = bp->f1;
-					bp++;
-					copy_v3_v3(bezt->vec[1], bp->vec);
-					bezt->f2 = bp->f1;
-					bp++;
-					copy_v3_v3(bezt->vec[2], bp->vec);
-					bezt->f3 = bp->f1;
-					bezt->radius = bp->radius;
-					bezt->weight = bp->weight;
-					bp++;
-					bezt++;
-				}
-				MEM_freeN(nu->bp);
-				nu->bp = NULL;
-				MEM_freeN(nu->knotsu);
-				nu->knotsu = NULL;
-				nu->pntsu = nr;
-				nu->type = CU_BEZIER;
-			}
-		}
-	}
-
-	return 0;
-}
-
-void ED_nurb_set_spline_type(Nurb *nu, int type)
-{
-	convertspline(type, nu);
-}
-
 static int set_spline_type_exec(bContext *C, wmOperator *op)
 {
 	Object *obedit = CTX_data_edit_object(C);
 	ListBase *editnurb = object_editcurve_get(obedit);
 	Nurb *nu;
-	int changed = 0, type = RNA_enum_get(op->ptr, "type");
+	bool change = false;
+	const bool use_handles = RNA_boolean_get(op->ptr, "use_handles");
+	const int type = RNA_enum_get(op->ptr, "type");
 
 	if (type == CU_CARDINAL || type == CU_BSPLINE) {
 		BKE_report(op->reports, RPT_ERROR, "Not yet implemented");
@@ -3545,14 +3403,14 @@
 	
 	for (nu = editnurb->first; nu; nu = nu->next) {
 		if (isNurbsel(nu)) {
-			if (convertspline(type, nu))
+			if (BKE_nurb_type_convert(nu, type, use_handles) == false)
 				BKE_report(op->reports, RPT_ERROR, "No conversion possible");
 			else
-				changed = 1;
+				change = true;
 		}
 	}
 
-	if (changed) {
+	if (change) {
 		if (ED_curve_updateAnimPaths(obedit->data))
 			WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
 
@@ -3592,6 +3450,7 @@
 
 	/* properties */
 	ot->prop = RNA_def_enum(ot->srna, "type", type_items, CU_POLY, "Type", "Spline type");
+	RNA_def_boolean(ot->srna, "use_handles", 0, "Handles", "Use handles when converting bezier curves into polygons");
 }
 
 /***************** set handle type operator *******************/

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_edit.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_edit.c	2013-03-20 13:58:03 UTC (rev 55442)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_edit.c	2013-03-20 15:01:15 UTC (rev 55443)
@@ -63,6 +63,7 @@
 #include "BKE_library.h"
 #include "BKE_object.h"
 #include "BKE_report.h"
+#include "BKE_scene.h"
 #include "BKE_tracking.h"
 
 #include "UI_interface.h"
@@ -393,6 +394,7 @@
 enum {
 	GP_STROKECONVERT_PATH = 1,
 	GP_STROKECONVERT_CURVE,
+	GP_STROKECONVERT_POLY,
 };
 
 /* Defines for possible timing modes */
@@ -407,6 +409,7 @@
 static EnumPropertyItem prop_gpencil_convertmodes[] = {
 	{GP_STROKECONVERT_PATH, "PATH", 0, "Path", ""},
 	{GP_STROKECONVERT_CURVE, "CURVE", 0, "Bezier Curve", ""},

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list