Fix: prevent duplicate shader node links during USD import
When reading UsdPreviewSurface materials from USD files, duplicate links between nodes would often result. This typically occurs between the Image node and its upstream UV Mapping node, or between the Image node and a downstream Separate RGB node. As processing progresses, we de-duplicate the nodes themselves as each new input/output socket is discovered. However, we would unconditionally add a link between the nodes even if we've already added one. Cycles will complain about this situation and it's obviously incorrect: `Cycles shader graph connect: input already connected.` As most UsdPreviewSurface material networks are all fairly small (<10 links total) I'm not worried about the cost of counting the links at this point. Pull Request: https://projects.blender.org/blender/blender/pulls/130356
This commit is contained in:
committed by
Jesse Yurkovich
parent
39e5e3c4fe
commit
e68897e117
@@ -148,20 +148,21 @@ static void link_nodes(
|
||||
bNodeTree *ntree, bNode *source, const char *sock_out, bNode *dest, const char *sock_in)
|
||||
{
|
||||
bNodeSocket *source_socket = blender::bke::node_find_socket(source, SOCK_OUT, sock_out);
|
||||
|
||||
if (!source_socket) {
|
||||
CLOG_ERROR(&LOG, "Couldn't find output socket %s", sock_out);
|
||||
return;
|
||||
}
|
||||
|
||||
bNodeSocket *dest_socket = blender::bke::node_find_socket(dest, SOCK_IN, sock_in);
|
||||
|
||||
if (!dest_socket) {
|
||||
CLOG_ERROR(&LOG, "Couldn't find input socket %s", sock_in);
|
||||
return;
|
||||
}
|
||||
|
||||
blender::bke::node_add_link(ntree, source, source_socket, dest, dest_socket);
|
||||
/* Only add the link if this is the first one to be connected. */
|
||||
if (blender::bke::node_count_socket_links(ntree, dest_socket) == 0) {
|
||||
blender::bke::node_add_link(ntree, source, source_socket, dest, dest_socket);
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns a layer handle retrieved from the given attribute's property specs.
|
||||
|
||||
Reference in New Issue
Block a user