Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2013-10-01 20:15:52 +0400
committerDalai Felinto <dfelinto@gmail.com>2013-10-01 20:15:52 +0400
commitd2e55cb28253b6085212d962a60567ef3d542c18 (patch)
tree9c57d7ef0f55fcfbd750e65769123a408e8e16d2
parent1fa59cdf4dcae382904ea06bfdeba19d89a9f0ad (diff)
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
-rw-r--r--source/blender/blenkernel/BKE_animsys.h3
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c71
-rw-r--r--source/blender/blenkernel/intern/node.c7
3 files changed, 81 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h
index dd150ba6a63..f0f6b5a2319 100644
--- a/source/blender/blenkernel/BKE_animsys.h
+++ b/source/blender/blenkernel/BKE_animsys.h
@@ -112,6 +112,9 @@ void BKE_animdata_fix_paths_rename(struct ID *owner_id, struct AnimData *adt, st
/* 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 */
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 8e697ad4ef3..b2ce6eef29a 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -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 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, cons
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 */
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 071edb9067c..e296e97fb11 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -1594,6 +1594,8 @@ static void node_unlink_attached(bNodeTree *ntree, bNode *parent)
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 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node)
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);