[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47324] trunk/blender/source/blender: Action Group Colors for Bones (Part 2)

Joshua Leung aligorith at gmail.com
Fri Jun 1 15:54:44 CEST 2012


Revision: 47324
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47324
Author:   aligorith
Date:     2012-06-01 13:54:44 +0000 (Fri, 01 Jun 2012)
Log Message:
-----------
Action Group Colors for Bones (Part 2)

Colors used by Bone Groups are now copied/assigned to Action Groups too when
they're created now. This completes the work started in r.46960 to restore this
functionality from 2.48.

Currently, there is no control over when/whether these colors are copied over
(although it is possible to disable the display of these colors for relevant
animation editors if desired). Originally I was going to make this a more
generic Keying Sets feature, though that turned out to be a bit too complex to
manage.

Other notes:
* Split out the code for copying colors to a common library function

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_action.h
    trunk/blender/source/blender/blenkernel/intern/action.c
    trunk/blender/source/blender/editors/animation/anim_channels_defines.c
    trunk/blender/source/blender/editors/animation/keyframes_general.c
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/editors/include/ED_keyframing.h
    trunk/blender/source/blender/editors/object/object_relations.c
    trunk/blender/source/blender/makesrna/intern/rna_action.c
    trunk/blender/source/blender/makesrna/intern/rna_pose.c

Modified: trunk/blender/source/blender/blenkernel/BKE_action.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_action.h	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/blenkernel/BKE_action.h	2012-06-01 13:54:44 UTC (rev 47324)
@@ -112,6 +112,9 @@
 /* Make the given Action Group the active one */
 void set_active_action_group(struct bAction *act, struct bActionGroup *agrp, short select);
 
+/* Sync colors used for action/bone group with theme settings */
+void action_group_colors_sync(struct bActionGroup *grp);
+
 /* Add a new action group with the given name to the action */
 struct bActionGroup *action_groups_add_new(struct bAction *act, const char name[]);
 

Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/blenkernel/intern/action.c	2012-06-01 13:54:44 UTC (rev 47324)
@@ -252,6 +252,31 @@
 	}
 }
 
+/* Sync colors used for action/bone group with theme settings */
+void action_group_colors_sync(bActionGroup *grp)
+{
+	/* only do color copying if using a custom color (i.e. not default color)  */
+	if (grp->customCol) {
+		if (grp->customCol > 0) {
+			/* copy theme colors on-to group's custom color in case user tries to edit color */
+			bTheme *btheme = U.themes.first;
+			ThemeWireColor *col_set = &btheme->tarm[(grp->customCol - 1)];
+			
+			memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
+		}
+		else {
+			/* init custom colors with a generic multi-color rgb set, if not initialized already
+			 * (for custom color set) */
+			if (grp->cs.solid[0] == 0) {
+				/* define for setting colors in theme below */
+				rgba_char_args_set(grp->cs.solid, 0xff, 0x00, 0x00, 255);
+				rgba_char_args_set(grp->cs.select, 0x81, 0xe6, 0x14, 255);
+				rgba_char_args_set(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
+			}
+		}
+	}
+}
+
 /* Add a new action group with the given name to the action */
 bActionGroup *action_groups_add_new(bAction *act, const char name[])
 {
@@ -409,10 +434,9 @@
 
 /* *************** Pose channels *************** */
 
-/* usually used within a loop, so we got a N^2 slowdown */
 bPoseChannel *BKE_pose_channel_find_name(const bPose *pose, const char *name)
 {
-	if (ELEM(NULL, pose, name) || (name[0] == 0))
+	if (ELEM(NULL, pose, name) || (name[0] == '\0'))
 		return NULL;
 	
 	if (pose->chanhash)

Modified: trunk/blender/source/blender/editors/animation/anim_channels_defines.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2012-06-01 13:54:44 UTC (rev 47324)
@@ -3060,7 +3060,7 @@
 		/* find or create new F-Curve */
 		// XXX is the group name for this ok?
 		bAction *act = verify_adt_action((ID *)key, 1);
-		FCurve *fcu = verify_fcurve(act, NULL, rna_path, 0, 1);
+		FCurve *fcu = verify_fcurve(act, NULL, &ptr, rna_path, 0, 1);
 		
 		/* set the special 'replace' flag if on a keyframe */
 		if (fcurve_frame_has_keyframe(fcu, cfra, 0))

Modified: trunk/blender/source/blender/editors/animation/keyframes_general.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframes_general.c	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/editors/animation/keyframes_general.c	2012-06-01 13:54:44 UTC (rev 47324)
@@ -671,7 +671,7 @@
 	BezTriple *bezt;
 	int i;
 
-	/* First de-select existing FCuvre */
+	/* First de-select existing FCurve's keyframes */
 	for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
 		bezt->f2 &= ~SELECT;
 	}

Modified: trunk/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframing.c	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/editors/animation/keyframing.c	2012-06-01 13:54:44 UTC (rev 47324)
@@ -150,9 +150,10 @@
 /* Get (or add relevant data to be able to do so) F-Curve from the Active Action, 
  * for the given Animation Data block. This assumes that all the destinations are valid.
  */
-FCurve *verify_fcurve(bAction *act, const char group[], const char rna_path[], const int array_index, short add)
+FCurve *verify_fcurve(bAction *act, const char group[], PointerRNA *ptr, 
+                      const char rna_path[], const int array_index, short add)
 {
-	bActionGroup *grp;
+	bActionGroup *agrp;
 	FCurve *fcu;
 	
 	/* sanity checks */
@@ -183,14 +184,30 @@
 		/* if a group name has been provided, try to add or find a group, then add F-Curve to it */
 		if (group) {
 			/* try to find group */
-			grp = BKE_action_group_find_name(act, group);
+			agrp = BKE_action_group_find_name(act, group);
 			
 			/* no matching groups, so add one */
-			if (grp == NULL)
-				grp = action_groups_add_new(act, group);
+			if (agrp == NULL) {
+				agrp = action_groups_add_new(act, group);
+				
+				/* sync bone group colors if applicable */
+				if (ptr && (ptr->type == &RNA_PoseBone)) {
+					Object *ob = (Object *)ptr->id.data;
+					bPoseChannel *pchan = (bPoseChannel *)ptr->data;
+					bPose *pose = ob->pose;
+					bActionGroup *grp;
+					
+					/* find bone group (if present), and use the color from that */
+					grp = (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
+					if (grp) {
+						agrp->customCol = grp->customCol;
+						action_group_colors_sync(agrp);
+					}
+				}
+			}
 			
 			/* add F-Curve to group */
-			action_groups_add_channel(act, grp, fcu);
+			action_groups_add_channel(act, agrp, fcu);
 		}
 		else {
 			/* just add F-Curve to end of Action's list */
@@ -939,7 +956,7 @@
 		 *	- if we're replacing keyframes only, DO NOT create new F-Curves if they do not exist yet
 		 *	  but still try to get the F-Curve if it exists...
 		 */
-		fcu = verify_fcurve(act, group, rna_path, array_index, (flag & INSERTKEY_REPLACE) == 0);
+		fcu = verify_fcurve(act, group, &ptr, rna_path, array_index, (flag & INSERTKEY_REPLACE) == 0);
 		
 		/* we may not have a F-Curve when we're replacing only... */
 		if (fcu) {
@@ -1027,7 +1044,7 @@
 	
 	/* will only loop once unless the array index was -1 */
 	for (; array_index < array_index_max; array_index++) {
-		FCurve *fcu = verify_fcurve(act, group, rna_path, array_index, 0);
+		FCurve *fcu = verify_fcurve(act, group, &ptr, rna_path, array_index, 0);
 		short found = -1;
 		int i;
 		

Modified: trunk/blender/source/blender/editors/include/ED_keyframing.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_keyframing.h	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/editors/include/ED_keyframing.h	2012-06-01 13:54:44 UTC (rev 47324)
@@ -75,7 +75,8 @@
 /* Get (or add relevant data to be able to do so) F-Curve from the given Action. 
  * This assumes that all the destinations are valid.
  */
-struct FCurve *verify_fcurve(struct bAction *act, const char group[], const char rna_path[], const int array_index, short add);
+struct FCurve *verify_fcurve(struct bAction *act, const char group[], struct PointerRNA *ptr,
+                             const char rna_path[], const int array_index, short add);
 
 /* -------- */
 

Modified: trunk/blender/source/blender/editors/object/object_relations.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_relations.c	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/editors/object/object_relations.c	2012-06-01 13:54:44 UTC (rev 47324)
@@ -542,7 +542,7 @@
 			if (partype == PAR_FOLLOW) {
 				/* get or create F-Curve */
 				bAction *act = verify_adt_action(&cu->id, 1);
-				FCurve *fcu = verify_fcurve(act, NULL, "eval_time", 0, 1);
+				FCurve *fcu = verify_fcurve(act, NULL, NULL, "eval_time", 0, 1);
 				
 				/* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
 				if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first)

Modified: trunk/blender/source/blender/makesrna/intern/rna_action.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_action.c	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/makesrna/intern/rna_action.c	2012-06-01 13:54:44 UTC (rev 47324)
@@ -104,12 +104,12 @@
 	}
 
 	/* annoying, check if this exists */
-	if (verify_fcurve(act, group, data_path, index, 0)) {
+	if (verify_fcurve(act, group, NULL, data_path, index, 0)) {
 		BKE_reportf(reports, RPT_ERROR, "F-Curve '%s[%d]' already exists in action '%s'", data_path,
 		            index, act->id.name + 2);
 		return NULL;
 	}
-	return verify_fcurve(act, group, data_path, index, 1);
+	return verify_fcurve(act, group, NULL, data_path, index, 1);
 }
 
 static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, FCurve *fcu)

Modified: trunk/blender/source/blender/makesrna/intern/rna_pose.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_pose.c	2012-06-01 13:49:49 UTC (rev 47323)
+++ trunk/blender/source/blender/makesrna/intern/rna_pose.c	2012-06-01 13:54:44 UTC (rev 47324)
@@ -139,31 +139,12 @@
 {
 	bActionGroup *grp = ptr->data;
 	
-	/* if valid value, set the new enum value, then copy the relevant colors? */
-	if ((value >= -1) && (value < 21))
+	/* ensure only valid values get set */
+	if ((value >= -1) && (value < 21)) {
 		grp->customCol = value;
-	else
-		return;
 	
-	/* only do color copying if using a custom color (i.e. not default color)  */
-	if (grp->customCol) {
-		if (grp->customCol > 0) {
-			/* copy theme colors on-to group's custom color in case user tries to edit color */
-			bTheme *btheme = U.themes.first;
-			ThemeWireColor *col_set = &btheme->tarm[(grp->customCol - 1)];
-			
-			memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
-		}
-		else {
-			/* init custom colors with a generic multi-color rgb set, if not initialized already
-			 * (for custom color set) */
-			if (grp->cs.solid[0] == 0) {
-				/* define for setting colors in theme below */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list