diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-02-08 13:14:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-02-08 13:14:26 +0300 |
commit | 345c6298e995ea618c34282ba6d7ab5af032f191 (patch) | |
tree | f4fbc4798e17d0f19efc28b51a41425d0c552be8 /source/blender/blenkernel/intern | |
parent | 14a19fed788af0cf3695eb5def92510841056e08 (diff) |
Object Mode: move to workspace struct
- Read-only access can often use EvaluationContext.object_mode
- Write access to go to WorkSpace.object_mode.
- Some TODO's remain (marked as "TODO/OBMODE")
- Add-ons will need updating
(context.active_object.mode -> context.workspace.object_mode)
- There will be small/medium issues that still need resolving
this does work on a basic level though.
See D3037
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/context.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/multires.c | 132 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 80 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/shrinkwrap.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 17 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/workspace.c | 25 |
10 files changed, 177 insertions, 117 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index ea54548ab09..c4e9ace2d5d 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -64,6 +64,8 @@ #include "GPU_shader.h" #include "GPU_basic_shader.h" +#include "DEG_depsgraph.h" + #include <string.h> #include <limits.h> #include <math.h> @@ -260,7 +262,8 @@ static bool can_pbvh_draw(Object *ob, DerivedMesh *dm) return cddm->mvert == me->mvert || ob->sculpt->kb; } -static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) +static PBVH *cdDM_getPBVH( + Object *ob, DerivedMesh *dm, eObjectMode UNUSED(object_mode)) { CDDerivedMesh *cddm = (CDDerivedMesh *) dm; diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 9ac4831a047..8b7356eaa9e 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -1035,9 +1035,11 @@ int CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, const eObjectM int CTX_data_mode_enum(const bContext *C) { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); Object *obedit = CTX_data_edit_object(C); Object *obact = obedit ? NULL : CTX_data_active_object(C); - return CTX_data_mode_enum_ex(obedit, obact, obact ? obact->mode : OB_MODE_OBJECT); + return CTX_data_mode_enum_ex(obedit, obact, eval_ctx.object_mode); } /* would prefer if we can use the enum version below over this one - Campbell */ @@ -1273,10 +1275,10 @@ void CTX_data_eval_ctx(const bContext *C, EvaluationContext *eval_ctx) Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *obact = OBACT(view_layer); RenderEngineType *engine_type = CTX_data_engine_type(C); + WorkSpace *workspace = CTX_wm_workspace(C); DEG_evaluation_context_init_from_scene( eval_ctx, scene, view_layer, engine_type, - obact ? obact->mode : OB_MODE_OBJECT, DAG_EVAL_VIEWPORT); + workspace->object_mode, DAG_EVAL_VIEWPORT); } diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 55f11604710..e7c36685c42 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -60,6 +60,8 @@ #include "BKE_object.h" +#include "DEG_depsgraph.h" + #include "CCGSubSurf.h" #include <math.h> @@ -336,12 +338,13 @@ MultiresModifierData *get_multires_modifier(Scene *scene, Object *ob, bool use_f return mmd; } -static int multires_get_level(Object *ob, MultiresModifierData *mmd, - bool render, bool ignore_simplify) +static int multires_get_level( + MultiresModifierData *mmd, + bool render, bool ignore_simplify, eObjectMode object_mode) { if (render) return (mmd->modifier.scene) ? get_render_subsurf_level(&mmd->modifier.scene->r, mmd->renderlvl, true) : mmd->renderlvl; - else if (ob->mode == OB_MODE_SCULPT) + else if (object_mode == OB_MODE_SCULPT) return mmd->sculptlvl; else if (ignore_simplify) return mmd->lvl; @@ -349,12 +352,13 @@ static int multires_get_level(Object *ob, MultiresModifierData *mmd, return (mmd->modifier.scene) ? get_render_subsurf_level(&mmd->modifier.scene->r, mmd->lvl, false) : mmd->lvl; } -void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lvl) +void multires_set_tot_level(MultiresModifierData *mmd, int lvl, eObjectMode object_mode) { mmd->totlvl = lvl; - if (ob->mode != OB_MODE_SCULPT) + if (object_mode != OB_MODE_SCULPT) { mmd->lvl = CLAMPIS(MAX2(mmd->lvl, lvl), 0, mmd->totlvl); + } mmd->sculptlvl = CLAMPIS(MAX2(mmd->sculptlvl, lvl), 0, mmd->totlvl); mmd->renderlvl = CLAMPIS(MAX2(mmd->renderlvl, lvl), 0, mmd->totlvl); @@ -392,9 +396,9 @@ void multires_force_external_reload(Object *ob) multires_force_update(ob); } -void multires_force_render_update(Object *ob) +void multires_force_render_update(Object *ob, eObjectMode object_mode) { - if (ob && (ob->mode & OB_MODE_SCULPT) && modifiers_findByType(ob, eModifierType_Multires)) + if (ob && (object_mode & OB_MODE_SCULPT) && modifiers_findByType(ob, eModifierType_Multires)) multires_force_update(ob); } @@ -434,7 +438,7 @@ int multiresModifier_reshapeFromDeformMod(const struct EvaluationContext *eval_c int numVerts, result; float (*deformedVerts)[3]; - if (multires_get_level(ob, mmd, false, true) == 0) + if (multires_get_level(mmd, false, true, eval_ctx->object_mode) == 0) return 0; /* Create DerivedMesh for deformation modifier */ @@ -614,7 +618,7 @@ static void multires_grid_paint_mask_downsample(GridPaintMask *gpm, int level) } } -static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) +static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl, eObjectMode object_mode) { Mesh *me = (Mesh *)ob->data; int levels = mmd->totlvl - lvl; @@ -676,14 +680,14 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) } } - multires_set_tot_level(ob, mmd, lvl); + multires_set_tot_level(mmd, lvl, object_mode); } /* (direction = 1) for delete higher, (direction = 0) for lower (not implemented yet) */ -void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int direction) +void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int direction, eObjectMode object_mode) { Mesh *me = BKE_mesh_from_object(ob); - int lvl = multires_get_level(ob, mmd, false, true); + int lvl = multires_get_level(mmd, false, true, object_mode); int levels = mmd->totlvl - lvl; MDisps *mdisps; @@ -694,13 +698,14 @@ void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int dire multires_force_update(ob); if (mdisps && levels > 0 && direction == 1) { - multires_del_higher(mmd, ob, lvl); + multires_del_higher(mmd, ob, lvl, object_mode); } - multires_set_tot_level(ob, mmd, lvl); + multires_set_tot_level(mmd, lvl, object_mode); } -static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int totlvl, int simple, bool alloc_paint_mask) +static DerivedMesh *multires_dm_create_local( + Object *ob, DerivedMesh *dm, int lvl, int totlvl, int simple, bool alloc_paint_mask, eObjectMode object_mode) { MultiresModifierData mmd = {{NULL}}; MultiresFlags flags = MULTIRES_USE_LOCAL_MMD; @@ -714,10 +719,12 @@ static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lv if (alloc_paint_mask) flags |= MULTIRES_ALLOC_PAINT_MASK; - return multires_make_derived_from_derived(dm, &mmd, ob, flags); + return multires_make_derived_from_derived(dm, &mmd, ob, flags, object_mode); } -static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple, int optimal, int plain_uv, int alloc_paint_mask) +static DerivedMesh *subsurf_dm_create_local( + DerivedMesh *dm, int lvl, int simple, + int optimal, int plain_uv, int alloc_paint_mask, eObjectMode object_mode) { SubsurfModifierData smd = {{NULL}}; SubsurfFlags flags = 0; @@ -730,7 +737,7 @@ static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl if (optimal) smd.flags |= eSubsurfModifierFlag_ControlEdges; - if (ob->mode & OB_MODE_EDIT) + if (object_mode & OB_MODE_EDIT) flags |= SUBSURF_IN_EDIT_MODE; if (alloc_paint_mask) @@ -750,7 +757,7 @@ static float v3_dist_from_plane(float v[3], float center[3], float no[3]) return dot_v3v3(s, no); } -void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) +void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob, eObjectMode object_mode) { DerivedMesh *cddm, *dispdm, *origdm; Mesh *me; @@ -772,7 +779,7 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) /* generate highest level with displacements */ cddm = CDDM_from_mesh(me); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - dispdm = multires_dm_create_local(ob, cddm, totlvl, totlvl, 0, 0); + dispdm = multires_dm_create_local(ob, cddm, totlvl, totlvl, 0, 0, object_mode); cddm->release(cddm); /* copy the new locations of the base verts into the mesh */ @@ -868,7 +875,9 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) /* subdivide the mesh to highest level without displacements */ cddm = CDDM_from_mesh(me); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - origdm = subsurf_dm_create_local(ob, cddm, totlvl, 0, 0, mmd->flags & eMultiresModifierFlag_PlainUv, 0); + origdm = subsurf_dm_create_local( + cddm, totlvl, 0, + 0, mmd->flags & eMultiresModifierFlag_PlainUv, 0, object_mode); cddm->release(cddm); /* calc disps */ @@ -878,7 +887,8 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) dispdm->release(dispdm); } -static void multires_subdivide(MultiresModifierData *mmd, Object *ob, int totlvl, int updateblock, int simple) +static void multires_subdivide( + MultiresModifierData *mmd, Object *ob, int totlvl, int updateblock, int simple, eObjectMode object_mode) { Mesh *me = ob->data; MDisps *mdisps; @@ -907,11 +917,13 @@ static void multires_subdivide(MultiresModifierData *mmd, Object *ob, int totlvl /* create subsurf DM from original mesh at high level */ cddm = CDDM_from_mesh(me); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv, has_mask); + highdm = subsurf_dm_create_local( + cddm, totlvl, simple, + 0, mmd->flags & eMultiresModifierFlag_PlainUv, has_mask, object_mode); ss = ((CCGDerivedMesh *)highdm)->ss; /* create multires DM from original mesh at low level */ - lowdm = multires_dm_create_local(ob, cddm, lvl, lvl, simple, has_mask); + lowdm = multires_dm_create_local(ob, cddm, lvl, lvl, simple, has_mask, object_mode); BLI_assert(lowdm != cddm); cddm->release(cddm); @@ -958,12 +970,13 @@ static void multires_subdivide(MultiresModifierData *mmd, Object *ob, int totlvl multires_reallocate_mdisps(me->totloop, mdisps, totlvl); } - multires_set_tot_level(ob, mmd, totlvl); + multires_set_tot_level(mmd, totlvl, object_mode); } -void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int updateblock, int simple) +void multiresModifier_subdivide( + MultiresModifierData *mmd, Object *ob, int updateblock, int simple, eObjectMode object_mode) { - multires_subdivide(mmd, ob, mmd->totlvl + 1, updateblock, simple); + multires_subdivide(mmd, ob, mmd->totlvl + 1, updateblock, simple, object_mode); } static void grid_tangent(const CCGKey *key, int x, int y, int axis, CCGElem *grid, float t[3]) @@ -1196,7 +1209,7 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm } } -void multires_modifier_update_mdisps(struct DerivedMesh *dm) +void multires_modifier_update_mdisps(struct DerivedMesh *dm, eObjectMode object_mode) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; Object *ob; @@ -1228,11 +1241,13 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm) else cddm = CDDM_from_mesh(me); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - highdm = subsurf_dm_create_local(ob, cddm, totlvl, mmd->simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv, has_mask); + highdm = subsurf_dm_create_local( + cddm, totlvl, mmd->simple, + 0, mmd->flags & eMultiresModifierFlag_PlainUv, has_mask, object_mode); ss = ((CCGDerivedMesh *)highdm)->ss; /* create multires DM from original mesh and displacements */ - lowdm = multires_dm_create_local(ob, cddm, lvl, totlvl, mmd->simple, has_mask); + lowdm = multires_dm_create_local(ob, cddm, lvl, totlvl, mmd->simple, has_mask, object_mode); cddm->release(cddm); /* gather grid data */ @@ -1290,7 +1305,9 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm) else cddm = CDDM_from_mesh(me); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - subdm = subsurf_dm_create_local(ob, cddm, mmd->totlvl, mmd->simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv, has_mask); + subdm = subsurf_dm_create_local( + cddm, mmd->totlvl, mmd->simple, + 0, mmd->flags & eMultiresModifierFlag_PlainUv, has_mask, object_mode); cddm->release(cddm); multiresModifier_disp_run(dm, me, NULL, CALC_DISPLACEMENTS, subdm->getGridData(subdm), mmd->totlvl); @@ -1332,7 +1349,7 @@ void multires_modifier_update_hidden(DerivedMesh *dm) } } -void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to) +void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to, eObjectMode object_mode) { DerivedMesh *ccgdm = NULL, *subsurf = NULL; CCGElem **gridData, **subGridData = NULL; @@ -1353,10 +1370,11 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to) } totlvl = mmd->totlvl; - ccgdm = multires_dm_create_local(ob, dm, totlvl, totlvl, mmd->simple, false); + ccgdm = multires_dm_create_local(ob, dm, totlvl, totlvl, mmd->simple, false, object_mode); - subsurf = subsurf_dm_create_local(ob, dm, totlvl, - mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges, mmd->flags & eMultiresModifierFlag_PlainUv, 0); + subsurf = subsurf_dm_create_local( + dm, totlvl, mmd->simple, + mmd->flags & eMultiresModifierFlag_ControlEdges, mmd->flags & eMultiresModifierFlag_PlainUv, 0, object_mode); numGrids = subsurf->getNumGrids(subsurf); gridSize = subsurf->getGridSize(subsurf); @@ -1471,10 +1489,12 @@ void multires_stitch_grids(Object *ob) } } -DerivedMesh *multires_make_derived_from_derived(DerivedMesh *dm, - MultiresModifierData *mmd, - Object *ob, - MultiresFlags flags) +DerivedMesh *multires_make_derived_from_derived( + DerivedMesh *dm, + MultiresModifierData *mmd, + Object *ob, + MultiresFlags flags, + eObjectMode object_mode) { Mesh *me = ob->data; DerivedMesh *result; @@ -1483,16 +1503,18 @@ DerivedMesh *multires_make_derived_from_derived(DerivedMesh *dm, CCGKey key; const bool render = (flags & MULTIRES_USE_RENDER_PARAMS) != 0; const bool ignore_simplify = (flags & MULTIRES_IGNORE_SIMPLIFY) != 0; - int lvl = multires_get_level(ob, mmd, render, ignore_simplify); + int lvl = multires_get_level(mmd, render, ignore_simplify, object_mode); int i, gridSize, numGrids; if (lvl == 0) return dm; - result = subsurf_dm_create_local(ob, dm, lvl, - mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges, - mmd->flags & eMultiresModifierFlag_PlainUv, - flags & MULTIRES_ALLOC_PAINT_MASK); + result = subsurf_dm_create_local( + dm, lvl, mmd->simple, + mmd->flags & eMultiresModifierFlag_ControlEdges, + mmd->flags & eMultiresModifierFlag_PlainUv, + flags & MULTIRES_ALLOC_PAINT_MASK, + object_mode); if (!(flags & MULTIRES_USE_LOCAL_MMD)) { ccgdm = (CCGDerivedMesh *)result; @@ -2120,6 +2142,7 @@ void multires_load_old(Object *ob, Mesh *me) DerivedMesh *dm, *orig; CustomDataLayer *l; int i; + const eObjectMode object_mode = OB_MODE_OBJECT; /* Load original level into the mesh */ lvl = me->mr->levels.first; @@ -2168,7 +2191,7 @@ void multires_load_old(Object *ob, Mesh *me) BLI_insertlinkbefore(&ob->modifiers, md, mmd); for (i = 0; i < me->mr->level_count - 1; ++i) - multiresModifier_subdivide(mmd, ob, 1, 0); + multiresModifier_subdivide(mmd, ob, 1, 0, object_mode); mmd->lvl = mmd->totlvl; orig = CDDM_from_mesh(me); @@ -2177,7 +2200,7 @@ void multires_load_old(Object *ob, Mesh *me) * reference subsurfed dm with this option, before calling multiresModifier_disp_run(), * which implicitly expects both subsurfs from its first dm and oldGridData parameters to * be of the same "format"! */ - dm = multires_make_derived_from_derived(orig, mmd, ob, 0); + dm = multires_make_derived_from_derived(orig, mmd, ob, 0, object_mode); multires_load_old_dm(dm, me, mmd->totlvl + 1); @@ -2192,21 +2215,22 @@ void multires_load_old(Object *ob, Mesh *me) /* If 'ob_src' and 'ob_dst' both have multires modifiers, synchronize them * such that 'ob_dst' has the same total number of levels as 'ob_src'. */ -void multiresModifier_sync_levels_ex(Object *ob_dst, MultiresModifierData *mmd_src, MultiresModifierData *mmd_dst) +void multiresModifier_sync_levels_ex( + Object *ob_dst, MultiresModifierData *mmd_src, MultiresModifierData *mmd_dst, eObjectMode object_mode) { if (mmd_src->totlvl == mmd_dst->totlvl) { return; } if (mmd_src->totlvl > mmd_dst->totlvl) { - multires_subdivide(mmd_dst, ob_dst, mmd_src->totlvl, false, mmd_dst->simple); + multires_subdivide(mmd_dst, ob_dst, mmd_src->totlvl, false, mmd_dst->simple, object_mode); } else { - multires_del_higher(mmd_dst, ob_dst, mmd_src->totlvl); + multires_del_higher(mmd_dst, ob_dst, mmd_src->totlvl, object_mode); } } -static void multires_sync_levels(Scene *scene, Object *ob_src, Object *ob_dst) +static void multires_sync_levels(Scene *scene, Object *ob_src, Object *ob_dst, eObjectMode object_mode) { MultiresModifierData *mmd_src = get_multires_modifier(scene, ob_src, true); MultiresModifierData *mmd_dst = get_multires_modifier(scene, ob_dst, true); @@ -2221,7 +2245,7 @@ static void multires_sync_levels(Scene *scene, Object *ob_src, Object *ob_dst) } if (mmd_src && mmd_dst) { - multiresModifier_sync_levels_ex(ob_dst, mmd_src, mmd_dst); + multiresModifier_sync_levels_ex(ob_dst, mmd_src, mmd_dst, object_mode); } } @@ -2314,7 +2338,9 @@ static void multires_apply_smat(const struct EvaluationContext *eval_ctx, Scene MEM_freeN(vertCos); /* scaled ccgDM for tangent space of object with applied scale */ - dm = subsurf_dm_create_local(ob, cddm, high_mmd.totlvl, high_mmd.simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv, 0); + dm = subsurf_dm_create_local( + cddm, high_mmd.totlvl, high_mmd.simple, + 0, mmd->flags & eMultiresModifierFlag_PlainUv, 0, eval_ctx->object_mode); cddm->release(cddm); gridSize = dm->getGridSize(dm); @@ -2377,7 +2403,7 @@ void multiresModifier_scale_disp(const struct EvaluationContext *eval_ctx, Scene void multiresModifier_prepare_join(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, Object *to_ob) { float smat[3][3], tmat[3][3], mat[3][3]; - multires_sync_levels(scene, to_ob, ob); + multires_sync_levels(scene, to_ob, ob, eval_ctx->object_mode); /* construct scale matrix for displacement */ BKE_object_scale_to_mat3(to_ob, tmat); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 1cf926c609d..7f20c2f271b 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -262,7 +262,9 @@ bool BKE_object_support_modifier_type_check(Object *ob, int modifier_type) return true; } -void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src) +void BKE_object_link_modifiers( + struct Object *ob_dst, const struct Object *ob_src, + eObjectMode object_mode) { ModifierData *md; BKE_object_free_modifiers(ob_dst); @@ -301,7 +303,8 @@ void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_sr if (md->type == eModifierType_Multires) { /* Has to be done after mod creation, but *before* we actually copy its settings! */ - multiresModifier_sync_levels_ex(ob_dst, (MultiresModifierData *)md, (MultiresModifierData *)nmd); + multiresModifier_sync_levels_ex( + ob_dst, (MultiresModifierData *)md, (MultiresModifierData *)nmd, object_mode); } modifier_copyData(md, nmd); @@ -1155,7 +1158,9 @@ bool BKE_object_pose_context_check(Object *ob) if ((ob) && (ob->type == OB_ARMATURE) && (ob->pose) && - (ob->mode & OB_MODE_POSE)) + // (ob->mode & OB_MODE_POSE) + (((bArmature *)ob->data)->flag & ARM_POSEMODE) + ) { return true; } @@ -1241,7 +1246,6 @@ void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_ BKE_object_facemap_copy_list(&ob_dst->fmaps, &ob_src->fmaps); BKE_constraints_copy_ex(&ob_dst->constraints, &ob_src->constraints, flag_subdata, true); - ob_dst->mode = OB_MODE_OBJECT; ob_dst->sculpt = NULL; if (ob_src->pd) { diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 5ba4face835..5a267f97d03 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -75,29 +75,67 @@ const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255}; static eOverlayControlFlags overlay_flags = 0; -void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex) +/* Keep in sync with 'BKE_paint_get_active' */ +#define OB_MODE_HAS_PAINT_STRUCT(SEP) \ + OB_MODE_SCULPT SEP \ + OB_MODE_VERTEX_PAINT SEP \ + OB_MODE_WEIGHT_PAINT SEP \ + OB_MODE_TEXTURE_PAINT SEP \ + OB_MODE_EDIT + +#define COMMA , +static const eObjectMode ob_mode_has_paint_struct = OB_MODE_HAS_PAINT_STRUCT(|); +static const eObjectMode ob_mode_has_paint_struct_array[] = {OB_MODE_HAS_PAINT_STRUCT(COMMA)}; +#undef COMMA + +#define FOREACH_OB_MODE_PAINT_ITER_BEGIN(scene, view_layer, object_mode, p) \ +{ \ + eObjectMode object_mode_test = object_mode & ob_mode_has_paint_struct; \ + for (uint _i = 0; _i < ARRAY_SIZE(ob_mode_has_paint_struct_array) && object_mode_test; _i++) { \ + eObjectMode object_mode_single = ob_mode_has_paint_struct_array[_i]; \ + if (object_mode_test & object_mode_single) { \ + object_mode_test &= ~object_mode_single; \ + Paint *p = BKE_paint_get_active(scene, view_layer, object_mode_single); \ + { + +#define FOREACH_OB_MODE_PAINT_ITER_END \ + } \ + } \ + } \ +} ((void)0) + +void BKE_paint_invalidate_overlay_tex( + Scene *scene, ViewLayer *view_layer, const Tex *tex, eObjectMode object_mode) { - /* TODO/OBMODE (we should combine all) */ - Paint *p = BKE_paint_get_active(scene, view_layer, G.main->eval_ctx->object_mode); - Brush *br = p->brush; - - if (!br) - return; - - if (br->mtex.tex == tex) - overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY; - if (br->mask_mtex.tex == tex) - overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY; + FOREACH_OB_MODE_PAINT_ITER_BEGIN(scene, view_layer, object_mode, p) + { + Brush *br = p->brush; + if (br) { + if (br->mtex.tex == tex) { + overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY; + } + if (br->mask_mtex.tex == tex) { + overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY; + } + } + } + FOREACH_OB_MODE_PAINT_ITER_END; } -void BKE_paint_invalidate_cursor_overlay(Scene *scene, ViewLayer *view_layer, CurveMapping *curve) +void BKE_paint_invalidate_cursor_overlay( + Scene *scene, ViewLayer *view_layer, CurveMapping *curve, eObjectMode object_mode) { - /* TODO/OBMODE (we should combine all) */ - Paint *p = BKE_paint_get_active(scene, view_layer, G.main->eval_ctx->object_mode); - Brush *br = p->brush; - - if (br && br->curve == curve) - overlay_flags |= PAINT_INVALID_OVERLAY_CURVE; + FOREACH_OB_MODE_PAINT_ITER_BEGIN(scene, view_layer, object_mode, p) + { + Brush *br = p->brush; + if (br) { + if (br->curve == curve) { + overlay_flags |= PAINT_INVALID_OVERLAY_CURVE; + break; + } + } + } + FOREACH_OB_MODE_PAINT_ITER_END; } void BKE_paint_invalidate_overlay_all(void) @@ -794,7 +832,7 @@ void BKE_sculptsession_free(Object *ob) BM_log_free(ss->bm_log); if (dm && dm->getPBVH) - dm->getPBVH(NULL, dm); /* signal to clear */ + dm->getPBVH(NULL, dm, OB_MODE_OBJECT); /* signal to clear */ if (ss->texcache) MEM_freeN(ss->texcache); @@ -949,7 +987,7 @@ void BKE_sculpt_update_mesh_elements( ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK); } - ss->pbvh = dm->getPBVH(ob, dm); + ss->pbvh = dm->getPBVH(ob, dm, eval_ctx->object_mode); ss->pmap = (need_pmap && dm->getPolyMap) ? dm->getPolyMap(ob, dm) : NULL; pbvh_show_diffuse_color_set(ss->pbvh, ss->show_diffuse_color); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 0ca83fba4b5..d227ea55816 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3223,8 +3223,6 @@ void object_remove_particle_system(Scene *UNUSED(scene), Object *ob) if (ob->particlesystem.first) ((ParticleSystem *) ob->particlesystem.first)->flag |= PSYS_CURRENT; - else - ob->mode &= ~OB_MODE_PARTICLE_EDIT; DEG_relations_tag_update(G.main); DEG_id_tag_update(&ob->id, OB_RECALC_DATA); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 16e9844241d..e3166b7d0b2 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -983,8 +983,7 @@ void BKE_scene_set_background(Main *bmain, Scene *scene) BKE_scene_validate_setscene(bmain, scene); /* can happen when switching modes in other scenes */ - if (scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT)) - scene->obedit = NULL; + scene->obedit = NULL; /* deselect objects (for dataselect) */ for (ob = bmain->object.first; ob; ob = ob->id.next) diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 618f495dbf1..e91c3e43b83 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -57,6 +57,8 @@ #include "BLI_strict_flags.h" +#include "DEG_depsgraph.h" + /* for timing... */ #if 0 # include "PIL_time_utildefines.h" @@ -614,8 +616,9 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) } /* Main shrinkwrap function */ -void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedMesh *dm, - float (*vertexCos)[3], int numVerts, bool for_render) +void shrinkwrapModifier_deform( + const EvaluationContext *eval_ctx, ShrinkwrapModifierData *smd, Object *ob, DerivedMesh *dm, + float (*vertexCos)[3], int numVerts, bool for_render) { DerivedMesh *ss_mesh = NULL; @@ -670,7 +673,8 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM ssmd.subdivType = ME_CC_SUBSURF; /* catmull clark */ ssmd.levels = smd->subsurfLevels; /* levels */ - ss_mesh = subsurf_make_derived_from_derived(dm, &ssmd, NULL, (ob->mode & OB_MODE_EDIT) ? SUBSURF_IN_EDIT_MODE : 0); + ss_mesh = subsurf_make_derived_from_derived( + dm, &ssmd, NULL, (eval_ctx->object_mode & OB_MODE_EDIT) ? SUBSURF_IN_EDIT_MODE : 0); if (ss_mesh) { calc.vert = ss_mesh->getVertDataArray(ss_mesh, CD_MVERT); diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 9280341b4e4..10792b7d579 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -85,6 +85,8 @@ #include "CCGSubSurf.h" +#include "DEG_depsgraph.h" + #ifdef WITH_OPENSUBDIV # include "opensubdiv_capi.h" #endif @@ -3788,12 +3790,14 @@ static void ccgDM_release(DerivedMesh *dm) { ccgdm->multires.mmd = NULL; } - if (ccgdm->multires.mmd) { - if (ccgdm->multires.modified_flags & MULTIRES_COORDS_MODIFIED) - multires_modifier_update_mdisps(dm); - if (ccgdm->multires.modified_flags & MULTIRES_HIDDEN_MODIFIED) + if (ccgdm->multires.modified_flags & MULTIRES_COORDS_MODIFIED) { + /* TODO/OBMODE, pass real mode? */ + multires_modifier_update_mdisps(dm, OB_MODE_OBJECT); + } + if (ccgdm->multires.modified_flags & MULTIRES_HIDDEN_MODIFIED) { multires_modifier_update_hidden(dm); + } } } @@ -4187,7 +4191,8 @@ static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm) return 1; } -static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) +static struct PBVH *ccgDM_getPBVH( + Object *ob, DerivedMesh *dm, eObjectMode object_mode) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; CCGKey key; @@ -4204,7 +4209,7 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) return NULL; bool grid_pbvh = ccgDM_use_grid_pbvh(ccgdm); - if ((ob->mode & OB_MODE_SCULPT) == 0) { + if ((object_mode & OB_MODE_SCULPT) == 0) { /* In vwpaint, we may use a grid_pbvh for multires/subsurf, under certain conditions. * More complex cases break 'history' trail back to original vertices, in that case we fall back to * deformed cage only (i.e. original deformed mesh). */ diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c index 4b6bd3ac35b..dcd4183210d 100644 --- a/source/blender/blenkernel/intern/workspace.c +++ b/source/blender/blenkernel/intern/workspace.c @@ -415,21 +415,6 @@ void BKE_workspace_active_screen_set(WorkSpaceInstanceHook *hook, WorkSpace *wor BKE_workspace_hook_layout_for_workspace_set(hook, workspace, layout); } -#ifdef USE_WORKSPACE_MODE -eObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace, const Scene *scene) -{ - Base *active_base = BKE_workspace_active_base_get(workspace, scene); - return active_base ? active_base->object->mode : OB_MODE_OBJECT; -} -void BKE_workspace_object_mode_set(WorkSpace *workspace, Scene *scene, const eObjectMode mode) -{ - Base *active_base = BKE_workspace_active_base_get(workspace, scene); - if (active_base) { - active_base->object->mode = mode; - } -} -#endif - Base *BKE_workspace_active_base_get(const WorkSpace *workspace, const Scene *scene) { ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene); @@ -526,14 +511,10 @@ void BKE_workspace_update_tagged(struct EvaluationContext *eval_ctx, void BKE_workspace_update_object_mode( struct EvaluationContext *eval_ctx, - WorkSpace *workspace, Scene *scene) + WorkSpace *workspace) { - ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene); - /* TODO(campbell): Investigate how this should work exactly, * for now without this 'bmain->eval_ctx' is never set. */ - { - Object *ob = view_layer->basact ? view_layer->basact->object : NULL; - eval_ctx->object_mode = ob ? (eObjectMode)ob->mode : OB_MODE_OBJECT; - } + + eval_ctx->object_mode = workspace->object_mode; }
\ No newline at end of file |