Commit: f9edcf46b38fa4e7d089e4dc26da65e02838cf5b Author: Jacques Lucke Date: Fri Jul 5 12:23:45 2019 +0200 Branches: functions https://developer.blender.org/rBf9edcf46b38fa4e7d089e4dc26da65e02838cf5b
improved change direction action =================================================================== M source/blender/blenlib/BLI_math.hpp M source/blender/simulations/bparticles/actions.cpp M source/blender/simulations/bparticles/core.cpp M source/blender/simulations/bparticles/core.hpp M source/blender/simulations/bparticles/events.cpp M source/blender/simulations/bparticles/simulate.cpp =================================================================== diff --git a/source/blender/blenlib/BLI_math.hpp b/source/blender/blenlib/BLI_math.hpp index 965ca949400..38a9aed7b26 100644 --- a/source/blender/blenlib/BLI_math.hpp +++ b/source/blender/blenlib/BLI_math.hpp @@ -14,6 +14,14 @@ struct float3 { { } + explicit float3(float value) : x(value), y(value), z(value) + { + } + + explicit float3(int value) : x(value), y(value), z(value) + { + } + float3(float x, float y, float z) : x{x}, y{y}, z{z} { } diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp index 3427a6d2ec1..05341418435 100644 --- a/source/blender/simulations/bparticles/actions.cpp +++ b/source/blender/simulations/bparticles/actions.cpp @@ -30,16 +30,21 @@ class ChangeDirectionAction : public Action { { ParticleSet particles = interface.particles(); auto velocities = particles.attributes().get_float3("Velocity"); + auto position_offsets = interface.attribute_offsets().get_float3("Position"); + auto velocity_offsets = interface.attribute_offsets().get_float3("Velocity"); FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_direction_body, fn_in, fn_out); FN::ExecutionStack stack; FN::ExecutionContext execution_context(stack); - for (uint pindex : particles.indices()) { + for (uint i : particles.range()) { + uint pindex = particles.get_particle_index(i); m_compute_direction_body->call(fn_in, fn_out, execution_context); float3 direction = fn_out.get<float3>(0); velocities[pindex] = direction; + position_offsets[pindex] = direction * interface.remaining_time_in_step(i); + velocity_offsets[pindex] = float3(0); } } }; diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp index e063e853f94..70606e742bb 100644 --- a/source/blender/simulations/bparticles/core.cpp +++ b/source/blender/simulations/bparticles/core.cpp @@ -343,13 +343,15 @@ EventExecuteInterface::EventExecuteInterface(ParticleSet particles, BlockAllocator &block_allocator, ArrayRef<float> current_times, EventStorage &event_storage, - AttributeArrays attribute_offsets) + AttributeArrays attribute_offsets, + float step_end_time) : m_particles(particles), m_block_allocator(block_allocator), m_current_times(current_times), m_kill_states(m_particles.attributes().get_byte("Kill State")), m_event_storage(event_storage), - m_attribute_offsets(attribute_offsets) + m_attribute_offsets(attribute_offsets), + m_step_end_time(step_end_time) { } diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp index aafc63ed5eb..ed6f3f03b94 100644 --- a/source/blender/simulations/bparticles/core.hpp +++ b/source/blender/simulations/bparticles/core.hpp @@ -539,13 +539,15 @@ class EventExecuteInterface { ArrayRef<uint8_t> m_kill_states; EventStorage &m_event_storage; AttributeArrays m_attribute_offsets; + float m_step_end_time; public: EventExecuteInterface(ParticleSet particles, BlockAllocator &block_allocator, ArrayRef<float> current_times, EventStorage &event_storage, - AttributeArrays attribute_offsets); + AttributeArrays attribute_offsets, + float step_end_time); ~EventExecuteInterface(); @@ -559,6 +561,16 @@ class EventExecuteInterface { */ ArrayRef<float> current_times(); + /** + * Get the end time of the current step. + */ + float step_end_time(); + + /** + * Get the remaining time a particle in the current step. + */ + float remaining_time_in_step(uint index); + /** * Get the data stored in the Event->filter() function for a particle index. */ @@ -883,6 +895,16 @@ inline ArrayRef<float> EventExecuteInterface::current_times() return m_current_times; } +inline float EventExecuteInterface::step_end_time() +{ + return m_step_end_time; +} + +inline float EventExecuteInterface::remaining_time_in_step(uint index) +{ + return m_step_end_time - m_current_times[index]; +} + template<typename T> inline T &EventExecuteInterface::get_storage(uint pindex) { return m_event_storage.get<T>(pindex); diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp index 4e0ca1df4e6..fce104ca43d 100644 --- a/source/blender/simulations/bparticles/events.cpp +++ b/source/blender/simulations/bparticles/events.cpp @@ -27,11 +27,14 @@ class AgeReachedEvent : public EventFilter { for (uint i : particles.range()) { uint pindex = particles.get_particle_index(i); - float duration = interface.durations()[i]; + TimeSpan time_span = interface.time_span(i); + float birth_time = birth_times[pindex]; - float age = end_time - birth_time; - if (age >= m_age && age - duration < m_age) { - float time_factor = TimeSpan(end_time - duration, duration).get_factor(birth_time + m_age); + float age_at_end = end_time - birth_time; + float age_at_start = age_at_end - time_span.duration(); + + if (age_at_end >= m_age && age_at_start < m_age) { + float time_factor = time_span.get_factor(birth_time + m_age); interface.trigger_particle(i, time_factor); } } diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp index 8d06406926a..9dbed3eb6ad 100644 --- a/source/blender/simulations/bparticles/simulate.cpp +++ b/source/blender/simulations/bparticles/simulate.cpp @@ -196,7 +196,8 @@ BLI_NOINLINE static void execute_events(BlockAllocator &block_allocator, ArrayRef<SmallVector<float>> current_time_per_particle, ArrayRef<Event *> events, EventStorage &event_storage, - AttributeArrays attribute_offsets) + AttributeArrays attribute_offsets, + float end_time) { BLI_assert(events.size() == particle_indices_per_event.size()); BLI_assert(events.size() == current_time_per_particle.size()); @@ -212,7 +213,8 @@ BLI_NOINLINE static void execute_events(BlockAllocator &block_allocator, block_allocator, current_time_per_particle[event_index], event_storage, - attribute_offsets); + attribute_offsets, + end_time); event->execute(interface); } } @@ -281,7 +283,8 @@ BLI_NOINLINE static void simulate_to_next_event(FixedArrayAllocator &array_alloc current_time_per_particle, events, event_storage, - attribute_offsets); + attribute_offsets, + end_time); find_unfinished_particles(indices_with_event, particles.indices(), @@ -443,7 +446,7 @@ BLI_NOINLINE static void simulate_block(FixedArrayAllocator &array_allocator, uint *indices_array = array_allocator.allocate_array<uint>(); VectorAdaptor<uint> unfinished_particle_indices(indices_array, amount); - simulate_with_max_n_events(10, + simulate_with_max_n_events(1, array_allocator, block_allocator, block, _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs