Blender V5.3
grease_pencil_utils.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_attribute.hh"
10#include "BKE_brush.hh"
11#include "BKE_colortools.hh"
12#include "BKE_context.hh"
13#include "BKE_curves_utils.hh"
14#include "BKE_deform.hh"
15#include "BKE_grease_pencil.hh"
16#include "BKE_lib_id.hh"
17#include "BKE_library.hh"
18#include "BKE_material.hh"
19#include "BKE_paint.hh"
20#include "BKE_report.hh"
21#include "BKE_scene.hh"
22
23#include "BLI_array_utils.hh"
24#include "BLI_bounds.hh"
25#include "BLI_listbase.hh"
26#include "BLI_math_geom_c.hh"
27#include "BLI_math_vector.hh"
28#include "BLI_vector_set.hh"
29
30#include "DNA_ID.h"
31#include "DNA_brush_types.h"
32#include "DNA_material_types.h"
33#include "DNA_object_types.h"
34#include "DNA_scene_types.h"
35#include "DNA_view3d_types.h"
36
38
39#include "GEO_merge_layers.hh"
40
41#include "RNA_prototypes.hh"
42
43#include "ED_curves.hh"
44#include "ED_grease_pencil.hh"
45#include "ED_view3d.hh"
46
48
50 const ARegion &region,
51 const View3D &view3d,
52 const Object &eval_object,
54 : region_(&region), view3d_(&view3d)
55{
56 layer_space_to_world_space_ = (layer != nullptr) ? layer->to_world_space(eval_object) :
57 eval_object.object_to_world();
58 world_space_to_layer_space_ = math::invert(layer_space_to_world_space_);
59 /* Initialize DrawingPlacementPlane from toolsettings. */
61 case GP_LOCKAXIS_VIEW:
62 plane_ = DrawingPlacementPlane::View;
63 break;
64 case GP_LOCKAXIS_Y:
65 plane_ = DrawingPlacementPlane::Front;
66 placement_normal_ = float3(0, 1, 0);
67 break;
68 case GP_LOCKAXIS_X:
69 plane_ = DrawingPlacementPlane::Side;
70 placement_normal_ = float3(1, 0, 0);
71 break;
72 case GP_LOCKAXIS_Z:
73 plane_ = DrawingPlacementPlane::Top;
74 placement_normal_ = float3(0, 0, 1);
75 break;
76 case GP_LOCKAXIS_CURSOR: {
77 plane_ = DrawingPlacementPlane::Cursor;
78 placement_normal_ = scene.cursor.matrix<float3x3>() * float3(0, 0, 1);
79 break;
80 }
81 }
82
83 /* Account for layer transform. */
84 if (!ELEM(scene.toolsettings->gp_sculpt.lock_axis, GP_LOCKAXIS_VIEW, GP_LOCKAXIS_CURSOR)) {
85 /* Use the transpose inverse for normal. */
86 placement_normal_ = math::transform_direction(math::transpose(world_space_to_layer_space_),
87 placement_normal_);
88 }
89
90 /* Initialize DrawingPlacementDepth from toolsettings. */
91 const char align_flag = scene.toolsettings->gpencil_v3d_align;
92 if (align_flag & GP_PROJECT_VIEWSPACE) {
93 if (align_flag & GP_PROJECT_CURSOR) {
95 surface_offset_ = 0.0f;
96 placement_loc_ = float3(scene.cursor.location);
97 }
98 else if (align_flag & GP_PROJECT_DEPTH_VIEW) {
100 if (align_flag & GP_PROJECT_DEPTH_ONLY_SELECTED) {
101 use_project_only_selected_ = true;
102 }
103 surface_offset_ = scene.toolsettings->gpencil_surface_offset;
104 /* Default to view placement with the object origin if we don't hit a surface. */
105 placement_loc_ = layer_space_to_world_space_.location();
106 }
107 else if (align_flag & GP_PROJECT_DEPTH_STROKE) {
109 surface_offset_ = 0.0f;
110 /* Default to view placement with the object origin if we don't hit a stroke. */
111 placement_loc_ = layer_space_to_world_space_.location();
112 }
113 else {
115 surface_offset_ = 0.0f;
116 placement_loc_ = layer_space_to_world_space_.location();
117 }
118 }
119 else {
121 surface_offset_ = 0.0f;
122 placement_loc_ = float3(0.0f);
123 }
124
125 if (plane_ != DrawingPlacementPlane::View) {
126 placement_plane_ = float4();
127 plane_from_point_normal_v3(*placement_plane_, placement_loc_, placement_normal_);
128 }
129}
130
132 const ARegion &region,
133 const View3D &view3d,
134 const Object &eval_object,
136 const ReprojectMode reproject_mode,
137 const float surface_offset,
138 ViewDepths *view_depths)
139 : region_(&region),
140 view3d_(&view3d),
141 depth_cache_(view_depths),
142 surface_offset_(surface_offset)
143{
144 layer_space_to_world_space_ = (layer != nullptr) ? layer->to_world_space(eval_object) :
145 eval_object.object_to_world();
146 world_space_to_layer_space_ = math::invert(layer_space_to_world_space_);
147 /* Initialize DrawingPlacementPlane from mode. */
148 switch (reproject_mode) {
151 break;
154 placement_normal_ = float3(0, 1, 0);
155 break;
158 placement_normal_ = float3(1, 0, 0);
159 break;
162 placement_normal_ = float3(0, 0, 1);
163 break;
166 placement_normal_ = scene.cursor.matrix<float3x3>() * float3(0, 0, 1);
167 break;
168 }
169 default:
170 break;
171 }
172
173 /* Account for layer transform. */
174 if (!ELEM(reproject_mode, ReprojectMode::View, ReprojectMode::Cursor)) {
175 /* Use the transpose inverse for normal. */
176 placement_normal_ = math::transform_direction(math::transpose(world_space_to_layer_space_),
177 placement_normal_);
178 }
179
180 /* Initialize DrawingPlacementDepth from mode. */
181 switch (reproject_mode) {
184 surface_offset_ = 0.0f;
185 placement_loc_ = float3(scene.cursor.location);
186 break;
189 surface_offset_ = 0.0f;
190 placement_loc_ = layer_space_to_world_space_.location();
191 break;
194 placement_loc_ = layer_space_to_world_space_.location();
195 break;
196 default:
198 surface_offset_ = 0.0f;
199 placement_loc_ = layer_space_to_world_space_.location();
200 break;
201 }
202
203 if (plane_ != DrawingPlacementPlane::View) {
204 placement_plane_ = float4();
205 plane_from_point_normal_v3(*placement_plane_, placement_loc_, placement_normal_);
206 }
207}
208
210{
211 region_ = other.region_;
212 view3d_ = other.view3d_;
213
214 depth_ = other.depth_;
215 plane_ = other.plane_;
216
217 if (other.depth_cache_ != nullptr) {
218 depth_cache_ = MEM_dupalloc(other.depth_cache_);
219 depth_cache_->depths = MEM_dupalloc(other.depth_cache_->depths);
220 }
221 use_project_only_selected_ = other.use_project_only_selected_;
222
223 surface_offset_ = other.surface_offset_;
224
225 placement_loc_ = other.placement_loc_;
226 placement_normal_ = other.placement_normal_;
227 placement_plane_ = other.placement_plane_;
228
229 layer_space_to_world_space_ = other.layer_space_to_world_space_;
230 world_space_to_layer_space_ = other.world_space_to_layer_space_;
231}
232
234{
235 region_ = other.region_;
236 view3d_ = other.view3d_;
237
238 depth_ = other.depth_;
239 plane_ = other.plane_;
240
241 std::swap(depth_cache_, other.depth_cache_);
242 use_project_only_selected_ = other.use_project_only_selected_;
243
244 surface_offset_ = other.surface_offset_;
245
246 placement_loc_ = other.placement_loc_;
247 placement_normal_ = other.placement_normal_;
248 placement_plane_ = other.placement_plane_;
249
250 layer_space_to_world_space_ = other.layer_space_to_world_space_;
251 world_space_to_layer_space_ = other.world_space_to_layer_space_;
252}
253
255{
256 if (this == &other) {
257 return *this;
258 }
259 std::destroy_at(this);
260 new (this) DrawingPlacement(other);
261 return *this;
262}
263
265{
266 if (this == &other) {
267 return *this;
268 }
269 std::destroy_at(this);
270 new (this) DrawingPlacement(std::move(other));
271 return *this;
272}
273
275{
276 if (depth_cache_ != nullptr) {
277 ED_view3d_depths_free(depth_cache_);
278 }
279}
280
285
290
292{
293 const eView3D_GPFlag previous_gp_flag = view3d->gp_flag;
295
297 if (use_project_only_selected_) {
299 }
300 else {
302 }
303 }
304 if (use_project_to_stroke()) {
305 /* Enforce render engine to use 3D stroke order, otherwise depth buffer values are not in 3D
306 * space. */
308 }
309
310 ED_view3d_depth_override(depsgraph, region, view3d, nullptr, mode, false, &this->depth_cache_);
311
312 view3d->gp_flag = previous_gp_flag;
313}
314
315std::optional<float3> DrawingPlacement::project_depth(const float2 co) const
316{
317 std::optional<float> depth = get_depth(co);
318 if (!depth) {
319 return std::nullopt;
320 }
321
322 float3 proj_point;
323 if (ED_view3d_depth_unproject_v3(region_, int2(co), *depth, proj_point)) {
324 float3 view_normal;
325 ED_view3d_win_to_vector(region_, co, view_normal);
326 proj_point -= view_normal * surface_offset_;
327 return proj_point;
328 }
329 return std::nullopt;
330}
331
332std::optional<float> DrawingPlacement::get_depth(float2 co) const
333{
334 float depth;
335 if (depth_cache_ != nullptr && ED_view3d_depth_read_cached(depth_cache_, int2(co), 4, &depth)) {
336 return depth;
337 }
338 return std::nullopt;
339}
340
341float3 DrawingPlacement::try_project_depth(const float2 co) const
342{
343 if (std::optional<float3> proj_point = this->project_depth(co)) {
344 return *proj_point;
345 }
346
347 float3 proj_point;
348 /* Fall back to `View` placement. */
349 ED_view3d_win_to_3d(view3d_, region_, placement_loc_, co, proj_point);
350 return proj_point;
351}
352
353float3 DrawingPlacement::project(const float2 co, bool &r_clipped) const
354{
355 float3 proj_point;
356 if (depth_ == DrawingPlacementDepth::Surface) {
357 /* Project using the viewport depth cache. */
358 proj_point = this->try_project_depth(co);
359 r_clipped = false;
360 }
361 else {
362 if (placement_plane_) {
363 r_clipped = !ED_view3d_win_to_3d_on_plane(region_, *placement_plane_, co, true, proj_point);
364 }
365 else {
366 ED_view3d_win_to_3d(view3d_, region_, placement_loc_, co, proj_point);
367 r_clipped = false;
368 }
369 }
370 return math::transform_point(world_space_to_layer_space_, proj_point);
371}
373{
374 [[maybe_unused]] bool clipped_unused;
375 return this->project(co, clipped_unused);
376}
377
379{
380 float3 proj_point;
381 if (depth_ == DrawingPlacementDepth::Surface) {
382 /* Project using the viewport depth cache. */
383 proj_point = this->try_project_depth(co);
384 }
385 else {
386 if (placement_plane_) {
387 ED_view3d_win_to_3d_on_plane(region_, *placement_plane_, co, false, proj_point);
388 }
389 else {
390 ED_view3d_win_to_3d_with_shift(view3d_, region_, placement_loc_, co, proj_point);
391 }
392 }
393 return math::transform_point(world_space_to_layer_space_, proj_point);
394}
395
397{
398 threading::parallel_for(src.index_range(), 1024, [&](const IndexRange range) {
399 for (const int i : range) {
400 dst[i] = this->project(src[i]);
401 }
402 });
403}
404
405float3 DrawingPlacement::place(const float2 co, const float depth) const
406{
407 float3 loc;
408 ED_view3d_unproject_v3(region_, co.x, co.y, depth, loc);
409
410 if (depth_ == DrawingPlacementDepth::Surface) {
411 float3 view_normal;
412 ED_view3d_win_to_vector(region_, co, view_normal);
413 loc -= view_normal * surface_offset_;
414 }
415
416 return math::transform_point(world_space_to_layer_space_, loc);
417}
418
420{
421 const float3 world_pos = math::transform_point(layer_space_to_world_space_, pos);
422 float3 proj_point;
423 if (depth_ == DrawingPlacementDepth::Surface) {
424 /* First project the position into view space. */
425 float2 co;
426 if (ED_view3d_project_float_global(region_, world_pos, co, V3D_PROJ_TEST_NOP)) {
427 /* Can't reproject the point. */
428 return pos;
429 }
430 /* Project using the viewport depth cache. */
431 proj_point = this->try_project_depth(co);
432 }
433 else {
434 /* Reproject the point onto the `placement_plane_` from the current view. */
435 RegionView3D *rv3d = static_cast<RegionView3D *>(region_->regiondata);
436
437 float3 ray_no;
438 if (rv3d->is_persp) {
439 ray_no = math::normalize(world_pos - float3(rv3d->viewinv[3]));
440 }
441 else {
442 ray_no = -float3(rv3d->viewinv[2]);
443 }
444 float4 plane;
445 if (placement_plane_) {
446 plane = *placement_plane_;
447 }
448 else {
449 plane_from_point_normal_v3(plane, placement_loc_, rv3d->viewinv[2]);
450 }
451
452 float lambda;
453 if (isect_ray_plane_v3(world_pos, ray_no, plane, &lambda, false)) {
454 proj_point = world_pos + ray_no * lambda;
455 }
456 else {
457 return pos;
458 }
459 }
460 return math::transform_point(world_space_to_layer_space_, proj_point);
461}
462
464{
465 threading::parallel_for(src.index_range(), 1024, [&](const IndexRange range) {
466 for (const int i : range) {
467 dst[i] = this->reproject(src[i]);
468 }
469 });
470}
471
473{
474 return layer_space_to_world_space_;
475}
476
477static float get_frame_falloff(const bool use_multi_frame_falloff,
478 const int frame_number,
479 const int active_frame,
480 const std::optional<Bounds<int>> frame_bounds,
481 const CurveMapping *falloff_curve)
482{
483 if (!use_multi_frame_falloff || !frame_bounds.has_value() || falloff_curve == nullptr) {
484 return 1.0f;
485 }
486
487 const int min_frame = frame_bounds->min;
488 const int max_frame = frame_bounds->max;
489
490 /* Frame right of the center frame. */
491 if (frame_number < active_frame) {
492 const float frame_factor = 0.5f * float(frame_number - min_frame) / (active_frame - min_frame);
493 return BKE_curvemapping_evaluateF(falloff_curve, 0, frame_factor);
494 }
495 /* Frame left of the center frame. */
496 if (frame_number > active_frame) {
497 const float frame_factor = 0.5f * float(frame_number - active_frame) /
498 (max_frame - active_frame);
499 return BKE_curvemapping_evaluateF(falloff_curve, 0, frame_factor + 0.5f);
500 }
501 /* Frame at center. */
502 return BKE_curvemapping_evaluateF(falloff_curve, 0, 0.5f);
503}
504
505static std::optional<Bounds<int>> get_selected_frame_number_bounds(
507{
508 using namespace blender::bke::greasepencil;
509 if (!layer.is_editable()) {
510 return {};
511 }
512 Vector<int> frame_numbers;
513 for (const auto [frame_number, frame] : layer.frames().items()) {
514 if (frame.is_selected()) {
515 frame_numbers.append(frame_number);
516 }
517 }
518 return bounds::min_max<int>(frame_numbers);
519}
520
522 const std::optional<Bounds<int>> frame_bounds,
523 const int current_frame)
524{
525 const std::optional<int> current_start_frame = layer.start_frame_at(current_frame);
526 if (current_start_frame) {
527 return *current_start_frame;
528 }
529 if (frame_bounds) {
530 return math::clamp(current_frame, frame_bounds->min, frame_bounds->max);
531 }
532 /* Unused by get_frame_falloff() when there are no frame bounds. */
533 return current_frame;
534}
535
536static std::optional<int> get_frame_id(const bke::greasepencil::Layer &layer,
537 const GreasePencilFrame &frame,
538 const int frame_number,
539 const int frame_index,
540 const int current_frame,
541 const int current_frame_index,
542 const int last_frame,
543 const int last_frame_index,
544 const bool use_multi_frame_editing,
545 const bool do_onion_skinning,
546 const bool is_before_first,
547 const GreasePencilOnionSkinningSettings onion_settings)
548{
549 if (use_multi_frame_editing) {
550 if (frame.is_selected()) {
551 if (do_onion_skinning) {
552 return (frame_number < current_frame) ? -1 : 1;
553 }
554 return 0;
555 }
556 return {};
557 }
558 if (do_onion_skinning && layer.use_onion_skinning()) {
559 /* Keyframe type filter. */
560 if (onion_settings.filter != 0 && (onion_settings.filter & (1 << frame.type)) == 0) {
561 return {};
562 }
563 /* Selected mode filter. */
564 if (onion_settings.mode == GP_ONION_SKINNING_MODE_SELECTED && !frame.is_selected()) {
565 return {};
566 }
567
568 int delta = 0;
569 if (onion_settings.mode == GP_ONION_SKINNING_MODE_ABSOLUTE) {
570 delta = frame_number - current_frame;
571 }
572 else {
573 delta = frame_index - current_frame_index;
574 }
575
576 if (is_before_first) {
577 delta++;
578 }
579 if ((onion_settings.flag & GP_ONION_SKINNING_SHOW_LOOP) != 0 &&
580 (-delta > onion_settings.num_frames_before || delta > onion_settings.num_frames_after))
581 {
582 /* We wrap the value using the last frame and 0 as reference. */
583 /* FIXME: This might not be good for animations not starting at 0. */
584 int shift = 0;
585 if (onion_settings.mode == GP_ONION_SKINNING_MODE_ABSOLUTE) {
586 shift = last_frame;
587 }
588 else {
589 shift = last_frame_index;
590 }
591 delta += (delta < 0) ? (shift + 1) : -(shift + 1);
592 }
593 /* Frame range filter. */
594 if (ELEM(onion_settings.mode,
597 (-delta > onion_settings.num_frames_before || delta > onion_settings.num_frames_after))
598 {
599 return {};
600 }
601
602 return delta;
603 }
604 return {};
605}
606
610 const int current_frame,
611 const bool use_multi_frame_editing,
612 const bool do_onion_skinning)
613{
614 GreasePencilOnionSkinningSettings onion_settings = grease_pencil.onion_skinning_settings;
615 Vector<std::pair<int, int>> frame_numbers;
616 const Span<int> sorted_keys = layer.sorted_keys();
617 if (sorted_keys.is_empty()) {
618 return {};
619 }
620 const int current_frame_index = std::max(layer.sorted_keys_index_at(current_frame), 0);
621 const int last_frame = sorted_keys.last();
622 const int last_frame_index = sorted_keys.index_range().last();
623 const bool is_before_first = (current_frame < sorted_keys.first());
624 const std::optional<int> current_start_frame = layer.start_frame_at(current_frame);
625 for (const int frame_i : sorted_keys.index_range()) {
626 const int frame_number = sorted_keys[frame_i];
627 if (current_start_frame && *current_start_frame == frame_number) {
628 continue;
629 }
630 const GreasePencilFrame &frame = layer.frames().lookup(frame_number);
631 const std::optional<int> frame_id = get_frame_id(layer,
632 frame,
633 frame_number,
634 frame_i,
635 current_frame,
636 current_frame_index,
637 last_frame,
638 last_frame_index,
639 use_multi_frame_editing,
640 do_onion_skinning,
641 is_before_first,
642 onion_settings);
643 if (!frame_id.has_value()) {
644 /* Drawing on this frame is not visible. */
645 continue;
646 }
647
648 frame_numbers.append({frame_number, *frame_id});
649 }
650
651 frame_numbers.append({current_frame, 0});
652
653 return frame_numbers.as_span();
654}
655
658 const int current_frame,
659 const bool use_multi_frame_editing)
660{
661 using namespace blender::bke::greasepencil;
662 Vector<int> frame_numbers;
663 Set<const Drawing *> added_drawings;
664 if (use_multi_frame_editing) {
665 const Drawing *current_drawing = grease_pencil.get_drawing_at(layer, current_frame);
666 for (const auto [frame_number, frame] : layer.frames().items()) {
667 if (!frame.is_selected()) {
668 continue;
669 }
670 frame_numbers.append(frame_number);
671 added_drawings.add(grease_pencil.get_drawing_at(layer, frame_number));
672 }
673 if (added_drawings.contains(current_drawing)) {
674 return frame_numbers.as_span();
675 }
676 }
677
678 frame_numbers.append(current_frame);
679 return frame_numbers.as_span();
680}
681
684{
685 using namespace blender::bke::greasepencil;
686 const int current_frame = scene.r.cfra;
687 const ToolSettings *toolsettings = scene.toolsettings;
688 const bool use_multi_frame_editing = (toolsettings->gpencil_flags &
690
691 Vector<MutableDrawingInfo> editable_drawings;
692 Span<const Layer *> layers = grease_pencil.layers();
693 for (const int layer_i : layers.index_range()) {
694 const Layer &layer = *layers[layer_i];
695 if (!layer.is_editable()) {
696 continue;
697 }
698 const Array<int> frame_numbers = get_editable_frames_for_layer(
699 grease_pencil, layer, current_frame, use_multi_frame_editing);
700 for (const int frame_number : frame_numbers) {
701 if (Drawing *drawing = grease_pencil.get_editable_drawing_at(layer, frame_number)) {
702 editable_drawings.append({*drawing, layer_i, frame_number, 1.0f});
703 }
704 }
705 }
706
707 return editable_drawings;
708}
709
712{
713 using namespace blender::bke::greasepencil;
714 const int current_frame = scene.r.cfra;
715 const ToolSettings *toolsettings = scene.toolsettings;
716 const bool use_multi_frame_editing = (toolsettings->gpencil_flags &
718 const bool use_multi_frame_falloff = use_multi_frame_editing &&
719 (toolsettings->gp_sculpt.flag &
721 if (use_multi_frame_falloff) {
723 }
724
725 Vector<MutableDrawingInfo> editable_drawings;
726 Span<const Layer *> layers = grease_pencil.layers();
727 for (const int layer_i : layers.index_range()) {
728 const Layer &layer = *layers[layer_i];
729 if (!layer.is_editable()) {
730 continue;
731 }
732 const std::optional<Bounds<int>> frame_bounds = get_selected_frame_number_bounds(layer);
733 const int active_frame = get_active_frame_for_falloff(layer, frame_bounds, current_frame);
734 const Array<int> frame_numbers = get_editable_frames_for_layer(
735 grease_pencil, layer, current_frame, use_multi_frame_editing);
736 for (const int frame_number : frame_numbers) {
737 if (Drawing *drawing = grease_pencil.get_editable_drawing_at(layer, frame_number)) {
738 const float falloff = get_frame_falloff(use_multi_frame_falloff,
739 frame_number,
740 active_frame,
741 frame_bounds,
742 toolsettings->gp_sculpt.cur_falloff);
743 editable_drawings.append({*drawing, layer_i, frame_number, falloff});
744 }
745 }
746 }
747
748 return editable_drawings;
749}
750
752 const Scene &scene, GreasePencil &grease_pencil)
753{
754 using namespace blender::bke::greasepencil;
755 int current_frame = scene.r.cfra;
756 const ToolSettings *toolsettings = scene.toolsettings;
757 const bool use_multi_frame_editing = (toolsettings->gpencil_flags &
759 const bool use_multi_frame_falloff = use_multi_frame_editing &&
760 (toolsettings->gp_sculpt.flag &
762 if (use_multi_frame_falloff) {
764 }
765
766 /* Get a set of unique frame numbers with editable drawings on them. */
767 VectorSet<int> selected_frames;
768 Span<const Layer *> layers = grease_pencil.layers();
769 if (use_multi_frame_editing) {
770 for (const int layer_i : layers.index_range()) {
771 const Layer &layer = *layers[layer_i];
772 if (!layer.is_editable()) {
773 continue;
774 }
775 for (const auto [frame_number, frame] : layer.frames().items()) {
776 if (frame_number != current_frame && frame.is_selected()) {
777 selected_frames.add(frame_number);
778 }
779 }
780 }
781 }
782 selected_frames.add(current_frame);
783
784 /* Get drawings grouped per frame. */
785 Array<Vector<MutableDrawingInfo>> drawings_grouped_per_frame(selected_frames.size());
786 Set<const Drawing *> added_drawings;
787 for (const int layer_i : layers.index_range()) {
788 const Layer &layer = *layers[layer_i];
789 if (!layer.is_editable()) {
790 continue;
791 }
792 const std::optional<Bounds<int>> frame_bounds = get_selected_frame_number_bounds(layer);
793 const int active_frame = get_active_frame_for_falloff(layer, frame_bounds, current_frame);
794
795 /* In multi frame editing mode, add drawings at selected frames. */
796 if (use_multi_frame_editing) {
797 for (const auto [frame_number, frame] : layer.frames().items()) {
798 Drawing *drawing = grease_pencil.get_editable_drawing_at(layer, frame_number);
799 if (!frame.is_selected() || drawing == nullptr || added_drawings.contains(drawing)) {
800 continue;
801 }
802 const float falloff = get_frame_falloff(use_multi_frame_falloff,
803 frame_number,
804 active_frame,
805 frame_bounds,
806 toolsettings->gp_sculpt.cur_falloff);
807 const int frame_group = selected_frames.index_of(frame_number);
808 drawings_grouped_per_frame[frame_group].append({*drawing, layer_i, frame_number, falloff});
809 added_drawings.add_new(drawing);
810 }
811 }
812
813 /* Add drawing at current frame. */
814 Drawing *current_drawing = grease_pencil.get_drawing_at(layer, current_frame);
815 if (current_drawing != nullptr && !added_drawings.contains(current_drawing)) {
816 const float falloff = get_frame_falloff(use_multi_frame_falloff,
817 current_frame,
818 active_frame,
819 frame_bounds,
820 toolsettings->gp_sculpt.cur_falloff);
821 const int frame_group = selected_frames.index_of(current_frame);
822 drawings_grouped_per_frame[frame_group].append(
823 {*current_drawing, layer_i, current_frame, falloff});
824 added_drawings.add_new(current_drawing);
825 }
826 }
827
828 return drawings_grouped_per_frame;
829}
830
833{
834 using namespace blender::bke::greasepencil;
835 const int current_frame = scene.r.cfra;
836 const ToolSettings *toolsettings = scene.toolsettings;
837 const bool use_multi_frame_editing = (toolsettings->gpencil_flags &
839 const int layer_index = *grease_pencil.get_layer_index(layer);
840
841 Vector<MutableDrawingInfo> editable_drawings;
842 const Array<int> frame_numbers = get_editable_frames_for_layer(
843 grease_pencil, layer, current_frame, use_multi_frame_editing);
844 for (const int frame_number : frame_numbers) {
845 if (Drawing *drawing = grease_pencil.get_editable_drawing_at(layer, frame_number)) {
846 editable_drawings.append({*drawing, layer_index, frame_number, 1.0f});
847 }
848 }
849
850 return editable_drawings;
851}
852
855{
856 using namespace blender::bke::greasepencil;
857 const int current_frame = scene.r.cfra;
858 const ToolSettings *toolsettings = scene.toolsettings;
859 const bool use_multi_frame_editing = (toolsettings->gpencil_flags &
861 const bool use_multi_frame_falloff = use_multi_frame_editing &&
862 (toolsettings->gp_sculpt.flag &
864 const int layer_index = *grease_pencil.get_layer_index(layer);
865 std::optional<Bounds<int>> frame_bounds;
866 if (use_multi_frame_falloff) {
869 }
870
871 const int active_frame = get_active_frame_for_falloff(layer, frame_bounds, current_frame);
872
873 Vector<MutableDrawingInfo> editable_drawings;
874 const Array<int> frame_numbers = get_editable_frames_for_layer(
875 grease_pencil, layer, current_frame, use_multi_frame_editing);
876 for (const int frame_number : frame_numbers) {
877 if (Drawing *drawing = grease_pencil.get_editable_drawing_at(layer, frame_number)) {
878 const float falloff = get_frame_falloff(use_multi_frame_falloff,
879 frame_number,
880 active_frame,
881 frame_bounds,
882 toolsettings->gp_sculpt.cur_falloff);
883 editable_drawings.append({*drawing, layer_index, frame_number, falloff});
884 }
885 }
886
887 return editable_drawings;
888}
889
892 const bool do_onion_skinning)
893{
894 using namespace blender::bke::greasepencil;
895 const int current_frame = BKE_scene_ctime_get(&scene);
896 const ToolSettings *toolsettings = scene.toolsettings;
897 const bool use_multi_frame_editing = (toolsettings->gpencil_flags &
899
900 Vector<DrawingInfo> visible_drawings;
901 Span<const Layer *> layers = grease_pencil.layers();
902 for (const int layer_i : layers.index_range()) {
903 const Layer &layer = *layers[layer_i];
904 if (!layer.is_visible()) {
905 continue;
906 }
908 grease_pencil, layer, current_frame, use_multi_frame_editing, do_onion_skinning);
909 for (const auto &[frame_number, onion_id] : frames) {
910 if (const Drawing *drawing = grease_pencil.get_drawing_at(layer, frame_number)) {
911 visible_drawings.append({*drawing, layer_i, frame_number, onion_id});
912 }
913 }
914 }
915
916 return visible_drawings;
917}
918
920{
921 BLI_assert(object.type == OB_GREASE_PENCIL);
922 VectorSet<int> locked_material_indices;
923 for (const int mat_i : IndexRange(object.totcol)) {
924 Material *material = BKE_object_material_get(&object, mat_i + 1);
925 /* The editable materials are unlocked and not hidden. */
926 if (material != nullptr && material->gp_style != nullptr &&
927 ((material->gp_style->flag & GP_MATERIAL_LOCKED) != 0 ||
928 (material->gp_style->flag & GP_MATERIAL_HIDE) != 0))
929 {
930 locked_material_indices.add_new(mat_i);
931 }
932 }
933 return locked_material_indices;
934}
935
937{
938 BLI_assert(object.type == OB_GREASE_PENCIL);
939 VectorSet<int> hidden_material_indices;
940 for (const int mat_i : IndexRange(object.totcol)) {
941 Material *material = BKE_object_material_get(&object, mat_i + 1);
942 if (material != nullptr && material->gp_style != nullptr &&
943 (material->gp_style->flag & GP_MATERIAL_HIDE) != 0)
944 {
945 hidden_material_indices.add_new(mat_i);
946 }
947 }
948 return hidden_material_indices;
949}
950
952 const bke::greasepencil::Drawing &drawing,
953 int layer_index,
954 IndexMaskMemory &memory)
955{
956 const bke::CurvesGeometry &curves = drawing.strokes();
957 const IndexRange curves_range = curves.curves_range();
958
959 if (object.totcol == 0) {
960 return IndexMask(curves_range);
961 }
962
963 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
964 const bke::greasepencil::Layer &layer = *grease_pencil.layers()[layer_index];
965
966 /* If we're not using material locking, the entire curves range is editable. */
967 if (layer.ignore_locked_materials()) {
968 return IndexMask(curves_range);
969 }
970
971 /* Get all the editable material indices */
972 VectorSet<int> locked_material_indices = get_locked_material_indices(object);
973 if (locked_material_indices.is_empty()) {
974 return curves_range;
975 }
976
977 const bke::AttributeAccessor attributes = curves.attributes();
978 const VArray<int> materials = *attributes.lookup_or_default<int>(
979 "material_index", bke::AttrDomain::Curve, 0);
980 if (!materials) {
981 /* If the attribute does not exist then the default is the first material. */
982 if (locked_material_indices.contains(0)) {
983 return {};
984 }
985 return curves_range;
986 }
987 /* Get all the strokes that have their material unlocked. */
988 return IndexMask::from_predicate(curves_range, memory, [&](const int64_t curve_i) {
989 return !locked_material_indices.contains(materials[curve_i]);
990 });
991}
992
994 const bke::greasepencil::Drawing &drawing,
995 int layer_index,
996 IndexMaskMemory &memory)
997{
998 const IndexMask editable_strokes = retrieve_editable_strokes(
999 object, drawing, layer_index, memory);
1000 if (editable_strokes.is_empty()) {
1001 return {};
1002 }
1003
1004 const bke::CurvesGeometry &curves = drawing.strokes();
1005 const IndexRange curves_range = curves.curves_range();
1006
1007 const bke::AttributeAccessor attributes = curves.attributes();
1008 const VArray<int> fill_ids = *attributes.lookup_or_default<int>(
1009 "fill_id", bke::AttrDomain::Curve, 0);
1010 if (!fill_ids) {
1011 return {};
1012 }
1013 const IndexMask fill_strokes = IndexMask::from_predicate(
1014 curves_range, memory, [&](const int64_t curve_i) { return fill_ids[curve_i] != 0; });
1015 return IndexMask::from_intersection(editable_strokes, fill_strokes, memory);
1016}
1017
1019 const bke::greasepencil::Drawing &drawing,
1020 const int mat_i,
1021 IndexMaskMemory &memory)
1022{
1023 const bke::CurvesGeometry &curves = drawing.strokes();
1024 const IndexRange curves_range = curves.curves_range();
1025
1026 /* Get all the editable material indices */
1027 VectorSet<int> locked_material_indices = get_locked_material_indices(object);
1028
1029 const bke::AttributeAccessor attributes = curves.attributes();
1030
1031 const VArray<int> materials = *attributes.lookup_or_default<int>(
1032 "material_index", bke::AttrDomain::Curve, 0);
1033 if (!materials) {
1034 /* If the attribute does not exist then the default is the first material. */
1035 if (locked_material_indices.contains(0)) {
1036 return {};
1037 }
1038 return curves_range;
1039 }
1040 /* Get all the strokes that share the same material and have it unlocked. */
1041 return IndexMask::from_predicate(curves_range, memory, [&](const int64_t curve_i) {
1042 const int material_index = materials[curve_i];
1043 if (material_index == mat_i) {
1044 return !locked_material_indices.contains(material_index);
1045 }
1046 return false;
1047 });
1048}
1049
1051 const bke::greasepencil::Drawing &drawing,
1052 int layer_index,
1053 IndexMaskMemory &memory)
1054{
1055 const bke::CurvesGeometry &curves = drawing.strokes();
1056 const IndexRange points_range = curves.points_range();
1057
1058 if (object.totcol == 0) {
1059 return IndexMask(points_range);
1060 }
1061
1062 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
1063 const bke::greasepencil::Layer &layer = *grease_pencil.layers()[layer_index];
1064
1065 /* If we're not using material locking, the entire points range is editable. */
1066 if (layer.ignore_locked_materials()) {
1067 return IndexMask(points_range);
1068 }
1069
1070 /* Get all the editable material indices */
1071 VectorSet<int> locked_material_indices = get_locked_material_indices(object);
1072 if (locked_material_indices.is_empty()) {
1073 return points_range;
1074 }
1075
1076 /* Propagate the material index to the points. */
1077 const bke::AttributeAccessor attributes = curves.attributes();
1078 const VArray<int> materials = *attributes.lookup_or_default<int>(
1079 "material_index", bke::AttrDomain::Point, 0);
1080 if (!materials) {
1081 /* If the attribute does not exist then the default is the first material. */
1082 if (locked_material_indices.contains(0)) {
1083 return {};
1084 }
1085 return points_range;
1086 }
1087 /* Get all the points that are part of a stroke with an unlocked material. */
1088 return IndexMask::from_predicate(points_range, memory, [&](const int64_t point_i) {
1089 return !locked_material_indices.contains(materials[point_i]);
1090 });
1091}
1092
1094 const MutableDrawingInfo &info,
1095 const bke::AttrDomain selection_domain,
1096 IndexMaskMemory &memory)
1097{
1098
1099 const bke::greasepencil::Drawing &drawing = info.drawing;
1100 if (selection_domain == bke::AttrDomain::Curve) {
1101 return ed::greasepencil::retrieve_editable_strokes(object, drawing, info.layer_index, memory);
1102 }
1103 if (selection_domain == bke::AttrDomain::Point) {
1104 return ed::greasepencil::retrieve_editable_points(object, drawing, info.layer_index, memory);
1105 }
1106 return {};
1107}
1108
1110 const bke::greasepencil::Drawing &drawing,
1111 IndexMaskMemory &memory)
1112{
1113 /* Get all the hidden material indices. */
1114 VectorSet<int> hidden_material_indices = get_hidden_material_indices(object);
1115
1116 if (hidden_material_indices.is_empty()) {
1117 return drawing.strokes().curves_range();
1118 }
1119
1120 const bke::CurvesGeometry &curves = drawing.strokes();
1121 const IndexRange curves_range = drawing.strokes().curves_range();
1122 const bke::AttributeAccessor attributes = curves.attributes();
1123
1124 /* Get all the strokes that have their material visible. */
1125 const VArray<int> materials = *attributes.lookup_or_default<int>(
1126 "material_index", bke::AttrDomain::Curve, 0);
1127 return IndexMask::from_predicate(curves_range, memory, [&](const int64_t curve_i) {
1128 const int material_index = materials[curve_i];
1129 return !hidden_material_indices.contains(material_index);
1130 });
1131}
1132
1134 const bke::greasepencil::Drawing &drawing,
1135 IndexMaskMemory &memory)
1136{
1137 /* Get all the hidden material indices. */
1138 VectorSet<int> hidden_material_indices = get_hidden_material_indices(object);
1139
1140 if (hidden_material_indices.is_empty()) {
1141 return drawing.strokes().points_range();
1142 }
1143
1144 const bke::CurvesGeometry &curves = drawing.strokes();
1145 const IndexRange points_range = curves.points_range();
1146 const bke::AttributeAccessor attributes = curves.attributes();
1147
1148 /* Propagate the material index to the points. */
1149 const VArray<int> materials = *attributes.lookup_or_default<int>(
1150 "material_index", bke::AttrDomain::Point, 0);
1151 if (const std::optional<int> single_material = materials.get_if_single()) {
1152 if (!hidden_material_indices.contains(*single_material)) {
1153 return points_range;
1154 }
1155 return {};
1156 }
1157
1158 /* Get all the points that are part of a stroke with a visible material. */
1159 return IndexMask::from_predicate(points_range, memory, [&](const int64_t point_i) {
1160 const int material_index = materials[point_i];
1161 return !hidden_material_indices.contains(material_index);
1162 });
1163}
1164
1166 const bke::greasepencil::Drawing &drawing,
1167 IndexMaskMemory &memory)
1168{
1169 const bke::CurvesGeometry &curves = drawing.strokes();
1170
1171 if (!curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
1172 return IndexMask(0);
1173 }
1174
1175 const IndexRange curves_range = curves.curves_range();
1176 const VArray<int8_t> curve_types = curves.curve_types();
1177 const std::array<int, CURVE_TYPES_NUM> type_counts = curves.curve_type_counts();
1178
1179 const IndexMask bezier_strokes = bke::curves::indices_for_type(
1180 curve_types, type_counts, CURVE_TYPE_BEZIER, curves_range, memory);
1181
1183 object, drawing, memory);
1184
1185 return IndexMask::from_intersection(visible_strokes, bezier_strokes, memory);
1186}
1187
1189 const bke::greasepencil::Drawing &drawing,
1190 IndexMaskMemory &memory)
1191{
1192 const bke::CurvesGeometry &curves = drawing.strokes();
1193
1194 if (!curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
1195 return IndexMask(0);
1196 }
1197
1198 const IndexMask visible_bezier_strokes = retrieve_visible_bezier_strokes(
1199 object, drawing, memory);
1200
1201 return IndexMask::from_ranges(curves.points_by_curve(), visible_bezier_strokes, memory);
1202}
1203
1208
1210 const bke::greasepencil::Drawing &drawing,
1211 const eHandleDisplay handle_display,
1212 IndexMaskMemory &memory)
1213{
1214 if (handle_display == CURVE_HANDLE_NONE) {
1215 return IndexMask(0);
1216 }
1217
1218 const bke::CurvesGeometry &curves = drawing.strokes();
1219
1220 if (!curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
1221 return IndexMask(0);
1222 }
1223
1224 const IndexMask visible_bezier_strokes = retrieve_visible_bezier_strokes(
1225 object, drawing, memory);
1226
1227 if (handle_display == CURVE_HANDLE_ALL) {
1228 return visible_bezier_strokes;
1229 }
1230
1231 /* handle_display == CURVE_HANDLE_SELECTED */
1232 const IndexMask selected_strokes = ed::curves::retrieve_selected_curves(curves, memory);
1233 return IndexMask::from_intersection(visible_bezier_strokes, selected_strokes, memory);
1234}
1235
1237 const bke::greasepencil::Drawing &drawing,
1238 IndexMaskMemory &memory)
1239{
1240 VectorSet<int> hidden_material_indices = get_hidden_material_indices(object);
1241
1242 const std::optional<GroupedSpan<int>> fills = drawing.fills();
1243 if (!fills) {
1244 return {};
1245 }
1246
1247 if (hidden_material_indices.is_empty()) {
1248 return fills->index_range();
1249 }
1250
1251 const bke::CurvesGeometry &curves = drawing.strokes();
1252 const bke::AttributeAccessor attributes = curves.attributes();
1253
1254 /* Get all the fills that have their first curve's material visible. */
1255 const VArray<int> materials = *attributes.lookup_or_default<int>(
1256 "material_index", bke::AttrDomain::Curve, 0);
1257 return IndexMask::from_predicate(fills->index_range(), memory, [&](const int64_t fill_index) {
1258 const Span<int> fill = (*fills)[fill_index];
1259 const int curve_i = fill.first();
1260 const int material_index = materials[curve_i];
1261 return !hidden_material_indices.contains(material_index);
1262 });
1263}
1264
1266 const bke::greasepencil::Drawing &drawing,
1267 const int layer_index,
1268 const eHandleDisplay handle_display,
1269 IndexMaskMemory &memory)
1270{
1271 if (handle_display == CURVE_HANDLE_NONE) {
1272 return IndexMask(0);
1273 }
1274 if (handle_display == CURVE_HANDLE_ALL) {
1275 return retrieve_visible_bezier_points(object, drawing, memory);
1276 }
1277 /* else handle_display == CURVE_HANDLE_SELECTED */
1278
1279 const bke::CurvesGeometry &curves = drawing.strokes();
1280
1281 if (!curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
1282 return IndexMask(0);
1283 }
1284
1285 const Array<int> point_to_curve_map = curves.point_to_curve_map();
1286 const VArray<int8_t> types = curves.curve_types();
1287
1288 const VArray<bool> selected_point = *curves.attributes().lookup_or_default<bool>(
1289 ".selection", bke::AttrDomain::Point, true);
1290 const VArray<bool> selected_left = *curves.attributes().lookup_or_default<bool>(
1291 ".selection_handle_left", bke::AttrDomain::Point, true);
1292 const VArray<bool> selected_right = *curves.attributes().lookup_or_default<bool>(
1293 ".selection_handle_right", bke::AttrDomain::Point, true);
1294
1296 object, drawing, layer_index, memory);
1297
1298 const IndexMask selected_points = IndexMask::from_predicate(
1299 curves.points_range(), memory, [&](const int64_t point_i) {
1300 const bool is_selected = selected_point[point_i] || selected_left[point_i] ||
1301 selected_right[point_i];
1302 const bool is_bezier = types[point_to_curve_map[point_i]] == CURVE_TYPE_BEZIER;
1303 return is_selected && is_bezier;
1304 });
1305
1306 return IndexMask::from_intersection(editable_points, selected_points, memory);
1307}
1308
1310 const bke::greasepencil::Drawing &drawing,
1311 const int layer_index,
1312 const bke::AttrDomain selection_domain,
1313 const eHandleDisplay handle_display,
1314 IndexMaskMemory &memory)
1315{
1316 if (selection_domain == bke::AttrDomain::Curve) {
1318 object, drawing, CURVE_HANDLE_NONE, memory);
1319 }
1320 if (selection_domain == bke::AttrDomain::Point) {
1322 object, drawing, layer_index, handle_display, memory);
1323 }
1324 return {};
1325}
1326
1328 const bke::greasepencil::Drawing &drawing,
1329 int layer_index,
1330 IndexMaskMemory &memory)
1331{
1332 const bke::CurvesGeometry &curves = drawing.strokes();
1333
1334 const IndexMask editable_strokes = retrieve_editable_strokes(
1335 object, drawing, layer_index, memory);
1336 const IndexMask selected_strokes = ed::curves::retrieve_selected_curves(curves, memory);
1337
1338 return IndexMask::from_intersection(editable_strokes, selected_strokes, memory);
1339}
1340
1342 const bke::greasepencil::Drawing &drawing,
1343 int layer_index,
1344 IndexMaskMemory &memory)
1345{
1346 const bke::CurvesGeometry &curves = drawing.strokes();
1347
1348 const IndexMask editable_strokes = retrieve_editable_fill_strokes(
1349 object, drawing, layer_index, memory);
1350 const IndexMask selected_strokes = ed::curves::retrieve_selected_curves(curves, memory);
1351
1352 return IndexMask::from_intersection(editable_strokes, selected_strokes, memory);
1353}
1354
1356 const bke::greasepencil::Drawing &drawing,
1357 int layer_index,
1358 IndexMaskMemory &memory)
1359{
1360 const bke::CurvesGeometry &curves = drawing.strokes();
1361
1362 const IndexMask editable_points = retrieve_editable_points(object, drawing, layer_index, memory);
1363 const IndexMask selected_points = ed::curves::retrieve_selected_points(curves, memory);
1364
1365 return IndexMask::from_intersection(editable_points, selected_points, memory);
1366}
1367
1369 const bke::greasepencil::Drawing &drawing,
1370 int layer_index,
1371 const bke::AttrDomain selection_domain,
1372 IndexMaskMemory &memory)
1373{
1374 if (selection_domain == bke::AttrDomain::Curve) {
1376 object, drawing, layer_index, memory);
1377 }
1378 if (selection_domain == bke::AttrDomain::Point) {
1380 object, drawing, layer_index, memory);
1381 }
1382 return {};
1383}
1384
1386 const bke::greasepencil::Drawing &drawing,
1387 const int layer_index,
1388 const eHandleDisplay handle_display,
1389 IndexMaskMemory &memory)
1390{
1391 const bke::CurvesGeometry &curves = drawing.strokes();
1392
1393 const IndexMask editable_points = retrieve_editable_points(object, drawing, layer_index, memory);
1395 curves, handle_display, memory);
1396
1397 return IndexMask::from_intersection(editable_points, selected_points, memory);
1398}
1399
1401{
1402 using namespace blender::bke::greasepencil;
1403 for (const Layer *layer : grease_pencil.layers()) {
1404 if (layer->is_editable()) {
1405 return true;
1406 }
1407 }
1408 return false;
1409}
1410
1412 const bke::CurvesGeometry &src,
1414 const Span<Vector<PointTransferData>> src_to_dst_points,
1415 const bool keep_caps)
1416{
1417 const int src_curves_num = src.curves_num();
1418 const OffsetIndices<int> src_points_by_curve = src.points_by_curve();
1419 const VArray<bool> src_cyclic = src.cyclic();
1420
1421 int dst_points_num = 0;
1422 for (const Vector<PointTransferData> &src_transfer_data : src_to_dst_points) {
1423 dst_points_num += src_transfer_data.size();
1424 }
1425 if (dst_points_num == 0) {
1426 dst.resize(0, 0);
1427 return Array<PointTransferData>(0);
1428 }
1429
1430 /* Set the intersection parameters in the destination domain : a pair of int and float
1431 * numbers for which the integer is the index of the corresponding segment in the
1432 * source curves, and the float part is the (0,1) factor representing its position in
1433 * the segment.
1434 */
1435 Array<PointTransferData> dst_transfer_data(dst_points_num);
1436
1437 Array<int> src_pivot_point(src_curves_num, -1);
1438 Array<int> dst_interm_curves_offsets(src_curves_num + 1, 0);
1439 int dst_point = -1;
1440 for (const int src_curve : src.curves_range()) {
1441 const IndexRange src_points = src_points_by_curve[src_curve];
1442
1443 for (const int src_point : src_points) {
1444 for (const PointTransferData &dst_point_transfer : src_to_dst_points[src_point]) {
1445 if (dst_point_transfer.is_src_point) {
1446 dst_transfer_data[++dst_point] = dst_point_transfer;
1447 continue;
1448 }
1449
1450 /* Add an intersection with the eraser and mark it as a cut. */
1451 dst_transfer_data[++dst_point] = dst_point_transfer;
1452
1453 /* For cyclic curves, mark the pivot point as the last intersection with the eraser
1454 * that starts a new segment in the destination.
1455 */
1456 if (src_cyclic[src_curve] && dst_point_transfer.is_cut) {
1457 src_pivot_point[src_curve] = dst_point;
1458 }
1459 }
1460 }
1461 /* We store intermediate curve offsets represent an intermediate state of the
1462 * destination curves before cutting the curves at eraser's intersection. Thus, it
1463 * contains the same number of curves than in the source, but the offsets are
1464 * different, because points may have been added or removed. */
1465 dst_interm_curves_offsets[src_curve + 1] = dst_point + 1;
1466 }
1467
1468 /* Cyclic curves. */
1469 Array<bool> src_now_cyclic(src_curves_num);
1470 threading::parallel_for(src.curves_range(), 4096, [&](const IndexRange src_curves) {
1471 for (const int src_curve : src_curves) {
1472 const int pivot_point = src_pivot_point[src_curve];
1473
1474 if (pivot_point == -1) {
1475 /* Either the curve was not cyclic or it wasn't cut : no need to change it. */
1476 src_now_cyclic[src_curve] = src_cyclic[src_curve];
1477 continue;
1478 }
1479
1480 /* A cyclic curve was cut :
1481 * - this curve is not cyclic anymore,
1482 * - and we have to shift points to keep the closing segment.
1483 */
1484 src_now_cyclic[src_curve] = false;
1485
1486 const int dst_interm_first = dst_interm_curves_offsets[src_curve];
1487 const int dst_interm_last = dst_interm_curves_offsets[src_curve + 1];
1488 std::rotate(dst_transfer_data.begin() + dst_interm_first,
1489 dst_transfer_data.begin() + pivot_point,
1490 dst_transfer_data.begin() + dst_interm_last);
1491 }
1492 });
1493
1494 /* Compute the destination curve offsets. */
1495 Vector<int> dst_curves_offset;
1496 Vector<int> dst_to_src_curve;
1497 dst_curves_offset.append(0);
1498 for (int src_curve : src.curves_range()) {
1499 const IndexRange dst_points(dst_interm_curves_offsets[src_curve],
1500 dst_interm_curves_offsets[src_curve + 1] -
1501 dst_interm_curves_offsets[src_curve]);
1502 int length_of_current = 0;
1503
1504 for (int dst_point : dst_points) {
1505
1506 if ((length_of_current > 0) && dst_transfer_data[dst_point].is_cut) {
1507 /* This is the new first point of a curve. */
1508 dst_curves_offset.append(dst_point);
1509 dst_to_src_curve.append(src_curve);
1510 length_of_current = 0;
1511 }
1512 ++length_of_current;
1513 }
1514
1515 if (length_of_current != 0) {
1516 /* End of a source curve. */
1517 dst_curves_offset.append(dst_points.one_after_last());
1518 dst_to_src_curve.append(src_curve);
1519 }
1520 }
1521 const int dst_curves_num = dst_curves_offset.size() - 1;
1522 if (dst_curves_num == 0) {
1523 dst.resize(0, 0);
1524 return dst_transfer_data;
1525 }
1526
1527 /* Build destination curves geometry. */
1528 dst.resize(dst_points_num, dst_curves_num);
1529 array_utils::copy(dst_curves_offset.as_span(), dst.offsets_for_write());
1530 const OffsetIndices<int> dst_points_by_curve = dst.points_by_curve();
1531
1532 /* Vertex group names. */
1533 BLI_assert(dst.vertex_group_names.count() == 0);
1534 BKE_defgroup_copy_list(&dst.vertex_group_names, &src.vertex_group_names);
1535
1536 /* Attributes. */
1537 const bke::AttributeAccessor src_attributes = src.attributes();
1538 bke::MutableAttributeAccessor dst_attributes = dst.attributes_for_write();
1539
1540 /* Copy curves attributes. */
1541 bke::gather_attributes(src_attributes,
1545 dst_to_src_curve,
1546 dst_attributes);
1547 if (src_cyclic.get_if_single().value_or(true)) {
1549 src_now_cyclic.as_span(), dst_to_src_curve.as_span(), dst.cyclic_for_write());
1550 }
1551
1552 dst.update_curve_types();
1553
1554 /* Display intersections with flat caps. */
1555 if (!keep_caps) {
1556 bke::SpanAttributeWriter<int8_t> dst_start_caps =
1557 dst_attributes.lookup_or_add_for_write_span<int8_t>("start_cap", bke::AttrDomain::Curve);
1558 bke::SpanAttributeWriter<int8_t> dst_end_caps =
1560
1561 threading::parallel_for(dst.curves_range(), 4096, [&](const IndexRange dst_curves) {
1562 for (const int dst_curve : dst_curves) {
1563 const IndexRange dst_curve_points = dst_points_by_curve[dst_curve];
1564 const PointTransferData &start_point_transfer =
1565 dst_transfer_data[dst_curve_points.first()];
1566 const PointTransferData &end_point_transfer = dst_transfer_data[dst_curve_points.last()];
1567
1568 if (dst_start_caps && start_point_transfer.is_cut) {
1569 dst_start_caps.span[dst_curve] = GP_STROKE_CAP_TYPE_FLAT;
1570 }
1571 /* The is_cut flag does not work for end points, but any end point that isn't the source
1572 * point must also be a cut. */
1573 if (dst_end_caps && !end_point_transfer.is_src_end_point()) {
1574 dst_end_caps.span[dst_curve] = GP_STROKE_CAP_TYPE_FLAT;
1575 }
1576 }
1577 });
1578
1579 dst_start_caps.finish();
1580 dst_end_caps.finish();
1581 }
1582
1583 /* Copy/Interpolate point attributes. */
1584 for (bke::AttributeTransferData &attribute : bke::retrieve_attributes_for_transfer(
1585 src_attributes, dst_attributes, {bke::AttrDomain::Point}))
1586 {
1587 bke::attribute_math::to_static_type(attribute.dst.span.type(), [&]<typename T>() {
1588 if constexpr (!std::is_same_v<T, std::string>) {
1589 auto src_attr = attribute.src.typed<T>();
1590 auto dst_attr = attribute.dst.span.typed<T>();
1591
1592 threading::parallel_for(dst.points_range(), 4096, [&](const IndexRange dst_points) {
1593 for (const int dst_point : dst_points) {
1594 const PointTransferData &point_transfer = dst_transfer_data[dst_point];
1595 if (point_transfer.is_src_point) {
1596 dst_attr[dst_point] = src_attr[point_transfer.src_point];
1597 }
1598 else {
1599 dst_attr[dst_point] = bke::attribute_math::mix2<T>(
1600 point_transfer.factor,
1601 src_attr[point_transfer.src_point],
1602 src_attr[point_transfer.src_next_point]);
1603 }
1604 }
1605 });
1606 }
1607
1608 attribute.dst.finish();
1609 });
1610 }
1611
1612 return dst_transfer_data;
1613}
1614
1616 const ARegion *region,
1617 const float3 center,
1618 const float4x4 to_world,
1619 const float pixel_radius)
1620{
1621 const float2 xy_delta = float2(pixel_radius, 0.0f);
1622 const float3 loc = math::transform_point(to_world, center);
1623
1624 const float zfac = ED_view3d_calc_zfac(rv3d, loc);
1625 float3 delta;
1626 ED_view3d_win_to_delta(region, xy_delta, zfac, delta);
1627
1628 const float scale = math::length(
1629 math::transform_direction(to_world, float3(std::numbers::inv_sqrt3)));
1630
1631 return math::safe_divide(math::length(delta), scale);
1632}
1633
1635 const ARegion *region,
1636 const Paint *paint,
1637 const Brush *brush,
1638 const float3 location,
1639 const float4x4 to_world)
1640{
1641 if ((brush->flag & BRUSH_LOCK_SIZE) == 0) {
1643 rv3d, region, location, to_world, BKE_brush_radius_get(paint, brush));
1644 }
1646}
1647
1649 const ARegion *region,
1650 const Paint &paint,
1651 const Brush *brush,
1652 const float pressure,
1653 const float3 &location,
1654 const float4x4 &to_world,
1655 const BrushGpencilSettings *settings)
1656{
1657 float radius = brush_radius_at_location(rv3d, region, &paint, brush, location, to_world);
1659 radius *= BKE_curvemapping_evaluateF(settings->curve_sensitivity, 0, pressure);
1660 }
1661 return radius;
1662}
1663
1664float opacity_from_input_sample(const float pressure,
1665 const Paint &paint,
1666 const Brush *brush,
1667 const BrushGpencilSettings *settings)
1668{
1669 float opacity = BKE_brush_alpha_get(&paint, brush);
1671 opacity *= BKE_curvemapping_evaluateF(settings->curve_strength, 0, pressure);
1672 }
1673 return opacity;
1674}
1675
1682
1684 const Brush &brush)
1685{
1687 if (!material) {
1689 }
1690
1691 const bool is_stroke_visible = material->gp_style->stroke_rgba[3] > 0.0f;
1692 const bool is_fill_visible = material->gp_style->fill_rgba[3] > 0.0f;
1693
1694 const bool brush_uses_stroke = (brush.gpencil_settings->flag2 & GP_BRUSH_USE_STROKE) != 0;
1695 const bool brush_uses_fill = (brush.gpencil_settings->flag2 & GP_BRUSH_USE_FILL) != 0;
1696 if (brush_uses_stroke && !brush_uses_fill && !is_stroke_visible) {
1698 }
1699 if (!brush_uses_stroke && brush_uses_fill && !is_fill_visible) {
1701 }
1702 if (brush_uses_stroke && brush_uses_fill && !is_stroke_visible && !is_fill_visible) {
1704 }
1705 BLI_assert(brush_uses_stroke || brush_uses_fill);
1707}
1708
1710 wmOperator *op,
1711 const bool use_duplicate_previous_key)
1712{
1713 const Scene *scene = CTX_data_scene(C);
1714 Object *object = CTX_data_active_object(C);
1715 if (!object || object->type != OB_GREASE_PENCIL) {
1716 return false;
1717 }
1718
1719 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
1720 if (!grease_pencil.has_active_layer()) {
1721 BKE_report(op->reports, RPT_ERROR, "No active Grease Pencil layer");
1722 return false;
1723 }
1724
1727 if (brush == nullptr) {
1728 return false;
1729 }
1730
1731 bke::greasepencil::Layer &active_layer = *grease_pencil.get_active_layer();
1732
1733 if (!active_layer.is_editable()) {
1734 BKE_report(op->reports, RPT_ERROR, "Active layer is locked or hidden");
1735 return false;
1736 }
1737
1740 {
1741 BKE_report(op->reports, RPT_ERROR, "Cannot create new material on linked object");
1742 return false;
1743 }
1744
1745 /* Ensure a drawing at the current keyframe. */
1746 bool inserted_keyframe = false;
1748 *scene, grease_pencil, active_layer, use_duplicate_previous_key, inserted_keyframe))
1749 {
1750 BKE_report(op->reports, RPT_ERROR, "No Grease Pencil frame to draw on");
1751 return false;
1752 }
1753
1754 if (inserted_keyframe) {
1755 for (bke::greasepencil::Layer *layer : grease_pencil.layers_for_write()) {
1756 for (auto [frame_number, frame] : layer->frames_for_write().items()) {
1757 const bool select_keyframe = (frame_number == scene->r.cfra) && (layer == &active_layer);
1758 SET_FLAG_FROM_TEST(frame.flag, select_keyframe, GP_FRAME_SELECTED);
1759 }
1760 }
1762 }
1763
1764 const StrokeVisibilityStatus visibility_status = get_visibility_status_for_draw_operator(object,
1765 *brush);
1766 if (visibility_status != StrokeVisibilityStatus::Visible) {
1767 switch (visibility_status) {
1769 BKE_report(op->reports, RPT_WARNING, "Stroke is fully transparent");
1770 break;
1772 BKE_report(op->reports, RPT_WARNING, "Fill is fully transparent");
1773 break;
1775 BKE_report(op->reports, RPT_WARNING, "Stroke & Fill are fully transparent");
1776 break;
1777 default:
1778 break;
1779 }
1780 }
1781 return true;
1782}
1783
1785 const ARegion *region,
1786 const float2 &mouse,
1787 const DrawingPlacement &placement)
1788{
1789 float3 u_dir;
1790 float3 v_dir;
1791 /* Set the texture space origin to be the first point. */
1792 float3 origin = placement.project(mouse);
1793 /* Align texture with the drawing plane. */
1794 switch (scene->toolsettings->gp_sculpt.lock_axis) {
1795 case GP_LOCKAXIS_VIEW:
1796 u_dir = math::normalize(placement.project(float2(region->winx, 0.0f) + mouse) - origin);
1797 v_dir = math::normalize(placement.project(float2(0.0f, region->winy) + mouse) - origin);
1798 break;
1799 case GP_LOCKAXIS_Y:
1800 u_dir = float3(1.0f, 0.0f, 0.0f);
1801 v_dir = float3(0.0f, 0.0f, 1.0f);
1802 break;
1803 case GP_LOCKAXIS_X:
1804 u_dir = float3(0.0f, 1.0f, 0.0f);
1805 v_dir = float3(0.0f, 0.0f, 1.0f);
1806 break;
1807 case GP_LOCKAXIS_Z:
1808 u_dir = float3(1.0f, 0.0f, 0.0f);
1809 v_dir = float3(0.0f, 1.0f, 0.0f);
1810 break;
1811 case GP_LOCKAXIS_CURSOR: {
1812 const float3x3 mat = scene->cursor.matrix<float3x3>();
1813 u_dir = mat * float3(1.0f, 0.0f, 0.0f);
1814 v_dir = mat * float3(0.0f, 1.0f, 0.0f);
1815 origin = float3(scene->cursor.location);
1816 break;
1817 }
1818 }
1819
1820 return math::transpose(float2x4(float4(u_dir, -math::dot(u_dir, origin)),
1821 float4(v_dir, -math::dot(v_dir, origin))));
1822}
1823
1825{
1826 GreasePencil *grease_pencil = static_cast<GreasePencil *>(
1827 CTX_data_pointer_get_type(&C, "grease_pencil", RNA_GreasePencil).data);
1828
1829 if (grease_pencil == nullptr) {
1830 Object *object = CTX_data_active_object(&C);
1831 if (object && object->type == OB_GREASE_PENCIL) {
1832 grease_pencil = id_cast<GreasePencil *>(object->data);
1833 }
1834 }
1835 return grease_pencil;
1836}
1837
1838void add_single_curve(bke::greasepencil::Drawing &drawing, const bool at_end)
1839{
1841 if (at_end) {
1842 const int num_old_curves = curves.curves_num();
1843 const int num_old_points = curves.points_num();
1844 curves.resize(curves.points_num() + 1, curves.curves_num() + 1);
1845 curves.offsets_for_write().last(1) = num_old_points;
1846
1847 /* Note: The triangle cache doesn't need to be resized here because the new curve has a single
1848 * point and can't form a new triangle yet. However, the `curve_plane_normals_cache` and
1849 * `curve_texture_matrices` are expected to have the same size as the number of curves in the
1850 * drawing. */
1851 drawing.runtime->curve_plane_normals_cache.update(
1852 [&](Vector<float3> &normals) { normals.append(float3(0, 0, 1)); });
1853 drawing.runtime->curve_texture_matrices.update([&](Vector<float4x2> &texture_matrices) {
1854 texture_matrices.append(float4x2::identity());
1855 });
1856 /* Update the fill cache if it exists. */
1857 drawing.runtime->fill_cache.update(
1858 [&](std::optional<bke::greasepencil::FillCache> &fill_cache) {
1859 if (fill_cache) {
1860 fill_cache->fill_map.append(num_old_curves);
1861 fill_cache->fill_offsets.append(fill_cache->fill_offsets.last() + 1);
1862 }
1863 });
1864 return;
1865 }
1866
1867 curves.resize(curves.points_num() + 1, curves.curves_num() + 1);
1868 MutableSpan<int> offsets = curves.offsets_for_write();
1869 offsets.first() = 0;
1870
1871 /* Loop through backwards to not overwrite the data. */
1872 for (int i = curves.curves_num() - 2; i >= 0; i--) {
1873 offsets[i + 1] = offsets[i] + 1;
1874 }
1875
1876 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
1877
1878 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
1880 return;
1881 }
1883 bke::attribute_math::shift_right(dst.span, 0, dst.span.size() - 1, dst.span.size());
1884 dst.finish();
1885 });
1886}
1887
1888void resize_single_curve(bke::CurvesGeometry &curves, const bool at_end, const int new_points_num)
1889{
1890 BLI_assert(new_points_num >= 0);
1891 const OffsetIndices<int> points_by_curve = curves.points_by_curve();
1892 const int curve_index = at_end ? curves.curves_range().last() : 0;
1893 const int current_points_num = points_by_curve[curve_index].size();
1894 if (new_points_num == current_points_num) {
1895 return;
1896 }
1897
1898 if (at_end) {
1899 const int diff_points_num = new_points_num - current_points_num;
1900 curves.resize(curves.points_num() + diff_points_num, curves.curves_num());
1901 curves.offsets_for_write().last() = curves.points_num();
1902 return;
1903 }
1904
1905 if (current_points_num < new_points_num) {
1906 const int last_active_point = points_by_curve[0].last();
1907
1908 const int added_points_num = new_points_num - current_points_num;
1909
1910 curves.resize(curves.points_num() + added_points_num, curves.curves_num());
1911 MutableSpan<int> offsets = curves.offsets_for_write();
1912 for (const int src_curve : curves.curves_range().drop_front(1)) {
1913 offsets[src_curve] = offsets[src_curve] + added_points_num;
1914 }
1915 offsets.last() = curves.points_num();
1916
1917 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
1918 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
1920 return;
1921 }
1922 if (iter.domain != bke::AttrDomain::Point) {
1923 return;
1924 }
1925
1928 dst.span, last_active_point, dst.span.size() - added_points_num, dst.span.size());
1929 dst.finish();
1930 });
1931 }
1932 else {
1933 /* First move the attribute data, then resize. */
1934 const int removed_points_num = current_points_num - new_points_num;
1935 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
1936 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
1938 return;
1939 }
1940 if (iter.domain != bke::AttrDomain::Point) {
1941 return;
1942 }
1943
1946 dst.span, new_points_num + removed_points_num, dst.span.size(), new_points_num);
1947 dst.finish();
1948 });
1949
1950 curves.resize(curves.points_num() - removed_points_num, curves.curves_num());
1951 MutableSpan<int> offsets = curves.offsets_for_write();
1952 for (const int src_curve : curves.curves_range().drop_front(1)) {
1953 offsets[src_curve] = offsets[src_curve] - removed_points_num;
1954 }
1955 offsets.last() = curves.points_num();
1956 }
1957}
1958
1959void apply_eval_grease_pencil_data(const GreasePencil &eval_grease_pencil,
1960 const int eval_frame,
1961 const IndexMask &orig_layers,
1962 GreasePencil &orig_grease_pencil)
1963{
1964 using namespace bke;
1965 using namespace bke::greasepencil;
1966 /* Build a set of pointers to the layers that we want to apply. */
1967 Set<const Layer *> orig_layers_to_apply;
1968 orig_layers.foreach_index([&](const int layer_i) {
1969 const Layer &layer = orig_grease_pencil.layer(layer_i);
1970 orig_layers_to_apply.add(&layer);
1971 });
1972
1973 /* Ensure that the layer names are unique by merging layers with the same name. */
1974 const int old_layers_num = eval_grease_pencil.layers().size();
1975 GreasePencil &merged_layers_grease_pencil = *geometry::merge_layers_by_name(
1976 eval_grease_pencil, VArray<bool>::from_single(true, old_layers_num), {});
1977
1978 Map<const Layer *, const Layer *> eval_to_orig_layer_map;
1979 {
1980 /* Set of orig layers that require the drawing on `eval_frame` to be cleared. These are layers
1981 * that existed in original geometry but were removed in the evaluated data. */
1982 Set<Layer *> orig_layers_to_clear;
1983 for (Layer *layer : orig_grease_pencil.layers_for_write()) {
1984 /* Only allow clearing a layer if it is visible. */
1985 if (layer->is_visible()) {
1986 orig_layers_to_clear.add(layer);
1987 }
1988 }
1989 for (const TreeNode *node_eval : merged_layers_grease_pencil.nodes()) {
1990 /* Check if the original geometry has a layer with the same name. */
1991 TreeNode *node_orig = orig_grease_pencil.find_node_by_name(node_eval->name());
1992
1993 BLI_assert(node_eval != nullptr);
1994 if (!node_eval->is_layer()) {
1995 continue;
1996 }
1997 /* If the orig layer isn't valid then a new layer with a unique name will be generated. */
1998 const bool has_valid_orig_layer = (node_orig != nullptr && node_orig->is_layer());
1999 if (!has_valid_orig_layer) {
2000 /* Note: This name might be empty! This has to be resolved at a later stage! */
2001 Layer &layer_orig = orig_grease_pencil.add_layer(node_eval->name(), true);
2002 orig_layers_to_apply.add(&layer_orig);
2003 /* Make sure to add a new keyframe with a new drawing. */
2004 orig_grease_pencil.insert_frame(layer_orig, eval_frame);
2005 node_orig = &layer_orig.as_node();
2006 }
2007 BLI_assert(node_orig != nullptr);
2008 Layer &layer_orig = node_orig->as_layer();
2009 /* This layer has a matching evaluated layer, so don't clear its keyframe. */
2010 orig_layers_to_clear.remove(&layer_orig);
2011 /* Only map layers in `eval_to_orig_layer_map` that we want to apply. */
2012 if (orig_layers_to_apply.contains(&layer_orig)) {
2013 /* Copy layer properties to original geometry. */
2014 const Layer &layer_eval = node_eval->as_layer();
2015 layer_orig.opacity = layer_eval.opacity;
2016 layer_orig.set_local_transform(layer_eval.local_transform());
2017
2018 /* Add new mapping for `layer_eval` -> `layer_orig`. */
2019 eval_to_orig_layer_map.add_new(&layer_eval, &layer_orig);
2020 }
2021 }
2022
2023 /* Clear the keyframe of all the original layers that don't have a matching evaluated layer,
2024 * e.g. the ones that were "deleted" in the evaluated data. */
2025 for (Layer *layer_orig : orig_layers_to_clear) {
2026 /* Try inserting a frame. */
2027 Drawing *drawing_orig = orig_grease_pencil.insert_frame(*layer_orig, eval_frame);
2028 if (drawing_orig == nullptr) {
2029 /* If that fails, get the drawing for this frame. */
2030 drawing_orig = orig_grease_pencil.get_drawing_at(*layer_orig, eval_frame);
2031 }
2032 /* Clear the existing drawing. */
2033 drawing_orig->strokes_for_write() = {};
2034 drawing_orig->tag_topology_changed();
2035 }
2036 }
2037
2038 /* Gather the original vertex group names. */
2039 Set<StringRef> orig_vgroup_names;
2040 for (bDeformGroup &dg : orig_grease_pencil.vertex_group_names) {
2041 orig_vgroup_names.add(dg.name);
2042 }
2043
2044 /* Update the drawings. */
2045 VectorSet<Drawing *> all_updated_drawings;
2046
2047 Set<StringRef> new_vgroup_names;
2048 for (auto [layer_eval, layer_orig] : eval_to_orig_layer_map.items()) {
2049 Drawing *drawing_eval = merged_layers_grease_pencil.get_drawing_at(*layer_eval, eval_frame);
2050 Drawing *drawing_orig = orig_grease_pencil.get_drawing_at(*layer_orig, eval_frame);
2051
2052 if (drawing_orig && drawing_eval) {
2053 bke::CurvesGeometry &eval_strokes = drawing_eval->strokes_for_write();
2054
2055 /* Check for new vertex groups in CurvesGeometry. */
2056 for (bDeformGroup &dg : eval_strokes.vertex_group_names) {
2057 if (!orig_vgroup_names.contains(dg.name)) {
2058 new_vgroup_names.add(dg.name);
2059 }
2060 }
2061
2062 /* Write the data to the original drawing. */
2063 drawing_orig->strokes_for_write() = std::move(eval_strokes);
2064 /* Anonymous attributes shouldn't be available on original geometry. */
2066 drawing_orig->tag_topology_changed();
2067 all_updated_drawings.add_new(drawing_orig);
2068 }
2069 }
2070
2071 /* Add new vertex groups to GreasePencil object. */
2072 for (StringRef new_vgroup_name : new_vgroup_names) {
2073 bDeformGroup *dst = MEM_new<bDeformGroup>(__func__);
2074 new_vgroup_name.copy_utf8_truncated(dst->name);
2075 BLI_addtail(&orig_grease_pencil.vertex_group_names, dst);
2076 }
2077
2078 /* Get the original material pointers from the result geometry. */
2079 VectorSet<Material *> original_materials;
2080 const Span<Material *> eval_materials = Span{eval_grease_pencil.material_array,
2081 eval_grease_pencil.material_array_num};
2082 for (Material *eval_material : eval_materials) {
2083 if (!eval_material) {
2084 return;
2085 }
2086 original_materials.add(DEG_get_original(eval_material));
2087 }
2088
2089 /* Build material indices mapping. This maps the materials indices on the original geometry to
2090 * the material indices used in the result geometry. The material indices for the drawings in
2091 * the result geometry are already correct, but this might not be the case for all drawings in
2092 * the original geometry (like for drawings that are not visible on the frame that the data is
2093 * being applied on). */
2094 const IndexRange orig_material_indices = IndexRange(orig_grease_pencil.material_array_num);
2095 Array<int> material_indices_map(orig_grease_pencil.material_array_num, -1);
2096 for (const int mat_i : orig_material_indices) {
2097 Material *material = orig_grease_pencil.material_array[mat_i];
2098 const int map_index = original_materials.index_of_try(material);
2099 if (map_index != -1) {
2100 material_indices_map[mat_i] = map_index;
2101 }
2102 }
2103
2104 /* Remap material indices for all other drawings. */
2105 if (!material_indices_map.is_empty() &&
2106 !array_utils::indices_are_range(material_indices_map, orig_material_indices))
2107 {
2108 for (GreasePencilDrawingBase *base : orig_grease_pencil.drawings()) {
2109 if (base->type != GP_DRAWING) {
2110 continue;
2111 }
2112 Drawing &drawing = reinterpret_cast<GreasePencilDrawing *>(base)->wrap();
2113 if (all_updated_drawings.contains(&drawing)) {
2114 /* Skip remapping drawings that already have been updated. */
2115 continue;
2116 }
2118 if (!attributes.contains("material_index")) {
2119 continue;
2120 }
2121 SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
2122 "material_index", AttrDomain::Curve);
2123 for (int &material_index : material_indices.span) {
2124 if (material_indices_map.index_range().contains(material_index)) {
2125 material_index = material_indices_map[material_index];
2126 }
2127 }
2128 material_indices.finish();
2129 }
2130 }
2131
2132 /* Convert the layer map into an index mapping. */
2133 Array<int> eval_to_orig_layer_indices_map(orig_grease_pencil.layers().size(), -1);
2134 for (const int layer_eval_i : merged_layers_grease_pencil.layers().index_range()) {
2135 const Layer *layer_eval = &merged_layers_grease_pencil.layer(layer_eval_i);
2136 if (eval_to_orig_layer_map.contains(layer_eval)) {
2137 const Layer *layer_orig = eval_to_orig_layer_map.lookup(layer_eval);
2138 const int layer_orig_index = *orig_grease_pencil.get_layer_index(*layer_orig);
2139 if (eval_to_orig_layer_indices_map[layer_orig_index] == -1) {
2140 /* Multiple evaluated layers can map to the same original layer. */
2141 eval_to_orig_layer_indices_map[layer_orig_index] = layer_eval_i;
2142 }
2143 }
2144 }
2145
2146 IndexMaskMemory memory;
2147 const IndexMask mapped_orig_layers = array_utils::indices_non_negative(
2148 eval_to_orig_layer_indices_map.index_range(), eval_to_orig_layer_indices_map, memory);
2149
2150 AttributeAccessor src_attributes = merged_layers_grease_pencil.attributes();
2151 MutableAttributeAccessor dst_attributes = orig_grease_pencil.attributes_for_write();
2152 src_attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
2154 return;
2155 }
2156 const GAttributeReader src = iter.get(AttrDomain::Layer);
2158 iter.name, AttrDomain::Layer, iter.data_type);
2159 if (!dst) {
2160 return;
2161 }
2163 src.varray, eval_to_orig_layer_indices_map, mapped_orig_layers, dst.span);
2164 dst.finish();
2165 });
2166
2167 /* Free temporary grease pencil struct. */
2168 BKE_id_free(nullptr, &merged_layers_grease_pencil);
2169}
2170
2172{
2173 if (!curves.attributes().contains(".is_fill_guide")) {
2174 return false;
2175 }
2176
2177 const bke::AttributeAccessor attributes = curves.attributes();
2178 const VArray<bool> is_fill_guide = *attributes.lookup<bool>(".is_fill_guide",
2180
2181 IndexMaskMemory memory;
2182 const IndexMask fill_guides = IndexMask::from_bools(is_fill_guide, memory);
2183 curves.remove_curves(fill_guides, {});
2184
2185 curves.attributes_for_write().remove(".is_fill_guide");
2186
2187 return true;
2188}
2189
2190} // namespace blender::ed::greasepencil
Low-level operations for curves.
support for deformation groups and hooks.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
ID and Library types, which are fundamental for SDNA.
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define NA_EDITED
Definition WM_types.hh:634
#define NC_GPENCIL
Definition WM_types.hh:412
#define SET_FLAG_FROM_TEST(value, test, flag)
#define BLI_assert(a)
#define ELEM(...)
Array(Allocator allocator={}) noexcept
Definition BLI_array.hh:78
IndexRange index_range() const
Definition BLI_array.hh:371
bool is_empty() const
Definition BLI_array.hh:275
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
static IndexMask from_ranges(OffsetIndices< T > offsets, const IndexMask &mask, LinearAllocator<> &memory)
static IndexMask from_intersection(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
constexpr int64_t last(const int64_t n=0) const
constexpr IndexRange()=default
constexpr bool contains(int64_t value) const
constexpr T & first() const
Definition BLI_span.hh:685
constexpr T & last(const int64_t n=0) const
Definition BLI_span.hh:695
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
void add_new(const Key &key)
Definition BLI_set.hh:233
bool remove(const Key &key)
Definition BLI_set.hh:404
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:329
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
std::optional< T > get_if_single() const
static VArray from_single(T value, const int64_t size)
int64_t index_of_try(const Key &key) const
bool add(const Key &key)
int64_t size() const
int64_t index_of(const Key &key) const
bool contains(const Key &key) const
void add_new(const Key &key)
int64_t size() const
void append(const T &value)
Span< T > as_span() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
bool contains(StringRef name) const
GAttributeReader lookup(const StringRef name) const
std::optional< AttrStorageType > storage_type
GAttributeReader get() const
void resize(int points_num, int curves_num)
VArray< bool > cyclic() const
IndexRange curves_range() const
IndexRange points_range() const
OffsetIndices< int > points_by_curve() const
MutableAttributeAccessor attributes_for_write()
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_for_write_span(StringRef name)
SharedCache< std::optional< FillCache > > fill_cache
SharedCache< Vector< float3 > > curve_plane_normals_cache
SharedCache< Vector< float4x2 > > curve_texture_matrices
std::optional< GroupedSpan< int > > fills() const
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
void set_local_transform(const float4x4 &transform)
DrawingPlacement & operator=(const DrawingPlacement &other)
std::optional< float > get_depth(float2 co) const
void cache_viewport_depths(Depsgraph *depsgraph, ARegion *region, View3D *view3d)
float3 place(float2 co, float depth) const
std::optional< float3 > project_depth(float2 co) const
float3 project(float2 co, bool &clipped) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define attribute(slot)
#define layer
float3x3 scale(float3x3 mat, float2 scale)
#define T
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
IndexMask indices_non_negative(const IndexMask &universe, Span< int > values, LinearAllocator<> &memory)
bool indices_are_range(Span< int > indices, IndexRange range)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void shift_right(GMutableSpan data, int src_begin, int src_end, int dst_begin)
void shift_left(GMutableSpan data, int src_begin, int src_end, int dst_begin)
void to_static_type(const CPPType &cpp_type, Fn &&fn)
IndexMask indices_for_type(const VArray< int8_t > &types, const std::array< int, CURVE_TYPES_NUM > &type_counts, const CurveType type, const IndexMask &selection, LinearAllocator<> &memory)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
void gather_attributes(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
Definition BLI_bounds.hh:56
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
IndexMask retrieve_all_selected_points(const bke::CurvesGeometry &curves, const int handle_display, LinearAllocator<> &memory)
IndexMask retrieve_editable_and_selected_elements(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, const bke::AttrDomain selection_domain, IndexMaskMemory &memory)
bool grease_pencil_draw_operator_begin(bContext *C, wmOperator *op, const bool use_duplicate_previous_key)
IndexMask retrieve_editable_and_selected_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
float opacity_from_input_sample(const float pressure, const Paint &paint, const Brush *brush, const BrushGpencilSettings *settings)
static Array< int > get_editable_frames_for_layer(const GreasePencil &grease_pencil, const bke::greasepencil::Layer &layer, const int current_frame, const bool use_multi_frame_editing)
void resize_single_curve(bke::CurvesGeometry &curves, const bool at_end, const int new_points_num)
static float get_frame_falloff(const bool use_multi_frame_falloff, const int frame_number, const int active_frame, const std::optional< Bounds< int > > frame_bounds, const CurveMapping *falloff_curve)
static std::optional< int > get_frame_id(const bke::greasepencil::Layer &layer, const GreasePencilFrame &frame, const int frame_number, const int frame_index, const int current_frame, const int current_frame_index, const int last_frame, const int last_frame_index, const bool use_multi_frame_editing, const bool do_onion_skinning, const bool is_before_first, const GreasePencilOnionSkinningSettings onion_settings)
IndexMask retrieve_editable_points(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
bool ensure_active_keyframe(const Scene &scene, GreasePencil &grease_pencil, bke::greasepencil::Layer &layer, const bool duplicate_previous_key, bool &r_inserted_keyframe)
GreasePencil * from_context(bContext &C)
IndexMask retrieve_visible_bezier_handle_strokes(Object &object, const bke::greasepencil::Drawing &drawing, const eHandleDisplay handle_display, IndexMaskMemory &memory)
IndexMask retrieve_editable_fill_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
IndexMask retrieve_editable_elements(Object &object, const MutableDrawingInfo &info, const bke::AttrDomain selection_domain, IndexMaskMemory &memory)
IndexMask retrieve_visible_bezier_strokes(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
Vector< MutableDrawingInfo > retrieve_editable_drawings_from_layer(const Scene &scene, GreasePencil &grease_pencil, const bke::greasepencil::Layer &layer)
static StrokeVisibilityStatus get_visibility_status_for_draw_operator(Object *object, const Brush &brush)
Vector< MutableDrawingInfo > retrieve_editable_drawings_from_layer_with_falloff(const Scene &scene, GreasePencil &grease_pencil, const bke::greasepencil::Layer &layer)
IndexMask retrieve_visible_points(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
Vector< DrawingInfo > retrieve_visible_drawings(const Scene &scene, const GreasePencil &grease_pencil, const bool do_onion_skinning)
IndexMask retrieve_editable_strokes_by_material(Object &object, const bke::greasepencil::Drawing &drawing, const int mat_i, IndexMaskMemory &memory)
IndexMask retrieve_editable_and_selected_fill_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
bool check_brush_needs_new_material(Object *ob, const Brush *brush)
bool has_editable_layer(const GreasePencil &grease_pencil)
static float pixel_radius_to_world_space_radius(const RegionView3D *rv3d, const ARegion *region, const float3 center, const float4x4 to_world, const float pixel_radius)
IndexMask retrieve_visible_bezier_points(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
static Array< std::pair< int, int > > get_visible_frames_for_layer(const GreasePencil &grease_pencil, const bke::greasepencil::Layer &layer, const int current_frame, const bool use_multi_frame_editing, const bool do_onion_skinning)
Array< PointTransferData > compute_topology_change(const bke::CurvesGeometry &src, bke::CurvesGeometry &dst, const Span< Vector< PointTransferData > > src_to_dst_points, const bool keep_caps)
IndexMask retrieve_editable_and_all_selected_points(Object &object, const bke::greasepencil::Drawing &drawing, const int layer_index, const eHandleDisplay handle_display, IndexMaskMemory &memory)
static VectorSet< int > get_locked_material_indices(Object &object)
IndexMask retrieve_editable_and_selected_points(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
static std::optional< Bounds< int > > get_selected_frame_number_bounds(const bke::greasepencil::Layer &layer)
IndexMask retrieve_visible_bezier_handle_points(Object &object, const bke::greasepencil::Drawing &drawing, const int layer_index, const eHandleDisplay handle_display, IndexMaskMemory &memory)
static VectorSet< int > get_hidden_material_indices(Object &object)
static int get_active_frame_for_falloff(const bke::greasepencil::Layer &layer, const std::optional< Bounds< int > > frame_bounds, const int current_frame)
IndexMask retrieve_visible_strokes(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
IndexMask retrieve_visible_fills(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
Vector< MutableDrawingInfo > retrieve_editable_drawings_with_falloff(const Scene &scene, GreasePencil &grease_pencil)
eHandleDisplay view3d_handle_type_or_default(const View3D *v3d)
IndexMask retrieve_editable_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
bool remove_fill_guides(bke::CurvesGeometry &curves)
Vector< MutableDrawingInfo > retrieve_editable_drawings(const Scene &scene, GreasePencil &grease_pencil)
static float brush_radius_at_location(const RegionView3D *rv3d, const ARegion *region, const Paint *paint, const Brush *brush, const float3 location, const float4x4 to_world)
float4x2 calculate_texture_space(const Scene *scene, const ARegion *region, const float2 &mouse, const DrawingPlacement &placement)
void add_single_curve(bke::greasepencil::Drawing &drawing, const bool at_end)
Array< Vector< MutableDrawingInfo > > retrieve_editable_drawings_grouped_per_frame(const Scene &scene, GreasePencil &grease_pencil)
IndexMask retrieve_visible_bezier_handle_elements(Object &object, const bke::greasepencil::Drawing &drawing, const int layer_index, const bke::AttrDomain selection_domain, const eHandleDisplay handle_display, IndexMaskMemory &memory)
float radius_from_input_sample(const RegionView3D *rv3d, const ARegion *region, const Paint &paint, const Brush *brush, const float pressure, const float3 &location, const float4x4 &to_world, const BrushGpencilSettings *settings)
void apply_eval_grease_pencil_data(const GreasePencil &eval_grease_pencil, const int eval_frame, const IndexMask &orig_layers, GreasePencil &orig_grease_pencil)
GreasePencil * merge_layers_by_name(const GreasePencil &src_grease_pencil, const VArray< bool > &selection, const bke::AttributeFilter &attribute_filter)
BLI_INLINE Texture * wrap(MTLTexture *texture)
MatBase< T, NumCol, NumRow > transpose(const MatBase< T, NumRow, NumCol > &mat)
T clamp(const T &a, const T &min, const T &max)
T safe_divide(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
CartesianBasis invert(const CartesianBasis &basis)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ GP_SCULPT_SETT_FLAG_FRAME_FALLOFF
__int64 int64_t
Definition BKE_text.h:90
@ CURVE_HANDLE_SELECTED
@ RPT_WARNING
Definition BKE_report.hh:40
void ED_view3d_win_to_3d_with_shift(const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
void ED_view3d_depths_free(ViewDepths *depths)
bool isect_ray_plane_v3(const float ray_origin[3], const float ray_direction[3], const float plane[4], float *r_lambda, bool clip)
Material * BKE_object_material_get(Object *ob, short act)
float BKE_brush_radius_get(const Paint *paint, const Brush *brush)
Definition brush.cc:1366
MatBase< float, 4, 4 > float4x4
MatBase< float, 2, 4 > float2x4
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
Definition math_geom.cc:225
bool BKE_brush_use_alpha_pressure(const Brush *brush)
Definition brush.cc:1385
bool ED_view3d_unproject_v3(const ARegion *region, float regionx, float regiony, float regionz, float world[3])
float BKE_brush_unprojected_radius_get(const Paint *paint, const Brush *brush)
Definition brush.cc:1412
VecBase< float, 4 > float4
void BKE_curvemapping_init(CurveMapping *cumap)
@ GP_USE_MULTI_FRAME_EDITING
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
bool ED_view3d_win_to_3d_on_plane(const ARegion *region, const float plane[4], const float mval[2], bool do_clip, float r_out[3])
MatBase< float, 4, 2 > float4x2
eV3DProjStatus ED_view3d_project_float_global(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float r_out[3])
switch(BMIterType(itype))
@ V3D_GP_FORCE_STROKE_ORDER_3D
float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3])
MatBase< float, 3, 3 > float3x3
void BKE_id_free(Main *bmain, void *idv)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool BKE_brush_use_size_pressure(const Brush *brush)
Definition brush.cc:1380
const Brush * BKE_paint_brush_for_read(const Paint *paint)
T * DEG_get_original(T *id)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
float BKE_scene_ctime_get(const Scene *scene)
Definition scene.cc:2581
Paint * BKE_paint_get_active_from_context(const bContext *C)
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
bool ED_view3d_depth_read_cached(const ViewDepths *vd, const int mval[2], int margin, float *r_depth)
Material * BKE_grease_pencil_object_material_from_brush_get(Object *ob, const Brush *brush)
@ V3D_PROJ_TEST_NOP
Definition ED_view3d.hh:295
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
Definition deform.cc:75
eV3DDepthOverrideMode
Definition ED_view3d.hh:205
@ V3D_DEPTH_GPENCIL_ONLY
Definition ED_view3d.hh:211
@ V3D_DEPTH_NO_GPENCIL
Definition ED_view3d.hh:209
@ V3D_DEPTH_SELECTED_ONLY
Definition ED_view3d.hh:215
Scene * CTX_data_scene(const bContext *C)
@ GP_PROJECT_DEPTH_STROKE
@ GP_PROJECT_DEPTH_ONLY_SELECTED
bool ED_view3d_depth_unproject_v3(const ARegion *region, const int mval[2], double depth, float r_location_world[3])
VecBase< float, 3 > float3
@ GP_BRUSH_USE_STROKE
void ED_view3d_win_to_3d(const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
Object * CTX_data_active_object(const bContext *C)
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
void ED_view3d_win_to_delta(const ARegion *region, const float xy_delta[2], float zfac, float r_out[3], bool precise=false)
float BKE_brush_alpha_get(const Paint *paint, const Brush *brush)
Definition brush.cc:1454
signed char int8_t
Definition BKE_text.h:76
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct CurveMapping * curve_sensitivity
struct CurveMapping * curve_strength
ListBaseT< struct bDeformGroup > vertex_group_names
eGP_Sculpt_SettingsFlag flag
struct CurveMapping * cur_falloff
bke::greasepencil::DrawingRuntime * runtime
View3DCursor cursor
struct RenderData r
struct ToolSettings * toolsettings
eGPencil_Flags gpencil_flags
struct GP_Sculpt_Settings gp_sculpt
eHandleDisplay handle_display
View3DOverlay overlay
struct ReportList * reports