Blender V5.0
MOD_lineart.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 "BLT_translation.hh"
10
11#include "BLO_read_write.hh"
12
14#include "DNA_defaults.h"
16#include "DNA_scene_types.h"
17
18#include "BKE_collection.hh"
19#include "BKE_geometry_set.hh"
20#include "BKE_grease_pencil.hh"
21#include "BKE_lib_query.hh"
22#include "BKE_material.hh"
23#include "BKE_modifier.hh"
24
26#include "UI_resources.hh"
27
29#include "MOD_lineart.hh"
30#include "MOD_modifiertypes.hh"
31#include "MOD_ui_common.hh"
32
33#include "RNA_access.hh"
34#include "RNA_prototypes.hh"
35
37
38#include "ED_grease_pencil.hh"
39
40namespace blender {
41
43{
45 return false;
46 }
47 ModifierData *imd = md.modifier.prev;
48 while (imd != nullptr) {
50 return false;
51 }
52 imd = imd->prev;
53 }
54 return true;
55}
56
57static bool is_last_line_art(const GreasePencilLineartModifierData &md, const bool use_render)
58{
60 return false;
61 }
62 ModifierData *imd = md.modifier.next;
63 while (imd != nullptr) {
65 if (use_render && (imd->mode & eModifierMode_Render)) {
66 return false;
67 }
68 if ((!use_render) && (imd->mode & eModifierMode_Realtime)) {
69 return false;
70 }
71 }
72 imd = imd->next;
73 }
74 return true;
75}
76
85
86static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
87{
89
90 const GreasePencilLineartModifierData *source_lmd =
91 reinterpret_cast<const GreasePencilLineartModifierData *>(md);
92 const LineartModifierRuntime *source_runtime = source_lmd->runtime;
93
95 reinterpret_cast<GreasePencilLineartModifierData *>(target);
96
97 target_lmd->runtime = MEM_new<LineartModifierRuntime>(__func__, *source_runtime);
98}
99
100static void free_data(ModifierData *md)
101{
103 if (LineartModifierRuntime *runtime = lmd->runtime) {
104 MEM_delete(runtime);
105 lmd->runtime = nullptr;
106 }
107}
108
109static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)
110{
112
113 if (lmd->target_layer[0] == '\0' || !lmd->target_material) {
114 return true;
115 }
116 if (lmd->source_type == LINEART_SOURCE_OBJECT && !lmd->source_object) {
117 return true;
118 }
120 return true;
121 }
122 /* Preventing calculation in depsgraph when baking frames. */
123 if (lmd->flags & MOD_LINEART_IS_BAKED) {
124 return true;
125 }
126
127 return false;
128}
129
130static void add_this_collection(Collection &collection,
132 const int mode,
133 Set<const Object *> &object_dependencies)
134{
135 bool default_add = true;
136 /* Do not do nested collection usage check, this is consistent with lineart calculation, because
137 * collection usage doesn't have a INHERIT mode. This might initially be derived from the fact
138 * that an object can be inside multiple collections, but might be irrelevant now with the way
139 * objects are iterated. Keep this logic for now. */
140 if (collection.lineart_usage & COLLECTION_LRT_EXCLUDE) {
141 default_add = false;
142 }
145 if ((ob->lineart.usage == OBJECT_LRT_INHERIT && default_add) ||
146 ob->lineart.usage != OBJECT_LRT_EXCLUDE)
147 {
148 DEG_add_object_relation(ctx->node, ob, DEG_OB_COMP_GEOMETRY, "Line Art Modifier");
149 DEG_add_object_relation(ctx->node, ob, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
150 object_dependencies.add(ob);
151 }
152 }
153 if (ob->type == OB_EMPTY && (ob->transflag & OB_DUPLICOLLECTION)) {
154 if (!ob->instance_collection) {
155 continue;
156 }
157 add_this_collection(*ob->instance_collection, ctx, mode, object_dependencies);
158 object_dependencies.add(ob);
159 }
160 }
162}
163
165{
166 DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
167
169
170 /* Always add whole master collection because line art will need the whole scene for
171 * visibility computation. Line art exclusion is handled inside #add_this_collection. */
172
173 /* Do we need to distinguish DAG_EVAL_VIEWPORT or DAG_EVAL_RENDER here? */
174
175 LineartModifierRuntime *runtime = reinterpret_cast<LineartModifierRuntime *>(lmd->runtime);
176 if (!runtime) {
177 runtime = MEM_new<LineartModifierRuntime>(__func__);
178 lmd->runtime = runtime;
179 }
180 Set<const Object *> &object_dependencies = runtime->object_dependencies;
181 object_dependencies.clear();
182
183 add_this_collection(*ctx->scene->master_collection, ctx, DAG_EVAL_VIEWPORT, object_dependencies);
184
185 /* No need to add any non-geometry objects into `lmd->object_dependencies` because we won't be
186 * loading... */
189 ctx->node, lmd->source_camera, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
191 ctx->node, lmd->source_camera, DEG_OB_COMP_PARAMETERS, "Line Art Modifier");
192 }
193 else if (ctx->scene->camera) {
195 ctx->node, ctx->scene->camera, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
197 ctx->node, ctx->scene->camera, DEG_OB_COMP_PARAMETERS, "Line Art Modifier");
198 DEG_add_scene_relation(ctx->node, ctx->scene, DEG_SCENE_COMP_PARAMETERS, "Line Art Modifier");
199 }
200 if (lmd->light_contour_object) {
202 ctx->node, lmd->light_contour_object, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
203 }
204}
205
206static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
207{
209
210 walk(user_data, ob, (ID **)&lmd->target_material, IDWALK_CB_USER);
211 walk(user_data, ob, (ID **)&lmd->source_collection, IDWALK_CB_NOP);
212
213 walk(user_data, ob, (ID **)&lmd->source_object, IDWALK_CB_NOP);
214 walk(user_data, ob, (ID **)&lmd->source_camera, IDWALK_CB_NOP);
215 walk(user_data, ob, (ID **)&lmd->light_contour_object, IDWALK_CB_NOP);
216}
217
218static void panel_draw(const bContext * /*C*/, Panel *panel)
219{
220 uiLayout *layout = panel->layout;
221
222 PointerRNA ob_ptr;
224
225 PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data");
226
227 const int source_type = RNA_enum_get(ptr, "source_type");
228 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
229
230 layout->use_property_split_set(true);
231 layout->enabled_set(!is_baked);
232
233 if (!is_first_lineart(*static_cast<const GreasePencilLineartModifierData *>(ptr->data))) {
234 layout->prop(ptr, "use_cache", UI_ITEM_NONE, std::nullopt, ICON_NONE);
235 }
236
237 layout->prop(ptr, "source_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
238
239 if (source_type == LINEART_SOURCE_OBJECT) {
240 layout->prop(ptr, "source_object", UI_ITEM_NONE, std::nullopt, ICON_OBJECT_DATA);
241 }
242 else if (source_type == LINEART_SOURCE_COLLECTION) {
243 uiLayout *sub = &layout->row(true);
244 sub->prop(ptr, "source_collection", UI_ITEM_NONE, std::nullopt, ICON_OUTLINER_COLLECTION);
245 sub->prop(ptr, "use_invert_collection", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT);
246 }
247 else {
248 /* Source is Scene. */
249 }
250
251 uiLayout *col = &layout->column(false);
252 col->prop_search(
253 ptr, "target_layer", &obj_data_ptr, "layers", std::nullopt, ICON_OUTLINER_DATA_GP_LAYER);
254 col->prop_search(
255 ptr, "target_material", &obj_data_ptr, "materials", std::nullopt, ICON_MATERIAL);
256
257 col = &layout->column(false);
258 col->prop(ptr, "radius", UI_ITEM_R_SLIDER, IFACE_("Line Radius"), ICON_NONE);
259 col->prop(ptr, "opacity", UI_ITEM_R_SLIDER, std::nullopt, ICON_NONE);
260
262}
263
264static void edge_types_panel_draw(const bContext * /*C*/, Panel *panel)
265{
266 uiLayout *layout = panel->layout;
267 PointerRNA ob_ptr;
269
270 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
271 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
272 const bool is_first = is_first_lineart(
273 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
274 const bool has_light = RNA_pointer_get(ptr, "light_contour_object").data != nullptr;
275
276 layout->enabled_set(!is_baked);
277
278 layout->use_property_split_set(true);
279
280 uiLayout *sub = &layout->row(false);
281 sub->active_set(has_light);
282 sub->prop(
283 ptr, "shadow_region_filtering", UI_ITEM_NONE, IFACE_("Illumination Filtering"), ICON_NONE);
284
285 uiLayout *col = &layout->column(true);
286
287 sub = &col->row(false, IFACE_("Create"));
288 sub->prop(ptr, "use_contour", UI_ITEM_NONE, "", ICON_NONE);
289
290 uiLayout *entry = &sub->row(true);
291 entry->active_set(RNA_boolean_get(ptr, "use_contour"));
292 entry->prop(ptr, "silhouette_filtering", UI_ITEM_NONE, "", ICON_NONE);
293
294 const int silhouette_filtering = RNA_enum_get(ptr, "silhouette_filtering");
295 if (silhouette_filtering != LINEART_SILHOUETTE_FILTER_NONE) {
296 entry->prop(ptr, "use_invert_silhouette", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT);
297 }
298
299 sub = &col->row(false);
300 if (use_cache && !is_first) {
301 sub->prop(ptr, "use_crease", UI_ITEM_NONE, IFACE_("Crease (Angle Cached)"), ICON_NONE);
302 }
303 else {
304 sub->prop(ptr, "use_crease", UI_ITEM_NONE, "", ICON_NONE);
305 sub->prop(ptr,
306 "crease_threshold",
308 std::nullopt,
309 ICON_NONE);
310 }
311
312 col->prop(ptr, "use_intersection", UI_ITEM_NONE, IFACE_("Intersections"), ICON_NONE);
313 col->prop(ptr, "use_material", UI_ITEM_NONE, IFACE_("Material Borders"), ICON_NONE);
314 col->prop(ptr, "use_edge_mark", UI_ITEM_NONE, IFACE_("Edge Marks"), ICON_NONE);
315 col->prop(ptr, "use_loose", UI_ITEM_NONE, IFACE_("Loose"), ICON_NONE);
316
317 entry = &col->column(false);
318 entry->active_set(has_light);
319
320 sub = &entry->row(false);
321 sub->prop(ptr, "use_light_contour", UI_ITEM_NONE, IFACE_("Light Contour"), ICON_NONE);
322
323 entry->prop(ptr,
324 "use_shadow",
327 ICON_NONE);
328
329 layout->label(IFACE_("Options"), ICON_NONE);
330
331 sub = &layout->column(false);
332 if (use_cache && !is_first) {
333 sub->label(IFACE_("Type overlapping cached"), ICON_INFO);
334 }
335 else {
336 sub->prop(ptr,
337 "use_overlap_edge_type_support",
339 IFACE_("Allow Overlapping Types"),
340 ICON_NONE);
341 }
342}
343
344static void options_light_reference_draw(const bContext * /*C*/, Panel *panel)
345{
346 uiLayout *layout = panel->layout;
347 PointerRNA ob_ptr;
349
350 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
351 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
352 const bool has_light = RNA_pointer_get(ptr, "light_contour_object").data != nullptr;
353 const bool is_first = is_first_lineart(
354 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
355
356 layout->use_property_split_set(true);
357 layout->enabled_set(!is_baked);
358
359 if (use_cache && !is_first) {
360 layout->label(RPT_("Cached from the first Line Art modifier."), ICON_INFO);
361 return;
362 }
363
364 layout->prop(ptr, "light_contour_object", UI_ITEM_NONE, std::nullopt, ICON_NONE);
365
366 uiLayout *remaining = &layout->column(false);
367 remaining->active_set(has_light);
368
369 remaining->prop(ptr, "shadow_camera_size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
370
371 uiLayout *col = &remaining->column(true);
372 col->prop(ptr, "shadow_camera_near", UI_ITEM_NONE, IFACE_("Near"), ICON_NONE);
373 col->prop(ptr, "shadow_camera_far", UI_ITEM_NONE, IFACE_("Far"), ICON_NONE);
374}
375
376static void options_panel_draw(const bContext * /*C*/, Panel *panel)
377{
378 uiLayout *layout = panel->layout;
379 PointerRNA ob_ptr;
381
382 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
383 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
384 const bool is_first = is_first_lineart(
385 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
386
387 layout->use_property_split_set(true);
388 layout->enabled_set(!is_baked);
389
390 if (use_cache && !is_first) {
391 layout->label(TIP_("Cached from the first Line Art modifier"), ICON_INFO);
392 return;
393 }
394
395 uiLayout *row = &layout->row(false, IFACE_("Custom Camera"));
396 row->prop(ptr, "use_custom_camera", UI_ITEM_NONE, "", ICON_NONE);
397 uiLayout *subrow = &row->row(true);
398 subrow->active_set(RNA_boolean_get(ptr, "use_custom_camera"));
399 subrow->use_property_split_set(true);
400 subrow->prop(ptr, "source_camera", UI_ITEM_NONE, "", ICON_OBJECT_DATA);
401
402 uiLayout *col = &layout->column(true);
403
404 col->prop(
405 ptr, "use_edge_overlap", UI_ITEM_NONE, IFACE_("Overlapping Edges As Contour"), ICON_NONE);
406 col->prop(ptr, "use_object_instances", UI_ITEM_NONE, std::nullopt, ICON_NONE);
407 col->prop(ptr, "use_clip_plane_boundaries", UI_ITEM_NONE, std::nullopt, ICON_NONE);
408 col->prop(ptr, "use_crease_on_smooth", UI_ITEM_NONE, IFACE_("Crease On Smooth"), ICON_NONE);
409 col->prop(ptr, "use_crease_on_sharp", UI_ITEM_NONE, IFACE_("Crease On Sharp"), ICON_NONE);
410 col->prop(
411 ptr, "use_back_face_culling", UI_ITEM_NONE, IFACE_("Force Backface Culling"), ICON_NONE);
412}
413
414static void occlusion_panel_draw(const bContext * /*C*/, Panel *panel)
415{
416 uiLayout *layout = panel->layout;
417 PointerRNA ob_ptr;
419
420 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
421
422 const bool use_multiple_levels = RNA_boolean_get(ptr, "use_multiple_levels");
423 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
424
425 layout->use_property_split_set(true);
426 layout->enabled_set(!is_baked);
427
428 if (!show_in_front) {
429 layout->label(TIP_("Object is not in front"), ICON_INFO);
430 }
431
432 layout = &layout->column(false);
433 layout->active_set(show_in_front);
434
435 layout->prop(ptr, "use_multiple_levels", UI_ITEM_NONE, IFACE_("Range"), ICON_NONE);
436
437 if (use_multiple_levels) {
438 uiLayout *col = &layout->column(true);
439 col->prop(ptr, "level_start", UI_ITEM_NONE, std::nullopt, ICON_NONE);
440 col->prop(ptr, "level_end", UI_ITEM_NONE, IFACE_("End"), ICON_NONE);
441 }
442 else {
443 layout->prop(ptr, "level_start", UI_ITEM_NONE, IFACE_("Level"), ICON_NONE);
444 }
445}
446
448{
449 const bool use_multiple_levels = RNA_boolean_get(ptr, "use_multiple_levels");
450 const int level_start = RNA_int_get(ptr, "level_start");
451 const int level_end = RNA_int_get(ptr, "level_end");
452 if (use_multiple_levels) {
453 return std::max(level_start, level_end) > 0;
454 }
455 return level_start > 0;
456}
457
458static void material_mask_panel_draw_header(const bContext * /*C*/, Panel *panel)
459{
460 uiLayout *layout = panel->layout;
461 PointerRNA ob_ptr;
463
464 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
465 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
466
467 layout->enabled_set(!is_baked);
468 layout->active_set(show_in_front && anything_showing_through(ptr));
469
470 layout->prop(ptr, "use_material_mask", UI_ITEM_NONE, IFACE_("Material Mask"), ICON_NONE);
471}
472
473static void material_mask_panel_draw(const bContext * /*C*/, Panel *panel)
474{
475 uiLayout *layout = panel->layout;
477
478 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
479 layout->enabled_set(!is_baked);
481
482 layout->use_property_split_set(true);
483
484 layout->enabled_set(RNA_boolean_get(ptr, "use_material_mask"));
485
486 uiLayout *col = &layout->column(true);
487 uiLayout *sub = &col->row(true, IFACE_("Masks"));
488
489 PropertyRNA *prop = RNA_struct_find_property(ptr, "use_material_mask_bits");
490 for (int i = 0; i < 8; i++) {
491 sub->prop(ptr, prop, i, 0, UI_ITEM_R_TOGGLE, " ", ICON_NONE);
492 if (i == 3) {
493 sub = &col->row(true);
494 }
495 }
496
497 layout->prop(ptr, "use_material_mask_match", UI_ITEM_NONE, IFACE_("Exact Match"), ICON_NONE);
498}
499
500static void intersection_panel_draw(const bContext * /*C*/, Panel *panel)
501{
502 uiLayout *layout = panel->layout;
504
505 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
506 layout->enabled_set(!is_baked);
507
508 layout->use_property_split_set(true);
509
510 layout->active_set(RNA_boolean_get(ptr, "use_intersection"));
511
512 uiLayout *col = &layout->column(true);
513 uiLayout *sub = &col->row(true, IFACE_("Collection Masks"));
514
515 PropertyRNA *prop = RNA_struct_find_property(ptr, "use_intersection_mask");
516 for (int i = 0; i < 8; i++) {
517 sub->prop(ptr, prop, i, 0, UI_ITEM_R_TOGGLE, " ", ICON_NONE);
518 if (i == 3) {
519 sub = &col->row(true);
520 }
521 }
522
523 layout->prop(ptr, "use_intersection_match", UI_ITEM_NONE, IFACE_("Exact Match"), ICON_NONE);
524}
525
526static void face_mark_panel_draw_header(const bContext * /*C*/, Panel *panel)
527{
528 uiLayout *layout = panel->layout;
529 PointerRNA ob_ptr;
531
532 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
533 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
534 const bool is_first = is_first_lineart(
535 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
536
537 if (!use_cache || is_first) {
538 layout->enabled_set(!is_baked);
539 layout->prop(ptr, "use_face_mark", UI_ITEM_NONE, IFACE_("Face Mark Filtering"), ICON_NONE);
540 }
541 else {
542 layout->label(IFACE_("Face Mark Filtering"), ICON_NONE);
543 }
544}
545
546static void face_mark_panel_draw(const bContext * /*C*/, Panel *panel)
547{
548 uiLayout *layout = panel->layout;
549 PointerRNA ob_ptr;
551
552 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
553 const bool use_mark = RNA_boolean_get(ptr, "use_face_mark");
554 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
555 const bool is_first = is_first_lineart(
556 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
557
558 layout->enabled_set(!is_baked);
559
560 if (use_cache && !is_first) {
561 layout->label(TIP_("Cached from the first Line Art modifier"), ICON_INFO);
562 return;
563 }
564
565 layout->use_property_split_set(true);
566
567 layout->active_set(use_mark);
568
569 layout->prop(ptr, "use_face_mark_invert", UI_ITEM_NONE, std::nullopt, ICON_NONE);
570 layout->prop(ptr, "use_face_mark_boundaries", UI_ITEM_NONE, std::nullopt, ICON_NONE);
571 layout->prop(ptr, "use_face_mark_keep_contour", UI_ITEM_NONE, std::nullopt, ICON_NONE);
572}
573
574static void chaining_panel_draw(const bContext * /*C*/, Panel *panel)
575{
576 PointerRNA ob_ptr;
578
579 uiLayout *layout = panel->layout;
580
581 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
582 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
583 const bool is_first = is_first_lineart(
584 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
585 const bool is_geom = RNA_boolean_get(ptr, "use_geometry_space_chain");
586
587 layout->use_property_split_set(true);
588 layout->enabled_set(!is_baked);
589
590 if (use_cache && !is_first) {
591 layout->label(TIP_("Cached from the first Line Art modifier"), ICON_INFO);
592 return;
593 }
594
595 uiLayout *col = &layout->column(true, IFACE_("Chain"));
596 col->prop(ptr, "use_fuzzy_intersections", UI_ITEM_NONE, std::nullopt, ICON_NONE);
597 col->prop(ptr, "use_fuzzy_all", UI_ITEM_NONE, std::nullopt, ICON_NONE);
598 col->prop(ptr, "use_loose_edge_chain", UI_ITEM_NONE, IFACE_("Loose Edges"), ICON_NONE);
599 col->prop(
600 ptr, "use_loose_as_contour", UI_ITEM_NONE, IFACE_("Loose Edges As Contour"), ICON_NONE);
601 col->prop(ptr, "use_detail_preserve", UI_ITEM_NONE, std::nullopt, ICON_NONE);
602 col->prop(ptr, "use_geometry_space_chain", UI_ITEM_NONE, IFACE_("Geometry Space"), ICON_NONE);
603
604 layout->prop(ptr,
605 "chaining_image_threshold",
607 is_geom ? std::make_optional<StringRefNull>(IFACE_("Geometry Threshold")) :
608 std::nullopt,
609 ICON_NONE);
610
611 layout->prop(ptr, "smooth_tolerance", UI_ITEM_R_SLIDER, std::nullopt, ICON_NONE);
612 layout->prop(ptr, "split_angle", UI_ITEM_R_SLIDER, std::nullopt, ICON_NONE);
613}
614
615static void vgroup_panel_draw(const bContext * /*C*/, Panel *panel)
616{
617 PointerRNA ob_ptr;
619
620 uiLayout *layout = panel->layout;
621
622 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
623 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
624 const bool is_first = is_first_lineart(
625 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
626
627 layout->use_property_split_set(true);
628 layout->enabled_set(!is_baked);
629
630 if (use_cache && !is_first) {
631 layout->label(TIP_("Cached from the first Line Art modifier"), ICON_INFO);
632 return;
633 }
634
635 uiLayout *col = &layout->column(true);
636
637 uiLayout *row = &col->row(true);
638
639 row->prop(ptr, "source_vertex_group", UI_ITEM_NONE, IFACE_("Filter Source"), ICON_GROUP_VERTEX);
640 row->prop(ptr, "invert_source_vertex_group", UI_ITEM_R_TOGGLE, "", ICON_ARROW_LEFTRIGHT);
641
642 col->prop(ptr, "use_output_vertex_group_match_by_name", UI_ITEM_NONE, std::nullopt, ICON_NONE);
643
644 col->prop_search(ptr, "vertex_group", &ob_ptr, "vertex_groups", IFACE_("Target"), ICON_NONE);
645}
646
647static void bake_panel_draw(const bContext * /*C*/, Panel *panel)
648{
649 uiLayout *layout = panel->layout;
650 PointerRNA ob_ptr;
652
653 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
654
655 layout->use_property_split_set(true);
656
657 if (is_baked) {
658 uiLayout *col = &layout->column(false);
659 col->use_property_split_set(false);
660 col->label(TIP_("Modifier has baked data"), ICON_NONE);
661 col->prop(ptr, "is_baked", UI_ITEM_R_TOGGLE, IFACE_("Continue Without Clearing"), ICON_NONE);
662 }
663
664 uiLayout *col = &layout->column(false);
665 col->enabled_set(!is_baked);
666 col->op("OBJECT_OT_lineart_bake_strokes", std::nullopt, ICON_NONE);
667 PointerRNA op_ptr = col->op("OBJECT_OT_lineart_bake_strokes", IFACE_("Bake All"), ICON_NONE);
668 RNA_boolean_set(&op_ptr, "bake_all", true);
669
670 col = &layout->column(false);
671 col->op("OBJECT_OT_lineart_clear", std::nullopt, ICON_NONE);
672 op_ptr = col->op("OBJECT_OT_lineart_clear", IFACE_("Clear All"), ICON_NONE);
673 RNA_boolean_set(&op_ptr, "clear_all", true);
674}
675
676static void composition_panel_draw(const bContext * /*C*/, Panel *panel)
677{
678 PointerRNA ob_ptr;
680
681 uiLayout *layout = panel->layout;
682
683 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
684
685 layout->use_property_split_set(true);
686
687 layout->prop(ptr, "overscan", UI_ITEM_NONE, std::nullopt, ICON_NONE);
688 layout->prop(ptr, "use_image_boundary_trimming", UI_ITEM_NONE, std::nullopt, ICON_NONE);
689
690 if (show_in_front) {
691 layout->label(TIP_("Object is shown in front"), ICON_ERROR);
692 }
693
694 uiLayout *col = &layout->column(false);
695 col->active_set(!show_in_front);
696
697 col->prop(ptr, "stroke_depth_offset", UI_ITEM_R_SLIDER, IFACE_("Depth Offset"), ICON_NONE);
698 col->prop(ptr,
699 "use_offset_towards_custom_camera",
701 IFACE_("Towards Custom Camera"),
702 ICON_NONE);
703}
704
705static void panel_register(ARegionType *region_type)
706{
709
711 region_type, "edge_types", "Edge Types", nullptr, edge_types_panel_draw, panel_type);
712 modifier_subpanel_register(region_type,
713 "light_reference",
714 "Light Reference",
715 nullptr,
717 panel_type);
719 region_type, "geometry", "Geometry Processing", nullptr, options_panel_draw, panel_type);
720 PanelType *occlusion_panel = modifier_subpanel_register(
721 region_type, "occlusion", "Occlusion", nullptr, occlusion_panel_draw, panel_type);
722 modifier_subpanel_register(region_type,
723 "material_mask",
724 "",
727 occlusion_panel);
729 region_type, "intersection", "Intersection", nullptr, intersection_panel_draw, panel_type);
731 region_type, "face_mark", "", face_mark_panel_draw_header, face_mark_panel_draw, panel_type);
733 region_type, "chaining", "Chaining", nullptr, chaining_panel_draw, panel_type);
735 region_type, "vgroup", "Vertex Weight Transfer", nullptr, vgroup_panel_draw, panel_type);
737 region_type, "composition", "Composition", nullptr, composition_panel_draw, panel_type);
738 modifier_subpanel_register(region_type, "bake", "Bake", nullptr, bake_panel_draw, panel_type);
739}
740
742 const ModifierEvalContext &ctx,
743 GreasePencil &grease_pencil,
744 GreasePencilLineartModifierData &first_lineart,
745 const bool force_compute)
746{
747 using namespace bke::greasepencil;
748 auto &lmd = reinterpret_cast<GreasePencilLineartModifierData &>(md);
749
750 TreeNode *node = grease_pencil.find_node_by_name(lmd.target_layer);
751 if (!node || !node->is_layer()) {
752 return;
753 }
754
755 const bool is_first_lineart = (&first_lineart == &lmd);
756 const bool use_cache = (lmd.flags & MOD_LINEART_USE_CACHE);
757 LineartCache *local_lc = (is_first_lineart || use_cache) ? first_lineart.shared_cache : nullptr;
758
759 /* Only calculate strokes in these three conditions:
760 * 1. It's the very first line art modifier in the stack.
761 * 2. This line art modifier doesn't want to use globally cached data.
762 * 3. This modifier is not the first line art in stack, but it's the first that's visible (so we
763 * need to do a `force_compute`). */
764 if (is_first_lineart || (!use_cache) || force_compute) {
766 ctx.depsgraph, lmd, &local_lc, !(ctx.object->dtx & OB_DRAW_IN_FRONT));
768 }
770 lmd.cache = local_lc;
771
772 const int current_frame = grease_pencil.runtime->eval_frame;
773
774 /* Ensure we have a frame in the selected layer to put line art result in. */
775 Layer &layer = node->as_layer();
776
777 const float4x4 &mat = ctx.object->world_to_object();
778
779 /* `drawing` can be nullptr if current frame is before any of the key frames, in which case no
780 * strokes are generated. We still allow cache operations to run at the end of this function
781 * because there might be other line art modifiers in the same stack. */
782 Drawing *drawing = [&]() -> Drawing * {
783 if (Drawing *drawing = grease_pencil.get_drawing_at(layer, current_frame)) {
784 return drawing;
785 }
786 return grease_pencil.insert_frame(layer, current_frame);
787 }();
788
789 if (drawing) {
791 lmd.cache,
792 mat,
793 ctx.depsgraph,
794 *drawing,
795 lmd.source_type,
796 lmd.source_object,
797 lmd.source_collection,
798 lmd.level_start,
799 lmd.use_multiple_levels ? lmd.level_end : lmd.level_start,
800 lmd.target_material ? BKE_object_material_index_get(ctx.object, lmd.target_material) : 0,
801 lmd.edge_types,
802 lmd.mask_switches,
803 lmd.material_mask_bits,
804 lmd.intersection_mask,
805 lmd.radius,
806 lmd.opacity,
807 lmd.shadow_selection,
808 lmd.silhouette_selection,
809 lmd.source_vertex_group,
810 lmd.vgname,
811 lmd.flags,
812 lmd.calculation_flags);
813 }
814
815 if ((!is_first_lineart) && (!use_cache)) {
816 /* We only clear local cache, not global cache from the first line art modifier. */
817 BLI_assert(local_lc != first_lineart.shared_cache);
818 MOD_lineart_clear_cache(&local_lc);
819 /* Restore the original cache pointer so the modifiers below still have access to the "global"
820 * cache. */
821 lmd.cache = first_lineart.shared_cache;
822 }
823}
824
826 const ModifierEvalContext *ctx,
827 bke::GeometrySet *geometry_set)
828{
829 if (!geometry_set->has_grease_pencil()) {
830 return;
831 }
832 GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();
833 auto *mmd = reinterpret_cast<GreasePencilLineartModifierData *>(md);
834
835 GreasePencilLineartModifierData *first_lineart =
837 BLI_assert(first_lineart);
838
839 /* Since settings for line art cached data are always in the first line art modifier, we need to
840 * get and set overall calculation limits on the first modifier regardless of its visibility
841 * state. If line art cache doesn't exist, it means line art hasn't done any calculation. */
842 const bool cache_ready = (first_lineart->shared_cache != nullptr);
843 if (!cache_ready) {
844 first_lineart->shared_cache = MOD_lineart_init_cache();
846 first_lineart->shared_cache->LimitInfo);
847 }
849 *mmd, first_lineart->shared_cache->LimitInfo, cache_ready);
850
851 generate_strokes(*md, *ctx, grease_pencil, *first_lineart, (!cache_ready));
852
853 const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER);
854 if (is_last_line_art(*mmd, use_render_params)) {
855 MOD_lineart_clear_cache(&first_lineart->shared_cache);
856 }
857
858 DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
859}
860
861static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md)
862{
863 const auto *lmd = reinterpret_cast<const GreasePencilLineartModifierData *>(md);
864
866}
867
868static void blend_read(BlendDataReader * /*reader*/, ModifierData *md)
869{
871 lmd->runtime = MEM_new<LineartModifierRuntime>(__func__);
872}
873
874} // namespace blender
875
877 /*idname*/ "Lineart Modifier",
878 /*name*/ N_("Lineart"),
879 /*struct_name*/ "GreasePencilLineartModifierData",
880 /*struct_size*/ sizeof(GreasePencilLineartModifierData),
881 /*srna*/ &RNA_GreasePencilLineartModifier,
884 /*icon*/ ICON_MOD_LINEART,
885
886 /*copy_data*/ blender::copy_data,
887
888 /*deform_verts*/ nullptr,
889 /*deform_matrices*/ nullptr,
890 /*deform_verts_EM*/ nullptr,
891 /*deform_matrices_EM*/ nullptr,
892 /*modify_mesh*/ nullptr,
893 /*modify_geometry_set*/ blender::modify_geometry_set,
894
895 /*init_data*/ blender::init_data,
896 /*required_data_mask*/ nullptr,
897 /*free_data*/ blender::free_data,
898 /*is_disabled*/ blender::is_disabled,
899 /*update_depsgraph*/ blender::update_depsgraph,
900 /*depends_on_time*/ nullptr,
901 /*depends_on_normals*/ nullptr,
902 /*foreach_ID_link*/ blender::foreach_ID_link,
903 /*foreach_tex_link*/ nullptr,
904 /*free_runtime_data*/ nullptr,
905 /*panel_register*/ blender::panel_register,
906 /*blend_write*/ blender::blend_write,
907 /*blend_read*/ blender::blend_read,
908};
#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode)
#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END
Low-level operations for grease pencil.
@ IDWALK_CB_USER
@ IDWALK_CB_NOP
General operations, lookup, etc. for materials.
int BKE_object_material_index_get(Object *ob, const Material *ma)
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_AcceptsGreasePencil
@ MOD_APPLY_RENDER
#define BLI_assert(a)
Definition BLI_assert.h:46
#define ELEM(...)
#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 RPT_(msgid)
#define TIP_(msgid)
#define BLT_I18NCONTEXT_ID_GPENCIL
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ DAG_EVAL_VIEWPORT
@ DEG_SCENE_COMP_PARAMETERS
void DEG_add_scene_relation(DepsNodeHandle *node_handle, Scene *scene, eDepsSceneComponentType component, const char *description)
void DEG_add_object_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
@ DEG_OB_COMP_GEOMETRY
@ DEG_OB_COMP_TRANSFORM
@ DEG_OB_COMP_PARAMETERS
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
Object groups, one object can be in many groups at once.
@ COLLECTION_LRT_EXCLUDE
#define DNA_struct_default_get(struct_name)
@ MOD_LINEART_USE_CUSTOM_CAMERA
@ eModifierMode_Render
@ eModifierMode_Realtime
@ LINEART_SILHOUETTE_FILTER_NONE
@ MOD_LINEART_IS_BAKED
@ MOD_LINEART_USE_CACHE
@ LINEART_SOURCE_OBJECT
@ LINEART_SOURCE_COLLECTION
@ eModifierType_GreasePencilLineart
@ OB_DRAW_IN_FRONT
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_FONT
@ OB_MESH
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_DUPLICOLLECTION
@ OBJECT_LRT_EXCLUDE
@ OBJECT_LRT_INHERIT
static bool is_disabled
ModifierTypeInfo modifierType_GreasePencilLineart
PanelType * modifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
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)
@ UI_ITEM_R_TOGGLE
@ UI_ITEM_R_FORCE_BLANK_DECORATE
@ UI_ITEM_R_SLIDER
#define UI_ITEM_NONE
bool is_layer() const
const Layer & as_layer() const
bool add(const Key &key)
Definition BLI_set.hh:248
void clear()
Definition BLI_set.hh:551
uint col
void MOD_lineart_chain_clear_picked_flag(LineartCache *lc)
LineartCache * MOD_lineart_init_cache()
void MOD_lineart_clear_cache(LineartCache **lc)
void MOD_lineart_destroy_render_data_v3(GreasePencilLineartModifierData *lmd)
void MOD_lineart_gpencil_generate_v3(const LineartCache *cache, const blender::float4x4 &inverse_mat, Depsgraph *depsgraph, blender::bke::greasepencil::Drawing &drawing, const int8_t source_type, Object *source_object, Collection *source_collection, const int level_start, const int level_end, const int mat_nr, const int16_t edge_types, const uchar mask_switches, const uchar material_mask_bits, const uchar intersection_mask, const float thickness, const float opacity, const uchar shadow_selection, const uchar silhouette_mode, const char *source_vgname, const char *vgname, const int modifier_flags, const int modifier_calculation_flags)
bool MOD_lineart_compute_feature_lines_v3(Depsgraph *depsgraph, GreasePencilLineartModifierData &lmd, LineartCache **cached_result, bool enable_stroke_depth_offset)
void get_lineart_modifier_limits(const Object &ob, blender::ed::greasepencil::LineartLimitInfo &info)
void set_lineart_modifier_limits(GreasePencilLineartModifierData &lmd, const blender::ed::greasepencil::LineartLimitInfo &info, const bool cache_is_ready)
GreasePencilLineartModifierData * get_first_lineart_modifier(const Object &ob)
static void material_mask_panel_draw_header(const bContext *, Panel *panel)
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 material_mask_panel_draw(const bContext *, Panel *panel)
static void chaining_panel_draw(const bContext *, Panel *panel)
static void init_data(ModifierData *md)
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
static void occlusion_panel_draw(const bContext *, Panel *panel)
static void panel_draw(const bContext *C, Panel *panel)
MatBase< float, 4, 4 > float4x4
static void add_this_collection(Collection &collection, const ModifierUpdateDepsgraphContext *ctx, const int mode, Set< const Object * > &object_dependencies)
static void modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set)
static bool anything_showing_through(PointerRNA *ptr)
static void generate_strokes(ModifierData &md, const ModifierEvalContext &ctx, GreasePencil &grease_pencil, GreasePencilLineartModifierData &first_lineart, const bool force_compute)
static void free_data(ModifierData *md)
static void bake_panel_draw(const bContext *, Panel *panel)
static void options_panel_draw(const bContext *, Panel *panel)
static void panel_register(ARegionType *region_type)
static bool is_last_line_art(const GreasePencilLineartModifierData &md, const bool use_render)
static void edge_types_panel_draw(const bContext *, Panel *panel)
static void face_mark_panel_draw_header(const bContext *, Panel *panel)
static void intersection_panel_draw(const bContext *, Panel *panel)
static void composition_panel_draw(const bContext *, Panel *panel)
static void vgroup_panel_draw(const bContext *, Panel *panel)
static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
static bool is_disabled(const Scene *, ModifierData *md, bool)
static void face_mark_panel_draw(const bContext *, Panel *panel)
static void blend_read(BlendDataReader *reader, ModifierData *md)
static bool is_first_lineart(const GreasePencilLineartModifierData &md)
static void options_light_reference_draw(const bContext *, Panel *panel)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
struct LineartModifierRuntime * runtime
GreasePencilRuntimeHandle * runtime
Definition DNA_ID.h:414
blender::ed::greasepencil::LineartLimitInfo LimitInfo
blender::Set< const Object * > object_dependencies
struct ModifierData * next
struct ModifierData * prev
ModifierApplyFlag flag
struct uiLayout * layout
void * data
Definition RNA_types.hh:53
struct Collection * master_collection
struct Object * camera
GreasePencil * get_grease_pencil_for_write()
void label(blender::StringRef name, int icon)
uiLayout & column(bool align)
void active_set(bool active)
void enabled_set(bool enabled)
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