Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/node_tree_update.cc
| Show All 15 Lines | |||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "BKE_node_runtime.hh" | #include "BKE_node_runtime.hh" | ||||
| #include "BKE_node_tree_update.h" | #include "BKE_node_tree_update.h" | ||||
| #include "MOD_nodes.h" | #include "MOD_nodes.h" | ||||
| #include "NOD_internal_link_builder.hh" | |||||
| #include "NOD_node_declaration.hh" | #include "NOD_node_declaration.hh" | ||||
| #include "NOD_socket.h" | #include "NOD_socket.h" | ||||
| #include "NOD_texture.h" | #include "NOD_texture.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| using namespace blender::nodes; | using namespace blender::nodes; | ||||
| ▲ Show 20 Lines • Show All 547 Lines • ▼ Show 20 Lines | #endif | ||||
| void update_internal_links(bNodeTree &ntree) | void update_internal_links(bNodeTree &ntree) | ||||
| { | { | ||||
| bke::node_tree_runtime::AllowUsingOutdatedInfo allow_outdated_info{ntree}; | bke::node_tree_runtime::AllowUsingOutdatedInfo allow_outdated_info{ntree}; | ||||
| ntree.ensure_topology_cache(); | ntree.ensure_topology_cache(); | ||||
| for (bNode *node : ntree.all_nodes()) { | for (bNode *node : ntree.all_nodes()) { | ||||
| if (!this->should_update_individual_node(ntree, *node)) { | if (!this->should_update_individual_node(ntree, *node)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!node->typeinfo->internal_link_function) { | |||||
| continue; | |||||
| } | |||||
| internal_link::NodeInternalLinkBuilder linker(ntree, *node); | |||||
| node->typeinfo->internal_link_function(linker); | |||||
| if (linker.try_to_relink()) { | |||||
| BKE_ntree_update_tag_node_internal_link(&ntree, *node); | |||||
| } | |||||
| /* Find all expected internal links. */ | /* Find all expected internal links. */ | ||||
| /* | |||||
| Vector<std::pair<bNodeSocket *, bNodeSocket *>> expected_internal_links; | Vector<std::pair<bNodeSocket *, bNodeSocket *>> expected_internal_links; | ||||
| for (const bNodeSocket *output_socket : node->output_sockets()) { | for (const bNodeSocket *output_socket : node->output_sockets()) { | ||||
| if (!output_socket->is_available()) { | if (!output_socket->is_available()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!output_socket->is_directly_linked()) { | if (!output_socket->is_directly_linked()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (output_socket->flag & SOCK_NO_INTERNAL_LINK) { | if (output_socket->flag & SOCK_NO_INTERNAL_LINK) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| const bNodeSocket *input_socket = this->find_internally_linked_input(output_socket); | const bNodeSocket *input_socket = this->find_internally_linked_input(output_socket); | ||||
| if (input_socket != nullptr) { | if (input_socket != nullptr) { | ||||
| expected_internal_links.append( | expected_internal_links.append( | ||||
| {const_cast<bNodeSocket *>(input_socket), const_cast<bNodeSocket *>(output_socket)}); | {const_cast<bNodeSocket *>(input_socket), const_cast<bNodeSocket *>(output_socket)}); | ||||
| } | } | ||||
| } | } | ||||
| /* Rebuilt internal links if they have changed. */ | /* Rebuilt internal links if they have changed. */ | ||||
| /* | |||||
| if (node->runtime->internal_links.size() != expected_internal_links.size()) { | if (node->runtime->internal_links.size() != expected_internal_links.size()) { | ||||
| this->update_internal_links_in_node(ntree, *node, expected_internal_links); | this->update_internal_links_in_node(ntree, *node, expected_internal_links); | ||||
| } | } | ||||
| else { | else { | ||||
| for (auto &item : expected_internal_links) { | for (auto &item : expected_internal_links) { | ||||
| const bNodeSocket *from_socket = item.first; | const bNodeSocket *from_socket = item.first; | ||||
| const bNodeSocket *to_socket = item.second; | const bNodeSocket *to_socket = item.second; | ||||
| bool found = false; | bool found = false; | ||||
| for (const bNodeLink &internal_link : node->runtime->internal_links) { | for (const bNodeLink &internal_link : node->runtime->internal_links) { | ||||
| if (from_socket == internal_link.fromsock && to_socket == internal_link.tosock) { | if (from_socket == internal_link.fromsock && to_socket == internal_link.tosock) { | ||||
| found = true; | found = true; | ||||
| } | } | ||||
| } | } | ||||
| if (!found) { | if (!found) { | ||||
| this->update_internal_links_in_node(ntree, *node, expected_internal_links); | this->update_internal_links_in_node(ntree, *node, expected_internal_links); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| */ | |||||
| } | } | ||||
| } | } | ||||
| const bNodeSocket *find_internally_linked_input(const bNodeSocket *output_socket) | const bNodeSocket *find_internally_linked_input(const bNodeSocket *output_socket) | ||||
| { | { | ||||
| const bNodeSocket *selected_socket = nullptr; | const bNodeSocket *selected_socket = nullptr; | ||||
| int selected_priority = -1; | int selected_priority = -1; | ||||
| bool selected_is_linked = false; | bool selected_is_linked = false; | ||||
| Show All 15 Lines | for (const bNodeSocket *input_socket : output_socket->owner_node().input_sockets()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| selected_socket = input_socket; | selected_socket = input_socket; | ||||
| selected_priority = priority; | selected_priority = priority; | ||||
| selected_is_linked = is_linked; | selected_is_linked = is_linked; | ||||
| } | } | ||||
| return selected_socket; | return selected_socket; | ||||
| } | } | ||||
| /* | |||||
| void update_internal_links_in_node(bNodeTree &ntree, | void update_internal_links_in_node(bNodeTree &ntree, | ||||
| bNode &node, | bNode &node, | ||||
| Span<std::pair<bNodeSocket *, bNodeSocket *>> links) | Span<std::pair<bNodeSocket *, bNodeSocket *>> links) | ||||
| { | { | ||||
| node.runtime->internal_links.clear(); | node.runtime->internal_links.clear(); | ||||
| node.runtime->internal_links.reserve(links.size()); | node.runtime->internal_links.reserve(links.size()); | ||||
| for (const auto &item : links) { | for (const auto &item : links) { | ||||
| bNodeSocket *from_socket = item.first; | bNodeSocket *from_socket = item.first; | ||||
| bNodeSocket *to_socket = item.second; | bNodeSocket *to_socket = item.second; | ||||
| bNodeLink link{}; | bNodeLink link{}; | ||||
| link.fromnode = &node; | link.fromnode = &node; | ||||
| link.fromsock = from_socket; | link.fromsock = from_socket; | ||||
| link.tonode = &node; | link.tonode = &node; | ||||
| link.tosock = to_socket; | link.tosock = to_socket; | ||||
| link.flag |= NODE_LINK_VALID; | link.flag |= NODE_LINK_VALID; | ||||
| node.runtime->internal_links.append(link); | node.runtime->internal_links.append(link); | ||||
| } | } | ||||
| BKE_ntree_update_tag_node_internal_link(&ntree, &node); | BKE_ntree_update_tag_node_internal_link(&ntree, &node); | ||||
| } | } | ||||
| */ | |||||
| void update_generic_callback(bNodeTree &ntree) | void update_generic_callback(bNodeTree &ntree) | ||||
| { | { | ||||
| if (ntree.typeinfo->update == nullptr) { | if (ntree.typeinfo->update == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| ntree.typeinfo->update(&ntree); | ntree.typeinfo->update(&ntree); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 562 Lines • Show Last 20 Lines | |||||