Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/intern/geometry_nodes_lazy_function.cc
| Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | |||||
| public: | public: | ||||
| LazyFunctionForMultiInput(const bNodeSocket &socket) | LazyFunctionForMultiInput(const bNodeSocket &socket) | ||||
| { | { | ||||
| debug_name_ = "Multi Input"; | debug_name_ = "Multi Input"; | ||||
| base_type_ = get_socket_cpp_type(socket); | base_type_ = get_socket_cpp_type(socket); | ||||
| BLI_assert(base_type_ != nullptr); | BLI_assert(base_type_ != nullptr); | ||||
| BLI_assert(socket.is_multi_input()); | BLI_assert(socket.is_multi_input()); | ||||
| const bNodeTree &btree = socket.owner_tree(); | |||||
| for (const bNodeLink *link : socket.directly_linked_links()) { | for (const bNodeLink *link : socket.directly_linked_links()) { | ||||
| if (!link->is_muted()) { | if (!(link->is_muted() || nodeIsDanglingReroute(&btree, link->fromnode))) { | ||||
| inputs_.append({"Input", *base_type_}); | inputs_.append({"Input", *base_type_}); | ||||
| } | } | ||||
| } | } | ||||
| const CPPType *vector_type = get_vector_type(*base_type_); | const CPPType *vector_type = get_vector_type(*base_type_); | ||||
| BLI_assert(vector_type != nullptr); | BLI_assert(vector_type != nullptr); | ||||
| outputs_.append({"Output", *vector_type}); | outputs_.append({"Output", *vector_type}); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 897 Lines • ▼ Show 20 Lines | private: | ||||
| { | { | ||||
| for (const auto item : output_socket_map_.items()) { | for (const auto item : output_socket_map_.items()) { | ||||
| this->insert_links_from_socket(*item.key, *item.value); | this->insert_links_from_socket(*item.key, *item.value); | ||||
| } | } | ||||
| } | } | ||||
| void insert_links_from_socket(const bNodeSocket &from_bsocket, lf::OutputSocket &from_lf_socket) | void insert_links_from_socket(const bNodeSocket &from_bsocket, lf::OutputSocket &from_lf_socket) | ||||
| { | { | ||||
| const bNode &from_bnode = from_bsocket.owner_node(); | if (nodeIsDanglingReroute(&btree_, &from_bsocket.owner_node())) { | ||||
| if (this->is_dangling_reroute_input(from_bnode)) { | |||||
| /* Dangling reroutes should not be used as source of values. */ | |||||
| return; | return; | ||||
| } | } | ||||
| const Span<const bNodeLink *> links_from_bsocket = from_bsocket.directly_linked_links(); | const Span<const bNodeLink *> links_from_bsocket = from_bsocket.directly_linked_links(); | ||||
| struct TypeWithLinks { | struct TypeWithLinks { | ||||
| const CPPType *type; | const CPPType *type; | ||||
| Vector<const bNodeLink *> links; | Vector<const bNodeLink *> links; | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | for (const TypeWithLinks &type_with_links : types_with_links) { | ||||
| const bNodeSocket &to_bsocket = *link->tosock; | const bNodeSocket &to_bsocket = *link->tosock; | ||||
| if (to_bsocket.is_multi_input()) { | if (to_bsocket.is_multi_input()) { | ||||
| /* TODO: Cache this index on the link. */ | /* TODO: Cache this index on the link. */ | ||||
| int link_index = 0; | int link_index = 0; | ||||
| for (const bNodeLink *multi_input_link : to_bsocket.directly_linked_links()) { | for (const bNodeLink *multi_input_link : to_bsocket.directly_linked_links()) { | ||||
| if (multi_input_link == link) { | if (multi_input_link == link) { | ||||
| break; | break; | ||||
| } | } | ||||
| if (!multi_input_link->is_muted()) { | if (!(multi_input_link->is_muted() || | ||||
| nodeIsDanglingReroute(&btree_, multi_input_link->fromnode))) { | |||||
| link_index++; | link_index++; | ||||
| } | } | ||||
| } | } | ||||
| if (to_bsocket.owner_node().is_muted()) { | if (to_bsocket.owner_node().is_muted()) { | ||||
| if (link_index == 0) { | if (link_index == 0) { | ||||
| for (lf::InputSocket *to_lf_socket : input_socket_map_.lookup(&to_bsocket)) { | for (lf::InputSocket *to_lf_socket : input_socket_map_.lookup(&to_bsocket)) { | ||||
| make_input_link_or_set_default(*to_lf_socket); | make_input_link_or_set_default(*to_lf_socket); | ||||
| } | } | ||||
| Show All 12 Lines | for (const TypeWithLinks &type_with_links : types_with_links) { | ||||
| for (lf::InputSocket *to_lf_socket : input_socket_map_.lookup(&to_bsocket)) { | for (lf::InputSocket *to_lf_socket : input_socket_map_.lookup(&to_bsocket)) { | ||||
| make_input_link_or_set_default(*to_lf_socket); | make_input_link_or_set_default(*to_lf_socket); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| bool is_dangling_reroute_input(const bNode &node) | |||||
| { | |||||
| if (!node.is_reroute()) { | |||||
| return false; | |||||
| } | |||||
| const bNode *iter_node = &node; | |||||
| /* It is guaranteed at a higher level that there are no link cycles. */ | |||||
| while (true) { | |||||
| const Span<const bNodeLink *> links = iter_node->input_socket(0).directly_linked_links(); | |||||
| BLI_assert(links.size() <= 1); | |||||
| if (links.is_empty()) { | |||||
| return true; | |||||
| } | |||||
| const bNodeLink &link = *links[0]; | |||||
| if (!link.is_available()) { | |||||
| return false; | |||||
| } | |||||
| if (link.is_muted()) { | |||||
| return false; | |||||
| } | |||||
| iter_node = link.fromnode; | |||||
| if (!iter_node->is_reroute()) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| } | |||||
| lf::OutputSocket *insert_type_conversion_if_necessary( | lf::OutputSocket *insert_type_conversion_if_necessary( | ||||
| lf::OutputSocket &from_socket, | lf::OutputSocket &from_socket, | ||||
| const CPPType &to_type, | const CPPType &to_type, | ||||
| Vector<const bNodeSocket *> &&target_sockets) | Vector<const bNodeSocket *> &&target_sockets) | ||||
| { | { | ||||
| const CPPType &from_type = from_socket.type(); | const CPPType &from_type = from_socket.type(); | ||||
| if (from_type == to_type) { | if (from_type == to_type) { | ||||
| return &from_socket; | return &from_socket; | ||||
| ▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines | |||||