diff options
Diffstat (limited to 'source/blender/editors/physics/particle_edit.c')
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 362 |
1 files changed, 153 insertions, 209 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 68506c8addb..2ea0e9dc018 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -93,6 +93,7 @@ bool PE_poll(bContext *C) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); @@ -100,7 +101,7 @@ bool PE_poll(bContext *C) return false; } - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); if (edit == NULL) { return false; } @@ -113,6 +114,7 @@ bool PE_poll(bContext *C) bool PE_hair_poll(bContext *C) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); @@ -120,7 +122,7 @@ bool PE_hair_poll(bContext *C) return false; } - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); if (edit == NULL || edit->psys == NULL) { return false; } @@ -149,8 +151,7 @@ void PE_free_ptcache_edit(PTCacheEdit *edit) } if (edit->points) { - LOOP_POINTS - { + LOOP_POINTS { if (point->keys) { MEM_freeN(point->keys); } @@ -356,9 +357,9 @@ static PTCacheEdit *pe_get_current(Depsgraph *depsgraph, Scene *scene, Object *o return edit; } -PTCacheEdit *PE_get_current(Scene *scene, Object *ob) +PTCacheEdit *PE_get_current(Depsgraph *depsgraph, Scene *scene, Object *ob) { - return pe_get_current(NULL, scene, ob, 0); + return pe_get_current(depsgraph, scene, ob, 0); } PTCacheEdit *PE_create_current(Depsgraph *depsgraph, Scene *scene, Object *ob) @@ -380,10 +381,8 @@ void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra) KEY_K; if (pset->flag & PE_FADE_TIME && pset->selectmode == SCE_SELECT_POINT) { - LOOP_POINTS - { - LOOP_KEYS - { + LOOP_POINTS { + LOOP_KEYS { if (fabsf(cfra - *key->time) < pset->fade_frames) { key->flag &= ~PEK_HIDE; } @@ -395,10 +394,8 @@ void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra) } } else { - LOOP_POINTS - { - LOOP_KEYS - { + LOOP_POINTS { + LOOP_KEYS { key->flag &= ~PEK_HIDE; } } @@ -466,14 +463,15 @@ static void PE_set_data(bContext *C, PEData *data) data->view_layer = CTX_data_view_layer(C); data->ob = CTX_data_active_object(C); data->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - data->edit = PE_get_current(data->scene, data->ob); + data->edit = PE_get_current(data->depsgraph, data->scene, data->ob); } static void PE_set_view3d_data(bContext *C, PEData *data) { PE_set_data(C, data); - ED_view3d_viewcontext_init(C, &data->vc); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ED_view3d_viewcontext_init(C, &data->vc, depsgraph); if (!XRAY_ENABLED(data->vc.v3d)) { if (data->vc.v3d->flag & V3D_INVALID_BACKBUF) { @@ -633,8 +631,7 @@ static bool point_is_selected(PTCacheEditPoint *point) return 0; } - LOOP_SELECTED_KEYS - { + LOOP_SELECTED_KEYS { return 1; } @@ -649,8 +646,8 @@ typedef void (*ForHitPointFunc)(PEData *data, int point_index, float mouse_dista typedef void (*ForKeyFunc)(PEData *data, int point_index, int key_index, bool is_inside); typedef void (*ForKeyMatFunc)(PEData *data, - float mat[4][4], - float imat[4][4], + const float mat[4][4], + const float imat[4][4], int point_index, int key_index, PTCacheEditKey *key); @@ -684,8 +681,7 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, const enum ePartic nearest_point = -1; nearest_key = -1; - LOOP_VISIBLE_POINTS - { + LOOP_VISIBLE_POINTS { if (pset->selectmode == SCE_SELECT_END) { if (point->totkey) { /* only do end keys */ @@ -707,8 +703,7 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, const enum ePartic } else { /* do all keys */ - LOOP_VISIBLE_KEYS - { + LOOP_VISIBLE_KEYS { if (flag & PSEL_NEAREST) { if (key_inside_circle(data, dist, KEY_WCO, &dist)) { nearest_point = p; @@ -745,8 +740,7 @@ static void foreach_mouse_hit_point(PEData *data, ForHitPointFunc func, int sele selected = 0; } - LOOP_VISIBLE_POINTS - { + LOOP_VISIBLE_POINTS { if (pset->selectmode == SCE_SELECT_END) { if (point->totkey) { /* only do end keys */ @@ -762,8 +756,7 @@ static void foreach_mouse_hit_point(PEData *data, ForHitPointFunc func, int sele } else { /* do all keys */ - LOOP_VISIBLE_KEYS - { + LOOP_VISIBLE_KEYS { if (selected == 0 || key->flag & PEK_SELECT) { float mouse_distance; if (key_inside_circle(data, data->rad, KEY_WCO, &mouse_distance)) { @@ -823,8 +816,7 @@ static void foreach_mouse_hit_key_iter(void *__restrict iter_data_v, /* do all keys */ PTCacheEditKey *key; int k; - LOOP_VISIBLE_KEYS - { + LOOP_VISIBLE_KEYS { if (selected == 0 || key->flag & PEK_SELECT) { float mouse_distance; if (key_inside_circle(data, data->rad, KEY_WCO, &mouse_distance)) { @@ -866,8 +858,7 @@ static void foreach_selected_point(PEData *data, ForPointFunc func) PTCacheEdit *edit = data->edit; POINT_P; - LOOP_SELECTED_POINTS - { + LOOP_SELECTED_POINTS { func(data, p); } } @@ -878,10 +869,8 @@ static void foreach_selected_key(PEData *data, ForKeyFunc func) POINT_P; KEY_K; - LOOP_VISIBLE_POINTS - { - LOOP_SELECTED_KEYS - { + LOOP_VISIBLE_POINTS { + LOOP_SELECTED_KEYS { func(data, p, k, true); } } @@ -892,8 +881,7 @@ static void foreach_point(PEData *data, ForPointFunc func) PTCacheEdit *edit = data->edit; POINT_P; - LOOP_POINTS - { + LOOP_POINTS { func(data, p); } } @@ -905,11 +893,9 @@ static int count_selected_keys(Scene *scene, PTCacheEdit *edit) KEY_K; int sel = 0; - LOOP_VISIBLE_POINTS - { + LOOP_VISIBLE_POINTS { if (pset->selectmode == SCE_SELECT_POINT) { - LOOP_SELECTED_KEYS - { + LOOP_SELECTED_KEYS { sel++; } } @@ -1117,8 +1103,7 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys) /* we delay settings the PARS_EDIT_RECALC for mirrored particles * to avoid doing mirror twice */ - LOOP_POINTS - { + LOOP_POINTS { if (point->flag & PEP_EDIT_RECALC) { PE_mirror_particle(ob, psmd_eval->mesh_final, psys, psys->particles + p, NULL); @@ -1128,8 +1113,7 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys) } } - LOOP_POINTS - { + LOOP_POINTS { if (point->flag & PEP_EDIT_RECALC) { if (edit->mirror_cache[p] != -1) { edit->points[edit->mirror_cache[p]].flag |= PEP_EDIT_RECALC; @@ -1173,13 +1157,11 @@ static void deflect_emitter_iter(void *__restrict iter_data_v, psys_mat_hair_to_object( object, psmd_eval->mesh_final, psys->part->from, psys->particles + iter, hairmat); - LOOP_KEYS - { + LOOP_KEYS { mul_m4_v3(hairmat, key->co); } - LOOP_KEYS - { + LOOP_KEYS { if (k == 0) { dist_1st = len_v3v3((key + 1)->co, key->co); dist_1st *= dist * emitterdist; @@ -1215,8 +1197,7 @@ static void deflect_emitter_iter(void *__restrict iter_data_v, invert_m4_m4(hairimat, hairmat); - LOOP_KEYS - { + LOOP_KEYS { mul_m4_v3(hairimat, key->co); } } @@ -1268,8 +1249,7 @@ static void apply_lengths_iter(void *__restrict iter_data_v, } PTCacheEditKey *key; int k; - LOOP_KEYS - { + LOOP_KEYS { if (k) { float dv1[3]; sub_v3_v3v3(dv1, key->co, (key - 1)->co); @@ -1377,7 +1357,7 @@ static void pe_iterate_lengths(Scene *scene, PTCacheEdit *edit) BLI_task_parallel_range(0, edit->totpoint, &iter_data, iterate_lengths_iter, &settings); } -/* set current distances to be kept between neighbouting keys */ +/* set current distances to be kept between neighboring keys */ void recalc_lengths(PTCacheEdit *edit) { POINT_P; @@ -1387,8 +1367,7 @@ void recalc_lengths(PTCacheEdit *edit) return; } - LOOP_EDITED_POINTS - { + LOOP_EDITED_POINTS { key = point->keys; for (k = 0; k < point->totkey - 1; k++, key++) { key->length = len_v3v3(key->co, (key + 1)->co); @@ -1461,15 +1440,14 @@ void recalc_emitter_field(Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), Part static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag) { - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); HairKey *hkey; POINT_P; KEY_K; /* flag all particles to be updated if not using flag */ if (!useflag) { - LOOP_POINTS - { + LOOP_POINTS { point->flag |= PEP_EDIT_RECALC; } } @@ -1477,11 +1455,9 @@ static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, /* flush edit key flag to hair key flag to preserve selection * on save */ if (edit->psys) { - LOOP_POINTS - { + LOOP_POINTS { hkey = edit->psys->particles[p].hair; - LOOP_KEYS - { + LOOP_KEYS { hkey->editflag = key->flag; hkey++; } @@ -1491,8 +1467,7 @@ static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering); /* disable update flag */ - LOOP_POINTS - { + LOOP_POINTS { point->flag &= ~PEP_EDIT_RECALC; } @@ -1511,15 +1486,13 @@ void update_world_cos(Object *ob, PTCacheEdit *edit) return; } - LOOP_POINTS - { + LOOP_POINTS { 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 - { + LOOP_KEYS { copy_v3_v3(key->world_co, key->co); if (!(psys->flag & PSYS_GLOBAL_HAIR)) { mul_m4_v3(hairmat, key->world_co); @@ -1541,10 +1514,8 @@ static void update_velocities(PTCacheEdit *edit) frs_sec = edit->pid.flag & PTCACHE_VEL_PER_SEC ? 25.0f : 1.0f; - LOOP_EDITED_POINTS - { - LOOP_KEYS - { + LOOP_EDITED_POINTS { + LOOP_KEYS { if (k == 0) { dfra = *(key + 1)->time - *key->time; @@ -1596,7 +1567,7 @@ void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int usefla /* use this to do partial particle updates, not usable when adding or * removing, then a full redo is necessary and calling this may crash */ ParticleEditSettings *pset = PE_settings(scene); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); POINT_P; if (!edit) { @@ -1605,8 +1576,7 @@ void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int usefla /* flag all particles to be updated if not using flag */ if (!useflag) { - LOOP_POINTS - { + LOOP_POINTS { point->flag |= PEP_EDIT_RECALC; } } @@ -1624,14 +1594,19 @@ void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int usefla if (pset->flag & PE_AUTO_VELOCITY) { update_velocities(edit); } - PE_hide_keys_time(scene, edit, CFRA); + + /* Only do this for emitter particles because drawing PE_FADE_TIME is not respected in 2.8 yet + * and flagging with PEK_HIDE will prevent selection. This might get restored once this is + * supported in drawing (but doesn't make much sense for hair anyways). */ + if (edit->psys->part->type == PART_EMITTER) { + PE_hide_keys_time(scene, edit, CFRA); + } /* regenerate path caches */ psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering); /* disable update flag */ - LOOP_POINTS - { + LOOP_POINTS { point->flag &= ~PEP_EDIT_RECALC; } @@ -1686,8 +1661,7 @@ static void select_keys(PEData *data, PTCacheEditPoint *point = edit->points + point_index; KEY_K; - LOOP_KEYS - { + LOOP_KEYS { if (data->select) { key->flag |= PEK_SELECT; } @@ -1780,17 +1754,15 @@ static int pe_select_all_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); POINT_P; KEY_K; int action = RNA_enum_get(op->ptr, "action"); if (action == SEL_TOGGLE) { action = SEL_SELECT; - LOOP_VISIBLE_POINTS - { - LOOP_SELECTED_KEYS - { + LOOP_VISIBLE_POINTS { + LOOP_SELECTED_KEYS { action = SEL_DESELECT; break; } @@ -1802,10 +1774,8 @@ static int pe_select_all_exec(bContext *C, wmOperator *op) } bool changed = false; - LOOP_VISIBLE_POINTS - { - LOOP_VISIBLE_KEYS - { + LOOP_VISIBLE_POINTS { + LOOP_VISIBLE_KEYS { changed |= select_action_apply(point, key, action); } } @@ -1841,7 +1811,7 @@ bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool desele PEData data; Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(data.depsgraph, scene, ob); POINT_P; KEY_K; @@ -1850,10 +1820,8 @@ bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool desele } if (!extend && !deselect && !toggle) { - LOOP_VISIBLE_POINTS - { - LOOP_SELECTED_KEYS - { + LOOP_VISIBLE_POINTS { + LOOP_SELECTED_KEYS { key->flag &= ~PEK_SELECT; point->flag |= PEP_EDIT_RECALC; } @@ -2029,6 +1997,7 @@ static const EnumPropertyItem select_random_type_items[] = { static int select_random_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); PEData data; int type; @@ -2048,26 +2017,22 @@ static int select_random_exec(bContext *C, wmOperator *op) PE_set_data(C, &data); data.select_action = SEL_SELECT; - edit = PE_get_current(data.scene, data.ob); + edit = PE_get_current(depsgraph, data.scene, data.ob); rng = BLI_rng_new_srandom(seed); switch (type) { case RAN_HAIR: - LOOP_VISIBLE_POINTS - { + LOOP_VISIBLE_POINTS { int flag = ((BLI_rng_get_float(rng) < randfac) == select) ? SEL_SELECT : SEL_DESELECT; - LOOP_KEYS - { + LOOP_KEYS { data.is_changed |= select_action_apply(point, key, flag); } } break; case RAN_POINTS: - LOOP_VISIBLE_POINTS - { - LOOP_VISIBLE_KEYS - { + LOOP_VISIBLE_POINTS { + LOOP_VISIBLE_KEYS { int flag = ((BLI_rng_get_float(rng) < randfac) == select) ? SEL_SELECT : SEL_DESELECT; data.is_changed |= select_action_apply(point, key, flag); } @@ -2166,10 +2131,8 @@ bool PE_deselect_all_visible_ex(PTCacheEdit *edit) POINT_P; KEY_K; - LOOP_VISIBLE_POINTS - { - LOOP_SELECTED_KEYS - { + LOOP_VISIBLE_POINTS { + LOOP_SELECTED_KEYS { if ((key->flag & PEK_SELECT) != 0) { key->flag &= ~PEK_SELECT; point->flag |= PEP_EDIT_RECALC; @@ -2182,9 +2145,10 @@ bool PE_deselect_all_visible_ex(PTCacheEdit *edit) bool PE_deselect_all_visible(bContext *C) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); if (!PE_start_edit(edit)) { return false; } @@ -2193,9 +2157,10 @@ bool PE_deselect_all_visible(bContext *C) bool PE_box_select(bContext *C, const rcti *rect, const int sel_op) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); PEData data; if (!PE_start_edit(edit)) { @@ -2229,9 +2194,10 @@ bool PE_box_select(bContext *C, const rcti *rect, const int sel_op) bool PE_circle_select(bContext *C, const int sel_op, const int mval[2], float rad) { BLI_assert(ELEM(sel_op, SEL_OP_SET, SEL_OP_ADD, SEL_OP_SUB)); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); PEData data; if (!PE_start_edit(edit)) { @@ -2260,11 +2226,12 @@ bool PE_circle_select(bContext *C, const int sel_op, const int mval[2], float ra int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, const int sel_op) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); ARegion *ar = CTX_wm_region(C); ParticleEditSettings *pset = PE_settings(scene); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); ParticleSystem *psys = edit->psys; ParticleSystemModifierData *psmd_eval = edit->psmd_eval; POINT_P; @@ -2287,16 +2254,14 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, const data.is_changed |= PE_deselect_all_visible_ex(edit); } - LOOP_VISIBLE_POINTS - { + LOOP_VISIBLE_POINTS { 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 - { + LOOP_VISIBLE_KEYS { copy_v3_v3(co, key->co); mul_m4_v3(mat, co); const bool is_select = key->flag & PEK_SELECT; @@ -2350,30 +2315,26 @@ static int hide_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); POINT_P; KEY_K; - if (RNA_enum_get(op->ptr, "unselected")) { - LOOP_UNSELECTED_POINTS - { + if (RNA_boolean_get(op->ptr, "unselected")) { + LOOP_UNSELECTED_POINTS { point->flag |= PEP_HIDE; point->flag |= PEP_EDIT_RECALC; - LOOP_KEYS - { + LOOP_KEYS { key->flag &= ~PEK_SELECT; } } } else { - LOOP_SELECTED_POINTS - { + LOOP_SELECTED_POINTS { point->flag |= PEP_HIDE; point->flag |= PEP_EDIT_RECALC; - LOOP_KEYS - { + LOOP_KEYS { key->flag &= ~PEK_SELECT; } } @@ -2410,19 +2371,17 @@ static int reveal_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); const bool select = RNA_boolean_get(op->ptr, "select"); POINT_P; KEY_K; - LOOP_POINTS - { + LOOP_POINTS { if (point->flag & PEP_HIDE) { point->flag &= ~PEP_HIDE; point->flag |= PEP_EDIT_RECALC; - LOOP_KEYS - { + LOOP_KEYS { SET_FLAG_FROM_TEST(key->flag, select, PEK_SELECT); } } @@ -2460,8 +2419,7 @@ static void select_less_keys(PEData *data, int point_index) PTCacheEditPoint *point = edit->points + point_index; KEY_K; - LOOP_SELECTED_KEYS - { + LOOP_SELECTED_KEYS { if (k == 0) { if (((key + 1)->flag & PEK_SELECT) == 0) { key->flag |= PEK_TAG; @@ -2479,8 +2437,7 @@ static void select_less_keys(PEData *data, int point_index) } } - LOOP_KEYS - { + LOOP_KEYS { if ((key->flag & PEK_TAG) && (key->flag & PEK_SELECT)) { key->flag &= ~(PEK_TAG | PEK_SELECT); point->flag |= PEP_EDIT_RECALC; /* redraw selection only */ @@ -2525,8 +2482,7 @@ static void select_more_keys(PEData *data, int point_index) PTCacheEditPoint *point = edit->points + point_index; KEY_K; - LOOP_KEYS - { + LOOP_KEYS { if (key->flag & PEK_SELECT) { continue; } @@ -2548,8 +2504,7 @@ static void select_more_keys(PEData *data, int point_index) } } - LOOP_KEYS - { + LOOP_KEYS { if ((key->flag & PEK_TAG) && (key->flag & PEK_SELECT) == 0) { key->flag &= ~PEK_TAG; key->flag |= PEK_SELECT; @@ -2694,7 +2649,8 @@ void PARTICLE_OT_rekey(wmOperatorType *ot) static void rekey_particle_to_time( const bContext *C, Scene *scene, Object *ob, int pa_index, float path_time) { - PTCacheEdit *edit = PE_get_current(scene, ob); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); ParticleSystem *psys; ParticleSimulationData sim = {0}; ParticleData *pa; @@ -2709,7 +2665,7 @@ static void rekey_particle_to_time( psys = edit->psys; - sim.depsgraph = CTX_data_depsgraph_pointer(C); + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = ob; sim.psys = psys; @@ -2758,14 +2714,12 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) /* mirror tags */ psmd_eval = edit->psmd_eval; - LOOP_TAGGED_POINTS - { + LOOP_TAGGED_POINTS { PE_mirror_particle(ob, psmd_eval->mesh_final, psys, psys->particles + p, NULL); } } - LOOP_TAGGED_POINTS - { + LOOP_TAGGED_POINTS { new_totpart--; removed++; } @@ -2850,21 +2804,17 @@ static void remove_tagged_keys(Depsgraph *depsgraph, Object *ob, ParticleSystem ParticleSystemModifierData *psmd_eval = (ParticleSystemModifierData *)modifier_get_evaluated( depsgraph, ob, &psmd->modifier); - LOOP_POINTS - { - LOOP_TAGGED_KEYS - { + LOOP_POINTS { + LOOP_TAGGED_KEYS { PE_mirror_particle(ob, psmd_eval->mesh_final, psys, psys->particles + p, NULL); break; } } } - LOOP_POINTS - { + LOOP_POINTS { new_totkey = point->totkey; - LOOP_TAGGED_KEYS - { + LOOP_TAGGED_KEYS { new_totkey--; } /* we can't have elements with less than two keys*/ @@ -2874,13 +2824,11 @@ static void remove_tagged_keys(Depsgraph *depsgraph, Object *ob, ParticleSystem } remove_tagged_particles(ob, psys, pe_x_mirror(ob)); - LOOP_POINTS - { + LOOP_POINTS { pa = psys->particles + p; new_totkey = pa->totkey; - LOOP_TAGGED_KEYS - { + LOOP_TAGGED_KEYS { new_totkey--; } @@ -2889,8 +2837,7 @@ static void remove_tagged_keys(Depsgraph *depsgraph, Object *ob, ParticleSystem nkey = new_keys = MEM_callocN(new_totkey * sizeof(PTCacheEditKey), "particle edit keys"); hkey = pa->hair; - LOOP_KEYS - { + LOOP_KEYS { while (key->flag & PEK_TAG && hkey < pa->hair + pa->totkey) { key++; hkey++; @@ -3062,9 +3009,10 @@ void PARTICLE_OT_subdivide(wmOperatorType *ot) static int remove_doubles_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); ParticleSystem *psys = edit->psys; ParticleSystemModifierData *psmd_eval; KDTree_3d *tree; @@ -3087,8 +3035,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) tree = BLI_kdtree_3d_new(psys->totpart); /* insert particles into kd tree */ - LOOP_SELECTED_POINTS - { + LOOP_SELECTED_POINTS { psys_mat_hair_to_object( ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat); copy_v3_v3(co, point->keys->co); @@ -3099,8 +3046,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) BLI_kdtree_3d_balance(tree); /* tag particles to be removed */ - LOOP_SELECTED_POINTS - { + LOOP_SELECTED_POINTS { psys_mat_hair_to_object( ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat); copy_v3_v3(co, point->keys->co); @@ -3130,7 +3076,11 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - BKE_reportf(op->reports, RPT_INFO, "Removed %d double particles", totremoved); + BKE_reportf(op->reports, + RPT_INFO, + totremoved == 1 ? "Removed %d double particle" : + "Removed %d double particles", + totremoved); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob); @@ -3166,10 +3116,11 @@ void PARTICLE_OT_remove_doubles(wmOperatorType *ot) static int weight_set_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); ParticleEditSettings *pset = PE_settings(scene); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); ParticleSystem *psys = edit->psys; POINT_P; KEY_K; @@ -3181,12 +3132,10 @@ static int weight_set_exec(bContext *C, wmOperator *op) weight = brush->strength; edit = psys->edit; - LOOP_SELECTED_POINTS - { + LOOP_SELECTED_POINTS { ParticleData *pa = psys->particles + p; - LOOP_SELECTED_KEYS - { + LOOP_SELECTED_KEYS { hkey = pa->hair + k; hkey->weight = interpf(weight, hkey->weight, factor); } @@ -3315,6 +3264,7 @@ static int delete_exec(bContext *C, wmOperator *op) } DEG_id_tag_update(&data.ob->id, ID_RECALC_GEOMETRY); + BKE_particle_batch_cache_dirty_tag(data.edit->psys, BKE_PARTICLE_BATCH_DIRTY_ALL); WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, data.ob); return OPERATOR_FINISHED; @@ -3346,11 +3296,11 @@ void PARTICLE_OT_delete(wmOperatorType *ot) /*************************** mirror operator **************************/ -static void PE_mirror_x(Scene *scene, Object *ob, int tagged) +static void PE_mirror_x(Depsgraph *depsgraph, Scene *scene, Object *ob, int tagged) { Mesh *me = (Mesh *)(ob->data); ParticleSystemModifierData *psmd_eval; - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); ParticleSystem *psys = edit->psys; ParticleData *pa, *newpa, *new_pars; PTCacheEditPoint *newpoint, *new_points; @@ -3386,8 +3336,7 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) totpart = psys->totpart; newtotpart = psys->totpart; - LOOP_VISIBLE_POINTS - { + LOOP_VISIBLE_POINTS { pa = psys->particles + p; if (!tagged) { @@ -3503,8 +3452,7 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) } } - LOOP_POINTS - { + LOOP_POINTS { point->flag &= ~PEP_TAG; } @@ -3513,14 +3461,18 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) static int mirror_exec(bContext *C, wmOperator *UNUSED(op)) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); - PE_mirror_x(scene, ob, 0); + PE_mirror_x(depsgraph, scene, ob, 0); update_world_cos(ob, edit); + psys_free_path_cache(NULL, edit); + WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob); + BKE_particle_batch_cache_dirty_tag(edit->psys, BKE_PARTICLE_BATCH_DIRTY_ALL); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); return OPERATOR_FINISHED; @@ -3681,8 +3633,7 @@ static void brush_length(PEData *data, int point_index, float UNUSED(mouse_dista KEY_K; float dvec[3], pvec[3] = {0.0f, 0.0f, 0.0f}; - LOOP_KEYS - { + LOOP_KEYS { if (k == 0) { copy_v3_v3(pvec, key->co); } @@ -3731,8 +3682,7 @@ static void brush_puff(PEData *data, int point_index, float mouse_distance) unit_m4(imat); } - LOOP_KEYS - { + LOOP_KEYS { float kco[3]; if (k == 0) { @@ -4504,10 +4454,11 @@ typedef struct BrushEdit { static int brush_edit_init(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = CTX_data_active_object(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); ARegion *ar = CTX_wm_region(C); BrushEdit *bedit; float min[3], max[3]; @@ -4518,7 +4469,7 @@ static int brush_edit_init(bContext *C, wmOperator *op) /* set the 'distance factor' for grabbing (used in comb etc) */ INIT_MINMAX(min, max); - PE_minmax(scene, view_layer, min, max); + PE_minmax(depsgraph, scene, view_layer, min, max); mid_v3_v3v3(min, min, max); bedit = MEM_callocN(sizeof(BrushEdit), "BrushEdit"); @@ -4744,7 +4695,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) 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); + PE_mirror_x(depsgraph, scene, ob, 1); } update_world_cos(ob, edit); @@ -4993,10 +4944,11 @@ static void shape_cut(PEData *data, int pa_index) static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) { + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); ParticleEditSettings *pset = PE_settings(scene); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); Object *shapeob = pset->shape_object; int selected = count_selected_keys(scene, edit); int lock_root = pset->flag & PE_LOCK_FIRST; @@ -5074,10 +5026,11 @@ void PARTICLE_OT_shape_cut(wmOperatorType *ot) /************************ utilities ******************************/ -int PE_minmax(Scene *scene, ViewLayer *view_layer, float min[3], float max[3]) +int PE_minmax( + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, float min[3], float max[3]) { Object *ob = OBACT(view_layer); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); ParticleSystem *psys; ParticleSystemModifierData *psmd_eval = NULL; POINT_P; @@ -5096,15 +5049,13 @@ int PE_minmax(Scene *scene, ViewLayer *view_layer, float min[3], float max[3]) unit_m4(mat); } - LOOP_VISIBLE_POINTS - { + LOOP_VISIBLE_POINTS { if (psys) { psys_mat_hair_to_global( ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat); } - LOOP_SELECTED_KEYS - { + LOOP_SELECTED_KEYS { copy_v3_v3(co, key->co); mul_m4_v3(mat, co); DO_MINMAX(co, min, max); @@ -5181,15 +5132,13 @@ void PE_create_particle_edit( BLI_listbase_clear(&edit->pathcachebufs); pa = psys->particles; - LOOP_POINTS - { + LOOP_POINTS { point->totkey = pa->totkey; point->keys = MEM_callocN(point->totkey * sizeof(PTCacheEditKey), "ParticleEditKeys"); point->flag |= PEP_EDIT_RECALC; hkey = pa->hair; - LOOP_KEYS - { + LOOP_KEYS { key->co = hkey->co; key->time = &hkey->time; key->flag = hkey->editflag; @@ -5217,8 +5166,7 @@ void PE_create_particle_edit( } for (pm = cache->mem_cache.first; pm; pm = pm->next) { - LOOP_POINTS - { + LOOP_POINTS { if (BKE_ptcache_mem_pointers_seek(p, pm) == 0) { continue; } @@ -5421,8 +5369,7 @@ static float calculate_point_length(PTCacheEditPoint *point) { float length = 0.0f; KEY_K; - LOOP_KEYS - { + LOOP_KEYS { if (k > 0) { length += len_v3v3((key - 1)->co, key->co); } @@ -5435,10 +5382,9 @@ static float calculate_average_length(PTCacheEdit *edit) int num_selected = 0; float total_length = 0; POINT_P; - LOOP_SELECTED_POINTS - { + LOOP_SELECTED_POINTS { total_length += calculate_point_length(point); - ++num_selected; + num_selected++; } if (num_selected == 0) { return 0.0f; @@ -5450,8 +5396,7 @@ static void scale_point_factor(PTCacheEditPoint *point, float factor) { float orig_prev_co[3], prev_co[3]; KEY_K; - LOOP_KEYS - { + LOOP_KEYS { if (k == 0) { copy_v3_v3(orig_prev_co, key->co); copy_v3_v3(prev_co, key->co); @@ -5484,8 +5429,7 @@ static void scale_point_to_length(PTCacheEditPoint *point, float length) static void scale_points_to_length(PTCacheEdit *edit, float length) { POINT_P; - LOOP_SELECTED_POINTS - { + LOOP_SELECTED_POINTS { scale_point_to_length(point, length); } recalc_lengths(edit); @@ -5497,7 +5441,7 @@ static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); float average_length = calculate_average_length(edit); if (average_length == 0.0f) { |