Nodes: deduplicate code to create declarations for socket type
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "NOD_node_declaration.hh"
|
||||
#include "NOD_socket.hh"
|
||||
|
||||
#include "BKE_node_runtime.hh"
|
||||
#include "BKE_node_tree_anonymous_attributes.hh"
|
||||
@@ -19,11 +20,6 @@ namespace blender::bke::anonymous_attribute_inferencing {
|
||||
namespace aal = nodes::aal;
|
||||
using nodes::NodeDeclaration;
|
||||
|
||||
static bool is_possible_field_socket(const eNodeSocketDatatype type)
|
||||
{
|
||||
return ELEM(type, SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA, SOCK_BOOLEAN, SOCK_INT, SOCK_ROTATION);
|
||||
}
|
||||
|
||||
static bool socket_is_field(const bNodeSocket &socket)
|
||||
{
|
||||
return socket.display_shape == SOCK_DISPLAY_SHAPE_DIAMOND;
|
||||
@@ -187,7 +183,7 @@ class bNodeTreeToDotOptionsForAnonymousAttributeInferencing : public bNodeTreeTo
|
||||
ss << "]";
|
||||
return ss.str();
|
||||
}
|
||||
else if (is_possible_field_socket(eNodeSocketDatatype(socket.type))) {
|
||||
else if (nodes::socket_type_supports_fields(eNodeSocketDatatype(socket.type))) {
|
||||
std::stringstream ss;
|
||||
ss << socket.identifier << " [";
|
||||
bits::foreach_1_index(result_.propagated_fields_by_socket[socket.index_in_tree()],
|
||||
@@ -219,7 +215,7 @@ static AnonymousAttributeInferencingResult analyse_anonymous_attribute_usages(
|
||||
if (type == SOCK_GEOMETRY) {
|
||||
all_geometry_sources.append_and_get_index({InputGeometrySource{i}});
|
||||
}
|
||||
else if (is_possible_field_socket(type)) {
|
||||
else if (nodes::socket_type_supports_fields(type)) {
|
||||
all_field_sources.append_and_get_index({InputFieldSource{i}});
|
||||
}
|
||||
}
|
||||
@@ -371,7 +367,7 @@ static AnonymousAttributeInferencingResult analyse_anonymous_attribute_usages(
|
||||
for (const int field_source_index : geometry_source.field_sources) {
|
||||
for (const bNodeSocket *other_socket :
|
||||
group_output_node->input_sockets().drop_back(1)) {
|
||||
if (!is_possible_field_socket(eNodeSocketDatatype(other_socket->type))) {
|
||||
if (!nodes::socket_type_supports_fields(eNodeSocketDatatype(other_socket->type))) {
|
||||
continue;
|
||||
}
|
||||
if (propagated_fields_by_socket[other_socket->index_in_tree()][field_source_index]
|
||||
@@ -386,7 +382,7 @@ static AnonymousAttributeInferencingResult analyse_anonymous_attribute_usages(
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (is_possible_field_socket(eNodeSocketDatatype(socket->type))) {
|
||||
else if (nodes::socket_type_supports_fields(eNodeSocketDatatype(socket->type))) {
|
||||
const BoundedBitSpan propagated_fields =
|
||||
propagated_fields_by_socket[socket->index_in_tree()];
|
||||
bits::foreach_1_index(propagated_fields, [&](const int field_source_index) {
|
||||
|
||||
@@ -739,6 +739,9 @@ void build_node_declaration_dynamic(const bNodeTree &node_tree,
|
||||
const bNode &node,
|
||||
NodeDeclaration &r_declaration);
|
||||
|
||||
std::unique_ptr<SocketDeclaration> make_declaration_for_socket_type(
|
||||
eNodeSocketDatatype socket_type);
|
||||
|
||||
template<typename SocketDecl>
|
||||
typename SocketDeclarationBuilder<SocketDecl>::Self &SocketDeclarationBuilder<
|
||||
SocketDecl>::reference_pass(const Span<int> input_indices)
|
||||
|
||||
@@ -29,5 +29,6 @@ void register_standard_node_socket_types();
|
||||
namespace blender::nodes {
|
||||
|
||||
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node);
|
||||
bool socket_type_supports_fields(eNodeSocketDatatype socket_type);
|
||||
|
||||
} // namespace blender::nodes
|
||||
|
||||
@@ -26,65 +26,19 @@ static std::unique_ptr<SocketDeclaration> socket_declaration_for_repeat_item(
|
||||
const NodeRepeatItem &item, const eNodeSocketInOut in_out, const int corresponding_input = -1)
|
||||
{
|
||||
const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
|
||||
BLI_assert(RepeatItemsAccessor::supports_socket_type(socket_type));
|
||||
|
||||
std::unique_ptr<SocketDeclaration> decl = make_declaration_for_socket_type(socket_type);
|
||||
BLI_assert(decl);
|
||||
|
||||
std::unique_ptr<SocketDeclaration> decl;
|
||||
|
||||
auto handle_field_decl = [&](SocketDeclaration &decl) {
|
||||
if (socket_type_supports_fields(socket_type)) {
|
||||
if (in_out == SOCK_IN) {
|
||||
decl.input_field_type = InputSocketFieldType::IsSupported;
|
||||
decl->input_field_type = InputSocketFieldType::IsSupported;
|
||||
}
|
||||
else {
|
||||
decl.output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
|
||||
decl->output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
|
||||
{corresponding_input});
|
||||
}
|
||||
};
|
||||
|
||||
switch (socket_type) {
|
||||
case SOCK_FLOAT:
|
||||
decl = std::make_unique<decl::Float>();
|
||||
handle_field_decl(*decl);
|
||||
break;
|
||||
case SOCK_VECTOR:
|
||||
decl = std::make_unique<decl::Vector>();
|
||||
handle_field_decl(*decl);
|
||||
break;
|
||||
case SOCK_RGBA:
|
||||
decl = std::make_unique<decl::Color>();
|
||||
handle_field_decl(*decl);
|
||||
break;
|
||||
case SOCK_BOOLEAN:
|
||||
decl = std::make_unique<decl::Bool>();
|
||||
handle_field_decl(*decl);
|
||||
break;
|
||||
case SOCK_ROTATION:
|
||||
decl = std::make_unique<decl::Rotation>();
|
||||
handle_field_decl(*decl);
|
||||
break;
|
||||
case SOCK_INT:
|
||||
decl = std::make_unique<decl::Int>();
|
||||
handle_field_decl(*decl);
|
||||
break;
|
||||
case SOCK_STRING:
|
||||
decl = std::make_unique<decl::String>();
|
||||
break;
|
||||
case SOCK_GEOMETRY:
|
||||
decl = std::make_unique<decl::Geometry>();
|
||||
break;
|
||||
case SOCK_OBJECT:
|
||||
decl = std::make_unique<decl::Object>();
|
||||
break;
|
||||
case SOCK_IMAGE:
|
||||
decl = std::make_unique<decl::Image>();
|
||||
break;
|
||||
case SOCK_COLLECTION:
|
||||
decl = std::make_unique<decl::Collection>();
|
||||
break;
|
||||
case SOCK_MATERIAL:
|
||||
decl = std::make_unique<decl::Material>();
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
break;
|
||||
}
|
||||
|
||||
decl->name = item.name ? item.name : "";
|
||||
|
||||
@@ -63,52 +63,17 @@ static std::unique_ptr<SocketDeclaration> socket_declaration_for_simulation_item
|
||||
const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
|
||||
BLI_assert(SimulationItemsAccessor::supports_socket_type(socket_type));
|
||||
|
||||
std::unique_ptr<SocketDeclaration> decl;
|
||||
switch (socket_type) {
|
||||
case SOCK_FLOAT:
|
||||
decl = std::make_unique<decl::Float>();
|
||||
std::unique_ptr<SocketDeclaration> decl = make_declaration_for_socket_type(socket_type);
|
||||
BLI_assert(decl);
|
||||
|
||||
if (socket_type_supports_fields(socket_type)) {
|
||||
if (in_out == SOCK_IN) {
|
||||
decl->input_field_type = InputSocketFieldType::IsSupported;
|
||||
}
|
||||
else {
|
||||
decl->output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
|
||||
{corresponding_input});
|
||||
break;
|
||||
case SOCK_VECTOR:
|
||||
decl = std::make_unique<decl::Vector>();
|
||||
decl->input_field_type = InputSocketFieldType::IsSupported;
|
||||
decl->output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
|
||||
{corresponding_input});
|
||||
break;
|
||||
case SOCK_RGBA:
|
||||
decl = std::make_unique<decl::Color>();
|
||||
decl->input_field_type = InputSocketFieldType::IsSupported;
|
||||
decl->output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
|
||||
{corresponding_input});
|
||||
break;
|
||||
case SOCK_BOOLEAN:
|
||||
decl = std::make_unique<decl::Bool>();
|
||||
decl->input_field_type = InputSocketFieldType::IsSupported;
|
||||
decl->output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
|
||||
{corresponding_input});
|
||||
break;
|
||||
case SOCK_ROTATION:
|
||||
decl = std::make_unique<decl::Rotation>();
|
||||
decl->input_field_type = InputSocketFieldType::IsSupported;
|
||||
decl->output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
|
||||
{corresponding_input});
|
||||
break;
|
||||
case SOCK_INT:
|
||||
decl = std::make_unique<decl::Int>();
|
||||
decl->input_field_type = InputSocketFieldType::IsSupported;
|
||||
decl->output_field_dependency = OutputFieldDependency::ForPartiallyDependentField(
|
||||
{corresponding_input});
|
||||
break;
|
||||
case SOCK_STRING:
|
||||
decl = std::make_unique<decl::String>();
|
||||
break;
|
||||
case SOCK_GEOMETRY:
|
||||
decl = std::make_unique<decl::Geometry>();
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
decl->name = item.name ? item.name : "";
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "NOD_geometry_nodes_execute.hh"
|
||||
#include "NOD_geometry_nodes_lazy_function.hh"
|
||||
#include "NOD_node_declaration.hh"
|
||||
#include "NOD_socket.hh"
|
||||
|
||||
#include "BKE_compute_contexts.hh"
|
||||
#include "BKE_geometry_fields.hh"
|
||||
@@ -42,7 +43,7 @@ StringRef input_attribute_name_suffix()
|
||||
|
||||
bool socket_type_has_attribute_toggle(const eNodeSocketDatatype type)
|
||||
{
|
||||
return ELEM(type, SOCK_FLOAT, SOCK_VECTOR, SOCK_BOOLEAN, SOCK_RGBA, SOCK_INT, SOCK_ROTATION);
|
||||
return socket_type_supports_fields(type);
|
||||
}
|
||||
|
||||
bool input_has_attribute_toggle(const bNodeTree &node_tree, const int socket_index)
|
||||
|
||||
@@ -392,6 +392,39 @@ void PanelDeclaration::update_or_build(const bNodePanelState &old_panel,
|
||||
SET_FLAG_FROM_TEST(new_panel.flag, old_panel.is_collapsed(), NODE_PANEL_COLLAPSED);
|
||||
}
|
||||
|
||||
std::unique_ptr<SocketDeclaration> make_declaration_for_socket_type(
|
||||
const eNodeSocketDatatype socket_type)
|
||||
{
|
||||
switch (socket_type) {
|
||||
case SOCK_FLOAT:
|
||||
return std::make_unique<decl::Float>();
|
||||
case SOCK_VECTOR:
|
||||
return std::make_unique<decl::Vector>();
|
||||
case SOCK_RGBA:
|
||||
return std::make_unique<decl::Color>();
|
||||
case SOCK_BOOLEAN:
|
||||
return std::make_unique<decl::Bool>();
|
||||
case SOCK_ROTATION:
|
||||
return std::make_unique<decl::Rotation>();
|
||||
case SOCK_INT:
|
||||
return std::make_unique<decl::Int>();
|
||||
case SOCK_STRING:
|
||||
return std::make_unique<decl::String>();
|
||||
case SOCK_GEOMETRY:
|
||||
return std::make_unique<decl::Geometry>();
|
||||
case SOCK_OBJECT:
|
||||
return std::make_unique<decl::Object>();
|
||||
case SOCK_IMAGE:
|
||||
return std::make_unique<decl::Image>();
|
||||
case SOCK_COLLECTION:
|
||||
return std::make_unique<decl::Collection>();
|
||||
case SOCK_MATERIAL:
|
||||
return std::make_unique<decl::Material>();
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
namespace implicit_field_inputs {
|
||||
|
||||
void position(const bNode & /*node*/, void *r_value)
|
||||
|
||||
@@ -376,6 +376,12 @@ void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node)
|
||||
refresh_node(ntree, node, *node.runtime->declaration, true);
|
||||
}
|
||||
|
||||
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
|
||||
{
|
||||
return ELEM(
|
||||
socket_type, SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA, SOCK_BOOLEAN, SOCK_INT, SOCK_ROTATION);
|
||||
}
|
||||
|
||||
} // namespace blender::nodes
|
||||
|
||||
void node_verify_sockets(bNodeTree *ntree, bNode *node, bool do_id_user)
|
||||
|
||||
Reference in New Issue
Block a user