Commit: e0a7c11dd088eb15cead4d2abad9a2ab02ddbf7a
Author: Jacques Lucke
Date: Thu Jul 11 15:14:12 2019 +0200
Branches: functions
https://developer.blender.org/rBe0a7c11dd088eb15cead4d2abad9a2ab02ddbf7a
cleanup simple emitter builders
===================================================================
M source/blender/simulations/bparticles/emitters.cpp
M source/blender/simulations/bparticles/emitters.hpp
M source/blender/simulations/bparticles/inserters.cpp
M source/blender/simulations/bparticles/inserters.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/emitters.cpp
b/source/blender/simulations/bparticles/emitters.cpp
index 51be0b5abd5..b6eea03fba6 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -156,17 +156,20 @@ class SurfaceEmitter : public Emitter {
}
};
-Emitter *EMITTER_point(StringRef particle_type_name, float3 point)
+std::unique_ptr<Emitter> EMITTER_point(StringRef particle_type_name, float3
point)
{
- return new PointEmitter(particle_type_name, point);
+ Emitter *emitter = new PointEmitter(particle_type_name, point);
+ return std::unique_ptr<Emitter>(emitter);
}
-Emitter *EMITTER_mesh_surface(StringRef particle_type_name,
- SharedFunction &compute_inputs_fn,
- WorldState &world_state,
- std::unique_ptr<Action> action)
+std::unique_ptr<Emitter> EMITTER_mesh_surface(StringRef particle_type_name,
+ SharedFunction
&compute_inputs_fn,
+ WorldState &world_state,
+ std::unique_ptr<Action> action)
{
- return new SurfaceEmitter(particle_type_name, compute_inputs_fn,
world_state, std::move(action));
+ Emitter *emitter = new SurfaceEmitter(
+ particle_type_name, compute_inputs_fn, world_state, std::move(action));
+ return std::unique_ptr<Emitter>(emitter);
}
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/emitters.hpp
b/source/blender/simulations/bparticles/emitters.hpp
index f7f1ffee558..d3380d0343f 100644
--- a/source/blender/simulations/bparticles/emitters.hpp
+++ b/source/blender/simulations/bparticles/emitters.hpp
@@ -11,11 +11,11 @@ namespace BParticles {
using FN::SharedFunction;
using FN::TupleCallBody;
-Emitter *EMITTER_point(StringRef particle_type_name, float3 point);
+std::unique_ptr<Emitter> EMITTER_point(StringRef particle_type_name, float3
point);
-Emitter *EMITTER_mesh_surface(StringRef particle_type_name,
- SharedFunction &compute_inputs_fn,
- WorldState &world_state,
- std::unique_ptr<Action> action);
+std::unique_ptr<Emitter> EMITTER_mesh_surface(StringRef particle_type_name,
+ SharedFunction
&compute_inputs_fn,
+ WorldState &world_state,
+ std::unique_ptr<Action> action);
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/inserters.cpp
b/source/blender/simulations/bparticles/inserters.cpp
index 4fb6f834dba..5e1594383f4 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -17,11 +17,6 @@ namespace BParticles {
using FN::SharedFunction;
-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") ||
@@ -216,54 +211,6 @@ static std::unique_ptr<Action> build_action(SocketWithNode
start,
}
}
-static void INSERT_EMITTER_mesh_surface(ProcessNodeInterface &interface)
-{
- for (SocketWithNode linked : interface.linked_with_output(1)) {
- if (!is_particle_type_node(linked.node)) {
- continue;
- }
-
- SharedFunction fn = create_function_for_data_inputs(
- interface.bnode(), interface.indexed_tree(), interface.data_graph());
-
- auto action = build_action({interface.outputs().get(0), interface.bnode()},
- interface.indexed_tree(),
- interface.data_graph(),
- interface.step_description());
-
- bNode *type_node = linked.node;
- Emitter *emitter = EMITTER_mesh_surface(
- type_node->name, fn, interface.world_state(), std::move(action));
- interface.step_description().m_emitters.append(emitter);
- }
-}
-
-static void INSERT_EMITTER_point(ProcessNodeInterface &interface)
-{
- for (SocketWithNode linked : interface.linked_with_output(0)) {
- if (!is_particle_type_node(linked.node)) {
- continue;
- }
-
- float3 position;
- PointerRNA rna = interface.node_rna();
- RNA_float_get_array(&rna, "position", position);
-
- bNode *type_node = linked.node;
- Emitter *emitter = EMITTER_point(type_node->name, position);
-
- interface.step_description().m_emitters.append(emitter);
- }
-}
-
-BLI_LAZY_INIT(ProcessFunctionsMap, get_node_processors)
-{
- ProcessFunctionsMap processors;
- processors.add_new("bp_MeshEmitterNode", INSERT_EMITTER_mesh_surface);
- processors.add_new("bp_PointEmitterNode", INSERT_EMITTER_point);
- return processors;
-}
-
static std::unique_ptr<Force> BUILD_FORCE_gravity(BuildContext &ctx, bNode
*bnode)
{
SharedFunction fn = create_function_for_data_inputs(bnode, ctx.indexed_tree,
ctx.data_graph);
@@ -318,4 +265,37 @@ BLI_LAZY_INIT(EventFromNodeCallbackMap, get_event_builders)
return map;
}
+static std::unique_ptr<Emitter> BUILD_EMITTER_point(BuildContext &ctx,
+ bNode *bnode,
+ StringRef
particle_type_name)
+{
+ float3 position;
+ PointerRNA rna = ctx.indexed_tree.get_rna(bnode);
+ RNA_float_get_array(&rna, "position", position);
+
+ return EMITTER_point(particle_type_name, position);
+}
+
+static std::unique_ptr<Emitter> BUILD_EMITTER_mesh_surface(BuildContext &ctx,
+ bNode *bnode,
+ StringRef
particle_type_name)
+{
+ SharedFunction fn = create_function_for_data_inputs(bnode, ctx.indexed_tree,
ctx.data_graph);
+
+ auto action = build_action({bSocketList(bnode->outputs).get(0), bnode},
+ ctx.indexed_tree,
+ ctx.data_graph,
+ ctx.step_description);
+
+ return EMITTER_mesh_surface(particle_type_name, fn, ctx.world_state,
std::move(action));
+}
+
+BLI_LAZY_INIT(EmitterFromNodeCallbackMap, get_emitter_builders)
+{
+ EmitterFromNodeCallbackMap map;
+ map.add_new("bp_PointEmitterNode", BUILD_EMITTER_point);
+ map.add_new("bp_MeshEmitterNode", BUILD_EMITTER_mesh_surface);
+ return map;
+}
+
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/inserters.hpp
b/source/blender/simulations/bparticles/inserters.hpp
index c1eefa79a9c..bc2ee622854 100644
--- a/source/blender/simulations/bparticles/inserters.hpp
+++ b/source/blender/simulations/bparticles/inserters.hpp
@@ -16,90 +16,11 @@ using BKE::IndexedNodeTree;
using BKE::SocketWithNode;
using FN::DataFlowNodes::BTreeDataGraph;
-class ProcessNodeInterface {
- private:
- bNode *m_bnode;
- IndexedNodeTree &m_indexed_tree;
- BTreeDataGraph &m_data_graph;
- WorldState &m_world_state;
- ModifierStepDescription &m_step_description;
-
- public:
- ProcessNodeInterface(bNode *bnode,
- IndexedNodeTree &indexed_tree,
- BTreeDataGraph &data_graph,
- WorldState &world_state,
- ModifierStepDescription &step_description)
- : m_bnode(bnode),
- m_indexed_tree(indexed_tree),
- m_data_graph(data_graph),
- m_world_state(world_state),
- m_step_description(step_description)
- {
- }
-
- bNode *bnode()
- {
- return m_bnode;
- }
-
- IndexedNodeTree &indexed_tree()
- {
- return m_indexed_tree;
- }
-
- FN::DataFlowNodes::BTreeDataGraph &data_graph()
- {
- return m_data_graph;
- }
-
- WorldState &world_state()
- {
- return m_world_state;
- }
-
- ModifierStepDescription &step_description()
- {
- return m_step_description;
- }
-
- ArrayRef<SocketWithNode> linked_with_input(uint index)
- {
- bNodeSocket *socket = this->inputs().get(index);
- return m_indexed_tree.linked(socket);
- }
-
- ArrayRef<SocketWithNode> linked_with_output(uint index)
- {
- bNodeSocket *socket = this->outputs().get(index);
- return m_indexed_tree.linked(socket);
- }
-
- bSocketList inputs()
- {
- return bSocketList(m_bnode->inputs);
- }
-
- bSocketList outputs()
- {
- return bSocketList(m_bnode->outputs);
- }
-
- PointerRNA node_rna()
- {
- return m_indexed_tree.get_rna(m_bnode);
- }
-};
-
-using ProcessNodeFunction = std::function<void(ProcessNodeInterface
&interface)>;
-using ProcessFunctionsMap = SmallMap<std::string, ProcessNodeFunction>;
-
-ProcessFunctionsMap &get_node_processors();
-
struct BuildContext {
IndexedNodeTree &indexed_tree;
BTreeDataGraph &data_graph;
ModifierStepDescription &step_description;
+ WorldState &world_state;
};
using ForceFromNodeCallback =
@@ -114,4 +35,10 @@ using EventFromNodeCallbackMap = SmallMap<std::string,
EventFromNodeCallback>;
EventFromNodeCallbackMap &get_event_builders();
+using EmitterFromNodeCallback = std::function<std::unique_ptr<Emitter>(
+ BuildContext &ctx, bNode *bnode, StringRef particle_type_name)>;
+using EmitterFromNodeCallbackMap = SmallMap<std::string,
EmitterFromNodeCallback>;
+
+EmitterFromNodeCallbackMap &get_emitter_builders();
+
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp
b/source/blender/simulations/bparticles/node_frontend.cpp
index fd665eb9774..70aff0ce7a8 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -9,6 +9,22 @@ static bool is_particle_type_node(bNode *bnode)
return STREQ(bnode->idname, "bp_ParticleTypeNode");
}
+static bool is_emitter_socket(bNodeSocket *bsocket)
+{
+ return STREQ(bsocket->idname, "bp_EmitterSocket");
+}
+
+static bNodeSocket *find_emitter_output(bNode *bnode)
+{
+ for (bNodeSocket *bsocket : bSocketList(bnode->outputs)) {
+ if (is_emitter_socket(bsocket)) {
+ return bsocket;
+ }
+ }
+ BLI_assert(false);
+ return nullptr;
+}
+
std::unique_ptr<
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs