Blender V5.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_kdopbvh.hh"
#include "BLI_kdtree.hh"
#include "BLI_linklist.hh"
#include "BLI_listbase.hh"
#include "BLI_math_base_safe.hh"
#include "BLI_math_matrix_c.hh"
#include "BLI_math_rotation_c.hh"
#include "BLI_math_vector_c.hh"
#include "BLI_rand_c.hh"
#include "BLI_string.hh"
#include "BLI_string_utils.hh"
#include "BLI_task_c.hh"
#include "BLI_threads.hh"
#include "BLI_utildefines.hh"
#include "BLI_vector.hh"
#include "BKE_animsys.hh"
#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  blender::SPHNeighbor
struct  blender::SPHRangeData
struct  blender::EfData
struct  blender::DynamicStepSolverTaskData
struct  blender::ParticleSystemIDLoopForModifier

Namespaces

namespace  blender
 BMesh Iterators.

Macros

#define ZERO_F43

Functions

Reacting to System Events
static int blender::particles_are_dynamic (ParticleSystem *psys)
float blender::psys_get_current_display_percentage (struct ParticleSystem *psys, bool use_render_params)
static int blender::tot_particles (ParticleSystem *psys, PTCacheID *pid)
void blender::psys_reset (struct ParticleSystem *psys, int mode)
void blender::psys_unique_name (struct Object *object, struct ParticleSystem *psys, const char *defname) ATTR_NONNULL(1
static void blender::realloc_particles (ParticleSimulationData *sim, int new_totpart)
int blender::psys_get_child_number (struct Scene *scene, struct ParticleSystem *psys, bool use_render_params)
int blender::psys_get_tot_child (struct Scene *scene, struct ParticleSystem *psys, bool use_render_params)
Distribution
void blender::psys_calc_dmcache (struct Object *ob, struct Mesh *mesh_final, struct Mesh *mesh_original, struct ParticleSystem *psys)
void blender::psys_thread_context_init (struct ParticleThreadContext *ctx, struct ParticleSimulationData *sim)
Vector< ParticleTask > blender::psys_tasks_create (struct ParticleThreadContext *ctx, int startpart, int endpart)
void blender::psys_tasks_free (Vector< ParticleTask > &tasks)
void blender::psys_thread_context_free (struct ParticleThreadContext *ctx)
static void blender::init_particle_texture (ParticleSimulationData *sim, ParticleData *pa, int p)
void blender::init_particle (struct ParticleSimulationData *sim, struct ParticleData *pa)
static void blender::initialize_all_particles (ParticleSimulationData *sim)
static void blender::free_unexisting_particles (ParticleSimulationData *sim)
static void blender::get_angular_velocity_vector (short avemode, ParticleKey *state, float vec[3])
void blender::psys_get_birth_coords (struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, float dtime, float cfra)
static void blender::evaluate_emitter_anim (Depsgraph *depsgraph, Scene *scene, Object *ob, float cfra)
void blender::reset_particle (struct ParticleSimulationData *sim, struct ParticleData *pa, float dtime, float cfra)
static void blender::reset_all_particles (ParticleSimulationData *sim, float dtime, float cfra, int from)
Particle Targets
struct ParticleSystem * blender::psys_get_target_system (struct Object *ob, struct ParticleTarget *pt)
Keyed Particles
void blender::psys_count_keyed_targets (struct ParticleSimulationData *sim)
static void blender::set_keyed_keys (ParticleSimulationData *sim)
Point Cache
void blender::psys_make_temp_pointcache (struct Object *ob, struct ParticleSystem *psys)
static void blender::psys_clear_temp_pointcache (ParticleSystem *psys)
void blender::psys_get_pointcache_start_end (struct Scene *scene, ParticleSystem *psys, int *sfra, int *efra)
static void blender::bvhtree_balance_isolated (void *userdata)
Effectors
static void blender::psys_update_particle_bvhtree (ParticleSystem *psys, float cfra)
void blender::psys_update_particle_tree (struct ParticleSystem *psys, float cfra)
static void blender::psys_update_effectors (ParticleSimulationData *sim)
static void blender::integrate_particle (ParticleSettings *part, ParticleData *pa, float dtime, float *external_acceleration, void(*force_func)(void *forcedata, ParticleKey *state, float *force, float *impulse), void *forcedata)
Basic Physics
static void blender::basic_force_cb (void *efdata_v, ParticleKey *state, float *force, float *impulse)
static void blender::basic_integrate (ParticleSimulationData *sim, int p, float dfra, float cfra)
static void blender::basic_rotate (ParticleSettings *part, ParticleData *pa, float dfra, float timestep)
System Core
static SPHData blender::dynamics_step_sphdata_reduce (const SPHData &sphdata_to, const SPHData &sphdata_from)
static void blender::dynamics_step_sph_ddr_task_cb_ex (DynamicStepSolverTaskData *data, const int p, SPHData *sphdata)
static void blender::dynamics_step_sph_classical_basic_integrate_task_cb_ex (void *__restrict userdata, const int p, const TaskParallelTLS *__restrict)
static void blender::dynamics_step_sph_classical_calc_density_task_cb_ex (void *__restrict userdata, const int p, const TaskParallelTLS *__restrict tls)
static void blender::dynamics_step_sph_classical_integrate_task_cb_ex (void *__restrict userdata, const int p, const TaskParallelTLS *__restrict tls)
static void blender::dynamics_step (ParticleSimulationData *sim, float cfra)
static void blender::update_children (ParticleSimulationData *sim, const bool use_render_params)
static void blender::cached_step (ParticleSimulationData *sim, float cfra, const bool use_render_params)
static bool blender::particles_has_flip (short parttype)
static bool blender::particles_has_tracer (short parttype)
static bool blender::particles_has_spray (short parttype)
static bool blender::particles_has_bubble (short parttype)
static bool blender::particles_has_foam (short parttype)
static void blender::particles_fluid_step (ParticleSimulationData *sim, int cfra, const bool use_render_params)
static int blender::emit_particles (ParticleSimulationData *sim, PTCacheID *pid, float)
static void blender::system_step (ParticleSimulationData *sim, float cfra, const bool use_render_params)
void blender::psys_changed_type (struct Object *ob, struct ParticleSystem *psys)
void blender::psys_check_boid_data (struct ParticleSystem *psys)
void blender::BKE_particlesettings_fluid_default_settings (struct ParticleSettings *part)
static void blender::psys_prepare_physics (ParticleSimulationData *sim)
static int blender::hair_needs_recalc (ParticleSystem *psys)
static ParticleSettings * blender::particle_settings_localize (ParticleSettings *particle_settings)
static void blender::particle_settings_free_local (ParticleSettings *particle_settings)
void blender::particle_system_update (struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
static void blender::particlesystem_modifiersForeachIDLink (void *user_data, Object *, ID **id_pointer, const LibraryForeachIDCallbackFlag cb_flag)
void blender::BKE_particlesystem_id_loop (struct ParticleSystem *psys, ParticleSystemIDFunc func, void *userdata)
void blender::BKE_particlesystem_reset_all (struct Object *object)
Depsgraph evaluation
void blender::BKE_particle_settings_eval_reset (struct Depsgraph *depsgraph, struct ParticleSettings *particle_settings)
void blender::BKE_particle_system_eval_init (struct Depsgraph *depsgraph, struct Object *object)

Variables

static ThreadRWMutex blender::psys_bvhtree_rwlock = BLI_RWLOCK_INITIALIZER

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

Collisions

The algorithm is roughly:

  1. Use a BVH tree to search for faces that a particle may collide with.
  2. Use Newton's method to find the exact time at which the collision occurs. https://en.wikipedia.org/wiki/Newton's_method
#define COLLISION_MIN_RADIUS   0.001f
#define COLLISION_MIN_DISTANCE   0.0001f
#define COLLISION_ZERO   0.00001f
#define COLLISION_INIT_STEP   0.00008f
using blender::NRDistanceFunc
static float blender::nr_signed_distance_to_plane (float *p, float radius, ParticleCollisionElement *pce, float *nor)
static float blender::nr_distance_to_edge (float *p, float radius, ParticleCollisionElement *pce, float *)
static float blender::nr_distance_to_vert (float *p, float radius, ParticleCollisionElement *pce, float *)
static void blender::collision_interpolate_element (ParticleCollisionElement *pce, float t, float fac, ParticleCollision *col)
static void blender::collision_point_velocity (ParticleCollisionElement *pce)
static float blender::collision_point_distance_with_normal (float p[3], ParticleCollisionElement *pce, float fac, ParticleCollision *col, float *nor)
static void blender::collision_point_on_surface (const float p[3], ParticleCollisionElement *pce, float fac, ParticleCollision *col, float *co)
static float blender::collision_newton_rhapson (ParticleCollision *col, float radius, ParticleCollisionElement *pce, NRDistanceFunc distance_func)
static int blender::collision_sphere_to_tri (ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
static int blender::collision_sphere_to_edges (ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
static int blender::collision_sphere_to_verts (ParticleCollision *col, float radius, ParticleCollisionElement *pce, float *t)
void blender::BKE_psys_collision_neartest_cb (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
static int blender::collision_detect (ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, ListBaseT< ColliderCache > *colliders)
static int blender::collision_response (ParticleSimulationData *sim, ParticleData *pa, ParticleCollision *col, BVHTreeRayHit *hit, int kill, int dynamic_rotation)
static void blender::collision_fail (ParticleData *pa, ParticleCollision *col)
static void blender::collision_check (ParticleSimulationData *sim, int p, float dfra, float cfra)

Hair

static const float blender::MIN_TIMESTEP = 1.0f / 101.0f
static const float blender::TIMESTEP_EXPANSION_FACTOR = 0.1f
static const float blender::TIMESTEP_EXPANSION_TOLERANCE = 1.5f
static void blender::psys_update_path_cache (ParticleSimulationData *sim, float cfra, const bool use_render_params)
static bool blender::psys_hair_use_simulation (ParticleData *pa, float max_length)
static MDeformVert * blender::hair_set_pinning (MDeformVert *dvert, float weight)
static void blender::hair_create_input_mesh (ParticleSimulationData *sim, int totpoint, int totedge, Mesh **r_mesh)
static void blender::do_hair_dynamics (ParticleSimulationData *sim)
static void blender::hair_step (ParticleSimulationData *sim, float cfra, const bool use_render_params)
static void blender::save_hair (ParticleSimulationData *sim, float)
static void blender::update_courant_num (ParticleSimulationData *sim, ParticleData *pa, float dtime, SPHData *sphdata, SpinLock *spin)
static float blender::get_base_time_step (ParticleSettings *part)
static void blender::update_timestep (ParticleSystem *psys, ParticleSimulationData *sim)
static float blender::sync_timestep (ParticleSystem *psys, float t_frac)

Macro Definition Documentation

◆ COLLISION_INIT_STEP

#define COLLISION_INIT_STEP   0.00008f

Definition at line 2395 of file particle_system.cc.

Referenced by blender::collision_newton_rhapson().

◆ COLLISION_MIN_DISTANCE

#define COLLISION_MIN_DISTANCE   0.0001f

Definition at line 2393 of file particle_system.cc.

Referenced by blender::collision_response().

◆ COLLISION_MIN_RADIUS

#define COLLISION_MIN_RADIUS   0.001f

Definition at line 2392 of file particle_system.cc.

Referenced by blender::collision_check().

◆ COLLISION_ZERO

#define COLLISION_ZERO   0.00001f

Definition at line 2394 of file particle_system.cc.

Referenced by blender::collision_newton_rhapson().

◆ PSYS_FLUID_SPRINGS_INITIAL_SIZE

#define PSYS_FLUID_SPRINGS_INITIAL_SIZE   256

Definition at line 1569 of file particle_system.cc.

Referenced by blender::sph_spring_add(), and blender::sph_spring_delete().

◆ SPH_NEIGHBORS

#define SPH_NEIGHBORS   512

◆ 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 blender::integrate_particle().