[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16998] branches/etch-a-ton/source/blender /src/editarmature_sketch.c: - Filter continuous strokes as they are drawn instead of only when ending a line .

Martin Poirier theeth at yahoo.com
Thu Oct 9 23:39:26 CEST 2008


Revision: 16998
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16998
Author:   theeth
Date:     2008-10-09 23:39:26 +0200 (Thu, 09 Oct 2008)

Log Message:
-----------
- Filter continuous strokes as they are drawn instead of only when ending a line.
- Pair depth hits per object, to stay consistent if you have an object instead another one (say, if you're drawing on a coat and at one point the hand starts, you don't want to pair the first hit on the coat with the first hit on the hand).

Modified Paths:
--------------
    branches/etch-a-ton/source/blender/src/editarmature_sketch.c

Modified: branches/etch-a-ton/source/blender/src/editarmature_sketch.c
===================================================================
--- branches/etch-a-ton/source/blender/src/editarmature_sketch.c	2008-10-09 20:45:33 UTC (rev 16997)
+++ branches/etch-a-ton/source/blender/src/editarmature_sketch.c	2008-10-09 21:39:26 UTC (rev 16998)
@@ -102,6 +102,7 @@
 	float depth;
 	float p[3];
 	float no[3];
+	Object *ob;
 } SK_DepthPeel;
 
 int cmpPeel(void *arg1, void *arg2)
@@ -122,11 +123,12 @@
 	return val;
 }
 
-void addDepthPeel(ListBase *depth_peels, float depth, float p[3], float no[3])
+void addDepthPeel(ListBase *depth_peels, float depth, float p[3], float no[3], Object *ob)
 {
 	SK_DepthPeel *peel = MEM_callocN(sizeof(SK_DepthPeel), "DepthPeel");
 	
 	peel->depth = depth;
+	peel->ob = ob;
 	VECCOPY(peel->p, p);
 	VECCOPY(peel->no, no);
 	
@@ -201,7 +203,7 @@
 					Mat3MulVecfl(timat, normal);
 					Normalize(normal);
 
-					addDepthPeel(depth_peels, new_depth, location, normal);
+					addDepthPeel(depth_peels, new_depth, location, normal, ob);
 				}
 		
 				if (f->v4 && result == 0)
@@ -231,7 +233,7 @@
 						Mat3MulVecfl(timat, normal);
 						Normalize(normal);
 	
-						addDepthPeel(depth_peels, new_depth, location, normal);
+						addDepthPeel(depth_peels, new_depth, location, normal, ob);
 					} 
 				}
 			}
@@ -394,17 +396,29 @@
 
 /* Apply reverse Chaikin filter to simplify the polyline
  * */
-void sk_filterStroke(SK_Stroke *stk)
+void sk_filterStroke(SK_Stroke *stk, int start, int end)
 {
 	SK_Point *old_points = stk->points;
 	int nb_points = stk->nb_points;
 	int i, j;
 	
+	if (start == -1)
+	{
+		start = 0;
+		end = stk->nb_points - 1;
+	}
+
 	sk_allocStrokeBuffer(stk);
 	stk->nb_points = 0;
 	
-	for (i = 0, j = 0; i < nb_points; i++)
+	/* adding points before range */
+	for (i = 0; i < start; i++)
 	{
+		sk_appendStrokePoint(stk, old_points + i);
+	}
+	
+	for (i = start, j = start; i <= end; i++)
+	{
 		if (i - j == 3)
 		{
 			SK_Point pt;
@@ -436,6 +450,7 @@
 			j += 2;
 		}
 		
+		/* this might be uneeded when filtering last continuous stroke */
 		if (old_points[i].type == PT_EXACT)
 		{
 			sk_appendStrokePoint(stk, old_points + i);
@@ -443,11 +458,34 @@
 		}
 	} 
 	
+	/* adding points after range */
+	for (i = end + 1; i < nb_points; i++)
+	{
+		sk_appendStrokePoint(stk, old_points + i);
+	}
+
 	MEM_freeN(old_points);
 
 	sk_shrinkStrokeBuffer(stk);
 }
 
+void sk_filterLastContinuousStroke(SK_Stroke *stk)
+{
+	int start, end;
+	
+	end = stk->nb_points -1;
+	
+	for (start = end - 1; start > 0 && stk->points[start].type == PT_CONTINUOUS; start--)
+	{
+		/* nothing to do here*/
+	}
+	
+	if (end - start > 1)
+	{
+		sk_filterStroke(stk, start, end);
+	}
+}
+
 SK_Point *sk_lastStrokePoint(SK_Stroke *stk)
 {
 	SK_Point *pt = NULL;
@@ -690,8 +728,12 @@
 		
 		pt.type = dd->type;
 
-		p2 = p1->next;
+		for (p2 = p1->next; p2 && p2->ob != p1->ob; p2 = p2->next)
+		{
+			/* nothing to do here */
+		}
 		
+		
 		if (p2)
 		{
 			VecAddf(pt.p, p1->p, p2->p);
@@ -873,12 +915,12 @@
 		} while (get_mbut() & LEFTMOUSE);
 		
 		sk_endContinuousStroke(sketch->active_stroke);
+		sk_filterLastContinuousStroke(sketch->active_stroke);
 	}
 	else if (mbut == RIGHTMOUSE)
 	{
 		if (sketch->active_stroke != NULL)
 		{
-			sk_filterStroke(sketch->active_stroke);
 			sk_endStroke(sketch);
 			allqueue(REDRAWVIEW3D, 0);
 		}





More information about the Bf-blender-cvs mailing list