[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60495] trunk/blender/source/blender/ blenkernel: bugfix [#32346] Node animation, removing nodes keeps FCurves.

Dalai Felinto dfelinto at gmail.com
Tue Oct 1 18:15:52 CEST 2013


Revision: 60495
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60495
Author:   dfelinto
Date:     2013-10-01 16:15:52 +0000 (Tue, 01 Oct 2013)
Log Message:
-----------
bugfix [#32346] Node animation, removing nodes keeps FCurves.

The same bug happens for modifiers, but better to address it separately.
Contribution and review by Lukas Toenne and Brecht van Lommel

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_animsys.h
    trunk/blender/source/blender/blenkernel/intern/anim_sys.c
    trunk/blender/source/blender/blenkernel/intern/node.c

Modified: trunk/blender/source/blender/blenkernel/BKE_animsys.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_animsys.h	2013-10-01 15:52:29 UTC (rev 60494)
+++ trunk/blender/source/blender/blenkernel/BKE_animsys.h	2013-10-01 16:15:52 UTC (rev 60495)
@@ -112,6 +112,9 @@
 /* Fix all the paths for the entire database... */
 void BKE_all_animdata_fix_paths_rename(ID *ref_id, const char *prefix, const char *oldName, const char *newName);
 
+/* Fix the path after removing elements that are not ID (e.g., node) */
+void BKE_animdata_fix_paths_remove(struct ID *id, const char *path);
+
 /* -------------------------------------- */
 
 /* Move animation data from src to destination if it's paths are based on basepaths */

Modified: trunk/blender/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2013-10-01 15:52:29 UTC (rev 60494)
+++ trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2013-10-01 16:15:52 UTC (rev 60495)
@@ -42,6 +42,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_alloca.h"
 #include "BLI_dynstr.h"
+#include "BLI_listbase.h"
 
 #include "BLF_translation.h"
 
@@ -759,6 +760,76 @@
 	MEM_freeN(newN);
 }
 
+/* *************************** */
+/* remove of individual paths */
+
+/* Check RNA-Paths for a list of F-Curves */
+static void fcurves_path_remove_fix(const char *prefix, ListBase *curves)
+{
+	FCurve *fcu, *fcn;
+	if (!prefix) return;
+
+	/* we need to check every curve... */
+	for (fcu = curves->first; fcu; fcu = fcn) {
+		fcn = fcu->next;
+
+		if (fcu->rna_path) {
+			if (strncmp(prefix, fcu->rna_path, strlen(prefix)) == 0) {
+				BLI_remlink(curves, fcu);
+				free_fcurve(fcu);
+			}
+		}
+	}
+}
+
+/* Check RNA-Paths for a list of F-Curves */
+static void nlastrips_path_remove_fix(const char *prefix, ListBase *strips)
+{
+	NlaStrip *strip;
+
+	/* recursively check strips, fixing only actions... */
+	for (strip = strips->first; strip; strip = strip->next) {
+
+		/* fix strip's action */
+		if (strip->act)
+			fcurves_path_remove_fix(prefix, &strip->act->curves);
+
+		/* check sub-strips (if metas) */
+		nlastrips_path_remove_fix(prefix, &strip->strips);
+	}
+}
+
+void BKE_animdata_fix_paths_remove(ID *id, const char *prefix)
+{
+	/* Only some ID-blocks have this info for now, so we cast the
+	 * types that do to be of type IdAdtTemplate
+	 */
+	NlaTrack *nlt;
+
+	if (id_type_can_have_animdata(id)) {
+		IdAdtTemplate *iat = (IdAdtTemplate *)id;
+		AnimData *adt = iat->adt;
+
+		/* check if there's any AnimData to start with */
+		if (adt) {
+
+			/* free fcurves */
+			if (adt->action)
+				fcurves_path_remove_fix(prefix, &adt->action->curves);
+
+			if (adt->tmpact)
+				fcurves_path_remove_fix(prefix, &adt->tmpact->curves);
+
+			/* free drivers - stored as a list of F-Curves */
+			fcurves_path_remove_fix(prefix, &adt->drivers);
+
+			/* NLA Data - Animation Data for Strips */
+			for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next)
+				nlastrips_path_remove_fix(prefix, &nlt->strips);
+		}
+	}
+}
+
 /* Whole Database Ops -------------------------------------------- */
 
 /* apply the given callback function on all data in main database */

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2013-10-01 15:52:29 UTC (rev 60494)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2013-10-01 16:15:52 UTC (rev 60495)
@@ -1594,6 +1594,8 @@
 void nodeFreeNode(bNodeTree *ntree, bNode *node)
 {
 	bNodeSocket *sock, *nextsock;
+	char propname_esc[MAX_IDPROP_NAME * 2];
+	char prefix[MAX_IDPROP_NAME * 2];
 	
 	/* extra free callback */
 	if (node->typeinfo && node->typeinfo->freefunc_api) {
@@ -1613,6 +1615,11 @@
 		
 		BLI_remlink(&ntree->nodes, node);
 		
+		BLI_strescape(propname_esc, node->name, sizeof(propname_esc));
+		BLI_snprintf(prefix, sizeof(prefix), "nodes[\"%s\"]", propname_esc);
+
+		BKE_animdata_fix_paths_remove((ID *)ntree, prefix);
+
 		if (ntree->typeinfo && ntree->typeinfo->free_node_cache)
 			ntree->typeinfo->free_node_cache(ntree, node);
 		




More information about the Bf-blender-cvs mailing list