[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17536] branches/etch-a-ton/source/blender : Cache the armature template graph while in editmode.

Martin Poirier theeth at yahoo.com
Sat Nov 22 18:58:49 CET 2008


Revision: 17536
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17536
Author:   theeth
Date:     2008-11-22 18:58:49 +0100 (Sat, 22 Nov 2008)

Log Message:
-----------
Cache the armature template graph while in editmode.
Display the number of joints in the selected template in the sketch panel
When using selected bones as template, turn off Connected if bone has a parent that is not copied.

Modified Paths:
--------------
    branches/etch-a-ton/source/blender/include/BIF_retarget.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_retarget.c
    branches/etch-a-ton/source/blender/src/editarmature_sketch.c

Modified: branches/etch-a-ton/source/blender/include/BIF_retarget.h
===================================================================
--- branches/etch-a-ton/source/blender/include/BIF_retarget.h	2008-11-22 15:10:47 UTC (rev 17535)
+++ branches/etch-a-ton/source/blender/include/BIF_retarget.h	2008-11-22 17:58:49 UTC (rev 17536)
@@ -31,6 +31,9 @@
 
 #include "reeb.h"
 
+struct Object;
+struct bArmature;
+
 struct EditBone;
 
 struct RigJoint;
@@ -65,7 +68,7 @@
 	GHash *bones_map;	/* map of editbones by name */
 	GHash *controls_map;	/* map of rigcontrols by bone pointer */
 	
-	Object *ob;
+	struct Object *ob;
 } RigGraph;
 
 typedef struct RigNode {
@@ -109,7 +112,7 @@
 	float length;
 	float angle; /* angle to next edge */
 	float up_angle; /* angle between up_axis and the joint normal (defined as Previous edge CrossProduct Current edge */
-	EditBone *bone;
+	struct EditBone *bone;
 	float up_axis[3];
 } RigEdge;
 
@@ -132,9 +135,9 @@
 typedef struct RigControl {
 	struct RigControl *next, *prev;
 	float head[3], tail[3];
-	EditBone *bone;
-	EditBone *link;
-	EditBone *link_tail;
+	struct EditBone *bone;
+	struct EditBone *link;
+	struct EditBone *link_tail;
 	float	up_axis[3];
 	float	offset[3];
 	float	qrot[4]; /* for dual linked bones, store the rotation of the linked bone for the finalization */
@@ -142,6 +145,9 @@
 	LinkTailMode tail_mode;
 } RigControl;
 
-void BIF_retargetArc(ReebArc *earc);
+void BIF_retargetArc(ReebArc *earc, RigGraph *template_rigg);
+RigGraph *RIG_graphFromArmature(struct Object *ob, struct bArmature *arm);
+int RIG_nbJoints(RigGraph *rg);
+void RIG_freeRigGraph(BGraph *rg);
 
 #endif /* BIF_RETARGET_H */

Modified: branches/etch-a-ton/source/blender/include/BIF_sketch.h
===================================================================
--- branches/etch-a-ton/source/blender/include/BIF_sketch.h	2008-11-22 15:10:47 UTC (rev 17535)
+++ branches/etch-a-ton/source/blender/include/BIF_sketch.h	2008-11-22 17:58:49 UTC (rev 17536)
@@ -36,6 +36,7 @@
 char *BIF_listTemplates();
 int   BIF_currentTemplate();
 void  BIF_freeTemplates();
-void  BIF_setTemplate(int);	
+void  BIF_setTemplate(int);
+int   BIF_nbJointsTemplate();	
 
 #endif /* BIF_SKETCH_H */

Modified: branches/etch-a-ton/source/blender/src/drawview.c
===================================================================
--- branches/etch-a-ton/source/blender/src/drawview.c	2008-11-22 15:10:47 UTC (rev 17535)
+++ branches/etch-a-ton/source/blender/src/drawview.c	2008-11-22 17:58:49 UTC (rev 17536)
@@ -2291,10 +2291,11 @@
 static void view3d_panel_bonesketch_spaces(short cntrl)
 {
 	static int template_index;
+	static char joint_label[32];
 	uiBlock *block;
 	uiBut *but;
 	int yco = 70, height = 140;
-//	int index;
+	int nb_joints;
 
 	/* replace with check call to sketching lib */
 	if (G.obedit && G.obedit->type == OB_ARMATURE)
@@ -2366,11 +2367,23 @@
 		uiDefBut(block, TEX,0,"S:",							10,  yco, 90, 20, G.scene->toolsettings->skgen_side_string, 0.0, 8.0, 0, 0, "Text to replace &S with");
 		uiDefBut(block, TEX,0,"N:",							100, yco, 90, 20, G.scene->toolsettings->skgen_num_string, 0.0, 8.0, 0, 0, "Text to replace &N with");
 		uiDefIconButBitC(block, TOG, SK_RETARGET_AUTONAME, B_DIFF, ICON_AUTO,190,yco,20,20, &G.scene->toolsettings->skgen_retarget_options, 0, 0, 0, 0, "Use Auto Naming");	
+		yco -= 20;
 
 		/* auto renaming magic */
-
 		uiBlockEndAlign(block);
+		
+		nb_joints = BIF_nbJointsTemplate();
 
+		if (nb_joints == -1)
+		{
+			nb_joints = G.totvertsel;
+		}
+		
+		BLI_snprintf(joint_label, 32, "%i joints", nb_joints);
+		
+		uiDefBut(block, LABEL, 1, joint_label,					10, yco, 200, 20, NULL, 0.0, 0.0, 0, 0, "");
+		
+
 		if(yco < 0) uiNewPanelHeight(block, height-yco);
 	}
 }

Modified: branches/etch-a-ton/source/blender/src/editarmature.c
===================================================================
--- branches/etch-a-ton/source/blender/src/editarmature.c	2008-11-22 15:10:47 UTC (rev 17535)
+++ branches/etch-a-ton/source/blender/src/editarmature.c	2008-11-22 17:58:49 UTC (rev 17536)
@@ -1740,6 +1740,8 @@
 	if (!arm) return;
 	
 	make_boneList(&G.edbo, &arm->bonebase,NULL);
+	
+	BIF_freeTemplates(); /* force template update when entering editmode */
 }
 
 /* put EditMode back in Object */

Modified: branches/etch-a-ton/source/blender/src/editarmature_retarget.c
===================================================================
--- branches/etch-a-ton/source/blender/src/editarmature_retarget.c	2008-11-22 15:10:47 UTC (rev 17535)
+++ branches/etch-a-ton/source/blender/src/editarmature_retarget.c	2008-11-22 17:58:49 UTC (rev 17536)
@@ -613,12 +613,22 @@
 				EditBone *bone;
 				
 				updateDuplicateSubtargetObjects(edge->bone, src->editbones, src->ob, rg->ob);
-				
-				bone = BLI_ghash_lookup(ptr_hash, edge->bone->parent);
-	
-				if (bone != NULL)
-				{
-					edge->bone->parent = bone;
+
+				if (edge->bone->parent)
+				{				
+					bone = BLI_ghash_lookup(ptr_hash, edge->bone->parent);
+		
+					if (bone != NULL)
+					{
+						edge->bone->parent = bone;
+					}
+					else
+					{
+						/* disconnect since parent isn't cloned
+						 * this will only happen when cloning from selected bones 
+						 * */
+						edge->bone->flag &= ~BONE_CONNECTED;
+					}
 				}
 			}
 		}
@@ -630,11 +640,21 @@
 		
 		updateDuplicateSubtargetObjects(ctrl->bone, src->editbones, src->ob, rg->ob);
 
-		bone = BLI_ghash_lookup(ptr_hash, ctrl->bone->parent);
-		
-		if (bone != NULL)
+		if (ctrl->bone->parent)
 		{
-			ctrl->bone->parent = bone;
+			bone = BLI_ghash_lookup(ptr_hash, ctrl->bone->parent);
+			
+			if (bone != NULL)
+			{
+				ctrl->bone->parent = bone;
+			}
+			else
+			{
+				/* disconnect since parent isn't cloned
+				 * this will only happen when cloning from selected bones 
+				 * */
+				ctrl->bone->flag &= ~BONE_CONNECTED;
+			}
 		}
 
 		ctrl->link = BLI_ghash_lookup(ptr_hash, ctrl->link);
@@ -1507,7 +1527,7 @@
 
 /*******************************************************************************************************/
 
-RigGraph *armatureToGraph(Object *ob, bArmature *arm)
+RigGraph *RIG_graphFromArmature(Object *ob, bArmature *arm)
 {
 	EditBone *ebone;
 	RigGraph *rg;
@@ -2958,6 +2978,20 @@
 	editbones_to_armature(rigg->editbones, rigg->ob);
 }
 
+int RIG_nbJoints(RigGraph *rg)
+{
+	RigArc *arc;
+	int total = 0;
+	
+	total += BLI_countlist(&rg->nodes);
+	
+	for (arc = rg->arcs.first; arc; arc = arc->next)
+	{
+		total += BLI_countlist(&arc->edges) - 1; /* -1 because end nodes are already counted */
+	}
+	
+	return total;
+}
 
 void BIF_retargetArmature()
 {
@@ -2995,7 +3029,7 @@
 			
 				start_time = PIL_check_seconds_timer();
 	
-				rigg = armatureToGraph(ob, arm);
+				rigg = RIG_graphFromArmature(ob, arm);
 				
 				end_time = PIL_check_seconds_timer();
 				rig_time = end_time - start_time;
@@ -3040,20 +3074,17 @@
 	allqueue(REDRAWVIEW3D, 0);
 }
 
-void BIF_retargetArc(ReebArc *earc)
+void BIF_retargetArc(ReebArc *earc, RigGraph *template_rigg)
 {
 	Object *ob;
-	RigGraph *template_rigg;
 	RigGraph *rigg;
 	RigArc *iarc;
 	bArmature *arm;
 	
-	if (G.scene->toolsettings->skgen_template &&
-		G.scene->toolsettings->skgen_template->type == OB_ARMATURE)
+	if (template_rigg)
 	{
-		ob = G.scene->toolsettings->skgen_template; 	
+		ob = template_rigg->ob; 	
 		arm = ob->data;
-		template_rigg = armatureToGraph(ob, arm);
 	}
 	else
 	{
@@ -3080,7 +3111,11 @@
 	
 	finishRetarget(rigg);
 	
-	RIG_freeRigGraph((BGraph*)template_rigg);
+	/* free template if it comes from the edit armature */
+	if (ob == G.obedit)
+	{
+		RIG_freeRigGraph((BGraph*)template_rigg);
+	}
 	RIG_freeRigGraph((BGraph*)rigg);
 	
 	allqueue(REDRAWVIEW3D, 0);

Modified: branches/etch-a-ton/source/blender/src/editarmature_sketch.c
===================================================================
--- branches/etch-a-ton/source/blender/src/editarmature_sketch.c	2008-11-22 15:10:47 UTC (rev 17535)
+++ branches/etch-a-ton/source/blender/src/editarmature_sketch.c	2008-11-22 17:58:49 UTC (rev 17536)
@@ -142,6 +142,7 @@
 char  *TEMPLATES_MENU = NULL;
 int    TEMPLATES_CURRENT = 0;
 GHash *TEMPLATES_HASH = NULL;
+RigGraph *TEMPLATE_RIGG = NULL;
 
 void BIF_makeListTemplates()
 {
@@ -230,17 +231,67 @@
 	return TEMPLATES_CURRENT;
 }
 
+RigGraph* sk_makeTemplateGraph(Object *ob)
+{
+	if (ob == G.obedit)
+	{
+		return NULL;
+	}
+	
+	if (ob != NULL)
+	{
+		if (TEMPLATE_RIGG && TEMPLATE_RIGG->ob != ob)
+		{
+			RIG_freeRigGraph((BGraph*)TEMPLATE_RIGG);
+			TEMPLATE_RIGG = NULL;
+		}
+		
+		if (TEMPLATE_RIGG == NULL)
+		{
+			bArmature *arm;
+
+			arm = ob->data;
+			
+			TEMPLATE_RIGG = RIG_graphFromArmature(ob, arm);
+		}
+	}
+	
+	return TEMPLATE_RIGG;
+}
+
+int BIF_nbJointsTemplate()
+{
+	RigGraph *rg = sk_makeTemplateGraph(G.scene->toolsettings->skgen_template);
+	
+	if (rg)
+	{
+		return RIG_nbJoints(rg);
+	}
+	else
+	{
+		return -1; 
+	}
+}
+
 void  BIF_freeTemplates()
 {
 	if (TEMPLATES_MENU != NULL)
 	{
 		MEM_freeN(TEMPLATES_MENU);
+		TEMPLATES_MENU = NULL;
 	}
 	
 	if (TEMPLATES_HASH != NULL)
 	{
 		BLI_ghash_free(TEMPLATES_HASH, NULL, NULL);
+		TEMPLATES_HASH = NULL;
 	}
+	
+	if (TEMPLATE_RIGG != NULL)
+	{
+		RIG_freeRigGraph((BGraph*)TEMPLATE_RIGG);
+		TEMPLATE_RIGG = NULL;
+	}
 }
 
 void  BIF_setTemplate(int index)
@@ -252,6 +303,12 @@
 	else
 	{
 		G.scene->toolsettings->skgen_template = NULL;
+		
+		if (TEMPLATE_RIGG != NULL)
+		{
+			RIG_freeRigGraph((BGraph*)TEMPLATE_RIGG);
+		}
+		TEMPLATE_RIGG = NULL;
 	}
 }	
 
@@ -565,6 +622,7 @@
 	float imat[4][4];
 	float tmat[3][3];
 	ReebArc *arc;
+	RigGraph *rg;
 	
 	Mat4Invert(imat, G.obedit->obmat);
 	
@@ -574,8 +632,10 @@
 	arc = sk_strokeToArc(stk, imat, tmat);
 	
 	sk_autoname(arc);
+	
+	rg = sk_makeTemplateGraph(G.scene->toolsettings->skgen_template);
 
-	BIF_retargetArc(arc);
+	BIF_retargetArc(arc, rg);
 	
 	sk_autoname(NULL);
 	





More information about the Bf-blender-cvs mailing list