Blender V4.3
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
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_global.hh"
21#include "BKE_grease_pencil.hh"
22#include "BKE_lib_query.hh"
23#include "BKE_material.h"
24#include "BKE_modifier.hh"
25
26#include "UI_interface.hh"
27#include "UI_resources.hh"
28
30#include "MOD_lineart.hh"
31#include "MOD_modifiertypes.hh"
32#include "MOD_ui_common.hh"
33
34#include "RNA_access.hh"
35#include "RNA_prototypes.hh"
36
38
39#include "ED_grease_pencil.hh"
40
41namespace blender {
42
44{
46 return false;
47 }
48 ModifierData *imd = md.modifier.prev;
49 while (imd != nullptr) {
51 return false;
52 }
53 imd = imd->prev;
54 }
55 return true;
56}
57
58static bool is_last_line_art(const GreasePencilLineartModifierData &md, const bool use_render)
59{
61 return false;
62 }
63 ModifierData *imd = md.modifier.next;
64 while (imd != nullptr) {
66 if (use_render && (imd->mode & eModifierMode_Render)) {
67 return false;
68 }
69 if ((!use_render) && (imd->mode & eModifierMode_Realtime)) {
70 return false;
71 }
72 }
73 imd = imd->next;
74 }
75 return true;
76}
77
86
87static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
88{
90
91 const GreasePencilLineartModifierData *source_lmd =
92 reinterpret_cast<const GreasePencilLineartModifierData *>(md);
93 const LineartModifierRuntime *source_runtime = reinterpret_cast<const LineartModifierRuntime *>(
94 source_lmd->runtime);
95
97 reinterpret_cast<GreasePencilLineartModifierData *>(target);
98
99 target_lmd->runtime = MEM_new<LineartModifierRuntime>(__func__);
100 LineartModifierRuntime *target_runtime = reinterpret_cast<LineartModifierRuntime *>(
101 target_lmd->runtime);
102
103 blender::Set<const Object *> *object_dependencies = source_runtime->object_dependencies.get();
104 target_runtime->object_dependencies.reset(
105 new blender::Set<const Object *>(*object_dependencies));
106}
107
108static void free_data(ModifierData *md)
109{
111 if (lmd->runtime) {
112 LineartModifierRuntime *runtime = reinterpret_cast<LineartModifierRuntime *>(lmd->runtime);
113 MEM_delete(runtime);
114 lmd->runtime = nullptr;
115 }
116}
117
118static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)
119{
121
122 if (lmd->target_layer[0] == '\0' || !lmd->target_material) {
123 return true;
124 }
125 if (lmd->source_type == LINEART_SOURCE_OBJECT && !lmd->source_object) {
126 return true;
127 }
129 return true;
130 }
131 /* Preventing calculation in depsgraph when baking frames. */
132 if (lmd->flags & MOD_LINEART_IS_BAKED) {
133 return true;
134 }
135
136 return false;
137}
138
139static void add_this_collection(Collection &collection,
141 const int mode,
142 Set<const Object *> &object_dependencies)
143{
144 bool default_add = true;
145 /* Do not do nested collection usage check, this is consistent with lineart calculation, because
146 * collection usage doesn't have a INHERIT mode. This might initially be derived from the fact
147 * that an object can be inside multiple collections, but might be irrelevant now with the way
148 * objects are iterated. Keep this logic for now. */
149 if (collection.lineart_usage & COLLECTION_LRT_EXCLUDE) {
150 default_add = false;
151 }
154 if ((ob->lineart.usage == OBJECT_LRT_INHERIT && default_add) ||
155 ob->lineart.usage != OBJECT_LRT_EXCLUDE)
156 {
157 DEG_add_object_relation(ctx->node, ob, DEG_OB_COMP_GEOMETRY, "Line Art Modifier");
158 DEG_add_object_relation(ctx->node, ob, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
159 object_dependencies.add(ob);
160 }
161 }
162 if (ob->type == OB_EMPTY && (ob->transflag & OB_DUPLICOLLECTION)) {
163 if (!ob->instance_collection) {
164 continue;
165 }
166 add_this_collection(*ob->instance_collection, ctx, mode, object_dependencies);
167 object_dependencies.add(ob);
168 }
169 }
171}
172
174{
175 DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
176
178
179 /* Always add whole master collection because line art will need the whole scene for
180 * visibility computation. Line art exclusion is handled inside #add_this_collection. */
181
182 /* Do we need to distinguish DAG_EVAL_VIEWPORT or DAG_EVAL_RENDER here? */
183
184 LineartModifierRuntime *runtime = reinterpret_cast<LineartModifierRuntime *>(lmd->runtime);
185 if (!runtime) {
186 runtime = MEM_new<LineartModifierRuntime>(__func__);
187 lmd->runtime = runtime;
188 runtime->object_dependencies = nullptr;
189 }
190 Set<const Object *> *object_dependencies = runtime->object_dependencies.get();
191 if (!object_dependencies) {
192 runtime->object_dependencies = std::make_unique<Set<const Object *>>();
193 object_dependencies = runtime->object_dependencies.get();
194 }
195
196 object_dependencies->clear();
198 *ctx->scene->master_collection, ctx, DAG_EVAL_VIEWPORT, *object_dependencies);
199
200 /* No need to add any non-geometry objects into `lmd->object_dependencies` because we won't be
201 * loading */
204 ctx->node, lmd->source_camera, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
206 ctx->node, lmd->source_camera, DEG_OB_COMP_PARAMETERS, "Line Art Modifier");
207 }
208 else if (ctx->scene->camera) {
210 ctx->node, ctx->scene->camera, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
212 ctx->node, ctx->scene->camera, DEG_OB_COMP_PARAMETERS, "Line Art Modifier");
213 }
214 if (lmd->light_contour_object) {
216 ctx->node, lmd->light_contour_object, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
217 }
218}
219
220static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
221{
223
224 walk(user_data, ob, (ID **)&lmd->target_material, IDWALK_CB_USER);
225 walk(user_data, ob, (ID **)&lmd->source_collection, IDWALK_CB_NOP);
226
227 walk(user_data, ob, (ID **)&lmd->source_object, IDWALK_CB_NOP);
228 walk(user_data, ob, (ID **)&lmd->source_camera, IDWALK_CB_NOP);
229 walk(user_data, ob, (ID **)&lmd->light_contour_object, IDWALK_CB_NOP);
230}
231
232static void panel_draw(const bContext * /*C*/, Panel *panel)
233{
234 uiLayout *layout = panel->layout;
235
236 PointerRNA ob_ptr;
238
239 PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data");
240
241 const int source_type = RNA_enum_get(ptr, "source_type");
242 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
243
244 uiLayoutSetPropSep(layout, true);
245 uiLayoutSetEnabled(layout, !is_baked);
246
247 if (!is_first_lineart(*static_cast<const GreasePencilLineartModifierData *>(ptr->data))) {
248 uiItemR(layout, ptr, "use_cache", UI_ITEM_NONE, nullptr, ICON_NONE);
249 }
250
251 uiItemR(layout, ptr, "source_type", UI_ITEM_NONE, nullptr, ICON_NONE);
252
253 if (source_type == LINEART_SOURCE_OBJECT) {
254 uiItemR(layout, ptr, "source_object", UI_ITEM_NONE, nullptr, ICON_OBJECT_DATA);
255 }
256 else if (source_type == LINEART_SOURCE_COLLECTION) {
257 uiLayout *sub = uiLayoutRow(layout, true);
258 uiItemR(sub, ptr, "source_collection", UI_ITEM_NONE, nullptr, ICON_OUTLINER_COLLECTION);
259 uiItemR(sub, ptr, "use_invert_collection", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT);
260 }
261 else {
262 /* Source is Scene. */
263 }
264
265 uiLayout *col = uiLayoutColumn(layout, false);
267 col, ptr, "target_layer", &obj_data_ptr, "layers", nullptr, ICON_OUTLINER_DATA_GP_LAYER);
268 uiItemPointerR(col, ptr, "target_material", &obj_data_ptr, "materials", nullptr, ICON_MATERIAL);
269
270 col = uiLayoutColumn(layout, false);
271 uiItemR(col, ptr, "thickness", UI_ITEM_R_SLIDER, IFACE_("Line Thickness"), ICON_NONE);
272 uiItemR(col, ptr, "opacity", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
273
274 modifier_panel_end(layout, ptr);
275}
276
277static void edge_types_panel_draw(const bContext * /*C*/, Panel *panel)
278{
279 uiLayout *layout = panel->layout;
280 PointerRNA ob_ptr;
282
283 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
284 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
285 const bool is_first = is_first_lineart(
286 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
287 const bool has_light = RNA_pointer_get(ptr, "light_contour_object").data != nullptr;
288
289 uiLayoutSetEnabled(layout, !is_baked);
290
291 uiLayoutSetPropSep(layout, true);
292
293 uiLayout *sub = uiLayoutRow(layout, false);
294 uiLayoutSetActive(sub, has_light);
295 uiItemR(sub,
296 ptr,
297 "shadow_region_filtering",
299 IFACE_("Illumination Filtering"),
300 ICON_NONE);
301
302 uiLayout *col = uiLayoutColumn(layout, true);
303
304 sub = uiLayoutRowWithHeading(col, false, IFACE_("Create"));
305 uiItemR(sub, ptr, "use_contour", UI_ITEM_NONE, "", ICON_NONE);
306
307 uiLayout *entry = uiLayoutRow(sub, true);
308 uiLayoutSetActive(entry, RNA_boolean_get(ptr, "use_contour"));
309 uiItemR(entry, ptr, "silhouette_filtering", UI_ITEM_NONE, "", ICON_NONE);
310
311 const int silhouette_filtering = RNA_enum_get(ptr, "silhouette_filtering");
312 if (silhouette_filtering != LINEART_SILHOUETTE_FILTER_NONE) {
313 uiItemR(entry, ptr, "use_invert_silhouette", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT);
314 }
315
316 sub = uiLayoutRow(col, false);
317 if (use_cache && !is_first) {
318 uiItemR(sub, ptr, "use_crease", UI_ITEM_NONE, IFACE_("Crease (Angle Cached)"), ICON_NONE);
319 }
320 else {
321 uiItemR(sub, ptr, "use_crease", UI_ITEM_NONE, "", ICON_NONE);
322 uiItemR(sub,
323 ptr,
324 "crease_threshold",
326 nullptr,
327 ICON_NONE);
328 }
329
330 uiItemR(col, ptr, "use_intersection", UI_ITEM_NONE, IFACE_("Intersections"), ICON_NONE);
331 uiItemR(col, ptr, "use_material", UI_ITEM_NONE, IFACE_("Material Borders"), ICON_NONE);
332 uiItemR(col, ptr, "use_edge_mark", UI_ITEM_NONE, IFACE_("Edge Marks"), ICON_NONE);
333 uiItemR(col, ptr, "use_loose", UI_ITEM_NONE, IFACE_("Loose"), ICON_NONE);
334
335 entry = uiLayoutColumn(col, false);
336 uiLayoutSetActive(entry, has_light);
337
338 sub = uiLayoutRow(entry, false);
339 uiItemR(sub, ptr, "use_light_contour", UI_ITEM_NONE, IFACE_("Light Contour"), ICON_NONE);
340
341 uiItemR(entry,
342 ptr,
343 "use_shadow",
346 ICON_NONE);
347
348 uiItemL(layout, IFACE_("Options"), ICON_NONE);
349
350 sub = uiLayoutColumn(layout, false);
351 if (use_cache && !is_first) {
352 uiItemL(sub, IFACE_("Type overlapping cached"), ICON_INFO);
353 }
354 else {
355 uiItemR(sub,
356 ptr,
357 "use_overlap_edge_type_support",
359 IFACE_("Allow Overlapping Types"),
360 ICON_NONE);
361 }
362}
363
364static void options_light_reference_draw(const bContext * /*C*/, Panel *panel)
365{
366 uiLayout *layout = panel->layout;
367 PointerRNA ob_ptr;
369
370 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
371 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
372 const bool has_light = RNA_pointer_get(ptr, "light_contour_object").data != nullptr;
373 const bool is_first = is_first_lineart(
374 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
375
376 uiLayoutSetPropSep(layout, true);
377 uiLayoutSetEnabled(layout, !is_baked);
378
379 if (use_cache && !is_first) {
380 uiItemL(layout, RPT_("Cached from the first line art modifier."), ICON_INFO);
381 return;
382 }
383
384 uiItemR(layout, ptr, "light_contour_object", UI_ITEM_NONE, nullptr, ICON_NONE);
385
386 uiLayout *remaining = uiLayoutColumn(layout, false);
387 uiLayoutSetActive(remaining, has_light);
388
389 uiItemR(remaining, ptr, "shadow_camera_size", UI_ITEM_NONE, nullptr, ICON_NONE);
390
391 uiLayout *col = uiLayoutColumn(remaining, true);
392 uiItemR(col, ptr, "shadow_camera_near", UI_ITEM_NONE, IFACE_("Near"), ICON_NONE);
393 uiItemR(col, ptr, "shadow_camera_far", UI_ITEM_NONE, IFACE_("Far"), ICON_NONE);
394}
395
396static void options_panel_draw(const bContext * /*C*/, Panel *panel)
397{
398 uiLayout *layout = panel->layout;
399 PointerRNA ob_ptr;
401
402 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
403 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
404 const bool is_first = is_first_lineart(
405 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
406
407 uiLayoutSetPropSep(layout, true);
408 uiLayoutSetEnabled(layout, !is_baked);
409
410 if (use_cache && !is_first) {
411 uiItemL(layout, TIP_("Cached from the first Line Art modifier"), ICON_INFO);
412 return;
413 }
414
415 uiLayout *row = uiLayoutRowWithHeading(layout, false, IFACE_("Custom Camera"));
416 uiItemR(row, ptr, "use_custom_camera", UI_ITEM_NONE, "", ICON_NONE);
417 uiLayout *subrow = uiLayoutRow(row, true);
418 uiLayoutSetActive(subrow, RNA_boolean_get(ptr, "use_custom_camera"));
419 uiLayoutSetPropSep(subrow, true);
420 uiItemR(subrow, ptr, "source_camera", UI_ITEM_NONE, "", ICON_OBJECT_DATA);
421
422 uiLayout *col = uiLayoutColumn(layout, true);
423
424 uiItemR(col,
425 ptr,
426 "use_edge_overlap",
428 IFACE_("Overlapping Edges As Contour"),
429 ICON_NONE);
430 uiItemR(col, ptr, "use_object_instances", UI_ITEM_NONE, nullptr, ICON_NONE);
431 uiItemR(col, ptr, "use_clip_plane_boundaries", UI_ITEM_NONE, nullptr, ICON_NONE);
432 uiItemR(col, ptr, "use_crease_on_smooth", UI_ITEM_NONE, IFACE_("Crease On Smooth"), ICON_NONE);
433 uiItemR(col, ptr, "use_crease_on_sharp", UI_ITEM_NONE, IFACE_("Crease On Sharp"), ICON_NONE);
434 uiItemR(col,
435 ptr,
436 "use_back_face_culling",
438 IFACE_("Force Backface Culling"),
439 ICON_NONE);
440}
441
442static void occlusion_panel_draw(const bContext * /*C*/, Panel *panel)
443{
444 uiLayout *layout = panel->layout;
445 PointerRNA ob_ptr;
447
448 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
449
450 const bool use_multiple_levels = RNA_boolean_get(ptr, "use_multiple_levels");
451 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
452
453 uiLayoutSetPropSep(layout, true);
454 uiLayoutSetEnabled(layout, !is_baked);
455
456 if (!show_in_front) {
457 uiItemL(layout, TIP_("Object is not in front"), ICON_INFO);
458 }
459
460 layout = uiLayoutColumn(layout, false);
461 uiLayoutSetActive(layout, show_in_front);
462
463 uiItemR(layout, ptr, "use_multiple_levels", UI_ITEM_NONE, IFACE_("Range"), ICON_NONE);
464
465 if (use_multiple_levels) {
466 uiLayout *col = uiLayoutColumn(layout, true);
467 uiItemR(col, ptr, "level_start", UI_ITEM_NONE, nullptr, ICON_NONE);
468 uiItemR(col, ptr, "level_end", UI_ITEM_NONE, IFACE_("End"), ICON_NONE);
469 }
470 else {
471 uiItemR(layout, ptr, "level_start", UI_ITEM_NONE, IFACE_("Level"), ICON_NONE);
472 }
473}
474
476{
477 const bool use_multiple_levels = RNA_boolean_get(ptr, "use_multiple_levels");
478 const int level_start = RNA_int_get(ptr, "level_start");
479 const int level_end = RNA_int_get(ptr, "level_end");
480 if (use_multiple_levels) {
481 return std::max(level_start, level_end) > 0;
482 }
483 return level_start > 0;
484}
485
486static void material_mask_panel_draw_header(const bContext * /*C*/, Panel *panel)
487{
488 uiLayout *layout = panel->layout;
489 PointerRNA ob_ptr;
491
492 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
493 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
494
495 uiLayoutSetEnabled(layout, !is_baked);
496 uiLayoutSetActive(layout, show_in_front && anything_showing_through(ptr));
497
498 uiItemR(layout, ptr, "use_material_mask", UI_ITEM_NONE, IFACE_("Material Mask"), ICON_NONE);
499}
500
501static void material_mask_panel_draw(const bContext * /*C*/, Panel *panel)
502{
503 uiLayout *layout = panel->layout;
505
506 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
507 uiLayoutSetEnabled(layout, !is_baked);
509
510 uiLayoutSetPropSep(layout, true);
511
512 uiLayoutSetEnabled(layout, RNA_boolean_get(ptr, "use_material_mask"));
513
514 uiLayout *col = uiLayoutColumn(layout, true);
515 uiLayout *sub = uiLayoutRowWithHeading(col, true, IFACE_("Masks"));
516
517 PropertyRNA *prop = RNA_struct_find_property(ptr, "use_material_mask_bits");
518 for (int i = 0; i < 8; i++) {
519 uiItemFullR(sub, ptr, prop, i, 0, UI_ITEM_R_TOGGLE, " ", ICON_NONE);
520 if (i == 3) {
521 sub = uiLayoutRow(col, true);
522 }
523 }
524
525 uiItemR(layout, ptr, "use_material_mask_match", UI_ITEM_NONE, IFACE_("Exact Match"), ICON_NONE);
526}
527
528static void intersection_panel_draw(const bContext * /*C*/, Panel *panel)
529{
530 uiLayout *layout = panel->layout;
532
533 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
534 uiLayoutSetEnabled(layout, !is_baked);
535
536 uiLayoutSetPropSep(layout, true);
537
538 uiLayoutSetActive(layout, RNA_boolean_get(ptr, "use_intersection"));
539
540 uiLayout *col = uiLayoutColumn(layout, true);
541 uiLayout *sub = uiLayoutRowWithHeading(col, true, IFACE_("Collection Masks"));
542
543 PropertyRNA *prop = RNA_struct_find_property(ptr, "use_intersection_mask");
544 for (int i = 0; i < 8; i++) {
545 uiItemFullR(sub, ptr, prop, i, 0, UI_ITEM_R_TOGGLE, " ", ICON_NONE);
546 if (i == 3) {
547 sub = uiLayoutRow(col, true);
548 }
549 }
550
551 uiItemR(layout, ptr, "use_intersection_match", UI_ITEM_NONE, IFACE_("Exact Match"), ICON_NONE);
552}
553
554static void face_mark_panel_draw_header(const bContext * /*C*/, Panel *panel)
555{
556 uiLayout *layout = panel->layout;
557 PointerRNA ob_ptr;
559
560 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
561 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
562 const bool is_first = is_first_lineart(
563 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
564
565 if (!use_cache || is_first) {
566 uiLayoutSetEnabled(layout, !is_baked);
567 uiItemR(layout, ptr, "use_face_mark", UI_ITEM_NONE, IFACE_("Face Mark Filtering"), ICON_NONE);
568 }
569 else {
570 uiItemL(layout, IFACE_("Face Mark Filtering"), ICON_NONE);
571 }
572}
573
574static void face_mark_panel_draw(const bContext * /*C*/, Panel *panel)
575{
576 uiLayout *layout = panel->layout;
577 PointerRNA ob_ptr;
579
580 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
581 const bool use_mark = RNA_boolean_get(ptr, "use_face_mark");
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
586 uiLayoutSetEnabled(layout, !is_baked);
587
588 if (use_cache && !is_first) {
589 uiItemL(layout, TIP_("Cached from the first Line Art modifier"), ICON_INFO);
590 return;
591 }
592
593 uiLayoutSetPropSep(layout, true);
594
595 uiLayoutSetActive(layout, use_mark);
596
597 uiItemR(layout, ptr, "use_face_mark_invert", UI_ITEM_NONE, nullptr, ICON_NONE);
598 uiItemR(layout, ptr, "use_face_mark_boundaries", UI_ITEM_NONE, nullptr, ICON_NONE);
599 uiItemR(layout, ptr, "use_face_mark_keep_contour", UI_ITEM_NONE, nullptr, ICON_NONE);
600}
601
602static void chaining_panel_draw(const bContext * /*C*/, Panel *panel)
603{
604 PointerRNA ob_ptr;
606
607 uiLayout *layout = panel->layout;
608
609 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
610 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
611 const bool is_first = is_first_lineart(
612 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
613 const bool is_geom = RNA_boolean_get(ptr, "use_geometry_space_chain");
614
615 uiLayoutSetPropSep(layout, true);
616 uiLayoutSetEnabled(layout, !is_baked);
617
618 if (use_cache && !is_first) {
619 uiItemL(layout, TIP_("Cached from the first Line Art modifier"), ICON_INFO);
620 return;
621 }
622
623 uiLayout *col = uiLayoutColumnWithHeading(layout, true, IFACE_("Chain"));
624 uiItemR(col, ptr, "use_fuzzy_intersections", UI_ITEM_NONE, nullptr, ICON_NONE);
625 uiItemR(col, ptr, "use_fuzzy_all", UI_ITEM_NONE, nullptr, ICON_NONE);
626 uiItemR(col, ptr, "use_loose_edge_chain", UI_ITEM_NONE, IFACE_("Loose Edges"), ICON_NONE);
627 uiItemR(
628 col, ptr, "use_loose_as_contour", UI_ITEM_NONE, IFACE_("Loose Edges As Contour"), ICON_NONE);
629 uiItemR(col, ptr, "use_detail_preserve", UI_ITEM_NONE, nullptr, ICON_NONE);
630 uiItemR(col, ptr, "use_geometry_space_chain", UI_ITEM_NONE, IFACE_("Geometry Space"), ICON_NONE);
631
632 uiItemR(layout,
633 ptr,
634 "chaining_image_threshold",
636 is_geom ? IFACE_("Geometry Threshold") : nullptr,
637 ICON_NONE);
638
639 uiItemR(layout, ptr, "smooth_tolerance", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
640 uiItemR(layout, ptr, "split_angle", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
641}
642
643static void vgroup_panel_draw(const bContext * /*C*/, Panel *panel)
644{
645 PointerRNA ob_ptr;
647
648 uiLayout *layout = panel->layout;
649
650 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
651 const bool use_cache = RNA_boolean_get(ptr, "use_cache");
652 const bool is_first = is_first_lineart(
653 *static_cast<const GreasePencilLineartModifierData *>(ptr->data));
654
655 uiLayoutSetPropSep(layout, true);
656 uiLayoutSetEnabled(layout, !is_baked);
657
658 if (use_cache && !is_first) {
659 uiItemL(layout, TIP_("Cached from the first Line Art modifier"), ICON_INFO);
660 return;
661 }
662
663 uiLayout *col = uiLayoutColumn(layout, true);
664
665 uiLayout *row = uiLayoutRow(col, true);
666
667 uiItemR(
668 row, ptr, "source_vertex_group", UI_ITEM_NONE, IFACE_("Filter Source"), ICON_GROUP_VERTEX);
669 uiItemR(row, ptr, "invert_source_vertex_group", UI_ITEM_R_TOGGLE, "", ICON_ARROW_LEFTRIGHT);
670
671 uiItemR(col, ptr, "use_output_vertex_group_match_by_name", UI_ITEM_NONE, nullptr, ICON_NONE);
672
673 uiItemPointerR(col, ptr, "vertex_group", &ob_ptr, "vertex_groups", IFACE_("Target"), ICON_NONE);
674}
675
676static void bake_panel_draw(const bContext * /*C*/, Panel *panel)
677{
678 uiLayout *layout = panel->layout;
679 PointerRNA ob_ptr;
681
682 const bool is_baked = RNA_boolean_get(ptr, "is_baked");
683
684 uiLayoutSetPropSep(layout, true);
685
686 if (is_baked) {
687 uiLayout *col = uiLayoutColumn(layout, false);
688 uiLayoutSetPropSep(col, false);
689 uiItemL(col, TIP_("Modifier has baked data"), ICON_NONE);
690 uiItemR(
691 col, ptr, "is_baked", UI_ITEM_R_TOGGLE, IFACE_("Continue Without Clearing"), ICON_NONE);
692 }
693
694 uiLayout *col = uiLayoutColumn(layout, false);
695 uiLayoutSetEnabled(col, !is_baked);
696 uiItemO(col, nullptr, ICON_NONE, "OBJECT_OT_lineart_bake_strokes");
698 col, IFACE_("Bake All"), ICON_NONE, "OBJECT_OT_lineart_bake_strokes", "bake_all", true);
699
700 col = uiLayoutColumn(layout, false);
701 uiItemO(col, nullptr, ICON_NONE, "OBJECT_OT_lineart_clear");
703 col, IFACE_("Clear All"), ICON_NONE, "OBJECT_OT_lineart_clear", "clear_all", true);
704}
705
706static void composition_panel_draw(const bContext * /*C*/, Panel *panel)
707{
708 PointerRNA ob_ptr;
710
711 uiLayout *layout = panel->layout;
712
713 const bool show_in_front = RNA_boolean_get(&ob_ptr, "show_in_front");
714
715 uiLayoutSetPropSep(layout, true);
716
717 uiItemR(layout, ptr, "overscan", UI_ITEM_NONE, nullptr, ICON_NONE);
718 uiItemR(layout, ptr, "use_image_boundary_trimming", UI_ITEM_NONE, nullptr, ICON_NONE);
719
720 if (show_in_front) {
721 uiItemL(layout, TIP_("Object is shown in front"), ICON_ERROR);
722 }
723
724 uiLayout *col = uiLayoutColumn(layout, false);
725 uiLayoutSetActive(col, !show_in_front);
726
727 uiItemR(col, ptr, "stroke_depth_offset", UI_ITEM_R_SLIDER, IFACE_("Depth Offset"), ICON_NONE);
728 uiItemR(col,
729 ptr,
730 "use_offset_towards_custom_camera",
732 IFACE_("Towards Custom Camera"),
733 ICON_NONE);
734}
735
736static void panel_register(ARegionType *region_type)
737{
740
742 region_type, "edge_types", "Edge Types", nullptr, edge_types_panel_draw, panel_type);
743 modifier_subpanel_register(region_type,
744 "light_reference",
745 "Light Reference",
746 nullptr,
748 panel_type);
750 region_type, "geometry", "Geometry Processing", nullptr, options_panel_draw, panel_type);
751 PanelType *occlusion_panel = modifier_subpanel_register(
752 region_type, "occlusion", "Occlusion", nullptr, occlusion_panel_draw, panel_type);
753 modifier_subpanel_register(region_type,
754 "material_mask",
755 "",
758 occlusion_panel);
760 region_type, "intersection", "Intersection", nullptr, intersection_panel_draw, panel_type);
762 region_type, "face_mark", "", face_mark_panel_draw_header, face_mark_panel_draw, panel_type);
764 region_type, "chaining", "Chaining", nullptr, chaining_panel_draw, panel_type);
766 region_type, "vgroup", "Vertex Weight Transfer", nullptr, vgroup_panel_draw, panel_type);
768 region_type, "composition", "Composition", nullptr, composition_panel_draw, panel_type);
769 modifier_subpanel_register(region_type, "bake", "Bake", nullptr, bake_panel_draw, panel_type);
770}
771
773 const ModifierEvalContext &ctx,
774 GreasePencil &grease_pencil,
775 GreasePencilLineartModifierData &first_lineart,
776 const bool force_compute)
777{
778 using namespace bke::greasepencil;
779 auto &lmd = reinterpret_cast<GreasePencilLineartModifierData &>(md);
780
781 TreeNode *node = grease_pencil.find_node_by_name(lmd.target_layer);
782 if (!node || !node->is_layer()) {
783 return;
784 }
785
786 const bool is_first_lineart = (&first_lineart == &lmd);
787 const bool use_cache = (lmd.flags & MOD_LINEART_USE_CACHE);
788 LineartCache *local_lc = (is_first_lineart || use_cache) ? first_lineart.shared_cache : nullptr;
789
790 /* Only calculate strokes in these three conditions:
791 * 1. It's the very first line art modifier in the stack.
792 * 2. This line art modifier doesn't want to use globally cached data.
793 * 3. This modifier is not the first line art in stack, but it's the first that's visible (so we
794 * need to do a `force_compute`). */
795 if (is_first_lineart || (!use_cache) || force_compute) {
797 ctx.depsgraph, lmd, &local_lc, !(ctx.object->dtx & OB_DRAW_IN_FRONT));
799 }
801 lmd.cache = local_lc;
802
803 const int current_frame = grease_pencil.runtime->eval_frame;
804
805 /* Ensure we have a frame in the selected layer to put line art result in. */
806 Layer &layer = node->as_layer();
807
808 Drawing &drawing = [&]() -> Drawing & {
809 if (Drawing *drawing = grease_pencil.get_editable_drawing_at(layer, current_frame)) {
810 return *drawing;
811 }
812 return *grease_pencil.insert_frame(layer, current_frame);
813 }();
814
815 const float4x4 &mat = ctx.object->world_to_object();
816
818 lmd.cache,
819 mat,
820 ctx.depsgraph,
821 drawing,
822 lmd.source_type,
823 lmd.source_object,
824 lmd.source_collection,
825 lmd.level_start,
826 lmd.use_multiple_levels ? lmd.level_end : lmd.level_start,
827 lmd.target_material ? BKE_object_material_index_get(ctx.object, lmd.target_material) : 0,
828 lmd.edge_types,
829 lmd.mask_switches,
830 lmd.material_mask_bits,
831 lmd.intersection_mask,
832 float(lmd.thickness) / 1000.0f,
833 lmd.opacity,
834 lmd.shadow_selection,
835 lmd.silhouette_selection,
836 lmd.source_vertex_group,
837 lmd.vgname,
838 lmd.flags,
839 lmd.calculation_flags);
840
841 if ((!is_first_lineart) && (!use_cache)) {
842 /* We only clear local cache, not global cache from the first line art modifier. */
843 BLI_assert(local_lc != first_lineart.shared_cache);
844 MOD_lineart_clear_cache(&local_lc);
845 /* Restore the original cache pointer so the modifiers below still have access to the "global"
846 * cache. */
847 lmd.cache = first_lineart.shared_cache;
848 }
849}
850
852 const ModifierEvalContext *ctx,
853 bke::GeometrySet *geometry_set)
854{
855 if (!geometry_set->has_grease_pencil()) {
856 return;
857 }
858 GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();
859 auto mmd = reinterpret_cast<GreasePencilLineartModifierData *>(md);
860
861 GreasePencilLineartModifierData *first_lineart =
863 BLI_assert(first_lineart);
864
865 /* Since settings for line art cached data are always in the first line art modifier, we need to
866 * get and set overall calculation limits on the first modifier regardless of its visibility
867 * state. If line art cache doesn't exist, it means line art hasn't done any calculation. */
868 const bool cache_ready = (first_lineart->shared_cache != nullptr);
869 if (!cache_ready) {
870 first_lineart->shared_cache = MOD_lineart_init_cache();
872 first_lineart->shared_cache->LimitInfo);
873 }
875 *mmd, first_lineart->shared_cache->LimitInfo, cache_ready);
876
877 generate_strokes(*md, *ctx, grease_pencil, *first_lineart, (!cache_ready));
878
879 const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER);
880 if (is_last_line_art(*mmd, use_render_params)) {
881 MOD_lineart_clear_cache(&first_lineart->shared_cache);
882 }
883
884 DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
885}
886
887static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md)
888{
889 const auto *lmd = reinterpret_cast<const GreasePencilLineartModifierData *>(md);
890
892}
893
894static void blend_read(BlendDataReader * /*reader*/, ModifierData *md)
895{
897 lmd->runtime = MEM_new<LineartModifierRuntime>(__func__);
898}
899
900} // namespace blender
901
903 /*idname*/ "Lineart Modifier",
904 /*name*/ N_("Lineart"),
905 /*struct_name*/ "GreasePencilLineartModifierData",
906 /*struct_size*/ sizeof(GreasePencilLineartModifierData),
907 /*srna*/ &RNA_GreasePencilLineartModifier,
910 /*icon*/ ICON_MOD_LINEART,
911
912 /*copy_data*/ blender::copy_data,
913
914 /*deform_verts*/ nullptr,
915 /*deform_matrices*/ nullptr,
916 /*deform_verts_EM*/ nullptr,
917 /*deform_matrices_EM*/ nullptr,
918 /*modify_mesh*/ nullptr,
919 /*modify_geometry_set*/ blender::modify_geometry_set,
920
921 /*init_data*/ blender::init_data,
922 /*required_data_mask*/ nullptr,
923 /*free_data*/ blender::free_data,
924 /*is_disabled*/ blender::is_disabled,
925 /*update_depsgraph*/ blender::update_depsgraph,
926 /*depends_on_time*/ nullptr,
927 /*depends_on_normals*/ nullptr,
928 /*foreach_ID_link*/ blender::foreach_ID_link,
929 /*foreach_tex_link*/ nullptr,
930 /*free_runtime_data*/ nullptr,
931 /*panel_register*/ blender::panel_register,
932 /*blend_write*/ blender::blend_write,
933 /*blend_read*/ blender::blend_read,
934};
#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 BKE_modifier_copydata_generic(const ModifierData *md, ModifierData *md_dst, int flag)
@ eModifierTypeFlag_AcceptsGreasePencil
void(*)(void *user_data, Object *ob, ID **idpoin, int cb_flag) IDWalkFunc
@ MOD_APPLY_RENDER
#define BLI_assert(a)
Definition BLI_assert.h:50
#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
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:1041
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
struct GreasePencilLineartModifierData GreasePencilLineartModifierData
@ MOD_LINEART_IS_BAKED
@ MOD_LINEART_USE_CACHE
@ LINEART_SOURCE_OBJECT
@ LINEART_SOURCE_COLLECTION
@ eModifierType_GreasePencilLineart
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_FONT
@ OB_MESH
@ OB_CURVES_LEGACY
@ OB_DRAW_IN_FRONT
@ 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)
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 uiItemBooleanO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, int value)
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
void uiItemL(uiLayout *layout, const char *name, int icon)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, const char *name, int icon, const char *placeholder=nullptr)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutRowWithHeading(uiLayout *layout, bool align, const char *heading)
#define UI_ITEM_NONE
void uiItemPointerR(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *searchptr, const char *searchpropname, const char *name, int icon)
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
uiLayout * uiLayoutColumnWithHeading(uiLayout *layout, bool align, const char *heading)
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
@ UI_ITEM_R_FORCE_BLANK_DECORATE
@ UI_ITEM_R_SLIDER
bool add(const Key &key)
Definition BLI_set.hh:248
void clear()
Definition BLI_set.hh:532
draw_view in_light_buf[] float
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)
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)
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)
GreasePencilRuntimeHandle * runtime
Definition DNA_ID.h:413
blender::ed::greasepencil::LineartLimitInfo LimitInfo
std::unique_ptr< blender::Set< const Object * > > object_dependencies
struct ModifierData * next
struct ModifierData * prev
ModifierApplyFlag flag
struct uiLayout * layout
void * data
Definition RNA_types.hh:42
struct Collection * master_collection
struct Object * camera
GreasePencil * get_grease_pencil_for_write()
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4126
uint8_t flag
Definition wm_window.cc:138