Sculpt/paint: Write brush types to brush asset metadata #124618

Merged
Julian Eisel merged 2 commits from JulianEisel/blender:temp-brush-assets-metadata-tool-type into main 2024-08-30 17:00:33 +02:00
3 changed files with 53 additions and 13 deletions

View File

@ -192,6 +192,8 @@ 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);
uint BKE_paint_get_brush_tool_offset_from_paintmode(PaintMode mode);
std::optional<int> BKE_paint_get_brush_tool_from_obmode(const Brush *brush,
const eObjectMode ob_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);

View File

@ -393,27 +393,37 @@ static void brush_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_da
/* Most names copied from brush RNA (not all are available there though). */
constexpr std::array mode_map{
std::pair{"use_paint_sculpt", OB_MODE_SCULPT},
std::pair{"use_paint_vertex", OB_MODE_VERTEX_PAINT},
std::pair{"use_paint_weight", OB_MODE_WEIGHT_PAINT},
std::pair{"use_paint_image", OB_MODE_TEXTURE_PAINT},
std::tuple{"use_paint_sculpt", OB_MODE_SCULPT, "sculpt_brush_type"},
std::tuple{"use_paint_vertex", OB_MODE_VERTEX_PAINT, "vertex_brush_type"},
std::tuple{"use_paint_weight", OB_MODE_WEIGHT_PAINT, "weight_brush_type"},
std::tuple{"use_paint_image", OB_MODE_TEXTURE_PAINT, "image_brush_type"},
/* Sculpt UVs in the image editor while in edit mode. */
std::pair{"use_paint_uv_sculpt", OB_MODE_EDIT},
std::pair{"use_paint_grease_pencil", OB_MODE_PAINT_GPENCIL_LEGACY},
std::tuple{"use_paint_uv_sculpt", OB_MODE_EDIT, "image_brush_type"},
std::tuple{"use_paint_grease_pencil", OB_MODE_PAINT_GPENCIL_LEGACY, "gpencil_brush_type"},
/* Note: Not defined in brush RNA, own name. */
std::pair{"use_sculpt_grease_pencil", OB_MODE_SCULPT_GPENCIL_LEGACY},
std::pair{"use_vertex_grease_pencil", OB_MODE_VERTEX_GPENCIL_LEGACY},
std::pair{"use_weight_grease_pencil", OB_MODE_WEIGHT_GPENCIL_LEGACY},
std::pair{"use_paint_sculpt_curves", OB_MODE_SCULPT_CURVES},
std::tuple{
"use_sculpt_grease_pencil", OB_MODE_SCULPT_GPENCIL_LEGACY, "gpencil_sculpt_brush_type"},
std::tuple{
"use_vertex_grease_pencil", OB_MODE_VERTEX_GPENCIL_LEGACY, "gpencil_vertex_brush_type"},
std::tuple{"use_weight_gpencil", OB_MODE_WEIGHT_GPENCIL_LEGACY, "gpencil_weight_brush_type"},
std::tuple{"use_paint_sculpt_curves", OB_MODE_SCULPT_CURVES, "curves_sculpt_brush_type"},
};
for (const auto &mode_mapping : mode_map) {
for (const auto &[prop_name, mode, tool_prop_name] : mode_map) {
/* Only add bools for supported modes. */
if (!(brush->ob_mode & mode_mapping.second)) {
if (!(brush->ob_mode & mode)) {
continue;
}
auto mode_property = idprop::create_bool(mode_mapping.first, true);
auto mode_property = idprop::create_bool(prop_name, true);
BKE_asset_metadata_idprop_ensure(asset_data, mode_property.release());
if (std::optional<int> brush_tool = BKE_paint_get_brush_tool_from_obmode(brush, mode)) {
auto type_property = idprop::create(tool_prop_name, *brush_tool);
BKE_asset_metadata_idprop_ensure(asset_data, type_property.release());
}
else {
BLI_assert_unreachable();
}
}
}

View File

@ -975,6 +975,34 @@ uint BKE_paint_get_brush_tool_offset_from_paintmode(const PaintMode mode)
return 0;
}
std::optional<int> BKE_paint_get_brush_tool_from_obmode(const Brush *brush,
const eObjectMode ob_mode)
{
switch (ob_mode) {
case OB_MODE_TEXTURE_PAINT:
case OB_MODE_EDIT:
return brush->imagepaint_tool;
case OB_MODE_SCULPT:
return brush->sculpt_tool;
case OB_MODE_VERTEX_PAINT:
return brush->vertexpaint_tool;
case OB_MODE_WEIGHT_PAINT:
return brush->weightpaint_tool;
case OB_MODE_PAINT_GPENCIL_LEGACY:
return brush->gpencil_tool;
case OB_MODE_VERTEX_GPENCIL_LEGACY:
return brush->gpencil_vertex_tool;
case OB_MODE_SCULPT_GPENCIL_LEGACY:
return brush->gpencil_sculpt_tool;
case OB_MODE_WEIGHT_GPENCIL_LEGACY:
return brush->gpencil_weight_tool;
case OB_MODE_SCULPT_CURVES:
return brush->curves_sculpt_tool;
default:
return {};
}
}
PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name)
{
PaintCurve *pc = static_cast<PaintCurve *>(BKE_id_new(bmain, ID_PC, name));