Blender V4.5
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
25#include "UI_interface.hh"
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 uiLayoutSetPropSep(layout, true);
231 uiLayoutSetEnabled(layout, !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);
253 ptr,
254 "target_layer",
255 &obj_data_ptr,
256 "layers",
257 std::nullopt,
258 ICON_OUTLINER_DATA_GP_LAYER);
260 col, ptr, "target_material", &obj_data_ptr, "materials", std::nullopt, ICON_MATERIAL);
261
262 col = &layout->column(false);
263 col->prop(ptr, "radius", UI_ITEM_R_SLIDER, IFACE_("Line Radius"), ICON_NONE);
264 col->prop(ptr, "opacity", UI_ITEM_R_SLIDER, std::nullopt, ICON_NONE);
265
267}
268
269static void edge_types_panel_draw(const bContext * /*C*/, Panel *panel)
270{
271 uiLayout *layout = panel->layout;
272 PointerRNA ob_ptr;
274
275 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
276 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
277 const bool is_first = is_first_lineart(
278 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
279 const bool has_light = RNA_pointer_get(ptr, "light_contour_object").data != nullptr;
280
281 uiLayoutSetEnabled(layout, !is_baked);
282
283 uiLayoutSetPropSep(layout, true);
284
285 uiLayout *sub = &layout->row(false);
286 uiLayoutSetActive(sub, has_light);
287 sub->prop(
288 ptr, "shadow_region_filtering", UI_ITEM_NONE, IFACE_("Illumination Filtering"), ICON_NONE);
289
290 uiLayout *col = &layout->column(true);
291
292 sub = &col->row(false, IFACE_("Create"));
293 sub->prop(ptr, "use_contour", UI_ITEM_NONE, "", ICON_NONE);
294
295 uiLayout *entry = &sub->row(true);
296 uiLayoutSetActive(entry, RNA_boolean_get(ptr, "use_contour"));
297 entry->prop(ptr, "silhouette_filtering", UI_ITEM_NONE, "", ICON_NONE);
298
299 const int silhouette_filtering = RNA_enum_get(ptr, "silhouette_filtering");
300 if (silhouette_filtering != LINEART_SILHOUETTE_FILTER_NONE) {
301 entry->prop(ptr, "use_invert_silhouette", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT);
302 }
303
304 sub = &col->row(false);
305 if (use_cache && !is_first) {
306 sub->prop(ptr, "use_crease", UI_ITEM_NONE, IFACE_("Crease (Angle Cached)"), ICON_NONE);
307 }
308 else {
309 sub->prop(ptr, "use_crease", UI_ITEM_NONE, "", ICON_NONE);
310 sub->prop(ptr,
311 "crease_threshold",
313 std::nullopt,
314 ICON_NONE);
315 }
316
317 col->prop(ptr, "use_intersection", UI_ITEM_NONE, IFACE_("Intersections"), ICON_NONE);
318 col->prop(ptr, "use_material", UI_ITEM_NONE, IFACE_("Material Borders"), ICON_NONE);
319 col->prop(ptr, "use_edge_mark", UI_ITEM_NONE, IFACE_("Edge Marks"), ICON_NONE);
320 col->prop(ptr, "use_loose", UI_ITEM_NONE, IFACE_("Loose"), ICON_NONE);
321
322 entry = &col->column(false);
323 uiLayoutSetActive(entry, has_light);
324
325 sub = &entry->row(false);
326 sub->prop(ptr, "use_light_contour", UI_ITEM_NONE, IFACE_("Light Contour"), ICON_NONE);
327
328 entry->prop(ptr,
329 "use_shadow",
332 ICON_NONE);
333
334 layout->label(IFACE_("Options"), ICON_NONE);
335
336 sub = &layout->column(false);
337 if (use_cache && !is_first) {
338 sub->label(IFACE_("Type overlapping cached"), ICON_INFO);
339 }
340 else {
341 sub->prop(ptr,
342 "use_overlap_edge_type_support",
344 IFACE_("Allow Overlapping Types"),
345 ICON_NONE);
346 }
347}
348
349static void options_light_reference_draw(const bContext * /*C*/, Panel *panel)
350{
351 uiLayout *layout = panel->layout;
352 PointerRNA ob_ptr;
354
355 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
356 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
357 const bool has_light = RNA_pointer_get(ptr, "light_contour_object").data != nullptr;
358 const bool is_first = is_first_lineart(
359 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
360
361 uiLayoutSetPropSep(layout, true);
362 uiLayoutSetEnabled(layout, !is_baked);
363
364 if (use_cache && !is_first) {
365 layout->label(RPT_("Cached from the first Line Art modifier."), ICON_INFO);
366 return;
367 }
368
369 layout->prop(ptr, "light_contour_object", UI_ITEM_NONE, std::nullopt, ICON_NONE);
370
371 uiLayout *remaining = &layout->column(false);
372 uiLayoutSetActive(remaining, has_light);
373
374 remaining->prop(ptr, "shadow_camera_size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
375
376 uiLayout *col = &remaining->column(true);
377 col->prop(ptr, "shadow_camera_near", UI_ITEM_NONE, IFACE_("Near"), ICON_NONE);
378 col->prop(ptr, "shadow_camera_far", UI_ITEM_NONE, IFACE_("Far"), ICON_NONE);
379}
380
381static void options_panel_draw(const bContext * /*C*/, Panel *panel)
382{
383 uiLayout *layout = panel->layout;
384 PointerRNA ob_ptr;
386
387 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
388 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
389 const bool is_first = is_first_lineart(
390 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
391
392 uiLayoutSetPropSep(layout, true);
393 uiLayoutSetEnabled(layout, !is_baked);
394
395 if (use_cache && !is_first) {
396 layout->label(TIP_("Cached from the first Line Art modifier"), ICON_INFO);
397 return;
398 }
399
400 uiLayout *row = &layout->row(false, IFACE_("Custom Camera"));
401 row->prop(ptr, "use_custom_camera", UI_ITEM_NONE, "", ICON_NONE);
402 uiLayout *subrow = &row->row(true);
403 uiLayoutSetActive(subrow, RNA_boolean_get(ptr, "use_custom_camera"));
404 uiLayoutSetPropSep(subrow, true);
405 subrow->prop(ptr, "source_camera", UI_ITEM_NONE, "", ICON_OBJECT_DATA);
406
407 uiLayout *col = &layout->column(true);
408
409 col->prop(
410 ptr, "use_edge_overlap", UI_ITEM_NONE, IFACE_("Overlapping Edges As Contour"), ICON_NONE);
411 col->prop(ptr, "use_object_instances", UI_ITEM_NONE, std::nullopt, ICON_NONE);
412 col->prop(ptr, "use_clip_plane_boundaries", UI_ITEM_NONE, std::nullopt, ICON_NONE);
413 col->prop(ptr, "use_crease_on_smooth", UI_ITEM_NONE, IFACE_("Crease On Smooth"), ICON_NONE);
414 col->prop(ptr, "use_crease_on_sharp", UI_ITEM_NONE, IFACE_("Crease On Sharp"), ICON_NONE);
415 col->prop(
416 ptr, "use_back_face_culling", UI_ITEM_NONE, IFACE_("Force Backface Culling"), ICON_NONE);
417}
418
419static void occlusion_panel_draw(const bContext * /*C*/, Panel *panel)
420{
421 uiLayout *layout = panel->layout;
422 PointerRNA ob_ptr;
424
425 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
426
427 const bool use_multiple_levels = RNA_boolean_get(ptr, "use_multiple_levels");
428 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
429
430 uiLayoutSetPropSep(layout, true);
431 uiLayoutSetEnabled(layout, !is_baked);
432
433 if (!show_in_front) {
434 layout->label(TIP_("Object is not in front"), ICON_INFO);
435 }
436
437 layout = &layout->column(false);
438 uiLayoutSetActive(layout, show_in_front);
439
440 layout->prop(ptr, "use_multiple_levels", UI_ITEM_NONE, IFACE_("Range"), ICON_NONE);
441
442 if (use_multiple_levels) {
443 uiLayout *col = &layout->column(true);
444 col->prop(ptr, "level_start", UI_ITEM_NONE, std::nullopt, ICON_NONE);
445 col->prop(ptr, "level_end", UI_ITEM_NONE, IFACE_("End"), ICON_NONE);
446 }
447 else {
448 layout->prop(ptr, "level_start", UI_ITEM_NONE, IFACE_("Level"), ICON_NONE);
449 }
450}
451
453{
454 const bool use_multiple_levels = RNA_boolean_get(ptr, "use_multiple_levels");
455 const int level_start = RNA_int_get(ptr, "level_start");
456 const int level_end = RNA_int_get(ptr, "level_end");
457 if (use_multiple_levels) {
458 return std::max(level_start, level_end) > 0;
459 }
460 return level_start > 0;
461}
462
463static void material_mask_panel_draw_header(const bContext * /*C*/, Panel *panel)
464{
465 uiLayout *layout = panel->layout;
466 PointerRNA ob_ptr;
468
469 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
470 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
471
472 uiLayoutSetEnabled(layout, !is_baked);
473 uiLayoutSetActive(layout, show_in_front && anything_showing_through(ptr));
474
475 layout->prop(ptr, "use_material_mask", UI_ITEM_NONE, IFACE_("Material Mask"), ICON_NONE);
476}
477
478static void material_mask_panel_draw(const bContext * /*C*/, Panel *panel)
479{
480 uiLayout *layout = panel->layout;
482
483 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
484 uiLayoutSetEnabled(layout, !is_baked);
486
487 uiLayoutSetPropSep(layout, true);
488
489 uiLayoutSetEnabled(layout, RNA_boolean_get(ptr, "use_material_mask"));
490
491 uiLayout *col = &layout->column(true);
492 uiLayout *sub = &col->row(true, IFACE_("Masks"));
493
494 PropertyRNA *prop = RNA_struct_find_property(ptr, "use_material_mask_bits");
495 for (int i = 0; i < 8; i++) {
496 sub->prop(ptr, prop, i, 0, UI_ITEM_R_TOGGLE, " ", ICON_NONE);
497 if (i == 3) {
498 sub = &col->row(true);
499 }
500 }
501
502 layout->prop(ptr, "use_material_mask_match", UI_ITEM_NONE, IFACE_("Exact Match"), ICON_NONE);
503}
504
505static void intersection_panel_draw(const bContext * /*C*/, Panel *panel)
506{
507 uiLayout *layout = panel->layout;
509
510 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
511 uiLayoutSetEnabled(layout, !is_baked);
512
513 uiLayoutSetPropSep(layout, true);
514
515 uiLayoutSetActive(layout, RNA_boolean_get(ptr, "use_intersection"));
516
517 uiLayout *col = &layout->column(true);
518 uiLayout *sub = &col->row(true, IFACE_("Collection Masks"));
519
520 PropertyRNA *prop = RNA_struct_find_property(ptr, "use_intersection_mask");
521 for (int i = 0; i < 8; i++) {
522 sub->prop(ptr, prop, i, 0, UI_ITEM_R_TOGGLE, " ", ICON_NONE);
523 if (i == 3) {
524 sub = &col->row(true);
525 }
526 }
527
528 layout->prop(ptr, "use_intersection_match", UI_ITEM_NONE, IFACE_("Exact Match"), ICON_NONE);
529}
530
531static void face_mark_panel_draw_header(const bContext * /*C*/, Panel *panel)
532{
533 uiLayout *layout = panel->layout;
534 PointerRNA ob_ptr;
536
537 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
538 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
539 const bool is_first = is_first_lineart(
540 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
541
542 if (!use_cache || is_first) {
543 uiLayoutSetEnabled(layout, !is_baked);
544 layout->prop(ptr, "use_face_mark", UI_ITEM_NONE, IFACE_("Face Mark Filtering"), ICON_NONE);
545 }
546 else {
547 layout->label(IFACE_("Face Mark Filtering"), ICON_NONE);
548 }
549}
550
551static void face_mark_panel_draw(const bContext * /*C*/, Panel *panel)
552{
553 uiLayout *layout = panel->layout;
554 PointerRNA ob_ptr;
556
557 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
558 const bool use_mark = RNA_boolean_get(ptr, "use_face_mark");
559 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
560 const bool is_first = is_first_lineart(
561 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
562
563 uiLayoutSetEnabled(layout, !is_baked);
564
565 if (use_cache && !is_first) {
566 layout->label(TIP_("Cached from the first Line Art modifier"), ICON_INFO);
567 return;
568 }
569
570 uiLayoutSetPropSep(layout, true);
571
572 uiLayoutSetActive(layout, use_mark);
573
574 layout->prop(ptr, "use_face_mark_invert", UI_ITEM_NONE, std::nullopt, ICON_NONE);
575 layout->prop(ptr, "use_face_mark_boundaries", UI_ITEM_NONE, std::nullopt, ICON_NONE);
576 layout->prop(ptr, "use_face_mark_keep_contour", UI_ITEM_NONE, std::nullopt, ICON_NONE);
577}
578
579static void chaining_panel_draw(const bContext * /*C*/, Panel *panel)
580{
581 PointerRNA ob_ptr;
583
584 uiLayout *layout = panel->layout;
585
586 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
587 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
588 const bool is_first = is_first_lineart(
589 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
590 const bool is_geom = RNA_boolean_get(ptr, "use_geometry_space_chain");
591
592 uiLayoutSetPropSep(layout, true);
593 uiLayoutSetEnabled(layout, !is_baked);
594
595 if (use_cache && !is_first) {
596 layout->label(TIP_("Cached from the first Line Art modifier"), ICON_INFO);
597 return;
598 }
599
600 uiLayout *col = &layout->column(true, IFACE_("Chain"));
601 col->prop(ptr, "use_fuzzy_intersections", UI_ITEM_NONE, std::nullopt, ICON_NONE);
602 col->prop(ptr, "use_fuzzy_all", UI_ITEM_NONE, std::nullopt, ICON_NONE);
603 col->prop(ptr, "use_loose_edge_chain", UI_ITEM_NONE, IFACE_("Loose Edges"), ICON_NONE);
604 col->prop(
605 ptr, "use_loose_as_contour", UI_ITEM_NONE, IFACE_("Loose Edges As Contour"), ICON_NONE);
606 col->prop(ptr, "use_detail_preserve", UI_ITEM_NONE, std::nullopt, ICON_NONE);
607 col->prop(ptr, "use_geometry_space_chain", UI_ITEM_NONE, IFACE_("Geometry Space"), ICON_NONE);
608
609 layout->prop(ptr,
610 "chaining_image_threshold",
612 is_geom ? std::make_optional<StringRefNull>(IFACE_("Geometry Threshold")) :
613 std::nullopt,
614 ICON_NONE);
615
616 layout->prop(ptr, "smooth_tolerance", UI_ITEM_R_SLIDER, std::nullopt, ICON_NONE);
617 layout->prop(ptr, "split_angle", UI_ITEM_R_SLIDER, std::nullopt, ICON_NONE);
618}
619
620static void vgroup_panel_draw(const bContext * /*C*/, Panel *panel)
621{
622 PointerRNA ob_ptr;
624
625 uiLayout *layout = panel->layout;
626
627 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
628 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
629 const bool is_first = is_first_lineart(
630 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
631
632 uiLayoutSetPropSep(layout, true);
633 uiLayoutSetEnabled(layout, !is_baked);
634
635 if (use_cache && !is_first) {
636 layout->label(TIP_("Cached from the first Line Art modifier"), ICON_INFO);
637 return;
638 }
639
640 uiLayout *col = &layout->column(true);
641
642 uiLayout *row = &col->row(true);
643
644 row->prop(ptr, "source_vertex_group", UI_ITEM_NONE, IFACE_("Filter Source"), ICON_GROUP_VERTEX);
645 row->prop(ptr, "invert_source_vertex_group", UI_ITEM_R_TOGGLE, "", ICON_ARROW_LEFTRIGHT);
646
647 col->prop(ptr, "use_output_vertex_group_match_by_name", UI_ITEM_NONE, std::nullopt, ICON_NONE);
648
649 uiItemPointerR(col, ptr, "vertex_group", &ob_ptr, "vertex_groups", IFACE_("Target"), ICON_NONE);
650}
651
652static void bake_panel_draw(const bContext * /*C*/, Panel *panel)
653{
654 uiLayout *layout = panel->layout;
655 PointerRNA ob_ptr;
657
658 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
659
660 uiLayoutSetPropSep(layout, true);
661
662 if (is_baked) {
663 uiLayout *col = &layout->column(false);
664 uiLayoutSetPropSep(col, false);
665 col->label(TIP_("Modifier has baked data"), ICON_NONE);
666 col->prop(ptr, "is_baked", UI_ITEM_R_TOGGLE, IFACE_("Continue Without Clearing"), ICON_NONE);
667 }
668
669 uiLayout *col = &layout->column(false);
670 uiLayoutSetEnabled(col, !is_baked);
671 col->op("OBJECT_OT_lineart_bake_strokes", std::nullopt, ICON_NONE);
672 PointerRNA op_ptr = col->op("OBJECT_OT_lineart_bake_strokes", IFACE_("Bake All"), ICON_NONE);
673 RNA_boolean_set(&op_ptr, "bake_all", true);
674
675 col = &layout->column(false);
676 col->op("OBJECT_OT_lineart_clear", std::nullopt, ICON_NONE);
677 op_ptr = col->op("OBJECT_OT_lineart_clear", IFACE_("Clear All"), ICON_NONE);
678 RNA_boolean_set(&op_ptr, "clear_all", true);
679}
680
681static void composition_panel_draw(const bContext * /*C*/, Panel *panel)
682{
683 PointerRNA ob_ptr;
685
686 uiLayout *layout = panel->layout;
687
688 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
689
690 uiLayoutSetPropSep(layout, true);
691
692 layout->prop(ptr, "overscan", UI_ITEM_NONE, std::nullopt, ICON_NONE);
693 layout->prop(ptr, "use_image_boundary_trimming", UI_ITEM_NONE, std::nullopt, ICON_NONE);
694
695 if (show_in_front) {
696 layout->label(TIP_("Object is shown in front"), ICON_ERROR);
697 }
698
699 uiLayout *col = &layout->column(false);
700 uiLayoutSetActive(col, !show_in_front);
701
702 col->prop(ptr, "stroke_depth_offset", UI_ITEM_R_SLIDER, IFACE_("Depth Offset"), ICON_NONE);
703 col->prop(ptr,
704 "use_offset_towards_custom_camera",
706 IFACE_("Towards Custom Camera"),
707 ICON_NONE);
708}
709
710static void panel_register(ARegionType *region_type)
711{
714
716 region_type, "edge_types", "Edge Types", nullptr, edge_types_panel_draw, panel_type);
717 modifier_subpanel_register(region_type,
718 "light_reference",
719 "Light Reference",
720 nullptr,
722 panel_type);
724 region_type, "geometry", "Geometry Processing", nullptr, options_panel_draw, panel_type);
725 PanelType *occlusion_panel = modifier_subpanel_register(
726 region_type, "occlusion", "Occlusion", nullptr, occlusion_panel_draw, panel_type);
727 modifier_subpanel_register(region_type,
728 "material_mask",
729 "",
732 occlusion_panel);
734 region_type, "intersection", "Intersection", nullptr, intersection_panel_draw, panel_type);
736 region_type, "face_mark", "", face_mark_panel_draw_header, face_mark_panel_draw, panel_type);
738 region_type, "chaining", "Chaining", nullptr, chaining_panel_draw, panel_type);
740 region_type, "vgroup", "Vertex Weight Transfer", nullptr, vgroup_panel_draw, panel_type);
742 region_type, "composition", "Composition", nullptr, composition_panel_draw, panel_type);
743 modifier_subpanel_register(region_type, "bake", "Bake", nullptr, bake_panel_draw, panel_type);
744}
745
747 const ModifierEvalContext &ctx,
748 GreasePencil &grease_pencil,
749 GreasePencilLineartModifierData &first_lineart,
750 const bool force_compute)
751{
752 using namespace bke::greasepencil;
753 auto &lmd = reinterpret_cast<GreasePencilLineartModifierData &>(md);
754
755 TreeNode *node = grease_pencil.find_node_by_name(lmd.target_layer);
756 if (!node || !node->is_layer()) {
757 return;
758 }
759
760 const bool is_first_lineart = (&first_lineart == &lmd);
761 const bool use_cache = (lmd.flags & MOD_LINEART_USE_CACHE);
762 LineartCache *local_lc = (is_first_lineart || use_cache) ? first_lineart.shared_cache : nullptr;
763
764 /* Only calculate strokes in these three conditions:
765 * 1. It's the very first line art modifier in the stack.
766 * 2. This line art modifier doesn't want to use globally cached data.
767 * 3. This modifier is not the first line art in stack, but it's the first that's visible (so we
768 * need to do a `force_compute`). */
769 if (is_first_lineart || (!use_cache) || force_compute) {
771 ctx.depsgraph, lmd, &local_lc, !(ctx.object->dtx & OB_DRAW_IN_FRONT));
773 }
775 lmd.cache = local_lc;
776
777 const int current_frame = grease_pencil.runtime->eval_frame;
778
779 /* Ensure we have a frame in the selected layer to put line art result in. */
780 Layer &layer = node->as_layer();
781
782 const float4x4 &mat = ctx.object->world_to_object();
783
784 /* `drawing` can be nullptr if current frame is before any of the key frames, in which case no
785 * strokes are generated. We still allow cache operations to run at the end of this function
786 * because there might be other line art modifiers in the same stack. */
787 Drawing *drawing = [&]() -> Drawing * {
788 if (Drawing *drawing = grease_pencil.get_drawing_at(layer, current_frame)) {
789 return drawing;
790 }
791 return grease_pencil.insert_frame(layer, current_frame);
792 }();
793
794 if (drawing) {
796 lmd.cache,
797 mat,
798 ctx.depsgraph,
799 *drawing,
800 lmd.source_type,
801 lmd.source_object,
802 lmd.source_collection,
803 lmd.level_start,
804 lmd.use_multiple_levels ? lmd.level_end : lmd.level_start,
805 lmd.target_material ? BKE_object_material_index_get(ctx.object, lmd.target_material) : 0,
806 lmd.edge_types,
807 lmd.mask_switches,
808 lmd.material_mask_bits,
809 lmd.intersection_mask,
810 lmd.radius,
811 lmd.opacity,
812 lmd.shadow_selection,
813 lmd.silhouette_selection,
814 lmd.source_vertex_group,
815 lmd.vgname,
816 lmd.flags,
817 lmd.calculation_flags);
818 }
819
820 if ((!is_first_lineart) && (!use_cache)) {
821 /* We only clear local cache, not global cache from the first line art modifier. */
822 BLI_assert(local_lc != first_lineart.shared_cache);
823 MOD_lineart_clear_cache(&local_lc);
824 /* Restore the original cache pointer so the modifiers below still have access to the "global"
825 * cache. */
826 lmd.cache = first_lineart.shared_cache;
827 }
828}
829
831 const ModifierEvalContext *ctx,
832 bke::GeometrySet *geometry_set)
833{
834 if (!geometry_set->has_grease_pencil()) {
835 return;
836 }
837 GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();
838 auto *mmd = reinterpret_cast<GreasePencilLineartModifierData *>(md);
839
840 GreasePencilLineartModifierData *first_lineart =
842 BLI_assert(first_lineart);
843
844 /* Since settings for line art cached data are always in the first line art modifier, we need to
845 * get and set overall calculation limits on the first modifier regardless of its visibility
846 * state. If line art cache doesn't exist, it means line art hasn't done any calculation. */
847 const bool cache_ready = (first_lineart->shared_cache != nullptr);
848 if (!cache_ready) {
849 first_lineart->shared_cache = MOD_lineart_init_cache();
851 first_lineart->shared_cache->LimitInfo);
852 }
854 *mmd, first_lineart->shared_cache->LimitInfo, cache_ready);
855
856 generate_strokes(*md, *ctx, grease_pencil, *first_lineart, (!cache_ready));
857
858 const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER);
859 if (is_last_line_art(*mmd, use_render_params)) {
860 MOD_lineart_clear_cache(&first_lineart->shared_cache);
861 }
862
863 DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
864}
865
866static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md)
867{
868 const auto *lmd = reinterpret_cast<const GreasePencilLineartModifierData *>(md);
869
871}
872
873static void blend_read(BlendDataReader * /*reader*/, ModifierData *md)
874{
876 lmd->runtime = MEM_new<LineartModifierRuntime>(__func__);
877}
878
879} // namespace blender
880
882 /*idname*/ "Lineart Modifier",
883 /*name*/ N_("Lineart"),
884 /*struct_name*/ "GreasePencilLineartModifierData",
885 /*struct_size*/ sizeof(GreasePencilLineartModifierData),
886 /*srna*/ &RNA_GreasePencilLineartModifier,
889 /*icon*/ ICON_MOD_LINEART,
890
891 /*copy_data*/ blender::copy_data,
892
893 /*deform_verts*/ nullptr,
894 /*deform_matrices*/ nullptr,
895 /*deform_verts_EM*/ nullptr,
896 /*deform_matrices_EM*/ nullptr,
897 /*modify_mesh*/ nullptr,
898 /*modify_geometry_set*/ blender::modify_geometry_set,
899
900 /*init_data*/ blender::init_data,
901 /*required_data_mask*/ nullptr,
902 /*free_data*/ blender::free_data,
903 /*is_disabled*/ blender::is_disabled,
904 /*update_depsgraph*/ blender::update_depsgraph,
905 /*depends_on_time*/ nullptr,
906 /*depends_on_normals*/ nullptr,
907 /*foreach_ID_link*/ blender::foreach_ID_link,
908 /*foreach_tex_link*/ nullptr,
909 /*free_runtime_data*/ nullptr,
910 /*panel_register*/ blender::panel_register,
911 /*blend_write*/ blender::blend_write,
912 /*blend_read*/ blender::blend_read,
913};
#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:982
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_DUPLICOLLECTION
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_FONT
@ OB_MESH
@ OB_CURVES_LEGACY
@ OB_DRAW_IN_FRONT
@ 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
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
void uiItemPointerR(uiLayout *layout, PointerRNA *ptr, blender::StringRefNull propname, PointerRNA *searchptr, blender::StringRefNull searchpropname, std::optional< blender::StringRefNull > name, int icon)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
#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:404
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)
uiLayout & row(bool align)
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:4226
uint8_t flag
Definition wm_window.cc:139