Cleanup: GPv3: Small tweaks to modifiers

- Fix modifier icon
- Remove unused includes
- Remove unused argument
- Change function name
- Use `eval_frame` for retrieving drawings
- Avoid unnecessary cast
- Remove unnecessary parentheses
- Declare some variables const

Pull Request: https://projects.blender.org/blender/blender/pulls/117281
This commit is contained in:
Hans Goudey 2024-01-18 16:29:03 +01:00 committed by Hans Goudey
parent f0f1afd250
commit 290b417998
3 changed files with 18 additions and 41 deletions

@ -203,7 +203,7 @@ const EnumPropertyItem rna_enum_object_modifier_type_items[] = {
"Convert faces into thickened edges"},
{eModifierType_GreasePencilSubdiv,
"GREASEPENCIL_SUBDIV",
ICON_GREASEPENCIL,
ICON_MOD_SUBSURF,
"Subdivide strokes",
"Grease Pencil subdivide modifier"},

@ -20,8 +20,6 @@
#include "BLO_read_write.hh"
#include "DEG_depsgraph_query.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
@ -143,11 +141,9 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd,
/* Fill color opacity per stroke. */
bke::SpanAttributeWriter<float> fill_opacities = attributes.lookup_or_add_for_write_span<float>(
"fill_opacity", bke::AttrDomain::Curve);
VArray<float> vgroup_weights = attributes
.lookup_or_default<float>(omd.influence.vertex_group_name,
bke::AttrDomain::Point,
1.0f)
.varray;
const StringRef vgroup_name = omd.influence.vertex_group_name;
const VArray<float> vgroup_weights =
attributes.lookup_or_default<float>(vgroup_name, bke::AttrDomain::Point, 1.0f).varray;
curves_mask.foreach_index(GrainSize(512), [&](int64_t curve_i) {
if (use_vgroup_opacity) {
@ -188,10 +184,10 @@ static void modify_curves(ModifierData *md,
const ModifierEvalContext *ctx,
bke::CurvesGeometry &curves)
{
auto *omd = reinterpret_cast<GreasePencilOpacityModifierData *>(md);
const auto *omd = reinterpret_cast<GreasePencilOpacityModifierData *>(md);
IndexMaskMemory mask_memory;
IndexMask curves_mask = modifier::greasepencil::get_filtered_stroke_mask(
const IndexMask curves_mask = modifier::greasepencil::get_filtered_stroke_mask(
ctx->object, curves, omd->influence, mask_memory);
switch (omd->color_mode) {
@ -215,9 +211,7 @@ static void modify_geometry_set(ModifierData *md,
const ModifierEvalContext *ctx,
bke::GeometrySet *geometry_set)
{
auto *omd = reinterpret_cast<GreasePencilOpacityModifierData *>(md);
const Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
const int frame = scene->r.cfra;
const auto *omd = reinterpret_cast<GreasePencilOpacityModifierData *>(md);
GreasePencil *grease_pencil = geometry_set->get_grease_pencil_for_write();
if (grease_pencil == nullptr) {
@ -225,9 +219,10 @@ static void modify_geometry_set(ModifierData *md,
}
IndexMaskMemory mask_memory;
IndexMask layer_mask = modifier::greasepencil::get_filtered_layer_mask(
const IndexMask layer_mask = modifier::greasepencil::get_filtered_layer_mask(
*grease_pencil, omd->influence, mask_memory);
Vector<Drawing *> drawings = modifier::greasepencil::get_drawings_for_write(
const int frame = grease_pencil->runtime->eval_frame;
const Vector<Drawing *> drawings = modifier::greasepencil::get_drawings_for_write(
*grease_pencil, layer_mask, frame);
threading::parallel_for_each(
drawings, [&](Drawing *drawing) { modify_curves(md, ctx, drawing->strokes_for_write()); });
@ -309,9 +304,8 @@ ModifierTypeInfo modifierType_GreasePencilOpacity = {
/*srna*/ &RNA_GreasePencilOpacityModifier,
/*type*/ ModifierTypeType::Nonconstructive,
/*flags*/
static_cast<ModifierTypeFlag>(
eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode |
eModifierTypeFlag_EnableInEditmode | eModifierTypeFlag_SupportsMapping),
eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode |
eModifierTypeFlag_EnableInEditmode | eModifierTypeFlag_SupportsMapping,
/*icon*/ ICON_MOD_OPACITY,
/*copy_data*/ blender::copy_data,

@ -6,11 +6,7 @@
* \ingroup modifiers
*/
#include "BLI_array.hh"
#include "BLI_index_mask.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
@ -18,33 +14,23 @@
#include "DNA_defaults.h"
#include "DNA_modifier_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "BKE_context.hh"
#include "BKE_curves.hh"
#include "BKE_geometry_set.hh"
#include "BKE_grease_pencil.hh"
#include "BKE_lib_query.hh"
#include "BKE_modifier.hh"
#include "BKE_screen.hh"
#include "GEO_subdivide_curves.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "ED_grease_pencil.hh"
#include "MOD_grease_pencil_util.hh"
#include "MOD_modifiertypes.hh"
#include "MOD_ui_common.hh"
#include "RNA_prototypes.h"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
namespace blender {
static void init_data(ModifierData *md)
@ -91,10 +77,7 @@ static void blend_read(BlendDataReader *reader, ModifierData *md)
modifier::greasepencil::read_influence_data(reader, &mmd->influence);
}
static void deform_drawing(ModifierData &md,
Depsgraph * /*depsgraph*/,
Object &ob,
bke::greasepencil::Drawing &drawing)
static void subdivide_drawing(ModifierData &md, Object &ob, bke::greasepencil::Drawing &drawing)
{
GreasePencilSubdivModifierData &mmd = reinterpret_cast<GreasePencilSubdivModifierData &>(md);
@ -102,7 +85,7 @@ static void deform_drawing(ModifierData &md,
const IndexMask strokes = modifier::greasepencil::get_filtered_stroke_mask(
&ob, drawing.strokes_for_write(), mmd.influence, memory);
VArray<int> cuts = VArray<int>::ForSingle(mmd.level, drawing.strokes().points_num());
const VArray<int> cuts = VArray<int>::ForSingle(mmd.level, drawing.strokes().points_num());
drawing.strokes_for_write() = geometry::subdivide_curves(
drawing.strokes(), strokes, std::move(cuts), {});
@ -120,7 +103,7 @@ static void modify_geometry_set(ModifierData *md,
}
GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();
const int current_frame = DEG_get_evaluated_scene(ctx->depsgraph)->r.cfra;
const int current_frame = grease_pencil.runtime->eval_frame;
IndexMaskMemory mask_memory;
const IndexMask layer_mask = modifier::greasepencil::get_filtered_layer_mask(
@ -129,7 +112,7 @@ static void modify_geometry_set(ModifierData *md,
modifier::greasepencil::get_drawings_for_write(grease_pencil, layer_mask, current_frame);
threading::parallel_for_each(drawings, [&](bke::greasepencil::Drawing *drawing) {
deform_drawing(*md, ctx->depsgraph, *ctx->object, *drawing);
subdivide_drawing(*md, *ctx->object, *drawing);
});
}
@ -176,8 +159,8 @@ ModifierTypeInfo modifierType_GreasePencilSubdiv = {
/*srna*/ &RNA_GreasePencilSubdivModifier,
/*type*/ ModifierTypeType::Constructive,
/*flags*/
(eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode |
eModifierTypeFlag_EnableInEditmode),
eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode |
eModifierTypeFlag_EnableInEditmode,
/*icon*/ ICON_MOD_SUBSURF,
/*copy_data*/ blender::copy_data,