diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-02-16 12:24:38 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-02-16 16:01:25 +0300 |
commit | c28dea5e241a993ae9f3ca9f5208ad1e5010da63 (patch) | |
tree | 4dfb01fd21e8cd86ca709f1675b922b48957f5c3 /source/blender | |
parent | 31f47f44dee2f1625c584e73e3e7f35e0157dd2a (diff) |
Vertex Paint: expose exist paint-mode to API
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_object.h | 16 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 251 |
2 files changed, 185 insertions, 82 deletions
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 757a463f171..0452464f9d0 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -57,6 +57,7 @@ struct PropertyRNA; struct EnumPropertyItem; struct EvaluationContext; struct WorkSpace; +struct wmWindowManager; #include "DNA_object_enums.h" @@ -134,6 +135,21 @@ bool ED_object_editmode_load(struct Object *obedit); bool ED_object_editmode_calc_active_center(struct Object *obedit, const bool select_only, float r_center[3]); + +void ED_object_vpaintmode_enter_ex( + const struct EvaluationContext *eval_ctx, struct wmWindowManager *wm, + struct WorkSpace *workspace, struct Scene *scene, struct Object *ob); +void ED_object_vpaintmode_enter(struct bContext *C); +void ED_object_wpaintmode_enter_ex( + const struct EvaluationContext *eval_ctx, struct wmWindowManager *wm, + struct WorkSpace *workspace, struct Scene *scene, struct Object *ob); +void ED_object_wpaintmode_enter(struct bContext *C); + +void ED_object_vpaintmode_exit_ex(struct WorkSpace *workspace, struct Object *ob); +void ED_object_vpaintmode_exit(struct bContext *C); +void ED_object_wpaintmode_exit_ex(struct WorkSpace *workspace, struct Object *ob); +void ED_object_wpaintmode_exit(struct bContext *C); + void ED_object_location_from_view(struct bContext *C, float loc[3]); void ED_object_rotation_from_view(struct bContext *C, float rot[3], const char align_axis); void ED_object_base_init_transform(struct bContext *C, struct Base *base, const float loc[3], const float rot[3]); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 4fc6ba40fdc..8ce0af068d6 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1035,75 +1035,200 @@ static void vertex_paint_init_session_data( } -/* *************** set wpaint operator ****************** */ +/* -------------------------------------------------------------------- */ +/** \name Enter Vertex/Weight Paint Mode + * \{ */ -/** - * \note Keep in sync with #vpaint_mode_toggle_exec - */ -static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) +static void ed_vwpaintmode_enter_generic( + const EvaluationContext *eval_ctx, + wmWindowManager *wm, + WorkSpace *workspace, Scene *scene, + Object *ob, const eObjectMode mode_flag) +{ + workspace->object_mode |= mode_flag; + Mesh *me = BKE_mesh_from_object(ob); + + if (mode_flag == OB_MODE_VERTEX_PAINT) { + const ePaintMode paint_mode = ePaintVertex; + ED_mesh_color_ensure(me, NULL); + + if (scene->toolsettings->vpaint == NULL) { + scene->toolsettings->vpaint = new_vpaint(); + } + + Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); + paint_cursor_start_explicit(paint, wm, vertex_paint_poll); + BKE_paint_init(scene, paint_mode, PAINT_CURSOR_VERTEX_PAINT); + } + else if (mode_flag == OB_MODE_WEIGHT_PAINT) { + const ePaintMode paint_mode = ePaintWeight; + + if (scene->toolsettings->wpaint == NULL) { + scene->toolsettings->wpaint = new_vpaint(); + } + + Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); + paint_cursor_start_explicit(paint, wm, weight_paint_poll); + BKE_paint_init(scene, paint_mode, PAINT_CURSOR_WEIGHT_PAINT); + + /* weight paint specific */ + ED_mesh_mirror_spatial_table(ob, NULL, NULL, NULL, 's'); + ED_vgroup_sync_from_pose(ob); + } + else { + BLI_assert(0); + } + + /* Create vertex/weight paint mode session data */ + if (ob->sculpt) { + if (ob->sculpt->cache) { + sculpt_cache_free(ob->sculpt->cache); + ob->sculpt->cache = NULL; + } + BKE_sculptsession_free(ob); + } + + vertex_paint_init_session(eval_ctx, scene, ob); +} + +void ED_object_vpaintmode_enter_ex( + const EvaluationContext *eval_ctx, wmWindowManager *wm, + WorkSpace *workspace, Scene *scene, Object *ob) { + ed_vwpaintmode_enter_generic( + eval_ctx, wm, workspace, scene, ob, OB_MODE_VERTEX_PAINT); +} +void ED_object_vpaintmode_enter(struct bContext *C) +{ + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + wmWindowManager *wm = CTX_wm_manager(C); WorkSpace *workspace = CTX_wm_workspace(C); + Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - const int mode_flag = OB_MODE_WEIGHT_PAINT; - const bool is_mode_set = (workspace->object_mode & mode_flag) != 0; + ED_object_vpaintmode_enter_ex(&eval_ctx, wm, workspace, scene, ob); +} + +void ED_object_wpaintmode_enter_ex( + const EvaluationContext *eval_ctx, wmWindowManager *wm, + WorkSpace *workspace, Scene *scene, Object *ob) +{ + ed_vwpaintmode_enter_generic( + eval_ctx, wm, workspace, scene, ob, OB_MODE_WEIGHT_PAINT); +} +void ED_object_wpaintmode_enter(struct bContext *C) +{ + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + wmWindowManager *wm = CTX_wm_manager(C); + WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); - VPaint *wp = scene->toolsettings->wpaint; - Mesh *me; + Object *ob = CTX_data_active_object(C); + ED_object_wpaintmode_enter_ex(&eval_ctx, wm, workspace, scene, ob); +} - if (!is_mode_set) { - if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { - return OPERATOR_CANCELLED; - } - } +/** \} */ - me = BKE_mesh_from_object(ob); +/* -------------------------------------------------------------------- */ +/** \name Exit Vertex/Weight Paint Mode + * \{ */ - if (workspace->object_mode & mode_flag) { - workspace->object_mode &= ~mode_flag; +static void ed_vwpaintmode_exit_generic( + WorkSpace *workspace, + Object *ob, const eObjectMode mode_flag) +{ + Mesh *me = BKE_mesh_from_object(ob); + workspace->object_mode &= ~mode_flag; + if (mode_flag == OB_MODE_VERTEX_PAINT) { + if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { + BKE_mesh_flush_select_from_polys(me); + } + else if (me->editflag & ME_EDIT_PAINT_VERT_SEL) { + BKE_mesh_flush_select_from_verts(me); + } + } + else if (mode_flag == OB_MODE_WEIGHT_PAINT) { if (me->editflag & ME_EDIT_PAINT_VERT_SEL) { BKE_mesh_flush_select_from_verts(me); } else if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { BKE_mesh_flush_select_from_polys(me); } + } + else { + BLI_assert(0); + } - /* weight paint specific */ - ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e'); - ED_mesh_mirror_topo_table(NULL, NULL, 'e'); + /* If the cache is not released by a cancel or a done, free it now. */ + if (ob->sculpt->cache) { + sculpt_cache_free(ob->sculpt->cache); + ob->sculpt->cache = NULL; + } - /* If the cache is not released by a cancel or a done, free it now. */ - if (ob->sculpt->cache) { - sculpt_cache_free(ob->sculpt->cache); - ob->sculpt->cache = NULL; - } + BKE_sculptsession_free(ob); - BKE_sculptsession_free(ob); + paint_cursor_delete_textures(); - paint_cursor_delete_textures(); + if (mode_flag == OB_MODE_WEIGHT_PAINT) { + ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e'); + ED_mesh_mirror_topo_table(NULL, NULL, 'e'); } - else { - workspace->object_mode |= mode_flag; +} - if (wp == NULL) - wp = scene->toolsettings->wpaint = new_vpaint(); +void ED_object_vpaintmode_exit_ex(WorkSpace *workspace, Object *ob) +{ + ed_vwpaintmode_exit_generic(workspace, ob, OB_MODE_VERTEX_PAINT); +} +void ED_object_vpaintmode_exit(struct bContext *C) +{ + WorkSpace *workspace = CTX_wm_workspace(C); + Object *ob = CTX_data_active_object(C); + ED_object_vpaintmode_exit_ex(workspace, ob); +} - paint_cursor_start(C, weight_paint_poll); +void ED_object_wpaintmode_exit_ex(WorkSpace *workspace, Object *ob) +{ + ed_vwpaintmode_exit_generic(workspace, ob, OB_MODE_WEIGHT_PAINT); +} +void ED_object_wpaintmode_exit(struct bContext *C) +{ + WorkSpace *workspace = CTX_wm_workspace(C); + Object *ob = CTX_data_active_object(C); + ED_object_wpaintmode_exit_ex(workspace, ob); +} - BKE_paint_init(scene, ePaintWeight, PAINT_CURSOR_WEIGHT_PAINT); +/** \} */ - /* weight paint specific */ - ED_mesh_mirror_spatial_table(ob, NULL, NULL, NULL, 's'); - ED_vgroup_sync_from_pose(ob); +/* *************** set wpaint operator ****************** */ - /* Create vertex/weight paint mode session data */ - if (ob->sculpt) { - BKE_sculptsession_free(ob); +/** + * \note Keep in sync with #vpaint_mode_toggle_exec + */ +static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) +{ + WorkSpace *workspace = CTX_wm_workspace(C); + Object *ob = CTX_data_active_object(C); + const int mode_flag = OB_MODE_WEIGHT_PAINT; + const bool is_mode_set = (workspace->object_mode & mode_flag) != 0; + Scene *scene = CTX_data_scene(C); + + if (!is_mode_set) { + if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { + return OPERATOR_CANCELLED; } + } + Mesh *me = BKE_mesh_from_object(ob); + + if (is_mode_set) { + ED_object_wpaintmode_exit_ex(workspace, ob); + } + else { EvaluationContext eval_ctx; CTX_data_eval_ctx(C, &eval_ctx); - vertex_paint_init_session(&eval_ctx, scene, ob); + wmWindowManager *wm = CTX_wm_manager(C); + ED_object_wpaintmode_enter_ex(&eval_ctx, wm, workspace, scene, ob); } BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL); @@ -2225,8 +2350,6 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op) const int mode_flag = OB_MODE_VERTEX_PAINT; const bool is_mode_set = (workspace->object_mode & mode_flag) != 0; Scene *scene = CTX_data_scene(C); - VPaint *vp = scene->toolsettings->vpaint; - Mesh *me; if (!is_mode_set) { if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) { @@ -2234,53 +2357,17 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op) } } - me = BKE_mesh_from_object(ob); + Mesh *me = BKE_mesh_from_object(ob); /* toggle: end vpaint */ if (is_mode_set) { - workspace->object_mode &= ~mode_flag; - - if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { - BKE_mesh_flush_select_from_polys(me); - } - else if (me->editflag & ME_EDIT_PAINT_VERT_SEL) { - BKE_mesh_flush_select_from_verts(me); - } - - /* If the cache is not released by a cancel or a done, free it now. */ - if (ob->sculpt->cache) { - sculpt_cache_free(ob->sculpt->cache); - ob->sculpt->cache = NULL; - } - - BKE_sculptsession_free(ob); - - paint_cursor_delete_textures(); + ED_object_vpaintmode_exit_ex(workspace, ob); } else { - workspace->object_mode |= mode_flag; - - ED_mesh_color_ensure(me, NULL); - - if (vp == NULL) - vp = scene->toolsettings->vpaint = new_vpaint(); - - paint_cursor_start(C, vertex_paint_poll); - - BKE_paint_init(scene, ePaintVertex, PAINT_CURSOR_VERTEX_PAINT); - - /* Create vertex/weight paint mode session data */ - if (ob->sculpt) { - if (ob->sculpt->cache) { - sculpt_cache_free(ob->sculpt->cache); - ob->sculpt->cache = NULL; - } - BKE_sculptsession_free(ob); - } - EvaluationContext eval_ctx; CTX_data_eval_ctx(C, &eval_ctx); - vertex_paint_init_session(&eval_ctx, scene, ob); + wmWindowManager *wm = CTX_wm_manager(C); + ED_object_vpaintmode_enter_ex(&eval_ctx, wm, workspace, scene, ob); } BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL); |