Fix T81580: No doversion for Emission Strength

The new parameter made so that previously keyed Alpha values were lost
and instead the new "Emission Strength" was keyed.

Issue introduced with the original commit of Emission Strength: b248ec9776

Note: Files created since the issue (September 17) that keyframed the
Emission Strength will have to fix their files manually.

Differential Revision: https://developer.blender.org/D9221
This commit is contained in:
Dalai Felinto 2020-10-15 12:02:56 +02:00
parent ca55a1b564
commit c866075dfb
Notes: blender-bot 2023-06-21 19:23:24 +02:00
Referenced by commit 89ffdad0f3, Fix misuse of alloc inside a loop
Referenced by issue #81580, Keyframed Principled Shader "Alpha" Values in older files get mapped to "Emission Strength" in 2.91
4 changed files with 100 additions and 18 deletions

View File

@ -152,6 +152,16 @@ void BKE_animdata_fix_paths_rename_all(struct ID *ref_id,
const char *oldName,
const char *newName);
/* Fix all the paths for the entire bmain with extra parameters. */
void BKE_animdata_fix_paths_rename_all_ex(struct Main *bmain,
struct ID *ref_id,
const char *prefix,
const char *oldName,
const char *newName,
const int oldSubscript,
const int newSubscript,
const bool verify_paths);
/* Fix the path after removing elements that are not ID (e.g., node).
* Return true if any animation data was affected. */
bool BKE_animdata_fix_paths_remove(struct ID *id, const char *path);

View File

@ -39,7 +39,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 7
#define BLENDER_FILE_SUBVERSION 8
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@ -1406,13 +1406,30 @@ void BKE_animdata_main_cb(Main *bmain, ID_AnimData_Edit_Callback func, void *use
* NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]>
* i.e. pose.bones["Bone"]
*/
/* TODO: use BKE_animdata_main_cb for looping over all data */
void BKE_animdata_fix_paths_rename_all(ID *ref_id,
const char *prefix,
const char *oldName,
const char *newName)
{
Main *bmain = G.main; /* XXX UGLY! */
BKE_animdata_fix_paths_rename_all_ex(bmain, ref_id, prefix, oldName, newName, 0, 0, 1);
}
/* Fix all RNA-Paths throughout the database
* NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]>
* i.e. pose.bones["Bone"]
*/
/* TODO: use BKE_animdata_main_cb for looping over all data */
void BKE_animdata_fix_paths_rename_all_ex(Main *bmain,
ID *ref_id,
const char *prefix,
const char *oldName,
const char *newName,
const int oldSubscript,
const int newSubscript,
const bool verify_paths)
{
ID *id;
/* macro for less typing
@ -1422,7 +1439,8 @@ void BKE_animdata_fix_paths_rename_all(ID *ref_id,
#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, ref_id, prefix, oldName, newName, 0, 0, 1); \
BKE_animdata_fix_paths_rename( \
id, adt, ref_id, prefix, oldName, newName, oldSubscript, newSubscript, verify_paths); \
} \
(void)0
@ -1433,10 +1451,18 @@ void BKE_animdata_fix_paths_rename_all(ID *ref_id,
NtId_Type *ntp = (NtId_Type *)id; \
if (ntp->nodetree) { \
AnimData *adt2 = BKE_animdata_from_id((ID *)ntp->nodetree); \
BKE_animdata_fix_paths_rename( \
(ID *)ntp->nodetree, adt2, ref_id, prefix, oldName, newName, 0, 0, 1); \
BKE_animdata_fix_paths_rename((ID *)ntp->nodetree, \
adt2, \
ref_id, \
prefix, \
oldName, \
newName, \
oldSubscript, \
newSubscript, \
verify_paths); \
} \
BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1); \
BKE_animdata_fix_paths_rename( \
id, adt, ref_id, prefix, oldName, newName, oldSubscript, newSubscript, verify_paths); \
} \
(void)0

View File

@ -20,6 +20,7 @@
/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW
#include "BLI_alloca.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_string.h"
@ -43,6 +44,7 @@
#include "DNA_shader_fx_types.h"
#include "DNA_workspace_types.h"
#include "BKE_animsys.h"
#include "BKE_collection.h"
#include "BKE_colortools.h"
#include "BKE_gpencil.h"
@ -229,6 +231,47 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports))
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 291, 8)) {
/**
* Make sure Emission Alpha fcurve and drivers is properly mapped after the Emission Strength
* got introduced.
* */
/**
* Effectively we are replacing the (animation of) node socket input 18 with 19.
* Emission Strength is the new socket input 18, pushing Emission Alpha to input 19.
*
* To play safe we move all the inputs beyond 18 to their rightful new place.
* In case users are doing unexpected things with not-really supported keyframeable channels.
*
* The for loop for the input ids is at the top level otherwise we loose the animation
* keyframe data.
* */
for (int input_id = 21; input_id >= 18; input_id--) {
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
if (ntree->type == NTREE_SHADER) {
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type != SH_NODE_BSDF_PRINCIPLED) {
continue;
}
const size_t node_name_length = strlen(node->name);
const size_t node_name_escaped_max_length = (node_name_length * 2);
char *node_name_escaped = BLI_array_alloca(node_name_escaped,
node_name_escaped_max_length + 1);
BLI_strescape(node_name_escaped, node->name, node_name_escaped_max_length);
char *rna_path_prefix = BLI_sprintfN("nodes[\"%s\"].inputs", node_name_escaped);
BKE_animdata_fix_paths_rename_all_ex(
bmain, id, rna_path_prefix, NULL, NULL, input_id, input_id + 1, false);
MEM_freeN(rna_path_prefix);
}
}
}
FOREACH_NODETREE_END;
}
}
/**
* Versioning code until next subversion bump goes here.
*
@ -769,17 +812,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
if (!MAIN_VERSION_ATLEAST(bmain, 291, 8)) {
if (!DNA_struct_elem_find(fd->filesdna, "WorkSpaceDataRelation", "int", "parentid")) {
LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) {
LISTBASE_FOREACH_MUTABLE (
@ -821,4 +854,17 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
}
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
}
}