[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18337] branches/blender2.5/blender/source /blender: 2.5 - Animation Fixes + More Porting work in Action Editor

Joshua Leung aligorith at gmail.com
Mon Jan 5 10:54:40 CET 2009


Revision: 18337
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18337
Author:   aligorith
Date:     2009-01-05 10:54:39 +0100 (Mon, 05 Jan 2009)

Log Message:
-----------
2.5 - Animation Fixes + More Porting work in Action Editor

* Added crash fixes for loading old files with Actions/Armatures in them. Was caused by usage of some old globals still and the functions in question not performing NULL checks on the validity of the data they're given.

* Added back reorganise action channels tools (shift/ctrl-shif pageup/down) for Action Editor. These are only available in 'Action Mode' only.

* Tidied up Action Editor/Dopesheet tools code - removed various unused things, and also, added an API call in anim_deps.c to send the correct notifiers, since I anticipate that they're likely to require a few context checks which would be better to centralise than copy+paste everywhere.

Note to Ton: could you have a look at this notifier stuff here? I'm not sure which ones I should be sending...


* Also added a few assorted comments in various places

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/action.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/ipo.c
    branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c
    branches/blender2.5/blender/source/blender/editors/animation/anim_deps.c
    branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
    branches/blender2.5/blender/source/blender/editors/include/ED_anim_api.h
    branches/blender2.5/blender/source/blender/editors/space_action/action_edit.c
    branches/blender2.5/blender/source/blender/editors/space_action/action_select.c
    branches/blender2.5/blender/source/blender/editors/space_action/space_action.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/action.c	2009-01-05 05:42:48 UTC (rev 18336)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/action.c	2009-01-05 09:54:39 UTC (rev 18337)
@@ -1493,19 +1493,19 @@
 void do_all_pose_actions(Scene *scene, Object *ob)
 {
 	/* only to have safe calls from editor */
-	if(ob==NULL) return;
-	if(ob->type!=OB_ARMATURE || ob->pose==NULL) return;
+	if(ELEM(NULL, scene, ob)) return;
+	if((ob->type!=OB_ARMATURE) || (ob->pose==NULL)) return;
 
 	if(ob->pose->flag & POSE_LOCKED) {  /*  no actions to execute while transform */
 		if(ob->pose->flag & POSE_DO_UNLOCK)
 			ob->pose->flag &= ~(POSE_LOCKED|POSE_DO_UNLOCK);
 	}
-	else if(ob->action && ((ob->nlaflag & OB_NLA_OVERRIDE)==0 || ob->nlastrips.first==NULL) ) {
+	else if( (ob->action) && ((ob->nlaflag & OB_NLA_OVERRIDE)==0 || (ob->nlastrips.first==NULL)) ) {
 		float cframe= (float) scene->r.cfra;
 		
 		cframe= get_action_frame(ob, cframe);
 		
-		extract_pose_from_action (ob->pose, ob->action, bsystem_time(scene, ob, cframe, 0.0));
+		extract_pose_from_action(ob->pose, ob->action, bsystem_time(scene, ob, cframe, 0.0));
 	}
 	else if(ob->nlastrips.first) {
 		do_nla(scene, ob, ID_AR);

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c	2009-01-05 05:42:48 UTC (rev 18336)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c	2009-01-05 09:54:39 UTC (rev 18337)
@@ -2273,13 +2273,15 @@
 	Bone *bone;
 	bPoseChannel *pchan;
 	float imat[4][4];
-	float ctime= bsystem_time(scene, ob, (float)scene->r.cfra, 0.0);	/* not accurate... */
+	float ctime;
 	
 	arm = get_armature(ob);
 	
-	if(arm==NULL) return;
-	if(ob->pose==NULL || (ob->pose->flag & POSE_RECALC)) 
+	if(ELEM(NULL, arm, scene)) return;
+	if((ob->pose==NULL) || (ob->pose->flag & POSE_RECALC)) 
 	   armature_rebuild_pose(ob, arm);
+	   
+	ctime= bsystem_time(scene, ob, (float)scene->r.cfra, 0.0);	/* not accurate... */
 	
 	/* In editmode or restposition we read the data from the bones */
 	if(arm->edbo || (arm->flag & ARM_RESTPOS)) {

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c	2009-01-05 05:42:48 UTC (rev 18336)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c	2009-01-05 09:54:39 UTC (rev 18337)
@@ -352,7 +352,7 @@
 	
 	/* this can happen when active scene was lib-linked, and doesnt exist anymore */
 	if(CTX_data_scene(C)==NULL) {
-		CTX_data_scene_set(C, G.main->scene.first);
+		CTX_data_scene_set(C, bfd->main->scene.first);
 		CTX_wm_screen(C)->scene= CTX_data_scene(C);
 		curscene= CTX_data_scene(C);
 	}

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/ipo.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/ipo.c	2009-01-05 05:42:48 UTC (rev 18336)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/ipo.c	2009-01-05 09:54:39 UTC (rev 18337)
@@ -233,6 +233,7 @@
 /* ---------------------- Init --------------------------- */
 
 /* on adding new ipos, or for empty views */
+// XXX users usually find these zoom settings problematic...
 void ipo_default_v2d_cur (Scene *scene, int blocktype, rctf *cur)
 {
 	switch (blocktype) {

Modified: branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c	2009-01-05 05:42:48 UTC (rev 18336)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c	2009-01-05 09:54:39 UTC (rev 18337)
@@ -276,9 +276,397 @@
 /* OPERATORS */
 
 /* ****************** Rearrange Channels Operator ******************* */
+/* This operator only works for Action Editor mode for now, as having it elsewhere makes things difficult */
 
+/* constants for channel rearranging */
+/* WARNING: don't change exising ones without modifying rearrange func accordingly */
+enum {
+	REARRANGE_ACTCHAN_TOP= -2,
+	REARRANGE_ACTCHAN_UP= -1,
+	REARRANGE_ACTCHAN_DOWN= 1,
+	REARRANGE_ACTCHAN_BOTTOM= 2
+};
 
+/* make sure all action-channels belong to a group (and clear action's list) */
+static void split_groups_action_temp (bAction *act, bActionGroup *tgrp)
+{
+	bActionChannel *achan;
+	bActionGroup *agrp;
+	
+	/* Separate action-channels into lists per group */
+	for (agrp= act->groups.first; agrp; agrp= agrp->next) {
+		if (agrp->channels.first) {
+			achan= agrp->channels.last;
+			act->chanbase.first= achan->next;
+			
+			achan= agrp->channels.first;
+			achan->prev= NULL;
+			
+			achan= agrp->channels.last;
+			achan->next= NULL;
+		}
+	}
+	
+	/* Initialise memory for temp-group */
+	memset(tgrp, 0, sizeof(bActionGroup));
+	tgrp->flag |= (AGRP_EXPANDED|AGRP_TEMP);
+	strcpy(tgrp->name, "#TempGroup");
+		
+	/* Move any action-channels not already moved, to the temp group */
+	if (act->chanbase.first) {
+		/* start of list */
+		achan= act->chanbase.first;
+		achan->prev= NULL;
+		tgrp->channels.first= achan;
+		act->chanbase.first= NULL;
+		
+		/* end of list */
+		achan= act->chanbase.last;
+		achan->next= NULL;
+		tgrp->channels.last= achan;
+		act->chanbase.last= NULL;
+	}
+	
+	/* Add temp-group to list */
+	BLI_addtail(&act->groups, tgrp);
+}
 
+/* link lists of channels that groups have */
+static void join_groups_action_temp (bAction *act)
+{
+	bActionGroup *agrp;
+	bActionChannel *achan;
+	
+	for (agrp= act->groups.first; agrp; agrp= agrp->next) {
+		ListBase tempGroup;
+		
+		/* add list of channels to action's channels */
+		tempGroup= agrp->channels;
+		addlisttolist(&act->chanbase, &agrp->channels);
+		agrp->channels= tempGroup;
+		
+		/* clear moved flag */
+		agrp->flag &= ~AGRP_MOVED;
+		
+		/* if temp-group... remove from list (but don't free as it's on the stack!) */
+		if (agrp->flag & AGRP_TEMP) {
+			BLI_remlink(&act->groups, agrp);
+			break;
+		}
+	}
+	
+	/* clear "moved" flag from all achans */
+	for (achan= act->chanbase.first; achan; achan= achan->next) 
+		achan->flag &= ~ACHAN_MOVED;
+}
+
+
+static short rearrange_actchannel_is_ok (Link *channel, short type)
+{
+	if (type == ANIMTYPE_GROUP) {
+		bActionGroup *agrp= (bActionGroup *)channel;
+		
+		if (SEL_AGRP(agrp) && !(agrp->flag & AGRP_MOVED))
+			return 1;
+	}
+	else if (type == ANIMTYPE_ACHAN) {
+		bActionChannel *achan= (bActionChannel *)channel;
+		
+		if (VISIBLE_ACHAN(achan) && SEL_ACHAN(achan) && !(achan->flag & ACHAN_MOVED))
+			return 1;
+	}
+	
+	return 0;
+}
+
+static short rearrange_actchannel_after_ok (Link *channel, short type)
+{
+	if (type == ANIMTYPE_GROUP) {
+		bActionGroup *agrp= (bActionGroup *)channel;
+		
+		if (agrp->flag & AGRP_TEMP)
+			return 0;
+	}
+	
+	return 1;
+}
+
+
+static short rearrange_actchannel_top (ListBase *list, Link *channel, short type)
+{
+	if (rearrange_actchannel_is_ok(channel, type)) {
+		/* take it out off the chain keep data */
+		BLI_remlink(list, channel);
+		
+		/* make it first element */
+		BLI_insertlinkbefore(list, list->first, channel);
+		
+		return 1;
+	}
+	
+	return 0;
+}
+
+static short rearrange_actchannel_up (ListBase *list, Link *channel, short type)
+{
+	if (rearrange_actchannel_is_ok(channel, type)) {
+		Link *prev= channel->prev;
+		
+		if (prev) {
+			/* take it out off the chain keep data */
+			BLI_remlink(list, channel);
+			
+			/* push it up */
+			BLI_insertlinkbefore(list, prev, channel);
+			
+			return 1;
+		}
+	}
+	
+	return 0;
+}
+
+static short rearrange_actchannel_down (ListBase *list, Link *channel, short type)
+{
+	if (rearrange_actchannel_is_ok(channel, type)) {
+		Link *next = (channel->next) ? channel->next->next : NULL;
+		
+		if (next) {
+			/* take it out off the chain keep data */
+			BLI_remlink(list, channel);
+			
+			/* move it down */
+			BLI_insertlinkbefore(list, next, channel);
+			
+			return 1;
+		}
+		else if (rearrange_actchannel_after_ok(list->last, type)) {
+			/* take it out off the chain keep data */
+			BLI_remlink(list, channel);
+			
+			/* add at end */
+			BLI_addtail(list, channel);
+			
+			return 1;
+		}
+		else {
+			/* take it out off the chain keep data */
+			BLI_remlink(list, channel);
+			
+			/* add just before end */
+			BLI_insertlinkbefore(list, list->last, channel);
+			
+			return 1;
+		}
+	}
+	
+	return 0;
+}
+
+static short rearrange_actchannel_bottom (ListBase *list, Link *channel, short type)
+{
+	if (rearrange_actchannel_is_ok(channel, type)) {
+		if (rearrange_actchannel_after_ok(list->last, type)) {
+			/* take it out off the chain keep data */
+			BLI_remlink(list, channel);
+			
+			/* add at end */
+			BLI_addtail(list, channel);
+			
+			return 1;
+		}
+	}
+	
+	return 0;
+}
+
+
+/* Change the order of action-channels 
+ *	mode: REARRANGE_ACTCHAN_*  
+ */
+static void rearrange_action_channels (bAnimContext *ac, short mode)
+{
+	bAction *act;
+	bActionChannel *achan, *chan;
+	bActionGroup *agrp, *grp;
+	bActionGroup tgrp;
+	
+	short (*rearrange_func)(ListBase *, Link *, short);
+	short do_channels = 1;
+	
+	/* Get the active action, exit if none are selected */
+	act= (bAction *)ac->data;
+	
+	/* exit if invalid mode */
+	switch (mode) {
+		case REARRANGE_ACTCHAN_TOP:
+			rearrange_func= rearrange_actchannel_top;
+			break;
+		case REARRANGE_ACTCHAN_UP:
+			rearrange_func= rearrange_actchannel_up;
+			break;
+		case REARRANGE_ACTCHAN_DOWN:
+			rearrange_func= rearrange_actchannel_down;
+			break;
+		case REARRANGE_ACTCHAN_BOTTOM:
+			rearrange_func= rearrange_actchannel_bottom;
+			break;
+		default:
+			return;
+	}
+	
+	/* make sure we're only operating with groups */
+	split_groups_action_temp(act, &tgrp);
+	
+	/* rearrange groups first (and then, only consider channels if the groups weren't moved) */
+	#define GET_FIRST(list) ((mode > 0) ? (list.first) : (list.last))
+	#define GET_NEXT(item) ((mode > 0) ? (item->next) : (item->prev))
+	
+	for (agrp= GET_FIRST(act->groups); agrp; agrp= grp) {
+		/* Get next group to consider */
+		grp= GET_NEXT(agrp);
+		
+		/* try to do group first */
+		if (rearrange_func(&act->groups, (Link *)agrp, ANIMTYPE_GROUP)) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list