diff options
author | Hans Goudey <h.goudey@me.com> | 2021-11-01 21:17:54 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-11-01 21:17:54 +0300 |
commit | 765c2cc6c7190540de48aaac4df11594dbd407ec (patch) | |
tree | 9ac2d19e46194b7724a644ed6cefcfd604b2943a | |
parent | 339fd8027f0b2d8aaa9efe7ecf0f7af410c14861 (diff) | |
parent | b6c2deef05cbaa015c74a0c5b1b0451686de49f6 (diff) |
Merge branch 'blender-v3.0-release'
5 files changed, 74 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc index cd40d5e8a41..ed4af2bbb08 100644 --- a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc +++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc @@ -202,7 +202,9 @@ static void spline_extrude_to_mesh_data(const ResultInfo &info, const int i_inv = info.profile_edge_len - i - 1; MLoop &loop_start = r_loops[cap_loop_offset + i]; loop_start.v = info.vert_offset + i_inv; - loop_start.e = profile_edges_start + i_inv; + loop_start.e = profile_edges_start + ((i == (info.profile_edge_len - 1)) ? + (info.profile_edge_len - 1) : + (i_inv - 1)); MLoop &loop_end = r_loops[cap_loop_offset + info.profile_edge_len + i]; loop_end.v = last_ring_vert_offset + i; loop_end.e = last_ring_edge_offset + i; diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c index def14768ec6..f82b7970a60 100644 --- a/source/blender/blenloader/intern/versioning_290.c +++ b/source/blender/blenloader/intern/versioning_290.c @@ -605,34 +605,8 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports)) * * 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 lose 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 = MEM_mallocN(node_name_escaped_max_length + 1, - "escaped name"); - BLI_str_escape(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); - MEM_freeN(node_name_escaped); - } - } - } - FOREACH_NODETREE_END; - } + version_node_socket_index_animdata(bmain, NTREE_SHADER, SH_NODE_BSDF_PRINCIPLED, 18, 1, 22); } /* Convert all Multires displacement to Catmull-Clark subdivision limit surface. */ diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index 68faa4c0672..47d919c151f 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -779,6 +779,8 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports)) */ { /* Keep this block, even when empty. */ + + version_node_socket_index_animdata(bmain, NTREE_SHADER, SH_NODE_BSDF_PRINCIPLED, 4, 2, 25); } } diff --git a/source/blender/blenloader/intern/versioning_common.cc b/source/blender/blenloader/intern/versioning_common.cc index ecc944defba..745bb7e8222 100644 --- a/source/blender/blenloader/intern/versioning_common.cc +++ b/source/blender/blenloader/intern/versioning_common.cc @@ -28,8 +28,10 @@ #include "BLI_listbase.h" #include "BLI_string.h" +#include "BKE_animsys.h" #include "BKE_lib_id.h" #include "BKE_main.h" +#include "BKE_node.h" #include "MEM_guardedalloc.h" @@ -149,3 +151,61 @@ void version_node_id(bNodeTree *ntree, const int node_type, const char *new_name } } } + +/** + * Adjust animation data for newly added node sockets. + * + * Node sockets are addressed by their index (in their RNA path, and thus FCurves/drivers), and + * thus when a new node is added in the middle of the list, existing animation data needs to be + * adjusted. + * + * Since this is about animation data, it only concerns input sockets. + * + * \param node_tree_type node tree type that has these nodes, for example NTREE_SHADER. + * \param node_type node type to adjust, for example SH_NODE_BSDF_PRINCIPLED. + * \param socket_index_orig the original index of the moved socket; when socket 4 moved to 6, + * pass 4 here. + * \param socket_index_offset the offset of the nodes, so when socket 4 moved to 6, + * pass 2 here. + * \param total_number_of_sockets the total number of sockets in the node. + */ +void version_node_socket_index_animdata(Main *bmain, + const int node_tree_type, + const int node_type, + const int socket_index_orig, + const int socket_index_offset, + const int total_number_of_sockets) +{ + + /* The for loop for the input ids is at the top level otherwise we lose the animation + * keyframe data. Not sure what causes that, so I (Sybren) moved the code here from + * versioning_290.c as-is (structure-wise). */ + for (int input_index = total_number_of_sockets - 1; input_index >= socket_index_orig; + input_index--) { + FOREACH_NODETREE_BEGIN (bmain, ntree, owner_id) { + if (ntree->type != node_tree_type) { + continue; + } + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type != node_type) { + 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 = (char *)MEM_mallocN(node_name_escaped_max_length + 1, + "escaped name"); + BLI_str_escape(node_name_escaped, node->name, node_name_escaped_max_length); + char *rna_path_prefix = BLI_sprintfN("nodes[\"%s\"].inputs", node_name_escaped); + + const int new_index = input_index + socket_index_offset; + BKE_animdata_fix_paths_rename_all_ex( + bmain, owner_id, rna_path_prefix, NULL, NULL, input_index, new_index, false); + MEM_freeN(rna_path_prefix); + MEM_freeN(node_name_escaped); + } + } + FOREACH_NODETREE_END; + } +} diff --git a/source/blender/blenloader/intern/versioning_common.h b/source/blender/blenloader/intern/versioning_common.h index 8697e8e2639..396927229c6 100644 --- a/source/blender/blenloader/intern/versioning_common.h +++ b/source/blender/blenloader/intern/versioning_common.h @@ -52,6 +52,14 @@ void version_node_output_socket_name(struct bNodeTree *ntree, const char *old_name, const char *new_name); +void version_node_socket_index_animdata( + Main *bmain, + int node_tree_type, /* NTREE_....., e.g. NTREE_SHADER */ + int node_type, /* SH_NODE_..., e.g. SH_NODE_BSDF_PRINCIPLED */ + int socket_index_lowest_modified, + int socket_index_offset, + int total_number_of_sockets); + void version_node_id(struct bNodeTree *ntree, const int node_type, const char *new_name); #ifdef __cplusplus |