[Bf-blender-cvs] [66c07705f94] functions: Initial Size Over Time node

Jacques Lucke noreply at git.blender.org
Thu Sep 5 19:12:07 CEST 2019


Commit: 66c07705f9481fe1abf3020b4135fa5d5f5aca2d
Author: Jacques Lucke
Date:   Thu Sep 5 16:58:35 2019 +0200
Branches: functions
https://developer.blender.org/rB66c07705f9481fe1abf3020b4135fa5d5f5aca2d

Initial Size Over Time node

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

A	release/scripts/startup/nodes/bparticle_nodes/size_over_time.py
M	source/blender/simulations/bparticles/node_frontend.cpp
M	source/blender/simulations/bparticles/offset_handlers.cpp
M	source/blender/simulations/bparticles/offset_handlers.hpp

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

diff --git a/release/scripts/startup/nodes/bparticle_nodes/size_over_time.py b/release/scripts/startup/nodes/bparticle_nodes/size_over_time.py
new file mode 100644
index 00000000000..9be5b8d4241
--- /dev/null
+++ b/release/scripts/startup/nodes/bparticle_nodes/size_over_time.py
@@ -0,0 +1,13 @@
+import bpy
+from bpy.props import *
+from .. base import BParticlesNode
+from .. node_builder import NodeBuilder
+
+class SizeOverTimeNode(bpy.types.Node, BParticlesNode):
+    bl_idname = "bp_SizeOverTimeNode"
+    bl_label = "Size Over Time"
+
+    def declaration(self, builder: NodeBuilder):
+        builder.fixed_input("final_size", "Final Size", "Float", default=0.0)
+        builder.fixed_input("final_age", "Final Age", "Float", default=3)
+        builder.particle_effector_output("type", "Type")
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 45cfd7d7c08..05b5b070697 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -455,6 +455,24 @@ static void PARSE_mesh_collision(BehaviorCollector &collector,
   }
 }
 
+static void PARSE_size_over_time(BehaviorCollector &collector,
+                                 VTreeDataGraph &vtree_data_graph,
+                                 WorldTransition &UNUSED(world_transition),
+                                 VirtualNode *vnode)
+{
+  Vector<std::string> type_names = find_connected_particle_type_names(vnode->output(0, "Type"));
+  for (std::string &type_name : type_names) {
+    auto fn_or_error = create_particle_function(vnode, vtree_data_graph);
+    if (fn_or_error.is_error()) {
+      continue;
+    }
+    std::unique_ptr<ParticleFunction> compute_inputs = fn_or_error.extract_value();
+
+    OffsetHandler *handler = new SizeOverTimeHandler(std::move(compute_inputs));
+    collector.m_offset_handlers.add(type_name, handler);
+  }
+}
+
 BLI_LAZY_INIT_STATIC(StringMap<ParseNodeCallback>, get_node_parsers)
 {
   StringMap<ParseNodeCallback> map;
@@ -466,6 +484,7 @@ BLI_LAZY_INIT_STATIC(StringMap<ParseNodeCallback>, get_node_parsers)
   map.add_new("bp_InitialGridEmitterNode", PARSE_initial_grid_emitter);
   map.add_new("bp_TurbulenceForceNode", PARSE_turbulence_force);
   map.add_new("bp_MeshCollisionEventNode", PARSE_mesh_collision);
+  map.add_new("bp_SizeOverTimeNode", PARSE_size_over_time);
   return map;
 }
 
diff --git a/source/blender/simulations/bparticles/offset_handlers.cpp b/source/blender/simulations/bparticles/offset_handlers.cpp
index 07f753317d1..1c8d8c75390 100644
--- a/source/blender/simulations/bparticles/offset_handlers.cpp
+++ b/source/blender/simulations/bparticles/offset_handlers.cpp
@@ -39,4 +39,28 @@ void CreateTrailHandler::execute(OffsetHandlerInterface &interface)
   }
 }
 
+void SizeOverTimeHandler::execute(OffsetHandlerInterface &interface)
+{
+  auto birth_times = interface.attributes().get<float>("Birth Time");
+  auto sizes = interface.attributes().get<float>("Size");
+
+  auto inputs = m_compute_inputs->compute(interface);
+
+  for (uint pindex : interface.pindices()) {
+    float final_size = inputs->get<float>("Final Size", 0, pindex);
+    float final_age = inputs->get<float>("Final Age", 1, pindex);
+
+    TimeSpan time_span = interface.time_span(pindex);
+    float age = time_span.start() - birth_times[pindex];
+    float time_until_end = final_age - age;
+    if (time_until_end <= 0.0f) {
+      continue;
+    }
+
+    float factor = std::min(time_span.duration() / time_until_end, 1.0f);
+    float new_size = final_size * factor + sizes[pindex] * (1.0f - factor);
+    sizes[pindex] = new_size;
+  }
+}
+
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/offset_handlers.hpp b/source/blender/simulations/bparticles/offset_handlers.hpp
index 3876ba90407..d59e3f61493 100644
--- a/source/blender/simulations/bparticles/offset_handlers.hpp
+++ b/source/blender/simulations/bparticles/offset_handlers.hpp
@@ -24,4 +24,17 @@ class CreateTrailHandler : public OffsetHandler {
   void execute(OffsetHandlerInterface &interface) override;
 };
 
+class SizeOverTimeHandler : public OffsetHandler {
+ private:
+  std::unique_ptr<ParticleFunction> m_compute_inputs;
+
+ public:
+  SizeOverTimeHandler(std::unique_ptr<ParticleFunction> compute_inputs)
+      : m_compute_inputs(std::move(compute_inputs))
+  {
+  }
+
+  void execute(OffsetHandlerInterface &interface) override;
+};
+
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list