[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17049] branches/etch-a-ton/source/blender : First draft for converting sketches to armature.

Martin Poirier theeth at yahoo.com
Sun Oct 12 19:33:03 CEST 2008


Revision: 17049
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17049
Author:   theeth
Date:     2008-10-12 19:33:03 +0200 (Sun, 12 Oct 2008)

Log Message:
-----------
First draft for converting sketches to armature.

- New Convert button in the bone sketching float panel
- Only adds straight bones between exact points (not continuous strokes) for now.

Modified Paths:
--------------
    branches/etch-a-ton/source/blender/include/BIF_editarmature.h
    branches/etch-a-ton/source/blender/include/BIF_sketch.h
    branches/etch-a-ton/source/blender/src/drawview.c
    branches/etch-a-ton/source/blender/src/editarmature.c
    branches/etch-a-ton/source/blender/src/editarmature_sketch.c

Modified: branches/etch-a-ton/source/blender/include/BIF_editarmature.h
===================================================================
--- branches/etch-a-ton/source/blender/include/BIF_editarmature.h	2008-10-12 15:35:17 UTC (rev 17048)
+++ branches/etch-a-ton/source/blender/include/BIF_editarmature.h	2008-10-12 17:33:03 UTC (rev 17049)
@@ -68,6 +68,7 @@
 
 } EditBone;
 
+EditBone *addEditBone(char *name, struct ListBase *ebones, struct bArmature *arm);
 
 void	adduplicate_armature(void);
 void	addvert_armature(void);

Modified: branches/etch-a-ton/source/blender/include/BIF_sketch.h
===================================================================
--- branches/etch-a-ton/source/blender/include/BIF_sketch.h	2008-10-12 15:35:17 UTC (rev 17048)
+++ branches/etch-a-ton/source/blender/include/BIF_sketch.h	2008-10-12 17:33:03 UTC (rev 17049)
@@ -24,5 +24,6 @@
 #define BIF_SKETCH_H
 
 int BIF_paintSketch();
+void BIF_convertSketch();
 
 #endif /* BIF_SKETCH_H */

Modified: branches/etch-a-ton/source/blender/src/drawview.c
===================================================================
--- branches/etch-a-ton/source/blender/src/drawview.c	2008-10-12 15:35:17 UTC (rev 17048)
+++ branches/etch-a-ton/source/blender/src/drawview.c	2008-10-12 17:33:03 UTC (rev 17049)
@@ -130,6 +130,7 @@
 #include "BIF_resources.h"
 #include "BIF_retopo.h"
 #include "BIF_screen.h"
+#include "BIF_sketch.h"
 #include "BIF_space.h"
 
 #ifdef WITH_VERSE
@@ -2268,11 +2269,16 @@
 	if(yco < 0) uiNewPanelHeight(block, height-yco);
 }
 
+static void convert_sketch_armature(void *arg1, void *arg2)
+{
+	BIF_convertSketch();
+}
+
 static void view3d_panel_bonesketch_spaces(short cntrl)
 {
 	uiBlock *block;
-//	uiBut *but;
-	int xco = 20, yco = 70, height = 140;
+	uiBut *but;
+	int yco = 70, height = 140;
 //	int index;
 
 	/* replace with check call to sketching lib */
@@ -2290,6 +2296,8 @@
 		
 		/* use real flag instead of 1 */
 		uiDefButBitI(block, TOG, 1, B_REDR, "Use Bone Sketching", 10, 225, 150, 20, &G.bone_sketching, 0, 0, 0, 0, "Use sketching to create and edit bones");
+		but = uiDefBut(block, BUT, B_REDR, "Convert Sketch", 10,205,150,20, 0, 0, 0, 0, 0, "Convert sketch to armature");
+		uiButSetFunc(but, convert_sketch_armature, NULL, NULL);
 	
 		uiBlockEndAlign(block);
 		

Modified: branches/etch-a-ton/source/blender/src/editarmature.c
===================================================================
--- branches/etch-a-ton/source/blender/src/editarmature.c	2008-10-12 15:35:17 UTC (rev 17048)
+++ branches/etch-a-ton/source/blender/src/editarmature.c	2008-10-12 17:33:03 UTC (rev 17049)
@@ -1969,17 +1969,14 @@
 /* **************** END EditMode stuff ********************** */
 /* *************** Adding stuff in editmode *************** */
 
-/* default bone add, returns it selected, but without tail set */
-static EditBone *add_editbone(char *name)
+EditBone *addEditBone(char *name, ListBase *ebones, bArmature *arm)
 {
-	bArmature *arm= G.obedit->data;
-	
 	EditBone *bone= MEM_callocN(sizeof(EditBone), "eBone");
 	
 	BLI_strncpy(bone->name, name, 32);
-	unique_editbone_name(&G.edbo, bone->name);
+	unique_editbone_name(ebones, bone->name);
 	
-	BLI_addtail(&G.edbo, bone);
+	BLI_addtail(ebones, bone);
 	
 	bone->flag |= BONE_TIPSEL;
 	bone->weight= 1.0F;
@@ -1996,6 +1993,14 @@
 	return bone;
 }
 
+/* default bone add, returns it selected, but without tail set */
+static EditBone *add_editbone(char *name)
+{
+	bArmature *arm= G.obedit->data;
+	
+	return addEditBone(name, &G.edbo, arm);
+}
+
 static void add_primitive_bone(Object *ob, short newob)
 {
 	float		obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3];

Modified: branches/etch-a-ton/source/blender/src/editarmature_sketch.c
===================================================================
--- branches/etch-a-ton/source/blender/src/editarmature_sketch.c	2008-10-12 15:35:17 UTC (rev 17048)
+++ branches/etch-a-ton/source/blender/src/editarmature_sketch.c	2008-10-12 17:33:03 UTC (rev 17049)
@@ -883,7 +883,60 @@
 	dd->previous_mval[1] = -1;
 	dd->type = PT_EXACT;
 }
+/********************************************/
 
+void sk_convertStroke(SK_Stroke *stk)
+{
+	bArmature *arm= G.obedit->data;
+	SK_Point *head;
+	EditBone *parent = NULL;
+	int i;
+	
+	head = NULL;
+	
+	for (i = 0; i < stk->nb_points; i++)
+	{
+		SK_Point *pt = stk->points + i;
+		
+		if (pt->type == PT_EXACT)
+		{
+			if (head == NULL)
+			{
+				head = pt;
+			}
+			else
+			{
+				EditBone *bone;
+				
+				bone = addEditBone("Bone", &G.edbo, arm);
+				
+				VECCOPY(bone->head, head->p);
+				VECCOPY(bone->tail, pt->p);
+				
+				if (parent != NULL)
+				{
+					bone->parent = parent;
+					bone->flag |= BONE_CONNECTED;					
+				}
+				
+				parent = bone;
+				head = pt;
+			}
+		}
+	}
+}
+
+void sk_convert(SK_Sketch *sketch)
+{
+	SK_Stroke *stk;
+	
+	for (stk = sketch->strokes.first; stk; stk = stk->next)
+	{
+		sk_convertStroke(stk);
+	}
+	
+	BLI_freelistN(&sketch->strokes);
+}
 /********************************************/
 
 void sk_queueRedrawSketch(SK_Sketch *sketch)
@@ -1047,6 +1100,17 @@
 	}
 }
 
+void BIF_convertSketch()
+{
+	if (G.bone_sketching & 1)
+	{
+		if (GLOBAL_sketch != NULL)
+		{
+			sk_convert(GLOBAL_sketch);
+		}
+	}
+}
+
 int BIF_paintSketch(short mbut)
 {
 	if (G.bone_sketching & 1)





More information about the Bf-blender-cvs mailing list