Brush Assets: Various changes regarding brush assignment #119801
|
@ -54,10 +54,6 @@ class VIEW3D_MT_brush_context_menu(Menu):
|
|||
|
||||
layout.operator("brush.asset_update", text="Update Asset")
|
||||
layout.operator("brush.asset_revert", text="Revert to Asset")
|
||||
|
||||
# TODO: does not behave in a useful way now, eventually improve or remove entirely.
|
||||
# if context.sculpt_object:
|
||||
# layout.operator("brush.reset", text="Reset to Defaults")
|
||||
else:
|
||||
layout.operator("brush.asset_save_as", text="Save As Asset...", icon='FILE_TICK')
|
||||
layout.operator("brush.asset_delete", text="Delete")
|
||||
|
|
|
@ -180,16 +180,5 @@ void BKE_brush_scale_size(int *r_brush_size,
|
|||
*/
|
||||
bool BKE_brush_has_cube_tip(const Brush *brush, PaintMode paint_mode);
|
||||
|
||||
/* Accessors */
|
||||
#define BKE_brush_tool_get(brush, p) \
|
||||
(CHECK_TYPE_ANY(brush, Brush *, const Brush *), \
|
||||
*(const char *)POINTER_OFFSET(brush, (p)->runtime.tool_offset))
|
||||
#define BKE_brush_tool_set(brush, p, tool) \
|
||||
{ \
|
||||
CHECK_TYPE_ANY(brush, Brush *); \
|
||||
*(char *)POINTER_OFFSET(brush, (p)->runtime.tool_offset) = tool; \
|
||||
} \
|
||||
((void)0)
|
||||
|
||||
/* debugging only */
|
||||
void BKE_brush_debug_print_state(Brush *br);
|
||||
|
|
|
@ -184,31 +184,30 @@ void BKE_paint_free(Paint *p);
|
|||
*/
|
||||
void BKE_paint_copy(const Paint *src, Paint *tar, int flag);
|
||||
|
||||
void BKE_paint_runtime_init(const ToolSettings *ts, Paint *paint);
|
||||
|
||||
void BKE_paint_cavity_curve_preset(Paint *p, int preset);
|
||||
|
||||
eObjectMode BKE_paint_object_mode_from_paintmode(PaintMode mode);
|
||||
bool BKE_paint_ensure_from_paintmode(Main *bmain, Scene *sce, PaintMode mode);
|
||||
Paint *BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode);
|
||||
const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(PaintMode mode);
|
||||
const char *BKE_paint_get_tool_enum_translation_context_from_paintmode(PaintMode mode);
|
||||
const char *BKE_paint_get_tool_prop_id_from_paintmode(PaintMode mode);
|
||||
uint BKE_paint_get_brush_tool_offset_from_paintmode(PaintMode mode);
|
||||
Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer);
|
||||
Paint *BKE_paint_get_active_from_context(const bContext *C);
|
||||
PaintMode BKE_paintmode_get_active_from_context(const bContext *C);
|
||||
PaintMode BKE_paintmode_get_from_tool(const bToolRef *tref);
|
||||
Brush *BKE_paint_brush(Paint *paint);
|
||||
const Brush *BKE_paint_brush_for_read(const Paint *p);
|
||||
void BKE_paint_brush_set(Paint *paint, Brush *br);
|
||||
|
||||
/**
|
||||
* Check if the given brush is a valid Brush Asset.
|
||||
*
|
||||
* A valid brush Asset is either an actual asset, or a local liboverride of a linked brush asset.
|
||||
*/
|
||||
bool BKE_paint_brush_is_valid_asset(const Brush *brush);
|
||||
/* Paint brush retrieval and assignment. */
|
||||
|
||||
Brush *BKE_paint_brush(Paint *paint);
|
||||
const Brush *BKE_paint_brush_for_read(const Paint *paint);
|
||||
|
||||
bool BKE_paint_brush_set(Paint *paint, Brush *brush);
|
||||
bool BKE_paint_brush_set_default(Main *bmain, Paint *paint);
|
||||
bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name);
|
||||
|
||||
void BKE_paint_brush_set_default_references(ToolSettings *ts);
|
||||
|
||||
void BKE_paint_brush_validate(Main *bmain, Paint *paint);
|
||||
|
||||
/**
|
||||
* Set the active brush of given paint struct, and store the weak asset reference to it.
|
||||
|
@ -218,17 +217,7 @@ bool BKE_paint_brush_asset_set(Paint *paint,
|
|||
Brush *brush,
|
||||
const AssetWeakReference &weak_asset_reference);
|
||||
|
||||
/**
|
||||
* Get the active brush of given paint struct, together with its weak asset reference.
|
||||
* \note Returns unset optional if the active brush is not a valid Brush Asset data..
|
||||
*/
|
||||
std::optional<AssetWeakReference *> BKE_paint_brush_asset_get(Paint *paint, Brush **r_brush);
|
||||
|
||||
/**
|
||||
* Attempt to restore a valid active brush in `paint` from brush asset information stored in
|
||||
* `paint`.
|
||||
*/
|
||||
void BKE_paint_brush_asset_restore(Main *bmain, Paint *p);
|
||||
/* Paint palette. */
|
||||
|
||||
Palette *BKE_paint_palette(Paint *paint);
|
||||
void BKE_paint_palette_set(Paint *p, Palette *palette);
|
||||
|
@ -282,19 +271,6 @@ void paint_update_brush_rake_rotation(UnifiedPaintSettings *ups, Brush *brush, f
|
|||
|
||||
void BKE_paint_stroke_get_average(const Scene *scene, const Object *ob, float stroke[3]);
|
||||
|
||||
/* Tool slot API. */
|
||||
|
||||
void BKE_paint_toolslots_init_from_main(Main *bmain);
|
||||
void BKE_paint_toolslots_len_ensure(Paint *paint, int len);
|
||||
void BKE_paint_toolslots_brush_update_ex(Paint *paint, Brush *brush);
|
||||
void BKE_paint_toolslots_brush_update(Paint *paint);
|
||||
/**
|
||||
* Run this to ensure brush types are set for each slot on entering modes
|
||||
* (for new scenes for example).
|
||||
*/
|
||||
void BKE_paint_toolslots_brush_validate(Main *bmain, Paint *paint);
|
||||
Brush *BKE_paint_toolslots_brush_get(Paint *paint, int slot_index);
|
||||
|
||||
/* .blend I/O */
|
||||
|
||||
void BKE_paint_blend_write(BlendWriter *writer, Paint *paint);
|
||||
|
|
|
@ -253,7 +253,6 @@ set(SRC
|
|||
intern/packedFile.cc
|
||||
intern/paint.cc
|
||||
intern/paint_canvas.cc
|
||||
intern/paint_toolslots.cc
|
||||
intern/particle.cc
|
||||
intern/particle_child.cc
|
||||
intern/particle_distribute.cc
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "BLI_math_matrix.h"
|
||||
#include "BLI_math_matrix.hh"
|
||||
#include "BLI_math_vector.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_string_utf8.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_vector.hh"
|
||||
|
@ -262,7 +263,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 +283,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;
|
||||
}
|
||||
|
@ -440,61 +441,6 @@ const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(const PaintMode m
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const char *BKE_paint_get_tool_prop_id_from_paintmode(const PaintMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case PaintMode::Sculpt:
|
||||
return "sculpt_tool";
|
||||
case PaintMode::Vertex:
|
||||
return "vertex_tool";
|
||||
case PaintMode::Weight:
|
||||
return "weight_tool";
|
||||
case PaintMode::Texture2D:
|
||||
case PaintMode::Texture3D:
|
||||
return "image_tool";
|
||||
case PaintMode::SculptUV:
|
||||
return "uv_sculpt_tool";
|
||||
case PaintMode::GPencil:
|
||||
return "gpencil_tool";
|
||||
case PaintMode::VertexGPencil:
|
||||
return "gpencil_vertex_tool";
|
||||
case PaintMode::SculptGPencil:
|
||||
return "gpencil_sculpt_tool";
|
||||
case PaintMode::WeightGPencil:
|
||||
return "gpencil_weight_tool";
|
||||
case PaintMode::SculptCurves:
|
||||
return "curves_sculpt_tool";
|
||||
case PaintMode::Invalid:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Invalid paint mode. */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char *BKE_paint_get_tool_enum_translation_context_from_paintmode(const PaintMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case PaintMode::Sculpt:
|
||||
case PaintMode::GPencil:
|
||||
case PaintMode::Texture2D:
|
||||
case PaintMode::Texture3D:
|
||||
return BLT_I18NCONTEXT_ID_BRUSH;
|
||||
case PaintMode::Vertex:
|
||||
case PaintMode::Weight:
|
||||
case PaintMode::SculptUV:
|
||||
case PaintMode::VertexGPencil:
|
||||
case PaintMode::SculptGPencil:
|
||||
case PaintMode::WeightGPencil:
|
||||
case PaintMode::SculptCurves:
|
||||
case PaintMode::Invalid:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Invalid paint mode. */
|
||||
return BLT_I18NCONTEXT_DEFAULT;
|
||||
}
|
||||
|
||||
Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
|
||||
{
|
||||
if (sce && view_layer) {
|
||||
|
@ -664,28 +610,53 @@ PaintMode BKE_paintmode_get_from_tool(const bToolRef *tref)
|
|||
return PaintMode::Invalid;
|
||||
}
|
||||
|
||||
Brush *BKE_paint_brush(Paint *p)
|
||||
static bool paint_brush_set_from_asset_reference(Main *bmain, Paint *paint)
|
||||
{
|
||||
return (Brush *)BKE_paint_brush_for_read((const Paint *)p);
|
||||
}
|
||||
|
||||
const Brush *BKE_paint_brush_for_read(const Paint *p)
|
||||
{
|
||||
return p ? p->brush : nullptr;
|
||||
}
|
||||
|
||||
void BKE_paint_brush_set(Paint *p, Brush *br)
|
||||
{
|
||||
if (p) {
|
||||
p->brush = br;
|
||||
|
||||
BKE_paint_toolslots_brush_update(p);
|
||||
/* Attempt to restore a valid active brush from brush asset information. */
|
||||
if (paint->brush != nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (paint->brush_asset_reference == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Brush *brush = reinterpret_cast<Brush *>(
|
||||
BKE_asset_weak_reference_ensure(*bmain, ID_BR, *paint->brush_asset_reference));
|
||||
BLI_assert(brush == nullptr || (brush->id.tag & LIB_TAG_ASSET_MAIN));
|
||||
|
||||
/* Ensure we have a brush with appropriate mode to assign.
|
||||
* Could happen if contents of asset blend was manually changed. */
|
||||
if (brush == nullptr || (paint->runtime.ob_mode & brush->ob_mode) == 0) {
|
||||
MEM_delete(paint->brush_asset_reference);
|
||||
paint->brush_asset_reference = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
paint->brush = brush;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BKE_paint_brush_is_valid_asset(const Brush *brush)
|
||||
Brush *BKE_paint_brush(Paint *paint)
|
||||
{
|
||||
return brush && ID_IS_ASSET(&brush->id);
|
||||
return (Brush *)BKE_paint_brush_for_read((const Paint *)paint);
|
||||
}
|
||||
|
||||
const Brush *BKE_paint_brush_for_read(const Paint *paint)
|
||||
{
|
||||
return paint ? paint->brush : nullptr;
|
||||
}
|
||||
|
||||
bool BKE_paint_brush_set(Paint *paint, Brush *brush)
|
||||
{
|
||||
if (paint == nullptr || paint->brush == brush) {
|
||||
return false;
|
||||
}
|
||||
if (brush && (paint->runtime.ob_mode & brush->ob_mode) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
paint->brush = brush;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void paint_brush_asset_update(Paint &paint,
|
||||
|
@ -718,67 +689,138 @@ bool BKE_paint_brush_asset_set(Paint *paint,
|
|||
return true;
|
||||
}
|
||||
|
||||
std::optional<AssetWeakReference *> BKE_paint_brush_asset_get(Paint *paint, Brush **r_brush)
|
||||
static void paint_brush_set_essentials_reference(Paint *paint, const char *name)
|
||||
{
|
||||
Brush *brush = *r_brush = BKE_paint_brush(paint);
|
||||
|
||||
if (!BKE_paint_brush_is_valid_asset(brush)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (paint->brush_asset_reference) {
|
||||
return paint->brush_asset_reference;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void BKE_paint_brush_asset_restore(Main *bmain, Paint *paint)
|
||||
{
|
||||
if (paint->brush != nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (paint->brush_asset_reference == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
AssetWeakReference weak_ref = std::move(*paint->brush_asset_reference);
|
||||
/* Set brush asset reference to a named brush in the essentials asset library. */
|
||||
MEM_delete(paint->brush_asset_reference);
|
||||
paint->brush_asset_reference = nullptr;
|
||||
|
||||
Brush *brush_asset = reinterpret_cast<Brush *>(
|
||||
BKE_asset_weak_reference_ensure(*bmain, ID_BR, weak_ref));
|
||||
|
||||
/* Will either re-assign the brush_asset_reference to `paint`, or free it if loading a brush ID
|
||||
* from it failed. */
|
||||
BKE_paint_brush_asset_set(paint, brush_asset, weak_ref);
|
||||
AssetWeakReference *weak_ref = MEM_new<AssetWeakReference>(__func__);
|
||||
weak_ref->asset_library_type = eAssetLibraryType::ASSET_LIBRARY_ESSENTIALS;
|
||||
weak_ref->relative_asset_identifier = BLI_sprintfN("brushes/essentials_brushes.blend/Brush/%s",
|
||||
name);
|
||||
paint->brush_asset_reference = weak_ref;
|
||||
paint->brush = nullptr;
|
||||
}
|
||||
|
||||
void BKE_paint_runtime_init(const ToolSettings *ts, Paint *paint)
|
||||
static void paint_brush_set_default_reference(Paint *paint)
|
||||
{
|
||||
const char *name = nullptr;
|
||||
|
||||
switch (paint->runtime.ob_mode) {
|
||||
case OB_MODE_SCULPT:
|
||||
name = "Draw";
|
||||
break;
|
||||
case OB_MODE_VERTEX_PAINT:
|
||||
name = "Paint Vertex";
|
||||
break;
|
||||
case OB_MODE_WEIGHT_PAINT:
|
||||
name = "Paint Weight";
|
||||
break;
|
||||
case OB_MODE_TEXTURE_PAINT:
|
||||
name = "Paint Texture";
|
||||
break;
|
||||
case OB_MODE_SCULPT_CURVES:
|
||||
name = "Comb Curves";
|
||||
break;
|
||||
case OB_MODE_EDIT:
|
||||
/* TODO: UV sculpt. */
|
||||
break;
|
||||
case OB_MODE_PAINT_GREASE_PENCIL:
|
||||
case OB_MODE_PAINT_GPENCIL_LEGACY:
|
||||
name = "Pencil";
|
||||
break;
|
||||
case OB_MODE_VERTEX_GPENCIL_LEGACY:
|
||||
name = "Paint Point Color";
|
||||
break;
|
||||
case OB_MODE_SCULPT_GPENCIL_LEGACY:
|
||||
name = "Smooth Stroke";
|
||||
break;
|
||||
case OB_MODE_WEIGHT_GPENCIL_LEGACY:
|
||||
name = "Paint Point Weight";
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
return;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
paint_brush_set_essentials_reference(paint, name);
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_paint_brush_set_default_references(ToolSettings *ts)
|
||||
{
|
||||
if (ts->sculpt) {
|
||||
paint_brush_set_default_reference(&ts->sculpt->paint);
|
||||
}
|
||||
if (ts->curves_sculpt) {
|
||||
paint_brush_set_default_reference(&ts->curves_sculpt->paint);
|
||||
}
|
||||
if (ts->wpaint) {
|
||||
paint_brush_set_default_reference(&ts->wpaint->paint);
|
||||
}
|
||||
if (ts->vpaint) {
|
||||
paint_brush_set_default_reference(&ts->vpaint->paint);
|
||||
}
|
||||
if (ts->uvsculpt) {
|
||||
paint_brush_set_default_reference(&ts->uvsculpt->paint);
|
||||
}
|
||||
if (ts->gp_paint) {
|
||||
paint_brush_set_default_reference(&ts->gp_paint->paint);
|
||||
}
|
||||
if (ts->gp_vertexpaint) {
|
||||
paint_brush_set_default_reference(&ts->gp_vertexpaint->paint);
|
||||
}
|
||||
if (ts->gp_sculptpaint) {
|
||||
paint_brush_set_default_reference(&ts->gp_sculptpaint->paint);
|
||||
}
|
||||
if (ts->gp_weightpaint) {
|
||||
paint_brush_set_default_reference(&ts->gp_weightpaint->paint);
|
||||
}
|
||||
paint_brush_set_default_reference(&ts->imapaint.paint);
|
||||
}
|
||||
|
||||
bool BKE_paint_brush_set_default(Main *bmain, Paint *paint)
|
||||
{
|
||||
paint_brush_set_default_reference(paint);
|
||||
return paint_brush_set_from_asset_reference(bmain, paint);
|
||||
}
|
||||
|
||||
bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
|
||||
{
|
||||
paint_brush_set_essentials_reference(paint, name);
|
||||
return paint_brush_set_from_asset_reference(bmain, paint);
|
||||
}
|
||||
|
||||
void BKE_paint_brush_validate(Main *bmain, Paint *paint)
|
||||
{
|
||||
/* Clear brush with invalid mode. Unclear if this can still happen,
|
||||
* but kept from old paint toolslots code. */
|
||||
Brush *brush = BKE_paint_brush(paint);
|
||||
if (brush && (paint->runtime.ob_mode & brush->ob_mode) == 0) {
|
||||
BKE_paint_brush_set(paint, nullptr);
|
||||
BKE_paint_brush_set_default(bmain, paint);
|
||||
}
|
||||
}
|
||||
|
||||
static void paint_runtime_init(const ToolSettings *ts, Paint *paint)
|
||||
{
|
||||
if (paint == &ts->imapaint.paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, imagepaint_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_TEXTURE_PAINT;
|
||||
}
|
||||
else if (ts->sculpt && paint == &ts->sculpt->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, sculpt_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_SCULPT;
|
||||
}
|
||||
else if (ts->vpaint && paint == &ts->vpaint->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, vertexpaint_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_VERTEX_PAINT;
|
||||
}
|
||||
else if (ts->wpaint && paint == &ts->wpaint->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, weightpaint_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_WEIGHT_PAINT;
|
||||
}
|
||||
else if (ts->uvsculpt && paint == &ts->uvsculpt->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, uv_sculpt_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_EDIT;
|
||||
}
|
||||
else if (ts->gp_paint && paint == &ts->gp_paint->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, gpencil_tool);
|
||||
if (U.experimental.use_grease_pencil_version3) {
|
||||
paint->runtime.ob_mode = OB_MODE_PAINT_GREASE_PENCIL;
|
||||
}
|
||||
|
@ -787,24 +829,22 @@ void BKE_paint_runtime_init(const ToolSettings *ts, Paint *paint)
|
|||
}
|
||||
}
|
||||
else if (ts->gp_vertexpaint && paint == &ts->gp_vertexpaint->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, gpencil_vertex_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_VERTEX_GPENCIL_LEGACY;
|
||||
}
|
||||
else if (ts->gp_sculptpaint && paint == &ts->gp_sculptpaint->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, gpencil_sculpt_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_SCULPT_GPENCIL_LEGACY;
|
||||
}
|
||||
else if (ts->gp_weightpaint && paint == &ts->gp_weightpaint->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, gpencil_weight_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_WEIGHT_GPENCIL_LEGACY;
|
||||
}
|
||||
else if (ts->curves_sculpt && paint == &ts->curves_sculpt->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, curves_sculpt_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_SCULPT_CURVES;
|
||||
}
|
||||
else {
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
paint->runtime.initialized = true;
|
||||
}
|
||||
|
||||
uint BKE_paint_get_brush_tool_offset_from_paintmode(const PaintMode mode)
|
||||
|
@ -1175,13 +1215,11 @@ bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint)
|
|||
{
|
||||
Paint *paint = nullptr;
|
||||
if (*r_paint) {
|
||||
/* Tool offset should never be 0 for initialized paint settings, so it's a reliable way to
|
||||
* check if already initialized. */
|
||||
if ((*r_paint)->runtime.tool_offset == 0) {
|
||||
if (!(*r_paint)->runtime.initialized) {
|
||||
/* Currently only image painting is initialized this way, others have to be allocated. */
|
||||
BLI_assert(ELEM(*r_paint, (Paint *)&ts->imapaint));
|
||||
|
||||
BKE_paint_runtime_init(ts, *r_paint);
|
||||
paint_runtime_init(ts, *r_paint);
|
||||
}
|
||||
else {
|
||||
BLI_assert(ELEM(*r_paint,
|
||||
|
@ -1198,14 +1236,13 @@ bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint)
|
|||
(Paint *)&ts->imapaint));
|
||||
#ifndef NDEBUG
|
||||
Paint paint_test = **r_paint;
|
||||
BKE_paint_runtime_init(ts, *r_paint);
|
||||
paint_runtime_init(ts, *r_paint);
|
||||
/* Swap so debug doesn't hide errors when release fails. */
|
||||
std::swap(**r_paint, paint_test);
|
||||
BLI_assert(paint_test.runtime.ob_mode == (*r_paint)->runtime.ob_mode);
|
||||
BLI_assert(paint_test.runtime.tool_offset == (*r_paint)->runtime.tool_offset);
|
||||
#endif
|
||||
}
|
||||
BKE_paint_brush_asset_restore(bmain, *r_paint);
|
||||
paint_brush_set_from_asset_reference(bmain, *r_paint);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1252,8 +1289,8 @@ bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint)
|
|||
|
||||
*r_paint = paint;
|
||||
|
||||
BKE_paint_runtime_init(ts, paint);
|
||||
BKE_paint_brush_asset_restore(bmain, paint);
|
||||
paint_runtime_init(ts, paint);
|
||||
BKE_paint_brush_set_default(bmain, paint);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1278,7 +1315,6 @@ void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3])
|
|||
void BKE_paint_free(Paint *paint)
|
||||
{
|
||||
BKE_curvemapping_free(paint->cavity_curve);
|
||||
MEM_SAFE_FREE(paint->tool_slots);
|
||||
MEM_delete(paint->brush_asset_reference);
|
||||
}
|
||||
|
||||
|
@ -1286,7 +1322,6 @@ void BKE_paint_copy(const Paint *src, Paint *dst, const int flag)
|
|||
{
|
||||
dst->brush = src->brush;
|
||||
dst->cavity_curve = BKE_curvemapping_copy(src->cavity_curve);
|
||||
dst->tool_slots = static_cast<PaintToolSlot *>(MEM_dupallocN(src->tool_slots));
|
||||
|
||||
if (src->brush_asset_reference) {
|
||||
dst->brush_asset_reference = MEM_new<AssetWeakReference>(__func__,
|
||||
|
@ -1318,7 +1353,6 @@ void BKE_paint_blend_write(BlendWriter *writer, Paint *p)
|
|||
if (p->brush_asset_reference) {
|
||||
BKE_asset_weak_reference_write(writer, p->brush_asset_reference);
|
||||
}
|
||||
BLO_write_struct_array(writer, PaintToolSlot, p->tool_slots_len, p->tool_slots);
|
||||
}
|
||||
|
||||
void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *p)
|
||||
|
@ -1336,17 +1370,8 @@ void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Pain
|
|||
BKE_asset_weak_reference_read(reader, p->brush_asset_reference);
|
||||
}
|
||||
|
||||
BLO_read_data_address(reader, &p->tool_slots);
|
||||
|
||||
/* Workaround for invalid data written in older versions. */
|
||||
const size_t expected_size = sizeof(PaintToolSlot) * p->tool_slots_len;
|
||||
if (p->tool_slots && MEM_allocN_len(p->tool_slots) < expected_size) {
|
||||
MEM_freeN(p->tool_slots);
|
||||
p->tool_slots = static_cast<PaintToolSlot *>(MEM_callocN(expected_size, "PaintToolSlot"));
|
||||
}
|
||||
|
||||
p->paint_cursor = nullptr;
|
||||
BKE_paint_runtime_init(scene->toolsettings, p);
|
||||
paint_runtime_init(scene->toolsettings, p);
|
||||
}
|
||||
|
||||
bool paint_is_grid_face_hidden(const blender::BoundedBitSpan grid_hidden,
|
||||
|
|
|
@ -1,164 +0,0 @@
|
|||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup bke
|
||||
*/
|
||||
|
||||
#include <climits>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_brush_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_brush.hh"
|
||||
#include "BKE_lib_id.hh"
|
||||
#include "BKE_main.hh"
|
||||
#include "BKE_paint.hh"
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Tool Slot Initialization / Versioning
|
||||
*
|
||||
* These functions run to update old files (while versioning),
|
||||
* take care only to perform low-level functions here.
|
||||
* \{ */
|
||||
|
||||
void BKE_paint_toolslots_len_ensure(Paint *paint, int len)
|
||||
{
|
||||
/* Tool slots are 'uchar'. */
|
||||
BLI_assert(len <= UCHAR_MAX);
|
||||
if (paint->tool_slots_len < len) {
|
||||
paint->tool_slots = static_cast<PaintToolSlot *>(
|
||||
MEM_recallocN(paint->tool_slots, sizeof(*paint->tool_slots) * len));
|
||||
paint->tool_slots_len = len;
|
||||
}
|
||||
}
|
||||
|
||||
static void paint_toolslots_init(Main *bmain, Paint *paint)
|
||||
{
|
||||
if (paint == nullptr) {
|
||||
return;
|
||||
}
|
||||
const eObjectMode ob_mode = eObjectMode(paint->runtime.ob_mode);
|
||||
BLI_assert(paint->runtime.tool_offset && ob_mode);
|
||||
for (Brush *brush = static_cast<Brush *>(bmain->brushes.first); brush;
|
||||
brush = static_cast<Brush *>(brush->id.next))
|
||||
{
|
||||
if (brush->ob_mode & ob_mode) {
|
||||
const int slot_index = BKE_brush_tool_get(brush, paint);
|
||||
BKE_paint_toolslots_len_ensure(paint, slot_index + 1);
|
||||
if (paint->tool_slots[slot_index].brush == nullptr) {
|
||||
paint->tool_slots[slot_index].brush = brush;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize runtime since this is called from versioning code.
|
||||
*/
|
||||
static void paint_toolslots_init_with_runtime(Main *bmain, ToolSettings *ts, Paint *paint)
|
||||
{
|
||||
if (paint == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Needed so #Paint_Runtime is updated when versioning. */
|
||||
BKE_paint_runtime_init(ts, paint);
|
||||
paint_toolslots_init(bmain, paint);
|
||||
}
|
||||
|
||||
void BKE_paint_toolslots_init_from_main(Main *bmain)
|
||||
{
|
||||
for (Scene *scene = static_cast<Scene *>(bmain->scenes.first); scene;
|
||||
scene = static_cast<Scene *>(scene->id.next))
|
||||
{
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->imapaint.paint);
|
||||
if (ts->sculpt) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->sculpt->paint);
|
||||
}
|
||||
if (ts->vpaint) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->vpaint->paint);
|
||||
}
|
||||
if (ts->wpaint) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->wpaint->paint);
|
||||
}
|
||||
if (ts->uvsculpt) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->uvsculpt->paint);
|
||||
}
|
||||
if (ts->gp_paint) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->gp_paint->paint);
|
||||
}
|
||||
if (ts->gp_vertexpaint) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->gp_vertexpaint->paint);
|
||||
}
|
||||
if (ts->gp_sculptpaint) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->gp_sculptpaint->paint);
|
||||
}
|
||||
if (ts->gp_weightpaint) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->gp_weightpaint->paint);
|
||||
}
|
||||
if (ts->curves_sculpt) {
|
||||
paint_toolslots_init_with_runtime(bmain, ts, &ts->curves_sculpt->paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
void BKE_paint_toolslots_brush_update_ex(Paint *paint, Brush *brush)
|
||||
{
|
||||
const uint tool_offset = paint->runtime.tool_offset;
|
||||
UNUSED_VARS_NDEBUG(tool_offset);
|
||||
BLI_assert(tool_offset != 0);
|
||||
const int slot_index = BKE_brush_tool_get(brush, paint);
|
||||
BKE_paint_toolslots_len_ensure(paint, slot_index + 1);
|
||||
PaintToolSlot *tslot = &paint->tool_slots[slot_index];
|
||||
tslot->brush = brush;
|
||||
}
|
||||
|
||||
void BKE_paint_toolslots_brush_update(Paint *paint)
|
||||
{
|
||||
if (paint->brush == nullptr) {
|
||||
return;
|
||||
}
|
||||
BKE_paint_toolslots_brush_update_ex(paint, paint->brush);
|
||||
}
|
||||
|
||||
void BKE_paint_toolslots_brush_validate(Main *bmain, Paint *paint)
|
||||
{
|
||||
/* Clear slots with invalid slots or mode (unlikely but possible). */
|
||||
const uint tool_offset = paint->runtime.tool_offset;
|
||||
UNUSED_VARS_NDEBUG(tool_offset);
|
||||
const eObjectMode ob_mode = eObjectMode(paint->runtime.ob_mode);
|
||||
BLI_assert(tool_offset && ob_mode);
|
||||
for (int i = 0; i < paint->tool_slots_len; i++) {
|
||||
PaintToolSlot *tslot = &paint->tool_slots[i];
|
||||
if (tslot->brush) {
|
||||
if ((i != BKE_brush_tool_get(tslot->brush, paint)) || (tslot->brush->ob_mode & ob_mode) == 0)
|
||||
{
|
||||
tslot->brush = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Unlikely but possible the active brush is not currently using a slot. */
|
||||
BKE_paint_toolslots_brush_update(paint);
|
||||
|
||||
/* Fill slots from brushes. */
|
||||
paint_toolslots_init(bmain, paint);
|
||||
}
|
||||
|
||||
Brush *BKE_paint_toolslots_brush_get(Paint *paint, int slot_index)
|
||||
{
|
||||
if (slot_index < paint->tool_slots_len) {
|
||||
PaintToolSlot *tslot = &paint->tool_slots[slot_index];
|
||||
return tslot->brush;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
|
@ -602,26 +602,6 @@ static void scene_foreach_paint(LibraryForeachIDData *data,
|
|||
&paint_old->brush,
|
||||
IDWALK_CB_NOP);
|
||||
|
||||
for (int i = 0; i < paint_old->tool_slots_len; i++) {
|
||||
/* This is a bit tricky.
|
||||
* - In case we do not do `undo_restore`, `paint` and `paint_old` pointers are the same, so
|
||||
* this is equivalent to simply looping over slots from `paint`.
|
||||
* - In case we do `undo_restore`, we only want to consider the slots from the old one, since
|
||||
* those are the one we keep in the end.
|
||||
* + In case the new data has less valid slots, we feed in a dummy null pointer.
|
||||
* + In case the new data has more valid slots, the extra ones are ignored.
|
||||
*/
|
||||
brush_tmp = nullptr;
|
||||
brush_p = (paint && i < paint->tool_slots_len) ? &paint->tool_slots[i].brush : &brush_tmp;
|
||||
BKE_LIB_FOREACHID_UNDO_PRESERVE_PROCESS_IDSUPER_P(data,
|
||||
brush_p,
|
||||
do_undo_restore,
|
||||
SCENE_FOREACH_UNDO_RESTORE,
|
||||
reader,
|
||||
&paint_old->tool_slots[i].brush,
|
||||
IDWALK_CB_NOP);
|
||||
}
|
||||
|
||||
Palette *palette_tmp = nullptr;
|
||||
Palette **palette_p = paint ? &paint->palette : &palette_tmp;
|
||||
BKE_LIB_FOREACHID_UNDO_PRESERVE_PROCESS_IDSUPER_P(data,
|
||||
|
|
|
@ -2557,7 +2557,6 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain)
|
|||
brush->gpencil_tool = brush->gpencil_settings->brush_type;
|
||||
}
|
||||
}
|
||||
BKE_paint_toolslots_init_from_main(bmain);
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 280, 38)) {
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "BKE_mesh_legacy_convert.hh"
|
||||
#include "BKE_nla.h"
|
||||
#include "BKE_node_runtime.hh"
|
||||
#include "BKE_paint.hh"
|
||||
#include "BKE_scene.hh"
|
||||
#include "BKE_tracking.h"
|
||||
|
||||
|
@ -1997,29 +1998,7 @@ static void update_paint_modes_for_brush_assets(Main &bmain)
|
|||
{
|
||||
/* Replace paint brushes with a reference to the default brush asset for that mode. */
|
||||
LISTBASE_FOREACH (Scene *, scene, &bmain.scenes) {
|
||||
auto set_paint_asset_ref = [&](Paint &paint, const blender::StringRef asset) {
|
||||
AssetWeakReference *weak_ref = MEM_new<AssetWeakReference>(__func__);
|
||||
weak_ref->asset_library_type = eAssetLibraryType::ASSET_LIBRARY_ESSENTIALS;
|
||||
const std::string path = "brushes/essentials_brushes.blend/Brush/" + asset;
|
||||
weak_ref->relative_asset_identifier = BLI_strdupn(path.data(), path.size());
|
||||
paint.brush_asset_reference = weak_ref;
|
||||
paint.brush = nullptr;
|
||||
};
|
||||
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
if (ts->sculpt) {
|
||||
set_paint_asset_ref(ts->sculpt->paint, "Draw");
|
||||
}
|
||||
if (ts->curves_sculpt) {
|
||||
set_paint_asset_ref(ts->curves_sculpt->paint, "Comb Curves");
|
||||
}
|
||||
if (ts->wpaint) {
|
||||
set_paint_asset_ref(ts->wpaint->paint, "Paint Weight");
|
||||
}
|
||||
if (ts->vpaint) {
|
||||
set_paint_asset_ref(ts->vpaint->paint, "Paint Vertex");
|
||||
}
|
||||
set_paint_asset_ref(ts->imapaint.paint, "Paint Texture");
|
||||
BKE_paint_brush_set_default_references(scene->toolsettings);
|
||||
}
|
||||
|
||||
/* Replace persistent tool references with the new single builtin brush tool. */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -2201,7 +2200,7 @@ static int gpencil_brush_reset_all_exec(bContext *C, wmOperator * /*op*/)
|
|||
}
|
||||
}
|
||||
|
||||
BKE_paint_toolslots_brush_validate(bmain, paint);
|
||||
BKE_paint_brush_validate(bmain, paint);
|
||||
|
||||
/* Set Again the first brush of the mode. */
|
||||
Brush *deft_brush = gpencil_brush_get_first_by_mode(bmain, paint, mode, tool);
|
||||
|
|
|
@ -395,11 +395,12 @@ 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);
|
||||
BKE_paint_brush_validate(bmain, &ts->gp_paint->paint);
|
||||
}
|
||||
|
||||
/* setup other modes */
|
||||
|
@ -503,10 +504,10 @@ 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);
|
||||
BKE_paint_brush_validate(bmain, &ts->gp_sculptpaint->paint);
|
||||
}
|
||||
|
||||
/* setup other modes */
|
||||
|
@ -617,10 +618,10 @@ 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);
|
||||
BKE_paint_brush_validate(bmain, &ts->gp_weightpaint->paint);
|
||||
}
|
||||
|
||||
/* setup other modes */
|
||||
|
@ -725,10 +726,10 @@ 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);
|
||||
BKE_paint_brush_validate(bmain, &ts->gp_vertexpaint->paint);
|
||||
|
||||
/* Ensure Palette by default. */
|
||||
BKE_gpencil_palette_ensure(bmain, CTX_data_scene(C));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1211,16 +1211,13 @@ 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);
|
||||
}
|
||||
|
||||
/* Set Draw brush. */
|
||||
Brush *brush = BKE_paint_toolslots_brush_get(paint, 0);
|
||||
|
||||
BKE_brush_tool_set(brush, paint, 0);
|
||||
BKE_paint_brush_set(paint, brush);
|
||||
tgpi->brush = brush;
|
||||
/* Set brush. */
|
||||
tgpi->brush = BKE_paint_brush(paint);
|
||||
|
||||
/* control points */
|
||||
tgpi->gpd->runtime.cp_points = static_cast<bGPDcontrolpoint *>(
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -901,7 +901,7 @@ void ED_object_texture_paint_mode_enter_ex(Main *bmain,
|
|||
|
||||
BKE_paint_init(bmain, scene, PaintMode::Texture3D, PAINT_CURSOR_TEXTURE_PAINT);
|
||||
|
||||
BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint);
|
||||
BKE_paint_brush_validate(bmain, &imapaint->paint);
|
||||
|
||||
if (U.glreslimit != 0) {
|
||||
BKE_image_free_all_gputextures(bmain);
|
||||
|
|
|
@ -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,
|
||||
|
@ -721,42 +721,6 @@ static void PALETTE_OT_join(wmOperatorType *ot)
|
|||
RNA_def_string(ot->srna, "palette", nullptr, MAX_ID_NAME - 2, "Palette", "Name of the Palette");
|
||||
}
|
||||
|
||||
static int brush_reset_exec(bContext *C, wmOperator * /*op*/)
|
||||
{
|
||||
Paint *paint = BKE_paint_get_active_from_context(C);
|
||||
Brush *brush = BKE_paint_brush(paint);
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
|
||||
if (!ob || !brush) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* TODO: other modes */
|
||||
if (ob->mode & OB_MODE_SCULPT) {
|
||||
BKE_brush_sculpt_reset(brush);
|
||||
}
|
||||
else {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static void BRUSH_OT_reset(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Reset Brush";
|
||||
ot->description = "Return brush to defaults based on current tool";
|
||||
ot->idname = "BRUSH_OT_reset";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = brush_reset_exec;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
namespace blender::ed::sculpt_paint {
|
||||
|
||||
/**************************** Brush Assets **********************************/
|
||||
|
@ -1091,11 +1055,11 @@ static int brush_asset_save_as_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
|
||||
/* Turn brush into asset if it isn't yet. */
|
||||
if (!BKE_paint_brush_is_valid_asset(brush)) {
|
||||
if (!ID_IS_ASSET(brush)) {
|
||||
asset::mark_id(&brush->id);
|
||||
asset::generate_preview(C, &brush->id);
|
||||
}
|
||||
BLI_assert(BKE_paint_brush_is_valid_asset(brush));
|
||||
BLI_assert(ID_IS_ASSET(brush));
|
||||
|
||||
asset_system::AssetLibrary *library = AS_asset_library_load(
|
||||
CTX_data_main(C), user_library_to_library_ref(*user_library));
|
||||
|
@ -1118,16 +1082,16 @@ static int brush_asset_save_as_exec(bContext *C, wmOperator *op)
|
|||
Main *asset_main = BKE_main_from_id(bmain, &brush->id);
|
||||
|
||||
std::string final_full_asset_filepath;
|
||||
const bool sucess = brush_asset_write_in_library(asset_main,
|
||||
brush,
|
||||
name,
|
||||
filepath,
|
||||
catalog_id,
|
||||
catalog_simple_name,
|
||||
final_full_asset_filepath,
|
||||
op->reports);
|
||||
const bool success = brush_asset_write_in_library(asset_main,
|
||||
brush,
|
||||
name,
|
||||
filepath,
|
||||
catalog_id,
|
||||
catalog_simple_name,
|
||||
final_full_asset_filepath,
|
||||
op->reports);
|
||||
|
||||
if (!sucess) {
|
||||
if (!success) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Failed to write to asset library");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
@ -1135,7 +1099,6 @@ static int brush_asset_save_as_exec(bContext *C, wmOperator *op)
|
|||
AssetWeakReference new_brush_weak_ref = brush_asset_create_weakref_hack(
|
||||
user_library, final_full_asset_filepath);
|
||||
|
||||
/* TODO: maybe not needed, even less so if there is more visual confirmation of change. */
|
||||
BKE_reportf(op->reports, RPT_INFO, "Saved \"%s\"", filepath.c_str());
|
||||
|
||||
brush = reinterpret_cast<Brush *>(
|
||||
|
@ -1249,7 +1212,7 @@ static bool brush_asset_delete_poll(bContext *C)
|
|||
}
|
||||
|
||||
/* Asset brush, check if belongs to an editable blend file. */
|
||||
if (paint->brush_asset_reference && BKE_paint_brush_is_valid_asset(brush)) {
|
||||
if (paint->brush_asset_reference && ID_IS_ASSET(brush)) {
|
||||
if (!asset_is_editable(*paint->brush_asset_reference)) {
|
||||
CTX_wm_operator_poll_msg_set(C, "Asset blend file is not editable");
|
||||
return false;
|
||||
|
@ -1272,7 +1235,7 @@ static int brush_asset_delete_exec(bContext *C, wmOperator *op)
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
if (paint->brush_asset_reference && BKE_paint_brush_is_valid_asset(brush)) {
|
||||
if (paint->brush_asset_reference && ID_IS_ASSET(brush)) {
|
||||
/* Delete from asset library on disk. */
|
||||
char path_buffer[FILE_MAX_LIBEXTRA];
|
||||
char *filepath;
|
||||
|
@ -1292,11 +1255,12 @@ static int brush_asset_delete_exec(bContext *C, wmOperator *op)
|
|||
// TODO: delete whole asset main if empty?
|
||||
|
||||
refresh_asset_library(C, *library);
|
||||
|
||||
BKE_paint_brush_set_default(bmain, paint);
|
||||
|
||||
WM_main_add_notifier(NC_ASSET | ND_ASSET_LIST | NA_REMOVED, nullptr);
|
||||
WM_main_add_notifier(NC_BRUSH | NA_EDITED, nullptr);
|
||||
|
||||
/* TODO: activate default brush. */
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
|
@ -1319,7 +1283,11 @@ static bool brush_asset_update_poll(bContext *C)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!(paint->brush_asset_reference && BKE_paint_brush_is_valid_asset(brush))) {
|
||||
if ((brush->id.tag & LIB_TAG_ASSET_MAIN) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(paint->brush_asset_reference && ID_IS_ASSET(brush))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1335,12 +1303,8 @@ static int brush_asset_update_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Paint *paint = BKE_paint_get_active_from_context(C);
|
||||
Brush *brush = nullptr;
|
||||
const AssetWeakReference *asset_weak_ref =
|
||||
BKE_paint_brush_asset_get(paint, &brush).value_or(nullptr);
|
||||
if (!asset_weak_ref) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
Brush *brush = BKE_paint_brush(paint);
|
||||
const AssetWeakReference *asset_weak_ref = paint->brush_asset_reference;
|
||||
|
||||
const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_by_name(
|
||||
&U, asset_weak_ref->asset_library_identifier);
|
||||
|
@ -1348,15 +1312,12 @@ static int brush_asset_update_exec(bContext *C, wmOperator *op)
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
// TODO: maybe can check directly in poll
|
||||
BLI_assert((brush->id.tag & LIB_TAG_ASSET_MAIN) != 0);
|
||||
|
||||
char path_buffer[FILE_MAX_LIBEXTRA];
|
||||
char *filepath;
|
||||
AS_asset_full_path_explode_from_weak_ref(
|
||||
asset_weak_ref, path_buffer, &filepath, nullptr, nullptr);
|
||||
|
||||
BLI_assert(BKE_paint_brush_is_valid_asset(brush));
|
||||
BLI_assert(ID_IS_ASSET(brush));
|
||||
|
||||
Main *asset_main = BKE_main_from_id(bmain, &brush->id);
|
||||
std::string final_full_asset_filepath;
|
||||
|
@ -1395,7 +1356,7 @@ static bool brush_asset_revert_poll(bContext *C)
|
|||
return false;
|
||||
}
|
||||
|
||||
return paint->brush_asset_reference && BKE_paint_brush_is_valid_asset(brush);
|
||||
return paint->brush_asset_reference && ID_IS_ASSET(brush);
|
||||
}
|
||||
|
||||
static int brush_asset_revert_exec(bContext *C, wmOperator * /*op*/)
|
||||
|
@ -1891,7 +1852,6 @@ void ED_operatortypes_paint()
|
|||
WM_operatortype_append(BRUSH_OT_scale_size);
|
||||
WM_operatortype_append(BRUSH_OT_curve_preset);
|
||||
WM_operatortype_append(BRUSH_OT_sculpt_curves_falloff_preset);
|
||||
WM_operatortype_append(BRUSH_OT_reset);
|
||||
WM_operatortype_append(BRUSH_OT_stencil_control);
|
||||
WM_operatortype_append(BRUSH_OT_stencil_fit_image_aspect);
|
||||
WM_operatortype_append(BRUSH_OT_stencil_reset_transform);
|
||||
|
|
|
@ -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;
|
||||
|
@ -574,24 +575,28 @@ void last_stroke_update(Scene *scene, const float location[3])
|
|||
/* -------------------------------------------------------------------- */
|
||||
void smooth_brush_toggle_on(const bContext *C, Paint *paint, StrokeCache *cache)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Brush *cur_brush = BKE_paint_brush(paint);
|
||||
|
||||
/* Switch to the blur (smooth) brush if possible. */
|
||||
/* Note: used for both vertexpaint and weightpaint, VPAINT_TOOL_BLUR & WPAINT_TOOL_BLUR are the
|
||||
* same, see comments for eBrushVertexPaintTool & eBrushWeightPaintTool. */
|
||||
Brush *smooth_brush = BKE_paint_toolslots_brush_get(paint, WPAINT_TOOL_BLUR);
|
||||
BKE_paint_brush_set_essentials(bmain,
|
||||
paint,
|
||||
(paint->runtime.ob_mode = OB_MODE_WEIGHT_PAINT) ? "Blur Weight" :
|
||||
"Blur Vertex");
|
||||
Brush *smooth_brush = BKE_paint_brush(paint);
|
||||
|
||||
if (!smooth_brush) {
|
||||
BKE_paint_brush_set(paint, cur_brush);
|
||||
CLOG_WARN(&LOG, "Switching to the blur (smooth) brush not possible, corresponding brush not");
|
||||
cache->saved_active_brush_name[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
Brush *cur_brush = paint->brush;
|
||||
int cur_brush_size = BKE_brush_size_get(scene, cur_brush);
|
||||
|
||||
STRNCPY(cache->saved_active_brush_name, cur_brush->id.name + 2);
|
||||
|
||||
BKE_paint_brush_set(paint, smooth_brush);
|
||||
cache->saved_smooth_size = BKE_brush_size_get(scene, smooth_brush);
|
||||
BKE_brush_size_set(scene, smooth_brush, cur_brush_size);
|
||||
BKE_curvemapping_init(smooth_brush->curve);
|
||||
|
@ -686,7 +691,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);
|
||||
|
@ -855,7 +860,7 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
|
|||
depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
||||
}
|
||||
ED_object_vpaintmode_enter_ex(bmain, depsgraph, scene, ob);
|
||||
BKE_paint_toolslots_brush_validate(bmain, &ts->vpaint->paint);
|
||||
BKE_paint_brush_validate(bmain, &ts->vpaint->paint);
|
||||
}
|
||||
|
||||
BKE_mesh_batch_cache_dirty_tag((Mesh *)ob->data, BKE_MESH_BATCH_DIRTY_ALL);
|
||||
|
@ -963,9 +968,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 +1956,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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__);
|
||||
}
|
||||
|
||||
|
@ -1672,7 +1674,7 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op)
|
|||
depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
||||
}
|
||||
ED_object_wpaintmode_enter_ex(bmain, depsgraph, scene, ob);
|
||||
BKE_paint_toolslots_brush_validate(bmain, &ts->wpaint->paint);
|
||||
BKE_paint_brush_validate(bmain, &ts->wpaint->paint);
|
||||
}
|
||||
|
||||
/* Prepare armature posemode. */
|
||||
|
|
|
@ -4125,8 +4125,9 @@ static void smooth_brush_toggle_on(const bContext *C,
|
|||
Paint *paint,
|
||||
blender::ed::sculpt_paint::StrokeCache *cache)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Brush *cur_brush = paint->brush;
|
||||
Brush *cur_brush = BKE_paint_brush(paint);
|
||||
|
||||
if (cur_brush->sculpt_tool == SCULPT_TOOL_MASK) {
|
||||
cache->saved_mask_brush_tool = cur_brush->mask_tool;
|
||||
|
@ -4145,8 +4146,11 @@ static void smooth_brush_toggle_on(const bContext *C,
|
|||
}
|
||||
|
||||
/* Switch to the smooth brush if possible. */
|
||||
Brush *smooth_brush = BKE_paint_toolslots_brush_get(paint, SCULPT_TOOL_SMOOTH);
|
||||
BKE_paint_brush_set_essentials(bmain, paint, "Smooth");
|
||||
Brush *smooth_brush = BKE_paint_brush(paint);
|
||||
|
||||
if (!smooth_brush) {
|
||||
BKE_paint_brush_set(paint, cur_brush);
|
||||
CLOG_WARN(&LOG, "Switching to the smooth brush not possible, corresponding brush not");
|
||||
cache->saved_active_brush_name[0] = '\0';
|
||||
return;
|
||||
|
@ -4156,7 +4160,6 @@ static void smooth_brush_toggle_on(const bContext *C,
|
|||
|
||||
STRNCPY(cache->saved_active_brush_name, cur_brush->id.name + 2);
|
||||
|
||||
BKE_paint_brush_set(paint, smooth_brush);
|
||||
cache->saved_smooth_size = BKE_brush_size_get(scene, smooth_brush);
|
||||
BKE_brush_size_set(scene, smooth_brush, cur_brush_size);
|
||||
BKE_curvemapping_init(smooth_brush->curve);
|
||||
|
|
|
@ -527,7 +527,7 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
|
|||
depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
||||
}
|
||||
ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, false, op->reports);
|
||||
BKE_paint_toolslots_brush_validate(bmain, &ts->sculpt->paint);
|
||||
BKE_paint_brush_validate(bmain, &ts->sculpt->paint);
|
||||
|
||||
if (ob->mode & mode_flag) {
|
||||
Mesh *mesh = static_cast<Mesh *>(ob->data);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -950,16 +950,11 @@ typedef struct TimeMarker {
|
|||
|
||||
typedef struct Paint_Runtime {
|
||||
/** Avoid having to compare with scene pointer everywhere. */
|
||||
unsigned int tool_offset;
|
||||
unsigned int initialized;
|
||||
unsigned short ob_mode;
|
||||
char _pad[2];
|
||||
} Paint_Runtime;
|
||||
|
||||
/** We might want to store other things here. */
|
||||
typedef struct PaintToolSlot {
|
||||
struct Brush *brush;
|
||||
} PaintToolSlot;
|
||||
|
||||
/** Paint Tool Base. */
|
||||
typedef struct Paint {
|
||||
/**
|
||||
|
@ -976,14 +971,6 @@ typedef struct Paint {
|
|||
*/
|
||||
struct AssetWeakReference *brush_asset_reference;
|
||||
|
||||
/**
|
||||
* Each tool has its own active brush,
|
||||
* The currently active tool is defined by the current 'brush'.
|
||||
*/
|
||||
struct PaintToolSlot *tool_slots;
|
||||
int tool_slots_len;
|
||||
char _pad1[4];
|
||||
|
||||
struct Palette *palette;
|
||||
/** Cavity curve. */
|
||||
struct CurveMapping *cavity_curve;
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -270,114 +270,27 @@ static std::optional<std::string> rna_ParticleEdit_path(const PointerRNA * /*ptr
|
|||
return "tool_settings.particle_edit";
|
||||
}
|
||||
|
||||
static bool rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value)
|
||||
static PointerRNA rna_Paint_brush_get(PointerRNA *ptr)
|
||||
{
|
||||
Paint *paint = static_cast<Paint *>(ptr->data);
|
||||
Brush *brush = BKE_paint_brush(paint);
|
||||
return RNA_id_pointer_create(&brush->id);
|
||||
}
|
||||
|
||||
static void rna_Paint_brush_set(PointerRNA *ptr, PointerRNA value, ReportList * /*reports*/)
|
||||
{
|
||||
Paint *paint = static_cast<Paint *>(ptr->data);
|
||||
Brush *brush = static_cast<Brush *>(value.data);
|
||||
BKE_paint_brush_set(paint, brush);
|
||||
BKE_paint_invalidate_overlay_all();
|
||||
}
|
||||
|
||||
static bool rna_Paint_brush_poll(PointerRNA *ptr, PointerRNA value)
|
||||
{
|
||||
const Paint *paint = static_cast<Paint *>(ptr->data);
|
||||
Brush *brush = (Brush *)value.owner_id;
|
||||
const uint tool_offset = paint->runtime.tool_offset;
|
||||
const eObjectMode ob_mode = eObjectMode(paint->runtime.ob_mode);
|
||||
UNUSED_VARS_NDEBUG(tool_offset);
|
||||
BLI_assert(tool_offset && ob_mode);
|
||||
const Brush *brush = static_cast<Brush *>(value.data);
|
||||
|
||||
if (brush->ob_mode & ob_mode) {
|
||||
if (paint->brush) {
|
||||
if (BKE_brush_tool_get(paint->brush, paint) == BKE_brush_tool_get(brush, paint)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool paint_contains_brush_slot(const Paint *paint, const PaintToolSlot *tslot, int *r_index)
|
||||
{
|
||||
if ((tslot >= paint->tool_slots) && (tslot < (paint->tool_slots + paint->tool_slots_len))) {
|
||||
*r_index = int(tslot - paint->tool_slots);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool rna_Brush_mode_with_tool_poll(PointerRNA *ptr, PointerRNA value)
|
||||
{
|
||||
Scene *scene = (Scene *)ptr->owner_id;
|
||||
const PaintToolSlot *tslot = static_cast<PaintToolSlot *>(ptr->data);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
Brush *brush = (Brush *)value.owner_id;
|
||||
int mode = 0;
|
||||
int slot_index = 0;
|
||||
|
||||
if (paint_contains_brush_slot(&ts->imapaint.paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->imagepaint_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_TEXTURE_PAINT;
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->sculpt->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->sculpt_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_SCULPT;
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->uvsculpt->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->uv_sculpt_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_EDIT;
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->vpaint->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->vertexpaint_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_VERTEX_PAINT;
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->wpaint->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->weightpaint_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_WEIGHT_PAINT;
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->gp_paint->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->gpencil_tool) {
|
||||
return false;
|
||||
}
|
||||
if (U.experimental.use_grease_pencil_version3) {
|
||||
mode = OB_MODE_PAINT_GREASE_PENCIL;
|
||||
}
|
||||
else {
|
||||
mode = OB_MODE_PAINT_GPENCIL_LEGACY;
|
||||
}
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->gp_vertexpaint->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->gpencil_vertex_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_VERTEX_GPENCIL_LEGACY;
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->gp_sculptpaint->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->gpencil_sculpt_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_SCULPT_GPENCIL_LEGACY;
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->gp_weightpaint->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->gpencil_weight_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_WEIGHT_GPENCIL_LEGACY;
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->curves_sculpt->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->curves_sculpt_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_SCULPT_CURVES;
|
||||
}
|
||||
|
||||
return brush->ob_mode & mode;
|
||||
return (brush == nullptr) || (paint->runtime.ob_mode & brush->ob_mode) != 0;
|
||||
}
|
||||
|
||||
static void rna_Sculpt_update(bContext *C, PointerRNA * /*ptr*/)
|
||||
|
@ -453,16 +366,6 @@ static std::optional<std::string> rna_ParticleBrush_path(const PointerRNA * /*pt
|
|||
return "tool_settings.particle_edit.brush";
|
||||
}
|
||||
|
||||
static void rna_Paint_brush_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
|
||||
{
|
||||
Paint *paint = static_cast<Paint *>(ptr->data);
|
||||
Brush *br = paint->brush;
|
||||
BKE_paint_invalidate_overlay_all();
|
||||
/* Needed because we're not calling 'BKE_paint_brush_set' which handles this. */
|
||||
BKE_paint_toolslots_brush_update(paint);
|
||||
WM_main_add_notifier(NC_BRUSH | NA_SELECTED, br);
|
||||
}
|
||||
|
||||
static void rna_ImaPaint_viewport_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA * /*ptr*/)
|
||||
{
|
||||
/* not the best solution maybe, but will refresh the 3D viewport */
|
||||
|
@ -598,20 +501,6 @@ static void rna_def_paint_curve(BlenderRNA *brna)
|
|||
RNA_def_struct_ui_icon(srna, ICON_CURVE_BEZCURVE);
|
||||
}
|
||||
|
||||
static void rna_def_paint_tool_slot(BlenderRNA *brna)
|
||||
{
|
||||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
|
||||
srna = RNA_def_struct(brna, "PaintToolSlot", nullptr);
|
||||
RNA_def_struct_ui_text(srna, "Paint Tool Slot", "");
|
||||
|
||||
prop = RNA_def_property(srna, "brush", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_pointer_funcs(prop, nullptr, nullptr, nullptr, "rna_Brush_mode_with_tool_poll");
|
||||
RNA_def_property_ui_text(prop, "Brush", "");
|
||||
}
|
||||
|
||||
static void rna_def_paint(BlenderRNA *brna)
|
||||
{
|
||||
StructRNA *srna;
|
||||
|
@ -623,9 +512,11 @@ static void rna_def_paint(BlenderRNA *brna)
|
|||
/* Global Settings */
|
||||
prop = RNA_def_property(srna, "brush", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_pointer_funcs(prop, nullptr, nullptr, nullptr, "rna_Brush_mode_poll");
|
||||
RNA_def_property_struct_type(prop, "Brush");
|
||||
RNA_def_property_pointer_funcs(
|
||||
prop, "rna_Paint_brush_get", "rna_Paint_brush_set", nullptr, "rna_Paint_brush_poll");
|
||||
RNA_def_property_ui_text(prop, "Brush", "Active Brush");
|
||||
RNA_def_property_update(prop, 0, "rna_Paint_brush_update");
|
||||
RNA_def_property_update(prop, NC_BRUSH | NA_SELECTED, nullptr);
|
||||
|
||||
prop = RNA_def_property(srna, "brush_asset_reference", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
|
@ -634,22 +525,6 @@ static void rna_def_paint(BlenderRNA *brna)
|
|||
"A weak reference to the matching brush asset, used e.g. to restore "
|
||||
"the last used brush on file load");
|
||||
|
||||
/* paint_tool_slots */
|
||||
prop = RNA_def_property(srna, "tool_slots", PROP_COLLECTION, PROP_NONE);
|
||||
RNA_def_property_collection_sdna(prop, nullptr, "tool_slots", "tool_slots_len");
|
||||
RNA_def_property_struct_type(prop, "PaintToolSlot");
|
||||
/* don't dereference pointer! */
|
||||
RNA_def_property_collection_funcs(prop,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
"rna_iterator_array_get",
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr);
|
||||
RNA_def_property_ui_text(prop, "Paint Tool Slots", "");
|
||||
|
||||
prop = RNA_def_property(srna, "palette", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_pointer_funcs(prop, nullptr, nullptr, nullptr, nullptr);
|
||||
|
@ -1687,7 +1562,6 @@ void RNA_def_sculpt_paint(BlenderRNA *brna)
|
|||
/* *** Non-Animated *** */
|
||||
RNA_define_animate_sdna(false);
|
||||
rna_def_paint_curve(brna);
|
||||
rna_def_paint_tool_slot(brna);
|
||||
rna_def_paint(brna);
|
||||
rna_def_sculpt(brna);
|
||||
rna_def_uv_sculpt(brna);
|
||||
|
|
Loading…
Reference in New Issue