Blender V4.3
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_blenlib.h"
#include "BLI_kdopbvh.h"
#include "BLI_kdtree.h"
#include "BLI_linklist.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_utils.hh"
#include "BLI_task.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#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.h"
#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)
 
void psys_tasks_create (ParticleThreadContext *ctx, int startpart, int endpart, ParticleTask **r_tasks, int *r_numtasks)
 
void psys_tasks_free (ParticleTask *tasks, int numtasks)
 
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 void dynamics_step_sphdata_reduce (const void *__restrict, void *__restrict join_v, void *__restrict chunk_v)
 
static void dynamics_step_sph_ddr_task_cb_ex (void *__restrict userdata, const int p, const TaskParallelTLS *__restrict tls)
 
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, int 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, intsph_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)
 
void psys_sph_init (ParticleSimulationData *sim, SPHData *sphdata)
 
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 2396 of file particle_system.cc.

Referenced by collision_newton_rhapson().

◆ COLLISION_MIN_DISTANCE

#define COLLISION_MIN_DISTANCE   0.0001f

Definition at line 2394 of file particle_system.cc.

Referenced by collision_response().

◆ COLLISION_MIN_RADIUS

#define COLLISION_MIN_RADIUS   0.001f

Definition at line 2393 of file particle_system.cc.

Referenced by collision_check().

◆ COLLISION_ZERO

#define COLLISION_ZERO   0.00001f

Definition at line 2395 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 1570 of file particle_system.cc.

Referenced by sph_spring_add(), and sph_spring_delete().

◆ SPH_NEIGHBORS

#define SPH_NEIGHBORS   512

Definition at line 1673 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)
draw_view in_light_buf[] float
Frequency::GEOMETRY nor[]

Definition at line 2397 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()

static void bvhtree_balance_isolated ( void * userdata)
static

Definition at line 1317 of file particle_system.cc.

References BLI_bvhtree_balance().

Referenced by psys_update_particle_bvhtree().

◆ cached_step()

◆ collision_check()

◆ collision_detect()

◆ collision_fail()

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

◆ collision_interpolate_element()

static void collision_interpolate_element ( ParticleCollisionElement * pce,
float t,
float fac,
ParticleCollision * col )
static
Parameters
tis the current time for newton rhapson.
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 2461 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()

static void dynamics_step ( ParticleSimulationData * sim,
float cfra )
static

Definition at line 3841 of file particle_system.cc.

References ParticleData::alive, basic_integrate(), basic_rotate(), BKE_collider_cache_create(), BKE_collider_cache_free(), BLI_findlink(), BLI_parallel_range_settings_defaults(), BLI_rng_free(), BLI_rng_new_srandom(), BLI_spin_end(), BLI_spin_init(), BLI_task_parallel_range(), boid_body(), boid_brain(), boids_precalc_rules(), BoidBrainData::cfra, ParticleSystem::cfra, ParticleSimulationData::colliders, collision_check(), copy_particle_key(), ParticleSimulationData::depsgraph, BoidBrainData::dfra, ParticleData::dietime, 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_sph_ddr_task_cb_ex(), dynamics_step_sphdata_reduce(), ELEM, ListBase::first, ParticleData::flag, BoidBrainData::goal_ob, LOOP_DYNAMIC_PARTICLES, LOOP_EXISTING_PARTICLES, LOOP_SHOWN_PARTICLES, ParticleTarget::next, ParticleSimulationData::ob, ParticleTarget::ob, PAMAP_SIZE, PARS_ALIVE, PARS_DEAD, 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, 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(), reset_particle(), BoidBrainData::rng, ParticleSimulationData::rng, ParticleSystem::seed, BoidBrainData::sim, DynamicStepSolverTaskData::sim, ParticleData::size, ParticleTexture::size, SPH_SOLVER_DDR, sph_springs_modify(), ParticleData::state, PointCache::step, ParticleSystem::targets, ParticleData::time, ParticleKey::time, BoidBrainData::timestep, and ParticleSystem::totpart.

Referenced by system_step().

◆ dynamics_step_sph_classical_basic_integrate_task_cb_ex()

static 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()

static 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()

static 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()

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

◆ dynamics_step_sphdata_reduce()

static void dynamics_step_sphdata_reduce ( const void * __restrict,
void *__restrict join_v,
void *__restrict chunk_v )
static

◆ emit_particles()

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

◆ evaluate_emitter_anim()

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

◆ free_unexisting_particles()

◆ get_angular_velocity_vector()

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

◆ get_base_time_step()

static float get_base_time_step ( ParticleSettings * part)
static

Definition at line 3660 of file particle_system.cc.

References float.

Referenced by system_step(), and update_timestep().

◆ hair_create_input_mesh()

◆ hair_needs_recalc()

◆ hair_set_pinning()

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

◆ hair_step()

◆ init_particle()

void init_particle ( struct ParticleSimulationData * sim,
struct ParticleData * pa )

Set particle parameters that don't change during particle's life.

Definition at line 576 of file particle_system.cc.

References ParticleData::flag, float, ParticleData::hair_index, ParticleSystem::part, ParticleSystem::particles, ParticleSimulationData::psys, ParticleData::time, and ParticleSystem::totpart.

Referenced by brush_add(), and initialize_all_particles().

◆ init_particle_texture()

◆ initialize_all_particles()

◆ integrate_particle()

◆ nr_distance_to_edge()

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

◆ nr_distance_to_vert()

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

Definition at line 2448 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()

static void particle_settings_free_local ( ParticleSettings * particle_settings)
static

◆ particle_settings_localize()

static ParticleSettings * particle_settings_localize ( ParticleSettings * particle_settings)
static

Definition at line 4777 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 4792 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, ParticleSystem::flag, ParticleSystemModifierData::flag, PTCacheEdit::flags, float, ParticleSystem::free_edit, free_hair(), free_keyed_keys(), free_unexisting_particles(), hair_needs_recalc(), hair_step(), ParticleSettings::hair_step, 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_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, 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_update_path_cache(), PT_CACHE_EDIT_UPDATE_PARTICLE_FROM_EVAL, ParticleSystem::recalc, reset_particle(), save_hair(), ParticleSimulationData::scene, scene, set_keyed_keys(), ParticleData::size, ParticleTexture::size, system_step(), ParticleSettings::totpart, ParticleSystem::totpart, and ParticleSystem::totunexist.

Referenced by BKE_object_handle_data_update(), and deform_verts().

◆ particles_are_dynamic()

◆ particles_fluid_step()

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

Definition at line 4196 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, FluidModifierData::domain, double(), FluidDomainSettings::dx, RenderData::efra, eModifierType_Fluid, 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, 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(), 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, realloc_particles(), FluidDomainSettings::res_max, FluidDomainSettings::res_min, ParticleSimulationData::rng, ParticleKey::rot, Object::scale, ParticleSimulationData::scene, ParticleSystem::seed, ParticleData::size, ParticleData::state, sub_v3_v3(), sub_v3_v3v3(), ParticleData::time, ParticleSystem::totpart, unit_qt(), UNUSED_VARS, ParticleKey::vel, and zero_v3().

Referenced by particle_system_update().

◆ particles_has_bubble()

static bool particles_has_bubble ( short parttype)
static

◆ particles_has_flip()

static bool particles_has_flip ( short parttype)
static

Definition at line 4171 of file particle_system.cc.

References PART_FLUID_FLIP.

Referenced by particle_system_update(), and particles_fluid_step().

◆ particles_has_foam()

static bool particles_has_foam ( short parttype)
static

◆ particles_has_spray()

static bool particles_has_spray ( short parttype)
static

◆ particles_has_tracer()

static bool particles_has_tracer ( short parttype)
static

Definition at line 4176 of file particle_system.cc.

References PART_FLUID_TRACER.

Referenced by particle_system_update(), and particles_fluid_step().

◆ particlesystem_modifiersForeachIDLink()

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

Definition at line 5020 of file particle_system.cc.

References ParticleSystemIDLoopForModifier::func.

Referenced by BKE_particlesystem_id_loop().

◆ psys_calc_dmcache()

◆ psys_changed_type()

◆ psys_check_boid_data()

◆ psys_clear_temp_pointcache()

static void psys_clear_temp_pointcache ( ParticleSystem * psys)
static

◆ psys_count_keyed_targets()

◆ psys_get_birth_coords()

◆ psys_get_child_number()

◆ psys_get_current_display_percentage()

float psys_get_current_display_percentage ( ParticleSystem * psys,
const bool use_render_params )

◆ psys_get_pointcache_start_end()

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

Definition at line 1306 of file particle_system.cc.

References max_ii(), min_ii(), and ParticleSystem::part.

Referenced by BKE_ptcache_bake(), and system_step().

◆ 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()

static bool psys_hair_use_simulation ( ParticleData * pa,
float max_length )
static

Definition at line 3283 of file particle_system.cc.

References HairKey::co, ParticleData::hair, len_v3v3(), and ParticleData::totkey.

Referenced by hair_create_input_mesh().

◆ psys_make_temp_pointcache()

◆ psys_prepare_physics()

◆ psys_reset()

◆ psys_sph_density()

◆ psys_sph_finalize()

void psys_sph_finalize ( SPHData * sphdata)

Definition at line 2172 of file particle_system.cc.

References psys_sph_flush_springs().

Referenced by dynamics_step().

◆ psys_sph_flush_springs()

static void psys_sph_flush_springs ( SPHData * sphdata)
static

◆ psys_sph_init()

◆ psys_tasks_create()

void psys_tasks_create ( ParticleThreadContext * ctx,
int startpart,
int endpart,
ParticleTask ** r_tasks,
int * r_numtasks )

◆ psys_tasks_free()

void psys_tasks_free ( ParticleTask * tasks,
int numtasks )

Definition at line 478 of file particle_system.cc.

References BLI_rng_free(), and MEM_freeN().

Referenced by distribute_particles_on_dm(), and psys_cache_child_paths().

◆ psys_thread_context_free()

◆ psys_thread_context_init()

◆ psys_unique_name()

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

Definition at line 164 of file particle_system.cc.

References BLI_uniquename(), ParticleSystem::name, and offsetof.

◆ 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()

static 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()

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

◆ 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()

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

◆ sync_timestep()

static float sync_timestep ( ParticleSystem * psys,
float t_frac )
static

Definition at line 3693 of file particle_system.cc.

References ParticleSystem::dt_frac, and TIMESTEP_EXPANSION_TOLERANCE.

Referenced by system_step().

◆ system_step()

static 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 4496 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(), get_base_time_step(), ID_RECALC_PSYS_RESET, initialize_all_particles(), int, 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, PointCache::startframe, sync_timestep(), ParticleSystem::tot_fluidsprings, ParticleSystem::totpart, update_children(), and update_timestep().

Referenced by particle_system_update().

◆ tot_particles()

◆ update_children()

◆ update_courant_num()

static 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 3644 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, spin, 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 3630 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 72 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 3635 of file particle_system.cc.

Referenced by update_timestep().

◆ TIMESTEP_EXPANSION_TOLERANCE

const float TIMESTEP_EXPANSION_TOLERANCE = 1.5f
static

Definition at line 3636 of file particle_system.cc.

Referenced by sync_timestep().