From dc5945e7f0f5d7e85f9ff1dfbb5f762f45cf3509 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Tue, 16 Mar 2010 07:44:57 +0000 Subject: [PATCH] Fix [#21165] Moved textures don't move the animation curves --- source/blender/blenkernel/BKE_animsys.h | 2 +- source/blender/blenkernel/intern/anim_sys.c | 47 ++++++++++--------- .../blender/editors/armature/editarmature.c | 2 +- .../blender/editors/render/render_shading.c | 13 ++++- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index 8644074d4e9..af5e31b1efa 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -92,7 +92,7 @@ void BKE_keyingsets_free(struct ListBase *list); /* Path Fixing API */ /* Fix all the paths for the given ID+AnimData */ -void BKE_animdata_fix_paths_rename(struct ID *owner_id, struct AnimData *adt, char *prefix, char *oldName, char *newName); +void BKE_animdata_fix_paths_rename(struct ID *owner_id, struct AnimData *adt, char *prefix, char *oldName, char *newName, int oldSubscript, int newSubscript, int verify_paths); /* Fix all the paths for the entire database... */ void BKE_all_animdata_fix_paths_rename(char *prefix, char *oldName, char *newName); diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 8ec8f24d5fe..307ed1bfcd4 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -274,7 +274,7 @@ static short check_rna_path_is_valid (ID *owner_id, char *path) /* Check if some given RNA Path needs fixing - free the given path and set a new one as appropriate * NOTE: we assume that oldName and newName have [" "] padding around them */ -static char *rna_path_rename_fix (ID *owner_id, char *prefix, char *oldName, char *newName, char *oldpath) +static char *rna_path_rename_fix (ID *owner_id, char *prefix, char *oldName, char *newName, char *oldpath, int verify_paths) { char *prefixPtr= strstr(oldpath, prefix); char *oldNamePtr= strstr(oldpath, oldName); @@ -286,7 +286,7 @@ static char *rna_path_rename_fix (ID *owner_id, char *prefix, char *oldName, cha */ if ( (prefixPtr && oldNamePtr) && (prefixPtr+prefixLen == oldNamePtr) ) { /* if we haven't aren't able to resolve the path now, try again after fixing it */ - if (check_rna_path_is_valid(owner_id, oldpath) == 0) { + if (!verify_paths || check_rna_path_is_valid(owner_id, oldpath) == 0) { DynStr *ds= BLI_dynstr_new(); char *postfixPtr= oldNamePtr+oldNameLen; char *newPath = NULL; @@ -315,7 +315,7 @@ static char *rna_path_rename_fix (ID *owner_id, char *prefix, char *oldName, cha /* check if the new path will solve our problems */ // TODO: will need to check whether this step really helps in practice - if (check_rna_path_is_valid(owner_id, newPath)) { + if (!verify_paths || check_rna_path_is_valid(owner_id, newPath)) { /* free the old path, and return the new one, since we've solved the issues */ MEM_freeN(oldpath); return newPath; @@ -332,7 +332,7 @@ static char *rna_path_rename_fix (ID *owner_id, char *prefix, char *oldName, cha } /* Check RNA-Paths for a list of F-Curves */ -static void fcurves_path_rename_fix (ID *owner_id, char *prefix, char *oldName, char *newName, ListBase *curves) +static void fcurves_path_rename_fix (ID *owner_id, char *prefix, char *oldName, char *newName, ListBase *curves, int verify_paths) { FCurve *fcu; @@ -340,7 +340,7 @@ static void fcurves_path_rename_fix (ID *owner_id, char *prefix, char *oldName, for (fcu= curves->first; fcu; fcu= fcu->next) { /* firstly, handle the F-Curve's own path */ if (fcu->rna_path) - fcu->rna_path= rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path); + fcu->rna_path= rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path, verify_paths); /* driver? */ if (fcu->driver) { @@ -354,7 +354,7 @@ static void fcurves_path_rename_fix (ID *owner_id, char *prefix, char *oldName, { /* rename RNA path */ if (dtar->rna_path) - dtar->rna_path= rna_path_rename_fix(dtar->id, prefix, oldName, newName, dtar->rna_path); + dtar->rna_path= rna_path_rename_fix(dtar->id, prefix, oldName, newName, dtar->rna_path, verify_paths); /* also fix the bone-name (if applicable) */ // XXX this has been disabled because the old/new names have padding which means this check will fail @@ -371,7 +371,7 @@ static void fcurves_path_rename_fix (ID *owner_id, char *prefix, char *oldName, } /* Fix all RNA-Paths for Actions linked to NLA Strips */ -static void nlastrips_path_rename_fix (ID *owner_id, char *prefix, char *oldName, char *newName, ListBase *strips) +static void nlastrips_path_rename_fix (ID *owner_id, char *prefix, char *oldName, char *newName, ListBase *strips, int verify_paths) { NlaStrip *strip; @@ -379,11 +379,11 @@ static void nlastrips_path_rename_fix (ID *owner_id, char *prefix, char *oldName for (strip= strips->first; strip; strip= strip->next) { /* fix strip's action */ if (strip->act) - fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &strip->act->curves); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &strip->act->curves, verify_paths); /* ignore own F-Curves, since those are local... */ /* check sub-strips (if metas) */ - nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, &strip->strips); + nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, &strip->strips, verify_paths); } } @@ -391,31 +391,36 @@ static void nlastrips_path_rename_fix (ID *owner_id, char *prefix, char *oldName * NOTE: it is assumed that the structure we're replacing is <["><"]> * i.e. pose.bones["Bone"] */ -void BKE_animdata_fix_paths_rename (ID *owner_id, AnimData *adt, char *prefix, char *oldName, char *newName) +void BKE_animdata_fix_paths_rename (ID *owner_id, AnimData *adt, char *prefix, char *oldName, char *newName, int oldSubscript, int newSubscript, int verify_paths) { NlaTrack *nlt; char *oldN, *newN; /* if no AnimData, no need to proceed */ - if (ELEM4(NULL, owner_id, adt, oldName, newName)) + if (ELEM(NULL, owner_id, adt)) return; - /* pad the names with [" "] so that only exact matches are made */ - oldN= BLI_sprintfN("[\"%s\"]", oldName); - newN= BLI_sprintfN("[\"%s\"]", newName); + if (oldName != NULL && newName != NULL) { + /* pad the names with [" "] so that only exact matches are made */ + oldN= BLI_sprintfN("[\"%s\"]", oldName); + newN= BLI_sprintfN("[\"%s\"]", newName); + } else { + oldN= BLI_sprintfN("[%d]", oldSubscript); + newN= BLI_sprintfN("[%d]", newSubscript); + } /* Active action and temp action */ if (adt->action) - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->action->curves); + fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->action->curves, verify_paths); if (adt->tmpact) - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->tmpact->curves); + fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->tmpact->curves, verify_paths); /* Drivers - Drivers are really F-Curves */ - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->drivers); + fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->drivers, verify_paths); /* NLA Data - Animation Data for Strips */ for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) - nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips); + nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips, verify_paths); /* free the temp names */ MEM_freeN(oldN); @@ -482,7 +487,7 @@ void BKE_all_animdata_fix_paths_rename (char *prefix, char *oldName, char *newNa #define RENAMEFIX_ANIM_IDS(first) \ for (id= first; id; id= id->next) { \ AnimData *adt= BKE_animdata_from_id(id); \ - BKE_animdata_fix_paths_rename(id, adt, prefix, oldName, newName);\ + BKE_animdata_fix_paths_rename(id, adt, prefix, oldName, newName, 0, 0, 1);\ } /* nodes */ @@ -532,11 +537,11 @@ void BKE_all_animdata_fix_paths_rename (char *prefix, char *oldName, char *newNa /* do compositing nodes first (since these aren't included in main tree) */ if (scene->nodetree) { AnimData *adt2= BKE_animdata_from_id((ID *)scene->nodetree); - BKE_animdata_fix_paths_rename((ID *)scene->nodetree, adt2, prefix, oldName, newName); + BKE_animdata_fix_paths_rename((ID *)scene->nodetree, adt2, prefix, oldName, newName, 0, 0, 1); } /* now fix scene animation data as per normal */ - BKE_animdata_fix_paths_rename((ID *)id, adt, prefix, oldName, newName); + BKE_animdata_fix_paths_rename((ID *)id, adt, prefix, oldName, newName, 0, 0, 1); } } diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 3f26a146c53..b4666923a03 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -5540,7 +5540,7 @@ void ED_armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep) // TODO: should we be using the database wide version instead (since drivers may break) if (ob->adt) { /* posechannels only... */ - BKE_animdata_fix_paths_rename(&ob->id, ob->adt, "pose.bones", oldname, newname); + BKE_animdata_fix_paths_rename(&ob->id, ob->adt, "pose.bones", oldname, newname, 0, 0, 1); } } } diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 91655855a61..d7f3436713c 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -697,6 +697,7 @@ void SCENE_OT_render_layer_remove(wmOperatorType *ot) static int texture_slot_move(bContext *C, wmOperator *op) { ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data; + Material *ma = (Material *)id; if(id) { MTex **mtex_ar, *mtexswap; @@ -710,6 +711,10 @@ static int texture_slot_move(bContext *C, wmOperator *op) mtexswap = mtex_ar[act]; mtex_ar[act] = mtex_ar[act-1]; mtex_ar[act-1] = mtexswap; + + BKE_animdata_fix_paths_rename(id, ma->adt, "texture_slots", NULL, NULL, act-1, -1, 0); + BKE_animdata_fix_paths_rename(id, ma->adt, "texture_slots", NULL, NULL, act, act-1, 0); + BKE_animdata_fix_paths_rename(id, ma->adt, "texture_slots", NULL, NULL, -1, act, 0); if(GS(id->name)==ID_MA) { Material *ma= (Material *)id; @@ -719,7 +724,7 @@ static int texture_slot_move(bContext *C, wmOperator *op) ma->septex &= ~(1<<(act-1)); ma->septex |= mtexuse >> 1; } - + set_active_mtex(id, act-1); } } @@ -728,6 +733,10 @@ static int texture_slot_move(bContext *C, wmOperator *op) mtexswap = mtex_ar[act]; mtex_ar[act] = mtex_ar[act+1]; mtex_ar[act+1] = mtexswap; + + BKE_animdata_fix_paths_rename(id, ma->adt, "texture_slots", NULL, NULL, act+1, -1, 0); + BKE_animdata_fix_paths_rename(id, ma->adt, "texture_slots", NULL, NULL, act, act+1, 0); + BKE_animdata_fix_paths_rename(id, ma->adt, "texture_slots", NULL, NULL, -1, act, 0); if(GS(id->name)==ID_MA) { Material *ma= (Material *)id; @@ -737,7 +746,7 @@ static int texture_slot_move(bContext *C, wmOperator *op) ma->septex &= ~(1<<(act+1)); ma->septex |= mtexuse << 1; } - + set_active_mtex(id, act+1); } }