[Bf-blender-cvs] [05969e5418f] functions: initial curve emitter

Jacques Lucke noreply at git.blender.org
Wed Jun 19 13:27:40 CEST 2019


Commit: 05969e5418f7723215e3be20e38808b31bcb42c0
Author: Jacques Lucke
Date:   Wed Jun 19 12:24:20 2019 +0200
Branches: functions
https://developer.blender.org/rB05969e5418f7723215e3be20e38808b31bcb42c0

initial curve emitter

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

M	source/blender/blenlib/BLI_math.hpp
M	source/blender/modifiers/intern/MOD_nodeparticles.c
M	source/blender/simulations/BParticles.h
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/emitters.hpp

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

diff --git a/source/blender/blenlib/BLI_math.hpp b/source/blender/blenlib/BLI_math.hpp
index 7cbd353c4c2..42a4b84a587 100644
--- a/source/blender/blenlib/BLI_math.hpp
+++ b/source/blender/blenlib/BLI_math.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "BLI_math_matrix.h"
+
 namespace BLI {
 
 struct float3 {
@@ -54,4 +56,28 @@ struct float3 {
   }
 };
 
+struct float4x4 {
+  float v[4][4];
+
+  float4x4(float *matrix)
+  {
+    memcpy(v, matrix, sizeof(float) * 16);
+  }
+
+  float4x4(float matrix[4][4]) : float4x4((float *)matrix)
+  {
+  }
+
+  operator float *()
+  {
+    return (float *)this;
+  }
+
+  float3 transform_position(float3 position)
+  {
+    mul_m4_v3((float(*)[4])this, position);
+    return position;
+  }
+};
+
 }  // namespace BLI
diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c
index 1d50bbb903c..0589297b140 100644
--- a/source/blender/modifiers/intern/MOD_nodeparticles.c
+++ b/source/blender/modifiers/intern/MOD_nodeparticles.c
@@ -62,18 +62,11 @@ static RuntimeData *get_runtime_data(NodeParticlesModifierData *npmd)
   return data;
 }
 
-static BParticlesDescription create_current_description(Object *self,
+static BParticlesDescription create_current_description(Object *UNUSED(self),
                                                         NodeParticlesModifierData *npmd,
-                                                        Depsgraph *depsgraph)
+                                                        Depsgraph *UNUSED(depsgraph))
 {
-  float position[3] = {0, 0, 0};
-  if (npmd->emitter_object != NULL) {
-    Object *emitter_eval = DEG_get_evaluated_object(depsgraph, npmd->emitter_object);
-    copy_v3_v3(position, emitter_eval->loc);
-  }
-  mul_m4_v3(self->imat, position);
-  return BParticles_playground_description(
-      npmd->control1, npmd->control2, position, (Mesh *)self->data);
+  return BParticles_playground_description(npmd->control1, npmd->control2, npmd->emitter_object);
 }
 
 static void ensure_runtime_data(Object *self,
@@ -193,7 +186,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
   NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md;
   if (npmd->emitter_object) {
     DEG_add_object_relation(
-        ctx->node, npmd->emitter_object, DEG_OB_COMP_TRANSFORM, "Node Particles Modifier");
+        ctx->node, npmd->emitter_object, DEG_OB_COMP_GEOMETRY, "Node Particles Modifier");
   }
 }
 
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 0212990a6b5..5fdc78a4b52 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -8,7 +8,7 @@
 extern "C" {
 #endif
 
-struct Mesh;
+struct Object;
 
 typedef struct OpaqueBParticlesDescription *BParticlesDescription;
 typedef struct OpaqueBParticlesSolver *BParticlesSolver;
@@ -16,8 +16,7 @@ typedef struct OpaqueBParticlesState *BParticlesState;
 
 BParticlesDescription BParticles_playground_description(float control1,
                                                         float control2,
-                                                        float *emitter_position,
-                                                        struct Mesh *mesh);
+                                                        struct Object *object);
 void BParticles_description_free(BParticlesDescription description);
 
 BParticlesSolver BParticles_solver_build(BParticlesDescription description);
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 9009f2b05e2..1df8dd8c89b 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -6,6 +6,12 @@
 #include "forces.hpp"
 
 #include "BLI_timeit.hpp"
+#include "BLI_listbase.h"
+
+#include "BKE_curve.h"
+
+#include "DNA_object_types.h"
+#include "DNA_curve_types.h"
 
 #define WRAPPERS(T1, T2) \
   inline T1 unwrap(T2 value) \
@@ -20,6 +26,7 @@
 using BParticles::AttributeArrays;
 using BParticles::AttributeType;
 using BParticles::Description;
+using BParticles::Emitter;
 using BParticles::EmitterHelper;
 using BParticles::EmitterInfoBuilder;
 using BParticles::EmitterTarget;
@@ -39,16 +46,31 @@ WRAPPERS(BParticles::WrappedState *, BParticlesState);
 
 BParticlesDescription BParticles_playground_description(float control1,
                                                         float control2,
-                                                        float *emitter_position,
-                                                        struct Mesh *mesh)
+                                                        Object *object)
 {
+  if (object == NULL) {
+    return wrap(new Description({}, {BParticles::EMITTER_point({1, 1, 1}).release()}));
+  }
+
   auto force = BParticles::FORCE_directional({0.0, 0.0, control1});
 
-  auto emitter1 = BParticles::EMITTER_point(emitter_position);
-  auto emitter2 = BParticles::EMITTER_mesh_surface(mesh, control2);
+  std::unique_ptr<Emitter> emitter;
+
+  ID *object_data = (ID *)object->data;
+  ID_Type type = GS(object_data->name);
+  if (type == ID_ME) {
+    emitter = BParticles::EMITTER_mesh_surface((Mesh *)object_data, control2);
+  }
+  else if (type == ID_CU) {
+    Path *path = object->runtime.curve_cache->path;
+    BLI_assert(path);
+    emitter = BParticles::EMITTER_path(path, object->obmat);
+  }
+  else {
+    BLI_assert(false);
+  }
 
-  Description *description = new Description({force.release()},
-                                             {emitter1.release(), emitter2.release()});
+  Description *description = new Description({force.release()}, {emitter.release()});
   return wrap(description);
 }
 void BParticles_description_free(BParticlesDescription description_c)
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index ee0fe022d94..4786f4947bf 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -23,6 +23,7 @@ class EmitterInfoBuilder;
 
 using BLI::ArrayRef;
 using BLI::float3;
+using BLI::float4x4;
 using BLI::SmallSetVector;
 using BLI::SmallVector;
 using BLI::StringRef;
diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index 6b7292ccbaf..1c64f6f90a6 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -1,7 +1,12 @@
 #include "emitters.hpp"
+
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_curve_types.h"
+
+#include "BKE_curve.h"
 #include "BKE_mesh_runtime.h"
+
 #include "BLI_math_geom.h"
 
 namespace BParticles {
@@ -81,6 +86,43 @@ class SurfaceEmitter : public Emitter {
   }
 };
 
+class PathEmitter : public Emitter {
+ private:
+  Path &m_path;
+  float4x4 m_transform;
+
+ public:
+  PathEmitter(Path &path, float4x4 transform) : m_path(path), m_transform(transform)
+  {
+  }
+
+  void info(EmitterInfoBuilder &builder) const override
+  {
+    builder.inits_attribute("Position", AttributeType::Float3);
+    builder.inits_attribute("Velocity", AttributeType::Float3);
+  }
+
+  void emit(EmitterHelper helper) override
+  {
+    SmallVector<float3> positions;
+    for (uint i = 0; i < m_path.len - 1; i++) {
+      float3 pos1 = m_path.data[i].vec;
+      float3 pos2 = m_path.data[i + 1].vec;
+
+      for (uint j = 0; j < 100; j++) {
+        float factor = (float)j / 100.0f;
+        float3 pos = pos1 * (1.0f - factor) + pos2 * factor;
+        pos = m_transform.transform_position(pos);
+        positions.append(pos);
+      }
+    }
+
+    auto target = helper.request(positions.size());
+    target.set_float3("Position", positions);
+    target.set_float3("Velocity", SmallVector<float3>(positions.size()));
+  }
+};
+
 std::unique_ptr<Emitter> EMITTER_point(float3 point)
 {
   Emitter *emitter = new PointEmitter(point);
@@ -93,4 +135,11 @@ std::unique_ptr<Emitter> EMITTER_mesh_surface(Mesh *mesh, float normal_velocity)
   return std::unique_ptr<Emitter>(emitter);
 }
 
+std::unique_ptr<Emitter> EMITTER_path(Path *path, float4x4 transform)
+{
+  BLI_assert(path);
+  Emitter *emitter = new PathEmitter(*path, transform);
+  return std::unique_ptr<Emitter>(emitter);
+}
+
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/emitters.hpp b/source/blender/simulations/bparticles/emitters.hpp
index c991a2e6eb4..c848cd7af6f 100644
--- a/source/blender/simulations/bparticles/emitters.hpp
+++ b/source/blender/simulations/bparticles/emitters.hpp
@@ -3,10 +3,12 @@
 #include "core.hpp"
 
 struct Mesh;
+struct Path;
 
 namespace BParticles {
 
 std::unique_ptr<Emitter> EMITTER_point(float3 point);
 std::unique_ptr<Emitter> EMITTER_mesh_surface(struct Mesh *mesh, float normal_velocity);
+std::unique_ptr<Emitter> EMITTER_path(struct Path *path, float4x4 transform);
 
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list