Blender V5.0
MOD_grease_pencil_thickness.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
8
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_colortools.hh"
22#include "BKE_curves.hh"
23#include "BKE_geometry_set.hh"
24#include "BKE_grease_pencil.hh"
25#include "BKE_modifier.hh"
26
28#include "UI_resources.hh"
29
31#include "MOD_ui_common.hh"
32
33#include "RNA_prototypes.hh"
34
35namespace blender {
36
46
47static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
48{
50 reinterpret_cast<const GreasePencilThickModifierData *>(md);
51 GreasePencilThickModifierData *tgmd = reinterpret_cast<GreasePencilThickModifierData *>(target);
52
55}
56
63
64static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
65{
67
69}
70
71static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md)
72{
74 reinterpret_cast<const GreasePencilThickModifierData *>(md);
75
78}
79
85
86static void deform_drawing(const ModifierData &md,
87 const Object &ob,
89{
90 const auto &mmd = reinterpret_cast<const GreasePencilThickModifierData &>(md);
91
92 bke::CurvesGeometry &curves = drawing.strokes_for_write();
93 if (curves.is_empty()) {
94 return;
95 }
96
97 IndexMaskMemory memory;
99 &ob, curves, mmd.influence, memory);
100 if (strokes.is_empty()) {
101 return;
102 }
103
104 MutableSpan<float> radii = drawing.radii_for_write();
105 const OffsetIndices points_by_curve = curves.points_by_curve();
107 curves, mmd.influence);
108 const bool is_normalized = (mmd.flag & MOD_GREASE_PENCIL_THICK_NORMALIZE) != 0;
109 const bool is_inverted = ((mmd.flag & MOD_GREASE_PENCIL_THICK_WEIGHT_FACTOR) == 0) &&
110 ((mmd.influence.flag & GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP) !=
111 0);
112
113 strokes.foreach_index(GrainSize(512), [&](const int curve) {
114 const IndexRange points = points_by_curve[curve];
115 for (const int i : points.index_range()) {
116 const int point = points[i];
117 const float weight = vgroup_weights[point];
118 if (weight <= 0.0f) {
119 continue;
120 }
121
122 if ((!is_normalized) && (mmd.flag & MOD_GREASE_PENCIL_THICK_WEIGHT_FACTOR)) {
123 radii[point] *= (is_inverted ? 1.0f - weight : weight);
124 radii[point] = math::max(radii[point], 0.0f);
125 continue;
126 }
127
128 const float influence = [&]() {
129 if (mmd.influence.flag & GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE &&
130 (mmd.influence.custom_curve))
131 {
132 /* Normalize value to evaluate curve. */
133 const float value = math::safe_divide(float(i), float(points.size() - 1));
134 return BKE_curvemapping_evaluateF(mmd.influence.custom_curve, 0, value);
135 }
136 return 1.0f;
137 }();
138
139 const float target = [&]() {
140 if (is_normalized) {
141 return mmd.thickness * influence;
142 }
143 return radii[point] * math::interpolate(1.0f, mmd.thickness_fac, influence);
144 }();
145
146 const float radius = math::interpolate(radii[point], target, weight);
147 radii[point] = math::max(radius, 0.0f);
148 }
149 });
150}
151
153 const ModifierEvalContext *ctx,
154 bke::GeometrySet *geometry_set)
155{
157
158 if (!geometry_set->has_grease_pencil()) {
159 return;
160 }
161 GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();
162 const int current_frame = grease_pencil.runtime->eval_frame;
163
164 IndexMaskMemory mask_memory;
166 grease_pencil, mmd->influence, mask_memory);
168 modifier::greasepencil::get_drawings_for_write(grease_pencil, layer_mask, current_frame);
169
171 deform_drawing(*md, *ctx->object, *drawing);
172 });
173}
174
175static void panel_draw(const bContext *C, Panel *panel)
176{
177 uiLayout *layout = panel->layout;
178
180
181 layout->use_property_split_set(true);
182
183 layout->prop(ptr, "use_uniform_thickness", UI_ITEM_NONE, std::nullopt, ICON_NONE);
184 if (RNA_boolean_get(ptr, "use_uniform_thickness")) {
185 layout->prop(ptr, "thickness", UI_ITEM_NONE, std::nullopt, ICON_NONE);
186 }
187 else {
188 const bool is_weighted = !RNA_boolean_get(ptr, "use_weight_factor");
189 uiLayout *row = &layout->row(true);
190 row->active_set(is_weighted);
191 row->prop(ptr, "thickness_factor", UI_ITEM_NONE, std::nullopt, ICON_NONE);
192 uiLayout *sub = &row->row(true);
193 sub->active_set(true);
194 row->prop(ptr, "use_weight_factor", UI_ITEM_NONE, "", ICON_MOD_VERTEX_WEIGHT);
195 }
196
197 if (uiLayout *influence_panel = layout->panel_prop(
198 C, ptr, "open_influence_panel", IFACE_("Influence")))
199 {
204 }
205
207}
208
213
214} // namespace blender
215
217 /*idname*/ "GreasePencilThicknessModifier",
218 /*name*/ N_("Thickness"),
219 /*struct_name*/ "GreasePencilThickModifierData",
220 /*struct_size*/ sizeof(GreasePencilThickModifierData),
221 /*srna*/ &RNA_GreasePencilThickModifierData,
223 /*flags*/
226 /*icon*/ ICON_MOD_THICKNESS,
227
228 /*copy_data*/ blender::copy_data,
229
230 /*deform_verts*/ nullptr,
231 /*deform_matrices*/ nullptr,
232 /*deform_verts_EM*/ nullptr,
233 /*deform_matrices_EM*/ nullptr,
234 /*modify_mesh*/ nullptr,
235 /*modify_geometry_set*/ blender::modify_geometry_set,
236
237 /*init_data*/ blender::init_data,
238 /*required_data_mask*/ nullptr,
239 /*free_data*/ blender::free_data,
240 /*is_disabled*/ nullptr,
241 /*update_depsgraph*/ nullptr,
242 /*depends_on_time*/ nullptr,
243 /*depends_on_normals*/ nullptr,
244 /*foreach_ID_link*/ blender::foreach_ID_link,
245 /*foreach_tex_link*/ nullptr,
246 /*free_runtime_data*/ nullptr,
247 /*panel_register*/ blender::panel_register,
248 /*blend_write*/ blender::blend_write,
249 /*blend_read*/ blender::blend_read,
250};
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
Low-level operations for curves.
Low-level operations for grease pencil.
void(*)(void *user_data, Object *ob, ID **idpoin, LibraryForeachIDCallbackFlag cb_flag) IDWalkFunc
void BKE_modifier_copydata_generic(const ModifierData *md, ModifierData *md_dst, int flag)
@ eModifierTypeFlag_SupportsMapping
@ eModifierTypeFlag_AcceptsGreasePencil
@ eModifierTypeFlag_EnableInEditmode
@ eModifierTypeFlag_SupportsEditmode
#define BLI_assert(a)
Definition BLI_assert.h:46
#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)
@ GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP
@ GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE
@ MOD_GREASE_PENCIL_THICK_WEIGHT_FACTOR
@ MOD_GREASE_PENCIL_THICK_NORMALIZE
@ eModifierType_GreasePencilThickness
ModifierTypeInfo modifierType_GreasePencilThickness
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void modifier_error_message_draw(uiLayout *layout, PointerRNA *ptr)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
constexpr int64_t size() const
constexpr IndexRange index_range() const
OffsetIndices< int > points_by_curve() const
MutableSpan< float > radii_for_write()
bke::CurvesGeometry & strokes_for_write()
void foreach_index(Fn &&fn) const
T safe_divide(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T max(const T &a, const T &b)
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_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)
VArray< float > get_influence_vertex_weights(const bke::CurvesGeometry &curves, const GreasePencilModifierInfluenceData &influence_data)
static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const std::optional< StringRef > tree_node_name_filter, const std::optional< int > layer_pass_filter, const bool layer_filter_invert, const bool layer_pass_filter_invert, IndexMaskMemory &memory)
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 draw_custom_curve_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 parallel_for_each(Range &&range, const Function &function)
Definition BLI_task.hh:56
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:414
struct uiLayout * layout
GreasePencil * get_grease_pencil_for_write()
PanelLayout panel_prop(const bContext *C, PointerRNA *open_prop_owner, blender::StringRefNull open_prop_name)
void active_set(bool active)
uiLayout & row(bool align)
void use_property_split_set(bool value)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
i
Definition text_draw.cc:230
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4238
uint8_t flag
Definition wm_window.cc:145