[Bf-blender-cvs] [c500e94670c] functions: cleanup handling of birth times in emitters
Jacques Lucke
noreply at git.blender.org
Fri Jun 28 13:49:59 CEST 2019
Commit: c500e94670caa68f68c1ca3b6f6dccfad7c9745e
Author: Jacques Lucke
Date: Fri Jun 28 13:30:36 2019 +0200
Branches: functions
https://developer.blender.org/rBc500e94670caa68f68c1ca3b6f6dccfad7c9745e
cleanup handling of birth times in emitters
===================================================================
M source/blender/simulations/bparticles/core.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index 1cb6f8533a2..47fcacd3c00 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -110,7 +110,8 @@ TimeSpanEmitTarget &EmitterInterface::request(uint particle_type_id, uint size)
m_block_allocator.allocate_block_ranges(particle_type_id, size, blocks, ranges);
AttributesInfo &attributes_info = m_block_allocator.attributes_info(particle_type_id);
- auto *target = new TimeSpanEmitTarget(particle_type_id, attributes_info, blocks, ranges);
+ auto *target = new TimeSpanEmitTarget(
+ particle_type_id, attributes_info, blocks, ranges, m_time_span);
m_targets.append(target);
return *target;
}
@@ -246,14 +247,17 @@ void EmitTargetBase::fill_float3(StringRef name, float3 value)
void TimeSpanEmitTarget::set_birth_moment(float time_factor)
{
BLI_assert(time_factor >= 0.0 && time_factor <= 1.0f);
- m_birth_moments.fill(time_factor);
+ this->fill_float("Birth Time", m_time_span.interpolate(time_factor));
}
void TimeSpanEmitTarget::set_randomized_birth_moments()
{
- for (float &birth_moment : m_birth_moments) {
- birth_moment = (rand() % 10000) / 10000.0f;
+ SmallVector<float> birth_times(m_size);
+ for (uint i = 0; i < m_size; i++) {
+ float factor = (rand() % 10000) / 10000.0f;
+ birth_times[i] = m_time_span.interpolate(factor);
}
+ this->set_float("Birth Time", birth_times);
}
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index b16b37ddd49..e8489496934 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -177,21 +177,16 @@ class InstantEmitTarget : public EmitTargetBase {
class TimeSpanEmitTarget : public EmitTargetBase {
private:
- SmallVector<float> m_birth_moments;
+ TimeSpan m_time_span;
public:
TimeSpanEmitTarget(uint particle_type_id,
AttributesInfo &attributes_info,
ArrayRef<ParticlesBlock *> blocks,
- ArrayRef<Range<uint>> ranges)
- : EmitTargetBase(particle_type_id, attributes_info, blocks, ranges)
- {
- m_birth_moments = SmallVector<float>(m_size, 1.0f);
- }
-
- ArrayRef<float> birth_moments()
+ ArrayRef<Range<uint>> ranges,
+ TimeSpan time_span)
+ : EmitTargetBase(particle_type_id, attributes_info, blocks, ranges), m_time_span(time_span)
{
- return m_birth_moments;
}
void set_birth_moment(float time_factor);
@@ -202,9 +197,11 @@ class EmitterInterface {
private:
BlockAllocator &m_block_allocator;
SmallVector<TimeSpanEmitTarget *> m_targets;
+ TimeSpan m_time_span;
public:
- EmitterInterface(BlockAllocator &allocator) : m_block_allocator(allocator)
+ EmitterInterface(BlockAllocator &allocator, TimeSpan time_span)
+ : m_block_allocator(allocator), m_time_span(time_span)
{
}
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index e2fc4f87658..5154dc6ba55 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -513,39 +513,6 @@ BLI_NOINLINE static void delete_tagged_particles(ArrayRef<ParticlesBlock *> bloc
}
}
-/* Emit new particles from emitters.
- **********************************************/
-
-BLI_NOINLINE static void emit_new_particles_from_emitter(BlockAllocator &block_allocator,
- TimeSpan time_span,
- Emitter &emitter)
-{
- EmitterInterface interface(block_allocator);
- emitter.emit(interface);
-
- for (TimeSpanEmitTarget *target_ptr : interface.targets()) {
- TimeSpanEmitTarget &target = *target_ptr;
-
- ArrayRef<float> all_birth_moments = target.birth_moments();
- uint particle_count = 0;
-
- for (uint part = 0; part < target.part_amount(); part++) {
- ParticlesBlock &block = *target.blocks()[part];
- Range<uint> range = target.ranges()[part];
- AttributeArrays attributes = block.slice(range);
-
- ArrayRef<float> birth_moments = all_birth_moments.slice(particle_count, range.size());
-
- auto birth_times = attributes.get_float("Birth Time");
- for (uint i = 0; i < birth_moments.size(); i++) {
- birth_times[i] = time_span.interpolate(birth_moments[i]);
- }
-
- particle_count += range.size();
- }
- }
-}
-
/* Compress particle blocks.
**************************************************/
@@ -618,7 +585,8 @@ void simulate_step(ParticlesState &state, StepDescription &description)
BlockAllocator &emitter_allocator = block_allocators.get_standalone_allocator();
for (Emitter *emitter : description.emitters()) {
- emit_new_particles_from_emitter(emitter_allocator, time_span, *emitter);
+ EmitterInterface interface(emitter_allocator, time_span);
+ emitter->emit(interface);
}
blocks_to_simulate_next = block_allocators.all_allocated_blocks();
More information about the Bf-blender-cvs
mailing list