Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/particle_edit.c
| Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "physics_intern.h" | #include "physics_intern.h" | ||||
| void PE_create_particle_edit( | void PE_create_particle_edit( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, Object *ob, | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, Object *ob, | ||||
| PointCache *cache, ParticleSystem *psys); | PointCache *cache, ParticleSystem *psys); | ||||
| void PTCacheUndo_clear(PTCacheEdit *edit); | void PTCacheUndo_clear(PTCacheEdit *edit); | ||||
| void recalc_lengths(PTCacheEdit *edit); | void recalc_lengths(PTCacheEdit *edit); | ||||
| void recalc_emitter_field(Object *ob, ParticleSystem *psys); | void recalc_emitter_field(Object *ob, ParticleSystem *psys); | ||||
| void update_world_cos(Object *ob, PTCacheEdit *edit); | void update_world_cos(Object *ob, PTCacheEdit *edit); | ||||
| #define KEY_K PTCacheEditKey *key; int k | #define KEY_K PTCacheEditKey *key; int k | ||||
| #define POINT_P PTCacheEditPoint *point; int p | #define POINT_P PTCacheEditPoint *point; int p | ||||
| Show All 10 Lines | |||||
| #define KEY_WCO ((key->flag & PEK_USE_WCO) ? key->world_co : key->co) | #define KEY_WCO ((key->flag & PEK_USE_WCO) ? key->world_co : key->co) | ||||
| /**************************** utilities *******************************/ | /**************************** utilities *******************************/ | ||||
| int PE_poll(bContext *C) | int PE_poll(bContext *C) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| Object *ob= CTX_data_active_object(C); | Object *ob= CTX_data_active_object(C); | ||||
| if (!scene || !sl || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) | if (!scene || !sl || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) | ||||
| return 0; | return 0; | ||||
| return (PE_get_current(scene, sl, ob) != NULL); | return (PE_get_current(scene, sl, ob) != NULL); | ||||
| } | } | ||||
| int PE_hair_poll(bContext *C) | int PE_hair_poll(bContext *C) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| Object *ob= CTX_data_active_object(C); | Object *ob= CTX_data_active_object(C); | ||||
| PTCacheEdit *edit; | PTCacheEdit *edit; | ||||
| if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) | if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) | ||||
| return 0; | return 0; | ||||
| edit= PE_get_current(scene, sl, ob); | edit= PE_get_current(scene, sl, ob); | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* always gets at least the first particlesystem even if PSYS_CURRENT flag is not set | /* always gets at least the first particlesystem even if PSYS_CURRENT flag is not set | ||||
| * | * | ||||
| * note: this function runs on poll, therefor it can runs many times a second | * note: this function runs on poll, therefor it can runs many times a second | ||||
| * keep it fast! */ | * keep it fast! */ | ||||
| static PTCacheEdit *pe_get_current( | static PTCacheEdit *pe_get_current( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, Object *ob, int create) | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, Object *ob, int create) | ||||
| { | { | ||||
| ParticleEditSettings *pset= PE_settings(scene); | ParticleEditSettings *pset= PE_settings(scene); | ||||
| PTCacheEdit *edit = NULL; | PTCacheEdit *edit = NULL; | ||||
| ListBase pidlist; | ListBase pidlist; | ||||
| PTCacheID *pid; | PTCacheID *pid; | ||||
| if (pset==NULL || ob==NULL) | if (pset==NULL || ob==NULL) | ||||
| return NULL; | return NULL; | ||||
| pset->scene = scene; | pset->scene = scene; | ||||
| pset->scene_layer = sl; | pset->view_layer = sl; | ||||
| pset->object = ob; | pset->object = ob; | ||||
| BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); | BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); | ||||
| /* in the case of only one editable thing, set pset->edittype accordingly */ | /* in the case of only one editable thing, set pset->edittype accordingly */ | ||||
| if (BLI_listbase_is_single(&pidlist)) { | if (BLI_listbase_is_single(&pidlist)) { | ||||
| pid = pidlist.first; | pid = pidlist.first; | ||||
| switch (pid->type) { | switch (pid->type) { | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | static PTCacheEdit *pe_get_current( | ||||
| if (edit) | if (edit) | ||||
| edit->pid = *pid; | edit->pid = *pid; | ||||
| BLI_freelistN(&pidlist); | BLI_freelistN(&pidlist); | ||||
| return edit; | return edit; | ||||
| } | } | ||||
| PTCacheEdit *PE_get_current(Scene *scene, SceneLayer *sl, Object *ob) | PTCacheEdit *PE_get_current(Scene *scene, ViewLayer *sl, Object *ob) | ||||
| { | { | ||||
| return pe_get_current(NULL, scene, sl, ob, 0); | return pe_get_current(NULL, scene, sl, ob, 0); | ||||
| } | } | ||||
| PTCacheEdit *PE_create_current(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) | PTCacheEdit *PE_create_current(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) | ||||
| { | { | ||||
| return pe_get_current(eval_ctx, scene, NULL, ob, 1); | return pe_get_current(eval_ctx, scene, NULL, ob, 1); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| /****************** common struct passed to callbacks ******************/ | /****************** common struct passed to callbacks ******************/ | ||||
| typedef struct PEData { | typedef struct PEData { | ||||
| ViewContext vc; | ViewContext vc; | ||||
| const bContext *context; | const bContext *context; | ||||
| Scene *scene; | Scene *scene; | ||||
| SceneLayer *scene_layer; | ViewLayer *view_layer; | ||||
| Object *ob; | Object *ob; | ||||
| DerivedMesh *dm; | DerivedMesh *dm; | ||||
| PTCacheEdit *edit; | PTCacheEdit *edit; | ||||
| BVHTreeFromMesh shape_bvh; | BVHTreeFromMesh shape_bvh; | ||||
| const int *mval; | const int *mval; | ||||
| rcti *rect; | rcti *rect; | ||||
| float rad; | float rad; | ||||
| Show All 18 Lines | typedef struct PEData { | ||||
| int select_toggle_action; | int select_toggle_action; | ||||
| } PEData; | } PEData; | ||||
| static void PE_set_data(bContext *C, PEData *data) | static void PE_set_data(bContext *C, PEData *data) | ||||
| { | { | ||||
| memset(data, 0, sizeof(*data)); | memset(data, 0, sizeof(*data)); | ||||
| data->scene = CTX_data_scene(C); | data->scene = CTX_data_scene(C); | ||||
| data->scene_layer = CTX_data_scene_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->edit = PE_get_current(data->scene, data->scene_layer, data->ob); | data->edit = PE_get_current(data->scene, data->view_layer, 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); | ||||
| view3d_set_viewcontext(C, &data->vc); | view3d_set_viewcontext(C, &data->vc); | ||||
| ▲ Show 20 Lines • Show All 745 Lines • ▼ Show 20 Lines | for (i=0; i<totface; i++, vec+=6, nor+=6) { | ||||
| normalize_v3(nor); | normalize_v3(nor); | ||||
| BLI_kdtree_insert(edit->emitter_field, i, vec); | BLI_kdtree_insert(edit->emitter_field, i, vec); | ||||
| } | } | ||||
| BLI_kdtree_balance(edit->emitter_field); | BLI_kdtree_balance(edit->emitter_field); | ||||
| } | } | ||||
| static void PE_update_selection(const bContext *C, Scene *scene, SceneLayer *sl, Object *ob, int useflag) | static void PE_update_selection(const bContext *C, Scene *scene, ViewLayer *sl, Object *ob, int useflag) | ||||
| { | { | ||||
| PTCacheEdit *edit = PE_get_current(scene, sl, ob); | PTCacheEdit *edit = PE_get_current(scene, sl, ob); | ||||
| HairKey *hkey; | HairKey *hkey; | ||||
| EvaluationContext eval_ctx; | EvaluationContext eval_ctx; | ||||
| POINT_P; KEY_K; | POINT_P; KEY_K; | ||||
| CTX_data_eval_ctx(C, &eval_ctx); | CTX_data_eval_ctx(C, &eval_ctx); | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | LOOP_KEYS { | ||||
| sub_v3_v3v3(key->vel, (key+1)->co, (key-1)->co); | sub_v3_v3v3(key->vel, (key+1)->co, (key-1)->co); | ||||
| } | } | ||||
| mul_v3_fl(key->vel, frs_sec/dfra); | mul_v3_fl(key->vel, frs_sec/dfra); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void PE_update_object(const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, Object *ob, int useflag) | void PE_update_object(const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, 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, sl, ob); | PTCacheEdit *edit = PE_get_current(scene, sl, ob); | ||||
| POINT_P; | POINT_P; | ||||
| if (!edit) | if (!edit) | ||||
| ▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | case SEL_INVERT: | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| 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); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = 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, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| POINT_P; KEY_K; | POINT_P; 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 All 37 Lines | |||||
| } | } | ||||
| /************************ pick select operator ************************/ | /************************ pick select operator ************************/ | ||||
| int PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) | int 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); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = 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, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| POINT_P; KEY_K; | POINT_P; KEY_K; | ||||
| if (!PE_start_edit(edit)) | if (!PE_start_edit(edit)) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| if (!extend && !deselect && !toggle) { | if (!extend && !deselect && !toggle) { | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (action == SEL_TOGGLE) { | ||||
| foreach_point(&data, select_root); | foreach_point(&data, select_root); | ||||
| action = data.select_toggle_action; | action = data.select_toggle_action; | ||||
| } | } | ||||
| data.select_action = action; | data.select_action = action; | ||||
| foreach_point(&data, select_root); | foreach_point(&data, select_root); | ||||
| PE_update_selection(C, data.scene, data.scene_layer, data.ob, 1); | PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); | ||||
| WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void PARTICLE_OT_select_roots(wmOperatorType *ot) | void PARTICLE_OT_select_roots(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if (action == SEL_TOGGLE) { | ||||
| foreach_point(&data, select_tip); | foreach_point(&data, select_tip); | ||||
| action = data.select_toggle_action; | action = data.select_toggle_action; | ||||
| } | } | ||||
| data.select_action = action; | data.select_action = action; | ||||
| foreach_point(&data, select_tip); | foreach_point(&data, select_tip); | ||||
| PE_update_selection(C, data.scene, data.scene_layer, data.ob, 1); | PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); | ||||
| WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void PARTICLE_OT_select_tips(wmOperatorType *ot) | void PARTICLE_OT_select_tips(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| Show All 22 Lines | static const EnumPropertyItem select_random_type_items[] = { | ||||
| {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) | ||||
| { | { | ||||
| PEData data; | PEData data; | ||||
| int type; | int type; | ||||
| Scene *scene; | Scene *scene; | ||||
| SceneLayer *sl; | ViewLayer *sl; | ||||
| Object *ob; | Object *ob; | ||||
| /* 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; | ||||
| scene = CTX_data_scene(C); | scene = CTX_data_scene(C); | ||||
| sl = CTX_data_scene_layer(C); | sl = CTX_data_view_layer(C); | ||||
| ob = CTX_data_active_object(C); | ob = CTX_data_active_object(C); | ||||
| edit = PE_get_current(scene, sl, ob); | edit = PE_get_current(scene, sl, 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 { | ||||
| Show All 10 Lines | case RAN_POINTS: | ||||
| select_action_apply (point, key, flag); | select_action_apply (point, key, flag); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| BLI_rng_free(rng); | BLI_rng_free(rng); | ||||
| PE_update_selection(C, data.scene, data.scene_layer, data.ob, 1); | PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); | ||||
| WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void PARTICLE_OT_select_random(wmOperatorType *ot) | void PARTICLE_OT_select_random(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| Show All 27 Lines | static int select_linked_exec(bContext *C, wmOperator *op) | ||||
| mval[1] = location[1]; | mval[1] = location[1]; | ||||
| PE_set_view3d_data(C, &data); | PE_set_view3d_data(C, &data); | ||||
| data.mval= mval; | data.mval= mval; | ||||
| data.rad=75.0f; | data.rad=75.0f; | ||||
| data.select= !RNA_boolean_get(op->ptr, "deselect"); | data.select= !RNA_boolean_get(op->ptr, "deselect"); | ||||
| for_mouse_hit_keys(&data, select_keys, 1); /* nearest only */ | for_mouse_hit_keys(&data, select_keys, 1); /* nearest only */ | ||||
| PE_update_selection(C, data.scene, data.scene_layer, data.ob, 1); | PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); | ||||
| WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static int select_linked_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int select_linked_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| RNA_int_set_array(op->ptr, "location", event->mval); | RNA_int_set_array(op->ptr, "location", event->mval); | ||||
| Show All 31 Lines | LOOP_SELECTED_KEYS { | ||||
| point->flag |= PEP_EDIT_RECALC; | point->flag |= PEP_EDIT_RECALC; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| int PE_border_select(bContext *C, rcti *rect, bool select, bool extend) | int PE_border_select(bContext *C, rcti *rect, bool select, bool extend) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = 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, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| PEData data; | PEData data; | ||||
| if (!PE_start_edit(edit)) | if (!PE_start_edit(edit)) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| if (extend == 0 && select) | if (extend == 0 && select) | ||||
| Show All 11 Lines | int PE_border_select(bContext *C, rcti *rect, bool select, bool extend) | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /************************ circle select operator ************************/ | /************************ circle select operator ************************/ | ||||
| int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) | int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = 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, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| PEData data; | PEData data; | ||||
| if (!PE_start_edit(edit)) | if (!PE_start_edit(edit)) | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| PE_set_view3d_data(C, &data); | PE_set_view3d_data(C, &data); | ||||
| Show All 9 Lines | int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /************************ lasso select operator ************************/ | /************************ lasso select operator ************************/ | ||||
| int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, bool extend, bool select) | int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, bool extend, bool select) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(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, sl, ob); | PTCacheEdit *edit = PE_get_current(scene, sl, ob); | ||||
| ParticleSystem *psys = edit->psys; | ParticleSystem *psys = edit->psys; | ||||
| ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); | ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); | ||||
| POINT_P; KEY_K; | POINT_P; KEY_K; | ||||
| float co[3], mat[4][4]; | float co[3], mat[4][4]; | ||||
| ▲ Show 20 Lines • Show All 73 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); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| POINT_P; KEY_K; | POINT_P; KEY_K; | ||||
| if (RNA_enum_get(op->ptr, "unselected")) { | if (RNA_enum_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 All 36 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); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| const bool select = RNA_boolean_get(op->ptr, "select"); | const bool select = RNA_boolean_get(op->ptr, "select"); | ||||
| POINT_P; KEY_K; | POINT_P; KEY_K; | ||||
| LOOP_POINTS { | LOOP_POINTS { | ||||
| if (point->flag & PEP_HIDE) { | if (point->flag & PEP_HIDE) { | ||||
| point->flag &= ~PEP_HIDE; | point->flag &= ~PEP_HIDE; | ||||
| point->flag |= PEP_EDIT_RECALC; | point->flag |= PEP_EDIT_RECALC; | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
| static int select_less_exec(bContext *C, wmOperator *UNUSED(op)) | static int select_less_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| PEData data; | PEData data; | ||||
| PE_set_data(C, &data); | PE_set_data(C, &data); | ||||
| foreach_point(&data, select_less_keys); | foreach_point(&data, select_less_keys); | ||||
| PE_update_selection(C, data.scene, data.scene_layer, data.ob, 1); | PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); | ||||
| WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void PARTICLE_OT_select_less(wmOperatorType *ot) | void PARTICLE_OT_select_less(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| static int select_more_exec(bContext *C, wmOperator *UNUSED(op)) | static int select_more_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| PEData data; | PEData data; | ||||
| PE_set_data(C, &data); | PE_set_data(C, &data); | ||||
| foreach_point(&data, select_more_keys); | foreach_point(&data, select_more_keys); | ||||
| PE_update_selection(C, data.scene, data.scene_layer, data.ob, 1); | PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); | ||||
| WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void PARTICLE_OT_select_more(wmOperatorType *ot) | void PARTICLE_OT_select_more(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | static int rekey_exec(bContext *C, wmOperator *op) | ||||
| PE_set_data(C, &data); | PE_set_data(C, &data); | ||||
| data.dval= 1.0f / (float)(data.totrekey-1); | data.dval= 1.0f / (float)(data.totrekey-1); | ||||
| data.totrekey= RNA_int_get(op->ptr, "keys_number"); | data.totrekey= RNA_int_get(op->ptr, "keys_number"); | ||||
| foreach_selected_point(&data, rekey_particle); | foreach_selected_point(&data, rekey_particle); | ||||
| recalc_lengths(data.edit); | recalc_lengths(data.edit); | ||||
| PE_update_object(&eval_ctx, data.scene, data.scene_layer, data.ob, 1); | PE_update_object(&eval_ctx, data.scene, data.view_layer, data.ob, 1); | ||||
| WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); | WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void PARTICLE_OT_rekey(wmOperatorType *ot) | void PARTICLE_OT_rekey(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Rekey"; | ot->name = "Rekey"; | ||||
| ot->idname = "PARTICLE_OT_rekey"; | ot->idname = "PARTICLE_OT_rekey"; | ||||
| ot->description = "Change the number of keys of selected particles (root and tip keys included)"; | ot->description = "Change the number of keys of selected particles (root and tip keys included)"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = rekey_exec; | ot->exec = rekey_exec; | ||||
| ot->invoke = WM_operator_props_popup; | ot->invoke = WM_operator_props_popup; | ||||
| ot->poll = PE_hair_poll; | ot->poll = PE_hair_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | ||||
| /* 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(const bContext *C, Scene *scene, SceneLayer *sl, Object *ob, int pa_index, float path_time) | static void rekey_particle_to_time(const bContext *C, Scene *scene, ViewLayer *sl, Object *ob, int pa_index, float path_time) | ||||
| { | { | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, 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; | ||||
| ▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | static int subdivide_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| EvaluationContext eval_ctx; | EvaluationContext eval_ctx; | ||||
| CTX_data_eval_ctx(C, &eval_ctx); | CTX_data_eval_ctx(C, &eval_ctx); | ||||
| PE_set_data(C, &data); | PE_set_data(C, &data); | ||||
| foreach_point(&data, subdivide_particle); | foreach_point(&data, subdivide_particle); | ||||
| recalc_lengths(data.edit); | recalc_lengths(data.edit); | ||||
| PE_update_object(&eval_ctx, data.scene, data.scene_layer, data.ob, 1); | PE_update_object(&eval_ctx, data.scene, data.view_layer, data.ob, 1); | ||||
| WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); | WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void PARTICLE_OT_subdivide(wmOperatorType *ot) | void PARTICLE_OT_subdivide(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| Show All 9 Lines | void PARTICLE_OT_subdivide(wmOperatorType *ot) | ||||
| 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) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = 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, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| ParticleSystem *psys = edit->psys; | ParticleSystem *psys = edit->psys; | ||||
| ParticleSystemModifierData *psmd; | ParticleSystemModifierData *psmd; | ||||
| KDTree *tree; | KDTree *tree; | ||||
| KDTreeNearest nearest[10]; | KDTreeNearest 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"); | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | void PARTICLE_OT_remove_doubles(wmOperatorType *ot) | ||||
| RNA_def_float(ot->srna, "threshold", 0.0002f, 0.0f, FLT_MAX, | RNA_def_float(ot->srna, "threshold", 0.0002f, 0.0f, FLT_MAX, | ||||
| "Merge Distance", "Threshold distance withing which particles are removed", 0.00001f, 0.1f); | "Merge Distance", "Threshold distance withing which particles are removed", 0.00001f, 0.1f); | ||||
| } | } | ||||
| static int weight_set_exec(bContext *C, wmOperator *op) | static int weight_set_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(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, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, 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; | ||||
| ▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | void PARTICLE_OT_delete(wmOperatorType *ot) | ||||
| ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| ot->prop = RNA_def_enum(ot->srna, "type", delete_type_items, DEL_PARTICLE, "Type", "Delete a full particle or only keys"); | ot->prop = RNA_def_enum(ot->srna, "type", delete_type_items, DEL_PARTICLE, "Type", "Delete a full particle or only keys"); | ||||
| } | } | ||||
| /*************************** mirror operator **************************/ | /*************************** mirror operator **************************/ | ||||
| static void PE_mirror_x(Scene *scene, SceneLayer *sl, Object *ob, int tagged) | static void PE_mirror_x(Scene *scene, ViewLayer *sl, Object *ob, int tagged) | ||||
| { | { | ||||
| Mesh *me= (Mesh *)(ob->data); | Mesh *me= (Mesh *)(ob->data); | ||||
| ParticleSystemModifierData *psmd; | ParticleSystemModifierData *psmd; | ||||
| PTCacheEdit *edit = PE_get_current(scene, sl, ob); | PTCacheEdit *edit = PE_get_current(scene, sl, 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; KEY_K; | POINT_P; KEY_K; | ||||
| ▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | static void PE_mirror_x(Scene *scene, ViewLayer *sl, Object *ob, int tagged) | ||||
| } | } | ||||
| MEM_freeN(mirrorfaces); | MEM_freeN(mirrorfaces); | ||||
| } | } | ||||
| static int mirror_exec(bContext *C, wmOperator *UNUSED(op)) | static int mirror_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = 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, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| PE_mirror_x(scene, sl, ob, 0); | PE_mirror_x(scene, sl, 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, OB_RECALC_DATA); | DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| ▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| if (cut) { | if (cut) { | ||||
| if (cut_time < 0.0f) { | if (cut_time < 0.0f) { | ||||
| edit->points[pa_index].flag |= PEP_TAG; | edit->points[pa_index].flag |= PEP_TAG; | ||||
| } | } | ||||
| else { | else { | ||||
| rekey_particle_to_time(data->context, data->scene, data->scene_layer, ob, pa_index, cut_time); | rekey_particle_to_time(data->context, data->scene, data->view_layer, ob, pa_index, cut_time); | ||||
| edit->points[pa_index].flag |= PEP_EDIT_RECALC; | edit->points[pa_index].flag |= PEP_EDIT_RECALC; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void brush_length(PEData *data, int point_index) | static void brush_length(PEData *data, int point_index) | ||||
| { | { | ||||
| PTCacheEdit *edit= data->edit; | PTCacheEdit *edit= data->edit; | ||||
| ▲ Show 20 Lines • Show All 619 Lines • ▼ Show 20 Lines | static int brush_add(const bContext *C, PEData *data, short number) | ||||
| return n; | return n; | ||||
| } | } | ||||
| /************************* brush edit operator ********************/ | /************************* brush edit operator ********************/ | ||||
| typedef struct BrushEdit { | typedef struct BrushEdit { | ||||
| Scene *scene; | Scene *scene; | ||||
| SceneLayer *sl; | ViewLayer *sl; | ||||
| Object *ob; | Object *ob; | ||||
| PTCacheEdit *edit; | PTCacheEdit *edit; | ||||
| int first; | int first; | ||||
| int lastmouse[2]; | int lastmouse[2]; | ||||
| 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) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(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, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, 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 (pset->brushtype < 0) | if (pset->brushtype < 0) | ||||
| Show All 20 Lines | static int brush_edit_init(bContext *C, wmOperator *op) | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) | static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) | ||||
| { | { | ||||
| BrushEdit *bedit= op->customdata; | BrushEdit *bedit= op->customdata; | ||||
| Scene *scene= bedit->scene; | Scene *scene= bedit->scene; | ||||
| SceneLayer *sl = bedit->sl; | ViewLayer *sl = bedit->sl; | ||||
| Object *ob= bedit->ob; | Object *ob= bedit->ob; | ||||
| PTCacheEdit *edit= bedit->edit; | PTCacheEdit *edit= bedit->edit; | ||||
| ParticleEditSettings *pset= PE_settings(scene); | ParticleEditSettings *pset= PE_settings(scene); | ||||
| ParticleSystemModifierData *psmd= edit->psys ? psys_get_modifier(ob, edit->psys) : NULL; | ParticleSystemModifierData *psmd= edit->psys ? psys_get_modifier(ob, edit->psys) : NULL; | ||||
| ParticleBrushData *brush= &pset->brush[pset->brushtype]; | ParticleBrushData *brush= &pset->brush[pset->brushtype]; | ||||
| ARegion *ar= CTX_wm_region(C); | ARegion *ar= CTX_wm_region(C); | ||||
| float vec[3], mousef[2]; | float vec[3], mousef[2]; | ||||
| int mval[2]; | int mval[2]; | ||||
| ▲ Show 20 Lines • Show All 400 Lines • ▼ Show 20 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| if (cut) { | if (cut) { | ||||
| if (cut_time < 0.0f) { | if (cut_time < 0.0f) { | ||||
| edit->points[pa_index].flag |= PEP_TAG; | edit->points[pa_index].flag |= PEP_TAG; | ||||
| } | } | ||||
| else { | else { | ||||
| rekey_particle_to_time(data->context, data->scene, data->scene_layer, ob, pa_index, cut_time); | rekey_particle_to_time(data->context, data->scene, data->view_layer, 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)) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(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, sl, ob); | PTCacheEdit *edit = PE_get_current(scene, sl, 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)) | ||||
| ▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | for (; pm; pm=pm->next) { | ||||
| } | } | ||||
| } | } | ||||
| BKE_ptcache_mem_pointers_incr(pm); | BKE_ptcache_mem_pointers_incr(pm); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void PE_undo_push(Scene *scene, SceneLayer *sl, const char *str) | void PE_undo_push(Scene *scene, ViewLayer *sl, const char *str) | ||||
| { | { | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | ||||
| PTCacheUndo *undo; | PTCacheUndo *undo; | ||||
| int nr; | int nr; | ||||
| if (!edit) return; | if (!edit) return; | ||||
| /* remove all undos after (also when curundo==NULL) */ | /* remove all undos after (also when curundo==NULL) */ | ||||
| Show All 25 Lines | while (edit->undo.first != undo) { | ||||
| MEM_freeN(first); | MEM_freeN(first); | ||||
| } | } | ||||
| } | } | ||||
| /* copy */ | /* copy */ | ||||
| make_PTCacheUndo(edit, edit->curundo); | make_PTCacheUndo(edit, edit->curundo); | ||||
| } | } | ||||
| void PE_undo_step(Scene *scene, SceneLayer *sl, int step) | void PE_undo_step(Scene *scene, ViewLayer *sl, int step) | ||||
| { | { | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | ||||
| if (!edit) return; | if (!edit) return; | ||||
| if (step==0) { | if (step==0) { | ||||
| get_PTCacheUndo(edit, edit->curundo); | get_PTCacheUndo(edit, edit->curundo); | ||||
| } | } | ||||
| Show All 19 Lines | else { | ||||
| edit->curundo= edit->curundo->next; | edit->curundo= edit->curundo->next; | ||||
| if (G.debug & G_DEBUG) printf("redo %s\n", edit->curundo->name); | if (G.debug & G_DEBUG) printf("redo %s\n", edit->curundo->name); | ||||
| } | } | ||||
| } | } | ||||
| DEG_id_tag_update(&OBACT(sl)->id, OB_RECALC_DATA); | DEG_id_tag_update(&OBACT(sl)->id, OB_RECALC_DATA); | ||||
| } | } | ||||
| bool PE_undo_is_valid(Scene *scene, SceneLayer *sl) | bool PE_undo_is_valid(Scene *scene, ViewLayer *sl) | ||||
| { | { | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | ||||
| if (edit) { | if (edit) { | ||||
| return (edit->undo.last != edit->undo.first); | return (edit->undo.last != edit->undo.first); | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| void PTCacheUndo_clear(PTCacheEdit *edit) | void PTCacheUndo_clear(PTCacheEdit *edit) | ||||
| { | { | ||||
| PTCacheUndo *undo; | PTCacheUndo *undo; | ||||
| if (edit==NULL) return; | if (edit==NULL) return; | ||||
| undo= edit->undo.first; | undo= edit->undo.first; | ||||
| while (undo) { | while (undo) { | ||||
| free_PTCacheUndo(undo); | free_PTCacheUndo(undo); | ||||
| undo= undo->next; | undo= undo->next; | ||||
| } | } | ||||
| BLI_freelistN(&edit->undo); | BLI_freelistN(&edit->undo); | ||||
| edit->curundo= NULL; | edit->curundo= NULL; | ||||
| } | } | ||||
| void PE_undo(Scene *scene, SceneLayer *sl) | void PE_undo(Scene *scene, ViewLayer *sl) | ||||
| { | { | ||||
| PE_undo_step(scene, sl, 1); | PE_undo_step(scene, sl, 1); | ||||
| } | } | ||||
| void PE_redo(Scene *scene, SceneLayer *sl) | void PE_redo(Scene *scene, ViewLayer *sl) | ||||
| { | { | ||||
| PE_undo_step(scene, sl, -1); | PE_undo_step(scene, sl, -1); | ||||
| } | } | ||||
| void PE_undo_number(Scene *scene, SceneLayer *sl, int nr) | void PE_undo_number(Scene *scene, ViewLayer *sl, int nr) | ||||
| { | { | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | ||||
| PTCacheUndo *undo; | PTCacheUndo *undo; | ||||
| int a=0; | int a=0; | ||||
| for (undo= edit->undo.first; undo; undo= undo->next, a++) { | for (undo= edit->undo.first; undo; undo= undo->next, a++) { | ||||
| if (a==nr) break; | if (a==nr) break; | ||||
| } | } | ||||
| edit->curundo= undo; | edit->curundo= undo; | ||||
| PE_undo_step(scene, sl, 0); | PE_undo_step(scene, sl, 0); | ||||
| } | } | ||||
| /* get name of undo item, return null if no item with this index */ | /* get name of undo item, return null if no item with this index */ | ||||
| /* if active pointer, set it to 1 if true */ | /* if active pointer, set it to 1 if true */ | ||||
| const char *PE_undo_get_name(Scene *scene, SceneLayer *sl, int nr, bool *r_active) | const char *PE_undo_get_name(Scene *scene, ViewLayer *sl, int nr, bool *r_active) | ||||
| { | { | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | PTCacheEdit *edit= PE_get_current(scene, sl, OBACT(sl)); | ||||
| PTCacheUndo *undo; | PTCacheUndo *undo; | ||||
| if (r_active) *r_active = false; | if (r_active) *r_active = false; | ||||
| if (edit) { | if (edit) { | ||||
| undo= BLI_findlink(&edit->undo, nr); | undo= BLI_findlink(&edit->undo, nr); | ||||
| if (undo) { | if (undo) { | ||||
| if (r_active && (undo == edit->curundo)) { | if (r_active && (undo == edit->curundo)) { | ||||
| *r_active = true; | *r_active = true; | ||||
| } | } | ||||
| return undo->name; | return undo->name; | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /************************ utilities ******************************/ | /************************ utilities ******************************/ | ||||
| int PE_minmax(Scene *scene, SceneLayer *sl, float min[3], float max[3]) | int PE_minmax(Scene *scene, ViewLayer *sl, float min[3], float max[3]) | ||||
| { | { | ||||
| Object *ob= OBACT(sl); | Object *ob= OBACT(sl); | ||||
| PTCacheEdit *edit= PE_get_current(scene, sl, ob); | PTCacheEdit *edit= PE_get_current(scene, sl, ob); | ||||
| ParticleSystem *psys; | ParticleSystem *psys; | ||||
| ParticleSystemModifierData *psmd = NULL; | ParticleSystemModifierData *psmd = NULL; | ||||
| POINT_P; KEY_K; | POINT_P; KEY_K; | ||||
| float co[3], mat[4][4]; | float co[3], mat[4][4]; | ||||
| int ok= 0; | int ok= 0; | ||||
| Show All 24 Lines | int PE_minmax(Scene *scene, ViewLayer *sl, float min[3], float max[3]) | ||||
| return ok; | return ok; | ||||
| } | } | ||||
| /************************ particle edit toggle operator ************************/ | /************************ particle edit toggle operator ************************/ | ||||
| /* initialize needed data for bake edit */ | /* initialize needed data for bake edit */ | ||||
| void PE_create_particle_edit( | void PE_create_particle_edit( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, Object *ob, PointCache *cache, ParticleSystem *psys) | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, Object *ob, PointCache *cache, ParticleSystem *psys) | ||||
| { | { | ||||
| PTCacheEdit *edit; | PTCacheEdit *edit; | ||||
| ParticleSystemModifierData *psmd = (psys) ? psys_get_modifier(ob, psys) : NULL; | ParticleSystemModifierData *psmd = (psys) ? psys_get_modifier(ob, psys) : NULL; | ||||
| POINT_P; KEY_K; | POINT_P; KEY_K; | ||||
| ParticleData *pa = NULL; | ParticleData *pa = NULL; | ||||
| HairKey *hkey; | HairKey *hkey; | ||||
| int totpoint; | int totpoint; | ||||
| ▲ Show 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | static void scale_points_to_length(PTCacheEdit *edit, float length) | ||||
| } | } | ||||
| recalc_lengths(edit); | recalc_lengths(edit); | ||||
| } | } | ||||
| 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); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| PTCacheEdit *edit = PE_get_current(scene, sl, ob); | PTCacheEdit *edit = PE_get_current(scene, sl, 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); | ||||
| Show All 30 Lines | |||||