From 6a03e8249da694f01a33148bede8e841ea23b7ed Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Thu, 5 Jun 2025 00:44:43 +0200 Subject: [PATCH] Paint: Add forward compatibility code for brush size In 5.0, we plan to change the brush size from representing radius to diameter. This means that for 5.0 files loaded in 4.5, we need to scale the stored value when reading the relevant brush fields. Related to #134204 Pull Request: https://projects.blender.org/blender/blender/pulls/139561 --- source/blender/blenkernel/intern/brush.cc | 7 +++++++ source/blender/blenkernel/intern/scene.cc | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/source/blender/blenkernel/intern/brush.cc b/source/blender/blenkernel/intern/brush.cc index 534aa5da607..ac5cb6dcd43 100644 --- a/source/blender/blenkernel/intern/brush.cc +++ b/source/blender/blenkernel/intern/brush.cc @@ -401,6 +401,13 @@ static void brush_blend_read_data(BlendDataReader *reader, ID *id) brush->icon_imbuf = nullptr; brush->has_unsaved_changes = false; + + /* Prior to 5.0, the brush->size value is expected to be the radius, not the diameter. To ensure + * correct behavior, convert this when reading newer files. */ + if (BLO_read_fileversion_get(reader) > 500) { + brush->size = std::max(brush->size / 2, 1); + brush->unprojected_radius = std::max(brush->unprojected_radius / 2, 0.001f); + } } static void brush_blend_read_after_liblink(BlendLibReader * /*reader*/, ID *id) diff --git a/source/blender/blenkernel/intern/scene.cc b/source/blender/blenkernel/intern/scene.cc index 3ec88fb6f60..4b4f56c08c9 100644 --- a/source/blender/blenkernel/intern/scene.cc +++ b/source/blender/blenkernel/intern/scene.cc @@ -1224,6 +1224,13 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id) zero_v3(ups->last_location); ups->last_hit = 0; + /* Prior to 5.0, the brush->size value is expected to be the radius, not the diameter. To + * ensure correct behavior, convert this when reading newer files. */ + if (BLO_read_fileversion_get(reader)) { + ups->size = std::max(ups->size / 2, 1); + ups->unprojected_radius = std::max(ups->unprojected_radius / 2, 0.001f); + } + BLO_read_struct(reader, CurveMapping, &ups->curve_rand_hue); if (ups->curve_rand_hue) { BKE_curvemapping_blend_read(reader, ups->curve_rand_hue);