From a730cda72ff94ea0df73b61d62c01c45992d5bde Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 23 Jan 2015 02:33:01 +1300 Subject: Fix: Joining armatures fixes up the drivers accordingly Finally! At long last, I've gotten this working! This ended up being far trickier to get right than anticipated; the normal remapping API's cannot be used as-is as they will just clobber over subtleties whenever datablock changes are involved. So, for now, we have to duplicate the logic a bit. --- source/blender/blenkernel/intern/anim_sys.c | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'source/blender/blenkernel/intern/anim_sys.c') diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 00e5c1be48e..aa353afadc1 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -858,6 +858,60 @@ static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, const ch } } +/* ----------------------- */ + + +/* Fix up the given RNA-Path + * + * This is just an external wrapper for the RNA-Path fixing function, + * with input validity checks on top of the basic method. + * + * NOTE: it is assumed that the structure we're replacing is <["><"]> + * i.e. pose.bones["Bone"] + */ +char *BKE_animsys_fix_rna_path_rename(ID *owner_id, char *old_path, const char *prefix, const char *oldName, + const char *newName, int oldSubscript, int newSubscript, bool verify_paths) +{ + char *oldN, *newN; + char *result; + + /* if no action, no need to proceed */ + if (ELEM(NULL, owner_id, old_path)) { + printf("early abort\n"); + return old_path; + } + + /* Name sanitation logic - copied from BKE_animdata_fix_paths_rename() */ + if ((oldName != NULL) && (newName != NULL)) { + /* pad the names with [" "] so that only exact matches are made */ + const size_t name_old_len = strlen(oldName); + const size_t name_new_len = strlen(newName); + char *name_old_esc = BLI_array_alloca(name_old_esc, (name_old_len * 2) + 1); + char *name_new_esc = BLI_array_alloca(name_new_esc, (name_new_len * 2) + 1); + + BLI_strescape(name_old_esc, oldName, (name_old_len * 2) + 1); + BLI_strescape(name_new_esc, newName, (name_new_len * 2) + 1); + oldN = BLI_sprintfN("[\"%s\"]", name_old_esc); + newN = BLI_sprintfN("[\"%s\"]", name_new_esc); + } + else { + oldN = BLI_sprintfN("[%d]", oldSubscript); + newN = BLI_sprintfN("[%d]", newSubscript); + } + + /* fix given path */ + printf("%s | %s | oldpath = %p ", oldN, newN, old_path); + result = rna_path_rename_fix(owner_id, prefix, oldN, newN, old_path, verify_paths); + printf("result = %p\n", result); + + /* free the temp names */ + MEM_freeN(oldN); + MEM_freeN(newN); + + /* return the resulting path - may be the same path again if nothing changed */ + return result; +} + /* Fix all RNA_Paths in the given Action, relative to the given ID block * * This is just an external wrapper for the F-Curve fixing function, -- cgit v1.2.3