[Bf-blender-cvs] [e3454c07081] functions: new Change Particle Size node

Jacques Lucke noreply at git.blender.org
Tue Sep 3 11:42:44 CEST 2019


Commit: e3454c07081233a1eda28d197ac6b05dff1a832e
Author: Jacques Lucke
Date:   Tue Sep 3 11:39:11 2019 +0200
Branches: functions
https://developer.blender.org/rBe3454c07081233a1eda28d197ac6b05dff1a832e

new Change Particle Size node

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

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

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

diff --git a/release/scripts/startup/nodes/bparticle_nodes/change_attribute.py b/release/scripts/startup/nodes/bparticle_nodes/change_attribute.py
index 953f4fd7e15..4a071b22fcf 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/change_attribute.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/change_attribute.py
@@ -36,3 +36,11 @@ class ChangeParticleVelocityNode(bpy.types.Node, BParticlesNode):
 
     def draw(self, layout):
         layout.prop(self, "mode", text="")
+
+class ChangeParticleSizeNode(bpy.types.Node, BParticlesNode):
+    bl_idname = "bp_ChangeParticleSizeNode"
+    bl_label = "Change Particle Size"
+
+    def declaration(self, builder: NodeBuilder):
+        builder.fixed_input("size", "Size", "Float", default=0.01)
+        builder.execute_output("execute", "Execute")
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index bf4c8d0b625..9ef4701d175 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -93,6 +93,17 @@ void ChangeColorAction::execute(ActionInterface &interface)
   }
 }
 
+void ChangeSizeAction::execute(ActionInterface &interface)
+{
+  auto sizes = interface.attributes().get<float>("Size");
+
+  auto inputs = m_compute_inputs->compute(interface);
+  for (uint pindex : interface.pindices()) {
+    float size = inputs->get<float>("Size", 0, pindex);
+    sizes[pindex] = size;
+  }
+}
+
 void KillAction::execute(ActionInterface &interface)
 {
   interface.kill(interface.pindices());
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index 9e6a304257c..4c68c750985 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -64,6 +64,19 @@ class ChangeColorAction : public Action {
   void execute(ActionInterface &interface) override;
 };
 
+class ChangeSizeAction : public Action {
+ private:
+  std::unique_ptr<ParticleFunction> m_compute_inputs;
+
+ public:
+  ChangeSizeAction(std::unique_ptr<ParticleFunction> compute_inputs)
+      : m_compute_inputs(std::move(compute_inputs))
+  {
+  }
+
+  void execute(ActionInterface &interface) override;
+};
+
 class ExplodeAction : public Action {
  private:
   Vector<std::string> m_types_to_emit;
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 814750eabbb..b719819d42f 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -167,6 +167,21 @@ static std::unique_ptr<Action> ACTION_change_color(VTreeDataGraph &vtree_data_gr
   return std::unique_ptr<Action>(action);
 }
 
+static std::unique_ptr<Action> ACTION_change_size(VTreeDataGraph &vtree_data_graph,
+                                                  VirtualSocket *execute_vsocket)
+{
+  VirtualNode *vnode = execute_vsocket->vnode();
+
+  auto fn_or_error = create_particle_function(vnode, vtree_data_graph);
+  if (fn_or_error.is_error()) {
+    return {};
+  }
+  std::unique_ptr<ParticleFunction> compute_inputs_fn = fn_or_error.extract_value();
+
+  Action *action = new ChangeSizeAction(std::move(compute_inputs_fn));
+  return std::unique_ptr<Action>(action);
+}
+
 BLI_LAZY_INIT_STATIC(StringMap<ActionParserCallback>, get_action_parsers)
 {
   StringMap<ActionParserCallback> map;
@@ -175,6 +190,7 @@ BLI_LAZY_INIT_STATIC(StringMap<ActionParserCallback>, get_action_parsers)
   map.add_new("bp_ExplodeParticleNode", ACTION_explode);
   map.add_new("bp_ParticleConditionNode", ACTION_condition);
   map.add_new("bp_ChangeParticleColorNode", ACTION_change_color);
+  map.add_new("bp_ChangeParticleSizeNode", ACTION_change_size);
   return map;
 }



More information about the Bf-blender-cvs mailing list