From 6f57268e9a2c77691318c1a4f21404c819ce55fd Mon Sep 17 00:00:00 2001 From: YimingWu Date: Thu, 7 Aug 2025 15:40:17 +0200 Subject: [PATCH] LineArt: Use "Radius" instead of "Thickness" for generating strokes Previously line art uses the same thickness value as found in grease pencil before blender v4.3 for generating strokes, now everything is migrated to using "radius", so it makes more sense to change that it to using "radius" so it's consistent with everywhere else. Pull Request: https://projects.blender.org/blender/blender/pulls/144121 --- .../intern/grease_pencil_convert_legacy.cc | 4 ++-- .../blender/blenloader/intern/versioning_500.cc | 17 +++++++++++++++++ .../intern/grease_pencil_lineart.cc | 2 +- source/blender/makesdna/DNA_modifier_defaults.h | 3 ++- source/blender/makesdna/DNA_modifier_types.h | 6 ++++-- .../blender/makesdna/intern/dna_rename_defs.h | 1 + source/blender/makesrna/intern/rna_modifier.cc | 8 ++++---- source/blender/modifiers/intern/MOD_lineart.cc | 4 ++-- 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc b/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc index 5d667d42b5c..95b853b3faa 100644 --- a/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc +++ b/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc @@ -3197,7 +3197,7 @@ void lineart_wrap_v3(const LineartGpencilModifierData *lmd_legacy, lmd->shadow_camera_near = lmd_legacy->shadow_camera_near; lmd->shadow_camera_far = lmd_legacy->shadow_camera_far; lmd->opacity = lmd_legacy->opacity; - lmd->thickness = lmd_legacy->thickness; + lmd->radius = float(lmd_legacy->thickness) * LEGACY_RADIUS_CONVERSION_FACTOR; lmd->mask_switches = lmd_legacy->mask_switches; lmd->material_mask_bits = lmd_legacy->material_mask_bits; lmd->intersection_mask = lmd_legacy->intersection_mask; @@ -3240,7 +3240,7 @@ void lineart_unwrap_v3(LineartGpencilModifierData *lmd_legacy, lmd_legacy->shadow_camera_near = lmd->shadow_camera_near; lmd_legacy->shadow_camera_far = lmd->shadow_camera_far; lmd_legacy->opacity = lmd->opacity; - lmd_legacy->thickness = lmd->thickness; + lmd_legacy->thickness = lmd->radius / LEGACY_RADIUS_CONVERSION_FACTOR; lmd_legacy->mask_switches = lmd->mask_switches; lmd_legacy->material_mask_bits = lmd->material_mask_bits; lmd_legacy->intersection_mask = lmd->intersection_mask; diff --git a/source/blender/blenloader/intern/versioning_500.cc b/source/blender/blenloader/intern/versioning_500.cc index c639747cda7..3fa41f2b61f 100644 --- a/source/blender/blenloader/intern/versioning_500.cc +++ b/source/blender/blenloader/intern/versioning_500.cc @@ -17,6 +17,7 @@ #include "DNA_curves_types.h" #include "DNA_grease_pencil_types.h" #include "DNA_mesh_types.h" +#include "DNA_modifier_types.h" #include "DNA_node_types.h" #include "DNA_rigidbody_types.h" #include "DNA_screen_types.h" @@ -37,6 +38,7 @@ #include "BKE_attribute_legacy_convert.hh" #include "BKE_colortools.hh" #include "BKE_curves.hh" +#include "BKE_grease_pencil.hh" #include "BKE_idprop.hh" #include "BKE_image_format.hh" #include "BKE_lib_id.hh" @@ -2161,6 +2163,21 @@ void blo_do_versions_500(FileData * /*fd*/, Library * /*lib*/, Main *bmain) } if (!MAIN_VERSION_FILE_ATLEAST(bmain, 500, 54)) { + LISTBASE_FOREACH (Object *, object, &bmain->objects) { + LISTBASE_FOREACH (ModifierData *, modifier, &object->modifiers) { + if (modifier->type != eModifierType_GreasePencilLineart) { + continue; + } + GreasePencilLineartModifierData *lmd = reinterpret_cast( + modifier); + if (lmd->radius != 0.0f) { + continue; + } + lmd->radius = float(lmd->thickness_legacy) * + bke::greasepencil::LEGACY_RADIUS_CONVERSION_FACTOR; + } + } + FOREACH_NODETREE_BEGIN (bmain, node_tree, id) { if (node_tree->type != NTREE_COMPOSIT) { continue; diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_lineart.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_lineart.cc index 359134a2d72..321bae06661 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_lineart.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_lineart.cc @@ -217,7 +217,7 @@ static bool bake_strokes(Object *ob, lmd->mask_switches, lmd->material_mask_bits, lmd->intersection_mask, - float(lmd->thickness) / 1000.0f, + lmd->radius, lmd->opacity, lmd->shadow_selection, lmd->silhouette_selection, diff --git a/source/blender/makesdna/DNA_modifier_defaults.h b/source/blender/makesdna/DNA_modifier_defaults.h index d74a1b16df7..5b95c6c4a4f 100644 --- a/source/blender/makesdna/DNA_modifier_defaults.h +++ b/source/blender/makesdna/DNA_modifier_defaults.h @@ -969,8 +969,9 @@ #define _DNA_DEFAULT_GreasePencilLineartModifierData \ { \ .edge_types = MOD_LINEART_EDGE_FLAG_INIT_TYPE, \ - .thickness = 25, \ + .radius = 0.0025, \ .opacity = 1.0f, \ + .thickness_legacy = 25, \ .crease_threshold = DEG2RAD(140.0f), \ .calculation_flags = MOD_LINEART_ALLOW_DUPLI_OBJECTS | MOD_LINEART_ALLOW_CLIPPING_BOUNDARIES | \ MOD_LINEART_USE_CREASE_ON_SHARP_EDGES | MOD_LINEART_FILTER_FACE_MARK_KEEP_CONTOUR | \ diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index cc31fd29a93..558a55235ea 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -3193,7 +3193,9 @@ typedef struct GreasePencilLineartModifierData { float shadow_camera_far; float opacity; - short thickness; + float radius; + + short thickness_legacy; /* Deprecated, use `radius`. */ unsigned char mask_switches; /* #eGreasePencilLineartMaskSwitches */ unsigned char material_mask_bits; @@ -3201,7 +3203,7 @@ typedef struct GreasePencilLineartModifierData { unsigned char shadow_selection; unsigned char silhouette_selection; - char _pad[1]; + char _pad[5]; /** `0..1` range for cosine angle */ float crease_threshold; diff --git a/source/blender/makesdna/intern/dna_rename_defs.h b/source/blender/makesdna/intern/dna_rename_defs.h index e9baad9a826..588f3fc0d22 100644 --- a/source/blender/makesdna/intern/dna_rename_defs.h +++ b/source/blender/makesdna/intern/dna_rename_defs.h @@ -112,6 +112,7 @@ DNA_STRUCT_RENAME_MEMBER(GreasePencil, drawing_array_size, drawing_array_num) DNA_STRUCT_RENAME_MEMBER(GreasePencil, layers_data, layers_data_legacy) DNA_STRUCT_RENAME_MEMBER(GreasePencil, material_array_size, material_array_num) DNA_STRUCT_RENAME_MEMBER(GreasePencilLayerFramesMapStorage, size, num) +DNA_STRUCT_RENAME_MEMBER(GreasePencilLineartModifierData, thickness, thickness_legacy) DNA_STRUCT_RENAME_MEMBER(HookModifierData, totindex, indexar_num) DNA_STRUCT_RENAME_MEMBER(Image, name, filepath) DNA_STRUCT_RENAME_MEMBER(LaplacianDeformModifierData, total_verts, verts_num) diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 662f6f7634c..95ee6bc9dbd 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -9047,10 +9047,10 @@ static void rna_def_modifier_grease_pencil_lineart(BlenderRNA *brna) RNA_def_property_range(prop, 0.0f, 0.5f); RNA_def_property_update(prop, NC_SCENE, "rna_Modifier_update"); - prop = RNA_def_property(srna, "thickness", PROP_INT, PROP_NONE); - RNA_def_property_ui_text(prop, "Thickness", "The thickness for the generated strokes"); - RNA_def_property_ui_range(prop, 1, 100, 1, 1); - RNA_def_property_range(prop, 1, 200); + prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_ui_text(prop, "Radius", "The radius for the generated strokes"); + RNA_def_property_ui_range(prop, 0.0f, 0.25f, 0.01f, 2); + RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "opacity", PROP_FLOAT, PROP_FACTOR); diff --git a/source/blender/modifiers/intern/MOD_lineart.cc b/source/blender/modifiers/intern/MOD_lineart.cc index a77bc3de2a1..ffcd1eee438 100644 --- a/source/blender/modifiers/intern/MOD_lineart.cc +++ b/source/blender/modifiers/intern/MOD_lineart.cc @@ -255,7 +255,7 @@ static void panel_draw(const bContext * /*C*/, Panel *panel) ptr, "target_material", &obj_data_ptr, "materials", std::nullopt, ICON_MATERIAL); col = &layout->column(false); - col->prop(ptr, "thickness", UI_ITEM_R_SLIDER, IFACE_("Line Thickness"), ICON_NONE); + col->prop(ptr, "radius", UI_ITEM_R_SLIDER, IFACE_("Line Radius"), ICON_NONE); col->prop(ptr, "opacity", UI_ITEM_R_SLIDER, std::nullopt, ICON_NONE); modifier_error_message_draw(layout, ptr); @@ -802,7 +802,7 @@ static void generate_strokes(ModifierData &md, lmd.mask_switches, lmd.material_mask_bits, lmd.intersection_mask, - float(lmd.thickness) / 1000.0f, + lmd.radius, lmd.opacity, lmd.shadow_selection, lmd.silhouette_selection,