[Bf-blender-cvs] [468e2b8e66a] functions: cleanup extracting all particle positions
Jacques Lucke
noreply at git.blender.org
Mon Jul 1 15:36:57 CEST 2019
Commit: 468e2b8e66a23df1f92887535d84191c532e8e31
Author: Jacques Lucke
Date: Mon Jul 1 14:14:02 2019 +0200
Branches: functions
https://developer.blender.org/rB468e2b8e66a23df1f92887535d84191c532e8e31
cleanup extracting all particle positions
===================================================================
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/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index b229efae25e..de724bb5560 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -222,7 +222,7 @@ void BParticles_simulate_modifier(NodeParticlesModifierData *npmd,
Depsgraph *UNUSED(depsgraph),
BParticlesState state_c)
{
- SCOPED_TIMER_STATS("simulate");
+ SCOPED_TIMER(__func__);
ParticlesState &state = *unwrap(state_c);
ModifierStepDescription description;
@@ -276,16 +276,13 @@ uint BParticles_state_particle_count(BParticlesState state_c)
void BParticles_state_get_positions(BParticlesState state_c, float (*dst_c)[3])
{
+ SCOPED_TIMER(__func__);
ParticlesState &state = *unwrap(state_c);
- float3 *dst = (float3 *)dst_c;
uint index = 0;
for (ParticlesContainer *container : state.particle_containers().values()) {
- for (auto *block : container->active_blocks()) {
- auto positions = block->slice_active().get_float3("Position");
- positions.copy_to(dst + index);
- index += positions.size();
- }
+ container->flatten_attribute_data("Position", dst_c + index);
+ index += container->count_active();
}
}
diff --git a/source/blender/simulations/bparticles/particles_container.cpp b/source/blender/simulations/bparticles/particles_container.cpp
index 50b78b51506..0b087742eff 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -121,6 +121,20 @@ void ParticlesContainer::update_attributes(AttributesInfo new_info)
}
}
+void ParticlesContainer::flatten_attribute_data(StringRef attribute_name, void *dst)
+{
+ uint attribute_index = m_attributes_info.attribute_index(attribute_name);
+ uint element_size = size_of_attribute_type(m_attributes_info.type_of(attribute_index));
+
+ uint offset = 0;
+ for (ParticlesBlock *block : m_blocks) {
+ uint amount = block->active_amount();
+ void *src = block->slice_active().get_ptr(attribute_index);
+ memcpy(POINTER_OFFSET(dst, offset), src, amount * element_size);
+ offset += amount * element_size;
+ }
+}
+
void ParticlesBlock::MoveUntilFull(ParticlesBlock &from, ParticlesBlock &to)
{
BLI_assert(&from.container() == &to.container());
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index 2c5c7264a3b..8e9cec92ef3 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -47,6 +47,8 @@ class ParticlesContainer {
ParticlesBlock &new_block();
void release_block(ParticlesBlock &block);
+ void flatten_attribute_data(StringRef attribute_name, void *dst);
+
friend bool operator==(const ParticlesContainer &a, const ParticlesContainer &b);
};
More information about the Bf-blender-cvs
mailing list