[Bf-blender-cvs] [5b60e21f1b8] functions-experimental-refactor: make text socket work again

Jacques Lucke noreply at git.blender.org
Thu Oct 31 15:02:03 CET 2019


Commit: 5b60e21f1b84e4d7e4e300c57436adf298310261
Author: Jacques Lucke
Date:   Thu Oct 31 14:57:40 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rB5b60e21f1b84e4d7e4e300c57436adf298310261

make text socket work again

===================================================================

M	source/blender/blenkernel/BKE_multi_functions.h
M	source/blender/blenkernel/intern/multi_functions.cc
M	source/blender/modifiers/intern/MOD_functiondeform_cxx.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_multi_functions.h b/source/blender/blenkernel/BKE_multi_functions.h
index 4178e833f68..7c132fddeb4 100644
--- a/source/blender/blenkernel/BKE_multi_functions.h
+++ b/source/blender/blenkernel/BKE_multi_functions.h
@@ -53,6 +53,12 @@ class MultiFunction_ObjectWorldLocation final : public MultiFunction {
   void call(ArrayRef<uint> mask_indices, MFParams &params, MFContext &context) const override;
 };
 
+class MultiFunction_TextLength final : public MultiFunction {
+ public:
+  MultiFunction_TextLength();
+  void call(ArrayRef<uint> mask_indices, MFParams &params, MFContext &context) const override;
+};
+
 class MultiFunction_GetListElement final : public MultiFunction {
  private:
   const CPPType &m_base_type;
diff --git a/source/blender/blenkernel/intern/multi_functions.cc b/source/blender/blenkernel/intern/multi_functions.cc
index 498696dcae3..64c2d6d6621 100644
--- a/source/blender/blenkernel/intern/multi_functions.cc
+++ b/source/blender/blenkernel/intern/multi_functions.cc
@@ -206,6 +206,26 @@ void MultiFunction_ObjectWorldLocation::call(ArrayRef<uint> mask_indices,
   }
 }
 
+MultiFunction_TextLength::MultiFunction_TextLength()
+{
+  MFSignatureBuilder signature("Text Length");
+  signature.readonly_single_input<std::string>("Text");
+  signature.single_output<int>("Length");
+  this->set_signature(signature);
+}
+
+void MultiFunction_TextLength::call(ArrayRef<uint> mask_indices,
+                                    MFParams &params,
+                                    MFContext &UNUSED(context)) const
+{
+  auto texts = params.readonly_single_input<std::string>(0, "Text");
+  auto lengths = params.single_output<int>(1, "Length");
+
+  for (uint i : mask_indices) {
+    lengths[i] = texts[i].size();
+  }
+}
+
 MultiFunction_PackList::MultiFunction_PackList(const CPPType &base_type,
                                                ArrayRef<bool> input_list_status)
     : m_base_type(base_type), m_input_list_status(input_list_status)
diff --git a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
index 1c0ea3983b5..e2d3554a54d 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
+++ b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
@@ -80,6 +80,9 @@ static MFDataType get_type_by_socket(const VirtualSocket &vsocket)
   else if (idname == "fn_ObjectSocket") {
     return MFDataType::ForSingle<Object *>();
   }
+  else if (idname == "fn_TextSocket") {
+    return MFDataType::ForSingle<std::string>();
+  }
   else if (idname == "fn_FloatListSocket") {
     return MFDataType::ForVector<float>();
   }
@@ -95,6 +98,9 @@ static MFDataType get_type_by_socket(const VirtualSocket &vsocket)
   else if (idname == "fn_ObjectListSocket") {
     return MFDataType::ForVector<Object *>();
   }
+  else if (idname == "fn_TextListSocket") {
+    return MFDataType::ForVector<std::string>();
+  }
 
   return MFDataType();
 }
@@ -116,6 +122,9 @@ static const CPPType &get_cpp_type_by_name(StringRef name)
   else if (name == "Object") {
     return BKE::GET_TYPE<Object *>();
   }
+  else if (name == "Text") {
+    return BKE::GET_TYPE<std::string>();
+  }
 
   BLI_assert(false);
   return BKE::GET_TYPE<float>();
@@ -550,6 +559,15 @@ static void INSERT_object_location(VTreeMFNetworkBuilder &builder,
   builder.add_function(fn, {0}, {1}, vnode);
 }
 
+static void INSERT_text_length(VTreeMFNetworkBuilder &builder,
+                               OwnedResources &resources,
+                               const VirtualNode &vnode)
+{
+  const MultiFunction &fn = allocate_resource<BKE::MultiFunction_TextLength>(
+      "text length function", resources);
+  builder.add_function(fn, {0}, {1}, vnode);
+}
+
 static StringMap<InsertVNodeFunction> get_node_inserters()
 {
   StringMap<InsertVNodeFunction> inserters;
@@ -561,6 +579,7 @@ static StringMap<InsertVNodeFunction> get_node_inserters()
   inserters.add_new("fn_PackListNode", INSERT_pack_list);
   inserters.add_new("fn_GetListElementNode", INSERT_get_list_element);
   inserters.add_new("fn_ObjectTransformsNode", INSERT_object_location);
+  inserters.add_new("fn_TextLengthNode", INSERT_text_length);
   return inserters;
 }
 
@@ -617,6 +636,21 @@ static MFBuilderOutputSocket &INSERT_object_socket(VTreeMFNetworkBuilder &builde
   return *node.outputs()[0];
 }
 
+static MFBuilderOutputSocket &INSERT_text_socket(VTreeMFNetworkBuilder &builder,
+                                                 OwnedResources &resources,
+                                                 const VirtualSocket &vsocket)
+{
+  PointerRNA rna = vsocket.rna();
+  char *value = RNA_string_get_alloc(&rna, "value", nullptr, 0);
+  std::string text = value;
+  MEM_freeN(value);
+
+  const MultiFunction &fn = allocate_resource<BKE::MultiFunction_ConstantValue<std::string>>(
+      "text socket", resources, text);
+  MFBuilderFunctionNode &node = builder.add_function(fn, {}, {0});
+  return *node.outputs()[0];
+}
+
 template<typename T>
 static MFBuilderOutputSocket &INSERT_empty_list_socket(VTreeMFNetworkBuilder &builder,
                                                        OwnedResources &resources,
@@ -635,10 +669,12 @@ static StringMap<InsertUnlinkedInputFunction> get_unlinked_input_inserter()
   inserters.add_new("fn_FloatSocket", INSERT_float_socket);
   inserters.add_new("fn_IntegerSocket", INSERT_int_socket);
   inserters.add_new("fn_ObjectSocket", INSERT_object_socket);
+  inserters.add_new("fn_TextSocket", INSERT_text_socket);
   inserters.add_new("fn_VectorListSocket", INSERT_empty_list_socket<float3>);
   inserters.add_new("fn_FloatListSocket", INSERT_empty_list_socket<float>);
   inserters.add_new("fn_IntegerListSocket", INSERT_empty_list_socket<int32_t>);
   inserters.add_new("fn_ObjectListSocket", INSERT_empty_list_socket<Object *>);
+  inserters.add_new("fn_TextListSocket", INSERT_empty_list_socket<std::string>);
   return inserters;
 }
 
@@ -860,6 +896,7 @@ class MultiFunction_FunctionTree : public BKE::MultiFunction {
       for (GenericVectorArray *vector_array : m_vector_arrays) {
         delete vector_array;
       }
+      /* TODO: Proper freeing of elements in array. */
       for (GenericMutableArrayRef array : m_arrays) {
         MEM_freeN(array.buffer());
       }



More information about the Bf-blender-cvs mailing list