Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
| Show All 22 Lines | |||||
| */ | */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_brush_types.h" | |||||
| #include "BLI_math_base.h" | #include "BLI_math_base.h" | ||||
| #include "BLI_math_color.h" | #include "BLI_math_color.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_depsgraph.h" | #include "BKE_depsgraph.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| Show All 16 Lines | static int vertex_weight_paint_mode_poll(bContext *C) | ||||
| return (ob && (ob->mode == OB_MODE_VERTEX_PAINT || ob->mode == OB_MODE_WEIGHT_PAINT)) && | return (ob && (ob->mode == OB_MODE_VERTEX_PAINT || ob->mode == OB_MODE_WEIGHT_PAINT)) && | ||||
| (me && me->totpoly && me->dvert); | (me && me->totpoly && me->dvert); | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Set Vertex Colors Operator | /** \name Set Vertex Colors Operator | ||||
| * \{ */ | * \{ */ | ||||
| static bool vertex_color_set(Object *ob, uint paintcol) | static bool vertex_color_set(Object *ob, Scene *scene) | ||||
| { | { | ||||
| VPaint *vp = scene->toolsettings->vpaint; | |||||
| unsigned int paintcol = vpaint_get_current_col(scene, vp); | |||||
| unsigned int alpha = vpaint_get_current_alpha(scene, vp); | |||||
| int tool = vp->paint.brush->vertexpaint_tool; | |||||
| Mesh *me; | Mesh *me; | ||||
| const MPoly *mp; | const MPoly *mp; | ||||
| int i, j; | int i, j; | ||||
| if (((me = BKE_mesh_from_object(ob)) == NULL) || | if (((me = BKE_mesh_from_object(ob)) == NULL) || | ||||
| (ED_mesh_color_ensure(me, NULL) == false)) | (ED_mesh_color_ensure(me, NULL) == false)) | ||||
| { | { | ||||
| return false; | return false; | ||||
| } | } | ||||
| const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; | const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; | ||||
| const bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; | const bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; | ||||
| mp = me->mpoly; | mp = me->mpoly; | ||||
| for (i = 0; i < me->totpoly; i++, mp++) { | for (i = 0; i < me->totpoly; i++, mp++) { | ||||
| MLoopCol *lcol = me->mloopcol + mp->loopstart; | MLoopCol *lcol = me->mloopcol + mp->loopstart; | ||||
| if (use_face_sel && !(mp->flag & ME_FACE_SEL)) | if (use_face_sel && !(mp->flag & ME_FACE_SEL)) | ||||
| continue; | continue; | ||||
| j = 0; | j = 0; | ||||
| do { | do { | ||||
| uint vidx = me->mloop[mp->loopstart + j].v; | uint vidx = me->mloop[mp->loopstart + j].v; | ||||
| if (!(use_vert_sel && !(me->mvert[vidx].flag & SELECT))) { | if (!(use_vert_sel && !(me->mvert[vidx].flag & SELECT))) { | ||||
| *(int *)lcol = paintcol; | uchar vert_alpha = lcol->a; | ||||
| uint *col = (uint*) lcol; | |||||
| *((uint*) lcol) = ED_vpaint_blend_tool(tool, *((uint*) lcol), paintcol, alpha); | |||||
| lcol->a = vert_alpha; | |||||
| } | } | ||||
| lcol++; | lcol++; | ||||
| j++; | j++; | ||||
| } while (j < mp->totloop); | } while (j < mp->totloop); | ||||
| } | } | ||||
| /* remove stale me->mcol, will be added later */ | /* remove stale me->mcol, will be added later */ | ||||
| BKE_mesh_tessface_clear(me); | BKE_mesh_tessface_clear(me); | ||||
| DAG_id_tag_update(&me->id, 0); | DAG_id_tag_update(&me->id, 0); | ||||
| return true; | return true; | ||||
| } | } | ||||
| static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op)) | static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *obact = CTX_data_active_object(C); | Object *obact = CTX_data_active_object(C); | ||||
| unsigned int paintcol = vpaint_get_current_col(scene, scene->toolsettings->vpaint); | |||||
| if (vertex_color_set(obact, paintcol)) { | if (vertex_color_set(obact, scene)) { | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obact); | WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obact); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 455 Lines • Show Last 20 Lines | |||||