diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-01-26 19:02:28 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-01-26 19:02:28 +0300 |
commit | 9e48cafd6d6a3512a41e98e71d957923fbf3cb1d (patch) | |
tree | 1431c8a1fd6e834059d4aa1f063620a036feba46 /source/blender/blenloader/intern/versioning_270.c | |
parent | 290e080db40e746416d2f70d28cb906ceb4c4723 (diff) | |
parent | fd69ba225540cde5e4c1fa651fb02df21ea0a143 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenloader/intern/versioning_270.c')
-rw-r--r-- | source/blender/blenloader/intern/versioning_270.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 58cc06ddec6..b0fe5cf93ad 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -34,6 +34,7 @@ /* allow readfile to use deprecated functionality */ #define DNA_DEPRECATED_ALLOW +#include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_brush_types.h" #include "DNA_camera_types.h" @@ -58,6 +59,7 @@ #include "DNA_genfile.h" +#include "BKE_animsys.h" #include "BKE_colortools.h" #include "BKE_library.h" #include "BKE_main.h" @@ -76,6 +78,9 @@ #include "BLO_readfile.h" +#include "NOD_common.h" +#include "NOD_socket.h" + #include "readfile.h" #include "MEM_guardedalloc.h" @@ -195,6 +200,50 @@ static void do_version_bones_super_bbone(ListBase *lb) } } +/* TODO(sergey): Consider making it somewhat more generic function in BLI_anim.h. */ +static void anim_change_prop_name(FCurve *fcu, + const char *prefix, + const char *old_prop_name, + const char *new_prop_name) +{ + const char *old_path = BLI_sprintfN("%s.%s", prefix, old_prop_name); + if (STREQ(fcu->rna_path, old_path)) { + MEM_freeN(fcu->rna_path); + fcu->rna_path = BLI_sprintfN("%s.%s", prefix, new_prop_name); + } + MEM_freeN((char *)old_path); +} + +static void do_version_hue_sat_node(bNodeTree *ntree, bNode *node) +{ + /* Make sure new sockets are properly created. */ + node_verify_socket_templates(ntree, node); + /* Convert value from old storage to new sockets. */ + NodeHueSat *nhs = node->storage; + bNodeSocket *hue = nodeFindSocket(node, SOCK_IN, "Hue"), + *saturation = nodeFindSocket(node, SOCK_IN, "Saturation"), + *value = nodeFindSocket(node, SOCK_IN, "Value"); + ((bNodeSocketValueFloat *)hue->default_value)->value = nhs->hue; + ((bNodeSocketValueFloat *)saturation->default_value)->value = nhs->sat; + ((bNodeSocketValueFloat *)value->default_value)->value = nhs->val; + /* Take care of possible animation. */ + AnimData *adt = BKE_animdata_from_id(&ntree->id); + if (adt != NULL && adt->action != NULL) { + const char *prefix = BLI_sprintfN("nodes[\"%s\"]", node->name); + for (FCurve *fcu = adt->action->curves.first; fcu != NULL; fcu = fcu->next) { + if (STRPREFIX(fcu->rna_path, prefix)) { + anim_change_prop_name(fcu, prefix, "color_hue", "inputs[1].default_value"); + anim_change_prop_name(fcu, prefix, "color_saturation", "inputs[2].default_value"); + anim_change_prop_name(fcu, prefix, "color_value", "inputs[3].default_value"); + } + } + MEM_freeN((char *)prefix); + } + /* Free storage, it is no longer used. */ + MEM_freeN(node->storage); + node->storage = NULL; +} + void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) { if (!MAIN_VERSION_ATLEAST(main, 270, 0)) { @@ -1521,6 +1570,24 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } + + } +} + +void do_versions_after_linking_270(Main *main) +{ + /* To be added to next subversion bump! */ + { + FOREACH_NODETREE(main, ntree, id) { + if (ntree->type == NTREE_COMPOSIT) { + ntreeSetTypes(NULL, ntree); + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_HUE_SAT) { + do_version_hue_sat_node(ntree, node); + } + } + } + } FOREACH_NODETREE_END } { |