Blender V4.3
brush.cc File Reference
#include <array>
#include <optional>
#include "MEM_guardedalloc.h"
#include "DNA_ID.h"
#include "DNA_brush_types.h"
#include "DNA_defaults.h"
#include "DNA_material_types.h"
#include "DNA_scene_types.h"
#include "BLI_listbase.h"
#include "BLI_math_base.hh"
#include "BLI_math_rotation.h"
#include "BLI_rand.h"
#include "BLT_translation.hh"
#include "BKE_asset.hh"
#include "BKE_bpath.hh"
#include "BKE_brush.hh"
#include "BKE_colortools.hh"
#include "BKE_gpencil_legacy.h"
#include "BKE_grease_pencil.hh"
#include "BKE_idprop.hh"
#include "BKE_idtype.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_lib_remap.hh"
#include "BKE_main.hh"
#include "BKE_material.h"
#include "BKE_paint.hh"
#include "BKE_preview_image.hh"
#include "BKE_texture.h"
#include "IMB_colormanagement.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "RE_texture.h"
#include "BLO_read_write.hh"

Go to the source code of this file.

Macros

#define FROM_DEFAULT(member)    memcpy((void *)&brush->member, (void *)&brush_def->member, sizeof(brush->member))
 
#define FROM_DEFAULT_PTR(member)   memcpy(brush->member, brush_def->member, sizeof(brush->member))
 
#define BR_TEST(field, t)
 
#define BR_TEST_FLAG(_f)
 
#define BR_TEST_FLAG_OVERLAY(_f)
 

Functions

static void brush_init_data (ID *id)
 
static void brush_copy_data (Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int flag)
 
static void brush_free_data (ID *id)
 
static void brush_make_local (Main *bmain, ID *id, const int flags)
 
static void brush_foreach_id (ID *id, LibraryForeachIDData *data)
 
static void brush_foreach_path (ID *id, BPathForeachPathData *bpath_data)
 
static void brush_blend_write (BlendWriter *writer, ID *id, const void *id_address)
 
static void brush_blend_read_data (BlendDataReader *reader, ID *id)
 
static void brush_blend_read_after_liblink (BlendLibReader *, ID *id)
 
static void brush_asset_metadata_ensure (void *asset_ptr, AssetMetaData *asset_data)
 
void BKE_brush_system_init ()
 
void BKE_brush_system_exit ()
 
static void brush_defaults (Brush *brush)
 
BrushBKE_brush_add (Main *bmain, const char *name, const eObjectMode ob_mode)
 
void BKE_brush_init_gpencil_settings (Brush *brush)
 
bool BKE_brush_delete (Main *bmain, Brush *brush)
 
void BKE_brush_init_curves_sculpt_settings (Brush *brush)
 
void BKE_brush_tag_unsaved_changes (Brush *brush)
 
BrushBKE_brush_first_search (Main *bmain, const eObjectMode ob_mode)
 
void BKE_brush_debug_print_state (Brush *br)
 
void BKE_brush_curve_preset (Brush *b, eCurveMappingPreset preset)
 
const MTexBKE_brush_mask_texture_get (const Brush *brush, const eObjectMode object_mode)
 
const MTexBKE_brush_color_texture_get (const Brush *brush, const eObjectMode object_mode)
 
float BKE_brush_sample_tex_3d (const Scene *scene, const Brush *br, const MTex *mtex, const float point[3], float rgba[4], const int thread, ImagePool *pool)
 
float BKE_brush_sample_masktex (const Scene *scene, Brush *br, const float point[2], const int thread, ImagePool *pool)
 
const floatBKE_brush_color_get (const Scene *scene, const Paint *paint, const Brush *brush)
 
const floatBKE_brush_secondary_color_get (const Scene *scene, const Paint *paint, const Brush *brush)
 
void BKE_brush_color_set (Scene *scene, const Paint *paint, Brush *brush, const float color[3])
 
void BKE_brush_size_set (Scene *scene, Brush *brush, int size)
 
int BKE_brush_size_get (const Scene *scene, const Brush *brush)
 
bool BKE_brush_use_locked_size (const Scene *scene, const Brush *brush)
 
bool BKE_brush_use_size_pressure (const Brush *brush)
 
bool BKE_brush_use_alpha_pressure (const Brush *brush)
 
bool BKE_brush_sculpt_has_secondary_color (const Brush *brush)
 
void BKE_brush_unprojected_radius_set (Scene *scene, Brush *brush, float unprojected_radius)
 
float BKE_brush_unprojected_radius_get (const Scene *scene, const Brush *brush)
 
void BKE_brush_alpha_set (Scene *scene, Brush *brush, float alpha)
 
float BKE_brush_alpha_get (const Scene *scene, const Brush *brush)
 
float BKE_brush_weight_get (const Scene *scene, const Brush *brush)
 
void BKE_brush_weight_set (const Scene *scene, Brush *brush, float value)
 
int BKE_brush_input_samples_get (const Scene *scene, const Brush *brush)
 
void BKE_brush_input_samples_set (const Scene *scene, Brush *brush, int value)
 
void BKE_brush_scale_unprojected_radius (float *unprojected_radius, int new_brush_size, int old_brush_size)
 
void BKE_brush_scale_size (int *r_brush_size, float new_unprojected_radius, float old_unprojected_radius)
 
void BKE_brush_jitter_pos (const Scene &scene, const Brush &brush, const float pos[2], float jitterpos[2])
 
void BKE_brush_randomize_texture_coords (UnifiedPaintSettings *ups, bool mask)
 
void BKE_brush_calc_curve_factors (const eBrushCurvePreset preset, const CurveMapping *cumap, const blender::Span< float > distances, const float brush_radius, const blender::MutableSpan< float > factors)
 
float BKE_brush_curve_strength (const eBrushCurvePreset preset, const CurveMapping *cumap, const float distance, const float brush_radius)
 
float BKE_brush_curve_strength (const Brush *br, float p, const float len)
 
float BKE_brush_curve_strength_clamped (const Brush *br, float p, const float len)
 
static bool brush_gen_texture (const Brush *br, const int side, const bool use_secondary, float *rect)
 
ImBufBKE_brush_gen_radial_control_imbuf (Brush *br, bool secondary, bool display_gradient)
 
bool BKE_brush_has_cube_tip (const Brush *brush, PaintMode paint_mode)
 

Variables

static AssetTypeInfo AssetType_BR
 
IDTypeInfo IDType_ID_BR
 
static RNGbrush_rng
 

Macro Definition Documentation

◆ BR_TEST

#define BR_TEST ( field,
t )
Value:
if (br->field != def.field) { \
printf("br->" #field " = %" #t ";\n", br->field); \
} \
((void)0)

Referenced by BKE_brush_debug_print_state().

◆ BR_TEST_FLAG

#define BR_TEST_FLAG ( _f)
Value:
if ((br->flag & _f) && !(def.flag & _f)) { \
printf("br->flag |= " #_f ";\n"); \
} \
else if (!(br->flag & _f) && (def.flag & _f)) { \
printf("br->flag &= ~" #_f ";\n"); \
} \
((void)0)

Referenced by BKE_brush_debug_print_state().

◆ BR_TEST_FLAG_OVERLAY

#define BR_TEST_FLAG_OVERLAY ( _f)
Value:
if ((br->overlay_flags & _f) && !(def.overlay_flags & _f)) { \
printf("br->overlay_flags |= " #_f ";\n"); \
} \
else if (!(br->overlay_flags & _f) && (def.overlay_flags & _f)) { \
printf("br->overlay_flags &= ~" #_f ";\n"); \
} \
((void)0)

Referenced by BKE_brush_debug_print_state().

◆ FROM_DEFAULT

#define FROM_DEFAULT ( member)     memcpy((void *)&brush->member, (void *)&brush_def->member, sizeof(brush->member))

Referenced by brush_defaults().

◆ FROM_DEFAULT_PTR

#define FROM_DEFAULT_PTR ( member)    memcpy(brush->member, brush_def->member, sizeof(brush->member))

Referenced by brush_defaults().

Function Documentation

◆ BKE_brush_add()

Brush * BKE_brush_add ( Main * bmain,
const char * name,
eObjectMode ob_mode )
Note
Resulting brush will have two users: one as a fake user, another is assumed to be used by the caller.

Definition at line 542 of file brush.cc.

References BKE_brush_init_curves_sculpt_settings(), BKE_brush_init_gpencil_settings(), BKE_id_new(), ELEM, ID_BR, Brush::ob_mode, OB_MODE_PAINT_GREASE_PENCIL, OB_MODE_SCULPT_CURVES, OB_MODE_SCULPT_GREASE_PENCIL, OB_MODE_VERTEX_GREASE_PENCIL, and OB_MODE_WEIGHT_GREASE_PENCIL.

◆ BKE_brush_alpha_get()

◆ BKE_brush_alpha_set()

◆ BKE_brush_calc_curve_factors()

◆ BKE_brush_color_get()

◆ BKE_brush_color_set()

void BKE_brush_color_set ( Scene * scene,
const Paint * paint,
Brush * brush,
const float color[3] )

◆ BKE_brush_color_texture_get()

const MTex * BKE_brush_color_texture_get ( const Brush * brush,
const eObjectMode object_mode )

Get the color texture for this given object mode.

This is preferred above using mtex/mask_mtex attributes directly as due to legacy these attributes got switched in sculpt mode.

Definition at line 770 of file brush.cc.

References Brush::mask_mtex, Brush::mtex, and OB_MODE_SCULPT.

Referenced by do_projectpaint_thread().

◆ BKE_brush_curve_preset()

◆ BKE_brush_curve_strength() [1/2]

float BKE_brush_curve_strength ( const Brush * br,
float p,
const float len )

Definition at line 1439 of file brush.cc.

References BKE_brush_curve_strength(), Brush::curve, Brush::curve_preset, and len.

◆ BKE_brush_curve_strength() [2/2]

float BKE_brush_curve_strength ( eBrushCurvePreset preset,
const CurveMapping * cumap,
float distance,
float brush_radius )

Uses the brush curve control to find a strength value.

Definition at line 1388 of file brush.cc.

References BKE_curvemapping_evaluateF(), BRUSH_CURVE_CONSTANT, BRUSH_CURVE_CUSTOM, BRUSH_CURVE_INVSQUARE, BRUSH_CURVE_LIN, BRUSH_CURVE_POW4, BRUSH_CURVE_ROOT, BRUSH_CURVE_SHARP, BRUSH_CURVE_SMOOTH, BRUSH_CURVE_SMOOTHER, BRUSH_CURVE_SPHERE, distance(), pow3f(), and sqrtf.

Referenced by blender::ed::sculpt_paint::cloth::add_constraints_for_verts(), blender::ed::sculpt_paint::greasepencil::WeightPaintOperation::add_point_under_brush_to_brush_buffer(), BKE_brush_curve_strength(), BKE_brush_curve_strength_clamped(), blender::ed::sculpt_paint::greasepencil::brush_fill_influence(), blender::ed::sculpt_paint::greasepencil::brush_point_influence(), blender::ed::sculpt_paint::greasepencil::brush_point_influence_mask(), calc_strength(), blender::ed::sculpt_paint::CombOperationExecutor::comb_projected(), blender::ed::sculpt_paint::CombOperationExecutor::comb_spherical(), blender::ed::sculpt_paint::greasepencil::EraseOperationExecutor::compute_piecewise_linear_falloff(), blender::ed::sculpt_paint::PuffOperationExecutor::find_curve_weights_projected(), blender::ed::sculpt_paint::SlideOperationExecutor::find_curves_to_slide(), blender::ed::sculpt_paint::PuffOperationExecutor::find_curves_weights_spherical(), blender::ed::sculpt_paint::SmoothOperationExecutor::find_projected_smooth_factors(), blender::ed::sculpt_paint::SmoothOperationExecutor::find_spherical_smooth_factors(), blender::ed::sculpt_paint::CurvesEffectOperationExecutor::gather_influences_projected(), blender::ed::sculpt_paint::CurvesEffectOperationExecutor::gather_influences_spherical(), blender::ed::sculpt_paint::expand::gradient_value_get(), blender::ed::sculpt_paint::boundary::init_falloff_bmesh(), blender::ed::sculpt_paint::boundary::init_falloff_grids(), blender::ed::sculpt_paint::boundary::init_falloff_mesh(), blender::ed::sculpt_paint::paint_stroke_overlapped_curve(), blender::ed::sculpt_paint::PinchOperationExecutor::pinch_projected(), blender::ed::sculpt_paint::PinchOperationExecutor::pinch_spherical(), blender::ed::sculpt_paint::SnakeHookOperatorExecutor::projected_snake_hook(), blender::ed::sculpt_paint::DensityAddOperationExecutor::sample_projected_with_symmetry(), blender::ed::sculpt_paint::DensityAddOperationExecutor::sample_spherical_with_symmetry(), blender::ed::sculpt_paint::greasepencil::EraseOperationExecutor::soft_eraser(), blender::ed::sculpt_paint::pose::solve_roll_chain(), and blender::ed::sculpt_paint::SnakeHookOperatorExecutor::spherical_snake_hook().

◆ BKE_brush_curve_strength_clamped()

float BKE_brush_curve_strength_clamped ( const Brush * br,
float p,
float len )

◆ BKE_brush_debug_print_state()

◆ BKE_brush_delete()

bool BKE_brush_delete ( Main * bmain,
Brush * brush )

◆ BKE_brush_first_search()

Brush * BKE_brush_first_search ( Main * bmain,
const eObjectMode ob_mode )

Definition at line 628 of file brush.cc.

References Main::brushes, and LISTBASE_FOREACH.

◆ BKE_brush_gen_radial_control_imbuf()

ImBuf * BKE_brush_gen_radial_control_imbuf ( Brush * br,
bool secondary,
bool display_gradient )

◆ BKE_brush_has_cube_tip()

◆ BKE_brush_init_curves_sculpt_settings()

void BKE_brush_init_curves_sculpt_settings ( Brush * brush)

◆ BKE_brush_init_gpencil_settings()

◆ BKE_brush_input_samples_get()

int BKE_brush_input_samples_get ( const Scene * scene,
const Brush * brush )

◆ BKE_brush_input_samples_set()

void BKE_brush_input_samples_set ( const Scene * scene,
Brush * brush,
int value )

◆ BKE_brush_jitter_pos()

void BKE_brush_jitter_pos ( const Scene & scene,
const Brush & brush,
const float pos[2],
float jitterpos[2] )

◆ BKE_brush_mask_texture_get()

◆ BKE_brush_randomize_texture_coords()

◆ BKE_brush_sample_masktex()

◆ BKE_brush_sample_tex_3d()

◆ BKE_brush_scale_size()

void BKE_brush_scale_size ( int * r_brush_size,
float new_unprojected_radius,
float old_unprojected_radius )

Scale brush size to reflect a change in the brush's unprojected radius.

Definition at line 1212 of file brush.cc.

References int.

◆ BKE_brush_scale_unprojected_radius()

void BKE_brush_scale_unprojected_radius ( float * unprojected_radius,
int new_brush_size,
int old_brush_size )

Scale unprojected radius to reflect a change in the brush's 2D size.

Definition at line 1200 of file brush.cc.

References float.

◆ BKE_brush_sculpt_has_secondary_color()

◆ BKE_brush_secondary_color_get()

◆ BKE_brush_size_get()

int BKE_brush_size_get ( const Scene * scene,
const Brush * brush )

Definition at line 1075 of file brush.cc.

References UnifiedPaintSettings::flag, Brush::size, size(), UnifiedPaintSettings::size, and UNIFIED_PAINT_SIZE.

Referenced by BKE_brush_jitter_pos(), blender::ed::sculpt_paint::greasepencil::brush_radius(), blender::ed::sculpt_paint::brush_radius_get(), brush_scale_size_exec(), blender::ed::sculpt_paint::filter::cache_init(), blender::ed::sculpt_paint::trim::calculate_depth(), blender::ed::sculpt_paint::min_distance_edit::calculate_points_per_side(), blender::ed::sculpt_paint::dyntopo::dyntopo_detail_size_edit_invoke(), blender::ed::sculpt_paint::CombOperationExecutor::execute(), blender::ed::sculpt_paint::CurvesEffectOperationExecutor::execute(), blender::ed::sculpt_paint::DeleteOperationExecutor::execute(), blender::ed::sculpt_paint::DensitySubtractOperationExecutor::execute(), blender::ed::sculpt_paint::PinchOperationExecutor::execute(), blender::ed::sculpt_paint::PuffOperationExecutor::execute(), blender::ed::sculpt_paint::SelectionPaintOperationExecutor::execute(), blender::ed::sculpt_paint::SlideOperationExecutor::execute(), blender::ed::sculpt_paint::SmoothOperationExecutor::execute(), blender::ed::sculpt_paint::SnakeHookOperatorExecutor::execute(), blender::ed::sculpt_paint::vwpaint::get_brush_alpha_data(), blender::ed::sculpt_paint::greasepencil::WeightPaintOperation::get_brush_settings(), blender::ed::sculpt_paint::grease_pencil_brush_cursor_draw(), blender::ed::sculpt_paint::load_tex(), blender::ed::sculpt_paint::load_tex_cursor(), blender::ed::sculpt_paint::min_distance_edit::min_distance_edit_draw(), blender::ed::sculpt_paint::paint_brush_update(), blender::ed::sculpt_paint::paint_cursor_context_init(), blender::ed::sculpt_paint::paint_cursor_update_object_space_radius(), blender::ed::sculpt_paint::paint_cursor_update_pixel_radius(), blender::ed::sculpt_paint::paint_cursor_update_unprojected_radius(), blender::ed::sculpt_paint::paint_draw_cursor_overlay(), blender::ed::sculpt_paint::paint_draw_tex_overlay(), paint_proj_new_stroke(), blender::ed::sculpt_paint::paint_space_stroke_spacing(), blender::ed::sculpt_paint::paint_stroke_new(), project_paint_begin(), blender::ed::sculpt_paint::sculpt_calc_radius(), SCULPT_cursor_geometry_info_update(), blender::ed::sculpt_paint::smooth_brush_toggle_on(), blender::ed::sculpt_paint::vwpaint::smooth_brush_toggle_on(), texture_paint_camera_project_exec(), blender::ed::sculpt_paint::vwpaint::update_cache_variants(), blender::ed::sculpt_paint::update_modal_transform(), and blender::ed::sculpt_paint::use_add_density_mode().

◆ BKE_brush_size_set()

◆ BKE_brush_system_exit()

void BKE_brush_system_exit ( )

Definition at line 476 of file brush.cc.

References BLI_rng_free(), and brush_rng.

Referenced by BKE_blender_free().

◆ BKE_brush_system_init()

void BKE_brush_system_init ( )

Definition at line 470 of file brush.cc.

References BLI_rng_new(), BLI_rng_srandom(), and brush_rng.

Referenced by main().

◆ BKE_brush_tag_unsaved_changes()

void BKE_brush_tag_unsaved_changes ( Brush * brush)

Tag a linked brush as having changed settings so an indicator can be displayed to the user, showing that the brush settings differ from the state of the imported brush asset. Call every time a user visible change to the brush is done.

Since this is meant to indicate brushes that are known to differ from the linked source file, tagging is only performed for linked brushes. File local brushes are normal data-blocks that get saved with the file, and don't need special attention by the user.

For convenience, null may be passed for brush.

Definition at line 621 of file brush.cc.

References Brush::has_unsaved_changes, and ID_IS_LINKED.

Referenced by BKE_brush_alpha_set(), BKE_brush_color_set(), BKE_brush_curve_preset(), BKE_brush_input_samples_set(), BKE_brush_size_set(), BKE_brush_unprojected_radius_set(), BKE_brush_weight_set(), BKE_gpencil_brush_material_set(), brush_colors_flip_exec(), brush_scale_size_exec(), brush_sculpt_curves_falloff_preset_exec(), calculateCenterActive(), ED_render_id_flush_update(), blender::ui::greasepencil::eyedropper_set_brush_color(), flushTransPaintCurve(), grab_clone_apply(), grab_clone_modal(), blender::ed::sculpt_paint::grease_pencil_apply_fill(), blender::ed::sculpt_paint::min_distance_edit::min_distance_edit_modal(), paintcurve_delete_point_exec(), paintcurve_new_exec(), paintcurve_point_add(), paintcurve_slide_invoke(), set_current_brush_texture(), stencil_control_calculate(), stencil_fit_image_aspect_exec(), stencil_reset_transform_exec(), blender::ed::greasepencil::toggle_weight_tool_direction(), and ui_do_but_COLOR().

◆ BKE_brush_unprojected_radius_get()

◆ BKE_brush_unprojected_radius_set()

◆ BKE_brush_use_alpha_pressure()

◆ BKE_brush_use_locked_size()

◆ BKE_brush_use_size_pressure()

◆ BKE_brush_weight_get()

◆ BKE_brush_weight_set()

◆ brush_asset_metadata_ensure()

◆ brush_blend_read_after_liblink()

static void brush_blend_read_after_liblink ( BlendLibReader * ,
ID * id )
static

◆ brush_blend_read_data()

◆ brush_blend_write()

◆ brush_copy_data()

◆ brush_defaults()

static void brush_defaults ( Brush * brush)
static

◆ brush_foreach_id()

◆ brush_foreach_path()

static void brush_foreach_path ( ID * id,
BPathForeachPathData * bpath_data )
static

Definition at line 215 of file brush.cc.

References BKE_bpath_foreach_path_fixed_process(), and Brush::icon_filepath.

◆ brush_free_data()

◆ brush_gen_texture()

static bool brush_gen_texture ( const Brush * br,
const int side,
const bool use_secondary,
float * rect )
static

Definition at line 1454 of file brush.cc.

References Brush::mask_mtex, Brush::mtex, RE_texture_evaluate(), MTex::tex, x, and y.

Referenced by BKE_brush_gen_radial_control_imbuf().

◆ brush_init_data()

◆ brush_make_local()

Variable Documentation

◆ AssetType_BR

AssetTypeInfo AssetType_BR
static
Initial value:
= {
}
static void brush_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_data)
Definition brush.cc:388

Definition at line 432 of file brush.cc.

◆ brush_rng

◆ IDType_ID_BR

IDTypeInfo IDType_ID_BR
Initial value:
= {
sizeof(Brush),
"Brush",
N_("brushes"),
nullptr,
nullptr,
nullptr,
nullptr,
}
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition BKE_idtype.hh:41
@ IDTYPE_FLAGS_NO_MEMFILE_UNDO
Definition BKE_idtype.hh:50
#define BLT_I18NCONTEXT_ID_BRUSH
#define FILTER_ID_MA
Definition DNA_ID.h:1175
#define FILTER_ID_BR
Definition DNA_ID.h:1166
#define FILTER_ID_TE
Definition DNA_ID.h:1187
@ INDEX_ID_BR
Definition DNA_ID.h:1314
#define FILTER_ID_PC
Definition DNA_ID.h:1183
#define FILTER_ID_IM
Definition DNA_ID.h:1171
@ ID_BR
static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition brush.cc:224
static void brush_free_data(ID *id)
Definition brush.cc:121
static AssetTypeInfo AssetType_BR
Definition brush.cc:432
static void brush_blend_read_after_liblink(BlendLibReader *, ID *id)
Definition brush.cc:371
static void brush_foreach_id(ID *id, LibraryForeachIDData *data)
Definition brush.cc:199
static void brush_init_data(ID *id)
Definition brush.cc:51
static void brush_make_local(Main *bmain, ID *id, const int flags)
Definition brush.cc:154
static void brush_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int flag)
Definition brush.cc:65
static void brush_blend_read_data(BlendDataReader *reader, ID *id)
Definition brush.cc:281
static void brush_foreach_path(ID *id, BPathForeachPathData *bpath_data)
Definition brush.cc:215
#define N_(msgid)

Definition at line 437 of file brush.cc.