diff options
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index 1a37973cd7d..436f4ac5993 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -35,8 +35,8 @@ #include "IMB_imbuf_types.h" #include "IMB_colormanagement.h" -//#include "DNA_armature_types.h" #include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #include "DNA_particle_types.h" #include "DNA_brush_types.h" #include "DNA_object_types.h" @@ -46,19 +46,21 @@ #include "RNA_define.h" #include "RNA_enum_types.h" -#include "BKE_DerivedMesh.h" #include "BKE_brush.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_deform.h" #include "BKE_mesh.h" +#include "BKE_mesh_iterators.h" #include "BKE_mesh_mapping.h" +#include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_object_deform.h" #include "BKE_paint.h" #include "BKE_report.h" #include "BKE_colortools.h" +#include "DEG_depsgraph.h" + #include "WM_api.h" #include "WM_types.h" @@ -124,15 +126,16 @@ static bool weight_from_bones_poll(bContext *C) static int weight_from_bones_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Object *armob = modifiers_isDeformedByArmature(ob); Mesh *me = ob->data; int type = RNA_enum_get(op->ptr, "type"); - ED_object_vgroup_calc_from_armature(op->reports, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X)); + ED_object_vgroup_calc_from_armature(op->reports, depsgraph, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X)); - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return OPERATOR_FINISHED; @@ -367,7 +370,7 @@ static int weight_sample_group_exec(bContext *C, wmOperator *op) BLI_assert(type + 1 >= 0); vc.obact->actdef = type + 1; - DAG_id_tag_update(&vc.obact->id, OB_RECALC_DATA); + DEG_id_tag_update(&vc.obact->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, vc.obact); return OPERATOR_FINISHED; } @@ -483,7 +486,7 @@ static bool weight_paint_set(Object *ob, float paintweight) wpaint_prev_destroy(&wpp); - DAG_id_tag_update(&me->id, 0); + DEG_id_tag_update(&me->id, 0); return true; } @@ -532,21 +535,21 @@ void PAINT_OT_weight_set(wmOperatorType *ot) * \{ */ /* *** VGroups Gradient *** */ -typedef struct DMGradient_vertStore { +typedef struct WPGradient_vertStore { float sco[2]; float weight_orig; enum { VGRAD_STORE_NOP = 0, VGRAD_STORE_DW_EXIST = (1 << 0) } flag; -} DMGradient_vertStore; +} WPGradient_vertStore; -typedef struct DMGradient_vertStoreBase { +typedef struct WPGradient_vertStoreBase { struct WPaintPrev wpp; - DMGradient_vertStore elem[0]; -} DMGradient_vertStoreBase; + WPGradient_vertStore elem[0]; +} WPGradient_vertStoreBase; -typedef struct DMGradient_userData { +typedef struct WPGradient_userData { struct ARegion *ar; Scene *scene; Mesh *me; @@ -556,7 +559,7 @@ typedef struct DMGradient_userData { float sco_line_div; /* store (1.0f / len_v2v2(sco_start, sco_end)) */ int def_nr; bool is_init; - DMGradient_vertStoreBase *vert_cache; + WPGradient_vertStoreBase *vert_cache; /* only for init */ BLI_bitmap *vert_visit; @@ -564,12 +567,12 @@ typedef struct DMGradient_userData { short use_select; short type; float weightpaint; -} DMGradient_userData; +} WPGradient_userData; -static void gradientVert_update(DMGradient_userData *grad_data, int index) +static void gradientVert_update(WPGradient_userData *grad_data, int index) { Mesh *me = grad_data->me; - DMGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; + WPGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; float alpha; if (grad_data->type == WPAINT_GRADIENT_TYPE_LINEAR) { @@ -617,10 +620,10 @@ static void gradientVertUpdate__mapFunc( void *userData, int index, const float UNUSED(co[3]), const float UNUSED(no_f[3]), const short UNUSED(no_s[3])) { - DMGradient_userData *grad_data = userData; + WPGradient_userData *grad_data = userData; Mesh *me = grad_data->me; if ((grad_data->use_select == false) || (me->mvert[index].flag & SELECT)) { - DMGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; + WPGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; if (vs->sco[0] != FLT_MAX) { gradientVert_update(grad_data, index); } @@ -631,7 +634,7 @@ static void gradientVertInit__mapFunc( void *userData, int index, const float co[3], const float UNUSED(no_f[3]), const short UNUSED(no_s[3])) { - DMGradient_userData *grad_data = userData; + WPGradient_userData *grad_data = userData; Mesh *me = grad_data->me; if ((grad_data->use_select == false) || (me->mvert[index].flag & SELECT)) { @@ -640,10 +643,11 @@ static void gradientVertInit__mapFunc( * updating the mesh may move them about (entering feedback loop) */ if (BLI_BITMAP_TEST(grad_data->vert_visit, index) == 0) { - DMGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; - if (ED_view3d_project_float_object(grad_data->ar, - co, vs->sco, - V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) + WPGradient_vertStore *vs = &grad_data->vert_cache->elem[index]; + if (ED_view3d_project_float_object( + grad_data->ar, + co, vs->sco, + V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { /* ok */ MDeformVert *dv = &me->dvert[index]; @@ -673,7 +677,7 @@ static void gradientVertInit__mapFunc( static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEvent *event) { wmGesture *gesture = op->customdata; - DMGradient_vertStoreBase *vert_cache = gesture->userdata; + WPGradient_vertStoreBase *vert_cache = gesture->userdata; int ret = WM_gesture_straightline_modal(C, op, event); if (ret & OPERATOR_RUNNING_MODAL) { @@ -695,7 +699,7 @@ static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEven } MEM_freeN(vert_cache); - 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); } else if (ret & OPERATOR_FINISHED) { @@ -709,7 +713,7 @@ static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEven static int paint_weight_gradient_exec(bContext *C, wmOperator *op) { wmGesture *gesture = op->customdata; - DMGradient_vertStoreBase *vert_cache; + WPGradient_vertStoreBase *vert_cache; struct ARegion *ar = CTX_wm_region(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); @@ -721,20 +725,21 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) float sco_start[2] = {x_start, y_start}; float sco_end[2] = {x_end, y_end}; const bool is_interactive = (gesture != NULL); - DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask); - DMGradient_userData data = {NULL}; + Depsgraph *depsgraph = CTX_data_depsgraph(C); + + WPGradient_userData data = {NULL}; if (is_interactive) { if (gesture->userdata == NULL) { gesture->userdata = MEM_mallocN( - sizeof(DMGradient_vertStoreBase) + - (sizeof(DMGradient_vertStore) * me->totvert), + sizeof(WPGradient_vertStoreBase) + + (sizeof(WPGradient_vertStore) * me->totvert), __func__); gesture->userdata_free = false; data.is_init = true; - wpaint_prev_create(&((DMGradient_vertStoreBase *)gesture->userdata)->wpp, me->dvert, me->totvert); + wpaint_prev_create(&((WPGradient_vertStoreBase *)gesture->userdata)->wpp, me->dvert, me->totvert); /* on init only, convert face -> vert sel */ if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { @@ -751,8 +756,8 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) data.is_init = true; vert_cache = MEM_mallocN( - sizeof(DMGradient_vertStoreBase) + - (sizeof(DMGradient_vertStore) * me->totvert), + sizeof(WPGradient_vertStoreBase) + + (sizeof(WPGradient_vertStore) * me->totvert), __func__); } @@ -781,19 +786,20 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) ED_view3d_init_mats_rv3d(ob, ar->regiondata); + Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob, scene->customdata_mask | CD_MASK_ORIGINDEX); if (data.is_init) { data.vert_visit = BLI_BITMAP_NEW(me->totvert, __func__); - dm->foreachMappedVert(dm, gradientVertInit__mapFunc, &data, DM_FOREACH_NOP); + BKE_mesh_foreach_mapped_vert(me_eval, gradientVertInit__mapFunc, &data, MESH_FOREACH_NOP); MEM_freeN(data.vert_visit); data.vert_visit = NULL; } else { - dm->foreachMappedVert(dm, gradientVertUpdate__mapFunc, &data, DM_FOREACH_NOP); + BKE_mesh_foreach_mapped_vert(me_eval, gradientVertUpdate__mapFunc, &data, MESH_FOREACH_NOP); } - 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); if (is_interactive == false) { @@ -845,7 +851,7 @@ void PAINT_OT_weight_gradient(wmOperatorType *ot) ot->invoke = paint_weight_gradient_invoke; ot->modal = paint_weight_gradient_modal; ot->exec = paint_weight_gradient_exec; - ot->poll = weight_paint_poll; + ot->poll = weight_paint_poll_ignore_tool; ot->cancel = WM_gesture_straightline_cancel; /* flags */ |