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:
authorCampbell Barton <ideasman42@gmail.com>2019-04-22 02:19:45 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-22 12:48:16 +0300
commit620b960d3d8cfd90b9f0df6ba3671c33eccb8309 (patch)
tree64f69db4bf9d44f0a32d1c92b0714bf2dc98ff2d /source/blender/editors/physics/particle_edit.c
parentbba60bb564cf5a16cfcac744d4ba82cf8eba3da9 (diff)
Cleanup: style, use braces for editors
Diffstat (limited to 'source/blender/editors/physics/particle_edit.c')
-rw-r--r--source/blender/editors/physics/particle_edit.c506
1 files changed, 337 insertions, 169 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index 68bbda51482..9921ca02af9 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -129,21 +129,24 @@ void PE_free_ptcache_edit(PTCacheEdit *edit)
{
POINT_P;
- if (edit == 0)
+ if (edit == 0) {
return;
+ }
if (edit->points) {
LOOP_POINTS
{
- if (point->keys)
+ if (point->keys) {
MEM_freeN(point->keys);
+ }
}
MEM_freeN(edit->points);
}
- if (edit->mirror_cache)
+ if (edit->mirror_cache) {
MEM_freeN(edit->mirror_cache);
+ }
if (edit->emitter_cosnos) {
MEM_freeN(edit->emitter_cosnos);
@@ -168,8 +171,9 @@ int PE_start_edit(PTCacheEdit *edit)
{
if (edit) {
edit->edited = 1;
- if (edit->psys)
+ if (edit->psys) {
edit->psys->flag |= PSYS_EDITED;
+ }
return 1;
}
@@ -242,8 +246,9 @@ static PTCacheEdit *pe_get_current(Depsgraph *depsgraph, Scene *scene, Object *o
ListBase pidlist;
PTCacheID *pid;
- if (pset == NULL || ob == NULL)
+ if (pset == NULL || ob == NULL) {
return NULL;
+ }
pset->scene = scene;
pset->object = ob;
@@ -273,8 +278,9 @@ static PTCacheEdit *pe_get_current(Depsgraph *depsgraph, Scene *scene, Object *o
if (psys->flag & PSYS_CURRENT) {
if (psys->part && psys->part->type == PART_HAIR) {
if (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED) {
- if (create && !psys->pointcache->edit)
+ if (create && !psys->pointcache->edit) {
PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL);
+ }
edit = pid->cache->edit;
}
else {
@@ -287,8 +293,9 @@ static PTCacheEdit *pe_get_current(Depsgraph *depsgraph, Scene *scene, Object *o
}
}
else {
- if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit)
+ if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) {
PE_create_particle_edit(depsgraph, scene, ob, pid->cache, psys);
+ }
edit = pid->cache->edit;
}
@@ -359,8 +366,9 @@ void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra)
{
LOOP_KEYS
{
- if (fabsf(cfra - *key->time) < pset->fade_frames)
+ if (fabsf(cfra - *key->time) < pset->fade_frames) {
key->flag &= ~PEK_HIDE;
+ }
else {
key->flag |= PEK_HIDE;
//key->flag &= ~PEK_SELECT;
@@ -381,8 +389,9 @@ void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra)
static int pe_x_mirror(Object *ob)
{
- if (ob->type == OB_MESH)
+ if (ob->type == OB_MESH) {
return (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X);
+ }
return 0;
}
@@ -505,10 +514,11 @@ static bool key_test_depth(const PEData *data, const float co[3], const int scre
float depth;
/* nothing to do */
- if (XRAY_ENABLED(v3d))
+ if (XRAY_ENABLED(v3d)) {
return true;
+ }
- /* used to calculate here but all callers have the screen_co already, so pass as arg */
+ /* used to calculate here but all callers have the screen_co already, so pass as arg */
#if 0
if (ED_view3d_project_int_global(data->vc.ar,
co,
@@ -525,16 +535,19 @@ static bool key_test_depth(const PEData *data, const float co[3], const int scre
/* we know its not clipped */
depth = vd->depths[screen_co[1] * vd->w + screen_co[0]];
}
- else
+ else {
return 0;
+ }
float win[3];
ED_view3d_project(data->vc.ar, co, win);
- if (win[2] - 0.00001f > depth)
+ if (win[2] - 0.00001f > depth) {
return 0;
- else
+ }
+ else {
return 1;
+ }
}
static bool key_inside_circle(const PEData *data, float rad, const float co[3], float *distance)
@@ -552,12 +565,14 @@ static bool key_inside_circle(const PEData *data, float rad, const float co[3],
dy = data->mval[1] - screen_co[1];
dist = sqrtf(dx * dx + dy * dy);
- if (dist > rad)
+ if (dist > rad) {
return 0;
+ }
if (key_test_depth(data, co, screen_co)) {
- if (distance)
+ if (distance) {
*distance = dist;
+ }
return 1;
}
@@ -584,18 +599,21 @@ static bool key_inside_rect(PEData *data, const float co[3])
static bool key_inside_test(PEData *data, const float co[3])
{
- if (data->mval)
+ if (data->mval) {
return key_inside_circle(data, data->rad, co, NULL);
- else
+ }
+ else {
return key_inside_rect(data, co);
+ }
}
static bool point_is_selected(PTCacheEditPoint *point)
{
KEY_K;
- if (point->flag & PEP_HIDE)
+ if (point->flag & PEP_HIDE) {
return 0;
+ }
LOOP_SELECTED_KEYS
{
@@ -641,8 +659,9 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, const enum ePartic
float dist = data->rad;
/* in path select mode we have no keys */
- if (pset->selectmode == SCE_SELECT_PATH)
+ if (pset->selectmode == SCE_SELECT_PATH) {
return;
+ }
nearest_point = -1;
nearest_key = -1;
@@ -704,8 +723,9 @@ static void foreach_mouse_hit_point(PEData *data, ForHitPointFunc func, int sele
KEY_K;
/* all is selected in path mode */
- if (pset->selectmode == SCE_SELECT_PATH)
+ if (pset->selectmode == SCE_SELECT_PATH) {
selected = 0;
+ }
LOOP_VISIBLE_POINTS
{
@@ -878,8 +898,9 @@ static int count_selected_keys(Scene *scene, PTCacheEdit *edit)
else if (pset->selectmode == SCE_SELECT_END) {
if (point->totkey) {
key = point->keys + point->totkey - 1;
- if (key->flag & PEK_SELECT)
+ if (key->flag & PEK_SELECT) {
sel++;
+ }
}
}
}
@@ -906,8 +927,9 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys)
psmd_eval = edit->psmd_eval;
totpart = psys->totpart;
- if (!psmd_eval->mesh_final)
+ if (!psmd_eval->mesh_final) {
return;
+ }
tree = BLI_kdtree_3d_new(totpart);
@@ -924,8 +946,9 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys)
BLI_kdtree_3d_balance(tree);
/* lookup particles and set in mirror cache */
- if (!edit->mirror_cache)
+ if (!edit->mirror_cache) {
edit->mirror_cache = MEM_callocN(sizeof(int) * totpart, "PE mirror cache");
+ }
LOOP_PARTICLES
{
@@ -938,10 +961,12 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys)
index = BLI_kdtree_3d_find_nearest(tree, co, &nearest);
/* this needs a custom threshold still, duplicated for editmode mirror */
- if (index != -1 && index != p && (nearest.dist <= 0.0002f))
+ if (index != -1 && index != p && (nearest.dist <= 0.0002f)) {
edit->mirror_cache[p] = index;
- else
+ }
+ else {
edit->mirror_cache[p] = -1;
+ }
}
/* make sure mirrors are in two directions */
@@ -949,8 +974,9 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys)
{
if (edit->mirror_cache[p]) {
index = edit->mirror_cache[p];
- if (edit->mirror_cache[index] != p)
+ if (edit->mirror_cache[index] != p) {
edit->mirror_cache[p] = -1;
+ }
}
}
@@ -972,29 +998,35 @@ static void PE_mirror_particle(
/* find mirrored particle if needed */
if (!mpa) {
- if (!edit->mirror_cache)
+ if (!edit->mirror_cache) {
PE_update_mirror_cache(ob, psys);
+ }
- if (!edit->mirror_cache)
+ if (!edit->mirror_cache) {
return; /* something went wrong! */
+ }
mi = edit->mirror_cache[i];
- if (mi == -1)
+ if (mi == -1) {
return;
+ }
mpa = psys->particles + mi;
}
- else
+ else {
mi = mpa - psys->particles;
+ }
point = edit->points + i;
mpoint = edit->points + mi;
/* make sure they have the same amount of keys */
if (pa->totkey != mpa->totkey) {
- if (mpa->hair)
+ if (mpa->hair) {
MEM_freeN(mpa->hair);
- if (mpoint->keys)
+ }
+ if (mpoint->keys) {
MEM_freeN(mpoint->keys);
+ }
mpa->hair = MEM_dupallocN(pa->hair);
mpa->totkey = pa->totkey;
@@ -1025,16 +1057,19 @@ static void PE_mirror_particle(
mhkey->co[0] = -mhkey->co[0];
mul_m4_v3(immat, mhkey->co);
- if (key->flag & PEK_TAG)
+ if (key->flag & PEK_TAG) {
mkey->flag |= PEK_TAG;
+ }
mkey->length = key->length;
}
- if (point->flag & PEP_TAG)
+ if (point->flag & PEP_TAG) {
mpoint->flag |= PEP_TAG;
- if (point->flag & PEP_EDIT_RECALC)
+ }
+ if (point->flag & PEP_EDIT_RECALC) {
mpoint->flag |= PEP_EDIT_RECALC;
+ }
}
static void PE_apply_mirror(Object *ob, ParticleSystem *psys)
@@ -1043,20 +1078,24 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys)
ParticleSystemModifierData *psmd_eval;
POINT_P;
- if (!psys)
+ if (!psys) {
return;
+ }
edit = psys->edit;
psmd_eval = edit->psmd_eval;
- if (!psmd_eval->mesh_final)
+ if (!psmd_eval->mesh_final) {
return;
+ }
- if (!edit->mirror_cache)
+ if (!edit->mirror_cache) {
PE_update_mirror_cache(ob, psys);
+ }
- if (!edit->mirror_cache)
+ if (!edit->mirror_cache) {
return; /* something went wrong */
+ }
/* we delay settings the PARS_EDIT_RECALC for mirrored particles
* to avoid doing mirror twice */
@@ -1065,16 +1104,19 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys)
if (point->flag & PEP_EDIT_RECALC) {
PE_mirror_particle(ob, psmd_eval->mesh_final, psys, psys->particles + p, NULL);
- if (edit->mirror_cache[p] != -1)
+ if (edit->mirror_cache[p] != -1) {
edit->points[edit->mirror_cache[p]].flag &= ~PEP_EDIT_RECALC;
+ }
}
}
LOOP_POINTS
{
- if (point->flag & PEP_EDIT_RECALC)
- if (edit->mirror_cache[p] != -1)
+ if (point->flag & PEP_EDIT_RECALC) {
+ if (edit->mirror_cache[p] != -1) {
edit->points[edit->mirror_cache[p]].flag |= PEP_EDIT_RECALC;
+ }
+ }
}
}
@@ -1225,11 +1267,13 @@ static void PE_apply_lengths(Scene *scene, PTCacheEdit *edit)
{
ParticleEditSettings *pset = PE_settings(scene);
- if (edit == 0 || (pset->flag & PE_KEEP_LENGTHS) == 0)
+ if (edit == 0 || (pset->flag & PE_KEEP_LENGTHS) == 0) {
return;
+ }
- if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
+ if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) {
return;
+ }
ApplyLengthsIterData iter_data;
iter_data.edit = edit;
@@ -1321,8 +1365,9 @@ void recalc_lengths(PTCacheEdit *edit)
POINT_P;
KEY_K;
- if (edit == 0)
+ if (edit == 0) {
return;
+ }
LOOP_EDITED_POINTS
{
@@ -1341,11 +1386,13 @@ void recalc_emitter_field(Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), Part
float *vec, *nor;
int i, totface /*, totvert*/;
- if (!mesh)
+ if (!mesh) {
return;
+ }
- if (edit->emitter_cosnos)
+ if (edit->emitter_cosnos) {
MEM_freeN(edit->emitter_cosnos);
+ }
BLI_kdtree_3d_free(edit->emitter_field);
@@ -1402,11 +1449,12 @@ static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob,
KEY_K;
/* flag all particles to be updated if not using flag */
- if (!useflag)
+ if (!useflag) {
LOOP_POINTS
{
point->flag |= PEP_EDIT_RECALC;
}
+ }
/* flush edit key flag to hair key flag to preserve selection
* on save */
@@ -1441,20 +1489,23 @@ void update_world_cos(Depsgraph *UNUSED(depsgraph), Object *ob, PTCacheEdit *edi
KEY_K;
float hairmat[4][4];
- if (psys == 0 || psys->edit == 0 || psmd_eval->mesh_final == NULL)
+ if (psys == 0 || psys->edit == 0 || psmd_eval->mesh_final == NULL) {
return;
+ }
LOOP_POINTS
{
- if (!(psys->flag & PSYS_GLOBAL_HAIR))
+ if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
psys_mat_hair_to_global(
ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, hairmat);
+ }
LOOP_KEYS
{
copy_v3_v3(key->world_co, key->co);
- if (!(psys->flag & PSYS_GLOBAL_HAIR))
+ if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
mul_m4_v3(hairmat, key->world_co);
+ }
}
}
}
@@ -1466,8 +1517,9 @@ static void update_velocities(PTCacheEdit *edit)
KEY_K;
/* hair doesn't use velocities */
- if (edit->psys || !edit->points || !edit->points->keys->vel)
+ if (edit->psys || !edit->points || !edit->points->keys->vel) {
return;
+ }
frs_sec = edit->pid.flag & PTCACHE_VEL_PER_SEC ? 25.0f : 1.0f;
@@ -1478,8 +1530,9 @@ static void update_velocities(PTCacheEdit *edit)
if (k == 0) {
dfra = *(key + 1)->time - *key->time;
- if (dfra <= 0.0f)
+ if (dfra <= 0.0f) {
continue;
+ }
sub_v3_v3v3(key->vel, (key + 1)->co, key->co);
@@ -1493,8 +1546,9 @@ static void update_velocities(PTCacheEdit *edit)
else if (k == point->totkey - 1) {
dfra = *key->time - *(key - 1)->time;
- if (dfra <= 0.0f)
+ if (dfra <= 0.0f) {
continue;
+ }
sub_v3_v3v3(key->vel, key->co, (key - 1)->co);
@@ -1508,8 +1562,9 @@ static void update_velocities(PTCacheEdit *edit)
else {
dfra = *(key + 1)->time - *(key - 1)->time;
- if (dfra <= 0.0f)
+ if (dfra <= 0.0f) {
continue;
+ }
sub_v3_v3v3(key->vel, (key + 1)->co, (key - 1)->co);
}
@@ -1526,26 +1581,31 @@ void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int usefla
PTCacheEdit *edit = PE_get_current(scene, ob);
POINT_P;
- if (!edit)
+ if (!edit) {
return;
+ }
/* flag all particles to be updated if not using flag */
- if (!useflag)
+ if (!useflag) {
LOOP_POINTS
{
point->flag |= PEP_EDIT_RECALC;
}
+ }
/* do post process on particle edit keys */
pe_iterate_lengths(scene, edit);
pe_deflect_emitter(scene, ob, edit);
PE_apply_lengths(scene, edit);
- if (pe_x_mirror(ob))
+ if (pe_x_mirror(ob)) {
PE_apply_mirror(ob, edit->psys);
- if (edit->psys)
+ }
+ if (edit->psys) {
update_world_cos(depsgraph, ob, edit);
- if (pset->flag & PE_AUTO_VELOCITY)
+ }
+ if (pset->flag & PE_AUTO_VELOCITY) {
update_velocities(edit);
+ }
PE_hide_keys_time(scene, edit, CFRA);
/* regenerate path caches */
@@ -1557,8 +1617,9 @@ void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int usefla
point->flag &= ~PEP_EDIT_RECALC;
}
- if (edit->psys)
+ if (edit->psys) {
edit->psys->flag &= ~PSYS_HAIR_UPDATED;
+ }
}
/************************************************/
@@ -1573,10 +1634,12 @@ static void select_key(PEData *data, int point_index, int key_index, bool UNUSED
PTCacheEditPoint *point = edit->points + point_index;
PTCacheEditKey *key = point->keys + key_index;
- if (data->select)
+ if (data->select) {
key->flag |= PEK_SELECT;
- else
+ }
+ else {
key->flag &= ~PEK_SELECT;
+ }
point->flag |= PEP_EDIT_RECALC;
data->is_changed = true;
@@ -1607,10 +1670,12 @@ static void select_keys(PEData *data,
LOOP_KEYS
{
- if (data->select)
+ if (data->select) {
key->flag |= PEK_SELECT;
- else
+ }
+ else {
key->flag &= ~PEK_SELECT;
+ }
}
point->flag |= PEP_EDIT_RECALC;
@@ -1712,8 +1777,9 @@ static int pe_select_all_exec(bContext *C, wmOperator *op)
break;
}
- if (action == SEL_DESELECT)
+ if (action == SEL_DESELECT) {
break;
+ }
}
}
@@ -1806,8 +1872,9 @@ static void select_root(PEData *data, int point_index)
PTCacheEditPoint *point = data->edit->points + point_index;
PTCacheEditKey *key = point->keys;
- if (point->flag & PEP_HIDE)
+ if (point->flag & PEP_HIDE) {
return;
+ }
if (data->select_action != SEL_TOGGLE) {
data->is_changed = select_action_apply(point, key, data->select_action);
@@ -1874,8 +1941,9 @@ static void select_tip(PEData *data, int point_index)
key = &point->keys[point->totkey - 1];
- if (point->flag & PEP_HIDE)
+ if (point->flag & PEP_HIDE) {
return;
+ }
if (data->select_action != SEL_TOGGLE) {
data->is_changed = select_action_apply(point, key, data->select_action);
@@ -2190,8 +2258,9 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, const
unit_m4(mat);
- if (!PE_start_edit(edit))
+ if (!PE_start_edit(edit)) {
return OPERATOR_CANCELLED;
+ }
/* only for depths */
PE_set_view3d_data(C, &data);
@@ -2202,9 +2271,10 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, const
LOOP_VISIBLE_POINTS
{
- if (edit->psys && !(psys->flag & PSYS_GLOBAL_HAIR))
+ if (edit->psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
psys_mat_hair_to_global(
ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat);
+ }
if (pset->selectmode == SCE_SELECT_POINT) {
LOOP_KEYS
@@ -2375,16 +2445,19 @@ static void select_less_keys(PEData *data, int point_index)
LOOP_SELECTED_KEYS
{
if (k == 0) {
- if (((key + 1)->flag & PEK_SELECT) == 0)
+ if (((key + 1)->flag & PEK_SELECT) == 0) {
key->flag |= PEK_TAG;
+ }
}
else if (k == point->totkey - 1) {
- if (((key - 1)->flag & PEK_SELECT) == 0)
+ if (((key - 1)->flag & PEK_SELECT) == 0) {
key->flag |= PEK_TAG;
+ }
}
else {
- if ((((key - 1)->flag & (key + 1)->flag) & PEK_SELECT) == 0)
+ if ((((key - 1)->flag & (key + 1)->flag) & PEK_SELECT) == 0) {
key->flag |= PEK_TAG;
+ }
}
}
@@ -2436,20 +2509,24 @@ static void select_more_keys(PEData *data, int point_index)
LOOP_KEYS
{
- if (key->flag & PEK_SELECT)
+ if (key->flag & PEK_SELECT) {
continue;
+ }
if (k == 0) {
- if ((key + 1)->flag & PEK_SELECT)
+ if ((key + 1)->flag & PEK_SELECT) {
key->flag |= PEK_TAG;
+ }
}
else if (k == point->totkey - 1) {
- if ((key - 1)->flag & PEK_SELECT)
+ if ((key - 1)->flag & PEK_SELECT) {
key->flag |= PEK_TAG;
+ }
}
else {
- if (((key - 1)->flag | (key + 1)->flag) & PEK_SELECT)
+ if (((key - 1)->flag | (key + 1)->flag) & PEK_SELECT) {
key->flag |= PEK_TAG;
+ }
}
}
@@ -2534,22 +2611,25 @@ static void rekey_particle(PEData *data, int pa_index)
}
/* replace keys */
- if (pa->hair)
+ if (pa->hair) {
MEM_freeN(pa->hair);
+ }
pa->hair = new_keys;
point->totkey = pa->totkey = data->totrekey;
- if (point->keys)
+ if (point->keys) {
MEM_freeN(point->keys);
+ }
ekey = point->keys = MEM_callocN(pa->totkey * sizeof(PTCacheEditKey), "Hair re-key edit keys");
for (k = 0, key = pa->hair; k < pa->totkey; k++, key++, ekey++) {
ekey->co = key->co;
ekey->time = &key->time;
ekey->flag |= PEK_SELECT;
- if (!(psys->flag & PSYS_GLOBAL_HAIR))
+ if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
ekey->flag |= PEK_USE_WCO;
+ }
}
pa->flag &= ~PARS_REKEY;
@@ -2605,8 +2685,9 @@ static void rekey_particle_to_time(
PTCacheEditKey *ekey;
int k;
- if (!edit || !edit->psys)
+ if (!edit || !edit->psys) {
return;
+ }
psys = edit->psys;
@@ -2629,8 +2710,9 @@ static void rekey_particle_to_time(
}
/* replace hair keys */
- if (pa->hair)
+ if (pa->hair) {
MEM_freeN(pa->hair);
+ }
pa->hair = new_keys;
/* update edit pointers */
@@ -2678,10 +2760,12 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror)
if (ELEM(NULL, new_pars, new_points)) {
/* allocation error! */
- if (new_pars)
+ if (new_pars) {
MEM_freeN(new_pars);
- if (new_points)
+ }
+ if (new_points) {
MEM_freeN(new_points);
+ }
return 0;
}
}
@@ -2690,10 +2774,12 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror)
point = edit->points;
for (i = 0; i < psys->totpart; i++, pa++, point++) {
if (point->flag & PEP_TAG) {
- if (point->keys)
+ if (point->keys) {
MEM_freeN(point->keys);
- if (pa->hair)
+ }
+ if (pa->hair) {
MEM_freeN(pa->hair);
+ }
}
else {
memcpy(npa, pa, sizeof(ParticleData));
@@ -2703,12 +2789,14 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror)
}
}
- if (psys->particles)
+ if (psys->particles) {
MEM_freeN(psys->particles);
+ }
psys->particles = new_pars;
- if (edit->points)
+ if (edit->points) {
MEM_freeN(edit->points);
+ }
edit->points = new_points;
if (edit->mirror_cache) {
@@ -2762,8 +2850,9 @@ static void remove_tagged_keys(Depsgraph *depsgraph, Object *ob, ParticleSystem
new_totkey--;
}
/* we can't have elements with less than two keys*/
- if (new_totkey < 2)
+ if (new_totkey < 2) {
point->flag |= PEP_TAG;
+ }
}
remove_tagged_particles(ob, psys, pe_x_mirror(ob));
@@ -2808,11 +2897,13 @@ static void remove_tagged_keys(Depsgraph *depsgraph, Object *ob, ParticleSystem
hkey++;
}
- if (pa->hair)
+ if (pa->hair) {
MEM_freeN(pa->hair);
+ }
- if (point->keys)
+ if (point->keys) {
MEM_freeN(point->keys);
+ }
pa->hair = new_hkeys;
point->keys = new_keys;
@@ -2849,12 +2940,14 @@ static void subdivide_particle(PEData *data, int pa_index)
sim.psys = edit->psys;
for (k = 0, ekey = point->keys; k < pa->totkey - 1; k++, ekey++) {
- if (ekey->flag & PEK_SELECT && (ekey + 1)->flag & PEK_SELECT)
+ if (ekey->flag & PEK_SELECT && (ekey + 1)->flag & PEK_SELECT) {
totnewkey++;
+ }
}
- if (totnewkey == 0)
+ if (totnewkey == 0) {
return;
+ }
pa->flag |= PARS_REKEY;
@@ -2886,8 +2979,9 @@ static void subdivide_particle(PEData *data, int pa_index)
nekey->co = nkey->co;
nekey->time = &nkey->time;
nekey->flag |= PEK_SELECT;
- if (!(psys->flag & PSYS_GLOBAL_HAIR))
+ if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
nekey->flag |= PEK_USE_WCO;
+ }
nekey++;
nkey++;
@@ -2900,12 +2994,14 @@ static void subdivide_particle(PEData *data, int pa_index)
nekey->co = nkey->co;
nekey->time = &nkey->time;
- if (pa->hair)
+ if (pa->hair) {
MEM_freeN(pa->hair);
+ }
pa->hair = new_keys;
- if (point->keys)
+ if (point->keys) {
MEM_freeN(point->keys);
+ }
point->keys = new_ekeys;
point->totkey = pa->totkey = pa->totkey + totnewkey;
@@ -2959,8 +3055,9 @@ static int remove_doubles_exec(bContext *C, wmOperator *op)
float mat[4][4], co[3], threshold = RNA_float_get(op->ptr, "threshold");
int n, totn, removed, totremoved;
- if (psys->flag & PSYS_GLOBAL_HAIR)
+ if (psys->flag & PSYS_GLOBAL_HAIR) {
return OPERATOR_CANCELLED;
+ }
edit = psys->edit;
psmd_eval = edit->psmd_eval;
@@ -3011,8 +3108,9 @@ static int remove_doubles_exec(bContext *C, wmOperator *op)
totremoved += removed;
} while (removed);
- if (totremoved == 0)
+ if (totremoved == 0) {
return OPERATOR_CANCELLED;
+ }
BKE_reportf(op->reports, RPT_INFO, "Removed %d double particles", totremoved);
@@ -3147,9 +3245,10 @@ static void toggle_particle_cursor(bContext *C, int enable)
WM_paint_cursor_end(CTX_wm_manager(C), pset->paintcursor);
pset->paintcursor = NULL;
}
- else if (enable)
+ else if (enable) {
pset->paintcursor = WM_paint_cursor_activate(
CTX_wm_manager(C), SPACE_VIEW3D, RGN_TYPE_WINDOW, PE_poll_view3d, brush_drawcursor, NULL);
+ }
}
/*************************** delete operator **************************/
@@ -3243,12 +3342,14 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged)
int *mirrorfaces = NULL;
int rotation, totpart, newtotpart;
- if (psys->flag & PSYS_GLOBAL_HAIR)
+ if (psys->flag & PSYS_GLOBAL_HAIR) {
return;
+ }
psmd_eval = edit->psmd_eval;
- if (!psmd_eval->mesh_final)
+ if (!psmd_eval->mesh_final) {
return;
+ }
const bool use_dm_final_indices = (psys->part->use_modifier_stack &&
!psmd_eval->mesh_final->runtime.deformed_only);
@@ -3261,8 +3362,9 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged)
mirrorfaces = mesh_get_x_mirror_faces(
ob, NULL, use_dm_final_indices ? psmd_eval->mesh_final : NULL);
- if (!edit->mirror_cache)
+ if (!edit->mirror_cache) {
PE_update_mirror_cache(ob, psys);
+ }
totpart = psys->totpart;
newtotpart = psys->totpart;
@@ -3277,13 +3379,15 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged)
PE_mirror_particle(ob, psmd_eval->mesh_final, psys, pa, NULL);
continue;
}
- else
+ else {
point->flag |= PEP_TAG;
+ }
}
}
- if ((point->flag & PEP_TAG) && mirrorfaces[pa->num * 2] != -1)
+ if ((point->flag & PEP_TAG) && mirrorfaces[pa->num * 2] != -1) {
newtotpart++;
+ }
}
if (newtotpart != psys->totpart) {
@@ -3320,19 +3424,23 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged)
pa = psys->particles + p;
const int pa_num = pa->num;
- if (point->flag & PEP_HIDE)
+ if (point->flag & PEP_HIDE) {
continue;
+ }
- if (!(point->flag & PEP_TAG) || mirrorfaces[pa_num * 2] == -1)
+ if (!(point->flag & PEP_TAG) || mirrorfaces[pa_num * 2] == -1) {
continue;
+ }
/* duplicate */
*newpa = *pa;
*newpoint = *point;
- if (pa->hair)
+ if (pa->hair) {
newpa->hair = MEM_dupallocN(pa->hair);
- if (point->keys)
+ }
+ if (point->keys) {
newpoint->keys = MEM_dupallocN(point->keys);
+ }
/* rotate weights according to vertex index rotation */
rotation = mirrorfaces[pa_num * 2 + 1];
@@ -3428,8 +3536,9 @@ static void brush_comb(PEData *data,
ParticleEditSettings *pset = PE_settings(data->scene);
float cvec[3], fac;
- if (pset->flag & PE_LOCK_FIRST && key_index == 0)
+ if (pset->flag & PE_LOCK_FIRST && key_index == 0) {
return;
+ }
fac = (float)pow((double)(1.0f - mouse_distance / data->rad), (double)data->combfac);
@@ -3460,12 +3569,14 @@ static void brush_cut(PEData *data, int pa_index)
}
/* don't cut hidden */
- if (edit->points[pa_index].flag & PEP_HIDE)
+ if (edit->points[pa_index].flag & PEP_HIDE) {
return;
+ }
if (ED_view3d_project_int_global(ar, key->co, screen_co, V3D_PROJ_TEST_CLIP_NEAR) !=
- V3D_PROJ_RET_OK)
+ V3D_PROJ_RET_OK) {
return;
+ }
rad2 = data->rad * data->rad;
@@ -3616,8 +3727,9 @@ static void brush_puff(PEData *data, int point_index, float mouse_distance)
mul_v3_m4v3(kco, data->ob->imat, co);
point_index = BLI_kdtree_3d_find_nearest(edit->emitter_field, kco, NULL);
- if (point_index == -1)
+ if (point_index == -1) {
return;
+ }
copy_v3_v3(co_root, co);
copy_v3_v3(no_root, &edit->emitter_cosnos[point_index * 6 + 3]);
@@ -3632,8 +3744,9 @@ static void brush_puff(PEData *data, int point_index, float mouse_distance)
fac = (float)pow((double)(1.0f - mouse_distance / data->rad), (double)data->pufffac);
fac *= 0.025f;
- if (data->invert)
+ if (data->invert) {
fac = -fac;
+ }
}
else {
/* compute position as if hair was standing up straight.
@@ -3729,8 +3842,9 @@ static void brush_puff(PEData *data, int point_index, float mouse_distance)
}
}
- if (changed)
+ if (changed) {
point->flag |= PEP_EDIT_RECALC;
+ }
}
static void BKE_brush_weight_get(PEData *data,
@@ -3877,15 +3991,17 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
copy_v3_v3(v1, vert_cos + 3 * mface->v1);
copy_v3_v3(v2, vert_cos + 3 * mface->v2);
copy_v3_v3(v3, vert_cos + 3 * mface->v3);
- if (mface->v4)
+ if (mface->v4) {
copy_v3_v3(v4, vert_cos + 3 * mface->v4);
+ }
}
else {
copy_v3_v3(v1, mvert[mface->v1].co);
copy_v3_v3(v2, mvert[mface->v2].co);
copy_v3_v3(v3, mvert[mface->v3].co);
- if (mface->v4)
+ if (mface->v4) {
copy_v3_v3(v4, mvert[mface->v4].co);
+ }
}
if (face_minmax == 0) {
@@ -3893,16 +4009,19 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
DO_MINMAX(v1, min, max);
DO_MINMAX(v2, min, max);
DO_MINMAX(v3, min, max);
- if (mface->v4)
+ if (mface->v4) {
DO_MINMAX(v4, min, max);
- if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0)
+ }
+ if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0) {
continue;
+ }
}
else {
copy_v3_v3(min, face_minmax + 6 * i);
copy_v3_v3(max, face_minmax + 6 * i + 3);
- if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0)
+ if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0) {
continue;
+ }
}
if (radius > 0.0f) {
@@ -3933,8 +4052,9 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
min_w[1] = cur_uv[0];
min_w[2] = cur_uv[1];
min_w[3] = 0.0f;
- if (mface->v4)
+ if (mface->v4) {
intersect_dm_quad_weights(v1, v2, v3, v4, min_w);
+ }
*min_face = i;
intersect = 1;
}
@@ -4090,8 +4210,9 @@ static int brush_add(const bContext *C, PEData *data, short number)
invert_m4_m4(imat, ob->obmat);
- if (psys->flag & PSYS_GLOBAL_HAIR)
+ if (psys->flag & PSYS_GLOBAL_HAIR) {
return 0;
+ }
add_pars = MEM_callocN(number * sizeof(ParticleData), "ParticleData add");
@@ -4173,12 +4294,14 @@ static int brush_add(const bContext *C, PEData *data, short number)
memcpy(new_points, edit->points, totpart * sizeof(PTCacheEditPoint));
/* change old arrays to new ones */
- if (psys->particles)
+ if (psys->particles) {
MEM_freeN(psys->particles);
+ }
psys->particles = new_pars;
- if (edit->points)
+ if (edit->points) {
MEM_freeN(edit->points);
+ }
edit->points = new_points;
if (edit->mirror_cache) {
@@ -4225,16 +4348,18 @@ static int brush_add(const bContext *C, PEData *data, short number)
key->co = hkey->co;
key->time = &hkey->time;
- if (!(psys->flag & PSYS_GLOBAL_HAIR))
+ if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
key->flag |= PEK_USE_WCO;
+ }
}
pa->size = 1.0f;
initialize_particle(&sim, pa);
reset_particle(&sim, pa, 0.0, 1.0);
point->flag |= PEP_EDIT_RECALC;
- if (pe_x_mirror(ob))
+ if (pe_x_mirror(ob)) {
point->flag |= PEP_TAG; /* signal for duplicate */
+ }
framestep = pa->lifetime / (float)(pset->totaddkey - 1);
@@ -4270,12 +4395,14 @@ static int brush_add(const bContext *C, PEData *data, short number)
}
if (totw > 0.0f) {
- for (w = 0; w < maxw; w++)
+ for (w = 0; w < maxw; w++) {
weight[w] /= totw;
+ }
}
else {
- for (w = 0; w < maxw; w++)
+ for (w = 0; w < maxw; w++) {
weight[w] = 1.0f / maxw;
+ }
}
ppa = psys->particles + ptn[0].index;
@@ -4305,8 +4432,9 @@ static int brush_add(const bContext *C, PEData *data, short number)
}
}
- if (k == 0)
+ if (k == 0) {
sub_v3_v3v3(co1, pa->state.co, key3[0].co);
+ }
add_v3_v3v3(thkey->co, key3[0].co, co1);
@@ -4327,8 +4455,9 @@ static int brush_add(const bContext *C, PEData *data, short number)
}
}
- if (tree)
+ if (tree) {
BLI_kdtree_3d_free(tree);
+ }
}
MEM_freeN(add_pars);
@@ -4408,8 +4537,9 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
float dx, dy, dmax;
int lock_root = pset->flag & PE_LOCK_FIRST;
- if (!PE_start_edit(edit))
+ if (!PE_start_edit(edit)) {
return;
+ }
RNA_float_get_array(itemptr, "mouse", mousef);
mouse[0] = mousef[0];
@@ -4428,8 +4558,9 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
mval[1] = mouse[1];
/* disable locking temporatily for disconnected hair */
- if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
+ if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) {
pset->flag &= ~PE_LOCK_FIRST;
+ }
if (((pset->brushtype == PE_BRUSH_ADD) ?
(sqrtf(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) :
@@ -4458,10 +4589,12 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
data.rad = pe_brush_size_get(scene, brush);
data.combfac = (brush->strength - 0.5f) * 2.0f;
- if (data.combfac < 0.0f)
+ if (data.combfac < 0.0f) {
data.combfac = 1.0f - 9.0f * data.combfac;
- else
+ }
+ else {
data.combfac = 1.0f - data.combfac;
+ }
invert_m4_m4(ob->imat, ob->obmat);
@@ -4477,17 +4610,21 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
data.rad = pe_brush_size_get(scene, brush);
data.cutfac = brush->strength;
- if (selected)
+ if (selected) {
foreach_selected_point(&data, brush_cut);
- else
+ }
+ else {
foreach_point(&data, brush_cut);
+ }
removed = remove_tagged_particles(ob, edit->psys, pe_x_mirror(ob));
- if (pset->flag & PE_KEEP_LENGTHS)
+ if (pset->flag & PE_KEEP_LENGTHS) {
recalc_lengths(edit);
+ }
}
- else
+ else {
removed = 0;
+ }
break;
}
@@ -4497,15 +4634,18 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
data.rad = pe_brush_size_get(scene, brush);
data.growfac = brush->strength / 50.0f;
- if (brush->invert ^ flip)
+ if (brush->invert ^ flip) {
data.growfac = 1.0f - data.growfac;
- else
+ }
+ else {
data.growfac = 1.0f + data.growfac;
+ }
foreach_mouse_hit_point(&data, brush_length, selected);
- if (pset->flag & PE_KEEP_LENGTHS)
+ if (pset->flag & PE_KEEP_LENGTHS) {
recalc_lengths(edit);
+ }
break;
}
case PE_BRUSH_PUFF: {
@@ -4516,10 +4656,12 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
data.select = selected;
data.pufffac = (brush->strength - 0.5f) * 2.0f;
- if (data.pufffac < 0.0f)
+ if (data.pufffac < 0.0f) {
data.pufffac = 1.0f - 9.0f * data.pufffac;
- else
+ }
+ else {
data.pufffac = 1.0f - data.pufffac;
+ }
data.invert = (brush->invert ^ flip);
invert_m4_m4(ob->imat, ob->obmat);
@@ -4534,11 +4676,13 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
added = brush_add(C, &data, brush->count);
- if (pset->flag & PE_KEEP_LENGTHS)
+ if (pset->flag & PE_KEEP_LENGTHS) {
recalc_lengths(edit);
+ }
}
- else
+ else {
added = 0;
+ }
break;
}
case PE_BRUSH_SMOOTH: {
@@ -4575,12 +4719,14 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
break;
}
}
- if ((pset->flag & PE_KEEP_LENGTHS) == 0)
+ if ((pset->flag & PE_KEEP_LENGTHS) == 0) {
recalc_lengths(edit);
+ }
if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_CUT) && (added || removed)) {
- if (pset->brushtype == PE_BRUSH_ADD && pe_x_mirror(ob))
+ if (pset->brushtype == PE_BRUSH_ADD && pe_x_mirror(ob)) {
PE_mirror_x(scene, ob, 1);
+ }
update_world_cos(depsgraph, ob, edit);
psys_free_path_cache(NULL, edit);
@@ -4619,8 +4765,9 @@ static void brush_edit_exit(wmOperator *op)
static int brush_edit_exec(bContext *C, wmOperator *op)
{
- if (!brush_edit_init(C, op))
+ if (!brush_edit_init(C, op)) {
return OPERATOR_CANCELLED;
+ }
RNA_BEGIN (op->ptr, itemptr, "stroke") {
brush_edit_apply(C, op, &itemptr);
@@ -4651,8 +4798,9 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, const wmEvent *e
static int brush_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- if (!brush_edit_init(C, op))
+ if (!brush_edit_init(C, op)) {
return OPERATOR_CANCELLED;
+ }
brush_edit_apply_event(C, op, event);
@@ -4738,8 +4886,9 @@ static void point_inside_bvh_cb(void *userdata,
data->bvhdata.raycast_callback(&data->bvhdata, index, ray, hit);
- if (hit->index != -1)
+ if (hit->index != -1) {
++data->num_hits;
+ }
}
/* true if the point is inside the shape mesh */
@@ -4771,8 +4920,9 @@ static void shape_cut(PEData *data, int pa_index)
int k, totkeys = 1 << pset->draw_step;
/* don't cut hidden */
- if (edit->points[pa_index].flag & PEP_HIDE)
+ if (edit->points[pa_index].flag & PEP_HIDE) {
return;
+ }
cut = false;
@@ -4833,12 +4983,14 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op))
int selected = count_selected_keys(scene, edit);
int lock_root = pset->flag & PE_LOCK_FIRST;
- if (!PE_start_edit(edit))
+ if (!PE_start_edit(edit)) {
return OPERATOR_CANCELLED;
+ }
/* disable locking temporatily for disconnected hair */
- if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
+ if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) {
pset->flag &= ~PE_LOCK_FIRST;
+ }
if (edit->psys && edit->pathcache) {
PEData data;
@@ -4850,10 +5002,12 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED;
}
- if (selected)
+ if (selected) {
foreach_selected_point(&data, shape_cut);
- else
+ }
+ else {
foreach_point(&data, shape_cut);
+ }
removed = remove_tagged_particles(ob, edit->psys, pe_x_mirror(ob));
recalc_lengths(edit);
@@ -4913,19 +5067,23 @@ int PE_minmax(Scene *scene, ViewLayer *view_layer, float min[3], float max[3])
float co[3], mat[4][4];
int ok = 0;
- if (!edit)
+ if (!edit) {
return ok;
+ }
- if ((psys = edit->psys))
+ if ((psys = edit->psys)) {
psmd_eval = edit->psmd_eval;
- else
+ }
+ else {
unit_m4(mat);
+ }
LOOP_VISIBLE_POINTS
{
- if (psys)
+ if (psys) {
psys_mat_hair_to_global(
ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat);
+ }
LOOP_SELECTED_KEYS
{
@@ -4965,14 +5123,17 @@ void PE_create_particle_edit(
}
/* no psmd->dm happens in case particle system modifier is not enabled */
- if (!(psys && psmd && psmd_eval->mesh_final) && !cache)
+ if (!(psys && psmd && psmd_eval->mesh_final) && !cache) {
return;
+ }
- if (cache && cache->flag & PTCACHE_DISK_CACHE)
+ if (cache && cache->flag & PTCACHE_DISK_CACHE) {
return;
+ }
- if (psys == NULL && (cache && BLI_listbase_is_empty(&cache->mem_cache)))
+ if (psys == NULL && (cache && BLI_listbase_is_empty(&cache->mem_cache))) {
return;
+ }
edit = (psys) ? psys->edit : cache->edit;
@@ -5033,21 +5194,24 @@ void PE_create_particle_edit(
cache->free_edit = PE_free_ptcache_edit;
edit->psys = NULL;
- for (pm = cache->mem_cache.first; pm; pm = pm->next)
+ for (pm = cache->mem_cache.first; pm; pm = pm->next) {
totframe++;
+ }
for (pm = cache->mem_cache.first; pm; pm = pm->next) {
LOOP_POINTS
{
- if (BKE_ptcache_mem_pointers_seek(p, pm) == 0)
+ if (BKE_ptcache_mem_pointers_seek(p, pm) == 0) {
continue;
+ }
if (!point->totkey) {
key = point->keys = MEM_callocN(totframe * sizeof(PTCacheEditKey), "ParticleEditKeys");
point->flag |= PEP_EDIT_RECALC;
}
- else
+ else {
key = point->keys + point->totkey;
+ }
key->co = pm->cur[BPHYS_DATA_LOCATION];
key->vel = pm->cur[BPHYS_DATA_VELOCITY];
@@ -5071,8 +5235,9 @@ void PE_create_particle_edit(
memset(edit->nosel_col, 0x00, sizeof(edit->nosel_col));
#endif
recalc_lengths(edit);
- if (psys && !cache)
+ if (psys && !cache) {
recalc_emitter_field(depsgraph, ob, psys);
+ }
PE_update_object(depsgraph, scene, ob, 1);
}
@@ -5082,12 +5247,15 @@ static bool particle_edit_toggle_poll(bContext *C)
{
Object *ob = CTX_data_active_object(C);
- if (ob == NULL || ob->type != OB_MESH)
+ if (ob == NULL || ob->type != OB_MESH) {
return 0;
- if (!ob->data || ID_IS_LINKED(ob->data))
+ }
+ if (!ob->data || ID_IS_LINKED(ob->data)) {
return 0;
- if (CTX_data_edit_object(C))
+ }
+ if (CTX_data_edit_object(C)) {
return 0;
+ }
return (ob->particlesystem.first || modifiers_findByType(ob, eModifierType_Cloth) ||
modifiers_findByType(ob, eModifierType_Softbody));