diff options
Diffstat (limited to 'source/blender/editors/physics/particle_edit.c')
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 218 |
1 files changed, 121 insertions, 97 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index e22a145b3a6..711ee6c8861 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -73,6 +73,8 @@ #include "ED_particle.h" #include "ED_view3d.h" +#include "GPU_immediate.h" + #include "UI_resources.h" #include "WM_api.h" @@ -83,7 +85,7 @@ #include "physics_intern.h" -void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys); +void PE_create_particle_edit(Scene *scene, SceneLayer *sl, Object *ob, PointCache *cache, ParticleSystem *psys); void PTCacheUndo_clear(PTCacheEdit *edit); void recalc_lengths(PTCacheEdit *edit); void recalc_emitter_field(Object *ob, ParticleSystem *psys); @@ -109,24 +111,26 @@ void update_world_cos(Object *ob, PTCacheEdit *edit); int PE_poll(bContext *C) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Object *ob= CTX_data_active_object(C); - if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) + if (!scene || !sl || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) return 0; - return (PE_get_current(scene, ob) != NULL); + return (PE_get_current(scene, sl, ob) != NULL); } int PE_hair_poll(bContext *C) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Object *ob= CTX_data_active_object(C); PTCacheEdit *edit; if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) return 0; - edit= PE_get_current(scene, ob); + edit= PE_get_current(scene, sl, ob); return (edit && edit->psys); } @@ -211,7 +215,7 @@ static float pe_brush_size_get(const Scene *UNUSED(scene), ParticleBrushData *br * * note: this function runs on poll, therefor it can runs many times a second * keep it fast! */ -static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) +static PTCacheEdit *pe_get_current(Scene *scene, SceneLayer *sl, Object *ob, int create) { ParticleEditSettings *pset= PE_settings(scene); PTCacheEdit *edit = NULL; @@ -222,6 +226,7 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) return NULL; pset->scene = scene; + pset->scene_layer = sl; pset->object = ob; BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); @@ -250,18 +255,18 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) if (psys->part && psys->part->type == PART_HAIR) { if (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED) { if (create && !psys->pointcache->edit) - PE_create_particle_edit(scene, ob, pid->cache, NULL); + PE_create_particle_edit(scene, sl, ob, pid->cache, NULL); edit = pid->cache->edit; } else { if (create && !psys->edit && psys->flag & PSYS_HAIR_DONE) - PE_create_particle_edit(scene, ob, NULL, psys); + PE_create_particle_edit(scene, sl, ob, NULL, psys); edit = psys->edit; } } else { if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) - PE_create_particle_edit(scene, ob, pid->cache, psys); + PE_create_particle_edit(scene, sl, ob, pid->cache, psys); edit = pid->cache->edit; } @@ -272,7 +277,7 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) { pset->flag |= PE_FADE_TIME; // NICE TO HAVE but doesn't work: pset->brushtype = PE_BRUSH_COMB; - PE_create_particle_edit(scene, ob, pid->cache, NULL); + PE_create_particle_edit(scene, sl, ob, pid->cache, NULL); } edit = pid->cache->edit; break; @@ -281,7 +286,7 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) { pset->flag |= PE_FADE_TIME; // NICE TO HAVE but doesn't work: pset->brushtype = PE_BRUSH_COMB; - PE_create_particle_edit(scene, ob, pid->cache, NULL); + PE_create_particle_edit(scene, sl, ob, pid->cache, NULL); } edit = pid->cache->edit; break; @@ -296,14 +301,14 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create) return edit; } -PTCacheEdit *PE_get_current(Scene *scene, Object *ob) +PTCacheEdit *PE_get_current(Scene *scene, SceneLayer *sl, Object *ob) { - return pe_get_current(scene, ob, 0); + return pe_get_current(scene, sl, ob, 0); } PTCacheEdit *PE_create_current(Scene *scene, Object *ob) { - return pe_get_current(scene, ob, 1); + return pe_get_current(scene, NULL, ob, 1); } void PE_current_changed(Scene *scene, Object *ob) @@ -351,9 +356,9 @@ static int pe_x_mirror(Object *ob) typedef struct PEData { ViewContext vc; - bglMats mats; Scene *scene; + SceneLayer *sl; Object *ob; DerivedMesh *dm; PTCacheEdit *edit; @@ -388,8 +393,9 @@ static void PE_set_data(bContext *C, PEData *data) memset(data, 0, sizeof(*data)); data->scene= CTX_data_scene(C); + data->sl = CTX_data_scene_layer(C); data->ob= CTX_data_active_object(C); - data->edit= PE_get_current(data->scene, data->ob); + data->edit= PE_get_current(data->scene, data->sl, data->ob); } static void PE_set_view3d_data(bContext *C, PEData *data) @@ -397,8 +403,6 @@ static void PE_set_view3d_data(bContext *C, PEData *data) PE_set_data(C, data); view3d_set_viewcontext(C, &data->vc); - /* note, the object argument means the modelview matrix does not account for the objects matrix, use viewmat rather than (obmat * viewmat) */ - view3d_get_transformation(data->vc.ar, data->vc.rv3d, NULL, &data->mats); if (V3D_IS_ZBUF(data->vc.v3d)) { if (data->vc.v3d->flag & V3D_INVALID_BACKBUF) { @@ -439,7 +443,6 @@ static bool key_test_depth(PEData *data, const float co[3], const int screen_co[ { View3D *v3d= data->vc.v3d; ViewDepths *vd = data->vc.rv3d->depths; - double ux, uy, uz; float depth; /* nothing to do */ @@ -455,9 +458,6 @@ static bool key_test_depth(PEData *data, const float co[3], const int screen_co[ } #endif - gluProject(co[0], co[1], co[2], data->mats.modelview, data->mats.projection, - (GLint *)data->mats.viewport, &ux, &uy, &uz); - /* check if screen_co is within bounds because brush_cut uses out of screen coords */ if (screen_co[0] >= 0 && screen_co[0] < vd->w && screen_co[1] >= 0 && screen_co[1] < vd->h) { BLI_assert(vd && vd->depths); @@ -467,7 +467,10 @@ static bool key_test_depth(PEData *data, const float co[3], const int screen_co[ else return 0; - if ((float)uz - 0.00001f > depth) + float win[3]; + ED_view3d_project(data->vc.ar, co, win); + + if (win[2] - 0.00001f > depth) return 0; else return 1; @@ -1152,9 +1155,9 @@ void recalc_emitter_field(Object *ob, ParticleSystem *psys) BLI_kdtree_balance(edit->emitter_field); } -static void PE_update_selection(Scene *scene, Object *ob, int useflag) +static void PE_update_selection(Scene *scene, SceneLayer *sl, Object *ob, int useflag) { - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); HairKey *hkey; POINT_P; KEY_K; @@ -1259,12 +1262,12 @@ static void update_velocities(PTCacheEdit *edit) } } -void PE_update_object(Scene *scene, Object *ob, int useflag) +void PE_update_object(Scene *scene, SceneLayer *sl, Object *ob, int useflag) { /* 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(scene, sl, ob); POINT_P; if (!edit) @@ -1399,8 +1402,9 @@ static void select_action_apply(PTCacheEditPoint *point, PTCacheEditKey *key, in static int pe_select_all_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Object *ob= CTX_data_active_object(C); - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); POINT_P; KEY_K; int action = RNA_enum_get(op->ptr, "action"); @@ -1423,7 +1427,7 @@ static int pe_select_all_exec(bContext *C, wmOperator *op) } } - PE_update_selection(scene, ob, 1); + PE_update_selection(scene, sl, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1452,8 +1456,9 @@ int PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselec { PEData data; Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Object *ob= CTX_data_active_object(C); - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); POINT_P; KEY_K; if (!PE_start_edit(edit)) @@ -1480,7 +1485,7 @@ int PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselec else for_mouse_hit_keys(&data, toggle_key_select, 1); - PE_update_selection(scene, ob, 1); + PE_update_selection(scene, sl, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1521,7 +1526,7 @@ static int select_roots_exec(bContext *C, wmOperator *op) data.select_action = action; foreach_point(&data, select_root); - PE_update_selection(data.scene, data.ob, 1); + PE_update_selection(data.scene, data.sl, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1586,7 +1591,7 @@ static int select_tips_exec(bContext *C, wmOperator *op) data.select_action = action; foreach_point(&data, select_tip); - PE_update_selection(data.scene, data.ob, 1); + PE_update_selection(data.scene, data.sl, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1625,6 +1630,7 @@ static int select_random_exec(bContext *C, wmOperator *op) PEData data; int type; Scene *scene; + SceneLayer *sl; Object *ob; /* used by LOOP_VISIBLE_POINTS, LOOP_VISIBLE_KEYS and LOOP_KEYS */ @@ -1644,8 +1650,9 @@ static int select_random_exec(bContext *C, wmOperator *op) PE_set_data(C, &data); data.select_action = SEL_SELECT; scene = CTX_data_scene(C); + sl = CTX_data_scene_layer(C); ob = CTX_data_active_object(C); - edit = PE_get_current(scene, ob); + edit = PE_get_current(scene, sl, ob); rng = BLI_rng_new_srandom(seed); @@ -1670,7 +1677,7 @@ static int select_random_exec(bContext *C, wmOperator *op) BLI_rng_free(rng); - PE_update_selection(data.scene, data.ob, 1); + PE_update_selection(data.scene, data.sl, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1714,7 +1721,7 @@ static int select_linked_exec(bContext *C, wmOperator *op) data.select= !RNA_boolean_get(op->ptr, "deselect"); for_mouse_hit_keys(&data, select_keys, 1); /* nearest only */ - PE_update_selection(data.scene, data.ob, 1); + PE_update_selection(data.scene, data.sl, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1762,8 +1769,9 @@ void PE_deselect_all_visible(PTCacheEdit *edit) int PE_border_select(bContext *C, rcti *rect, bool select, bool extend) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Object *ob= CTX_data_active_object(C); - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); PEData data; if (!PE_start_edit(edit)) @@ -1778,7 +1786,7 @@ int PE_border_select(bContext *C, rcti *rect, bool select, bool extend) for_mouse_hit_keys(&data, select_key, 0); - PE_update_selection(scene, ob, 1); + PE_update_selection(scene, sl, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1789,8 +1797,9 @@ int PE_border_select(bContext *C, rcti *rect, bool select, bool extend) int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Object *ob= CTX_data_active_object(C); - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); PEData data; if (!PE_start_edit(edit)) @@ -1803,7 +1812,7 @@ int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) for_mouse_hit_keys(&data, select_key, 0); - PE_update_selection(scene, ob, 1); + PE_update_selection(scene, sl, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1814,10 +1823,11 @@ int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, bool extend, bool select) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(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(scene, sl, ob); ParticleSystem *psys = edit->psys; ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); POINT_P; KEY_K; @@ -1891,7 +1901,7 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, bool } } - PE_update_selection(scene, ob, 1); + PE_update_selection(scene, sl, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1903,7 +1913,8 @@ static int hide_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); Scene *scene= CTX_data_scene(C); - PTCacheEdit *edit= PE_get_current(scene, ob); + SceneLayer *sl = CTX_data_scene_layer(C); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); POINT_P; KEY_K; if (RNA_enum_get(op->ptr, "unselected")) { @@ -1925,7 +1936,7 @@ static int hide_exec(bContext *C, wmOperator *op) } } - PE_update_selection(scene, ob, 1); + PE_update_selection(scene, sl, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1955,7 +1966,8 @@ static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_active_object(C); Scene *scene= CTX_data_scene(C); - PTCacheEdit *edit= PE_get_current(scene, ob); + SceneLayer *sl = CTX_data_scene_layer(C); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); POINT_P; KEY_K; LOOP_POINTS { @@ -1968,7 +1980,7 @@ static int reveal_exec(bContext *C, wmOperator *UNUSED(op)) } } - PE_update_selection(scene, ob, 1); + PE_update_selection(scene, sl, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -2027,7 +2039,7 @@ static int select_less_exec(bContext *C, wmOperator *UNUSED(op)) PE_set_data(C, &data); foreach_point(&data, select_less_keys); - PE_update_selection(data.scene, data.ob, 1); + PE_update_selection(data.scene, data.sl, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -2089,7 +2101,7 @@ static int select_more_exec(bContext *C, wmOperator *UNUSED(op)) PE_set_data(C, &data); foreach_point(&data, select_more_keys); - PE_update_selection(data.scene, data.ob, 1); + PE_update_selection(data.scene, data.sl, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -2186,7 +2198,7 @@ static int rekey_exec(bContext *C, wmOperator *op) foreach_selected_point(&data, rekey_particle); recalc_lengths(data.edit); - PE_update_object(data.scene, data.ob, 1); + PE_update_object(data.scene, data.sl, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); return OPERATOR_FINISHED; @@ -2211,9 +2223,9 @@ void PARTICLE_OT_rekey(wmOperatorType *ot) RNA_def_int(ot->srna, "keys_number", 2, 2, INT_MAX, "Number of Keys", "", 2, 100); } -static void rekey_particle_to_time(Scene *scene, Object *ob, int pa_index, float path_time) +static void rekey_particle_to_time(Scene *scene, SceneLayer *sl, Object *ob, int pa_index, float path_time) { - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); ParticleSystem *psys; ParticleSimulationData sim= {0}; ParticleData *pa; @@ -2517,7 +2529,7 @@ static int subdivide_exec(bContext *C, wmOperator *UNUSED(op)) foreach_point(&data, subdivide_particle); recalc_lengths(data.edit); - PE_update_object(data.scene, data.ob, 1); + PE_update_object(data.scene, data.sl, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); return OPERATOR_FINISHED; @@ -2543,8 +2555,9 @@ void PARTICLE_OT_subdivide(wmOperatorType *ot) static int remove_doubles_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Object *ob= CTX_data_active_object(C); - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); ParticleSystem *psys = edit->psys; ParticleSystemModifierData *psmd; KDTree *tree; @@ -2635,9 +2648,10 @@ void PARTICLE_OT_remove_doubles(wmOperatorType *ot) static int weight_set_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(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(scene, sl, ob); ParticleSystem *psys = edit->psys; POINT_P; KEY_K; @@ -2690,24 +2704,27 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata) ParticleEditSettings *pset= PE_settings(scene); ParticleBrushData *brush; - if (pset->brushtype < 0) + if (pset->brushtype < 0) { return; + } - brush= &pset->brush[pset->brushtype]; + brush = &pset->brush[pset->brushtype]; if (brush) { - glPushMatrix(); + unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - glTranslatef((float)x, (float)y, 0.0f); + immUniformColor4ub(255, 255, 255, 128); - glColor4ub(255, 255, 255, 128); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); - glutil_draw_lined_arc(0.0, M_PI*2.0, pe_brush_size_get(scene, brush), 40); + + imm_draw_lined_circle(pos, (float)x, (float)y, pe_brush_size_get(scene, brush), 40); + glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); - - glPopMatrix(); + + immUnbindProgram(); } } @@ -2791,11 +2808,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(Scene *scene, SceneLayer *sl, Object *ob, int tagged) { Mesh *me= (Mesh *)(ob->data); ParticleSystemModifierData *psmd; - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); ParticleSystem *psys = edit->psys; ParticleData *pa, *newpa, *new_pars; PTCacheEditPoint *newpoint, *new_points; @@ -2942,10 +2959,11 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) static int mirror_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Object *ob= CTX_data_active_object(C); - PTCacheEdit *edit= PE_get_current(scene, ob); + PTCacheEdit *edit= PE_get_current(scene, sl, ob); - PE_mirror_x(scene, ob, 0); + PE_mirror_x(scene, sl, ob, 0); update_world_cos(ob, edit); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob); @@ -3082,7 +3100,7 @@ static void brush_cut(PEData *data, int pa_index) edit->points[pa_index].flag |= PEP_TAG; } else { - rekey_particle_to_time(data->scene, ob, pa_index, cut_time); + rekey_particle_to_time(data->scene, data->sl, ob, pa_index, cut_time); edit->points[pa_index].flag |= PEP_EDIT_RECALC; } } @@ -3711,6 +3729,7 @@ static int brush_add(PEData *data, short number) typedef struct BrushEdit { Scene *scene; + SceneLayer *sl; Object *ob; PTCacheEdit *edit; @@ -3725,9 +3744,10 @@ typedef struct BrushEdit { static int brush_edit_init(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(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(scene, sl, ob); ARegion *ar= CTX_wm_region(C); BrushEdit *bedit; float min[3], max[3]; @@ -3737,7 +3757,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, min, max); + PE_minmax(scene, sl, min, max); mid_v3_v3v3(min, min, max); bedit= MEM_callocN(sizeof(BrushEdit), "BrushEdit"); @@ -3745,6 +3765,7 @@ static int brush_edit_init(bContext *C, wmOperator *op) op->customdata= bedit; bedit->scene= scene; + bedit->sl = sl; bedit->ob= ob; bedit->edit= edit; @@ -3760,6 +3781,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) { BrushEdit *bedit= op->customdata; Scene *scene= bedit->scene; + SceneLayer *sl = bedit->sl; Object *ob= bedit->ob; PTCacheEdit *edit= bedit->edit; ParticleEditSettings *pset= PE_settings(scene); @@ -3950,14 +3972,14 @@ 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(scene, sl, ob, 1); update_world_cos(ob, edit); psys_free_path_cache(NULL, edit); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } else - PE_update_object(scene, ob, 1); + PE_update_object(scene, sl, ob, 1); } if (edit->psys) { @@ -4170,7 +4192,7 @@ static void shape_cut(PEData *data, int pa_index) edit->points[pa_index].flag |= PEP_TAG; } else { - rekey_particle_to_time(data->scene, ob, pa_index, cut_time); + rekey_particle_to_time(data->scene, data->sl, ob, pa_index, cut_time); edit->points[pa_index].flag |= PEP_EDIT_RECALC; } } @@ -4179,9 +4201,10 @@ static void shape_cut(PEData *data, int pa_index) static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(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(scene, sl, ob); Object *shapeob = pset->shape_object; int selected = count_selected_keys(scene, edit); int lock_root = pset->flag & PE_LOCK_FIRST; @@ -4217,7 +4240,7 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } else - PE_update_object(scene, ob, 1); + PE_update_object(scene, sl, ob, 1); if (edit->psys) { WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob); @@ -4389,9 +4412,9 @@ static void get_PTCacheUndo(PTCacheEdit *edit, PTCacheUndo *undo) } } -void PE_undo_push(Scene *scene, const char *str) +void PE_undo_push(Scene *scene, SceneLayer *sl, const char *str) { - PTCacheEdit *edit= PE_get_current(scene, OBACT); + PTCacheEdit *edit= PE_get_current(scene, sl, OBACT_NEW); PTCacheUndo *undo; int nr; @@ -4431,9 +4454,9 @@ void PE_undo_push(Scene *scene, const char *str) make_PTCacheUndo(edit, edit->curundo); } -void PE_undo_step(Scene *scene, int step) +void PE_undo_step(Scene *scene, SceneLayer *sl, int step) { - PTCacheEdit *edit= PE_get_current(scene, OBACT); + PTCacheEdit *edit= PE_get_current(scene, sl, OBACT_NEW); if (!edit) return; @@ -4464,12 +4487,12 @@ void PE_undo_step(Scene *scene, int step) } } - DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); + DAG_id_tag_update(&OBACT_NEW->id, OB_RECALC_DATA); } -bool PE_undo_is_valid(Scene *scene) +bool PE_undo_is_valid(Scene *scene, SceneLayer *sl) { - PTCacheEdit *edit= PE_get_current(scene, OBACT); + PTCacheEdit *edit= PE_get_current(scene, sl, OBACT_NEW); if (edit) { return (edit->undo.last != edit->undo.first); @@ -4492,19 +4515,19 @@ void PTCacheUndo_clear(PTCacheEdit *edit) edit->curundo= NULL; } -void PE_undo(Scene *scene) +void PE_undo(Scene *scene, SceneLayer *sl) { - PE_undo_step(scene, 1); + PE_undo_step(scene, sl, 1); } -void PE_redo(Scene *scene) +void PE_redo(Scene *scene, SceneLayer *sl) { - PE_undo_step(scene, -1); + PE_undo_step(scene, sl, -1); } -void PE_undo_number(Scene *scene, int nr) +void PE_undo_number(Scene *scene, SceneLayer *sl, int nr) { - PTCacheEdit *edit= PE_get_current(scene, OBACT); + PTCacheEdit *edit= PE_get_current(scene, sl, OBACT_NEW); PTCacheUndo *undo; int a=0; @@ -4512,15 +4535,15 @@ void PE_undo_number(Scene *scene, int nr) if (a==nr) break; } edit->curundo= undo; - PE_undo_step(scene, 0); + PE_undo_step(scene, sl, 0); } /* get name of undo item, return null if no item with this index */ /* if active pointer, set it to 1 if true */ -const char *PE_undo_get_name(Scene *scene, int nr, bool *r_active) +const char *PE_undo_get_name(Scene *scene, SceneLayer *sl, int nr, bool *r_active) { - PTCacheEdit *edit= PE_get_current(scene, OBACT); + PTCacheEdit *edit= PE_get_current(scene, sl, OBACT_NEW); PTCacheUndo *undo; if (r_active) *r_active = false; @@ -4539,10 +4562,10 @@ const char *PE_undo_get_name(Scene *scene, int nr, bool *r_active) /************************ utilities ******************************/ -int PE_minmax(Scene *scene, float min[3], float max[3]) +int PE_minmax(Scene *scene, SceneLayer *sl, float min[3], float max[3]) { - Object *ob= OBACT; - PTCacheEdit *edit= PE_get_current(scene, ob); + Object *ob= OBACT_NEW; + PTCacheEdit *edit= PE_get_current(scene, sl, ob); ParticleSystem *psys; ParticleSystemModifierData *psmd = NULL; POINT_P; KEY_K; @@ -4579,7 +4602,7 @@ int PE_minmax(Scene *scene, float min[3], float max[3]) /************************ particle edit toggle operator ************************/ /* initialize needed data for bake edit */ -void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys) +void PE_create_particle_edit(Scene *scene, SceneLayer *sl, Object *ob, PointCache *cache, ParticleSystem *psys) { PTCacheEdit *edit; ParticleSystemModifierData *psmd = (psys) ? psys_get_modifier(ob, psys) : NULL; @@ -4680,10 +4703,10 @@ void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, Partic recalc_lengths(edit); if (psys && !cache) recalc_emitter_field(ob, psys); - PE_update_object(scene, ob, 1); + PE_update_object(scene, sl, ob, 1); PTCacheUndo_clear(edit); - PE_undo_push(scene, "Original"); + PE_undo_push(scene, sl, "Original"); } } @@ -4887,14 +4910,15 @@ static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); - PTCacheEdit *edit = PE_get_current(scene, ob); + SceneLayer *sl = CTX_data_scene_layer(C); + PTCacheEdit *edit = PE_get_current(scene, sl, ob); float average_length = calculate_average_length(edit); if (average_length == 0.0f) { return OPERATOR_CANCELLED; } scale_points_to_length(edit, average_length); - PE_update_object(scene, ob, 1); + PE_update_object(scene, sl, ob, 1); if (edit->psys) { WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob); } |