From 5861e1fa28140d6dfe73f1542c0e87c728b028ba Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 16 Jan 2019 11:46:55 +1100 Subject: Object: avoid calling operators in ED_editors_init Don't call operator when entering sculpt modes. --- source/blender/editors/util/ed_util.c | 71 +++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 24 deletions(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 5cc1f15cb2e..abc4f20ac71 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -90,6 +90,7 @@ void ED_editors_init(bContext *C) { + struct Depsgraph *depsgraph = CTX_data_depsgraph(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); wmWindowManager *wm = CTX_wm_manager(C); @@ -111,43 +112,65 @@ void ED_editors_init(bContext *C) if (obact != NULL) { for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { int mode = ob->mode; - if (mode == OB_MODE_OBJECT) { - /* pass */ + continue; + } + else if (BKE_object_has_mode_data(ob, mode)) { + continue; } - else if (!BKE_object_has_mode_data(ob, mode)) { + else if (ob->type == OB_GPENCIL) { /* For multi-edit mode we may already have mode data. - * (grease pencil does not need it) - */ - if (ob->type != OB_GPENCIL) { - ID *data = ob->data; - ob->mode = OB_MODE_OBJECT; - if ((ob->type == obact->type) && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data))) { - if (mode == OB_MODE_EDIT) { - ED_object_editmode_enter_ex(bmain, scene, ob, 0); + * (grease pencil does not need it) */ + continue; + } + + ID *ob_data = ob->data; + ob->mode = OB_MODE_OBJECT; + if ((ob->type == obact->type) && + !ID_IS_LINKED(ob) && + !(ob_data && ID_IS_LINKED(ob_data))) + { + if (mode == OB_MODE_EDIT) { + ED_object_editmode_enter_ex(bmain, scene, ob, 0); + } + else if (mode == OB_MODE_POSE) { + ED_object_posemode_enter_ex(bmain, ob); + } + else if (mode & OB_MODE_ALL_SCULPT) { + if (obact == ob) { + if (mode == OB_MODE_SCULPT) { + ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, reports); + } + else if (mode == OB_MODE_VERTEX_PAINT) { + ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); } - else if (mode == OB_MODE_POSE) { - ED_object_posemode_enter_ex(bmain, ob); + else if (mode == OB_MODE_WEIGHT_PAINT) { + ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); } else { - if (obact == ob) { - ED_object_mode_toggle(C, mode); - } - else { - /* Create data for non-active objects which need it for - * mode-switching but don't yet support multi-editing. */ - if (mode & OB_MODE_ALL_SCULPT) { - ob->mode = mode; - BKE_object_sculpt_data_create(ob); - } - } + BLI_assert(0); } } + else { + /* Create data for non-active objects which need it for + * mode-switching but don't yet support multi-editing. */ + if (mode & OB_MODE_ALL_SCULPT) { + ob->mode = mode; + BKE_object_sculpt_data_create(ob); + } + } + } + else { + /* TODO(campbell): avoid operator calls. */ + if (obact == ob) { + ED_object_mode_toggle(C, mode); + } } } } } + /* image editor paint mode */ if (scene) { ED_space_image_paint_update(bmain, wm, scene); -- cgit v1.2.3