[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13302] trunk/blender/source/blender: == Bone Groups ==

Joshua Leung aligorith at gmail.com
Sun Jan 20 03:55:37 CET 2008


Revision: 13302
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13302
Author:   aligorith
Date:     2008-01-20 03:55:35 +0100 (Sun, 20 Jan 2008)

Log Message:
-----------
== Bone Groups ==

I'm committing some work-in-progress code for "bone groups" now, as I there have been are some major bugs caused by the timeoffset stuff (some of my test files were not loading, and other files were showing all sorts of weird problems). 

Anyway, in this commit, the following things for "bone groups" have been done:
* Bone groups are stored per armature (internally, this is per bPose block)
* Added controls for editing bone-groups per armature - "add", "remove", "rename". These can be found in the "Links and Materials" panel in PoseMode, beside the settings for PoseLib.
* Reorganised buttons for editing selected bones in PoseMode. I've replaced the "dist" and "weight" buttons (they existed in EditMode anyway) with a menu to choose the bone-group and the custom-shape-ob field. In the place of the old custom-shape-ob field, I've restored the "Hide" button. This might break muscle-memory a bit, but there isn't a lot of space to play with there.

Some stuff I'd been originally planning to do before committing:
* When adding keyframes for bones, an action-group with the same name as the bone's group will be added to the action, and the action-channel will be made a member of that. 
* New action/bone groups have unique names (renaming/adding new should check if name exists before assigning it)
* There's a setting under Bone-Groups stuff which sets which custom-colour set is used to colour that group's bones. Currently, this is non-functional, as the necessary drawing code for armatures is not in place yet.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_action.h
    trunk/blender/source/blender/blenkernel/intern/action.c
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/include/BIF_editaction.h
    trunk/blender/source/blender/include/butspace.h
    trunk/blender/source/blender/makesdna/DNA_action_types.h
    trunk/blender/source/blender/src/buttons_editing.c
    trunk/blender/source/blender/src/drawaction.c
    trunk/blender/source/blender/src/drawarmature.c
    trunk/blender/source/blender/src/drawipo.c

Modified: trunk/blender/source/blender/blenkernel/BKE_action.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_action.h	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/blenkernel/BKE_action.h	2008-01-20 02:55:35 UTC (rev 13302)
@@ -60,6 +60,11 @@
  */
 void free_pose_channels(struct bPose *pose);
 
+/** 
+ * Removes and deallocates all data from a pose, and also frees the pose.
+ */
+void free_pose(struct bPose *pose);
+
 /**
  * Allocate a new pose on the heap, and copy the src pose and it's channels
  * into the new pose. *dst is set to the newly allocated structure, and assumed to be NULL.

Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/blenkernel/intern/action.c	2008-01-20 02:55:35 UTC (rev 13302)
@@ -312,7 +312,7 @@
 {
 	bPoseChannel *pchan;
 	
-	if (pose->chanbase.first){
+	if (pose->chanbase.first) {
 		for (pchan = pose->chanbase.first; pchan; pchan=pchan->next){
 			if(pchan->path)
 				MEM_freeN(pchan->path);
@@ -322,6 +322,21 @@
 	}
 }
 
+void free_pose(bPose *pose)
+{
+	if (pose) {
+		/* free pose-channels */
+		free_pose_channels(pose);
+		
+		/* free pose-groups */
+		if (pose->agroups.first)
+			BLI_freelistN(&pose->agroups);
+		
+		/* free pose */
+		MEM_freeN(pose);
+	}
+}
+
 static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan)
 {
 	bConstraint *pcon, *con;
@@ -415,7 +430,7 @@
 	if (!act || !name)
 		return NULL;
 	
-	for (chan = act->chanbase.first; chan; chan=chan->next){
+	for (chan = act->chanbase.first; chan; chan=chan->next) {
 		if (!strcmp (chan->name, name))
 			return chan;
 	}
@@ -423,18 +438,16 @@
 	return NULL;
 }
 
-/* returns existing channel, or adds new one. In latter case it doesnt activate it, context is required for that*/
+/* returns existing channel, or adds new one. In latter case it doesnt activate it, context is required for that */
 bActionChannel *verify_action_channel(bAction *act, const char *name)
 {
 	bActionChannel *chan;
 	
 	chan= get_action_channel(act, name);
-	if(chan==NULL) {
-		if (!chan) {
-			chan = MEM_callocN (sizeof(bActionChannel), "actionChannel");
-			strncpy (chan->name, name, 31);
-			BLI_addtail (&act->chanbase, chan);
-		}
+	if (chan == NULL) {
+		chan = MEM_callocN (sizeof(bActionChannel), "actionChannel");
+		strncpy(chan->name, name, 31);
+		BLI_addtail(&act->chanbase, chan);
 	}
 	return chan;
 }
@@ -1340,10 +1353,8 @@
 	}
 	
 	/* free */
-	if (tpose){
-		free_pose_channels(tpose);
-		MEM_freeN(tpose);
-	}
+	if (tpose)
+		free_pose(tpose);
 	if(chanbase.first)
 		BLI_freelistN(&chanbase);
 }

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2008-01-20 02:55:35 UTC (rev 13302)
@@ -2036,8 +2036,7 @@
 			Mat4CpyMat4(ct->matrix, tchan->chan_mat);
 			
 			/* Clean up */
-			free_pose_channels(pose);
-			MEM_freeN(pose);
+			free_pose(pose);
 		}
 		else if (cob->type == CONSTRAINT_OBTYPE_OBJECT) {
 			/* evaluate using workob */

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2008-01-20 02:55:35 UTC (rev 13302)
@@ -229,10 +229,8 @@
 	if(ob->dup_group) ob->dup_group->id.us--;
 	if(ob->defbase.first)
 		BLI_freelistN(&ob->defbase);
-	if(ob->pose) {
-		free_pose_channels(ob->pose);
-		MEM_freeN(ob->pose);
-	}
+	if(ob->pose)
+		free_pose(ob->pose);
 	free_effects(&ob->effect);
 	free_properties(&ob->prop);
 	object_free_modifiers(ob);
@@ -1438,7 +1436,7 @@
 {
 	Curve *cu;
 	float q[4], vec[4], dir[3], *quat, x1, ctime;
-	float timeoffs, sf_orig = 0.0;
+	float timeoffs = 0.0, sf_orig = 0.0;
 	
 	Mat4One(mat);
 	
@@ -2255,4 +2253,4 @@
 	} else {
 		return ob->sf;
 	}
-}
\ No newline at end of file
+}

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2008-01-20 02:55:35 UTC (rev 13302)
@@ -2830,8 +2830,7 @@
 				else printf("Object %s lost data.", ob->id.name+2);
 				
 				if(ob->pose) {
-					free_pose_channels(ob->pose);
-					MEM_freeN(ob->pose);
+					free_pose(ob->pose);
 					ob->pose= NULL;
 					ob->flag &= ~OB_POSEMODE;
 				}
@@ -2968,6 +2967,7 @@
 		return;
 
 	link_list(fd, &pose->chanbase);
+	link_list(fd, &pose->agroups);
 
 	for (pchan = pose->chanbase.first; pchan; pchan=pchan->next) {
 		pchan->bone= NULL;

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2008-01-20 02:55:35 UTC (rev 13302)
@@ -777,6 +777,7 @@
 static void write_pose(WriteData *wd, bPose *pose)
 {
 	bPoseChannel *chan;
+	bActionGroup *grp;
 
 	/* Write each channel */
 	if (!pose)
@@ -792,6 +793,10 @@
 		
 		writestruct(wd, DATA, "bPoseChannel", 1, chan);
 	}
+	
+	/* Write groups */
+	for (grp=pose->agroups.first; grp; grp=grp->next) 
+		writestruct(wd, DATA, "bActionGroup", 1, grp);
 
 	/* Write this pose */
 	writestruct(wd, DATA, "bPose", 1, pose);

Modified: trunk/blender/source/blender/include/BIF_editaction.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editaction.h	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/include/BIF_editaction.h	2008-01-20 02:55:35 UTC (rev 13302)
@@ -142,6 +142,8 @@
 /* Group/Channel Operations */
 struct bActionGroup *get_active_actiongroup(struct bAction *act);
 void set_active_actiongroup(struct bAction *act, struct bActionGroup *agrp, short select);
+void unique_name_actiongroup(struct ListBase *lb, struct bActionGroup *agrp);
+// <--- add some func to add group for action-channel based on corresponding pchan's grouping 
 void action_groups_group(short add_group);
 void action_groups_ungroup(void);
 

Modified: trunk/blender/source/blender/include/butspace.h
===================================================================
--- trunk/blender/source/blender/include/butspace.h	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/include/butspace.h	2008-01-20 02:55:35 UTC (rev 13302)
@@ -524,6 +524,11 @@
 #define B_POSELIB_ALONE			2321
 #define B_POSELIB_DELETE		2322
 
+
+#define B_POSEGRP_RECALC	2330
+#define B_POSEGRP_ADD		2331
+#define B_POSEGRP_REMOVE	2332
+
 /* *********************** */
 #define B_CAMBUTS		2500
 

Modified: trunk/blender/source/blender/makesdna/DNA_action_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_action_types.h	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/makesdna/DNA_action_types.h	2008-01-20 02:55:35 UTC (rev 13302)
@@ -51,7 +51,7 @@
 	short				ikflag;		/* settings for IK bones */
 	short               selectflag;	/* copy of bone flag, so you can work with library armatures */
 	short				protectflag; /* protect channels from being transformed */
-	short				customCol;	/* index of custom color set to use (0=default - used for all old files) */
+	short				agrp_index; /* index of action-group this bone belongs to (0 = default/no group) */
 	
 	int				    pathlen;	/* for drawing paths, the amount of frames */
 	int 				pathsf;		/* for drawing paths, the start frame number */
@@ -98,6 +98,12 @@
 	float ctime;				/* local action time of this pose */
 	float stride_offset[3];		/* applied to object */
 	float cyclic_offset[3];		/* result of match and cycles, applied in where_is_pose() */
+	
+	
+	ListBase agroups;			/* list of bActionGroups */
+	
+	int active_group;			/* index of active group (starts from 1) */
+	int pad;
 } bPose;
 
 
@@ -114,7 +120,7 @@
 	struct bActionGroup *next, *prev;
 	
 	int flag;				/* settings for this action-group */
-	int pad;				
+	int customCol;			/* index of custom color set to use when used for bones (0=default - used for all old files) */				
 	char name[32];			/* name of the group */
 	
 	ListBase channels;		/* Note: this must not be touched by standard listbase functions */
@@ -197,6 +203,7 @@
 	AGRP_ACTIVE 	= (1<<1),
 	AGRP_PROTECTED 	= (1<<2),
 	AGRP_EXPANDED 	= (1<<3),
+	
 	AGRP_TEMP		= (1<<30),
 	AGRP_MOVED 		= (1<<31)
 } AGRP_FLAG;

Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c	2008-01-19 21:54:33 UTC (rev 13301)
+++ trunk/blender/source/blender/src/buttons_editing.c	2008-01-20 02:55:35 UTC (rev 13302)
@@ -3852,6 +3852,42 @@
 			}
 		}
 		break;
+	case B_POSEGRP_RECALC:
+		allqueue(REDRAWVIEW3D, 0);
+		allqueue(REDRAWBUTSEDIT, 0);
+		break;
+	case B_POSEGRP_ADD:
+		if (ob && ob->pose) {
+			bPose *pose= ob->pose;
+			bActionGroup *grp;
+			
+			grp= MEM_callocN(sizeof(bActionGroup), "PoseGroup");
+			strcpy(grp->name, "Group");
+			BLI_addtail(&pose->agroups, grp);
+			
+			pose->active_group= BLI_countlist(&pose->agroups);
+			
+			BIF_undo_push("Add Pose Group");
+			allqueue(REDRAWBUTSEDIT, 0);
+			allqueue(REDRAWVIEW3D, 0);
+		}
+		break;
+	case B_POSEGRP_REMOVE:
+		if (ob && ob->pose && ob->pose->active_group) {
+			bPose *pose= ob->pose;
+			bActionGroup *grp= NULL;
+			
+			grp= BLI_findlink(&pose->agroups, pose->active_group-1);
+			if (grp) {
+				BLI_freelinkN(&pose->agroups, grp);
+				pose->active_group= 0;
+			}
+			
+			BIF_undo_push("Remove Pose Group");
+			allqueue(REDRAWBUTSEDIT, 0);
+			allqueue(REDRAWVIEW3D, 0);
+		}
+		break;
 	}
 }
 
@@ -4282,6 +4318,37 @@
 	return 0;
 }
 
+static char *build_posegroups_menustr(bPose *pose)
+{
+	DynStr *pupds= BLI_dynstr_new();
+	bActionGroup *agrp;
+	char *str;
+	char buf[16];
+	int i;
+	
+	/* add title first (and the "none" entry) */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list