[Bf-blender-cvs] [c665ef49adb] functions: store surface velocities in surface context

Jacques Lucke noreply at git.blender.org
Wed Sep 4 19:43:28 CEST 2019


Commit: c665ef49adb99ec622cfeef4186852b29617055c
Author: Jacques Lucke
Date:   Wed Sep 4 13:52:40 2019 +0200
Branches: functions
https://developer.blender.org/rBc665ef49adb99ec622cfeef4186852b29617055c

store surface velocities in surface context

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

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

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

diff --git a/source/blender/simulations/bparticles/action_contexts.hpp b/source/blender/simulations/bparticles/action_contexts.hpp
index 81e01d97400..d0d60153d77 100644
--- a/source/blender/simulations/bparticles/action_contexts.hpp
+++ b/source/blender/simulations/bparticles/action_contexts.hpp
@@ -18,6 +18,7 @@ class MeshSurfaceContext : public ActionContext {
   ArrayRef<float3> m_local_normals;
   ArrayRef<float3> m_world_normals;
   ArrayRef<uint> m_looptri_indices;
+  ArrayRef<float3> m_surface_velocities;
 
  public:
   MeshSurfaceContext(Object *object,
@@ -25,13 +26,15 @@ class MeshSurfaceContext : public ActionContext {
                      ArrayRef<float3> local_positions,
                      ArrayRef<float3> local_normals,
                      ArrayRef<float3> world_normals,
-                     ArrayRef<uint> looptri_indices)
+                     ArrayRef<uint> looptri_indices,
+                     ArrayRef<float3> surface_velocities)
       : m_object(object),
         m_world_transforms(world_transforms),
         m_local_positions(local_positions),
         m_local_normals(local_normals),
         m_world_normals(world_normals),
-        m_looptri_indices(looptri_indices)
+        m_looptri_indices(looptri_indices),
+        m_surface_velocities(surface_velocities)
   {
   }
 
@@ -50,16 +53,20 @@ class MeshSurfaceContext : public ActionContext {
     float4x4 *world_transforms_buffer = (float4x4 *)BLI_temporary_allocate(sizeof(float4x4) *
                                                                            size);
     float3 *world_normals_buffer = (float3 *)BLI_temporary_allocate(sizeof(float3) * size);
+    float3 *surface_velocities_buffer = (float3 *)BLI_temporary_allocate(sizeof(float3) * size);
 
     for (uint pindex : pindices) {
       world_transforms_buffer[pindex] = world_transform;
       world_normals_buffer[pindex] = local_normals[pindex];
+      surface_velocities_buffer[pindex] = float3(0, 0, 0);
     }
 
     m_world_transforms = ArrayRef<float4x4>(world_transforms_buffer, size);
     m_world_normals = ArrayRef<float3>(world_normals_buffer, size);
+    m_surface_velocities = ArrayRef<float3>(surface_velocities_buffer, size);
 
-    m_buffers_to_free.extend({world_transforms_buffer, world_normals_buffer});
+    m_buffers_to_free.extend(
+        {world_transforms_buffer, world_normals_buffer, surface_velocities_buffer});
   }
 
   ~MeshSurfaceContext()
@@ -101,6 +108,11 @@ class MeshSurfaceContext : public ActionContext {
   {
     return m_looptri_indices;
   }
+
+  ArrayRef<float3> surface_velicities() const
+  {
+    return m_surface_velocities;
+  }
 };
 
 };  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index be5934f10e4..5a06461b8f3 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -290,12 +290,22 @@ void SurfaceEmitter::emit(EmitterInterface &interface)
   TemporaryArray<float3> local_normals(particles_to_emit);
   sample_looptris(mesh, triangles, triangles_to_sample, local_positions, local_normals);
 
+  float epsilon = 0.01f;
   TemporaryArray<float4x4> transforms_at_birth(particles_to_emit);
+  TemporaryArray<float4x4> transforms_before_birth(particles_to_emit);
   m_transform.interpolate(birth_moments, 0.0f, transforms_at_birth);
+  m_transform.interpolate(birth_moments, -epsilon, transforms_before_birth);
 
   TemporaryArray<float3> positions_at_birth(particles_to_emit);
   float4x4::transform_positions(transforms_at_birth, local_positions, positions_at_birth);
 
+  TemporaryArray<float3> surface_velocities(particles_to_emit);
+  for (uint i = 0; i < particles_to_emit; i++) {
+    float3 position_before_birth = transforms_before_birth[i].transform_position(
+        local_positions[i]);
+    surface_velocities[i] = (positions_at_birth[i] - position_before_birth) / epsilon;
+  }
+
   TemporaryArray<float3> world_normals(particles_to_emit);
   float4x4::transform_directions(transforms_at_birth, local_normals, world_normals);
 
@@ -315,7 +325,8 @@ void SurfaceEmitter::emit(EmitterInterface &interface)
                                        local_positions.as_ref().slice(range),
                                        local_normals.as_ref().slice(range),
                                        world_normals.as_ref().slice(range),
-                                       triangles_to_sample.as_ref().slice(range));
+                                       triangles_to_sample.as_ref().slice(range),
+                                       surface_velocities.as_ref().slice(range));
         });
   }
 }



More information about the Bf-blender-cvs mailing list