[Bf-blender-cvs] [d2e050e5e12] functions: experimental explode action

Jacques Lucke noreply at git.blender.org
Fri Jun 28 12:56:27 CEST 2019


Commit: d2e050e5e12e9f159487a915013698cbfdcbde00
Author: Jacques Lucke
Date:   Fri Jun 28 12:50:16 2019 +0200
Branches: functions
https://developer.blender.org/rBd2e050e5e12e9f159487a915013698cbfdcbde00

experimental explode action

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

M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/actions.hpp
M	source/blender/simulations/bparticles/c_wrapper.cpp

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

diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 35b63691f29..d432fa218b1 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -59,6 +59,45 @@ class SpawnAction : public Action {
   }
 };
 
+static float3 random_direction()
+{
+  return float3(
+      (rand() % 1000 - 500) / 500.f, (rand() % 1000 - 500) / 500.f, (rand() % 1000 - 500) / 500.f);
+}
+
+class ExplodeAction : public Action {
+  void execute(ActionInterface &interface) override
+  {
+    ParticleSet &particles = interface.particles();
+
+    auto positions = particles.attributes().get_float3("Position");
+    auto kill_states = particles.attributes().get_byte("Kill State");
+    auto current_times = interface.current_times();
+
+    SmallVector<float3> new_positions;
+    SmallVector<float3> new_velocities;
+    SmallVector<float> new_birth_times;
+
+    uint parts_amount = 100;
+
+    for (uint i : particles.range()) {
+      uint pindex = particles.get_particle_index(i);
+
+      kill_states[pindex] = 1;
+      new_positions.append_n_times(positions[pindex], parts_amount);
+      new_birth_times.append_n_times(current_times[i], parts_amount);
+      for (uint j = 0; j < parts_amount; j++) {
+        new_velocities.append(random_direction() * 4);
+      }
+    }
+
+    auto &target = interface.request_emit_target(1, new_positions.size());
+    target.set_float3("Position", new_positions);
+    target.set_float3("Velocity", new_velocities);
+    target.set_float("Birth Time", new_birth_times);
+  }
+};
+
 std::unique_ptr<Action> ACTION_kill()
 {
   Action *action = new KillAction();
@@ -77,4 +116,10 @@ std::unique_ptr<Action> ACTION_spawn()
   return std::unique_ptr<Action>(action);
 }
 
+std::unique_ptr<Action> ACTION_explode()
+{
+  Action *action = new ExplodeAction();
+  return std::unique_ptr<Action>(action);
+}
+
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index 4e31d7c192e..c628dd9c904 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -7,5 +7,6 @@ namespace BParticles {
 std::unique_ptr<Action> ACTION_kill();
 std::unique_ptr<Action> ACTION_move(float3 offset);
 std::unique_ptr<Action> ACTION_spawn();
+std::unique_ptr<Action> ACTION_explode();
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 4350118f99f..54958b7b7da 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -142,10 +142,6 @@ void BParticles_simulate_modifier(NodeParticlesModifierData *npmd,
         EMITTER_mesh_surface(
             0, (Mesh *)npmd->emitter_object->data, npmd->emitter_object->obmat, npmd->control1)
             .release());
-    description.m_emitters.append(
-        EMITTER_mesh_surface(
-            1, (Mesh *)npmd->emitter_object->data, npmd->emitter_object->obmat, npmd->control1)
-            .release());
   }
   BVHTreeFromMesh treedata = {0};
   if (npmd->collision_object) {
@@ -153,15 +149,14 @@ void BParticles_simulate_modifier(NodeParticlesModifierData *npmd,
         &treedata, (Mesh *)npmd->collision_object->data, BVHTREE_FROM_LOOPTRI, 4);
     type0->m_events.append(
         EVENT_mesh_collection(&treedata, npmd->collision_object->obmat).release());
-    type0->m_actions.append(ACTION_kill().release());
+    type0->m_actions.append(ACTION_explode().release());
+    type0->m_forces.append(FORCE_directional({0, 0, -2}).release());
   }
-  type0->m_forces.append(FORCE_directional({0, 0, -2}).release());
-  type0->m_events.append(EVENT_age_reached(3.0f).release());
-  type0->m_actions.append(ACTION_spawn().release());
 
   auto *type1 = new ModifierParticleType();
   description.m_types.add_new(1, type1);
-  type1->m_forces.append(FORCE_directional({0, 0, 1}).release());
+  type1->m_events.append(EVENT_age_reached(0.3f).release());
+  type1->m_actions.append(ACTION_kill().release());
 
   simulate_step(state, description);



More information about the Bf-blender-cvs mailing list