Cleanup: Refactor use of implicit inputs in geometry nodes

Instead of checking whether the socket value was hidden, use the proper
node declaration to check whether the socket has an implicit input. The
remaining larger change to make is allowing nodes to specify what their
implicit input should actually be.
This commit is contained in:
Hans Goudey 2021-10-15 13:57:00 -05:00
parent 4682aad432
commit 47a72ac4fd
1 changed files with 29 additions and 24 deletions

View File

@ -17,6 +17,7 @@
#include "MOD_nodes_evaluator.hh"
#include "NOD_geometry_exec.hh"
#include "NOD_socket_declarations.hh"
#include "NOD_type_conversions.hh"
#include "DEG_depsgraph_query.h"
@ -321,41 +322,45 @@ static const CPPType *get_socket_cpp_type(const DSocket socket)
return get_socket_cpp_type(*socket.socket_ref());
}
static void get_socket_value(const SocketRef &socket, void *r_value)
/**
* \note This is not supposed to be a long term solution. Eventually we want that nodes can
* specify more complex defaults (other than just single values) in their socket declarations.
*/
static bool get_implicit_socket_input(const SocketRef &socket, void *r_value)
{
const bNodeSocket &bsocket = *socket.bsocket();
/* This is not supposed to be a long term solution. Eventually we want that nodes can specify
* more complex defaults (other than just single values) in their socket declarations. */
if (bsocket.flag & SOCK_HIDE_VALUE) {
const bNode &bnode = *socket.bnode();
if (bsocket.type == SOCK_VECTOR) {
if (ELEM(bnode.type,
GEO_NODE_SET_POSITION,
SH_NODE_TEX_GRADIENT,
SH_NODE_TEX_NOISE,
SH_NODE_TEX_VORONOI,
SH_NODE_TEX_WHITE_NOISE,
GEO_NODE_MESH_TO_POINTS,
GEO_NODE_PROXIMITY)) {
new (r_value) Field<float3>(bke::AttributeFieldInput::Create<float3>("position"));
return;
}
const NodeRef &node = socket.node();
const nodes::NodeDeclaration *node_declaration = node.declaration();
if (node_declaration == nullptr) {
return false;
}
const nodes::SocketDeclaration &socket_declaration = *node_declaration->inputs()[socket.index()];
if (socket_declaration.input_field_type() == nodes::InputSocketFieldType::Implicit) {
if (socket.typeinfo()->type == SOCK_VECTOR) {
const bNode &bnode = *socket.bnode();
if (bnode.type == GEO_NODE_SET_CURVE_HANDLES) {
StringRef side = ((NodeGeometrySetCurveHandlePositions *)bnode.storage)->mode ==
GEO_NODE_CURVE_HANDLE_LEFT ?
"handle_left" :
"handle_right";
new (r_value) Field<float3>(bke::AttributeFieldInput::Create<float3>(side));
return;
return true;
}
new (r_value) Field<float3>(bke::AttributeFieldInput::Create<float3>("position"));
return true;
}
else if (bsocket.type == SOCK_INT) {
if (ELEM(bnode.type, FN_NODE_RANDOM_VALUE, GEO_NODE_INSTANCE_ON_POINTS)) {
new (r_value) Field<int>(std::make_shared<fn::IndexFieldInput>());
return;
}
if (socket.typeinfo()->type == SOCK_INT) {
new (r_value) Field<int>(std::make_shared<fn::IndexFieldInput>());
return true;
}
}
return false;
}
static void get_socket_value(const SocketRef &socket, void *r_value)
{
if (get_implicit_socket_input(socket, r_value)) {
return;
}
const bNodeSocketType *typeinfo = socket.typeinfo();
typeinfo->get_geometry_nodes_cpp_value(*socket.bsocket(), r_value);