[Bf-blender-cvs] [43d037b0862] functions: move inserters to separate file

Jacques Lucke noreply at git.blender.org
Tue Jul 9 18:01:20 CEST 2019


Commit: 43d037b0862d44168868bc1e42e313bbc307fc26
Author: Jacques Lucke
Date:   Tue Jul 9 12:13:34 2019 +0200
Branches: functions
https://developer.blender.org/rB43d037b0862d44168868bc1e42e313bbc307fc26

move inserters to separate file

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

M	source/blender/simulations/CMakeLists.txt
M	source/blender/simulations/bparticles/c_wrapper.cpp
A	source/blender/simulations/bparticles/inserters.cpp
A	source/blender/simulations/bparticles/inserters.hpp

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

diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index f9518a5890b..9e07ffc1d8d 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -39,6 +39,8 @@ set(SRC
   bparticles/world_state.hpp
   bparticles/integrator.hpp
   bparticles/integrator.cpp
+  bparticles/inserters.hpp
+  bparticles/inserters.cpp
 )
 
 set(LIB
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 9a425aedfa7..f8b25ac7152 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -9,6 +9,7 @@
 #include "world_state.hpp"
 #include "step_description.hpp"
 #include "integrator.hpp"
+#include "inserters.hpp"
 
 #include "BLI_timeit.hpp"
 #include "BLI_listbase.h"
@@ -79,388 +80,6 @@ void BParticles_world_state_free(BParticlesWorldState world_state_c)
   delete unwrap(world_state_c);
 }
 
-using EmitterInserter = std::function<void(bNode *bnode,
-                                           IndexedNodeTree &indexed_tree,
-                                           FN::DataFlowNodes::GeneratedGraph &data_graph,
-                                           ModifierStepDescription &step_description,
-                                           WorldState &world_state)>;
-using EventInserter = EmitterInserter;
-using ModifierInserter = EmitterInserter;
-
-static bool is_particle_type_node(bNode *bnode)
-{
-  return STREQ(bnode->idname, "bp_ParticleTypeNode");
-}
-
-static bool is_particle_data_input(bNode *bnode)
-{
-  return STREQ(bnode->idname, "bp_ParticleInfoNode") ||
-         STREQ(bnode->idname, "bp_MeshCollisionEventNode");
-}
-
-static ArrayRef<bNode *> get_particle_type_nodes(IndexedNodeTree &indexed_tree)
-{
-  return indexed_tree.nodes_with_idname("bp_ParticleTypeNode");
-}
-
-static SmallVector<FN::DFGraphSocket> insert_inputs(FN::FunctionBuilder &fn_builder,
-                                                    IndexedNodeTree &indexed_tree,
-                                                    FN::DataFlowNodes::GeneratedGraph &data_graph,
-                                                    ArrayRef<bNodeSocket *> output_sockets)
-{
-  SmallSet<bNodeSocket *> to_be_checked = output_sockets;
-  SmallSet<bNodeSocket *> found_inputs;
-  SmallVector<FN::DFGraphSocket> inputs;
-
-  while (to_be_checked.size() > 0) {
-    bNodeSocket *bsocket = to_be_checked.pop();
-    if (bsocket->in_out == SOCK_IN) {
-      auto linked = indexed_tree.linked(bsocket);
-      BLI_assert(linked.size() <= 1);
-      if (linked.size() == 1) {
-        SocketWithNode origin = linked[0];
-        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);
-        }
-      }
-    }
-    else {
-      bNode *bnode = indexed_tree.node_of_socket(bsocket);
-      for (bNodeSocket *input : bSocketList(bnode->inputs)) {
-        to_be_checked.add(input);
-      }
-    }
-  }
-  return inputs;
-}
-
-static SharedFunction create_function(IndexedNodeTree &indexed_tree,
-                                      FN::DataFlowNodes::GeneratedGraph &data_graph,
-                                      ArrayRef<bNodeSocket *> output_bsockets,
-                                      StringRef name)
-{
-  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) {
-    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 = fn_builder.build(name);
-  FN::fgraph_add_TupleCallBody(fn, function_graph);
-  return fn;
-}
-
-static std::unique_ptr<Action> build_action(SocketWithNode start,
-                                            IndexedNodeTree &indexed_tree,
-                                            FN::DataFlowNodes::GeneratedGraph &data_graph,
-                                            ModifierStepDescription &step_description)
-{
-  if (start.socket->in_out == SOCK_OUT) {
-    auto linked = indexed_tree.linked(start.socket);
-    if (linked.size() == 0) {
-      return ACTION_none();
-    }
-    else if (linked.size() == 1) {
-      return build_action(linked[0], indexed_tree, data_graph, step_description);
-    }
-    else {
-      return nullptr;
-    }
-  }
-
-  BLI_assert(start.socket->in_out == SOCK_IN);
-  bNode *bnode = start.node;
-  bSocketList node_inputs(bnode->inputs);
-  bSocketList node_outputs(bnode->outputs);
-
-  if (STREQ(bnode->idname, "bp_KillParticleNode")) {
-    return ACTION_kill();
-  }
-  else if (STREQ(bnode->idname, "bp_ChangeParticleDirectionNode")) {
-    SharedFunction fn = create_function(
-        indexed_tree, data_graph, {node_inputs.get(1)}, "Compute Direction");
-    ParticleFunction particle_fn(fn);
-    return ACTION_change_direction(
-        particle_fn,
-        build_action({node_outputs.get(0), bnode}, indexed_tree, data_graph, step_description));
-  }
-  else if (STREQ(bnode->idname, "bp_ExplodeParticleNode")) {
-    SharedFunction fn = create_function(
-        indexed_tree, data_graph, {node_inputs.get(1), node_inputs.get(2)}, bnode->name);
-    ParticleFunction particle_fn(fn);
-
-    PointerRNA rna = indexed_tree.get_rna(bnode);
-    char name[65];
-    RNA_string_get(&rna, "particle_type_name", name);
-
-    auto post_action = build_action(
-        {node_outputs.get(0), bnode}, indexed_tree, data_graph, step_description);
-
-    if (step_description.m_types.contains(name)) {
-      return ACTION_explode(name, particle_fn, std::move(post_action));
-    }
-    else {
-      return post_action;
-    }
-  }
-  else if (STREQ(bnode->idname, "bp_ParticleConditionNode")) {
-    SharedFunction fn = create_function(
-        indexed_tree, data_graph, {node_inputs.get(1)}, bnode->name);
-    ParticleFunction particle_fn(fn);
-
-    auto true_action = build_action(
-        {node_outputs.get(0), bnode}, indexed_tree, data_graph, step_description);
-    auto false_action = build_action(
-        {node_outputs.get(1), bnode}, indexed_tree, data_graph, step_description);
-
-    return ACTION_condition(particle_fn, std::move(true_action), std::move(false_action));
-  }
-  else {
-    return nullptr;
-  }
-}
-
-static void INSERT_EMITTER_mesh_surface(bNode *emitter_node,
-                                        IndexedNodeTree &indexed_tree,
-                                        FN::DataFlowNodes::GeneratedGraph &UNUSED(data_graph),
-                                        ModifierStepDescription &step_description,
-                                        WorldState &world_state)
-{
-  BLI_assert(STREQ(emitter_node->idname, "bp_MeshEmitterNode"));
-  bNodeSocket *emitter_output = (bNodeSocket *)emitter_node->outputs.first;
-  for (SocketWithNode linked : indexed_tree.linked(emitter_output)) {
-    if (!is_particle_type_node(linked.node)) {
-      continue;
-    }
-
-    bNode *type_node = linked.node;
-
-    PointerRNA rna = indexed_tree.get_rna(emitter_node);
-
-    Object *object = (Object *)RNA_pointer_get(&rna, "object").id.data;
-    if (object == nullptr) {
-      continue;
-    }
-
-    float4x4 last_transformation = world_state.update(emitter_node->name, object->obmat);
-    float4x4 current_transformation = object->obmat;
-
-    Emitter *emitter = EMITTER_mesh_surface(
-        type_node->name, (Mesh *)object->data, last_transformation, current_transformation, 1.0f);
-    step_description.m_emitters.append(emitter);
-  }
-}
-
-static void INSERT_EMITTER_point(bNode *emitter_node,
-                                 IndexedNodeTree &indexed_tree,
-                                 FN::DataFlowNodes::GeneratedGraph &UNUSED(data_graph),
-                                 ModifierStepDescription &step_description,
-                                 WorldState &UNUSED(world_state))
-{
-  BLI_assert(STREQ(emitter_node->idname, "bp_PointEmitterNode"));
-  bNodeSocket *emitter_output = (bNodeSocket *)emitter_node->outputs.first;
-
-  for (SocketWithNode linked : indexed_tree.linked(emitter_output)) {
-    if (!is_particle_type_node(linked.node)) {
-      continue;
-    }
-
-    bNode *type_node = linked.node;
-
-    PointerRNA rna = indexed_tree.get_rna(emitter_node);
-
-    float3 position;
-    RNA_float_get_array(&rna, "position", position);
-
-    Emitter *emitter = EMITTER_point(type_node->name, position);
-    step_description.m_emitters.append(emitter);
-  }
-}
-
-static void INSERT_EVENT_age_reached(bNode *event_node,
-                                     IndexedNodeTree &indexed_tree,
-                                     FN::DataFlowNodes::GeneratedGraph &data_graph,
-                                     ModifierStepDescription &step_description,
-                                     WorldState &UNUSED(world_state))
-{
-  BLI_assert(STREQ(event_node->idname, "bp_AgeReachedEventNode"));
-  bSocketList node_inputs(event_node->inputs);
-  FN::SharedFunction fn = create_function(
-      indexed_tree, data_graph, {node_inputs.get(1)}, event_node->name);
-
-  for (SocketWithNode linked : indexed_tree.linked(node_inputs.get(0))) {
-    if (!is_particle_type_node(linked.node)) {
-      continue;
-    }
-
-    auto action = build_action({(bNodeSocket *)event_node->outputs.first, event_node},
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list