[Bf-blender-cvs] [5381fbc1a31] functions: turn attribute name into an input socket

Jacques Lucke noreply at git.blender.org
Sat Dec 14 13:15:46 CET 2019


Commit: 5381fbc1a31878482d7394555f7d599e8442e703
Author: Jacques Lucke
Date:   Sat Dec 14 13:15:28 2019 +0100
Branches: functions
https://developer.blender.org/rB5381fbc1a31878482d7394555f7d599e8442e703

turn attribute name into an input socket

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

M	release/scripts/startup/nodes/bparticle_nodes/custom_attributes.py
M	release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py
M	source/blender/functions/FN_generic_array_ref.h
M	source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
M	source/blender/functions/intern/multi_functions/particles.cc
M	source/blender/functions/intern/multi_functions/particles.h
M	source/blender/simulations/bparticles/node_frontend.cpp

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

diff --git a/release/scripts/startup/nodes/bparticle_nodes/custom_attributes.py b/release/scripts/startup/nodes/bparticle_nodes/custom_attributes.py
index c1f90fcabff..d25f397c1ea 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/custom_attributes.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/custom_attributes.py
@@ -7,11 +7,6 @@ class SetParticleAttributeNode(bpy.types.Node, SimulationNode):
     bl_idname = "fn_SetParticleAttributeNode"
     bl_label = "Set Particle Attribute"
 
-    attribute_name: StringProperty(
-        name="Attribute Name",
-        default="My Attribute",
-    )
-
     attribute_type: StringProperty(
         name="Attribute Type",
         default="Float",
@@ -19,13 +14,12 @@ class SetParticleAttributeNode(bpy.types.Node, SimulationNode):
     )
 
     def declaration(self, builder: NodeBuilder):
+        builder.fixed_input("name", "Name", "Text", default="My Attribute", display_name=False)
         builder.fixed_input("value", "Value", self.attribute_type)
         builder.execute_output("execute", "Execute")
 
     def draw(self, layout):
-        row = layout.row(align=True)
-        row.prop(self, "attribute_name", text="")
-        self.invoke_type_selection(row, "set_type", "", mode="BASE", icon="SETTINGS")
+        self.invoke_type_selection(layout, "set_type", "Select Type", mode="BASE", icon="SETTINGS")
 
     def set_type(self, data_type):
         self.attribute_type = data_type
@@ -35,11 +29,6 @@ class GetParticleAttribute(bpy.types.Node, FunctionNode):
     bl_idname = "fn_GetParticleAttributeNode"
     bl_label = "Get Particle Attribute"
 
-    attribute_name: StringProperty(
-        name="Attribute Name",
-        default="My Attribute",
-    )
-
     attribute_type: StringProperty(
         name="Attribute Type",
         default="Float",
@@ -47,12 +36,11 @@ class GetParticleAttribute(bpy.types.Node, FunctionNode):
     )
 
     def declaration(self, builder: NodeBuilder):
+        builder.fixed_input("name", "Name", "Text", default="My Attribute", display_name=False)
         builder.fixed_output("value", "Value", self.attribute_type)
 
     def draw(self, layout):
-        row = layout.row(align=True)
-        row.prop(self, "attribute_name", text="")
-        self.invoke_type_selection(row, "set_type", "", mode="BASE", icon="SETTINGS")
+        self.invoke_type_selection(layout, "set_type", "Select Type", mode="BASE", icon="SETTINGS")
 
     def set_type(self, data_type):
         self.attribute_type = data_type
diff --git a/release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py b/release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py
index 45336819ae5..ea3b4237a03 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py
@@ -13,4 +13,3 @@ class ParticleInfoNode(bpy.types.Node, SimulationNode):
         builder.fixed_output("position", "Position", "Vector")
         builder.fixed_output("velocity", "Velocity", "Vector")
         builder.fixed_output("birth_time", "Birth Time", "Float")
-        builder.fixed_output("emit_location", "Emit Hook", "Surface Hook")
diff --git a/source/blender/functions/FN_generic_array_ref.h b/source/blender/functions/FN_generic_array_ref.h
index 1b51233d306..19a795b812d 100644
--- a/source/blender/functions/FN_generic_array_ref.h
+++ b/source/blender/functions/FN_generic_array_ref.h
@@ -126,6 +126,13 @@ class GenericMutableArrayRef {
     return m_size;
   }
 
+  void default_initialize(ArrayRef<uint> indices)
+  {
+    for (uint i : indices) {
+      m_type->construct_default((*this)[i]);
+    }
+  }
+
   void fill__uninitialized(const void *value)
   {
     for (uint i = 0; i < m_size; i++) {
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 b715aafb1d0..0cd9edb19e5 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
@@ -367,48 +367,35 @@ static void INSERT_perlin_noise(VNodeMFNetworkBuilder &builder)
   builder.set_constructed_matching_fn<MF_PerlinNoise>();
 }
 
-static void INSERT_particle_info(VNodeMFNetworkBuilder &builder)
+static void create_particle_info_nodes(VNodeMFNetworkBuilder &builder,
+                                       StringRef name,
+                                       const XOutputSocket &xsocket)
 {
   InlinedTreeMFNetworkBuilder &network_builder = builder.network_builder();
+  const CPPType &type = network_builder.try_get_data_type(xsocket)->single__cpp_type();
+
+  const MultiFunction &name_fn = network_builder.construct_fn<MF_ConstantValue<std::string>>(name);
+  const MultiFunction &attribute_fn = network_builder.construct_fn<MF_ParticleAttribute>(type);
+  MFBuilderFunctionNode &name_node = network_builder.add_function(name_fn);
+  MFBuilderFunctionNode &attribute_node = network_builder.add_function(attribute_fn);
+  network_builder.add_link(name_node.output(0), attribute_node.input(0));
+  network_builder.map_sockets(xsocket, attribute_node.output(0));
+}
+
+static void INSERT_particle_info(VNodeMFNetworkBuilder &builder)
+{
   const XNode &xnode = builder.xnode();
 
-  {
-    const MultiFunction &fn = network_builder.construct_fn<MF_ParticleAttributes>("ID",
-                                                                                  CPP_TYPE<int>());
-    MFBuilderFunctionNode &node = network_builder.add_function(fn);
-    network_builder.map_sockets(xnode.output(0), node.output(0));
-  }
-  {
-    const MultiFunction &fn = network_builder.construct_fn<MF_ParticleAttributes>(
-        "Position", CPP_TYPE<float3>());
-    MFBuilderFunctionNode &node = network_builder.add_function(fn);
-    network_builder.map_sockets(xnode.output(1), node.output(0));
-  }
-  {
-    const MultiFunction &fn = network_builder.construct_fn<MF_ParticleAttributes>(
-        "Velocity", CPP_TYPE<float3>());
-    MFBuilderFunctionNode &node = network_builder.add_function(fn);
-    network_builder.map_sockets(xnode.output(2), node.output(0));
-  }
-  {
-    const MultiFunction &fn = network_builder.construct_fn<MF_ParticleAttributes>(
-        "Birth Time", CPP_TYPE<float>());
-    MFBuilderFunctionNode &node = network_builder.add_function(fn);
-    network_builder.map_sockets(xnode.output(3), node.output(0));
-  }
-  {
-    const MultiFunction &fn = network_builder.construct_fn<MF_ParticleAttributes>(
-        "Emit Hook", CPP_TYPE<BKE::SurfaceHook>());
-    MFBuilderFunctionNode &node = network_builder.add_function(fn);
-    network_builder.map_sockets(xnode.output(4), node.output(0));
-  }
+  create_particle_info_nodes(builder, "ID", xnode.output(0));
+  create_particle_info_nodes(builder, "Position", xnode.output(1));
+  create_particle_info_nodes(builder, "Velocity", xnode.output(2));
+  create_particle_info_nodes(builder, "Birth Time", xnode.output(3));
 }
 
 static void INSERT_get_particle_attribute(VNodeMFNetworkBuilder &builder)
 {
-  std::string name = builder.string_from_property("attribute_name");
   const CPPType &type = builder.cpp_type_from_property("attribute_type");
-  builder.set_constructed_matching_fn<MF_ParticleAttributes>(std::move(name), type);
+  builder.set_constructed_matching_fn<MF_ParticleAttribute>(type);
 }
 
 static void INSERT_closest_surface_hook_on_object(VNodeMFNetworkBuilder &builder)
diff --git a/source/blender/functions/intern/multi_functions/particles.cc b/source/blender/functions/intern/multi_functions/particles.cc
index d083f3dddc8..cdb9687d5a6 100644
--- a/source/blender/functions/intern/multi_functions/particles.cc
+++ b/source/blender/functions/intern/multi_functions/particles.cc
@@ -1,51 +1,49 @@
 #include "particles.h"
+#include "util.h"
 
 #include "FN_multi_function_common_contexts.h"
 
 namespace FN {
 
-MF_ParticleAttributes::MF_ParticleAttributes(Vector<std::string> attribute_names,
-                                             Vector<const CPPType *> attribute_types)
-    : m_attribute_names(attribute_names), m_attribute_types(attribute_types)
+MF_ParticleAttribute::MF_ParticleAttribute(const CPPType &type) : m_type(type)
 {
-  BLI_assert(m_attribute_names.size() == m_attribute_types.size());
-
-  MFSignatureBuilder signature("Particle Attributes");
+  MFSignatureBuilder signature("Particle Attribute");
   signature.depends_on_per_element_context(true);
-  for (uint i = 0; i < m_attribute_names.size(); i++) {
-    signature.single_output(m_attribute_names[i], *m_attribute_types[i]);
-  }
+  signature.single_input<std::string>("Attribute Name");
+  signature.single_output("Value", type);
   this->set_signature(signature);
 }
 
-void MF_ParticleAttributes::call(MFMask mask, MFParams params, MFContext context) const
+void MF_ParticleAttribute::call(MFMask mask, MFParams params, MFContext context) const
 {
-  auto context_data = context.try_find_per_element<ParticleAttributesContext>();
-
-  for (uint i = 0; i < m_attribute_names.size(); i++) {
-    StringRef attribute_name = m_attribute_names[i];
-    const CPPType &attribute_type = *m_attribute_types[i];
+  VirtualListRef<std::string> attribute_names = params.readonly_single_input<std::string>(
+      0, "Attribute Name");
+  GenericMutableArrayRef r_values = params.uninitialized_single_output(1, "Value");
 
-    GenericMutableArrayRef r_output = params.uninitialized_single_output(0, attribute_name);
+  auto context_data = context.try_find_per_element<ParticleAttributesContext>();
+  if (!context_data.has_value()) {
+    r_values.default_initialize(mask.indices());
+    return;
+  }
 
-    if (context_data.has_value()) {
-      AttributesRef attributes = context_data.value().data->attributes;
-      Optional<GenericMutableArrayRef> opt_array = attributes.try_get(attribute_name,
-                                                                      attribute_type);
-      if (opt_array.has_value()) {
+  AttributesRef attributes = context_data->data->attributes;
+  VirtualListRef<uint> element_indices = context_data->indices;
+
+  group_indices_by_same

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list