[Bf-blender-cvs] [59d9310b28a] functions: initial point randomization accross surface

Jacques Lucke noreply at git.blender.org
Mon Jul 1 17:47:27 CEST 2019


Commit: 59d9310b28a4b709d6a5741e078858e3a974dd88
Author: Jacques Lucke
Date:   Mon Jul 1 17:45:21 2019 +0200
Branches: functions
https://developer.blender.org/rB59d9310b28a4b709d6a5741e078858e3a974dd88

initial point randomization accross surface

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

M	source/blender/simulations/bparticles/emitters.cpp

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

diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index a275092c430..2aae2a282e0 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -69,7 +69,7 @@ class SurfaceEmitter : public Emitter {
       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 pos = (v1 + v2 + v3) / 3.0f;
+      float3 pos = random_point_in_triangle(v1, v2, v3);
 
       float3 normal;
       normal_tri_v3(normal, v1, v2, v3);
@@ -86,6 +86,20 @@ class SurfaceEmitter : public Emitter {
     target.set_float3("Velocity", velocities);
     target.set_birth_moments(birth_moments);
   }
+
+  float3 random_point_in_triangle(float3 a, float3 b, float3 c)
+  {
+    float3 dir1 = b - a;
+    float3 dir2 = c - a;
+    float rand1, rand2;
+
+    do {
+      rand1 = (rand() % 1000) / 1000.0f;
+      rand2 = (rand() % 1000) / 1000.0f;
+    } while (rand1 + rand2 > 1.0f);
+
+    return a + dir1 * rand1 + dir2 * rand2;
+  }
 };
 
 class PathEmitter : public Emitter {



More information about the Bf-blender-cvs mailing list