Blender V4.3
MOD_grease_pencil_smooth.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_index_mask.hh"
10
11#include "BLT_translation.hh"
12
13#include "BLO_read_write.hh"
14
15#include "DNA_defaults.h"
16#include "DNA_modifier_types.h"
17#include "DNA_screen_types.h"
18
19#include "RNA_access.hh"
20
21#include "BKE_curves.hh"
22#include "BKE_geometry_set.hh"
23#include "BKE_grease_pencil.hh"
24#include "BKE_modifier.hh"
25
26#include "UI_interface.hh"
27#include "UI_resources.hh"
28
29#include "GEO_smooth_curves.hh"
30
32#include "MOD_ui_common.hh"
33
34#include "RNA_prototypes.hh"
35
36namespace blender {
37
47
48static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
49{
51 reinterpret_cast<const GreasePencilSmoothModifierData *>(md);
53 target);
54
57}
58
65
66static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
67{
69
71}
72
73static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md)
74{
76 reinterpret_cast<const GreasePencilSmoothModifierData *>(md);
77
80}
81
87
88static void deform_drawing(const ModifierData &md,
89 const Object &ob,
91{
92 auto &mmd = reinterpret_cast<const GreasePencilSmoothModifierData &>(md);
93
94 const int iterations = mmd.step;
95 const float influence = mmd.factor;
96 const bool keep_shape = (mmd.flag & MOD_GREASE_PENCIL_SMOOTH_KEEP_SHAPE);
97 const bool smooth_ends = (mmd.flag & MOD_GREASE_PENCIL_SMOOTH_SMOOTH_ENDS);
98
99 const bool smooth_position = (mmd.flag & MOD_GREASE_PENCIL_SMOOTH_MOD_LOCATION);
100 const bool smooth_radius = (mmd.flag & MOD_GREASE_PENCIL_SMOOTH_MOD_THICKNESS);
101 const bool smooth_opacity = (mmd.flag & MOD_GREASE_PENCIL_SMOOTH_MOD_STRENGTH);
102 const bool smooth_uv = (mmd.flag & MOD_GREASE_PENCIL_SMOOTH_MOD_UV);
103
104 if (iterations <= 0 || influence <= 0.0f) {
105 return;
106 }
107
108 if (!(smooth_position || smooth_radius || smooth_opacity || smooth_uv)) {
109 return;
110 }
111
113 bke::CurvesGeometry &curves = drawing.strokes_for_write();
114 if (curves.points_num() == 0) {
115 return;
116 }
117
118 IndexMaskMemory memory;
120 &ob, curves, mmd.influence, memory);
121
122 if (strokes.is_empty()) {
123 return;
124 }
125
126 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
127 const OffsetIndices points_by_curve = curves.points_by_curve();
128 const VArray<bool> cyclic = curves.cyclic();
129 const VArray<bool> point_selection = VArray<bool>::ForSingle(true, curves.points_num());
130
131 if (smooth_position) {
132 bke::GSpanAttributeWriter positions = attributes.lookup_for_write_span("position");
134 points_by_curve,
135 point_selection,
136 cyclic,
137 iterations,
138 influence,
139 smooth_ends,
140 keep_shape,
141 positions.span);
142 positions.finish();
143 drawing.tag_positions_changed();
144 }
145 if (smooth_opacity && drawing.opacities().is_span()) {
146 bke::GSpanAttributeWriter opacities = attributes.lookup_for_write_span("opacity");
148 points_by_curve,
149 point_selection,
150 cyclic,
151 iterations,
152 influence,
153 smooth_ends,
154 false,
155 opacities.span);
156 opacities.finish();
157 }
158 if (smooth_radius && drawing.radii().is_span()) {
159 bke::GSpanAttributeWriter radii = attributes.lookup_for_write_span("radius");
161 points_by_curve,
162 point_selection,
163 cyclic,
164 iterations,
165 influence,
166 smooth_ends,
167 false,
168 radii.span);
169 radii.finish();
170 }
171 if (smooth_uv) {
172 bke::SpanAttributeWriter<float> rotation = attributes.lookup_for_write_span<float>("rotation");
173 if (rotation) {
175 points_by_curve,
176 point_selection,
177 cyclic,
178 iterations,
179 influence,
180 smooth_ends,
181 false,
182 rotation.span);
183 }
184 rotation.finish();
185 }
186}
187
189 const ModifierEvalContext *ctx,
190 bke::GeometrySet *geometry_set)
191{
193
194 if (!geometry_set->has_grease_pencil()) {
195 return;
196 }
197 GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();
198 const int current_frame = grease_pencil.runtime->eval_frame;
199
200 IndexMaskMemory mask_memory;
202 grease_pencil, mmd->influence, mask_memory);
204 modifier::greasepencil::get_drawings_for_write(grease_pencil, layer_mask, current_frame);
205
207 deform_drawing(*md, *ctx->object, *drawing);
208 });
209}
210
211static void panel_draw(const bContext *C, Panel *panel)
212{
213 uiLayout *row, *col;
214 uiLayout *layout = panel->layout;
215
217
218 row = uiLayoutRow(layout, true);
219 uiItemR(row, ptr, "use_edit_position", UI_ITEM_R_TOGGLE, IFACE_("Position"), ICON_NONE);
220 uiItemR(row, ptr, "use_edit_strength", UI_ITEM_R_TOGGLE, IFACE_("Strength"), ICON_NONE);
221 uiItemR(row, ptr, "use_edit_thickness", UI_ITEM_R_TOGGLE, IFACE_("Thickness"), ICON_NONE);
222
223 uiItemR(row, ptr, "use_edit_uv", UI_ITEM_R_TOGGLE, IFACE_("UV"), ICON_NONE);
224
225 uiLayoutSetPropSep(layout, true);
226
227 uiItemR(layout, ptr, "factor", UI_ITEM_NONE, nullptr, ICON_NONE);
228 uiItemR(layout, ptr, "step", UI_ITEM_NONE, IFACE_("Repeat"), ICON_NONE);
229
230 col = uiLayoutColumn(layout, false);
231 uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_edit_position"));
232 uiItemR(col, ptr, "use_keep_shape", UI_ITEM_NONE, nullptr, ICON_NONE);
233 uiItemR(col, ptr, "use_smooth_ends", UI_ITEM_NONE, nullptr, ICON_NONE);
234
235 if (uiLayout *influence_panel = uiLayoutPanelProp(
236 C, layout, ptr, "open_influence_panel", IFACE_("Influence")))
237 {
241 }
242
243 modifier_panel_end(layout, ptr);
244}
245
250
251} // namespace blender
252
254 /*idname*/ "GreasePencilSmoothModifier",
255 /*name*/ N_("Smooth"),
256 /*struct_name*/ "GreasePencilSmoothModifierData",
257 /*struct_size*/ sizeof(GreasePencilSmoothModifierData),
258 /*srna*/ &RNA_GreasePencilSmoothModifier,
260 /*flags*/
263 /*icon*/ ICON_SMOOTHCURVE,
264
265 /*copy_data*/ blender::copy_data,
266
267 /*deform_verts*/ nullptr,
268 /*deform_matrices*/ nullptr,
269 /*deform_verts_EM*/ nullptr,
270 /*deform_matrices_EM*/ nullptr,
271 /*modify_mesh*/ nullptr,
272 /*modify_geometry_set*/ blender::modify_geometry_set,
273
274 /*init_data*/ blender::init_data,
275 /*required_data_mask*/ nullptr,
276 /*free_data*/ blender::free_data,
277 /*is_disabled*/ nullptr,
278 /*update_depsgraph*/ nullptr,
279 /*depends_on_time*/ nullptr,
280 /*depends_on_normals*/ nullptr,
281 /*foreach_ID_link*/ blender::foreach_ID_link,
282 /*foreach_tex_link*/ nullptr,
283 /*free_runtime_data*/ nullptr,
284 /*panel_register*/ blender::panel_register,
285 /*blend_write*/ blender::blend_write,
286 /*blend_read*/ blender::blend_read,
287};
Low-level operations for curves.
Low-level operations for grease pencil.
void BKE_modifier_copydata_generic(const ModifierData *md, ModifierData *md_dst, int flag)
@ eModifierTypeFlag_SupportsMapping
@ eModifierTypeFlag_AcceptsGreasePencil
@ eModifierTypeFlag_EnableInEditmode
@ eModifierTypeFlag_SupportsEditmode
void(*)(void *user_data, Object *ob, ID **idpoin, int cb_flag) IDWalkFunc
#define BLI_assert(a)
Definition BLI_assert.h:50
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define BLO_write_struct(writer, struct_name, data_ptr)
#define IFACE_(msgid)
#define DNA_struct_default_get(struct_name)
struct GreasePencilSmoothModifierData GreasePencilSmoothModifierData
@ MOD_GREASE_PENCIL_SMOOTH_MOD_LOCATION
@ MOD_GREASE_PENCIL_SMOOTH_MOD_STRENGTH
@ MOD_GREASE_PENCIL_SMOOTH_KEEP_SHAPE
@ MOD_GREASE_PENCIL_SMOOTH_MOD_UV
@ MOD_GREASE_PENCIL_SMOOTH_SMOOTH_ENDS
@ MOD_GREASE_PENCIL_SMOOTH_MOD_THICKNESS
@ eModifierType_GreasePencilSmooth
ModifierTypeInfo modifierType_GreasePencilSmooth
void modifier_panel_end(uiLayout *layout, PointerRNA *ptr)
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void uiLayoutSetActive(uiLayout *layout, bool active)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
#define UI_ITEM_NONE
PanelLayout uiLayoutPanelProp(const bContext *C, uiLayout *layout, PointerRNA *open_prop_owner, const char *open_prop_name)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_TOGGLE
static VArray ForSingle(T value, const int64_t size)
bke::CurvesGeometry & strokes_for_write()
VArray< float > opacities() const
uint col
void smooth_curve_attribute(const IndexMask &curves_to_smooth, const OffsetIndices< int > points_by_curve, const VArray< bool > &point_selection, const VArray< bool > &cyclic, int iterations, float influence, bool smooth_ends, bool keep_shape, GMutableSpan attribute_data)
void read_influence_data(BlendDataReader *reader, GreasePencilModifierInfluenceData *influence_data)
void init_influence_data(GreasePencilModifierInfluenceData *influence_data, const bool has_custom_curve)
static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const std::optional< StringRef > layer_name_filter, const std::optional< int > layer_pass_filter, const bool layer_filter_invert, const bool layer_pass_filter_invert, IndexMaskMemory &memory)
static IndexMask get_filtered_stroke_mask(const Object *ob, const bke::CurvesGeometry &curves, const Material *material_filter, const std::optional< int > material_pass_filter, const bool material_filter_invert, const bool material_pass_filter_invert, IndexMaskMemory &memory)
void write_influence_data(BlendWriter *writer, const GreasePencilModifierInfluenceData *influence_data)
void draw_vertex_group_settings(const bContext *, uiLayout *layout, PointerRNA *ptr)
Vector< bke::greasepencil::Drawing * > get_drawings_for_write(GreasePencil &grease_pencil, const IndexMask &layer_mask, const int frame)
void draw_material_filter_settings(const bContext *, uiLayout *layout, PointerRNA *ptr)
void draw_layer_filter_settings(const bContext *, uiLayout *layout, PointerRNA *ptr)
void free_influence_data(GreasePencilModifierInfluenceData *influence_data)
void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data, Object *ob, IDWalkFunc walk, void *user_data)
void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, GreasePencilModifierInfluenceData *influence_data_dst, const int)
void ensure_no_bezier_curves(Drawing &drawing)
void parallel_for_each(Range &&range, const Function &function)
Definition BLI_task.hh:58
static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
static void blend_write(BlendWriter *writer, const ID *, const ModifierData *md)
static void init_data(ModifierData *md)
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
static void panel_draw(const bContext *C, Panel *panel)
static void modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set)
static void deform_drawing(const ModifierData &md, const Object &ob, bke::greasepencil::Drawing &drawing)
static void free_data(ModifierData *md)
static void panel_register(ARegionType *region_type)
static void blend_read(BlendDataReader *reader, ModifierData *md)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
GreasePencilModifierInfluenceData influence
GreasePencilRuntimeHandle * runtime
Definition DNA_ID.h:413
struct uiLayout * layout
GreasePencil * get_grease_pencil_for_write()
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4126
uint8_t flag
Definition wm_window.cc:138