Fix: Empty grease pencil brush libraries linked on startup
Second part to fix #128420. On startup, the Blender File Outliner mode would show empty libraries linked, pointing to the brush essentials files. This was because some grease pencil versioning code would call `BKE_paint_ensure_from_paintmode()`, which would link in the default brushes. Then a bit later, brush assets versioning code would remove local brushes from the default starup file, so the library link became empty. Initializing paint data shouldn't necessarily include importing default brushes. In an earlier version I made this optional with a boolean, but it's easy enough to separate out entirely. Now `BKE_paint_ensure()` just initializes paint data, and `BKE_paint_brushes_ensure()` has to be called to ensure that active brushes are available. Pull Request: https://projects.blender.org/blender/blender/pulls/128801
This commit is contained in:
committed by
Julian Eisel
parent
ee3fdf4099
commit
2499299ff2
@@ -181,8 +181,12 @@ PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name);
|
||||
/**
|
||||
* Call when entering each respective paint mode.
|
||||
*/
|
||||
bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint);
|
||||
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3]);
|
||||
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint);
|
||||
/**
|
||||
* \param ensure_brushes: Call #BKE_paint_brushes_ensure().
|
||||
*/
|
||||
void BKE_paint_init(
|
||||
Main *bmain, Scene *sce, PaintMode mode, const uchar col[3], bool ensure_brushes = true);
|
||||
void BKE_paint_free(Paint *paint);
|
||||
/**
|
||||
* Called when copying scene settings, so even if 'src' and 'tar' are the same still do a
|
||||
@@ -194,7 +198,7 @@ void BKE_paint_copy(const Paint *src, Paint *dst, int flag);
|
||||
void BKE_paint_cavity_curve_preset(Paint *paint, int preset);
|
||||
|
||||
eObjectMode BKE_paint_object_mode_from_paintmode(PaintMode mode);
|
||||
bool BKE_paint_ensure_from_paintmode(Main *bmain, Scene *sce, PaintMode mode);
|
||||
bool BKE_paint_ensure_from_paintmode(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);
|
||||
uint BKE_paint_get_brush_type_offset_from_paintmode(PaintMode mode);
|
||||
@@ -246,6 +250,17 @@ bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
|
||||
std::optional<AssetWeakReference> BKE_paint_brush_type_default_reference(
|
||||
eObjectMode ob_mode, std::optional<int> brush_type);
|
||||
void BKE_paint_brushes_set_default_references(ToolSettings *ts);
|
||||
/**
|
||||
* Make sure the active brush asset is available as active brush, importing it if necessary. If
|
||||
* there is no user set active brush, the default one is used/imported from the essentials asset
|
||||
* library.
|
||||
*
|
||||
* It's good to avoid this until the user actually shows intentions to use brushes, to avoid unused
|
||||
* brushes in files. E.g. use this when entering a paint mode, but not for versioning.
|
||||
*
|
||||
* Also handles the active eraser brush asset.
|
||||
*/
|
||||
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint);
|
||||
void BKE_paint_brushes_validate(Main *bmain, Paint *paint);
|
||||
|
||||
/* Secondary eraser brush. */
|
||||
|
||||
@@ -317,7 +317,7 @@ void BKE_paint_reset_overlay_invalid(ePaintOverlayControlFlags flag)
|
||||
overlay_flags &= ~(flag);
|
||||
}
|
||||
|
||||
bool BKE_paint_ensure_from_paintmode(Main *bmain, Scene *sce, PaintMode mode)
|
||||
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
|
||||
{
|
||||
ToolSettings *ts = sce->toolsettings;
|
||||
Paint **paint_ptr = nullptr;
|
||||
@@ -362,7 +362,7 @@ bool BKE_paint_ensure_from_paintmode(Main *bmain, Scene *sce, PaintMode mode)
|
||||
break;
|
||||
}
|
||||
if (paint_ptr) {
|
||||
BKE_paint_ensure(bmain, ts, paint_ptr);
|
||||
BKE_paint_ensure(ts, paint_ptr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1671,7 +1671,7 @@ eObjectMode BKE_paint_object_mode_from_paintmode(const PaintMode mode)
|
||||
}
|
||||
}
|
||||
|
||||
bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint)
|
||||
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
|
||||
{
|
||||
Paint *paint = nullptr;
|
||||
if (*r_paint) {
|
||||
@@ -1680,8 +1680,6 @@ bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint)
|
||||
BLI_assert(ELEM(*r_paint, (Paint *)&ts->imapaint));
|
||||
|
||||
paint_runtime_init(ts, *r_paint);
|
||||
BKE_paint_brush_set_default(bmain, *r_paint);
|
||||
BKE_paint_eraser_brush_set_default(bmain, *r_paint);
|
||||
}
|
||||
else {
|
||||
BLI_assert(ELEM(*r_paint,
|
||||
@@ -1703,8 +1701,6 @@ bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint)
|
||||
BLI_assert(paint_test.runtime.ob_mode == (*r_paint)->runtime.ob_mode);
|
||||
#endif
|
||||
}
|
||||
paint_brush_update_from_asset_reference(bmain, *r_paint);
|
||||
paint_eraser_brush_set_from_asset_reference(bmain, *r_paint);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1748,19 +1744,39 @@ bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint)
|
||||
*r_paint = paint;
|
||||
|
||||
paint_runtime_init(ts, paint);
|
||||
BKE_paint_brush_set_default(bmain, paint);
|
||||
BKE_paint_eraser_brush_set_default(bmain, paint);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3])
|
||||
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
|
||||
{
|
||||
if (paint->brush_asset_reference) {
|
||||
paint_brush_update_from_asset_reference(bmain, paint);
|
||||
}
|
||||
if (paint->eraser_brush_asset_reference) {
|
||||
paint_eraser_brush_set_from_asset_reference(bmain, paint);
|
||||
}
|
||||
|
||||
if (!paint->brush) {
|
||||
BKE_paint_brush_set_default(bmain, paint);
|
||||
}
|
||||
if (!paint->eraser_brush) {
|
||||
BKE_paint_eraser_brush_set_default(bmain, paint);
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_paint_init(
|
||||
Main *bmain, Scene *sce, PaintMode mode, const uchar col[3], const bool ensure_brushes)
|
||||
{
|
||||
UnifiedPaintSettings *ups = &sce->toolsettings->unified_paint_settings;
|
||||
|
||||
BKE_paint_ensure_from_paintmode(bmain, sce, mode);
|
||||
BKE_paint_ensure_from_paintmode(sce, mode);
|
||||
Paint *paint = BKE_paint_get_active_from_paintmode(sce, mode);
|
||||
|
||||
if (ensure_brushes) {
|
||||
BKE_paint_brushes_ensure(bmain, paint);
|
||||
}
|
||||
|
||||
copy_v3_v3_uchar(paint->paint_cursor_col, col);
|
||||
paint->paint_cursor_col[3] = 128;
|
||||
ups->last_stroke_valid = false;
|
||||
@@ -2649,7 +2665,8 @@ void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph,
|
||||
|
||||
void BKE_sculpt_toolsettings_data_ensure(Main *bmain, Scene *scene)
|
||||
{
|
||||
BKE_paint_ensure(bmain, scene->toolsettings, (Paint **)&scene->toolsettings->sculpt);
|
||||
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->sculpt);
|
||||
BKE_paint_brushes_ensure(bmain, &scene->toolsettings->sculpt->paint);
|
||||
|
||||
Sculpt *sd = scene->toolsettings->sculpt;
|
||||
|
||||
|
||||
@@ -2886,10 +2886,10 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain)
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
|
||||
/* Ensure new Paint modes. */
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::GPencil);
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil);
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil);
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::GPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil);
|
||||
|
||||
/* Enable cursor by default. */
|
||||
Paint *paint = &ts->gp_paint->paint;
|
||||
@@ -2933,9 +2933,9 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain)
|
||||
/* Reset all grease pencil brushes. */
|
||||
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
|
||||
/* Ensure new Paint modes. */
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil);
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil);
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -513,9 +513,9 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
|
||||
/* Ensure new Paint modes. */
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil);
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil);
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil);
|
||||
BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil);
|
||||
|
||||
/* Enable cursor. */
|
||||
if (ts->gp_paint) {
|
||||
|
||||
@@ -81,8 +81,10 @@ static int paintmode_toggle_exec(bContext *C, wmOperator *op)
|
||||
if (mode == OB_MODE_PAINT_GREASE_PENCIL) {
|
||||
/* Be sure we have brushes and Paint settings.
|
||||
* Need Draw and Vertex (used for Tint). */
|
||||
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint);
|
||||
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_vertexpaint);
|
||||
BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
|
||||
BKE_paint_brushes_ensure(bmain, &ts->gp_paint->paint);
|
||||
BKE_paint_ensure(ts, (Paint **)&ts->gp_vertexpaint);
|
||||
BKE_paint_brushes_ensure(bmain, &ts->gp_vertexpaint->paint);
|
||||
|
||||
/* Ensure Palette by default. */
|
||||
BKE_gpencil_palette_ensure(bmain, CTX_data_scene(C));
|
||||
@@ -188,7 +190,8 @@ static int sculptmode_toggle_exec(bContext *C, wmOperator *op)
|
||||
ob->mode = mode;
|
||||
|
||||
if (mode == OB_MODE_SCULPT_GREASE_PENCIL) {
|
||||
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_sculptpaint);
|
||||
BKE_paint_ensure(ts, (Paint **)&ts->gp_sculptpaint);
|
||||
BKE_paint_brushes_ensure(bmain, &ts->gp_sculptpaint->paint);
|
||||
BKE_paint_brushes_validate(bmain, &ts->gp_sculptpaint->paint);
|
||||
}
|
||||
|
||||
@@ -278,13 +281,13 @@ static int weightmode_toggle_exec(bContext *C, wmOperator *op)
|
||||
|
||||
if (mode == OB_MODE_WEIGHT_GREASE_PENCIL) {
|
||||
/* Be sure we have brushes. */
|
||||
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_weightpaint);
|
||||
BKE_paint_ensure(ts, (Paint **)&ts->gp_weightpaint);
|
||||
Paint *weight_paint = BKE_paint_get_active_from_paintmode(scene, PaintMode::WeightGPencil);
|
||||
|
||||
ED_paint_cursor_start(weight_paint, grease_pencil_poll_weight_cursor);
|
||||
|
||||
BKE_paint_brushes_validate(bmain, weight_paint);
|
||||
BKE_paint_init(bmain, scene, PaintMode::WeightGPencil, PAINT_CURSOR_PAINT_GREASE_PENCIL);
|
||||
BKE_paint_brushes_validate(bmain, weight_paint);
|
||||
}
|
||||
|
||||
GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
|
||||
@@ -371,10 +374,13 @@ static int vertexmode_toggle_exec(bContext *C, wmOperator *op)
|
||||
if (mode == OB_MODE_VERTEX_GREASE_PENCIL) {
|
||||
/* Be sure we have brushes.
|
||||
* Need Draw as well (used for Palettes). */
|
||||
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint);
|
||||
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_vertexpaint);
|
||||
BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
|
||||
BKE_paint_ensure(ts, (Paint **)&ts->gp_vertexpaint);
|
||||
Paint *gp_paint = BKE_paint_get_active_from_paintmode(scene, PaintMode::GPencil);
|
||||
Paint *vertex_paint = BKE_paint_get_active_from_paintmode(scene, PaintMode::VertexGPencil);
|
||||
|
||||
BKE_paint_brushes_ensure(bmain, gp_paint);
|
||||
BKE_paint_brushes_ensure(bmain, vertex_paint);
|
||||
BKE_paint_brushes_validate(bmain, vertex_paint);
|
||||
|
||||
ED_paint_cursor_start(vertex_paint, grease_pencil_poll_vertex_cursor);
|
||||
|
||||
@@ -284,14 +284,16 @@ static void curves_sculptmode_enter(bContext *C)
|
||||
wmMsgBus *mbus = CTX_wm_message_bus(C);
|
||||
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
BKE_paint_ensure(
|
||||
CTX_data_main(C), scene->toolsettings, (Paint **)&scene->toolsettings->curves_sculpt);
|
||||
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->curves_sculpt);
|
||||
CurvesSculpt *curves_sculpt = scene->toolsettings->curves_sculpt;
|
||||
|
||||
ob->mode = OB_MODE_SCULPT_CURVES;
|
||||
|
||||
/* Setup cursor color. BKE_paint_init() could be used, but creates an additional brush. */
|
||||
Paint *paint = BKE_paint_get_active_from_paintmode(scene, PaintMode::SculptCurves);
|
||||
|
||||
BKE_paint_brushes_ensure(CTX_data_main(C), paint);
|
||||
|
||||
/* Setup cursor color. BKE_paint_init() could be used, but creates an additional brush. */
|
||||
copy_v3_v3_uchar(paint->paint_cursor_col, PAINT_CURSOR_SCULPT_CURVES);
|
||||
paint->paint_cursor_col[3] = 128;
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ void mode_enter_generic(
|
||||
const PaintMode paint_mode = PaintMode::Vertex;
|
||||
ED_mesh_color_ensure(mesh, nullptr);
|
||||
|
||||
BKE_paint_ensure(&bmain, scene.toolsettings, (Paint **)&scene.toolsettings->vpaint);
|
||||
BKE_paint_ensure(scene.toolsettings, (Paint **)&scene.toolsettings->vpaint);
|
||||
Paint *paint = BKE_paint_get_active_from_paintmode(&scene, paint_mode);
|
||||
ED_paint_cursor_start(paint, vertex_paint_poll);
|
||||
BKE_paint_init(&bmain, &scene, paint_mode, PAINT_CURSOR_VERTEX_PAINT);
|
||||
@@ -335,7 +335,7 @@ void mode_enter_generic(
|
||||
else if (mode_flag == OB_MODE_WEIGHT_PAINT) {
|
||||
const PaintMode paint_mode = PaintMode::Weight;
|
||||
|
||||
BKE_paint_ensure(&bmain, scene.toolsettings, (Paint **)&scene.toolsettings->wpaint);
|
||||
BKE_paint_ensure(scene.toolsettings, (Paint **)&scene.toolsettings->wpaint);
|
||||
Paint *paint = BKE_paint_get_active_from_paintmode(&scene, paint_mode);
|
||||
ED_paint_cursor_start(paint, weight_paint_poll);
|
||||
BKE_paint_init(&bmain, &scene, paint_mode, PAINT_CURSOR_WEIGHT_PAINT);
|
||||
|
||||
@@ -330,7 +330,7 @@ static void toolsystem_brush_activate_from_toolref_for_object_paint(const bConte
|
||||
continue;
|
||||
}
|
||||
Scene *scene = WM_window_get_active_scene(win);
|
||||
BKE_paint_ensure_from_paintmode(bmain, scene, paint_mode);
|
||||
BKE_paint_ensure_from_paintmode(scene, paint_mode);
|
||||
Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
|
||||
|
||||
/* Attempt to re-activate a brush remembered for this brush type, as stored in a brush
|
||||
|
||||
Reference in New Issue
Block a user