diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-02-06 09:06:20 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-02-06 10:03:28 +0300 |
commit | c7fecab2efd3b28a18b56dbd321616728d8b7cce (patch) | |
tree | 0169ab63925ce3d6730f519a4a54822e7f77c652 /source/blender/blenkernel/intern | |
parent | ef11113399e3273ee647b3710b346356a2b5f8f0 (diff) |
Object Mode: Use eval_ctx mode for drawing, paint & modifiers
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 40 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 24 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 40 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 14 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 7 |
5 files changed, 71 insertions, 54 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index d71735ca8c4..5229cb35645 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -51,6 +51,8 @@ #include "BLI_linklist.h" #include "BLI_task.h" +#include "DEG_depsgraph.h" + #include "BKE_cdderivedmesh.h" #include "BKE_colorband.h" #include "BKE_editmesh.h" @@ -1776,17 +1778,19 @@ static void mesh_calc_modifiers( MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0); const bool has_multires = (mmd && mmd->sculptlvl != 0); bool multires_applied = false; - const bool sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt && !useRenderParams; + const bool sculpt_mode = eval_ctx->object_mode & OB_MODE_SCULPT && ob->sculpt && !useRenderParams; const bool sculpt_dyntopo = (sculpt_mode && ob->sculpt->bm) && !useRenderParams; const int draw_flag = dm_drawflag_calc(scene->toolsettings, me); /* Generic preview only in object mode! */ - const bool do_mod_mcol = (ob->mode == OB_MODE_OBJECT); + const bool do_mod_mcol = (eval_ctx->object_mode == OB_MODE_OBJECT); #if 0 /* XXX Will re-enable this when we have global mod stack options. */ const bool do_final_wmcol = (scene->toolsettings->weights_preview == WP_WPREVIEW_FINAL) && do_wmcol; #endif const bool do_final_wmcol = false; - const bool do_init_wmcol = ((dataMask & CD_MASK_PREVIEW_MLOOPCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT) && !do_final_wmcol); + const bool do_init_wmcol = ( + (dataMask & CD_MASK_PREVIEW_MLOOPCOL) && + (eval_ctx->object_mode & OB_MODE_WEIGHT_PAINT) && !do_final_wmcol); /* XXX Same as above... For now, only weights preview in WPaint mode. */ const bool do_mod_wmcol = do_init_wmcol; @@ -2624,7 +2628,7 @@ static bool calc_modifiers_skip_orco(const EvaluationContext *eval_ctx, if (U.opensubdiv_compute_type == USER_OPENSUBDIV_COMPUTE_NONE) { return false; } - else if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) { + else if ((eval_ctx->object_mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) { return false; } else if ((DEG_get_eval_flags_for_id(eval_ctx->depsgraph, &ob->id) & DAG_EVAL_NEED_CPU) != 0) { @@ -2665,7 +2669,7 @@ static void mesh_build_data( ob->lastDataMask = dataMask; ob->lastNeedMapping = need_mapping; - if ((ob->mode & OB_MODE_ALL_SCULPT) && ob->sculpt) { + if ((eval_ctx->object_mode & OB_MODE_ALL_SCULPT) && ob->sculpt) { /* create PBVH immediately (would be created on the fly too, * but this avoids waiting on first stroke) */ @@ -2703,7 +2707,9 @@ static void editbmesh_build_data( BLI_assert(!(em->derivedFinal->dirty & DM_DIRTY_NORMALS)); } -static CustomDataMask object_get_datamask(const Scene *scene, Object *ob, bool *r_need_mapping) +static CustomDataMask object_get_datamask( + const EvaluationContext *eval_ctx, + const Scene *scene, Object *ob, bool *r_need_mapping) { /* TODO(sergey): Avoid this linear list lookup. */ ViewLayer *view_layer = BKE_view_layer_context_active_PLACEHOLDER(scene); @@ -2715,28 +2721,28 @@ static CustomDataMask object_get_datamask(const Scene *scene, Object *ob, bool * } if (ob == actob) { - bool editing = BKE_paint_select_face_test(ob); + bool editing = BKE_paint_select_face_test(eval_ctx, ob); /* weight paint and face select need original indices because of selection buffer drawing */ if (r_need_mapping) { - *r_need_mapping = (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT))); + *r_need_mapping = (editing || (eval_ctx->object_mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT))); } /* check if we need tfaces & mcols due to face select or texture paint */ - if ((ob->mode & OB_MODE_TEXTURE_PAINT) || editing) { + if ((eval_ctx->object_mode & OB_MODE_TEXTURE_PAINT) || editing) { mask |= CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL; } /* check if we need mcols due to vertex paint or weightpaint */ - if (ob->mode & OB_MODE_VERTEX_PAINT) { + if (eval_ctx->object_mode & OB_MODE_VERTEX_PAINT) { mask |= CD_MASK_MLOOPCOL; } - if (ob->mode & OB_MODE_WEIGHT_PAINT) { + if (eval_ctx->object_mode & OB_MODE_WEIGHT_PAINT) { mask |= CD_MASK_PREVIEW_MLOOPCOL; } - if (ob->mode & OB_MODE_EDIT) + if (eval_ctx->object_mode & OB_MODE_EDIT) mask |= CD_MASK_MVERT_SKIN; } @@ -2748,7 +2754,7 @@ void makeDerivedMesh( CustomDataMask dataMask, const bool build_shapekey_layers) { bool need_mapping; - dataMask |= object_get_datamask(scene, ob, &need_mapping); + dataMask |= object_get_datamask(eval_ctx, scene, ob, &need_mapping); if (em) { editbmesh_build_data(eval_ctx, scene, ob, em, dataMask); @@ -2767,7 +2773,7 @@ DerivedMesh *mesh_get_derived_final( * the data we need, rebuild the derived mesh */ bool need_mapping; - dataMask |= object_get_datamask(scene, ob, &need_mapping); + dataMask |= object_get_datamask(eval_ctx, scene, ob, &need_mapping); if (!ob->derivedFinal || ((dataMask & ob->lastDataMask) != dataMask) || @@ -2787,7 +2793,7 @@ DerivedMesh *mesh_get_derived_deform(const struct EvaluationContext *eval_ctx, S */ bool need_mapping; - dataMask |= object_get_datamask(scene, ob, &need_mapping); + dataMask |= object_get_datamask(eval_ctx, scene, ob, &need_mapping); if (!ob->derivedDeform || ((dataMask & ob->lastDataMask) != dataMask) || @@ -2906,7 +2912,7 @@ DerivedMesh *editbmesh_get_derived_cage_and_final( /* if there's no derived mesh or the last data mask used doesn't include * the data we need, rebuild the derived mesh */ - dataMask |= object_get_datamask(scene, obedit, NULL); + dataMask |= object_get_datamask(eval_ctx, scene, obedit, NULL); if (!em->derivedCage || (em->lastDataMask & dataMask) != dataMask) @@ -2926,7 +2932,7 @@ DerivedMesh *editbmesh_get_derived_cage( /* if there's no derived mesh or the last data mask used doesn't include * the data we need, rebuild the derived mesh */ - dataMask |= object_get_datamask(scene, obedit, NULL); + dataMask |= object_get_datamask(eval_ctx, scene, obedit, NULL); if (!em->derivedCage || (em->lastDataMask & dataMask) != dataMask) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 8c85a0413b8..2e257a329ea 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -486,7 +486,7 @@ void BKE_object_free(Object *ob) } /* actual check for internal data, not context or flags */ -bool BKE_object_is_in_editmode(Object *ob) +bool BKE_object_is_in_editmode(const Object *ob) { if (ob->data == NULL) return false; @@ -535,11 +535,11 @@ bool BKE_object_is_in_editmode_vgroup(Object *ob) BKE_object_is_in_editmode(ob)); } -bool BKE_object_is_in_wpaint_select_vert(Object *ob) +bool BKE_object_is_in_wpaint_select_vert(const EvaluationContext *eval_ctx, const Object *ob) { if (ob->type == OB_MESH) { - Mesh *me = ob->data; - return ((ob->mode & OB_MODE_WEIGHT_PAINT) && + const Mesh *me = ob->data; + return ((eval_ctx->object_mode & OB_MODE_WEIGHT_PAINT) && (me->edit_btmesh == NULL) && (ME_EDIT_PAINT_SEL_MODE(me) == SCE_SELECT_VERTEX)); } @@ -884,10 +884,10 @@ static LodLevel *lod_level_select(Object *ob, const float camera_position[3]) return current; } -bool BKE_object_lod_is_usable(Object *ob, ViewLayer *view_layer) +bool BKE_object_lod_is_usable(Object *ob, ViewLayer *view_layer, const short object_mode) { bool active = (view_layer) ? ob == OBACT(view_layer) : false; - return (ob->mode == OB_MODE_OBJECT || !active); + return (object_mode == OB_MODE_OBJECT || !active); } void BKE_object_lod_update(Object *ob, const float camera_position[3]) @@ -900,11 +900,11 @@ void BKE_object_lod_update(Object *ob, const float camera_position[3]) } } -static Object *lod_ob_get(Object *ob, ViewLayer *view_layer, int flag) +static Object *lod_ob_get(Object *ob, ViewLayer *view_layer, int flag, const short object_mode) { LodLevel *current = ob->currentlod; - if (!current || !BKE_object_lod_is_usable(ob, view_layer)) + if (!current || !BKE_object_lod_is_usable(ob, view_layer, object_mode)) return ob; while (current->prev && (!(current->flags & flag) || !current->source || current->source->type != OB_MESH)) { @@ -914,14 +914,14 @@ static Object *lod_ob_get(Object *ob, ViewLayer *view_layer, int flag) return current->source; } -struct Object *BKE_object_lod_meshob_get(Object *ob, ViewLayer *view_layer) +struct Object *BKE_object_lod_meshob_get(Object *ob, ViewLayer *view_layer, const short object_mode) { - return lod_ob_get(ob, view_layer, OB_LOD_USE_MESH); + return lod_ob_get(ob, view_layer, OB_LOD_USE_MESH, object_mode); } -struct Object *BKE_object_lod_matob_get(Object *ob, ViewLayer *view_layer) +struct Object *BKE_object_lod_matob_get(Object *ob, ViewLayer *view_layer, const short object_mode) { - return lod_ob_get(ob, view_layer, OB_LOD_USE_MAT); + return lod_ob_get(ob, view_layer, OB_LOD_USE_MAT, object_mode); } #endif /* WITH_GAMEENGINE */ diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 2bf5d12e50e..f0ad8de33b9 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -77,7 +77,8 @@ static eOverlayControlFlags overlay_flags = 0; void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex) { - Paint *p = BKE_paint_get_active(scene, view_layer); + /* 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) @@ -91,7 +92,8 @@ void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const void BKE_paint_invalidate_cursor_overlay(Scene *scene, ViewLayer *view_layer, CurveMapping *curve) { - Paint *p = BKE_paint_get_active(scene, view_layer); + /* 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) @@ -157,13 +159,13 @@ Paint *BKE_paint_get_active_from_paintmode(Scene *sce, ePaintMode mode) return NULL; } -Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer) +Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer, const short object_mode) { if (sce && view_layer) { ToolSettings *ts = sce->toolsettings; if (view_layer->basact && view_layer->basact->object) { - switch (view_layer->basact->object->mode) { + switch (object_mode) { case OB_MODE_SCULPT: return &ts->sculpt->paint; case OB_MODE_VERTEX_PAINT: @@ -193,6 +195,9 @@ Paint *BKE_paint_get_active_from_context(const bContext *C) SpaceImage *sima; if (sce && view_layer) { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + ToolSettings *ts = sce->toolsettings; Object *obact = NULL; @@ -200,7 +205,7 @@ Paint *BKE_paint_get_active_from_context(const bContext *C) obact = view_layer->basact->object; if ((sima = CTX_wm_space_image(C)) != NULL) { - if (obact && obact->mode == OB_MODE_EDIT) { + if (obact && eval_ctx.object_mode == OB_MODE_EDIT) { if (sima->mode == SI_MODE_PAINT) return &ts->imapaint.paint; else if (ts->use_uv_sculpt) @@ -211,7 +216,7 @@ Paint *BKE_paint_get_active_from_context(const bContext *C) } } else if (obact) { - switch (obact->mode) { + switch (eval_ctx.object_mode) { case OB_MODE_SCULPT: return &ts->sculpt->paint; case OB_MODE_VERTEX_PAINT: @@ -244,6 +249,9 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C) SpaceImage *sima; if (sce && view_layer) { + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + ToolSettings *ts = sce->toolsettings; Object *obact = NULL; @@ -251,7 +259,7 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C) obact = view_layer->basact->object; if ((sima = CTX_wm_space_image(C)) != NULL) { - if (obact && obact->mode == OB_MODE_EDIT) { + if (obact && eval_ctx.object_mode == OB_MODE_EDIT) { if (sima->mode == SI_MODE_PAINT) return ePaintTexture2D; else if (ts->use_uv_sculpt) @@ -262,7 +270,7 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C) } } else if (obact) { - switch (obact->mode) { + switch (eval_ctx.object_mode) { case OB_MODE_SCULPT: return ePaintSculpt; case OB_MODE_VERTEX_PAINT: @@ -453,24 +461,24 @@ bool BKE_palette_is_empty(const struct Palette *palette) /* are we in vertex paint or weight pain face select mode? */ -bool BKE_paint_select_face_test(Object *ob) +bool BKE_paint_select_face_test(const EvaluationContext *eval_ctx, Object *ob) { return ( (ob != NULL) && (ob->type == OB_MESH) && (ob->data != NULL) && (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_FACE_SEL) && - (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) + (eval_ctx->object_mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) ); } /* are we in weight paint vertex select mode? */ -bool BKE_paint_select_vert_test(Object *ob) +bool BKE_paint_select_vert_test(const EvaluationContext *eval_ctx, Object *ob) { return ( (ob != NULL) && (ob->type == OB_MESH) && (ob->data != NULL) && (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_VERT_SEL) && - (ob->mode & OB_MODE_WEIGHT_PAINT || ob->mode & OB_MODE_VERTEX_PAINT) + (eval_ctx->object_mode & OB_MODE_WEIGHT_PAINT || eval_ctx->object_mode & OB_MODE_VERTEX_PAINT) ); } @@ -478,10 +486,10 @@ bool BKE_paint_select_vert_test(Object *ob) * used to check if selection is possible * (when we don't care if its face or vert) */ -bool BKE_paint_select_elem_test(Object *ob) +bool BKE_paint_select_elem_test(const EvaluationContext *eval_ctx, Object *ob) { - return (BKE_paint_select_vert_test(ob) || - BKE_paint_select_face_test(ob)); + return (BKE_paint_select_vert_test(eval_ctx, ob) || + BKE_paint_select_face_test(eval_ctx, ob)); } void BKE_paint_cavity_curve_preset(Paint *p, int preset) @@ -921,7 +929,7 @@ void BKE_sculpt_update_mesh_elements( dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH); /* VWPaint require mesh info for loop lookup, so require sculpt mode here */ - if (mmd && ob->mode & OB_MODE_SCULPT) { + if (mmd && eval_ctx->object_mode & OB_MODE_SCULPT) { ss->multires = mmd; ss->totvert = dm->getNumVerts(dm); ss->totpoly = dm->getNumPolys(dm); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 5e2cd89a750..0ca83fba4b5 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -252,7 +252,7 @@ struct LatticeDeformData *psys_create_lattice_deform_data(ParticleSimulationData { struct LatticeDeformData *lattice_deform_data = NULL; - if (psys_in_edit_mode(sim->eval_ctx->view_layer, sim->psys) == 0) { + if (psys_in_edit_mode(sim->eval_ctx, sim->eval_ctx->view_layer, sim->psys) == 0) { Object *lattice = NULL; ModifierData *md = (ModifierData *)psys_get_modifier(sim->ob, sim->psys); int mode = G.is_rendering ? eModifierMode_Render : eModifierMode_Realtime; @@ -289,10 +289,10 @@ void psys_enable_all(Object *ob) psys->flag &= ~PSYS_DISABLED; } -bool psys_in_edit_mode(ViewLayer *view_layer, ParticleSystem *psys) +bool psys_in_edit_mode(const EvaluationContext *eval_ctx, ViewLayer *view_layer, ParticleSystem *psys) { return (view_layer->basact && - (view_layer->basact->object->mode & OB_MODE_PARTICLE_EDIT) && + (eval_ctx->object_mode & OB_MODE_PARTICLE_EDIT) && psys == psys_get_current((view_layer->basact)->object) && (psys->edit || psys->pointcache->edit) && !psys->renderdata); @@ -2098,7 +2098,7 @@ static bool psys_thread_context_init_path( psys_thread_context_init(ctx, sim); /*---start figuring out what is actually wanted---*/ - if (psys_in_edit_mode(sim->eval_ctx->view_layer, psys)) { + if (psys_in_edit_mode(sim->eval_ctx, sim->eval_ctx->view_layer, psys)) { ParticleEditSettings *pset = &scene->toolsettings->particle; if ((psys->renderdata == 0 && use_render_params == 0) && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0) @@ -2187,7 +2187,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp ParticleSystem *psys = ctx->sim.psys; ParticleSettings *part = psys->part; ParticleCacheKey **cache = psys->childcache; - ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.eval_ctx->view_layer, psys) && psys->edit ? psys->edit->pathcache : psys->pathcache; + ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.eval_ctx, ctx->sim.eval_ctx->view_layer, psys) && psys->edit ? psys->edit->pathcache : psys->pathcache; ParticleCacheKey *child, *key[4]; ParticleTexture ptex; float *cpa_fuv = 0, *par_rot = 0, rot[4]; @@ -2596,7 +2596,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re if ((psys->flag & PSYS_HAIR_DONE || psys->flag & PSYS_KEYED || psys->pointcache) == 0) return; - if (psys_in_edit_mode(sim->eval_ctx->view_layer, psys)) + if (psys_in_edit_mode(sim->eval_ctx, sim->eval_ctx->view_layer, psys)) if (psys->renderdata == 0 && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0) return; @@ -3789,7 +3789,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * pind.bspline = (psys->part->flag & PART_HAIR_BSPLINE); /* pind.dm disabled in editmode means we don't get effectors taken into * account when subdividing for instance */ - pind.dm = psys_in_edit_mode(sim->eval_ctx->view_layer, psys) ? NULL : psys->hair_out_dm; + pind.dm = psys_in_edit_mode(sim->eval_ctx, sim->eval_ctx->view_layer, psys) ? NULL : psys->hair_out_dm; init_particle_interpolation(sim->ob, psys, pa, &pind); do_particle_interpolation(psys, p, pa, t, &pind, state); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index ac10ad44bf1..8ece77737b7 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -2904,8 +2904,11 @@ static void psys_update_path_cache(ParticleSimulationData *sim, float cfra, cons if ((psys->part->childtype && psys->totchild != psys_get_tot_child(sim->scene, psys)) || psys->recalc&PSYS_RECALC_RESET) alloc=1; - if (alloc || psys->recalc&PSYS_RECALC_CHILD || (psys->vgroup[PSYS_VG_DENSITY] && (sim->ob && sim->ob->mode & OB_MODE_WEIGHT_PAINT))) + if (alloc || psys->recalc&PSYS_RECALC_CHILD || + (psys->vgroup[PSYS_VG_DENSITY] && (sim->ob && sim->eval_ctx->object_mode & OB_MODE_WEIGHT_PAINT))) + { distr=1; + } if (distr) { if (alloc) @@ -2933,7 +2936,7 @@ static void psys_update_path_cache(ParticleSimulationData *sim, float cfra, cons skip = 1; /* draw visualization */ else if (psys->pointcache->flag & PTCACHE_BAKING) skip = 1; /* no need to cache paths while baking dynamics */ - else if (psys_in_edit_mode(sim->eval_ctx->view_layer, psys)) { + else if (psys_in_edit_mode(sim->eval_ctx, sim->eval_ctx->view_layer, psys)) { if ((pset->flag & PE_DRAW_PART)==0) skip = 1; else if (part->childtype==0 && (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED)==0) |