Fix [#21165] Moved textures don't move the animation curves

This commit is contained in:
Matt Ebb 2010-03-16 07:44:57 +00:00
parent ea4a987fd4
commit dc5945e7f0
4 changed files with 39 additions and 25 deletions

@ -92,7 +92,7 @@ void BKE_keyingsets_free(struct ListBase *list);
/* Path Fixing API */ /* Path Fixing API */
/* Fix all the paths for the given ID+AnimData */ /* 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... */ /* Fix all the paths for the entire database... */
void BKE_all_animdata_fix_paths_rename(char *prefix, char *oldName, char *newName); void BKE_all_animdata_fix_paths_rename(char *prefix, char *oldName, char *newName);

@ -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 /* 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 * 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 *prefixPtr= strstr(oldpath, prefix);
char *oldNamePtr= strstr(oldpath, oldName); 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 ( (prefixPtr && oldNamePtr) && (prefixPtr+prefixLen == oldNamePtr) ) {
/* if we haven't aren't able to resolve the path now, try again after fixing it */ /* 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(); DynStr *ds= BLI_dynstr_new();
char *postfixPtr= oldNamePtr+oldNameLen; char *postfixPtr= oldNamePtr+oldNameLen;
char *newPath = NULL; 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 */ /* check if the new path will solve our problems */
// TODO: will need to check whether this step really helps in practice // 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 */ /* free the old path, and return the new one, since we've solved the issues */
MEM_freeN(oldpath); MEM_freeN(oldpath);
return newPath; 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 */ /* 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; 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) { for (fcu= curves->first; fcu; fcu= fcu->next) {
/* firstly, handle the F-Curve's own path */ /* firstly, handle the F-Curve's own path */
if (fcu->rna_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? */ /* driver? */
if (fcu->driver) { if (fcu->driver) {
@ -354,7 +354,7 @@ static void fcurves_path_rename_fix (ID *owner_id, char *prefix, char *oldName,
{ {
/* rename RNA path */ /* rename RNA path */
if (dtar->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) */ /* 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 // 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 */ /* 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; 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) { for (strip= strips->first; strip; strip= strip->next) {
/* fix strip's action */ /* fix strip's action */
if (strip->act) 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... */ /* ignore own F-Curves, since those are local... */
/* check sub-strips (if metas) */ /* 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 <prefix><["><name><"]> * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]>
* i.e. pose.bones["Bone"] * 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; NlaTrack *nlt;
char *oldN, *newN; char *oldN, *newN;
/* if no AnimData, no need to proceed */ /* if no AnimData, no need to proceed */
if (ELEM4(NULL, owner_id, adt, oldName, newName)) if (ELEM(NULL, owner_id, adt))
return; return;
/* pad the names with [" "] so that only exact matches are made */ if (oldName != NULL && newName != NULL) {
oldN= BLI_sprintfN("[\"%s\"]", oldName); /* pad the names with [" "] so that only exact matches are made */
newN= BLI_sprintfN("[\"%s\"]", newName); 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 */ /* Active action and temp action */
if (adt->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) 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 */ /* 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 */ /* NLA Data - Animation Data for Strips */
for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) 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 */ /* free the temp names */
MEM_freeN(oldN); 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) \ #define RENAMEFIX_ANIM_IDS(first) \
for (id= first; id; id= id->next) { \ for (id= first; id; id= id->next) { \
AnimData *adt= BKE_animdata_from_id(id); \ 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 */ /* 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) */ /* do compositing nodes first (since these aren't included in main tree) */
if (scene->nodetree) { if (scene->nodetree) {
AnimData *adt2= BKE_animdata_from_id((ID *)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 */ /* 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);
} }
} }

@ -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) // TODO: should we be using the database wide version instead (since drivers may break)
if (ob->adt) { if (ob->adt) {
/* posechannels only... */ /* 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);
} }
} }
} }

@ -697,6 +697,7 @@ void SCENE_OT_render_layer_remove(wmOperatorType *ot)
static int texture_slot_move(bContext *C, wmOperator *op) static int texture_slot_move(bContext *C, wmOperator *op)
{ {
ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data; ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
Material *ma = (Material *)id;
if(id) { if(id) {
MTex **mtex_ar, *mtexswap; MTex **mtex_ar, *mtexswap;
@ -710,6 +711,10 @@ static int texture_slot_move(bContext *C, wmOperator *op)
mtexswap = mtex_ar[act]; mtexswap = mtex_ar[act];
mtex_ar[act] = mtex_ar[act-1]; mtex_ar[act] = mtex_ar[act-1];
mtex_ar[act-1] = mtexswap; 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) { if(GS(id->name)==ID_MA) {
Material *ma= (Material *)id; Material *ma= (Material *)id;
@ -719,7 +724,7 @@ static int texture_slot_move(bContext *C, wmOperator *op)
ma->septex &= ~(1<<(act-1)); ma->septex &= ~(1<<(act-1));
ma->septex |= mtexuse >> 1; ma->septex |= mtexuse >> 1;
} }
set_active_mtex(id, act-1); set_active_mtex(id, act-1);
} }
} }
@ -728,6 +733,10 @@ static int texture_slot_move(bContext *C, wmOperator *op)
mtexswap = mtex_ar[act]; mtexswap = mtex_ar[act];
mtex_ar[act] = mtex_ar[act+1]; mtex_ar[act] = mtex_ar[act+1];
mtex_ar[act+1] = mtexswap; 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) { if(GS(id->name)==ID_MA) {
Material *ma= (Material *)id; Material *ma= (Material *)id;
@ -737,7 +746,7 @@ static int texture_slot_move(bContext *C, wmOperator *op)
ma->septex &= ~(1<<(act+1)); ma->septex &= ~(1<<(act+1));
ma->septex |= mtexuse << 1; ma->septex |= mtexuse << 1;
} }
set_active_mtex(id, act+1); set_active_mtex(id, act+1);
} }
} }