Paint: add BKE_paint_ensure to initialize toolsettings
Each mode had its own logic for initializing paint structs, move to a single function. Also remove "BKE_brush_get_gpencil_paint", entering grease pencil mode is responsible for ensuring the data is created.
This commit is contained in:
@@ -62,7 +62,6 @@ void BKE_brush_sculpt_reset(struct Brush *brush);
|
|||||||
void BKE_brush_gpencil_presets(struct bContext *C);
|
void BKE_brush_gpencil_presets(struct bContext *C);
|
||||||
void BKE_brush_update_material(struct Main *bmain, struct Material *ma, struct Brush *exclude_brush);
|
void BKE_brush_update_material(struct Main *bmain, struct Material *ma, struct Brush *exclude_brush);
|
||||||
struct Brush *BKE_brush_getactive_gpencil(struct ToolSettings *ts);
|
struct Brush *BKE_brush_getactive_gpencil(struct ToolSettings *ts);
|
||||||
struct Paint *BKE_brush_get_gpencil_paint(struct ToolSettings *ts);
|
|
||||||
|
|
||||||
/* image icon function */
|
/* image icon function */
|
||||||
struct ImBuf *get_brush_icon(struct Brush *brush);
|
struct ImBuf *get_brush_icon(struct Brush *brush);
|
||||||
|
@@ -61,6 +61,7 @@ struct Tex;
|
|||||||
struct ImagePool;
|
struct ImagePool;
|
||||||
struct UnifiedPaintSettings;
|
struct UnifiedPaintSettings;
|
||||||
struct Depsgraph;
|
struct Depsgraph;
|
||||||
|
struct ToolSettings;
|
||||||
|
|
||||||
enum eOverlayFlags;
|
enum eOverlayFlags;
|
||||||
|
|
||||||
@@ -124,6 +125,7 @@ void BKE_paint_curve_copy_data(
|
|||||||
struct PaintCurve *BKE_paint_curve_copy(struct Main *bmain, const struct PaintCurve *pc);
|
struct PaintCurve *BKE_paint_curve_copy(struct Main *bmain, const struct PaintCurve *pc);
|
||||||
void BKE_paint_curve_make_local(struct Main *bmain, struct PaintCurve *pc, const bool lib_local);
|
void BKE_paint_curve_make_local(struct Main *bmain, struct PaintCurve *pc, const bool lib_local);
|
||||||
|
|
||||||
|
bool BKE_paint_ensure(const struct ToolSettings *ts, struct Paint **r_paint);
|
||||||
void BKE_paint_init(struct Main *bmain, struct Scene *sce, ePaintMode mode, const char col[3]);
|
void BKE_paint_init(struct Main *bmain, struct Scene *sce, ePaintMode mode, const char col[3]);
|
||||||
void BKE_paint_free(struct Paint *p);
|
void BKE_paint_free(struct Paint *p);
|
||||||
void BKE_paint_copy(struct Paint *src, struct Paint *tar, const int flag);
|
void BKE_paint_copy(struct Paint *src, struct Paint *tar, const int flag);
|
||||||
|
@@ -193,7 +193,7 @@ void BKE_brush_init_gpencil_settings(Brush *brush)
|
|||||||
Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name)
|
Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name)
|
||||||
{
|
{
|
||||||
Brush *brush;
|
Brush *brush;
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
Paint *paint = &ts->gp_paint->paint;
|
||||||
brush = BKE_brush_add(bmain, name, OB_MODE_GPENCIL_PAINT);
|
brush = BKE_brush_add(bmain, name, OB_MODE_GPENCIL_PAINT);
|
||||||
|
|
||||||
BKE_paint_brush_set(paint, brush);
|
BKE_paint_brush_set(paint, brush);
|
||||||
@@ -208,16 +208,6 @@ Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name)
|
|||||||
return brush;
|
return brush;
|
||||||
}
|
}
|
||||||
|
|
||||||
Paint *BKE_brush_get_gpencil_paint(ToolSettings *ts)
|
|
||||||
{
|
|
||||||
/* alloc paint session */
|
|
||||||
if (ts->gp_paint == NULL) {
|
|
||||||
ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ts->gp_paint->paint;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* grease pencil cumapping->preset */
|
/* grease pencil cumapping->preset */
|
||||||
typedef enum eGPCurveMappingPreset {
|
typedef enum eGPCurveMappingPreset {
|
||||||
GPCURVE_PRESET_PENCIL = 0,
|
GPCURVE_PRESET_PENCIL = 0,
|
||||||
@@ -273,7 +263,7 @@ void BKE_brush_gpencil_presets(bContext *C)
|
|||||||
#define SMOOTH_STROKE_FACTOR 0.9f
|
#define SMOOTH_STROKE_FACTOR 0.9f
|
||||||
|
|
||||||
ToolSettings *ts = CTX_data_tool_settings(C);
|
ToolSettings *ts = CTX_data_tool_settings(C);
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
Paint *paint = &ts->gp_paint->paint;
|
||||||
Main *bmain = CTX_data_main(C);
|
Main *bmain = CTX_data_main(C);
|
||||||
|
|
||||||
Brush *brush, *deft;
|
Brush *brush, *deft;
|
||||||
|
@@ -570,6 +570,53 @@ eObjectMode BKE_paint_object_mode_from_paint_mode(ePaintMode mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call when entering each respective paint mode.
|
||||||
|
*/
|
||||||
|
bool BKE_paint_ensure(const ToolSettings *ts, struct Paint **r_paint)
|
||||||
|
{
|
||||||
|
Paint *paint = NULL;
|
||||||
|
if (*r_paint) {
|
||||||
|
/* Note: 'ts->imapaint' is ignored, it's not allocated. */
|
||||||
|
BLI_assert(
|
||||||
|
ELEM(*r_paint,
|
||||||
|
&ts->gp_paint->paint,
|
||||||
|
&ts->sculpt->paint,
|
||||||
|
&ts->vpaint->paint,
|
||||||
|
&ts->wpaint->paint,
|
||||||
|
&ts->uvsculpt->paint));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ELEM(*r_paint, &ts->vpaint->paint, &ts->wpaint->paint)) {
|
||||||
|
VPaint *data = MEM_callocN(sizeof(*data), __func__);
|
||||||
|
paint = &data->paint;
|
||||||
|
}
|
||||||
|
else if (*r_paint == &ts->sculpt->paint) {
|
||||||
|
Sculpt *data = MEM_callocN(sizeof(*data), __func__);
|
||||||
|
paint = &data->paint;
|
||||||
|
|
||||||
|
/* Turn on X plane mirror symmetry by default */
|
||||||
|
paint->symmetry_flags |= PAINT_SYMM_X;
|
||||||
|
|
||||||
|
/* Make sure at least dyntopo subdivision is enabled */
|
||||||
|
data->flags |= SCULPT_DYNTOPO_SUBDIVIDE | SCULPT_DYNTOPO_COLLAPSE;
|
||||||
|
}
|
||||||
|
else if (*r_paint == &ts->gp_paint->paint) {
|
||||||
|
GpPaint *data = MEM_callocN(sizeof(*data), __func__);
|
||||||
|
paint = &data->paint;
|
||||||
|
}
|
||||||
|
else if (*r_paint == &ts->uvsculpt->paint) {
|
||||||
|
UvSculpt *data = MEM_callocN(sizeof(*data), __func__);
|
||||||
|
paint = &data->paint;
|
||||||
|
}
|
||||||
|
|
||||||
|
paint->flags |= PAINT_SHOW_BRUSH;
|
||||||
|
|
||||||
|
*r_paint = paint;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void BKE_paint_init(Main *bmain, Scene *sce, ePaintMode mode, const char col[3])
|
void BKE_paint_init(Main *bmain, Scene *sce, ePaintMode mode, const char col[3])
|
||||||
{
|
{
|
||||||
UnifiedPaintSettings *ups = &sce->toolsettings->unified_paint_settings;
|
UnifiedPaintSettings *ups = &sce->toolsettings->unified_paint_settings;
|
||||||
@@ -1144,18 +1191,9 @@ int BKE_sculpt_mask_layers_ensure(Object *ob, MultiresModifierData *mmd)
|
|||||||
|
|
||||||
void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene)
|
void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene)
|
||||||
{
|
{
|
||||||
|
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->sculpt);
|
||||||
|
|
||||||
Sculpt *sd = scene->toolsettings->sculpt;
|
Sculpt *sd = scene->toolsettings->sculpt;
|
||||||
if (sd == NULL) {
|
|
||||||
sd = scene->toolsettings->sculpt = MEM_callocN(sizeof(Sculpt), __func__);
|
|
||||||
|
|
||||||
/* Turn on X plane mirror symmetry by default */
|
|
||||||
sd->paint.symmetry_flags |= PAINT_SYMM_X;
|
|
||||||
sd->paint.flags |= PAINT_SHOW_BRUSH;
|
|
||||||
|
|
||||||
/* Make sure at least dyntopo subdivision is enabled */
|
|
||||||
sd->flags |= SCULPT_DYNTOPO_SUBDIVIDE | SCULPT_DYNTOPO_COLLAPSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sd->detail_size) {
|
if (!sd->detail_size) {
|
||||||
sd->detail_size = 12;
|
sd->detail_size = 12;
|
||||||
}
|
}
|
||||||
|
@@ -688,9 +688,6 @@ void BKE_scene_init(Scene *sce)
|
|||||||
sce->toolsettings->imapaint.normal_angle = 80;
|
sce->toolsettings->imapaint.normal_angle = 80;
|
||||||
sce->toolsettings->imapaint.seam_bleed = 2;
|
sce->toolsettings->imapaint.seam_bleed = 2;
|
||||||
|
|
||||||
/* alloc grease pencil drawing brushes */
|
|
||||||
sce->toolsettings->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
|
|
||||||
|
|
||||||
/* grease pencil multiframe falloff curve */
|
/* grease pencil multiframe falloff curve */
|
||||||
sce->toolsettings->gp_sculpt.cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
sce->toolsettings->gp_sculpt.cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
||||||
CurveMapping *gp_falloff_curve = sce->toolsettings->gp_sculpt.cur_falloff;
|
CurveMapping *gp_falloff_curve = sce->toolsettings->gp_sculpt.cur_falloff;
|
||||||
|
@@ -1561,7 +1561,7 @@ static int gp_brush_select_exec(bContext *C, wmOperator *op)
|
|||||||
|
|
||||||
const int index = RNA_int_get(op->ptr, "index");
|
const int index = RNA_int_get(op->ptr, "index");
|
||||||
|
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
Paint *paint = &ts->gp_paint->paint;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
|
for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
|
||||||
if (brush->ob_mode == OB_MODE_GPENCIL_PAINT) {
|
if (brush->ob_mode == OB_MODE_GPENCIL_PAINT) {
|
||||||
|
@@ -319,7 +319,8 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op)
|
|||||||
|
|
||||||
if (mode == OB_MODE_GPENCIL_PAINT) {
|
if (mode == OB_MODE_GPENCIL_PAINT) {
|
||||||
/* be sure we have brushes */
|
/* be sure we have brushes */
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
|
||||||
|
Paint *paint = &ts->gp_paint->paint;
|
||||||
/* if not exist, create a new one */
|
/* if not exist, create a new one */
|
||||||
if (paint->brush == NULL) {
|
if (paint->brush == NULL) {
|
||||||
BKE_brush_gpencil_presets(C);
|
BKE_brush_gpencil_presets(C);
|
||||||
|
@@ -105,7 +105,6 @@ static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op))
|
|||||||
{
|
{
|
||||||
Main *bmain = CTX_data_main(C);
|
Main *bmain = CTX_data_main(C);
|
||||||
Scene *scene = CTX_data_scene(C);
|
Scene *scene = CTX_data_scene(C);
|
||||||
ToolSettings *ts = CTX_data_tool_settings(C);
|
|
||||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||||
|
|
||||||
/* Convert grease pencil scene datablock to GP object */
|
/* Convert grease pencil scene datablock to GP object */
|
||||||
@@ -114,13 +113,6 @@ static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op))
|
|||||||
ob = BKE_object_add_for_data(bmain, view_layer, OB_GPENCIL, "GP_Scene", &scene->gpd->id, false);
|
ob = BKE_object_add_for_data(bmain, view_layer, OB_GPENCIL, "GP_Scene", &scene->gpd->id, false);
|
||||||
zero_v3(ob->loc);
|
zero_v3(ob->loc);
|
||||||
|
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
|
||||||
/* if not exist, create a new one */
|
|
||||||
if (paint->brush == NULL) {
|
|
||||||
/* create new brushes */
|
|
||||||
BKE_brush_gpencil_presets(C);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* convert grease pencil palettes (version >= 2.78) to materials and weights */
|
/* convert grease pencil palettes (version >= 2.78) to materials and weights */
|
||||||
bGPdata *gpd = scene->gpd;
|
bGPdata *gpd = scene->gpd;
|
||||||
for (const bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
|
for (const bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
|
||||||
|
@@ -1641,7 +1641,7 @@ static void gp_session_validatebuffer(tGPsdata *p)
|
|||||||
static Brush *gp_get_default_eraser(Main *bmain, ToolSettings *ts)
|
static Brush *gp_get_default_eraser(Main *bmain, ToolSettings *ts)
|
||||||
{
|
{
|
||||||
Brush *brush_dft = NULL;
|
Brush *brush_dft = NULL;
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
Paint *paint = &ts->gp_paint->paint;
|
||||||
Brush *brush_old = paint->brush;
|
Brush *brush_old = paint->brush;
|
||||||
for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
|
for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
|
||||||
if ((brush->ob_mode == OB_MODE_GPENCIL_PAINT) &&
|
if ((brush->ob_mode == OB_MODE_GPENCIL_PAINT) &&
|
||||||
@@ -1685,7 +1685,7 @@ static void gp_init_drawing_brush(bContext *C, tGPsdata *p)
|
|||||||
Scene *scene = CTX_data_scene(C);
|
Scene *scene = CTX_data_scene(C);
|
||||||
ToolSettings *ts = CTX_data_tool_settings(C);
|
ToolSettings *ts = CTX_data_tool_settings(C);
|
||||||
|
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
Paint *paint = &ts->gp_paint->paint;
|
||||||
|
|
||||||
/* if not exist, create a new one */
|
/* if not exist, create a new one */
|
||||||
if (paint->brush == NULL) {
|
if (paint->brush == NULL) {
|
||||||
|
@@ -144,7 +144,7 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
|
|||||||
Brush *brush;
|
Brush *brush;
|
||||||
|
|
||||||
/* if brush doesn't exist, create a new one */
|
/* if brush doesn't exist, create a new one */
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
Paint *paint = &ts->gp_paint->paint;
|
||||||
/* if not exist, create a new one */
|
/* if not exist, create a new one */
|
||||||
if (paint->brush == NULL) {
|
if (paint->brush == NULL) {
|
||||||
/* create new brushes */
|
/* create new brushes */
|
||||||
|
@@ -1201,7 +1201,8 @@ void ED_gpencil_add_defaults(bContext *C)
|
|||||||
/* ensure color exist */
|
/* ensure color exist */
|
||||||
BKE_gpencil_material_ensure(bmain, ob);
|
BKE_gpencil_material_ensure(bmain, ob);
|
||||||
|
|
||||||
Paint *paint = BKE_brush_get_gpencil_paint(ts);
|
BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
|
||||||
|
Paint *paint = &ts->gp_paint->paint;
|
||||||
/* if not exist, create a new one */
|
/* if not exist, create a new one */
|
||||||
if (paint->brush == NULL) {
|
if (paint->brush == NULL) {
|
||||||
/* create new brushes */
|
/* create new brushes */
|
||||||
|
@@ -236,15 +236,12 @@ void ED_space_image_uv_sculpt_update(Main *bmain, wmWindowManager *wm, Scene *sc
|
|||||||
{
|
{
|
||||||
ToolSettings *settings = scene->toolsettings;
|
ToolSettings *settings = scene->toolsettings;
|
||||||
if (settings->use_uv_sculpt) {
|
if (settings->use_uv_sculpt) {
|
||||||
if (!settings->uvsculpt) {
|
if (settings->uvsculpt == NULL) {
|
||||||
settings->uvsculpt = MEM_callocN(sizeof(*settings->uvsculpt), "UV Smooth paint");
|
|
||||||
settings->uv_sculpt_tool = UV_SCULPT_TOOL_GRAB;
|
settings->uv_sculpt_tool = UV_SCULPT_TOOL_GRAB;
|
||||||
settings->uv_sculpt_settings = UV_SCULPT_LOCK_BORDERS | UV_SCULPT_ALL_ISLANDS;
|
settings->uv_sculpt_settings = UV_SCULPT_LOCK_BORDERS | UV_SCULPT_ALL_ISLANDS;
|
||||||
settings->uv_relax_method = UV_SCULPT_TOOL_RELAX_LAPLACIAN;
|
settings->uv_relax_method = UV_SCULPT_TOOL_RELAX_LAPLACIAN;
|
||||||
/* Uv sculpting does not include explicit brush view control yet, always enable */
|
|
||||||
settings->uvsculpt->paint.flags |= PAINT_SHOW_BRUSH;
|
|
||||||
}
|
}
|
||||||
|
BKE_paint_ensure(settings, (Paint **)&settings->uvsculpt);
|
||||||
BKE_paint_init(bmain, scene, ePaintSculptUV, PAINT_CURSOR_SCULPT);
|
BKE_paint_init(bmain, scene, ePaintSculptUV, PAINT_CURSOR_SCULPT);
|
||||||
|
|
||||||
settings->uvsculpt->paint.paint_cursor = WM_paint_cursor_activate(
|
settings->uvsculpt->paint.paint_cursor = WM_paint_cursor_activate(
|
||||||
|
Reference in New Issue
Block a user