diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_object.h | 14 | ||||
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 86 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 167 |
3 files changed, 167 insertions, 100 deletions
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index a2a8fbab6b3..c99b132ad7c 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -226,6 +226,20 @@ void ED_object_vpaintmode_exit(struct bContext *C); void ED_object_wpaintmode_exit_ex(struct Object *ob); void ED_object_wpaintmode_exit(struct bContext *C); +void ED_object_texture_paint_mode_enter_ex(struct Main *bmain, struct Scene *scene, Object *ob); +void ED_object_texture_paint_mode_enter(struct bContext *C); + +void ED_object_texture_paint_mode_exit_ex(struct Main *bmain, struct Scene *scene, Object *ob); +void ED_object_texture_paint_mode_exit(struct bContext *C); + +void ED_object_particle_edit_mode_enter_ex(struct Depsgraph *depsgraph, + struct Scene *scene, + Object *ob); +void ED_object_particle_edit_mode_enter(struct bContext *C); + +void ED_object_particle_edit_mode_exit_ex(struct Scene *scene, Object *ob); +void ED_object_particle_edit_mode_exit(struct bContext *C); + void ED_object_sculptmode_enter_ex(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 3639cd64b7c..ef5ed806c1e 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -3230,9 +3230,9 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata) } } -static void toggle_particle_cursor(bContext *C, int enable) +static void toggle_particle_cursor(Scene *scene, bool enable) { - ParticleEditSettings *pset = PE_settings(CTX_data_scene(C)); + ParticleEditSettings *pset = PE_settings(scene); if (pset->paintcursor && !enable) { WM_paint_cursor_end(pset->paintcursor); @@ -5268,10 +5268,60 @@ static void free_all_psys_edit(Object *object) } } +void ED_object_particle_edit_mode_enter_ex(Depsgraph *depsgraph, Scene *scene, Object *ob) +{ + PTCacheEdit *edit; + + ob->mode |= OB_MODE_PARTICLE_EDIT; + + edit = PE_create_current(depsgraph, scene, ob); + + /* Mesh may have changed since last entering editmode. + * note, this may have run before if the edit data was just created, + * so could avoid this and speed up a little. */ + if (edit && edit->psys) { + /* Make sure pointer to the evaluated modifier data is up to date, + * with possible changes applied when object was outside of the + * edit mode. */ + Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); + edit->psmd_eval = (ParticleSystemModifierData *)BKE_modifiers_findby_name( + object_eval, edit->psmd->modifier.name); + recalc_emitter_field(depsgraph, ob, edit->psys); + } + + toggle_particle_cursor(scene, true); + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_PARTICLE, NULL); +} + +void ED_object_particle_edit_mode_enter(bContext *C) +{ + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + ED_object_particle_edit_mode_enter_ex(depsgraph, scene, ob); +} + +void ED_object_particle_edit_mode_exit_ex(Scene *scene, Object *ob) +{ + ob->mode &= ~OB_MODE_PARTICLE_EDIT; + toggle_particle_cursor(scene, false); + free_all_psys_edit(ob); + + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); +} + +void ED_object_particle_edit_mode_exit(bContext *C) +{ + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + ED_object_particle_edit_mode_exit_ex(scene, ob); +} + static int particle_edit_toggle_exec(bContext *C, wmOperator *op) { struct wmMsgBus *mbus = CTX_wm_message_bus(C); - Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_PARTICLE_EDIT; @@ -5284,37 +5334,13 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op) } if (!is_mode_set) { - PTCacheEdit *edit; - - ob->mode |= mode_flag; - - edit = PE_create_current(depsgraph, scene, ob); - - /* Mesh may have changed since last entering editmode. - * note, this may have run before if the edit data was just created, - * so could avoid this and speed up a little. */ - if (edit && edit->psys) { - /* Make sure pointer to the evaluated modifier data is up to date, - * with possible changes applied when object was outside of the - * edit mode. */ - Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); - edit->psmd_eval = (ParticleSystemModifierData *)BKE_modifiers_findby_name( - object_eval, edit->psmd->modifier.name); - recalc_emitter_field(depsgraph, ob, edit->psys); - } - - toggle_particle_cursor(C, 1); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_PARTICLE, NULL); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + ED_object_particle_edit_mode_enter_ex(depsgraph, scene, ob); } else { - ob->mode &= ~mode_flag; - toggle_particle_cursor(C, 0); - free_all_psys_edit(ob); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); + ED_object_particle_edit_mode_exit_ex(scene, ob); } - DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); - WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode); WM_toolsystem_update_from_context_view3d(C); diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 6ad4d1e650a..08af3bdd16c 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -781,9 +781,8 @@ bool get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy) /************************ cursor drawing *******************************/ -static void toggle_paint_cursor(bContext *C, int enable) +static void toggle_paint_cursor(Scene *scene, bool enable) { - Scene *scene = CTX_data_scene(C); ToolSettings *settings = scene->toolsettings; Paint *p = &settings->imapaint.paint; @@ -1117,6 +1116,100 @@ void PAINT_OT_sample_color(wmOperatorType *ot) /******************** texture paint toggle operator ********************/ +void ED_object_texture_paint_mode_enter_ex(Main *bmain, Scene *scene, Object *ob) +{ + bScreen *screen; + Image *ima = NULL; + ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; + + /* This has to stay here to regenerate the texture paint + * cache in case we are loading a file */ + BKE_texpaint_slots_refresh_object(scene, ob); + + BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); + + /* entering paint mode also sets image to editors */ + if (imapaint->mode == IMAGEPAINT_MODE_MATERIAL) { + /* set the current material active paint slot on image editor */ + Material *ma = BKE_object_material_get(ob, ob->actcol); + + if (ma && ma->texpaintslot) { + ima = ma->texpaintslot[ma->paint_active_slot].ima; + } + } + else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) { + ima = imapaint->canvas; + } + + if (ima) { + for (screen = bmain->screens.first; screen; screen = screen->id.next) { + ScrArea *area; + for (area = screen->areabase.first; area; area = area->next) { + SpaceLink *sl; + for (sl = area->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_IMAGE) { + SpaceImage *sima = (SpaceImage *)sl; + + if (!sima->pin) { + ED_space_image_set(bmain, sima, NULL, ima, true); + } + } + } + } + } + } + + ob->mode |= OB_MODE_TEXTURE_PAINT; + + BKE_paint_init(bmain, scene, PAINT_MODE_TEXTURE_3D, PAINT_CURSOR_TEXTURE_PAINT); + + BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint); + + if (U.glreslimit != 0) { + GPU_free_images(bmain); + } + GPU_paint_set_mipmap(bmain, 0); + + toggle_paint_cursor(scene, true); + + Mesh *me = BKE_mesh_from_object(ob); + BLI_assert(me != NULL); + DEG_id_tag_update(&me->id, ID_RECALC_COPY_ON_WRITE); + WM_main_add_notifier(NC_SCENE | ND_MODE, scene); +} + +void ED_object_texture_paint_mode_enter(bContext *C) +{ + Main *bmain = CTX_data_main(C); + Object *ob = CTX_data_active_object(C); + Scene *scene = CTX_data_scene(C); + ED_object_texture_paint_mode_enter_ex(bmain, scene, ob); +} + +void ED_object_texture_paint_mode_exit_ex(Main *bmain, Scene *scene, Object *ob) +{ + ob->mode &= ~OB_MODE_TEXTURE_PAINT; + + if (U.glreslimit != 0) { + GPU_free_images(bmain); + } + GPU_paint_set_mipmap(bmain, 1); + toggle_paint_cursor(scene, false); + + Mesh *me = BKE_mesh_from_object(ob); + BLI_assert(me != NULL); + DEG_id_tag_update(&me->id, ID_RECALC_COPY_ON_WRITE); + WM_main_add_notifier(NC_SCENE | ND_MODE, scene); +} + +void ED_object_texture_paint_mode_exit(bContext *C) +{ + Main *bmain = CTX_data_main(C); + Object *ob = CTX_data_active_object(C); + Scene *scene = CTX_data_scene(C); + ED_object_texture_paint_mode_exit_ex(bmain, scene, ob); +} + static bool texture_paint_toggle_poll(bContext *C) { Object *ob = CTX_data_active_object(C); @@ -1146,78 +1239,12 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) } if (ob->mode & mode_flag) { - ob->mode &= ~mode_flag; - - if (U.glreslimit != 0) { - GPU_free_images(bmain); - } - GPU_paint_set_mipmap(bmain, 1); - - toggle_paint_cursor(C, 0); + ED_object_texture_paint_mode_exit_ex(bmain, scene, ob); } else { - bScreen *screen; - Image *ima = NULL; - ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; - - /* This has to stay here to regenerate the texture paint - * cache in case we are loading a file */ - BKE_texpaint_slots_refresh_object(scene, ob); - - BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); - - /* entering paint mode also sets image to editors */ - if (imapaint->mode == IMAGEPAINT_MODE_MATERIAL) { - /* set the current material active paint slot on image editor */ - Material *ma = BKE_object_material_get(ob, ob->actcol); - - if (ma && ma->texpaintslot) { - ima = ma->texpaintslot[ma->paint_active_slot].ima; - } - } - else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) { - ima = imapaint->canvas; - } - - if (ima) { - for (screen = bmain->screens.first; screen; screen = screen->id.next) { - ScrArea *area; - for (area = screen->areabase.first; area; area = area->next) { - SpaceLink *sl; - for (sl = area->spacedata.first; sl; sl = sl->next) { - if (sl->spacetype == SPACE_IMAGE) { - SpaceImage *sima = (SpaceImage *)sl; - - if (!sima->pin) { - Object *obedit = CTX_data_edit_object(C); - ED_space_image_set(bmain, sima, obedit, ima, true); - } - } - } - } - } - } - - ob->mode |= mode_flag; - - BKE_paint_init(bmain, scene, PAINT_MODE_TEXTURE_3D, PAINT_CURSOR_TEXTURE_PAINT); - - BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint); - - if (U.glreslimit != 0) { - GPU_free_images(bmain); - } - GPU_paint_set_mipmap(bmain, 0); - - toggle_paint_cursor(C, 1); + ED_object_texture_paint_mode_enter_ex(bmain, scene, ob); } - Mesh *me = BKE_mesh_from_object(ob); - BLI_assert(me != NULL); - DEG_id_tag_update(&me->id, ID_RECALC_COPY_ON_WRITE); - - WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); - WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode); WM_toolsystem_update_from_context_view3d(C); |