[Bf-blender-cvs] [f7e73351238] functions: improved event info usage

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:57:17 CEST 2019


Commit: f7e73351238f4b6a91490aad7c3d0bb2d000fa1a
Author: Jacques Lucke
Date:   Mon Jul 8 15:39:54 2019 +0200
Branches: functions
https://developer.blender.org/rBf7e73351238f4b6a91490aad7c3d0bb2d000fa1a

improved event info usage

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

M	release/scripts/startup/nodes/bparticle_nodes/mesh_collision_event.py
M	source/blender/simulations/bparticles/actions.hpp
M	source/blender/simulations/bparticles/c_wrapper.cpp

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

diff --git a/release/scripts/startup/nodes/bparticle_nodes/mesh_collision_event.py b/release/scripts/startup/nodes/bparticle_nodes/mesh_collision_event.py
index 6f56af7db69..dacb5e4e517 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/mesh_collision_event.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/mesh_collision_event.py
@@ -15,7 +15,7 @@ class MeshCollisionEventNode(bpy.types.Node, BParticlesNode):
     def declaration(self, builder : SocketBuilder):
         builder.event_input("event", "Event")
         builder.control_flow_output("on_event", "On event")
-        builder.fixed_output("normal", "EVENTNormal", "Vector")
+        builder.fixed_output("normal", "Normal", "Vector")
 
     def draw(self, layout):
         layout.prop(self, "object", text="")
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index fce6ac6b650..b92daefc832 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -66,16 +66,20 @@ class ParticleFunction {
       StringRef input_name = m_function->input_name(i);
       void *ptr;
       uint stride;
-      if (input_name.startswith("EVENT")) {
-        StringRef event_attribute_name = input_name.drop_prefix("EVENT");
+      if (input_name.startswith("Event")) {
+        StringRef event_attribute_name = input_name.drop_prefix("Event: ");
         ptr = event_info.get_info_array(event_attribute_name);
         stride = sizeof(float3); /* TODO make not hardcoded */
       }
-      else {
-        uint index = attributes.attribute_index(input_name);
+      else if (input_name.startswith("Attribute")) {
+        StringRef attribute_name = input_name.drop_prefix("Attribute: ");
+        uint index = attributes.attribute_index(attribute_name);
         stride = attributes.attribute_stride(index);
         ptr = attributes.get_ptr(index);
       }
+      else {
+        BLI_assert(false);
+      }
 
       BLI_assert(ptr);
       caller.m_attribute_buffers.append(ptr);
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 064435ecae1..3fd6fc77988 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -225,12 +225,14 @@ static ArrayRef<bNode *> get_particle_type_nodes(IndexedNodeTree &indexed_tree)
   return indexed_tree.nodes_with_idname("bp_ParticleTypeNode");
 }
 
-static SmallVector<bNodeSocket *> find_input_sockets(IndexedNodeTree &indexed_tree,
-                                                     ArrayRef<bNodeSocket *> output_sockets)
+static SmallVector<FN::DFGraphSocket> insert_inputs(FN::FunctionBuilder &fn_builder,
+                                                    IndexedNodeTree &indexed_tree,
+                                                    FN::DataFlowNodes::GeneratedGraph &data_graph,
+                                                    ArrayRef<bNodeSocket *> output_sockets)
 {
-  /* TODO: this has bad time complexity currently */
   SmallSet<bNodeSocket *> to_be_checked = output_sockets;
-  SmallSetVector<bNodeSocket *> found_inputs;
+  SmallSet<bNodeSocket *> found_inputs;
+  SmallVector<FN::DFGraphSocket> inputs;
 
   while (to_be_checked.size() > 0) {
     bNodeSocket *bsocket = to_be_checked.pop();
@@ -239,8 +241,19 @@ static SmallVector<bNodeSocket *> find_input_sockets(IndexedNodeTree &indexed_tr
       BLI_assert(linked.size() <= 1);
       if (linked.size() == 1) {
         SocketWithNode origin = linked[0];
-        if (is_particle_data_input(origin.node)) {
+        if (is_particle_data_input(origin.node) && !found_inputs.contains(origin.socket)) {
+          FN::DFGraphSocket socket = data_graph.lookup_socket(origin.socket);
+          FN::SharedType &type = data_graph.graph()->type_of_socket(socket);
+          std::string name_prefix;
+          if (STREQ(origin.node->idname, "bp_ParticleInfoNode")) {
+            name_prefix = "Attribute: ";
+          }
+          else if (STREQ(origin.node->idname, "bp_MeshCollisionEventNode")) {
+            name_prefix = "Event: ";
+          }
+          fn_builder.add_input(name_prefix + origin.socket->name, type);
           found_inputs.add(origin.socket);
+          inputs.append(socket);
         }
         else {
           to_be_checked.add(origin.socket);
@@ -254,8 +267,7 @@ static SmallVector<bNodeSocket *> find_input_sockets(IndexedNodeTree &indexed_tr
       }
     }
   }
-
-  return found_inputs.to_small_vector();
+  return inputs;
 }
 
 static SharedFunction create_function(IndexedNodeTree &indexed_tree,
@@ -263,18 +275,18 @@ static SharedFunction create_function(IndexedNodeTree &indexed_tree,
                                       ArrayRef<bNodeSocket *> output_bsockets,
                                       StringRef name)
 {
-  SmallVector<FN::DFGraphSocket> inputs;
-  for (bNodeSocket *bsocket : find_input_sockets(indexed_tree, output_bsockets)) {
-    inputs.append(data_graph.lookup_socket(bsocket));
-  }
+  FN::FunctionBuilder fn_builder;
+  auto inputs = insert_inputs(fn_builder, indexed_tree, data_graph, output_bsockets);
 
   SmallVector<FN::DFGraphSocket> outputs;
   for (bNodeSocket *bsocket : output_bsockets) {
-    outputs.append(data_graph.lookup_socket(bsocket));
+    FN::DFGraphSocket socket = data_graph.lookup_socket(bsocket);
+    fn_builder.add_output(bsocket->name, data_graph.graph()->type_of_socket(socket));
+    outputs.append(socket);
   }
 
   FN::FunctionGraph function_graph(data_graph.graph(), inputs, outputs);
-  SharedFunction fn = function_graph.new_function(name);
+  SharedFunction fn = fn_builder.build(name);
   FN::fgraph_add_TupleCallBody(fn, function_graph);
   return fn;
 }



More information about the Bf-blender-cvs mailing list