[Bf-blender-cvs] [d6230d15633] functions: don't always use cache for now since it makes testing more annoying

Jacques Lucke noreply at git.blender.org
Wed Jul 17 18:03:16 CEST 2019


Commit: d6230d15633fbd7f5dbff0882faa4a7ff45d68b2
Author: Jacques Lucke
Date:   Wed Jul 17 18:01:25 2019 +0200
Branches: functions
https://developer.blender.org/rBd6230d15633fbd7f5dbff0882faa4a7ff45d68b2

don't always use cache for now since it makes testing more annoying

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

M	source/blender/modifiers/intern/MOD_bparticles.c
M	source/blender/simulations/BParticles.h
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/particles_container.cpp
M	source/blender/simulations/bparticles/particles_container.hpp

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

diff --git a/source/blender/modifiers/intern/MOD_bparticles.c b/source/blender/modifiers/intern/MOD_bparticles.c
index e2110ccaa20..46d916ea255 100644
--- a/source/blender/modifiers/intern/MOD_bparticles.c
+++ b/source/blender/modifiers/intern/MOD_bparticles.c
@@ -109,12 +109,6 @@ static Mesh *applyModifier(ModifierData *md,
   Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
   float current_frame = BKE_scene_frame_get(scene);
 
-  for (uint i = 0; i < bpmd_orig->num_cached_frames; i++) {
-    if (bpmd_orig->cached_frames[i].frame == current_frame) {
-      return BParticles_modifier_mesh_from_cache(&bpmd_orig->cached_frames[i]);
-    }
-  }
-
   RuntimeData *runtime = get_runtime_struct(bpmd);
 
   if (runtime->particles_state == NULL) {
@@ -143,9 +137,7 @@ static Mesh *applyModifier(ModifierData *md,
     runtime->last_simulated_frame = current_frame;
   }
 
-  BParticles_modifier_cache_state(bpmd_orig, runtime->particles_state, current_frame);
-  return BParticles_modifier_mesh_from_cache(
-      &bpmd_orig->cached_frames[bpmd_orig->num_cached_frames - 1]);
+  return BParticles_modifier_mesh_from_state(runtime->particles_state);
 }
 
 static void initData(ModifierData *UNUSED(md))
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 498b83fdf3f..0ed70da4d65 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -31,6 +31,7 @@ void BParticles_simulate_modifier(struct BParticlesModifierData *bpmd,
 uint BParticles_state_particle_count(BParticlesState particles_state);
 void BParticles_state_get_positions(BParticlesState particles_state, float (*dst)[3]);
 
+Mesh *BParticles_modifier_mesh_from_state(BParticlesState particles_state);
 void BParticles_modifier_free_cache(struct BParticlesModifierData *bpmd);
 struct Mesh *BParticles_modifier_mesh_from_cache(struct BParticlesFrameCache *cached_frame);
 void BParticles_modifier_cache_state(struct BParticlesModifierData *bpmd,
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 02c89bd8ace..f624db181ed 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -173,6 +173,8 @@ static Mesh *distribute_tetrahedons(ArrayRef<float3> centers,
                                     ArrayRef<float> scales,
                                     ArrayRef<float3> colors)
 {
+  SCOPED_TIMER(__func__);
+
   uint amount = centers.size();
   Mesh *mesh = BKE_mesh_new_nomain(amount * ARRAY_SIZE(tetrahedon_vertices),
                                    amount * ARRAY_SIZE(tetrahedon_edges),
@@ -224,6 +226,26 @@ void BParticles_modifier_free_cache(BParticlesModifierData *bpmd)
   bpmd->num_cached_frames = 0;
 }
 
+Mesh *BParticles_modifier_mesh_from_state(BParticlesState state_c)
+{
+  SCOPED_TIMER(__func__);
+
+  ParticlesState &state = *unwrap(state_c);
+
+  SmallVector<float3> positions;
+  SmallVector<float> sizes;
+  SmallVector<float3> colors;
+
+  for (ParticlesContainer *container : state.particle_containers().values()) {
+    positions.extend(container->flatten_attribute_float3("Position"));
+    colors.extend(container->flatten_attribute_float3("Color"));
+    sizes.extend(container->flatten_attribute_float("Size"));
+  }
+
+  Mesh *mesh = distribute_tetrahedons(positions, sizes, colors);
+  return mesh;
+}
+
 Mesh *BParticles_modifier_mesh_from_cache(BParticlesFrameCache *cached_frame)
 {
   SCOPED_TIMER(__func__);
@@ -231,11 +253,9 @@ Mesh *BParticles_modifier_mesh_from_cache(BParticlesFrameCache *cached_frame)
   SmallVector<float3> positions;
   SmallVector<float> sizes;
   SmallVector<float3> colors;
-  SmallVector<uint> particle_counts;
 
   for (uint i = 0; i < cached_frame->num_particle_types; i++) {
     BParticlesTypeCache &type = cached_frame->particle_types[i];
-    particle_counts.append(type.particle_amount);
     positions.extend(
         ArrayRef<float3>((float3 *)type.attributes_float[0].values, type.particle_amount));
     sizes.extend(ArrayRef<float>(type.attributes_float[1].values, type.particle_amount));
diff --git a/source/blender/simulations/bparticles/particles_container.cpp b/source/blender/simulations/bparticles/particles_container.cpp
index 01f064f9938..89975c442a3 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -168,6 +168,14 @@ void ParticlesContainer::flatten_attribute_data(StringRef attribute_name, void *
   }
 }
 
+SmallVector<float> ParticlesContainer::flatten_attribute_float(StringRef attribute_name)
+{
+  BLI_assert(m_attributes_info.type_of(attribute_name) == AttributeType::Float);
+  SmallVector<float> result(this->count_active());
+  this->flatten_attribute_data(attribute_name, (void *)result.begin());
+  return result;
+}
+
 SmallVector<float3> ParticlesContainer::flatten_attribute_float3(StringRef attribute_name)
 {
   BLI_assert(m_attributes_info.type_of(attribute_name) == AttributeType::Float3);
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index ea91000ab68..072f8e1952a 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -83,8 +83,9 @@ class ParticlesContainer {
   void flatten_attribute_data(StringRef attribute_name, void *dst);
 
   /**
-   * Get a vector containing a a float3 attribute value from every particle.
+   * Get a vector containing an attribute value from every particle.
    */
+  SmallVector<float> flatten_attribute_float(StringRef attribute_name);
   SmallVector<float3> flatten_attribute_float3(StringRef attribute_name);
 
   friend bool operator==(const ParticlesContainer &a, const ParticlesContainer &b);



More information about the Bf-blender-cvs mailing list