From 509e0454fc4863caed0cdea396932d52df0daaed Mon Sep 17 00:00:00 2001 From: illua1 Date: Thu, 30 Mar 2023 18:22:16 +0300 Subject: [PATCH 1/6] init commit --- source/blender/blenkernel/intern/node_tree_update.cc | 3 +++ source/blender/editors/space_node/node_edit.cc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/source/blender/blenkernel/intern/node_tree_update.cc b/source/blender/blenkernel/intern/node_tree_update.cc index c4e25a8e97d..c09f3ef84d7 100644 --- a/source/blender/blenkernel/intern/node_tree_update.cc +++ b/source/blender/blenkernel/intern/node_tree_update.cc @@ -667,6 +667,9 @@ class NodeTreeMainUpdater { link.tonode = &node; link.tosock = to_socket; link.flag |= NODE_LINK_VALID; + /* Drawing of internal link for multi-input socket have to starting at last index of set of + * random number of connection. */ + link.multi_input_socket_index = -1; node.runtime->internal_links.append(link); } BKE_ntree_update_tag_node_internal_link(&ntree, &node); diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index 80d83fcf55b..bde873b71de 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -112,6 +112,9 @@ float2 node_link_calculate_multi_input_position(const float2 &socket_position, { const float offset = (total_inputs * NODE_MULTI_INPUT_LINK_GAP - NODE_MULTI_INPUT_LINK_GAP) * 0.5f; + if (index == -1) { + return {socket_position.x, socket_position.y + offset}; + } return {socket_position.x, socket_position.y - offset + index * NODE_MULTI_INPUT_LINK_GAP}; } -- 2.30.2 From 2443c6a439c19fb78c719069145f3d0a40b8e2cc Mon Sep 17 00:00:00 2001 From: illua1 Date: Fri, 31 Mar 2023 00:19:28 +0300 Subject: [PATCH 2/6] make better --- source/blender/blenkernel/intern/node_tree_update.cc | 6 +++--- source/blender/editors/space_node/node_edit.cc | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/source/blender/blenkernel/intern/node_tree_update.cc b/source/blender/blenkernel/intern/node_tree_update.cc index c09f3ef84d7..7b2e282d2dc 100644 --- a/source/blender/blenkernel/intern/node_tree_update.cc +++ b/source/blender/blenkernel/intern/node_tree_update.cc @@ -667,9 +667,9 @@ class NodeTreeMainUpdater { link.tonode = &node; link.tosock = to_socket; link.flag |= NODE_LINK_VALID; - /* Drawing of internal link for multi-input socket have to starting at last index of set of - * random number of connection. */ - link.multi_input_socket_index = -1; + const int internal_multi_input_socket_index = from_socket->directly_linked_links().size() - + 1; + link.multi_input_socket_index = internal_multi_input_socket_index; node.runtime->internal_links.append(link); } BKE_ntree_update_tag_node_internal_link(&ntree, &node); diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index bde873b71de..80d83fcf55b 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -112,9 +112,6 @@ float2 node_link_calculate_multi_input_position(const float2 &socket_position, { const float offset = (total_inputs * NODE_MULTI_INPUT_LINK_GAP - NODE_MULTI_INPUT_LINK_GAP) * 0.5f; - if (index == -1) { - return {socket_position.x, socket_position.y + offset}; - } return {socket_position.x, socket_position.y - offset + index * NODE_MULTI_INPUT_LINK_GAP}; } -- 2.30.2 From b60c388faf96e40e7fd936ac9b38755619a08a01 Mon Sep 17 00:00:00 2001 From: illua1 Date: Fri, 31 Mar 2023 17:17:53 +0300 Subject: [PATCH 3/6] refactoring of fix way Make fix of all indefing, directly linked link sorting, unconnected multiinput socket offset. --- source/blender/blenkernel/intern/node_runtime.cc | 2 +- source/blender/blenkernel/intern/node_tree_update.cc | 4 +--- source/blender/editors/space_node/drawnode.cc | 5 ++++- source/blender/editors/space_node/node_edit.cc | 2 +- source/blender/editors/space_node/node_relationships.cc | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/blender/blenkernel/intern/node_runtime.cc b/source/blender/blenkernel/intern/node_runtime.cc index dc24e5ddbc4..a50129c153c 100644 --- a/source/blender/blenkernel/intern/node_runtime.cc +++ b/source/blender/blenkernel/intern/node_runtime.cc @@ -130,7 +130,7 @@ static void update_directly_linked_links_and_sockets(const bNodeTree &ntree) std::sort(socket->runtime->directly_linked_links.begin(), socket->runtime->directly_linked_links.end(), [&](const bNodeLink *a, const bNodeLink *b) { - return a->multi_input_socket_index > b->multi_input_socket_index; + return a->multi_input_socket_index < b->multi_input_socket_index; }); } } diff --git a/source/blender/blenkernel/intern/node_tree_update.cc b/source/blender/blenkernel/intern/node_tree_update.cc index 7b2e282d2dc..471c7a4e03d 100644 --- a/source/blender/blenkernel/intern/node_tree_update.cc +++ b/source/blender/blenkernel/intern/node_tree_update.cc @@ -667,9 +667,7 @@ class NodeTreeMainUpdater { link.tonode = &node; link.tosock = to_socket; link.flag |= NODE_LINK_VALID; - const int internal_multi_input_socket_index = from_socket->directly_linked_links().size() - - 1; - link.multi_input_socket_index = internal_multi_input_socket_index; + link.multi_input_socket_index = 0; node.runtime->internal_links.append(link); } BKE_ntree_update_tag_node_internal_link(&ntree, &node); diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 4eb1dffd880..2a5c3066fee 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -1595,8 +1595,11 @@ static float2 socket_link_connection_location(const bNode &node, { const float2 socket_location = socket.runtime->location; if (socket.is_multi_input() && socket.is_input() && !(node.flag & NODE_HIDDEN)) { + /* If link didn't connected to socket. In this case, at less this link have to be counted in + * the list as single one. */ + const int total_inputs = math::max(1, socket.runtime->total_inputs); return node_link_calculate_multi_input_position( - socket_location, link.multi_input_socket_index, socket.runtime->total_inputs); + socket_location, link.multi_input_socket_index, total_inputs); } return socket_location; } diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index 80d83fcf55b..69aa0c20bab 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -112,7 +112,7 @@ float2 node_link_calculate_multi_input_position(const float2 &socket_position, { const float offset = (total_inputs * NODE_MULTI_INPUT_LINK_GAP - NODE_MULTI_INPUT_LINK_GAP) * 0.5f; - return {socket_position.x, socket_position.y - offset + index * NODE_MULTI_INPUT_LINK_GAP}; + return {socket_position.x, socket_position.y + offset - index * NODE_MULTI_INPUT_LINK_GAP}; } static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags) diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index 7d65292ae90..5803c44b387 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -309,7 +309,7 @@ static void sort_multi_input_socket_links_with_drag(bNodeSocket &socket, }); for (const int i : links.index_range()) { - links[i].link->multi_input_socket_index = i; + links[i].link->multi_input_socket_index = links.size() - 1 - i; } } -- 2.30.2 From 6cfe9fc444e9b1621234f401b3e797352623acd7 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Thu, 6 Jul 2023 13:36:41 +0300 Subject: [PATCH 4/6] progress --- source/blender/blenkernel/intern/node_tree_update.cc | 1 - source/blender/editors/space_node/drawnode.cc | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/source/blender/blenkernel/intern/node_tree_update.cc b/source/blender/blenkernel/intern/node_tree_update.cc index 9263a36c7b5..401714547ed 100644 --- a/source/blender/blenkernel/intern/node_tree_update.cc +++ b/source/blender/blenkernel/intern/node_tree_update.cc @@ -684,7 +684,6 @@ class NodeTreeMainUpdater { link.tonode = &node; link.tosock = to_socket; link.flag |= NODE_LINK_VALID; - link.multi_input_socket_index = 0; node.runtime->internal_links.append(link); } BKE_ntree_update_tag_node_internal_link(&ntree, &node); diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 3082cdaa3b8..107c0491f66 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -1635,11 +1635,8 @@ static float2 socket_link_connection_location(const bNode &node, { const float2 socket_location = socket.runtime->location; if (socket.is_multi_input() && socket.is_input() && !(node.flag & NODE_HIDDEN)) { - /* If link didn't connected to socket. In this case, at less this link have to be counted in - * the list as single one. */ - const int total_inputs = math::max(1, socket.runtime->total_inputs); return node_link_calculate_multi_input_position( - socket_location, link.multi_input_socket_index, total_inputs); + socket_location, link.multi_input_socket_index, socket.runtime->total_inputs); } return socket_location; } -- 2.30.2 From 01929a4de25c7e3bbb7ccd7c1c31060f7d3c3dca Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Tue, 5 Sep 2023 16:03:27 +0300 Subject: [PATCH 5/6] add versioning code --- .../blenloader/intern/versioning_400.cc | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index f8459e480ef..25991e9a390 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -969,7 +969,7 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) scene->eevee.gi_irradiance_pool_size = 16; } } - + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { scene->toolsettings->snap_flag_anim |= SCE_SNAP; scene->toolsettings->snap_anim_mode |= SCE_SNAP_TO_FRAME; @@ -1015,6 +1015,29 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) FOREACH_NODETREE_END; } + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 23)) { + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + blender::Map total_inputs; + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { + const bNodeSocket &socket = *link->tosock; + if (!socket.is_multi_input()) { + continue; + } + total_inputs.add_or_modify( + &socket, [](int *value) { *value = 0; }, [](int *value) { (*value)++; }); + } + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { + const bNodeSocket &socket = *link->tosock; + if (!socket.is_multi_input()) { + continue; + } + const int last_input_index = total_inputs.lookup(&socket); + link->multi_input_socket_index = last_input_index - link->multi_input_socket_index; + } + } + FOREACH_NODETREE_END; + } + /** * Versioning code until next subversion bump goes here. * -- 2.30.2 From af6cf1ca0ae61c0ec08111e31fc4257f9c271f34 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Sat, 14 Oct 2023 11:47:13 +0300 Subject: [PATCH 6/6] progress --- source/blender/blenloader/intern/versioning_400.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index c7dfa57eeff..b8bd8a3b0fb 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -1685,7 +1685,7 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) } } - if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 54)) { + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 401, 1)) { FOREACH_NODETREE_BEGIN (bmain, ntree, id) { blender::Map total_inputs; LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { -- 2.30.2