diff options
Diffstat (limited to 'source/blender/editors/object/object_edit.c')
-rw-r--r-- | source/blender/editors/object/object_edit.c | 393 |
1 files changed, 108 insertions, 285 deletions
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index f67ecbce1d0..3e629c8d7f6 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -59,6 +59,7 @@ #include "DNA_vfont_types.h" #include "DNA_mesh_types.h" #include "DNA_lattice_types.h" +#include "DNA_workspace_types.h" #include "IMB_imbuf_types.h" @@ -67,7 +68,6 @@ #include "BKE_context.h" #include "BKE_curve.h" #include "BKE_effect.h" -#include "BKE_depsgraph.h" #include "BKE_global.h" #include "BKE_image.h" #include "BKE_lattice.h" @@ -77,6 +77,7 @@ #include "BKE_mball.h" #include "BKE_mesh.h" #include "BKE_object.h" +#include "BKE_paint.h" #include "BKE_pointcache.h" #include "BKE_property.h" #include "BKE_sca.h" @@ -85,6 +86,11 @@ #include "BKE_editlattice.h" #include "BKE_editmesh.h" #include "BKE_report.h" +#include "BKE_object.h" +#include "BKE_workspace.h" + +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" #include "ED_armature.h" #include "ED_curve.h" @@ -134,192 +140,6 @@ Object *ED_object_active_context(bContext *C) } -/* ********* clear/set restrict view *********/ -static int object_hide_view_clear_exec(bContext *C, wmOperator *op) -{ - Main *bmain = CTX_data_main(C); - ScrArea *sa = CTX_wm_area(C); - View3D *v3d = sa->spacedata.first; - Scene *scene = CTX_data_scene(C); - Base *base; - bool changed = false; - const bool select = RNA_boolean_get(op->ptr, "select"); - - /* XXX need a context loop to handle such cases */ - for (base = FIRSTBASE; base; base = base->next) { - if ((base->lay & v3d->lay) && base->object->restrictflag & OB_RESTRICT_VIEW) { - if (!(base->object->restrictflag & OB_RESTRICT_SELECT)) { - SET_FLAG_FROM_TEST(base->flag, select, SELECT); - } - base->object->flag = base->flag; - base->object->restrictflag &= ~OB_RESTRICT_VIEW; - changed = true; - } - } - if (changed) { - DAG_id_type_tag(bmain, ID_OB); - DAG_relations_tag_update(bmain); - WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - } - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_hide_view_clear(wmOperatorType *ot) -{ - - /* identifiers */ - ot->name = "Clear Restrict View"; - ot->description = "Reveal the object by setting the hide flag"; - ot->idname = "OBJECT_OT_hide_view_clear"; - - /* api callbacks */ - ot->exec = object_hide_view_clear_exec; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "select", true, "Select", ""); -} - -static int object_hide_view_set_exec(bContext *C, wmOperator *op) -{ - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - bool changed = false; - const bool unselected = RNA_boolean_get(op->ptr, "unselected"); - - CTX_DATA_BEGIN(C, Base *, base, visible_bases) - { - if (!unselected) { - if (base->flag & SELECT) { - base->flag &= ~SELECT; - base->object->flag = base->flag; - base->object->restrictflag |= OB_RESTRICT_VIEW; - changed = true; - if (base == BASACT) { - ED_base_object_activate(C, NULL); - } - } - } - else { - if (!(base->flag & SELECT)) { - base->object->restrictflag |= OB_RESTRICT_VIEW; - changed = true; - if (base == BASACT) { - ED_base_object_activate(C, NULL); - } - } - } - } - CTX_DATA_END; - - if (changed) { - DAG_id_type_tag(bmain, ID_OB); - DAG_relations_tag_update(bmain); - - WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - - } - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_hide_view_set(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Set Restrict View"; - ot->description = "Hide the object by setting the hide flag"; - ot->idname = "OBJECT_OT_hide_view_set"; - - /* api callbacks */ - ot->exec = object_hide_view_set_exec; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects"); - -} - -/* 99% same as above except no need for scene refreshing (TODO, update render preview) */ -static int object_hide_render_clear_exec(bContext *C, wmOperator *UNUSED(op)) -{ - bool changed = false; - - /* XXX need a context loop to handle such cases */ - CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) - { - if (ob->restrictflag & OB_RESTRICT_RENDER) { - ob->restrictflag &= ~OB_RESTRICT_RENDER; - changed = true; - } - } - CTX_DATA_END; - - if (changed) - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL); - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_hide_render_clear(wmOperatorType *ot) -{ - - /* identifiers */ - ot->name = "Clear Restrict Render"; - ot->description = "Reveal the render object by setting the hide render flag"; - ot->idname = "OBJECT_OT_hide_render_clear"; - - /* api callbacks */ - ot->exec = object_hide_render_clear_exec; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -static int object_hide_render_set_exec(bContext *C, wmOperator *op) -{ - const bool unselected = RNA_boolean_get(op->ptr, "unselected"); - - CTX_DATA_BEGIN(C, Base *, base, visible_bases) - { - if (!unselected) { - if (base->flag & SELECT) { - base->object->restrictflag |= OB_RESTRICT_RENDER; - } - } - else { - if (!(base->flag & SELECT)) { - base->object->restrictflag |= OB_RESTRICT_RENDER; - } - } - } - CTX_DATA_END; - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL); - return OPERATOR_FINISHED; -} - -void OBJECT_OT_hide_render_set(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Set Restrict Render"; - ot->description = "Hide the render object by setting the hide render flag"; - ot->idname = "OBJECT_OT_hide_render_set"; - - /* api callbacks */ - ot->exec = object_hide_render_set_exec; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects"); -} - /* ******************* toggle editmode operator ***************** */ static bool mesh_needs_keyindex(const Mesh *me) @@ -390,7 +210,7 @@ static bool ED_object_editmode_load_ex(Main *bmain, Object *obedit, const bool f * to inform dependency graph about this. But is it really the * best place to do this? */ - DAG_relations_tag_update(bmain); + DEG_relations_tag_update(bmain); } else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { const Curve *cu = obedit->data; @@ -448,7 +268,7 @@ bool ED_object_editmode_load(Object *obedit) * - Only in exceptional cases should #EM_DO_UNDO NOT be in the flag. * - If #EM_FREEDATA isn't in the flag, use ED_object_editmode_load directly. */ -void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int flag) +void ED_object_editmode_exit_ex(bContext *C, WorkSpace *workspace, Scene *scene, Object *obedit, int flag) { BLI_assert(C || !(flag & EM_DO_UNDO)); const bool freedata = (flag & EM_FREEDATA) != 0; @@ -458,9 +278,7 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f if (ED_object_editmode_load_ex(G.main, obedit, freedata) == false) { /* in rare cases (background mode) its possible active object * is flagged for editmode, without 'obedit' being set [#35489] */ - if (UNLIKELY(scene->basact && (scene->basact->object->mode & OB_MODE_EDIT))) { - scene->basact->object->mode &= ~OB_MODE_EDIT; - } + workspace->object_mode &= ~OB_MODE_EDIT; if (flag & EM_WAITCURSOR) waitcursor(0); return; } @@ -470,9 +288,6 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f ListBase pidlist; PTCacheID *pid; - /* for example; displist make is different in editmode */ - scene->obedit = NULL; // XXX for context - /* flag object caches as outdated */ BKE_ptcache_ids_from_object(&pidlist, obedit, scene, 0); for (pid = pidlist.first; pid; pid = pid->next) { @@ -484,7 +299,9 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_OUTDATED); /* also flush ob recalc, doesn't take much overhead, but used for particles */ - DAG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA); + DEG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA); + + workspace->object_mode &= ~OB_MODE_EDIT; if (flag & EM_DO_UNDO) ED_undo_push(C, "Editmode"); @@ -495,48 +312,44 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f else { WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene); } - - obedit->mode &= ~OB_MODE_EDIT; } + ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, obedit); + if (flag & EM_WAITCURSOR) waitcursor(0); + + /* This way we ensure scene's obedit is copied into all CoW scenes. */ + DEG_id_tag_update(&scene->id, 0); } void ED_object_editmode_exit(bContext *C, int flag) { + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); Object *obedit = CTX_data_edit_object(C); - ED_object_editmode_exit_ex(C, scene, obedit, flag); + ED_object_editmode_exit_ex(C, workspace, scene, obedit, flag); } void ED_object_editmode_enter(bContext *C, int flag) { + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); - Base *base = NULL; + ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob; - ScrArea *sa = CTX_wm_area(C); - View3D *v3d = NULL; bool ok = false; if (ID_IS_LINKED(scene)) return; - if (sa && sa->spacetype == SPACE_VIEW3D) - v3d = sa->spacedata.first; - if ((flag & EM_IGNORE_LAYER) == 0) { - base = CTX_data_active_base(C); /* active layer checked here for view3d */ + ob = CTX_data_active_object(C); /* active layer checked here for view3d */ - if (base == NULL) return; - else if (v3d && (base->lay & v3d->lay) == 0) return; - else if (!v3d && (base->lay & scene->lay) == 0) return; + if (ob == NULL) return; } else { - base = scene->basact; + ob = view_layer->basact->object; } - if (ELEM(NULL, base, base->object, base->object->data)) return; - - ob = base->object; + if (ELEM(NULL, ob, ob->data)) return; /* this checks actual object->data, for cases when other scenes have it in editmode context */ if (BKE_object_is_in_editmode(ob)) @@ -549,20 +362,18 @@ void ED_object_editmode_enter(bContext *C, int flag) if (flag & EM_WAITCURSOR) waitcursor(1); - ob->restore_mode = ob->mode; + workspace->object_mode_restore = workspace->object_mode; /* note, when switching scenes the object can have editmode data but * not be scene->obedit: bug 22954, this avoids calling self eternally */ - if ((ob->restore_mode & OB_MODE_EDIT) == 0) - ED_object_mode_toggle(C, ob->mode); + if ((workspace->object_mode_restore & OB_MODE_EDIT) == 0) + ED_object_mode_toggle(C, workspace->object_mode); - ob->mode = OB_MODE_EDIT; + workspace->object_mode = OB_MODE_EDIT; if (ob->type == OB_MESH) { BMEditMesh *em; ok = 1; - scene->obedit = ob; /* context sees this */ - const bool use_key_index = mesh_needs_keyindex(ob->data); EDBM_mesh_make(ob, scene->toolsettings->selectmode, use_key_index); @@ -592,29 +403,25 @@ void ED_object_editmode_enter(bContext *C, int flag) return; } ok = 1; - scene->obedit = ob; ED_armature_to_edit(arm); /* to ensure all goes in restposition and without striding */ - DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */ + DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */ WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_ARMATURE, scene); } else if (ob->type == OB_FONT) { - scene->obedit = ob; /* XXX for context */ ok = 1; ED_curve_editfont_make(ob); WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_TEXT, scene); } else if (ob->type == OB_MBALL) { - scene->obedit = ob; /* XXX for context */ ok = 1; ED_mball_editmball_make(ob); WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MBALL, scene); } else if (ob->type == OB_LATTICE) { - scene->obedit = ob; /* XXX for context */ ok = 1; BKE_editlattice_make(ob); @@ -622,34 +429,36 @@ void ED_object_editmode_enter(bContext *C, int flag) } else if (ob->type == OB_SURF || ob->type == OB_CURVE) { ok = 1; - scene->obedit = ob; /* XXX for context */ ED_curve_editnurb_make(ob); WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_CURVE, scene); } if (ok) { - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + /* This way we ensure scene's obedit is copied into all CoW scenes. */ + DEG_id_tag_update(&scene->id, 0); } else { - scene->obedit = NULL; /* XXX for context */ - ob->mode &= ~OB_MODE_EDIT; + workspace->object_mode &= ~OB_MODE_EDIT; WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene); } + ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, ob); + if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode"); if (flag & EM_WAITCURSOR) waitcursor(0); } static int editmode_toggle_exec(bContext *C, wmOperator *op) { + WorkSpace *workspace = CTX_wm_workspace(C); const int mode_flag = OB_MODE_EDIT; const bool is_mode_set = (CTX_data_edit_object(C) != NULL); Scene *scene = CTX_data_scene(C); if (!is_mode_set) { - Object *ob = CTX_data_active_object(C); - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } @@ -672,9 +481,12 @@ static int editmode_toggle_poll(bContext *C) if (ELEM(NULL, ob, ob->data) || ID_IS_LINKED(ob->data)) return 0; + const WorkSpace *workspace = CTX_wm_workspace(C); + /* if hidden but in edit mode, we still display */ - if ((ob->restrictflag & OB_RESTRICT_VIEW) && !(ob->mode & OB_MODE_EDIT)) + if ((ob->restrictflag & OB_RESTRICT_VIEW) && !(workspace->object_mode & OB_MODE_EDIT)) { return 0; + } return OB_TYPE_SUPPORT_EDITMODE(ob->type); } @@ -699,13 +511,15 @@ void OBJECT_OT_editmode_toggle(wmOperatorType *ot) static int posemode_exec(bContext *C, wmOperator *op) { + wmWindowManager *wm = CTX_wm_manager(C); + WorkSpace *workspace = CTX_wm_workspace(C); Base *base = CTX_data_active_base(C); Object *ob = base->object; const int mode_flag = OB_MODE_POSE; - const bool is_mode_set = (ob->mode & mode_flag) != 0; - + const bool is_mode_set = (workspace->object_mode & mode_flag) != 0; + if (!is_mode_set) { - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } @@ -719,7 +533,9 @@ static int posemode_exec(bContext *C, wmOperator *op) ED_armature_exit_posemode(C, base); else ED_armature_enter_posemode(C, base); - + + ED_workspace_object_mode_sync_from_object(wm, workspace, ob); + return OPERATOR_FINISHED; } @@ -741,7 +557,7 @@ void OBJECT_OT_posemode_toggle(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob) +static void copymenu_properties(ViewLayer *view_layer, Object *ob) { //XXX no longer used - to be removed - replaced by game_properties_copy_exec bProperty *prop; @@ -774,8 +590,8 @@ static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob) nr = pupmenu(str); if (nr == 1 || nr == 2) { - for (base = FIRSTBASE; base; base = base->next) { - if ((base != BASACT) && (TESTBASELIB(v3d, base))) { + for (base = FIRSTBASE(view_layer); base; base = base->next) { + if ((base != BASACT(view_layer)) && (TESTBASELIB(base))) { if (nr == 1) { /* replace */ BKE_bproperty_copy_list(&base->object->prop, &ob->prop); } @@ -791,8 +607,8 @@ static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob) prop = BLI_findlink(&ob->prop, nr - 4); /* account for first 3 menu items & menu index starting at 1*/ if (prop) { - for (base = FIRSTBASE; base; base = base->next) { - if ((base != BASACT) && (TESTBASELIB(v3d, base))) { + for (base = FIRSTBASE(view_layer); base; base = base->next) { + if ((base != BASACT(view_layer)) && (TESTBASELIB(base))) { BKE_bproperty_object_set(base->object, prop); } } @@ -802,14 +618,14 @@ static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob) } -static void copymenu_logicbricks(Scene *scene, View3D *v3d, Object *ob) +static void copymenu_logicbricks(ViewLayer *view_layer, Object *ob) { //XXX no longer used - to be removed - replaced by logicbricks_copy_exec Base *base; - for (base = FIRSTBASE; base; base = base->next) { + for (base = FIRSTBASE(view_layer); base; base = base->next) { if (base->object != ob) { - if (TESTBASELIB(v3d, base)) { + if (TESTBASELIB(base)) { /* first: free all logic */ free_sensors(&base->object->sensors); @@ -888,7 +704,7 @@ static void copy_texture_space(Object *to, Object *ob) } /* UNUSED, keep in case we want to copy functionality for use elsewhere */ -static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) +static void copy_attr(Main *bmain, Scene *scene, ViewLayer *view_layer, short event) { Object *ob; Base *base; @@ -898,18 +714,18 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) if (ID_IS_LINKED(scene)) return; - if (!(ob = OBACT)) return; + if (!(ob = OBACT(view_layer))) return; - if (scene->obedit) { // XXX get from context + if (BKE_object_is_in_editmode(ob)) { /* obedit_copymenu(); */ return; } if (event == 9) { - copymenu_properties(scene, v3d, ob); + copymenu_properties(view_layer, ob); return; } else if (event == 10) { - copymenu_logicbricks(scene, v3d, ob); + copymenu_logicbricks(view_layer, ob); return; } else if (event == 24) { @@ -918,10 +734,10 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) return; } - for (base = FIRSTBASE; base; base = base->next) { - if (base != BASACT) { - if (TESTBASELIB(v3d, base)) { - DAG_id_tag_update(&base->object->id, OB_RECALC_DATA); + for (base = FIRSTBASE(view_layer); base; base = base->next) { + if (base != BASACT(view_layer)) { + if (TESTBASELIB(base)) { + DEG_id_tag_update(&base->object->id, OB_RECALC_DATA); if (event == 1) { /* loc */ copy_v3_v3(base->object->loc, ob->loc); @@ -1024,7 +840,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family)); - DAG_id_tag_update(&base->object->id, OB_RECALC_DATA); + DEG_id_tag_update(&base->object->id, OB_RECALC_DATA); } } else if (event == 19) { /* bevel settings */ @@ -1040,7 +856,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) cu1->ext1 = cu->ext1; cu1->ext2 = cu->ext2; - DAG_id_tag_update(&base->object->id, OB_RECALC_DATA); + DEG_id_tag_update(&base->object->id, OB_RECALC_DATA); } } else if (event == 25) { /* curve resolution */ @@ -1059,7 +875,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) nu = nu->next; } - DAG_id_tag_update(&base->object->id, OB_RECALC_DATA); + DEG_id_tag_update(&base->object->id, OB_RECALC_DATA); } } else if (event == 21) { @@ -1075,7 +891,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) } modifier_copyData(md, tmd); - DAG_id_tag_update(&base->object->id, OB_RECALC_DATA); + DEG_id_tag_update(&base->object->id, OB_RECALC_DATA); } } } @@ -1136,18 +952,18 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) } if (do_depgraph_update) - DAG_relations_tag_update(bmain); + DEG_relations_tag_update(bmain); } -static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, View3D *v3d) +static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, ViewLayer *view_layer, Object *obedit) { Object *ob; short event; char str[512]; - if (!(ob = OBACT)) return; + if (!(ob = OBACT(view_layer))) return; - if (scene->obedit) { /* XXX get from context */ + if (obedit) { /* if (ob->type == OB_MESH) */ /* XXX mesh_copy_menu(); */ return; @@ -1193,12 +1009,12 @@ static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, View3D * event = pupmenu(str); if (event <= 0) return; - copy_attr(bmain, scene, v3d, event); + copy_attr(bmain, scene, view_layer, event); } /* ******************* force field toggle operator ***************** */ -void ED_object_check_force_modifiers(Main *bmain, Scene *scene, Object *object) +void ED_object_check_force_modifiers(Main *bmain, Scene *scene, Object *object, eObjectMode object_mode) { PartDeflect *pd = object->pd; ModifierData *md = modifiers_findByType(object, eModifierType_Surface); @@ -1207,7 +1023,7 @@ void ED_object_check_force_modifiers(Main *bmain, Scene *scene, Object *object) if (!md) { if (pd && (pd->shape == PFIELD_SHAPE_SURFACE) && !ELEM(pd->forcefield, 0, PFIELD_GUIDE, PFIELD_TEXTURE)) { if (ELEM(object->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVE)) { - ED_object_modifier_add(NULL, bmain, scene, object, NULL, eModifierType_Surface); + ED_object_modifier_add(NULL, bmain, scene, object, object_mode, NULL, eModifierType_Surface); } } } @@ -1228,8 +1044,9 @@ static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op)) ob->pd->forcefield = PFIELD_FORCE; else ob->pd->forcefield = 0; - - ED_object_check_force_modifiers(CTX_data_main(C), CTX_data_scene(C), ob); + + const WorkSpace *workspace = CTX_wm_workspace(C); + ED_object_check_force_modifiers(CTX_data_main(C), CTX_data_scene(C), ob, workspace->object_mode); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1262,6 +1079,9 @@ void OBJECT_OT_forcefield_toggle(wmOperatorType *ot) */ void ED_objects_recalculate_paths(bContext *C, Scene *scene) { + struct Main *bmain = CTX_data_main(C); + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); ListBase targets = {NULL, NULL}; /* loop over objects in scene */ @@ -1274,7 +1094,7 @@ void ED_objects_recalculate_paths(bContext *C, Scene *scene) CTX_DATA_END; /* recalculate paths, then free */ - animviz_calc_motionpaths(scene, &targets); + animviz_calc_motionpaths(&eval_ctx, bmain, scene, &targets); BLI_freelistN(&targets); } @@ -1495,7 +1315,8 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) if (ob->type == OB_MESH) { BKE_mesh_smooth_flag_set(ob, !clear); - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); done = true; @@ -1508,7 +1329,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) else nu->flag &= ~ME_SMOOTH; } - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); done = true; @@ -1559,7 +1380,7 @@ void OBJECT_OT_shade_smooth(wmOperatorType *ot) /* ********************** */ -static void UNUSED_FUNCTION(image_aspect) (Scene *scene, View3D *v3d) +static void UNUSED_FUNCTION(image_aspect) (Scene *scene, ViewLayer *view_layer, Object *obedit) { /* all selected objects with an image map: scale in image aspect */ Base *base; @@ -1569,11 +1390,11 @@ static void UNUSED_FUNCTION(image_aspect) (Scene *scene, View3D *v3d) float x, y, space; int a, b, done; - if (scene->obedit) return; // XXX get from context + if (obedit) return; if (ID_IS_LINKED(scene)) return; - for (base = FIRSTBASE; base; base = base->next) { - if (TESTBASELIB(v3d, base)) { + for (base = FIRSTBASE(view_layer); base; base = base->next) { + if (TESTBASELIB(base)) { ob = base->object; done = false; @@ -1606,7 +1427,7 @@ static void UNUSED_FUNCTION(image_aspect) (Scene *scene, View3D *v3d) else ob->size[1] = ob->size[0] * y / x; done = true; - DAG_id_tag_update(&ob->id, OB_RECALC_OB); + DEG_id_tag_update(&ob->id, OB_RECALC_OB); BKE_image_release_ibuf(tex->ima, ibuf, NULL); } @@ -1686,10 +1507,11 @@ static int object_mode_set_poll(bContext *C) static int object_mode_set_exec(bContext *C, wmOperator *op) { + WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); bGPdata *gpd = CTX_data_gpencil_data(C); eObjectMode mode = RNA_enum_get(op->ptr, "mode"); - eObjectMode restore_mode = (ob) ? ob->mode : OB_MODE_OBJECT; + eObjectMode restore_mode = workspace->object_mode; const bool toggle = RNA_boolean_get(op->ptr, "toggle"); if (gpd) { @@ -1713,28 +1535,31 @@ static int object_mode_set_exec(bContext *C, wmOperator *op) if (!ob || !ED_object_mode_compat_test(ob, mode)) return OPERATOR_PASS_THROUGH; - if (ob->mode != mode) { + if (workspace->object_mode != mode) { /* we should be able to remove this call, each operator calls */ - ED_object_mode_compat_set(C, ob, mode, op->reports); + ED_object_mode_compat_set(C, workspace, mode, op->reports); } /* Exit current mode if it's not the mode we're setting */ - if (mode != OB_MODE_OBJECT && (ob->mode != mode || toggle)) { + if (mode != OB_MODE_OBJECT && (workspace->object_mode != mode || toggle)) { /* Enter new mode */ ED_object_mode_toggle(C, mode); } if (toggle) { /* Special case for Object mode! */ - if (mode == OB_MODE_OBJECT && restore_mode == OB_MODE_OBJECT && ob->restore_mode != OB_MODE_OBJECT) { - ED_object_mode_toggle(C, ob->restore_mode); + if ((mode == OB_MODE_OBJECT) && + (restore_mode == OB_MODE_OBJECT) && + (workspace->object_mode_restore != OB_MODE_OBJECT)) + { + ED_object_mode_toggle(C, workspace->object_mode_restore); } - else if (ob->mode == mode) { + else if (workspace->object_mode == mode) { /* For toggling, store old mode so we know what to go back to */ - ob->restore_mode = restore_mode; + workspace->object_mode_restore = restore_mode; } - else if (ob->restore_mode != OB_MODE_OBJECT && ob->restore_mode != mode) { - ED_object_mode_toggle(C, ob->restore_mode); + else if (!ELEM(workspace->object_mode_restore, mode, OB_MODE_OBJECT)) { + ED_object_mode_toggle(C, workspace->object_mode_restore); } } @@ -2153,8 +1978,6 @@ void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -/* generic utility function */ - bool ED_object_editmode_calc_active_center(Object *obedit, const bool select_only, float r_center[3]) { switch (obedit->type) { |