diff options
author | Cian Jinks <cjinks99@gmail.com> | 2021-09-22 17:09:31 +0300 |
---|---|---|
committer | Cian Jinks <cjinks99@gmail.com> | 2021-09-22 17:09:31 +0300 |
commit | e734491048ef2436af41e272b8900f20785ecbe6 (patch) | |
tree | 8cee3fc068c782c0ba8cb9a581e768968c565569 /source/blender/nodes/geometry/nodes/node_geo_string_join.cc | |
parent | f21cd0881948f6eaf16af0b354cd904df7407bda (diff) | |
parent | 204b01a254ac2445fea217e5211b2ed6aef631ca (diff) |
Merge branch 'master' into soc-2021-knife-toolssoc-2021-knife-tools
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_string_join.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_string_join.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_string_join.cc b/source/blender/nodes/geometry/nodes/node_geo_string_join.cc new file mode 100644 index 00000000000..1e4a4d1f68b --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_string_join.cc @@ -0,0 +1,53 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "node_geometry_util.hh" + +namespace blender::nodes { + +static void geo_node_string_join_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::String>("Delimiter"); + b.add_input<decl::String>("Strings").multi_input().hide_value(); + b.add_output<decl::String>("String"); +}; + +static void geo_node_string_join_exec(GeoNodeExecParams params) +{ + Vector<std::string> strings = params.extract_multi_input<std::string>("Strings"); + const std::string delim = params.extract_input<std::string>("Delimiter"); + + std::string output; + for (const int i : strings.index_range()) { + output += strings[i]; + if (i < (strings.size() - 1)) { + output += delim; + } + } + params.set_output("String", std::move(output)); +} + +} // namespace blender::nodes + +void register_node_type_geo_string_join() +{ + static bNodeType ntype; + + geo_node_type_base(&ntype, GEO_NODE_STRING_JOIN, "String Join", NODE_CLASS_CONVERTER, 0); + ntype.geometry_node_execute = blender::nodes::geo_node_string_join_exec; + ntype.declare = blender::nodes::geo_node_string_join_declare; + nodeRegisterType(&ntype); +} |