[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18885] branches/blender2.5/blender/source /blender: Animato: Added 'experimental' grouping schemes for F-Curves

Joshua Leung aligorith at gmail.com
Mon Feb 9 11:04:12 CET 2009


Revision: 18885
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18885
Author:   aligorith
Date:     2009-02-09 11:04:11 +0100 (Mon, 09 Feb 2009)

Log Message:
-----------
Animato: Added 'experimental' grouping schemes for F-Curves

When inserting keyframes on previous un-animated Objects/bones, F-Curves will be added into Action Groups into either "Object Transform" or <PoseChannel Name>. Ob->Material settings are not grouped for now to illustrate what's possible.

Old files are currently not patched to use do this, as it's still not clear whether this will be ideal.   

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_action.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/action.c
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c
    branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
    branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h
    branches/blender2.5/blender/source/blender/editors/space_action/action_draw.c
    branches/blender2.5/blender/source/blender/editors/space_action/space_action.c
    branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c
    branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c
    branches/blender2.5/blender/source/blender/editors/space_graph/space_graph.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_action.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_action.h	2009-02-09 07:15:22 UTC (rev 18884)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_action.h	2009-02-09 10:04:11 UTC (rev 18885)
@@ -36,11 +36,10 @@
 
 #include "DNA_listBase.h"
 
-/**
- * The following structures are defined in DNA_action_types.h, and DNA_anim_types.h
- */
-
+/* The following structures are defined in DNA_action_types.h, and DNA_anim_types.h */
 struct bAction;
+struct bActionGroup;
+struct FCurve;
 struct bPose;
 struct bPoseChannel;
 struct Object;
@@ -52,28 +51,40 @@
 extern "C" {
 #endif
 
+/* Action API ----------------- */
+
+/* Allocate a new bAction with the given name */
 struct bAction *add_empty_action(const char name[]);
-	
-	/**
- * Allocate a new bAction on the heap and copy 
- * the contents of src into it. If src is NULL NULL is returned.
- */
 
+/* Allocate a copy of the given Action and all its data */	
 struct bAction *copy_action(struct bAction *src);
 
-/**
- * Deallocate the action's channels including constraint channels.
- * does not free the action structure.
- */
+/* Deallocate all of the Action's data, but not the Action itself */
 void free_action(struct bAction *act);
 
 // XXX is this needed?
 void make_local_action(struct bAction *act);
-	
-/**
- * Some kind of bounding box operation on the action.
- */
+		
+/* Some kind of bounding box operation on the action */
+// XXX depreceated..
 void calc_action_range(const struct bAction *act, float *start, float *end, int incl_hidden);
+
+/* Action Groups API ----------------- */
+
+/* Make the given Action Group the active one */
+void set_active_action_group(struct bAction *act, struct bActionGroup *agrp, short select);
+
+/* Add given channel into (active) group  */
+void action_groups_add_channel(struct bAction *act, struct bActionGroup *agrp, struct FCurve *fcurve);
+
+/* Remove the given channel from all groups */
+void action_groups_remove_channel(struct bAction *act, struct FCurve *fcu);
+
+/* Find a group with the given name */
+struct bActionGroup *action_groups_find_named(struct bAction *act, const char name[]);
+
+
+/* Pose API ----------------- */	
 	
 /**
  * Removes and deallocates all channels from a pose.

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/action.c	2009-02-09 07:15:22 UTC (rev 18884)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/action.c	2009-02-09 10:04:11 UTC (rev 18885)
@@ -188,7 +188,193 @@
 }
 
 
+/* Get the active action-group for an Action */
+bActionGroup *get_active_actiongroup (bAction *act)
+{
+	bActionGroup *agrp= NULL;
+	
+	if (act && act->groups.first) {	
+		for (agrp= act->groups.first; agrp; agrp= agrp->next) {
+			if (agrp->flag & AGRP_ACTIVE)
+				break;
+		}
+	}
+	
+	return agrp;
+}
 
+/* Make the given Action-Group the active one */
+void set_active_action_group (bAction *act, bActionGroup *agrp, short select)
+{
+	bActionGroup *grp;
+	
+	/* sanity checks */
+	if (act == NULL)
+		return;
+	
+	/* Deactive all others */
+	for (grp= act->groups.first; grp; grp= grp->next) {
+		if ((grp==agrp) && (select))
+			grp->flag |= AGRP_ACTIVE;
+		else	
+			grp->flag &= ~AGRP_ACTIVE;
+	}
+}
+
+/* Add given channel into (active) group 
+ *	- assumes that channel is not linked to anything anymore
+ *	- always adds at the end of the group 
+ */
+void action_groups_add_channel (bAction *act, bActionGroup *agrp, FCurve *fcurve)
+{
+	FCurve *fcu;
+	short done=0;
+	
+	/* sanity checks */
+	if (ELEM3(NULL, act, agrp, fcurve))
+		return;
+	
+	/* if no channels, just add to two lists at the same time */
+	if (act->curves.first == NULL) {
+		fcurve->next = fcurve->prev = NULL;
+		
+		agrp->channels.first = agrp->channels.last = fcurve;
+		act->curves.first = act->curves.last = fcurve;
+		
+		fcurve->grp= agrp;
+		return;
+	}
+	
+	/* try to find a channel to slot this in before/after */
+	for (fcu= act->curves.first; fcu; fcu= fcu->next) {
+		/* if channel has no group, then we have ungrouped channels, which should always occur after groups */
+		if (fcu->grp == NULL) {
+			BLI_insertlinkbefore(&act->curves, fcu, fcurve);
+			
+			if (agrp->channels.first == NULL)
+				agrp->channels.first= fcurve;
+			agrp->channels.last= fcurve;
+			
+			done= 1;
+			break;
+		}
+		
+		/* if channel has group after current, we can now insert (otherwise we have gone too far) */
+		else if (fcu->grp == agrp->next) {
+			BLI_insertlinkbefore(&act->curves, fcu, fcurve);
+			
+			if (agrp->channels.first == NULL)
+				agrp->channels.first= fcurve;
+			agrp->channels.last= fcurve;
+			
+			done= 1;
+			break;
+		}
+		
+		/* if channel has group we're targeting, check whether it is the last one of these */
+		else if (fcu->grp == agrp) {
+			if ((fcu->next) && (fcu->next->grp != agrp)) {
+				BLI_insertlinkafter(&act->curves, fcu, fcurve);
+				agrp->channels.last= fcurve;
+				done= 1;
+				break;
+			}
+			else if (fcu->next == NULL) {
+				BLI_addtail(&act->curves, fcurve);
+				agrp->channels.last= fcurve;
+				done= 1;
+				break;
+			}
+		}
+		
+		/* if channel has group before target, check whether the next one is something after target */
+		else if (fcu->grp == agrp->prev) {
+			if (fcu->next) {
+				if ((fcu->next->grp != fcu->grp) && (fcu->next->grp != agrp)) {
+					BLI_insertlinkafter(&act->curves, fcu, fcurve);
+					
+					agrp->channels.first= fcurve;
+					agrp->channels.last= fcurve;
+					
+					done= 1;
+					break;
+				}
+			}
+			else {
+				BLI_insertlinkafter(&act->curves, fcu, fcurve);
+				
+				agrp->channels.first= fcurve;
+				agrp->channels.last= fcurve;
+				
+				done= 1;
+				break;
+			}
+		}
+	}
+	
+	/* only if added, set channel as belonging to this group */
+	if (done)
+		fcurve->grp= agrp;
+	else 
+		printf("Error: FCurve '%s' couldn't be added to Group '%s' \n", fcurve->rna_path, agrp->name);
+}	
+
+/* Remove the given channel from all groups */
+void action_groups_remove_channel (bAction *act, FCurve *fcu)
+{
+	/* sanity checks */
+	if (ELEM(NULL, act, fcu))	
+		return;
+	
+	/* check if any group used this directly */
+	if (fcu->grp) {
+		bActionGroup *agrp= fcu->grp;
+		
+		if (agrp->channels.first == agrp->channels.last) {
+			if (agrp->channels.first == fcu) {
+				agrp->channels.first= NULL;
+				agrp->channels.last= NULL;
+			}
+		}
+		else if (agrp->channels.first == fcu) {
+			if ((fcu->next) && (fcu->next->grp==agrp))
+				agrp->channels.first= fcu->next;
+			else
+				agrp->channels.first= NULL;
+		}
+		else if (agrp->channels.last == fcu) {
+			if ((fcu->prev) && (fcu->prev->grp==agrp))
+				agrp->channels.last= fcu->prev;
+			else
+				agrp->channels.last= NULL;
+		}
+		
+		fcu->grp= NULL;
+	}
+	
+	/* now just remove from list */
+	BLI_remlink(&act->curves, fcu);
+}
+
+/* Find a group with the given name */
+bActionGroup *action_groups_find_named (bAction *act, const char name[])
+{
+	bActionGroup *grp;
+	
+	/* sanity checks */
+	if (ELEM3(NULL, act, act->groups.first, name) || (name[0] == 0))
+		return NULL;
+		
+	/* do string comparisons */
+	for (grp= act->groups.first; grp; grp= grp->next) {
+		if (strcmp(grp->name, name) == 0)
+			return grp;
+	}
+	
+	/* not found */
+	return NULL;
+}
+
 /* ************************ Pose channels *************** */
 
 /* usually used within a loop, so we got a N^2 slowdown */

Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-02-09 07:15:22 UTC (rev 18884)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-02-09 10:04:11 UTC (rev 18885)
@@ -5525,7 +5525,7 @@
 				/* we totally reinit the view for the Action Editor, as some old instances had some weird cruft set */
 				ar->v2d.tot.xmin= -20.0f;
 				ar->v2d.tot.ymin= (float)(-sa->winy);
-				ar->v2d.tot.xmax= (float)(sa->winx);
+				ar->v2d.tot.xmax= (float)((sa->winx > 120)? (sa->winx) : 120);
 				ar->v2d.tot.ymax= 0.0f;
 				
 				ar->v2d.cur= ar->v2d.tot;

Modified: branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c	2009-02-09 07:15:22 UTC (rev 18884)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c	2009-02-09 10:04:11 UTC (rev 18885)
@@ -1075,7 +1075,7 @@
 		case ANIMTYPE_GROUP: 
 		{
 			bActionGroup *agrp= (bActionGroup *)ale->data;
-			short offset= (ac->datatype == ANIMCONT_DOPESHEET)? 21 : 0;
+			short offset= (ac->datatype == ANIMCONT_DOPESHEET)? 18 : 0;
 			
 			if ((x < (offset+17)) && (agrp->channels.first)) {
 				/* toggle expand */

Modified: branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/keyframing.c	2009-02-09 07:15:22 UTC (rev 18884)
+++ branches/blender2.5/blender/source/blender/editors/animation/keyframing.c	2009-02-09 10:04:11 UTC (rev 18885)
@@ -3,6 +3,7 @@
  */
  
 #include <stdio.h>
+#include <stddef.h>
 #include <string.h>
 #include <math.h>
 #include <float.h>
@@ -95,13 +96,13 @@
 /* Animation Data Validation */
 
 /* Get (or add relevant data to be able to do so) F-Curve from the Active Action, 
- * for the given Animation Data block 
+ * for the given Animation Data block. This assumes that all the destinations are valid.
  */
-// TODO: should we check if path is valid? For now, assume that it's already set OK by caller...
-FCurve *verify_fcurve (ID *id, const char rna_path[], const int array_index, short add)
+FCurve *verify_fcurve (ID *id, const char group[], const char rna_path[], const int array_index, short add)
 {
 	AnimData *adt;
 	bAction *act;
+	bActionGroup *grp;
 	FCurve *fcu;
 	
 	/* sanity checks */
@@ -133,7 +134,7 @@
 		fcu= NULL;
 	
 	if ((fcu == NULL) && (add)) {
-		/* use default settings */
+		/* use default settings to make a F-Curve */
 		fcu= MEM_callocN(sizeof(FCurve), "FCurve");
 		
 		fcu->flag |= (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES);
@@ -144,8 +145,33 @@
 		fcu->rna_path= BLI_strdupn(rna_path, strlen(rna_path));

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list