Nodes: multi-input support for Attribute Remove node

This patch adds multi-input support to the Attribute Remove node.

Reviewed By: Hans Goudey

Differential Revision: https://developer.blender.org/D10698
This commit is contained in:
2021-03-14 23:11:36 +01:00
parent a01fb22f28
commit 070010e203
3 changed files with 33 additions and 17 deletions

View File

@@ -304,17 +304,17 @@ class GeometryNodesEvaluator {
Vector<DSocket> from_sockets;
socket_to_compute.foreach_origin_socket([&](DSocket socket) { from_sockets.append(socket); });
/* Multi-input sockets contain a vector of inputs. */
if (socket_to_compute->is_multi_input_socket()) {
return this->get_inputs_from_incoming_links(socket_to_compute, from_sockets);
}
if (from_sockets.is_empty()) {
/* The input is not connected, use the value from the socket itself. */
const CPPType &type = *blender::nodes::socket_cpp_type_get(*socket_to_compute->typeinfo());
return {get_unlinked_input_value(socket_to_compute, type)};
}
/* Multi-input sockets contain a vector of inputs. */
if (socket_to_compute->is_multi_input_socket()) {
return this->get_inputs_from_incoming_links(socket_to_compute, from_sockets);
}
const DSocket from_socket = from_sockets[0];
GMutablePointer value = this->get_input_from_incoming_link(socket_to_compute, from_socket);
return {value};

View File

@@ -129,7 +129,7 @@ class GeoNodeExecParams {
if (!input_values_.contains(sub_identifier)) {
break;
}
values.append(input_values_.extract<T>(sub_identifier));
values.append(input_values_.extract<T, StringRef>(sub_identifier));
index++;
}
return values;

View File

@@ -18,7 +18,16 @@
static bNodeSocketTemplate geo_node_attribute_remove_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_STRING, N_("Attribute")},
{SOCK_STRING,
N_("Attribute"),
0.0f,
0.0f,
0.0f,
1.0f,
-1.0f,
1.0f,
PROP_NONE,
SOCK_MULTI_INPUT},
{-1, ""},
};
@@ -29,30 +38,37 @@ static bNodeSocketTemplate geo_node_attribute_remove_out[] = {
namespace blender::nodes {
static void remove_attribute(GeometryComponent &component, const GeoNodeExecParams &params)
static void remove_attribute(GeometryComponent &component,
GeoNodeExecParams &params,
Span<std::string> attribute_names)
{
const std::string attribute_name = params.get_input<std::string>("Attribute");
if (attribute_name.empty()) {
return;
}
for (std::string attribute_name : attribute_names) {
if (attribute_name.empty()) {
continue;
}
if (!component.attribute_try_delete(attribute_name)) {
params.error_message_add(NodeWarningType::Error,
TIP_("Cannot delete attribute with name \"") + attribute_name + "\"");
if (!component.attribute_try_delete(attribute_name)) {
params.error_message_add(NodeWarningType::Error,
TIP_("Cannot delete attribute with name \"") + attribute_name +
"\"");
}
}
}
static void geo_node_attribute_remove_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
Vector<std::string> attribute_names = params.extract_multi_input<std::string>("Attribute");
geometry_set = geometry_set_realize_instances(geometry_set);
if (geometry_set.has<MeshComponent>()) {
remove_attribute(geometry_set.get_component_for_write<MeshComponent>(), params);
remove_attribute(
geometry_set.get_component_for_write<MeshComponent>(), params, attribute_names);
}
if (geometry_set.has<PointCloudComponent>()) {
remove_attribute(geometry_set.get_component_for_write<PointCloudComponent>(), params);
remove_attribute(
geometry_set.get_component_for_write<PointCloudComponent>(), params, attribute_names);
}
params.set_output("Geometry", geometry_set);