76 if (dverts && dcount) {
128 {
ARM_GROUPS_AUTO,
"AUTOMATIC", 0,
"Automatic",
"Automatic weights from bones"},
133 "Weights from envelopes with user defined radius"},
134 {0,
nullptr, 0,
nullptr,
nullptr},
138 ot->
name =
"Weight from Bones";
139 ot->
idname =
"PAINT_OT_weight_from_bones";
141 (
"Set the weights of the groups matching the attached armature's selected bones, "
142 "using the distance between the vertices and the bones");
154 ot->
srna,
"type", type_items, 0,
"Type",
"Method to use for assigning weights");
172 bool changed =
false;
176 const MDeformVert *dvert = mesh->deform_verts().data();
178 if (mesh && dvert && vc.
v3d && vc.
rv3d && (mesh->vertex_group_active_index != 0)) {
206 if (v_idx_best != -1) {
209 const int vgroup_active = mesh->vertex_group_active_index - 1;
213 bool *defbase_locked =
nullptr, *defbase_unlocked =
nullptr;
215 if (use_lock_relative) {
220 defbase_locked, defbase_unlocked, vgroup_active);
228 vc.
obact, defbase_tot, &defbase_tot_sel);
230 if (defbase_tot_sel > 1) {
233 vc.
obact, defbase_tot, defbase_sel, defbase_sel, &defbase_tot_sel);
236 use_lock_relative = use_lock_relative &&
238 defbase_tot, defbase_locked, defbase_sel, defbase_tot_sel);
242 &dvert[v_idx_best], defbase_tot, defbase_sel, defbase_tot_sel, is_normalized);
248 if (use_lock_relative) {
250 defbase_tot, defbase_locked, defbase_unlocked, defbase_locked, defbase_unlocked);
253 vgroup_weight, &dvert[v_idx_best], defbase_tot, defbase_locked, defbase_unlocked);
259 CLAMP(vgroup_weight, 0.0f, 1.0f);
277 ot->
name =
"Weight Paint Sample Weight";
278 ot->
idname =
"PAINT_OT_weight_sample";
279 ot->
description =
"Use the mouse to sample a weight in the 3D view";
305 for (dw = dvert->
dw; i > 0; dw++, i--) {
309 groups[dw->
def_nr] =
true;
322 const MDeformVert *dverts = mesh->deform_verts().data();
351 for (
const int vert : corner_verts.
slice(faces[index])) {
357 if (found ==
false) {
370 if (groups[i] ==
false) {
386 ot->
name =
"Weight Paint Sample Group";
387 ot->
idname =
"PAINT_OT_weight_sample_group";
388 ot->
description =
"Select one of the vertex groups available under current mouse position";
410 int vgroup_active, vgroup_mirror = -1;
418 MDeformVert *dvert = mesh->deform_verts_for_write().data();
420 if (mesh->faces_num == 0 || dvert ==
nullptr) {
435 const VArraySpan select_vert = *attributes.lookup<
bool>(
".select_vert", bke::AttrDomain::Point);
436 const VArraySpan select_poly = *attributes.lookup<
bool>(
".select_poly", bke::AttrDomain::Face);
438 for (
const int i : faces.index_range()) {
439 if ((paint_selmode ==
SCE_SELECT_FACE) && !(!select_poly.is_empty() && select_poly[i])) {
443 for (
const int vert : corner_verts.
slice(faces[i])) {
444 if (!dvert[vert].
flag) {
446 !(!select_vert.
is_empty() && select_vert[vert]))
462 if (vgroup_mirror != -1) {
475 dvert[vert].
flag = 1;
482 for (
int index = mesh->verts_num; index != 0; index--, dv++) {
518 ot->
description =
"Fill the active vertex group with the current paint weight";
612 CLAMP(testw, 0.0f, 1.0f);
716 ret &= ~OPERATOR_RUNNING_MODAL;
722 if (vert_cache !=
nullptr) {
725 MDeformVert *dvert = mesh->deform_verts_for_write().data();
753 MDeformVert *dverts = mesh->deform_verts_for_write().data();
758 const float sco_start[2] = {
float(x_start),
float(y_start)};
759 const float sco_end[2] = {
float(x_end),
float(y_end)};
760 const bool is_interactive = (gesture !=
nullptr);
766 if (is_interactive) {
779 bke::mesh_select_face_flush(*mesh);
798 data.region = region;
802 data.select_vert = *attributes.lookup<
bool>(
".select_vert", bke::AttrDomain::Point);
803 data.hide_vert = *attributes.lookup_or_default<
bool>(
804 ".hide_vert", bke::AttrDomain::Point,
false);
805 data.sco_start = sco_start;
806 data.sco_end = sco_end;
807 data.sco_line_div = 1.0f /
len_v2v2(sco_start, sco_end);
810 data.vert_cache = vert_cache;
811 data.vert_visit =
nullptr;
836 data.vert_visit =
nullptr;
845 if (is_interactive ==
false) {
849 if (scene->toolsettings->auto_normalize) {
853 if (vgroup_validmap !=
nullptr) {
855 for (
int i = 0; i < mesh->verts_num; i++) {
857 if (lock_flags !=
nullptr) {
859 &dvert[i], vgroup_validmap, vgroup_num, lock_flags, vgroup_num);
901 {0,
nullptr, 0,
nullptr,
nullptr},
907 ot->
name =
"Weight Gradient";
908 ot->
idname =
"PAINT_OT_weight_gradient";
909 ot->
description =
"Draw a line to apply a weight gradient to selected vertices";
void BKE_brush_weight_set(const Scene *scene, Brush *brush, float value)
float BKE_brush_weight_get(const Scene *scene, const Brush *brush)
float BKE_brush_curve_strength_clamped(const Brush *br, float p, float len)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
Mesh * BKE_mesh_from_object(Object *ob)
void BKE_mesh_foreach_mapped_vert(const Mesh *mesh, void(*func)(void *user_data, int index, const float co[3], const float no[3]), void *user_data, MeshForeachFlag flag)
Object * BKE_modifiers_is_deformed_by_armature(Object *ob)
General operations, lookup, etc. for blender objects.
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Brush * BKE_paint_brush(Paint *paint)
void BKE_report(ReportList *reports, eReportType type, const char *message)
#define BLI_BITMAP_NEW(_num, _alloc_string)
#define BLI_BITMAP_TEST(_bitmap, _index)
#define BLI_BITMAP_ENABLE(_bitmap, _index)
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2])
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_fl(float r[2], float f)
#define ENUM_OPERATORS(_type, _max)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
#define ME_USING_MIRROR_X_VERTEX_GROUPS(_me)
#define ME_EDIT_PAINT_SEL_MODE(_me)
Object is a sort of wrapper for general info.
@ VP_FLAG_VGROUP_RESTRICT
#define ARM_GROUPS_ENVELOPE
#define ED_MESH_PICK_DEFAULT_VERT_DIST
int mesh_get_x_mirror_vert(Object *ob, Mesh *mesh_eval, int index, bool use_topology)
bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], uint dist_px, uint *r_index)
bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], uint dist_px, uint *r_index)
#define ED_MESH_PICK_DEFAULT_FACE_DIST
bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], uint dist_px, bool use_zbuf, uint *r_index)
void ED_region_tag_redraw(ARegion *region)
@ V3D_PROJ_TEST_CLIP_NEAR
eV3DProjStatus ED_view3d_project_float_object(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
void ED_view3d_init_mats_rv3d(const Object *ob, RegionView3D *rv3d)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
void view3d_operator_needs_opengl(const bContext *C)
Read Guarded memory(de)allocation.
void UI_popup_menu_end(bContext *C, uiPopupMenu *pup)
void uiItemFullO_ptr(uiLayout *layout, wmOperatorType *ot, const char *name, int icon, IDProperty *properties, wmOperatorCallContext context, eUI_Item_Flag flag, PointerRNA *r_opptr)
uiPopupMenu * UI_popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
uiLayout * UI_popup_menu_layout(uiPopupMenu *pup)
void uiLayoutSetOperatorContext(uiLayout *layout, wmOperatorCallContext opcontext)
@ OPTYPE_DEPENDS_ON_CURSOR
void ED_object_vgroup_calc_from_armature(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par, const int mode, const bool mirror)
constexpr Span slice(int64_t start, int64_t size) const
constexpr bool is_empty() const
const Depsgraph * depsgraph
draw_view in_light_buf[] float
void *(* MEM_mallocN)(size_t len, const char *str)
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
float ED_wpaint_blend_tool(int tool, float weight, float paintval, float alpha)
int ED_wpaint_mirror_vgroup_ensure(Object *ob, int vgroup_active)
@ WPAINT_GRADIENT_TYPE_RADIAL
@ WPAINT_GRADIENT_TYPE_LINEAR
bool weight_paint_mode_poll(bContext *C)
bool weight_paint_mode_region_view3d_poll(bContext *C)
bool weight_paint_poll_ignore_tool(bContext *C)
bool ED_wpaint_ensure_data(bContext *C, ReportList *reports, enum eWPaintFlag flag, WPaintVGroupIndex *vgroup_index)
static bool weight_paint_sample_mark_groups(const MDeformVert *dvert, blender::MutableSpan< bool > groups)
void PAINT_OT_weight_set(wmOperatorType *ot)
static int paint_weight_gradient_exec(bContext *C, wmOperator *op)
static bool weight_paint_set(Object *ob, float paintweight)
static int weight_from_bones_exec(bContext *C, wmOperator *op)
static int weight_paint_set_exec(bContext *C, wmOperator *op)
static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEvent *event)
void PAINT_OT_weight_sample(wmOperatorType *ot)
static int paint_weight_gradient_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void gradientVert_update(WPGradient_userData *grad_data, int index)
static void wpaint_prev_init(WPaintPrev *wpp)
static void gradientVertInit__mapFunc(void *user_data, int index, const float co[3], const float[3])
static int weight_sample_group_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool weight_from_bones_poll(bContext *C)
static void gradientVertUpdate__mapFunc(void *user_data, int index, const float[3], const float[3])
void PAINT_OT_weight_from_bones(wmOperatorType *ot)
void PAINT_OT_weight_gradient(wmOperatorType *ot)
static void wpaint_prev_destroy(WPaintPrev *wpp)
static void wpaint_prev_create(WPaintPrev *wpp, MDeformVert *dverts, int dcount)
void PAINT_OT_weight_sample_group(wmOperatorType *ot)
static int weight_sample_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
int RNA_int_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
struct CurveMapping * curve
struct ToolSettings * toolsettings
blender::VArray< bool > hide_vert
WPGradient_vertStoreBase * vert_cache
blender::VArraySpan< bool > select_vert
WPGradient_vertStore elem[0]
@ VGRAD_STORE_IS_MODIFIED
MDeformVert * wpaint_prev
wmGenericUserData user_data
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
int(* modal)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(* cancel)(bContext *C, wmOperator *op)
struct ReportList * reports
struct wmOperatorType * type
void WM_main_add_notifier(uint type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
int WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void WM_gesture_straightline_cancel(bContext *C, wmOperator *op)
int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)