[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20340] branches/soc-2009-aligorith/source /blender: NLA SoC: File IO for new NLA Datatypes

Joshua Leung aligorith at gmail.com
Fri May 22 13:19:35 CEST 2009


Revision: 20340
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20340
Author:   aligorith
Date:     2009-05-22 13:19:35 +0200 (Fri, 22 May 2009)

Log Message:
-----------
NLA SoC: File IO for new NLA Datatypes

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
    branches/soc-2009-aligorith/source/blender/blenloader/intern/readfile.c
    branches/soc-2009-aligorith/source/blender/blenloader/intern/writefile.c

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-05-22 09:48:05 UTC (rev 20339)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-05-22 11:19:35 UTC (rev 20340)
@@ -33,6 +33,7 @@
 struct AnimData;
 struct NlaStrip;
 struct NlaTrack;
+struct bAction;
 
 /* ----------------------------- */
 /* Data Management */
@@ -41,6 +42,7 @@
 void free_nlatrack(ListBase *tracks, struct NlaTrack *nlt);
 void free_nladata(ListBase *tracks);
 
+struct NlaStrip *add_nlastrip(struct NlaTrack *nlt, struct bAction *act);
 struct NlaTrack *add_nlatrack(struct AnimData *adt);
 
 /* ----------------------------- */

Modified: branches/soc-2009-aligorith/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenloader/intern/readfile.c	2009-05-22 09:48:05 UTC (rev 20339)
+++ branches/soc-2009-aligorith/source/blender/blenloader/intern/readfile.c	2009-05-22 11:19:35 UTC (rev 20340)
@@ -1657,10 +1657,26 @@
 
 /* Data Linking ----------------------------- */
 
+static void lib_link_fmodifiers(FileData *fd, ID *id, ListBase *list)
+{
+	FModifier *fcm;
+	
+	for (fcm= list->first; fcm; fcm= fcm->next) {
+		/* data for specific modifiers */
+		switch (fcm->type) {
+			case FMODIFIER_TYPE_PYTHON:
+			{
+				FMod_Python *data= (FMod_Python *)fcm->data;
+				data->script = newlibadr(fd, id->lib, data->script);
+			}
+				break;
+		}
+	}
+}
+
 static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list) 
 {
 	FCurve *fcu;
-	FModifier *fcm;
 	
 	/* relink ID-block references... */
 	for (fcu= list->first; fcu; fcu= fcu->next) {
@@ -1674,16 +1690,45 @@
 		}
 		
 		/* modifiers */
-		for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
-			/* data for specific modifiers */
-			switch (fcm->type) {
-				case FMODIFIER_TYPE_PYTHON:
-				{
-					FMod_Python *data= (FMod_Python *)fcm->data;
-					data->script = newlibadr(fd, id->lib, data->script);
-				}
-					break;
+		lib_link_fmodifiers(fd, id, &fcu->modifiers);
+	}
+}
+
+
+/* NOTE: this assumes that link_list has already been called on the list */
+static void direct_link_fmodifiers(FileData *fd, ListBase *list)
+{
+	FModifier *fcm;
+	
+	for (fcm= list->first; fcm; fcm= fcm->next) {
+		/* relink general data */
+		fcm->data = newdataadr(fd, fcm->data);
+		fcm->edata= NULL;
+		
+		/* do relinking of data for specific types */
+		switch (fcm->type) {
+			case FMODIFIER_TYPE_GENERATOR:
+			{
+				FMod_Generator *data= (FMod_Generator *)fcm->data;
+				
+				data->coefficients= newdataadr(fd, data->coefficients);
 			}
+				break;
+			case FMODIFIER_TYPE_ENVELOPE:
+			{
+				FMod_Envelope *data= (FMod_Envelope *)fcm->data;
+				
+				data->data= newdataadr(fd, data->data);
+			}
+				break;
+			case FMODIFIER_TYPE_PYTHON:
+			{
+				FMod_Python *data= (FMod_Python *)fcm->data;
+				
+				data->prop = newdataadr(fd, data->prop);
+				IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+			}
+				break;
 		}
 	}
 }
@@ -1692,7 +1737,6 @@
 static void direct_link_fcurves(FileData *fd, ListBase *list)
 {
 	FCurve *fcu;
-	FModifier *fcm;
 	
 	/* link F-Curve data to F-Curve again (non ID-libs) */
 	for (fcu= list->first; fcu; fcu= fcu->next) {
@@ -1720,37 +1764,7 @@
 		
 		/* modifiers */
 		link_list(fd, &fcu->modifiers);
-		for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
-			/* relink general data */
-			fcm->data = newdataadr(fd, fcm->data);
-			fcm->edata= NULL;
-			
-			/* do relinking of data for specific types */
-			switch (fcm->type) {
-				case FMODIFIER_TYPE_GENERATOR:
-				{
-					FMod_Generator *data= (FMod_Generator *)fcm->data;
-					
-					data->coefficients= newdataadr(fd, data->coefficients);
-				}
-					break;
-				case FMODIFIER_TYPE_ENVELOPE:
-				{
-					FMod_Envelope *data= (FMod_Envelope *)fcm->data;
-					
-					data->data= newdataadr(fd, data->data);
-				}
-					break;
-				case FMODIFIER_TYPE_PYTHON:
-				{
-					FMod_Python *data= (FMod_Python *)fcm->data;
-					
-					data->prop = newdataadr(fd, data->prop);
-					IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
-				}
-					break;
-			}
-		}
+		direct_link_fmodifiers(fd, &fcu->modifiers);
 	}
 }
 
@@ -1802,6 +1816,44 @@
 	}
 }
 
+
+static void lib_link_nladata (FileData *fd, ID *id, ListBase *list)
+{
+	NlaTrack *nlt;
+	NlaStrip *strip;
+	
+	/* we only acare about the NLA strips inside the tracks */
+	for (nlt= list->first; nlt; nlt= nlt->next) {
+		for (strip= nlt->strips.first; strip; strip= strip->next) {
+			/* reassign the counted-reference to action */
+			strip->act = newlibadr_us(fd, id->lib, strip->act);
+		}
+	}
+}
+
+/* NOTE: this assumes that link_list has already been called on the list */
+static void direct_link_nladata(FileData *fd, ListBase *list)
+{
+	NlaTrack *nlt;
+	NlaStrip *strip;
+	
+	for (nlt= list->first; nlt; nlt= nlt->next) {
+		/* relink list of strips */
+		link_list(fd, &nlt->strips);
+		
+		/* relink strip data */
+		for (strip= nlt->strips.first; strip; strip= strip->next) {
+			/* strip's F-Curves */
+			link_list(fd, &strip->fcurves);
+			direct_link_fcurves(fd, &strip->fcurves);
+			
+			/* strip's F-Modifiers */
+			link_list(fd, &strip->modifiers);
+			direct_link_fcurves(fd, &strip->modifiers);
+		}
+	}
+}
+
 /* ------- */
 
 static void lib_link_keyingsets(FileData *fd, ID *id, ListBase *list)
@@ -1851,7 +1903,7 @@
 	/* overrides don't have lib-link for now, so no need to do anything */
 	
 	/* link NLA-data */
-	// TODO... 
+	lib_link_nladata(fd, id, &adt->nla_tracks);
 }
 
 static void direct_link_animdata(FileData *fd, AnimData *adt)
@@ -1868,7 +1920,8 @@
 	// TODO...
 	
 	/* link NLA-data */
-	// TODO...
+	link_list(fd, &adt->nla_tracks);
+	direct_link_nladata(fd, &adt->nla_tracks);
 }	
 
 /* ************ READ NODE TREE *************** */
@@ -9302,6 +9355,8 @@
 static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt)
 {
 	FCurve *fcd;
+	NlaTrack *nlt;
+	NlaStrip *strip;
 	
 	/* own action */
 	expand_doit(fd, mainvar, adt->action);
@@ -9314,6 +9369,12 @@
 		for (dtar= driver->targets.first; dtar; dtar= dtar->next)
 			expand_doit(fd, mainvar, dtar->id);
 	}
+	
+	/* nla-data - referenced actions */
+	for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
+		for (strip= nlt->strips.first; strip; strip= strip->next) 
+			expand_doit(fd, mainvar, strip->act);
+	}
 }	
 
 static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSettings *part)

Modified: branches/soc-2009-aligorith/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenloader/intern/writefile.c	2009-05-22 09:48:05 UTC (rev 20339)
+++ branches/soc-2009-aligorith/source/blender/blenloader/intern/writefile.c	2009-05-22 11:19:35 UTC (rev 20340)
@@ -760,10 +760,59 @@
 	}
 }
 
+static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
+{
+	FModifier *fcm;
+	
+	/* Modifiers */
+	for (fcm= fmodifiers->first; fcm; fcm= fcm->next) {
+		FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
+		
+		/* Write the specific data */
+		if (fmi && fcm->data) {
+			/* firstly, just write the plain fmi->data struct */
+			writestruct(wd, DATA, fmi->structName, 1, fcm->data);
+			
+			/* do any modifier specific stuff */
+			switch (fcm->type) {
+				case FMODIFIER_TYPE_GENERATOR:
+				{
+					FMod_Generator *data= (FMod_Generator *)fcm->data;
+					
+					/* write coefficients array */
+					if (data->coefficients)
+						writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients);
+				}
+					break;
+				case FMODIFIER_TYPE_ENVELOPE:
+				{
+					FMod_Envelope *data= (FMod_Envelope *)fcm->data;
+					
+					/* write envelope data */
+					if (data->data)
+						writedata(wd, DATA, sizeof(FCM_EnvelopeData)*(data->totvert), data->data);
+				}
+					break;
+				case FMODIFIER_TYPE_PYTHON:
+				{
+					FMod_Python *data = (FMod_Python *)fcm->data;
+					
+					/* Write ID Properties -- and copy this comment EXACTLY for easy finding
+					 of library blocks that implement this.*/
+					IDP_WriteProperty(data->prop, wd);
+				}
+					break;
+			}
+		}
+		
+		/* Write the modifier */
+		writestruct(wd, DATA, "FModifier", 1, fcm);
+	}
+}
+
 static void write_fcurves(WriteData *wd, ListBase *fcurves)
 {
 	FCurve *fcu;
-	FModifier *fcm;
 	
 	for (fcu=fcurves->first; fcu; fcu=fcu->next) {
 		/* F-Curve */
@@ -794,50 +843,8 @@
 			}
 		}
 		
-		/* Modifiers */
-		for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
-			FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
-			
-			/* Write the specific data */
-			if (fmi && fcm->data) {
-				/* firstly, just write the plain fmi->data struct */
-				writestruct(wd, DATA, fmi->structName, 1, fcm->data);
-				
-				/* do any modifier specific stuff */
-				switch (fcm->type) {
-					case FMODIFIER_TYPE_GENERATOR:
-					{
-						FMod_Generator *data= (FMod_Generator *)fcm->data;
-						
-						/* write coefficients array */
-						if (data->coefficients)
-							writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients);
-					}
-						break;
-					case FMODIFIER_TYPE_ENVELOPE:
-					{
-						FMod_Envelope *data= (FMod_Envelope *)fcm->data;
-						
-						/* write envelope data */
-						if (data->data)
-							writedata(wd, DATA, sizeof(FCM_EnvelopeData)*(data->totvert), data->data);
-					}
-						break;
-					case FMODIFIER_TYPE_PYTHON:
-					{
-						FMod_Python *data = (FMod_Python *)fcm->data;
-						
-						/* Write ID Properties -- and copy this comment EXACTLY for easy finding
-						 of library blocks that implement this.*/
-						IDP_WriteProperty(data->prop, wd);
-					}
-						break;
-				}
-			}
-			
-			/* Write the modifier */
-			writestruct(wd, DATA, "FModifier", 1, fcm);
-		}
+		/* write F-Modifiers */
+		write_fmodifiers(wd, &fcu->modifiers);
 	}
 }
 
@@ -888,6 +895,29 @@
 	}
 }
 
+static void write_nladata(WriteData *wd, ListBase *nlabase)
+{
+	NlaTrack *nlt;
+	NlaStrip *strip;
+	
+	/* write all the tracks */
+	for (nlt= nlabase->first; nlt; nlt= nlt->next) {
+		/* write the track first */
+		writestruct(wd, DATA, "NlaTrack", 1, nlt);
+		
+		for (strip= nlt->strips.first; strip; strip= strip->next) {
+			/* write the strip first */
+			writestruct(wd, DATA, "NlaStrip", 1, strip);
+			
+			/* write the strip's F-Curves and modifiers */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list