[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16044] trunk/blender/source/blender: == Armature Editing Tweaks ==

Joshua Leung aligorith at gmail.com
Sun Aug 10 05:10:09 CEST 2008


Revision: 16044
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16044
Author:   aligorith
Date:     2008-08-10 05:10:07 +0200 (Sun, 10 Aug 2008)

Log Message:
-----------
== Armature Editing Tweaks ==

* New Tool: Switch Direction
This tool switches the direction of selected bones in EditMode, and can be found under the Specials Menu (WKey). It also adjusts the parenting, so that continuous chains can still be linked. 

* Bone Locking:
Removed Lock/Unlock functions from Specials menu, and moved this functionality under the Toggle/Set/Clear Bone Settings tools (Shift/Ctrl-Shift/Alt W respectively)

Modified Paths:
--------------
    trunk/blender/source/blender/include/BIF_editarmature.h
    trunk/blender/source/blender/src/editarmature.c
    trunk/blender/source/blender/src/editobject.c

Modified: trunk/blender/source/blender/include/BIF_editarmature.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editarmature.h	2008-08-10 01:38:02 UTC (rev 16043)
+++ trunk/blender/source/blender/include/BIF_editarmature.h	2008-08-10 03:10:07 UTC (rev 16044)
@@ -114,6 +114,7 @@
 void    unique_editbone_name (struct ListBase *ebones, char *name);
 
 void	auto_align_armature(short mode);
+void	switch_direction_armature(void);
 
 void	create_vgroups_from_armature(struct Object *ob, struct Object *par);
 void 	add_verts_to_dgroups(struct Object *ob, struct Object *par, int heat, int mirror);
@@ -135,7 +136,6 @@
 void	hide_selected_armature_bones(void);
 void	hide_unselected_armature_bones(void);
 void	show_all_armature_bones(void);
-void	set_locks_armature_bones(short lock);
 
 #define	BONESEL_ROOT	0x10000000
 #define	BONESEL_TIP		0x20000000
@@ -144,6 +144,9 @@
 
 #define BONESEL_NOSEL	0x80000000	/* Indicates a negative number */
 
+#define EBONE_VISIBLE(arm, ebone) ((arm->layer & ebone->layer) && !(ebone->flag & BONE_HIDDEN_A))
+#define EBONE_EDITABLE(ebone) ((ebone->flag & BONE_SELECTED) && !(ebone->flag & BONE_EDITMODE_LOCKED)) 
+
 /* used in bone_select_hierachy() */
 #define BONE_SELECT_PARENT	0
 #define BONE_SELECT_CHILD	1

Modified: trunk/blender/source/blender/src/editarmature.c
===================================================================
--- trunk/blender/source/blender/src/editarmature.c	2008-08-10 01:38:02 UTC (rev 16043)
+++ trunk/blender/source/blender/src/editarmature.c	2008-08-10 03:10:07 UTC (rev 16044)
@@ -1159,17 +1159,18 @@
 	
 	/* get flag to set (sync these with the ones used in eBone_Flag */
 	if (mode == 2)
-		flag= pupmenu("Disable Setting%t|Draw Wire%x1|Deform%x2|Mult VG%x3|Hinge%x4|No Scale%x5");
+		flag= pupmenu("Disable Setting%t|Draw Wire%x1|Deform%x2|Mult VG%x3|Hinge%x4|No Scale%x5|Locked%x6");
 	else if (mode == 1)
-		flag= pupmenu("Enable Setting%t|Draw Wire%x1|Deform%x2|Mult VG%x3|Hinge%x4|No Scale%x5");
+		flag= pupmenu("Enable Setting%t|Draw Wire%x1|Deform%x2|Mult VG%x3|Hinge%x4|No Scale%x5|Locked%x6");
 	else
-		flag= pupmenu("Toggle Setting%t|Draw Wire%x1|Deform%x2|Mult VG%x3|Hinge%x4|No Scale%x5");
+		flag= pupmenu("Toggle Setting%t|Draw Wire%x1|Deform%x2|Mult VG%x3|Hinge%x4|No Scale%x5|Locked%x6");
 	switch (flag) {
 		case 1: 	flag = BONE_DRAWWIRE; 	break;
 		case 2:		flag = BONE_NO_DEFORM; break;
 		case 3: 	flag = BONE_MULT_VG_ENV; break;
 		case 4:		flag = BONE_HINGE; break;
 		case 5:		flag = BONE_NO_SCALE; break;
+		case 6: 	flag = BONE_EDITMODE_LOCKED; break;
 		default:	return;
 	}
 	
@@ -2711,32 +2712,6 @@
 	BIF_undo_push("Reveal Bones");
 }
 
-/* Sets editmode transform locks for bones (adds if lock==1, clears otherwise) */
-void set_locks_armature_bones(short lock)
-{
-	bArmature *arm= G.obedit->data;
-	EditBone *ebone;
-	
-	for (ebone = G.edbo.first; ebone; ebone=ebone->next) {
-		if (arm->layer & ebone->layer) {
-			if (ebone->flag & BONE_SELECTED) {
-				if (lock)
-					ebone->flag |= BONE_EDITMODE_LOCKED;
-				else	
-					ebone->flag &= ~BONE_EDITMODE_LOCKED;
-			}
-		}
-	}
-	countall();
-	allqueue(REDRAWVIEW3D, 0);
-	allqueue(REDRAWBUTSEDIT, 0);
-	
-	if (lock)
-		BIF_undo_push("Lock Bones");
-	else
-		BIF_undo_push("Unlock Bones");
-}
-
 /* check for null, before calling! */
 static void bone_connect_to_existing_parent(EditBone *bone)
 {
@@ -3176,6 +3151,59 @@
 	else BIF_undo_push("Subdivide multi");
 }
 
+/* switch direction of bone chains */
+void switch_direction_armature (void)
+{
+	bArmature *arm= (G.obedit) ? G.obedit->data : NULL;
+	ListBase chains = {NULL, NULL};
+	LinkData *chain;
+	
+	/* error checking paranoia */
+	if (arm == NULL)
+		return;
+	
+	/* get chains of bones (ends on chains) */
+	chains_find_tips(&chains);
+	if (chains.first == NULL) return;
+	
+	/* loop over chains, only considering selected and visible bones */
+	for (chain= chains.first; chain; chain= chain->next) {
+		EditBone *ebo, *child=NULL, *parent=NULL;
+		
+		/* loop over bones in chain */
+		for (ebo= chain->data; ebo; child= ebo, ebo=parent) {
+			parent= ebo->parent;
+			
+			/* only if selected and editable */
+			if (EBONE_VISIBLE(arm, ebo) && EBONE_EDITABLE(ebo)) {				
+				/* swap head and tail coordinates */
+				SWAP(float, ebo->head[0], ebo->tail[0]);
+				SWAP(float, ebo->head[1], ebo->tail[1]);
+				SWAP(float, ebo->head[2], ebo->tail[2]);
+				
+				/* do parent swapping:
+				 *	- use 'child' as new parent
+				 *	- connected flag is only set if points are coincidental
+				 */
+				ebo->parent= child;
+				if ((child) && VecEqual(ebo->head, child->tail))
+					ebo->flag |= BONE_CONNECTED;
+				else	
+					ebo->flag &= ~BONE_CONNECTED;
+				
+				/* FIXME: other things that need fixing?
+				 *		i.e. roll?
+				 */
+			}
+		}
+	}
+	
+	/* free chains */
+	BLI_freelistN(&chains);
+	
+	BIF_undo_push("Switch Direction");
+}
+
 /* ***************** Pose tools ********************* */
 
 void clear_armature(Object *ob, char mode)

Modified: trunk/blender/source/blender/src/editobject.c
===================================================================
--- trunk/blender/source/blender/src/editobject.c	2008-08-10 01:38:02 UTC (rev 16043)
+++ trunk/blender/source/blender/src/editobject.c	2008-08-10 03:10:07 UTC (rev 16044)
@@ -2760,7 +2760,7 @@
 		DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
 	}
 	else if(G.obedit->type==OB_ARMATURE) {
-		nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Flip Left-Right Names%x3|%l|AutoName Left-Right%x4|AutoName Front-Back%x5|AutoName Top-Bottom%x6|%l|Lock%x7|Unlock%x8");
+		nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Switch Direction%x7|Flip Left-Right Names%x3|%l|AutoName Left-Right%x4|AutoName Front-Back%x5|AutoName Top-Bottom%x6");
 		if(nr==1)
 			subdivide_armature(1);
 		if(nr==2) {
@@ -2773,10 +2773,8 @@
 		else if(ELEM3(nr, 4, 5, 6)) {
 			armature_autoside_names(nr-4);
 		}
-		else if(nr==7)
-			set_locks_armature_bones(1);
-		else if(nr==8)
-			set_locks_armature_bones(0);
+		else if(nr == 7)
+			switch_direction_armature();
 	}
 	else if(G.obedit->type==OB_LATTICE) {
 		static float weight= 1.0f;





More information about the Bf-blender-cvs mailing list