[Bf-blender-cvs] [4d72f25e9a5] functions: make vertex group name an input socket

Jacques Lucke noreply at git.blender.org
Wed Dec 11 16:05:57 CET 2019


Commit: 4d72f25e9a5d2304394276efa7c31900655f8b16
Author: Jacques Lucke
Date:   Wed Dec 11 16:05:47 2019 +0100
Branches: functions
https://developer.blender.org/rB4d72f25e9a5d2304394276efa7c31900655f8b16

make vertex group name an input socket

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

M	release/scripts/startup/nodes/function_nodes/object_mesh.py
M	source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
M	source/blender/functions/intern/multi_functions/surface_hook.cc
M	source/blender/functions/intern/multi_functions/surface_hook.h

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

diff --git a/release/scripts/startup/nodes/function_nodes/object_mesh.py b/release/scripts/startup/nodes/function_nodes/object_mesh.py
index 33b602f5232..0ab7c4d3f38 100644
--- a/release/scripts/startup/nodes/function_nodes/object_mesh.py
+++ b/release/scripts/startup/nodes/function_nodes/object_mesh.py
@@ -63,19 +63,13 @@ class GetWeightOnSurfaceNode(bpy.types.Node, FunctionNode):
     bl_idname = "fn_GetWeightOnSurfaceNode"
     bl_label = "Get Weight on Surface"
 
-    vertex_group_name: StringProperty(
-        name="Vertex Group Name",
-        default="Group",
-    )
-
     use_list__surface_hook: NodeBuilder.VectorizedProperty()
+    use_list__vertex_group_name: NodeBuilder.VectorizedProperty()
 
-    def declaration(self, builder):
+    def declaration(self, builder: NodeBuilder):
         builder.vectorized_input("surface_hook", "use_list__surface_hook", "Surface Hook", "Surface Hooks", "Surface Hook")
-        builder.vectorized_output("weight", ["use_list__surface_hook"], "Weight", "Weights", "Float")
-
-    def draw(self, layout):
-        layout.prop(self, "vertex_group_name", text="", icon="GROUP_VERTEX")
+        builder.vectorized_input("vertex_group_name", "use_list__vertex_group_name", "Name", "Names", "Text", default="Group")
+        builder.vectorized_output("weight", ["use_list__surface_hook", "use_list__vertex_group_name"], "Weight", "Weights", "Float")
 
 
 class GetImageColorOnSurfaceNode(bpy.types.Node, FunctionNode):
diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
index 0ead4e34143..2b06b133ae8 100644
--- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
+++ b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
@@ -76,9 +76,8 @@ static void INSERT_get_normal_on_surface(VNodeMFNetworkBuilder &builder)
 
 static void INSERT_get_weight_on_surface(VNodeMFNetworkBuilder &builder)
 {
-  std::string group_name = builder.string_from_property("vertex_group_name");
-  builder.set_vectorized_constructed_matching_fn<MF_GetWeightOnSurface>({"use_list__surface_hook"},
-                                                                        std::move(group_name));
+  builder.set_vectorized_constructed_matching_fn<MF_GetWeightOnSurface>(
+      {"use_list__surface_hook", "use_list__vertex_group_name"});
 }
 
 static void INSERT_get_image_color_on_surface(VNodeMFNetworkBuilder &builder)
diff --git a/source/blender/functions/intern/multi_functions/surface_hook.cc b/source/blender/functions/intern/multi_functions/surface_hook.cc
index 4060793173e..43d30d565f6 100644
--- a/source/blender/functions/intern/multi_functions/surface_hook.cc
+++ b/source/blender/functions/intern/multi_functions/surface_hook.cc
@@ -251,11 +251,11 @@ void MF_GetNormalOnSurface::call(MFMask mask, MFParams params, MFContext context
       SurfaceHook::on_same_surface);
 }
 
-MF_GetWeightOnSurface::MF_GetWeightOnSurface(std::string vertex_group_name)
-    : m_vertex_group_name(std::move(vertex_group_name))
+MF_GetWeightOnSurface::MF_GetWeightOnSurface()
 {
   MFSignatureBuilder signature("Get Weight on Surface");
   signature.single_input<SurfaceHook>("Surface Hook");
+  signature.single_input<std::string>("Group Name");
   signature.single_output<float>("Weight");
   this->set_signature(signature);
 }
@@ -264,7 +264,9 @@ void MF_GetWeightOnSurface::call(MFMask mask, MFParams params, MFContext context
 {
   VirtualListRef<SurfaceHook> surface_hooks = params.readonly_single_input<SurfaceHook>(
       0, "Surface Hook");
-  MutableArrayRef<float> r_weights = params.uninitialized_single_output<float>(1, "Weight");
+  VirtualListRef<std::string> group_names = params.readonly_single_input<std::string>(
+      1, "Group Name");
+  MutableArrayRef<float> r_weights = params.uninitialized_single_output<float>(2, "Weight");
 
   float fallback = 0.0f;
 
@@ -293,33 +295,37 @@ void MF_GetWeightOnSurface::call(MFMask mask, MFParams params, MFContext context
         const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(mesh);
         int triangle_amount = BKE_mesh_runtime_looptri_len(mesh);
 
-        MDeformVert *vertex_weights = mesh->dvert;
-        int group_index = defgroup_name_index(object, m_vertex_group_name.data());
-        if (group_index == -1 || vertex_weights == nullptr) {
-          r_weights.fill_indices(indices_on_same_surface, fallback);
-          return;
-        }
-
-        for (uint i : indices_on_same_surface) {
-          SurfaceHook hook = surface_hooks[i];
-
-          if (hook.triangle_index() >= triangle_amount) {
-            r_weights[i] = fallback;
-            continue;
-          }
-
-          const MLoopTri &triangle = triangles[hook.triangle_index()];
-          uint v1 = mesh->mloop[triangle.tri[0]].v;
-          uint v2 = mesh->mloop[triangle.tri[1]].v;
-          uint v3 = mesh->mloop[triangle.tri[2]].v;
-
-          float3 corner_weights{defvert_find_weight(vertex_weights + v1, group_index),
-                                defvert_find_weight(vertex_weights + v2, group_index),
-                                defvert_find_weight(vertex_weights + v3, group_index)};
-
-          float weight = float3::dot(hook.bary_coords(), corner_weights);
-          r_weights[i] = weight;
-        }
+        group_indices_by_same_value(
+            indices_on_same_surface,
+            group_names,
+            [&](const std::string &group, ArrayRef<uint> indices_with_same_group) {
+              MDeformVert *vertex_weights = mesh->dvert;
+              int group_index = defgroup_name_index(object, group.c_str());
+              if (group_index == -1 || vertex_weights == nullptr) {
+                r_weights.fill_indices(indices_on_same_surface, fallback);
+                return;
+              }
+              for (uint i : indices_with_same_group) {
+                SurfaceHook hook = surface_hooks[i];
+
+                if (hook.triangle_index() >= triangle_amount) {
+                  r_weights[i] = fallback;
+                  continue;
+                }
+
+                const MLoopTri &triangle = triangles[hook.triangle_index()];
+                uint v1 = mesh->mloop[triangle.tri[0]].v;
+                uint v2 = mesh->mloop[triangle.tri[1]].v;
+                uint v3 = mesh->mloop[triangle.tri[2]].v;
+
+                float3 corner_weights{defvert_find_weight(vertex_weights + v1, group_index),
+                                      defvert_find_weight(vertex_weights + v2, group_index),
+                                      defvert_find_weight(vertex_weights + v3, group_index)};
+
+                float weight = float3::dot(hook.bary_coords(), corner_weights);
+                r_weights[i] = weight;
+              }
+            });
       },
       SurfaceHook::on_same_surface);
 }
diff --git a/source/blender/functions/intern/multi_functions/surface_hook.h b/source/blender/functions/intern/multi_functions/surface_hook.h
index 030e733201e..d2d2754e249 100644
--- a/source/blender/functions/intern/multi_functions/surface_hook.h
+++ b/source/blender/functions/intern/multi_functions/surface_hook.h
@@ -23,11 +23,8 @@ class MF_GetNormalOnSurface final : public MultiFunction {
 };
 
 class MF_GetWeightOnSurface final : public MultiFunction {
- private:
-  std::string m_vertex_group_name;
-
  public:
-  MF_GetWeightOnSurface(std::string vertex_group_name);
+  MF_GetWeightOnSurface();
   void call(MFMask mask, MFParams params, MFContext context) const override;
 };



More information about the Bf-blender-cvs mailing list