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