Geometry Nodes: Link error when implicit conversion isn't possible

This turns links red if no implicit conversion can be made between the
from socket and the to socket. For geometry nodes this happens with
object, geometry, collection, and string sockets that are connected to
a different type. The change is simply implementing a callback that is
already implemented for other node tree types.

Differential Revision: https://developer.blender.org/D11229
This commit is contained in:
Wannes Malfait 2021-05-11 16:46:02 -05:00 committed by Hans Goudey
parent 2770d43da6
commit 65244ac1c3
1 changed files with 11 additions and 0 deletions

View File

@ -84,6 +84,16 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa
func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
}
static bool geometry_node_tree_validate_link(bNodeTree *UNUSED(ntree), bNodeLink *link)
{
/* Geometry, string, object and collection sockets can only be connected to themselves. */
if (ELEM(link->fromsock->type, SOCK_GEOMETRY, SOCK_STRING, SOCK_OBJECT, SOCK_COLLECTION) ||
ELEM(link->tosock->type, SOCK_GEOMETRY, SOCK_STRING, SOCK_OBJECT, SOCK_COLLECTION)) {
return (link->tosock->type == link->fromsock->type);
}
return true;
}
static bool geometry_node_tree_socket_type_valid(eNodeSocketDatatype socket_type,
bNodeTreeType *UNUSED(ntreetype))
{
@ -113,6 +123,7 @@ void register_node_tree_type_geo(void)
tt->get_from_context = geometry_node_tree_get_from_context;
tt->foreach_nodeclass = foreach_nodeclass;
tt->valid_socket_type = geometry_node_tree_socket_type_valid;
tt->validate_link = geometry_node_tree_validate_link;
ntreeTypeAdd(tt);
}