Blender V5.3
erase.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
5#include <algorithm>
6
7#include "BLI_array.hh"
8#include "BLI_index_mask.hh"
9#include "BLI_math_base.hh"
10#include "BLI_math_geom_c.hh"
11#include "BLI_task.hh"
12
13#include "BKE_asset_edit.hh"
14#include "BKE_attribute.hh"
15#include "BKE_brush.hh"
16#include "BKE_colortools.hh"
17#include "BKE_context.hh"
18#include "BKE_crazyspace.hh"
19#include "BKE_curves.hh"
20#include "BKE_grease_pencil.hh"
21#include "BKE_material.hh"
22#include "BKE_paint.hh"
23
25
26#include "DNA_brush_enums.h"
27#include "DNA_brush_types.h"
28#include "DNA_material_types.h"
29
30#include "ED_grease_pencil.hh"
31#include "ED_view3d.hh"
32
34
35#include "WM_api.hh"
36#include "WM_toolsystem.hh"
37#include "WM_types.hh"
38
40
42
45
46 private:
47 Brush *eraser_brush_;
48 /* Eraser is used by the draw tool temporarily. */
49 bool temp_eraser_ = false;
50
51 bool keep_caps_ = false;
52 float radius_ = 0.0f;
53 float strength_ = 0.1f;
55 bool active_layer_only_ = false;
56
57 Set<GreasePencilDrawing *> affected_drawings_;
58
59 public:
60 EraseOperation(bool temp_use_eraser = false) : temp_eraser_(temp_use_eraser) {}
61 ~EraseOperation() override = default;
62
63 void on_stroke_begin(const bContext &C, const InputSample &start_sample) override;
64 void on_stroke_extended(const bContext &C, const InputSample &extension_sample) override;
65 void on_stroke_done(const bContext &C) override;
66};
67
69 /* Position of the intersection in the segment.
70 * Note: we use a value > 1.0f as initial value so that sorting intersection by increasing
71 * factor can directly put the invalid ones at the end. */
72 float factor = 2.0f;
73
74 /* True if the intersection corresponds to an inside/outside transition with respect to the
75 * circle, false if it corresponds to an outside/inside transition. */
77
78 int ring_index = -1;
79
80 /* An intersection is considered valid if it lies inside of the segment, i.e.
81 * if its factor is in (0,1). */
82 bool is_valid() const
83 {
84 return IN_RANGE(factor, 0.0f, 1.0f);
85 }
86};
88
94
99
102
103 /* Threshold below which points are considered as transparent and thus shall be removed. */
104 static constexpr float opacity_threshold = 0.05f;
105
107
108 struct EraserRing {
109 float radius;
111 float opacity;
112 bool hard_erase{false};
113 };
114
130 const int2 &s1,
131 const int2 &center,
132 const int64_t radius_2,
133 int64_t &r_mu0,
134 int64_t &r_mu1)
135 {
136 const int64_t d_s0_center = math::distance_squared(s0, center);
137 const int64_t a = math::distance_squared(s0, s1);
138 const int64_t b = 2 * math::dot(s0 - center, s1 - s0);
139 const int64_t c = d_s0_center - radius_2;
140
141 /* If points are close together there is no direction vector.
142 * Since the solution multiplies by this factor for integer math,
143 * the valid case of degenerate segments inside the circle needs special handling. */
144 if (a == 0) {
145 const int64_t i = -4 * c;
146 if (i < 0) {
147 /* No intersections. */
148 return 0;
149 }
150 if (i == 0) {
151 /* One intersection. */
152 r_mu0 = 0.0f;
153 return 1;
154 }
155 /* Two intersections. */
156 const float i_sqrt = math::sqrt(float(i));
157 r_mu0 = math::round(i_sqrt / 2.0f);
158 r_mu1 = math::round(-i_sqrt / 2.0f);
159 return 2;
160 }
161
162 const int64_t i = b * b - 4 * a * c;
163
164 if (i < 0) {
165 /* No intersections. */
166 return 0;
167 }
168
169 const int64_t segment_length = math::distance(s0, s1);
170
171 if (i == 0) {
172 /* One intersection. */
173 const float mu0_f = -b / (2.0f * a);
174 r_mu0 = math::round(mu0_f * segment_length);
175 return 1;
176 }
177
178 /* Two intersections. */
179 const float i_sqrt = math::sqrt(float(i));
180 const float mu0_f = (-b + i_sqrt) / (2.0f * a);
181 const float mu1_f = (-b - i_sqrt) / (2.0f * a);
182
183 r_mu0 = math::round(mu0_f * segment_length);
184 r_mu1 = math::round(mu1_f * segment_length);
185
186 return 2;
187 }
188
211 const int2 &point_after,
212 const int64_t squared_radius,
213 float &r_mu0,
214 float &r_mu1,
215 PointCircleSide &r_point_side,
216 PointCircleSide &r_point_after_side) const
217 {
218
219 /* Compute the integer values of the intersection. */
220 const int64_t segment_length = math::distance(point, point_after);
221 int64_t mu0 = -1;
222 int64_t mu1 = -1;
223 const int8_t nb_intersections = intersections_segment_circle_integers(
224 point, point_after, this->mouse_position_pixels, squared_radius, mu0, mu1);
225
226 if (nb_intersections != 2) {
227 /* No intersection with the infinite line : none of the points are inside the circle.
228 * If only one intersection was found, then the eraser is tangential to the line, we don't
229 * account for intersections in this case.
230 */
231 r_mu0 = r_mu1 = -1.0f;
232 r_point_side = PointCircleSide::Outside;
233 r_point_after_side = PointCircleSide::Outside;
234 return 0;
235 }
236
237 if (mu0 > mu1) {
238 std::swap(mu0, mu1);
239 }
240
241 /* Compute on which side of the segment each intersection lies.
242 * -1 : before or at the first endpoint,
243 * 0 : in-between the endpoints,
244 * 1 : after or at the last endpoint.
245 */
246 const int8_t side_mu0 = (mu0 <= 0) ? (-1) : ((mu0 >= segment_length) ? 1 : 0);
247 const int8_t side_mu1 = (mu1 <= 0) ? (-1) : ((mu1 >= segment_length) ? 1 : 0);
248
249 /* The endpoints are on the circle's boundary if one of the intersection falls exactly on them.
250 */
251 r_point_side = (mu0 == 0) ? PointCircleSide::OutsideInsideBoundary :
254 r_point_after_side = (mu0 == segment_length) ?
256 ((mu1 == segment_length) ? PointCircleSide::InsideOutsideBoundary :
258
259 /* Compute the normalized position of the intersection in the curve. */
260 r_mu0 = mu0 / float(segment_length);
261 r_mu1 = mu1 / float(segment_length);
262
263 const bool is_mu0_inside = (side_mu0 == 0);
264 const bool is_mu1_inside = (side_mu1 == 0);
265 if (!is_mu0_inside && !is_mu1_inside) {
266 /* None of the intersection lie within the segment the infinite line. */
267
268 if (side_mu0 == side_mu1) {
269 /* If they are on the same side of the line, then none of the point are inside the circle.
270 */
271 r_point_side = PointCircleSide::Outside;
272 r_point_after_side = PointCircleSide::Outside;
273 return 0;
274 }
275
276 /* If they are on different sides of the line, then both points are inside the circle, or in
277 * the boundary. */
278 return 0;
279 }
280
281 if (is_mu0_inside && is_mu1_inside) {
282 /* Both intersections lie within the segment, none of the points are inside the circle. */
283 r_point_side = PointCircleSide::Outside;
284 r_point_after_side = PointCircleSide::Outside;
285 return 2;
286 }
287
288 /* Only one intersection lies within the segment. Only one point should be erased, depending on
289 * the side of the other intersection. */
290 const int8_t side_outside_intersection = is_mu0_inside ? side_mu1 : side_mu0;
291
292 /* If the other intersection lies before the first endpoint, the first endpoint is inside. */
293 r_point_side = (side_outside_intersection == -1) ? r_point_side : PointCircleSide::Outside;
294 r_point_after_side = (side_outside_intersection == 1) ? r_point_after_side :
296
297 if (is_mu1_inside) {
298 std::swap(r_mu0, r_mu1);
299 }
300 return 1;
301 }
302
321 const bke::CurvesGeometry &src,
322 const Span<float2> screen_space_positions,
323 const Span<EraserRing> rings,
324 MutableSpan<std::pair<int, PointCircleSide>> r_point_ring,
325 MutableSpan<SegmentCircleIntersection> r_intersections) const
326 {
327 /* Each ring can generate zero, one or two intersections per segment.
328 * Maximum number of intersections per-segment. */
329 const int intersections_max_per_segment = rings.size() * 2;
330 const OffsetIndices<int> src_points_by_curve = src.points_by_curve();
331 const VArray<bool> src_cyclic = src.cyclic();
332
333 Array<int2> screen_space_positions_pixel(src.points_num());
334 threading::parallel_for(src.points_range(), 1024, [&](const IndexRange src_points) {
335 for (const int src_point : src_points) {
336 const float2 pos = screen_space_positions[src_point];
337 screen_space_positions_pixel[src_point] = int2(round_fl_to_int(pos[0]),
338 round_fl_to_int(pos[1]));
339 }
340 });
341
342 threading::parallel_for(src.curves_range(), 512, [&](const IndexRange src_curves) {
343 for (const int src_curve : src_curves) {
344 const IndexRange src_curve_points = src_points_by_curve[src_curve];
345
346 if (src_curve_points.size() == 1) {
347 /* One-point stroke : just check if the point is inside the eraser. */
348 int ring_index = 0;
349 for (const EraserRing &eraser_point : rings) {
350 const int src_point = src_curve_points.first();
351 const int64_t squared_distance = math::distance_squared(
352 this->mouse_position_pixels, screen_space_positions_pixel[src_point]);
353
354 /* NOTE: We don't account for boundaries here, since we are not going to split any
355 * curve. */
356 if ((r_point_ring[src_point].first == -1) &&
357 (squared_distance <= eraser_point.squared_radius))
358 {
359 r_point_ring[src_point] = {ring_index, PointCircleSide::Inside};
360 }
361 ++ring_index;
362 }
363 continue;
364 }
365
366 for (const int src_point : src_curve_points.drop_back(1)) {
367 int ring_index = 0;
368 int intersection_offset = src_point * intersections_max_per_segment - 1;
369
370 for (const EraserRing &eraser_point : rings) {
371 SegmentCircleIntersection inter0;
372 SegmentCircleIntersection inter1;
373
374 inter0.ring_index = ring_index;
375 inter1.ring_index = ring_index;
376
377 PointCircleSide point_side;
378 PointCircleSide point_after_side;
379
380 const int8_t nb_inter = segment_intersections_and_points_sides(
381 screen_space_positions_pixel[src_point],
382 screen_space_positions_pixel[src_point + 1],
383 eraser_point.squared_radius,
384 inter0.factor,
385 inter1.factor,
386 point_side,
387 point_after_side);
388
389 /* The point belongs in the ring of the smallest radius circle it is in.
390 * Since our rings are stored in increasing radius order, it corresponds to the first
391 * ring that contains the point. We only include the InsideOutside boundary of the
392 * ring, that is why we do not check for OutsideInsideBoundary.
393 */
394 if ((r_point_ring[src_point].first == -1) &&
395 ELEM(point_side, PointCircleSide::Inside, PointCircleSide::InsideOutsideBoundary))
396 {
397 r_point_ring[src_point] = {ring_index, point_side};
398 }
399
400 if (src_point + 1 == src_curve_points.last()) {
401 if ((r_point_ring[src_point + 1].first == -1) &&
402 ELEM(point_after_side,
403 PointCircleSide::Inside,
404 PointCircleSide::InsideOutsideBoundary))
405 {
406 r_point_ring[src_point + 1] = {ring_index, point_after_side};
407 }
408 }
409
410 if (nb_inter > 0) {
411 inter0.inside_outside_intersection = (inter0.factor > inter1.factor);
412 r_intersections[++intersection_offset] = inter0;
413
414 if (nb_inter > 1) {
415 inter1.inside_outside_intersection = true;
416 r_intersections[++intersection_offset] = inter1;
417 }
418 }
419
420 ++ring_index;
421 }
422 }
423
424 if (src_cyclic[src_curve]) {
425 /* If the curve is cyclic, we need to check for the closing segment. */
426 const int src_last_point = src_curve_points.last();
427 const int src_first_point = src_curve_points.first();
428 int ring_index = 0;
429 int intersection_offset = src_last_point * intersections_max_per_segment - 1;
430
431 for (const EraserRing &eraser_point : rings) {
432 SegmentCircleIntersection inter0;
433 SegmentCircleIntersection inter1;
434
435 inter0.ring_index = ring_index;
436 inter1.ring_index = ring_index;
437
438 PointCircleSide point_side;
439 PointCircleSide point_after_side;
440
441 const int8_t nb_inter = segment_intersections_and_points_sides(
442 screen_space_positions_pixel[src_last_point],
443 screen_space_positions_pixel[src_first_point],
444 eraser_point.squared_radius,
445 inter0.factor,
446 inter1.factor,
447 point_side,
448 point_after_side);
449
450 /* Note : we don't need to set the point side here, since it was already set by the
451 * former loop. */
452
453 if (nb_inter > 0) {
454 inter0.inside_outside_intersection = (inter0.factor > inter1.factor);
455 r_intersections[++intersection_offset] = inter0;
456
457 if (nb_inter > 1) {
458 inter1.inside_outside_intersection = true;
459 r_intersections[++intersection_offset] = inter1;
460 }
461 }
462
463 ++ring_index;
464 }
465 }
466 }
467 });
468
469 /* Compute total number of intersections. */
470 int total_intersections = 0;
471 for (const SegmentCircleIntersection &intersection : r_intersections) {
472 if (intersection.is_valid()) {
473 total_intersections++;
474 }
475 }
476
477 return total_intersections;
478 }
479
481 Object &ob,
482 const int src_curve,
483 const IndexRange &src_points,
484 const VArray<int> stroke_material,
485 const VArray<float> &point_opacity,
487 {
489 &ob, stroke_material[src_curve] + 1);
490
491 if ((mat->flag & GP_MATERIAL_LOCKED) == 0) {
492 return false;
493 }
494
495 for (const int src_point : src_points) {
496 const int src_next_point = (src_point == src_points.last()) ? src_points.first() :
497 (src_point + 1);
498 src_to_dst_points[src_point].append(
499 {src_point, src_next_point, 0.0f, true, false, point_opacity[src_point]});
500 }
501 return true;
502 }
503
504 /* The hard eraser cuts out the curves at their intersection with the eraser, and removes
505 * everything that lies in-between two consecutive intersections. Note that intersections are
506 * computed using integers (pixel-space) to avoid floating-point approximation errors. */
507
509 const bke::CurvesGeometry &src,
510 const Span<float2> screen_space_positions,
512 const bool keep_caps) const
513 {
514 const VArray<bool> src_cyclic = src.cyclic();
515 const int src_points_num = src.points_num();
516
517 /* For the hard erase, we compute with a circle, so there can only be a maximum of two
518 * intersection per segment. */
519 const Vector<EraserRing> eraser_rings(
520 1, {this->eraser_radius, this->eraser_squared_radius_pixels, 0.0f, true});
521 const int intersections_max_per_segment = eraser_rings.size() * 2;
522
523 /* Compute intersections between the eraser and the curves in the source domain. */
524 Array<std::pair<int, PointCircleSide>> src_point_ring(src_points_num,
526 Array<SegmentCircleIntersection> src_intersections(src_points_num *
527 intersections_max_per_segment);
529 src, screen_space_positions, eraser_rings, src_point_ring, src_intersections);
530
531 Array<Vector<ed::greasepencil::PointTransferData>> src_to_dst_points(src_points_num);
532
533 const VArray<int> &stroke_material = *src.attributes().lookup_or_default<int>(
534 "material_index", bke::AttrDomain::Curve, 0);
535 const VArray<float> &point_opacity = *src.attributes().lookup_or_default<float>(
536 "opacity", bke::AttrDomain::Point, 1.0f);
537
538 const OffsetIndices<int> src_points_by_curve = src.points_by_curve();
539 for (const int src_curve : src.curves_range()) {
540 const IndexRange src_points = src_points_by_curve[src_curve];
541
543 ob, src_curve, src_points, stroke_material, point_opacity, src_to_dst_points))
544 {
545 continue;
546 }
547
548 for (const int src_point : src_points) {
549 Vector<ed::greasepencil::PointTransferData> &dst_points = src_to_dst_points[src_point];
550 const int src_next_point = (src_point == src_points.last()) ? src_points.first() :
551 (src_point + 1);
552 const PointCircleSide point_side = src_point_ring[src_point].second;
553
554 /* Add the source point only if it does not lie inside of the eraser. */
555 if (point_side != PointCircleSide::Inside) {
556 dst_points.append({src_point,
557 src_next_point,
558 0.0f,
559 true,
561 }
562
563 /* Add all intersections with the eraser. */
564 const IndexRange src_point_intersections(src_point * intersections_max_per_segment,
565 intersections_max_per_segment);
566 for (const SegmentCircleIntersection &intersection :
567 src_intersections.as_span().slice(src_point_intersections))
568 {
569 if (!intersection.is_valid()) {
570 /* Stop at the first non valid intersection. */
571 break;
572 }
573 dst_points.append({src_point,
574 src_next_point,
575 intersection.factor,
576 false,
577 intersection.inside_outside_intersection});
578 }
579 }
580 }
581
582 ed::greasepencil::compute_topology_change(src, dst, src_to_dst_points, keep_caps);
583
584 return true;
585 }
586
588 {
589 /* The changes in opacity implied by the soft eraser are described by a falloff curve
590 * mapping. Abscissa of the curve is the normalized distance to the brush, and ordinate of
591 * the curve is the strength of the eraser.
592 *
593 * To apply this falloff as precisely as possible, we compute a set of "rings" to the brush,
594 * meaning a set of samples in the curve mapping in between which the strength of the eraser
595 * is applied linearly.
596 *
597 * In other words, we compute a minimal set of samples that describe the falloff curve as a
598 * polyline. */
599
600 /* First, distance-based sampling with a small pixel distance.
601 * The samples are stored in increasing radius order. */
602 const int step_pixels = 2;
603 int nb_samples = math::round(this->eraser_radius / step_pixels);
604 Vector<EraserRing> eraser_rings(nb_samples);
605 for (const int sample_index : eraser_rings.index_range()) {
606 const int64_t sampled_distance = (sample_index + 1) * step_pixels;
607
608 EraserRing &ring = eraser_rings[sample_index];
609 ring.radius = sampled_distance;
610 ring.squared_radius = sampled_distance * sampled_distance;
611 ring.opacity = 1.0 - this->eraser_strength *
613 this->brush_, float(sampled_distance), this->eraser_radius);
614 }
615
616 /* Then, prune samples that are under the opacity threshold. */
617 Array<bool> prune_sample(nb_samples, false);
618 for (const int sample_index : eraser_rings.index_range()) {
619 EraserRing &sample = eraser_rings[sample_index];
620
621 if (sample_index == nb_samples - 1) {
622 /* If this is the last samples, we need to keep it at the same position (it corresponds
623 * to the brush overall radius). It is a cut if the opacity is under the threshold. */
624 sample.hard_erase = (sample.opacity < opacity_threshold);
625 continue;
626 }
627
628 EraserRing next_sample = eraser_rings[sample_index + 1];
629
630 /* If both samples are under the threshold, prune it !
631 * If none of them are under the threshold, leave them as they are.
632 */
633 if ((sample.opacity < opacity_threshold) == (next_sample.opacity < opacity_threshold)) {
634 prune_sample[sample_index] = (sample.opacity < opacity_threshold);
635 continue;
636 }
637
638 /* Otherwise, shift the sample to the spot where the opacity is exactly at the threshold.
639 * This way we don't remove larger opacity values in-between the samples. */
640 const EraserRing &sample_after = eraser_rings[sample_index + 1];
641
642 const float t = (opacity_threshold - sample.opacity) /
643 (sample_after.opacity - sample.opacity);
644
645 const int64_t radius = math::round(
646 math::interpolate(sample.radius, float(sample_after.radius), t));
647
648 sample.radius = radius;
649 sample.squared_radius = radius * radius;
650 sample.opacity = opacity_threshold;
651 sample.hard_erase = !(next_sample.opacity < opacity_threshold);
652 }
653
654 for (const int rev_sample_index : eraser_rings.index_range()) {
655 const int sample_index = nb_samples - rev_sample_index - 1;
656 if (prune_sample[sample_index]) {
657 eraser_rings.remove(sample_index);
658 }
659 }
660
661 /* Finally, simplify the array to have a minimal set of samples. */
662 nb_samples = eraser_rings.size();
663
664 const auto opacity_distance = [&](int64_t first_index, int64_t last_index, int64_t index) {
665 /* Distance function for the simplification algorithm.
666 * It is computed as the difference in opacity that may result from removing the
667 * samples inside the range. */
668 const EraserRing &sample_first = eraser_rings[first_index];
669 const EraserRing &sample_last = eraser_rings[last_index];
670 const EraserRing &sample = eraser_rings[index];
671
672 /* If we were to remove the samples between sample_first and sample_last, then the opacity
673 * at sample.radius would be a linear interpolation between the opacities in the endpoints
674 * of the range, with a parameter depending on the distance between radii. That is what we
675 * are computing here. */
676 const float t = (sample.radius - sample_first.radius) /
677 (sample_last.radius - sample_first.radius);
678 const float linear_opacity = math::interpolate(sample_first.opacity, sample_last.opacity, t);
679
680 return math::abs(sample.opacity - linear_opacity);
681 };
682 Array<bool> simplify_sample(nb_samples, false);
683 const float distance_threshold = 0.1f;
685 eraser_rings.index_range(), distance_threshold, opacity_distance, simplify_sample);
686
687 for (const int rev_sample_index : eraser_rings.index_range()) {
688 const int sample_index = nb_samples - rev_sample_index - 1;
689 if (simplify_sample[sample_index]) {
690 eraser_rings.remove(sample_index);
691 }
692 }
693
694 return eraser_rings;
695 }
696
705 const bke::CurvesGeometry &src,
706 const Span<float2> screen_space_positions,
708 const bool keep_caps)
709 {
710 using namespace blender::bke;
711 const std::string opacity_attr = "opacity";
712
713 /* The soft eraser changes the opacity of the strokes underneath it using a curve falloff. We
714 * sample this curve to get a set of rings in the brush. */
716 const int intersections_max_per_segment = eraser_rings.size() * 2;
717
718 /* Compute intersections between the source curves geometry and all the rings of the eraser.
719 */
720 const int src_points_num = src.points_num();
721 Array<std::pair<int, PointCircleSide>> src_point_ring(src_points_num,
723 Array<SegmentCircleIntersection> src_intersections(src_points_num *
724 intersections_max_per_segment);
726 src, screen_space_positions, eraser_rings, src_point_ring, src_intersections);
727
728 /* Function to get the resulting opacity at a specific point in the source. */
729 const VArray<float> &src_opacity = *src.attributes().lookup_or_default<float>(
730 opacity_attr, bke::AttrDomain::Point, 1.0f);
731 const VArray<int> &stroke_material = *src.attributes().lookup_or_default<int>(
732 "material_index", bke::AttrDomain::Curve, 0);
733
734 const auto compute_opacity = [&](const int src_point) {
735 const float distance = math::distance(screen_space_positions[src_point],
736 this->mouse_position);
737 const float brush_strength = this->eraser_strength *
739 this->brush_, distance, this->eraser_radius);
740 return math::clamp(src_opacity[src_point] - brush_strength, 0.0f, 1.0f);
741 };
742
743 /* Compute the map of points in the destination.
744 * For each point in the source, we create a vector of destination points. Destination points
745 * can either be directly a point of the source, or a point inside a segment of the source. A
746 * destination point can also carry the role of a "cut", meaning it is going to be the first
747 * point of a new curve split into the destination. */
748 Array<Vector<ed::greasepencil::PointTransferData>> src_to_dst_points(src_points_num);
749 const OffsetIndices<int> src_points_by_curve = src.points_by_curve();
750 for (const int src_curve : src.curves_range()) {
751 const IndexRange src_points = src_points_by_curve[src_curve];
752
754 ob, src_curve, src_points, stroke_material, src_opacity, src_to_dst_points))
755 {
756 continue;
757 }
758 for (const int src_point : src_points) {
759 Vector<ed::greasepencil::PointTransferData> &dst_points = src_to_dst_points[src_point];
760 const int src_next_point = (src_point == src_points.last()) ? src_points.first() :
761 (src_point + 1);
762
763 /* Get the ring into which the source point lies.
764 * If the point is completely outside of the eraser, then the index is (-1). */
765 const int point_ring = src_point_ring[src_point].first;
766 const bool ring_is_cut = (point_ring != -1) && eraser_rings[point_ring].hard_erase;
767 const PointCircleSide point_side = src_point_ring[src_point].second;
768
769 const bool point_is_cut = ring_is_cut &&
771 const bool remove_point = ring_is_cut && (point_side == PointCircleSide::Inside);
772 if (!remove_point) {
773 dst_points.append(
774 {src_point, src_next_point, 0.0f, true, point_is_cut, compute_opacity(src_point)});
775 }
776
777 const IndexRange src_point_intersections(src_point * intersections_max_per_segment,
778 intersections_max_per_segment);
779
780 std::sort(src_intersections.begin() + src_point_intersections.first(),
781 src_intersections.begin() + src_point_intersections.last() + 1,
783 return a.factor < b.factor;
784 });
785
786 /* Add all intersections with the rings. */
787 for (const SegmentCircleIntersection &intersection :
788 src_intersections.as_span().slice(src_point_intersections))
789 {
790 if (!intersection.is_valid()) {
791 /* Stop at the first non valid intersection. */
792 break;
793 }
794
795 const EraserRing &ring = eraser_rings[intersection.ring_index];
796 const bool is_cut = intersection.inside_outside_intersection && ring.hard_erase;
797 const float initial_opacity = math::interpolate(
798 src_opacity[src_point], src_opacity[src_next_point], intersection.factor);
799
800 const float opacity = math::max(0.0f, math::min(initial_opacity, ring.opacity));
801
802 /* Avoid the accumulation of multiple cuts. */
803 if (is_cut && !dst_points.is_empty() && dst_points.last().is_cut) {
804 dst_points.remove_last();
805 }
806
807 dst_points.append(
808 {src_point, src_next_point, intersection.factor, false, is_cut, opacity});
809 }
810 }
811 }
812
813 const Array<ed::greasepencil::PointTransferData> dst_points = compute_topology_change(
814 src, dst, src_to_dst_points, keep_caps);
815
816 /* Set opacity. */
818
819 if (bke::SpanAttributeWriter<float> dst_opacity =
820 dst_attributes.lookup_or_add_for_write_span<float>(opacity_attr,
822 {
823 SpanAttributeWriter<bool> opacity_modified =
824 dst_attributes.lookup_or_add_for_write_span<bool>(
825 "_eraser_opacity_modified", bke::AttrDomain::Point, bke::AttributeInitValue(false));
826 BLI_assert(opacity_modified);
827
828 threading::parallel_for(dst.points_range(), 4096, [&](const IndexRange dst_points_range) {
829 for (const int dst_point_index : dst_points_range) {
830 const ed::greasepencil::PointTransferData &dst_point = dst_points[dst_point_index];
831 dst_opacity.span[dst_point_index] = dst_point.opacity;
832
833 if (!dst_point.is_src_point || dst_point.opacity != src_opacity[dst_point.src_point]) {
834 opacity_modified.span[dst_point_index] = true;
835 }
836 }
837 });
838 dst_opacity.finish();
839 opacity_modified.finish();
840 }
841
842 SpanAttributeWriter<bool> dst_inserted = dst_attributes.lookup_or_add_for_write_span<bool>(
843 "_eraser_inserted", bke::AttrDomain::Point);
844 BLI_assert(dst_inserted);
845 const OffsetIndices<int> &dst_points_by_curve = dst.points_by_curve();
846 threading::parallel_for(dst.curves_range(), 4096, [&](const IndexRange dst_curves_range) {
847 for (const int dst_curve : dst_curves_range) {
848 IndexRange dst_points_range = dst_points_by_curve[dst_curve];
849
850 dst_inserted.span[dst_points_range.first()] = false;
851 dst_inserted.span[dst_points_range.last()] = false;
852
853 if (dst_points_range.size() < 3) {
854 continue;
855 }
856
857 for (const int dst_point_index : dst_points_range.drop_back(1).drop_front(1)) {
858 const ed::greasepencil::PointTransferData &dst_point = dst_points[dst_point_index];
859 dst_inserted.span[dst_point_index] |= !dst_point.is_src_point;
860 }
861 }
862 });
863 dst_inserted.finish();
864
865 return true;
866 }
867
869 const bke::CurvesGeometry &src,
870 const Span<float2> screen_space_positions,
871 bke::CurvesGeometry &dst) const
872 {
873 const OffsetIndices<int> src_points_by_curve = src.points_by_curve();
874 const VArray<bool> src_cyclic = src.cyclic();
875
876 IndexMaskMemory memory;
877 const VArray<int> &stroke_materials = *src.attributes().lookup_or_default<int>(
878 "material_index", bke::AttrDomain::Curve, 0);
879 const IndexMask strokes_to_keep = IndexMask::from_predicate(
880 src.curves_range(), memory, [&](const int src_curve) {
881 const MaterialGPencilStyle *mat = BKE_gpencil_material_settings(
882 &ob, stroke_materials[src_curve] + 1);
883 /* Keep strokes with locked material. */
884 if (mat->flag & GP_MATERIAL_LOCKED) {
885 return true;
886 }
887
888 const IndexRange src_curve_points = src_points_by_curve[src_curve];
889
890 /* One-point stroke : remove the stroke if the point lies inside of the eraser. */
891 if (src_curve_points.size() == 1) {
892 const float2 &point_pos = screen_space_positions[src_curve_points.first()];
893 const float dist_to_eraser = math::distance(point_pos, this->mouse_position);
894 return !(dist_to_eraser < this->eraser_radius);
895 }
896
897 /* If any segment of the stroke is closer to the eraser than its radius, then remove
898 * the stroke. */
899 for (const int src_point : src_curve_points.drop_back(1)) {
900 const float dist_to_eraser = dist_to_line_segment_v2(
901 this->mouse_position,
902 screen_space_positions[src_point],
903 screen_space_positions[src_point + 1]);
904 if (dist_to_eraser < this->eraser_radius) {
905 return false;
906 }
907 }
908
909 if (src_cyclic[src_curve]) {
910 const float dist_to_eraser = dist_to_line_segment_v2(
911 this->mouse_position,
912 screen_space_positions[src_curve_points.first()],
913 screen_space_positions[src_curve_points.last()]);
914 if (dist_to_eraser < this->eraser_radius) {
915 return false;
916 }
917 }
918
919 return true;
920 });
921
922 if (strokes_to_keep.size() == src.curves_num()) {
923 return false;
924 }
925
926 dst = bke::curves_copy_curve_selection(src, strokes_to_keep, {});
927 return true;
928 }
929
930 void execute(EraseOperation &self, const bContext &C, const InputSample &extension_sample)
931 {
932 using namespace blender::bke::greasepencil;
933 Scene *scene = CTX_data_scene(&C);
934 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(&C);
935 ARegion *region = CTX_wm_region(&C);
937 Object *ob_eval = DEG_get_evaluated(depsgraph, obact);
938
939 /* Get the brush data. */
940 this->mouse_position = extension_sample.mouse_position;
941 this->eraser_radius = self.radius_;
942 this->eraser_strength = self.strength_;
943
944 if (BKE_brush_use_size_pressure(self.eraser_brush_)) {
945 this->eraser_radius *= BKE_curvemapping_evaluateF(
946 self.eraser_brush_->gpencil_settings->curve_strength, 0, extension_sample.pressure);
947 }
948 if (BKE_brush_use_alpha_pressure(self.eraser_brush_)) {
949 this->eraser_strength *= BKE_curvemapping_evaluateF(
950 self.eraser_brush_->gpencil_settings->curve_strength, 0, extension_sample.pressure);
951 }
952 this->brush_ = self.eraser_brush_;
953
954 this->mouse_position_pixels = int2(round_fl_to_int(this->mouse_position.x),
955 round_fl_to_int(this->mouse_position.y));
956 const int64_t eraser_radius_pixels = round_fl_to_int(this->eraser_radius);
957 this->eraser_squared_radius_pixels = eraser_radius_pixels * eraser_radius_pixels;
958
959 /* Get the grease pencil drawing. */
960 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(obact->data);
961
962 bool changed = false;
963 const auto execute_eraser_on_drawing = [&](const int layer_index, Drawing &drawing) {
964 const Layer &layer = grease_pencil.layer(layer_index);
965 const bke::CurvesGeometry &src = drawing.strokes();
966
967 /* Evaluated geometry. */
970 ob_eval, *obact, drawing);
971
972 /* Compute screen space positions. */
973 Array<float2> screen_space_positions(src.points_num());
974 threading::parallel_for(src.points_range(), 4096, [&](const IndexRange src_points) {
975 for (const int src_point : src_points) {
976 const int result = ED_view3d_project_float_global(
977 region,
978 math::transform_point(layer.to_world_space(*ob_eval),
979 deformation.positions[src_point]),
980 screen_space_positions[src_point],
981 V3D_PROJ_TEST_CLIP_NEAR | V3D_PROJ_TEST_CLIP_FAR);
982 if (result != V3D_PROJ_RET_OK) {
983 /* Set the screen space position to a impossibly far coordinate for all the points
984 * that are outside near/far clipping planes, this is to prevent accidental
985 * intersections with strokes not visibly present in the camera. */
986 screen_space_positions[src_point] = float2(1e20);
987 }
988 }
989 });
990
991 /* Erasing operator. */
993 bool erased = false;
994 switch (self.eraser_mode_) {
996 erased = stroke_eraser(*obact, src, screen_space_positions, dst);
997 break;
999 erased = hard_eraser(*obact, src, screen_space_positions, dst, self.keep_caps_);
1000 break;
1002 erased = soft_eraser(*obact, src, screen_space_positions, dst, self.keep_caps_);
1003 break;
1004 }
1005
1006 if (erased) {
1007 /* Set the new geometry. */
1008 drawing.strokes_for_write() = std::move(dst);
1009 drawing.tag_topology_changed();
1010 changed = true;
1011 self.affected_drawings_.add(&drawing);
1012 }
1013 };
1014
1015 if (self.active_layer_only_) {
1016 /* Erase only on the drawing at the current frame of the active layer. */
1017 if (!grease_pencil.has_active_layer()) {
1018 return;
1019 }
1020 const Layer &active_layer = *grease_pencil.get_active_layer();
1021 Drawing *drawing = grease_pencil.get_editable_drawing_at(active_layer, scene->r.cfra);
1022
1023 if (drawing == nullptr) {
1024 return;
1025 }
1026
1027 execute_eraser_on_drawing(*grease_pencil.get_layer_index(active_layer), *drawing);
1028 }
1029 else {
1030 /* Erase on all editable drawings. */
1033 for (const ed::greasepencil::MutableDrawingInfo &info : drawings) {
1034 execute_eraser_on_drawing(info.layer_index, info.drawing);
1035 }
1036 }
1037
1038 if (changed) {
1041 }
1042 }
1043};
1044
1045void EraseOperation::on_stroke_begin(const bContext &C, const InputSample & /*start_sample*/)
1046{
1049
1050 eraser_brush_ = brush;
1051 radius_ = BKE_brush_radius_get(paint, brush);
1052
1053 /* If we're using the draw tool to erase (e.g. while holding ctrl), then we should use the
1054 * eraser brush instead. Find the last used eraser for this. */
1055 if (temp_eraser_) {
1056 Main *bmain = CTX_data_main(&C);
1057 Scene *scene = CTX_data_scene(&C);
1058 Object *object = CTX_data_active_object(&C);
1059 GreasePencil *grease_pencil = id_cast<GreasePencil *>(object->data);
1060
1061 std::optional<AssetWeakReference> asset_reference =
1064 /* This should only fail in the case where the essential assets are not found. */
1065 if (asset_reference) {
1066 Brush *eraser_brush = reinterpret_cast<Brush *>(
1067 bke::asset_edit_id_from_weak_reference(*bmain, ID_BR, *asset_reference));
1068 if (eraser_brush) {
1069 eraser_brush_ = eraser_brush;
1070 radius_ = BKE_brush_radius_get(paint, eraser_brush_);
1071 }
1072 }
1073
1074 grease_pencil->runtime->temp_eraser_radius = radius_;
1075 grease_pencil->runtime->temp_use_eraser = true;
1076 }
1077
1078 if (eraser_brush_->gpencil_settings == nullptr) {
1079 BKE_brush_init_gpencil_settings(eraser_brush_);
1080 }
1081 BLI_assert(eraser_brush_->gpencil_settings != nullptr);
1082
1083 BKE_curvemapping_init(eraser_brush_->curve_distance_falloff);
1084 BKE_curvemapping_init(eraser_brush_->gpencil_settings->curve_strength);
1085
1086 eraser_mode_ = eGP_BrushEraserMode(eraser_brush_->gpencil_settings->eraser_mode);
1087 keep_caps_ = ((eraser_brush_->gpencil_settings->flag & GP_BRUSH_ERASER_KEEP_CAPS) != 0);
1088 active_layer_only_ = ((eraser_brush_->gpencil_settings->flag & GP_BRUSH_ACTIVE_LAYER_ONLY) != 0);
1089 strength_ = eraser_brush_->alpha;
1090}
1091
1092void EraseOperation::on_stroke_extended(const bContext &C, const InputSample &extension_sample)
1093{
1094 EraseOperationExecutor executor{C};
1095 executor.execute(*this, C, extension_sample);
1096}
1097
1099 const VArray<float> &opacities,
1100 const float epsilon)
1101{
1102 /* Simplify in between the ranges of inserted points. */
1103 const VArray<bool> point_was_inserted = *curves.attributes().lookup<bool>(
1104 "_eraser_inserted", bke::AttrDomain::Point);
1105 BLI_assert(point_was_inserted);
1106 IndexMaskMemory memory;
1107 const IndexMask inserted_points = IndexMask::from_bools(point_was_inserted, memory);
1108
1109 /* Distance function for the simplification algorithm.
1110 * It is computed as the difference in opacity that may result from removing the
1111 * samples inside the range. */
1112 const Span<float3> positions = curves.positions();
1113 const auto opacity_distance = [&](int64_t first_index, int64_t last_index, int64_t index) {
1114 const float3 &s0 = positions[first_index];
1115 const float3 &s1 = positions[last_index];
1116 const float segment_length = math::distance(s0, s1);
1117 if (segment_length < 1e-6) {
1118 return 0.0f;
1119 }
1120 const float t = math::distance(s0, positions[index]) / segment_length;
1121 const float linear_opacity = math::interpolate(
1122 opacities[first_index], opacities[last_index], t);
1123 return math::abs(opacities[index] - linear_opacity);
1124 };
1125
1126 Array<bool> dissolve_points(curves.points_num(), false);
1127 inserted_points.foreach_range([&](const IndexRange &range) {
1128 const IndexRange range_to_simplify(range.one_before_start(), range.size() + 2);
1130 range_to_simplify, epsilon, opacity_distance, dissolve_points);
1131 });
1132
1133 /* Remove the points. */
1134 const IndexMask points_to_dissolve = IndexMask::from_bools(dissolve_points, memory);
1135 curves.remove_points(points_to_dissolve, {});
1136}
1137
1139 const VArray<float> &opacities,
1140 const float epsilon)
1141{
1142 const VArray<bool> point_was_modified = *curves.attributes().lookup<bool>(
1143 "_eraser_opacity_modified", bke::AttrDomain::Point);
1144 if (!point_was_modified) {
1145 return;
1146 }
1147
1148 IndexMaskMemory memory;
1149 const IndexMask points_to_remove_and_split = IndexMask::from_predicate(
1150 curves.points_range(), memory, [&](const int64_t point) {
1151 return opacities[point] < epsilon && point_was_modified[point];
1152 });
1153 curves = geometry::grease_pencil_remove_points_and_split(curves, points_to_remove_and_split);
1154}
1155
1157{
1158 Object *object = CTX_data_active_object(&C);
1159 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
1160 if (temp_eraser_) {
1161 /* If we're using the draw tool to temporarily erase, then we need to reset the
1162 * `temp_use_eraser` flag here. */
1163 grease_pencil.runtime->temp_use_eraser = false;
1164 grease_pencil.runtime->temp_eraser_radius = 0.0f;
1165 }
1166
1167 for (GreasePencilDrawing *drawing_ : affected_drawings_) {
1168 bke::greasepencil::Drawing &drawing = drawing_->wrap();
1169
1170 if (drawing.strokes().attributes().contains("_eraser_inserted")) {
1171 simplify_opacities(drawing.strokes_for_write(), drawing.opacities(), 0.01f);
1172 }
1173
1174 if (this->eraser_mode_ == GP_BRUSH_ERASER_SOFT) {
1175 remove_points_with_low_opacity(drawing.strokes_for_write(), drawing.opacities(), 0.0001f);
1176 drawing.strokes_for_write().attributes_for_write().remove("_eraser_opacity_modified");
1177 }
1178
1179 drawing.strokes_for_write().attributes_for_write().remove("_eraser_inserted");
1180 drawing.tag_topology_changed();
1181 }
1182
1183 affected_drawings_.clear();
1184
1187}
1188
1189std::unique_ptr<GreasePencilStrokeOperation> new_erase_operation(const bool temp_eraser)
1190{
1191 return std::make_unique<EraseOperation>(temp_eraser);
1192}
1193
1194} // namespace blender::ed::sculpt_paint::greasepencil
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define IN_RANGE(a, b, c)
Span< T > as_span() const
Definition BLI_array.hh:254
const T * begin() const
Definition BLI_array.hh:332
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)
constexpr int64_t one_before_start() const
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr int64_t size() const
Definition BLI_span.hh:256
int64_t size() const
void append(const T &value)
const T & last(const int64_t n=0) const
void remove(const int64_t index)
bool is_empty() const
IndexRange index_range() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
bool contains(StringRef name) const
VArray< bool > cyclic() const
AttributeAccessor attributes() 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())
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
void on_stroke_done(const bContext &C) override
Definition erase.cc:1156
void on_stroke_extended(const bContext &C, const InputSample &extension_sample) override
Definition erase.cc:1092
void on_stroke_begin(const bContext &C, const InputSample &start_sample) override
Definition erase.cc:1045
void foreach_range(ForeachRangeFn auto &&fn) const
#define layer
float distance(float, float) RET
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval, const Object &ob_orig, const bke::greasepencil::Drawing &drawing_orig)
ID * asset_edit_id_from_weak_reference(Main &global_main, ID_Type id_type, const AssetWeakReference &weak_ref)
CurvesGeometry curves_copy_curve_selection(const CurvesGeometry &curves, const IndexMask &curves_to_copy, const AttributeFilter &attribute_filter)
int64_t ramer_douglas_peucker_simplify(const IndexRange range, const float epsilon, const FunctionRef< float(int64_t, int64_t, int64_t)> dist_function, MutableSpan< bool > points_to_delete)
Array< PointTransferData > compute_topology_change(const bke::CurvesGeometry &src, bke::CurvesGeometry &dst, const Span< Vector< PointTransferData > > src_to_dst_points, const bool keep_caps)
Vector< MutableDrawingInfo > retrieve_editable_drawings(const Scene &scene, GreasePencil &grease_pencil)
static void simplify_opacities(bke::CurvesGeometry &curves, const VArray< float > &opacities, const float epsilon)
Definition erase.cc:1098
std::unique_ptr< GreasePencilStrokeOperation > new_erase_operation(const bool temp_eraser)
Definition erase.cc:1189
static void remove_points_with_low_opacity(bke::CurvesGeometry &curves, const VArray< float > &opacities, const float epsilon)
Definition erase.cc:1138
bke::CurvesGeometry grease_pencil_remove_points_and_split(const bke::CurvesGeometry &curves, const IndexMask &mask)
T clamp(const T &a, const T &min, const T &max)
T sqrt(const T &a)
T distance(const T &a, const T &b)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T max(const T &a, const T &b)
T abs(const T &a)
T round(const T &a)
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
float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:316
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
std::optional< AssetWeakReference > WM_toolsystem_last_brush_asset_from_brush_type(Scene *scene, const int brush_type, const PaintMode paint_mode)
MINLINE int round_fl_to_int(float a)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
float BKE_brush_radius_get(const Paint *paint, const Brush *brush)
Definition brush.cc:1366
void BKE_brush_init_gpencil_settings(Brush *brush)
Definition brush.cc:719
bool BKE_brush_use_alpha_pressure(const Brush *brush)
Definition brush.cc:1385
MaterialGPencilStyle * BKE_gpencil_material_settings(Object *ob, short act)
void BKE_curvemapping_init(CurveMapping *cumap)
@ GPAINT_BRUSH_TYPE_ERASE
@ GP_BRUSH_ERASER_STROKE
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void DEG_id_tag_update(ID *id, unsigned int flags)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
float BKE_brush_curve_strength(eBrushCurvePreset preset, const CurveMapping *cumap, float distance, float brush_radius)
Definition brush.cc:1691
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
Main * CTX_data_main(const bContext *C)
Paint * BKE_paint_get_active_from_context(const bContext *C)
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
Brush * BKE_paint_brush(Paint *paint)
Scene * CTX_data_scene(const bContext *C)
VecBase< float, 3 > float3
@ GP_BRUSH_ERASER_KEEP_CAPS
@ GP_BRUSH_ACTIVE_LAYER_ONLY
Object * CTX_data_active_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
signed char int8_t
Definition BKE_text.h:76
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct CurveMapping * curve_strength
struct BrushGpencilSettings * gpencil_settings
eMaterialGPencilStyle_Flag flag
static int8_t intersections_segment_circle_integers(const int2 &s0, const int2 &s1, const int2 &center, const int64_t radius_2, int64_t &r_mu0, int64_t &r_mu1)
Definition erase.cc:129
bool hard_eraser(Object &ob, const bke::CurvesGeometry &src, const Span< float2 > screen_space_positions, bke::CurvesGeometry &dst, const bool keep_caps) const
Definition erase.cc:508
void execute(EraseOperation &self, const bContext &C, const InputSample &extension_sample)
Definition erase.cc:930
bool soft_eraser(Object &ob, const bke::CurvesGeometry &src, const Span< float2 > screen_space_positions, bke::CurvesGeometry &dst, const bool keep_caps)
Definition erase.cc:704
static bool skip_strokes_with_locked_material(Object &ob, const int src_curve, const IndexRange &src_points, const VArray< int > stroke_material, const VArray< float > &point_opacity, Array< Vector< ed::greasepencil::PointTransferData > > &src_to_dst_points)
Definition erase.cc:480
int8_t segment_intersections_and_points_sides(const int2 &point, const int2 &point_after, const int64_t squared_radius, float &r_mu0, float &r_mu1, PointCircleSide &r_point_side, PointCircleSide &r_point_after_side) const
Definition erase.cc:210
int curves_intersections_and_points_sides(const bke::CurvesGeometry &src, const Span< float2 > screen_space_positions, const Span< EraserRing > rings, MutableSpan< std::pair< int, PointCircleSide > > r_point_ring, MutableSpan< SegmentCircleIntersection > r_intersections) const
Definition erase.cc:320
bool stroke_eraser(Object &ob, const bke::CurvesGeometry &src, const Span< float2 > screen_space_positions, bke::CurvesGeometry &dst) const
Definition erase.cc:868