Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_relationships.cc
| Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "UI_view2d.h" | #include "UI_view2d.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "NOD_node_declaration.hh" | |||||
| #include "NOD_node_tree_ref.hh" | #include "NOD_node_tree_ref.hh" | ||||
| #include "node_intern.h" /* own include */ | #include "node_intern.h" /* own include */ | ||||
| using namespace blender::nodes::node_tree_ref_types; | using namespace blender::nodes::node_tree_ref_types; | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Relations Helpers | /** \name Relations Helpers | ||||
| ▲ Show 20 Lines • Show All 2,109 Lines • ▼ Show 20 Lines | switch ((eNodeSocketDatatype)socket->type) { | ||||
| case SOCK_COLLECTION: | case SOCK_COLLECTION: | ||||
| case SOCK_TEXTURE: | case SOCK_TEXTURE: | ||||
| case SOCK_MATERIAL: | case SOCK_MATERIAL: | ||||
| return 5; | return 5; | ||||
| } | } | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| /** Get the "main" socket of a socket list using a heuristic based on socket types. */ | /** Get the "main" socket based on the node declaration or an heuristic. */ | ||||
| static bNodeSocket *get_main_socket(ListBase *sockets) | static bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) | ||||
| { | { | ||||
| using namespace blender; | |||||
| using namespace blender::nodes; | |||||
| ListBase *sockets = (in_out == SOCK_IN) ? &node.inputs : &node.outputs; | |||||
| /* Try to get the main socket based on the socket declaration. */ | |||||
| nodeDeclarationEnsure(&ntree, &node); | |||||
| const NodeDeclaration *node_decl = node.declaration; | |||||
| if (node_decl != nullptr) { | |||||
| Span<SocketDeclarationPtr> socket_decls = (in_out == SOCK_IN) ? node_decl->inputs() : | |||||
| node_decl->outputs(); | |||||
| int index; | |||||
| LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, sockets, index) { | |||||
| const SocketDeclaration &socket_decl = *socket_decls[index]; | |||||
| if (nodeSocketIsHidden(socket)) { | |||||
HooglyBoogly: Could this check the type too? It seems reasonable to only use the default where the types… | |||||
JacquesLuckeAuthorUnsubmitted Done Inline ActionsTypes don't have to match exactly in general. We could check for convertability, but that can be fixed as part of T91840. JacquesLucke: Types don't have to match exactly in general. We could check for convertability, but that can… | |||||
HooglyBooglyUnsubmitted Not Done Inline ActionsOkay, as long as we have a task for it, works for me. HooglyBoogly: Okay, as long as we have a task for it, works for me. | |||||
| continue; | |||||
| } | |||||
| if (socket_decl.is_default_link_socket()) { | |||||
| return socket; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* find priority range */ | /* find priority range */ | ||||
| int maxpriority = -1; | int maxpriority = -1; | ||||
| LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { | LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { | ||||
| if (sock->flag & SOCK_UNAVAIL) { | if (sock->flag & SOCK_UNAVAIL) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| maxpriority = max_ii(get_main_socket_priority(sock), maxpriority); | maxpriority = max_ii(get_main_socket_priority(sock), maxpriority); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 360 Lines • ▼ Show 20 Lines | void ED_node_link_insert(Main *bmain, ScrArea *area) | ||||
| bNodeLink *link; | bNodeLink *link; | ||||
| for (link = (bNodeLink *)snode->edittree->links.first; link; link = link->next) { | for (link = (bNodeLink *)snode->edittree->links.first; link; link = link->next) { | ||||
| if (link->flag & NODE_LINKFLAG_HILITE) { | if (link->flag & NODE_LINKFLAG_HILITE) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (link) { | if (link) { | ||||
| bNodeSocket *best_input = get_main_socket(&select->inputs); | bNodeSocket *best_input = get_main_socket(*snode->edittree, *select, SOCK_IN); | ||||
| bNodeSocket *best_output = get_main_socket(&select->outputs); | bNodeSocket *best_output = get_main_socket(*snode->edittree, *select, SOCK_OUT); | ||||
| if (best_input && best_output) { | if (best_input && best_output) { | ||||
| bNode *node = link->tonode; | bNode *node = link->tonode; | ||||
| bNodeSocket *sockto = link->tosock; | bNodeSocket *sockto = link->tosock; | ||||
| link->tonode = select; | link->tonode = select; | ||||
| link->tosock = best_input; | link->tosock = best_input; | ||||
| node_remove_extra_links(snode, link); | node_remove_extra_links(snode, link); | ||||
| Show All 30 Lines | |||||
Could this check the type too? It seems reasonable to only use the default where the types match.