81 if (dverts && dcount) {
132 {
ARM_GROUPS_AUTO,
"AUTOMATIC", 0,
"Automatic",
"Automatic weights from bones"},
137 "Weights from envelopes with user defined radius"},
138 {0,
nullptr, 0,
nullptr,
nullptr},
142 ot->
name =
"Weight from Bones";
143 ot->
idname =
"PAINT_OT_weight_from_bones";
145 (
"Set the weights of the groups matching the attached armature's bones that have \"Deform\" "
146 "option enabled, using the distance between the vertices and the bones");
158 ot->
srna,
"type", type_items, 0,
"Type",
"Method to use for assigning weights");
176 bool changed =
false;
182 if (
mesh && dvert && vc.
v3d && vc.
rv3d && (
mesh->vertex_group_active_index != 0)) {
210 if (v_idx_best != -1) {
213 if (
brush ==
nullptr) {
216 const int vgroup_active =
mesh->vertex_group_active_index - 1;
218 const int defbase_tot =
mesh->vertex_group_names.count();
220 bool *defbase_locked =
nullptr, *defbase_unlocked =
nullptr;
222 if (use_lock_relative) {
227 defbase_locked, defbase_unlocked, vgroup_active);
235 vc.
obact, defbase_tot, &defbase_tot_sel);
237 if (defbase_tot_sel > 1) {
240 vc.
obact, defbase_tot, defbase_sel, defbase_sel, &defbase_tot_sel);
243 use_lock_relative = use_lock_relative &&
245 defbase_tot, defbase_locked, defbase_sel, defbase_tot_sel);
249 &dvert[v_idx_best], defbase_tot, defbase_sel, defbase_tot_sel, is_normalized);
252 MEM_delete(defbase_sel);
255 if (use_lock_relative) {
257 defbase_tot, defbase_locked, defbase_unlocked, defbase_locked, defbase_unlocked);
260 vgroup_weight, &dvert[v_idx_best], defbase_tot, defbase_locked, defbase_unlocked);
263 MEM_SAFE_DELETE(defbase_locked);
264 MEM_SAFE_DELETE(defbase_unlocked);
266 CLAMP(vgroup_weight, 0.0f, 1.0f);
284 ot->
name =
"Weight Paint Sample Weight";
285 ot->
idname =
"PAINT_OT_weight_sample";
286 ot->
description =
"Use the mouse to sample a weight in the 3D view";
311 for (dw = dvert->
dw; i > 0; dw++, i--) {
312 if (dw->
def_nr >= groups.
size()) [[unlikely]] {
315 groups[dw->
def_nr] =
true;
331 if (
mesh->vertex_group_names.is_empty() || (dverts ==
nullptr)) {
359 for (
const int vert : corner_verts.
slice(faces[
index])) {
365 if (found ==
false) {
377 for (
const auto [i, dg] :
mesh->vertex_group_names.enumerate()) {
378 if (groups[i] ==
false) {
385 popup_menu_end(
C, pup);
393 ot->
name =
"Weight Paint Sample Group";
394 ot->
idname =
"PAINT_OT_weight_sample_group";
395 ot->
description =
"Select one of the vertex groups available under current mouse position";
416 int vgroup_active, vgroup_mirror = -1;
426 if (
mesh->faces_num == 0 || dvert ==
nullptr) {
445 if ((paint_selmode ==
SCE_SELECT_FACE) && !(!select_poly.is_empty() && select_poly[i])) {
449 for (
const int vert : corner_verts.
slice(faces[i])) {
450 if (!dvert[vert].flag) {
452 !(!select_vert.
is_empty() && select_vert[vert]))
468 if (vgroup_mirror != -1) {
481 dvert[vert].
flag = 1;
505 if (
brush ==
nullptr) {
524 ot->
name =
"Set Weight";
525 ot->
idname =
"PAINT_OT_weight_set";
526 ot->
description =
"Fill the active vertex group with the current paint weight";
624 CLAMP(testw, 0.0f, 1.0f);
736 if (vert_cache !=
nullptr) {
744 MEM_delete(vert_cache);
752 MEM_delete(vert_cache);
771 const float sco_start[2] = {
float(x_start),
float(y_start)};
772 const float sco_end[2] = {
float(x_end),
float(y_end)};
773 const bool is_interactive = (
gesture !=
nullptr);
779 if (is_interactive) {
780 if (
gesture->user_data.data ==
nullptr) {
784 gesture->user_data.use_free =
false;
812 data.region = region;
819 data.sco_start = sco_start;
820 data.sco_end = sco_end;
821 data.sco_line_div = 1.0f /
len_v2v2(sco_start, sco_end);
824 data.vert_cache = vert_cache;
825 data.vert_visit =
nullptr;
849 MEM_delete(
data.vert_visit);
850 data.vert_visit =
nullptr;
859 if (is_interactive ==
false) {
860 MEM_delete(vert_cache);
864 const int vgroup_num =
mesh->vertex_group_names.count();
868 std::memset(lock_flags, 0, vgroup_num);
869 lock_flags[
data.def_nr] =
true;
872 if (vgroup_validmap !=
nullptr) {
877 for (
int i = 0; i <
mesh->verts_num; i++) {
882 MEM_SAFE_DELETE(lock_flags);
883 MEM_delete(vgroup_validmap);
920 {0,
nullptr, 0,
nullptr,
nullptr},
926 ot->
name =
"Weight Gradient";
927 ot->
idname =
"PAINT_OT_weight_gradient";
928 ot->
description =
"Draw a line to apply a weight gradient to selected vertices";
General operations, lookup, etc. for blender objects.
#define BLI_BITMAP_NEW(_num, _alloc_string)
#define BLI_BITMAP_TEST(_bitmap, _index)
#define BLI_BITMAP_ENABLE(_bitmap, _index)
#define ME_USING_MIRROR_X_VERTEX_GROUPS(_me)
#define ME_EDIT_PAINT_SEL_MODE(_me)
Object is a sort of wrapper for general info.
#define ARM_GROUPS_ENVELOPE
#define ED_MESH_PICK_DEFAULT_VERT_DIST
#define ED_MESH_PICK_DEFAULT_FACE_DIST
Read Blender memory allocation and freeing.
constexpr int64_t size() const
constexpr Span slice(int64_t start, int64_t size) const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
GAttributeReader lookup(const StringRef name) const
constexpr bool is_empty() const
IndexRange index_range() const
ENUM_OPERATORS(Layer::Flags)
void mesh_select_face_flush(Mesh &mesh)
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void WM_main_add_notifier(uint type, void *reference)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static bool weight_from_bones_poll(bContext *C)
bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], uint dist_px, uint *r_index)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void BKE_defvert_array_free(MDeformVert *dvert, int totvert)
static void gradientVertInit__mapFunc(void *user_data, int index, const float co[3], const float[3])
int RNA_enum_get(PointerRNA *ptr, const char *name)
MINLINE void copy_v2_fl(float r[2], float f)
@ VP_FLAG_VGROUP_RESTRICT
bool ED_wpaint_ensure_data(bContext *C, ReportList *reports, eWPaintFlag flag, WPaintVGroupIndex *vgroup_index)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert)
static void gradientVertUpdate__mapFunc(void *user_data, int index, const float[3], const float[3])
void BKE_object_defgroup_mirror_selection(struct Object *ob, int defbase_tot, const bool *selection, bool *dg_flags_sel, int *r_dg_flags_sel_tot)
wmOperatorStatus WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
eV3DProjStatus ED_view3d_project_float_object(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void PAINT_OT_weight_sample_group(wmOperatorType *ot)
bool * BKE_object_defgroup_validmap_get(struct Object *ob, int defbase_tot)
wmOperatorStatus WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void wpaint_prev_destroy(WPaintPrev *wpp)
void BKE_defvert_array_free_elems(MDeformVert *dvert, int totvert)
Object * BKE_modifiers_is_deformed_by_armature(Object *ob)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
@ WPAINT_GRADIENT_TYPE_RADIAL
@ WPAINT_GRADIENT_TYPE_LINEAR
int mesh_get_x_mirror_vert(Object *ob, Mesh *mesh_eval, int index, bool use_topology)
int RNA_int_get(PointerRNA *ptr, const char *name)
void view3d_operator_needs_gpu(const bContext *C)
void BKE_object_defgroup_split_locked_validmap(int defbase_tot, const bool *locked, const bool *deform, bool *r_locked, bool *r_unlocked)
void ED_region_tag_redraw(ARegion *region)
int ED_wpaint_mirror_vgroup_ensure(Object *ob, const int vgroup_active)
static wmOperatorStatus paint_weight_gradient_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool * BKE_object_defgroup_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
void BKE_curvemapping_init(CurveMapping *cumap)
float BKE_defvert_find_weight(const MDeformVert *dvert, int defgroup)
static wmOperatorStatus weight_paint_set_exec(bContext *C, wmOperator *op)
bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], uint dist_px, uint *r_index)
static bool weight_paint_set(Object *ob, float paintweight)
bool weight_paint_mode_region_view3d_poll(bContext *C)
float BKE_defvert_lock_relative_weight(float weight, const MDeformVert *dv, int defbase_num, const bool *defbase_locked, const bool *defbase_unlocked)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
static wmOperatorStatus paint_weight_gradient_exec(bContext *C, wmOperator *op)
BMesh const char void * data
Mesh * BKE_mesh_from_object(Object *ob)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2])
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
MDeformWeight * BKE_defvert_ensure_index(MDeformVert *dv, int defgroup)
ToolSettings * CTX_data_tool_settings(const bContext *C)
void PAINT_OT_weight_sample(wmOperatorType *ot)
void ED_view3d_init_mats_rv3d(const Object *ob, RegionView3D *rv3d)
bool weight_paint_poll_ignore_tool(bContext *C)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
float BKE_brush_curve_strength_clamped(const Brush *br, float p, float len)
bool * BKE_object_defgroup_lock_flags_get(struct Object *ob, int defbase_tot)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
bool BKE_object_defgroup_check_lock_relative_multi(int defbase_tot, const bool *lock_flags, const bool *selected, int sel_tot)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Main * CTX_data_main(const bContext *C)
void PAINT_OT_weight_set(wmOperatorType *ot)
static void wpaint_prev_create(WPaintPrev *wpp, MDeformVert *dverts, int dcount)
void PAINT_OT_weight_from_bones(wmOperatorType *ot)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
bool BKE_object_defgroup_active_is_locked(const struct Object *ob)
float ED_wpaint_blend_tool(const int tool, const float weight, const float paintval, const float alpha)
void BKE_brush_weight_set(Paint *paint, Brush *brush, float value)
@ V3D_PROJ_TEST_CLIP_NEAR
void PAINT_OT_weight_gradient(wmOperatorType *ot)
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)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
static wmOperatorStatus weight_sample_group_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Brush * BKE_paint_brush(Paint *paint)
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_DEPENDS_ON_CURSOR
float BKE_brush_weight_get(const Paint *paint, const Brush *brush)
void ED_object_vgroup_calc_from_armature(ReportList *reports, Depsgraph *, Scene *scene, Object *ob, Object *par, const int mode, const bool mirror)
bool BKE_object_defgroup_check_lock_relative(const bool *lock_flags, const bool *validmap, int index)
void BKE_defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], uint dist_px, bool use_zbuf, uint *r_index)
static bool weight_paint_sample_mark_groups(const MDeformVert *dvert, MutableSpan< bool > groups)
Object * CTX_data_active_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
bool weight_paint_mode_poll(bContext *C)
static void wpaint_prev_init(WPaintPrev *wpp)
static void gradientVert_update(WPGradient_userData *grad_data, int index)
static wmOperatorStatus weight_sample_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus weight_from_bones_exec(bContext *C, wmOperator *op)
MDeformWeight * BKE_defvert_find_index(const MDeformVert *dv, int defgroup)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
float BKE_defvert_multipaint_collective_weight(const MDeformVert *dv, int defbase_num, const bool *defbase_sel, int defbase_sel_num, bool is_normalized)
static wmOperatorStatus paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_gesture_straightline_cancel(bContext *C, wmOperator *op)
void BKE_defvert_normalize_lock_map(MDeformVert &dvert, Span< bool > subset_flags, Span< bool > lock_flags)
int BKE_object_defgroup_active_index_get(const Object *ob)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct ToolSettings * toolsettings
WPGradient_vertStoreBase * vert_cache
VArraySpan< bool > select_vert
WPGradient_vertStore elem[0]
@ VGRAD_STORE_IS_MODIFIED
MDeformVert * wpaint_prev
void operator_context_set(wm::OpCallContext opcontext)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) cancel(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
struct wmOperatorType * type