WIP: Brush assets project #106303

Draft
Julian Eisel wants to merge 358 commits from brush-assets-project into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
25 changed files with 115 additions and 90 deletions
Showing only changes of commit 05ab2baacc - Show all commits

View File

@ -1392,7 +1392,7 @@ void BKE_brush_gpencil_paint_presets(Main *bmain, ToolSettings *ts, const bool r
bool is_new = false;
Paint *paint = &ts->gp_paint->paint;
Brush *brush_prev = paint->brush;
Brush *brush_prev = BKE_paint_brush(paint);
Brush *brush, *deft_draw;
/* Airbrush brush. */
brush = gpencil_brush_ensure(bmain, ts, "Airbrush", OB_MODE_PAINT_GPENCIL_LEGACY, &is_new);
@ -1493,7 +1493,7 @@ void BKE_brush_gpencil_vertex_presets(Main *bmain, ToolSettings *ts, const bool
bool is_new = false;
Paint *vertexpaint = &ts->gp_vertexpaint->paint;
Brush *brush_prev = vertexpaint->brush;
Brush *brush_prev = BKE_paint_brush(vertexpaint);
Brush *brush, *deft_vertex;
/* Vertex Draw brush. */
brush = gpencil_brush_ensure(bmain, ts, "Vertex Draw", OB_MODE_VERTEX_GPENCIL_LEGACY, &is_new);
@ -1541,7 +1541,7 @@ void BKE_brush_gpencil_sculpt_presets(Main *bmain, ToolSettings *ts, const bool
bool is_new = false;
Paint *sculptpaint = &ts->gp_sculptpaint->paint;
Brush *brush_prev = sculptpaint->brush;
Brush *brush_prev = BKE_paint_brush(sculptpaint);
Brush *brush, *deft_sculpt;
/* Smooth brush. */
@ -1618,7 +1618,7 @@ void BKE_brush_gpencil_weight_presets(Main *bmain, ToolSettings *ts, const bool
bool is_new = false;
Paint *weightpaint = &ts->gp_weightpaint->paint;
Brush *brush_prev = weightpaint->brush;
Brush *brush_prev = BKE_paint_brush(weightpaint);
Brush *brush, *deft_weight;
/* Weight Draw brush. */

View File

@ -1749,9 +1749,9 @@ Material *BKE_gpencil_object_material_ensure_from_active_input_toolsettings(Main
Object *ob,
ToolSettings *ts)
{
if (ts && ts->gp_paint && ts->gp_paint->paint.brush) {
if (ts && ts->gp_paint && BKE_paint_brush(&ts->gp_paint->paint)) {
return BKE_gpencil_object_material_ensure_from_active_input_brush(
bmain, ob, ts->gp_paint->paint.brush);
bmain, ob, BKE_paint_brush(&ts->gp_paint->paint));
}
return BKE_gpencil_object_material_ensure_from_active_input_brush(bmain, ob, nullptr);

View File

@ -262,7 +262,7 @@ void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const
return;
}
Brush *br = p->brush;
Brush *br = BKE_paint_brush(p);
if (!br) {
return;
}
@ -282,7 +282,7 @@ void BKE_paint_invalidate_cursor_overlay(Scene *scene, ViewLayer *view_layer, Cu
return;
}
Brush *br = p->brush;
Brush *br = BKE_paint_brush(p);
if (br && br->curve == curve) {
overlay_flags |= PAINT_OVERLAY_INVALID_CURVE;
}

View File

@ -75,8 +75,9 @@ static bool is_cursor_visible(const DRWContextState *draw_ctx, Scene *scene, Vie
/* exception: object in texture paint mode, clone brush, use_clone_layer disabled */
else if (draw_ctx->object_mode & OB_MODE_TEXTURE_PAINT) {
const Paint *p = BKE_paint_get_active(scene, view_layer);
const Brush *brush = (p) ? BKE_paint_brush_for_read(p) : nullptr;
if (p && p->brush && p->brush->imagepaint_tool == PAINT_TOOL_CLONE) {
if (brush && brush->imagepaint_tool == PAINT_TOOL_CLONE) {
if ((scene->toolsettings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) == 0) {
return true;
}

View File

@ -1961,12 +1961,11 @@ static int gpencil_brush_reset_exec(bContext *C, wmOperator * /*op*/)
Main *bmain = CTX_data_main(C);
ToolSettings *ts = CTX_data_tool_settings(C);
const enum eContextObjectMode mode = CTX_data_mode_enum(C);
Brush *brush = nullptr;
switch (mode) {
case CTX_MODE_PAINT_GPENCIL_LEGACY: {
Paint *paint = &ts->gp_paint->paint;
brush = paint->brush;
Brush *brush = BKE_paint_brush(paint);
if (brush && brush->gpencil_settings) {
BKE_gpencil_brush_preset_set(bmain, brush, brush->gpencil_settings->preset_type);
}
@ -1974,7 +1973,7 @@ static int gpencil_brush_reset_exec(bContext *C, wmOperator * /*op*/)
}
case CTX_MODE_SCULPT_GPENCIL_LEGACY: {
Paint *paint = &ts->gp_sculptpaint->paint;
brush = paint->brush;
Brush *brush = BKE_paint_brush(paint);
if (brush && brush->gpencil_settings) {
BKE_gpencil_brush_preset_set(bmain, brush, brush->gpencil_settings->preset_type);
}
@ -1982,7 +1981,7 @@ static int gpencil_brush_reset_exec(bContext *C, wmOperator * /*op*/)
}
case CTX_MODE_WEIGHT_GPENCIL_LEGACY: {
Paint *paint = &ts->gp_weightpaint->paint;
brush = paint->brush;
Brush *brush = BKE_paint_brush(paint);
if (brush && brush->gpencil_settings) {
BKE_gpencil_brush_preset_set(bmain, brush, brush->gpencil_settings->preset_type);
}
@ -1990,7 +1989,7 @@ static int gpencil_brush_reset_exec(bContext *C, wmOperator * /*op*/)
}
case CTX_MODE_VERTEX_GPENCIL_LEGACY: {
Paint *paint = &ts->gp_vertexpaint->paint;
brush = paint->brush;
Brush *brush = BKE_paint_brush(paint);
if (brush && brush->gpencil_settings) {
BKE_gpencil_brush_preset_set(bmain, brush, brush->gpencil_settings->preset_type);
}
@ -2057,7 +2056,7 @@ static void gpencil_brush_delete_mode_brushes(Main *bmain,
Paint *paint,
const enum eContextObjectMode mode)
{
Brush *brush_active = paint->brush;
Brush *brush_active = BKE_paint_brush(paint);
Brush *brush_next = nullptr;
for (Brush *brush = static_cast<Brush *>(bmain->brushes.first); brush; brush = brush_next) {
brush_next = static_cast<Brush *>(brush->id.next);
@ -2151,8 +2150,8 @@ static int gpencil_brush_reset_all_exec(bContext *C, wmOperator * /*op*/)
char tool = '0';
if (paint) {
if (paint->brush) {
Brush *brush_active = paint->brush;
Brush *brush_active = BKE_paint_brush(paint);
if (brush_active) {
switch (mode) {
case CTX_MODE_PAINT_GPENCIL_LEGACY: {
tool = brush_active->gpencil_tool;

View File

@ -395,8 +395,9 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op)
BKE_gpencil_palette_ensure(bmain, CTX_data_scene(C));
Paint *paint = &ts->gp_paint->paint;
Brush *brush = BKE_paint_brush(paint);
/* if not exist, create a new one */
if ((paint->brush == nullptr) || (paint->brush->gpencil_settings == nullptr)) {
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
BKE_brush_gpencil_paint_presets(bmain, ts, true);
}
BKE_paint_toolslots_brush_validate(bmain, &ts->gp_paint->paint);
@ -503,7 +504,7 @@ static int gpencil_sculptmode_toggle_exec(bContext *C, wmOperator *op)
/* Be sure we have brushes. */
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_sculptpaint);
const bool reset_mode = (ts->gp_sculptpaint->paint.brush == nullptr);
const bool reset_mode = (BKE_paint_brush(&ts->gp_sculptpaint->paint) == nullptr);
BKE_brush_gpencil_sculpt_presets(bmain, ts, reset_mode);
BKE_paint_toolslots_brush_validate(bmain, &ts->gp_sculptpaint->paint);
@ -617,7 +618,7 @@ static int gpencil_weightmode_toggle_exec(bContext *C, wmOperator *op)
/* Be sure we have brushes. */
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_weightpaint);
const bool reset_mode = (ts->gp_weightpaint->paint.brush == nullptr);
const bool reset_mode = (BKE_paint_brush(&ts->gp_weightpaint->paint) == nullptr);
BKE_brush_gpencil_weight_presets(bmain, ts, reset_mode);
BKE_paint_toolslots_brush_validate(bmain, &ts->gp_weightpaint->paint);
@ -725,7 +726,7 @@ static int gpencil_vertexmode_toggle_exec(bContext *C, wmOperator *op)
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint);
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_vertexpaint);
const bool reset_mode = (ts->gp_vertexpaint->paint.brush == nullptr);
const bool reset_mode = (BKE_paint_brush(&ts->gp_vertexpaint->paint) == nullptr);
BKE_brush_gpencil_vertex_presets(bmain, ts, reset_mode);
BKE_paint_toolslots_brush_validate(bmain, &ts->gp_vertexpaint->paint);

View File

@ -22,6 +22,7 @@
#include "BKE_gpencil_geom_legacy.h"
#include "BKE_gpencil_legacy.h"
#include "BKE_material.h"
#include "BKE_paint.hh"
#include "BKE_report.hh"
#include "WM_api.hh"
@ -97,12 +98,13 @@ static bGPDstroke *gpencil_prepare_stroke(bContext *C, wmOperator *op, int totpo
const bool cyclic = RNA_boolean_get(op->ptr, "cyclic");
Paint *paint = &ts->gp_paint->paint;
Brush *brush = BKE_paint_brush(paint);
/* if not exist, create a new one */
if ((paint->brush == nullptr) || (paint->brush->gpencil_settings == nullptr)) {
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
/* create new brushes */
BKE_brush_gpencil_paint_presets(bmain, ts, false);
}
Brush *brush = paint->brush;
brush = BKE_paint_brush(paint);
/* frame */
short add_frame_mode;

View File

@ -302,7 +302,7 @@ static bool gpencil_draw_poll(bContext *C)
}
ToolSettings *ts = CTX_data_scene(C)->toolsettings;
if (!ts->gp_paint->paint.brush) {
if (!BKE_paint_brush(&ts->gp_paint->paint)) {
CTX_wm_operator_poll_msg_set(C, "Grease Pencil has no active paint tool");
return false;
}
@ -1919,7 +1919,7 @@ static Brush *gpencil_get_default_eraser(Main *bmain, ToolSettings *ts)
{
Brush *brush_dft = nullptr;
Paint *paint = &ts->gp_paint->paint;
Brush *brush_prev = paint->brush;
Brush *brush_prev = BKE_paint_brush(paint);
for (Brush *brush = static_cast<Brush *>(bmain->brushes.first); brush;
brush = static_cast<Brush *>(brush->id.next))
{
@ -1989,30 +1989,33 @@ static void gpencil_init_drawing_brush(bContext *C, tGPsdata *p)
Paint *paint = &ts->gp_paint->paint;
bool changed = false;
Brush *brush = BKE_paint_brush(paint);
/* if not exist, create a new one */
if ((paint->brush == nullptr) || (paint->brush->gpencil_settings == nullptr)) {
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
/* create new brushes */
BKE_brush_gpencil_paint_presets(bmain, ts, true);
changed = true;
brush = BKE_paint_brush(paint);
}
/* Be sure curves are initialized. */
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_sensitivity);
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_strength);
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_jitter);
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_rand_pressure);
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_rand_strength);
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_rand_uv);
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_rand_hue);
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_rand_saturation);
BKE_curvemapping_init(paint->brush->gpencil_settings->curve_rand_value);
BKE_curvemapping_init(brush->gpencil_settings->curve_sensitivity);
BKE_curvemapping_init(brush->gpencil_settings->curve_strength);
BKE_curvemapping_init(brush->gpencil_settings->curve_jitter);
BKE_curvemapping_init(brush->gpencil_settings->curve_rand_pressure);
BKE_curvemapping_init(brush->gpencil_settings->curve_rand_strength);
BKE_curvemapping_init(brush->gpencil_settings->curve_rand_uv);
BKE_curvemapping_init(brush->gpencil_settings->curve_rand_hue);
BKE_curvemapping_init(brush->gpencil_settings->curve_rand_saturation);
BKE_curvemapping_init(brush->gpencil_settings->curve_rand_value);
/* Assign to temp #tGPsdata */
p->brush = paint->brush;
if (paint->brush->gpencil_tool != GPAINT_TOOL_ERASE) {
p->brush = BKE_paint_brush(paint);
if (p->brush->gpencil_tool != GPAINT_TOOL_ERASE) {
p->eraser = gpencil_get_default_eraser(p->bmain, ts);
}
else {
p->eraser = paint->brush;
p->eraser = p->brush;
}
/* set new eraser as default */
gpencil_set_default_eraser(p->bmain, p->eraser);

View File

@ -1211,7 +1211,8 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
gpencil_point_conversion_init(C, &tgpi->gsc);
/* if brush doesn't exist, create a new set (fix damaged files from old versions) */
if ((paint->brush == nullptr) || (paint->brush->gpencil_settings == nullptr)) {
Brush *brush = BKE_paint_brush(paint);
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
BKE_brush_gpencil_paint_presets(bmain, ts, true);
}

View File

@ -43,6 +43,7 @@
#include "BKE_gpencil_modifier_legacy.h"
#include "BKE_main.hh"
#include "BKE_material.h"
#include "BKE_paint.hh"
#include "BKE_report.hh"
#include "UI_interface.hh"
@ -1202,7 +1203,7 @@ static bool gpencil_sculpt_brush_init(bContext *C, wmOperator *op)
gso->region = CTX_wm_region(C);
Paint *paint = &ts->gp_sculptpaint->paint;
Brush *brush = paint->brush;
Brush *brush = BKE_paint_brush(paint);
gso->brush = brush;
BKE_curvemapping_init(gso->brush->curve);

View File

@ -328,7 +328,7 @@ bool gpencil_active_brush_poll(bContext *C)
ToolSettings *ts = CTX_data_tool_settings(C);
Paint *paint = &ts->gp_paint->paint;
if (paint) {
return (paint->brush != nullptr);
return (BKE_paint_brush(paint) != nullptr);
}
return false;
}
@ -1431,8 +1431,9 @@ void ED_gpencil_add_defaults(bContext *C, Object *ob)
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint);
Paint *paint = &ts->gp_paint->paint;
Brush *brush = BKE_paint_brush(paint);
/* if not exist, create a new one */
if ((paint->brush == nullptr) || (paint->brush->gpencil_settings == nullptr)) {
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
/* create new brushes */
BKE_brush_gpencil_paint_presets(bmain, ts, true);
}
@ -1739,7 +1740,7 @@ float ED_gpencil_cursor_radius(bContext *C, int x, int y)
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
ARegion *region = CTX_wm_region(C);
Brush *brush = scene->toolsettings->gp_paint->paint.brush;
Brush *brush = BKE_paint_brush(&scene->toolsettings->gp_paint->paint);
bGPdata *gpd = ED_gpencil_data_get_active(C);
/* Show brush size. */
@ -1830,7 +1831,7 @@ static void gpencil_brush_cursor_draw(bContext *C, int x, int y, void *customdat
/* for paint use paint brush size and color */
if (gpd->flag & GP_DATA_STROKE_PAINTMODE) {
brush = scene->toolsettings->gp_paint->paint.brush;
brush = BKE_paint_brush(&scene->toolsettings->gp_paint->paint);
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
return;
}
@ -1902,7 +1903,7 @@ static void gpencil_brush_cursor_draw(bContext *C, int x, int y, void *customdat
/* Sculpt use sculpt brush size */
if (GPENCIL_SCULPT_MODE(gpd)) {
brush = scene->toolsettings->gp_sculptpaint->paint.brush;
brush = BKE_paint_brush(&scene->toolsettings->gp_sculptpaint->paint);
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
return;
}
@ -1922,7 +1923,7 @@ static void gpencil_brush_cursor_draw(bContext *C, int x, int y, void *customdat
/* Weight Paint */
if (GPENCIL_WEIGHT_MODE(gpd)) {
brush = scene->toolsettings->gp_weightpaint->paint.brush;
brush = BKE_paint_brush(&scene->toolsettings->gp_weightpaint->paint);
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
return;
}
@ -1942,7 +1943,7 @@ static void gpencil_brush_cursor_draw(bContext *C, int x, int y, void *customdat
/* For Vertex Paint use brush size. */
if (GPENCIL_VERTEX_MODE(gpd)) {
brush = scene->toolsettings->gp_vertexpaint->paint.brush;
brush = BKE_paint_brush(&scene->toolsettings->gp_vertexpaint->paint);
if ((brush == nullptr) || (brush->gpencil_settings == nullptr)) {
return;
}

View File

@ -553,7 +553,7 @@ static int gpencil_vertexpaint_set_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C);
bGPdata *gpd = (bGPdata *)ob->data;
Paint *paint = &ts->gp_vertexpaint->paint;
Brush *brush = paint->brush;
Brush *brush = BKE_paint_brush(paint);
const bool is_multiedit = bool(GPENCIL_MULTIEDIT_SESSIONS_ON(gpd));
const eGp_Vertex_Mode mode = eGp_Vertex_Mode(RNA_enum_get(op->ptr, "mode"));

View File

@ -24,6 +24,7 @@
#include "BKE_context.hh"
#include "BKE_gpencil_legacy.h"
#include "BKE_material.h"
#include "BKE_paint.hh"
#include "BKE_report.hh"
#include "WM_api.hh"
@ -714,7 +715,7 @@ static bool gpencil_vertexpaint_brush_init(bContext *C, wmOperator *op)
MEM_callocN(sizeof(tGP_BrushVertexpaintData), "tGP_BrushVertexpaintData"));
op->customdata = gso;
gso->brush = paint->brush;
gso->brush = BKE_paint_brush(paint);
srgb_to_linearrgb_v3_v3(gso->linear_color, gso->brush->rgb);
BKE_curvemapping_init(gso->brush->curve);

View File

@ -30,6 +30,7 @@
#include "BKE_gpencil_legacy.h"
#include "BKE_modifier.hh"
#include "BKE_object_deform.h"
#include "BKE_paint.hh"
#include "BKE_report.hh"
#include "DNA_meshdata_types.h"
@ -752,7 +753,7 @@ static bool gpencil_weightpaint_brush_init(bContext *C, wmOperator *op)
gso->bmain = CTX_data_main(C);
gso->brush = paint->brush;
gso->brush = BKE_paint_brush(paint);
BKE_curvemapping_init(gso->brush->curve);
gso->is_painting = false;
@ -866,7 +867,8 @@ static bool gpencil_weightpaint_brush_poll(bContext *C)
}
ToolSettings *ts = CTX_data_scene(C)->toolsettings;
if (!ts->gp_weightpaint->paint.brush) {
Brush *brush = BKE_paint_brush(&ts->gp_weightpaint->paint);
if (brush == nullptr) {
CTX_wm_operator_poll_msg_set(C, "Grease Pencil has no active paint tool");
return false;
}
@ -1519,9 +1521,10 @@ static int gpencil_weight_toggle_direction_invoke(bContext *C,
{
ToolSettings *ts = CTX_data_tool_settings(C);
Paint *paint = &ts->gp_weightpaint->paint;
Brush *brush = BKE_paint_brush(paint);
/* Toggle Add/Subtract flag. */
paint->brush->flag ^= BRUSH_DIR_IN;
brush->flag ^= BRUSH_DIR_IN;
/* Update tool settings. */
WM_main_add_notifier(NC_BRUSH | NA_EDITED, nullptr);
@ -1582,7 +1585,7 @@ static int gpencil_weight_sample_invoke(bContext *C, wmOperator * /*op*/, const
/* Get brush radius. */
ToolSettings *ts = CTX_data_tool_settings(C);
Brush *brush = ts->gp_weightpaint->paint.brush;
Brush *brush = BKE_paint_brush(&ts->gp_weightpaint->paint);
const int radius = brush->size;
/* Init closest points. */

View File

@ -12,6 +12,7 @@
#include "BKE_context.hh"
#include "BKE_grease_pencil.hh"
#include "BKE_paint.hh"
#include "BKE_report.hh"
#include "DEG_depsgraph.hh"
@ -350,7 +351,7 @@ bool ensure_active_keyframe(const Scene &scene, GreasePencil &grease_pencil)
(*active_layer.frame_key_at(current_frame) < current_frame);
if (blender::animrig::is_autokey_on(&scene) && needs_new_drawing) {
const Brush *brush = scene.toolsettings->gp_paint->paint.brush;
const Brush *brush = BKE_paint_brush_for_read(&scene.toolsettings->gp_paint->paint);
if (((scene.toolsettings->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) != 0) ||
(brush->gpencil_tool == GPAINT_TOOL_ERASE))
{

View File

@ -43,7 +43,6 @@
bool paint_curve_poll(bContext *C)
{
Object *ob = CTX_data_active_object(C);
Paint *p;
RegionView3D *rv3d = CTX_wm_region_view3d(C);
SpaceImage *sima;
@ -57,9 +56,10 @@ bool paint_curve_poll(bContext *C)
return false;
}
p = BKE_paint_get_active_from_context(C);
Paint *p = BKE_paint_get_active_from_context(C);
Brush *brush = (p) ? BKE_paint_brush(p) : nullptr;
if (p && p->brush && (p->brush->flag & BRUSH_CURVE)) {
if (brush && (brush->flag & BRUSH_CURVE)) {
return true;
}
@ -147,10 +147,11 @@ static char paintcurve_point_side_index(const BezTriple *bezt,
static int paintcurve_new_exec(bContext *C, wmOperator * /*op*/)
{
Paint *p = BKE_paint_get_active_from_context(C);
Brush *brush = (p) ? BKE_paint_brush(p) : nullptr;
Main *bmain = CTX_data_main(C);
if (p && p->brush) {
p->brush->paint_curve = BKE_paint_curve_add(bmain, DATA_("PaintCurve"));
if (brush) {
brush->paint_curve = BKE_paint_curve_add(bmain, DATA_("PaintCurve"));
}
WM_event_add_notifier(C, NC_PAINTCURVE | NA_ADDED, nullptr);
@ -176,7 +177,7 @@ void PAINTCURVE_OT_new(wmOperatorType *ot)
static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2])
{
Paint *p = BKE_paint_get_active_from_context(C);
Brush *br = p->brush;
Brush *br = BKE_paint_brush(p);
Main *bmain = CTX_data_main(C);
wmWindow *window = CTX_wm_window(C);
ARegion *region = CTX_wm_region(C);
@ -287,7 +288,7 @@ void PAINTCURVE_OT_add_point(wmOperatorType *ot)
static int paintcurve_delete_point_exec(bContext *C, wmOperator *op)
{
Paint *p = BKE_paint_get_active_from_context(C);
Brush *br = p->brush;
Brush *br = BKE_paint_brush(p);
PaintCurve *pc;
PaintCurvePoint *pcp;
wmWindow *window = CTX_wm_window(C);
@ -370,7 +371,7 @@ static bool paintcurve_point_select(
wmWindow *window = CTX_wm_window(C);
ARegion *region = CTX_wm_region(C);
Paint *p = BKE_paint_get_active_from_context(C);
Brush *br = p->brush;
Brush *br = BKE_paint_brush(p);
PaintCurve *pc;
int i;
const float loc_fl[2] = {float(loc[0]), float(loc[1])};
@ -544,7 +545,7 @@ static int paintcurve_slide_invoke(bContext *C, wmOperator *op, const wmEvent *e
int i;
bool do_select = RNA_boolean_get(op->ptr, "select");
bool align = RNA_boolean_get(op->ptr, "align");
Brush *br = p->brush;
Brush *br = BKE_paint_brush(p);
PaintCurve *pc = br->paint_curve;
PaintCurvePoint *pcp;

View File

@ -77,7 +77,8 @@ static bool paintcurve_undosys_poll(bContext *C)
return false;
}
Paint *p = BKE_paint_get_active_from_context(C);
return (p->brush && p->brush->paint_curve);
Brush *brush = BKE_paint_brush(p);
return (brush && brush->paint_curve);
}
static void paintcurve_undosys_step_encode_init(bContext *C, UndoStep *us_p)
@ -95,7 +96,8 @@ static bool paintcurve_undosys_step_encode(bContext *C, Main * /*bmain*/, UndoSt
}
Paint *p = BKE_paint_get_active_from_context(C);
PaintCurve *pc = p ? (p->brush ? p->brush->paint_curve : nullptr) : nullptr;
Brush *brush = BKE_paint_brush(p);
PaintCurve *pc = p ? (brush ? brush->paint_curve : nullptr) : nullptr;
if (pc == nullptr) {
return false;
}

View File

@ -369,8 +369,8 @@ static int palette_color_add_exec(bContext *C, wmOperator * /*op*/)
color = BKE_palette_color_add(palette);
palette->active_color = BLI_listbase_count(&palette->colors) - 1;
if (paint->brush) {
const Brush *brush = paint->brush;
const Brush *brush = BKE_paint_brush_for_read(paint);
if (brush) {
if (ELEM(mode,
PaintMode::Texture3D,
PaintMode::Texture2D,

View File

@ -181,8 +181,8 @@ bool test_brush_angle_falloff(const Brush &brush,
bool use_normal(const VPaint *vp)
{
return ((vp->paint.brush->flag & BRUSH_FRONTFACE) != 0) ||
((vp->paint.brush->flag & BRUSH_FRONTFACE_FALLOFF) != 0);
const Brush *brush = BKE_paint_brush_for_read(&vp->paint);
return ((brush->flag & BRUSH_FRONTFACE) != 0) || ((brush->flag & BRUSH_FRONTFACE_FALLOFF) != 0);
}
bool brush_use_accumulate_ex(const Brush *brush, const int ob_mode)
@ -194,7 +194,8 @@ bool brush_use_accumulate_ex(const Brush *brush, const int ob_mode)
bool brush_use_accumulate(const VPaint *vp)
{
return brush_use_accumulate_ex(vp->paint.brush, vp->paint.runtime.ob_mode);
const Brush *brush = BKE_paint_brush_for_read(&vp->paint);
return brush_use_accumulate_ex(brush, vp->paint.runtime.ob_mode);
}
void init_stroke(Depsgraph *depsgraph, Object *ob)
@ -479,7 +480,7 @@ void update_cache_invariants(
}
copy_v2_v2(cache->mouse, cache->initial_mouse);
const Brush *brush = vp->paint.brush;
const Brush *brush = BKE_paint_brush(&vp->paint);
/* Truly temporary data that isn't stored in properties */
cache->vc = vc;
cache->brush = brush;
@ -686,7 +687,7 @@ static Color vpaint_blend(const VPaint *vp,
{
using Value = typename Traits::ValueType;
const Brush *brush = vp->paint.brush;
const Brush *brush = BKE_paint_brush_for_read(&vp->paint);
const IMB_BlendMode blend = (IMB_BlendMode)brush->blend;
const Color color_blend = BLI_mix_colors<Color, Traits>(blend, color_curr, color_paint, alpha);
@ -963,9 +964,10 @@ static VPaintData *vpaint_init_vpaint(bContext *C,
vpd->domain = domain;
vpd->vc = ED_view3d_viewcontext_init(C, depsgraph);
vwpaint::view_angle_limits_init(&vpd->normal_angle_precalc,
vp->paint.brush->falloff_angle,
(vp->paint.brush->flag & BRUSH_FRONTFACE_FALLOFF) != 0);
brush->falloff_angle,
(brush->flag & BRUSH_FRONTFACE_FALLOFF) != 0);
vpd->paintcol = vpaint_get_current_col(
scene, vp, (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT));
@ -1950,7 +1952,8 @@ static void vpaint_stroke_update_step(bContext *C,
BKE_mesh_batch_cache_dirty_tag((Mesh *)ob->data, BKE_MESH_BATCH_DIRTY_ALL);
if (vp->paint.brush->vertexpaint_tool == VPAINT_TOOL_SMEAR) {
Brush *brush = BKE_paint_brush(&vp->paint);
if (brush->vertexpaint_tool == VPAINT_TOOL_SMEAR) {
vpd->smear.color_prev = vpd->smear.color_curr;
}

View File

@ -184,7 +184,7 @@ static float wpaint_blend(const VPaint *wp,
const float /*brush_alpha_value*/,
const bool do_flip)
{
const Brush *brush = wp->paint.brush;
const Brush *brush = BKE_paint_brush_for_read(&wp->paint);
IMB_BlendMode blend = (IMB_BlendMode)brush->blend;
if (do_flip) {
@ -932,9 +932,11 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
wpd = (WPaintData *)MEM_callocN(sizeof(WPaintData), "WPaintData");
paint_stroke_set_mode_data(stroke, wpd);
wpd->vc = ED_view3d_viewcontext_init(C, depsgraph);
const Brush *brush = BKE_paint_brush(&vp->paint);
vwpaint::view_angle_limits_init(&wpd->normal_angle_precalc,
vp->paint.brush->falloff_angle,
(vp->paint.brush->flag & BRUSH_FRONTFACE_FALLOFF) != 0);
brush->falloff_angle,
(brush->flag & BRUSH_FRONTFACE_FALLOFF) != 0);
wpd->active.index = vgroup_index.active;
wpd->mirror.index = vgroup_index.mirror;
@ -1007,7 +1009,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
vwpaint::update_cache_invariants(C, vp, ss, op, mouse);
vwpaint::init_session_data(ts, ob);
if (ELEM(vp->paint.brush->weightpaint_tool, WPAINT_TOOL_SMEAR, WPAINT_TOOL_BLUR)) {
if (ELEM(brush->weightpaint_tool, WPAINT_TOOL_SMEAR, WPAINT_TOOL_BLUR)) {
wpd->precomputed_weight = (float *)MEM_mallocN(sizeof(float) * mesh->verts_num, __func__);
}

View File

@ -647,10 +647,11 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
UvSculptData *data = MEM_cnew<UvSculptData>(__func__);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
Brush *brush = BKE_paint_brush(&ts->uvsculpt->paint);
op->customdata = data;
BKE_curvemapping_init(ts->uvsculpt->paint.brush->curve);
BKE_curvemapping_init(brush->curve);
if (data) {
ARegion *region = CTX_wm_region(C);
@ -668,7 +669,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
int island_index = 0;
data->tool = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_SMOOTH) ?
UV_SCULPT_TOOL_RELAX :
eBrushUVSculptTool(ts->uvsculpt->paint.brush->uv_sculpt_tool);
eBrushUVSculptTool(brush->uv_sculpt_tool);
data->invert = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT) ? 1 : 0;
data->uvsculpt = &ts->uvsculpt->paint;

View File

@ -22,6 +22,7 @@
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_paint.hh"
#include "BKE_scene.hh"
#include "IMB_imbuf_types.hh"
@ -520,7 +521,7 @@ bool ED_space_image_paint_curve(const bContext *C)
SpaceImage *sima = CTX_wm_space_image(C);
if (sima && sima->mode == SI_MODE_PAINT) {
Brush *br = CTX_data_tool_settings(C)->imapaint.paint.brush;
Brush *br = BKE_paint_brush(&CTX_data_tool_settings(C)->imapaint.paint);
if (br && (br->flag & BRUSH_CURVE)) {
return true;

View File

@ -112,9 +112,9 @@ static void PaintCurvePointToTransData(PaintCurvePoint *pcp,
static void createTransPaintCurveVerts(bContext *C, TransInfo *t)
{
Paint *paint = BKE_paint_get_active_from_context(C);
Brush *br = (paint) ? BKE_paint_brush(paint) : nullptr;
PaintCurve *pc;
PaintCurvePoint *pcp;
Brush *br;
TransData *td = nullptr;
TransData2D *td2d = nullptr;
TransDataPaintCurve *tdpc = nullptr;
@ -125,11 +125,10 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t)
tc->data_len = 0;
if (!paint || !paint->brush || !paint->brush->paint_curve) {
if (!paint || !br) {
return;
}
br = paint->brush;
pc = br->paint_curve;
for (pcp = pc->points, i = 0; i < pc->tot_points; i++, pcp++) {

View File

@ -271,7 +271,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
if ((object_mode & OB_MODE_ALL_PAINT) || (object_mode & OB_MODE_SCULPT_CURVES)) {
Paint *p = BKE_paint_get_active_from_context(C);
if (p && p->brush && (p->brush->flag & BRUSH_CURVE)) {
Brush *brush = (p) ? BKE_paint_brush(p) : nullptr;
if (brush && (brush->flag & BRUSH_CURVE)) {
t->options |= CTX_PAINT_CURVE;
}
}
@ -303,7 +304,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
else if (sima->mode == SI_MODE_PAINT) {
Paint *p = &sce->toolsettings->imapaint.paint;
if (p->brush && (p->brush->flag & BRUSH_CURVE)) {
Brush *brush = (p) ? BKE_paint_brush(p) : nullptr;
if (brush && (brush->flag & BRUSH_CURVE)) {
t->options |= CTX_PAINT_CURVE;
}
}
@ -1110,7 +1112,7 @@ bool calculateCenterActive(TransInfo *t, bool select_only, float r_center[3])
}
else if (t->options & CTX_PAINT_CURVE) {
Paint *p = BKE_paint_get_active(t->scene, t->view_layer);
Brush *br = p->brush;
Brush *br = BKE_paint_brush(p);
PaintCurve *pc = br->paint_curve;
copy_v3_v3(r_center, pc->points[pc->add_index - 1].bez.vec[1]);
r_center[2] = 0.0f;

View File

@ -1087,7 +1087,7 @@ static void rna_BrushGpencilSettings_default_eraser_update(Main *bmain,
{
ToolSettings *ts = scene->toolsettings;
Paint *paint = &ts->gp_paint->paint;
Brush *brush_cur = paint->brush;
Brush *brush_cur = BKE_paint_brush(paint);
/* disable default eraser in all brushes */
for (Brush *brush = static_cast<Brush *>(bmain->brushes.first); brush;
@ -1127,7 +1127,7 @@ static void rna_BrushGpencilSettings_eraser_mode_update(Main * /*bmain*/,
{
ToolSettings *ts = scene->toolsettings;
Paint *paint = &ts->gp_paint->paint;
Brush *brush = paint->brush;
Brush *brush = BKE_paint_brush(paint);
/* set eraser icon */
if ((brush) && (brush->gpencil_tool == GPAINT_TOOL_ERASE)) {