Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/particle_edit.c
| Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
| #include "physics_intern.h" | #include "physics_intern.h" | ||||
| #include "particle_edit_utildefines.h" | #include "particle_edit_utildefines.h" | ||||
| /**************************** utilities *******************************/ | /**************************** utilities *******************************/ | ||||
| bool PE_poll(bContext *C) | bool PE_poll(bContext *C) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(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 false; | return false; | ||||
| } | } | ||||
| PTCacheEdit *edit = PE_get_current(scene, ob); | PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); | ||||
| if (edit == NULL) { | if (edit == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (edit->psmd_eval == NULL || edit->psmd_eval->mesh_final == NULL) { | if (edit->psmd_eval == NULL || edit->psmd_eval->mesh_final == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool PE_hair_poll(bContext *C) | bool PE_hair_poll(bContext *C) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(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 false; | return false; | ||||
| } | } | ||||
| PTCacheEdit *edit = PE_get_current(scene, ob); | PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); | ||||
| if (edit == NULL || edit->psys == NULL) { | if (edit == NULL || edit->psys == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (edit->psmd_eval == NULL || edit->psmd_eval->mesh_final == NULL) { | if (edit->psmd_eval == NULL || edit->psmd_eval->mesh_final == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| ▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | if (edit && DEG_is_active(depsgraph)) { | ||||
| } | } | ||||
| } | } | ||||
| BLI_freelistN(&pidlist); | BLI_freelistN(&pidlist); | ||||
| return edit; | 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) | PTCacheEdit *PE_create_current(Depsgraph *depsgraph, Scene *scene, Object *ob) | ||||
| { | { | ||||
| return pe_get_current(depsgraph, scene, ob, 1); | return pe_get_current(depsgraph, scene, ob, 1); | ||||
| } | } | ||||
| void PE_current_changed(Depsgraph *depsgraph, Scene *scene, Object *ob) | void PE_current_changed(Depsgraph *depsgraph, Scene *scene, Object *ob) | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | static void PE_set_data(bContext *C, PEData *data) | ||||
| memset(data, 0, sizeof(*data)); | memset(data, 0, sizeof(*data)); | ||||
| data->context = C; | data->context = C; | ||||
| data->bmain = CTX_data_main(C); | data->bmain = CTX_data_main(C); | ||||
| data->scene = CTX_data_scene(C); | data->scene = CTX_data_scene(C); | ||||
| data->view_layer = CTX_data_view_layer(C); | data->view_layer = CTX_data_view_layer(C); | ||||
| data->ob = CTX_data_active_object(C); | data->ob = CTX_data_active_object(C); | ||||
| data->depsgraph = CTX_data_ensure_evaluated_depsgraph(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) | static void PE_set_view3d_data(bContext *C, PEData *data) | ||||
| { | { | ||||
| PE_set_data(C, data); | PE_set_data(C, data); | ||||
| ED_view3d_viewcontext_init(C, &data->vc); | ED_view3d_viewcontext_init(C, &data->vc); | ||||
| ▲ Show 20 Lines • Show All 978 Lines • ▼ Show 20 Lines | for (i = 0; i < totface; i++, vec += 6, nor += 6) { | ||||
| BLI_kdtree_3d_insert(edit->emitter_field, i, vec); | BLI_kdtree_3d_insert(edit->emitter_field, i, vec); | ||||
| } | } | ||||
| BLI_kdtree_3d_balance(edit->emitter_field); | BLI_kdtree_3d_balance(edit->emitter_field); | ||||
| } | } | ||||
| static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag) | 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; | HairKey *hkey; | ||||
| POINT_P; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| /* flag all particles to be updated if not using flag */ | /* flag all particles to be updated if not using flag */ | ||||
| if (!useflag) { | if (!useflag) { | ||||
| LOOP_POINTS | LOOP_POINTS | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | static void update_velocities(PTCacheEdit *edit) | ||||
| } | } | ||||
| } | } | ||||
| void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag) | void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag) | ||||
| { | { | ||||
| /* use this to do partial particle updates, not usable when adding or | /* use this to do partial particle updates, not usable when adding or | ||||
| * removing, then a full redo is necessary and calling this may crash */ | * removing, then a full redo is necessary and calling this may crash */ | ||||
| ParticleEditSettings *pset = PE_settings(scene); | ParticleEditSettings *pset = PE_settings(scene); | ||||
| PTCacheEdit *edit = PE_get_current(scene, ob); | PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); | ||||
| POINT_P; | POINT_P; | ||||
| if (!edit) { | if (!edit) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* flag all particles to be updated if not using flag */ | /* flag all particles to be updated if not using flag */ | ||||
| if (!useflag) { | if (!useflag) { | ||||
| ▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | static bool select_action_apply(PTCacheEditPoint *point, PTCacheEditKey *key, int action) | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| static int pe_select_all_exec(bContext *C, wmOperator *op) | static int pe_select_all_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| Object *ob = CTX_data_active_object(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; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| int action = RNA_enum_get(op->ptr, "action"); | int action = RNA_enum_get(op->ptr, "action"); | ||||
| if (action == SEL_TOGGLE) { | if (action == SEL_TOGGLE) { | ||||
| action = SEL_SELECT; | action = SEL_SELECT; | ||||
| LOOP_VISIBLE_POINTS | LOOP_VISIBLE_POINTS | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| /************************ pick select operator ************************/ | /************************ pick select operator ************************/ | ||||
| bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) | bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) | ||||
| { | { | ||||
| PEData data; | PEData data; | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(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; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| if (!PE_start_edit(edit)) { | if (!PE_start_edit(edit)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!extend && !deselect && !toggle) { | if (!extend && !deselect && !toggle) { | ||||
| ▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | |||||
| static const EnumPropertyItem select_random_type_items[] = { | static const EnumPropertyItem select_random_type_items[] = { | ||||
| {RAN_HAIR, "HAIR", 0, "Hair", ""}, | {RAN_HAIR, "HAIR", 0, "Hair", ""}, | ||||
| {RAN_POINTS, "POINTS", 0, "Points", ""}, | {RAN_POINTS, "POINTS", 0, "Points", ""}, | ||||
| {0, NULL, 0, NULL, NULL}, | {0, NULL, 0, NULL, NULL}, | ||||
| }; | }; | ||||
| static int select_random_exec(bContext *C, wmOperator *op) | static int select_random_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| PEData data; | PEData data; | ||||
| int type; | int type; | ||||
| /* used by LOOP_VISIBLE_POINTS, LOOP_VISIBLE_KEYS and LOOP_KEYS */ | /* used by LOOP_VISIBLE_POINTS, LOOP_VISIBLE_KEYS and LOOP_KEYS */ | ||||
| PTCacheEdit *edit; | PTCacheEdit *edit; | ||||
| PTCacheEditPoint *point; | PTCacheEditPoint *point; | ||||
| PTCacheEditKey *key; | PTCacheEditKey *key; | ||||
| int p; | int p; | ||||
| int k; | int k; | ||||
| const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f; | const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f; | ||||
| const int seed = WM_operator_properties_select_random_seed_increment_get(op); | const int seed = WM_operator_properties_select_random_seed_increment_get(op); | ||||
| const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT); | const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT); | ||||
| RNG *rng; | RNG *rng; | ||||
| type = RNA_enum_get(op->ptr, "type"); | type = RNA_enum_get(op->ptr, "type"); | ||||
| PE_set_data(C, &data); | PE_set_data(C, &data); | ||||
| data.select_action = SEL_SELECT; | 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); | rng = BLI_rng_new_srandom(seed); | ||||
| switch (type) { | switch (type) { | ||||
| case RAN_HAIR: | case RAN_HAIR: | ||||
| LOOP_VISIBLE_POINTS | LOOP_VISIBLE_POINTS | ||||
| { | { | ||||
| int flag = ((BLI_rng_get_float(rng) < randfac) == select) ? SEL_SELECT : SEL_DESELECT; | int flag = ((BLI_rng_get_float(rng) < randfac) == select) ? SEL_SELECT : SEL_DESELECT; | ||||
| ▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | LOOP_SELECTED_KEYS | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| bool PE_deselect_all_visible(bContext *C) | bool PE_deselect_all_visible(bContext *C) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(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)) { | if (!PE_start_edit(edit)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return PE_deselect_all_visible_ex(edit); | return PE_deselect_all_visible_ex(edit); | ||||
| } | } | ||||
| bool PE_box_select(bContext *C, const rcti *rect, const int sel_op) | 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); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(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; | PEData data; | ||||
| if (!PE_start_edit(edit)) { | if (!PE_start_edit(edit)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| PE_set_view3d_data(C, &data); | PE_set_view3d_data(C, &data); | ||||
| data.rect = rect; | data.rect = rect; | ||||
| Show All 17 Lines | bool PE_box_select(bContext *C, const rcti *rect, const int sel_op) | ||||
| return data.is_changed; | return data.is_changed; | ||||
| } | } | ||||
| /************************ circle select operator ************************/ | /************************ circle select operator ************************/ | ||||
| bool PE_circle_select(bContext *C, const int sel_op, const int mval[2], float rad) | 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)); | 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); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(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; | PEData data; | ||||
| if (!PE_start_edit(edit)) { | if (!PE_start_edit(edit)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| const bool select = (sel_op != SEL_OP_SUB); | const bool select = (sel_op != SEL_OP_SUB); | ||||
| Show All 12 Lines | bool PE_circle_select(bContext *C, const int sel_op, const int mval[2], float rad) | ||||
| } | } | ||||
| return data.is_changed; | return data.is_changed; | ||||
| } | } | ||||
| /************************ lasso select operator ************************/ | /************************ lasso select operator ************************/ | ||||
| int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, const int sel_op) | 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); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| ParticleEditSettings *pset = PE_settings(scene); | ParticleEditSettings *pset = PE_settings(scene); | ||||
| PTCacheEdit *edit = PE_get_current(scene, ob); | PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); | ||||
| ParticleSystem *psys = edit->psys; | ParticleSystem *psys = edit->psys; | ||||
| ParticleSystemModifierData *psmd_eval = edit->psmd_eval; | ParticleSystemModifierData *psmd_eval = edit->psmd_eval; | ||||
| POINT_P; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| float co[3], mat[4][4]; | float co[3], mat[4][4]; | ||||
| int screen_co[2]; | int screen_co[2]; | ||||
| PEData data; | PEData data; | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
| /*************************** hide operator **************************/ | /*************************** hide operator **************************/ | ||||
| static int hide_exec(bContext *C, wmOperator *op) | static int hide_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(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; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| if (RNA_boolean_get(op->ptr, "unselected")) { | if (RNA_boolean_get(op->ptr, "unselected")) { | ||||
| LOOP_UNSELECTED_POINTS | LOOP_UNSELECTED_POINTS | ||||
| { | { | ||||
| point->flag |= PEP_HIDE; | point->flag |= PEP_HIDE; | ||||
| point->flag |= PEP_EDIT_RECALC; | point->flag |= PEP_EDIT_RECALC; | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| /*************************** reveal operator **************************/ | /*************************** reveal operator **************************/ | ||||
| static int reveal_exec(bContext *C, wmOperator *op) | static int reveal_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(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"); | const bool select = RNA_boolean_get(op->ptr, "select"); | ||||
| POINT_P; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| LOOP_POINTS | LOOP_POINTS | ||||
| { | { | ||||
| if (point->flag & PEP_HIDE) { | if (point->flag & PEP_HIDE) { | ||||
| point->flag &= ~PEP_HIDE; | point->flag &= ~PEP_HIDE; | ||||
| ▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | void PARTICLE_OT_rekey(wmOperatorType *ot) | ||||
| /* properties */ | /* properties */ | ||||
| RNA_def_int(ot->srna, "keys_number", 2, 2, INT_MAX, "Number of Keys", "", 2, 100); | RNA_def_int(ot->srna, "keys_number", 2, 2, INT_MAX, "Number of Keys", "", 2, 100); | ||||
| } | } | ||||
| static void rekey_particle_to_time( | static void rekey_particle_to_time( | ||||
| const bContext *C, Scene *scene, Object *ob, int pa_index, float path_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; | ParticleSystem *psys; | ||||
| ParticleSimulationData sim = {0}; | ParticleSimulationData sim = {0}; | ||||
| ParticleData *pa; | ParticleData *pa; | ||||
| ParticleKey state; | ParticleKey state; | ||||
| HairKey *new_keys, *key; | HairKey *new_keys, *key; | ||||
| PTCacheEditKey *ekey; | PTCacheEditKey *ekey; | ||||
| int k; | int k; | ||||
| if (!edit || !edit->psys) { | if (!edit || !edit->psys) { | ||||
| return; | return; | ||||
| } | } | ||||
| psys = edit->psys; | psys = edit->psys; | ||||
| sim.depsgraph = CTX_data_depsgraph_pointer(C); | sim.depsgraph = depsgraph; | ||||
| sim.scene = scene; | sim.scene = scene; | ||||
| sim.ob = ob; | sim.ob = ob; | ||||
| sim.psys = psys; | sim.psys = psys; | ||||
| pa = psys->particles + pa_index; | pa = psys->particles + pa_index; | ||||
| pa->flag |= PARS_REKEY; | pa->flag |= PARS_REKEY; | ||||
| ▲ Show 20 Lines • Show All 336 Lines • ▼ Show 20 Lines | void PARTICLE_OT_subdivide(wmOperatorType *ot) | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| /************************ remove doubles opertor *********************/ | /************************ remove doubles opertor *********************/ | ||||
| static int remove_doubles_exec(bContext *C, wmOperator *op) | static int remove_doubles_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(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; | ParticleSystem *psys = edit->psys; | ||||
| ParticleSystemModifierData *psmd_eval; | ParticleSystemModifierData *psmd_eval; | ||||
| KDTree_3d *tree; | KDTree_3d *tree; | ||||
| KDTreeNearest_3d nearest[10]; | KDTreeNearest_3d nearest[10]; | ||||
| POINT_P; | POINT_P; | ||||
| float mat[4][4], co[3], threshold = RNA_float_get(op->ptr, "threshold"); | float mat[4][4], co[3], threshold = RNA_float_get(op->ptr, "threshold"); | ||||
| int n, totn, removed, totremoved; | int n, totn, removed, totremoved; | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | RNA_def_float(ot->srna, | ||||
| "Merge Distance", | "Merge Distance", | ||||
| "Threshold distance within which particles are removed", | "Threshold distance within which particles are removed", | ||||
| 0.00001f, | 0.00001f, | ||||
| 0.1f); | 0.1f); | ||||
| } | } | ||||
| static int weight_set_exec(bContext *C, wmOperator *op) | static int weight_set_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ParticleEditSettings *pset = PE_settings(scene); | ParticleEditSettings *pset = PE_settings(scene); | ||||
| Object *ob = CTX_data_active_object(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; | ParticleSystem *psys = edit->psys; | ||||
| POINT_P; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| HairKey *hkey; | HairKey *hkey; | ||||
| float weight; | float weight; | ||||
| ParticleBrushData *brush = &pset->brush[pset->brushtype]; | ParticleBrushData *brush = &pset->brush[pset->brushtype]; | ||||
| float factor = RNA_float_get(op->ptr, "factor"); | float factor = RNA_float_get(op->ptr, "factor"); | ||||
| ▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | ot->prop = RNA_def_enum(ot->srna, | ||||
| delete_type_items, | delete_type_items, | ||||
| DEL_PARTICLE, | DEL_PARTICLE, | ||||
| "Type", | "Type", | ||||
| "Delete a full particle or only keys"); | "Delete a full particle or only keys"); | ||||
| } | } | ||||
| /*************************** mirror operator **************************/ | /*************************** 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); | Mesh *me = (Mesh *)(ob->data); | ||||
| ParticleSystemModifierData *psmd_eval; | ParticleSystemModifierData *psmd_eval; | ||||
| PTCacheEdit *edit = PE_get_current(scene, ob); | PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); | ||||
| ParticleSystem *psys = edit->psys; | ParticleSystem *psys = edit->psys; | ||||
| ParticleData *pa, *newpa, *new_pars; | ParticleData *pa, *newpa, *new_pars; | ||||
| PTCacheEditPoint *newpoint, *new_points; | PTCacheEditPoint *newpoint, *new_points; | ||||
| POINT_P; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| HairKey *hkey; | HairKey *hkey; | ||||
| int *mirrorfaces = NULL; | int *mirrorfaces = NULL; | ||||
| int rotation, totpart, newtotpart; | int rotation, totpart, newtotpart; | ||||
| ▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | LOOP_POINTS | ||||
| point->flag &= ~PEP_TAG; | point->flag &= ~PEP_TAG; | ||||
| } | } | ||||
| MEM_freeN(mirrorfaces); | MEM_freeN(mirrorfaces); | ||||
| } | } | ||||
| static int mirror_exec(bContext *C, wmOperator *UNUSED(op)) | static int mirror_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(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); | update_world_cos(ob, edit); | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob); | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 970 Lines • ▼ Show 20 Lines | typedef struct BrushEdit { | ||||
| float zfac; | float zfac; | ||||
| /* optional cached view settings to avoid setting on every mousemove */ | /* optional cached view settings to avoid setting on every mousemove */ | ||||
| PEData data; | PEData data; | ||||
| } BrushEdit; | } BrushEdit; | ||||
| static int brush_edit_init(bContext *C, wmOperator *op) | static int brush_edit_init(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| Object *ob = CTX_data_active_object(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); | ARegion *ar = CTX_wm_region(C); | ||||
| BrushEdit *bedit; | BrushEdit *bedit; | ||||
| float min[3], max[3]; | float min[3], max[3]; | ||||
| if (!WM_toolsystem_active_tool_is_brush(C)) { | if (!WM_toolsystem_active_tool_is_brush(C)) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* set the 'distance factor' for grabbing (used in comb etc) */ | /* set the 'distance factor' for grabbing (used in comb etc) */ | ||||
| INIT_MINMAX(min, max); | 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); | mid_v3_v3v3(min, min, max); | ||||
| bedit = MEM_callocN(sizeof(BrushEdit), "BrushEdit"); | bedit = MEM_callocN(sizeof(BrushEdit), "BrushEdit"); | ||||
| bedit->first = 1; | bedit->first = 1; | ||||
| op->customdata = bedit; | op->customdata = bedit; | ||||
| bedit->scene = scene; | bedit->scene = scene; | ||||
| bedit->view_layer = view_layer; | bedit->view_layer = view_layer; | ||||
| ▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | for (step = 1; step <= tot_steps; step++) { | ||||
| } | } | ||||
| } | } | ||||
| if ((pset->flag & PE_KEEP_LENGTHS) == 0) { | if ((pset->flag & PE_KEEP_LENGTHS) == 0) { | ||||
| recalc_lengths(edit); | recalc_lengths(edit); | ||||
| } | } | ||||
| if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_CUT) && (added || removed)) { | if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_CUT) && (added || removed)) { | ||||
| if (pset->brushtype == PE_BRUSH_ADD && pe_x_mirror(ob)) { | if (pset->brushtype == PE_BRUSH_ADD && pe_x_mirror(ob)) { | ||||
| PE_mirror_x(scene, ob, 1); | PE_mirror_x(depsgraph, scene, ob, 1); | ||||
| } | } | ||||
| update_world_cos(ob, edit); | update_world_cos(ob, edit); | ||||
| psys_free_path_cache(NULL, edit); | psys_free_path_cache(NULL, edit); | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | ||||
| } | } | ||||
| else { | else { | ||||
| PE_update_object(depsgraph, scene, ob, 1); | PE_update_object(depsgraph, scene, ob, 1); | ||||
| ▲ Show 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | else { | ||||
| rekey_particle_to_time(data->context, data->scene, ob, pa_index, cut_time); | rekey_particle_to_time(data->context, data->scene, ob, pa_index, cut_time); | ||||
| edit->points[pa_index].flag |= PEP_EDIT_RECALC; | edit->points[pa_index].flag |= PEP_EDIT_RECALC; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) | static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| ParticleEditSettings *pset = PE_settings(scene); | 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; | Object *shapeob = pset->shape_object; | ||||
| int selected = count_selected_keys(scene, edit); | int selected = count_selected_keys(scene, edit); | ||||
| int lock_root = pset->flag & PE_LOCK_FIRST; | int lock_root = pset->flag & PE_LOCK_FIRST; | ||||
| if (!PE_start_edit(edit)) { | if (!PE_start_edit(edit)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | void PARTICLE_OT_shape_cut(wmOperatorType *ot) | ||||
| ot->poll = shape_cut_poll; | ot->poll = shape_cut_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| /************************ utilities ******************************/ | /************************ 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); | Object *ob = OBACT(view_layer); | ||||
| PTCacheEdit *edit = PE_get_current(scene, ob); | PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); | ||||
| ParticleSystem *psys; | ParticleSystem *psys; | ||||
| ParticleSystemModifierData *psmd_eval = NULL; | ParticleSystemModifierData *psmd_eval = NULL; | ||||
| POINT_P; | POINT_P; | ||||
| KEY_K; | KEY_K; | ||||
| float co[3], mat[4][4]; | float co[3], mat[4][4]; | ||||
| int ok = 0; | int ok = 0; | ||||
| if (!edit) { | if (!edit) { | ||||
| ▲ Show 20 Lines • Show All 403 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) | static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(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); | float average_length = calculate_average_length(edit); | ||||
| if (average_length == 0.0f) { | if (average_length == 0.0f) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| scale_points_to_length(edit, average_length); | scale_points_to_length(edit, average_length); | ||||
| PE_update_object(depsgraph, scene, ob, 1); | PE_update_object(depsgraph, scene, ob, 1); | ||||
| Show All 25 Lines | |||||