[Bf-blender-cvs] [4faf2de83a6] functions: initial particle action abstraction
Jacques Lucke
noreply at git.blender.org
Mon Jun 10 12:23:37 CEST 2019
Commit: 4faf2de83a66c055f809a66b780200c022c8a949
Author: Jacques Lucke
Date: Mon Jun 10 12:23:15 2019 +0200
Branches: functions
https://developer.blender.org/rB4faf2de83a66c055f809a66b780200c022c8a949
initial particle action abstraction
===================================================================
M source/blender/simulations/bparticles/core.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/playground_solver.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index b08461c9531..51cf9d3bee7 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -32,6 +32,10 @@ Emitter::~Emitter()
{
}
+Action::~Action()
+{
+}
+
void adapt_state(Solver *new_solver, WrappedState *wrapped_state)
{
wrapped_state->m_solver = new_solver;
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index f30dfb904ff..d923140d19a 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -40,6 +40,13 @@ class Force {
virtual void add_force(NamedBuffers &buffers, ArrayRef<float3> dst) = 0;
};
+class Action {
+ public:
+ virtual ~Action();
+
+ virtual void execute(NamedBuffers &buffers, ArrayRef<uint> indices_to_influence) = 0;
+};
+
class EmitterBuffers {
private:
NamedBuffers &m_buffers;
diff --git a/source/blender/simulations/bparticles/playground_solver.cpp b/source/blender/simulations/bparticles/playground_solver.cpp
index d0c741808cb..9428d5a9ef4 100644
--- a/source/blender/simulations/bparticles/playground_solver.cpp
+++ b/source/blender/simulations/bparticles/playground_solver.cpp
@@ -5,6 +5,18 @@
namespace BParticles {
+class MoveUpAction : public BParticles::Action {
+ public:
+ void execute(NamedBuffers &buffers, ArrayRef<uint> indices_to_influence) override
+ {
+ auto positions = buffers.get_float3("Position");
+
+ for (uint i : indices_to_influence) {
+ positions[i].z += 2.0f;
+ }
+ }
+};
+
class SimpleSolver : public Solver {
struct MyState : StateBase {
@@ -81,16 +93,22 @@ class SimpleSolver : public Solver {
new_velocities[i] = velocities[i] + combined_force[i] / mass * elapsed_seconds;
}
+ SmallVector<uint> indices;
+
for (uint i = 0; i < buffers.size(); i++) {
if (positions[i].y <= 2 && new_positions[i].y > 2) {
- new_positions[i].z += 1;
- new_velocities[i].y *= -1;
+ new_positions[i] = (positions[i] + new_positions[i]) * 0.5f;
+ new_velocities[i] = (velocities[i] + new_velocities[i]) * 0.5f;
+ indices.append(i);
}
}
positions.copy_from(new_positions);
velocities.copy_from(new_velocities);
+ MoveUpAction action;
+ action.execute(buffers, indices);
+
auto birth_times = buffers.get_float("Birth Time");
auto kill_states = buffers.get_byte("Kill State");
More information about the Bf-blender-cvs
mailing list