Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/scripts/startup/nodeitems_builtins.py1
-rw-r--r--source/blender/blenkernel/BKE_node.h1
-rw-r--r--source/blender/blenkernel/intern/node.cc1
-rw-r--r--source/blender/nodes/CMakeLists.txt1
-rw-r--r--source/blender/nodes/NOD_function.h1
-rw-r--r--source/blender/nodes/NOD_static_types.h1
-rw-r--r--source/blender/nodes/function/nodes/node_fn_replace_string.cc67
7 files changed, 73 insertions, 0 deletions
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 215bd65cd1a..a9112727daa 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -720,6 +720,7 @@ geometry_node_categories = [
NodeItem("GeometryNodeStringJoin"),
NodeItem("FunctionNodeInputSpecialCharacters"),
NodeItem("GeometryNodeStringToCurves"),
+ NodeItem("FunctionNodeReplaceString"),
]),
GeometryNodeCategory("GEO_TEXTURE", "Texture", items=[
NodeItem("ShaderNodeTexGradient"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 07ad317dd30..2d3b24630b1 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1566,6 +1566,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define FN_NODE_ROTATE_EULER 1215
#define FN_NODE_ALIGN_EULER_TO_VECTOR 1216
#define FN_NODE_INPUT_COLOR 1217
+#define FN_NODE_REPLACE_STRING 1218
/** \} */
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index ce8f941b0b6..54a094e40ef 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5879,6 +5879,7 @@ static void registerFunctionNodes()
register_node_type_fn_input_vector();
register_node_type_fn_input_color();
register_node_type_fn_random_value();
+ register_node_type_fn_replace_string();
register_node_type_fn_rotate_euler();
register_node_type_fn_string_length();
register_node_type_fn_string_substring();
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 4d006342e72..879d24fdf53 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -145,6 +145,7 @@ set(SRC
function/nodes/node_fn_input_vector.cc
function/nodes/node_fn_input_color.cc
function/nodes/node_fn_random_value.cc
+ function/nodes/node_fn_replace_string.cc
function/nodes/node_fn_rotate_euler.cc
function/nodes/node_fn_string_length.cc
function/nodes/node_fn_string_substring.cc
diff --git a/source/blender/nodes/NOD_function.h b/source/blender/nodes/NOD_function.h
index 999162b1803..e3e75b6fa7a 100644
--- a/source/blender/nodes/NOD_function.h
+++ b/source/blender/nodes/NOD_function.h
@@ -31,6 +31,7 @@ void register_node_type_fn_input_string(void);
void register_node_type_fn_input_vector(void);
void register_node_type_fn_input_color(void);
void register_node_type_fn_random_value(void);
+void register_node_type_fn_replace_string(void);
void register_node_type_fn_rotate_euler(void);
void register_node_type_fn_string_length(void);
void register_node_type_fn_string_substring(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index c20a9545968..78a3735c5b8 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -274,6 +274,7 @@ DefNode(FunctionNode, FN_NODE_INPUT_SPECIAL_CHARACTERS, 0, "INPUT_SPECIAL_CHARAC
DefNode(FunctionNode, FN_NODE_INPUT_STRING, def_fn_input_string, "INPUT_STRING", InputString, "String", "")
DefNode(FunctionNode, FN_NODE_INPUT_VECTOR, def_fn_input_vector, "INPUT_VECTOR", InputVector, "Vector", "")
DefNode(FunctionNode, FN_NODE_RANDOM_VALUE, def_fn_random_value, "RANDOM_VALUE", RandomValue, "Random Value", "")
+DefNode(FunctionNode, FN_NODE_REPLACE_STRING, 0, "REPLACE_STRING", ReplaceString, "Replace String", "")
DefNode(FunctionNode, FN_NODE_ROTATE_EULER, def_fn_rotate_euler, "ROTATE_EULER", RotateEuler, "Rotate Euler", "")
DefNode(FunctionNode, FN_NODE_STRING_LENGTH, 0, "STRING_LENGTH", StringLength, "String Length", "")
DefNode(FunctionNode, FN_NODE_STRING_SUBSTRING, 0, "STRING_SUBSTRING", StringSubstring, "String Substring", "")
diff --git a/source/blender/nodes/function/nodes/node_fn_replace_string.cc b/source/blender/nodes/function/nodes/node_fn_replace_string.cc
new file mode 100644
index 00000000000..d21044d54a5
--- /dev/null
+++ b/source/blender/nodes/function/nodes/node_fn_replace_string.cc
@@ -0,0 +1,67 @@
+/*
+ * 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 "BLI_string_utf8.h"
+
+#include "node_function_util.hh"
+
+namespace blender::nodes {
+
+static void fn_node_replace_string_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::String>("String");
+ b.add_input<decl::String>("Find").description("The string to find in the input string");
+ b.add_input<decl::String>("Replace").description("The string to replace each match with");
+ b.add_output<decl::String>("String");
+};
+
+} // namespace blender::nodes
+
+static std::string replace_all(std::string str, const std::string &from, const std::string &to)
+{
+ if (from.length() <= 0) {
+ return str;
+ }
+ const size_t step = to.length() > 0 ? to.length() : 1;
+
+ size_t offset = 0;
+ while ((offset = str.find(from, offset)) != std::string::npos) {
+ str.replace(offset, from.length(), to);
+ offset += step;
+ }
+ return str;
+}
+
+static void fn_node_replace_string_build_multi_function(
+ blender::nodes::NodeMultiFunctionBuilder &builder)
+{
+ static blender::fn::CustomMF_SI_SI_SI_SO<std::string, std::string, std::string, std::string>
+ substring_fn{"Replace",
+ [](const std::string &str,
+ const std::string &find,
+ const std::string &replace) { return replace_all(str, find, replace); }};
+ builder.set_matching_fn(&substring_fn);
+}
+
+void register_node_type_fn_replace_string()
+{
+ static bNodeType ntype;
+
+ fn_node_type_base(&ntype, FN_NODE_REPLACE_STRING, "Replace String", NODE_CLASS_CONVERTER, 0);
+ ntype.declare = blender::nodes::fn_node_replace_string_declare;
+ ntype.build_multi_function = fn_node_replace_string_build_multi_function;
+ nodeRegisterType(&ntype);
+}