Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/particle_system.c')
-rw-r--r--source/blender/blenkernel/intern/particle_system.c626
1 files changed, 417 insertions, 209 deletions
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index bf34e98c482..38183f97b72 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -102,13 +102,16 @@ static ThreadRWMutex psys_bvhtree_rwlock = BLI_RWLOCK_INITIALIZER;
static int particles_are_dynamic(ParticleSystem *psys)
{
- if (psys->pointcache->flag & PTCACHE_BAKED)
+ if (psys->pointcache->flag & PTCACHE_BAKED) {
return 0;
+ }
- if (psys->part->type == PART_HAIR)
+ if (psys->part->type == PART_HAIR) {
return psys->flag & PSYS_HAIR_DYNAMICS;
- else
+ }
+ else {
return ELEM(psys->part->phystype, PART_PHYS_NEWTON, PART_PHYS_BOIDS, PART_PHYS_FLUID);
+ }
}
float psys_get_current_display_percentage(ParticleSystem *psys, const bool use_render_params)
@@ -128,12 +131,15 @@ float psys_get_current_display_percentage(ParticleSystem *psys, const bool use_r
static int tot_particles(ParticleSystem *psys, PTCacheID *pid)
{
- if (pid && psys->pointcache->flag & PTCACHE_EXTERNAL)
+ if (pid && psys->pointcache->flag & PTCACHE_EXTERNAL) {
return pid->cache->totpoint;
- else if (psys->part->distr == PART_DISTR_GRID && psys->part->from != PART_FROM_VERT)
+ }
+ else if (psys->part->distr == PART_DISTR_GRID && psys->part->from != PART_FROM_VERT) {
return psys->part->grid_res * psys->part->grid_res * psys->part->grid_res - psys->totunexist;
- else
+ }
+ else {
return psys->part->totpart - psys->totunexist;
+ }
}
void psys_reset(ParticleSystem *psys, int mode)
@@ -212,11 +218,13 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
totpart = part->grid_res;
totpart *= totpart * totpart;
}
- else
+ else {
totpart = part->totpart;
+ }
}
- else
+ else {
totpart = new_totpart;
+ }
if (totpart != psys->totpart) {
if (psys->edit && psys->free_edit) {
@@ -227,16 +235,18 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
if (totpart) {
newpars = MEM_callocN(totpart * sizeof(ParticleData), "particles");
- if (newpars == NULL)
+ if (newpars == NULL) {
return;
+ }
if (psys->part->phystype == PART_PHYS_BOIDS) {
newboids = MEM_callocN(totpart * sizeof(BoidParticle), "boid particles");
if (newboids == NULL) {
/* allocation error! */
- if (newpars)
+ if (newpars) {
MEM_freeN(newpars);
+ }
return;
}
}
@@ -248,15 +258,18 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
if (totsaved) {
memcpy(newpars, psys->particles, totsaved * sizeof(ParticleData));
- if (psys->particles->boid)
+ if (psys->particles->boid) {
memcpy(newboids, psys->particles->boid, totsaved * sizeof(BoidParticle));
+ }
}
- if (psys->particles->keys)
+ if (psys->particles->keys) {
MEM_freeN(psys->particles->keys);
+ }
- if (psys->particles->boid)
+ if (psys->particles->boid) {
MEM_freeN(psys->particles->boid);
+ }
for (p = 0, pa = newpars; p < totsaved; p++, pa++) {
if (pa->keys) {
@@ -265,9 +278,11 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
}
}
- for (p = totsaved, pa = psys->particles + totsaved; p < psys->totpart; p++, pa++)
- if (pa->hair)
+ for (p = totsaved, pa = psys->particles + totsaved; p < psys->totpart; p++, pa++) {
+ if (pa->hair) {
MEM_freeN(pa->hair);
+ }
+ }
MEM_freeN(psys->particles);
psys_free_pdd(psys);
@@ -295,13 +310,16 @@ int psys_get_child_number(Scene *scene, ParticleSystem *psys, const bool use_ren
{
int nbr;
- if (!psys->part->childtype)
+ if (!psys->part->childtype) {
return 0;
+ }
- if (use_render_params)
+ if (use_render_params) {
nbr = psys->part->ren_child_nbr;
- else
+ }
+ else {
nbr = psys->part->child_nbr;
+ }
return get_render_child_particle_number(&scene->r, nbr, use_render_params);
}
@@ -406,17 +424,21 @@ void psys_calc_dmcache(Object *ob, Mesh *mesh_final, Mesh *mesh_original, Partic
}
if (use_modifier_stack) {
- if (pa->num < totelem)
+ if (pa->num < totelem) {
pa->num_dmcache = DMCACHE_ISCHILD;
- else
+ }
+ else {
pa->num_dmcache = DMCACHE_NOTFOUND;
+ }
}
else {
if (psys->part->from == PART_FROM_VERT) {
- if (pa->num < totelem && nodearray[pa->num])
+ if (pa->num < totelem && nodearray[pa->num]) {
pa->num_dmcache = POINTER_AS_INT(nodearray[pa->num]->link);
- else
+ }
+ else {
pa->num_dmcache = DMCACHE_NOTFOUND;
+ }
}
else { /* FROM_FACE/FROM_VOLUME */
pa->num_dmcache = psys_particle_dm_face_lookup(
@@ -488,10 +510,12 @@ void psys_tasks_free(ParticleTask *tasks, int numtasks)
/* threads */
for (i = 0; i < numtasks; ++i) {
- if (tasks[i].rng)
+ if (tasks[i].rng) {
BLI_rng_free(tasks[i].rng);
- if (tasks[i].rng_path)
+ }
+ if (tasks[i].rng_path) {
BLI_rng_free(tasks[i].rng_path);
+ }
}
MEM_freeN(tasks);
@@ -500,20 +524,27 @@ void psys_tasks_free(ParticleTask *tasks, int numtasks)
void psys_thread_context_free(ParticleThreadContext *ctx)
{
/* path caching */
- if (ctx->vg_length)
+ if (ctx->vg_length) {
MEM_freeN(ctx->vg_length);
- if (ctx->vg_clump)
+ }
+ if (ctx->vg_clump) {
MEM_freeN(ctx->vg_clump);
- if (ctx->vg_kink)
+ }
+ if (ctx->vg_kink) {
MEM_freeN(ctx->vg_kink);
- if (ctx->vg_rough1)
+ }
+ if (ctx->vg_rough1) {
MEM_freeN(ctx->vg_rough1);
- if (ctx->vg_rough2)
+ }
+ if (ctx->vg_rough2) {
MEM_freeN(ctx->vg_rough2);
- if (ctx->vg_roughe)
+ }
+ if (ctx->vg_roughe) {
MEM_freeN(ctx->vg_roughe);
- if (ctx->vg_twist)
+ }
+ if (ctx->vg_twist) {
MEM_freeN(ctx->vg_twist);
+ }
if (ctx->sim.psys->lattice_deform_data) {
end_latt_deform(ctx->sim.psys->lattice_deform_data);
@@ -521,16 +552,21 @@ void psys_thread_context_free(ParticleThreadContext *ctx)
}
/* distribution */
- if (ctx->jit)
+ if (ctx->jit) {
MEM_freeN(ctx->jit);
- if (ctx->jitoff)
+ }
+ if (ctx->jitoff) {
MEM_freeN(ctx->jitoff);
- if (ctx->weight)
+ }
+ if (ctx->weight) {
MEM_freeN(ctx->weight);
- if (ctx->index)
+ }
+ if (ctx->index) {
MEM_freeN(ctx->index);
- if (ctx->seams)
+ }
+ if (ctx->seams) {
MEM_freeN(ctx->seams);
+ }
//if (ctx->vertpart) MEM_freeN(ctx->vertpart);
BLI_kdtree_3d_free(ctx->tree);
@@ -626,8 +662,9 @@ static void free_unexisting_particles(ParticleSimulationData *sim)
}
if (psys->totpart && psys->totunexist == psys->totpart) {
- if (psys->particles->boid)
+ if (psys->particles->boid) {
MEM_freeN(psys->particles->boid);
+ }
MEM_freeN(psys->particles);
psys->particles = NULL;
@@ -641,14 +678,16 @@ static void free_unexisting_particles(ParticleSimulationData *sim)
npa = newpars = MEM_callocN(newtotpart * sizeof(ParticleData), "particles");
for (p = 0, pa = psys->particles; p < newtotpart; p++, pa++, npa++) {
- while (pa->flag & PARS_UNEXIST)
+ while (pa->flag & PARS_UNEXIST) {
pa++;
+ }
memcpy(npa, pa, sizeof(ParticleData));
}
- if (psys->particles->boid)
+ if (psys->particles->boid) {
MEM_freeN(psys->particles->boid);
+ }
MEM_freeN(psys->particles);
psys->particles = newpars;
psys->totpart -= psys->totunexist;
@@ -720,7 +759,7 @@ void psys_get_birth_coords(
int p = pa - psys->particles;
/* get birth location from object */
- if (use_tangents)
+ if (use_tangents) {
psys_particle_on_emitter(sim->psmd,
part->from,
pa->num,
@@ -732,9 +771,11 @@ void psys_get_birth_coords(
utan,
vtan,
0);
- else
+ }
+ else {
psys_particle_on_emitter(
sim->psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, nor, 0, 0, 0);
+ }
/* get possible textural influence */
psys_get_texture(sim, pa, &ptex, PAMAP_IVEL, cfra);
@@ -842,12 +883,14 @@ void psys_get_birth_coords(
}
/* *emitter normal */
- if (part->normfac != 0.f)
+ if (part->normfac != 0.f) {
madd_v3_v3fl(vel, nor, part->normfac);
+ }
/* *emitter tangent */
- if (sim->psmd && part->tanfac != 0.f)
+ if (sim->psmd && part->tanfac != 0.f) {
madd_v3_v3fl(vel, vtan, part->tanfac);
+ }
/* *emitter object orientation */
if (part->ob_vel[0] != 0.f) {
@@ -867,12 +910,14 @@ void psys_get_birth_coords(
/* TODO */
/* *random */
- if (part->randfac != 0.f)
+ if (part->randfac != 0.f) {
madd_v3_v3fl(vel, r_vel, part->randfac);
+ }
/* *particle */
- if (part->partfac != 0.f)
+ if (part->partfac != 0.f) {
madd_v3_v3fl(vel, p_vel, part->partfac);
+ }
mul_v3_v3fl(state->vel, vel, ptex.ivel);
@@ -990,8 +1035,9 @@ void psys_get_birth_coords(
/* rotation phase */
phasefac = part->phasefac;
- if (part->randphasefac != 0.0f)
+ if (part->randphasefac != 0.0f) {
phasefac += part->randphasefac * psys_frand(psys, p + 20);
+ }
axis_angle_to_quat(q_phase, x_vec, phasefac * (float)M_PI);
/* combine base rotation & phase */
@@ -1003,10 +1049,12 @@ void psys_get_birth_coords(
zero_v3(state->ave);
if (part->avemode) {
- if (part->avemode == PART_AVE_RAND)
+ if (part->avemode == PART_AVE_RAND) {
copy_v3_v3(state->ave, r_ave);
- else
+ }
+ else {
get_angular_velocity_vector(part->avemode, state, state->ave);
+ }
normalize_v3(state->ave);
mul_v3_fl(state->ave, part->avefac);
@@ -1020,8 +1068,9 @@ static void evaluate_emitter_anim(struct Depsgraph *depsgraph,
Object *ob,
float cfra)
{
- if (ob->parent)
+ if (ob->parent) {
evaluate_emitter_anim(depsgraph, scene, ob->parent, cfra);
+ }
BKE_object_where_is_calc_time(depsgraph, scene, ob, cfra);
}
@@ -1083,8 +1132,9 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
pa->lifetime = part->lifetime * ptex.life;
- if (part->randlife != 0.0f)
+ if (part->randlife != 0.0f) {
pa->lifetime *= 1.0f - part->randlife * psys_frand(psys, p + 21);
+ }
}
pa->dietime = pa->time + pa->lifetime;
@@ -1095,12 +1145,15 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
pa->dietime = MIN2(pa->dietime, dietime);
}
- if (pa->time > cfra)
+ if (pa->time > cfra) {
pa->alive = PARS_UNBORN;
- else if (pa->dietime <= cfra)
+ }
+ else if (pa->dietime <= cfra) {
pa->alive = PARS_DEAD;
- else
+ }
+ else {
pa->alive = PARS_ALIVE;
+ }
pa->state.time = cfra;
}
@@ -1109,8 +1162,9 @@ static void reset_all_particles(ParticleSimulationData *sim, float dtime, float
ParticleData *pa;
int p, totpart = sim->psys->totpart;
- for (p = from, pa = sim->psys->particles + from; p < totpart; p++, pa++)
+ for (p = from, pa = sim->psys->particles + from; p < totpart; p++, pa++) {
reset_particle(sim, pa, dtime, cfra);
+ }
}
/************************************************/
/* Particle targets */
@@ -1119,15 +1173,19 @@ ParticleSystem *psys_get_target_system(Object *ob, ParticleTarget *pt)
{
ParticleSystem *psys = NULL;
- if (pt->ob == NULL || pt->ob == ob)
+ if (pt->ob == NULL || pt->ob == ob) {
psys = BLI_findlink(&ob->particlesystem, pt->psys - 1);
- else
+ }
+ else {
psys = BLI_findlink(&pt->ob->particlesystem, pt->psys - 1);
+ }
- if (psys)
+ if (psys) {
pt->flag |= PTARGET_VALID;
- else
+ }
+ else {
pt->flag &= ~PTARGET_VALID;
+ }
return psys;
}
@@ -1147,8 +1205,9 @@ void psys_count_keyed_targets(ParticleSimulationData *sim)
if (kpsys && kpsys->totpart) {
psys->totkeyed += keys_valid;
- if (psys->flag & PSYS_KEYED_TIMING && pt->duration != 0.0f)
+ if (psys->flag & PSYS_KEYED_TIMING && pt->duration != 0.0f) {
psys->totkeyed += 1;
+ }
}
else {
keys_valid = 0;
@@ -1214,14 +1273,17 @@ static void set_keyed_keys(ParticleSimulationData *sim)
(key + 1)->time = pa->time + pt->time + pt->duration;
}
}
- else if (totkeys > 1)
+ else if (totkeys > 1) {
key->time = pa->time + (float)k / (float)(totkeys - 1) * pa->lifetime;
- else
+ }
+ else {
key->time = pa->time;
+ }
}
- if (psys->flag & PSYS_KEYED_TIMING && pt->duration != 0.0f)
+ if (psys->flag & PSYS_KEYED_TIMING && pt->duration != 0.0f) {
k++;
+ }
ksim.psys->flag |= keyed_flag;
@@ -1248,8 +1310,9 @@ void psys_make_temp_pointcache(Object *ob, ParticleSystem *psys)
}
static void psys_clear_temp_pointcache(ParticleSystem *psys)
{
- if (psys->pointcache->flag & PTCACHE_DISK_CACHE)
+ if (psys->pointcache->flag & PTCACHE_DISK_CACHE) {
BKE_ptcache_free_mem(&psys->pointcache->mem_cache);
+ }
}
void psys_get_pointcache_start_end(Scene *scene, ParticleSystem *psys, int *sfra, int *efra)
{
@@ -1287,10 +1350,12 @@ static void psys_update_particle_bvhtree(ParticleSystem *psys, float cfra)
LOOP_SHOWN_PARTICLES
{
if (pa->alive == PARS_ALIVE) {
- if (pa->state.time == cfra)
+ if (pa->state.time == cfra) {
BLI_bvhtree_insert(psys->bvhtree, p, pa->prev_state.co, 1);
- else
+ }
+ else {
BLI_bvhtree_insert(psys->bvhtree, p, pa->state.co, 1);
+ }
}
}
BLI_bvhtree_balance(psys->bvhtree);
@@ -1319,10 +1384,12 @@ void psys_update_particle_tree(ParticleSystem *psys, float cfra)
LOOP_SHOWN_PARTICLES
{
if (pa->alive == PARS_ALIVE) {
- if (pa->state.time == cfra)
+ if (pa->state.time == cfra) {
BLI_kdtree_3d_insert(psys->tree, p, pa->prev_state.co);
- else
+ }
+ else {
BLI_kdtree_3d_insert(psys->tree, p, pa->state.co);
+ }
}
}
BLI_kdtree_3d_balance(psys->tree);
@@ -1367,8 +1434,9 @@ static void integrate_particle(
copy_v3_v3(oldpos, pa->state.co);
/* Verlet integration behaves strangely with moving emitters, so do first step with euler. */
- if (pa->prev_state.time < 0.f && integrator == PART_INT_VERLET)
+ if (pa->prev_state.time < 0.f && integrator == PART_INT_VERLET) {
integrator = PART_INT_EULER;
+ }
switch (integrator) {
case PART_INT_EULER:
@@ -1400,8 +1468,9 @@ static void integrate_particle(
/* force to acceleration*/
mul_v3_v3fl(acceleration, force, 1.0f / pa_mass);
- if (external_acceleration)
+ if (external_acceleration) {
add_v3_v3(acceleration, external_acceleration);
+ }
/* calculate next state */
add_v3_v3(states[i].vel, impulse);
@@ -1522,8 +1591,9 @@ static ParticleSpring *sph_spring_add(ParticleSystem *psys, ParticleSpring *spri
}
static void sph_spring_delete(ParticleSystem *psys, int j)
{
- if (j != psys->tot_fluidsprings - 1)
+ if (j != psys->tot_fluidsprings - 1) {
psys->fluid_springs[j] = psys->fluid_springs[psys->tot_fluidsprings - 1];
+ }
psys->tot_fluidsprings--;
@@ -1548,8 +1618,9 @@ static void sph_springs_modify(ParticleSystem *psys, float dtime)
/* scale things according to dtime */
float timefix = 25.f * dtime;
- if ((fluid->flag & SPH_VISCOELASTIC_SPRINGS) == 0 || fluid->spring_k == 0.f)
+ if ((fluid->flag & SPH_VISCOELASTIC_SPRINGS) == 0 || fluid->spring_k == 0.f) {
return;
+ }
/* Loop through the springs */
for (i = 0; i < psys->tot_fluidsprings; i++, spring++) {
@@ -1563,21 +1634,25 @@ static void sph_springs_modify(ParticleSystem *psys, float dtime)
Lij = spring->rest_length;
d = yield_ratio * timefix * Lij;
- if (rij > Lij + d) // Stretch
+ if (rij > Lij + d) { // Stretch
spring->rest_length += plasticity * (rij - Lij - d) * timefix;
- else if (rij < Lij - d) // Compress
+ }
+ else if (rij < Lij - d) { // Compress
spring->rest_length -= plasticity * (Lij - d - rij) * timefix;
+ }
h = 4.f * pa1->size;
- if (spring->rest_length > h)
+ if (spring->rest_length > h) {
spring->delete_flag = 1;
+ }
}
/* Loop through springs backwaqrds - for efficient delete function */
for (i = psys->tot_fluidsprings - 1; i >= 0; i--) {
- if (psys->fluid_springs[i].delete_flag)
+ if (psys->fluid_springs[i].delete_flag) {
sph_spring_delete(psys, i);
+ }
}
}
static EdgeHash *sph_springhash_build(ParticleSystem *psys)
@@ -1588,9 +1663,10 @@ static EdgeHash *sph_springhash_build(ParticleSystem *psys)
springhash = BLI_edgehash_new_ex(__func__, psys->tot_fluidsprings);
- for (i = 0, spring = psys->fluid_springs; i < psys->tot_fluidsprings; i++, spring++)
+ for (i = 0, spring = psys->fluid_springs; i < psys->tot_fluidsprings; i++, spring++) {
BLI_edgehash_insert(
springhash, spring->particle_index[0], spring->particle_index[1], POINTER_FROM_INT(i + 1));
+ }
return springhash;
}
@@ -1654,8 +1730,9 @@ static void sph_density_accum_cb(void *userdata, int index, const float co[3], f
UNUSED_VARS(co);
- if (npa == pfr->pa || squared_dist < FLT_EPSILON)
+ if (npa == pfr->pa || squared_dist < FLT_EPSILON) {
return;
+ }
/* Ugh! One particle has too many neighbors! If some aren't taken into
* account, the forces will be biased by the tree search order. This
@@ -1663,8 +1740,9 @@ static void sph_density_accum_cb(void *userdata, int index, const float co[3], f
* But, we have to stop somewhere, and it's not the end of the world.
* - jahka and z0r
*/
- if (pfr->tot_neighbors >= SPH_NEIGHBORS)
+ if (pfr->tot_neighbors >= SPH_NEIGHBORS) {
return;
+ }
pfr->neighbors[pfr->tot_neighbors].index = index;
pfr->neighbors[pfr->tot_neighbors].psys = pfr->npsys;
@@ -1673,8 +1751,9 @@ static void sph_density_accum_cb(void *userdata, int index, const float co[3], f
dist = sqrtf(squared_dist);
q = (1.f - dist / pfr->h) * pfr->massfac;
- if (pfr->use_size)
+ if (pfr->use_size) {
q *= npa->size;
+ }
pfr->data[0] += q * q;
pfr->data[1] += q * q * q;
@@ -1778,8 +1857,9 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa
q = (1.f - rij / h) * pfn->psys->part->mass * inv_mass;
- if (pfn->psys->part->flag & PART_SIZEMASS)
+ if (pfn->psys->part->flag & PART_SIZEMASS) {
q *= npa->size;
+ }
copy_v3_v3(vel, npa->prev_state.vel);
@@ -1791,11 +1871,13 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa
sub_v3_v3v3(dv, vel, state->vel);
u = dot_v3v3(vec, dv);
- if (u < 0.f && visc > 0.f)
+ if (u < 0.f && visc > 0.f) {
madd_v3_v3fl(force, vec, 0.5f * q * visc * u);
+ }
- if (u > 0.f && stiff_visc > 0.f)
+ if (u > 0.f && stiff_visc > 0.f) {
madd_v3_v3fl(force, vec, 0.5f * q * stiff_visc * u);
+ }
}
if (spring_constant > 0.f) {
@@ -1829,11 +1911,13 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa
}
/* Artificial buoyancy force in negative gravity direction */
- if (fluid->buoyancy > 0.f && gravity)
+ if (fluid->buoyancy > 0.f && gravity) {
madd_v3_v3fl(force, gravity, fluid->buoyancy * (density - rest_density));
+ }
- if (sphdata->pass == 0 && psys[0]->part->time_flag & PART_TIME_AUTOSF)
+ if (sphdata->pass == 0 && psys[0]->part->time_flag & PART_TIME_AUTOSF) {
sph_particle_courant(sphdata, &pfr);
+ }
sphdata->pass++;
}
@@ -1855,8 +1939,9 @@ static void sphclassical_density_accum_cb(void *userdata,
sub_v3_v3v3(vec, npa->state.co, co);
rij = len_v3(vec);
rij_h = rij / pfr->h;
- if (rij_h > 2.0f)
+ if (rij_h > 2.0f) {
return;
+ }
/* Smoothing factor. Utilise the Wendland kernel. gnuplot:
* q1(x) = (2.0 - x)**4 * ( 1.0 + 2.0 * x)
@@ -1864,8 +1949,9 @@ static void sphclassical_density_accum_cb(void *userdata,
q = qfac / pow3f(pfr->h) * pow4f(2.0f - rij_h) * (1.0f + 2.0f * rij_h);
q *= pfr->npsys->part->mass;
- if (pfr->use_size)
+ if (pfr->use_size) {
q *= pfr->pa->size;
+ }
pfr->data[0] += q;
pfr->data[1] += q / npa->sphdensity;
@@ -1881,8 +1967,9 @@ static void sphclassical_neighbour_accum_cb(void *userdata,
float rij, rij_h;
float vec[3];
- if (pfr->tot_neighbors >= SPH_NEIGHBORS)
+ if (pfr->tot_neighbors >= SPH_NEIGHBORS) {
return;
+ }
/* Exclude particles that are more than 2h away. Can't use squared_dist here
* because it is not accurate enough. Use current state, i.e. the output of
@@ -1890,8 +1977,9 @@ static void sphclassical_neighbour_accum_cb(void *userdata,
sub_v3_v3v3(vec, npa->state.co, co);
rij = len_v3(vec);
rij_h = rij / pfr->h;
- if (rij_h > 2.0f)
+ if (rij_h > 2.0f) {
return;
+ }
pfr->neighbors[pfr->tot_neighbors].index = index;
pfr->neighbors[pfr->tot_neighbors].psys = pfr->npsys;
@@ -1964,8 +2052,9 @@ static void sphclassical_force_cb(void *sphdata_v,
sub_v3_v3v3(vec, co, state->co);
rij = normalize_v3(vec);
rij_h = rij / pfr.h;
- if (rij_h > 2.0f)
+ if (rij_h > 2.0f) {
continue;
+ }
npressure = stiffness * (pow7f(npa->sphdensity / rest_density) - 1.0f);
@@ -1976,8 +2065,9 @@ static void sphclassical_force_cb(void *sphdata_v,
* Particles > 2h away are excluded above. */
dq = qfac2 * (2.0f * pow4f(2.0f - rij_h) - 4.0f * pow3f(2.0f - rij_h) * (1.0f + 2.0f * rij_h));
- if (pfn->psys->part->flag & PART_SIZEMASS)
+ if (pfn->psys->part->flag & PART_SIZEMASS) {
dq *= npa->size;
+ }
pressureTerm = pressure / pow2f(pa->sphdensity) + npressure / pow2f(npa->sphdensity);
@@ -1996,11 +2086,13 @@ static void sphclassical_force_cb(void *sphdata_v,
}
/* Artificial buoyancy force in negative gravity direction */
- if (fluid->buoyancy > 0.f && gravity)
+ if (fluid->buoyancy > 0.f && gravity) {
madd_v3_v3fl(force, gravity, fluid->buoyancy * (pa->sphdensity - rest_density));
+ }
- if (sphdata->pass == 0 && psys[0]->part->time_flag & PART_TIME_AUTOSF)
+ if (sphdata->pass == 0 && psys[0]->part->time_flag & PART_TIME_AUTOSF) {
sph_particle_courant(sphdata, &pfr);
+ }
sphdata->pass++;
}
@@ -2033,13 +2125,16 @@ void psys_sph_init(ParticleSimulationData *sim, SPHData *sphdata)
// Add other coupled particle systems.
sphdata->psys[0] = sim->psys;
- for (i = 1, pt = sim->psys->targets.first; i < 10; i++, pt = (pt ? pt->next : NULL))
+ for (i = 1, pt = sim->psys->targets.first; i < 10; i++, pt = (pt ? pt->next : NULL)) {
sphdata->psys[i] = pt ? psys_get_target_system(sim->ob, pt) : NULL;
+ }
- if (psys_uses_gravity(sim))
+ if (psys_uses_gravity(sim)) {
sphdata->gravity = sim->scene->physics_settings.gravity;
- else
+ }
+ else {
sphdata->gravity = NULL;
+ }
sphdata->eh = sph_springhash_build(sim->psys);
// These per-particle values should be overridden later, but just for
@@ -2134,16 +2229,18 @@ static void basic_force_cb(void *efdata_v, ParticleKey *state, float *force, flo
/* add effectors */
pd_point_from_particle(efdata->sim, efdata->pa, state, &epoint);
- if (part->type != PART_HAIR || part->effector_weights->flag & EFF_WEIGHT_DO_HAIR)
+ if (part->type != PART_HAIR || part->effector_weights->flag & EFF_WEIGHT_DO_HAIR) {
BKE_effectors_apply(
sim->psys->effectors, sim->colliders, part->effector_weights, &epoint, force, impulse);
+ }
mul_v3_fl(force, efdata->ptex.field);
mul_v3_fl(impulse, efdata->ptex.field);
/* calculate air-particle interaction */
- if (part->dragfac != 0.0f)
+ if (part->dragfac != 0.0f) {
madd_v3_v3fl(force, state->vel, -part->dragfac * pa->size * pa->size * len_v3(state->vel));
+ }
/* brownian force */
if (part->brownfac != 0.0f) {
@@ -2152,8 +2249,9 @@ static void basic_force_cb(void *efdata_v, ParticleKey *state, float *force, flo
force[2] += (BLI_rng_get_float(rng) - 0.5f) * part->brownfac;
}
- if (part->flag & PART_ROT_DYN && epoint.ave)
+ if (part->flag & PART_ROT_DYN && epoint.ave) {
copy_v3_v3(pa->state.ave, epoint.ave);
+ }
}
/* gathers all forces that effect particles and calculates a new state for the particle */
static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, float cfra)
@@ -2187,8 +2285,9 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa
integrate_particle(part, pa, dtime, gravity, basic_force_cb, &efdata);
/* damp affects final velocity */
- if (part->dampfac != 0.f)
+ if (part->dampfac != 0.f) {
mul_v3_fl(pa->state.vel, 1.f - part->dampfac * efdata.ptex.damp * 25.f * dtime);
+ }
//copy_v3_v3(pa->state.ave, states->ave);
@@ -2292,10 +2391,12 @@ static float nr_signed_distance_to_plane(float *p,
d = dot_v3v3(p0, nor);
if (pce->inv_nor == -1) {
- if (d < 0.f)
+ if (d < 0.f) {
pce->inv_nor = 1;
- else
+ }
+ else {
pce->inv_nor = 0;
+ }
}
if (pce->inv_nor == 1) {
@@ -2343,8 +2444,9 @@ static void collision_interpolate_element(ParticleCollisionElement *pce,
if (pce->tot > 1) {
madd_v3_v3v3fl(pce->x1, pce->x[1], pce->v[1], mul);
- if (pce->tot > 2)
+ if (pce->tot > 2) {
madd_v3_v3v3fl(pce->x2, pce->x[2], pce->v[2], mul);
+ }
}
}
}
@@ -2367,8 +2469,9 @@ 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)
{
- if (fac >= 0.f)
+ if (fac >= 0.f) {
collision_interpolate_element(pce, 0.f, fac, col);
+ }
switch (pce->tot) {
case 1: {
@@ -2424,8 +2527,9 @@ static void collision_point_on_surface(
cross_v3_v3v3(nor, e1, e2);
normalize_v3(nor);
- if (pce->inv_nor == 1)
+ if (pce->inv_nor == 1) {
negate_v3(nor);
+ }
madd_v3_v3v3fl(co, pce->x0, nor, col->radius);
madd_v3_v3fl(co, e1, pce->uv[0]);
@@ -2489,8 +2593,9 @@ static float collision_newton_rhapson(ParticleCollision *col,
d1 = 0.f;
continue;
}
- else
+ else {
return -1.f;
+ }
}
dd = (t1 - t0) / (d1 - d0);
@@ -2510,20 +2615,23 @@ static float collision_newton_rhapson(ParticleCollision *col,
d1 = 0.f;
continue;
}
- else if (iter == 1 && (t1 < -COLLISION_ZERO || t1 > 1.f))
+ else if (iter == 1 && (t1 < -COLLISION_ZERO || t1 > 1.f)) {
return -1.f;
+ }
if (d1 <= COLLISION_ZERO && d1 >= -COLLISION_ZERO) {
if (t1 >= -COLLISION_ZERO && t1 <= 1.f) {
- if (distance_func == nr_signed_distance_to_plane)
+ if (distance_func == nr_signed_distance_to_plane) {
copy_v3_v3(pce->nor, n);
+ }
CLAMP(t1, 0.f, 1.f);
return t1;
}
- else
+ else {
return -1.f;
+ }
}
}
return -1.0;
@@ -2603,8 +2711,9 @@ static int collision_sphere_to_edges(ParticleCollision *col,
sub_v3_v3v3(vec, cur->p, cur->x0);
u = dot_v3v3(vec, e) / dot_v3v3(e, e);
- if (u < 0.f || u > 1.f)
+ if (u < 0.f || u > 1.f) {
break;
+ }
*result = *cur;
@@ -2703,8 +2812,9 @@ static int collision_detect(ParticleData *pa,
ColliderCache *coll;
float ray_dir[3];
- if (BLI_listbase_is_empty(colliders))
+ if (BLI_listbase_is_empty(colliders)) {
return 0;
+ }
sub_v3_v3v3(ray_dir, col->co2, col->co1);
hit->index = -1;
@@ -2713,8 +2823,9 @@ static int collision_detect(ParticleData *pa,
/* even if particle is stationary we want to check for moving colliders */
/* if hit.dist is zero the bvhtree_ray_cast will just ignore everything */
- if (hit->dist == 0.0f)
+ if (hit->dist == 0.0f) {
hit->dist = col->original_ray_length = 0.000001f;
+ }
for (coll = colliders->first; coll; coll = coll->next) {
/* for boids: don't check with current ground object; also skip if permeated */
@@ -2727,12 +2838,14 @@ static int collision_detect(ParticleData *pa,
}
}
- if (skip)
+ if (skip) {
continue;
+ }
/* particles should not collide with emitter at birth */
- if (coll->ob == col->emitter && pa->time < col->cfra && pa->time >= col->old_cfra)
+ if (coll->ob == col->emitter && pa->time < col->cfra && pa->time >= col->old_cfra) {
continue;
+ }
col->current = coll->ob;
col->md = coll->collmd;
@@ -2874,8 +2987,9 @@ static int collision_response(ParticleSimulationData *sim,
/* otherwise particles go flying out of the surface because of high reversed sticky velocity */
if (v0_dot < 0.0f) {
v0_dot += pd->pdef_stickness;
- if (v0_dot > 0.0f)
+ if (v0_dot > 0.0f) {
v0_dot = 0.0f;
+ }
}
/* damping and flipping of velocity around normal */
@@ -2885,12 +2999,15 @@ static int collision_response(ParticleSimulationData *sim,
/* calculate normal particle velocity */
/* special case for object hitting the particle from behind */
if (through == 0 && ((vc_dot > 0.0f && v0_dot > 0.0f && vc_dot > v0_dot) ||
- (vc_dot < 0.0f && v0_dot < 0.0f && vc_dot < v0_dot)))
+ (vc_dot < 0.0f && v0_dot < 0.0f && vc_dot < v0_dot))) {
mul_v3_v3fl(v0_nor, pce->nor, vc_dot);
- else if (v0_dot > 0.f)
+ }
+ else if (v0_dot > 0.f) {
mul_v3_v3fl(v0_nor, pce->nor, vc_dot + v0_dot);
- else
+ }
+ else {
mul_v3_v3fl(v0_nor, pce->nor, vc_dot + (through ? 1.0f : -1.0f) * v0_dot);
+ }
/* combine components together again */
add_v3_v3v3(v0, v0_nor, v0_tan);
@@ -2913,21 +3030,25 @@ static int collision_response(ParticleSimulationData *sim,
if (!through) {
distance = collision_point_distance_with_normal(co, pce, -1.f, col, nor);
- if (distance < col->radius + COLLISION_MIN_DISTANCE)
+ if (distance < col->radius + COLLISION_MIN_DISTANCE) {
madd_v3_v3fl(co, nor, col->radius + COLLISION_MIN_DISTANCE - distance);
+ }
dot = dot_v3v3(nor, v0);
- if (dot < 0.f)
+ if (dot < 0.f) {
madd_v3_v3fl(v0, nor, -dot);
+ }
distance = collision_point_distance_with_normal(pa->state.co, pce, 1.f, col, nor);
- if (distance < col->radius + COLLISION_MIN_DISTANCE)
+ if (distance < col->radius + COLLISION_MIN_DISTANCE) {
madd_v3_v3fl(pa->state.co, nor, col->radius + COLLISION_MIN_DISTANCE - distance);
+ }
dot = dot_v3v3(nor, pa->state.vel);
- if (dot < 0.f)
+ if (dot < 0.f) {
madd_v3_v3fl(pa->state.vel, nor, -dot);
+ }
}
/* add stickiness to surface */
@@ -3017,15 +3138,18 @@ static void collision_check(ParticleSimulationData *sim, int p, float dfra, floa
collision_count++;
- if (collision_count == PARTICLE_COLLISION_MAX_COLLISIONS)
+ if (collision_count == PARTICLE_COLLISION_MAX_COLLISIONS) {
collision_fail(pa, &col);
+ }
else if (collision_response(
sim, pa, &col, &hit, part->flag & PART_DIE_ON_COL, part->flag & PART_ROT_DYN) ==
- 0)
+ 0) {
return;
+ }
}
- else
+ else {
return;
+ }
}
}
/************************************************/
@@ -3043,48 +3167,58 @@ static void psys_update_path_cache(ParticleSimulationData *sim,
if ((psys->part->childtype &&
psys->totchild != psys_get_tot_child(sim->scene, psys, use_render_params)) ||
- psys->recalc & ID_RECALC_PSYS_RESET)
+ psys->recalc & ID_RECALC_PSYS_RESET) {
alloc = 1;
+ }
if (alloc || psys->recalc & ID_RECALC_PSYS_CHILD ||
- (psys->vgroup[PSYS_VG_DENSITY] && (sim->ob && sim->ob->mode & OB_MODE_WEIGHT_PAINT)))
+ (psys->vgroup[PSYS_VG_DENSITY] && (sim->ob && sim->ob->mode & OB_MODE_WEIGHT_PAINT))) {
distr = 1;
+ }
if (distr) {
- if (alloc)
+ if (alloc) {
realloc_particles(sim, sim->psys->totpart);
+ }
if (psys_get_tot_child(sim->scene, psys, use_render_params)) {
/* don't generate children while computing the hair keys */
if (!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE)) {
distribute_particles(sim, PART_FROM_CHILD);
- if (part->childtype == PART_CHILD_FACES && part->parents != 0.0f)
+ if (part->childtype == PART_CHILD_FACES && part->parents != 0.0f) {
psys_find_parents(sim, use_render_params);
+ }
}
}
- else
+ else {
psys_free_children(psys);
+ }
}
if ((part->type == PART_HAIR || psys->flag & PSYS_KEYED ||
- psys->pointcache->flag & PTCACHE_BAKED) == 0)
+ psys->pointcache->flag & PTCACHE_BAKED) == 0) {
skip = 1; /* only hair, keyed and baked stuff can have paths */
+ }
else if (part->ren_as != PART_DRAW_PATH &&
- !(part->type == PART_HAIR && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)))
+ !(part->type == PART_HAIR && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR))) {
skip = 1; /* particle visualization must be set as path */
+ }
else if (DEG_get_mode(sim->depsgraph) != DAG_EVAL_RENDER) {
- if (part->draw_as != PART_DRAW_REND)
+ if (part->draw_as != PART_DRAW_REND) {
skip = 1; /* draw visualization */
- else if (psys->pointcache->flag & PTCACHE_BAKING)
+ }
+ else if (psys->pointcache->flag & PTCACHE_BAKING) {
skip = 1; /* no need to cache paths while baking dynamics */
-
+ }
else if (psys_in_edit_mode(sim->depsgraph, psys)) {
- if ((pset->flag & PE_DRAW_PART) == 0)
+ if ((pset->flag & PE_DRAW_PART) == 0) {
skip = 1;
+ }
else if (part->childtype == 0 &&
- (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED) == 0)
+ (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED) == 0) {
skip = 1; /* in edit mode paths are needed for child particles and dynamic hair */
+ }
}
}
@@ -3093,17 +3227,21 @@ static void psys_update_path_cache(ParticleSimulationData *sim,
/* for render, child particle paths are computed on the fly */
if (part->childtype) {
- if (!psys->totchild)
+ if (!psys->totchild) {
skip = 1;
- else if (psys->part->type == PART_HAIR && (psys->flag & PSYS_HAIR_DONE) == 0)
+ }
+ else if (psys->part->type == PART_HAIR && (psys->flag & PSYS_HAIR_DONE) == 0) {
skip = 1;
+ }
- if (!skip)
+ if (!skip) {
psys_cache_child_paths(sim, cfra, 0, use_render_params);
+ }
}
}
- else if (psys->pathcache)
+ else if (psys->pathcache) {
psys_free_path_cache(psys, NULL);
+ }
}
static bool psys_hair_use_simulation(ParticleData *pa, float max_length)
@@ -3119,13 +3257,15 @@ static bool psys_hair_use_simulation(ParticleData *pa, float max_length)
HairKey *key;
int k;
- if (pa->totkey < 2)
+ if (pa->totkey < 2) {
return false;
+ }
for (k = 1, key = pa->hair + 1; k < pa->totkey; k++, key++) {
float length = len_v3v3(key->co, (key - 1)->co);
- if (length < min_length)
+ if (length < min_length) {
return false;
+ }
}
return true;
@@ -3187,8 +3327,9 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
if (!(pa->flag & PARS_UNEXIST)) {
for (k = 1, key = pa->hair + 1; k < pa->totkey; k++, key++) {
float length = len_v3v3(key->co, (key - 1)->co);
- if (max_length < length)
+ if (max_length < length) {
max_length = length;
+ }
}
}
}
@@ -3263,14 +3404,17 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
}
/* roots and disabled hairs should be 1.0, the rest can be anything from 0.0 to 1.0 */
- if (use_hair)
+ if (use_hair) {
dvert = hair_set_pinning(dvert, key->weight);
- else
+ }
+ else {
dvert = hair_set_pinning(dvert, 1.0f);
+ }
mvert++;
- if (k)
+ if (k) {
medge++;
+ }
}
hair_index += pa->totkey + 1;
@@ -3327,8 +3471,9 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
hair_create_input_mesh(sim, totpoint, totedge, &psys->hair_in_mesh, &psys->clmd->hairdata);
- if (psys->hair_out_mesh)
+ if (psys->hair_out_mesh) {
BKE_id_free(NULL, psys->hair_out_mesh);
+ }
psys->clmd->point_cache = psys->pointcache;
/* for hair sim we replace the internal cloth effector weights temporarily
@@ -3358,26 +3503,31 @@ static void hair_step(ParticleSimulationData *sim, float cfra, const bool use_re
LOOP_PARTICLES
{
pa->size = part->size;
- if (part->randsize > 0.0f)
+ if (part->randsize > 0.0f) {
pa->size *= 1.0f - part->randsize * psys_frand(psys, p + 1);
+ }
- if (psys_frand(psys, p) > disp)
+ if (psys_frand(psys, p) > disp) {
pa->flag |= PARS_NO_DISP;
- else
+ }
+ else {
pa->flag &= ~PARS_NO_DISP;
+ }
}
if (psys->recalc & ID_RECALC_PSYS_RESET) {
/* need this for changing subsurf levels */
psys_calc_dmcache(sim->ob, sim->psmd->mesh_final, sim->psmd->mesh_original, psys);
- if (psys->clmd)
+ if (psys->clmd) {
cloth_free_modifier(psys->clmd);
+ }
}
/* dynamics with cloth simulation, psys->particles can be NULL with 0 particles [#25519] */
- if (psys->part->type == PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS && psys->particles)
+ if (psys->part->type == PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS && psys->particles) {
do_hair_dynamics(sim);
+ }
/* following lines were removed r29079 but cause bug [#22811], see report for details */
psys_update_effectors(sim);
@@ -3397,8 +3547,9 @@ static void save_hair(ParticleSimulationData *sim, float UNUSED(cfra))
psys->lattice_deform_data = psys_create_lattice_deform_data(sim);
- if (psys->totpart == 0)
+ if (psys->totpart == 0) {
return;
+ }
/* save new keys for elements if needed */
LOOP_PARTICLES
@@ -3471,34 +3622,43 @@ static float get_base_time_step(ParticleSettings *part)
static void update_timestep(ParticleSystem *psys, ParticleSimulationData *sim)
{
float dt_target;
- if (sim->courant_num == 0.0f)
+ if (sim->courant_num == 0.0f) {
dt_target = 1.0f;
- else
+ }
+ else {
dt_target = psys->dt_frac * (psys->part->courant_target / sim->courant_num);
+ }
/* Make sure the time step is reasonable. For some reason, the CLAMP macro
* doesn't work here. The time step becomes too large. - z0r */
- if (dt_target < MIN_TIMESTEP)
+ if (dt_target < MIN_TIMESTEP) {
dt_target = MIN_TIMESTEP;
- else if (dt_target > get_base_time_step(psys->part))
+ }
+ else if (dt_target > get_base_time_step(psys->part)) {
dt_target = get_base_time_step(psys->part);
+ }
/* Decrease time step instantly, but increase slowly. */
- if (dt_target > psys->dt_frac)
+ if (dt_target > psys->dt_frac) {
psys->dt_frac = interpf(dt_target, psys->dt_frac, TIMESTEP_EXPANSION_FACTOR);
- else
+ }
+ else {
psys->dt_frac = dt_target;
+ }
}
static float sync_timestep(ParticleSystem *psys, float t_frac)
{
/* Sync with frame end if it's close. */
- if (t_frac == 1.0f)
+ if (t_frac == 1.0f) {
return psys->dt_frac;
- else if (t_frac + (psys->dt_frac * TIMESTEP_EXPANSION_TOLERANCE) >= 1.0f)
+ }
+ else if (t_frac + (psys->dt_frac * TIMESTEP_EXPANSION_TOLERANCE) >= 1.0f) {
return 1.0f - t_frac;
- else
+ }
+ else {
return psys->dt_frac;
+ }
}
/************************************************/
@@ -3538,8 +3698,9 @@ static void dynamics_step_sph_ddr_task_cb_ex(void *__restrict userdata,
/* actual fluids calculations */
sph_integrate(sim, pa, pa->state.time, sphdata);
- if (sim->colliders)
+ if (sim->colliders) {
collision_check(sim, p, pa->state.time, data->cfra);
+ }
/* SPH particles are not physical particles, just interpolation
* particles, thus rotation has not a direct sense for them */
@@ -3603,8 +3764,9 @@ static void dynamics_step_sph_classical_integrate_task_cb_ex(
/* actual fluids calculations */
sph_integrate(sim, pa, pa->state.time, sphdata);
- if (sim->colliders)
+ if (sim->colliders) {
collision_check(sim, p, pa->state.time, data->cfra);
+ }
/* SPH particles are not physical particles, just interpolation
* particles, thus rotation has not a direct sense for them */
@@ -3639,8 +3801,9 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
{
psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra);
pa->size = part->size * ptex.size;
- if (part->randsize > 0.0f)
+ if (part->randsize > 0.0f) {
pa->size *= 1.0f - part->randsize * psys_frand(psys, p + 1);
+ }
reset_particle(sim, pa, dtime, cfra);
}
@@ -3652,8 +3815,9 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
psys_update_effectors(sim);
- if (part->type != PART_HAIR)
+ if (part->type != PART_HAIR) {
sim->colliders = BKE_collider_cache_create(sim->depsgraph, sim->ob, part->collision_group);
+ }
/* initialize physics type specific stuff */
switch (part->phystype) {
@@ -3684,8 +3848,9 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
for (; pt;
pt = pt->next) { /* Updating others systems particle tree for fluid-fluid interaction */
- if (pt->ob)
+ if (pt->ob) {
psys_update_particle_bvhtree(BLI_findlink(&pt->ob->particlesystem, pt->psys - 1), cfra);
+ }
}
break;
}
@@ -3698,8 +3863,9 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra);
pa->size = part->size * ptex.size;
- if (part->randsize > 0.0f)
+ if (part->randsize > 0.0f) {
pa->size *= 1.0f - part->randsize * psys_frand(psys, p + 1);
+ }
birthtime = pa->time;
dietime = pa->dietime;
@@ -3731,8 +3897,10 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
reset_particle(sim, pa, dtime, cfra);
}
- if (ELEM(pa->alive, PARS_ALIVE, PARS_DYING) == 0 || (pa->flag & (PARS_UNEXIST | PARS_NO_DISP)))
+ if (ELEM(pa->alive, PARS_ALIVE, PARS_DYING) == 0 ||
+ (pa->flag & (PARS_UNEXIST | PARS_NO_DISP))) {
pa->state.time = -1.f;
+ }
}
switch (part->phystype) {
@@ -3743,8 +3911,9 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
basic_integrate(sim, p, pa->state.time, cfra);
/* deflection */
- if (sim->colliders)
+ if (sim->colliders) {
collision_check(sim, p, pa->state.time, cfra);
+ }
/* rotations */
basic_rotate(part, pa, pa->state.time, timestep);
@@ -3762,8 +3931,9 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
boid_body(&bbd, pa);
/* deflection */
- if (sim->colliders)
+ if (sim->colliders) {
collision_check(sim, p, pa->state.time, cfra);
+ }
}
}
break;
@@ -3857,8 +4027,9 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
pa->alive = PARS_DEAD;
pa->state.time = pa->dietime;
}
- else
+ else {
pa->state.time = cfra;
+ }
}
BKE_collider_cache_free(&sim->colliders);
@@ -3868,18 +4039,21 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
static void update_children(ParticleSimulationData *sim, const bool use_render_params)
{
- if ((sim->psys->part->type == PART_HAIR) && (sim->psys->flag & PSYS_HAIR_DONE) == 0)
+ if ((sim->psys->part->type == PART_HAIR) && (sim->psys->flag & PSYS_HAIR_DONE) == 0) {
/* don't generate children while growing hair - waste of time */
psys_free_children(sim->psys);
+ }
else if (sim->psys->part->childtype) {
- if (sim->psys->totchild != psys_get_tot_child(sim->scene, sim->psys, use_render_params))
+ if (sim->psys->totchild != psys_get_tot_child(sim->scene, sim->psys, use_render_params)) {
distribute_particles(sim, PART_FROM_CHILD);
+ }
else {
/* Children are up to date, nothing to do. */
}
}
- else
+ else {
psys_free_children(sim->psys);
+ }
}
/* updates cached particles' alive & other flags etc..*/
static void cached_step(ParticleSimulationData *sim, float cfra, const bool use_render_params)
@@ -3898,8 +4072,9 @@ static void cached_step(ParticleSimulationData *sim, float cfra, const bool use_
{
psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra);
pa->size = part->size * ptex.size;
- if (part->randsize > 0.0f)
+ if (part->randsize > 0.0f) {
pa->size *= 1.0f - part->randsize * psys_frand(psys, p + 1);
+ }
psys->lattice_deform_data = psys_create_lattice_deform_data(sim);
@@ -3908,23 +4083,28 @@ static void cached_step(ParticleSimulationData *sim, float cfra, const bool use_
/* update alive status and push events */
if (pa->time > cfra) {
pa->alive = PARS_UNBORN;
- if (part->flag & PART_UNBORN && (psys->pointcache->flag & PTCACHE_EXTERNAL) == 0)
+ if (part->flag & PART_UNBORN && (psys->pointcache->flag & PTCACHE_EXTERNAL) == 0) {
reset_particle(sim, pa, 0.0f, cfra);
+ }
}
- else if (dietime <= cfra)
+ else if (dietime <= cfra) {
pa->alive = PARS_DEAD;
- else
+ }
+ else {
pa->alive = PARS_ALIVE;
+ }
if (psys->lattice_deform_data) {
end_latt_deform(psys->lattice_deform_data);
psys->lattice_deform_data = NULL;
}
- if (psys_frand(psys, p) > disp)
+ if (psys_frand(psys, p) > disp) {
pa->flag |= PARS_NO_DISP;
- else
+ }
+ else {
pa->flag &= ~PARS_NO_DISP;
+ }
}
}
@@ -4057,8 +4237,9 @@ static int emit_particles(ParticleSimulationData *sim, PTCacheID *pid, float UNU
int oldtotpart = psys->totpart;
int totpart = tot_particles(psys, pid);
- if (totpart != oldtotpart)
+ if (totpart != oldtotpart) {
realloc_particles(sim, totpart);
+ }
return totpart - oldtotpart;
}
@@ -4084,8 +4265,9 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
psys_clear_temp_pointcache(psys);
/* set suitable cache range automatically */
- if ((cache->flag & (PTCACHE_BAKING | PTCACHE_BAKED)) == 0)
+ if ((cache->flag & (PTCACHE_BAKING | PTCACHE_BAKED)) == 0) {
psys_get_pointcache_start_end(sim->scene, psys, &cache->startframe, &cache->endframe);
+ }
pid = &ptcacheid;
BKE_ptcache_id_from_particles(pid, sim->ob, psys);
@@ -4135,8 +4317,9 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
BKE_ptcache_validate(cache, (int)cache_cfra);
- if (cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED)
+ if (cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED) {
BKE_ptcache_write(pid, (int)cache_cfra);
+ }
return;
}
@@ -4151,11 +4334,13 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
}
/* if on second frame, write cache for first frame */
- if (psys->cfra == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0))
+ if (psys->cfra == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) {
BKE_ptcache_write(pid, startframe);
+ }
}
- else
+ else {
BKE_ptcache_invalidate(cache);
+ }
/* 3. do dynamics */
/* set particles to be not calculated TODO: can't work with pointcache */
@@ -4163,10 +4348,12 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
LOOP_PARTICLES
{
- if (psys_frand(psys, p) > disp)
+ if (psys_frand(psys, p) > disp) {
pa->flag |= PARS_NO_DISP;
- else
+ }
+ else {
pa->flag &= ~PARS_NO_DISP;
+ }
}
if (psys->totpart) {
@@ -4175,8 +4362,9 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
/* handle negative frame start at the first frame by doing
* all the steps before the first frame */
- if ((int)cfra == startframe && part->sta < startframe)
+ if ((int)cfra == startframe && part->sta < startframe) {
totframesback = (startframe - (int)part->sta);
+ }
if (!(part->time_flag & PART_TIME_AUTOSF)) {
/* Constant time step */
@@ -4199,8 +4387,9 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
dynamics_step(sim, cfra + dframe + t_frac - 1.f);
psys->cfra = cfra + dframe + t_frac - 1.f;
- if (part->time_flag & PART_TIME_AUTOSF)
+ if (part->time_flag & PART_TIME_AUTOSF) {
update_timestep(psys, sim);
+ }
/* Even without AUTOSF dt_frac may not add up to 1.0 due to float precision. */
dt_frac = sync_timestep(psys, t_frac);
}
@@ -4210,8 +4399,9 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
/* 4. only write cache starting from second frame */
if (pid) {
BKE_ptcache_validate(cache, (int)cache_cfra);
- if ((int)cache_cfra != startframe)
+ if ((int)cache_cfra != startframe) {
BKE_ptcache_write(pid, (int)cache_cfra);
+ }
}
update_children(sim, use_render_params);
@@ -4231,18 +4421,22 @@ void psys_changed_type(Object *ob, ParticleSystem *psys)
BKE_ptcache_id_from_particles(&pid, ob, psys);
- if (part->phystype != PART_PHYS_KEYED)
+ if (part->phystype != PART_PHYS_KEYED) {
psys->flag &= ~PSYS_KEYED;
+ }
if (part->type == PART_HAIR) {
- if (ELEM(part->ren_as, PART_DRAW_NOT, PART_DRAW_PATH, PART_DRAW_OB, PART_DRAW_GR) == 0)
+ if (ELEM(part->ren_as, PART_DRAW_NOT, PART_DRAW_PATH, PART_DRAW_OB, PART_DRAW_GR) == 0) {
part->ren_as = PART_DRAW_PATH;
+ }
- if (part->distr == PART_DISTR_GRID)
+ if (part->distr == PART_DISTR_GRID) {
part->distr = PART_DISTR_JIT;
+ }
- if (ELEM(part->draw_as, PART_DRAW_NOT, PART_DRAW_REND, PART_DRAW_PATH) == 0)
+ if (ELEM(part->draw_as, PART_DRAW_NOT, PART_DRAW_REND, PART_DRAW_PATH) == 0) {
part->draw_as = PART_DRAW_REND;
+ }
CLAMP(part->path_start, 0.0f, 100.0f);
CLAMP(part->path_end, 0.0f, 100.0f);
@@ -4265,8 +4459,9 @@ void psys_check_boid_data(ParticleSystem *psys)
pa = psys->particles;
- if (!pa)
+ if (!pa) {
return;
+ }
if (psys->part && psys->part->phystype == PART_PHYS_BOIDS) {
if (!pa->boid) {
@@ -4371,11 +4566,13 @@ void particle_system_update(struct Depsgraph *depsgraph,
ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
/* drawdata is outdated after ANY change */
- if (psys->pdd)
+ if (psys->pdd) {
psys->pdd->flag &= ~PARTICLE_DRAW_DATA_UPDATED;
+ }
- if (!psys_check_enabled(ob, psys, use_render_params))
+ if (!psys_check_enabled(ob, psys, use_render_params)) {
return;
+ }
cfra = DEG_get_ctime(depsgraph);
@@ -4389,12 +4586,14 @@ void particle_system_update(struct Depsgraph *depsgraph,
if (sim.psmd->flag & eParticleSystemFlag_psys_updated) {
sim.psmd->flag &= ~eParticleSystemFlag_psys_updated;
/* make sure it really was updated to cfra */
- if (psys->cfra == cfra)
+ if (psys->cfra == cfra) {
return;
+ }
}
- if (!sim.psmd->mesh_final)
+ if (!sim.psmd->mesh_final) {
return;
+ }
if (part->from != PART_FROM_VERT) {
BKE_mesh_tessface_ensure(sim.psmd->mesh_final);
@@ -4403,8 +4602,9 @@ void particle_system_update(struct Depsgraph *depsgraph,
/* to verify if we need to restore object afterwards */
psys->flag &= ~PSYS_OB_ANIM_RESTORE;
- if (psys->recalc & ID_RECALC_PSYS_RESET)
+ if (psys->recalc & ID_RECALC_PSYS_RESET) {
psys->totunexist = 0;
+ }
/* setup necessary physics type dependent additional data if it doesn't yet exist */
psys_prepare_physics(&sim);
@@ -4441,9 +4641,10 @@ void particle_system_update(struct Depsgraph *depsgraph,
for (i = 0; i <= part->hair_step; i++) {
hcfra = 100.0f * (float)i / (float)psys->part->hair_step;
- if ((part->flag & PART_HAIR_REGROW) == 0)
+ if ((part->flag & PART_HAIR_REGROW) == 0) {
BKE_animsys_evaluate_animdata(
depsgraph, scene, &part_local->id, part_local->adt, hcfra, ADT_RECALC_ANIM);
+ }
system_step(&sim, hcfra, use_render_params);
psys->cfra = hcfra;
psys->recalc = 0;
@@ -4458,11 +4659,13 @@ void particle_system_update(struct Depsgraph *depsgraph,
psys->flag |= PSYS_HAIR_DONE;
psys->recalc = recalc;
}
- else if (psys->flag & PSYS_EDITED)
+ else if (psys->flag & PSYS_EDITED) {
psys->flag |= PSYS_HAIR_DONE;
+ }
- if (psys->flag & PSYS_HAIR_DONE)
+ if (psys->flag & PSYS_HAIR_DONE) {
hair_step(&sim, cfra, use_render_params);
+ }
break;
}
case PART_FLUID: {
@@ -4478,8 +4681,9 @@ void particle_system_update(struct Depsgraph *depsgraph,
bool free_unexisting = false;
/* Particles without dynamics haven't been reset yet because they don't use pointcache */
- if (psys->recalc & ID_RECALC_PSYS_RESET)
+ if (psys->recalc & ID_RECALC_PSYS_RESET) {
psys_reset(psys, PSYS_RESET_ALL);
+ }
if (emit_particles(&sim, NULL, cfra) || (psys->recalc & ID_RECALC_PSYS_RESET)) {
free_keyed_keys(psys);
@@ -4494,20 +4698,24 @@ void particle_system_update(struct Depsgraph *depsgraph,
LOOP_EXISTING_PARTICLES
{
pa->size = part->size;
- if (part->randsize > 0.0f)
+ if (part->randsize > 0.0f) {
pa->size *= 1.0f - part->randsize * psys_frand(psys, p + 1);
+ }
reset_particle(&sim, pa, 0.0, cfra);
- if (psys_frand(psys, p) > disp)
+ if (psys_frand(psys, p) > disp) {
pa->flag |= PARS_NO_DISP;
- else
+ }
+ else {
pa->flag &= ~PARS_NO_DISP;
+ }
}
/* free unexisting after resetting particles */
- if (free_unexisting)
+ if (free_unexisting) {
free_unexisting_particles(&sim);
+ }
if (part->phystype == PART_PHYS_KEYED) {
psys_count_keyed_targets(&sim);