Cleanup: use single declare function for all group nodes

The longer term plan is to allow using the same node groups in different
node tree types anyway. Also, the implicit field inputs is something that
shader nodes could benefit from soonish already.

This also fixes a bug where the geometry nodes specific declare function
was not used anymore since 38813a7441.
This commit is contained in:
Jacques Lucke
2023-10-19 11:13:33 +02:00
parent ab91c18995
commit 1c703eac2e
2 changed files with 44 additions and 59 deletions

View File

@@ -15,65 +15,6 @@
namespace blender::nodes {
static void set_default_input_field(const bNodeTreeInterfaceSocket &input, SocketDeclaration &decl)
{
if (dynamic_cast<decl::Vector *>(&decl)) {
if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_NORMAL_FIELD) {
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
implicit_field_inputs::normal);
decl.hide_value = true;
}
else if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_POSITION_FIELD) {
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
implicit_field_inputs::position);
decl.hide_value = true;
}
}
else if (dynamic_cast<decl::Int *>(&decl)) {
if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_INDEX_FIELD) {
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
implicit_field_inputs::index);
decl.hide_value = true;
}
else if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_ID_INDEX_FIELD) {
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
implicit_field_inputs::id_or_index);
decl.hide_value = true;
}
}
}
static void node_group_declare(const bNodeTree &node_tree,
const bNode &node,
NodeDeclarationBuilder &b)
{
NodeDeclaration &r_declaration = b.declaration();
const bNodeTree *group = reinterpret_cast<const bNodeTree *>(node.id);
if (!group) {
return;
}
node_group_declare(node_tree, node, b);
if (!node.id) {
return;
}
if (ID_IS_LINKED(&group->id) && (group->id.tag & LIB_TAG_MISSING)) {
return;
}
group->ensure_interface_cache();
const Span<const bNodeTreeInterfaceSocket *> inputs = group->interface_inputs();
const FieldInferencingInterface &field_interface = *group->runtime->field_inferencing_interface;
for (const int i : inputs.index_range()) {
SocketDeclaration &decl = *r_declaration.inputs[i];
decl.input_field_type = field_interface.inputs[i];
set_default_input_field(*inputs[i], decl);
}
for (const int i : r_declaration.outputs.index_range()) {
r_declaration.outputs[i]->output_field_dependency = field_interface.outputs[i];
}
}
static void register_node_type_geo_group()
{
static bNodeType ntype;

View File

@@ -357,6 +357,34 @@ static PanelDeclarationPtr declaration_for_interface_panel(const bNodeTree & /*n
return dst;
}
static void set_default_input_field(const bNodeTreeInterfaceSocket &input, SocketDeclaration &decl)
{
if (dynamic_cast<decl::Vector *>(&decl)) {
if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_NORMAL_FIELD) {
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
implicit_field_inputs::normal);
decl.hide_value = true;
}
else if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_POSITION_FIELD) {
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
implicit_field_inputs::position);
decl.hide_value = true;
}
}
else if (dynamic_cast<decl::Int *>(&decl)) {
if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_INDEX_FIELD) {
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
implicit_field_inputs::index);
decl.hide_value = true;
}
else if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_ID_INDEX_FIELD) {
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
implicit_field_inputs::id_or_index);
decl.hide_value = true;
}
}
}
void node_group_declare(NodeDeclarationBuilder &b)
{
const bNode *node = b.node_or_null();
@@ -412,6 +440,22 @@ void node_group_declare(NodeDeclarationBuilder &b)
}
return true;
});
if (group->type == NTREE_GEOMETRY) {
group->ensure_interface_cache();
const Span<const bNodeTreeInterfaceSocket *> inputs = group->interface_inputs();
const FieldInferencingInterface &field_interface =
*group->runtime->field_inferencing_interface;
for (const int i : inputs.index_range()) {
SocketDeclaration &decl = *r_declaration.inputs[i];
decl.input_field_type = field_interface.inputs[i];
set_default_input_field(*inputs[i], decl);
}
for (const int i : r_declaration.outputs.index_range()) {
r_declaration.outputs[i]->output_field_dependency = field_interface.outputs[i];
}
}
}
} // namespace blender::nodes