From 4ba55e7805bf988eb05acd3d576483363f03cc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 9 Jan 2024 15:37:10 +0100 Subject: [PATCH 01/45] Skeleton modifier for grease pencil opacity. --- .../startup/bl_ui/properties_data_modifier.py | 5 +- source/blender/makesdna/DNA_modifier_types.h | 6 + .../blender/makesrna/intern/rna_modifier.cc | 22 +++ source/blender/modifiers/CMakeLists.txt | 1 + source/blender/modifiers/MOD_modifiertypes.hh | 1 + .../intern/MOD_grease_pencil_opacity.cc | 151 ++++++++++++++++++ source/blender/modifiers/intern/MOD_util.cc | 1 + 7 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc diff --git a/scripts/startup/bl_ui/properties_data_modifier.py b/scripts/startup/bl_ui/properties_data_modifier.py index 36f164f4f01..fdc198b5e3b 100644 --- a/scripts/startup/bl_ui/properties_data_modifier.py +++ b/scripts/startup/bl_ui/properties_data_modifier.py @@ -46,6 +46,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): def draw(self, _context): layout = self.layout + ob_type = _context.object.type layout.operator("wm.call_menu", text="Add Modifier", icon='ADD').name = "OBJECT_MT_modifier_add" layout.template_modifiers() @@ -71,7 +72,7 @@ class OBJECT_MT_modifier_add(ModifierAddMenu, Menu): if geometry_nodes_supported: self.operator_modifier_add(layout, 'NODES') layout.separator() - if ob_type in {'MESH', 'CURVE', 'FONT', 'SURFACE', 'LATTICE'}: + if ob_type in {'MESH', 'CURVE', 'FONT', 'SURFACE', 'LATTICE', 'GREASEPENCIL'}: layout.menu("OBJECT_MT_modifier_add_edit") if ob_type in {'MESH', 'CURVE', 'FONT', 'SURFACE', 'VOLUME'}: layout.menu("OBJECT_MT_modifier_add_generate") @@ -105,6 +106,8 @@ class OBJECT_MT_modifier_add_edit(ModifierAddMenu, Menu): self.operator_modifier_add(layout, 'VERTEX_WEIGHT_EDIT') self.operator_modifier_add(layout, 'VERTEX_WEIGHT_MIX') self.operator_modifier_add(layout, 'VERTEX_WEIGHT_PROXIMITY') + if ob_type == 'GREASEPENCIL': + self.operator_modifier_add(layout, 'GREASE_PENCIL_OPACITY') layout.template_modifier_asset_menu_items(catalog_path=self.bl_label) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 0e31f383266..dcbbb6144a0 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -93,6 +93,7 @@ typedef enum ModifierType { eModifierType_MeshToVolume = 58, eModifierType_VolumeDisplace = 59, eModifierType_VolumeToMesh = 60, + eModifierType_GreasePencilOpacity = 61, NUM_MODIFIER_TYPES, } ModifierType; @@ -2484,3 +2485,8 @@ typedef enum VolumeToMeshResolutionMode { typedef enum VolumeToMeshFlag { VOLUME_TO_MESH_USE_SMOOTH_SHADE = 1 << 0, } VolumeToMeshFlag; + +typedef struct GreasePencilOpacityModifierData { + ModifierData modifier; + +} GreasePencilOpacityModifierData; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 3dbc5db42bc..41704e8f087 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -100,6 +100,11 @@ const EnumPropertyItem rna_enum_object_modifier_type_items[] = { ICON_MOD_VERTEX_WEIGHT, "Vertex Weight Proximity", "Set the vertex group weights based on the distance to another target object"}, + {eModifierType_GreasePencilOpacity, + "GREASE_PENCIL_OPACITY", + ICON_MOD_OPACITY, + "Opacity", + "Opacity of the strokes"}, RNA_ENUM_ITEM_HEADING(N_("Generate"), nullptr), {eModifierType_Array, @@ -7423,6 +7428,22 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna) RNA_define_lib_overridable(false); } +static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) +{ + StructRNA *srna; + + srna = RNA_def_struct(brna, "GreasePencilOpacityModifier", "Modifier"); + RNA_def_struct_ui_text(srna, "Grease Pencil Opacity Modifier", ""); + RNA_def_struct_sdna(srna, "GreasePencilOpacityModifierData"); + RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY); + + RNA_define_lib_overridable(true); + + // TODO + + RNA_define_lib_overridable(false); +} + void RNA_def_modifier(BlenderRNA *brna) { StructRNA *srna; @@ -7583,6 +7604,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_mesh_to_volume(brna); rna_def_modifier_volume_displace(brna); rna_def_modifier_volume_to_mesh(brna); + rna_def_modifier_grease_pencil_opacity(brna); } #endif diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index ef9ff57b606..d72cb2e3e3d 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -44,6 +44,7 @@ set(SRC intern/MOD_edgesplit.cc intern/MOD_explode.cc intern/MOD_fluid.cc + intern/MOD_grease_pencil_opacity.cc intern/MOD_hook.cc intern/MOD_laplaciandeform.cc intern/MOD_laplaciansmooth.cc diff --git a/source/blender/modifiers/MOD_modifiertypes.hh b/source/blender/modifiers/MOD_modifiertypes.hh index 64f95d4479f..909e6b3ce18 100644 --- a/source/blender/modifiers/MOD_modifiertypes.hh +++ b/source/blender/modifiers/MOD_modifiertypes.hh @@ -73,6 +73,7 @@ extern ModifierTypeInfo modifierType_Nodes; extern ModifierTypeInfo modifierType_MeshToVolume; extern ModifierTypeInfo modifierType_VolumeDisplace; extern ModifierTypeInfo modifierType_VolumeToMesh; +extern ModifierTypeInfo modifierType_GreasePencilOpacity; /* MOD_util.cc */ diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc new file mode 100644 index 00000000000..7b8a8863eec --- /dev/null +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -0,0 +1,151 @@ +/* SPDX-FileCopyrightText: 2005 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup modifiers + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_defaults.h" +#include "DNA_modifier_types.h" + +#include "BKE_modifier.hh" + +#include "BLO_read_write.hh" + +#include "UI_interface.hh" +#include "UI_resources.hh" + +#include "BLT_translation.h" + +#include "WM_types.hh" + +#include "RNA_access.hh" +#include "RNA_enum_types.hh" +#include "RNA_prototypes.h" + +#include "MOD_modifiertypes.hh" +#include "MOD_ui_common.hh" + +namespace blender { + +static void init_data(ModifierData *md) +{ + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + + BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(omd, modifier)); + + MEMCPY_STRUCT_AFTER(omd, DNA_struct_default_get(GreasePencilOpacityModifierData), modifier); + + // TODO +} + +static void copy_data(const ModifierData *md, ModifierData *target, const int flag) +{ + const GreasePencilOpacityModifierData *omd = (const GreasePencilOpacityModifierData *)md; + GreasePencilOpacityModifierData *tomd = (GreasePencilOpacityModifierData *)target; + + BKE_modifier_copydata_generic(md, target, flag); + + // TODO + UNUSED_VARS(omd, tomd); +} + +static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks) +{ + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + + // TODO + UNUSED_VARS(omd, r_cddata_masks); +} + +static void free_data(ModifierData *md) +{ + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + + // TODO + UNUSED_VARS(omd); +} + +static void modify_geometry_set(ModifierData *md, + const ModifierEvalContext *ctx, + bke::GeometrySet *geometry_set) +{ + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + + // TODO + UNUSED_VARS(omd, ctx, geometry_set); +} + +static void panel_draw(const bContext * /*C*/, Panel *panel) +{ + uiLayout *layout = panel->layout; + + PointerRNA ob_ptr; + PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr); + + uiLayoutSetPropSep(layout, true); + + // TODO + + modifier_panel_end(layout, ptr); +} + +static void panel_register(ARegionType *region_type) +{ + modifier_panel_register(region_type, eModifierType_GreasePencilOpacity, panel_draw); +} + +static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md) +{ + const GreasePencilOpacityModifierData *omd = (const GreasePencilOpacityModifierData *)md; + + BLO_write_struct(writer, GreasePencilOpacityModifierData, omd); +} + +static void blend_read(BlendDataReader *reader, ModifierData *md) +{ + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + UNUSED_VARS(reader, omd); +} + +} // namespace blender + +ModifierTypeInfo modifierType_GreasePencilOpacity = { + /*idname*/ "GreasePencilOpacity", + /*name*/ N_("GreasePencilOpacity"), + /*struct_name*/ "GreasePencilOpacityModifierData", + /*struct_size*/ sizeof(GreasePencilOpacityModifierData), + /*srna*/ &RNA_GreasePencilOpacityModifier, + /*type*/ ModifierTypeType::NonGeometrical, + /*flags*/ + static_cast( + eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode | + eModifierTypeFlag_EnableInEditmode | eModifierTypeFlag_SupportsMapping), + /*icon*/ ICON_MOD_OPACITY, + + /*copy_data*/ blender::copy_data, + + /*deform_verts*/ nullptr, + /*deform_matrices*/ nullptr, + /*deform_verts_EM*/ nullptr, + /*deform_matrices_EM*/ nullptr, + /*modify_mesh*/ nullptr, + /*modify_geometry_set*/ blender::modify_geometry_set, + + /*init_data*/ blender::init_data, + /*required_data_mask*/ blender::required_data_mask, + /*free_data*/ blender::free_data, + /*is_disabled*/ nullptr, + /*update_depsgraph*/ nullptr, + /*depends_on_time*/ nullptr, + /*depends_on_normals*/ nullptr, + /*foreach_ID_link*/ nullptr, + /*foreach_tex_link*/ nullptr, + /*free_runtime_data*/ nullptr, + /*panel_register*/ blender::panel_register, + /*blend_write*/ blender::blend_write, + /*blend_read*/ blender::blend_read, +}; diff --git a/source/blender/modifiers/intern/MOD_util.cc b/source/blender/modifiers/intern/MOD_util.cc index 8b6fdbeb481..b4bd44081ac 100644 --- a/source/blender/modifiers/intern/MOD_util.cc +++ b/source/blender/modifiers/intern/MOD_util.cc @@ -270,5 +270,6 @@ void modifier_type_init(ModifierTypeInfo *types[]) INIT_TYPE(VolumeDisplace); INIT_TYPE(VolumeToMesh); INIT_TYPE(Nodes); + INIT_TYPE(GreasePencilOpacity); #undef INIT_TYPE } -- 2.30.2 From ca665e7ad89bdd7339eb2d79abfcf465c5e9dc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Wed, 10 Jan 2024 12:18:38 +0100 Subject: [PATCH 02/45] Utility function for gathering drawings for modifiers. --- source/blender/makesdna/DNA_modifier_types.h | 4 +- source/blender/modifiers/CMakeLists.txt | 2 + .../intern/MOD_grease_pencil_opacity.cc | 48 +++++++++++++++++-- .../intern/MOD_grease_pencil_util.cc | 45 +++++++++++++++++ .../intern/MOD_grease_pencil_util.hh | 23 +++++++++ 5 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 source/blender/modifiers/intern/MOD_grease_pencil_util.cc create mode 100644 source/blender/modifiers/intern/MOD_grease_pencil_util.hh diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index dcbbb6144a0..eb9f7a9703b 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -152,8 +152,8 @@ typedef enum { */ eModifierFlag_Active = (1 << 2), /** - * Only set on modifiers in evaluated objects. The flag indicates that the user modified inputs - * to the modifier which might invalidate simulation caches. + * Only set on modifiers in evaluated objects. The flag indicates that the user modified + * inputs to the modifier which might invalidate simulation caches. */ eModifierFlag_UserModified = (1 << 3), } ModifierFlag; diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index d72cb2e3e3d..f3920f2560f 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -45,6 +45,7 @@ set(SRC intern/MOD_explode.cc intern/MOD_fluid.cc intern/MOD_grease_pencil_opacity.cc + intern/MOD_grease_pencil_util.cc intern/MOD_hook.cc intern/MOD_laplaciandeform.cc intern/MOD_laplaciansmooth.cc @@ -98,6 +99,7 @@ set(SRC MOD_modifiertypes.hh MOD_nodes.hh + intern/MOD_grease_pencil_util.hh intern/MOD_meshcache_util.hh intern/MOD_solidify_util.hh intern/MOD_ui_common.hh diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 7b8a8863eec..9d4fcfa9c2b 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -10,11 +10,17 @@ #include "DNA_defaults.h" #include "DNA_modifier_types.h" +#include "DNA_scene_types.h" +#include "BKE_curves.hh" +#include "BKE_geometry_set.hh" +#include "BKE_grease_pencil.hh" #include "BKE_modifier.hh" #include "BLO_read_write.hh" +#include "DEG_depsgraph_query.hh" + #include "UI_interface.hh" #include "UI_resources.hh" @@ -26,11 +32,16 @@ #include "RNA_enum_types.hh" #include "RNA_prototypes.h" +#include "MOD_grease_pencil_util.hh" #include "MOD_modifiertypes.hh" #include "MOD_ui_common.hh" namespace blender { +using bke::greasepencil::Drawing; +using bke::greasepencil::FramesMapKey; +using bke::greasepencil::Layer; + static void init_data(ModifierData *md) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; @@ -69,14 +80,43 @@ static void free_data(ModifierData *md) UNUSED_VARS(omd); } +static void modify_curves(ModifierData *md, + const ModifierEvalContext * /*ctx*/, + bke::CurvesGeometry &curves) +{ + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + UNUSED_VARS(omd); + + bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); + bke::SpanAttributeWriter opacities = attributes.lookup_or_add_for_write_span( + "opacity", bke::AttrDomain::Point); + + for (const int i : opacities.span.index_range()) { + opacities.span[i] *= 0.5f; + } + + opacities.finish(); +} + static void modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set) { - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + const Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); + const int frame = scene->r.cfra; - // TODO - UNUSED_VARS(omd, ctx, geometry_set); + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + UNUSED_VARS(omd); + + GreasePencil *grease_pencil = geometry_set->get_grease_pencil_for_write(); + if (grease_pencil == nullptr) { + return; + } + + Vector drawings = greasepencil::get_drawings_for_write(*grease_pencil, frame); + for (Drawing *drawing : drawings) { + modify_curves(md, ctx, drawing->strokes_for_write()); + } } static void panel_draw(const bContext * /*C*/, Panel *panel) @@ -119,7 +159,7 @@ ModifierTypeInfo modifierType_GreasePencilOpacity = { /*struct_name*/ "GreasePencilOpacityModifierData", /*struct_size*/ sizeof(GreasePencilOpacityModifierData), /*srna*/ &RNA_GreasePencilOpacityModifier, - /*type*/ ModifierTypeType::NonGeometrical, + /*type*/ ModifierTypeType::Nonconstructive, /*flags*/ static_cast( eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode | diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc new file mode 100644 index 00000000000..7caae168a2b --- /dev/null +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -0,0 +1,45 @@ +/* SPDX-FileCopyrightText: 2011 by Bastien Montagne. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup modifiers + */ + +#include "MOD_grease_pencil_util.hh" + +#include "BLI_set.hh" + +#include "DNA_grease_pencil_types.h" + +#include "BKE_grease_pencil.hh" + +namespace blender::greasepencil { + +using bke::greasepencil::Drawing; +using bke::greasepencil::Layer; + +Vector get_drawings_for_write(GreasePencil &grease_pencil, int frame) +{ + /* Set of unique drawing indices. */ + Set drawing_indices; + for (Layer *layer : grease_pencil.layers_for_write()) { + const int drawing_index = layer->drawing_index_at(frame); + if (drawing_index >= 0) { + drawing_indices.add(drawing_index); + } + } + + /* List of owned drawings, ignore drawing references to other data blocks. */ + Vector drawings; + for (const int drawing_index : drawing_indices) { + GreasePencilDrawingBase *drawing_base = grease_pencil.drawing(drawing_index); + if (drawing_base->type == GP_DRAWING) { + GreasePencilDrawing *drawing = reinterpret_cast(drawing_base); + drawings.append(&drawing->wrap()); + } + } + return drawings; +} + +} // namespace blender::greasepencil diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh new file mode 100644 index 00000000000..4ae7ceebfd7 --- /dev/null +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -0,0 +1,23 @@ +/* SPDX-FileCopyrightText: 2011 by Bastien Montagne. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup modifiers + */ + +#pragma once + +#include "BLI_vector.hh" + +struct GreasePencil; +namespace blender::bke::greasepencil { +class Drawing; +} + +namespace blender::greasepencil { + +Vector get_drawings_for_write(GreasePencil &grease_pencil, + int frame); + +} -- 2.30.2 From 2fe5dd11a1815e89948535782ec08614208e3f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Wed, 10 Jan 2024 16:25:11 +0100 Subject: [PATCH 03/45] DNA filter struct for grease pencil modifiers. This comes with utility functions that generate index masks, which can then be used to filter layers and strokes by layer name, material, or pass. --- source/blender/makesdna/DNA_modifier_types.h | 24 +++- .../intern/MOD_grease_pencil_opacity.cc | 17 ++- .../intern/MOD_grease_pencil_util.cc | 117 +++++++++++++++++- .../intern/MOD_grease_pencil_util.hh | 9 +- 4 files changed, 161 insertions(+), 6 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index eb9f7a9703b..a66097e15e5 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2486,7 +2486,29 @@ typedef enum VolumeToMeshFlag { VOLUME_TO_MESH_USE_SMOOTH_SHADE = 1 << 0, } VolumeToMeshFlag; +typedef struct GreasePencilModifierFilterData { + /** Filter by layer name. */ + char layername[64]; + /** Filter by stroke material. */ + struct Material *material; + /** Filter by layer pass. */ + int layer_pass; + /** Filter by material pass. */ + int material_pass; + /** GreasePencilModifierFilterFlag */ + int flag; + char _pad[4]; +} GreasePencilModifierFilterData; + +typedef enum GreasePencilModifierFilterFlag { + GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 0), + GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 1), + GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 2), + GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS = (1 << 3), +} GreasePencilModifierFilterFlag; + typedef struct GreasePencilOpacityModifierData { ModifierData modifier; - + GreasePencilModifierFilterData filter; + void *_pad; } GreasePencilOpacityModifierData; diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 9d4fcfa9c2b..fec21b27838 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -36,6 +36,8 @@ #include "MOD_modifiertypes.hh" #include "MOD_ui_common.hh" +#include + namespace blender { using bke::greasepencil::Drawing; @@ -48,7 +50,14 @@ static void init_data(ModifierData *md) BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(omd, modifier)); - MEMCPY_STRUCT_AFTER(omd, DNA_struct_default_get(GreasePencilOpacityModifierData), modifier); + // XXX Why is this crashing, but the expanded code below works fine?!? + // MEMCPY_STRUCT_AFTER(omd, DNA_struct_default_get(GreasePencilOpacityModifierData), modifier); + { + CHECK_TYPE_NONCONST(omd); + memcpy((char *)(omd) + OFFSETOF_STRUCT_AFTER(omd, modifier), + (const char *)(md) + OFFSETOF_STRUCT_AFTER(omd, modifier), + sizeof(*(omd)) - OFFSETOF_STRUCT_AFTER(omd, modifier)); + } // TODO } @@ -113,7 +122,11 @@ static void modify_geometry_set(ModifierData *md, return; } - Vector drawings = greasepencil::get_drawings_for_write(*grease_pencil, frame); + IndexMaskMemory mask_memory; + IndexMask layer_mask = greasepencil::get_filtered_layer_mask( + *grease_pencil, omd->filter, mask_memory); + Vector drawings = greasepencil::get_drawings_for_write( + *grease_pencil, layer_mask, frame); for (Drawing *drawing : drawings) { modify_curves(md, ctx, drawing->strokes_for_write()); } diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 7caae168a2b..feb46beb75e 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -11,19 +11,132 @@ #include "BLI_set.hh" #include "DNA_grease_pencil_types.h" +#include "DNA_material_types.h" +#include "DNA_modifier_types.h" +#include "BKE_curves.hh" #include "BKE_grease_pencil.hh" +#include "BKE_material.h" + +#include "DEG_depsgraph_query.hh" namespace blender::greasepencil { using bke::greasepencil::Drawing; using bke::greasepencil::Layer; -Vector get_drawings_for_write(GreasePencil &grease_pencil, int frame) +/** + * Get a list of pass IDs used by grease pencil materials. + * This way the material pass can be looked up by index instead of having to get the material for + * each curve. + */ +static Vector get_grease_pencil_material_passes(const Object *ob) +{ + short *totcol = BKE_object_material_len_p(const_cast(ob)); + Vector result(*totcol); + Material *ma = nullptr; + for (short i = 0; i < *totcol; i++) { + ma = BKE_object_material_get(const_cast(ob), i + 1); + /* Pass index of the grease pencil material. */ + result[i] = ma->gp_style->index; + } + return result; +} + +static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, + const std::optional layer_name_filter, + const std::optional layer_pass_filter, + const bool layer_filter_invert, + const bool layer_pass_filter_invert, + IndexMaskMemory &memory) +{ + bke::AttributeAccessor layer_attributes = grease_pencil.attributes(); + const Span layers = grease_pencil.layers(); + const VArray layer_passes = + layer_attributes.lookup_or_default("pass", bke::AttrDomain::Layer, 0).varray; + + IndexMask result = IndexMask::from_predicate( + grease_pencil.layers().index_range(), GrainSize(4096), memory, [&](const int64_t layer_i) { + if (layer_name_filter) { + const Layer &layer = *layers[layer_i]; + const bool match = (layer.name() == layer_name_filter.value()); + if (match ^ layer_filter_invert) { + return false; + } + } + if (layer_pass_filter) { + const int layer_pass = layer_passes.get(layer_i); + const bool match = (layer_pass == layer_pass_filter.value()); + if (match ^ layer_pass_filter_invert) { + return false; + } + } + return true; + }); + return result; +} + +IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, + const GreasePencilModifierFilterData &filter_data, + IndexMaskMemory &memory) +{ + /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ + return get_filtered_layer_mask( + grease_pencil, + filter_data.layername[0] != '\0' ? std::make_optional(filter_data.layername) : + std::nullopt, + filter_data.layer_pass > 0 ? std::make_optional(filter_data.layer_pass) : std::nullopt, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, + memory); +} + +static Vector is_material_affected_by_modifier(const Object *ob, + const bke::CurvesGeometry &curves, + const Material *material_filter, + const std::optional material_pass_filter, + const bool material_filter_invert, + const bool material_pass_filter_invert) +{ + bke::AttributeAccessor attributes = curves.attributes(); + VArray stroke_materials = + attributes.lookup_or_default("material_index", bke::AttrDomain::Curve, 0).varray; + + Vector result(curves.curves_num(), true); + if (material_filter != nullptr) { + const int material_filter_index = BKE_grease_pencil_object_material_index_get( + const_cast(ob), const_cast(material_filter)); + for (const int stroke_i : result.index_range()) { + const int material_index = stroke_materials.get(stroke_i); + const bool match = (material_index == material_filter_index); + if (match ^ material_filter_invert) { + result[stroke_i] = false; + } + } + } + if (material_pass_filter) { + const Vector material_pass_by_index = get_grease_pencil_material_passes(ob); + for (const int stroke_i : result.index_range()) { + const int material_index = stroke_materials.get(stroke_i); + const int material_pass = material_pass_by_index[material_index]; + const bool match = (material_pass == material_pass_filter.value()); + if (match ^ material_pass_filter_invert) { + result[stroke_i] = false; + } + } + } + + return result; +} + +Vector get_drawings_for_write(GreasePencil &grease_pencil, + const IndexMask &layer_mask, + int frame) { /* Set of unique drawing indices. */ Set drawing_indices; - for (Layer *layer : grease_pencil.layers_for_write()) { + for (const int64_t i : layer_mask.index_range()) { + Layer *layer = grease_pencil.layers_for_write()[layer_mask[i]]; const int drawing_index = layer->drawing_index_at(frame); if (drawing_index >= 0) { drawing_indices.add(drawing_index); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index 4ae7ceebfd7..851b47f3fc7 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -8,16 +8,23 @@ #pragma once +#include "BLI_index_mask.hh" #include "BLI_vector.hh" struct GreasePencil; +struct GreasePencilModifierFilterData; namespace blender::bke::greasepencil { class Drawing; } namespace blender::greasepencil { +IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, + const GreasePencilModifierFilterData &filter_data, + IndexMaskMemory &memory); + Vector get_drawings_for_write(GreasePencil &grease_pencil, + const IndexMask &layer_mask, int frame); -} +} // namespace blender::greasepencil -- 2.30.2 From 519df52896ab5a51071bb523e02cc3ed2e35d3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Wed, 10 Jan 2024 18:28:43 +0100 Subject: [PATCH 04/45] Added boilerplate code for filter data and panel drawing. --- source/blender/makesdna/DNA_modifier_types.h | 2 +- .../blender/makesrna/intern/rna_modifier.cc | 102 ++++++++++++++++++ .../intern/MOD_grease_pencil_opacity.cc | 21 ++-- .../intern/MOD_grease_pencil_util.cc | 87 +++++++++++++-- .../intern/MOD_grease_pencil_util.hh | 15 +++ 5 files changed, 212 insertions(+), 15 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index a66097e15e5..d8aa3b5e0fd 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2488,7 +2488,7 @@ typedef enum VolumeToMeshFlag { typedef struct GreasePencilModifierFilterData { /** Filter by layer name. */ - char layername[64]; + char layer_name[64]; /** Filter by stroke material. */ struct Material *material; /** Filter by layer pass. */ diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 41704e8f087..3e957920902 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -673,11 +673,13 @@ const EnumPropertyItem rna_enum_subdivision_boundary_smooth_items[] = { #ifdef RNA_RUNTIME # include "DNA_curve_types.h" # include "DNA_fluid_types.h" +# include "DNA_material_types.h" # include "DNA_particle_types.h" # include "BKE_cachefile.h" # include "BKE_context.hh" # include "BKE_deform.h" +# include "BKE_grease_pencil.hh" # include "BKE_mesh_runtime.hh" # include "BKE_modifier.hh" # include "BKE_object.hh" @@ -1710,6 +1712,37 @@ static IDProperty **rna_NodesModifier_properties(PointerRNA *ptr) NodesModifierSettings *settings = &nmd->settings; return &settings->properties; } + +bool rna_GreasePencilModifierFilter_material_poll(PointerRNA *ptr, PointerRNA value) +{ + Object *ob = reinterpret_cast(ptr->owner_id); + Material *ma = reinterpret_cast(value.owner_id); + + return BKE_grease_pencil_object_material_index_get(ob, ma) != -1; +} + +static void rna_GreasePencilModifierFilter_material_set(PointerRNA *ptr, + PointerRNA value, + ReportList *reports) +{ + Object *ob = reinterpret_cast(ptr->owner_id); + GreasePencilModifierFilterData *filter_data = static_cast( + ptr->data); + Material *ma = reinterpret_cast(value.owner_id); + + if (ma == nullptr || BKE_grease_pencil_object_material_index_get(ob, ma) != -1) { + id_lib_extern(reinterpret_cast(ob)); + filter_data->material = ma; + } + else { + BKE_reportf( + reports, + RPT_ERROR, + "Cannot assign material '%s', it has to be used by the grease pencil object already", + ma->id.name); + } +} + #else static void rna_def_modifier_panel_open_prop(StructRNA *srna, const char *identifier, const int id) @@ -7428,15 +7461,83 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna) RNA_define_lib_overridable(false); } +static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "GreasePencilModifierFilter", nullptr); + RNA_def_struct_ui_text( + srna, "Grease Pencil Modifier Filter", "Filter settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierFilterData"); + + RNA_define_lib_overridable(true); + + prop = RNA_def_property(srna, "layer", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, nullptr, "layer_name"); + RNA_def_property_ui_text(prop, "Layer", "Layer name"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "layer_pass", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, nullptr, "layer_pass"); + RNA_def_property_range(prop, 0, 100); + RNA_def_property_ui_text(prop, "Layer Pass", "Layer pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_layer", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_LAYER); + RNA_def_property_ui_text(prop, "Invert Layer", "Invert layer filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_layer_pass", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_LAYER_PASS); + RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, + nullptr, + "rna_GreasePencilModifierFilter_material_set", + nullptr, + "rna_GreasePencilModifierFilter_material_poll"); + RNA_def_property_ui_text(prop, "Material", "Material used for filtering"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "material_pass", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, nullptr, "material_pass"); + RNA_def_property_range(prop, 0, 100); + RNA_def_property_ui_text(prop, "Material Pass", "Material pass"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_material", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_MATERIAL); + RNA_def_property_ui_text(prop, "Invert Material", "Invert material filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_material_pass", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS); + RNA_def_property_ui_text(prop, "Invert Material Pass", "Invert material pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + RNA_define_lib_overridable(false); +} + static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) { StructRNA *srna; + PropertyRNA *prop; srna = RNA_def_struct(brna, "GreasePencilOpacityModifier", "Modifier"); RNA_def_struct_ui_text(srna, "Grease Pencil Opacity Modifier", ""); RNA_def_struct_sdna(srna, "GreasePencilOpacityModifierData"); RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY); + prop = RNA_def_property(srna, "filter", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, "filter"); + RNA_def_property_struct_type(prop, "GreasePencilModifierFilter"); + RNA_def_property_ui_text(prop, "Filter", "Filter settings"); + RNA_define_lib_overridable(true); // TODO @@ -7605,6 +7706,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_volume_displace(brna); rna_def_modifier_volume_to_mesh(brna); rna_def_modifier_grease_pencil_opacity(brna); + rna_def_modifier_grease_pencil_filter(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index fec21b27838..021c691ea66 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -59,7 +59,7 @@ static void init_data(ModifierData *md) sizeof(*(omd)) - OFFSETOF_STRUCT_AFTER(omd, modifier)); } - // TODO + greasepencil::init_data_filter(&omd->filter); } static void copy_data(const ModifierData *md, ModifierData *target, const int flag) @@ -68,9 +68,7 @@ static void copy_data(const ModifierData *md, ModifierData *target, const int fl GreasePencilOpacityModifierData *tomd = (GreasePencilOpacityModifierData *)target; BKE_modifier_copydata_generic(md, target, flag); - - // TODO - UNUSED_VARS(omd, tomd); + greasepencil::copy_data_filter(&omd->filter, &tomd->filter, flag); } static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks) @@ -81,12 +79,17 @@ static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_ UNUSED_VARS(omd, r_cddata_masks); } +static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data) +{ + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + greasepencil::foreach_ID_link_filter(&omd->filter, ob, walk, user_data); +} + static void free_data(ModifierData *md) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - // TODO - UNUSED_VARS(omd); + greasepencil::free_data_filter(&omd->filter); } static void modify_curves(ModifierData *md, @@ -148,7 +151,9 @@ static void panel_draw(const bContext * /*C*/, Panel *panel) static void panel_register(ARegionType *region_type) { - modifier_panel_register(region_type, eModifierType_GreasePencilOpacity, panel_draw); + PanelType *panel_type = modifier_panel_register( + region_type, eModifierType_GreasePencilOpacity, panel_draw); + greasepencil::filter_subpanel_register(region_type, panel_type); } static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md) @@ -195,7 +200,7 @@ ModifierTypeInfo modifierType_GreasePencilOpacity = { /*update_depsgraph*/ nullptr, /*depends_on_time*/ nullptr, /*depends_on_normals*/ nullptr, - /*foreach_ID_link*/ nullptr, + /*foreach_ID_link*/ blender::foreach_ID_link, /*foreach_tex_link*/ nullptr, /*free_runtime_data*/ nullptr, /*panel_register*/ blender::panel_register, diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index feb46beb75e..ee02630561c 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -13,18 +13,93 @@ #include "DNA_grease_pencil_types.h" #include "DNA_material_types.h" #include "DNA_modifier_types.h" +#include "DNA_screen_types.h" #include "BKE_curves.hh" #include "BKE_grease_pencil.hh" +#include "BKE_lib_query.h" #include "BKE_material.h" #include "DEG_depsgraph_query.hh" +#include "MOD_ui_common.hh" + +#include "RNA_access.hh" + +#include "UI_interface.hh" + namespace blender::greasepencil { using bke::greasepencil::Drawing; using bke::greasepencil::Layer; +void init_data_filter(GreasePencilModifierFilterData * /*filter_data*/) {} + +void copy_data_filter(const GreasePencilModifierFilterData *filter_data_src, + GreasePencilModifierFilterData *filter_data_dst, + const int /*flag*/) +{ + memcpy((char *)filter_data_dst, + (const char *)filter_data_src, + sizeof(GreasePencilModifierFilterData)); +} + +void free_data_filter(GreasePencilModifierFilterData * /*filter_data*/) {} + +void foreach_ID_link_filter(GreasePencilModifierFilterData *filter_data, + Object *ob, + IDWalkFunc walk, + void *user_data) +{ + walk(user_data, ob, (ID **)&filter_data->material, IDWALK_CB_USER); +} + +static void filter_panel_draw(const bContext * /*C*/, Panel *panel) +{ + uiLayout *row, *col, *sub; + uiLayout *layout = panel->layout; + + PointerRNA ob_ptr; + PointerRNA *modifier_ptr = modifier_panel_get_property_pointers(panel, &ob_ptr); + PointerRNA ptr = RNA_pointer_get(modifier_ptr, "filter"); + + PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); + + uiLayoutSetPropSep(layout, true); + + col = uiLayoutColumn(layout, true); + row = uiLayoutRow(col, true); + uiItemPointerR(row, &ptr, "layer", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); + sub = uiLayoutRow(row, true); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, &ptr, "invert_layer", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + + row = uiLayoutRow(col, true); + uiItemR(row, &ptr, "layer_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + sub = uiLayoutRow(row, true); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, &ptr, "invert_layer_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + + col = uiLayoutColumn(layout, true); + row = uiLayoutRow(col, true); + uiItemPointerR(row, &ptr, "material", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); + sub = uiLayoutRow(row, true); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, &ptr, "invert_material", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + + row = uiLayoutRow(col, true); + uiItemR(row, &ptr, "material_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + sub = uiLayoutRow(row, true); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, &ptr, "invert_material_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); +} + +void filter_subpanel_register(ARegionType *region_type, PanelType *panel_type) +{ + modifier_subpanel_register( + region_type, "influence", "Influence", nullptr, filter_panel_draw, panel_type); +} + /** * Get a list of pass IDs used by grease pencil materials. * This way the material pass can be looked up by index instead of having to get the material for @@ -60,14 +135,14 @@ static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, if (layer_name_filter) { const Layer &layer = *layers[layer_i]; const bool match = (layer.name() == layer_name_filter.value()); - if (match ^ layer_filter_invert) { + if (match == layer_filter_invert) { return false; } } if (layer_pass_filter) { const int layer_pass = layer_passes.get(layer_i); const bool match = (layer_pass == layer_pass_filter.value()); - if (match ^ layer_pass_filter_invert) { + if (match == layer_pass_filter_invert) { return false; } } @@ -83,8 +158,8 @@ IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ return get_filtered_layer_mask( grease_pencil, - filter_data.layername[0] != '\0' ? std::make_optional(filter_data.layername) : - std::nullopt, + filter_data.layer_name[0] != '\0' ? std::make_optional(filter_data.layer_name) : + std::nullopt, filter_data.layer_pass > 0 ? std::make_optional(filter_data.layer_pass) : std::nullopt, filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, @@ -109,7 +184,7 @@ static Vector is_material_affected_by_modifier(const Object *ob, for (const int stroke_i : result.index_range()) { const int material_index = stroke_materials.get(stroke_i); const bool match = (material_index == material_filter_index); - if (match ^ material_filter_invert) { + if (match == material_filter_invert) { result[stroke_i] = false; } } @@ -120,7 +195,7 @@ static Vector is_material_affected_by_modifier(const Object *ob, const int material_index = stroke_materials.get(stroke_i); const int material_pass = material_pass_by_index[material_index]; const bool match = (material_pass == material_pass_filter.value()); - if (match ^ material_pass_filter_invert) { + if (match == material_pass_filter_invert) { result[stroke_i] = false; } } diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index 851b47f3fc7..ae81b0c1fc1 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -11,14 +11,29 @@ #include "BLI_index_mask.hh" #include "BLI_vector.hh" +#include "BKE_modifier.hh" + +struct ARegionType; struct GreasePencil; struct GreasePencilModifierFilterData; +struct PanelType; namespace blender::bke::greasepencil { class Drawing; } namespace blender::greasepencil { +void init_data_filter(GreasePencilModifierFilterData *filter_data); +void copy_data_filter(const GreasePencilModifierFilterData *filter_data_src, + GreasePencilModifierFilterData *filter_data_dst, + int flag); +void free_data_filter(GreasePencilModifierFilterData *filter_data); +void foreach_ID_link_filter(GreasePencilModifierFilterData *filter_data, + Object *ob, + IDWalkFunc walk, + void *user_data); +void filter_subpanel_register(ARegionType *region_type, PanelType *panel_type); + IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierFilterData &filter_data, IndexMaskMemory &memory); -- 2.30.2 From cbd61664abe3ce03773b89fded9ea37e04fdcf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Wed, 10 Jan 2024 18:59:17 +0100 Subject: [PATCH 05/45] Added index mask for curves. --- .../intern/MOD_grease_pencil_opacity.cc | 18 ++-- .../intern/MOD_grease_pencil_util.cc | 84 ++++++++++++------- .../intern/MOD_grease_pencil_util.hh | 10 ++- 3 files changed, 74 insertions(+), 38 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 021c691ea66..6c3ae9bd8a9 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -93,18 +93,24 @@ static void free_data(ModifierData *md) } static void modify_curves(ModifierData *md, - const ModifierEvalContext * /*ctx*/, + const ModifierEvalContext *ctx, bke::CurvesGeometry &curves) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - UNUSED_VARS(omd); bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); bke::SpanAttributeWriter opacities = attributes.lookup_or_add_for_write_span( "opacity", bke::AttrDomain::Point); - for (const int i : opacities.span.index_range()) { - opacities.span[i] *= 0.5f; + OffsetIndices points_by_curve = curves.points_by_curve(); + IndexMaskMemory mask_memory; + IndexMask curves_mask = greasepencil::get_filtered_stroke_mask( + ctx->object, curves, omd->filter, mask_memory); + for (const int64_t i : curves_mask.index_range()) { + const int64_t curve_i = curves_mask[i]; + for (const int64_t point_i : points_by_curve[curve_i]) { + opacities.span[point_i] *= 0.5f; + } } opacities.finish(); @@ -114,12 +120,10 @@ static void modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set) { + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; const Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); const int frame = scene->r.cfra; - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - UNUSED_VARS(omd); - GreasePencil *grease_pencil = geometry_set->get_grease_pencil_for_write(); if (grease_pencil == nullptr) { return; diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index ee02630561c..1f6578b4c36 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -125,6 +125,10 @@ static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const bool layer_pass_filter_invert, IndexMaskMemory &memory) { + if (!layer_name_filter && !layer_pass_filter) { + return {}; + } + bke::AttributeAccessor layer_attributes = grease_pencil.attributes(); const Span layers = grease_pencil.layers(); const VArray layer_passes = @@ -166,44 +170,64 @@ IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, memory); } -static Vector is_material_affected_by_modifier(const Object *ob, - const bke::CurvesGeometry &curves, - const Material *material_filter, - const std::optional material_pass_filter, - const bool material_filter_invert, - const bool material_pass_filter_invert) +static IndexMask get_filtered_stroke_mask(const Object *ob, + const bke::CurvesGeometry &curves, + const Material *material_filter, + const std::optional material_pass_filter, + const bool material_filter_invert, + const bool material_pass_filter_invert, + IndexMaskMemory &memory) { + if (!material_filter && !material_pass_filter) { + return {}; + } + + const int material_filter_index = BKE_grease_pencil_object_material_index_get( + const_cast(ob), const_cast(material_filter)); + const Vector material_pass_by_index = get_grease_pencil_material_passes(ob); + bke::AttributeAccessor attributes = curves.attributes(); VArray stroke_materials = attributes.lookup_or_default("material_index", bke::AttrDomain::Curve, 0).varray; - Vector result(curves.curves_num(), true); - if (material_filter != nullptr) { - const int material_filter_index = BKE_grease_pencil_object_material_index_get( - const_cast(ob), const_cast(material_filter)); - for (const int stroke_i : result.index_range()) { - const int material_index = stroke_materials.get(stroke_i); - const bool match = (material_index == material_filter_index); - if (match == material_filter_invert) { - result[stroke_i] = false; - } - } - } - if (material_pass_filter) { - const Vector material_pass_by_index = get_grease_pencil_material_passes(ob); - for (const int stroke_i : result.index_range()) { - const int material_index = stroke_materials.get(stroke_i); - const int material_pass = material_pass_by_index[material_index]; - const bool match = (material_pass == material_pass_filter.value()); - if (match == material_pass_filter_invert) { - result[stroke_i] = false; - } - } - } - + IndexMask result = IndexMask::from_predicate( + curves.curves_range(), GrainSize(4096), memory, [&](const int64_t stroke_i) { + const int material_index = stroke_materials.get(stroke_i); + if (material_filter != nullptr) { + const bool match = (material_index == material_filter_index); + if (match == material_filter_invert) { + return false; + } + } + if (material_pass_filter) { + const int material_pass = material_pass_by_index[material_index]; + const bool match = (material_pass == material_pass_filter.value()); + if (match == material_pass_filter_invert) { + return false; + } + } + return true; + }); return result; } +IndexMask get_filtered_stroke_mask(const Object *ob, + const bke::CurvesGeometry &curves, + const GreasePencilModifierFilterData &filter_data, + IndexMaskMemory &memory) +{ + /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ + return get_filtered_stroke_mask(ob, + curves, + filter_data.material, + filter_data.material_pass > 0 ? + std::make_optional(filter_data.material_pass) : + std::nullopt, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS, + memory); +} + Vector get_drawings_for_write(GreasePencil &grease_pencil, const IndexMask &layer_mask, int frame) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index ae81b0c1fc1..91d873a7676 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -17,9 +17,12 @@ struct ARegionType; struct GreasePencil; struct GreasePencilModifierFilterData; struct PanelType; -namespace blender::bke::greasepencil { +namespace blender::bke { +class CurvesGeometry; +namespace greasepencil { class Drawing; } +} // namespace blender::bke namespace blender::greasepencil { @@ -38,6 +41,11 @@ IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierFilterData &filter_data, IndexMaskMemory &memory); +IndexMask get_filtered_stroke_mask(const Object *ob, + const bke::CurvesGeometry &curves, + const GreasePencilModifierFilterData &filter_data, + IndexMaskMemory &memory); + Vector get_drawings_for_write(GreasePencil &grease_pencil, const IndexMask &layer_mask, int frame); -- 2.30.2 From 3fa0c4dfbadc7c6e8ac07fa0d59691463f70c417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 09:41:59 +0100 Subject: [PATCH 06/45] Fix early return value, should be full mask instead of empty. --- .../blender/modifiers/intern/MOD_grease_pencil_util.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 1f6578b4c36..56ede9567dc 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -125,8 +125,9 @@ static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const bool layer_pass_filter_invert, IndexMaskMemory &memory) { + const IndexMask full_mask = grease_pencil.layers().index_range(); if (!layer_name_filter && !layer_pass_filter) { - return {}; + return full_mask; } bke::AttributeAccessor layer_attributes = grease_pencil.attributes(); @@ -135,7 +136,7 @@ static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, layer_attributes.lookup_or_default("pass", bke::AttrDomain::Layer, 0).varray; IndexMask result = IndexMask::from_predicate( - grease_pencil.layers().index_range(), GrainSize(4096), memory, [&](const int64_t layer_i) { + full_mask, GrainSize(4096), memory, [&](const int64_t layer_i) { if (layer_name_filter) { const Layer &layer = *layers[layer_i]; const bool match = (layer.name() == layer_name_filter.value()); @@ -178,8 +179,9 @@ static IndexMask get_filtered_stroke_mask(const Object *ob, const bool material_pass_filter_invert, IndexMaskMemory &memory) { + const IndexMask full_mask = curves.curves_range(); if (!material_filter && !material_pass_filter) { - return {}; + return full_mask; } const int material_filter_index = BKE_grease_pencil_object_material_index_get( @@ -191,7 +193,7 @@ static IndexMask get_filtered_stroke_mask(const Object *ob, attributes.lookup_or_default("material_index", bke::AttrDomain::Curve, 0).varray; IndexMask result = IndexMask::from_predicate( - curves.curves_range(), GrainSize(4096), memory, [&](const int64_t stroke_i) { + full_mask, GrainSize(4096), memory, [&](const int64_t stroke_i) { const int material_index = stroke_materials.get(stroke_i); if (material_filter != nullptr) { const bool match = (material_index == material_filter_index); -- 2.30.2 From bab7a2f9074151527d6d90cd21ebbe3df3f91975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 10:46:46 +0100 Subject: [PATCH 07/45] Use explicit flags to turn pass filters on/off. GP2 was using "pass > 0" as a toggle for pass filters, but 0 is a valid pass ID, so it was never possible to select pass 0. --- source/blender/makesdna/DNA_modifier_types.h | 10 +++-- .../blender/makesrna/intern/rna_modifier.cc | 10 +++++ .../intern/MOD_grease_pencil_util.cc | 37 ++++++++++++------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index d8aa3b5e0fd..38ef9c1acd3 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2501,10 +2501,12 @@ typedef struct GreasePencilModifierFilterData { } GreasePencilModifierFilterData; typedef enum GreasePencilModifierFilterFlag { - GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 0), - GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 1), - GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 2), - GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS = (1 << 3), + GREASE_PENCIL_FILTER_USE_LAYER_PASS = (1 << 0), + GREASE_PENCIL_FILTER_USE_MATERIAL_PASS = (1 << 1), + GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 2), + GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 3), + GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 4), + GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS = (1 << 5), } GreasePencilModifierFilterFlag; typedef struct GreasePencilOpacityModifierData { diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 3e957920902..7f04cbe22d5 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -7478,6 +7478,11 @@ static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Layer", "Layer name"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "use_layer_pass", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_USE_LAYER_PASS); + RNA_def_property_ui_text(prop, "Use Layer Pass", "Use layer pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "layer_pass", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, nullptr, "layer_pass"); RNA_def_property_range(prop, 0, 100); @@ -7504,6 +7509,11 @@ static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Material", "Material used for filtering"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "use_material_pass", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_USE_MATERIAL_PASS); + RNA_def_property_ui_text(prop, "Use Material Pass", "Use material pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "material_pass", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, nullptr, "material_pass"); RNA_def_property_range(prop, 0, 100); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 56ede9567dc..c089226a4f5 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -20,6 +20,8 @@ #include "BKE_lib_query.h" #include "BKE_material.h" +#include "DNA_defaults.h" + #include "DEG_depsgraph_query.hh" #include "MOD_ui_common.hh" @@ -39,9 +41,7 @@ void copy_data_filter(const GreasePencilModifierFilterData *filter_data_src, GreasePencilModifierFilterData *filter_data_dst, const int /*flag*/) { - memcpy((char *)filter_data_dst, - (const char *)filter_data_src, - sizeof(GreasePencilModifierFilterData)); + memcpy(filter_data_dst, filter_data_src, sizeof(GreasePencilModifierFilterData)); } void free_data_filter(GreasePencilModifierFilterData * /*filter_data*/) {} @@ -64,6 +64,8 @@ static void filter_panel_draw(const bContext * /*C*/, Panel *panel) PointerRNA ptr = RNA_pointer_get(modifier_ptr, "filter"); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); + const bool use_layer_pass = RNA_boolean_get(&ptr, "use_layer_pass"); + const bool use_material_pass = RNA_boolean_get(&ptr, "use_material_pass"); uiLayoutSetPropSep(layout, true); @@ -74,7 +76,11 @@ static void filter_panel_draw(const bContext * /*C*/, Panel *panel) uiLayoutSetPropDecorate(sub, false); uiItemR(sub, &ptr, "invert_layer", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + /* TODO Would be nice to have the checkbox in the same line as the pass button. */ row = uiLayoutRow(col, true); + uiItemR(row, &ptr, "use_layer_pass", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); + row = uiLayoutRow(col, true); + uiLayoutSetActive(row, use_layer_pass); uiItemR(row, &ptr, "layer_pass", UI_ITEM_NONE, nullptr, ICON_NONE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); @@ -87,7 +93,11 @@ static void filter_panel_draw(const bContext * /*C*/, Panel *panel) uiLayoutSetPropDecorate(sub, false); uiItemR(sub, &ptr, "invert_material", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + /* TODO Would be nice to have the checkbox in the same line as the pass button. */ row = uiLayoutRow(col, true); + uiItemR(row, &ptr, "use_material_pass", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); + row = uiLayoutRow(col, true); + uiLayoutSetActive(row, use_material_pass); uiItemR(row, &ptr, "material_pass", UI_ITEM_NONE, nullptr, ICON_NONE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); @@ -160,15 +170,16 @@ IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierFilterData &filter_data, IndexMaskMemory &memory) { - /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ - return get_filtered_layer_mask( - grease_pencil, - filter_data.layer_name[0] != '\0' ? std::make_optional(filter_data.layer_name) : - std::nullopt, - filter_data.layer_pass > 0 ? std::make_optional(filter_data.layer_pass) : std::nullopt, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, - memory); + return get_filtered_layer_mask(grease_pencil, + filter_data.layer_name[0] != '\0' ? + std::make_optional(filter_data.layer_name) : + std::nullopt, + (filter_data.flag & GREASE_PENCIL_FILTER_USE_LAYER_PASS) ? + std::make_optional(filter_data.layer_pass) : + std::nullopt, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, + memory); } static IndexMask get_filtered_stroke_mask(const Object *ob, @@ -222,7 +233,7 @@ IndexMask get_filtered_stroke_mask(const Object *ob, return get_filtered_stroke_mask(ob, curves, filter_data.material, - filter_data.material_pass > 0 ? + (filter_data.flag & GREASE_PENCIL_FILTER_USE_MATERIAL_PASS) ? std::make_optional(filter_data.material_pass) : std::nullopt, filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, -- 2.30.2 From a3109b6e8253bf0862fc3461378ad36796c266e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 11:41:22 +0100 Subject: [PATCH 08/45] Use the new uiLayoutPanel function to draw influence subpanel. --- source/blender/makesdna/DNA_modifier_types.h | 9 +++- .../blender/makesrna/intern/rna_modifier.cc | 7 ++++ .../intern/MOD_grease_pencil_opacity.cc | 13 ++++-- .../intern/MOD_grease_pencil_util.cc | 42 +++++++------------ .../intern/MOD_grease_pencil_util.hh | 6 ++- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 38ef9c1acd3..0106f839739 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2511,6 +2511,13 @@ typedef enum GreasePencilModifierFilterFlag { typedef struct GreasePencilOpacityModifierData { ModifierData modifier; + /** GreasePencilOpacityModifierFlag */ + int flag; + char _pad1[4]; GreasePencilModifierFilterData filter; - void *_pad; + void *_pad2; } GreasePencilOpacityModifierData; + +typedef enum GreasePencilOpacityModifierFlag { + MOD_GREASE_PENCIL_OPACITY_OPEN_INFLUENCE_PANEL = (1 << 0), +} GreasePencilOpacityModifierFlag; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 7f04cbe22d5..ca37239ba52 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -7548,6 +7548,13 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) RNA_def_property_struct_type(prop, "GreasePencilModifierFilter"); RNA_def_property_ui_text(prop, "Filter", "Filter settings"); + prop = RNA_def_property(srna, "open_influence_panel", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", MOD_GREASE_PENCIL_OPACITY_OPEN_INFLUENCE_PANEL); + RNA_def_property_ui_text(prop, "Open Influence Panel", "Open the influence panel"); + RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE); + RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, nullptr); + RNA_define_lib_overridable(true); // TODO diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 6c3ae9bd8a9..66206e1e3f3 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -139,13 +139,20 @@ static void modify_geometry_set(ModifierData *md, } } -static void panel_draw(const bContext * /*C*/, Panel *panel) +static void panel_draw(const bContext *C, Panel *panel) { uiLayout *layout = panel->layout; PointerRNA ob_ptr; PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr); + if (uiLayout *influence_panel = uiLayoutPanel( + C, layout, "Influence", ptr, "open_influence_panel")) + { + PointerRNA filter_ptr = RNA_pointer_get(ptr, "filter"); + greasepencil::draw_influence_settings(C, influence_panel, &filter_ptr); + } + uiLayoutSetPropSep(layout, true); // TODO @@ -155,9 +162,7 @@ static void panel_draw(const bContext * /*C*/, Panel *panel) static void panel_register(ARegionType *region_type) { - PanelType *panel_type = modifier_panel_register( - region_type, eModifierType_GreasePencilOpacity, panel_draw); - greasepencil::filter_subpanel_register(region_type, panel_type); + modifier_panel_register(region_type, eModifierType_GreasePencilOpacity, panel_draw); } static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index c089226a4f5..6b1f49c9ffe 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -27,6 +27,7 @@ #include "MOD_ui_common.hh" #include "RNA_access.hh" +#include "RNA_prototypes.h" #include "UI_interface.hh" @@ -54,60 +55,49 @@ void foreach_ID_link_filter(GreasePencilModifierFilterData *filter_data, walk(user_data, ob, (ID **)&filter_data->material, IDWALK_CB_USER); } -static void filter_panel_draw(const bContext * /*C*/, Panel *panel) +void draw_influence_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { - uiLayout *row, *col, *sub; - uiLayout *layout = panel->layout; - - PointerRNA ob_ptr; - PointerRNA *modifier_ptr = modifier_panel_get_property_pointers(panel, &ob_ptr); - PointerRNA ptr = RNA_pointer_get(modifier_ptr, "filter"); - + PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); - const bool use_layer_pass = RNA_boolean_get(&ptr, "use_layer_pass"); - const bool use_material_pass = RNA_boolean_get(&ptr, "use_material_pass"); + const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass"); + const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass"); + uiLayout *row, *col, *sub; uiLayoutSetPropSep(layout, true); col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); - uiItemPointerR(row, &ptr, "layer", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); + uiItemPointerR(row, ptr, "layer", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, &ptr, "invert_layer", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_layer", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); /* TODO Would be nice to have the checkbox in the same line as the pass button. */ row = uiLayoutRow(col, true); - uiItemR(row, &ptr, "use_layer_pass", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); + uiItemR(row, ptr, "use_layer_pass", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); row = uiLayoutRow(col, true); uiLayoutSetActive(row, use_layer_pass); - uiItemR(row, &ptr, "layer_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + uiItemR(row, ptr, "layer_pass", UI_ITEM_NONE, nullptr, ICON_NONE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, &ptr, "invert_layer_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_layer_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); - uiItemPointerR(row, &ptr, "material", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); + uiItemPointerR(row, ptr, "material", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, &ptr, "invert_material", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_material", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); /* TODO Would be nice to have the checkbox in the same line as the pass button. */ row = uiLayoutRow(col, true); - uiItemR(row, &ptr, "use_material_pass", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); + uiItemR(row, ptr, "use_material_pass", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); row = uiLayoutRow(col, true); uiLayoutSetActive(row, use_material_pass); - uiItemR(row, &ptr, "material_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + uiItemR(row, ptr, "material_pass", UI_ITEM_NONE, nullptr, ICON_NONE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, &ptr, "invert_material_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); -} - -void filter_subpanel_register(ARegionType *region_type, PanelType *panel_type) -{ - modifier_subpanel_register( - region_type, "influence", "Influence", nullptr, filter_panel_draw, panel_type); + uiItemR(sub, ptr, "invert_material_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } /** diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index 91d873a7676..c43c255c9c4 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -14,9 +14,12 @@ #include "BKE_modifier.hh" struct ARegionType; +struct bContext; struct GreasePencil; struct GreasePencilModifierFilterData; struct PanelType; +struct PointerRNA; +struct uiLayout; namespace blender::bke { class CurvesGeometry; namespace greasepencil { @@ -35,7 +38,8 @@ void foreach_ID_link_filter(GreasePencilModifierFilterData *filter_data, Object *ob, IDWalkFunc walk, void *user_data); -void filter_subpanel_register(ARegionType *region_type, PanelType *panel_type); + +void draw_influence_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierFilterData &filter_data, -- 2.30.2 From 35b8228385cf1618f47baafbed54965f3e9afd00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 11:52:49 +0100 Subject: [PATCH 09/45] Cleanup: more consistent function names. --- .../modifiers/intern/MOD_grease_pencil_opacity.cc | 10 +++++----- .../blender/modifiers/intern/MOD_grease_pencil_util.cc | 10 +++++----- .../blender/modifiers/intern/MOD_grease_pencil_util.hh | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 66206e1e3f3..9c4310a97dc 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -59,7 +59,7 @@ static void init_data(ModifierData *md) sizeof(*(omd)) - OFFSETOF_STRUCT_AFTER(omd, modifier)); } - greasepencil::init_data_filter(&omd->filter); + greasepencil::init_filter_data(&omd->filter); } static void copy_data(const ModifierData *md, ModifierData *target, const int flag) @@ -68,7 +68,7 @@ static void copy_data(const ModifierData *md, ModifierData *target, const int fl GreasePencilOpacityModifierData *tomd = (GreasePencilOpacityModifierData *)target; BKE_modifier_copydata_generic(md, target, flag); - greasepencil::copy_data_filter(&omd->filter, &tomd->filter, flag); + greasepencil::copy_filter_data(&omd->filter, &tomd->filter, flag); } static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks) @@ -82,14 +82,14 @@ static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_ static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - greasepencil::foreach_ID_link_filter(&omd->filter, ob, walk, user_data); + greasepencil::foreach_filter_ID_link(&omd->filter, ob, walk, user_data); } static void free_data(ModifierData *md) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - greasepencil::free_data_filter(&omd->filter); + greasepencil::free_filter_data(&omd->filter); } static void modify_curves(ModifierData *md, @@ -150,7 +150,7 @@ static void panel_draw(const bContext *C, Panel *panel) C, layout, "Influence", ptr, "open_influence_panel")) { PointerRNA filter_ptr = RNA_pointer_get(ptr, "filter"); - greasepencil::draw_influence_settings(C, influence_panel, &filter_ptr); + greasepencil::draw_filter_settings(C, influence_panel, &filter_ptr); } uiLayoutSetPropSep(layout, true); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 6b1f49c9ffe..0a9c6cd2fbf 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -36,18 +36,18 @@ namespace blender::greasepencil { using bke::greasepencil::Drawing; using bke::greasepencil::Layer; -void init_data_filter(GreasePencilModifierFilterData * /*filter_data*/) {} +void init_filter_data(GreasePencilModifierFilterData * /*filter_data*/) {} -void copy_data_filter(const GreasePencilModifierFilterData *filter_data_src, +void copy_filter_data(const GreasePencilModifierFilterData *filter_data_src, GreasePencilModifierFilterData *filter_data_dst, const int /*flag*/) { memcpy(filter_data_dst, filter_data_src, sizeof(GreasePencilModifierFilterData)); } -void free_data_filter(GreasePencilModifierFilterData * /*filter_data*/) {} +void free_filter_data(GreasePencilModifierFilterData * /*filter_data*/) {} -void foreach_ID_link_filter(GreasePencilModifierFilterData *filter_data, +void foreach_filter_ID_link(GreasePencilModifierFilterData *filter_data, Object *ob, IDWalkFunc walk, void *user_data) @@ -55,7 +55,7 @@ void foreach_ID_link_filter(GreasePencilModifierFilterData *filter_data, walk(user_data, ob, (ID **)&filter_data->material, IDWALK_CB_USER); } -void draw_influence_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +void draw_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index c43c255c9c4..d565ac1c54e 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -29,17 +29,17 @@ class Drawing; namespace blender::greasepencil { -void init_data_filter(GreasePencilModifierFilterData *filter_data); -void copy_data_filter(const GreasePencilModifierFilterData *filter_data_src, +void init_filter_data(GreasePencilModifierFilterData *filter_data); +void copy_filter_data(const GreasePencilModifierFilterData *filter_data_src, GreasePencilModifierFilterData *filter_data_dst, int flag); -void free_data_filter(GreasePencilModifierFilterData *filter_data); -void foreach_ID_link_filter(GreasePencilModifierFilterData *filter_data, +void free_filter_data(GreasePencilModifierFilterData *filter_data); +void foreach_filter_ID_link(GreasePencilModifierFilterData *filter_data, Object *ob, IDWalkFunc walk, void *user_data); -void draw_influence_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierFilterData &filter_data, -- 2.30.2 From dddd4eb52aec4ffa9ed0f90d27bf24b033ce2ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 12:03:46 +0100 Subject: [PATCH 10/45] General filter settings and functions for Grease Pencil modifiers. --- source/blender/makesdna/DNA_modifier_types.h | 27 +- .../blender/makesrna/intern/rna_modifier.cc | 106 +++++++ source/blender/modifiers/CMakeLists.txt | 2 + .../intern/MOD_grease_pencil_util.cc | 260 ++++++++++++++++++ .../intern/MOD_grease_pencil_util.hh | 57 ++++ 5 files changed, 450 insertions(+), 2 deletions(-) create mode 100644 source/blender/modifiers/intern/MOD_grease_pencil_util.cc create mode 100644 source/blender/modifiers/intern/MOD_grease_pencil_util.hh diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 0e31f383266..6a77a62fe1f 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -151,8 +151,8 @@ typedef enum { */ eModifierFlag_Active = (1 << 2), /** - * Only set on modifiers in evaluated objects. The flag indicates that the user modified inputs - * to the modifier which might invalidate simulation caches. + * Only set on modifiers in evaluated objects. The flag indicates that the user modified + * inputs to the modifier which might invalidate simulation caches. */ eModifierFlag_UserModified = (1 << 3), } ModifierFlag; @@ -2484,3 +2484,26 @@ typedef enum VolumeToMeshResolutionMode { typedef enum VolumeToMeshFlag { VOLUME_TO_MESH_USE_SMOOTH_SHADE = 1 << 0, } VolumeToMeshFlag; + +typedef struct GreasePencilModifierFilterData { + /** Filter by layer name. */ + char layer_name[64]; + /** Filter by stroke material. */ + struct Material *material; + /** Filter by layer pass. */ + int layer_pass; + /** Filter by material pass. */ + int material_pass; + /** GreasePencilModifierFilterFlag */ + int flag; + char _pad[4]; +} GreasePencilModifierFilterData; + +typedef enum GreasePencilModifierFilterFlag { + GREASE_PENCIL_FILTER_USE_LAYER_PASS = (1 << 0), + GREASE_PENCIL_FILTER_USE_MATERIAL_PASS = (1 << 1), + GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 2), + GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 3), + GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 4), + GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS = (1 << 5), +} GreasePencilModifierFilterFlag; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 3dbc5db42bc..aff61ddfd55 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -668,11 +668,13 @@ const EnumPropertyItem rna_enum_subdivision_boundary_smooth_items[] = { #ifdef RNA_RUNTIME # include "DNA_curve_types.h" # include "DNA_fluid_types.h" +# include "DNA_material_types.h" # include "DNA_particle_types.h" # include "BKE_cachefile.h" # include "BKE_context.hh" # include "BKE_deform.h" +# include "BKE_grease_pencil.hh" # include "BKE_mesh_runtime.hh" # include "BKE_modifier.hh" # include "BKE_object.hh" @@ -1705,6 +1707,37 @@ static IDProperty **rna_NodesModifier_properties(PointerRNA *ptr) NodesModifierSettings *settings = &nmd->settings; return &settings->properties; } + +bool rna_GreasePencilModifierFilter_material_poll(PointerRNA *ptr, PointerRNA value) +{ + Object *ob = reinterpret_cast(ptr->owner_id); + Material *ma = reinterpret_cast(value.owner_id); + + return BKE_grease_pencil_object_material_index_get(ob, ma) != -1; +} + +static void rna_GreasePencilModifierFilter_material_set(PointerRNA *ptr, + PointerRNA value, + ReportList *reports) +{ + Object *ob = reinterpret_cast(ptr->owner_id); + GreasePencilModifierFilterData *filter_data = static_cast( + ptr->data); + Material *ma = reinterpret_cast(value.owner_id); + + if (ma == nullptr || BKE_grease_pencil_object_material_index_get(ob, ma) != -1) { + id_lib_extern(reinterpret_cast(ob)); + filter_data->material = ma; + } + else { + BKE_reportf( + reports, + RPT_ERROR, + "Cannot assign material '%s', it has to be used by the grease pencil object already", + ma->id.name); + } +} + #else static void rna_def_modifier_panel_open_prop(StructRNA *srna, const char *identifier, const int id) @@ -7423,6 +7456,78 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna) RNA_define_lib_overridable(false); } +static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "GreasePencilModifierFilter", nullptr); + RNA_def_struct_ui_text( + srna, "Grease Pencil Modifier Filter", "Filter settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierFilterData"); + + RNA_define_lib_overridable(true); + + prop = RNA_def_property(srna, "layer", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, nullptr, "layer_name"); + RNA_def_property_ui_text(prop, "Layer", "Layer name"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "use_layer_pass", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_USE_LAYER_PASS); + RNA_def_property_ui_text(prop, "Use Layer Pass", "Use layer pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "layer_pass", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, nullptr, "layer_pass"); + RNA_def_property_range(prop, 0, 100); + RNA_def_property_ui_text(prop, "Layer Pass", "Layer pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_layer", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_LAYER); + RNA_def_property_ui_text(prop, "Invert Layer", "Invert layer filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_layer_pass", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_LAYER_PASS); + RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, + nullptr, + "rna_GreasePencilModifierFilter_material_set", + nullptr, + "rna_GreasePencilModifierFilter_material_poll"); + RNA_def_property_ui_text(prop, "Material", "Material used for filtering"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "use_material_pass", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_USE_MATERIAL_PASS); + RNA_def_property_ui_text(prop, "Use Material Pass", "Use material pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "material_pass", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, nullptr, "material_pass"); + RNA_def_property_range(prop, 0, 100); + RNA_def_property_ui_text(prop, "Material Pass", "Material pass"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_material", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_MATERIAL); + RNA_def_property_ui_text(prop, "Invert Material", "Invert material filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_material_pass", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS); + RNA_def_property_ui_text(prop, "Invert Material Pass", "Invert material pass filter"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + RNA_define_lib_overridable(false); +} + void RNA_def_modifier(BlenderRNA *brna) { StructRNA *srna; @@ -7583,6 +7688,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_mesh_to_volume(brna); rna_def_modifier_volume_displace(brna); rna_def_modifier_volume_to_mesh(brna); + rna_def_modifier_grease_pencil_filter(brna); } #endif diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index ef9ff57b606..c7daf7b51bf 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -44,6 +44,7 @@ set(SRC intern/MOD_edgesplit.cc intern/MOD_explode.cc intern/MOD_fluid.cc + intern/MOD_grease_pencil_util.cc intern/MOD_hook.cc intern/MOD_laplaciandeform.cc intern/MOD_laplaciansmooth.cc @@ -97,6 +98,7 @@ set(SRC MOD_modifiertypes.hh MOD_nodes.hh + intern/MOD_grease_pencil_util.hh intern/MOD_meshcache_util.hh intern/MOD_solidify_util.hh intern/MOD_ui_common.hh diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc new file mode 100644 index 00000000000..0a9c6cd2fbf --- /dev/null +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -0,0 +1,260 @@ +/* SPDX-FileCopyrightText: 2011 by Bastien Montagne. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup modifiers + */ + +#include "MOD_grease_pencil_util.hh" + +#include "BLI_set.hh" + +#include "DNA_grease_pencil_types.h" +#include "DNA_material_types.h" +#include "DNA_modifier_types.h" +#include "DNA_screen_types.h" + +#include "BKE_curves.hh" +#include "BKE_grease_pencil.hh" +#include "BKE_lib_query.h" +#include "BKE_material.h" + +#include "DNA_defaults.h" + +#include "DEG_depsgraph_query.hh" + +#include "MOD_ui_common.hh" + +#include "RNA_access.hh" +#include "RNA_prototypes.h" + +#include "UI_interface.hh" + +namespace blender::greasepencil { + +using bke::greasepencil::Drawing; +using bke::greasepencil::Layer; + +void init_filter_data(GreasePencilModifierFilterData * /*filter_data*/) {} + +void copy_filter_data(const GreasePencilModifierFilterData *filter_data_src, + GreasePencilModifierFilterData *filter_data_dst, + const int /*flag*/) +{ + memcpy(filter_data_dst, filter_data_src, sizeof(GreasePencilModifierFilterData)); +} + +void free_filter_data(GreasePencilModifierFilterData * /*filter_data*/) {} + +void foreach_filter_ID_link(GreasePencilModifierFilterData *filter_data, + Object *ob, + IDWalkFunc walk, + void *user_data) +{ + walk(user_data, ob, (ID **)&filter_data->material, IDWALK_CB_USER); +} + +void draw_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +{ + PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); + PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); + const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass"); + const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass"); + uiLayout *row, *col, *sub; + + uiLayoutSetPropSep(layout, true); + + col = uiLayoutColumn(layout, true); + row = uiLayoutRow(col, true); + uiItemPointerR(row, ptr, "layer", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); + sub = uiLayoutRow(row, true); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, ptr, "invert_layer", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + + /* TODO Would be nice to have the checkbox in the same line as the pass button. */ + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "use_layer_pass", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); + row = uiLayoutRow(col, true); + uiLayoutSetActive(row, use_layer_pass); + uiItemR(row, ptr, "layer_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + sub = uiLayoutRow(row, true); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, ptr, "invert_layer_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + + col = uiLayoutColumn(layout, true); + row = uiLayoutRow(col, true); + uiItemPointerR(row, ptr, "material", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); + sub = uiLayoutRow(row, true); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, ptr, "invert_material", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + + /* TODO Would be nice to have the checkbox in the same line as the pass button. */ + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "use_material_pass", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); + row = uiLayoutRow(col, true); + uiLayoutSetActive(row, use_material_pass); + uiItemR(row, ptr, "material_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + sub = uiLayoutRow(row, true); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, ptr, "invert_material_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); +} + +/** + * Get a list of pass IDs used by grease pencil materials. + * This way the material pass can be looked up by index instead of having to get the material for + * each curve. + */ +static Vector get_grease_pencil_material_passes(const Object *ob) +{ + short *totcol = BKE_object_material_len_p(const_cast(ob)); + Vector result(*totcol); + Material *ma = nullptr; + for (short i = 0; i < *totcol; i++) { + ma = BKE_object_material_get(const_cast(ob), i + 1); + /* Pass index of the grease pencil material. */ + result[i] = ma->gp_style->index; + } + return result; +} + +static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, + const std::optional layer_name_filter, + const std::optional layer_pass_filter, + const bool layer_filter_invert, + const bool layer_pass_filter_invert, + IndexMaskMemory &memory) +{ + const IndexMask full_mask = grease_pencil.layers().index_range(); + if (!layer_name_filter && !layer_pass_filter) { + return full_mask; + } + + bke::AttributeAccessor layer_attributes = grease_pencil.attributes(); + const Span layers = grease_pencil.layers(); + const VArray layer_passes = + layer_attributes.lookup_or_default("pass", bke::AttrDomain::Layer, 0).varray; + + IndexMask result = IndexMask::from_predicate( + full_mask, GrainSize(4096), memory, [&](const int64_t layer_i) { + if (layer_name_filter) { + const Layer &layer = *layers[layer_i]; + const bool match = (layer.name() == layer_name_filter.value()); + if (match == layer_filter_invert) { + return false; + } + } + if (layer_pass_filter) { + const int layer_pass = layer_passes.get(layer_i); + const bool match = (layer_pass == layer_pass_filter.value()); + if (match == layer_pass_filter_invert) { + return false; + } + } + return true; + }); + return result; +} + +IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, + const GreasePencilModifierFilterData &filter_data, + IndexMaskMemory &memory) +{ + return get_filtered_layer_mask(grease_pencil, + filter_data.layer_name[0] != '\0' ? + std::make_optional(filter_data.layer_name) : + std::nullopt, + (filter_data.flag & GREASE_PENCIL_FILTER_USE_LAYER_PASS) ? + std::make_optional(filter_data.layer_pass) : + std::nullopt, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, + memory); +} + +static IndexMask get_filtered_stroke_mask(const Object *ob, + const bke::CurvesGeometry &curves, + const Material *material_filter, + const std::optional material_pass_filter, + const bool material_filter_invert, + const bool material_pass_filter_invert, + IndexMaskMemory &memory) +{ + const IndexMask full_mask = curves.curves_range(); + if (!material_filter && !material_pass_filter) { + return full_mask; + } + + const int material_filter_index = BKE_grease_pencil_object_material_index_get( + const_cast(ob), const_cast(material_filter)); + const Vector material_pass_by_index = get_grease_pencil_material_passes(ob); + + bke::AttributeAccessor attributes = curves.attributes(); + VArray stroke_materials = + attributes.lookup_or_default("material_index", bke::AttrDomain::Curve, 0).varray; + + IndexMask result = IndexMask::from_predicate( + full_mask, GrainSize(4096), memory, [&](const int64_t stroke_i) { + const int material_index = stroke_materials.get(stroke_i); + if (material_filter != nullptr) { + const bool match = (material_index == material_filter_index); + if (match == material_filter_invert) { + return false; + } + } + if (material_pass_filter) { + const int material_pass = material_pass_by_index[material_index]; + const bool match = (material_pass == material_pass_filter.value()); + if (match == material_pass_filter_invert) { + return false; + } + } + return true; + }); + return result; +} + +IndexMask get_filtered_stroke_mask(const Object *ob, + const bke::CurvesGeometry &curves, + const GreasePencilModifierFilterData &filter_data, + IndexMaskMemory &memory) +{ + /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ + return get_filtered_stroke_mask(ob, + curves, + filter_data.material, + (filter_data.flag & GREASE_PENCIL_FILTER_USE_MATERIAL_PASS) ? + std::make_optional(filter_data.material_pass) : + std::nullopt, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, + filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS, + memory); +} + +Vector get_drawings_for_write(GreasePencil &grease_pencil, + const IndexMask &layer_mask, + int frame) +{ + /* Set of unique drawing indices. */ + Set drawing_indices; + for (const int64_t i : layer_mask.index_range()) { + Layer *layer = grease_pencil.layers_for_write()[layer_mask[i]]; + const int drawing_index = layer->drawing_index_at(frame); + if (drawing_index >= 0) { + drawing_indices.add(drawing_index); + } + } + + /* List of owned drawings, ignore drawing references to other data blocks. */ + Vector drawings; + for (const int drawing_index : drawing_indices) { + GreasePencilDrawingBase *drawing_base = grease_pencil.drawing(drawing_index); + if (drawing_base->type == GP_DRAWING) { + GreasePencilDrawing *drawing = reinterpret_cast(drawing_base); + drawings.append(&drawing->wrap()); + } + } + return drawings; +} + +} // namespace blender::greasepencil diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh new file mode 100644 index 00000000000..d565ac1c54e --- /dev/null +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -0,0 +1,57 @@ +/* SPDX-FileCopyrightText: 2011 by Bastien Montagne. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup modifiers + */ + +#pragma once + +#include "BLI_index_mask.hh" +#include "BLI_vector.hh" + +#include "BKE_modifier.hh" + +struct ARegionType; +struct bContext; +struct GreasePencil; +struct GreasePencilModifierFilterData; +struct PanelType; +struct PointerRNA; +struct uiLayout; +namespace blender::bke { +class CurvesGeometry; +namespace greasepencil { +class Drawing; +} +} // namespace blender::bke + +namespace blender::greasepencil { + +void init_filter_data(GreasePencilModifierFilterData *filter_data); +void copy_filter_data(const GreasePencilModifierFilterData *filter_data_src, + GreasePencilModifierFilterData *filter_data_dst, + int flag); +void free_filter_data(GreasePencilModifierFilterData *filter_data); +void foreach_filter_ID_link(GreasePencilModifierFilterData *filter_data, + Object *ob, + IDWalkFunc walk, + void *user_data); + +void draw_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); + +IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, + const GreasePencilModifierFilterData &filter_data, + IndexMaskMemory &memory); + +IndexMask get_filtered_stroke_mask(const Object *ob, + const bke::CurvesGeometry &curves, + const GreasePencilModifierFilterData &filter_data, + IndexMaskMemory &memory); + +Vector get_drawings_for_write(GreasePencil &grease_pencil, + const IndexMask &layer_mask, + int frame); + +} // namespace blender::greasepencil -- 2.30.2 From 25cd79488bc32ca490dc00fe6e920ea5939b3ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 13:04:31 +0100 Subject: [PATCH 11/45] Split the filters for GP modifiers into separate structs. This will allow easier combination of influence settings for various modifier types. --- source/blender/makesdna/DNA_modifier_types.h | 35 ++++++--- .../blender/makesrna/intern/rna_modifier.cc | 73 ++++++++++++++----- .../intern/MOD_grease_pencil_opacity.cc | 18 +++-- .../intern/MOD_grease_pencil_util.cc | 61 +++++++++------- .../intern/MOD_grease_pencil_util.hh | 29 ++++---- 5 files changed, 140 insertions(+), 76 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 0106f839739..c84afaf077c 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2486,35 +2486,48 @@ typedef enum VolumeToMeshFlag { VOLUME_TO_MESH_USE_SMOOTH_SHADE = 1 << 0, } VolumeToMeshFlag; -typedef struct GreasePencilModifierFilterData { +typedef struct GreasePencilModifierLayerFilter { /** Filter by layer name. */ char layer_name[64]; - /** Filter by stroke material. */ - struct Material *material; /** Filter by layer pass. */ int layer_pass; + /** GreasePencilModifierFilterFlag */ + int flag; +} GreasePencilModifierLayerFilter; + +typedef struct GreasePencilModifierMaterialFilter { + /** Filter by stroke material. */ + struct Material *material; /** Filter by material pass. */ int material_pass; /** GreasePencilModifierFilterFlag */ int flag; - char _pad[4]; -} GreasePencilModifierFilterData; +} GreasePencilModifierMaterialFilter; typedef enum GreasePencilModifierFilterFlag { - GREASE_PENCIL_FILTER_USE_LAYER_PASS = (1 << 0), - GREASE_PENCIL_FILTER_USE_MATERIAL_PASS = (1 << 1), - GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 2), - GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 3), - GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 4), + GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 0), + GREASE_PENCIL_FILTER_USE_LAYER_PASS = (1 << 1), + GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 2), + GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 3), + GREASE_PENCIL_FILTER_USE_MATERIAL_PASS = (1 << 4), GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS = (1 << 5), } GreasePencilModifierFilterFlag; +/** + * Combined generic influence data for grease pencil modifiers. + * Not all parts may be used by all modifier types. + */ +typedef struct GreasePencilModifierInfluenceData { + GreasePencilModifierLayerFilter layer_filter; + GreasePencilModifierMaterialFilter material_filter; +} GreasePencilModifierInfluenceData; + typedef struct GreasePencilOpacityModifierData { ModifierData modifier; + GreasePencilModifierInfluenceData influence; /** GreasePencilOpacityModifierFlag */ int flag; char _pad1[4]; - GreasePencilModifierFilterData filter; void *_pad2; } GreasePencilOpacityModifierData; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index ca37239ba52..58964b356a0 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -1713,7 +1713,7 @@ static IDProperty **rna_NodesModifier_properties(PointerRNA *ptr) return &settings->properties; } -bool rna_GreasePencilModifierFilter_material_poll(PointerRNA *ptr, PointerRNA value) +bool rna_GreasePencilModifierMaterialFilter_material_poll(PointerRNA *ptr, PointerRNA value) { Object *ob = reinterpret_cast(ptr->owner_id); Material *ma = reinterpret_cast(value.owner_id); @@ -1721,18 +1721,18 @@ bool rna_GreasePencilModifierFilter_material_poll(PointerRNA *ptr, PointerRNA va return BKE_grease_pencil_object_material_index_get(ob, ma) != -1; } -static void rna_GreasePencilModifierFilter_material_set(PointerRNA *ptr, - PointerRNA value, - ReportList *reports) +static void rna_GreasePencilModifierMaterialFilter_material_set(PointerRNA *ptr, + PointerRNA value, + ReportList *reports) { Object *ob = reinterpret_cast(ptr->owner_id); - GreasePencilModifierFilterData *filter_data = static_cast( + GreasePencilModifierMaterialFilter *filter = static_cast( ptr->data); Material *ma = reinterpret_cast(value.owner_id); if (ma == nullptr || BKE_grease_pencil_object_material_index_get(ob, ma) != -1) { id_lib_extern(reinterpret_cast(ob)); - filter_data->material = ma; + filter->material = ma; } else { BKE_reportf( @@ -7461,15 +7461,16 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna) RNA_define_lib_overridable(false); } -static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_layer_filter(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierFilter", nullptr); - RNA_def_struct_ui_text( - srna, "Grease Pencil Modifier Filter", "Filter settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierFilterData"); + srna = RNA_def_struct(brna, "GreasePencilModifierLayerFilter", nullptr); + RNA_def_struct_ui_text(srna, + "Grease Pencil Modifier Layer Filter", + "Layer filter settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierLayerFilter"); RNA_define_lib_overridable(true); @@ -7499,13 +7500,29 @@ static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + RNA_define_lib_overridable(false); +} + +static void rna_def_modifier_grease_pencil_material_filter(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "GreasePencilModifierMaterialFilter", nullptr); + RNA_def_struct_ui_text(srna, + "Grease Pencil Modifier Material Filter", + "Material filter settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierMaterialFilter"); + + RNA_define_lib_overridable(true); + prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_pointer_funcs(prop, nullptr, - "rna_GreasePencilModifierFilter_material_set", + "rna_GreasePencilModifierMaterialFilter_material_set", nullptr, - "rna_GreasePencilModifierFilter_material_poll"); + "rna_GreasePencilModifierMaterialFilter_material_poll"); RNA_def_property_ui_text(prop, "Material", "Material used for filtering"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7533,6 +7550,27 @@ static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) RNA_define_lib_overridable(false); } +/** Utility function to register common influence properties for grease pencil modifiers. */ +static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, + const char *layer_filter_sdna, + const char *material_filter_sdna) +{ + PropertyRNA *prop; + + if (layer_filter_sdna) { + prop = RNA_def_property(srna, "layer_filter", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, layer_filter_sdna); + RNA_def_property_struct_type(prop, "GreasePencilModifierLayerFilter"); + RNA_def_property_ui_text(prop, "Layer Filter", "Layer filter settings"); + } + if (material_filter_sdna) { + prop = RNA_def_property(srna, "material_filter", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, material_filter_sdna); + RNA_def_property_struct_type(prop, "GreasePencilModifierMaterialFilter"); + RNA_def_property_ui_text(prop, "Material Filter", "Material filter settings"); + } +} + static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) { StructRNA *srna; @@ -7543,10 +7581,8 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) RNA_def_struct_sdna(srna, "GreasePencilOpacityModifierData"); RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY); - prop = RNA_def_property(srna, "filter", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, "filter"); - RNA_def_property_struct_type(prop, "GreasePencilModifierFilter"); - RNA_def_property_ui_text(prop, "Filter", "Filter settings"); + rna_def_modifier_grease_pencil_influence_properties( + srna, "influence.layer_filter", "influence.material_filter"); prop = RNA_def_property(srna, "open_influence_panel", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( @@ -7723,7 +7759,8 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_volume_displace(brna); rna_def_modifier_volume_to_mesh(brna); rna_def_modifier_grease_pencil_opacity(brna); - rna_def_modifier_grease_pencil_filter(brna); + rna_def_modifier_grease_pencil_layer_filter(brna); + rna_def_modifier_grease_pencil_material_filter(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 9c4310a97dc..e24ebacacef 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -59,7 +59,7 @@ static void init_data(ModifierData *md) sizeof(*(omd)) - OFFSETOF_STRUCT_AFTER(omd, modifier)); } - greasepencil::init_filter_data(&omd->filter); + greasepencil::init_influence_data(&omd->influence); } static void copy_data(const ModifierData *md, ModifierData *target, const int flag) @@ -68,7 +68,7 @@ static void copy_data(const ModifierData *md, ModifierData *target, const int fl GreasePencilOpacityModifierData *tomd = (GreasePencilOpacityModifierData *)target; BKE_modifier_copydata_generic(md, target, flag); - greasepencil::copy_filter_data(&omd->filter, &tomd->filter, flag); + greasepencil::copy_influence_data(&omd->influence, &tomd->influence, flag); } static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks) @@ -82,14 +82,14 @@ static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_ static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - greasepencil::foreach_filter_ID_link(&omd->filter, ob, walk, user_data); + greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data); } static void free_data(ModifierData *md) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - greasepencil::free_filter_data(&omd->filter); + greasepencil::free_influence_data(&omd->influence); } static void modify_curves(ModifierData *md, @@ -105,7 +105,7 @@ static void modify_curves(ModifierData *md, OffsetIndices points_by_curve = curves.points_by_curve(); IndexMaskMemory mask_memory; IndexMask curves_mask = greasepencil::get_filtered_stroke_mask( - ctx->object, curves, omd->filter, mask_memory); + ctx->object, curves, omd->influence.material_filter, mask_memory); for (const int64_t i : curves_mask.index_range()) { const int64_t curve_i = curves_mask[i]; for (const int64_t point_i : points_by_curve[curve_i]) { @@ -131,7 +131,7 @@ static void modify_geometry_set(ModifierData *md, IndexMaskMemory mask_memory; IndexMask layer_mask = greasepencil::get_filtered_layer_mask( - *grease_pencil, omd->filter, mask_memory); + *grease_pencil, omd->influence.layer_filter, mask_memory); Vector drawings = greasepencil::get_drawings_for_write( *grease_pencil, layer_mask, frame); for (Drawing *drawing : drawings) { @@ -149,8 +149,10 @@ static void panel_draw(const bContext *C, Panel *panel) if (uiLayout *influence_panel = uiLayoutPanel( C, layout, "Influence", ptr, "open_influence_panel")) { - PointerRNA filter_ptr = RNA_pointer_get(ptr, "filter"); - greasepencil::draw_filter_settings(C, influence_panel, &filter_ptr); + PointerRNA layer_filter_ptr = RNA_pointer_get(ptr, "layer_filter"); + PointerRNA material_filter_ptr = RNA_pointer_get(ptr, "material_filter"); + greasepencil::draw_layer_filter_settings(C, influence_panel, &layer_filter_ptr); + greasepencil::draw_material_filter_settings(C, influence_panel, &material_filter_ptr); } uiLayoutSetPropSep(layout, true); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 0a9c6cd2fbf..2a27b01e341 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -36,31 +36,30 @@ namespace blender::greasepencil { using bke::greasepencil::Drawing; using bke::greasepencil::Layer; -void init_filter_data(GreasePencilModifierFilterData * /*filter_data*/) {} +void init_influence_data(GreasePencilModifierInfluenceData * /*influence_data*/) {} -void copy_filter_data(const GreasePencilModifierFilterData *filter_data_src, - GreasePencilModifierFilterData *filter_data_dst, - const int /*flag*/) +void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, + GreasePencilModifierInfluenceData *influence_data_dst, + const int /*flag*/) { - memcpy(filter_data_dst, filter_data_src, sizeof(GreasePencilModifierFilterData)); + memcpy(influence_data_dst, influence_data_src, sizeof(GreasePencilModifierInfluenceData)); } -void free_filter_data(GreasePencilModifierFilterData * /*filter_data*/) {} +void free_influence_data(GreasePencilModifierInfluenceData * /*influence_data*/) {} -void foreach_filter_ID_link(GreasePencilModifierFilterData *filter_data, - Object *ob, - IDWalkFunc walk, - void *user_data) +void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data, + Object *ob, + IDWalkFunc walk, + void *user_data) { - walk(user_data, ob, (ID **)&filter_data->material, IDWALK_CB_USER); + walk(user_data, ob, (ID **)&influence_data->material_filter.material, IDWALK_CB_USER); } -void draw_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass"); - const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass"); uiLayout *row, *col, *sub; uiLayoutSetPropSep(layout, true); @@ -81,6 +80,16 @@ void draw_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA * sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); uiItemR(sub, ptr, "invert_layer_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); +} + +void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +{ + PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); + PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); + const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass"); + uiLayout *row, *col, *sub; + + uiLayoutSetPropSep(layout, true); col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); @@ -157,18 +166,18 @@ static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, } IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, - const GreasePencilModifierFilterData &filter_data, + const GreasePencilModifierLayerFilter &filter, IndexMaskMemory &memory) { return get_filtered_layer_mask(grease_pencil, - filter_data.layer_name[0] != '\0' ? - std::make_optional(filter_data.layer_name) : + filter.layer_name[0] != '\0' ? + std::make_optional(filter.layer_name) : std::nullopt, - (filter_data.flag & GREASE_PENCIL_FILTER_USE_LAYER_PASS) ? - std::make_optional(filter_data.layer_pass) : + (filter.flag & GREASE_PENCIL_FILTER_USE_LAYER_PASS) ? + std::make_optional(filter.layer_pass) : std::nullopt, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, + filter.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, + filter.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, memory); } @@ -216,18 +225,18 @@ static IndexMask get_filtered_stroke_mask(const Object *ob, IndexMask get_filtered_stroke_mask(const Object *ob, const bke::CurvesGeometry &curves, - const GreasePencilModifierFilterData &filter_data, + const GreasePencilModifierMaterialFilter &filter, IndexMaskMemory &memory) { /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ return get_filtered_stroke_mask(ob, curves, - filter_data.material, - (filter_data.flag & GREASE_PENCIL_FILTER_USE_MATERIAL_PASS) ? - std::make_optional(filter_data.material_pass) : + filter.material, + (filter.flag & GREASE_PENCIL_FILTER_USE_MATERIAL_PASS) ? + std::make_optional(filter.material_pass) : std::nullopt, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS, + filter.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, + filter.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS, memory); } diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index d565ac1c54e..f0cd122a449 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -16,7 +16,9 @@ struct ARegionType; struct bContext; struct GreasePencil; -struct GreasePencilModifierFilterData; +struct GreasePencilModifierInfluenceData; +struct GreasePencilModifierLayerFilter; +struct GreasePencilModifierMaterialFilter; struct PanelType; struct PointerRNA; struct uiLayout; @@ -29,25 +31,26 @@ class Drawing; namespace blender::greasepencil { -void init_filter_data(GreasePencilModifierFilterData *filter_data); -void copy_filter_data(const GreasePencilModifierFilterData *filter_data_src, - GreasePencilModifierFilterData *filter_data_dst, - int flag); -void free_filter_data(GreasePencilModifierFilterData *filter_data); -void foreach_filter_ID_link(GreasePencilModifierFilterData *filter_data, - Object *ob, - IDWalkFunc walk, - void *user_data); +void init_influence_data(GreasePencilModifierInfluenceData *influence_data); +void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, + GreasePencilModifierInfluenceData *influence_data_dst, + int flag); +void free_influence_data(GreasePencilModifierInfluenceData *influence_data); +void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data, + Object *ob, + IDWalkFunc walk, + void *user_data); -void draw_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_layer_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_material_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, - const GreasePencilModifierFilterData &filter_data, + const GreasePencilModifierLayerFilter &filter, IndexMaskMemory &memory); IndexMask get_filtered_stroke_mask(const Object *ob, const bke::CurvesGeometry &curves, - const GreasePencilModifierFilterData &filter_data, + const GreasePencilModifierMaterialFilter &filter, IndexMaskMemory &memory); Vector get_drawings_for_write(GreasePencil &grease_pencil, -- 2.30.2 From d6b1232d07de086c66dc98d7ac3efc70977af681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 13:04:31 +0100 Subject: [PATCH 12/45] Split the filters for GP modifiers into separate structs. This will allow easier combination of influence settings for various modifier types. --- source/blender/makesdna/DNA_modifier_types.h | 32 ++++++--- .../blender/makesrna/intern/rna_modifier.cc | 67 +++++++++++++++---- .../intern/MOD_grease_pencil_util.cc | 61 ++++++++++------- .../intern/MOD_grease_pencil_util.hh | 29 ++++---- 4 files changed, 126 insertions(+), 63 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 6a77a62fe1f..4746c0909e9 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2485,25 +2485,37 @@ typedef enum VolumeToMeshFlag { VOLUME_TO_MESH_USE_SMOOTH_SHADE = 1 << 0, } VolumeToMeshFlag; -typedef struct GreasePencilModifierFilterData { +typedef struct GreasePencilModifierLayerFilter { /** Filter by layer name. */ char layer_name[64]; - /** Filter by stroke material. */ - struct Material *material; /** Filter by layer pass. */ int layer_pass; + /** GreasePencilModifierFilterFlag */ + int flag; +} GreasePencilModifierLayerFilter; + +typedef struct GreasePencilModifierMaterialFilter { + /** Filter by stroke material. */ + struct Material *material; /** Filter by material pass. */ int material_pass; /** GreasePencilModifierFilterFlag */ int flag; - char _pad[4]; -} GreasePencilModifierFilterData; +} GreasePencilModifierMaterialFilter; typedef enum GreasePencilModifierFilterFlag { - GREASE_PENCIL_FILTER_USE_LAYER_PASS = (1 << 0), - GREASE_PENCIL_FILTER_USE_MATERIAL_PASS = (1 << 1), - GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 2), - GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 3), - GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 4), + GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 0), + GREASE_PENCIL_FILTER_USE_LAYER_PASS = (1 << 1), + GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 2), + GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 3), + GREASE_PENCIL_FILTER_USE_MATERIAL_PASS = (1 << 4), GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS = (1 << 5), } GreasePencilModifierFilterFlag; +/** + * Combined generic influence data for grease pencil modifiers. + * Not all parts may be used by all modifier types. + */ +typedef struct GreasePencilModifierInfluenceData { + GreasePencilModifierLayerFilter layer_filter; + GreasePencilModifierMaterialFilter material_filter; +} GreasePencilModifierInfluenceData; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index aff61ddfd55..a2ec2a1358b 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -1708,7 +1708,7 @@ static IDProperty **rna_NodesModifier_properties(PointerRNA *ptr) return &settings->properties; } -bool rna_GreasePencilModifierFilter_material_poll(PointerRNA *ptr, PointerRNA value) +bool rna_GreasePencilModifierMaterialFilter_material_poll(PointerRNA *ptr, PointerRNA value) { Object *ob = reinterpret_cast(ptr->owner_id); Material *ma = reinterpret_cast(value.owner_id); @@ -1716,18 +1716,18 @@ bool rna_GreasePencilModifierFilter_material_poll(PointerRNA *ptr, PointerRNA va return BKE_grease_pencil_object_material_index_get(ob, ma) != -1; } -static void rna_GreasePencilModifierFilter_material_set(PointerRNA *ptr, - PointerRNA value, - ReportList *reports) +static void rna_GreasePencilModifierMaterialFilter_material_set(PointerRNA *ptr, + PointerRNA value, + ReportList *reports) { Object *ob = reinterpret_cast(ptr->owner_id); - GreasePencilModifierFilterData *filter_data = static_cast( + GreasePencilModifierMaterialFilter *filter = static_cast( ptr->data); Material *ma = reinterpret_cast(value.owner_id); if (ma == nullptr || BKE_grease_pencil_object_material_index_get(ob, ma) != -1) { id_lib_extern(reinterpret_cast(ob)); - filter_data->material = ma; + filter->material = ma; } else { BKE_reportf( @@ -7456,15 +7456,16 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna) RNA_define_lib_overridable(false); } -static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_layer_filter(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierFilter", nullptr); - RNA_def_struct_ui_text( - srna, "Grease Pencil Modifier Filter", "Filter settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierFilterData"); + srna = RNA_def_struct(brna, "GreasePencilModifierLayerFilter", nullptr); + RNA_def_struct_ui_text(srna, + "Grease Pencil Modifier Layer Filter", + "Layer filter settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierLayerFilter"); RNA_define_lib_overridable(true); @@ -7494,13 +7495,29 @@ static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + RNA_define_lib_overridable(false); +} + +static void rna_def_modifier_grease_pencil_material_filter(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "GreasePencilModifierMaterialFilter", nullptr); + RNA_def_struct_ui_text(srna, + "Grease Pencil Modifier Material Filter", + "Material filter settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierMaterialFilter"); + + RNA_define_lib_overridable(true); + prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_pointer_funcs(prop, nullptr, - "rna_GreasePencilModifierFilter_material_set", + "rna_GreasePencilModifierMaterialFilter_material_set", nullptr, - "rna_GreasePencilModifierFilter_material_poll"); + "rna_GreasePencilModifierMaterialFilter_material_poll"); RNA_def_property_ui_text(prop, "Material", "Material used for filtering"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7528,6 +7545,27 @@ static void rna_def_modifier_grease_pencil_filter(BlenderRNA *brna) RNA_define_lib_overridable(false); } +/** Utility function to register common influence properties for grease pencil modifiers. */ +static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, + const char *layer_filter_sdna, + const char *material_filter_sdna) +{ + PropertyRNA *prop; + + if (layer_filter_sdna) { + prop = RNA_def_property(srna, "layer_filter", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, layer_filter_sdna); + RNA_def_property_struct_type(prop, "GreasePencilModifierLayerFilter"); + RNA_def_property_ui_text(prop, "Layer Filter", "Layer filter settings"); + } + if (material_filter_sdna) { + prop = RNA_def_property(srna, "material_filter", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, material_filter_sdna); + RNA_def_property_struct_type(prop, "GreasePencilModifierMaterialFilter"); + RNA_def_property_ui_text(prop, "Material Filter", "Material filter settings"); + } +} + void RNA_def_modifier(BlenderRNA *brna) { StructRNA *srna; @@ -7688,7 +7726,8 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_mesh_to_volume(brna); rna_def_modifier_volume_displace(brna); rna_def_modifier_volume_to_mesh(brna); - rna_def_modifier_grease_pencil_filter(brna); + rna_def_modifier_grease_pencil_layer_filter(brna); + rna_def_modifier_grease_pencil_material_filter(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 0a9c6cd2fbf..2a27b01e341 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -36,31 +36,30 @@ namespace blender::greasepencil { using bke::greasepencil::Drawing; using bke::greasepencil::Layer; -void init_filter_data(GreasePencilModifierFilterData * /*filter_data*/) {} +void init_influence_data(GreasePencilModifierInfluenceData * /*influence_data*/) {} -void copy_filter_data(const GreasePencilModifierFilterData *filter_data_src, - GreasePencilModifierFilterData *filter_data_dst, - const int /*flag*/) +void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, + GreasePencilModifierInfluenceData *influence_data_dst, + const int /*flag*/) { - memcpy(filter_data_dst, filter_data_src, sizeof(GreasePencilModifierFilterData)); + memcpy(influence_data_dst, influence_data_src, sizeof(GreasePencilModifierInfluenceData)); } -void free_filter_data(GreasePencilModifierFilterData * /*filter_data*/) {} +void free_influence_data(GreasePencilModifierInfluenceData * /*influence_data*/) {} -void foreach_filter_ID_link(GreasePencilModifierFilterData *filter_data, - Object *ob, - IDWalkFunc walk, - void *user_data) +void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data, + Object *ob, + IDWalkFunc walk, + void *user_data) { - walk(user_data, ob, (ID **)&filter_data->material, IDWALK_CB_USER); + walk(user_data, ob, (ID **)&influence_data->material_filter.material, IDWALK_CB_USER); } -void draw_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass"); - const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass"); uiLayout *row, *col, *sub; uiLayoutSetPropSep(layout, true); @@ -81,6 +80,16 @@ void draw_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA * sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); uiItemR(sub, ptr, "invert_layer_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); +} + +void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +{ + PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); + PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); + const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass"); + uiLayout *row, *col, *sub; + + uiLayoutSetPropSep(layout, true); col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); @@ -157,18 +166,18 @@ static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, } IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, - const GreasePencilModifierFilterData &filter_data, + const GreasePencilModifierLayerFilter &filter, IndexMaskMemory &memory) { return get_filtered_layer_mask(grease_pencil, - filter_data.layer_name[0] != '\0' ? - std::make_optional(filter_data.layer_name) : + filter.layer_name[0] != '\0' ? + std::make_optional(filter.layer_name) : std::nullopt, - (filter_data.flag & GREASE_PENCIL_FILTER_USE_LAYER_PASS) ? - std::make_optional(filter_data.layer_pass) : + (filter.flag & GREASE_PENCIL_FILTER_USE_LAYER_PASS) ? + std::make_optional(filter.layer_pass) : std::nullopt, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, + filter.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, + filter.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, memory); } @@ -216,18 +225,18 @@ static IndexMask get_filtered_stroke_mask(const Object *ob, IndexMask get_filtered_stroke_mask(const Object *ob, const bke::CurvesGeometry &curves, - const GreasePencilModifierFilterData &filter_data, + const GreasePencilModifierMaterialFilter &filter, IndexMaskMemory &memory) { /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ return get_filtered_stroke_mask(ob, curves, - filter_data.material, - (filter_data.flag & GREASE_PENCIL_FILTER_USE_MATERIAL_PASS) ? - std::make_optional(filter_data.material_pass) : + filter.material, + (filter.flag & GREASE_PENCIL_FILTER_USE_MATERIAL_PASS) ? + std::make_optional(filter.material_pass) : std::nullopt, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, - filter_data.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS, + filter.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, + filter.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS, memory); } diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index d565ac1c54e..f0cd122a449 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -16,7 +16,9 @@ struct ARegionType; struct bContext; struct GreasePencil; -struct GreasePencilModifierFilterData; +struct GreasePencilModifierInfluenceData; +struct GreasePencilModifierLayerFilter; +struct GreasePencilModifierMaterialFilter; struct PanelType; struct PointerRNA; struct uiLayout; @@ -29,25 +31,26 @@ class Drawing; namespace blender::greasepencil { -void init_filter_data(GreasePencilModifierFilterData *filter_data); -void copy_filter_data(const GreasePencilModifierFilterData *filter_data_src, - GreasePencilModifierFilterData *filter_data_dst, - int flag); -void free_filter_data(GreasePencilModifierFilterData *filter_data); -void foreach_filter_ID_link(GreasePencilModifierFilterData *filter_data, - Object *ob, - IDWalkFunc walk, - void *user_data); +void init_influence_data(GreasePencilModifierInfluenceData *influence_data); +void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, + GreasePencilModifierInfluenceData *influence_data_dst, + int flag); +void free_influence_data(GreasePencilModifierInfluenceData *influence_data); +void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data, + Object *ob, + IDWalkFunc walk, + void *user_data); -void draw_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_layer_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_material_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, - const GreasePencilModifierFilterData &filter_data, + const GreasePencilModifierLayerFilter &filter, IndexMaskMemory &memory); IndexMask get_filtered_stroke_mask(const Object *ob, const bke::CurvesGeometry &curves, - const GreasePencilModifierFilterData &filter_data, + const GreasePencilModifierMaterialFilter &filter, IndexMaskMemory &memory); Vector get_drawings_for_write(GreasePencil &grease_pencil, -- 2.30.2 From ae51e9c4b93ca0af0f47e7bb08eef2fc40b1e8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 15:11:32 +0100 Subject: [PATCH 13/45] Influence settings for vertex groups. --- source/blender/makesdna/DNA_modifier_types.h | 26 ++++--- .../blender/makesrna/intern/rna_modifier.cc | 67 ++++++++++++++++--- .../intern/MOD_grease_pencil_opacity.cc | 2 + .../intern/MOD_grease_pencil_util.cc | 41 ++++++++---- .../intern/MOD_grease_pencil_util.hh | 1 + 5 files changed, 109 insertions(+), 28 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index c84afaf077c..d5d57fed289 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2504,14 +2504,23 @@ typedef struct GreasePencilModifierMaterialFilter { int flag; } GreasePencilModifierMaterialFilter; -typedef enum GreasePencilModifierFilterFlag { - GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 0), - GREASE_PENCIL_FILTER_USE_LAYER_PASS = (1 << 1), - GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 2), - GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 3), - GREASE_PENCIL_FILTER_USE_MATERIAL_PASS = (1 << 4), - GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS = (1 << 5), -} GreasePencilModifierFilterFlag; +typedef struct GreasePencilModifierVertexGroupData { + /** #MAX_VGROUP_NAME. */ + char vertex_group_name[64]; + /** GreasePencilModifierFilterFlag */ + int flag; + char _pad[4]; +} GreasePencilModifierVertexGroupData; + +typedef enum GreasePencilModifierInfluenceFlag { + GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER = (1 << 0), + GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER = (1 << 1), + GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER = (1 << 2), + GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER = (1 << 3), + GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER = (1 << 4), + GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER = (1 << 5), + GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP = (1 << 6), +} GreasePencilModifierInfluenceFlag; /** * Combined generic influence data for grease pencil modifiers. @@ -2520,6 +2529,7 @@ typedef enum GreasePencilModifierFilterFlag { typedef struct GreasePencilModifierInfluenceData { GreasePencilModifierLayerFilter layer_filter; GreasePencilModifierMaterialFilter material_filter; + GreasePencilModifierVertexGroupData vertex_group; } GreasePencilModifierInfluenceData; typedef struct GreasePencilOpacityModifierData { diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 58964b356a0..1bf171712f0 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -1743,6 +1743,14 @@ static void rna_GreasePencilModifierMaterialFilter_material_set(PointerRNA *ptr, } } +static void rna_GreasePencilModifierVertexGroupData_name_set(PointerRNA *ptr, const char *value) +{ + GreasePencilModifierVertexGroupData *vgroup_data = + static_cast(ptr->data); + rna_object_vgroup_name_set( + ptr, value, vgroup_data->vertex_group_name, sizeof(vgroup_data->vertex_group_name)); +} + #else static void rna_def_modifier_panel_open_prop(StructRNA *srna, const char *identifier, const int id) @@ -7480,7 +7488,8 @@ static void rna_def_modifier_grease_pencil_layer_filter(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "use_layer_pass", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_USE_LAYER_PASS); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Layer Pass", "Use layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7491,12 +7500,14 @@ static void rna_def_modifier_grease_pencil_layer_filter(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_layer", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_LAYER); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER); RNA_def_property_ui_text(prop, "Invert Layer", "Invert layer filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_layer_pass", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_LAYER_PASS); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7527,7 +7538,8 @@ static void rna_def_modifier_grease_pencil_material_filter(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "use_material_pass", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_USE_MATERIAL_PASS); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Material Pass", "Use material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7538,22 +7550,54 @@ static void rna_def_modifier_grease_pencil_material_filter(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_material", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_MATERIAL); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER); RNA_def_property_ui_text(prop, "Invert Material", "Invert material filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_material_pass", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Material Pass", "Invert material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); RNA_define_lib_overridable(false); } +static void rna_def_modifier_grease_pencil_vertex_group(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "GreasePencilModifierVertexGroupData", nullptr); + RNA_def_struct_ui_text(srna, + "Grease Pencil Modifier Vertex Group", + "Vertex group settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierVertexGroupData"); + + RNA_define_lib_overridable(true); + + prop = RNA_def_property(srna, "vertex_group_name", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, nullptr, "vertex_group_name"); + RNA_def_property_ui_text(prop, "Name", "Vertex group name for modulating the deform"); + RNA_def_property_string_funcs( + prop, nullptr, nullptr, "rna_GreasePencilModifierVertexGroupData_name_set"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_vertex_group", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); + RNA_def_property_ui_text(prop, "Invert Vertex Group", "Invert vertex group weights"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + RNA_define_lib_overridable(false); +} + /** Utility function to register common influence properties for grease pencil modifiers. */ static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, const char *layer_filter_sdna, - const char *material_filter_sdna) + const char *material_filter_sdna, + const char *vertex_group_sdna) { PropertyRNA *prop; @@ -7569,6 +7613,12 @@ static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, RNA_def_property_struct_type(prop, "GreasePencilModifierMaterialFilter"); RNA_def_property_ui_text(prop, "Material Filter", "Material filter settings"); } + if (vertex_group_sdna) { + prop = RNA_def_property(srna, "vertex_group", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, vertex_group_sdna); + RNA_def_property_struct_type(prop, "GreasePencilModifierVertexGroupData"); + RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group settings"); + } } static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) @@ -7582,7 +7632,7 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY); rna_def_modifier_grease_pencil_influence_properties( - srna, "influence.layer_filter", "influence.material_filter"); + srna, "influence.layer_filter", "influence.material_filter", "influence.vertex_group"); prop = RNA_def_property(srna, "open_influence_panel", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( @@ -7761,6 +7811,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_grease_pencil_opacity(brna); rna_def_modifier_grease_pencil_layer_filter(brna); rna_def_modifier_grease_pencil_material_filter(brna); + rna_def_modifier_grease_pencil_vertex_group(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index e24ebacacef..8610917973b 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -151,8 +151,10 @@ static void panel_draw(const bContext *C, Panel *panel) { PointerRNA layer_filter_ptr = RNA_pointer_get(ptr, "layer_filter"); PointerRNA material_filter_ptr = RNA_pointer_get(ptr, "material_filter"); + PointerRNA vertex_group_ptr = RNA_pointer_get(ptr, "vertex_group"); greasepencil::draw_layer_filter_settings(C, influence_panel, &layer_filter_ptr); greasepencil::draw_material_filter_settings(C, influence_panel, &material_filter_ptr); + greasepencil::draw_vertex_group_settings(C, influence_panel, &vertex_group_ptr); } uiLayoutSetPropSep(layout, true); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 2a27b01e341..f099d26dd93 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -109,6 +109,22 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi uiItemR(sub, ptr, "invert_material_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } +void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +{ + PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); + bool has_vertex_group = RNA_string_length(ptr, "name") != 0; + uiLayout *row, *sub; + + uiLayoutSetPropSep(layout, true); + + row = uiLayoutRow(layout, true); + uiItemPointerR(row, ptr, "vertex_group_name", &ob_ptr, "vertex_groups", nullptr, ICON_NONE); + sub = uiLayoutRow(row, true); + uiLayoutSetActive(sub, has_vertex_group); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, ptr, "invert_vertex_group", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); +} + /** * Get a list of pass IDs used by grease pencil materials. * This way the material pass can be looked up by index instead of having to get the material for @@ -173,11 +189,11 @@ IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, filter.layer_name[0] != '\0' ? std::make_optional(filter.layer_name) : std::nullopt, - (filter.flag & GREASE_PENCIL_FILTER_USE_LAYER_PASS) ? + (filter.flag & GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER) ? std::make_optional(filter.layer_pass) : std::nullopt, - filter.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, - filter.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, + filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER, + filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER, memory); } @@ -229,15 +245,16 @@ IndexMask get_filtered_stroke_mask(const Object *ob, IndexMaskMemory &memory) { /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ - return get_filtered_stroke_mask(ob, - curves, - filter.material, - (filter.flag & GREASE_PENCIL_FILTER_USE_MATERIAL_PASS) ? - std::make_optional(filter.material_pass) : - std::nullopt, - filter.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, - filter.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS, - memory); + return get_filtered_stroke_mask( + ob, + curves, + filter.material, + (filter.flag & GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER) ? + std::make_optional(filter.material_pass) : + std::nullopt, + filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER, + filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER, + memory); } Vector get_drawings_for_write(GreasePencil &grease_pencil, diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index f0cd122a449..19584e01876 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -43,6 +43,7 @@ void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data void draw_layer_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); void draw_material_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierLayerFilter &filter, -- 2.30.2 From 1e94f8519ae061c9b0ffba2719de9531fe01f4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 17:08:05 +0100 Subject: [PATCH 14/45] Added custom curve settings to generic modifier influence data. --- source/blender/makesdna/DNA_modifier_types.h | 10 +++++ .../blender/makesrna/intern/rna_modifier.cc | 40 +++++++++++++++++-- .../intern/MOD_grease_pencil_opacity.cc | 20 ++++++---- .../intern/MOD_grease_pencil_util.cc | 34 ++++++++++++++-- .../intern/MOD_grease_pencil_util.hh | 5 ++- 5 files changed, 93 insertions(+), 16 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index d5d57fed289..21c13ca50b2 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2512,6 +2512,14 @@ typedef struct GreasePencilModifierVertexGroupData { char _pad[4]; } GreasePencilModifierVertexGroupData; +typedef struct GreasePencilModifierCustomCurveData { + struct CurveMapping *curve; + /** GreasePencilModifierFilterFlag */ + int flag; + char _pad1[4]; + void *_pad2; +} GreasePencilModifierCustomCurveData; + typedef enum GreasePencilModifierInfluenceFlag { GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER = (1 << 0), GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER = (1 << 1), @@ -2520,6 +2528,7 @@ typedef enum GreasePencilModifierInfluenceFlag { GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER = (1 << 4), GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER = (1 << 5), GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP = (1 << 6), + GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE = (1 << 7), } GreasePencilModifierInfluenceFlag; /** @@ -2530,6 +2539,7 @@ typedef struct GreasePencilModifierInfluenceData { GreasePencilModifierLayerFilter layer_filter; GreasePencilModifierMaterialFilter material_filter; GreasePencilModifierVertexGroupData vertex_group; + GreasePencilModifierCustomCurveData custom_curve; } GreasePencilModifierInfluenceData; typedef struct GreasePencilOpacityModifierData { diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 1bf171712f0..04aba1f61d8 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -7593,11 +7593,35 @@ static void rna_def_modifier_grease_pencil_vertex_group(BlenderRNA *brna) RNA_define_lib_overridable(false); } +static void rna_def_modifier_grease_pencil_custom_curve(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "GreasePencilModifierCustomCurveData", nullptr); + RNA_def_struct_ui_text(srna, + "Grease Pencil Modifier Custom Curve", + "Custom curve settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierCustomCurveData"); + + prop = RNA_def_property(srna, "use_custom_curve", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); + RNA_def_property_ui_text( + prop, "Use Custom Curve", "Use a custom curve to define a factor along the strokes"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, "curve"); + RNA_def_property_ui_text(prop, "Curve", "Custom curve to apply effect"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); +} + /** Utility function to register common influence properties for grease pencil modifiers. */ static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, const char *layer_filter_sdna, const char *material_filter_sdna, - const char *vertex_group_sdna) + const char *vertex_group_sdna, + const char *custom_curve_sdna) { PropertyRNA *prop; @@ -7619,6 +7643,12 @@ static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, RNA_def_property_struct_type(prop, "GreasePencilModifierVertexGroupData"); RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group settings"); } + if (custom_curve_sdna) { + prop = RNA_def_property(srna, "custom_curve", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, custom_curve_sdna); + RNA_def_property_struct_type(prop, "GreasePencilModifierCustomCurveData"); + RNA_def_property_ui_text(prop, "Custom Curve", "Custom curve settings"); + } } static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) @@ -7631,8 +7661,11 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) RNA_def_struct_sdna(srna, "GreasePencilOpacityModifierData"); RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY); - rna_def_modifier_grease_pencil_influence_properties( - srna, "influence.layer_filter", "influence.material_filter", "influence.vertex_group"); + rna_def_modifier_grease_pencil_influence_properties(srna, + "influence.layer_filter", + "influence.material_filter", + "influence.vertex_group", + "influence.custom_curve"); prop = RNA_def_property(srna, "open_influence_panel", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( @@ -7812,6 +7845,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_grease_pencil_layer_filter(brna); rna_def_modifier_grease_pencil_material_filter(brna); rna_def_modifier_grease_pencil_vertex_group(brna); + rna_def_modifier_grease_pencil_custom_curve(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 8610917973b..1b388646a45 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -59,7 +59,7 @@ static void init_data(ModifierData *md) sizeof(*(omd)) - OFFSETOF_STRUCT_AFTER(omd, modifier)); } - greasepencil::init_influence_data(&omd->influence); + greasepencil::init_influence_data(&omd->influence, true); } static void copy_data(const ModifierData *md, ModifierData *target, const int flag) @@ -67,10 +67,19 @@ static void copy_data(const ModifierData *md, ModifierData *target, const int fl const GreasePencilOpacityModifierData *omd = (const GreasePencilOpacityModifierData *)md; GreasePencilOpacityModifierData *tomd = (GreasePencilOpacityModifierData *)target; + greasepencil::free_influence_data(&tomd->influence); + BKE_modifier_copydata_generic(md, target, flag); greasepencil::copy_influence_data(&omd->influence, &tomd->influence, flag); } +static void free_data(ModifierData *md) +{ + GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + + greasepencil::free_influence_data(&omd->influence); +} + static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; @@ -85,13 +94,6 @@ static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data); } -static void free_data(ModifierData *md) -{ - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - - greasepencil::free_influence_data(&omd->influence); -} - static void modify_curves(ModifierData *md, const ModifierEvalContext *ctx, bke::CurvesGeometry &curves) @@ -152,9 +154,11 @@ static void panel_draw(const bContext *C, Panel *panel) PointerRNA layer_filter_ptr = RNA_pointer_get(ptr, "layer_filter"); PointerRNA material_filter_ptr = RNA_pointer_get(ptr, "material_filter"); PointerRNA vertex_group_ptr = RNA_pointer_get(ptr, "vertex_group"); + PointerRNA custom_curve_ptr = RNA_pointer_get(ptr, "custom_curve"); greasepencil::draw_layer_filter_settings(C, influence_panel, &layer_filter_ptr); greasepencil::draw_material_filter_settings(C, influence_panel, &material_filter_ptr); greasepencil::draw_vertex_group_settings(C, influence_panel, &vertex_group_ptr); + greasepencil::draw_custom_curve_settings(C, influence_panel, &custom_curve_ptr); } uiLayoutSetPropSep(layout, true); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index f099d26dd93..dc4b4be5888 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -15,6 +15,7 @@ #include "DNA_modifier_types.h" #include "DNA_screen_types.h" +#include "BKE_colortools.hh" #include "BKE_curves.hh" #include "BKE_grease_pencil.hh" #include "BKE_lib_query.h" @@ -36,16 +37,31 @@ namespace blender::greasepencil { using bke::greasepencil::Drawing; using bke::greasepencil::Layer; -void init_influence_data(GreasePencilModifierInfluenceData * /*influence_data*/) {} +void init_influence_data(GreasePencilModifierInfluenceData *influence_data, + const bool has_custom_curve) +{ + if (has_custom_curve) { + influence_data->custom_curve.curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + BKE_curvemapping_init(influence_data->custom_curve.curve); + } +} void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, GreasePencilModifierInfluenceData *influence_data_dst, const int /*flag*/) { memcpy(influence_data_dst, influence_data_src, sizeof(GreasePencilModifierInfluenceData)); + influence_data_dst->custom_curve.curve = BKE_curvemapping_copy( + influence_data_src->custom_curve.curve); } -void free_influence_data(GreasePencilModifierInfluenceData * /*influence_data*/) {} +void free_influence_data(GreasePencilModifierInfluenceData *influence_data) +{ + if (influence_data->custom_curve.curve) { + BKE_curvemapping_free(influence_data->custom_curve.curve); + influence_data->custom_curve.curve = nullptr; + } +} void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data, Object *ob, @@ -112,7 +128,7 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); - bool has_vertex_group = RNA_string_length(ptr, "name") != 0; + bool has_vertex_group = RNA_string_length(ptr, "vertex_group_name") != 0; uiLayout *row, *sub; uiLayoutSetPropSep(layout, true); @@ -125,6 +141,18 @@ void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, Pointe uiItemR(sub, ptr, "invert_vertex_group", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } +void draw_custom_curve_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +{ + bool use_custom_curve = RNA_boolean_get(ptr, "use_custom_curve"); + + uiLayoutSetPropSep(layout, true); + + uiItemR(layout, ptr, "use_custom_curve", UI_ITEM_NONE, nullptr, ICON_NONE); + if (use_custom_curve) { + uiTemplateCurveMapping(layout, ptr, "curve", 0, false, false, false, false); + } +} + /** * Get a list of pass IDs used by grease pencil materials. * This way the material pass can be looked up by index instead of having to get the material for diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index 19584e01876..d2688134a36 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -31,7 +31,7 @@ class Drawing; namespace blender::greasepencil { -void init_influence_data(GreasePencilModifierInfluenceData *influence_data); +void init_influence_data(GreasePencilModifierInfluenceData *influence_data, bool has_custom_curve); void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, GreasePencilModifierInfluenceData *influence_data_dst, int flag); @@ -43,7 +43,8 @@ void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data void draw_layer_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); void draw_material_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); -void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr); +void draw_vertex_group_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_custom_curve_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierLayerFilter &filter, -- 2.30.2 From 057fa04e3eeca620435d35cd7df650a5cef9c450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 18:16:55 +0100 Subject: [PATCH 15/45] Flattened RNA definition to add filter properties directly to modifiers. --- .../blender/makesrna/intern/rna_modifier.cc | 202 +++++++----------- .../intern/MOD_grease_pencil_opacity.cc | 12 +- .../intern/MOD_grease_pencil_util.cc | 28 +-- 3 files changed, 96 insertions(+), 146 deletions(-) diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 04aba1f61d8..8706a754595 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -1713,7 +1713,7 @@ static IDProperty **rna_NodesModifier_properties(PointerRNA *ptr) return &settings->properties; } -bool rna_GreasePencilModifierMaterialFilter_material_poll(PointerRNA *ptr, PointerRNA value) +bool rna_GreasePencilModifier_material_poll(PointerRNA *ptr, PointerRNA value) { Object *ob = reinterpret_cast(ptr->owner_id); Material *ma = reinterpret_cast(value.owner_id); @@ -1721,18 +1721,18 @@ bool rna_GreasePencilModifierMaterialFilter_material_poll(PointerRNA *ptr, Point return BKE_grease_pencil_object_material_index_get(ob, ma) != -1; } -static void rna_GreasePencilModifierMaterialFilter_material_set(PointerRNA *ptr, - PointerRNA value, - ReportList *reports) +/* Write material to a generic target pointer without the final modifier struct. */ +static void rna_GreasePencilModifier_material_set(PointerRNA *ptr, + PointerRNA value, + ReportList *reports, + Material **ma_target) { Object *ob = reinterpret_cast(ptr->owner_id); - GreasePencilModifierMaterialFilter *filter = static_cast( - ptr->data); Material *ma = reinterpret_cast(value.owner_id); if (ma == nullptr || BKE_grease_pencil_object_material_index_get(ob, ma) != -1) { id_lib_extern(reinterpret_cast(ob)); - filter->material = ma; + *ma_target = ma; } else { BKE_reportf( @@ -1743,13 +1743,27 @@ static void rna_GreasePencilModifierMaterialFilter_material_set(PointerRNA *ptr, } } -static void rna_GreasePencilModifierVertexGroupData_name_set(PointerRNA *ptr, const char *value) -{ - GreasePencilModifierVertexGroupData *vgroup_data = - static_cast(ptr->data); - rna_object_vgroup_name_set( - ptr, value, vgroup_data->vertex_group_name, sizeof(vgroup_data->vertex_group_name)); -} +# define RNA_MOD_GREASE_PENCIL_MATERIAL_FILTER_SET(_type) \ + static void rna_##_type##Modifier_material_filter_set( \ + PointerRNA *ptr, PointerRNA value, ReportList *reports) \ + { \ + _type##ModifierData *tmd = static_cast<_type##ModifierData *>(ptr->data); \ + rna_GreasePencilModifier_material_set( \ + ptr, value, reports, &tmd->influence.material_filter.material); \ + } + +# define RNA_MOD_GREASE_PENCIL_VERTEX_GROUP_SET(_type) \ + static void rna_##_type##Modifier_vertex_group_name_set(PointerRNA *ptr, const char *value) \ + { \ + _type##ModifierData *tmd = static_cast<_type##ModifierData *>(ptr->data); \ + rna_object_vgroup_name_set(ptr, \ + value, \ + tmd->influence.vertex_group.vertex_group_name, \ + sizeof(tmd->influence.vertex_group.vertex_group_name)); \ + } + +RNA_MOD_GREASE_PENCIL_MATERIAL_FILTER_SET(GreasePencilOpacity); +RNA_MOD_GREASE_PENCIL_VERTEX_GROUP_SET(GreasePencilOpacity); #else @@ -7469,186 +7483,127 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna) RNA_define_lib_overridable(false); } -static void rna_def_modifier_grease_pencil_layer_filter(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_layer_filter(StructRNA *srna) { - StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierLayerFilter", nullptr); - RNA_def_struct_ui_text(srna, - "Grease Pencil Modifier Layer Filter", - "Layer filter settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierLayerFilter"); +# define PROPNAME_PREFIX "influence.layer_filter." - RNA_define_lib_overridable(true); - - prop = RNA_def_property(srna, "layer", PROP_STRING, PROP_NONE); - RNA_def_property_string_sdna(prop, nullptr, "layer_name"); + prop = RNA_def_property(srna, "layer_filter", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, nullptr, PROPNAME_PREFIX "layer_name"); RNA_def_property_ui_text(prop, "Layer", "Layer name"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "use_layer_pass", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "use_layer_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Layer Pass", "Use layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "layer_pass", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, nullptr, "layer_pass"); + prop = RNA_def_property(srna, "layer_pass_filter", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, nullptr, PROPNAME_PREFIX "layer_pass"); RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Layer Pass", "Layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "invert_layer", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "invert_layer_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER); RNA_def_property_ui_text(prop, "Invert Layer", "Invert layer filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "invert_layer_pass", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "invert_layer_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - RNA_define_lib_overridable(false); +# undef PROPNAME_PREFIX } -static void rna_def_modifier_grease_pencil_material_filter(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_material_filter(StructRNA *srna, + const char *material_set_fn) { - StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierMaterialFilter", nullptr); - RNA_def_struct_ui_text(srna, - "Grease Pencil Modifier Material Filter", - "Material filter settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierMaterialFilter"); +# define PROPNAME_PREFIX "influence.material_filter." - RNA_define_lib_overridable(true); - - prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE); + prop = RNA_def_property(srna, "material_filter", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, PROPNAME_PREFIX "material"); RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_pointer_funcs(prop, - nullptr, - "rna_GreasePencilModifierMaterialFilter_material_set", - nullptr, - "rna_GreasePencilModifierMaterialFilter_material_poll"); + RNA_def_property_pointer_funcs( + prop, nullptr, material_set_fn, nullptr, "rna_GreasePencilModifier_material_poll"); RNA_def_property_ui_text(prop, "Material", "Material used for filtering"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "use_material_pass", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "use_material_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Material Pass", "Use material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "material_pass", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, nullptr, "material_pass"); + prop = RNA_def_property(srna, "material_pass_filter", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, nullptr, PROPNAME_PREFIX "material_pass"); RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Material Pass", "Material pass"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "invert_material", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "invert_material_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER); RNA_def_property_ui_text(prop, "Invert Material", "Invert material filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "invert_material_pass", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "invert_material_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Material Pass", "Invert material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - RNA_define_lib_overridable(false); +# undef PROPNAME_PREFIX } -static void rna_def_modifier_grease_pencil_vertex_group(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_vertex_group(StructRNA *srna, + const char *vertex_group_name_set_fn) { - StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierVertexGroupData", nullptr); - RNA_def_struct_ui_text(srna, - "Grease Pencil Modifier Vertex Group", - "Vertex group settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierVertexGroupData"); - - RNA_define_lib_overridable(true); +# define PROPNAME_PREFIX "influence.vertex_group." prop = RNA_def_property(srna, "vertex_group_name", PROP_STRING, PROP_NONE); - RNA_def_property_string_sdna(prop, nullptr, "vertex_group_name"); + RNA_def_property_string_sdna(prop, nullptr, PROPNAME_PREFIX "vertex_group_name"); RNA_def_property_ui_text(prop, "Name", "Vertex group name for modulating the deform"); - RNA_def_property_string_funcs( - prop, nullptr, nullptr, "rna_GreasePencilModifierVertexGroupData_name_set"); + RNA_def_property_string_funcs(prop, nullptr, nullptr, vertex_group_name_set_fn); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_vertex_group", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); RNA_def_property_ui_text(prop, "Invert Vertex Group", "Invert vertex group weights"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - RNA_define_lib_overridable(false); +# undef PROPNAME_PREFIX } -static void rna_def_modifier_grease_pencil_custom_curve(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_custom_curve(StructRNA *srna) { - StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierCustomCurveData", nullptr); - RNA_def_struct_ui_text(srna, - "Grease Pencil Modifier Custom Curve", - "Custom curve settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierCustomCurveData"); +# define PROPNAME_PREFIX "influence.custom_curve." prop = RNA_def_property(srna, "use_custom_curve", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); + RNA_def_property_boolean_sdna( + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); RNA_def_property_ui_text( prop, "Use Custom Curve", "Use a custom curve to define a factor along the strokes"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, "curve"); + prop = RNA_def_property(srna, "custom_curve", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, PROPNAME_PREFIX "curve"); RNA_def_property_ui_text(prop, "Curve", "Custom curve to apply effect"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); -} -/** Utility function to register common influence properties for grease pencil modifiers. */ -static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, - const char *layer_filter_sdna, - const char *material_filter_sdna, - const char *vertex_group_sdna, - const char *custom_curve_sdna) -{ - PropertyRNA *prop; - - if (layer_filter_sdna) { - prop = RNA_def_property(srna, "layer_filter", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, layer_filter_sdna); - RNA_def_property_struct_type(prop, "GreasePencilModifierLayerFilter"); - RNA_def_property_ui_text(prop, "Layer Filter", "Layer filter settings"); - } - if (material_filter_sdna) { - prop = RNA_def_property(srna, "material_filter", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, material_filter_sdna); - RNA_def_property_struct_type(prop, "GreasePencilModifierMaterialFilter"); - RNA_def_property_ui_text(prop, "Material Filter", "Material filter settings"); - } - if (vertex_group_sdna) { - prop = RNA_def_property(srna, "vertex_group", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, vertex_group_sdna); - RNA_def_property_struct_type(prop, "GreasePencilModifierVertexGroupData"); - RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group settings"); - } - if (custom_curve_sdna) { - prop = RNA_def_property(srna, "custom_curve", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, custom_curve_sdna); - RNA_def_property_struct_type(prop, "GreasePencilModifierCustomCurveData"); - RNA_def_property_ui_text(prop, "Custom Curve", "Custom curve settings"); - } +# undef PROPNAME_PREFIX } static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) @@ -7661,11 +7616,12 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) RNA_def_struct_sdna(srna, "GreasePencilOpacityModifierData"); RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY); - rna_def_modifier_grease_pencil_influence_properties(srna, - "influence.layer_filter", - "influence.material_filter", - "influence.vertex_group", - "influence.custom_curve"); + rna_def_modifier_grease_pencil_layer_filter(srna); + rna_def_modifier_grease_pencil_material_filter( + srna, "rna_GreasePencilOpacityModifier_material_filter_set"); + rna_def_modifier_grease_pencil_vertex_group( + srna, "rna_GreasePencilOpacityModifier_vertex_group_name_set"); + rna_def_modifier_grease_pencil_custom_curve(srna); prop = RNA_def_property(srna, "open_influence_panel", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( @@ -7842,10 +7798,6 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_volume_displace(brna); rna_def_modifier_volume_to_mesh(brna); rna_def_modifier_grease_pencil_opacity(brna); - rna_def_modifier_grease_pencil_layer_filter(brna); - rna_def_modifier_grease_pencil_material_filter(brna); - rna_def_modifier_grease_pencil_vertex_group(brna); - rna_def_modifier_grease_pencil_custom_curve(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 1b388646a45..b7d58267120 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -151,14 +151,10 @@ static void panel_draw(const bContext *C, Panel *panel) if (uiLayout *influence_panel = uiLayoutPanel( C, layout, "Influence", ptr, "open_influence_panel")) { - PointerRNA layer_filter_ptr = RNA_pointer_get(ptr, "layer_filter"); - PointerRNA material_filter_ptr = RNA_pointer_get(ptr, "material_filter"); - PointerRNA vertex_group_ptr = RNA_pointer_get(ptr, "vertex_group"); - PointerRNA custom_curve_ptr = RNA_pointer_get(ptr, "custom_curve"); - greasepencil::draw_layer_filter_settings(C, influence_panel, &layer_filter_ptr); - greasepencil::draw_material_filter_settings(C, influence_panel, &material_filter_ptr); - greasepencil::draw_vertex_group_settings(C, influence_panel, &vertex_group_ptr); - greasepencil::draw_custom_curve_settings(C, influence_panel, &custom_curve_ptr); + greasepencil::draw_layer_filter_settings(C, influence_panel, ptr); + greasepencil::draw_material_filter_settings(C, influence_panel, ptr); + greasepencil::draw_vertex_group_settings(C, influence_panel, ptr); + greasepencil::draw_custom_curve_settings(C, influence_panel, ptr); } uiLayoutSetPropSep(layout, true); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index dc4b4be5888..23d13ef30d7 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -75,54 +75,56 @@ void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, Pointe { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); - const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass"); + const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass_filter"); uiLayout *row, *col, *sub; uiLayoutSetPropSep(layout, true); col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); - uiItemPointerR(row, ptr, "layer", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); + uiItemPointerR(row, ptr, "layer_filter", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_layer", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_layer_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); /* TODO Would be nice to have the checkbox in the same line as the pass button. */ row = uiLayoutRow(col, true); - uiItemR(row, ptr, "use_layer_pass", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); + uiItemR(row, ptr, "use_layer_pass_filter", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); row = uiLayoutRow(col, true); uiLayoutSetActive(row, use_layer_pass); - uiItemR(row, ptr, "layer_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + uiItemR(row, ptr, "layer_pass_filter", UI_ITEM_NONE, nullptr, ICON_NONE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_layer_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_layer_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); - const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass"); + const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass_filter"); uiLayout *row, *col, *sub; uiLayoutSetPropSep(layout, true); col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); - uiItemPointerR(row, ptr, "material", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); + uiItemPointerR( + row, ptr, "material_filter", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_material", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_material_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); /* TODO Would be nice to have the checkbox in the same line as the pass button. */ row = uiLayoutRow(col, true); - uiItemR(row, ptr, "use_material_pass", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); + uiItemR( + row, ptr, "use_material_pass_filter", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); row = uiLayoutRow(col, true); uiLayoutSetActive(row, use_material_pass); - uiItemR(row, ptr, "material_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + uiItemR(row, ptr, "material_pass_filter", UI_ITEM_NONE, nullptr, ICON_NONE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_material_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_material_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) @@ -149,7 +151,7 @@ void draw_custom_curve_settings(const bContext * /*C*/, uiLayout *layout, Pointe uiItemR(layout, ptr, "use_custom_curve", UI_ITEM_NONE, nullptr, ICON_NONE); if (use_custom_curve) { - uiTemplateCurveMapping(layout, ptr, "curve", 0, false, false, false, false); + uiTemplateCurveMapping(layout, ptr, "custom_curve", 0, false, false, false, false); } } -- 2.30.2 From cf5e9d8d38819a09608e78704a4b217debb84423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 15:11:32 +0100 Subject: [PATCH 16/45] Influence settings for vertex groups. --- source/blender/makesdna/DNA_modifier_types.h | 26 +++++--- .../blender/makesrna/intern/rna_modifier.cc | 65 +++++++++++++++++-- .../intern/MOD_grease_pencil_util.cc | 41 ++++++++---- .../intern/MOD_grease_pencil_util.hh | 1 + 4 files changed, 106 insertions(+), 27 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 4746c0909e9..ef830a4432c 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2503,14 +2503,23 @@ typedef struct GreasePencilModifierMaterialFilter { int flag; } GreasePencilModifierMaterialFilter; -typedef enum GreasePencilModifierFilterFlag { - GREASE_PENCIL_FILTER_INVERT_LAYER = (1 << 0), - GREASE_PENCIL_FILTER_USE_LAYER_PASS = (1 << 1), - GREASE_PENCIL_FILTER_INVERT_LAYER_PASS = (1 << 2), - GREASE_PENCIL_FILTER_INVERT_MATERIAL = (1 << 3), - GREASE_PENCIL_FILTER_USE_MATERIAL_PASS = (1 << 4), - GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS = (1 << 5), -} GreasePencilModifierFilterFlag; +typedef struct GreasePencilModifierVertexGroupData { + /** #MAX_VGROUP_NAME. */ + char vertex_group_name[64]; + /** GreasePencilModifierFilterFlag */ + int flag; + char _pad[4]; +} GreasePencilModifierVertexGroupData; + +typedef enum GreasePencilModifierInfluenceFlag { + GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER = (1 << 0), + GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER = (1 << 1), + GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER = (1 << 2), + GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER = (1 << 3), + GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER = (1 << 4), + GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER = (1 << 5), + GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP = (1 << 6), +} GreasePencilModifierInfluenceFlag; /** * Combined generic influence data for grease pencil modifiers. * Not all parts may be used by all modifier types. @@ -2518,4 +2527,5 @@ typedef enum GreasePencilModifierFilterFlag { typedef struct GreasePencilModifierInfluenceData { GreasePencilModifierLayerFilter layer_filter; GreasePencilModifierMaterialFilter material_filter; + GreasePencilModifierVertexGroupData vertex_group; } GreasePencilModifierInfluenceData; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index a2ec2a1358b..480b06b78d8 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -1738,6 +1738,14 @@ static void rna_GreasePencilModifierMaterialFilter_material_set(PointerRNA *ptr, } } +static void rna_GreasePencilModifierVertexGroupData_name_set(PointerRNA *ptr, const char *value) +{ + GreasePencilModifierVertexGroupData *vgroup_data = + static_cast(ptr->data); + rna_object_vgroup_name_set( + ptr, value, vgroup_data->vertex_group_name, sizeof(vgroup_data->vertex_group_name)); +} + #else static void rna_def_modifier_panel_open_prop(StructRNA *srna, const char *identifier, const int id) @@ -7475,7 +7483,8 @@ static void rna_def_modifier_grease_pencil_layer_filter(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "use_layer_pass", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_USE_LAYER_PASS); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Layer Pass", "Use layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7486,12 +7495,14 @@ static void rna_def_modifier_grease_pencil_layer_filter(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_layer", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_LAYER); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER); RNA_def_property_ui_text(prop, "Invert Layer", "Invert layer filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_layer_pass", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_LAYER_PASS); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7522,7 +7533,8 @@ static void rna_def_modifier_grease_pencil_material_filter(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "use_material_pass", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_USE_MATERIAL_PASS); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Material Pass", "Use material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7533,22 +7545,54 @@ static void rna_def_modifier_grease_pencil_material_filter(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_material", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_MATERIAL); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER); RNA_def_property_ui_text(prop, "Invert Material", "Invert material filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_material_pass", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Material Pass", "Invert material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); RNA_define_lib_overridable(false); } +static void rna_def_modifier_grease_pencil_vertex_group(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "GreasePencilModifierVertexGroupData", nullptr); + RNA_def_struct_ui_text(srna, + "Grease Pencil Modifier Vertex Group", + "Vertex group settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierVertexGroupData"); + + RNA_define_lib_overridable(true); + + prop = RNA_def_property(srna, "vertex_group_name", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, nullptr, "vertex_group_name"); + RNA_def_property_ui_text(prop, "Name", "Vertex group name for modulating the deform"); + RNA_def_property_string_funcs( + prop, nullptr, nullptr, "rna_GreasePencilModifierVertexGroupData_name_set"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_vertex_group", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); + RNA_def_property_ui_text(prop, "Invert Vertex Group", "Invert vertex group weights"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + RNA_define_lib_overridable(false); +} + /** Utility function to register common influence properties for grease pencil modifiers. */ static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, const char *layer_filter_sdna, - const char *material_filter_sdna) + const char *material_filter_sdna, + const char *vertex_group_sdna) { PropertyRNA *prop; @@ -7564,6 +7608,12 @@ static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, RNA_def_property_struct_type(prop, "GreasePencilModifierMaterialFilter"); RNA_def_property_ui_text(prop, "Material Filter", "Material filter settings"); } + if (vertex_group_sdna) { + prop = RNA_def_property(srna, "vertex_group", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, vertex_group_sdna); + RNA_def_property_struct_type(prop, "GreasePencilModifierVertexGroupData"); + RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group settings"); + } } void RNA_def_modifier(BlenderRNA *brna) @@ -7728,6 +7778,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_volume_to_mesh(brna); rna_def_modifier_grease_pencil_layer_filter(brna); rna_def_modifier_grease_pencil_material_filter(brna); + rna_def_modifier_grease_pencil_vertex_group(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 2a27b01e341..f099d26dd93 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -109,6 +109,22 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi uiItemR(sub, ptr, "invert_material_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } +void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +{ + PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); + bool has_vertex_group = RNA_string_length(ptr, "name") != 0; + uiLayout *row, *sub; + + uiLayoutSetPropSep(layout, true); + + row = uiLayoutRow(layout, true); + uiItemPointerR(row, ptr, "vertex_group_name", &ob_ptr, "vertex_groups", nullptr, ICON_NONE); + sub = uiLayoutRow(row, true); + uiLayoutSetActive(sub, has_vertex_group); + uiLayoutSetPropDecorate(sub, false); + uiItemR(sub, ptr, "invert_vertex_group", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); +} + /** * Get a list of pass IDs used by grease pencil materials. * This way the material pass can be looked up by index instead of having to get the material for @@ -173,11 +189,11 @@ IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, filter.layer_name[0] != '\0' ? std::make_optional(filter.layer_name) : std::nullopt, - (filter.flag & GREASE_PENCIL_FILTER_USE_LAYER_PASS) ? + (filter.flag & GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER) ? std::make_optional(filter.layer_pass) : std::nullopt, - filter.flag & GREASE_PENCIL_FILTER_INVERT_LAYER, - filter.flag & GREASE_PENCIL_FILTER_INVERT_LAYER_PASS, + filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER, + filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER, memory); } @@ -229,15 +245,16 @@ IndexMask get_filtered_stroke_mask(const Object *ob, IndexMaskMemory &memory) { /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ - return get_filtered_stroke_mask(ob, - curves, - filter.material, - (filter.flag & GREASE_PENCIL_FILTER_USE_MATERIAL_PASS) ? - std::make_optional(filter.material_pass) : - std::nullopt, - filter.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL, - filter.flag & GREASE_PENCIL_FILTER_INVERT_MATERIAL_PASS, - memory); + return get_filtered_stroke_mask( + ob, + curves, + filter.material, + (filter.flag & GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER) ? + std::make_optional(filter.material_pass) : + std::nullopt, + filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER, + filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER, + memory); } Vector get_drawings_for_write(GreasePencil &grease_pencil, diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index f0cd122a449..19584e01876 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -43,6 +43,7 @@ void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data void draw_layer_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); void draw_material_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierLayerFilter &filter, -- 2.30.2 From c7a3f9aecb5eec2fae21ff2936e396cacbeaa534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 17:08:05 +0100 Subject: [PATCH 17/45] Added custom curve settings to generic modifier influence data. --- source/blender/makesdna/DNA_modifier_types.h | 10 ++++++ .../blender/makesrna/intern/rna_modifier.cc | 33 +++++++++++++++++- .../intern/MOD_grease_pencil_util.cc | 34 +++++++++++++++++-- .../intern/MOD_grease_pencil_util.hh | 5 +-- 4 files changed, 76 insertions(+), 6 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index ef830a4432c..d0b9add9f30 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2511,6 +2511,14 @@ typedef struct GreasePencilModifierVertexGroupData { char _pad[4]; } GreasePencilModifierVertexGroupData; +typedef struct GreasePencilModifierCustomCurveData { + struct CurveMapping *curve; + /** GreasePencilModifierFilterFlag */ + int flag; + char _pad1[4]; + void *_pad2; +} GreasePencilModifierCustomCurveData; + typedef enum GreasePencilModifierInfluenceFlag { GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER = (1 << 0), GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER = (1 << 1), @@ -2519,6 +2527,7 @@ typedef enum GreasePencilModifierInfluenceFlag { GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER = (1 << 4), GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER = (1 << 5), GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP = (1 << 6), + GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE = (1 << 7), } GreasePencilModifierInfluenceFlag; /** * Combined generic influence data for grease pencil modifiers. @@ -2528,4 +2537,5 @@ typedef struct GreasePencilModifierInfluenceData { GreasePencilModifierLayerFilter layer_filter; GreasePencilModifierMaterialFilter material_filter; GreasePencilModifierVertexGroupData vertex_group; + GreasePencilModifierCustomCurveData custom_curve; } GreasePencilModifierInfluenceData; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 480b06b78d8..af5bce82cb6 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -7588,11 +7588,35 @@ static void rna_def_modifier_grease_pencil_vertex_group(BlenderRNA *brna) RNA_define_lib_overridable(false); } +static void rna_def_modifier_grease_pencil_custom_curve(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "GreasePencilModifierCustomCurveData", nullptr); + RNA_def_struct_ui_text(srna, + "Grease Pencil Modifier Custom Curve", + "Custom curve settings for grease pencil modifiers"); + RNA_def_struct_sdna(srna, "GreasePencilModifierCustomCurveData"); + + prop = RNA_def_property(srna, "use_custom_curve", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); + RNA_def_property_ui_text( + prop, "Use Custom Curve", "Use a custom curve to define a factor along the strokes"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, "curve"); + RNA_def_property_ui_text(prop, "Curve", "Custom curve to apply effect"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); +} + /** Utility function to register common influence properties for grease pencil modifiers. */ static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, const char *layer_filter_sdna, const char *material_filter_sdna, - const char *vertex_group_sdna) + const char *vertex_group_sdna, + const char *custom_curve_sdna) { PropertyRNA *prop; @@ -7614,6 +7638,12 @@ static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, RNA_def_property_struct_type(prop, "GreasePencilModifierVertexGroupData"); RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group settings"); } + if (custom_curve_sdna) { + prop = RNA_def_property(srna, "custom_curve", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, custom_curve_sdna); + RNA_def_property_struct_type(prop, "GreasePencilModifierCustomCurveData"); + RNA_def_property_ui_text(prop, "Custom Curve", "Custom curve settings"); + } } void RNA_def_modifier(BlenderRNA *brna) @@ -7779,6 +7809,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_grease_pencil_layer_filter(brna); rna_def_modifier_grease_pencil_material_filter(brna); rna_def_modifier_grease_pencil_vertex_group(brna); + rna_def_modifier_grease_pencil_custom_curve(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index f099d26dd93..dc4b4be5888 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -15,6 +15,7 @@ #include "DNA_modifier_types.h" #include "DNA_screen_types.h" +#include "BKE_colortools.hh" #include "BKE_curves.hh" #include "BKE_grease_pencil.hh" #include "BKE_lib_query.h" @@ -36,16 +37,31 @@ namespace blender::greasepencil { using bke::greasepencil::Drawing; using bke::greasepencil::Layer; -void init_influence_data(GreasePencilModifierInfluenceData * /*influence_data*/) {} +void init_influence_data(GreasePencilModifierInfluenceData *influence_data, + const bool has_custom_curve) +{ + if (has_custom_curve) { + influence_data->custom_curve.curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + BKE_curvemapping_init(influence_data->custom_curve.curve); + } +} void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, GreasePencilModifierInfluenceData *influence_data_dst, const int /*flag*/) { memcpy(influence_data_dst, influence_data_src, sizeof(GreasePencilModifierInfluenceData)); + influence_data_dst->custom_curve.curve = BKE_curvemapping_copy( + influence_data_src->custom_curve.curve); } -void free_influence_data(GreasePencilModifierInfluenceData * /*influence_data*/) {} +void free_influence_data(GreasePencilModifierInfluenceData *influence_data) +{ + if (influence_data->custom_curve.curve) { + BKE_curvemapping_free(influence_data->custom_curve.curve); + influence_data->custom_curve.curve = nullptr; + } +} void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data, Object *ob, @@ -112,7 +128,7 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); - bool has_vertex_group = RNA_string_length(ptr, "name") != 0; + bool has_vertex_group = RNA_string_length(ptr, "vertex_group_name") != 0; uiLayout *row, *sub; uiLayoutSetPropSep(layout, true); @@ -125,6 +141,18 @@ void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, Pointe uiItemR(sub, ptr, "invert_vertex_group", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } +void draw_custom_curve_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) +{ + bool use_custom_curve = RNA_boolean_get(ptr, "use_custom_curve"); + + uiLayoutSetPropSep(layout, true); + + uiItemR(layout, ptr, "use_custom_curve", UI_ITEM_NONE, nullptr, ICON_NONE); + if (use_custom_curve) { + uiTemplateCurveMapping(layout, ptr, "curve", 0, false, false, false, false); + } +} + /** * Get a list of pass IDs used by grease pencil materials. * This way the material pass can be looked up by index instead of having to get the material for diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index 19584e01876..d2688134a36 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -31,7 +31,7 @@ class Drawing; namespace blender::greasepencil { -void init_influence_data(GreasePencilModifierInfluenceData *influence_data); +void init_influence_data(GreasePencilModifierInfluenceData *influence_data, bool has_custom_curve); void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, GreasePencilModifierInfluenceData *influence_data_dst, int flag); @@ -43,7 +43,8 @@ void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data void draw_layer_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); void draw_material_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); -void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr); +void draw_vertex_group_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); +void draw_custom_curve_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierLayerFilter &filter, -- 2.30.2 From 6ff68593cbc7e9b39d968065061bb52b9401d900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Thu, 11 Jan 2024 18:16:55 +0100 Subject: [PATCH 18/45] Flattened RNA definition to add filter properties directly to modifiers. --- .../blender/makesrna/intern/rna_modifier.cc | 188 +++++++----------- .../intern/MOD_grease_pencil_util.cc | 28 +-- 2 files changed, 83 insertions(+), 133 deletions(-) diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index af5bce82cb6..bfe424e4afb 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -1708,7 +1708,7 @@ static IDProperty **rna_NodesModifier_properties(PointerRNA *ptr) return &settings->properties; } -bool rna_GreasePencilModifierMaterialFilter_material_poll(PointerRNA *ptr, PointerRNA value) +bool rna_GreasePencilModifier_material_poll(PointerRNA *ptr, PointerRNA value) { Object *ob = reinterpret_cast(ptr->owner_id); Material *ma = reinterpret_cast(value.owner_id); @@ -1716,18 +1716,18 @@ bool rna_GreasePencilModifierMaterialFilter_material_poll(PointerRNA *ptr, Point return BKE_grease_pencil_object_material_index_get(ob, ma) != -1; } -static void rna_GreasePencilModifierMaterialFilter_material_set(PointerRNA *ptr, - PointerRNA value, - ReportList *reports) +/* Write material to a generic target pointer without the final modifier struct. */ +static void rna_GreasePencilModifier_material_set(PointerRNA *ptr, + PointerRNA value, + ReportList *reports, + Material **ma_target) { Object *ob = reinterpret_cast(ptr->owner_id); - GreasePencilModifierMaterialFilter *filter = static_cast( - ptr->data); Material *ma = reinterpret_cast(value.owner_id); if (ma == nullptr || BKE_grease_pencil_object_material_index_get(ob, ma) != -1) { id_lib_extern(reinterpret_cast(ob)); - filter->material = ma; + *ma_target = ma; } else { BKE_reportf( @@ -1738,13 +1738,24 @@ static void rna_GreasePencilModifierMaterialFilter_material_set(PointerRNA *ptr, } } -static void rna_GreasePencilModifierVertexGroupData_name_set(PointerRNA *ptr, const char *value) -{ - GreasePencilModifierVertexGroupData *vgroup_data = - static_cast(ptr->data); - rna_object_vgroup_name_set( - ptr, value, vgroup_data->vertex_group_name, sizeof(vgroup_data->vertex_group_name)); -} +# define RNA_MOD_GREASE_PENCIL_MATERIAL_FILTER_SET(_type) \ + static void rna_##_type##Modifier_material_filter_set( \ + PointerRNA *ptr, PointerRNA value, ReportList *reports) \ + { \ + _type##ModifierData *tmd = static_cast<_type##ModifierData *>(ptr->data); \ + rna_GreasePencilModifier_material_set( \ + ptr, value, reports, &tmd->influence.material_filter.material); \ + } + +# define RNA_MOD_GREASE_PENCIL_VERTEX_GROUP_SET(_type) \ + static void rna_##_type##Modifier_vertex_group_name_set(PointerRNA *ptr, const char *value) \ + { \ + _type##ModifierData *tmd = static_cast<_type##ModifierData *>(ptr->data); \ + rna_object_vgroup_name_set(ptr, \ + value, \ + tmd->influence.vertex_group.vertex_group_name, \ + sizeof(tmd->influence.vertex_group.vertex_group_name)); \ + } #else @@ -7464,186 +7475,127 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna) RNA_define_lib_overridable(false); } -static void rna_def_modifier_grease_pencil_layer_filter(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_layer_filter(StructRNA *srna) { - StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierLayerFilter", nullptr); - RNA_def_struct_ui_text(srna, - "Grease Pencil Modifier Layer Filter", - "Layer filter settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierLayerFilter"); +# define PROPNAME_PREFIX "influence.layer_filter." - RNA_define_lib_overridable(true); - - prop = RNA_def_property(srna, "layer", PROP_STRING, PROP_NONE); - RNA_def_property_string_sdna(prop, nullptr, "layer_name"); + prop = RNA_def_property(srna, "layer_filter", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, nullptr, PROPNAME_PREFIX "layer_name"); RNA_def_property_ui_text(prop, "Layer", "Layer name"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "use_layer_pass", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "use_layer_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Layer Pass", "Use layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "layer_pass", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, nullptr, "layer_pass"); + prop = RNA_def_property(srna, "layer_pass_filter", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, nullptr, PROPNAME_PREFIX "layer_pass"); RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Layer Pass", "Layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "invert_layer", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "invert_layer_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER); RNA_def_property_ui_text(prop, "Invert Layer", "Invert layer filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "invert_layer_pass", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "invert_layer_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - RNA_define_lib_overridable(false); +# undef PROPNAME_PREFIX } -static void rna_def_modifier_grease_pencil_material_filter(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_material_filter(StructRNA *srna, + const char *material_set_fn) { - StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierMaterialFilter", nullptr); - RNA_def_struct_ui_text(srna, - "Grease Pencil Modifier Material Filter", - "Material filter settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierMaterialFilter"); +# define PROPNAME_PREFIX "influence.material_filter." - RNA_define_lib_overridable(true); - - prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE); + prop = RNA_def_property(srna, "material_filter", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, PROPNAME_PREFIX "material"); RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_pointer_funcs(prop, - nullptr, - "rna_GreasePencilModifierMaterialFilter_material_set", - nullptr, - "rna_GreasePencilModifierMaterialFilter_material_poll"); + RNA_def_property_pointer_funcs( + prop, nullptr, material_set_fn, nullptr, "rna_GreasePencilModifier_material_poll"); RNA_def_property_ui_text(prop, "Material", "Material used for filtering"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "use_material_pass", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "use_material_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Material Pass", "Use material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "material_pass", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, nullptr, "material_pass"); + prop = RNA_def_property(srna, "material_pass_filter", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, nullptr, PROPNAME_PREFIX "material_pass"); RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Material Pass", "Material pass"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "invert_material", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "invert_material_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER); RNA_def_property_ui_text(prop, "Invert Material", "Invert material filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "invert_material_pass", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "invert_material_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Material Pass", "Invert material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - RNA_define_lib_overridable(false); +# undef PROPNAME_PREFIX } -static void rna_def_modifier_grease_pencil_vertex_group(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_vertex_group(StructRNA *srna, + const char *vertex_group_name_set_fn) { - StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierVertexGroupData", nullptr); - RNA_def_struct_ui_text(srna, - "Grease Pencil Modifier Vertex Group", - "Vertex group settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierVertexGroupData"); - - RNA_define_lib_overridable(true); +# define PROPNAME_PREFIX "influence.vertex_group." prop = RNA_def_property(srna, "vertex_group_name", PROP_STRING, PROP_NONE); - RNA_def_property_string_sdna(prop, nullptr, "vertex_group_name"); + RNA_def_property_string_sdna(prop, nullptr, PROPNAME_PREFIX "vertex_group_name"); RNA_def_property_ui_text(prop, "Name", "Vertex group name for modulating the deform"); - RNA_def_property_string_funcs( - prop, nullptr, nullptr, "rna_GreasePencilModifierVertexGroupData_name_set"); + RNA_def_property_string_funcs(prop, nullptr, nullptr, vertex_group_name_set_fn); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_vertex_group", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); RNA_def_property_ui_text(prop, "Invert Vertex Group", "Invert vertex group weights"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - RNA_define_lib_overridable(false); +# undef PROPNAME_PREFIX } -static void rna_def_modifier_grease_pencil_custom_curve(BlenderRNA *brna) +static void rna_def_modifier_grease_pencil_custom_curve(StructRNA *srna) { - StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "GreasePencilModifierCustomCurveData", nullptr); - RNA_def_struct_ui_text(srna, - "Grease Pencil Modifier Custom Curve", - "Custom curve settings for grease pencil modifiers"); - RNA_def_struct_sdna(srna, "GreasePencilModifierCustomCurveData"); +# define PROPNAME_PREFIX "influence.custom_curve." prop = RNA_def_property(srna, "use_custom_curve", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "flag", GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); + RNA_def_property_boolean_sdna( + prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); RNA_def_property_ui_text( prop, "Use Custom Curve", "Use a custom curve to define a factor along the strokes"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, "curve"); + prop = RNA_def_property(srna, "custom_curve", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, nullptr, PROPNAME_PREFIX "curve"); RNA_def_property_ui_text(prop, "Curve", "Custom curve to apply effect"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); -} -/** Utility function to register common influence properties for grease pencil modifiers. */ -static void rna_def_modifier_grease_pencil_influence_properties(StructRNA *srna, - const char *layer_filter_sdna, - const char *material_filter_sdna, - const char *vertex_group_sdna, - const char *custom_curve_sdna) -{ - PropertyRNA *prop; - - if (layer_filter_sdna) { - prop = RNA_def_property(srna, "layer_filter", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, layer_filter_sdna); - RNA_def_property_struct_type(prop, "GreasePencilModifierLayerFilter"); - RNA_def_property_ui_text(prop, "Layer Filter", "Layer filter settings"); - } - if (material_filter_sdna) { - prop = RNA_def_property(srna, "material_filter", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, material_filter_sdna); - RNA_def_property_struct_type(prop, "GreasePencilModifierMaterialFilter"); - RNA_def_property_ui_text(prop, "Material Filter", "Material filter settings"); - } - if (vertex_group_sdna) { - prop = RNA_def_property(srna, "vertex_group", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, vertex_group_sdna); - RNA_def_property_struct_type(prop, "GreasePencilModifierVertexGroupData"); - RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group settings"); - } - if (custom_curve_sdna) { - prop = RNA_def_property(srna, "custom_curve", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, custom_curve_sdna); - RNA_def_property_struct_type(prop, "GreasePencilModifierCustomCurveData"); - RNA_def_property_ui_text(prop, "Custom Curve", "Custom curve settings"); - } +# undef PROPNAME_PREFIX } void RNA_def_modifier(BlenderRNA *brna) @@ -7806,10 +7758,6 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_mesh_to_volume(brna); rna_def_modifier_volume_displace(brna); rna_def_modifier_volume_to_mesh(brna); - rna_def_modifier_grease_pencil_layer_filter(brna); - rna_def_modifier_grease_pencil_material_filter(brna); - rna_def_modifier_grease_pencil_vertex_group(brna); - rna_def_modifier_grease_pencil_custom_curve(brna); } #endif diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index dc4b4be5888..23d13ef30d7 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -75,54 +75,56 @@ void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, Pointe { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); - const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass"); + const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass_filter"); uiLayout *row, *col, *sub; uiLayoutSetPropSep(layout, true); col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); - uiItemPointerR(row, ptr, "layer", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); + uiItemPointerR(row, ptr, "layer_filter", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_layer", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_layer_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); /* TODO Would be nice to have the checkbox in the same line as the pass button. */ row = uiLayoutRow(col, true); - uiItemR(row, ptr, "use_layer_pass", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); + uiItemR(row, ptr, "use_layer_pass_filter", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); row = uiLayoutRow(col, true); uiLayoutSetActive(row, use_layer_pass); - uiItemR(row, ptr, "layer_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + uiItemR(row, ptr, "layer_pass_filter", UI_ITEM_NONE, nullptr, ICON_NONE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_layer_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_layer_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); - const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass"); + const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass_filter"); uiLayout *row, *col, *sub; uiLayoutSetPropSep(layout, true); col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); - uiItemPointerR(row, ptr, "material", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); + uiItemPointerR( + row, ptr, "material_filter", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_material", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_material_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); /* TODO Would be nice to have the checkbox in the same line as the pass button. */ row = uiLayoutRow(col, true); - uiItemR(row, ptr, "use_material_pass", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); + uiItemR( + row, ptr, "use_material_pass_filter", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); row = uiLayoutRow(col, true); uiLayoutSetActive(row, use_material_pass); - uiItemR(row, ptr, "material_pass", UI_ITEM_NONE, nullptr, ICON_NONE); + uiItemR(row, ptr, "material_pass_filter", UI_ITEM_NONE, nullptr, ICON_NONE); sub = uiLayoutRow(row, true); uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_material_pass", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "invert_material_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); } void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) @@ -149,7 +151,7 @@ void draw_custom_curve_settings(const bContext * /*C*/, uiLayout *layout, Pointe uiItemR(layout, ptr, "use_custom_curve", UI_ITEM_NONE, nullptr, ICON_NONE); if (use_custom_curve) { - uiTemplateCurveMapping(layout, ptr, "curve", 0, false, false, false, false); + uiTemplateCurveMapping(layout, ptr, "custom_curve", 0, false, false, false, false); } } -- 2.30.2 From b3f163ee63b65da6a55db9d801b83c774ba66adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 13:51:13 +0100 Subject: [PATCH 19/45] Ported evaluation functions for the opacity modifier. --- source/blender/makesdna/DNA_modifier_types.h | 18 ++- .../blender/makesrna/intern/rna_modifier.cc | 1 + .../intern/MOD_grease_pencil_opacity.cc | 146 ++++++++++++++++-- 3 files changed, 152 insertions(+), 13 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 21c13ca50b2..1c7e693f24c 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2547,10 +2547,26 @@ typedef struct GreasePencilOpacityModifierData { GreasePencilModifierInfluenceData influence; /** GreasePencilOpacityModifierFlag */ int flag; - char _pad1[4]; + /** GreasePencilModifierColorMode */ + char color_mode; + char _pad1[3]; + float color_factor; + float hardness_factor; void *_pad2; } GreasePencilOpacityModifierData; +/** Which attributes are affected by color modifiers. */ +typedef enum GreasePencilModifierColorMode { + MOD_GREASE_PENCIL_COLOR_STROKE = 0, + MOD_GREASE_PENCIL_COLOR_FILL = 1, + MOD_GREASE_PENCIL_COLOR_BOTH = 2, + MOD_GREASE_PENCIL_COLOR_HARDNESS = 3, +} GreasePencilModifierColorMode; + typedef enum GreasePencilOpacityModifierFlag { MOD_GREASE_PENCIL_OPACITY_OPEN_INFLUENCE_PANEL = (1 << 0), + /* Use vertex group as opacity factors instead of influence. */ + MOD_GREASE_PENCIL_OPACITY_USE_VERTEX_GROUP = (1 << 1), + /* Set the opacity for every point in a stroke, otherwise multiply existing opacity. */ + MOD_GREASE_PENCIL_OPACITY_USE_UNIFORM_OPACITY = (1 << 2), } GreasePencilOpacityModifierFlag; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index affcc59921c..8706a754595 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -7635,6 +7635,7 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) // TODO RNA_define_lib_overridable(false); +} void RNA_def_modifier(BlenderRNA *brna) { diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index b7d58267120..b96103ec3ee 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -12,6 +12,7 @@ #include "DNA_modifier_types.h" #include "DNA_scene_types.h" +#include "BKE_colortools.hh" #include "BKE_curves.hh" #include "BKE_geometry_set.hh" #include "BKE_grease_pencil.hh" @@ -94,28 +95,149 @@ static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data); } +/* XXX Placeholder for vertex groupn weights. */ +static VArray get_grease_pencil_modifier_vertex_weights( + const bke::CurvesGeometry &curves, const GreasePencilModifierVertexGroupData &vertex_group) +{ + const bool use_vertex_group = (vertex_group.vertex_group_name[0] != '\0'); + return VArray::ForSingle(use_vertex_group ? 1.0f : 0.0f, curves.point_num); +} + +static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, + bke::CurvesGeometry &curves, + const IndexMask &curves_mask) +{ + const bool use_uniform_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_UNIFORM_OPACITY); + const bool use_vgroup_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_VERTEX_GROUP); + const bool invert_vertex_group = (omd.influence.vertex_group.flag & + GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); + const bool use_curve = (omd.influence.custom_curve.flag & + GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); + const OffsetIndices points_by_curve = curves.points_by_curve(); + const VArray vgroup_weights = get_grease_pencil_modifier_vertex_weights( + curves, omd.influence.vertex_group); + + bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); + bke::SpanAttributeWriter opacities = attributes.lookup_or_add_for_write_span( + "opacity", bke::AttrDomain::Point); + + for (const int64_t i : curves_mask.index_range()) { + const int64_t curve_i = curves_mask[i]; + + const IndexRange points_range = points_by_curve[curve_i]; + for (const int64_t point_i : points_range) { + const float curve_input = points_range.size() >= 2 ? (float(point_i - points_range.first()) / + float(points_range.size() - 1)) : + 0.0f; + const float curve_factor = use_curve ? + BKE_curvemapping_evaluateF( + omd.influence.custom_curve.curve, 0, curve_input) : + 1.0f; + + if (use_uniform_opacity) { + opacities.span[point_i] = std::clamp(curve_factor, 0.0f, 1.0f); + } + else if (use_vgroup_opacity) { + /* Use vertex group weights as opacity factors. */ + const float vgroup_weight = vgroup_weights[point_i]; + const float point_factor = vgroup_weight; + + opacities.span[point_i] = std::clamp( + opacities.span[point_i] + omd.color_factor * curve_factor * point_factor - 1.0f, + 0.0f, + 1.0f); + } + else { + /* Use vertex group weights as influence factors. */ + const float vgroup_weight = vgroup_weights[point_i]; + const float vgroup_influence = invert_vertex_group ? 1.0f - vgroup_weight : vgroup_weight; + opacities.span[point_i] = std::clamp( + omd.color_factor * curve_factor * vgroup_influence, 0.0f, 1.0f); + } + } + } + + opacities.finish(); +} + +static void modify_fill_color(const GreasePencilOpacityModifierData &omd, + bke::CurvesGeometry &curves, + const IndexMask &curves_mask) +{ + const bool use_vgroup_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_VERTEX_GROUP); + const bool invert_vertex_group = (omd.influence.vertex_group.flag & + GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); + const OffsetIndices points_by_curve = curves.points_by_curve(); + const VArray vgroup_weights = get_grease_pencil_modifier_vertex_weights( + curves, omd.influence.vertex_group); + + bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); + /* Fill color opacity per stroke. */ + bke::SpanAttributeWriter fill_opacities = attributes.lookup_or_add_for_write_span( + "fill_opacity", bke::AttrDomain::Curve); + + for (const int64_t i : curves_mask.index_range()) { + const int64_t curve_i = curves_mask[i]; + + if (use_vgroup_opacity) { + /* Use the first stroke point as vertex weight. */ + const IndexRange points_range = points_by_curve[curve_i]; + const float stroke_weight = points_range.is_empty() ? 1.0f : + vgroup_weights[points_range.first()]; + const float stroke_influence = invert_vertex_group ? 1.0f - stroke_weight : stroke_weight; + + fill_opacities.span[curve_i] = std::clamp(stroke_influence, 0.0f, 1.0f); + } + else { + fill_opacities.span[curve_i] = std::clamp(omd.color_factor, 0.0f, 1.0f); + } + } + + fill_opacities.finish(); +} + +static void modify_hardness(const GreasePencilOpacityModifierData &omd, + bke::CurvesGeometry &curves, + const IndexMask &curves_mask) +{ + bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); + bke::SpanAttributeWriter hardnesses = attributes.lookup_or_add_for_write_span( + "hardness", bke::AttrDomain::Curve); + + for (const int64_t i : curves_mask.index_range()) { + const int64_t curve_i = curves_mask[i]; + hardnesses.span[curve_i] = std::clamp( + hardnesses.span[curve_i] * omd.hardness_factor, 0.0f, 1.0f); + } + + hardnesses.finish(); +} + static void modify_curves(ModifierData *md, const ModifierEvalContext *ctx, bke::CurvesGeometry &curves) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); - bke::SpanAttributeWriter opacities = attributes.lookup_or_add_for_write_span( - "opacity", bke::AttrDomain::Point); - - OffsetIndices points_by_curve = curves.points_by_curve(); IndexMaskMemory mask_memory; IndexMask curves_mask = greasepencil::get_filtered_stroke_mask( ctx->object, curves, omd->influence.material_filter, mask_memory); - for (const int64_t i : curves_mask.index_range()) { - const int64_t curve_i = curves_mask[i]; - for (const int64_t point_i : points_by_curve[curve_i]) { - opacities.span[point_i] *= 0.5f; - } - } - opacities.finish(); + switch (omd->color_mode) { + case MOD_GREASE_PENCIL_COLOR_STROKE: + modify_stroke_color(*omd, curves, curves_mask); + break; + case MOD_GREASE_PENCIL_COLOR_FILL: + modify_fill_color(*omd, curves, curves_mask); + break; + case MOD_GREASE_PENCIL_COLOR_BOTH: + modify_stroke_color(*omd, curves, curves_mask); + modify_fill_color(*omd, curves, curves_mask); + break; + case MOD_GREASE_PENCIL_COLOR_HARDNESS: + modify_hardness(*omd, curves, curves_mask); + break; + } } static void modify_geometry_set(ModifierData *md, -- 2.30.2 From 1577d8175a724d547b62eea7f4ba12131f6775d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 14:20:39 +0100 Subject: [PATCH 20/45] Flattened the DNA struct for modifier influence. --- source/blender/makesdna/DNA_modifier_types.h | 59 ++++++------------- .../blender/makesrna/intern/rna_modifier.cc | 51 ++++++---------- .../intern/MOD_grease_pencil_opacity.cc | 30 +++++----- .../intern/MOD_grease_pencil_util.cc | 50 ++++++++-------- .../intern/MOD_grease_pencil_util.hh | 4 +- 5 files changed, 76 insertions(+), 118 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 1c7e693f24c..e3f1a2b65d6 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2486,39 +2486,27 @@ typedef enum VolumeToMeshFlag { VOLUME_TO_MESH_USE_SMOOTH_SHADE = 1 << 0, } VolumeToMeshFlag; -typedef struct GreasePencilModifierLayerFilter { - /** Filter by layer name. */ - char layer_name[64]; - /** Filter by layer pass. */ - int layer_pass; - /** GreasePencilModifierFilterFlag */ - int flag; -} GreasePencilModifierLayerFilter; - -typedef struct GreasePencilModifierMaterialFilter { - /** Filter by stroke material. */ - struct Material *material; - /** Filter by material pass. */ - int material_pass; - /** GreasePencilModifierFilterFlag */ - int flag; -} GreasePencilModifierMaterialFilter; - -typedef struct GreasePencilModifierVertexGroupData { - /** #MAX_VGROUP_NAME. */ - char vertex_group_name[64]; - /** GreasePencilModifierFilterFlag */ - int flag; - char _pad[4]; -} GreasePencilModifierVertexGroupData; - -typedef struct GreasePencilModifierCustomCurveData { - struct CurveMapping *curve; - /** GreasePencilModifierFilterFlag */ +/** + * Common influence data for grease pencil modifiers. + * Not all parts may be used by all modifier types. + */ +typedef struct GreasePencilModifierInfluenceData { + /** GreasePencilModifierInfluenceFlag */ int flag; char _pad1[4]; + /** Filter by layer name. */ + char layer_name[64]; + /** Filter by stroke material. */ + struct Material *material; + /** Filter by layer pass. */ + int layer_pass; + /** Filter by material pass. */ + int material_pass; + /** #MAX_VGROUP_NAME. */ + char vertex_group_name[64]; + struct CurveMapping *custom_curve; void *_pad2; -} GreasePencilModifierCustomCurveData; +} GreasePencilModifierInfluenceData; typedef enum GreasePencilModifierInfluenceFlag { GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER = (1 << 0), @@ -2531,17 +2519,6 @@ typedef enum GreasePencilModifierInfluenceFlag { GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE = (1 << 7), } GreasePencilModifierInfluenceFlag; -/** - * Combined generic influence data for grease pencil modifiers. - * Not all parts may be used by all modifier types. - */ -typedef struct GreasePencilModifierInfluenceData { - GreasePencilModifierLayerFilter layer_filter; - GreasePencilModifierMaterialFilter material_filter; - GreasePencilModifierVertexGroupData vertex_group; - GreasePencilModifierCustomCurveData custom_curve; -} GreasePencilModifierInfluenceData; - typedef struct GreasePencilOpacityModifierData { ModifierData modifier; GreasePencilModifierInfluenceData influence; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 8706a754595..f10c57907df 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -1748,8 +1748,7 @@ static void rna_GreasePencilModifier_material_set(PointerRNA *ptr, PointerRNA *ptr, PointerRNA value, ReportList *reports) \ { \ _type##ModifierData *tmd = static_cast<_type##ModifierData *>(ptr->data); \ - rna_GreasePencilModifier_material_set( \ - ptr, value, reports, &tmd->influence.material_filter.material); \ + rna_GreasePencilModifier_material_set(ptr, value, reports, &tmd->influence.material); \ } # define RNA_MOD_GREASE_PENCIL_VERTEX_GROUP_SET(_type) \ @@ -1758,8 +1757,8 @@ static void rna_GreasePencilModifier_material_set(PointerRNA *ptr, _type##ModifierData *tmd = static_cast<_type##ModifierData *>(ptr->data); \ rna_object_vgroup_name_set(ptr, \ value, \ - tmd->influence.vertex_group.vertex_group_name, \ - sizeof(tmd->influence.vertex_group.vertex_group_name)); \ + tmd->influence.vertex_group_name, \ + sizeof(tmd->influence.vertex_group_name)); \ } RNA_MOD_GREASE_PENCIL_MATERIAL_FILTER_SET(GreasePencilOpacity); @@ -7487,38 +7486,34 @@ static void rna_def_modifier_grease_pencil_layer_filter(StructRNA *srna) { PropertyRNA *prop; -# define PROPNAME_PREFIX "influence.layer_filter." - prop = RNA_def_property(srna, "layer_filter", PROP_STRING, PROP_NONE); - RNA_def_property_string_sdna(prop, nullptr, PROPNAME_PREFIX "layer_name"); + RNA_def_property_string_sdna(prop, nullptr, "influence.layer_name"); RNA_def_property_ui_text(prop, "Layer", "Layer name"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "use_layer_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER); + prop, nullptr, "influence.flag", GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Layer Pass", "Use layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "layer_pass_filter", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, nullptr, PROPNAME_PREFIX "layer_pass"); + RNA_def_property_int_sdna(prop, nullptr, "influence.layer_pass"); RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Layer Pass", "Layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_layer_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER); + prop, nullptr, "influence.flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER); RNA_def_property_ui_text(prop, "Invert Layer", "Invert layer filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_layer_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER); + prop, nullptr, "influence.flag", GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Layer Pass", "Invert layer pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - -# undef PROPNAME_PREFIX } static void rna_def_modifier_grease_pencil_material_filter(StructRNA *srna, @@ -7526,10 +7521,8 @@ static void rna_def_modifier_grease_pencil_material_filter(StructRNA *srna, { PropertyRNA *prop; -# define PROPNAME_PREFIX "influence.material_filter." - prop = RNA_def_property(srna, "material_filter", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, PROPNAME_PREFIX "material"); + RNA_def_property_pointer_sdna(prop, nullptr, "influence.material"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_pointer_funcs( prop, nullptr, material_set_fn, nullptr, "rna_GreasePencilModifier_material_poll"); @@ -7538,29 +7531,27 @@ static void rna_def_modifier_grease_pencil_material_filter(StructRNA *srna, prop = RNA_def_property(srna, "use_material_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER); + prop, nullptr, "influence.flag", GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Use Material Pass", "Use material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "material_pass_filter", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, nullptr, PROPNAME_PREFIX "material_pass"); + RNA_def_property_int_sdna(prop, nullptr, "influence.material_pass"); RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Material Pass", "Material pass"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_material_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER); + prop, nullptr, "influence.flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER); RNA_def_property_ui_text(prop, "Invert Material", "Invert material filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_material_pass_filter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER); + prop, nullptr, "influence.flag", GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER); RNA_def_property_ui_text(prop, "Invert Material Pass", "Invert material pass filter"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - -# undef PROPNAME_PREFIX } static void rna_def_modifier_grease_pencil_vertex_group(StructRNA *srna, @@ -7568,42 +7559,34 @@ static void rna_def_modifier_grease_pencil_vertex_group(StructRNA *srna, { PropertyRNA *prop; -# define PROPNAME_PREFIX "influence.vertex_group." - prop = RNA_def_property(srna, "vertex_group_name", PROP_STRING, PROP_NONE); - RNA_def_property_string_sdna(prop, nullptr, PROPNAME_PREFIX "vertex_group_name"); + RNA_def_property_string_sdna(prop, nullptr, "influence.vertex_group_name"); RNA_def_property_ui_text(prop, "Name", "Vertex group name for modulating the deform"); RNA_def_property_string_funcs(prop, nullptr, nullptr, vertex_group_name_set_fn); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "invert_vertex_group", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); + prop, nullptr, "influence.flag", GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); RNA_def_property_ui_text(prop, "Invert Vertex Group", "Invert vertex group weights"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - -# undef PROPNAME_PREFIX } static void rna_def_modifier_grease_pencil_custom_curve(StructRNA *srna) { PropertyRNA *prop; -# define PROPNAME_PREFIX "influence.custom_curve." - prop = RNA_def_property(srna, "use_custom_curve", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna( - prop, nullptr, PROPNAME_PREFIX "flag", GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); + prop, nullptr, "influence.flag", GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); RNA_def_property_ui_text( prop, "Use Custom Curve", "Use a custom curve to define a factor along the strokes"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "custom_curve", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, nullptr, PROPNAME_PREFIX "curve"); + RNA_def_property_pointer_sdna(prop, nullptr, "influence.custom_curve"); RNA_def_property_ui_text(prop, "Curve", "Custom curve to apply effect"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - -# undef PROPNAME_PREFIX } static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index b96103ec3ee..fea9e8eac4e 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -97,9 +97,9 @@ static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void /* XXX Placeholder for vertex groupn weights. */ static VArray get_grease_pencil_modifier_vertex_weights( - const bke::CurvesGeometry &curves, const GreasePencilModifierVertexGroupData &vertex_group) + const bke::CurvesGeometry &curves, const GreasePencilModifierInfluenceData &influence_data) { - const bool use_vertex_group = (vertex_group.vertex_group_name[0] != '\0'); + const bool use_vertex_group = (influence_data.vertex_group_name[0] != '\0'); return VArray::ForSingle(use_vertex_group ? 1.0f : 0.0f, curves.point_num); } @@ -109,13 +109,12 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, { const bool use_uniform_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_UNIFORM_OPACITY); const bool use_vgroup_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_VERTEX_GROUP); - const bool invert_vertex_group = (omd.influence.vertex_group.flag & + const bool invert_vertex_group = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); - const bool use_curve = (omd.influence.custom_curve.flag & - GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); + const bool use_curve = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); const OffsetIndices points_by_curve = curves.points_by_curve(); - const VArray vgroup_weights = get_grease_pencil_modifier_vertex_weights( - curves, omd.influence.vertex_group); + const VArray vgroup_weights = get_grease_pencil_modifier_vertex_weights(curves, + omd.influence); bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); bke::SpanAttributeWriter opacities = attributes.lookup_or_add_for_write_span( @@ -129,10 +128,9 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, const float curve_input = points_range.size() >= 2 ? (float(point_i - points_range.first()) / float(points_range.size() - 1)) : 0.0f; - const float curve_factor = use_curve ? - BKE_curvemapping_evaluateF( - omd.influence.custom_curve.curve, 0, curve_input) : - 1.0f; + const float curve_factor = use_curve ? BKE_curvemapping_evaluateF( + omd.influence.custom_curve, 0, curve_input) : + 1.0f; if (use_uniform_opacity) { opacities.span[point_i] = std::clamp(curve_factor, 0.0f, 1.0f); @@ -165,11 +163,11 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd, const IndexMask &curves_mask) { const bool use_vgroup_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_VERTEX_GROUP); - const bool invert_vertex_group = (omd.influence.vertex_group.flag & + const bool invert_vertex_group = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); const OffsetIndices points_by_curve = curves.points_by_curve(); - const VArray vgroup_weights = get_grease_pencil_modifier_vertex_weights( - curves, omd.influence.vertex_group); + const VArray vgroup_weights = get_grease_pencil_modifier_vertex_weights(curves, + omd.influence); bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); /* Fill color opacity per stroke. */ @@ -221,7 +219,7 @@ static void modify_curves(ModifierData *md, IndexMaskMemory mask_memory; IndexMask curves_mask = greasepencil::get_filtered_stroke_mask( - ctx->object, curves, omd->influence.material_filter, mask_memory); + ctx->object, curves, omd->influence, mask_memory); switch (omd->color_mode) { case MOD_GREASE_PENCIL_COLOR_STROKE: @@ -255,7 +253,7 @@ static void modify_geometry_set(ModifierData *md, IndexMaskMemory mask_memory; IndexMask layer_mask = greasepencil::get_filtered_layer_mask( - *grease_pencil, omd->influence.layer_filter, mask_memory); + *grease_pencil, omd->influence, mask_memory); Vector drawings = greasepencil::get_drawings_for_write( *grease_pencil, layer_mask, frame); for (Drawing *drawing : drawings) { diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 23d13ef30d7..2b34e742dec 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -41,8 +41,8 @@ void init_influence_data(GreasePencilModifierInfluenceData *influence_data, const bool has_custom_curve) { if (has_custom_curve) { - influence_data->custom_curve.curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); - BKE_curvemapping_init(influence_data->custom_curve.curve); + influence_data->custom_curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + BKE_curvemapping_init(influence_data->custom_curve); } } @@ -51,15 +51,14 @@ void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data const int /*flag*/) { memcpy(influence_data_dst, influence_data_src, sizeof(GreasePencilModifierInfluenceData)); - influence_data_dst->custom_curve.curve = BKE_curvemapping_copy( - influence_data_src->custom_curve.curve); + influence_data_dst->custom_curve = BKE_curvemapping_copy(influence_data_src->custom_curve); } void free_influence_data(GreasePencilModifierInfluenceData *influence_data) { - if (influence_data->custom_curve.curve) { - BKE_curvemapping_free(influence_data->custom_curve.curve); - influence_data->custom_curve.curve = nullptr; + if (influence_data->custom_curve) { + BKE_curvemapping_free(influence_data->custom_curve); + influence_data->custom_curve = nullptr; } } @@ -68,7 +67,7 @@ void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data IDWalkFunc walk, void *user_data) { - walk(user_data, ob, (ID **)&influence_data->material_filter.material, IDWALK_CB_USER); + walk(user_data, ob, (ID **)&influence_data->material, IDWALK_CB_USER); } void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) @@ -212,19 +211,20 @@ static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, } IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, - const GreasePencilModifierLayerFilter &filter, + const GreasePencilModifierInfluenceData &influence_data, IndexMaskMemory &memory) { - return get_filtered_layer_mask(grease_pencil, - filter.layer_name[0] != '\0' ? - std::make_optional(filter.layer_name) : - std::nullopt, - (filter.flag & GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER) ? - std::make_optional(filter.layer_pass) : - std::nullopt, - filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER, - filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER, - memory); + return get_filtered_layer_mask( + grease_pencil, + influence_data.layer_name[0] != '\0' ? + std::make_optional(influence_data.layer_name) : + std::nullopt, + (influence_data.flag & GREASE_PENCIL_INFLUENCE_USE_LAYER_PASS_FILTER) ? + std::make_optional(influence_data.layer_pass) : + std::nullopt, + influence_data.flag & GREASE_PENCIL_INFLUENCE_INVERT_LAYER_FILTER, + influence_data.flag & GREASE_PENCIL_INFLUENCE_INVERT_LAYER_PASS_FILTER, + memory); } static IndexMask get_filtered_stroke_mask(const Object *ob, @@ -271,19 +271,19 @@ static IndexMask get_filtered_stroke_mask(const Object *ob, IndexMask get_filtered_stroke_mask(const Object *ob, const bke::CurvesGeometry &curves, - const GreasePencilModifierMaterialFilter &filter, + const GreasePencilModifierInfluenceData &influence_data, IndexMaskMemory &memory) { /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ return get_filtered_stroke_mask( ob, curves, - filter.material, - (filter.flag & GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER) ? - std::make_optional(filter.material_pass) : + influence_data.material, + (influence_data.flag & GREASE_PENCIL_INFLUENCE_USE_MATERIAL_PASS_FILTER) ? + std::make_optional(influence_data.material_pass) : std::nullopt, - filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER, - filter.flag & GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER, + influence_data.flag & GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_FILTER, + influence_data.flag & GREASE_PENCIL_INFLUENCE_INVERT_MATERIAL_PASS_FILTER, memory); } diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index d2688134a36..fea1384ffa7 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -47,12 +47,12 @@ void draw_vertex_group_settings(const bContext *C, uiLayout *layout, PointerRNA void draw_custom_curve_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, - const GreasePencilModifierLayerFilter &filter, + const GreasePencilModifierInfluenceData &influence_data, IndexMaskMemory &memory); IndexMask get_filtered_stroke_mask(const Object *ob, const bke::CurvesGeometry &curves, - const GreasePencilModifierMaterialFilter &filter, + const GreasePencilModifierInfluenceData &influence_data, IndexMaskMemory &memory); Vector get_drawings_for_write(GreasePencil &grease_pencil, -- 2.30.2 From e47d168b2b1f82a58edef1dfb5892cc8bef9c893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 14:38:24 +0100 Subject: [PATCH 21/45] RNA definition for opacity modifier settings. --- source/blender/makesdna/DNA_modifier_types.h | 2 +- .../blender/makesrna/intern/rna_modifier.cc | 51 ++++++++++++++++++- .../intern/MOD_grease_pencil_opacity.cc | 6 +-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index e3f1a2b65d6..e3028b31fca 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2543,7 +2543,7 @@ typedef enum GreasePencilModifierColorMode { typedef enum GreasePencilOpacityModifierFlag { MOD_GREASE_PENCIL_OPACITY_OPEN_INFLUENCE_PANEL = (1 << 0), /* Use vertex group as opacity factors instead of influence. */ - MOD_GREASE_PENCIL_OPACITY_USE_VERTEX_GROUP = (1 << 1), + MOD_GREASE_PENCIL_OPACITY_USE_WEIGHT_AS_FACTOR = (1 << 1), /* Set the opacity for every point in a stroke, otherwise multiply existing opacity. */ MOD_GREASE_PENCIL_OPACITY_USE_UNIFORM_OPACITY = (1 << 2), } GreasePencilOpacityModifierFlag; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index f10c57907df..adfe70ab2fa 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -1764,6 +1764,26 @@ static void rna_GreasePencilModifier_material_set(PointerRNA *ptr, RNA_MOD_GREASE_PENCIL_MATERIAL_FILTER_SET(GreasePencilOpacity); RNA_MOD_GREASE_PENCIL_VERTEX_GROUP_SET(GreasePencilOpacity); +static void rna_GreasePencilOpacityModifier_opacity_factor_range( + PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax) +{ + GreasePencilOpacityModifierData *omd = static_cast(ptr->data); + + *min = 0.0f; + *softmin = 0.0f; + *softmax = (omd->flag & MOD_GREASE_PENCIL_OPACITY_USE_UNIFORM_OPACITY) ? 1.0f : 2.0f; + *max = *softmax; +} + +static void rna_GreasePencilOpacityModifier_opacity_factor_max_set(PointerRNA *ptr, float value) +{ + GreasePencilOpacityModifierData *omd = static_cast(ptr->data); + + omd->color_factor = (omd->flag & MOD_GREASE_PENCIL_OPACITY_USE_UNIFORM_OPACITY) ? + std::min(value, 1.0f) : + value; +} + #else static void rna_def_modifier_panel_open_prop(StructRNA *srna, const char *identifier, const int id) @@ -7615,7 +7635,36 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) RNA_define_lib_overridable(true); - // TODO + prop = RNA_def_property(srna, "color_factor", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, nullptr, "color_factor"); + RNA_def_property_ui_range(prop, 0, 2.0, 0.1, 2); + RNA_def_property_float_funcs(prop, + nullptr, + "rna_GreasePencilOpacityModifier_opacity_factor_max_set", + "rna_GreasePencilOpacityModifier_opacity_factor_range"); + RNA_def_property_ui_text(prop, "Opacity Factor", "Factor of opacity"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "hardness_factor", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, nullptr, "hardness_factor"); + RNA_def_property_range(prop, 0.0, FLT_MAX); + RNA_def_property_ui_range(prop, 0.0, FLT_MAX, 0.1, 2); + RNA_def_property_ui_text(prop, "Hardness Factor", "Factor of stroke hardness"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "use_weight_as_factor", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", MOD_GREASE_PENCIL_OPACITY_USE_WEIGHT_AS_FACTOR); + RNA_def_property_ui_text( + prop, "Use Weight as Factor", "Use vertex group weight as factor instead of influence"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "use_uniform_opacity", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna( + prop, nullptr, "flag", MOD_GREASE_PENCIL_OPACITY_USE_UNIFORM_OPACITY); + RNA_def_property_ui_text( + prop, "Uniform Opacity", "Replace the stroke opacity instead of modulating each point"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); RNA_define_lib_overridable(false); } diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index fea9e8eac4e..b963e6e653d 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -108,7 +108,7 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, const IndexMask &curves_mask) { const bool use_uniform_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_UNIFORM_OPACITY); - const bool use_vgroup_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_VERTEX_GROUP); + const bool use_weight_as_factor = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_WEIGHT_AS_FACTOR); const bool invert_vertex_group = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); const bool use_curve = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); @@ -135,7 +135,7 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, if (use_uniform_opacity) { opacities.span[point_i] = std::clamp(curve_factor, 0.0f, 1.0f); } - else if (use_vgroup_opacity) { + else if (use_weight_as_factor) { /* Use vertex group weights as opacity factors. */ const float vgroup_weight = vgroup_weights[point_i]; const float point_factor = vgroup_weight; @@ -162,7 +162,7 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd, bke::CurvesGeometry &curves, const IndexMask &curves_mask) { - const bool use_vgroup_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_VERTEX_GROUP); + const bool use_vgroup_opacity = (omd.flag & MOD_GREASE_PENCIL_OPACITY_USE_WEIGHT_AS_FACTOR); const bool invert_vertex_group = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); const OffsetIndices points_by_curve = curves.points_by_curve(); -- 2.30.2 From ca2413e91d49fc36a7dc4700aac1e56f45cfb017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 15:02:56 +0100 Subject: [PATCH 22/45] UI drawing for opacity modifier properties. --- .../blender/makesrna/intern/rna_modifier.cc | 13 ++++++++ .../intern/MOD_grease_pencil_opacity.cc | 31 ++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index adfe70ab2fa..9c021b0cbb9 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -7614,6 +7614,14 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; + static const EnumPropertyItem color_mode_items[] = { + {MOD_GREASE_PENCIL_COLOR_BOTH, "BOTH", 0, "Stroke & Fill", "Modify fill and stroke colors"}, + {MOD_GREASE_PENCIL_COLOR_STROKE, "STROKE", 0, "Stroke", "Modify stroke color only"}, + {MOD_GREASE_PENCIL_COLOR_FILL, "FILL", 0, "Fill", "Modify fill color only"}, + {MOD_GREASE_PENCIL_COLOR_HARDNESS, "HARDNESS", 0, "Hardness", "Modify stroke hardness"}, + {0, nullptr, 0, nullptr, nullptr}, + }; + srna = RNA_def_struct(brna, "GreasePencilOpacityModifier", "Modifier"); RNA_def_struct_ui_text(srna, "Grease Pencil Opacity Modifier", ""); RNA_def_struct_sdna(srna, "GreasePencilOpacityModifierData"); @@ -7635,6 +7643,11 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) RNA_define_lib_overridable(true); + prop = RNA_def_property(srna, "color_mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, color_mode_items); + RNA_def_property_ui_text(prop, "Color Mode", "Attributes to modify"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "color_factor", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, nullptr, "color_factor"); RNA_def_property_ui_range(prop, 0, 2.0, 0.1, 2); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index b963e6e653d..75ee159b521 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -268,6 +268,33 @@ static void panel_draw(const bContext *C, Panel *panel) PointerRNA ob_ptr; PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr); + uiLayoutSetPropSep(layout, true); + + const GreasePencilModifierColorMode color_mode = GreasePencilModifierColorMode( + RNA_enum_get(ptr, "color_mode")); + + uiItemR(layout, ptr, "color_mode", UI_ITEM_NONE, nullptr, ICON_NONE); + + if (color_mode == MOD_GREASE_PENCIL_COLOR_HARDNESS) { + uiItemR(layout, ptr, "hardness_factor", UI_ITEM_NONE, nullptr, ICON_NONE); + } + else { + const bool use_uniform_opacity = RNA_boolean_get(ptr, "use_uniform_opacity"); + const bool use_weight_as_factor = RNA_boolean_get(ptr, "use_weight_as_factor"); + + uiItemR(layout, ptr, "use_uniform_opacity", UI_ITEM_NONE, nullptr, ICON_NONE); + const char *text = (use_uniform_opacity) ? IFACE_("Opacity") : IFACE_("Opacity Factor"); + + uiLayout *row = uiLayoutRow(layout, true); + uiLayoutSetActive(row, !use_weight_as_factor || use_uniform_opacity); + uiItemR(row, ptr, "color_factor", UI_ITEM_NONE, text, ICON_NONE); + if (!use_uniform_opacity) { + uiLayout *sub = uiLayoutRow(row, true); + uiLayoutSetActive(sub, true); + uiItemR(row, ptr, "use_weight_as_factor", UI_ITEM_NONE, "", ICON_MOD_VERTEX_WEIGHT); + } + } + if (uiLayout *influence_panel = uiLayoutPanel( C, layout, "Influence", ptr, "open_influence_panel")) { @@ -277,10 +304,6 @@ static void panel_draw(const bContext *C, Panel *panel) greasepencil::draw_custom_curve_settings(C, influence_panel, ptr); } - uiLayoutSetPropSep(layout, true); - - // TODO - modifier_panel_end(layout, ptr); } -- 2.30.2 From 46a82c6a008e4f45c958dfacc86809a1a2d3c19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 15:13:50 +0100 Subject: [PATCH 23/45] Added missing read/write code for curve mapping. --- .../intern/MOD_grease_pencil_opacity.cc | 4 +++- .../intern/MOD_grease_pencil_util.cc | 19 +++++++++++++++++++ .../intern/MOD_grease_pencil_util.hh | 4 ++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 75ee159b521..b67e15904ad 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -317,12 +317,14 @@ static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const Modi const GreasePencilOpacityModifierData *omd = (const GreasePencilOpacityModifierData *)md; BLO_write_struct(writer, GreasePencilOpacityModifierData, omd); + greasepencil::write_influence_data(writer, &omd->influence); } static void blend_read(BlendDataReader *reader, ModifierData *md) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - UNUSED_VARS(reader, omd); + + greasepencil::read_influence_data(reader, &omd->influence); } } // namespace blender diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 2b34e742dec..885a0c5a575 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -21,6 +21,8 @@ #include "BKE_lib_query.h" #include "BKE_material.h" +#include "BLO_read_write.hh" + #include "DNA_defaults.h" #include "DEG_depsgraph_query.hh" @@ -70,6 +72,23 @@ void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data walk(user_data, ob, (ID **)&influence_data->material, IDWALK_CB_USER); } +void write_influence_data(BlendWriter *writer, + const GreasePencilModifierInfluenceData *influence_data) +{ + if (influence_data->custom_curve) { + BKE_curvemapping_blend_write(writer, influence_data->custom_curve); + } +} + +void read_influence_data(BlendDataReader *reader, + GreasePencilModifierInfluenceData *influence_data) +{ + BLO_read_data_address(reader, &influence_data->custom_curve); + if (influence_data->custom_curve) { + BKE_curvemapping_blend_read(reader, influence_data->custom_curve); + } +} + void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) { PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index fea1384ffa7..0e0f7668e07 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -40,6 +40,10 @@ void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data Object *ob, IDWalkFunc walk, void *user_data); +void write_influence_data(BlendWriter *writer, + const GreasePencilModifierInfluenceData *influence_data); +void read_influence_data(BlendDataReader *reader, + GreasePencilModifierInfluenceData *influence_data); void draw_layer_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); void draw_material_filter_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr); -- 2.30.2 From 50a330a250ed27895d299c3c8339f0ed672ce45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 15:40:19 +0100 Subject: [PATCH 24/45] Fixed DNA defaults for opacity modifier. --- .../blender/makesdna/DNA_modifier_defaults.h | 7 +++++++ source/blender/makesdna/intern/dna_defaults.c | 2 ++ .../intern/MOD_grease_pencil_opacity.cc | 20 ++----------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_defaults.h b/source/blender/makesdna/DNA_modifier_defaults.h index 4fc4a9341b1..288fa3b4473 100644 --- a/source/blender/makesdna/DNA_modifier_defaults.h +++ b/source/blender/makesdna/DNA_modifier_defaults.h @@ -801,4 +801,11 @@ .mat_ofs = 0, \ } +#define _DNA_DEFAULT_GreasePencilOpacityModifierData \ + { \ + .color_mode = MOD_GREASE_PENCIL_COLOR_BOTH, \ + .color_factor = 1.0f, \ + .hardness_factor = 1.0f, \ + } + /* clang-format off */ diff --git a/source/blender/makesdna/intern/dna_defaults.c b/source/blender/makesdna/intern/dna_defaults.c index 82dfa47d76d..5249d684906 100644 --- a/source/blender/makesdna/intern/dna_defaults.c +++ b/source/blender/makesdna/intern/dna_defaults.c @@ -322,6 +322,7 @@ SDNA_DEFAULT_DECL_STRUCT(DashGpencilModifierData); SDNA_DEFAULT_DECL_STRUCT(DashGpencilModifierSegment); SDNA_DEFAULT_DECL_STRUCT(ShrinkwrapGpencilModifierData); SDNA_DEFAULT_DECL_STRUCT(EnvelopeGpencilModifierData); +SDNA_DEFAULT_DECL_STRUCT(GreasePencilOpacityModifierData); #undef SDNA_DEFAULT_DECL_STRUCT @@ -566,6 +567,7 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = { SDNA_DEFAULT_DECL(DashGpencilModifierSegment), SDNA_DEFAULT_DECL(ShrinkwrapGpencilModifierData), SDNA_DEFAULT_DECL(EnvelopeGpencilModifierData), + SDNA_DEFAULT_DECL(GreasePencilOpacityModifierData), }; #undef SDNA_DEFAULT_DECL #undef SDNA_DEFAULT_DECL_EX diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index b67e15904ad..bceb7cf0ccf 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -51,15 +51,7 @@ static void init_data(ModifierData *md) BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(omd, modifier)); - // XXX Why is this crashing, but the expanded code below works fine?!? - // MEMCPY_STRUCT_AFTER(omd, DNA_struct_default_get(GreasePencilOpacityModifierData), modifier); - { - CHECK_TYPE_NONCONST(omd); - memcpy((char *)(omd) + OFFSETOF_STRUCT_AFTER(omd, modifier), - (const char *)(md) + OFFSETOF_STRUCT_AFTER(omd, modifier), - sizeof(*(omd)) - OFFSETOF_STRUCT_AFTER(omd, modifier)); - } - + MEMCPY_STRUCT_AFTER(omd, DNA_struct_default_get(GreasePencilOpacityModifierData), modifier); greasepencil::init_influence_data(&omd->influence, true); } @@ -81,14 +73,6 @@ static void free_data(ModifierData *md) greasepencil::free_influence_data(&omd->influence); } -static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks) -{ - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - - // TODO - UNUSED_VARS(omd, r_cddata_masks); -} - static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data) { GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; @@ -352,7 +336,7 @@ ModifierTypeInfo modifierType_GreasePencilOpacity = { /*modify_geometry_set*/ blender::modify_geometry_set, /*init_data*/ blender::init_data, - /*required_data_mask*/ blender::required_data_mask, + /*required_data_mask*/ nullptr, /*free_data*/ blender::free_data, /*is_disabled*/ nullptr, /*update_depsgraph*/ nullptr, -- 2.30.2 From 6f38dcdec75d34c94fe2285eeb3c6e09c73b152c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 16:06:53 +0100 Subject: [PATCH 25/45] Fix inverted "uniform" setting. --- .../modifiers/intern/MOD_grease_pencil_opacity.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index bceb7cf0ccf..aaf39872a8c 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -84,7 +84,7 @@ static VArray get_grease_pencil_modifier_vertex_weights( const bke::CurvesGeometry &curves, const GreasePencilModifierInfluenceData &influence_data) { const bool use_vertex_group = (influence_data.vertex_group_name[0] != '\0'); - return VArray::ForSingle(use_vertex_group ? 1.0f : 0.0f, curves.point_num); + return VArray::ForSingle(use_vertex_group ? 0.0f : 1.0f, curves.point_num); } static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, @@ -123,18 +123,17 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, /* Use vertex group weights as opacity factors. */ const float vgroup_weight = vgroup_weights[point_i]; const float point_factor = vgroup_weight; - opacities.span[point_i] = std::clamp( - opacities.span[point_i] + omd.color_factor * curve_factor * point_factor - 1.0f, - 0.0f, - 1.0f); + omd.color_factor * curve_factor * point_factor, 0.0f, 1.0f); } else { /* Use vertex group weights as influence factors. */ const float vgroup_weight = vgroup_weights[point_i]; const float vgroup_influence = invert_vertex_group ? 1.0f - vgroup_weight : vgroup_weight; opacities.span[point_i] = std::clamp( - omd.color_factor * curve_factor * vgroup_influence, 0.0f, 1.0f); + opacities.span[point_i] + omd.color_factor * curve_factor * vgroup_influence - 1.0f, + 0.0f, + 1.0f); } } } -- 2.30.2 From 3ec92d9530f706e9cb1e7f2191301b0ca943c461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 16:52:10 +0100 Subject: [PATCH 26/45] Initialize internal curve table after file read. --- source/blender/modifiers/intern/MOD_grease_pencil_util.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 885a0c5a575..eb2b1750dc7 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -86,6 +86,8 @@ void read_influence_data(BlendDataReader *reader, BLO_read_data_address(reader, &influence_data->custom_curve); if (influence_data->custom_curve) { BKE_curvemapping_blend_read(reader, influence_data->custom_curve); + /* Make sure the internal table exists. */ + BKE_curvemapping_init(influence_data->custom_curve); } } -- 2.30.2 From 15aeafe9ec9eb7c9cbc41eb5f3322a7dcabb3137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 16:55:04 +0100 Subject: [PATCH 27/45] Include color factor in the uniform opacity mode. --- source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index aaf39872a8c..e0b99010b0b 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -117,7 +117,7 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, 1.0f; if (use_uniform_opacity) { - opacities.span[point_i] = std::clamp(curve_factor, 0.0f, 1.0f); + opacities.span[point_i] = std::clamp(omd.color_factor * curve_factor, 0.0f, 1.0f); } else if (use_weight_as_factor) { /* Use vertex group weights as opacity factors. */ -- 2.30.2 From 7eaa51f282d50b26d5bc96fbf185a96099044c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 12 Jan 2024 18:08:01 +0100 Subject: [PATCH 28/45] Removed outdated comment. --- source/blender/modifiers/intern/MOD_grease_pencil_util.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index eb2b1750dc7..233f5e99258 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -295,7 +295,6 @@ IndexMask get_filtered_stroke_mask(const Object *ob, const GreasePencilModifierInfluenceData &influence_data, IndexMaskMemory &memory) { - /* TODO Add an option to toggle pass filter on and off, instead of using "pass > 0". */ return get_filtered_stroke_mask( ob, curves, -- 2.30.2 From 3c45f62887ad2afc9a5086ea080c3c8d939f4a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Mon, 15 Jan 2024 16:28:27 +0100 Subject: [PATCH 29/45] BKE_grease_pencil_object_material_index_get was removed. BKE_object_material_index_get does exactly the same thing. --- source/blender/makesrna/intern/rna_modifier.cc | 6 +++--- source/blender/modifiers/intern/MOD_grease_pencil_util.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 9c021b0cbb9..0da7113f414 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -679,7 +679,7 @@ const EnumPropertyItem rna_enum_subdivision_boundary_smooth_items[] = { # include "BKE_cachefile.h" # include "BKE_context.hh" # include "BKE_deform.h" -# include "BKE_grease_pencil.hh" +# include "BKE_material.h" # include "BKE_mesh_runtime.hh" # include "BKE_modifier.hh" # include "BKE_object.hh" @@ -1718,7 +1718,7 @@ bool rna_GreasePencilModifier_material_poll(PointerRNA *ptr, PointerRNA value) Object *ob = reinterpret_cast(ptr->owner_id); Material *ma = reinterpret_cast(value.owner_id); - return BKE_grease_pencil_object_material_index_get(ob, ma) != -1; + return BKE_object_material_index_get(ob, ma) != -1; } /* Write material to a generic target pointer without the final modifier struct. */ @@ -1730,7 +1730,7 @@ static void rna_GreasePencilModifier_material_set(PointerRNA *ptr, Object *ob = reinterpret_cast(ptr->owner_id); Material *ma = reinterpret_cast(value.owner_id); - if (ma == nullptr || BKE_grease_pencil_object_material_index_get(ob, ma) != -1) { + if (ma == nullptr || BKE_object_material_index_get(ob, ma) != -1) { id_lib_extern(reinterpret_cast(ob)); *ma_target = ma; } diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 233f5e99258..9eabe3034a7 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -261,7 +261,7 @@ static IndexMask get_filtered_stroke_mask(const Object *ob, return full_mask; } - const int material_filter_index = BKE_grease_pencil_object_material_index_get( + const int material_filter_index = BKE_object_material_index_get( const_cast(ob), const_cast(material_filter)); const Vector material_pass_by_index = get_grease_pencil_material_passes(ob); -- 2.30.2 From a640088fe913ce3aff9e845d1c18e3f45087ef92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Mon, 15 Jan 2024 16:57:41 +0100 Subject: [PATCH 30/45] Use "RowWithHeader" feature to put pass toggles on the same line. --- .../intern/MOD_grease_pencil_util.cc | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 9eabe3034a7..343e249bb25 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -96,7 +96,7 @@ void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, Pointe PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); const bool use_layer_pass = RNA_boolean_get(ptr, "use_layer_pass_filter"); - uiLayout *row, *col, *sub; + uiLayout *row, *col, *sub, *subsub; uiLayoutSetPropSep(layout, true); @@ -107,15 +107,15 @@ void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, Pointe uiLayoutSetPropDecorate(sub, false); uiItemR(sub, ptr, "invert_layer_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); - /* TODO Would be nice to have the checkbox in the same line as the pass button. */ - row = uiLayoutRow(col, true); - uiItemR(row, ptr, "use_layer_pass_filter", UI_ITEM_NONE, "Filter by layer pass", ICON_NONE); - row = uiLayoutRow(col, true); - uiLayoutSetActive(row, use_layer_pass); - uiItemR(row, ptr, "layer_pass_filter", UI_ITEM_NONE, nullptr, ICON_NONE); + row = uiLayoutRowWithHeading(col, true, "Layer Pass Filter"); + uiLayoutSetPropDecorate(row, false); sub = uiLayoutRow(row, true); - uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_layer_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "use_layer_pass_filter", UI_ITEM_NONE, "", ICON_NONE); + subsub = uiLayoutRow(sub, true); + uiLayoutSetActive(subsub, use_layer_pass); + uiItemR(subsub, ptr, "layer_pass_filter", UI_ITEM_NONE, "", ICON_NONE); + uiItemR(subsub, ptr, "invert_layer_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiLayoutSetPropDecorate(sub, true); } void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) @@ -123,7 +123,7 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi PointerRNA ob_ptr = RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id); PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); const bool use_material_pass = RNA_boolean_get(ptr, "use_material_pass_filter"); - uiLayout *row, *col, *sub; + uiLayout *row, *col, *sub, *subsub; uiLayoutSetPropSep(layout, true); @@ -135,16 +135,15 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi uiLayoutSetPropDecorate(sub, false); uiItemR(sub, ptr, "invert_material_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); - /* TODO Would be nice to have the checkbox in the same line as the pass button. */ - row = uiLayoutRow(col, true); - uiItemR( - row, ptr, "use_material_pass_filter", UI_ITEM_NONE, "Filter by material pass", ICON_NONE); - row = uiLayoutRow(col, true); - uiLayoutSetActive(row, use_material_pass); - uiItemR(row, ptr, "material_pass_filter", UI_ITEM_NONE, nullptr, ICON_NONE); + row = uiLayoutRowWithHeading(col, true, "Material Pass Filter"); + uiLayoutSetPropDecorate(row, false); sub = uiLayoutRow(row, true); - uiLayoutSetPropDecorate(sub, false); - uiItemR(sub, ptr, "invert_material_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiItemR(sub, ptr, "use_material_pass_filter", UI_ITEM_NONE, "", ICON_NONE); + subsub = uiLayoutRow(sub, true); + uiLayoutSetActive(subsub, use_material_pass); + uiItemR(subsub, ptr, "material_pass_filter", UI_ITEM_NONE, "", ICON_NONE); + uiItemR(subsub, ptr, "invert_material_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); + uiLayoutSetPropDecorate(sub, true); } void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) -- 2.30.2 From e99e274f81db1df81fe07a74024fd38aa77df695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 12:08:07 +0100 Subject: [PATCH 31/45] Use generic attributes for vertex group weights. --- .../intern/MOD_grease_pencil_opacity.cc | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index e0b99010b0b..f17333e6e7e 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -79,14 +79,6 @@ static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data); } -/* XXX Placeholder for vertex groupn weights. */ -static VArray get_grease_pencil_modifier_vertex_weights( - const bke::CurvesGeometry &curves, const GreasePencilModifierInfluenceData &influence_data) -{ - const bool use_vertex_group = (influence_data.vertex_group_name[0] != '\0'); - return VArray::ForSingle(use_vertex_group ? 0.0f : 1.0f, curves.point_num); -} - static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, bke::CurvesGeometry &curves, const IndexMask &curves_mask) @@ -97,12 +89,12 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); const bool use_curve = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE); const OffsetIndices points_by_curve = curves.points_by_curve(); - const VArray vgroup_weights = get_grease_pencil_modifier_vertex_weights(curves, - omd.influence); bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); bke::SpanAttributeWriter opacities = attributes.lookup_or_add_for_write_span( "opacity", bke::AttrDomain::Point); + const bke::AttributeReader vgroup_weights = attributes.lookup_or_default( + omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f); for (const int64_t i : curves_mask.index_range()) { const int64_t curve_i = curves_mask[i]; @@ -121,14 +113,14 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, } else if (use_weight_as_factor) { /* Use vertex group weights as opacity factors. */ - const float vgroup_weight = vgroup_weights[point_i]; + const float vgroup_weight = vgroup_weights.varray[point_i]; const float point_factor = vgroup_weight; opacities.span[point_i] = std::clamp( omd.color_factor * curve_factor * point_factor, 0.0f, 1.0f); } else { /* Use vertex group weights as influence factors. */ - const float vgroup_weight = vgroup_weights[point_i]; + const float vgroup_weight = vgroup_weights.varray[point_i]; const float vgroup_influence = invert_vertex_group ? 1.0f - vgroup_weight : vgroup_weight; opacities.span[point_i] = std::clamp( opacities.span[point_i] + omd.color_factor * curve_factor * vgroup_influence - 1.0f, @@ -149,13 +141,13 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd, const bool invert_vertex_group = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP); const OffsetIndices points_by_curve = curves.points_by_curve(); - const VArray vgroup_weights = get_grease_pencil_modifier_vertex_weights(curves, - omd.influence); bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); /* Fill color opacity per stroke. */ bke::SpanAttributeWriter fill_opacities = attributes.lookup_or_add_for_write_span( "fill_opacity", bke::AttrDomain::Curve); + bke::AttributeReader vgroup_weights = attributes.lookup_or_default( + omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f); for (const int64_t i : curves_mask.index_range()) { const int64_t curve_i = curves_mask[i]; @@ -163,8 +155,9 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd, if (use_vgroup_opacity) { /* Use the first stroke point as vertex weight. */ const IndexRange points_range = points_by_curve[curve_i]; - const float stroke_weight = points_range.is_empty() ? 1.0f : - vgroup_weights[points_range.first()]; + const float stroke_weight = points_range.is_empty() ? + 1.0f : + vgroup_weights.varray[points_range.first()]; const float stroke_influence = invert_vertex_group ? 1.0f - stroke_weight : stroke_weight; fill_opacities.span[curve_i] = std::clamp(stroke_influence, 0.0f, 1.0f); -- 2.30.2 From dc1961e7982e59e65a8834ea91cc75e749b6a203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 12:10:50 +0100 Subject: [PATCH 32/45] points_range -> points --- .../intern/MOD_grease_pencil_opacity.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index f17333e6e7e..3c56dbc87b0 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -99,11 +99,11 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, for (const int64_t i : curves_mask.index_range()) { const int64_t curve_i = curves_mask[i]; - const IndexRange points_range = points_by_curve[curve_i]; - for (const int64_t point_i : points_range) { - const float curve_input = points_range.size() >= 2 ? (float(point_i - points_range.first()) / - float(points_range.size() - 1)) : - 0.0f; + const IndexRange points = points_by_curve[curve_i]; + for (const int64_t point_i : points) { + const float curve_input = points.size() >= 2 ? + (float(point_i - points.first()) / float(points.size() - 1)) : + 0.0f; const float curve_factor = use_curve ? BKE_curvemapping_evaluateF( omd.influence.custom_curve, 0, curve_input) : 1.0f; @@ -154,10 +154,8 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd, if (use_vgroup_opacity) { /* Use the first stroke point as vertex weight. */ - const IndexRange points_range = points_by_curve[curve_i]; - const float stroke_weight = points_range.is_empty() ? - 1.0f : - vgroup_weights.varray[points_range.first()]; + const IndexRange points = points_by_curve[curve_i]; + const float stroke_weight = points.is_empty() ? 1.0f : vgroup_weights.varray[points.first()]; const float stroke_influence = invert_vertex_group ? 1.0f - stroke_weight : stroke_weight; fill_opacities.span[curve_i] = std::clamp(stroke_influence, 0.0f, 1.0f); -- 2.30.2 From d600c0f5aca5c6790df86bf5ef850396dba78bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 12:23:35 +0100 Subject: [PATCH 33/45] Skip hardness modulation if the attribute does not exist. --- .../blender/modifiers/intern/MOD_grease_pencil_opacity.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 3c56dbc87b0..7407090bf44 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -173,8 +173,10 @@ static void modify_hardness(const GreasePencilOpacityModifierData &omd, const IndexMask &curves_mask) { bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); - bke::SpanAttributeWriter hardnesses = attributes.lookup_or_add_for_write_span( - "hardness", bke::AttrDomain::Curve); + bke::SpanAttributeWriter hardnesses = attributes.lookup_for_write_span("hardness"); + if (!hardnesses) { + return; + } for (const int64_t i : curves_mask.index_range()) { const int64_t curve_i = curves_mask[i]; -- 2.30.2 From e5e2647e46722be787202351ae4bb31a7c1cb153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 12:27:05 +0100 Subject: [PATCH 34/45] C++ style casts. --- .../intern/MOD_grease_pencil_opacity.cc | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 7407090bf44..dff112531ac 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -47,7 +47,7 @@ using bke::greasepencil::Layer; static void init_data(ModifierData *md) { - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + GreasePencilOpacityModifierData *omd = reinterpret_cast(md); BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(omd, modifier)); @@ -57,8 +57,10 @@ static void init_data(ModifierData *md) static void copy_data(const ModifierData *md, ModifierData *target, const int flag) { - const GreasePencilOpacityModifierData *omd = (const GreasePencilOpacityModifierData *)md; - GreasePencilOpacityModifierData *tomd = (GreasePencilOpacityModifierData *)target; + const GreasePencilOpacityModifierData *omd = + reinterpret_cast(md); + GreasePencilOpacityModifierData *tomd = reinterpret_cast( + target); greasepencil::free_influence_data(&tomd->influence); @@ -68,14 +70,13 @@ static void copy_data(const ModifierData *md, ModifierData *target, const int fl static void free_data(ModifierData *md) { - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; - + GreasePencilOpacityModifierData *omd = reinterpret_cast(md); greasepencil::free_influence_data(&omd->influence); } static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data) { - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + GreasePencilOpacityModifierData *omd = reinterpret_cast(md); greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data); } @@ -191,7 +192,7 @@ static void modify_curves(ModifierData *md, const ModifierEvalContext *ctx, bke::CurvesGeometry &curves) { - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + GreasePencilOpacityModifierData *omd = reinterpret_cast(md); IndexMaskMemory mask_memory; IndexMask curves_mask = greasepencil::get_filtered_stroke_mask( @@ -218,7 +219,7 @@ static void modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set) { - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + GreasePencilOpacityModifierData *omd = reinterpret_cast(md); const Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); const int frame = scene->r.cfra; @@ -290,7 +291,8 @@ static void panel_register(ARegionType *region_type) static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md) { - const GreasePencilOpacityModifierData *omd = (const GreasePencilOpacityModifierData *)md; + const GreasePencilOpacityModifierData *omd = + reinterpret_cast(md); BLO_write_struct(writer, GreasePencilOpacityModifierData, omd); greasepencil::write_influence_data(writer, &omd->influence); @@ -298,7 +300,7 @@ static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const Modi static void blend_read(BlendDataReader *reader, ModifierData *md) { - GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md; + GreasePencilOpacityModifierData *omd = reinterpret_cast(md); greasepencil::read_influence_data(reader, &omd->influence); } -- 2.30.2 From 0e9a03886c7ec7823ece133691b1d6254df7fe0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 14:32:22 +0100 Subject: [PATCH 35/45] Use `blender::modifier::greasepencil` namespace. --- .../intern/MOD_grease_pencil_opacity.cc | 28 +++++++++---------- .../intern/MOD_grease_pencil_util.cc | 4 +-- .../intern/MOD_grease_pencil_util.hh | 4 +-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index dff112531ac..d7e767bfc81 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -52,7 +52,7 @@ static void init_data(ModifierData *md) BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(omd, modifier)); MEMCPY_STRUCT_AFTER(omd, DNA_struct_default_get(GreasePencilOpacityModifierData), modifier); - greasepencil::init_influence_data(&omd->influence, true); + modifier::greasepencil::init_influence_data(&omd->influence, true); } static void copy_data(const ModifierData *md, ModifierData *target, const int flag) @@ -62,22 +62,22 @@ static void copy_data(const ModifierData *md, ModifierData *target, const int fl GreasePencilOpacityModifierData *tomd = reinterpret_cast( target); - greasepencil::free_influence_data(&tomd->influence); + modifier::greasepencil::free_influence_data(&tomd->influence); BKE_modifier_copydata_generic(md, target, flag); - greasepencil::copy_influence_data(&omd->influence, &tomd->influence, flag); + modifier::greasepencil::copy_influence_data(&omd->influence, &tomd->influence, flag); } static void free_data(ModifierData *md) { GreasePencilOpacityModifierData *omd = reinterpret_cast(md); - greasepencil::free_influence_data(&omd->influence); + modifier::greasepencil::free_influence_data(&omd->influence); } static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data) { GreasePencilOpacityModifierData *omd = reinterpret_cast(md); - greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data); + modifier::greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data); } static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, @@ -195,7 +195,7 @@ static void modify_curves(ModifierData *md, GreasePencilOpacityModifierData *omd = reinterpret_cast(md); IndexMaskMemory mask_memory; - IndexMask curves_mask = greasepencil::get_filtered_stroke_mask( + IndexMask curves_mask = modifier::greasepencil::get_filtered_stroke_mask( ctx->object, curves, omd->influence, mask_memory); switch (omd->color_mode) { @@ -229,9 +229,9 @@ static void modify_geometry_set(ModifierData *md, } IndexMaskMemory mask_memory; - IndexMask layer_mask = greasepencil::get_filtered_layer_mask( + IndexMask layer_mask = modifier::greasepencil::get_filtered_layer_mask( *grease_pencil, omd->influence, mask_memory); - Vector drawings = greasepencil::get_drawings_for_write( + Vector drawings = modifier::greasepencil::get_drawings_for_write( *grease_pencil, layer_mask, frame); for (Drawing *drawing : drawings) { modify_curves(md, ctx, drawing->strokes_for_write()); @@ -275,10 +275,10 @@ static void panel_draw(const bContext *C, Panel *panel) if (uiLayout *influence_panel = uiLayoutPanel( C, layout, "Influence", ptr, "open_influence_panel")) { - greasepencil::draw_layer_filter_settings(C, influence_panel, ptr); - greasepencil::draw_material_filter_settings(C, influence_panel, ptr); - greasepencil::draw_vertex_group_settings(C, influence_panel, ptr); - greasepencil::draw_custom_curve_settings(C, influence_panel, ptr); + modifier::greasepencil::draw_layer_filter_settings(C, influence_panel, ptr); + modifier::greasepencil::draw_material_filter_settings(C, influence_panel, ptr); + modifier::greasepencil::draw_vertex_group_settings(C, influence_panel, ptr); + modifier::greasepencil::draw_custom_curve_settings(C, influence_panel, ptr); } modifier_panel_end(layout, ptr); @@ -295,14 +295,14 @@ static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const Modi reinterpret_cast(md); BLO_write_struct(writer, GreasePencilOpacityModifierData, omd); - greasepencil::write_influence_data(writer, &omd->influence); + modifier::greasepencil::write_influence_data(writer, &omd->influence); } static void blend_read(BlendDataReader *reader, ModifierData *md) { GreasePencilOpacityModifierData *omd = reinterpret_cast(md); - greasepencil::read_influence_data(reader, &omd->influence); + modifier::greasepencil::read_influence_data(reader, &omd->influence); } } // namespace blender diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 343e249bb25..9910c9d64e0 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -34,7 +34,7 @@ #include "UI_interface.hh" -namespace blender::greasepencil { +namespace blender::modifier::greasepencil { using bke::greasepencil::Drawing; using bke::greasepencil::Layer; @@ -332,4 +332,4 @@ Vector get_drawings_for_write(GreasePencil &grease return drawings; } -} // namespace blender::greasepencil +} // namespace blender::modifier::greasepencil diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index 0e0f7668e07..76c0b3e1561 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -29,7 +29,7 @@ class Drawing; } } // namespace blender::bke -namespace blender::greasepencil { +namespace blender::modifier::greasepencil { void init_influence_data(GreasePencilModifierInfluenceData *influence_data, bool has_custom_curve); void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, @@ -63,4 +63,4 @@ Vector get_drawings_for_write(GreasePencil &grease const IndexMask &layer_mask, int frame); -} // namespace blender::greasepencil +} // namespace blender::modifier::greasepencil -- 2.30.2 From e3fd2127f0a9d27b06a5ef9d9ded1c44666bf824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 14:50:22 +0100 Subject: [PATCH 36/45] Remove redundant local variables. --- source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index d7e767bfc81..d3fe23266a2 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -114,10 +114,8 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, } else if (use_weight_as_factor) { /* Use vertex group weights as opacity factors. */ - const float vgroup_weight = vgroup_weights.varray[point_i]; - const float point_factor = vgroup_weight; opacities.span[point_i] = std::clamp( - omd.color_factor * curve_factor * point_factor, 0.0f, 1.0f); + omd.color_factor * curve_factor * vgroup_weights.varray[point_i], 0.0f, 1.0f); } else { /* Use vertex group weights as influence factors. */ -- 2.30.2 From abd248fa5efc009863ca150aa1b78a01562f2e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 15:18:52 +0100 Subject: [PATCH 37/45] Use parallel loops for drawings and curves. --- .../intern/MOD_grease_pencil_opacity.cc | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index d3fe23266a2..10600160ae6 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -97,9 +97,7 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, const bke::AttributeReader vgroup_weights = attributes.lookup_or_default( omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f); - for (const int64_t i : curves_mask.index_range()) { - const int64_t curve_i = curves_mask[i]; - + curves_mask.foreach_index(GrainSize(512), [&](const int64_t curve_i) { const IndexRange points = points_by_curve[curve_i]; for (const int64_t point_i : points) { const float curve_input = points.size() >= 2 ? @@ -127,7 +125,7 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, 1.0f); } } - } + }); opacities.finish(); } @@ -148,9 +146,7 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd, bke::AttributeReader vgroup_weights = attributes.lookup_or_default( omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f); - for (const int64_t i : curves_mask.index_range()) { - const int64_t curve_i = curves_mask[i]; - + curves_mask.foreach_index(GrainSize(512), [&](int64_t curve_i) { if (use_vgroup_opacity) { /* Use the first stroke point as vertex weight. */ const IndexRange points = points_by_curve[curve_i]; @@ -162,7 +158,7 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd, else { fill_opacities.span[curve_i] = std::clamp(omd.color_factor, 0.0f, 1.0f); } - } + }); fill_opacities.finish(); } @@ -177,11 +173,10 @@ static void modify_hardness(const GreasePencilOpacityModifierData &omd, return; } - for (const int64_t i : curves_mask.index_range()) { - const int64_t curve_i = curves_mask[i]; + curves_mask.foreach_index(GrainSize(512), [&](int64_t curve_i) { hardnesses.span[curve_i] = std::clamp( hardnesses.span[curve_i] * omd.hardness_factor, 0.0f, 1.0f); - } + }); hardnesses.finish(); } @@ -231,9 +226,9 @@ static void modify_geometry_set(ModifierData *md, *grease_pencil, omd->influence, mask_memory); Vector drawings = modifier::greasepencil::get_drawings_for_write( *grease_pencil, layer_mask, frame); - for (Drawing *drawing : drawings) { - modify_curves(md, ctx, drawing->strokes_for_write()); - } + threading::parallel_for_each(drawings.index_range(), [&](int64_t i) { + modify_curves(md, ctx, drawings[i]->strokes_for_write()); + }); } static void panel_draw(const bContext *C, Panel *panel) -- 2.30.2 From aec063e8e7abc1b083c22d56c6c330012bccdff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 15:29:22 +0100 Subject: [PATCH 38/45] Removed unused line. --- scripts/startup/bl_ui/properties_data_modifier.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/startup/bl_ui/properties_data_modifier.py b/scripts/startup/bl_ui/properties_data_modifier.py index fdc198b5e3b..7d046148de7 100644 --- a/scripts/startup/bl_ui/properties_data_modifier.py +++ b/scripts/startup/bl_ui/properties_data_modifier.py @@ -46,7 +46,6 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): def draw(self, _context): layout = self.layout - ob_type = _context.object.type layout.operator("wm.call_menu", text="Add Modifier", icon='ADD').name = "OBJECT_MT_modifier_add" layout.template_modifiers() -- 2.30.2 From 50ca30a504a336d769be8c0110fec5be2b8c0b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 15:40:36 +0100 Subject: [PATCH 39/45] Revert incorrect clang-format changes. --- source/blender/makesdna/DNA_modifier_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index e3028b31fca..7bc475c24f1 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -152,8 +152,8 @@ typedef enum { */ eModifierFlag_Active = (1 << 2), /** - * Only set on modifiers in evaluated objects. The flag indicates that the user modified - * inputs to the modifier which might invalidate simulation caches. + * Only set on modifiers in evaluated objects. The flag indicates that the user modified inputs + * to the modifier which might invalidate simulation caches. */ eModifierFlag_UserModified = (1 << 3), } ModifierFlag; -- 2.30.2 From a216b35b51f98dd9fcda70e7fe6c89f0fa97ef30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 16:10:10 +0100 Subject: [PATCH 40/45] Update description of opacity modifier. --- source/blender/makesrna/intern/rna_modifier.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index 0da7113f414..f6d2cd82a97 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -104,7 +104,7 @@ const EnumPropertyItem rna_enum_object_modifier_type_items[] = { "GREASE_PENCIL_OPACITY", ICON_MOD_OPACITY, "Opacity", - "Opacity of the strokes"}, + "Change the opacity of the strokes"}, RNA_ENUM_ITEM_HEADING(N_("Generate"), nullptr), {eModifierType_Array, -- 2.30.2 From 3ae79ab53c78161c7585626bb52f73a73ed95427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 16:11:58 +0100 Subject: [PATCH 41/45] Update copyright notices. --- source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc | 2 +- source/blender/modifiers/intern/MOD_grease_pencil_util.cc | 2 +- source/blender/modifiers/intern/MOD_grease_pencil_util.hh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 10600160ae6..0d9b0200f91 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: 2005 Blender Authors +/* SPDX-FileCopyrightText: 2024 Blender Authors * * SPDX-License-Identifier: GPL-2.0-or-later */ diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 9910c9d64e0..2419061d4a7 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: 2011 by Bastien Montagne. All rights reserved. +/* SPDX-FileCopyrightText: 2024 Blender Authors * * SPDX-License-Identifier: GPL-2.0-or-later */ diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh index 76c0b3e1561..9652ff47e0d 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.hh +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.hh @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: 2011 by Bastien Montagne. All rights reserved. +/* SPDX-FileCopyrightText: 2024 Blender Authors * * SPDX-License-Identifier: GPL-2.0-or-later */ -- 2.30.2 From 11f54b0817b2f02b78a9b98beafa241c7c5e991a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 16:13:20 +0100 Subject: [PATCH 42/45] Use auto to shorten modifier cast. --- .../intern/MOD_grease_pencil_opacity.cc | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index 0d9b0200f91..d0a8d65fb52 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -47,7 +47,7 @@ using bke::greasepencil::Layer; static void init_data(ModifierData *md) { - GreasePencilOpacityModifierData *omd = reinterpret_cast(md); + auto *omd = reinterpret_cast(md); BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(omd, modifier)); @@ -57,10 +57,8 @@ static void init_data(ModifierData *md) static void copy_data(const ModifierData *md, ModifierData *target, const int flag) { - const GreasePencilOpacityModifierData *omd = - reinterpret_cast(md); - GreasePencilOpacityModifierData *tomd = reinterpret_cast( - target); + const auto *omd = reinterpret_cast(md); + auto *tomd = reinterpret_cast(target); modifier::greasepencil::free_influence_data(&tomd->influence); @@ -70,13 +68,13 @@ static void copy_data(const ModifierData *md, ModifierData *target, const int fl static void free_data(ModifierData *md) { - GreasePencilOpacityModifierData *omd = reinterpret_cast(md); + auto *omd = reinterpret_cast(md); modifier::greasepencil::free_influence_data(&omd->influence); } static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data) { - GreasePencilOpacityModifierData *omd = reinterpret_cast(md); + auto *omd = reinterpret_cast(md); modifier::greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data); } @@ -185,7 +183,7 @@ static void modify_curves(ModifierData *md, const ModifierEvalContext *ctx, bke::CurvesGeometry &curves) { - GreasePencilOpacityModifierData *omd = reinterpret_cast(md); + auto *omd = reinterpret_cast(md); IndexMaskMemory mask_memory; IndexMask curves_mask = modifier::greasepencil::get_filtered_stroke_mask( @@ -212,7 +210,7 @@ static void modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set) { - GreasePencilOpacityModifierData *omd = reinterpret_cast(md); + auto *omd = reinterpret_cast(md); const Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); const int frame = scene->r.cfra; @@ -284,8 +282,7 @@ static void panel_register(ARegionType *region_type) static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md) { - const GreasePencilOpacityModifierData *omd = - reinterpret_cast(md); + const auto *omd = reinterpret_cast(md); BLO_write_struct(writer, GreasePencilOpacityModifierData, omd); modifier::greasepencil::write_influence_data(writer, &omd->influence); @@ -293,7 +290,7 @@ static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const Modi static void blend_read(BlendDataReader *reader, ModifierData *md) { - GreasePencilOpacityModifierData *omd = reinterpret_cast(md); + auto *omd = reinterpret_cast(md); modifier::greasepencil::read_influence_data(reader, &omd->influence); } -- 2.30.2 From 5fb3351d0f8d4bf7b2a9203ffead6572b8835974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 16:15:42 +0100 Subject: [PATCH 43/45] VArray local variable instead of AttributeReader. --- .../intern/MOD_grease_pencil_opacity.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc index d0a8d65fb52..52d31d7bc06 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_opacity.cc @@ -92,8 +92,10 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); bke::SpanAttributeWriter opacities = attributes.lookup_or_add_for_write_span( "opacity", bke::AttrDomain::Point); - const bke::AttributeReader vgroup_weights = attributes.lookup_or_default( - omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f); + const VArray vgroup_weights = + attributes + .lookup_or_default(omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f) + .varray; curves_mask.foreach_index(GrainSize(512), [&](const int64_t curve_i) { const IndexRange points = points_by_curve[curve_i]; @@ -111,11 +113,11 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd, else if (use_weight_as_factor) { /* Use vertex group weights as opacity factors. */ opacities.span[point_i] = std::clamp( - omd.color_factor * curve_factor * vgroup_weights.varray[point_i], 0.0f, 1.0f); + omd.color_factor * curve_factor * vgroup_weights[point_i], 0.0f, 1.0f); } else { /* Use vertex group weights as influence factors. */ - const float vgroup_weight = vgroup_weights.varray[point_i]; + const float vgroup_weight = vgroup_weights[point_i]; const float vgroup_influence = invert_vertex_group ? 1.0f - vgroup_weight : vgroup_weight; opacities.span[point_i] = std::clamp( opacities.span[point_i] + omd.color_factor * curve_factor * vgroup_influence - 1.0f, @@ -141,14 +143,17 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd, /* Fill color opacity per stroke. */ bke::SpanAttributeWriter fill_opacities = attributes.lookup_or_add_for_write_span( "fill_opacity", bke::AttrDomain::Curve); - bke::AttributeReader vgroup_weights = attributes.lookup_or_default( - omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f); + VArray vgroup_weights = attributes + .lookup_or_default(omd.influence.vertex_group_name, + bke::AttrDomain::Point, + 1.0f) + .varray; curves_mask.foreach_index(GrainSize(512), [&](int64_t curve_i) { if (use_vgroup_opacity) { /* Use the first stroke point as vertex weight. */ const IndexRange points = points_by_curve[curve_i]; - const float stroke_weight = points.is_empty() ? 1.0f : vgroup_weights.varray[points.first()]; + const float stroke_weight = points.is_empty() ? 1.0f : vgroup_weights[points.first()]; const float stroke_influence = invert_vertex_group ? 1.0f - stroke_weight : stroke_weight; fill_opacities.span[curve_i] = std::clamp(stroke_influence, 0.0f, 1.0f); -- 2.30.2 From 3fec3e5471c14549e59b4fa47b3432fbac43816d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 16:46:40 +0100 Subject: [PATCH 44/45] Remove layout decorators from correct row layouts for alignment. --- source/blender/modifiers/intern/MOD_grease_pencil_util.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index 2419061d4a7..a4d75e25373 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -102,9 +102,9 @@ void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, Pointe col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); + uiLayoutSetPropDecorate(row, false); uiItemPointerR(row, ptr, "layer_filter", &obj_data_ptr, "layers", nullptr, ICON_GREASEPENCIL); sub = uiLayoutRow(row, true); - uiLayoutSetPropDecorate(sub, false); uiItemR(sub, ptr, "invert_layer_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); row = uiLayoutRowWithHeading(col, true, "Layer Pass Filter"); @@ -115,7 +115,6 @@ void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, Pointe uiLayoutSetActive(subsub, use_layer_pass); uiItemR(subsub, ptr, "layer_pass_filter", UI_ITEM_NONE, "", ICON_NONE); uiItemR(subsub, ptr, "invert_layer_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); - uiLayoutSetPropDecorate(sub, true); } void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) @@ -129,10 +128,10 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi col = uiLayoutColumn(layout, true); row = uiLayoutRow(col, true); + uiLayoutSetPropDecorate(row, false); uiItemPointerR( row, ptr, "material_filter", &obj_data_ptr, "materials", nullptr, ICON_SHADING_TEXTURE); sub = uiLayoutRow(row, true); - uiLayoutSetPropDecorate(sub, false); uiItemR(sub, ptr, "invert_material_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); row = uiLayoutRowWithHeading(col, true, "Material Pass Filter"); @@ -143,7 +142,6 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi uiLayoutSetActive(subsub, use_material_pass); uiItemR(subsub, ptr, "material_pass_filter", UI_ITEM_NONE, "", ICON_NONE); uiItemR(subsub, ptr, "invert_material_pass_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); - uiLayoutSetPropDecorate(sub, true); } void draw_vertex_group_settings(const bContext * /*C*/, uiLayout *layout, PointerRNA *ptr) -- 2.30.2 From 5fdae3d54ab67fadec20554282237b3ae57df1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 16 Jan 2024 16:54:01 +0100 Subject: [PATCH 45/45] Simplified some UI labels and RNA UI names. --- source/blender/makesrna/intern/rna_modifier.cc | 4 ++-- source/blender/modifiers/intern/MOD_grease_pencil_util.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index f6d2cd82a97..3b6306e3852 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -7581,7 +7581,7 @@ static void rna_def_modifier_grease_pencil_vertex_group(StructRNA *srna, prop = RNA_def_property(srna, "vertex_group_name", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, nullptr, "influence.vertex_group_name"); - RNA_def_property_ui_text(prop, "Name", "Vertex group name for modulating the deform"); + RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group name for modulating the deform"); RNA_def_property_string_funcs(prop, nullptr, nullptr, vertex_group_name_set_fn); RNA_def_property_update(prop, 0, "rna_Modifier_update"); @@ -7645,7 +7645,7 @@ static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna) prop = RNA_def_property(srna, "color_mode", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, color_mode_items); - RNA_def_property_ui_text(prop, "Color Mode", "Attributes to modify"); + RNA_def_property_ui_text(prop, "Mode", "Attributes to modify"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "color_factor", PROP_FLOAT, PROP_NONE); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc index a4d75e25373..fdb2e4c496b 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_util.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_util.cc @@ -107,7 +107,7 @@ void draw_layer_filter_settings(const bContext * /*C*/, uiLayout *layout, Pointe sub = uiLayoutRow(row, true); uiItemR(sub, ptr, "invert_layer_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); - row = uiLayoutRowWithHeading(col, true, "Layer Pass Filter"); + row = uiLayoutRowWithHeading(col, true, "Layer Pass"); uiLayoutSetPropDecorate(row, false); sub = uiLayoutRow(row, true); uiItemR(sub, ptr, "use_layer_pass_filter", UI_ITEM_NONE, "", ICON_NONE); @@ -134,7 +134,7 @@ void draw_material_filter_settings(const bContext * /*C*/, uiLayout *layout, Poi sub = uiLayoutRow(row, true); uiItemR(sub, ptr, "invert_material_filter", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT); - row = uiLayoutRowWithHeading(col, true, "Material Pass Filter"); + row = uiLayoutRowWithHeading(col, true, "Material Pass"); uiLayoutSetPropDecorate(row, false); sub = uiLayoutRow(row, true); uiItemR(sub, ptr, "use_material_pass_filter", UI_ITEM_NONE, "", ICON_NONE); -- 2.30.2