Blender V5.0
particle_system.cc File Reference
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "DNA_boid_types.h"
#include "DNA_cloth_types.h"
#include "DNA_listBase.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_force_types.h"
#include "DNA_object_types.h"
#include "DNA_particle_types.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
#include "BLI_kdopbvh.hh"
#include "BLI_kdtree.h"
#include "BLI_linklist.h"
#include "BLI_listbase.h"
#include "BLI_math_base_safe.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_rand.h"
#include "BLI_string.h"
#include "BLI_string_utils.hh"
#include "BLI_task.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
#include "BKE_animsys.h"
#include "BKE_boids.h"
#include "BKE_collision.h"
#include "BKE_colortools.hh"
#include "BKE_customdata.hh"
#include "BKE_effect.h"
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_mesh_legacy_convert.hh"
#include "BKE_particle.h"
#include "BKE_cloth.hh"
#include "BKE_material.hh"
#include "BKE_mesh.hh"
#include "BKE_modifier.hh"
#include "BKE_object.hh"
#include "BKE_pointcache.h"
#include "BKE_scene.hh"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"

Go to the source code of this file.

Classes

struct  SPHNeighbor
struct  SPHRangeData
struct  EfData
struct  DynamicStepSolverTaskData
struct  ParticleSystemIDLoopForModifier

Macros

#define ZERO_F43
#define COLLISION_MIN_RADIUS   0.001f
#define COLLISION_MIN_DISTANCE   0.0001f
#define COLLISION_ZERO   0.00001f
#define COLLISION_INIT_STEP   0.00008f

Typedefs

using NRDistanceFunc

Functions

static int particles_are_dynamic (ParticleSystem *psys)
float psys_get_current_display_percentage (ParticleSystem *psys, const bool use_render_params)
static int tot_particles (ParticleSystem *psys, PTCacheID *pid)
void psys_reset (ParticleSystem *psys, int mode)
void psys_unique_name (Object *object, ParticleSystem *psys, const char *defname)
static void realloc_particles (ParticleSimulationData *sim, int new_totpart)
int psys_get_child_number (Scene *scene, ParticleSystem *psys, const bool use_render_params)
int psys_get_tot_child (Scene *scene, ParticleSystem *psys, const bool use_render_params)
void psys_calc_dmcache (Object *ob, Mesh *mesh_final, Mesh *mesh_original, ParticleSystem *psys)
void psys_thread_context_init (ParticleThreadContext *ctx, ParticleSimulationData *sim)
blender::Vector< ParticleTaskpsys_tasks_create (ParticleThreadContext *ctx, int startpart, int endpart)
void psys_tasks_free (blender::Vector< ParticleTask > &tasks)
void psys_thread_context_free (ParticleThreadContext *ctx)
static void init_particle_texture (ParticleSimulationData *sim, ParticleData *pa, int p)
void init_particle (ParticleSimulationData *sim, ParticleData *pa)
static void initialize_all_particles (ParticleSimulationData *sim)
static void free_unexisting_particles (ParticleSimulationData *sim)
static void get_angular_velocity_vector (short avemode, ParticleKey *state, float vec[3])
void psys_get_birth_coords (ParticleSimulationData *sim, ParticleData *pa, ParticleKey *state, float dtime, float cfra)
static void evaluate_emitter_anim (Depsgraph *depsgraph, Scene *scene, Object *ob, float cfra)
void reset_particle (ParticleSimulationData *sim, ParticleData *pa, float dtime, float cfra)
static void reset_all_particles (ParticleSimulationData *sim, float dtime, float cfra, int from)
ParticleSystempsys_get_target_system (Object *ob, ParticleTarget *pt)
void psys_count_keyed_targets (ParticleSimulationData *sim)
static void set_keyed_keys (ParticleSimulationData *sim)
void psys_make_temp_pointcache (Object *ob, ParticleSystem *psys)
static void psys_clear_temp_pointcache (ParticleSystem *psys)
void psys_get_pointcache_start_end (Scene *scene, ParticleSystem *psys, int *sfra, int *efra)
static void bvhtree_balance_isolated (void *userdata)
static void psys_update_particle_bvhtree (ParticleSystem *psys, float cfra)
void psys_update_particle_tree (ParticleSystem *psys, float cfra)
static void psys_update_effectors (ParticleSimulationData *sim)
static void integrate_particle (ParticleSettings *part, ParticleData *pa, float dtime, float *external_acceleration, void(*force_func)(void *forcedata, ParticleKey *state, float *force, float *impulse), void *forcedata)
static void basic_force_cb (void *efdata_v, ParticleKey *state, float *force, float *impulse)
static void basic_integrate (ParticleSimulationData *sim, int p, float dfra, float cfra)
static void basic_rotate (ParticleSettings *part, ParticleData *pa, float dfra, float timestep)
static float nr_signed_distance_to_plane (float *p, float radius, ParticleCollisionElement *pce, float *nor)
static float nr_distance_to_edge (float *p, float radius, ParticleCollisionElement *pce, float *)
static float nr_distance_to_vert (float *p, float radius, ParticleCollisionElement *pce, float *)
static void collision_interpolate_element (ParticleCollisionElement *pce, float t, float fac, ParticleCollision *col)
static void collision_point_velocity (ParticleCollisionElement *pce)
static float collision_point_distance_with_normal (float p[3], ParticleCollisionElement *pce, float fac, ParticleCollision *col, float *nor)
static void collision_point_on_surface (const float p[3], ParticleCollisionElement *pce, float fac, ParticleCollision *col, float *co)
static float collision_newton_rhapson (ParticleCollision *col, float radius, ParticleCollisionElement *pce, NRDistanceFunc distance_func)
static int collision_sphere_to_tri (ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
static int collision_sphere_to_edges (ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
static int collision_sphere_to_verts (ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
void BKE_psys_collision_neartest_cb (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
static int collision_detect (ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, ListBase *colliders)
static int collision_response (ParticleSimulationData *sim, ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, int kill, int dynamic_rotation)
static void collision_fail (ParticleData *pa, ParticleCollision *col)
static void collision_check (ParticleSimulationData *sim, int p, float dfra, float cfra)
static void psys_update_path_cache (ParticleSimulationData *sim, float cfra, const bool use_render_params)
static bool psys_hair_use_simulation (ParticleData *pa, float max_length)
static MDeformVerthair_set_pinning (MDeformVert *dvert, float weight)
static void hair_create_input_mesh (ParticleSimulationData *sim, int totpoint, int totedge, Mesh **r_mesh)
static void do_hair_dynamics (ParticleSimulationData *sim)
static void hair_step (ParticleSimulationData *sim, float cfra, const bool use_render_params)
static void save_hair (ParticleSimulationData *sim, float)
static void update_courant_num (ParticleSimulationData *sim, ParticleData *pa, float dtime, SPHData *sphdata, SpinLock *spin)
static float get_base_time_step (ParticleSettings *part)
static void update_timestep (ParticleSystem *psys, ParticleSimulationData *sim)
static float sync_timestep (ParticleSystem *psys, float t_frac)
static SPHData dynamics_step_sphdata_reduce (const SPHData &sphdata_to, const SPHData &sphdata_from)
static void dynamics_step_sph_ddr_task_cb_ex (DynamicStepSolverTaskData *data, const int p, SPHData *sphdata)
static void dynamics_step_sph_classical_basic_integrate_task_cb_ex (void *__restrict userdata, const int p, const TaskParallelTLS *__restrict)
static void dynamics_step_sph_classical_calc_density_task_cb_ex (void *__restrict userdata, const int p, const TaskParallelTLS *__restrict tls)
static void dynamics_step_sph_classical_integrate_task_cb_ex (void *__restrict userdata, const int p, const TaskParallelTLS *__restrict tls)
static void dynamics_step (ParticleSimulationData *sim, float cfra)
static void update_children (ParticleSimulationData *sim, const bool use_render_params)
static void cached_step (ParticleSimulationData *sim, float cfra, const bool use_render_params)
static bool particles_has_flip (short parttype)
static bool particles_has_tracer (short parttype)
static bool particles_has_spray (short parttype)
static bool particles_has_bubble (short parttype)
static bool particles_has_foam (short parttype)
static void particles_fluid_step (ParticleSimulationData *sim, int cfra, const bool use_render_params)
static int emit_particles (ParticleSimulationData *sim, PTCacheID *pid, float)
static void system_step (ParticleSimulationData *sim, float cfra, const bool use_render_params)
void psys_changed_type (Object *ob, ParticleSystem *psys)
void psys_check_boid_data (ParticleSystem *psys)
void BKE_particlesettings_fluid_default_settings (ParticleSettings *part)
static void psys_prepare_physics (ParticleSimulationData *sim)
static int hair_needs_recalc (ParticleSystem *psys)
static ParticleSettingsparticle_settings_localize (ParticleSettings *particle_settings)
static void particle_settings_free_local (ParticleSettings *particle_settings)
void particle_system_update (Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, const bool use_render_params)
static void particlesystem_modifiersForeachIDLink (void *user_data, Object *, ID **id_pointer, const LibraryForeachIDCallbackFlag cb_flag)
void BKE_particlesystem_id_loop (ParticleSystem *psys, ParticleSystemIDFunc func, void *userdata)
void BKE_particlesystem_reset_all (Object *object)
void BKE_particle_settings_eval_reset (Depsgraph *depsgraph, ParticleSettings *particle_settings)
void BKE_particle_system_eval_init (Depsgraph *depsgraph, Object *object)

Variables

static ThreadRWMutex psys_bvhtree_rwlock = BLI_RWLOCK_INITIALIZER
static const float MIN_TIMESTEP = 1.0f / 101.0f
static const float TIMESTEP_EXPANSION_FACTOR = 0.1f
static const float TIMESTEP_EXPANSION_TOLERANCE = 1.5f

SPH fluid physics

In theory, there could be unlimited implementation of SPH simulators

This code uses in some parts adapted algorithms from the pseudo code as outlined in the Research paper:

Titled: Particle-based Viscoelastic Fluid Simulation. Authors: Simon Clavet, Philippe Beaudoin and Pierre Poulin Website: http://www.iro.umontreal.ca/labs/infographie/papers/Clavet-2005-PVFS/

Presented at SIGGRAPH, (2005)

#define PSYS_FLUID_SPRINGS_INITIAL_SIZE   256
#define SPH_NEIGHBORS   512
static ParticleSpringsph_spring_add (ParticleSystem *psys, ParticleSpring *spring)
static void sph_spring_delete (ParticleSystem *psys, int j)
static void sph_springs_modify (ParticleSystem *psys, float dtime)
static blender::Map< blender::OrderedEdge, int > sph_springhash_build (ParticleSystem *psys)
static void sph_evaluate_func (BVHTree *tree, ParticleSystem **psys, const float co[3], SPHRangeData *pfr, float interaction_radius, BVHTree_RangeQuery callback)
static void sph_density_accum_cb (void *userdata, int index, const float co[3], float squared_dist)
static void sph_particle_courant (SPHData *sphdata, SPHRangeData *pfr)
static void sph_force_cb (void *sphdata_v, ParticleKey *state, float *force, float *)
static void sphclassical_density_accum_cb (void *userdata, int index, const float co[3], float)
static void sphclassical_neighbor_accum_cb (void *userdata, int index, const float co[3], float)
static void sphclassical_force_cb (void *sphdata_v, ParticleKey *state, float *force, float *)
static void sphclassical_calc_dens (ParticleData *pa, float, SPHData *sphdata)
static void psys_sph_init (ParticleSimulationData *sim, SPHData *sphdata, blender::Map< blender::OrderedEdge, int > &r_eh)
static void psys_sph_flush_springs (SPHData *sphdata)
void psys_sph_finalize (SPHData *sphdata)
void psys_sph_density (BVHTree *tree, SPHData *sphdata, float co[3], float vars[2])
static void sph_integrate (ParticleSimulationData *sim, ParticleData *pa, float dfra, SPHData *sphdata)

Macro Definition Documentation

◆ COLLISION_INIT_STEP

#define COLLISION_INIT_STEP   0.00008f

Definition at line 2382 of file particle_system.cc.

Referenced by collision_newton_rhapson().

◆ COLLISION_MIN_DISTANCE

#define COLLISION_MIN_DISTANCE   0.0001f

Definition at line 2380 of file particle_system.cc.

Referenced by collision_response().

◆ COLLISION_MIN_RADIUS

#define COLLISION_MIN_RADIUS   0.001f

Definition at line 2379 of file particle_system.cc.

Referenced by collision_check().

◆ COLLISION_ZERO

#define COLLISION_ZERO   0.00001f

Definition at line 2381 of file particle_system.cc.

Referenced by collision_newton_rhapson().

◆ PSYS_FLUID_SPRINGS_INITIAL_SIZE

#define PSYS_FLUID_SPRINGS_INITIAL_SIZE   256

Definition at line 1556 of file particle_system.cc.

Referenced by sph_spring_add(), and sph_spring_delete().

◆ SPH_NEIGHBORS

#define SPH_NEIGHBORS   512

Definition at line 1659 of file particle_system.cc.

Referenced by sph_density_accum_cb(), and sphclassical_neighbor_accum_cb().

◆ ZERO_F43

#define ZERO_F43
Value:
{ \
{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f} \
}

Referenced by integrate_particle().

Typedef Documentation

◆ NRDistanceFunc

Initial value:
float (*)(float *p,
float radius,
float *nor)
nullptr float
uint nor

Definition at line 2383 of file particle_system.cc.

Function Documentation

◆ basic_force_cb()

◆ basic_integrate()

◆ basic_rotate()

◆ BKE_particle_settings_eval_reset()

void BKE_particle_settings_eval_reset ( Depsgraph * depsgraph,
ParticleSettings * particle_settings )

◆ BKE_particle_system_eval_init()

void BKE_particle_system_eval_init ( Depsgraph * depsgraph,
Object * object )

◆ BKE_particlesettings_fluid_default_settings()

◆ BKE_particlesystem_id_loop()

◆ BKE_particlesystem_reset_all()

void BKE_particlesystem_reset_all ( struct Object * object)

◆ BKE_psys_collision_neartest_cb()

◆ bvhtree_balance_isolated()

void bvhtree_balance_isolated ( void * userdata)
static

Definition at line 1306 of file particle_system.cc.

References BLI_bvhtree_balance().

Referenced by psys_update_particle_bvhtree().

◆ cached_step()

◆ collision_check()

◆ collision_detect()

◆ collision_fail()

void collision_fail ( ParticleData * pa,
ParticleCollision * col )
static

◆ collision_interpolate_element()

void collision_interpolate_element ( ParticleCollisionElement * pce,
float t,
float fac,
ParticleCollision * col )
static
Parameters
tis the current time for newton raphson.
facis the starting factor for current collision iteration.
colThe particle collision, col->fac's are factors for the particle sub-frame step start and end during collision modifier step.

Definition at line 2447 of file particle_system.cc.

References col, madd_v3_v3v3fl(), mul(), ParticleCollisionElement::tot, ParticleCollisionElement::v, ParticleCollisionElement::x, ParticleCollisionElement::x0, ParticleCollisionElement::x1, and ParticleCollisionElement::x2.

Referenced by collision_newton_rhapson(), collision_point_distance_with_normal(), and collision_point_on_surface().

◆ collision_newton_rhapson()

◆ collision_point_distance_with_normal()

◆ collision_point_on_surface()

◆ collision_point_velocity()

◆ collision_response()

◆ collision_sphere_to_edges()

◆ collision_sphere_to_tri()

◆ collision_sphere_to_verts()

◆ do_hair_dynamics()

◆ dynamics_step()

void dynamics_step ( ParticleSimulationData * sim,
float cfra )
static

Definition at line 3806 of file particle_system.cc.

References ParticleData::alive, basic_integrate(), basic_rotate(), BKE_collider_cache_create(), BLI_findlink(), BLI_parallel_range_settings_defaults(), BLI_rng_new_srandom(), BLI_spin_end(), BLI_spin_init(), BLI_task_parallel_range(), boid_body(), boid_brain(), boids_precalc_rules(), BoidBrainData::cfra, DynamicStepSolverTaskData::cfra, ParticleSystem::cfra, ParticleSimulationData::colliders, collision_check(), ParticleSettings::collision_group, copy_particle_key(), data, ParticleSimulationData::depsgraph, BoidBrainData::dfra, ParticleData::dietime, DynamicStepSolverTaskData::dtime, dynamics_step_sph_classical_basic_integrate_task_cb_ex(), dynamics_step_sph_classical_calc_density_task_cb_ex(), dynamics_step_sph_classical_integrate_task_cb_ex(), dynamics_step_sphdata_reduce(), ELEM, ListBase::first, ParticleData::flag, ParticleSettings::flag, ParticleSettings::fluid, BoidBrainData::goal_ob, LOOP_DYNAMIC_PARTICLES, LOOP_EXISTING_PARTICLES, LOOP_SHOWN_PARTICLES, ParticleTarget::next, ParticleSimulationData::ob, ParticleTarget::ob, PAMAP_SIZE, blender::threading::parallel_reduce(), PARS_ALIVE, PARS_DYING, PARS_NO_DISP, PARS_UNBORN, PARS_UNEXIST, BoidBrainData::part, ParticleSystem::part, PART_HAIR, PART_PHYS_BOIDS, PART_PHYS_FLUID, PART_PHYS_NEWTON, PART_PHYS_NO, PART_UNBORN, PARTICLE_P, Object::particlesystem, ParticleSettings::phystype, ParticleSystem::pointcache, ParticleData::prev_state, ParticleSimulationData::psys, ParticleTarget::psys, psys_frand(), psys_get_target_system(), psys_get_texture(), psys_get_timestep(), psys_sph_finalize(), psys_sph_init(), psys_update_effectors(), psys_update_particle_bvhtree(), psys_update_particle_tree(), ParticleSettings::randsize, reset_particle(), BoidBrainData::rng, ParticleSimulationData::rng, ParticleSystem::seed, BoidBrainData::sim, DynamicStepSolverTaskData::sim, ParticleData::size, ParticleSettings::size, ParticleTexture::size, SPHFluidSettings::solver, SPH_SOLVER_DDR, sph_springs_modify(), DynamicStepSolverTaskData::spin, ParticleData::state, PointCache::step, ParticleSystem::targets, ParticleData::time, ParticleKey::time, BoidBrainData::timestep, DynamicStepSolverTaskData::timestep, ParticleSystem::totpart, ParticleSettings::type, TaskParallelSettings::use_threading, TaskParallelSettings::userdata_chunk, and TaskParallelSettings::userdata_chunk_size.

Referenced by system_step().

◆ dynamics_step_sph_classical_basic_integrate_task_cb_ex()

void dynamics_step_sph_classical_basic_integrate_task_cb_ex ( void *__restrict userdata,
const int p,
const TaskParallelTLS * __restrict )
static

◆ dynamics_step_sph_classical_calc_density_task_cb_ex()

void dynamics_step_sph_classical_calc_density_task_cb_ex ( void *__restrict userdata,
const int p,
const TaskParallelTLS *__restrict tls )
static

◆ dynamics_step_sph_classical_integrate_task_cb_ex()

void dynamics_step_sph_classical_integrate_task_cb_ex ( void *__restrict userdata,
const int p,
const TaskParallelTLS *__restrict tls )
static

◆ dynamics_step_sph_ddr_task_cb_ex()

◆ dynamics_step_sphdata_reduce()

SPHData dynamics_step_sphdata_reduce ( const SPHData & sphdata_to,
const SPHData & sphdata_from )
static

Definition at line 3698 of file particle_system.cc.

References SPHData::new_springs, and result.

Referenced by dynamics_step().

◆ emit_particles()

int emit_particles ( ParticleSimulationData * sim,
PTCacheID * pid,
float  )
static

◆ evaluate_emitter_anim()

void evaluate_emitter_anim ( Depsgraph * depsgraph,
Scene * scene,
Object * ob,
float cfra )
static

◆ free_unexisting_particles()

◆ get_angular_velocity_vector()

void get_angular_velocity_vector ( short avemode,
ParticleKey * state,
float vec[3] )
static

◆ get_base_time_step()

float get_base_time_step ( ParticleSettings * part)
static

Definition at line 3638 of file particle_system.cc.

References float, and ParticleSettings::subframes.

Referenced by system_step(), and update_timestep().

◆ hair_create_input_mesh()

◆ hair_needs_recalc()

◆ hair_set_pinning()

MDeformVert * hair_set_pinning ( MDeformVert * dvert,
float weight )
static

◆ hair_step()

◆ init_particle()

◆ init_particle_texture()

◆ initialize_all_particles()

◆ integrate_particle()

◆ nr_distance_to_edge()

float nr_distance_to_edge ( float * p,
float radius,
ParticleCollisionElement * pce,
float *  )
static

◆ nr_distance_to_vert()

float nr_distance_to_vert ( float * p,
float radius,
ParticleCollisionElement * pce,
float *  )
static

Definition at line 2434 of file particle_system.cc.

References len_v3v3(), and ParticleCollisionElement::x0.

Referenced by collision_sphere_to_verts().

◆ nr_signed_distance_to_plane()

◆ particle_settings_free_local()

void particle_settings_free_local ( ParticleSettings * particle_settings)
static

◆ particle_settings_localize()

ParticleSettings * particle_settings_localize ( ParticleSettings * particle_settings)
static

Definition at line 4745 of file particle_system.cc.

References BKE_id_copy_ex(), ParticleSettings::id, and LIB_ID_COPY_LOCALIZE.

Referenced by particle_system_update().

◆ particle_system_update()

void particle_system_update ( struct Depsgraph * depsgraph,
struct Scene * scene,
struct Object * ob,
struct ParticleSystem * psys,
bool use_render_params )

Main particle update call, checks that things are ok on the large scale and then advances in to actual particle calculations depending on particle type.

Definition at line 4760 of file particle_system.cc.

References ParticleSettings::adt, ADT_RECALC_ANIM, BKE_animsys_eval_context_construct(), BKE_animsys_evaluate_animdata(), BKE_mesh_tessface_ensure(), BKE_particle_batch_cache_dirty_tag(), BKE_PARTICLE_BATCH_DIRTY_ALL, ParticleSystem::cfra, DEG_get_ctime(), DEG_is_active(), depsgraph, ParticleSimulationData::depsgraph, distribute_particles(), ParticleSystem::edit, emit_particles(), eParticleSystemFlag_Pars, eParticleSystemFlag_psys_updated, evaluate_emitter_anim(), ParticleData::flag, ParticleDrawData::flag, ParticleSettings::flag, ParticleSystem::flag, ParticleSystemModifierData::flag, PTCacheEdit::flags, float, ParticleSystem::free_edit, free_hair(), free_keyed_keys(), free_unexisting_particles(), ParticleSettings::from, hair_needs_recalc(), hair_step(), ParticleSettings::hair_step, i, ParticleSettings::id, ID_RECALC_PSYS_RESET, ParticleSystem::imat, initialize_all_particles(), invert_m4_m4(), LOOP_EXISTING_PARTICLES, ParticleSystemModifierData::mesh_final, ParticleSimulationData::ob, PAMAP_SIZE, PARS_NO_DISP, ParticleSystem::part, PART_FROM_VERT, PART_HAIR, PART_HAIR_REGROW, PART_PHYS_KEYED, PART_PHYS_NO, PARTICLE_DRAW_DATA_UPDATED, PARTICLE_P, particle_settings_free_local(), particle_settings_localize(), particles_fluid_step(), particles_has_bubble(), particles_has_flip(), particles_has_foam(), particles_has_spray(), particles_has_tracer(), ParticleSystem::pdd, ParticleSettings::phystype, ParticleSimulationData::psmd, PTCacheEdit::psmd_eval, ParticleSimulationData::psys, PTCacheEdit::psys, psys_check_enabled(), psys_count_keyed_targets(), PSYS_EDITED, PTCacheEdit::psys_eval, psys_frand(), psys_free_path_cache(), psys_get_current_display_percentage(), psys_get_modifier(), psys_get_texture(), PSYS_HAIR_DONE, PSYS_OB_ANIM_RESTORE, psys_orig_get(), psys_prepare_physics(), psys_reset(), PSYS_RESET_ALL, PSYS_SHARED_CACHES, psys_update_path_cache(), PT_CACHE_EDIT_UPDATE_PARTICLE_FROM_EVAL, ParticleSettings::randsize, ParticleSystem::recalc, reset_particle(), save_hair(), ParticleSimulationData::scene, set_keyed_keys(), ParticleData::size, ParticleSettings::size, ParticleTexture::size, system_step(), ParticleSettings::totpart, ParticleSystem::totpart, ParticleSystem::totunexist, and ParticleSettings::type.

Referenced by BKE_object_handle_data_update(), and deform_verts().

◆ particles_are_dynamic()

◆ particles_fluid_step()

void particles_fluid_step ( ParticleSimulationData * sim,
int cfra,
const bool use_render_params )
static

Definition at line 4165 of file particle_system.cc.

References add_v3_v3(), add_v3_v3v3(), ParticleData::alive, ParticleKey::ave, BKE_modifiers_findby_type(), BLI_rng_free(), BLI_rng_get_double(), BLI_rng_new_srandom(), BLI_snprintf(), FluidDomainSettings::cell_size, ParticleKey::co, copy_v3_v3(), ParticleData::dietime, ParticleSettings::disp, FluidModifierData::domain, FluidDomainSettings::dx, RenderData::efra, eModifierType_Fluid, ParticleSettings::end, fabsf, float, FluidDomainSettings::fluid, FLUID_DOMAIN_PARTICLE_BUBBLE, FLUID_DOMAIN_PARTICLE_FLIP, FLUID_DOMAIN_PARTICLE_FOAM, FLUID_DOMAIN_PARTICLE_SPRAY, FLUID_DOMAIN_PARTICLE_TRACER, ParticleData::lifetime, ParticleSettings::lifetime, madd_v3fl_v3fl_v3fl_v3i(), manta_get_res_x(), manta_get_res_y(), manta_get_res_z(), manta_liquid_get_flip_particle_flag_at(), manta_liquid_get_flip_particle_position_x_at(), manta_liquid_get_flip_particle_position_y_at(), manta_liquid_get_flip_particle_position_z_at(), manta_liquid_get_flip_particle_velocity_x_at(), manta_liquid_get_flip_particle_velocity_y_at(), manta_liquid_get_flip_particle_velocity_z_at(), manta_liquid_get_num_flip_particles(), manta_liquid_get_num_snd_particles(), manta_liquid_get_particle_res_x(), manta_liquid_get_particle_res_y(), manta_liquid_get_particle_res_z(), manta_liquid_get_particle_upres(), manta_liquid_get_snd_particle_flag_at(), manta_liquid_get_snd_particle_position_x_at(), manta_liquid_get_snd_particle_position_y_at(), manta_liquid_get_snd_particle_position_z_at(), manta_liquid_get_snd_particle_velocity_x_at(), manta_liquid_get_snd_particle_velocity_y_at(), manta_liquid_get_snd_particle_velocity_z_at(), max, MEM_freeN(), min, mul_m4_v3(), mul_v3_fl(), mul_v3_v3(), ParticleSimulationData::ob, FluidDomainSettings::p0, FluidDomainSettings::p1, PARS_ALIVE, ParticleSystem::part, PART_FLUID_FLIP, FluidDomainSettings::particle_type, PARTICLE_TYPE_BUBBLE, PARTICLE_TYPE_DELETE, PARTICLE_TYPE_FOAM, PARTICLE_TYPE_SPRAY, PARTICLE_TYPE_TRACER, ParticleSystem::particles, particles_has_bubble(), particles_has_flip(), particles_has_foam(), particles_has_spray(), particles_has_tracer(), printf, ParticleSimulationData::psys, psys_frand(), Scene::r, ParticleSettings::randsize, realloc_particles(), FluidDomainSettings::res_max, FluidDomainSettings::res_min, ParticleSimulationData::rng, ParticleKey::rot, Object::scale, ParticleSimulationData::scene, ParticleSystem::seed, ParticleData::size, ParticleSettings::size, size(), ParticleSettings::sta, ParticleData::state, sub_v3_v3(), sub_v3_v3v3(), ParticleData::time, ParticleSettings::totpart, ParticleSystem::totpart, ParticleSettings::type, unit_qt(), UNUSED_VARS, ParticleKey::vel, and zero_v3().

Referenced by particle_system_update().

◆ particles_has_bubble()

bool particles_has_bubble ( short parttype)
static

◆ particles_has_flip()

bool particles_has_flip ( short parttype)
static

Definition at line 4140 of file particle_system.cc.

References PART_FLUID_FLIP.

Referenced by particle_system_update(), and particles_fluid_step().

◆ particles_has_foam()

bool particles_has_foam ( short parttype)
static

◆ particles_has_spray()

bool particles_has_spray ( short parttype)
static

◆ particles_has_tracer()

bool particles_has_tracer ( short parttype)
static

Definition at line 4145 of file particle_system.cc.

References PART_FLUID_TRACER.

Referenced by particle_system_update(), and particles_fluid_step().

◆ particlesystem_modifiersForeachIDLink()

void particlesystem_modifiersForeachIDLink ( void * user_data,
Object * ,
ID ** id_pointer,
const LibraryForeachIDCallbackFlag cb_flag )
static

Definition at line 4988 of file particle_system.cc.

References data.

Referenced by BKE_particlesystem_id_loop().

◆ psys_calc_dmcache()

◆ psys_changed_type()

◆ psys_check_boid_data()

◆ psys_clear_temp_pointcache()

void psys_clear_temp_pointcache ( ParticleSystem * psys)
static

◆ psys_count_keyed_targets()

◆ psys_get_birth_coords()

void psys_get_birth_coords ( ParticleSimulationData * sim,
ParticleData * pa,
ParticleKey * state,
float dtime,
float cfra )

Definition at line 699 of file particle_system.cc.

References ParticleSettings::avefac, ParticleSettings::avemode, axis_angle_to_quat(), BLI_assert, ParticleData::boid, copy_qt_qt(), copy_v3_v3(), cosf, cross_v3_v3v3(), dot_v3v3(), fabsf, ParticleData::foffset, ParticleSettings::from, ParticleData::fuv, get_angular_velocity_vector(), interp_qt_qtqt(), invert_qt_qt_normalized(), ParticleTexture::ivel, M_PI, madd_v3_v3fl(), mat3_to_quat(), mat3_to_quat_legacy(), mat4_to_quat(), mul_m4_v3(), mul_mat3_m4_v3(), mul_qt_qtqt(), mul_qt_v3(), mul_v3_fl(), mul_v3_v3fl(), negate_v3(), negate_v3_v3(), nor, normalize_qt(), normalize_v3(), normalize_v3_v3(), ParticleSettings::normfac, ParticleData::num, ParticleData::num_dmcache, ParticleSimulationData::ob, OB_POSX, OB_POSZ, ParticleSettings::ob_vel, ParticleSettings::obfac, PAMAP_IVEL, ParticleSystem::part, PART_AVE_RAND, PART_PHYS_BOIDS, PART_ROT_GLOB_X, PART_ROT_GLOB_Y, PART_ROT_GLOB_Z, PART_ROT_NOR, PART_ROT_NOR_TAN, PART_ROT_OB_X, PART_ROT_OB_Y, PART_ROT_OB_Z, PART_ROT_VEL, ParticleSettings::partfac, ParticleSystem::particles, ParticleSettings::phasefac, ParticleSettings::phystype, ParticleData::prev_state, project_v3_v3v3(), ParticleSimulationData::psmd, ParticleSimulationData::psys, psys_frand(), psys_get_texture(), psys_particle_on_emitter(), psys_particle_value_from_verts(), ParticleSettings::randfac, ParticleSettings::randphasefac, ParticleSettings::randrotfac, rot, ParticleSettings::rotmode, sinf, ParticleData::state, state, sub_v3_v3(), sub_v3_v3v3(), ParticleSettings::tanfac, ParticleSettings::tanphase, unit_qt(), vec_to_quat(), ParticleKey::vel, and zero_v3().

Referenced by explodeMesh(), and reset_particle().

◆ psys_get_child_number()

◆ psys_get_current_display_percentage()

◆ psys_get_pointcache_start_end()

void psys_get_pointcache_start_end ( Scene * scene,
ParticleSystem * psys,
int * sfra,
int * efra )

◆ psys_get_target_system()

◆ psys_get_tot_child()

int psys_get_tot_child ( Scene * scene,
ParticleSystem * psys,
const bool use_render_params )

◆ psys_hair_use_simulation()

bool psys_hair_use_simulation ( ParticleData * pa,
float max_length )
static

◆ psys_make_temp_pointcache()

◆ psys_prepare_physics()

◆ psys_reset()

◆ psys_sph_density()

◆ psys_sph_finalize()

void psys_sph_finalize ( SPHData * sphdata)

Definition at line 2158 of file particle_system.cc.

References psys_sph_flush_springs().

Referenced by dynamics_step().

◆ psys_sph_flush_springs()

◆ psys_sph_init()

◆ psys_tasks_create()

◆ psys_tasks_free()

◆ psys_thread_context_free()

◆ psys_thread_context_init()

◆ psys_unique_name()

void psys_unique_name ( Object * object,
ParticleSystem * psys,
const char * defname )

◆ psys_update_effectors()

◆ psys_update_particle_bvhtree()

◆ psys_update_particle_tree()

void psys_update_particle_tree ( ParticleSystem * psys,
float cfra )

◆ psys_update_path_cache()

◆ realloc_particles()

◆ reset_all_particles()

void reset_all_particles ( ParticleSimulationData * sim,
float dtime,
float cfra,
int from )
static

◆ reset_particle()

◆ save_hair()

◆ set_keyed_keys()

◆ sph_density_accum_cb()

◆ sph_evaluate_func()

◆ sph_force_cb()

void sph_force_cb ( void * sphdata_v,
ParticleKey * state,
float * force,
float *  )
static

Definition at line 1775 of file particle_system.cc.

References Vector< T, InlineBufferCapacity, Allocator >::append(), SPHFluidSettings::buoyancy, ParticleKey::co, copy_v3_v3(), data, SPHRangeData::data, ParticleSpring::delete_flag, dot_v3v3(), SPHData::eh, ParticleSettings::flag, SPHFluidSettings::flag, ParticleSettings::fluid, ParticleSystem::fluid_springs, SPHData::gravity, SPHRangeData::h, SPHData::hfac, i, SPHNeighbor::index, blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_default(), madd_v3_v3fl(), madd_v3_v3v3fl(), ParticleSettings::mass, SPHData::mass, SPHRangeData::mass, SPHRangeData::neighbors, SPHData::new_springs, normalize_v3(), SPHData::pa, SPHRangeData::pa, ParticleSystem::part, PART_SIZEMASS, PART_TIME_AUTOSF, ParticleSpring::particle_index, ParticleSystem::particles, SPHData::pass, ParticleData::prev_state, SPHData::psys, SPHNeighbor::psys, SPHFluidSettings::radius, SPHFluidSettings::rest_density, ParticleSpring::rest_length, SPHFluidSettings::rest_length, ParticleData::size, SPH_CURRENT_REST_LENGTH, sph_density_accum_cb(), sph_evaluate_func(), SPH_FAC_DENSITY, SPH_FAC_RADIUS, SPH_FAC_REPULSION, SPH_FAC_REST_LENGTH, SPH_FAC_VISCOSITY, sph_particle_courant(), SPH_VISCOELASTIC_SPRINGS, SPHFluidSettings::spring_frames, SPHFluidSettings::spring_k, state, SPHFluidSettings::stiffness_k, SPHFluidSettings::stiffness_knear, sub_v3_v3v3(), ParticleData::time, ParticleKey::time, ParticleSettings::time_flag, SPHRangeData::tot_neighbors, ParticleKey::vel, SPHFluidSettings::viscosity_beta, and SPHFluidSettings::viscosity_omega.

Referenced by psys_sph_init().

◆ sph_integrate()

◆ sph_particle_courant()

◆ sph_spring_add()

◆ sph_spring_delete()

◆ sph_springhash_build()

◆ sph_springs_modify()

◆ sphclassical_calc_dens()

◆ sphclassical_density_accum_cb()

◆ sphclassical_force_cb()

◆ sphclassical_neighbor_accum_cb()

void sphclassical_neighbor_accum_cb ( void * userdata,
int index,
const float co[3],
float  )
static

◆ sync_timestep()

float sync_timestep ( ParticleSystem * psys,
float t_frac )
static

Definition at line 3671 of file particle_system.cc.

References ParticleSystem::dt_frac, and TIMESTEP_EXPANSION_TOLERANCE.

Referenced by system_step().

◆ system_step()

void system_step ( ParticleSimulationData * sim,
float cfra,
const bool use_render_params )
static

Calculates the next state for all particles of the system. In particles code most 'cfra - ending' are frames, 'time - ending' are 'cfra * timestep' (seconds).

  1. Emit particles
  2. Check cache (if used) and return if frame is cached
  3. Do dynamics
  4. Save to cache

Definition at line 4465 of file particle_system.cc.

References ParticleSystem::alloc_fluidsprings, BKE_ptcache_id_clear(), BKE_ptcache_id_from_particles(), BKE_ptcache_id_reset(), BKE_ptcache_id_time(), BKE_ptcache_invalidate(), BKE_ptcache_read(), BKE_ptcache_validate(), BKE_ptcache_write(), cached_step(), ParticleSystem::cfra, CLAMP, ParticleSimulationData::courant_num, distribute_particles(), ParticleSystem::dt_frac, dynamics_step(), ELEM, emit_particles(), PointCache::endframe, eParticleSystemFlag_Pars, ParticleData::flag, ParticleSystemModifierData::flag, PointCache::flag, float, ParticleSystem::fluid_springs, free_unexisting_particles(), ParticleSettings::from, get_base_time_step(), ID_RECALC_PSYS_RESET, initialize_all_particles(), PointCache::last_exact, LOOP_PARTICLES, MEM_SAFE_FREE, MIN_TIMESTEP, ParticleSimulationData::ob, PARS_NO_DISP, ParticleSystem::part, PART_HAIR, PART_TIME_AUTOSF, PARTICLE_P, ParticleSystem::pointcache, ParticleSimulationData::psmd, ParticleSimulationData::psys, psys_clear_temp_pointcache(), psys_frand(), psys_get_current_display_percentage(), psys_get_pointcache_start_end(), psys_reset(), PSYS_RESET_CACHE_MISS, psys_sim_data_free(), psys_update_path_cache(), PTCACHE_BAKED, PTCACHE_BAKING, PTCACHE_CLEAR_AFTER, PTCACHE_OUTDATED, PTCACHE_READ_EXACT, PTCACHE_READ_INTERPOLATED, PTCACHE_READ_OLD, PTCACHE_REDO_NEEDED, PTCACHE_RESET_OUTDATED, ParticleSystem::recalc, reset_all_particles(), ParticleSimulationData::scene, PointCache::simframe, ParticleSettings::sta, PointCache::startframe, sync_timestep(), ParticleSettings::time_flag, ParticleSystem::tot_fluidsprings, ParticleSystem::totpart, ParticleSettings::type, update_children(), and update_timestep().

Referenced by particle_system_update().

◆ tot_particles()

◆ update_children()

◆ update_courant_num()

void update_courant_num ( ParticleSimulationData * sim,
ParticleData * pa,
float dtime,
SPHData * sphdata,
SpinLock * spin )
static

Calculate the speed of the particle relative to the local scale of the simulation. This should be called once per particle during a simulation step, after the velocity has been updated. element_size defines the scale of the simulation, and is typically the distance to neighboring particles.

Definition at line 3624 of file particle_system.cc.

References BLI_spin_lock(), BLI_spin_unlock(), ParticleSimulationData::courant_num, SPHData::element_size, SPHData::flow, len_v3(), ParticleData::prev_state, sub_v3_v3v3(), and ParticleKey::vel.

Referenced by dynamics_step_sph_classical_integrate_task_cb_ex(), and dynamics_step_sph_ddr_task_cb_ex().

◆ update_timestep()

Variable Documentation

◆ MIN_TIMESTEP

const float MIN_TIMESTEP = 1.0f / 101.0f
static

Code for an adaptive time step based on the Courant-Friedrichs-Lewy condition.

Definition at line 3610 of file particle_system.cc.

Referenced by system_step(), and update_timestep().

◆ psys_bvhtree_rwlock

ThreadRWMutex psys_bvhtree_rwlock = BLI_RWLOCK_INITIALIZER
static

Definition at line 74 of file particle_system.cc.

Referenced by psys_update_particle_bvhtree(), and sph_evaluate_func().

◆ TIMESTEP_EXPANSION_FACTOR

const float TIMESTEP_EXPANSION_FACTOR = 0.1f
static

Tolerance of 1.5 means the last sub-frame neither favors growing nor shrinking (e.g if it were 1.3, the last sub-frame would tend to be too small).

Definition at line 3615 of file particle_system.cc.

Referenced by update_timestep().

◆ TIMESTEP_EXPANSION_TOLERANCE

const float TIMESTEP_EXPANSION_TOLERANCE = 1.5f
static

Definition at line 3616 of file particle_system.cc.

Referenced by sync_timestep().