[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21029] branches/soc-2009-aligorith/source /blender/blenkernel/intern/ipo.c: NLA SoC: Conversions for old NLA-data to the new system

Joshua Leung aligorith at gmail.com
Sat Jun 20 11:36:56 CEST 2009


Revision: 21029
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21029
Author:   aligorith
Date:     2009-06-20 11:36:55 +0200 (Sat, 20 Jun 2009)

Log Message:
-----------
NLA SoC: Conversions for old NLA-data to the new system 

Old NLA-data now gets mostly ported converted over to the new system, with strips and their respective Actions being handled correctly in the test cases I've got. 

The conversion procedure now tries to fit multiple strips into since tracks as it is assumed that quite a few old setups tried to do. However, some old setups may be adversely affected by this (i.e. if they depend on a certain order of holding adds for example). 

For now, there are no complete replacements for the NLA-Modifier/Auto-Walking stuff yet, so that info is currently just ignored (but correctly freed). The current plan here is to get Armature-level pose-offset system + F-Modifiers where appropriate. This should be one of the major causes of file breakage now...

Also, I've yet to restore some patching for group instancing NLA stuff, since more trickery here is required. This is probably the second major cause of file breakage...

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/ipo.c

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/ipo.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/ipo.c	2009-06-20 06:41:50 UTC (rev 21028)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/ipo.c	2009-06-20 09:36:55 UTC (rev 21029)
@@ -58,6 +58,7 @@
 #include "DNA_key_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_nla_types.h"
 #include "DNA_object_types.h"
 #include "DNA_object_force.h"
 #include "DNA_particle_types.h"
@@ -85,6 +86,7 @@
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
+#include "BKE_nla.h"
 #include "BKE_object.h"
 
 
@@ -1463,6 +1465,87 @@
 	action_to_animato(act, &adt->action->groups, &adt->action->curves, &adt->drivers);
 }
 
+/* ------------------------- */
+
+// TODO:
+//	- NLA group duplicators info
+//	- NLA curve/stride modifiers...
+
+/* Convert NLA-Strip to new system */
+static void nlastrips_to_animdata (ID *id, ListBase *strips)
+{
+	AnimData *adt= BKE_animdata_from_id(id);
+	NlaTrack *nlt = NULL;
+	NlaStrip *strip;
+	bActionStrip *as, *asn;
+	
+	/* for each one of the original strips, convert to a new strip and free the old... */
+	for (as= strips->first; as; as= asn) {
+		asn= as->next;
+		
+		/* this old strip is only worth something if it had an action... */
+		if (as->act) {
+			/* convert Action data (if not yet converted), storing the results in the same Action */
+			action_to_animato(as->act, &as->act->groups, &as->act->curves, &adt->drivers);
+			
+			/* create a new-style NLA-strip which references this Action, then copy over relevant settings */
+			{
+				/* init a new strip, and assign the action to it 
+				 *	- no need to muck around with the user-counts, since this is just 
+				 *	  passing over the ref to the new owner, not creating an additional ref
+				 */
+				strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip");
+				strip->act= as->act;
+				
+					/* endpoints */
+				strip->start= as->start;
+				strip->end= as->end;
+				strip->actstart= as->actstart;
+				strip->actend= as->actend;
+				
+					/* action reuse */
+				strip->repeat= as->repeat;
+				strip->scale= as->scale;
+				if (as->flag & ACTSTRIP_LOCK_ACTION)	strip->flag |= NLASTRIP_FLAG_SYNC_LENGTH;
+				
+					/* blending */
+				strip->blendin= as->blendin;
+				strip->blendout= as->blendout;
+				strip->blendmode= (as->mode==ACTSTRIPMODE_ADD) ? NLASTRIP_MODE_ADD : NLASTRIP_MODE_BLEND;
+				if (as->flag & ACTSTRIP_AUTO_BLENDS)	strip->flag |= NLASTRIP_FLAG_AUTO_BLENDS;
+					
+					/* assorted setting flags */
+				if (as->flag & ACTSTRIP_SELECT) 		strip->flag |= NLASTRIP_FLAG_SELECT;
+				if (as->flag & ACTSTRIP_ACTIVE) 		strip->flag |= NLASTRIP_FLAG_ACTIVE;
+				
+				if (as->flag & ACTSTRIP_MUTE)			strip->flag |= NLASTRIP_FLAG_MUTED;
+				if (as->flag & ACTSTRIP_REVERSE)		strip->flag |= NLASTRIP_FLAG_REVERSE;
+				
+					/* by default, we now always extrapolate, while in the past this was optional */
+				if ((as->flag & ACTSTRIP_HOLDLASTFRAME)==0) 
+					strip->extendmode= NLASTRIP_EXTEND_NOTHING;
+			}	
+			
+			/* try to add this strip to the current NLA-Track (i.e. the 'last' one on the stack atm) */
+			if (BKE_nlatrack_add_strip(nlt, strip) == 0) {
+				/* trying to add to the current failed (no space), 
+				 * so add a new track to the stack, and add to that...
+				 */
+				nlt= add_nlatrack(adt, NULL);
+				BKE_nlatrack_add_strip(nlt, strip);
+			}
+		}
+		
+		/* modifiers */
+		// FIXME: for now, we just free them...
+		if (as->modifiers.first)
+			BLI_freelistN(&as->modifiers);
+		
+		/* free the old strip */
+		BLI_freelinkN(strips, as);
+	}
+}
+
 /* *************************************************** */
 /* External API - Only Called from do_versions() */
 
@@ -1509,10 +1592,33 @@
 		if (G.f & G_DEBUG) printf("\tconverting ob %s \n", id->name+2);
 		
 		/* check if object has any animation data */
-		if ((ob->ipo) || (ob->action) || (ob->nlastrips.first)) {
+		if (ob->nlastrips.first) {
 			/* Add AnimData block */
 			adt= BKE_id_add_animdata(id);
 			
+			/* IPO first to take into any non-NLA'd Object Animation */
+			if (ob->ipo) {
+				ipo_to_animdata(id, ob->ipo, NULL, NULL);
+				
+				ob->ipo->id.us--;
+				ob->ipo= NULL;
+			}
+			
+			/* Action is skipped since it'll be used by some strip in the NLA anyway, 
+			 * causing errors with evaluation in the new evaluation pipeline
+			 */
+			if (ob->action) {
+				ob->action->id.us--;
+				ob->action= NULL;
+			}
+			
+			/* finally NLA */
+			nlastrips_to_animdata(id, &ob->nlastrips);
+		}
+		else if ((ob->ipo) || (ob->action)) {
+			/* Add AnimData block */
+			adt= BKE_id_add_animdata(id);
+			
 			/* Action first - so that Action name get conserved */
 			if (ob->action) {
 				action_to_animdata(id, ob->action);
@@ -1530,9 +1636,6 @@
 				ob->ipo->id.us--;
 				ob->ipo= NULL;
 			}
-			
-			/* finally NLA */
-			// XXX todo... for now, new NLA code not hooked up yet, so keep old stuff (but not for too long!)
 		}
 		
 		/* check PoseChannels for constraints with local data */





More information about the Bf-blender-cvs mailing list