[Bf-blender-cvs] [d537af93038] functions: execute action for new particles after explosion
Jacques Lucke
noreply at git.blender.org
Fri Aug 2 19:14:55 CEST 2019
Commit: d537af93038922ec895da4fdf86dcda54302f6f4
Author: Jacques Lucke
Date: Fri Aug 2 13:43:56 2019 +0200
Branches: functions
https://developer.blender.org/rBd537af93038922ec895da4fdf86dcda54302f6f4
execute action for new particles after explosion
===================================================================
M release/scripts/startup/nodes/bparticle_nodes/explode_particle.py
M source/blender/simulations/bparticles/action_interface.hpp
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/actions.hpp
M source/blender/simulations/bparticles/inserters.cpp
===================================================================
diff --git a/release/scripts/startup/nodes/bparticle_nodes/explode_particle.py b/release/scripts/startup/nodes/bparticle_nodes/explode_particle.py
index c8238b7bc98..da35660aa8d 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/explode_particle.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/explode_particle.py
@@ -14,6 +14,7 @@ class ExplodeParticleNode(bpy.types.Node, BParticlesNode):
builder.fixed_input("amount", "Amount", "Integer", default=10)
builder.fixed_input("speed", "Speed", "Float", default=2)
builder.control_flow_output("control_out", "(Out)")
+ builder.control_flow_output("new_control_out", "On Birth")
def draw(self, layout):
row = layout.row(align=True)
diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index cebe829740b..98daf770b2a 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -59,6 +59,7 @@ class Action {
void execute_from_event(EventExecuteInterface &event_interface,
ActionContext *action_context = nullptr);
void execute_for_subset(ArrayRef<uint> pindices, ActionInterface &action_interface);
+ void execute_for_new_particles(ParticleSets &particle_sets, ActionInterface &action_interface);
};
/* ActionInterface inline functions
@@ -139,6 +140,30 @@ inline void Action::execute_for_subset(ArrayRef<uint> pindices, ActionInterface
this->execute(sub_interface);
}
+inline void Action::execute_for_new_particles(ParticleSets &particle_sets,
+ ActionInterface &action_interface)
+{
+ AttributesInfo info;
+ AttributeArraysCore offsets_core(info, {}, 0);
+ AttributeArrays offsets = offsets_core.slice_all();
+
+ /* Use empty action context, until there a better solution is implemented. */
+ EmptyEventInfo empty_context;
+
+ for (ParticleSet particles : particle_sets.sets()) {
+ ArrayAllocator::Array<float> durations(action_interface.array_allocator());
+ ArrayRef<float>(durations).fill_indices(particles.pindices(), 0);
+ ActionInterface new_interface(action_interface.particle_allocator(),
+ action_interface.array_allocator(),
+ particles,
+ offsets,
+ particles.attributes().get<float>("Birth Time"),
+ durations,
+ empty_context);
+ this->execute(new_interface);
+ }
+}
+
inline ActionContext &ActionInterface::context()
{
return m_action_context;
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index a898f50cf96..35b52520b69 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -98,6 +98,7 @@ void ExplodeAction::execute(ActionInterface &interface)
new_particles.set<float>("Birth Time", new_birth_times);
m_post_action->execute(interface);
+ m_new_particle_action->execute_for_new_particles(new_particles, interface);
}
void ConditionAction::execute(ActionInterface &interface)
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index 8ac5081915f..31c4ecc3ce4 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -48,14 +48,17 @@ class ExplodeAction : public Action {
std::string m_new_particle_name;
std::unique_ptr<ParticleFunction> m_compute_inputs;
std::unique_ptr<Action> m_post_action;
+ std::unique_ptr<Action> m_new_particle_action;
public:
ExplodeAction(StringRef new_particle_name,
std::unique_ptr<ParticleFunction> compute_inputs,
- std::unique_ptr<Action> post_action)
+ std::unique_ptr<Action> post_action,
+ std::unique_ptr<Action> new_particle_action)
: m_new_particle_name(new_particle_name.to_std_string()),
m_compute_inputs(std::move(compute_inputs)),
- m_post_action(std::move(post_action))
+ m_post_action(std::move(post_action)),
+ m_new_particle_action(std::move(new_particle_action))
{
}
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index f6f6405b28b..47c09935eb4 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -100,10 +100,13 @@ static std::unique_ptr<Action> BUILD_ACTION_explode(
RNA_string_get(&rna, "particle_type_name", name);
auto post_action = build_action(ctx, vnode->output(0), trigger);
+ auto new_particles_action = build_action(ctx, vnode->output(1), trigger);
if (ctx.type_name_exists(name)) {
- return std::unique_ptr<Action>(
- new ExplodeAction(name, std::move(compute_inputs_fn), std::move(post_action)));
+ return std::unique_ptr<Action>(new ExplodeAction(name,
+ std::move(compute_inputs_fn),
+ std::move(post_action),
+ std::move(new_particles_action)));
}
else {
return post_action;
More information about the Bf-blender-cvs
mailing list