Commit: 28e4e9b0247e001d10e90f5ed5f3be0866e6e9c6 Author: Darshan Kadu Date: Thu Jun 29 14:03:51 2017 +0530 Branches: soc-2017-vertex_paint https://developer.blender.org/rB28e4e9b0247e001d10e90f5ed5f3be0866e6e9c6
added weight to vertex paint converter =================================================================== M source/blender/editors/sculpt_paint/paint_intern.h M source/blender/editors/sculpt_paint/paint_ops.c M source/blender/editors/sculpt_paint/paint_vertex.c =================================================================== diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index f91a6baf6a9..718bd35167a 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -118,6 +118,7 @@ enum { WPAINT_GRADIENT_TYPE_RADIAL }; void PAINT_OT_weight_gradient(struct wmOperatorType *ot); +void PAINT_OT_weight_to_vertex_convert(struct wmOperatorType *ot); void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot); void PAINT_OT_vertex_paint(struct wmOperatorType *ot); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index ace18044bda..fc15556b6d9 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -1333,6 +1333,7 @@ void ED_operatortypes_paint(void) WM_operatortype_append(PAINT_OT_weight_gradient); WM_operatortype_append(PAINT_OT_weight_sample); WM_operatortype_append(PAINT_OT_weight_sample_group); + WM_operatortype_append(PAINT_OT_weight_to_vertex_convert); /* uv */ WM_operatortype_append(SCULPT_OT_uv_sculpt_stroke); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index e9384687888..6112fec5cca 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -4583,3 +4583,59 @@ void PAINT_OT_weight_gradient(wmOperatorType *ot) WM_operator_properties_gesture_straightline(ot, CURSOR_EDIT); } + +static bool weight_to_vert_convert(Object *ob) +{ + Mesh *me; + const MPoly *mp; + int vgroup_active; + + if (((me = BKE_mesh_from_object(ob)) == NULL || (me->dvert == NULL) || + (me->mloopcol == NULL && (make_vertexcol(ob)) == false))) + { + return false; + } + + mp = me->mpoly; + vgroup_active = ob->actdef - 1; + for (int i = 0; i < me->totpoly; i++, mp++) { + MLoopCol *lcol = &me->mloopcol[mp->loopstart]; + unsigned int fidx = mp->totloop - 1,j = 0; + do{ + unsigned int vidx = me->mloop[mp->loopstart + j].v; + if (1) { + const float weight = defvert_find_weight(&me->dvert[vidx], vgroup_active); + lcol->r = (-1.0f * weight +1) * 255; + lcol->b = (-1.0f * weight + 1) * 255; + lcol->g = (-1.0f * weight + 1) * 255; + } + lcol++; + j++; + } while (j <= fidx); + } + return true; +} + +static int weight_to_vert_convert_exec(bContext *C, wmOperator *op) +{ + Object *obact = CTX_data_active_object(C); + if (weight_to_vert_convert(obact)) { + return OPERATOR_FINISHED; + } + return OPERATOR_CANCELLED; +} + +void PAINT_OT_weight_to_vertex_convert(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Weight to Vertex Converter"; + ot->idname = "PAINT_OT_weight_to_vertex_convert"; + ot->description = "Converts the weight color into the black and white vertex color"; + + /* api callback */ + ot->exec = weight_to_vert_convert_exec; + ot->poll = weight_paint_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} \ No newline at end of file _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs