diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-04-05 19:20:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-04-05 19:21:14 +0300 |
commit | 1c24c04e6023f2d2a328dfcdc9f86cd381d029a3 (patch) | |
tree | 7a5af59ce078cb66fb17ec33cf111ffc8d5fb328 /source/blender/editors/object/object_modifier.c | |
parent | 57329304b061efe756e3a4ce1b828e9a7c7f7030 (diff) |
Remove workspace object mode, reverts changes w/ 2.8
This caused too many problems syncing object modes
with multiple objects/windows/workspaces, see: D3130 for details.
Diffstat (limited to 'source/blender/editors/object/object_modifier.c')
-rw-r--r-- | source/blender/editors/object/object_modifier.c | 142 |
1 files changed, 57 insertions, 85 deletions
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 9d1792e9f16..04243660440 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -95,10 +95,7 @@ static void modifier_skin_customdata_delete(struct Object *ob); /******************************** API ****************************/ -ModifierData *ED_object_modifier_add( - ReportList *reports, - Main *bmain, Scene *scene, - Object *ob, eObjectMode object_mode, const char *name, int type) +ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *scene, Object *ob, const char *name, int type) { ModifierData *md = NULL, *new_md = NULL; const ModifierTypeInfo *mti = modifierType_getInfo(type); @@ -165,7 +162,7 @@ ModifierData *ED_object_modifier_add( /* set totlvl from existing MDISPS layer if object already had it */ multiresModifier_set_levels_from_disps((MultiresModifierData *)new_md, ob); - if (object_mode & OB_MODE_SCULPT) { + if (ob->mode & OB_MODE_SCULPT) { /* ensure that grid paint mask layer is created */ BKE_sculpt_mask_layers_ensure(ob, (MultiresModifierData *)new_md); } @@ -205,11 +202,9 @@ static bool object_has_modifier(const Object *ob, const ModifierData *exclude, * If the callback ever returns true, iteration will stop and the * function value will be true. Otherwise the function returns false. */ -bool ED_object_iter_other( - const EvaluationContext *eval_ctx, - Main *bmain, Object *orig_ob, const bool include_orig, - bool (*callback)(const EvaluationContext *eval_ctx, Object *ob, void *callback_data), - void *callback_data) +bool ED_object_iter_other(Main *bmain, Object *orig_ob, const bool include_orig, + bool (*callback)(Object *ob, void *callback_data), + void *callback_data) { ID *ob_data_id = orig_ob->data; int users = ob_data_id->us; @@ -228,7 +223,7 @@ bool ED_object_iter_other( if (((ob != orig_ob) || include_orig) && (ob->data == orig_ob->data)) { - if (callback(eval_ctx, ob, callback_data)) + if (callback(ob, callback_data)) return true; totfound++; @@ -236,15 +231,13 @@ bool ED_object_iter_other( } } else if (include_orig) { - return callback(eval_ctx, orig_ob, callback_data); + return callback(orig_ob, callback_data); } return false; } -static bool object_has_modifier_cb( - const EvaluationContext *UNUSED(eval_ctx), - Object *ob, void *data) +static bool object_has_modifier_cb(Object *ob, void *data) { ModifierType type = *((ModifierType *)data); @@ -254,16 +247,14 @@ static bool object_has_modifier_cb( /* Use with ED_object_iter_other(). Sets the total number of levels * for any multires modifiers on the object to the int pointed to by * callback_data. */ -bool ED_object_multires_update_totlevels_cb( - const struct EvaluationContext *eval_ctx, - Object *ob, void *totlevel_v) +bool ED_object_multires_update_totlevels_cb(Object *ob, void *totlevel_v) { ModifierData *md; int totlevel = *((char *)totlevel_v); for (md = ob->modifiers.first; md; md = md->next) { if (md->type == eModifierType_Multires) { - multires_set_tot_level((MultiresModifierData *)md, totlevel, eval_ctx->object_mode); + multires_set_tot_level(ob, (MultiresModifierData *)md, totlevel); DEG_id_tag_update(&ob->id, OB_RECALC_DATA); } } @@ -276,7 +267,7 @@ static bool object_modifier_safe_to_delete(Main *bmain, Object *ob, ModifierType type) { return (!object_has_modifier(ob, exclude, type) && - !ED_object_iter_other(NULL, bmain, ob, false, + !ED_object_iter_other(bmain, ob, false, object_has_modifier_cb, &type)); } @@ -325,13 +316,11 @@ static bool object_modifier_remove(Main *bmain, Object *ob, ModifierData *md, modifier_skin_customdata_delete(ob); } -#if 0 /* not needed now modes are in workspace */ if (ELEM(md->type, eModifierType_Softbody, eModifierType_Cloth) && BLI_listbase_is_empty(&ob->particlesystem)) { ob->mode &= ~OB_MODE_PARTICLE_EDIT; } -#endif DEG_relations_tag_update(bmain); @@ -424,9 +413,7 @@ int ED_object_modifier_move_down(ReportList *reports, Object *ob, ModifierData * return 1; } -int ED_object_modifier_convert( - ReportList *UNUSED(reports), Main *bmain, Scene *scene, - ViewLayer *view_layer, Object *UNUSED(ob), eObjectMode object_mode, ModifierData *md) +int ED_object_modifier_convert(ReportList *UNUSED(reports), Main *bmain, Scene *scene, ViewLayer *view_layer, Object *ob, ModifierData *md) { Object *obn; ParticleSystem *psys; @@ -440,7 +427,7 @@ int ED_object_modifier_convert( int totpart = 0, totchild = 0; if (md->type != eModifierType_ParticleSystem) return 0; - if (object_mode & OB_MODE_PARTICLE_EDIT) return 0; + if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) return 0; psys = ((ParticleSystemModifierData *)md)->psys; part = psys->part; @@ -535,12 +522,9 @@ int ED_object_modifier_convert( return 1; } -static int modifier_apply_shape(ReportList *reports, const bContext *C, Scene *scene, Object *ob, ModifierData *md) +static int modifier_apply_shape(ReportList *reports, const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ModifierData *md) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); md->scene = scene; @@ -571,7 +555,7 @@ static int modifier_apply_shape(ReportList *reports, const bContext *C, Scene *s return 0; } - dm = mesh_create_derived_for_modifier(&eval_ctx, scene, ob, md, 0); + dm = mesh_create_derived_for_modifier(eval_ctx, scene, ob, md, 0); if (!dm) { BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply"); return 0; @@ -598,12 +582,9 @@ static int modifier_apply_shape(ReportList *reports, const bContext *C, Scene *s return 1; } -static int modifier_apply_obdata(ReportList *reports, const bContext *C, Scene *scene, Object *ob, ModifierData *md) +static int modifier_apply_obdata(ReportList *reports, const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ModifierData *md) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); md->scene = scene; @@ -627,13 +608,13 @@ static int modifier_apply_obdata(ReportList *reports, const bContext *C, Scene * multires_force_update(ob); if (mmd && mmd->totlvl && mti->type == eModifierTypeType_OnlyDeform) { - if (!multiresModifier_reshapeFromDeformMod(&eval_ctx, scene, mmd, ob, md)) { + if (!multiresModifier_reshapeFromDeformMod(eval_ctx, scene, mmd, ob, md)) { BKE_report(reports, RPT_ERROR, "Multires modifier returned error, skipping apply"); return 0; } } else { - dm = mesh_create_derived_for_modifier(&eval_ctx, scene, ob, md, 1); + dm = mesh_create_derived_for_modifier(eval_ctx, scene, ob, md, 1); if (!dm) { BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply"); return 0; @@ -659,7 +640,7 @@ static int modifier_apply_obdata(ReportList *reports, const bContext *C, Scene * BKE_report(reports, RPT_INFO, "Applied modifier only changed CV points, not tessellated/bevel vertices"); vertexCos = BKE_curve_nurbs_vertexCos_get(&cu->nurb, &numVerts); - mti->deformVerts(md, &eval_ctx, ob, NULL, vertexCos, numVerts, 0); + mti->deformVerts(md, eval_ctx, ob, NULL, vertexCos, numVerts, 0); BK_curve_nurbs_vertexCos_apply(&cu->nurb, vertexCos); MEM_freeN(vertexCos); @@ -681,16 +662,17 @@ static int modifier_apply_obdata(ReportList *reports, const bContext *C, Scene * if (psys->part->type != PART_HAIR) continue; - psys_apply_hair_lattice(&eval_ctx, scene, ob, psys); + psys_apply_hair_lattice(eval_ctx, scene, ob, psys); } } return 1; } -int ED_object_modifier_apply(ReportList *reports, const bContext *C, Scene *scene, Object *ob, ModifierData *md, int mode) +int ED_object_modifier_apply( + ReportList *reports, const EvaluationContext *eval_ctx, + Scene *scene, Object *ob, ModifierData *md, int mode) { - const WorkSpace *workspace = CTX_wm_workspace(C); int prev_mode; if (BKE_object_is_in_editmode(ob)) { @@ -701,7 +683,7 @@ int ED_object_modifier_apply(ReportList *reports, const bContext *C, Scene *scen BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied to multi-user data"); return 0; } - else if ((workspace->object_mode & OB_MODE_SCULPT) && + else if ((ob->mode & OB_MODE_SCULPT) && (find_multires_modifier_before(scene, md)) && (modifier_isSameTopology(md) == false)) { @@ -717,13 +699,13 @@ int ED_object_modifier_apply(ReportList *reports, const bContext *C, Scene *scen md->mode |= eModifierMode_Realtime; if (mode == MODIFIER_APPLY_SHAPE) { - if (!modifier_apply_shape(reports, C, scene, ob, md)) { + if (!modifier_apply_shape(reports, eval_ctx, scene, ob, md)) { md->mode = prev_mode; return 0; } } else { - if (!modifier_apply_obdata(reports, C, scene, ob, md)) { + if (!modifier_apply_obdata(reports, eval_ctx, scene, ob, md)) { md->mode = prev_mode; return 0; } @@ -753,13 +735,12 @@ int ED_object_modifier_copy(ReportList *UNUSED(reports), Object *ob, ModifierDat static int modifier_add_exec(bContext *C, wmOperator *op) { - const WorkSpace *workspace = CTX_wm_workspace(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); int type = RNA_enum_get(op->ptr, "type"); - if (!ED_object_modifier_add(op->reports, bmain, scene, ob, workspace->object_mode, NULL, type)) + if (!ED_object_modifier_add(op->reports, bmain, scene, ob, NULL, type)) return OPERATOR_CANCELLED; WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -896,12 +877,11 @@ ModifierData *edit_modifier_property_get(wmOperator *op, Object *ob, int type) static int modifier_remove_exec(bContext *C, wmOperator *op) { - const WorkSpace *workspace = CTX_wm_workspace(C); Main *bmain = CTX_data_main(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = ED_object_active_context(C); ModifierData *md = edit_modifier_property_get(op, ob, 0); - int mode_orig = workspace->object_mode; + int mode_orig = ob->mode; if (!md || !ED_object_modifier_remove(op->reports, bmain, ob, md)) return OPERATOR_CANCELLED; @@ -910,8 +890,8 @@ static int modifier_remove_exec(bContext *C, wmOperator *op) /* if cloth/softbody was removed, particle mode could be cleared */ if (mode_orig & OB_MODE_PARTICLE_EDIT) { - if ((workspace->object_mode & OB_MODE_PARTICLE_EDIT) == 0) { - if (view_layer->basact && view_layer->basact->object == ob) { + if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0) { + if (ob == OBACT(view_layer)) { WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); } } @@ -1029,7 +1009,10 @@ static int modifier_apply_exec(bContext *C, wmOperator *op) ModifierData *md = edit_modifier_property_get(op, ob, 0); int apply_as = RNA_enum_get(op->ptr, "apply_as"); - if (!md || !ED_object_modifier_apply(op->reports, C, scene, ob, md, apply_as)) { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + + if (!md || !ED_object_modifier_apply(op->reports, &eval_ctx, scene, ob, md, apply_as)) { return OPERATOR_CANCELLED; } @@ -1074,16 +1057,14 @@ void OBJECT_OT_modifier_apply(wmOperatorType *ot) static int modifier_convert_exec(bContext *C, wmOperator *op) { - const WorkSpace *workspace = CTX_wm_workspace(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = ED_object_active_context(C); ModifierData *md = edit_modifier_property_get(op, ob, 0); - - if (!md || !ED_object_modifier_convert(op->reports, bmain, scene, view_layer, ob, workspace->object_mode, md)) { + + if (!md || !ED_object_modifier_convert(op->reports, bmain, scene, view_layer, ob, md)) return OPERATOR_CANCELLED; - } DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1167,13 +1148,10 @@ static int multires_higher_levels_delete_exec(bContext *C, wmOperator *op) if (!mmd) return OPERATOR_CANCELLED; + + multiresModifier_del_levels(mmd, ob, 1); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - - multiresModifier_del_levels(mmd, ob, 1, eval_ctx.object_mode); - - ED_object_iter_other(&eval_ctx, CTX_data_main(C), ob, true, + ED_object_iter_other(CTX_data_main(C), ob, true, ED_object_multires_update_totlevels_cb, &mmd->totlvl); @@ -1214,20 +1192,17 @@ static int multires_subdivide_exec(bContext *C, wmOperator *op) if (!mmd) return OPERATOR_CANCELLED; + + multiresModifier_subdivide(mmd, ob, 0, mmd->simple); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - multiresModifier_subdivide(mmd, ob, 0, mmd->simple, eval_ctx.object_mode); - - ED_object_iter_other( - &eval_ctx, CTX_data_main(C), ob, true, - ED_object_multires_update_totlevels_cb, - &mmd->totlvl); + ED_object_iter_other(CTX_data_main(C), ob, true, + ED_object_multires_update_totlevels_cb, + &mmd->totlvl); DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); - if (eval_ctx.mode & OB_MODE_SCULPT) { + if (ob->mode & OB_MODE_SCULPT) { /* ensure that grid paint mask layer is created */ BKE_sculpt_mask_layers_ensure(ob, mmd); } @@ -1264,11 +1239,8 @@ static int multires_reshape_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_active_context(C), *secondob = NULL; Scene *scene = CTX_data_scene(C); - EvaluationContext eval_ctx; MultiresModifierData *mmd = (MultiresModifierData *)edit_modifier_property_get(op, ob, eModifierType_Multires); - CTX_data_eval_ctx(C, &eval_ctx); - if (!mmd) return OPERATOR_CANCELLED; @@ -1291,6 +1263,9 @@ static int multires_reshape_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + if (!multiresModifier_reshape(&eval_ctx, scene, mmd, ob, secondob)) { BKE_report(op->reports, RPT_ERROR, "Objects do not have the same number of vertices"); return OPERATOR_CANCELLED; @@ -1441,9 +1416,8 @@ static int multires_base_apply_exec(bContext *C, wmOperator *op) if (!mmd) return OPERATOR_CANCELLED; - - const WorkSpace *workspace = CTX_wm_workspace(C); - multiresModifier_base_apply(mmd, ob, workspace->object_mode); + + multiresModifier_base_apply(mmd, ob); DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1725,10 +1699,8 @@ static void skin_armature_bone_create(Object *skin_ob, } } -static Object *modifier_skin_armature_create(const bContext *C, Scene *scene, ViewLayer *view_layer, Object *skin_ob) +static Object *modifier_skin_armature_create(const EvaluationContext *eval_ctx, Main *bmain, Scene *scene, Object *skin_ob) { - Main *bmain = CTX_data_main(C); - EvaluationContext eval_ctx; BLI_bitmap *edges_visited; DerivedMesh *deform_dm; MVert *mvert; @@ -1740,9 +1712,7 @@ static Object *modifier_skin_armature_create(const bContext *C, Scene *scene, Vi int *emap_mem; int v; - CTX_data_eval_ctx(C, &eval_ctx); - - deform_dm = mesh_get_derived_deform(&eval_ctx, scene, skin_ob, CD_MASK_BAREMESH); + deform_dm = mesh_get_derived_deform(eval_ctx, scene, skin_ob, CD_MASK_BAREMESH); mvert = deform_dm->getVertArray(deform_dm); /* add vertex weights to original mesh */ @@ -1752,7 +1722,7 @@ static Object *modifier_skin_armature_create(const bContext *C, Scene *scene, Vi NULL, me->totvert); - arm_ob = BKE_object_add(bmain, scene, view_layer, OB_ARMATURE, NULL); + arm_ob = BKE_object_add(bmain, scene, eval_ctx->view_layer, OB_ARMATURE, NULL); BKE_object_transform_copy(arm_ob, skin_ob); arm = arm_ob->data; arm->layer = 1; @@ -1811,7 +1781,6 @@ static int skin_armature_create_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = CTX_data_active_object(C), *arm_ob; Mesh *me = ob->data; ModifierData *skin_md; @@ -1822,8 +1791,11 @@ static int skin_armature_create_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + /* create new armature */ - arm_ob = modifier_skin_armature_create(C, scene, view_layer, ob); + arm_ob = modifier_skin_armature_create(&eval_ctx, bmain, scene, ob); /* add a modifier to connect the new armature to the mesh */ arm_md = (ArmatureModifierData *)modifier_new(eModifierType_Armature); |