[Bf-blender-cvs] [125ff9f320c] functions: initial mesh surface emitter

Jacques Lucke noreply at git.blender.org
Mon Jun 17 15:52:46 CEST 2019


Commit: 125ff9f320c9fbad50abbadadac6e3932c4d4c71
Author: Jacques Lucke
Date:   Mon Jun 17 12:16:41 2019 +0200
Branches: functions
https://developer.blender.org/rB125ff9f320c9fbad50abbadadac6e3932c4d4c71

initial mesh surface emitter

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

M	source/blender/blenkernel/BKE_mesh_runtime.h
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/emitter.cpp
M	source/blender/simulations/bparticles/emitter.hpp

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

diff --git a/source/blender/blenkernel/BKE_mesh_runtime.h b/source/blender/blenkernel/BKE_mesh_runtime.h
index 93d952bcae5..41c9f692861 100644
--- a/source/blender/blenkernel/BKE_mesh_runtime.h
+++ b/source/blender/blenkernel/BKE_mesh_runtime.h
@@ -39,6 +39,10 @@ struct Mesh;
 struct Object;
 struct Scene;
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void BKE_mesh_runtime_reset(struct Mesh *mesh);
 void BKE_mesh_runtime_reset_on_copy(struct Mesh *mesh, const int flag);
 int BKE_mesh_runtime_looptri_len(const struct Mesh *mesh);
@@ -104,4 +108,8 @@ void BKE_mesh_runtime_debug_print_cdlayers(struct CustomData *data);
 bool BKE_mesh_runtime_is_valid(struct Mesh *me_eval);
 #endif /* NDEBUG */
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __BKE_MESH_RUNTIME_H__ */
diff --git a/source/blender/blenlib/BLI_math.hpp b/source/blender/blenlib/BLI_math.hpp
index 9f9ab6d405e..b54aaf4dfa9 100644
--- a/source/blender/blenlib/BLI_math.hpp
+++ b/source/blender/blenlib/BLI_math.hpp
@@ -7,7 +7,7 @@ struct float3 {
 
   float3() = default;
 
-  float3(float *value) : x{value[0]}, y{value[1]}, z{value[2]}
+  float3(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]}
   {
   }
 
@@ -15,6 +15,11 @@ struct float3 {
   {
   }
 
+  operator float *()
+  {
+    return (float *)this;
+  }
+
   friend float3 operator+(float3 a, float3 b)
   {
     return {a.x + b.x, a.y + b.y, a.z + b.z};
diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c
index 013e755c0aa..1d50bbb903c 100644
--- a/source/blender/modifiers/intern/MOD_nodeparticles.c
+++ b/source/blender/modifiers/intern/MOD_nodeparticles.c
@@ -72,7 +72,8 @@ static BParticlesDescription create_current_description(Object *self,
     copy_v3_v3(position, emitter_eval->loc);
   }
   mul_m4_v3(self->imat, position);
-  return BParticles_playground_description(npmd->control1, npmd->control2, position);
+  return BParticles_playground_description(
+      npmd->control1, npmd->control2, position, (Mesh *)self->data);
 }
 
 static void ensure_runtime_data(Object *self,
@@ -199,15 +200,13 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
 static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
 {
   NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md;
-
   walk(userData, ob, &npmd->emitter_object, IDWALK_CB_NOP);
 }
 
-static void foreachIDLink(ModifierData *UNUSED(md),
-                          Object *UNUSED(ob),
-                          IDWalkFunc UNUSED(walk),
-                          void *UNUSED(userData))
+static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
 {
+  NodeParticlesModifierData *npmd = (NodeParticlesModifierData *)md;
+  walk(userData, ob, (ID **)&npmd->emitter_object, IDWALK_CB_NOP);
 }
 
 ModifierTypeInfo modifierType_NodeParticles = {
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 2a76f770bbb..0212990a6b5 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -8,13 +8,16 @@
 extern "C" {
 #endif
 
+struct Mesh;
+
 typedef struct OpaqueBParticlesDescription *BParticlesDescription;
 typedef struct OpaqueBParticlesSolver *BParticlesSolver;
 typedef struct OpaqueBParticlesState *BParticlesState;
 
 BParticlesDescription BParticles_playground_description(float control1,
                                                         float control2,
-                                                        float *emitter_position);
+                                                        float *emitter_position,
+                                                        struct Mesh *mesh);
 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 f4531f035fa..0eaebf01d92 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -96,12 +96,15 @@ class TestEmitter : public BParticles::Emitter {
 
 BParticlesDescription BParticles_playground_description(float control1,
                                                         float control2,
-                                                        float *emitter_position)
+                                                        float *emitter_position,
+                                                        struct Mesh *mesh)
 {
-  auto emitter = BParticles::new_point_emitter(emitter_position);
+  auto emitter1 = BParticles::new_point_emitter(emitter_position);
+  auto emitter2 = BParticles::new_surface_emitter(mesh);
 
   Description *description = new Description(
-      {new TestForce(control1), new TurbulenceForce(control2)}, {emitter.release()});
+      {new TestForce(control1), new TurbulenceForce(control2)},
+      {emitter1.release(), emitter2.release()});
   return wrap(description);
 }
 void BParticles_description_free(BParticlesDescription description_c)
diff --git a/source/blender/simulations/bparticles/emitter.cpp b/source/blender/simulations/bparticles/emitter.cpp
index b9eef730d53..2ee6e8f9c03 100644
--- a/source/blender/simulations/bparticles/emitter.cpp
+++ b/source/blender/simulations/bparticles/emitter.cpp
@@ -1,6 +1,8 @@
 #include "emitter.hpp"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "BKE_mesh_runtime.h"
+#include "BLI_math_geom.h"
 
 namespace BParticles {
 
@@ -31,10 +33,60 @@ class PointEmitter : public Emitter {
   }
 };
 
+class SurfaceEmitter : public Emitter {
+ private:
+  Mesh *m_mesh;
+
+ public:
+  SurfaceEmitter(Mesh *mesh) : m_mesh(mesh)
+  {
+  }
+
+  void info(EmitterInfoBuilder &builder) const override
+  {
+    builder.inits_float3_attribute("Position");
+    builder.inits_float3_attribute("Velocity");
+  }
+
+  void emit(RequestEmitterBufferCB request_buffers) override
+  {
+    MLoop *loops = m_mesh->mloop;
+    MVert *verts = m_mesh->mvert;
+    const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(m_mesh);
+    int triangle_amount = BKE_mesh_runtime_looptri_len(m_mesh);
+
+    for (int i = 0; i < triangle_amount; i++) {
+      auto &buffer = request_buffers();
+      auto positions = buffer.buffers().get_float3("Position");
+      auto velocities = buffer.buffers().get_float3("Velocity");
+
+      MLoopTri triangle = triangles[i];
+
+      float3 v1 = verts[loops[triangle.tri[0]].v].co;
+      float3 v2 = verts[loops[triangle.tri[1]].v].co;
+      float3 v3 = verts[loops[triangle.tri[2]].v].co;
+
+      float3 normal;
+      normal_tri_v3(normal, v1, v2, v3);
+
+      float3 pos = (v1 + v2 + v3) / 3.0f;
+      positions[0] = pos;
+      velocities[0] = normal;
+      buffer.set_initialized(1);
+    }
+  }
+};
+
 std::unique_ptr<Emitter> new_point_emitter(float3 point)
 {
   Emitter *emitter = new PointEmitter(point);
   return std::unique_ptr<Emitter>(emitter);
 }
 
+std::unique_ptr<Emitter> new_surface_emitter(Mesh *mesh)
+{
+  Emitter *emitter = new SurfaceEmitter(mesh);
+  return std::unique_ptr<Emitter>(emitter);
+}
+
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/emitter.hpp b/source/blender/simulations/bparticles/emitter.hpp
index 8496c905192..b100b43d1e1 100644
--- a/source/blender/simulations/bparticles/emitter.hpp
+++ b/source/blender/simulations/bparticles/emitter.hpp
@@ -2,7 +2,11 @@
 
 #include "core.hpp"
 
+struct Mesh;
+
 namespace BParticles {
 
 std::unique_ptr<Emitter> new_point_emitter(float3 point);
-}
+std::unique_ptr<Emitter> new_surface_emitter(struct Mesh *mesh);
+
+}  // namespace BParticles



More information about the Bf-blender-cvs mailing list