diff options
Diffstat (limited to 'source/blender/editors/physics/particle_edit.c')
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 797 |
1 files changed, 399 insertions, 398 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 15f2006e2b8..68d464da261 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -89,16 +89,16 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys); #define KEY_K PTCacheEditKey *key; int k #define POINT_P PTCacheEditPoint *point; int p -#define LOOP_POINTS for(p=0, point=edit->points; p<edit->totpoint; p++, point++) -#define LOOP_VISIBLE_POINTS for(p=0, point=edit->points; p<edit->totpoint; p++, point++) if(!(point->flag & PEP_HIDE)) -#define LOOP_SELECTED_POINTS for(p=0, point=edit->points; p<edit->totpoint; p++, point++) if(point_is_selected(point)) -#define LOOP_UNSELECTED_POINTS for(p=0, point=edit->points; p<edit->totpoint; p++, point++) if(!point_is_selected(point)) -#define LOOP_EDITED_POINTS for(p=0, point=edit->points; p<edit->totpoint; p++, point++) if(point->flag & PEP_EDIT_RECALC) -#define LOOP_TAGGED_POINTS for(p=0, point=edit->points; p<edit->totpoint; p++, point++) if(point->flag & PEP_TAG) -#define LOOP_KEYS for(k=0, key=point->keys; k<point->totkey; k++, key++) -#define LOOP_VISIBLE_KEYS for(k=0, key=point->keys; k<point->totkey; k++, key++) if(!(key->flag & PEK_HIDE)) -#define LOOP_SELECTED_KEYS for(k=0, key=point->keys; k<point->totkey; k++, key++) if((key->flag & PEK_SELECT) && !(key->flag & PEK_HIDE)) -#define LOOP_TAGGED_KEYS for(k=0, key=point->keys; k<point->totkey; k++, key++) if(key->flag & PEK_TAG) +#define LOOP_POINTS for (p=0, point=edit->points; p<edit->totpoint; p++, point++) +#define LOOP_VISIBLE_POINTS for (p=0, point=edit->points; p<edit->totpoint; p++, point++) if(!(point->flag & PEP_HIDE)) +#define LOOP_SELECTED_POINTS for (p=0, point=edit->points; p<edit->totpoint; p++, point++) if(point_is_selected(point)) +#define LOOP_UNSELECTED_POINTS for (p=0, point=edit->points; p<edit->totpoint; p++, point++) if(!point_is_selected(point)) +#define LOOP_EDITED_POINTS for (p=0, point=edit->points; p<edit->totpoint; p++, point++) if(point->flag & PEP_EDIT_RECALC) +#define LOOP_TAGGED_POINTS for (p=0, point=edit->points; p<edit->totpoint; p++, point++) if(point->flag & PEP_TAG) +#define LOOP_KEYS for (k=0, key=point->keys; k<point->totkey; k++, key++) +#define LOOP_VISIBLE_KEYS for (k=0, key=point->keys; k<point->totkey; k++, key++) if(!(key->flag & PEK_HIDE)) +#define LOOP_SELECTED_KEYS for (k=0, key=point->keys; k<point->totkey; k++, key++) if((key->flag & PEK_SELECT) && !(key->flag & PEK_HIDE)) +#define LOOP_TAGGED_KEYS for (k=0, key=point->keys; k<point->totkey; k++, key++) if(key->flag & PEK_TAG) #define KEY_WCO (key->flag & PEK_USE_WCO ? key->world_co : key->co) @@ -109,7 +109,7 @@ int PE_poll(bContext *C) Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); - if(!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) + if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) return 0; return (PE_get_current(scene, ob) != NULL); @@ -121,7 +121,7 @@ int PE_hair_poll(bContext *C) Object *ob= CTX_data_active_object(C); PTCacheEdit *edit; - if(!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) + if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) return 0; edit= PE_get_current(scene, ob); @@ -139,28 +139,28 @@ void PE_free_ptcache_edit(PTCacheEdit *edit) { POINT_P; - if(edit==0) return; + if (edit==0) return; PTCacheUndo_clear(edit); - if(edit->points) { + 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) { + if (edit->emitter_cosnos) { MEM_freeN(edit->emitter_cosnos); edit->emitter_cosnos= 0; } - if(edit->emitter_field) { + if (edit->emitter_field) { BLI_kdtree_free(edit->emitter_field); edit->emitter_field= 0; } @@ -176,9 +176,9 @@ void PE_free_ptcache_edit(PTCacheEdit *edit) int PE_start_edit(PTCacheEdit *edit) { - if(edit) { + if (edit) { edit->edited = 1; - if(edit->psys) + if (edit->psys) edit->psys->flag |= PSYS_EDITED; return 1; } @@ -202,7 +202,7 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) ListBase pidlist; PTCacheID *pid; - if(pset==NULL || ob==NULL) + if (pset==NULL || ob==NULL) return NULL; pset->scene = scene; @@ -211,7 +211,7 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); /* in the case of only one editable thing, set pset->edittype accordingly */ - if(pidlist.first && pidlist.first == pidlist.last) { + if (pidlist.first && pidlist.first == pidlist.last) { pid = pidlist.first; switch(pid->type) { case PTCACHE_TYPE_PARTICLES: @@ -226,25 +226,25 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) } } - for(pid=pidlist.first; pid; pid=pid->next) { - if(pset->edittype == PE_TYPE_PARTICLES && pid->type == PTCACHE_TYPE_PARTICLES) { + for (pid=pidlist.first; pid; pid=pid->next) { + if (pset->edittype == PE_TYPE_PARTICLES && pid->type == PTCACHE_TYPE_PARTICLES) { ParticleSystem *psys = pid->calldata; - 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 (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) PE_create_particle_edit(scene, ob, pid->cache, NULL); edit = pid->cache->edit; } else { - if(create && !psys->edit && psys->flag & PSYS_HAIR_DONE) + if (create && !psys->edit && psys->flag & PSYS_HAIR_DONE) PE_create_particle_edit(scene, ob, NULL, psys); edit = psys->edit; } } 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(scene, ob, pid->cache, psys); edit = pid->cache->edit; } @@ -272,7 +272,7 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) } } - if(edit) + if (edit) edit->pid = *pid; BLI_freelistN(&pidlist); @@ -292,7 +292,7 @@ PTCacheEdit *PE_create_current(Scene *scene, Object *ob) void PE_current_changed(Scene *scene, Object *ob) { - if(ob->mode == OB_MODE_PARTICLE_EDIT) + if (ob->mode == OB_MODE_PARTICLE_EDIT) PE_create_current(scene, ob); } @@ -302,10 +302,10 @@ void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra) POINT_P; KEY_K; - if(pset->flag & PE_FADE_TIME && pset->selectmode==SCE_SELECT_POINT) { + if (pset->flag & PE_FADE_TIME && pset->selectmode==SCE_SELECT_POINT) { LOOP_POINTS { LOOP_KEYS { - if(fabs(cfra-*key->time) < pset->fade_frames) + if (fabs(cfra-*key->time) < pset->fade_frames) key->flag &= ~PEK_HIDE; else { key->flag |= PEK_HIDE; @@ -325,7 +325,7 @@ 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; @@ -380,8 +380,8 @@ static void PE_set_view3d_data(bContext *C, PEData *data) /* note, the object argument means the modelview matrix does not account for the objects matrix, use viewmat rather than (obmat * viewmat) */ view3d_get_transformation(data->vc.ar, data->vc.rv3d, NULL, &data->mats); - if((data->vc.v3d->drawtype>OB_WIRE) && (data->vc.v3d->flag & V3D_ZBUF_SELECT)) { - if(data->vc.v3d->flag & V3D_INVALID_BACKBUF) { + if ((data->vc.v3d->drawtype>OB_WIRE) && (data->vc.v3d->flag & V3D_ZBUF_SELECT)) { + if (data->vc.v3d->flag & V3D_INVALID_BACKBUF) { /* needed or else the draw matrix can be incorrect */ view3d_operator_needs_opengl(C); @@ -404,12 +404,12 @@ static int key_test_depth(PEData *data, const float co[3]) short wco[3], x,y; /* nothing to do */ - if((v3d->drawtype<=OB_WIRE) || (v3d->flag & V3D_ZBUF_SELECT)==0) + if ((v3d->drawtype<=OB_WIRE) || (v3d->flag & V3D_ZBUF_SELECT)==0) return 1; project_short(data->vc.ar, co, wco); - if(wco[0] == IS_CLIPPED) + if (wco[0] == IS_CLIPPED) return 0; gluProject(co[0],co[1],co[2], data->mats.modelview, data->mats.projection, @@ -434,7 +434,7 @@ static int key_test_depth(PEData *data, const float co[3]) } #endif - if((float)uz - 0.00001f > depth) + if ((float)uz - 0.00001f > depth) return 0; else return 1; @@ -447,18 +447,18 @@ static int key_inside_circle(PEData *data, float rad, const float co[3], float * project_int(data->vc.ar, co, sco); - if(sco[0] == IS_CLIPPED) + if (sco[0] == IS_CLIPPED) return 0; dx= data->mval[0] - sco[0]; dy= data->mval[1] - sco[1]; dist= sqrt(dx*dx + dy*dy); - if(dist > rad) + if (dist > rad) return 0; - if(key_test_depth(data, co)) { - if(distance) + if (key_test_depth(data, co)) { + if (distance) *distance=dist; return 1; @@ -473,10 +473,10 @@ static int key_inside_rect(PEData *data, const float co[3]) project_int(data->vc.ar, co,sco); - if(sco[0] == IS_CLIPPED) + if (sco[0] == IS_CLIPPED) return 0; - if(sco[0] > data->rect->xmin && sco[0] < data->rect->xmax && + if (sco[0] > data->rect->xmin && sco[0] < data->rect->xmax && sco[1] > data->rect->ymin && sco[1] < data->rect->ymax) return key_test_depth(data, co); @@ -485,7 +485,7 @@ static int key_inside_rect(PEData *data, const float co[3]) static int 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 return key_inside_rect(data, co); @@ -495,7 +495,7 @@ static int point_is_selected(PTCacheEditPoint *point) { KEY_K; - if(point->flag & PEP_HIDE) + if (point->flag & PEP_HIDE) return 0; LOOP_SELECTED_KEYS { @@ -520,43 +520,43 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, int nearest) 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; LOOP_VISIBLE_POINTS { - if(pset->selectmode == SCE_SELECT_END) { + if (pset->selectmode == SCE_SELECT_END) { /* only do end keys */ key= point->keys + point->totkey-1; - if(nearest) { - if(key_inside_circle(data, dist, KEY_WCO, &dist)) { + if (nearest) { + if (key_inside_circle(data, dist, KEY_WCO, &dist)) { nearest_point= p; nearest_key= point->totkey-1; } } - else if(key_inside_test(data, KEY_WCO)) + else if (key_inside_test(data, KEY_WCO)) func(data, p, point->totkey-1); } else { /* do all keys */ LOOP_VISIBLE_KEYS { - if(nearest) { - if(key_inside_circle(data, dist, KEY_WCO, &dist)) { + if (nearest) { + if (key_inside_circle(data, dist, KEY_WCO, &dist)) { nearest_point= p; nearest_key= k; } } - else if(key_inside_test(data, KEY_WCO)) + else if (key_inside_test(data, KEY_WCO)) func(data, p, k); } } } /* do nearest only */ - if(nearest && nearest_point > -1) + if (nearest && nearest_point > -1) func(data, nearest_point, nearest_key); } @@ -567,23 +567,23 @@ static void foreach_mouse_hit_point(PEData *data, ForPointFunc func, int selecte POINT_P; 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 { - if(pset->selectmode==SCE_SELECT_END) { + if (pset->selectmode==SCE_SELECT_END) { /* only do end keys */ key= point->keys + point->totkey - 1; - if(selected==0 || key->flag & PEK_SELECT) - if(key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) + if (selected==0 || key->flag & PEK_SELECT) + if (key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) func(data, p); } else { /* do all keys */ LOOP_VISIBLE_KEYS { - if(selected==0 || key->flag & PEK_SELECT) { - if(key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) { + if (selected==0 || key->flag & PEK_SELECT) { + if (key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) { func(data, p); break; } @@ -602,21 +602,21 @@ static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected POINT_P; KEY_K; float mat[4][4]= MAT4_UNITY, imat[4][4]= MAT4_UNITY; - if(edit->psys) + if (edit->psys) psmd= psys_get_modifier(data->ob, edit->psys); /* all is selected in path mode */ - if(pset->selectmode==SCE_SELECT_PATH) + if (pset->selectmode==SCE_SELECT_PATH) selected= 0; LOOP_VISIBLE_POINTS { - if(pset->selectmode==SCE_SELECT_END) { + if (pset->selectmode==SCE_SELECT_END) { /* only do end keys */ key= point->keys + point->totkey-1; - if(selected==0 || key->flag & PEK_SELECT) { - if(key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) { - if(edit->psys && !(edit->psys->flag & PSYS_GLOBAL_HAIR)) { + if (selected==0 || key->flag & PEK_SELECT) { + if (key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) { + if (edit->psys && !(edit->psys->flag & PSYS_GLOBAL_HAIR)) { psys_mat_hair_to_global(data->ob, psmd->dm, psys->part->from, psys->particles + p, mat); invert_m4_m4(imat,mat); } @@ -628,9 +628,9 @@ static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected else { /* do all keys */ LOOP_VISIBLE_KEYS { - if(selected==0 || key->flag & PEK_SELECT) { - if(key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) { - if(edit->psys && !(edit->psys->flag & PSYS_GLOBAL_HAIR)) { + if (selected==0 || key->flag & PEK_SELECT) { + if (key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) { + if (edit->psys && !(edit->psys->flag & PSYS_GLOBAL_HAIR)) { psys_mat_hair_to_global(data->ob, psmd->dm, psys->part->from, psys->particles + p, mat); invert_m4_m4(imat,mat); } @@ -682,14 +682,14 @@ static int count_selected_keys(Scene *scene, PTCacheEdit *edit) int sel= 0; LOOP_VISIBLE_POINTS { - if(pset->selectmode==SCE_SELECT_POINT) { + if (pset->selectmode==SCE_SELECT_POINT) { LOOP_SELECTED_KEYS { sel++; } } - else if(pset->selectmode==SCE_SELECT_END) { + else if (pset->selectmode==SCE_SELECT_END) { key = point->keys + point->totkey - 1; - if(key->flag & PEK_SELECT) + if (key->flag & PEK_SELECT) sel++; } } @@ -716,7 +716,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) psmd= psys_get_modifier(ob, psys); totpart= psys->totpart; - if(!psmd->dm) + if (!psmd->dm) return; tree= BLI_kdtree_new(totpart); @@ -733,7 +733,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) BLI_kdtree_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 { @@ -746,7 +746,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) index= BLI_kdtree_find_nearest(tree, co, NULL, &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 edit->mirror_cache[p]= -1; @@ -754,9 +754,9 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) /* make sure mirrors are in two directions */ LOOP_PARTICLES { - if(edit->mirror_cache[p]) { + 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; } } @@ -777,15 +777,15 @@ static void PE_mirror_particle(Object *ob, DerivedMesh *dm, ParticleSystem *psys i= pa - psys->particles; /* find mirrored particle if needed */ - if(!mpa) { - if(!edit->mirror_cache) + if (!mpa) { + 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; } @@ -796,9 +796,9 @@ static void PE_mirror_particle(Object *ob, DerivedMesh *dm, ParticleSystem *psys mpoint = edit->points + mi; /* make sure they have the same amount of keys */ - if(pa->totkey != mpa->totkey) { - if(mpa->hair) MEM_freeN(mpa->hair); - if(mpoint->keys) MEM_freeN(mpoint->keys); + if (pa->totkey != mpa->totkey) { + if (mpa->hair) MEM_freeN(mpa->hair); + if (mpoint->keys) MEM_freeN(mpoint->keys); mpa->hair= MEM_dupallocN(pa->hair); mpa->totkey= pa->totkey; @@ -807,7 +807,7 @@ static void PE_mirror_particle(Object *ob, DerivedMesh *dm, ParticleSystem *psys mhkey= mpa->hair; mkey= mpoint->keys; - for(k=0; k<mpa->totkey; k++, mkey++, mhkey++) { + for (k=0; k<mpa->totkey; k++, mkey++, mhkey++) { mkey->co= mhkey->co; mkey->time= &mhkey->time; mkey->flag &= ~PEK_SELECT; @@ -823,21 +823,21 @@ static void PE_mirror_particle(Object *ob, DerivedMesh *dm, ParticleSystem *psys mhkey=mpa->hair; key= point->keys; mkey= mpoint->keys; - for(k=0; k<pa->totkey; k++, hkey++, mhkey++, key++, mkey++) { + for (k=0; k<pa->totkey; k++, hkey++, mhkey++, key++, mkey++) { copy_v3_v3(mhkey->co, hkey->co); mul_m4_v3(mat, mhkey->co); 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; } @@ -847,35 +847,35 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys) ParticleSystemModifierData *psmd; POINT_P; - if(!psys) + if (!psys) return; edit= psys->edit; psmd= psys_get_modifier(ob, psys); - if(!psmd->dm) + if (!psmd->dm) 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 */ LOOP_POINTS { - if(point->flag & PEP_EDIT_RECALC) { + if (point->flag & PEP_EDIT_RECALC) { PE_mirror_particle(ob, psmd->dm, 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; } } @@ -894,13 +894,13 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit) float *vec, *nor, dvec[3], dot, dist_1st=0.0f; float hairimat[4][4], hairmat[4][4]; - if(edit==NULL || edit->psys==NULL || (pset->flag & PE_DEFLECT_EMITTER)==0 || (edit->psys->flag & PSYS_GLOBAL_HAIR)) + if (edit==NULL || edit->psys==NULL || (pset->flag & PE_DEFLECT_EMITTER)==0 || (edit->psys->flag & PSYS_GLOBAL_HAIR)) return; psys = edit->psys; psmd = psys_get_modifier(ob,psys); - if(!psmd->dm) + if (!psmd->dm) return; LOOP_EDITED_POINTS { @@ -911,7 +911,7 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit) } LOOP_KEYS { - if(k==0) { + if (k==0) { dist_1st = len_v3v3((key+1)->co, key->co); dist_1st *= 0.75f * pset->emitterdist; } @@ -926,8 +926,8 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit) dot=dot_v3v3(dvec,nor); copy_v3_v3(dvec,nor); - if(dot>0.0f) { - if(dot<dist_1st) { + if (dot>0.0f) { + if (dot<dist_1st) { normalize_v3(dvec); mul_v3_fl(dvec,dist_1st-dot); add_v3_v3(key->co, dvec); @@ -938,7 +938,7 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit) mul_v3_fl(dvec,dist_1st-dot); add_v3_v3(key->co, dvec); } - if(k==1) + if (k==1) dist_1st*=1.3333f; } } @@ -958,15 +958,15 @@ static void PE_apply_lengths(Scene *scene, PTCacheEdit *edit) POINT_P; KEY_K; float dv1[3]; - 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; LOOP_EDITED_POINTS { LOOP_KEYS { - if(k) { + if (k) { sub_v3_v3v3(dv1, key->co, (key - 1)->co); normalize_v3(dv1); mul_v3_fl(dv1, (key - 1)->length); @@ -987,17 +987,17 @@ static void pe_iterate_lengths(Scene *scene, PTCacheEdit *edit) float dv1[3]= {0.0f, 0.0f, 0.0f}; float dv2[3]= {0.0f, 0.0f, 0.0f}; - 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; LOOP_EDITED_POINTS { - for(j=1; j<point->totkey; j++) { + for (j=1; j<point->totkey; j++) { float mul= 1.0f / (float)point->totkey; - if(pset->flag & PE_LOCK_FIRST) { + if (pset->flag & PE_LOCK_FIRST) { key= point->keys + 1; k= 1; dv1[0]= dv1[1]= dv1[2]= 0.0; @@ -1008,20 +1008,20 @@ static void pe_iterate_lengths(Scene *scene, PTCacheEdit *edit) dv0[0]= dv0[1]= dv0[2]= 0.0; } - for(; k<point->totkey; k++, key++) { - if(k) { + for (; k<point->totkey; k++, key++) { + if (k) { sub_v3_v3v3(dv0, (key - 1)->co, key->co); tlen= normalize_v3(dv0); mul_v3_fl(dv0, (mul * (tlen - (key - 1)->length))); } - if(k < point->totkey - 1) { + if (k < point->totkey - 1) { sub_v3_v3v3(dv2, (key + 1)->co, key->co); tlen= normalize_v3(dv2); mul_v3_fl(dv2, mul * (tlen - key->length)); } - if(k) { + if (k) { add_v3_v3((key-1)->co, dv1); } @@ -1035,12 +1035,12 @@ static void recalc_lengths(PTCacheEdit *edit) { POINT_P; KEY_K; - if(edit==0) + if (edit==0) return; LOOP_EDITED_POINTS { key= point->keys; - for(k=0; k<point->totkey-1; k++, key++) { + for (k=0; k<point->totkey-1; k++, key++) { key->length= len_v3v3(key->co, (key + 1)->co); } } @@ -1054,10 +1054,10 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys) float *vec, *nor; int i, totface /*, totvert*/; - if(!dm) + if (!dm) return; - if(edit->emitter_cosnos) + if (edit->emitter_cosnos) MEM_freeN(edit->emitter_cosnos); BLI_kdtree_free(edit->emitter_field); @@ -1072,7 +1072,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys) vec=edit->emitter_cosnos; nor=vec+3; - for(i=0; i<totface; i++, vec+=6, nor+=6) { + for (i=0; i<totface; i++, vec+=6, nor+=6) { MFace *mface=dm->getTessFaceData(dm,i,CD_MFACE); MVert *mvert; @@ -1088,7 +1088,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys) add_v3_v3v3(vec,vec,mvert->co); VECADD(nor,nor,mvert->no); - if(mface->v4) { + if (mface->v4) { mvert=dm->getVertData(dm,mface->v4,CD_MVERT); add_v3_v3v3(vec,vec,mvert->co); VECADD(nor,nor,mvert->no); @@ -1113,13 +1113,13 @@ static void PE_update_selection(Scene *scene, Object *ob, int useflag) POINT_P; 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 */ - if(edit->psys) LOOP_POINTS { + if (edit->psys) LOOP_POINTS { hkey = edit->psys->particles[p].hair; LOOP_KEYS { hkey->editflag= key->flag; @@ -1142,16 +1142,16 @@ static void update_world_cos(Object *ob, PTCacheEdit *edit) POINT_P; KEY_K; float hairmat[4][4]; - if(psys==0 || psys->edit==0 || psmd->dm==NULL) + if (psys==0 || psys->edit==0 || psmd->dm==NULL) return; LOOP_POINTS { - if(!(psys->flag & PSYS_GLOBAL_HAIR)) + if (!(psys->flag & PSYS_GLOBAL_HAIR)) psys_mat_hair_to_global(ob, psmd->dm, 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); } } @@ -1163,37 +1163,37 @@ static void update_velocities(PTCacheEdit *edit) POINT_P; 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; LOOP_EDITED_POINTS { LOOP_KEYS { - if(k==0) { + 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); - if(point->totkey>2) { + if (point->totkey>2) { sub_v3_v3v3(vec1, (key+1)->co, (key+2)->co); project_v3_v3v3(vec2, vec1, key->vel); sub_v3_v3v3(vec2, vec1, vec2); madd_v3_v3fl(key->vel, vec2, 0.5f); } } - else if(k==point->totkey-1) { + 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); - if(point->totkey>2) { + if (point->totkey>2) { sub_v3_v3v3(vec1, (key-2)->co, (key-1)->co); project_v3_v3v3(vec2, vec1, key->vel); sub_v3_v3v3(vec2, vec1, vec2); @@ -1203,7 +1203,7 @@ 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); @@ -1221,11 +1221,11 @@ void PE_update_object(Scene *scene, Object *ob, int useflag) 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; } @@ -1234,11 +1234,11 @@ void PE_update_object(Scene *scene, Object *ob, int useflag) 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(ob, edit); - if(pset->flag & PE_AUTO_VELOCITY) + if (pset->flag & PE_AUTO_VELOCITY) update_velocities(edit); PE_hide_keys_time(scene, edit, CFRA); @@ -1250,7 +1250,7 @@ void PE_update_object(Scene *scene, Object *ob, int useflag) point->flag &= ~PEP_EDIT_RECALC; } - if(edit->psys) + if (edit->psys) edit->psys->flag &= ~PSYS_HAIR_UPDATED; } @@ -1266,7 +1266,7 @@ static void select_key(PEData *data, int point_index, int key_index) PTCacheEditPoint *point = edit->points + point_index; PTCacheEditKey *key = point->keys + key_index; - if(data->select) + if (data->select) key->flag |= PEK_SELECT; else key->flag &= ~PEK_SELECT; @@ -1281,7 +1281,7 @@ static void select_keys(PEData *data, int point_index, int UNUSED(key_index)) KEY_K; LOOP_KEYS { - if(data->select) + if (data->select) key->flag |= PEK_SELECT; else key->flag &= ~PEK_SELECT; @@ -1342,7 +1342,8 @@ static int pe_select_all_exec(bContext *C, wmOperator *op) if ((key->flag & PEK_SELECT) == 0) { key->flag |= PEK_SELECT; point->flag |= PEP_EDIT_RECALC; - } else { + } + else { key->flag &= ~PEK_SELECT; point->flag |= PEP_EDIT_RECALC; } @@ -1383,10 +1384,10 @@ int PE_mouse_particles(bContext *C, const int mval[2], int extend) PTCacheEdit *edit= PE_get_current(scene, ob); POINT_P; KEY_K; - if(!PE_start_edit(edit)) + if (!PE_start_edit(edit)) return OPERATOR_CANCELLED; - if(!extend) { + if (!extend) { LOOP_VISIBLE_POINTS { LOOP_SELECTED_KEYS { key->flag &= ~PEK_SELECT; @@ -1554,7 +1555,7 @@ int PE_border_select(bContext *C, rcti *rect, int select, int extend) PTCacheEdit *edit= PE_get_current(scene, ob); PEData data; - if(!PE_start_edit(edit)) + if (!PE_start_edit(edit)) return OPERATOR_CANCELLED; if (extend == 0 && select) @@ -1581,7 +1582,7 @@ int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) PTCacheEdit *edit= PE_get_current(scene, ob); PEData data; - if(!PE_start_edit(edit)) + if (!PE_start_edit(edit)) return OPERATOR_FINISHED; PE_set_view3d_data(C, &data); @@ -1614,7 +1615,7 @@ int PE_lasso_select(bContext *C, int mcords[][2], short moves, short extend, sho PEData data; - if(!PE_start_edit(edit)) + if (!PE_start_edit(edit)) return OPERATOR_CANCELLED; if (extend == 0 && select) @@ -1624,38 +1625,38 @@ int PE_lasso_select(bContext *C, int mcords[][2], short moves, short extend, sho PE_set_view3d_data(C, &data); 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->dm, psys->part->from, psys->particles + p, mat); - if(pset->selectmode==SCE_SELECT_POINT) { + if (pset->selectmode==SCE_SELECT_POINT) { LOOP_KEYS { copy_v3_v3(co, key->co); mul_m4_v3(mat, co); project_int(ar, co, vertco); - if((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1]) && key_test_depth(&data, co)) { - if(select && !(key->flag & PEK_SELECT)) { + if ((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1]) && key_test_depth(&data, co)) { + if (select && !(key->flag & PEK_SELECT)) { key->flag |= PEK_SELECT; point->flag |= PEP_EDIT_RECALC; } - else if(key->flag & PEK_SELECT) { + else if (key->flag & PEK_SELECT) { key->flag &= ~PEK_SELECT; point->flag |= PEP_EDIT_RECALC; } } } } - else if(pset->selectmode==SCE_SELECT_END) { + else if (pset->selectmode==SCE_SELECT_END) { key= point->keys + point->totkey - 1; copy_v3_v3(co, key->co); mul_m4_v3(mat, co); project_int(ar, co,vertco); - if((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1]) && key_test_depth(&data, co)) { - if(select && !(key->flag & PEK_SELECT)) { + if ((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1]) && key_test_depth(&data, co)) { + if (select && !(key->flag & PEK_SELECT)) { key->flag |= PEK_SELECT; point->flag |= PEP_EDIT_RECALC; } - else if(key->flag & PEK_SELECT) { + else if (key->flag & PEK_SELECT) { key->flag &= ~PEK_SELECT; point->flag |= PEP_EDIT_RECALC; } @@ -1678,7 +1679,7 @@ static int hide_exec(bContext *C, wmOperator *op) PTCacheEdit *edit= PE_get_current(scene, ob); POINT_P; KEY_K; - if(RNA_enum_get(op->ptr, "unselected")) { + if (RNA_enum_get(op->ptr, "unselected")) { LOOP_UNSELECTED_POINTS { point->flag |= PEP_HIDE; point->flag |= PEP_EDIT_RECALC; @@ -1730,7 +1731,7 @@ static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) POINT_P; KEY_K; LOOP_POINTS { - if(point->flag & PEP_HIDE) { + if (point->flag & PEP_HIDE) { point->flag &= ~PEP_HIDE; point->flag |= PEP_EDIT_RECALC; @@ -1768,22 +1769,22 @@ static void select_less_keys(PEData *data, int point_index) KEY_K; LOOP_SELECTED_KEYS { - if(k==0) { - if(((key+1)->flag&PEK_SELECT)==0) + if (k==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) + else if (k==point->totkey-1) { + 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; } } LOOP_KEYS { - if(key->flag&PEK_TAG) { + if (key->flag&PEK_TAG) { key->flag &= ~(PEK_TAG|PEK_SELECT); point->flag |= PEP_EDIT_RECALC; /* redraw selection only */ } @@ -1826,24 +1827,24 @@ static void select_more_keys(PEData *data, int point_index) KEY_K; LOOP_KEYS { - if(key->flag & PEK_SELECT) continue; + if (key->flag & PEK_SELECT) continue; - if(k==0) { - if((key+1)->flag&PEK_SELECT) + if (k==0) { + if ((key+1)->flag&PEK_SELECT) key->flag |= PEK_TAG; } - else if(k==point->totkey-1) { - if((key-1)->flag&PEK_SELECT) + else if (k==point->totkey-1) { + 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; } } LOOP_KEYS { - if(key->flag&PEK_TAG) { + if (key->flag&PEK_TAG) { key->flag &= ~PEK_TAG; key->flag |= PEK_SELECT; point->flag |= PEP_EDIT_RECALC; /* redraw selection only */ @@ -1911,7 +1912,7 @@ static void rekey_particle(PEData *data, int pa_index) dval= (end - sta) / (float)(data->totrekey - 1); /* interpolate new keys from old ones */ - for(k=1,key++; k<data->totrekey-1; k++,key++) { + for (k=1,key++; k<data->totrekey-1; k++,key++) { state.time= (float)k / (float)(data->totrekey-1); psys_get_particle_on_path(&sim, pa_index, &state, 0); copy_v3_v3(key->co, state.co); @@ -1919,22 +1920,22 @@ 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++) { + 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; } @@ -1989,7 +1990,7 @@ static void rekey_particle_to_time(Scene *scene, Object *ob, int pa_index, float PTCacheEditKey *ekey; int k; - if(!edit || !edit->psys) return; + if (!edit || !edit->psys) return; psys = edit->psys; @@ -2004,19 +2005,19 @@ static void rekey_particle_to_time(Scene *scene, Object *ob, int pa_index, float key= new_keys= MEM_dupallocN(pa->hair); /* interpolate new keys from old ones (roots stay the same) */ - for(k=1, key++; k < pa->totkey; k++, key++) { + for (k=1, key++; k < pa->totkey; k++, key++) { state.time= path_time * (float)k / (float)(pa->totkey-1); psys_get_particle_on_path(&sim, pa_index, &state, 0); copy_v3_v3(key->co, state.co); } /* replace hair keys */ - if(pa->hair) + if (pa->hair) MEM_freeN(pa->hair); pa->hair= new_keys; /* update edit pointers */ - for(k=0, key=pa->hair, ekey=edit->points[pa_index].keys; k<pa->totkey; k++, key++, ekey++) { + for (k=0, key=pa->hair, ekey=edit->points[pa_index].keys; k<pa->totkey; k++, key++, ekey++) { ekey->co= key->co; ekey->time= &key->time; } @@ -2035,7 +2036,7 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) ParticleSystemModifierData *psmd; int i, new_totpart= psys->totpart, removed= 0; - if(mirror) { + if (mirror) { /* mirror tags */ psmd= psys_get_modifier(ob, psys); @@ -2049,16 +2050,16 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) removed++; } - if(new_totpart != psys->totpart) { - if(new_totpart) { + if (new_totpart != psys->totpart) { + if (new_totpart) { npa= new_pars= MEM_callocN(new_totpart * sizeof(ParticleData), "ParticleData array"); npoint= new_points= MEM_callocN(new_totpart * sizeof(PTCacheEditPoint), "PTCacheEditKey array"); - if(ELEM(NULL, new_pars, new_points)) { + 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; } @@ -2066,11 +2067,11 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) pa= psys->particles; point= edit->points; - for(i=0; i<psys->totpart; i++, pa++, point++) { - if(point->flag & PEP_TAG) { - if(point->keys) + for (i=0; i<psys->totpart; i++, pa++, point++) { + if (point->flag & PEP_TAG) { + if (point->keys) MEM_freeN(point->keys); - if(pa->hair) + if (pa->hair) MEM_freeN(pa->hair); } else { @@ -2081,18 +2082,18 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) } } - if(psys->particles) MEM_freeN(psys->particles); + if (psys->particles) MEM_freeN(psys->particles); psys->particles= new_pars; - if(edit->points) MEM_freeN(edit->points); + if (edit->points) MEM_freeN(edit->points); edit->points= new_points; - if(edit->mirror_cache) { + if (edit->mirror_cache) { MEM_freeN(edit->mirror_cache); edit->mirror_cache= NULL; } - if(psys->child) { + if (psys->child) { MEM_freeN(psys->child); psys->child= NULL; psys->totchild=0; @@ -2114,7 +2115,7 @@ static void remove_tagged_keys(Object *ob, ParticleSystem *psys) ParticleSystemModifierData *psmd; short new_totkey; - if(pe_x_mirror(ob)) { + if (pe_x_mirror(ob)) { /* mirror key tags */ psmd= psys_get_modifier(ob, psys); @@ -2132,7 +2133,7 @@ static void remove_tagged_keys(Object *ob, ParticleSystem *psys) 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)); @@ -2145,7 +2146,7 @@ static void remove_tagged_keys(Object *ob, ParticleSystem *psys) new_totkey--; } - if(new_totkey != pa->totkey) { + if (new_totkey != pa->totkey) { nhkey= new_hkeys= MEM_callocN(new_totkey*sizeof(HairKey), "HairKeys"); nkey= new_keys= MEM_callocN(new_totkey*sizeof(PTCacheEditKey), "particle edit keys"); @@ -2156,7 +2157,7 @@ static void remove_tagged_keys(Object *ob, ParticleSystem *psys) hkey++; } - if(hkey < pa->hair + pa->totkey) { + if (hkey < pa->hair + pa->totkey) { copy_v3_v3(nhkey->co, hkey->co); nhkey->editflag = hkey->editflag; nhkey->time= hkey->time; @@ -2175,10 +2176,10 @@ static void remove_tagged_keys(Object *ob, ParticleSystem *psys) 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; @@ -2214,12 +2215,12 @@ static void subdivide_particle(PEData *data, int pa_index) sim.ob= data->ob; 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) + for (k=0, ekey=point->keys; k<pa->totkey-1; k++,ekey++) { + if (ekey->flag&PEK_SELECT && (ekey+1)->flag&PEK_SELECT) totnewkey++; } - if(totnewkey==0) return; + if (totnewkey==0) return; pa->flag |= PARS_REKEY; @@ -2229,7 +2230,7 @@ static void subdivide_particle(PEData *data, int pa_index) key = pa->hair; endtime= key[pa->totkey-1].time; - for(k=0, ekey=point->keys; k<pa->totkey-1; k++, key++, ekey++) { + for (k=0, ekey=point->keys; k<pa->totkey-1; k++, key++, ekey++) { memcpy(nkey,key,sizeof(HairKey)); memcpy(nekey,ekey,sizeof(PTCacheEditKey)); @@ -2240,7 +2241,7 @@ static void subdivide_particle(PEData *data, int pa_index) nkey++; nekey++; - if(ekey->flag & PEK_SELECT && (ekey+1)->flag & PEK_SELECT) { + if (ekey->flag & PEK_SELECT && (ekey+1)->flag & PEK_SELECT) { nkey->time= (key->time + (key+1)->time)*0.5f; state.time= (endtime != 0.0f)? nkey->time/endtime: 0.0f; psys_get_particle_on_path(&sim, pa_index, &state, 0); @@ -2249,7 +2250,7 @@ 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++; @@ -2263,11 +2264,11 @@ 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; @@ -2319,7 +2320,7 @@ 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; @@ -2349,10 +2350,10 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) totn= BLI_kdtree_find_n_nearest(tree,10,co,NULL,nearest); - for(n=0; n<totn; n++) { + for (n=0; n<totn; n++) { /* this needs a custom threshold still */ - if(nearest[n].index > p && nearest[n].dist < threshold) { - if(!(point->flag & PEP_TAG)) { + if (nearest[n].index > p && nearest[n].dist < threshold) { + if (!(point->flag & PEP_TAG)) { point->flag |= PEP_TAG; removed++; } @@ -2367,7 +2368,7 @@ 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, "Remove %d double particles", totremoved); @@ -2451,12 +2452,12 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata) ParticleEditSettings *pset= PE_settings(CTX_data_scene(C)); ParticleBrushData *brush; - if(pset->brushtype < 0) + if (pset->brushtype < 0) return; brush= &pset->brush[pset->brushtype]; - if(brush) { + if (brush) { glPushMatrix(); glTranslatef((float)x, (float)y, 0.0f); @@ -2476,11 +2477,11 @@ static void toggle_particle_cursor(bContext *C, int enable) { ParticleEditSettings *pset= PE_settings(CTX_data_scene(C)); - if(pset->paintcursor && !enable) { + if (pset->paintcursor && !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), PE_poll_view3d, brush_drawcursor, NULL); } @@ -2514,12 +2515,12 @@ static int delete_exec(bContext *C, wmOperator *op) PE_set_data(C, &data); - if(type == DEL_KEY) { + if (type == DEL_KEY) { foreach_selected_key(&data, set_delete_particle_key); remove_tagged_keys(data.ob, data.edit->psys); recalc_lengths(data.edit); } - else if(type == DEL_PARTICLE) { + else if (type == DEL_PARTICLE) { foreach_selected_point(&data, set_delete_particle); remove_tagged_particles(data.ob, data.edit->psys, pe_x_mirror(data.ob)); recalc_lengths(data.edit); @@ -2564,25 +2565,25 @@ 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= psys_get_modifier(ob, psys); - if(!psmd->dm) + if (!psmd->dm) return; mirrorfaces= mesh_get_x_mirror_faces(ob, NULL); - if(!edit->mirror_cache) + if (!edit->mirror_cache) PE_update_mirror_cache(ob, psys); totpart= psys->totpart; newtotpart= psys->totpart; LOOP_VISIBLE_POINTS { pa = psys->particles + p; - if(!tagged) { - if(point_is_selected(point)) { - if(edit->mirror_cache[p] != -1) { + if (!tagged) { + if (point_is_selected(point)) { + if (edit->mirror_cache[p] != -1) { /* already has a mirror, don't need to duplicate */ PE_mirror_particle(ob, psmd->dm, psys, pa, NULL); continue; @@ -2592,28 +2593,28 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) } } - 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) { + if (newtotpart != psys->totpart) { /* allocate new arrays and copy existing */ new_pars= MEM_callocN(newtotpart*sizeof(ParticleData), "ParticleData new"); new_points= MEM_callocN(newtotpart*sizeof(PTCacheEditPoint), "PTCacheEditPoint new"); - if(psys->particles) { + if (psys->particles) { memcpy(new_pars, psys->particles, totpart*sizeof(ParticleData)); MEM_freeN(psys->particles); } psys->particles= new_pars; - if(edit->points) { + if (edit->points) { memcpy(new_points, edit->points, totpart*sizeof(PTCacheEditPoint)); MEM_freeN(edit->points); } edit->points= new_points; - if(edit->mirror_cache) { + if (edit->mirror_cache) { MEM_freeN(edit->mirror_cache); edit->mirror_cache= NULL; } @@ -2624,19 +2625,19 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) newpa= psys->particles + totpart; newpoint= edit->points + totpart; - for(p=0, point=edit->points; p<totpart; p++, point++) { + for (p=0, point=edit->points; p<totpart; p++, point++) { pa = psys->particles + p; - 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) newpa->hair= MEM_dupallocN(pa->hair); - if(point->keys) newpoint->keys= MEM_dupallocN(point->keys); + if (pa->hair) newpa->hair= MEM_dupallocN(pa->hair); + if (point->keys) newpoint->keys= MEM_dupallocN(point->keys); /* rotate weights according to vertex index rotation */ rotation= mirrorfaces[pa->num*2+1]; @@ -2658,7 +2659,7 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) /* update edit key pointers */ key= newpoint->keys; - for(k=0, hkey=newpa->hair; k<newpa->totkey; k++, hkey++, key++) { + for (k=0, hkey=newpa->hair; k<newpa->totkey; k++, hkey++, key++) { key->co= hkey->co; key->time= &hkey->time; } @@ -2714,7 +2715,7 @@ static void brush_comb(PEData *data, float UNUSED(mat[][4]), float imat[][4], in ParticleEditSettings *pset= PE_settings(data->scene); float cvec[3], fac; - if(pset->flag & PE_LOCK_FIRST && key_index == 0) return; + if (pset->flag & PE_LOCK_FIRST && key_index == 0) return; fac= (float)pow((double)(1.0f - data->dist / data->rad), (double)data->combfac); @@ -2739,10 +2740,10 @@ static void brush_cut(PEData *data, int pa_index) int vertco[2]; /* blunt scissors */ - if(BLI_frand() > data->cutfac) return; + if (BLI_frand() > data->cutfac) return; /* don't cut hidden */ - if(edit->points[pa_index].flag & PEP_HIDE) + if (edit->points[pa_index].flag & PEP_HIDE) return; rad2= data->rad * data->rad; @@ -2760,16 +2761,16 @@ static void brush_cut(PEData *data, int pa_index) xo1= x1 - o1; /* check if root is inside circle */ - if(xo0*xo0 + xo1*xo1 < rad2 && key_test_depth(data, key->co)) { + if (xo0*xo0 + xo1*xo1 < rad2 && key_test_depth(data, key->co)) { cut_time= -1.0f; cut= 1; } else { /* calculate path time closest to root that was inside the circle */ - for(k=1, key++; k<=keys; k++, key++) { + for (k=1, key++; k<=keys; k++, key++) { project_int_noclip(ar, key->co, vertco); - if(key_test_depth(data, key->co) == 0) { + if (key_test_depth(data, key->co) == 0) { x0= (float)vertco[0]; x1= (float)vertco[1]; @@ -2787,15 +2788,15 @@ static void brush_cut(PEData *data, int pa_index) d= dv * rad2 - d*d; - if(d > 0.0f) { + if (d > 0.0f) { d= sqrt(d); cut_time= -(v0*xo0 + v1*xo1 + d); - if(cut_time > 0.0f) { + if (cut_time > 0.0f) { cut_time /= dv; - if(cut_time < 1.0f) { + if (cut_time < 1.0f) { cut_time += (float)(k-1); cut_time /= (float)keys; cut= 1; @@ -2812,8 +2813,8 @@ static void brush_cut(PEData *data, int pa_index) } } - if(cut) { - if(cut_time < 0.0f) { + if (cut) { + if (cut_time < 0.0f) { edit->points[pa_index].flag |= PEP_TAG; } else { @@ -2831,7 +2832,7 @@ static void brush_length(PEData *data, int point_index) float dvec[3],pvec[3] = {0.0f, 0.0f, 0.0f}; LOOP_KEYS { - if(k==0) { + if (k==0) { copy_v3_v3(pvec,key->co); } else { @@ -2863,7 +2864,7 @@ static void brush_puff(PEData *data, int point_index) puff_volume = brush->flag & PE_BRUSH_DATA_PUFF_VOLUME; } - if(psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { + if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { psys_mat_hair_to_global(data->ob, data->dm, psys->part->from, psys->particles + point_index, mat); invert_m4_m4(imat,mat); } @@ -2873,14 +2874,14 @@ static void brush_puff(PEData *data, int point_index) } LOOP_KEYS { - if(k==0) { + if (k==0) { /* find root coordinate and normal on emitter */ copy_v3_v3(co, key->co); mul_m4_v3(mat, co); mul_v3_m4v3(kco, data->ob->imat, co); /* use 'kco' as the object space version of worldspace 'co', ob->imat is set before calling */ point_index= BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL, NULL); - if(point_index == -1) return; + if (point_index == -1) return; copy_v3_v3(rootco, co); copy_v3_v3(nor, &edit->emitter_cosnos[point_index*6+3]); @@ -2891,7 +2892,7 @@ static void brush_puff(PEData *data, int point_index) fac= (float)pow((double)(1.0f - data->dist / data->rad), (double)data->pufffac); fac *= 0.025f; - if(data->invert) + if (data->invert) fac= -fac; } else { @@ -2901,7 +2902,7 @@ static void brush_puff(PEData *data, int point_index) copy_v3_v3(co, key->co); mul_m4_v3(mat, co); length += len_v3v3(lastco, co); - if((data->select==0 || (key->flag & PEK_SELECT)) && !(key->flag & PEK_HIDE)) { + if ((data->select==0 || (key->flag & PEK_SELECT)) && !(key->flag & PEK_HIDE)) { madd_v3_v3v3fl(kco, rootco, nor, length); /* blend between the current and straight position */ @@ -2913,7 +2914,7 @@ static void brush_puff(PEData *data, int point_index) mul_v3_m4v3(key->co, imat, co); - if(puff_volume) { + if (puff_volume) { /* accumulate the total distance moved to apply to unselected * keys that come after */ ofs[0] += key->co[0] - dco[0]; @@ -2924,13 +2925,13 @@ static void brush_puff(PEData *data, int point_index) } else { - if(puff_volume) { + if (puff_volume) { #if 0 /* this is simple but looks bad, adds annoying kinks */ add_v3_v3(key->co, ofs); #else /* translate (not rotate) the rest of the hair if its not selected */ - if(ofs[0] || ofs[1] || ofs[2]) { + if (ofs[0] || ofs[1] || ofs[2]) { #if 0 /* kindof works but looks worse then whats below */ /* Move the unselected point on a vector based on the @@ -2955,7 +2956,7 @@ static void brush_puff(PEData *data, int point_index) mul_v3_m4v3(kco, data->ob->imat, oco); /* use 'kco' as the object space version of worldspace 'co', ob->imat is set before calling */ point_index= BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL, NULL); - if(point_index != -1) { + if (point_index != -1) { copy_v3_v3(onor, &edit->emitter_cosnos[point_index*6+3]); mul_mat3_m4_v3(data->ob->obmat, onor); /* normal into worldspace */ mul_mat3_m4_v3(imat, onor); /* worldspace into particle space */ @@ -2973,7 +2974,7 @@ static void brush_puff(PEData *data, int point_index) } } - if(change) + if (change) point->flag |= PEP_EDIT_RECALC; } @@ -2981,7 +2982,7 @@ static void brush_puff(PEData *data, int point_index) static void brush_weight(PEData *data, float UNUSED(mat[][4]), float UNUSED(imat[][4]), int point_index, int key_index, PTCacheEditKey *UNUSED(key)) { /* roots have full weight allways */ - if(key_index) { + if (key_index) { PTCacheEdit *edit = data->edit; ParticleSystem *psys = edit->psys; @@ -2994,7 +2995,7 @@ static void brush_weight(PEData *data, float UNUSED(mat[][4]), float UNUSED(imat static void brush_smooth_get(PEData *data, float mat[][4], float UNUSED(imat[][4]), int UNUSED(point_index), int key_index, PTCacheEditKey *key) { - if(key_index) { + if (key_index) { float dvec[3]; sub_v3_v3v3(dvec,key->co,(key-1)->co); @@ -3008,7 +3009,7 @@ static void brush_smooth_do(PEData *data, float UNUSED(mat[][4]), float imat[][4 { float vec[3], dvec[3]; - if(key_index) { + if (key_index) { copy_v3_v3(vec, data->vec); mul_mat3_m4_v3(imat,vec); @@ -3054,16 +3055,16 @@ static int particle_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, float cur_d, cur_uv[2], v1[3], v2[3], v3[3], v4[3], min[3], max[3], p_min[3],p_max[3]; float cur_ipoint[3]; - if(dm == NULL){ + if (dm == NULL) { psys_disable_all(ob); dm=mesh_get_derived_final(scene, ob, 0); - if(dm == NULL) + if (dm == NULL) dm=mesh_get_derived_deform(scene, ob, 0); psys_enable_all(ob); - if(dm == NULL) + if (dm == NULL) return 0; } @@ -3071,12 +3072,12 @@ static int particle_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, DM_ensure_tessface(dm); - if(pa_minmax==0){ + if (pa_minmax==0) { INIT_MINMAX(p_min,p_max); DO_MINMAX(co1,p_min,p_max); DO_MINMAX(co2,p_min,p_max); } - else{ + else { copy_v3_v3(p_min,pa_minmax); copy_v3_v3(p_max,pa_minmax+3); } @@ -3086,23 +3087,23 @@ static int particle_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, mvert=dm->getVertDataArray(dm,CD_MVERT); /* lets intersect the faces */ - for(i=0; i<totface; i++,mface++){ - if(vert_cos){ + for (i=0; i<totface; i++,mface++) { + if (vert_cos) { 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{ + 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){ + if (face_minmax==0) { INIT_MINMAX(min,max); DO_MINMAX(v1,min,max); DO_MINMAX(v2,min,max); @@ -3112,25 +3113,25 @@ static int particle_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, if (isect_aabb_aabb_v3(min,max,p_min,p_max)==0) continue; } - else{ + 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){ - if(isect_sweeping_sphere_tri_v3(co1, co2, radius, v2, v3, v1, &cur_d, cur_ipoint)){ - if(cur_d<*min_d){ + if (radius>0.0f) { + if (isect_sweeping_sphere_tri_v3(co1, co2, radius, v2, v3, v1, &cur_d, cur_ipoint)) { + if (cur_d<*min_d) { *min_d=cur_d; copy_v3_v3(ipoint,cur_ipoint); *min_face=i; intersect=1; } } - if(mface->v4){ - if(isect_sweeping_sphere_tri_v3(co1, co2, radius, v4, v1, v3, &cur_d, cur_ipoint)){ - if(cur_d<*min_d){ + if (mface->v4) { + if (isect_sweeping_sphere_tri_v3(co1, co2, radius, v4, v1, v3, &cur_d, cur_ipoint)) { + if (cur_d<*min_d) { *min_d=cur_d; copy_v3_v3(ipoint,cur_ipoint); *min_face=i; @@ -3139,23 +3140,23 @@ static int particle_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, } } } - else{ - if(isect_line_tri_v3(co1, co2, v1, v2, v3, &cur_d, cur_uv)){ - if(cur_d<*min_d){ + else { + if (isect_line_tri_v3(co1, co2, v1, v2, v3, &cur_d, cur_uv)) { + if (cur_d<*min_d) { *min_d=cur_d; min_w[0]= 1.0f - cur_uv[0] - cur_uv[1]; 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; } } - if(mface->v4){ - if(isect_line_tri_v3(co1, co2, v1, v3, v4, &cur_d, cur_uv)){ - if(cur_d<*min_d){ + if (mface->v4) { + if (isect_line_tri_v3(co1, co2, v1, v3, v4, &cur_d, cur_uv)) { + if (cur_d<*min_d) { *min_d=cur_d; min_w[0]= 1.0f - cur_uv[0] - cur_uv[1]; min_w[1]= 0.0f; @@ -3192,7 +3193,7 @@ static int brush_add(PEData *data, short number) DerivedMesh *dm=0; invert_m4_m4(imat,ob->obmat); - if(psys->flag & PSYS_GLOBAL_HAIR) + if (psys->flag & PSYS_GLOBAL_HAIR) return 0; BLI_srandom(psys->seed+data->mval[0]+data->mval[1]); @@ -3205,13 +3206,13 @@ static int brush_add(PEData *data, short number) timestep= psys_get_timestep(&sim); /* painting onto the deformed mesh, could be an option? */ - if(psmd->dm->deformedOnly) + if (psmd->dm->deformedOnly) dm= psmd->dm; else dm= mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); - for(i=0; i<number; i++) { - if(number>1) { + for (i=0; i<number; i++) { + if (number>1) { dmx=dmy=size; while(dmx*dmx+dmy*dmy>size2) { dmx=(short)((2.0f*BLI_frand()-1.0f)*size); @@ -3228,12 +3229,12 @@ static int brush_add(PEData *data, short number) min_d=2.0; /* warning, returns the derived mesh face */ - if(particle_intersect_dm(scene, ob,dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)) { + if (particle_intersect_dm(scene, ob,dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)) { add_pars[n].num_dmcache= psys_particle_dm_face_lookup(ob,psmd->dm,add_pars[n].num,add_pars[n].fuv,NULL); n++; } } - if(n) { + if (n) { int newtotpart=totpart+n; float hairmat[4][4], cur_co[3]; KDTree *tree=0; @@ -3247,22 +3248,22 @@ static int brush_add(PEData *data, short number) memcpy(new_points, edit->points, totpart * sizeof(PTCacheEditPoint)); /* change old arrays to new ones */ - if(psys->particles) MEM_freeN(psys->particles); + if (psys->particles) MEM_freeN(psys->particles); psys->particles= new_pars; - if(edit->points) MEM_freeN(edit->points); + if (edit->points) MEM_freeN(edit->points); edit->points= new_points; - if(edit->mirror_cache) { + if (edit->mirror_cache) { MEM_freeN(edit->mirror_cache); edit->mirror_cache= NULL; } /* create tree for interpolation */ - if(pset->flag & PE_INTERPOLATE_ADDED && psys->totpart) { + if (pset->flag & PE_INTERPOLATE_ADDED && psys->totpart) { tree=BLI_kdtree_new(psys->totpart); - for(i=0, pa=psys->particles; i<totpart; i++, pa++) { + for (i=0, pa=psys->particles; i<totpart; i++, pa++) { psys_particle_on_dm(psmd->dm,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,cur_co,0,0,0,0,0); BLI_kdtree_insert(tree, i, cur_co, NULL); } @@ -3276,17 +3277,17 @@ static int brush_add(PEData *data, short number) pa= psys->particles + totpart; point= edit->points + totpart; - for(i=totpart; i<newtotpart; i++, pa++, point++) { + for (i=totpart; i<newtotpart; i++, pa++, point++) { memcpy(pa, add_pars + i - totpart, sizeof(ParticleData)); pa->hair= MEM_callocN(pset->totaddkey * sizeof(HairKey), "BakeKey key add"); key= point->keys= MEM_callocN(pset->totaddkey * sizeof(PTCacheEditKey), "PTCacheEditKey add"); point->totkey= pa->totkey= pset->totaddkey; - for(k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, key++) { + for (k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, key++) { 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; } @@ -3294,12 +3295,12 @@ static int brush_add(PEData *data, short number) initialize_particle(&sim, pa,i); 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); - if(tree) { + if (tree) { ParticleData *ppa; HairKey *thkey; ParticleKey key3[3]; @@ -3312,20 +3313,20 @@ static int brush_add(PEData *data, short number) maxd= ptn[maxw-1].dist; - for(w=0; w<maxw; w++) { + for (w=0; w<maxw; w++) { weight[w]= (float)pow(2.0, (double)(-6.0f * ptn[w].dist / maxd)); totw += weight[w]; } - for(;w<3; w++) { + for (;w<3; w++) { weight[w]= 0.0f; } - for(w=0; w<maxw; w++) + for (w=0; w<maxw; w++) weight[w] /= totw; ppa= psys->particles+ptn[0].index; - for(k=0; k<pset->totaddkey; k++) { + for (k=0; k<pset->totaddkey; k++) { thkey= (HairKey*)pa->hair + k; thkey->time= pa->time + k * framestep; @@ -3336,13 +3337,13 @@ static int brush_add(PEData *data, short number) /* TODO: interpolatint the weight would be nicer */ thkey->weight= (ppa->hair+MIN2(k, ppa->totkey-1))->weight; - if(maxw>1) { + if (maxw>1) { key3[1].time= key3[0].time; psys_get_particle_on_path(&sim, ptn[1].index, &key3[1], 0); mul_v3_fl(key3[1].co, weight[1]); add_v3_v3(key3[0].co, key3[1].co); - if(maxw>2) { + if (maxw>2) { key3[2].time= key3[0].time; psys_get_particle_on_path(&sim, ptn[2].index, &key3[2], 0); mul_v3_fl(key3[2].co, weight[2]); @@ -3350,7 +3351,7 @@ static int brush_add(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); @@ -3359,26 +3360,26 @@ static int brush_add(PEData *data, short number) } } else { - for(k=0, hkey=pa->hair; k<pset->totaddkey; k++, hkey++) { + for (k=0, hkey=pa->hair; k<pset->totaddkey; k++, hkey++) { madd_v3_v3v3fl(hkey->co, pa->state.co, pa->state.vel, k * framestep * timestep); hkey->time += k * framestep; hkey->weight = 1.f - (float)k/(float)(pset->totaddkey-1); } } - for(k=0, hkey=pa->hair; k<pset->totaddkey; k++, hkey++) { + for (k=0, hkey=pa->hair; k<pset->totaddkey; k++, hkey++) { psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); invert_m4_m4(imat,hairmat); mul_m4_v3(imat, hkey->co); } } - if(tree) + if (tree) BLI_kdtree_free(tree); } - if(add_pars) + if (add_pars) MEM_freeN(add_pars); - if(!psmd->dm->deformedOnly) + if (!psmd->dm->deformedOnly) dm->release(dm); return n; @@ -3407,7 +3408,7 @@ static int brush_edit_init(bContext *C, wmOperator *op) ARegion *ar= CTX_wm_region(C); BrushEdit *bedit; - if(pset->brushtype < 0) + if (pset->brushtype < 0) return 0; initgrabz(ar->regiondata, ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]); @@ -3442,7 +3443,7 @@ 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); @@ -3450,7 +3451,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) mouse[1] = mousef[1]; flip= RNA_boolean_get(itemptr, "pen_flip"); - if(bedit->first) { + if (bedit->first) { bedit->lastmouse[0]= mouse[0]; bedit->lastmouse[1]= mouse[1]; } @@ -3463,10 +3464,10 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) /* 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) ? + if (((pset->brushtype == PE_BRUSH_ADD) ? (sqrt(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0)) || bedit->first) { PEData data= bedit->data; @@ -3480,7 +3481,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) dx /= (float)tot_steps; dy /= (float)tot_steps; - for(step = 1; step<=tot_steps; step++) { + for (step = 1; step<=tot_steps; step++) { mval[0] = bedit->lastmouse[0] + step*dx; mval[1] = bedit->lastmouse[1] + step*dy; @@ -3492,7 +3493,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) data.rad= (float)brush->size; 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 data.combfac= 1.0f - data.combfac; @@ -3509,18 +3510,18 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) } case PE_BRUSH_CUT: { - if(edit->psys && edit->pathcache) { + if (edit->psys && edit->pathcache) { data.mval= mval; data.rad= (float)brush->size; data.cutfac= brush->strength; - if(selected) + if (selected) foreach_selected_point(&data, brush_cut); 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 @@ -3535,27 +3536,27 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) data.rad= (float)brush->size; data.growfac= brush->strength / 50.0f; - if(brush->invert ^ flip) + if (brush->invert ^ flip) data.growfac= 1.0f - data.growfac; 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: { - if(edit->psys) { + if (edit->psys) { data.dm= psmd->dm; data.mval= mval; data.rad= (float)brush->size; 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 data.pufffac= 1.0f - data.pufffac; @@ -3569,12 +3570,12 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) } case PE_BRUSH_ADD: { - if(edit->psys && edit->psys->part->from==PART_FROM_FACE) { + if (edit->psys && edit->psys->part->from==PART_FROM_FACE) { data.mval= mval; added= brush_add(&data, brush->count); - if(pset->flag & PE_KEEP_LENGTHS) + if (pset->flag & PE_KEEP_LENGTHS) recalc_lengths(edit); } else @@ -3595,7 +3596,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) foreach_mouse_hit_key(&data, brush_smooth_get, selected); - if(data.tot) { + if (data.tot) { mul_v3_fl(data.vec, 1.0f / (float)data.tot); foreach_mouse_hit_key(&data, brush_smooth_do, selected); } @@ -3604,7 +3605,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) } case PE_BRUSH_WEIGHT: { - if(edit->psys) { + if (edit->psys) { data.dm= psmd->dm; data.mval= mval; data.rad= (float)brush->size; @@ -3617,11 +3618,11 @@ 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 (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_CUT) && (added || removed)) { + if (pset->brushtype == PE_BRUSH_ADD && pe_x_mirror(ob)) PE_mirror_x(scene, ob, 1); update_world_cos(ob,edit); @@ -3657,7 +3658,7 @@ 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") { @@ -3689,7 +3690,7 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, wmEvent *event) static int brush_edit_invoke(bContext *C, wmOperator *op, wmEvent *event) { - if(!brush_edit_init(C, op)) + if (!brush_edit_init(C, op)) return OPERATOR_CANCELLED; brush_edit_apply_event(C, op, event); @@ -3749,16 +3750,16 @@ static void free_PTCacheUndo(PTCacheUndo *undo) PTCacheEditPoint *point; int i; - for(i=0, point=undo->points; i<undo->totpoint; i++, point++) { - if(undo->particles && (undo->particles + i)->hair) + for (i=0, point=undo->points; i<undo->totpoint; i++, point++) { + if (undo->particles && (undo->particles + i)->hair) MEM_freeN((undo->particles + i)->hair); - if(point->keys) + if (point->keys) MEM_freeN(point->keys); } - if(undo->points) + if (undo->points) MEM_freeN(undo->points); - if(undo->particles) + if (undo->particles) MEM_freeN(undo->particles); BKE_ptcache_free_mem(&undo->mem_cache); @@ -3771,12 +3772,12 @@ static void make_PTCacheUndo(PTCacheEdit *edit, PTCacheUndo *undo) undo->totpoint= edit->totpoint; - if(edit->psys) { + if (edit->psys) { ParticleData *pa; pa= undo->particles= MEM_dupallocN(edit->psys->particles); - for(i=0; i<edit->totpoint; i++, pa++) + for (i=0; i<edit->totpoint; i++, pa++) pa->hair= MEM_dupallocN(pa->hair); undo->psys_flag = edit->psys->flag; @@ -3787,8 +3788,8 @@ static void make_PTCacheUndo(PTCacheEdit *edit, PTCacheUndo *undo) BLI_duplicatelist(&undo->mem_cache, &edit->pid.cache->mem_cache); pm = undo->mem_cache.first; - for(; pm; pm=pm->next) { - for(i=0; i<BPHYS_TOT_DATA; i++) + for (; pm; pm=pm->next) { + for (i=0; i<BPHYS_TOT_DATA; i++) pm->data[i] = MEM_dupallocN(pm->data[i]); } } @@ -3796,7 +3797,7 @@ static void make_PTCacheUndo(PTCacheEdit *edit, PTCacheUndo *undo) point= undo->points = MEM_dupallocN(edit->points); undo->totpoint = edit->totpoint; - for(i=0; i<edit->totpoint; i++, point++) { + for (i=0; i<edit->totpoint; i++, point++) { point->keys= MEM_dupallocN(point->keys); /* no need to update edit key->co & key->time pointers here */ } @@ -3810,17 +3811,17 @@ static void get_PTCacheUndo(PTCacheEdit *edit, PTCacheUndo *undo) POINT_P; KEY_K; LOOP_POINTS { - if(psys && psys->particles[p].hair) + if (psys && psys->particles[p].hair) MEM_freeN(psys->particles[p].hair); - if(point->keys) + if (point->keys) MEM_freeN(point->keys); } - if(psys && psys->particles) + if (psys && psys->particles) MEM_freeN(psys->particles); - if(edit->points) + if (edit->points) MEM_freeN(edit->points); - if(edit->mirror_cache) { + if (edit->mirror_cache) { MEM_freeN(edit->mirror_cache); edit->mirror_cache= NULL; } @@ -3832,7 +3833,7 @@ static void get_PTCacheUndo(PTCacheEdit *edit, PTCacheUndo *undo) point->keys= MEM_dupallocN(point->keys); } - if(psys) { + if (psys) { psys->particles= MEM_dupallocN(undo->particles); psys->totpart= undo->totpoint; @@ -3860,15 +3861,15 @@ static void get_PTCacheUndo(PTCacheEdit *edit, PTCacheUndo *undo) pm = edit->pid.cache->mem_cache.first; - for(; pm; pm=pm->next) { - for(i=0; i<BPHYS_TOT_DATA; i++) + for (; pm; pm=pm->next) { + for (i=0; i<BPHYS_TOT_DATA; i++) pm->data[i] = MEM_dupallocN(pm->data[i]); BKE_ptcache_mem_pointers_init(pm); LOOP_POINTS { LOOP_KEYS { - if((int)key->ftime == (int)pm->frame) { + if ((int)key->ftime == (int)pm->frame) { key->co = pm->cur[BPHYS_DATA_LOCATION]; key->vel = pm->cur[BPHYS_DATA_VELOCITY]; key->rot = pm->cur[BPHYS_DATA_ROTATION]; @@ -3887,7 +3888,7 @@ void PE_undo_push(Scene *scene, const char *str) PTCacheUndo *undo; int nr; - if(!edit) return; + if (!edit) return; /* remove all undos after (also when curundo==NULL) */ while(edit->undo.last != edit->curundo) { @@ -3907,10 +3908,10 @@ void PE_undo_push(Scene *scene, const char *str) undo= edit->undo.last; while(undo) { nr++; - if(nr==U.undosteps) break; + if (nr==U.undosteps) break; undo= undo->prev; } - if(undo) { + if (undo) { while(edit->undo.first!=undo) { PTCacheUndo *first= edit->undo.first; BLI_remlink(&edit->undo, first); @@ -3927,16 +3928,16 @@ void PE_undo_step(Scene *scene, int step) { PTCacheEdit *edit= PE_get_current(scene, OBACT); - if(!edit) return; + if (!edit) return; - if(step==0) { + if (step==0) { get_PTCacheUndo(edit,edit->curundo); } - else if(step==1) { + else if (step==1) { - if(edit->curundo==NULL || edit->curundo->prev==NULL); + if (edit->curundo==NULL || edit->curundo->prev==NULL); else { - if(G.f & G_DEBUG) printf("undo %s\n", edit->curundo->name); + if (G.f & G_DEBUG) printf("undo %s\n", edit->curundo->name); edit->curundo= edit->curundo->prev; get_PTCacheUndo(edit, edit->curundo); } @@ -3944,11 +3945,11 @@ void PE_undo_step(Scene *scene, int step) else { /* curundo has to remain current situation! */ - if(edit->curundo==NULL || edit->curundo->next==NULL); + if (edit->curundo==NULL || edit->curundo->next==NULL); else { get_PTCacheUndo(edit, edit->curundo->next); edit->curundo= edit->curundo->next; - if(G.f & G_DEBUG) printf("redo %s\n", edit->curundo->name); + if (G.f & G_DEBUG) printf("redo %s\n", edit->curundo->name); } } @@ -3959,7 +3960,7 @@ int PE_undo_valid(Scene *scene) { PTCacheEdit *edit= PE_get_current(scene, OBACT); - if(edit) { + if (edit) { return (edit->undo.last != edit->undo.first); } return 0; @@ -3969,7 +3970,7 @@ static void PTCacheUndo_clear(PTCacheEdit *edit) { PTCacheUndo *undo; - if(edit==NULL) return; + if (edit==NULL) return; undo= edit->undo.first; while(undo) { @@ -3996,8 +3997,8 @@ void PE_undo_number(Scene *scene, int nr) PTCacheUndo *undo; int a=0; - for(undo= edit->undo.first; undo; undo= undo->next, a++) { - if(a==nr) break; + for (undo= edit->undo.first; undo; undo= undo->next, a++) { + if (a==nr) break; } edit->curundo= undo; PE_undo_step(scene, 0); @@ -4011,12 +4012,12 @@ const char *PE_undo_get_name(Scene *scene, int nr, int *active) PTCacheEdit *edit= PE_get_current(scene, OBACT); PTCacheUndo *undo; - if(active) *active= 0; + if (active) *active= 0; - if(edit) { + if (edit) { undo= BLI_findlink(&edit->undo, nr); - if(undo) { - if(active && undo==edit->curundo) + if (undo) { + if (active && undo==edit->curundo) *active= 1; return undo->name; } @@ -4036,15 +4037,15 @@ int PE_minmax(Scene *scene, float min[3], float max[3]) float co[3], mat[4][4]; int ok= 0; - if(!edit) return ok; + if (!edit) return ok; - if((psys = edit->psys)) + if ((psys = edit->psys)) psmd= psys_get_modifier(ob, psys); else unit_m4(mat); LOOP_VISIBLE_POINTS { - if(psys) + if (psys) psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, psys->particles+p, mat); LOOP_SELECTED_KEYS { @@ -4055,7 +4056,7 @@ int PE_minmax(Scene *scene, float min[3], float max[3]) } } - if(!ok) { + if (!ok) { minmax_object(ob, min, max); ok= 1; } @@ -4076,23 +4077,23 @@ static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, int totpoint; /* no psmd->dm happens in case particle system modifier is not enabled */ - if(!(psys && psmd && psmd->dm) && !cache) + if (!(psys && psmd && psmd->dm) && !cache) return; - if(cache && cache->flag & PTCACHE_DISK_CACHE) + if (cache && cache->flag & PTCACHE_DISK_CACHE) return; - if(psys == NULL && cache->mem_cache.first == NULL) + if (psys == NULL && cache->mem_cache.first == NULL) return; - if(!edit) { + if (!edit) { totpoint = psys ? psys->totpart : (int)((PTCacheMem*)cache->mem_cache.first)->totpoint; edit= MEM_callocN(sizeof(PTCacheEdit), "PE_create_particle_edit"); edit->points=MEM_callocN(totpoint*sizeof(PTCacheEditPoint),"PTCacheEditPoints"); edit->totpoint = totpoint; - if(psys && !cache) { + if (psys && !cache) { psys->edit= edit; edit->psys = psys; @@ -4112,7 +4113,7 @@ static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, key->co= hkey->co; key->time= &hkey->time; key->flag= hkey->editflag; - if(!(psys->flag & PSYS_GLOBAL_HAIR)) { + if (!(psys->flag & PSYS_GLOBAL_HAIR)) { key->flag |= PEK_USE_WCO; hkey->editflag |= PEK_USE_WCO; } @@ -4131,15 +4132,15 @@ static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, 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) { + 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) { + if (!point->totkey) { key = point->keys = MEM_callocN(totframe*sizeof(PTCacheEditKey),"ParticleEditKeys"); point->flag |= PEP_EDIT_RECALC; } @@ -4163,7 +4164,7 @@ static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, UI_GetThemeColor3ubv(TH_WIRE, edit->nosel_col); recalc_lengths(edit); - if(psys && !cache) + if (psys && !cache) recalc_emitter_field(ob, psys); PE_update_object(scene, ob, 1); @@ -4177,7 +4178,7 @@ static int particle_edit_toggle_poll(bContext *C) Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); - if(!scene || !ob || ob->id.lib) + if (!scene || !ob || ob->id.lib) return 0; return (ob->particlesystem.first || modifiers_findByType(ob, eModifierType_Cloth) || modifiers_findByType(ob, eModifierType_Softbody)); @@ -4188,14 +4189,14 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); - if(!(ob->mode & OB_MODE_PARTICLE_EDIT)) { + if (!(ob->mode & OB_MODE_PARTICLE_EDIT)) { PTCacheEdit *edit; ob->mode |= OB_MODE_PARTICLE_EDIT; edit= PE_create_current(scene, ob); /* mesh may have changed since last entering editmode. * note, this may have run before if the edit data was just created, so could avoid this and speed up a little */ - if(edit && edit->psys) + if (edit && edit->psys) recalc_emitter_field(ob, edit->psys); toggle_particle_cursor(C, 1); @@ -4234,8 +4235,8 @@ static int clear_edited_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob= CTX_data_active_object(C); ParticleSystem *psys = psys_get_current(ob); - if(psys->edit) { - if(psys->edit->edited || 1) { // XXX okee("Lose changes done in particle mode?")) + if (psys->edit) { + if (psys->edit->edited || 1) { // XXX okee("Lose changes done in particle mode?")) PE_free_ptcache_edit(psys->edit); psys->edit = NULL; |