[Bf-blender-cvs] [b1bee3ffc51] functions-experimental-refactor: update Function Points modifier to use new system

Jacques Lucke noreply at git.blender.org
Sun Nov 3 16:06:29 CET 2019


Commit: b1bee3ffc510c8a3cc7fb1539275027e2fa35a61
Author: Jacques Lucke
Date:   Sun Nov 3 16:06:25 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rBb1bee3ffc510c8a3cc7fb1539275027e2fa35a61

update Function Points modifier to use new system

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

M	source/blender/functions2/FN_generic_array_ref.h
M	source/blender/functions2/FN_multi_function.h
M	source/blender/functions2/intern/multi_functions/network.cc
M	source/blender/functions2/intern/vtree_multi_function_network/builder.cc
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/intern/MOD_functionpoints.c
A	source/blender/modifiers/intern/MOD_functionpoints_cxx.cc

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

diff --git a/source/blender/functions2/FN_generic_array_ref.h b/source/blender/functions2/FN_generic_array_ref.h
index d4225509e07..5487128b66d 100644
--- a/source/blender/functions2/FN_generic_array_ref.h
+++ b/source/blender/functions2/FN_generic_array_ref.h
@@ -49,7 +49,7 @@ class GenericArrayRef {
     return POINTER_OFFSET(m_buffer, m_type->size() * index);
   }
 
-  template<typename T> ArrayRef<T> get_ref() const
+  template<typename T> ArrayRef<T> as_typed_ref() const
   {
     BLI_assert(GET_TYPE<T>().is_same_or_generalization(*m_type));
     return ArrayRef<T>((const T *)m_buffer, m_size);
@@ -142,7 +142,7 @@ class GenericMutableArrayRef {
     return POINTER_OFFSET(m_buffer, m_type->size() * index);
   }
 
-  template<typename T> MutableArrayRef<T> get_ref()
+  template<typename T> MutableArrayRef<T> as_typed_ref()
   {
     BLI_assert(GET_TYPE<T>().is_same_or_generalization(*m_type));
     return MutableArrayRef<T>((T *)m_buffer, m_size);
diff --git a/source/blender/functions2/FN_multi_function.h b/source/blender/functions2/FN_multi_function.h
index 09075aa2418..f479a5269b0 100644
--- a/source/blender/functions2/FN_multi_function.h
+++ b/source/blender/functions2/FN_multi_function.h
@@ -257,7 +257,7 @@ class MFParams {
   template<typename T> MutableArrayRef<T> single_output(uint index, StringRef name)
   {
     BLI_assert(m_signature->is_single_output<T>(index, name));
-    return this->single_output(index, name).get_ref<T>();
+    return this->single_output(index, name).as_typed_ref<T>();
   }
   GenericMutableArrayRef single_output(uint index, StringRef name)
   {
diff --git a/source/blender/functions2/intern/multi_functions/network.cc b/source/blender/functions2/intern/multi_functions/network.cc
index 91b451fb57a..1a15443b5d5 100644
--- a/source/blender/functions2/intern/multi_functions/network.cc
+++ b/source/blender/functions2/intern/multi_functions/network.cc
@@ -219,7 +219,7 @@ BLI_NOINLINE void MF_EvaluateNetwork::compute_and_forward_outputs(
         }
       }
       else if (m_outputs.contains(target)) {
-        storage.set_vector_array_for_input__non_owning(*target, values);
+        storage.set_virtual_list_list_for_input__non_owning(*target, *values);
       }
     }
   }
diff --git a/source/blender/functions2/intern/vtree_multi_function_network/builder.cc b/source/blender/functions2/intern/vtree_multi_function_network/builder.cc
index 1eb0e0af387..b5c6412d2be 100644
--- a/source/blender/functions2/intern/vtree_multi_function_network/builder.cc
+++ b/source/blender/functions2/intern/vtree_multi_function_network/builder.cc
@@ -141,7 +141,7 @@ const CPPType &VTreeMFNetworkBuilder::cpp_type_from_property(const VNode &vnode,
 
 std::unique_ptr<VTreeMFNetwork> VTreeMFNetworkBuilder::build()
 {
-  // m_builder->to_dot__clipboard();
+  m_builder->to_dot__clipboard();
 
   Array<int> socket_ids(m_vtree.socket_count(), -1);
   for (uint vsocket_id = 0; vsocket_id < m_vtree.socket_count(); vsocket_id++) {
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index 7ef0c4f18fa..569900e7872 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -62,8 +62,9 @@ set(SRC
   intern/MOD_explode.c
   intern/MOD_fluidsim.c
   intern/MOD_fluidsim_util.c
-  intern/MOD_functiondeform.c
   intern/MOD_functiondeform_cxx.cc
+  intern/MOD_functiondeform.c
+  intern/MOD_functionpoints_cxx.cc
   intern/MOD_functionpoints.c
   intern/MOD_hook.c
   intern/MOD_laplaciandeform.c
diff --git a/source/blender/modifiers/intern/MOD_functionpoints.c b/source/blender/modifiers/intern/MOD_functionpoints.c
index fcf0a70e2ed..1de9acc60f6 100644
--- a/source/blender/modifiers/intern/MOD_functionpoints.c
+++ b/source/blender/modifiers/intern/MOD_functionpoints.c
@@ -51,58 +51,13 @@
 #include "DEG_depsgraph_query.h"
 #include "time.h"
 
-#include "FN_all-c.h"
-
-static FnFunction get_current_function(FunctionPointsModifierData *fpmd)
-{
-  bNodeTree *tree = (bNodeTree *)DEG_get_original_id((ID *)fpmd->function_tree);
-
-  FnType float_ty = FN_type_get_float();
-  FnType int32_ty = FN_type_get_int32();
-  FnType float3_list_ty = FN_type_get_float3_list();
-
-  FnType inputs[] = {float_ty, int32_ty, NULL};
-  FnType outputs[] = {float3_list_ty, NULL};
-
-  return FN_function_get_with_signature(tree, inputs, outputs);
-}
-
-static Mesh *build_point_mesh(FunctionPointsModifierData *fpmd)
-{
-  FnFunction fn = get_current_function(fpmd);
-  if (fn == NULL) {
-    modifier_setError(&fpmd->modifier, "Invalid function");
-    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
-  }
-
-  FnTupleCallBody body = FN_tuple_call_get(fn);
-  FN_TUPLE_CALL_PREPARE_STACK(body, fn_in, fn_out);
-
-  FN_tuple_set_float(fn_in, 0, fpmd->control1);
-  FN_tuple_set_int32(fn_in, 1, fpmd->control2);
-  FN_tuple_call_invoke(body, fn_in, fn_out, __func__);
-  FnList list = FN_tuple_relocate_out_list(fn_out, 0);
-
-  FN_TUPLE_CALL_DESTRUCT_STACK(body, fn_in, fn_out);
-  FN_function_free(fn);
-
-  uint amount = FN_list_size(list);
-  float *ptr = (float *)FN_list_storage(list);
-
-  Mesh *mesh = BKE_mesh_new_nomain(amount, 0, 0, 0, 0);
-  for (uint i = 0; i < amount; i++) {
-    copy_v3_v3(mesh->mvert[i].co, ptr + (3 * i));
-  }
-  FN_list_free(list);
-
-  return mesh;
-}
+Mesh *MOD_functionpoints_do(FunctionPointsModifierData *fpmd);
 
 static Mesh *applyModifier(ModifierData *md,
                            const struct ModifierEvalContext *UNUSED(ctx),
                            struct Mesh *UNUSED(mesh))
 {
-  return build_point_mesh((FunctionPointsModifierData *)md);
+  return MOD_functionpoints_do((FunctionPointsModifierData *)md);
 }
 
 static void initData(ModifierData *md)
@@ -117,15 +72,9 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
   return true;
 }
 
-static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
+static void updateDepsgraph(ModifierData *UNUSED(md),
+                            const ModifierUpdateDepsgraphContext *UNUSED(ctx))
 {
-  FunctionPointsModifierData *fpmd = (FunctionPointsModifierData *)md;
-
-  FnFunction fn = get_current_function(fpmd);
-  if (fn) {
-    FN_function_update_dependencies(fn, ctx->node);
-    FN_function_free(fn);
-  }
 }
 
 static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
diff --git a/source/blender/modifiers/intern/MOD_functionpoints_cxx.cc b/source/blender/modifiers/intern/MOD_functionpoints_cxx.cc
new file mode 100644
index 00000000000..0338582f5d3
--- /dev/null
+++ b/source/blender/modifiers/intern/MOD_functionpoints_cxx.cc
@@ -0,0 +1,75 @@
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+
+#include "BKE_mesh.h"
+
+#include "BLI_math.h"
+
+#include "FN_vtree_multi_function_network_generation.h"
+#include "FN_multi_functions.h"
+
+#include "DEG_depsgraph_query.h"
+
+using BKE::VirtualNodeTree;
+using BKE::VNode;
+using BLI::ArrayRef;
+using BLI::float3;
+using BLI::IndexRange;
+using BLI::TemporaryVector;
+using BLI::Vector;
+using FN::MFContext;
+using FN::MFInputSocket;
+using FN::MFOutputSocket;
+using FN::MFParamsBuilder;
+
+extern "C" {
+Mesh *MOD_functionpoints_do(FunctionPointsModifierData *fpmd);
+}
+
+Mesh *MOD_functionpoints_do(FunctionPointsModifierData *fpmd)
+{
+  if (fpmd->function_tree == nullptr) {
+    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+  }
+
+  bNodeTree *btree = (bNodeTree *)DEG_get_original_id((ID *)fpmd->function_tree);
+
+  BKE::VirtualNodeTreeBuilder vtree_builder;
+  vtree_builder.add_all_of_node_tree(btree);
+  auto vtree = vtree_builder.build();
+
+  const VNode &input_vnode = *vtree->nodes_with_idname("fn_FunctionInputNode")[0];
+  const VNode &output_vnode = *vtree->nodes_with_idname("fn_FunctionOutputNode")[0];
+
+  BLI::OwnedResources resources;
+  auto vtree_network = FN::generate_vtree_multi_function_network(*vtree, resources);
+
+  Vector<const MFOutputSocket *> function_inputs = {
+      &vtree_network->lookup_socket(input_vnode.output(0)).as_output(),
+      &vtree_network->lookup_socket(input_vnode.output(1)).as_output()};
+
+  Vector<const MFInputSocket *> function_outputs = {
+      &vtree_network->lookup_socket(output_vnode.input(0)).as_input()};
+
+  FN::MF_EvaluateNetwork function{function_inputs, function_outputs};
+
+  MFParamsBuilder params(function, 1);
+  params.add_readonly_single_input(&fpmd->control1);
+  params.add_readonly_single_input(&fpmd->control2);
+
+  FN::GenericVectorArray vector_array{FN::GET_TYPE<float3>(), 1};
+  params.add_vector_output(vector_array);
+
+  MFContext context;
+  function.call(FN::MFMask({0}), params.build(), context);
+
+  ArrayRef<float3> output_points = vector_array[0].as_typed_ref<float3>();
+
+  Mesh *mesh = BKE_mesh_new_nomain(output_points.size(), 0, 0, 0, 0);
+  for (uint i = 0; i < output_points.size(); i++) {
+    copy_v3_v3(mesh->mvert[i].co, output_points[i]);
+  }
+
+  return mesh;
+}



More information about the Bf-blender-cvs mailing list