[Bf-blender-cvs] [e468ca977e6] functions: use particle function in trails node
Jacques Lucke
noreply at git.blender.org
Wed Jul 24 19:11:59 CEST 2019
Commit: e468ca977e683aac8c30ed774029ced58c60a36d
Author: Jacques Lucke
Date: Wed Jul 24 15:25:43 2019 +0200
Branches: functions
https://developer.blender.org/rBe468ca977e683aac8c30ed774029ced58c60a36d
use particle function in trails node
===================================================================
M source/blender/simulations/bparticles/inserters.cpp
M source/blender/simulations/bparticles/offset_handlers.cpp
M source/blender/simulations/bparticles/offset_handlers.hpp
M source/blender/simulations/bparticles/particle_function.cpp
M source/blender/simulations/bparticles/particle_function.hpp
M source/blender/simulations/bparticles/step_description_interfaces.hpp
===================================================================
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index d75872d605a..23bc0c54ccb 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -86,23 +86,6 @@ static ValueOrError<SharedFunction> create_function__event_inputs(VirtualNode *e
return fn;
}
-static ValueOrError<SharedFunction> create_function__offset_handler_inputs(
- VirtualNode *offset_handler_vnode, VTreeDataGraph &data_graph)
-{
- Vector<DFGraphSocket> sockets_to_compute = find_input_data_sockets(offset_handler_vnode,
- data_graph);
- auto dependencies = data_graph.find_placeholder_dependencies(sockets_to_compute);
-
- if (dependencies.size() > 0) {
- return BLI_ERROR_CREATE("Offset handler inputs cannot have dependencies currently.");
- }
-
- FunctionGraph fgraph(data_graph.graph(), {}, sockets_to_compute);
- SharedFunction fn = fgraph.new_function(offset_handler_vnode->name());
- FN::fgraph_add_TupleCallBody(fn, fgraph);
- return fn;
-}
-
static ValueOrError<SharedFunction> create_function__action_inputs(VirtualNode *action_vnode,
VTreeDataGraph &data_graph)
{
@@ -138,6 +121,12 @@ static ValueOrError<SharedFunction> create_function__action_inputs(VirtualNode *
return fn;
}
+static ValueOrError<SharedFunction> create_function__offset_handler_inputs(
+ VirtualNode *offset_handler_vnode, VTreeDataGraph &data_graph)
+{
+ return create_function__action_inputs(offset_handler_vnode, data_graph);
+}
+
static std::unique_ptr<Action> build_action(BuildContext &ctx,
VirtualSocket *start,
VirtualSocket *trigger);
@@ -503,14 +492,9 @@ static std::unique_ptr<OffsetHandler> BUILD_OFFSET_HANDLER_trails(BuildContext &
}
SharedFunction fn = fn_or_error.extract_value();
- TupleCallBody *body = fn->body<TupleCallBody>();
- FN_TUPLE_CALL_ALLOC_TUPLES(body, fn_in, fn_out);
- body->call__setup_execution_context(fn_in, fn_out);
- float rate = body->get_output<float>(fn_out, 0, "Rate");
- rate = std::max(rate, 0.0f);
if (ctx.type_name_exists(name)) {
- return std::unique_ptr<OffsetHandler>(new CreateTrailHandler(name, rate));
+ return std::unique_ptr<OffsetHandler>(new CreateTrailHandler(name, ParticleFunction(fn)));
}
else {
return {};
diff --git a/source/blender/simulations/bparticles/offset_handlers.cpp b/source/blender/simulations/bparticles/offset_handlers.cpp
index e79c710b33f..bceb8b88b41 100644
--- a/source/blender/simulations/bparticles/offset_handlers.cpp
+++ b/source/blender/simulations/bparticles/offset_handlers.cpp
@@ -4,19 +4,18 @@ namespace BParticles {
void CreateTrailHandler::execute(OffsetHandlerInterface &interface)
{
- if (m_rate <= 0.0f) {
- return;
- }
-
ParticleSet particles = interface.particles();
auto positions = particles.attributes().get_float3("Position");
auto position_offsets = interface.offsets().get_float3("Position");
- float frequency = 1.0f / m_rate;
+ auto caller = m_compute_inputs.get_caller(interface);
+ auto rates = caller.add_output<float>();
+ caller.call(particles.pindices());
Vector<float3> new_positions;
Vector<float> new_birth_times;
for (uint pindex : particles.pindices()) {
+ float frequency = 1.0f / rates[pindex];
float time_factor = interface.time_factors()[pindex];
TimeSpan time_span = interface.time_span(pindex);
float current_time = frequency * (std::floor(time_span.start() / frequency) + 1.0f);
diff --git a/source/blender/simulations/bparticles/offset_handlers.hpp b/source/blender/simulations/bparticles/offset_handlers.hpp
index 2ec28a65796..932bc9703b7 100644
--- a/source/blender/simulations/bparticles/offset_handlers.hpp
+++ b/source/blender/simulations/bparticles/offset_handlers.hpp
@@ -1,17 +1,19 @@
#pragma once
#include "step_description.hpp"
+#include "particle_function.hpp"
namespace BParticles {
class CreateTrailHandler : public OffsetHandler {
private:
std::string m_particle_type_name;
- float m_rate;
+ ParticleFunction m_compute_inputs;
public:
- CreateTrailHandler(StringRef particle_type_name, float rate)
- : m_particle_type_name(particle_type_name.to_std_string()), m_rate(rate)
+ CreateTrailHandler(StringRef particle_type_name, ParticleFunction compute_inputs)
+ : m_particle_type_name(particle_type_name.to_std_string()),
+ m_compute_inputs(std::move(compute_inputs))
{
}
diff --git a/source/blender/simulations/bparticles/particle_function.cpp b/source/blender/simulations/bparticles/particle_function.cpp
index aec56857fe3..a0d9c3aedce 100644
--- a/source/blender/simulations/bparticles/particle_function.cpp
+++ b/source/blender/simulations/bparticles/particle_function.cpp
@@ -9,6 +9,14 @@ ParticleFunctionCaller ParticleFunction::get_caller(ActionInterface &action_inte
&action_interface.context());
}
+ParticleFunctionCaller ParticleFunction::get_caller(
+ OffsetHandlerInterface &offset_handler_interface)
+{
+ return this->get_caller(offset_handler_interface.array_allocator(),
+ offset_handler_interface.particles().attributes(),
+ nullptr);
+}
+
ParticleFunctionCaller ParticleFunction::get_caller(ArrayAllocator &array_allocator,
AttributeArrays attributes,
ActionContext *action_context)
diff --git a/source/blender/simulations/bparticles/particle_function.hpp b/source/blender/simulations/bparticles/particle_function.hpp
index 8e11533385b..4a108b9b491 100644
--- a/source/blender/simulations/bparticles/particle_function.hpp
+++ b/source/blender/simulations/bparticles/particle_function.hpp
@@ -90,6 +90,7 @@ class ParticleFunction {
}
ParticleFunctionCaller get_caller(ActionInterface &action_interface);
+ ParticleFunctionCaller get_caller(OffsetHandlerInterface &offset_handler_interface);
private:
ParticleFunctionCaller get_caller(ArrayAllocator &array_allocator,
diff --git a/source/blender/simulations/bparticles/step_description_interfaces.hpp b/source/blender/simulations/bparticles/step_description_interfaces.hpp
index b877a1c89ca..c61130b4d40 100644
--- a/source/blender/simulations/bparticles/step_description_interfaces.hpp
+++ b/source/blender/simulations/bparticles/step_description_interfaces.hpp
@@ -241,6 +241,7 @@ class OffsetHandlerInterface {
float step_end_time();
ArrayRef<float> durations();
TimeSpan time_span(uint pindex);
+ ArrayAllocator &array_allocator();
};
/* EmitterInterface inline functions
@@ -445,4 +446,9 @@ inline TimeSpan OffsetHandlerInterface::time_span(uint pindex)
return TimeSpan(m_step_data.step_end_time - duration, duration);
}
+inline ArrayAllocator &OffsetHandlerInterface::array_allocator()
+{
+ return m_step_data.array_allocator;
+}
+
}; // namespace BParticles
More information about the Bf-blender-cvs
mailing list