Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_attribute_remove.cc
| Show All 12 Lines | |||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| static bNodeSocketTemplate geo_node_attribute_remove_in[] = { | static bNodeSocketTemplate geo_node_attribute_remove_in[] = { | ||||
| {SOCK_GEOMETRY, N_("Geometry")}, | {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, ""}, | {-1, ""}, | ||||
| }; | }; | ||||
| static bNodeSocketTemplate geo_node_attribute_remove_out[] = { | static bNodeSocketTemplate geo_node_attribute_remove_out[] = { | ||||
| {SOCK_GEOMETRY, N_("Geometry")}, | {SOCK_GEOMETRY, N_("Geometry")}, | ||||
| {-1, ""}, | {-1, ""}, | ||||
| }; | }; | ||||
| namespace blender::nodes { | namespace blender::nodes { | ||||
| static void remove_attribute(GeometryComponent &component, const GeoNodeExecParams ¶ms) | static void remove_attribute(GeometryComponent &component, GeoNodeExecParams ¶ms, Span<std::string> attribute_names) | ||||
| { | { | ||||
| const std::string attribute_name = params.get_input<std::string>("Attribute"); | for(std::string attribute_name : attribute_names){ | ||||
| if (attribute_name.empty()) { | if (attribute_name.empty()) { | ||||
JacquesLucke: This check is not necessary. | |||||
| return; | continue; | ||||
| } | } | ||||
Done Inline ActionsYou wouldn't need to add a new get_multi_input function if you used extract_input in geo_node_attribute_remove_exec and passed a span into this function. HooglyBoogly: You wouldn't need to add a new `get_multi_input` function if you used `extract_input` in… | |||||
| if (!component.attribute_try_delete(attribute_name)) { | if (!component.attribute_try_delete(attribute_name)) { | ||||
| params.error_message_add(NodeWarningType::Error, | params.error_message_add(NodeWarningType::Error, | ||||
| TIP_("Cannot delete attribute with name \"") + attribute_name + "\""); | TIP_("Cannot delete attribute with name \"") + attribute_name + "\""); | ||||
Done Inline ActionsThis should probably be continue. JacquesLucke: This should probably be `continue`. | |||||
| } | } | ||||
| } | } | ||||
| } | |||||
| static void geo_node_attribute_remove_exec(GeoNodeExecParams params) | static void geo_node_attribute_remove_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | 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); | geometry_set = geometry_set_realize_instances(geometry_set); | ||||
| if (geometry_set.has<MeshComponent>()) { | 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>()) { | 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); | params.set_output("Geometry", geometry_set); | ||||
| } | } | ||||
| } // namespace blender::nodes | } // namespace blender::nodes | ||||
| void register_node_type_geo_attribute_remove() | void register_node_type_geo_attribute_remove() | ||||
| { | { | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base( | geo_node_type_base( | ||||
| &ntype, GEO_NODE_ATTRIBUTE_REMOVE, "Attribute Remove", NODE_CLASS_ATTRIBUTE, 0); | &ntype, GEO_NODE_ATTRIBUTE_REMOVE, "Attribute Remove", NODE_CLASS_ATTRIBUTE, 0); | ||||
| node_type_socket_templates(&ntype, geo_node_attribute_remove_in, geo_node_attribute_remove_out); | node_type_socket_templates(&ntype, geo_node_attribute_remove_in, geo_node_attribute_remove_out); | ||||
| ntype.geometry_node_execute = blender::nodes::geo_node_attribute_remove_exec; | ntype.geometry_node_execute = blender::nodes::geo_node_attribute_remove_exec; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||
This check is not necessary.