Blender V4.3
paint_weight.cc File Reference
#include "MEM_guardedalloc.h"
#include "BLI_array_utils.h"
#include "BLI_color.hh"
#include "BLI_color_mix.hh"
#include "BLI_enumerable_thread_specific.hh"
#include "BLI_listbase.h"
#include "BLI_math_base.hh"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_task.h"
#include "BLI_task.hh"
#include "BLI_vector.hh"
#include "DNA_brush_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_particle_types.h"
#include "DNA_scene_types.h"
#include "RNA_access.hh"
#include "BKE_attribute.hh"
#include "BKE_brush.hh"
#include "BKE_context.hh"
#include "BKE_deform.hh"
#include "BKE_editmesh.hh"
#include "BKE_lib_id.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_mapping.hh"
#include "BKE_object.hh"
#include "BKE_object_deform.h"
#include "BKE_paint.hh"
#include "BKE_report.hh"
#include "DEG_depsgraph.hh"
#include "WM_api.hh"
#include "WM_message.hh"
#include "WM_toolsystem.hh"
#include "WM_types.hh"
#include "ED_image.hh"
#include "ED_mesh.hh"
#include "ED_object.hh"
#include "ED_paint.hh"
#include "ED_screen.hh"
#include "ED_view3d.hh"
#include "IMB_imbuf.hh"
#include "BKE_ccg.hh"
#include "bmesh.hh"
#include "mesh_brush_common.hh"
#include "paint_intern.hh"
#include "sculpt_automask.hh"
#include "sculpt_intern.hh"

Go to the source code of this file.

Classes

struct  WPaintAverageAccum
 
struct  WeightPaintGroupData
 
struct  WPaintData
 
struct  WeightPaintInfo
 

Functions

static MDeformVertdefweight_prev_init (MDeformVert *dvert_prev, MDeformVert *dvert_curr, int index)
 
static float wpaint_blend (const VPaint &wp, float weight, const float alpha, float paintval, const float, const bool do_flip)
 
static float wpaint_clamp_monotonic (float oldval, float curval, float newval)
 
static float wpaint_undo_lock_relative (float weight, float old_weight, float locked_weight, float free_weight, bool auto_normalize)
 
static void do_weight_paint_normalize_all (MDeformVert *dvert, const int defbase_tot, const bool *vgroup_validmap)
 
static bool do_weight_paint_normalize_all_locked (MDeformVert *dvert, const int defbase_tot, const bool *vgroup_validmap, const bool *lock_flags)
 
static void do_weight_paint_normalize_all_locked_try_active (MDeformVert *dvert, const int defbase_tot, const bool *vgroup_validmap, const bool *lock_flags, const bool *lock_with_active)
 
static void multipaint_clamp_change (MDeformVert *dvert, const int defbase_tot, const bool *defbase_sel, float *change_p)
 
static bool multipaint_verify_change (MDeformVert *dvert, const int defbase_tot, float change, const bool *defbase_sel)
 
static void multipaint_apply_change (MDeformVert *dvert, const int defbase_tot, float change, const bool *defbase_sel)
 
static void do_weight_paint_vertex_single (const VPaint &wp, Object &ob, const WeightPaintInfo &wpi, const uint index, float alpha, float paintweight)
 
static void do_weight_paint_vertex_multi (const VPaint &wp, Object &ob, const WeightPaintInfo &wpi, const uint index, float alpha, float paintweight)
 
static void do_weight_paint_vertex (const VPaint &wp, Object &ob, const WeightPaintInfo &wpi, const uint index, float alpha, float paintweight)
 
static bool wpaint_stroke_test_start (bContext *C, wmOperator *op, const float mouse[2])
 
static float wpaint_get_active_weight (const MDeformVert &dv, const WeightPaintInfo &wpi)
 
static void precompute_weight_values (Object &ob, const Brush &brush, WPaintData &wpd, WeightPaintInfo &wpi, Mesh &mesh)
 
Weight paint brushes.
static void parallel_nodes_loop_with_mirror_check (const Mesh &mesh, const IndexMask &node_mask, FunctionRef< void(IndexRange)> fn)
 
static void filter_factors_with_selection (const Span< bool > select_vert, const Span< int > verts, const MutableSpan< float > factors)
 
static void do_wpaint_brush_blur (const Depsgraph &depsgraph, const Scene &scene, Object &ob, const Brush &brush, VPaint &vp, WPaintData &wpd, const WeightPaintInfo &wpi, Mesh &mesh, const IndexMask &node_mask)
 
static void do_wpaint_brush_smear (const Depsgraph &depsgraph, const Scene &scene, Object &ob, const Brush &brush, VPaint &vp, WPaintData &wpd, const WeightPaintInfo &wpi, Mesh &mesh, const IndexMask &node_mask)
 
static void do_wpaint_brush_draw (const Depsgraph &depsgraph, const Scene &scene, Object &ob, const Brush &brush, VPaint &vp, WPaintData &wpd, const WeightPaintInfo &wpi, Mesh &mesh, const float strength, const IndexMask &node_mask)
 
static float calculate_average_weight (const Depsgraph &depsgraph, Object &ob, const Mesh &mesh, const Brush &brush, const VPaint &vp, WeightPaintInfo &wpi, const IndexMask &node_mask)
 
static void wpaint_paint_leaves (bContext *C, Object &ob, VPaint &vp, WPaintData &wpd, WeightPaintInfo &wpi, Mesh &mesh, const IndexMask &node_mask)
 
Enter Weight Paint Mode
void ED_object_wpaintmode_enter_ex (Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &ob)
 
void ED_object_wpaintmode_enter (bContext *C, Depsgraph &depsgraph)
 
Exit Weight Paint Mode
void ED_object_wpaintmode_exit_ex (Object &ob)
 
void ED_object_wpaintmode_exit (bContext *C)
 
Toggle Weight Paint Operator
bool weight_paint_mode_poll (bContext *C)
 
bool weight_paint_mode_region_view3d_poll (bContext *C)
 
static bool weight_paint_poll_ex (bContext *C, bool check_tool)
 
bool weight_paint_poll (bContext *C)
 
bool weight_paint_poll_ignore_tool (bContext *C)
 
static int wpaint_mode_toggle_exec (bContext *C, wmOperator *op)
 
void PAINT_OT_weight_paint_toggle (wmOperatorType *ot)
 
Weight Paint Operator
static void wpaint_do_paint (bContext *C, Object &ob, VPaint &wp, WPaintData &wpd, WeightPaintInfo &wpi, Mesh &mesh, Brush &brush, const ePaintSymmetryFlags symm, const int axis, const int i, const float angle)
 
static void wpaint_do_radial_symmetry (bContext *C, Object &ob, VPaint &wp, WPaintData &wpd, WeightPaintInfo &wpi, Mesh &mesh, Brush &brush, const ePaintSymmetryFlags symm, const int axis)
 
static void wpaint_do_symmetrical_brush_actions (bContext *C, Object &ob, VPaint &wp, WPaintData &wpd, WeightPaintInfo &wpi)
 
static void wpaint_stroke_update_step (bContext *C, wmOperator *, PaintStroke *stroke, PointerRNA *itemptr)
 
static void wpaint_stroke_done (const bContext *C, PaintStroke *)
 
static int wpaint_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
static int wpaint_exec (bContext *C, wmOperator *op)
 
static void wpaint_cancel (bContext *C, wmOperator *op)
 
static int wpaint_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
void PAINT_OT_weight_paint (wmOperatorType *ot)
 

Detailed Description

Used for vertex color & weight paint and mode switching.

Note
This file is already big, use paint_vertex_color_ops.cc & paint_vertex_weight_ops.cc for general purpose operators.

Definition in file paint_weight.cc.

Function Documentation

◆ calculate_average_weight()

◆ defweight_prev_init()

static MDeformVert * defweight_prev_init ( MDeformVert * dvert_prev,
MDeformVert * dvert_curr,
int index )
static

◆ do_weight_paint_normalize_all()

static void do_weight_paint_normalize_all ( MDeformVert * dvert,
const int defbase_tot,
const bool * vgroup_validmap )
static

◆ do_weight_paint_normalize_all_locked()

static bool do_weight_paint_normalize_all_locked ( MDeformVert * dvert,
const int defbase_tot,
const bool * vgroup_validmap,
const bool * lock_flags )
static

◆ do_weight_paint_normalize_all_locked_try_active()

static void do_weight_paint_normalize_all_locked_try_active ( MDeformVert * dvert,
const int defbase_tot,
const bool * vgroup_validmap,
const bool * lock_flags,
const bool * lock_with_active )
static
Note
same as function above except it does a second pass without active group if normalize fails with it.

Locks prevented the first pass from full completion, so remove restriction on active group; e.g:

  • With 1.0 weight painted into active: nonzero locked weight; first pass zeroed out unlocked weight; scale 1 down to fit.
  • With 0.0 weight painted into active: no unlocked groups; first pass did nothing; increase 0 to fit.

Definition at line 406 of file paint_weight.cc.

References do_weight_paint_normalize_all_locked().

Referenced by do_weight_paint_vertex_multi(), and do_weight_paint_vertex_single().

◆ do_weight_paint_vertex()

static void do_weight_paint_vertex ( const VPaint & wp,
Object & ob,
const WeightPaintInfo & wpi,
const uint index,
float alpha,
float paintweight )
static

◆ do_weight_paint_vertex_multi()

◆ do_weight_paint_vertex_single()

static void do_weight_paint_vertex_single ( const VPaint & wp,
Object & ob,
const WeightPaintInfo & wpi,
const uint index,
float alpha,
float paintweight )
static

◆ do_wpaint_brush_blur()

static void do_wpaint_brush_blur ( const Depsgraph & depsgraph,
const Scene & scene,
Object & ob,
const Brush & brush,
VPaint & vp,
WPaintData & wpd,
const WeightPaintInfo & wpi,
Mesh & mesh,
const IndexMask & node_mask )
static

◆ do_wpaint_brush_draw()

static void do_wpaint_brush_draw ( const Depsgraph & depsgraph,
const Scene & scene,
Object & ob,
const Brush & brush,
VPaint & vp,
WPaintData & wpd,
const WeightPaintInfo & wpi,
Mesh & mesh,
const float strength,
const IndexMask & node_mask )
static

◆ do_wpaint_brush_smear()

static void do_wpaint_brush_smear ( const Depsgraph & depsgraph,
const Scene & scene,
Object & ob,
const Brush & brush,
VPaint & vp,
WPaintData & wpd,
const WeightPaintInfo & wpi,
Mesh & mesh,
const IndexMask & node_mask )
static

Definition at line 1202 of file paint_weight.cc.

References brush_strength(), blender::ed::sculpt_paint::StrokeCache::bstrength, SculptSession::cache, blender::ed::sculpt_paint::calc_brush_distances(), blender::ed::sculpt_paint::calc_brush_strength_factors(), depsgraph, blender::ed::sculpt_paint::LocalData::distances, do_weight_paint_vertex(), dot_v3v3(), blender::ed::sculpt_paint::LocalData::factors, Brush::falloff_shape, blender::ed::sculpt_paint::fill_factor_from_hide(), blender::ed::sculpt_paint::filter_distances_with_radius(), filter_factors_with_selection(), blender::ed::sculpt_paint::vwpaint::get_brush_alpha_data(), blender::ed::sculpt_paint::StrokeCache::is_last_valid, blender::ed::sculpt_paint::StrokeCache::last_location_symm, blender::threading::EnumerableThreadSpecific< T >::local(), blender::ed::sculpt_paint::StrokeCache::location_symm, ME_EDIT_PAINT_FACE_SEL, ME_EDIT_PAINT_VERT_SEL, blender::bke::pbvh::Tree::nodes(), WPaintData::normal_angle_precalc, normalize_v3(), parallel_nodes_loop_with_mirror_check(), blender::bke::object::pbvh_get(), WPaintData::precomputed_weight, project_plane_v3_v3v3(), blender::ed::sculpt_paint::StrokeCache::radius, blender::Vector< T, InlineBufferCapacity, Allocator >::resize(), Object::sculpt, SCULPT_brush_frontface_normal_from_falloff_shape(), blender::index_mask::IndexMask::slice(), blender::Span< T >::slice(), sub_v3_v3v3(), blender::ed::sculpt_paint::vwpaint::test_brush_angle_falloff(), blender::ed::sculpt_paint::vwpaint::use_normal(), blender::bke::pbvh::vert_normals_eval(), blender::bke::pbvh::vert_positions_eval(), verts, and blender::ed::sculpt_paint::StrokeCache::view_normal_symm.

Referenced by wpaint_paint_leaves().

◆ ED_object_wpaintmode_enter()

void ED_object_wpaintmode_enter ( bContext * C,
Depsgraph & depsgraph )

◆ ED_object_wpaintmode_enter_ex()

void ED_object_wpaintmode_enter_ex ( Main & bmain,
Depsgraph & depsgraph,
Scene & scene,
Object & ob )

◆ ED_object_wpaintmode_exit()

void ED_object_wpaintmode_exit ( bContext * C)

Definition at line 1574 of file paint_weight.cc.

References CTX_data_active_object(), and ED_object_wpaintmode_exit_ex().

◆ ED_object_wpaintmode_exit_ex()

◆ filter_factors_with_selection()

static void filter_factors_with_selection ( const Span< bool > select_vert,
const Span< int > verts,
const MutableSpan< float > factors )
static

◆ multipaint_apply_change()

static void multipaint_apply_change ( MDeformVert * dvert,
const int defbase_tot,
float change,
const bool * defbase_sel )
static

◆ multipaint_clamp_change()

static void multipaint_clamp_change ( MDeformVert * dvert,
const int defbase_tot,
const bool * defbase_sel,
float * change_p )
static

◆ multipaint_verify_change()

static bool multipaint_verify_change ( MDeformVert * dvert,
const int defbase_tot,
float change,
const bool * defbase_sel )
static

◆ PAINT_OT_weight_paint()

◆ PAINT_OT_weight_paint_toggle()

◆ parallel_nodes_loop_with_mirror_check()

static void parallel_nodes_loop_with_mirror_check ( const Mesh & mesh,
const IndexMask & node_mask,
FunctionRef< void(IndexRange)> fn )
static

◆ precompute_weight_values()

static void precompute_weight_values ( Object & ob,
const Brush & brush,
WPaintData & wpd,
WeightPaintInfo & wpi,
Mesh & mesh )
static

◆ weight_paint_mode_poll()

◆ weight_paint_mode_region_view3d_poll()

bool weight_paint_mode_region_view3d_poll ( bContext * C)

◆ weight_paint_poll()

bool weight_paint_poll ( bContext * C)

◆ weight_paint_poll_ex()

◆ weight_paint_poll_ignore_tool()

bool weight_paint_poll_ignore_tool ( bContext * C)

Definition at line 1621 of file paint_weight.cc.

References weight_paint_poll_ex().

Referenced by PAINT_OT_weight_gradient().

◆ wpaint_blend()

static float wpaint_blend ( const VPaint & wp,
float weight,
const float alpha,
float paintval,
const float ,
const bool do_flip )
static

◆ wpaint_cancel()

◆ wpaint_clamp_monotonic()

static float wpaint_clamp_monotonic ( float oldval,
float curval,
float newval )
static

Definition at line 233 of file paint_weight.cc.

Referenced by do_weight_paint_vertex_multi(), and do_weight_paint_vertex_single().

◆ wpaint_do_paint()

◆ wpaint_do_radial_symmetry()

static void wpaint_do_radial_symmetry ( bContext * C,
Object & ob,
VPaint & wp,
WPaintData & wpd,
WeightPaintInfo & wpi,
Mesh & mesh,
Brush & brush,
const ePaintSymmetryFlags symm,
const int axis )
static

Definition at line 1717 of file paint_weight.cc.

References M_PI, VPaint::radial_symm, and wpaint_do_paint().

Referenced by wpaint_do_symmetrical_brush_actions().

◆ wpaint_do_symmetrical_brush_actions()

◆ wpaint_exec()

◆ wpaint_get_active_weight()

◆ wpaint_invoke()

◆ wpaint_modal()

static int wpaint_modal ( bContext * C,
wmOperator * op,
const wmEvent * event )
static

◆ wpaint_mode_toggle_exec()

◆ wpaint_paint_leaves()

◆ wpaint_stroke_done()

◆ wpaint_stroke_test_start()

static bool wpaint_stroke_test_start ( bContext * C,
wmOperator * op,
const float mouse[2] )
static

Definition at line 864 of file paint_weight.cc.

References WPaintVGroupIndex::active, ToolSettings::auto_normalize, BKE_mesh_from_object(), BKE_object_defgroup_check_lock_relative(), BKE_object_defgroup_check_lock_relative_multi(), BKE_object_defgroup_lock_flags_get(), BKE_object_defgroup_mirror_selection(), BKE_object_defgroup_selected_get(), BKE_object_defgroup_split_locked_validmap(), BKE_object_defgroup_validmap_get(), BKE_paint_brush(), BKE_paint_brush_for_read(), BKE_report(), BLI_array_binary_or, BLI_findlink(), BLI_listbase_count(), BRUSH_FRONTFACE_FALLOFF, CTX_data_active_object(), CTX_data_ensure_evaluated_depsgraph(), CTX_data_scene(), CTX_data_tool_settings(), wmOperator::customdata, blender::Array< T, InlineBufferCapacity, Allocator >::data(), depsgraph, DG_LOCK_WEIGHT, SculptSession::dvert_prev, ED_view3d_viewcontext_init(), ED_wpaint_ensure_data(), ELEM, Brush::falloff_angle, bDeformGroup::flag, Brush::flag, MDeformVert::flag, blender::ed::sculpt_paint::vwpaint::init_session_data(), blender::ed::sculpt_paint::vwpaint::init_stroke(), blender::Array< T, InlineBufferCapacity, Allocator >::is_empty(), ME_USING_MIRROR_X_VERTEX_GROUPS, MEM_callocN, MEM_dupallocN, MEM_freeN(), MEM_mallocN, WPaintVGroupIndex::mirror, SculptSession::mode, ToolSettings::multipaint, VPaint::paint, blender::ed::sculpt_paint::paint_stroke_set_mode_data(), wmOperator::reports, RPT_WARNING, Object::sculpt, blender::ed::sculpt_paint::vwpaint::update_cache_invariants(), blender::ed::sculpt_paint::vwpaint::view_angle_limits_init(), Brush::weight_brush_type, SculptSession::wpaint, ToolSettings::wpaint, WPAINT_BRUSH_TYPE_BLUR, WPAINT_BRUSH_TYPE_SMEAR, WPAINT_ENSURE_MIRROR, and ToolSettings::wpaint_lock_relative.

Referenced by wpaint_exec(), and wpaint_invoke().

◆ wpaint_stroke_update_step()

static void wpaint_stroke_update_step ( bContext * C,
wmOperator * ,
PaintStroke * stroke,
PointerRNA * itemptr )
static

Definition at line 1788 of file paint_weight.cc.

References WeightPaintInfo::active, WPaintData::active, ToolSettings::auto_normalize, BKE_brush_alpha_get(), BKE_mesh_batch_cache_dirty_tag(), BKE_MESH_BATCH_DIRTY_ALL, BKE_paint_brush(), BLI_rcti_is_empty(), BLI_rcti_union(), WeightPaintInfo::brush_alpha_value, SculptSession::cache, CTX_data_active_object(), CTX_data_scene(), CTX_data_tool_settings(), CTX_wm_region(), CTX_wm_region_view3d(), blender::ed::sculpt_paint::StrokeCache::current_r, Object::data, WeightPaintInfo::defbase_sel, WPaintData::defbase_sel, WeightPaintInfo::defbase_tot, WPaintData::defbase_tot, WeightPaintInfo::defbase_tot_sel, WPaintData::defbase_tot_sel, WeightPaintInfo::defbase_tot_unsel, DEG_id_tag_update(), WeightPaintInfo::do_auto_normalize, WeightPaintInfo::do_flip, WeightPaintInfo::do_lock_relative, WPaintData::do_lock_relative, WeightPaintInfo::do_multipaint, WPaintData::do_multipaint, WeightPaintInfo::dvert, ED_region_tag_redraw(), ED_region_tag_redraw_partial(), ED_view3d_init_mats_rv3d(), WeightPaintGroupData::index, blender::ed::sculpt_paint::StrokeCache::invert, WeightPaintInfo::is_normalized, blender::ed::sculpt_paint::vwpaint::last_stroke_update(), blender::ed::sculpt_paint::StrokeCache::location, WeightPaintInfo::lock_flags, WPaintData::lock_flags, WeightPaintInfo::mirror, WPaintData::mirror, mul_m4_m4m4(), mul_v3_m4v3(), NC_OBJECT, ND_DRAW, ViewContext::obact, VPaint::paint, blender::ed::sculpt_paint::paint_stroke_mode_data(), RegionView3D::persmat, precompute_weight_values(), WPaintData::precomputed_weight, blender::ed::sculpt_paint::StrokeCache::previous_r, ViewContext::region, RNA_boolean_get(), ViewContext::rv3d, Object::sculpt, SCULPT_get_redraw_rect(), swap_m4m4(), blender::ed::sculpt_paint::vwpaint::update_cache_variants(), WPaintData::vc, WeightPaintInfo::vgroup_locked, WPaintData::vgroup_locked, WeightPaintInfo::vgroup_unlocked, WPaintData::vgroup_unlocked, WeightPaintInfo::vgroup_validmap, WPaintData::vgroup_validmap, view3d_operator_needs_opengl(), ARegion::winrct, WM_event_add_notifier(), ToolSettings::wpaint, wpaint_do_symmetrical_brush_actions(), rcti::xmax, rcti::xmin, rcti::ymax, and rcti::ymin.

Referenced by wpaint_exec(), and wpaint_invoke().

◆ wpaint_undo_lock_relative()

static float wpaint_undo_lock_relative ( float weight,
float old_weight,
float locked_weight,
float free_weight,
bool auto_normalize )
static