Blender V5.3
draw_ops.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 "ANIM_keyframing.hh"
6
7#include "BKE_brush.hh"
8#include "BKE_colortools.hh"
9#include "BKE_context.hh"
10#include "BKE_crazyspace.hh"
11#include "BKE_curves.hh"
12#include "BKE_deform.hh"
13#include "BKE_geometry_set.hh"
14#include "BKE_grease_pencil.hh"
15#include "BKE_library.hh"
16#include "BKE_material.hh"
17#include "BKE_object_deform.h"
18#include "BKE_paint.hh"
19#include "BKE_paint_types.hh"
20#include "BKE_report.hh"
21#include "BKE_screen.hh"
22
23#include "BLI_array_utils.hh"
24#include "BLI_assert.hh"
25#include "BLI_bounds.hh"
26#include "BLI_color_types.hh"
27#include "BLI_index_mask.hh"
28#include "BLI_kdopbvh.hh"
29#include "BLI_kdtree.hh"
30#include "BLI_math_geom_c.hh"
31#include "BLI_math_matrix.hh"
32#include "BLI_math_vector.hh"
33#include "BLI_offset_indices.hh"
34#include "BLI_rect.hh"
35
36#include "DNA_brush_enums.h"
37#include "DNA_brush_types.h"
38#include "DNA_scene_types.h"
39#include "DNA_view3d_types.h"
41
43
46#include "GEO_smooth_curves.hh"
47
48#include "ED_grease_pencil.hh"
49#include "ED_image.hh"
50#include "ED_object.hh"
51#include "ED_screen.hh"
52#include "ED_space_api.hh"
53#include "ED_view3d.hh"
54
55#include "MEM_guardedalloc.h"
56
57#include "RNA_access.hh"
58#include "RNA_define.hh"
59
60#include "UI_interface.hh"
61
62#include "BLT_translation.hh"
63
64#include "WM_api.hh"
65#include "WM_toolsystem.hh"
66#include "WM_types.hh"
67
68#include "../paint_intern.hh"
70#include "wm_event_types.hh"
71
72#include <algorithm>
73#include <fmt/format.h>
74#include <optional>
75
76namespace blender {
77
78namespace ed::sculpt_paint {
79
80/* -------------------------------------------------------------------- */
83
86 : PaintStroke(C, op, event, mode)
87 {
88 }
89
90 std::optional<float3> get_location(float2 mouse, bool force_original) override;
91 bool test_start(wmOperator *op, float2 mouse) override;
92 void update_step(wmOperator *op, const StrokeStep &stroke_step) override;
93 void redraw(bool final) override;
94 bool test_cancel() override;
95 void done(bool is_cancel, bool stroke_started) override;
96};
97
98std::optional<float3> GreasePencilPaintStroke::get_location(const float2 mouse,
99 bool /*force_original*/)
100{
101 return float3(mouse.x, mouse.y, 0);
102}
103
104static std::unique_ptr<GreasePencilStrokeOperation> get_stroke_operation(bContext &C,
105 wmOperator *op)
106{
110 const auto stroke_mode = BrushStrokeMode(RNA_enum_get(op->ptr, "mode"));
111 const auto brush_switch_mode = BrushSwitchMode(RNA_enum_get(op->ptr, "brush_toggle"));
112
113 if (mode == PaintMode::GPencil) {
114 if (brush.gpencil_brush_type == GPAINT_BRUSH_TYPE_DRAW &&
115 brush_switch_mode == BrushSwitchMode::Erase)
116 {
117 /* Special case: We're using the draw tool but with the eraser mode, so create an erase
118 * operation. */
120 }
121 /* FIXME: Somehow store the unique_ptr in the PaintStroke. */
122 switch (brush.gpencil_brush_type) {
128 /* Fill tool keymap uses the paint operator to draw fill guides. */
129 return greasepencil::new_paint_operation(/* do_fill_guides = */ true);
131 return greasepencil::new_tint_operation(brush_switch_mode == BrushSwitchMode::Erase);
132 }
133 }
134 else if (mode == PaintMode::SculptGPencil) {
135
136 if (brush_switch_mode == BrushSwitchMode::Smooth) {
137 return greasepencil::new_smooth_operation(stroke_mode, true);
138 }
139 switch (eBrushGPSculptType(brush.gpencil_sculpt_brush_type)) {
141 return greasepencil::new_smooth_operation(stroke_mode);
143 return greasepencil::new_thickness_operation(stroke_mode);
145 return greasepencil::new_strength_operation(stroke_mode);
147 return greasepencil::new_grab_operation(stroke_mode);
149 return greasepencil::new_push_operation(stroke_mode);
151 return greasepencil::new_twist_operation(stroke_mode);
153 return greasepencil::new_pinch_operation(stroke_mode);
155 return greasepencil::new_randomize_operation(stroke_mode);
157 return greasepencil::new_clone_operation(stroke_mode);
158 }
159 }
160 else if (mode == PaintMode::WeightGPencil) {
161 switch (eBrushGPWeightType(brush.gpencil_weight_brush_type)) {
170 }
171 }
172 else if (mode == PaintMode::VertexGPencil) {
173 switch (eBrushGPVertexType(brush.gpencil_vertex_brush_type)) {
185 /* Unused. */
187 return nullptr;
188 }
189 }
190 return nullptr;
191}
192
194{
195 return true;
196}
197
199{
201 mode_data_.get());
202
204 sample.mouse_position = stroke_step.mouse;
205 sample.pressure = stroke_step.pressure;
206
207 if (!operation) {
208 std::unique_ptr<GreasePencilStrokeOperation> new_operation = get_stroke_operation(
209 *this->evil_C, op);
210 BLI_assert(new_operation != nullptr);
211 new_operation->on_stroke_begin(*this->evil_C, sample);
212 mode_data_ = std::move(new_operation);
213 }
214 else {
215 operation->on_stroke_extended(*this->evil_C, sample);
216 }
217}
218
223
225{
226 return false;
227}
228
229void GreasePencilPaintStroke::done(bool /*is_cancel*/, bool /*stroke_started*/)
230{
232 mode_data_.get());
233 if (operation != nullptr) {
234 operation->on_stroke_done(*this->evil_C);
235 }
236}
237
239
240/* -------------------------------------------------------------------- */
243
245{
247 return false;
248 }
250 return false;
251 }
252 return true;
253}
254
256{
260 const auto brush_switch_mode = BrushSwitchMode(RNA_enum_get(op->ptr, "brush_toggle"));
261
262 if (brush && mode == PaintMode::GPencil) {
263 /* For the eraser and tint tool, we don't want auto-key to create an empty keyframe, so we
264 * duplicate the previous frame. */
265 if (ELEM(brush->gpencil_brush_type, GPAINT_BRUSH_TYPE_ERASE, GPAINT_BRUSH_TYPE_TINT)) {
266 return true;
267 }
268 /* Same for the temporary eraser when using the draw tool. */
269 if (brush->gpencil_brush_type == GPAINT_BRUSH_TYPE_DRAW &&
270 brush_switch_mode == BrushSwitchMode::Erase)
271 {
272 return true;
273 }
274 }
275 return false;
276}
277
279{
281 C, op, use_duplicate_previous_key(C, op)))
282 {
283 return OPERATOR_CANCELLED;
284 }
285 GreasePencilPaintStroke *stroke = MEM_new<GreasePencilPaintStroke>(
286 __func__, C, op, nullptr, PaintMode::GPencil);
287 op->customdata = stroke;
288
289 const wmOperatorStatus retval = stroke->exec(C, op);
290 OPERATOR_RETVAL_CHECK(retval);
291
292 MEM_delete(stroke);
293
294 return OPERATOR_FINISHED;
295}
296
298 wmOperator *op,
299 const wmEvent *event)
300{
301 if (event->tablet.active == EVT_TABLET_ERASER) {
302 RNA_enum_set(op->ptr, "brush_toggle", int(BrushSwitchMode::Erase));
303 }
304
306 C, op, use_duplicate_previous_key(C, op)))
307 {
308 return OPERATOR_CANCELLED;
309 }
310
311 GreasePencilPaintStroke *stroke = MEM_new<GreasePencilPaintStroke>(
312 __func__, C, op, event, PaintMode::GPencil);
313 op->customdata = stroke;
314
315 const wmOperatorStatus retval = op->type->modal(C, op, event);
316 OPERATOR_RETVAL_CHECK(retval);
317
318 if (retval == OPERATOR_FINISHED) {
319 MEM_delete(stroke);
320 return OPERATOR_FINISHED;
321 }
322
325}
326
328 wmOperator *op,
329 const wmEvent *event)
330{
331 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
332 const wmOperatorStatus retval = stroke->modal(C, op, event);
333
335 MEM_delete(stroke);
336 }
337
338 return retval;
339}
340
342{
343 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
344 stroke->cancel(C);
345}
346
348{
349 ot->name = "Grease Pencil Draw";
350 ot->idname = "GREASE_PENCIL_OT_brush_stroke";
351 ot->description = "Draw a new stroke in the active Grease Pencil object";
352
358
359 /* No #OPTYPE_REGISTER: interactive strokes don't record their samples, so redo and repeat
360 * would run #exec with an empty stroke. */
361 ot->flag = OPTYPE_UNDO;
362
364}
365
367
368/* -------------------------------------------------------------------- */
371
373{
375 return false;
376 }
378 return false;
379 }
380 return true;
381}
382
384 wmOperator *op,
385 const wmEvent *event)
386{
387 const Scene *scene = CTX_data_scene(C);
388 const Object *object = CTX_data_active_object(C);
389 if (!object || object->type != OB_GREASE_PENCIL) {
390 return OPERATOR_CANCELLED;
391 }
392
393 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
395 BKE_report(op->reports, RPT_ERROR, "No editable Grease Pencil layer");
396 return OPERATOR_CANCELLED;
397 }
398
401 if (brush == nullptr) {
402 return OPERATOR_CANCELLED;
403 }
404
405 /* Ensure a drawing at the current keyframe. */
406 bool inserted_keyframe = false;
407 /* For the sculpt tools, we don't want the auto-key to create an empty keyframe, so we duplicate
408 * the previous key. */
409 const bool use_duplicate_previous_key = true;
410 for (bke::greasepencil::Layer *layer : grease_pencil.layers_for_write()) {
411 if (layer->is_editable() &&
413 *scene, grease_pencil, *layer, use_duplicate_previous_key, inserted_keyframe))
414 {
415 inserted_keyframe = true;
416 }
417 }
418 if (!inserted_keyframe) {
419 BKE_report(op->reports, RPT_ERROR, "No Grease Pencil frame to draw on");
420 return OPERATOR_CANCELLED;
421 }
423
424 GreasePencilPaintStroke *stroke = MEM_new<GreasePencilPaintStroke>(
425 __func__, C, op, event, PaintMode::SculptGPencil);
426 op->customdata = stroke;
427
428 const wmOperatorStatus retval = op->type->modal(C, op, event);
429 OPERATOR_RETVAL_CHECK(retval);
430
431 if (retval == OPERATOR_FINISHED) {
432 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
433 if (stroke) {
434 MEM_delete(stroke);
435 }
436 return OPERATOR_FINISHED;
437 }
438
441}
442
444 wmOperator *op,
445 const wmEvent *event)
446{
447 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
448 const wmOperatorStatus retval = stroke->modal(C, op, event);
449
451 MEM_delete(stroke);
452 op->customdata = nullptr;
453 }
454
455 return retval;
456}
457
459{
460 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
461 stroke->cancel(C);
462}
463
465{
466 ot->name = "Grease Pencil Sculpt";
467 ot->idname = "GREASE_PENCIL_OT_sculpt_paint";
468 ot->description = "Sculpt strokes in the active Grease Pencil object";
469
474
476
478}
479
481
482/* -------------------------------------------------------------------- */
485
487{
489 return false;
490 }
492 return false;
493 }
494 return true;
495}
496
498 wmOperator *op,
499 const wmEvent *event)
500{
501 const Scene *scene = CTX_data_scene(C);
502 const Object *object = CTX_data_active_object(C);
503 if (!object || object->type != OB_GREASE_PENCIL) {
504 return OPERATOR_CANCELLED;
505 }
506
507 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
510 if (brush == nullptr) {
511 return OPERATOR_CANCELLED;
512 }
513
516 if (drawings.is_empty()) {
517 BKE_report(op->reports, RPT_ERROR, "No Grease Pencil frame to draw weight on");
518 return OPERATOR_CANCELLED;
519 }
520
521 const int active_defgroup_nr = BKE_object_defgroup_active_index_get(object) - 1;
522 if (active_defgroup_nr >= 0 && BKE_object_defgroup_active_is_locked(object)) {
523 BKE_report(op->reports, RPT_WARNING, "Active group is locked, aborting");
524 return OPERATOR_CANCELLED;
525 }
526
527 GreasePencilPaintStroke *stroke = MEM_new<GreasePencilPaintStroke>(
528 __func__, C, op, event, PaintMode::WeightGPencil);
529 op->customdata = stroke;
530
531 const wmOperatorStatus retval = op->type->modal(C, op, event);
532 OPERATOR_RETVAL_CHECK(retval);
533
534 if (retval == OPERATOR_FINISHED) {
535 MEM_delete(stroke);
536 return OPERATOR_FINISHED;
537 }
538
541}
542
544 wmOperator *op,
545 const wmEvent *event)
546{
547 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
548 const wmOperatorStatus retval = stroke->modal(C, op, event);
549
551 MEM_delete(stroke);
552 }
553
554 return retval;
555}
556
558{
559 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
560 stroke->cancel(C);
561}
562
564{
565 ot->name = "Grease Pencil Paint Weight";
566 ot->idname = "GREASE_PENCIL_OT_weight_brush_stroke";
567 ot->description = "Draw weight on stroke points in the active Grease Pencil object";
568
573
575
577}
578
580
581/* -------------------------------------------------------------------- */
584
586{
588 return false;
589 }
591 return false;
592 }
593 return true;
594}
595
597 wmOperator *op,
598 const wmEvent *event)
599{
600 const Scene *scene = CTX_data_scene(C);
601 const Object *object = CTX_data_active_object(C);
602 if (!object || object->type != OB_GREASE_PENCIL) {
603 return OPERATOR_CANCELLED;
604 }
605
606 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
608 BKE_report(op->reports, RPT_ERROR, "No editable Grease Pencil layer");
609 return OPERATOR_CANCELLED;
610 }
611
614 if (brush == nullptr) {
615 return OPERATOR_CANCELLED;
616 }
617
618 /* Ensure a drawing at the current keyframe. */
619 bool inserted_keyframe = false;
620 /* For the vertex paint tools, we don't want the auto-key to create an empty keyframe, so we
621 * duplicate the previous key. */
622 const bool use_duplicate_previous_key = true;
623 for (bke::greasepencil::Layer *layer : grease_pencil.layers_for_write()) {
624 if (layer->is_editable() &&
626 *scene, grease_pencil, *layer, use_duplicate_previous_key, inserted_keyframe))
627 {
628 inserted_keyframe = true;
629 }
630 }
631 if (!inserted_keyframe) {
632 BKE_report(op->reports, RPT_ERROR, "No Grease Pencil frame to draw on");
633 return OPERATOR_CANCELLED;
634 }
636
637 GreasePencilPaintStroke *stroke = MEM_new<GreasePencilPaintStroke>(
638 __func__, C, op, event, PaintMode::VertexGPencil);
639 op->customdata = stroke;
640
641 const wmOperatorStatus retval = op->type->modal(C, op, event);
642 OPERATOR_RETVAL_CHECK(retval);
643
644 if (retval == OPERATOR_FINISHED) {
645 MEM_delete(stroke);
646 return OPERATOR_FINISHED;
647 }
648
651}
652
654 wmOperator *op,
655 const wmEvent *event)
656{
657 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
658 const wmOperatorStatus retval = stroke->modal(C, op, event);
659
661 MEM_delete(stroke);
662 }
663
664 return retval;
665}
666
668{
669 GreasePencilPaintStroke *stroke = static_cast<GreasePencilPaintStroke *>(op->customdata);
670 stroke->cancel(C);
671}
672
674{
675 ot->name = "Grease Pencil Paint Vertex";
676 ot->idname = "GREASE_PENCIL_OT_vertex_brush_stroke";
677 ot->description = "Draw on vertex colors in the active Grease Pencil object";
678
683
685
687}
688
690
691/* -------------------------------------------------------------------- */
694
697
698 /* Material of the generated stroke. */
700 /* Toggle inverse filling. */
701 bool invert = false;
702 /* Toggle precision mode. */
703 bool precision = false;
704
705 /* Methods for gap filling. */
707 /* Length of extension lines. */
709 /* Cut off extension lines at first intersection. */
711
712 /* Draw boundaries stroke overlay. */
714 /* Draw extension lines overlay. */
716 /* Is the method Delaunay. */
718
719 /* Mouse position where fill was initialized */
721 /* Extension lines drag mode is enabled (middle mouse button). */
723 /* Mouse position where the extension mode was enabled. */
725
726 /* All the mouse positions while its held down. Only used for the Delaunay method. */
728
729 /* Overlay draw callback for helper lines, etc. */
731
734 const int material_index,
735 const bool invert,
736 const bool precision)
737 {
739
741 const Brush &brush = *BKE_paint_brush(&ts.gp_paint->paint);
743 brush.gpencil_settings->fill_extend_mode);
744
745 const bool is_delaunay_method = brush.gpencil_settings->fill_solver == GP_FILL_SOLVER_DELAUNAY;
746 const bool show_boundaries = (brush.gpencil_settings->flag & GP_BRUSH_FILL_SHOW_HELPLINES) &&
748 const bool show_extension = (brush.gpencil_settings->flag & GP_BRUSH_FILL_SHOW_EXTENDLINES) &&
750 const float extension_length = brush.gpencil_settings->fill_extend_fac *
752 const bool extension_cut = brush.gpencil_settings->flag & GP_BRUSH_FILL_STROKE_COLLIDE;
753 const bool brush_invert = brush.gpencil_settings->fill_direction == BRUSH_DIR_IN;
754 /* Both operator properties and brush properties can invert. Actual invert is XOR of both. */
755 const bool combined_invert = (invert != brush_invert);
756
757 return {layer,
759 combined_invert,
760 precision,
767 }
768};
769
770/* Find and cut extension lines at intersections with other lines and strokes. */
772 ed::greasepencil::ExtensionData &extension_data,
773 Span<int> origin_drawings,
774 Span<int> origin_points)
775{
776 const RegionView3D &rv3d = *CTX_wm_region_view3d(&C);
777 const Scene &scene = *CTX_data_scene(&C);
778 const Object &object = *CTX_data_active_object(&C);
779 const GreasePencil &grease_pencil = *id_cast<const GreasePencil *>(object.data);
780
781 const float4x4 view_matrix = float4x4(rv3d.viewmat);
782
785
786 const IndexRange bvh_extension_range = extension_data.lines.starts.index_range();
787 Array<int> bvh_curve_offsets_data(drawings.size() + 1);
788 for (const int i : drawings.index_range()) {
789 bvh_curve_offsets_data[i] = drawings[i].drawing.strokes().points_num();
790 }
792 bvh_curve_offsets_data, bvh_extension_range.size());
793
794 /* Upper bound for segment count. Arrays are sized for easy index mapping, exact count isn't
795 * necessary. Not all entries are added to the BVH tree. */
796 const int max_bvh_lines = bvh_curve_offsets.data().last();
797 /* Cached view positions for lines. */
798 Array<float2> view_starts(max_bvh_lines);
799 Array<float2> view_ends(max_bvh_lines);
800
801 BVHTree *tree = BLI_bvhtree_new(max_bvh_lines, 0.0f, 4, 6);
802 BLI_SCOPED_DEFER([&]() { BLI_bvhtree_free(tree); });
803
804 /* Insert extension lines for intersection.
805 * Note: These are added first, so that the extension index matches its index in BVH data. */
806 for (const int i_line : bvh_extension_range.index_range()) {
807 const float2 start =
808 math::transform_point(view_matrix, extension_data.lines.starts[i_line]).xy();
809 const float2 end = math::transform_point(view_matrix, extension_data.lines.ends[i_line]).xy();
810
811 const int bvh_index = bvh_extension_range[i_line];
812 view_starts[bvh_index] = start;
813 view_ends[bvh_index] = end;
814
815 const float bb[6] = {start.x, start.y, 0.0f, end.x, end.y, 0.0f};
816 BLI_bvhtree_insert(tree, bvh_index, bb, 2);
817 }
818
819 /* Insert segments for cutting extensions on stroke intersection. */
820 for (const int i_drawing : drawings.index_range()) {
821 const ed::greasepencil::DrawingInfo &info = drawings[i_drawing];
823 const OffsetIndices points_by_curve = curves.points_by_curve();
824 const Span<float3> positions = curves.positions();
825 const VArray<bool> cyclic = curves.cyclic();
827 const float4x4 layer_to_view = view_matrix * layer.to_world_space(object);
828
829 for (const int i_curve : curves.curves_range()) {
830 const bool is_cyclic = cyclic[i_curve];
831 const IndexRange points = points_by_curve[i_curve];
832
833 for (const int i_point : points.drop_back(1)) {
834 const float2 start = math::transform_point(layer_to_view, positions[i_point]).xy();
835 const float2 end = math::transform_point(layer_to_view, positions[i_point + 1]).xy();
836
837 const int bvh_index = bvh_curve_offsets[i_drawing][i_point];
838 view_starts[bvh_index] = start;
839 view_ends[bvh_index] = end;
840
841 const float bb[6] = {start.x, start.y, 0.0f, end.x, end.y, 0.0f};
842 BLI_bvhtree_insert(tree, bvh_index, bb, 2);
843 }
844 /* Last->first point segment only used for cyclic curves. */
845 if (is_cyclic) {
846 const float2 start = math::transform_point(layer_to_view, positions[points.last()]).xy();
847 const float2 end = math::transform_point(layer_to_view, positions[points.first()]).xy();
848
849 const int bvh_index = bvh_curve_offsets[i_drawing][points.last()];
850 view_starts[bvh_index] = start;
851 view_ends[bvh_index] = end;
852
853 const float bb[6] = {start.x, start.y, 0.0f, end.x, end.y, 0.0f};
854 BLI_bvhtree_insert(tree, bvh_index, bb, 2);
855 }
856 }
857 }
858
860
861 struct RaycastArgs {
862 Span<float2> starts;
863 Span<float2> ends;
864 /* Indices that may need to be ignored to avoid self-intersection. */
865 int ignore_index1;
866 int ignore_index2;
867 int ignore_index3;
868 };
869 BVHTree_RayCastCallback callback =
870 [](void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) {
871 using Result = math::isect_result<float2>;
872
873 const RaycastArgs &args = *static_cast<const RaycastArgs *>(userdata);
874 if (ELEM(index, args.ignore_index1, args.ignore_index2, args.ignore_index3)) {
875 return;
876 }
877
878 const float2 ray_start = float2(ray->origin);
879 const float2 ray_end = ray_start + float2(ray->direction) * ray->radius;
880 const float2 &line_start = args.starts[index];
881 const float2 &line_end = args.ends[index];
882 Result result = math::isect_seg_seg(ray_start, ray_end, line_start, line_end);
883 if (result.kind <= 0) {
884 return;
885 }
886 const float dist = result.lambda * math::distance(ray_start, ray_end);
887 if (dist >= hit->dist) {
888 return;
889 }
890 /* These always need to be calculated for the BVH traversal function. */
891 hit->index = index;
892 hit->dist = result.lambda * math::distance(ray_start, ray_end);
893 /* Don't need the hit point, only the lambda. */
894 hit->no[0] = result.lambda;
895 };
896
897 /* Store intersections first before applying to the data, so that subsequent ray-casts use
898 * original end points until all intersections are found. */
899 Vector<float3> new_extension_ends(extension_data.lines.ends.size());
900 for (const int i_line : extension_data.lines.starts.index_range()) {
901 const float2 start =
902 math::transform_point(view_matrix, extension_data.lines.starts[i_line]).xy();
903 const float2 end = math::transform_point(view_matrix, extension_data.lines.ends[i_line]).xy();
904 float length;
905 const float2 dir = math::normalize_and_get_length(end - start, length);
906
907 const int bvh_index = i_line;
908 const int origin_drawing = origin_drawings[i_line];
909 const int origin_point = origin_points[i_line];
910 const int bvh_origin_index = bvh_curve_offsets[origin_drawing][origin_point];
911
912 /* For curvature extensions (mid-stroke), also exclude the adjacent segment. */
913 int bvh_adjacent_index = -1;
914 if (origin_point > 0 && origin_point < bvh_curve_offsets[origin_drawing].size() - 1) {
915 /* This is a curvature extension, exclude the previous segment. */
916 bvh_adjacent_index = bvh_curve_offsets[origin_drawing][origin_point - 1];
917 }
918
919 RaycastArgs args = {view_starts, view_ends, bvh_index, bvh_origin_index, bvh_adjacent_index};
920 BVHTreeRayHit hit;
921 hit.index = -1;
922 hit.dist = FLT_MAX;
924 tree, float3(start, 0.0f), float3(dir, 0.0f), length, &hit, callback, &args);
925
926 if (hit.index >= 0) {
927 const float lambda = hit.no[0];
928 new_extension_ends[i_line] = math::interpolate(
929 extension_data.lines.starts[i_line], extension_data.lines.ends[i_line], lambda);
930 }
931 else {
932 new_extension_ends[i_line] = extension_data.lines.ends[i_line];
933 }
934 }
935
936 extension_data.lines.ends = std::move(new_extension_ends);
937}
938
939/* Find closest point in each circle and generate extension lines between such pairs. */
941 const bContext &C,
942 ed::greasepencil::ExtensionData &extension_data,
943 Span<int> /*origin_drawings*/,
944 Span<int> /*origin_points*/)
945{
946 const RegionView3D &rv3d = *CTX_wm_region_view3d(&C);
947 const Scene &scene = *CTX_data_scene(&C);
948 const Object &object = *CTX_data_active_object(&C);
949 const GreasePencil &grease_pencil = *id_cast<const GreasePencil *>(object.data);
950
951 const float4x4 view_matrix = float4x4(rv3d.viewmat);
952
955
956 const IndexRange circles_range = extension_data.circles.centers.index_range();
957 /* TODO Include high-curvature feature points. */
958 const IndexRange feature_points_range = circles_range.after(0);
959 const IndexRange kd_points_range = IndexRange(circles_range.size() +
960 feature_points_range.size());
961
962 /* Upper bound for segment count. Arrays are sized for easy index mapping, exact count isn't
963 * necessary. Not all entries are added to the BVH tree. */
964 const int max_kd_entries = kd_points_range.size();
965 /* Cached view positions for lines. */
966 Array<float2> view_centers(max_kd_entries);
967 Array<float> view_radii(max_kd_entries);
968
969 KDTree<float2> *kdtree = kdtree_new<float2>(max_kd_entries);
970
971 /* Insert points for overlap tests. */
972 for (const int point_i : circles_range.index_range()) {
973 const float2 center =
974 math::transform_point(view_matrix, extension_data.circles.centers[point_i]).xy();
975 const float radius = math::average(math::to_scale(view_matrix)) *
976 extension_data.circles.radii[point_i];
977
978 const int kd_index = circles_range[point_i];
979 view_centers[kd_index] = center;
980 view_radii[kd_index] = radius;
981
982 kdtree_insert<float2>(kdtree, kd_index, center);
983 }
984 for (const int i_point : feature_points_range.index_range()) {
985 /* TODO Insert feature points into the KDTree. */
986 UNUSED_VARS(i_point);
987 }
989
990 struct {
991 Vector<float3> starts;
992 Vector<float3> ends;
993 } connection_lines;
994 /* Circles which can be kept because they generate no extension lines. */
995 Vector<int> keep_circle_indices;
996 keep_circle_indices.reserve(circles_range.size());
997
998 for (const int point_i : circles_range.index_range()) {
999 const int kd_index = circles_range[point_i];
1000 const float2 center = view_centers[kd_index];
1001 const float radius = view_radii[kd_index];
1002
1003 bool found = false;
1005 kdtree,
1006 center,
1007 radius,
1008 [&](const int other_point_i, const float2 & /*co*/, float /*dist_sq*/) {
1009 if (other_point_i == kd_index) {
1010 return true;
1011 }
1012
1013 found = true;
1014 connection_lines.starts.append(extension_data.circles.centers[point_i]);
1015 if (circles_range.contains(other_point_i)) {
1016 connection_lines.ends.append(extension_data.circles.centers[other_point_i]);
1017 }
1018 else if (feature_points_range.contains(other_point_i)) {
1019 /* TODO copy feature point to connection_lines (beware of start index!). */
1020 connection_lines.ends.append(float3(0));
1021 }
1022 else {
1024 }
1025 return true;
1026 });
1027 /* Keep the circle if no extension line was found. */
1028 if (!found) {
1029 keep_circle_indices.append(point_i);
1030 }
1031 }
1032
1034
1035 /* Add new extension lines. */
1036 extension_data.lines.starts.extend(connection_lines.starts);
1037 extension_data.lines.ends.extend(connection_lines.ends);
1038 /* Remove circles that formed extension lines. */
1039 Vector<float3> old_centers = std::move(extension_data.circles.centers);
1040 Vector<float> old_radii = std::move(extension_data.circles.radii);
1041 extension_data.circles.centers.resize(keep_circle_indices.size());
1042 extension_data.circles.radii.resize(keep_circle_indices.size());
1043 array_utils::gather(old_centers.as_span(),
1044 keep_circle_indices.as_span(),
1045 extension_data.circles.centers.as_mutable_span());
1046 array_utils::gather(old_radii.as_span(),
1047 keep_circle_indices.as_span(),
1048 extension_data.circles.radii.as_mutable_span());
1049}
1050
1052 const bContext &C, const GreasePencilFillOpData &op_data)
1053{
1054 const Scene &scene = *CTX_data_scene(&C);
1055 const Object &object = *CTX_data_active_object(&C);
1056 const GreasePencil &grease_pencil = *id_cast<const GreasePencil *>(object.data);
1057
1060
1061 ed::greasepencil::ExtensionData extension_data;
1062 Vector<int> origin_points;
1063 Vector<int> origin_drawings;
1064 for (const int i_drawing : drawings.index_range()) {
1065 const ed::greasepencil::DrawingInfo &info = drawings[i_drawing];
1066 const bke::CurvesGeometry &curves = info.drawing.strokes();
1067 const OffsetIndices points_by_curve = curves.points_by_curve();
1068 const Span<float3> positions = curves.positions();
1069 const VArray<float> radii = info.drawing.radii();
1070 const VArray<bool> cyclic = curves.cyclic();
1071 const float4x4 layer_to_world = grease_pencil.layer(info.layer_index).to_world_space(object);
1072
1073 for (const int i_curve : curves.curves_range()) {
1074 const IndexRange points = points_by_curve[i_curve];
1075 /* No extension lines on cyclic curves. */
1076 if (cyclic[i_curve]) {
1077 continue;
1078 }
1079 /* Can't compute directions for single-point curves. */
1080 if (points.size() < 2) {
1081 continue;
1082 }
1083
1084 const float3 pos_head = math::transform_point(layer_to_world, positions[points[0]]);
1085 const float3 pos_tail = math::transform_point(layer_to_world, positions[points.last()]);
1086 const float3 pos_head_next = math::transform_point(layer_to_world, positions[points[1]]);
1087 const float3 pos_tail_prev = math::transform_point(layer_to_world,
1088 positions[points.last(1)]);
1089 const float3 dir_head = math::normalize(pos_head - pos_head_next);
1090 const float3 dir_tail = math::normalize(pos_tail - pos_tail_prev);
1091 /* Initial length before intersection tests. */
1092 const float length = op_data.extension_length;
1093
1094 switch (op_data.extension_mode) {
1095 case GP_FILL_EMODE_EXTEND: {
1096 extension_data.lines.starts.append(pos_head);
1097 extension_data.lines.ends.append(pos_head + dir_head * length);
1098 origin_drawings.append(i_drawing);
1099 origin_points.append(points.first());
1100
1101 extension_data.lines.starts.append(pos_tail);
1102 extension_data.lines.ends.append(pos_tail + dir_tail * length);
1103 origin_drawings.append(i_drawing);
1104 /* Segment index is the start point. */
1105 origin_points.append(points.last() - 1);
1106
1107 /* Find points of high curvature and extend them. */
1108 float3 pos_prev = math::transform_point(layer_to_world, positions[points[0]]);
1109 float3 pos_next = math::transform_point(layer_to_world, positions[points[1]]);
1110 float distance_prev;
1111 float distance_next;
1112 float3 tangent_prev;
1113 float3 tangent_next = math::normalize_and_get_length(pos_next - pos_prev, distance_next);
1114 for (const int i : points.index_range().drop_front(2)) {
1115 tangent_prev = tangent_next;
1116 distance_prev = distance_next;
1117 pos_prev = pos_next;
1118
1119 pos_next = math::transform_point(layer_to_world, positions[points[i]]);
1120 tangent_next = math::normalize_and_get_length(pos_next - pos_prev, distance_next);
1121
1122 float curvature_length;
1123 const float3 curvature = math::normalize_and_get_length(tangent_next - tangent_prev,
1124 curvature_length);
1125
1126 /*
1127 * The smaller the radius of curvature, the sharper the corner.
1128 * The thicker the line, the larger the radius of curvature it
1129 * takes to be visually indistinguishable from an endpoint.
1130 */
1131 const float stroke_radius = radii[points[i - 1]];
1132 const float min_radius = stroke_radius;
1133
1134 /*
1135 * Is the radius of curvature (1 / curvature_length) smaller than the
1136 * minimum radius? Rearranged algebraically to avoid division by zero.
1137 */
1138 if (distance_prev + distance_next < 2.0f * curvature_length * min_radius) {
1139 /* Extend along direction of curvature. */
1140 extension_data.lines.starts.append(pos_prev);
1141 extension_data.lines.ends.append(pos_prev + (-curvature * length));
1142 origin_drawings.append(i_drawing);
1143 origin_points.append(points[i - 1]);
1144 }
1145 }
1146 break;
1147 }
1149 extension_data.circles.centers.append(pos_head);
1150 extension_data.circles.radii.append(length);
1151 origin_drawings.append(i_drawing);
1152 origin_points.append(points.first());
1153
1154 extension_data.circles.centers.append(pos_tail);
1155 extension_data.circles.radii.append(length);
1156 origin_drawings.append(i_drawing);
1157 /* Segment index is the start point. */
1158 origin_points.append(points.last() - 1);
1159 break;
1160 }
1161 }
1162 }
1163
1164 switch (op_data.extension_mode) {
1166 /* Intersection test against strokes and other extension lines. */
1167 if (op_data.extension_cut) {
1168 grease_pencil_fill_extension_cut(C, extension_data, origin_drawings, origin_points);
1169 }
1170 break;
1173 C, extension_data, origin_drawings, origin_points);
1174 break;
1175 }
1176
1177 return extension_data;
1178}
1179
1181 const GreasePencilFillOpData &op_data)
1182{
1183 const bool is_extend = (op_data.extension_mode == GP_FILL_EMODE_EXTEND);
1184
1185 WorkspaceStatus status(&C);
1186 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
1187 status.item(IFACE_("Fill"), ICON_MOUSE_LMB);
1188
1189 if (!op_data.is_delaunay_method) {
1190 status.item(
1191 fmt::format("{} ({})", IFACE_("Mode"), (is_extend ? IFACE_("Extend") : IFACE_("Radius"))),
1192 ICON_EVENT_S);
1193 status.item(fmt::format("{} ({:.3f})",
1194 is_extend ? IFACE_("Length") : IFACE_("Radius"),
1195 op_data.extension_length),
1196 ICON_MOUSE_MMB_SCROLL);
1197 if (is_extend) {
1198 status.item_bool(IFACE_("Collision"), op_data.extension_cut, ICON_EVENT_D);
1199 }
1200 }
1201}
1202
1204 const GreasePencilFillOpData &op_data)
1205{
1206 const ARegion &region = *CTX_wm_region(&C);
1207 const RegionView3D &rv3d = *CTX_wm_region_view3d(&C);
1208 const Scene &scene = *CTX_data_scene(&C);
1209 const Object &object = *CTX_data_active_object(&C);
1210 const GreasePencil &grease_pencil = *id_cast<const GreasePencil *>(object.data);
1211
1212 const float4x4 world_to_view = float4x4(rv3d.viewmat);
1213 /* Note: The initial view matrix is already set, clear to draw in view space. */
1215
1216 const ColorGeometry4f stroke_curves_color = ColorGeometry4f(1, 0, 0, 1);
1217 const ColorGeometry4f extension_lines_color = ColorGeometry4f(0, 1, 1, 1);
1218 const ColorGeometry4f extension_circles_color = ColorGeometry4f(1, 0.5, 0, 1);
1219
1222
1223 if (op_data.show_boundaries) {
1226
1227 for (const ed::greasepencil::DrawingInfo &info : drawings) {
1228 const IndexMask curve_mask = info.drawing.strokes().curves_range();
1230 stroke_curves_color, info.drawing.strokes().points_num());
1231 const float4x4 layer_to_world = grease_pencil.layer(info.layer_index).to_world_space(object);
1232 const bool use_xray = false;
1233 const float radius_scale = 1.0f;
1234
1236 int2(region.winx, region.winy),
1237 object,
1238 info.drawing,
1239 layer_to_world,
1240 curve_mask,
1241 colors,
1242 use_xray,
1243 radius_scale);
1244 }
1245 }
1246
1247 if (op_data.show_extension) {
1249 C, op_data);
1250
1251 const float line_width = 2.0f;
1252
1253 const IndexRange lines_range = extensions.lines.starts.index_range();
1254 if (!lines_range.is_empty()) {
1256 extension_lines_color, lines_range.size());
1257
1259 lines_range,
1260 extensions.lines.starts,
1261 extensions.lines.ends,
1262 line_colors,
1263 line_width);
1264 }
1265 const IndexRange circles_range = extensions.circles.centers.index_range();
1266 if (!circles_range.is_empty()) {
1268 extension_circles_color, circles_range.size());
1269
1271 world_to_view,
1272 circles_range,
1273 extensions.circles.centers,
1274 VArray<float>::from_span(extensions.circles.radii),
1275 circle_colors,
1276 float2(region.winx, region.winy),
1277 line_width,
1278 false);
1279 }
1280 }
1281}
1282
1284 const GreasePencilFillOpData &op_data)
1285{
1286 const ARegion &region = *CTX_wm_region(&C);
1287 const RegionView3D &rv3d = *CTX_wm_region_view3d(&C);
1288 const View3D &view3d = *CTX_wm_view3d(&C);
1289 const ToolSettings &ts = *CTX_data_tool_settings(&C);
1290 Main &bmain = *CTX_data_main(&C);
1291 Object &object = *CTX_data_active_object(&C);
1292 Paint &paint = ts.gp_paint->paint;
1294
1295 const float4x4 world_to_view = float4x4(rv3d.viewmat);
1296 /* Note: The initial view matrix is already set, clear to draw in view space. */
1298
1299 float4 color;
1302 }
1303 else {
1305 &bmain, &object, &brush);
1306 color = float4(material->gp_style->fill_rgba);
1307 }
1308
1309 const float line_width = 2.0f;
1310
1311 Array<float3> line_positions(op_data.mouse_positions.size());
1312
1314 op_data.mouse_positions.index_range(), 8192, [&](const IndexRange range) {
1315 for (const int64_t point_i : range) {
1316 const float2 co = op_data.mouse_positions[point_i];
1317
1318 ED_view3d_win_to_3d(&view3d, &region, float3(0.0f), co, line_positions[point_i]);
1319 }
1320 });
1321
1322 if (line_positions.size() < 2) {
1323 return;
1324 }
1325
1327 ColorGeometry4f(color), line_positions.size());
1328
1330 world_to_view, line_positions.index_range(), line_positions, line_colors, false, line_width);
1331}
1332
1333/* Draw callback for fill tool overlay. */
1334static void grease_pencil_fill_overlay_cb(const bContext *C, ARegion * /*region*/, void *arg)
1335{
1336 auto &op_data = *static_cast<GreasePencilFillOpData *>(arg);
1337
1338 if (op_data.is_delaunay_method) {
1340 }
1341 else {
1343 }
1344}
1345
1347 GreasePencilFillOpData &op_data)
1348{
1349 const bool needs_overlay = op_data.show_boundaries || op_data.show_extension ||
1350 op_data.is_delaunay_method;
1351
1352 if (needs_overlay) {
1353 if (op_data.overlay_cb_handle == nullptr) {
1356 }
1357 }
1358 else {
1359 if (op_data.overlay_cb_handle) {
1361 op_data.overlay_cb_handle = nullptr;
1362 }
1363 }
1364}
1365
1372
1373/* Layer mode defines layers where only marked boundary strokes are used. */
1375 eGP_FillLayerModes fill_layer_mode)
1376{
1377 BLI_assert(grease_pencil.has_active_layer());
1378 const IndexRange all_layers = grease_pencil.layers().index_range();
1379 const int active_layer_index = *grease_pencil.get_layer_index(*grease_pencil.get_active_layer());
1380
1381 switch (fill_layer_mode) {
1383 return VArray<bool>::from_std_func(all_layers.size(), [active_layer_index](const int index) {
1384 return index != active_layer_index;
1385 });
1387 return VArray<bool>::from_std_func(all_layers.size(), [active_layer_index](const int index) {
1388 return index != active_layer_index + 1;
1389 });
1391 return VArray<bool>::from_std_func(all_layers.size(), [active_layer_index](const int index) {
1392 return index != active_layer_index - 1;
1393 });
1395 return VArray<bool>::from_std_func(all_layers.size(), [active_layer_index](const int index) {
1396 return index <= active_layer_index;
1397 });
1399 return VArray<bool>::from_std_func(all_layers.size(), [active_layer_index](const int index) {
1400 return index >= active_layer_index;
1401 });
1403 return VArray<bool>::from_std_func(all_layers.size(), [grease_pencil](const int index) {
1404 return !grease_pencil.layers()[index]->is_visible();
1405 });
1406 }
1407 return {};
1408}
1409
1410/* Array of visible drawings to use as borders for generating a stroke in the editable drawing on
1411 * the active layer. This is provided for every frame in the multi-frame edit range. */
1415 /* Used for removing newly created (auto)keyframes again in case the tool does not create fills
1416 * and thus makes no changes. */
1417 bool is_new_keyframe = false;
1418};
1419
1422 bke::greasepencil::Layer &target_layer)
1423{
1424 using namespace bke::greasepencil;
1427
1428 const ToolSettings *toolsettings = scene.toolsettings;
1429 const bool use_multi_frame_editing = (toolsettings->gpencil_flags &
1431 const bool use_autokey = animrig::is_autokey_on(&scene);
1432 const bool use_duplicate_frame = (scene.toolsettings->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST);
1433 const int target_layer_index = *grease_pencil.get_layer_index(target_layer);
1434
1435 VectorSet<int> target_frames;
1436 VectorSet<int> new_keyframes;
1437 /* Add drawing on the current frame. */
1438 target_frames.add(scene.r.cfra);
1439 /* Multi-frame edit: Add drawing on frames that are selected in any layer. */
1440 if (use_multi_frame_editing) {
1441 for (const Layer *layer : grease_pencil.layers()) {
1442 for (const auto [frame_number, frame] : layer->frames().items()) {
1443 if (frame.is_selected()) {
1444 target_frames.add(frame_number);
1445 }
1446 }
1447 }
1448 }
1449
1450 /* Create new drawings when autokey is enabled. */
1451 if (use_autokey) {
1452 for (const int frame_number : target_frames) {
1453 if (!target_layer.frames().contains(frame_number)) {
1454 if (use_duplicate_frame) {
1455 if (grease_pencil.insert_duplicate_frame(
1456 target_layer, *target_layer.start_frame_at(frame_number), frame_number, false))
1457 {
1458 new_keyframes.add(frame_number);
1459 }
1460 }
1461 else {
1462 if (grease_pencil.insert_frame(target_layer, frame_number)) {
1463 new_keyframes.add(frame_number);
1464 }
1465 }
1466 }
1467 }
1468 }
1469
1471 for (const int frame_number : target_frames) {
1472 if (Drawing *target_drawing = grease_pencil.get_editable_drawing_at(target_layer,
1473 frame_number))
1474 {
1475 MutableDrawingInfo target = {*target_drawing, target_layer_index, frame_number, 1.0f};
1476
1477 Vector<DrawingInfo> sources;
1478 for (const Layer *source_layer : grease_pencil.layers()) {
1479 if (const Drawing *source_drawing = grease_pencil.get_drawing_at(*source_layer,
1480 frame_number))
1481 {
1482 const int source_layer_index = *grease_pencil.get_layer_index(*source_layer);
1483 sources.append({*source_drawing, source_layer_index, frame_number, 0});
1484 }
1485 }
1486
1487 const bool is_new_keyframe = new_keyframes.contains(frame_number);
1488 drawings.append({std::move(target), std::move(sources), is_new_keyframe});
1489 }
1490 }
1491
1492 return drawings;
1493}
1494
1496{
1497 const int iterations = 20;
1498 if (curves.is_empty()) {
1499 return;
1500 }
1501 if (stroke_mask.is_empty()) {
1502 return;
1503 }
1504
1505 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
1506 const OffsetIndices points_by_curve = curves.points_by_curve();
1507 const VArray<bool> cyclic = curves.cyclic();
1508 const VArray<bool> point_selection = VArray<bool>::from_single(true, curves.points_num());
1509
1510 bke::GSpanAttributeWriter positions = attributes.lookup_for_write_span("position");
1512 points_by_curve,
1513 point_selection,
1514 cyclic,
1515 iterations,
1516 1.0f,
1517 false,
1518 true,
1519 positions.span);
1520 positions.finish();
1521 curves.tag_positions_changed();
1522}
1523
1525{
1526 const OffsetIndices points_by_curve = curves.points_by_curve();
1527 const Array<int> point_to_curve_map = curves.point_to_curve_map();
1528
1529 IndexMaskMemory memory;
1530 IndexMask points_to_keep = IndexMask::from_predicate(
1531 curves.points_range(), memory, [&](const int64_t i) {
1532 const int curve_i = point_to_curve_map[i];
1533 const IndexRange points = points_by_curve[curve_i];
1534 if (points.size() <= 2) {
1535 return true;
1536 }
1537 const int local_i = i - points.start();
1538 return (local_i % int(math::pow(2.0f, float(step))) == 0) || points.last() == i;
1539 });
1540
1541 return bke::curves_copy_point_selection(curves, points_to_keep, {});
1542}
1543
1545 const ViewContext &view_context,
1546 const Paint &paint,
1547 const Brush &brush,
1548 const Scene &scene,
1549 const float4x4 &to_world,
1550 const int material_index,
1551 const float hardness)
1552{
1553 /* Attributes that are defined explicitly and should not be set to default values. */
1554 Set<std::string> skip_curve_attributes = {
1555 "curve_type", "material_index", "cyclic", "hardness", "fill_opacity"};
1556 Set<std::string> skip_point_attributes = {"position", "radius", "opacity"};
1557
1558 bke::MutableAttributeAccessor attributes = fill_curves.attributes_for_write();
1559 const Span<float3> positions = fill_curves.positions();
1564
1565 for (const int point_i : fill_curves.points_range()) {
1566 /* Calculate radius and opacity for the outline as if it was a user stroke with full
1567 * pressure. */
1568 const float pressure = 1.0f;
1569 radii.span[point_i] = ed::greasepencil::radius_from_input_sample(view_context.rv3d,
1570 view_context.region,
1571 paint,
1572 &brush,
1573 pressure,
1574 positions[point_i],
1575 to_world,
1576 brush.gpencil_settings);
1577 opacities.span[point_i] = ed::greasepencil::opacity_from_input_sample(
1578 pressure, paint, &brush, brush.gpencil_settings);
1579 }
1580
1581 radii.finish();
1582 opacities.finish();
1583
1584 attributes.add<int>(
1585 "material_index", bke::AttrDomain::Curve, bke::AttributeInitValue(material_index));
1586 attributes.add<bool>("cyclic", bke::AttrDomain::Curve, bke::AttributeInitValue(true));
1587 attributes.add<float>("hardness", bke::AttrDomain::Curve, bke::AttributeInitValue(hardness));
1588 /* TODO: `fill_opacities` are currently always 1.0f for the new strokes. Maybe this should be a
1589 * parameter. */
1590 attributes.add<float>("fill_opacity", bke::AttrDomain::Curve, bke::AttributeInitValue(1.0f));
1591
1593 scene.toolsettings->gp_paint, &brush);
1594 if (use_vertex_color) {
1595 ColorGeometry4f vertex_color;
1596 copy_v3_v3(vertex_color, BKE_brush_color_get(&paint, &brush));
1597 vertex_color.a = brush.gpencil_settings->vertex_factor;
1598
1599 skip_curve_attributes.add("fill_color");
1601 attributes.lookup_or_add_for_write_span<ColorGeometry4f>("fill_color",
1603 fill_colors.span.fill(vertex_color);
1604 fill_colors.finish();
1605
1606 if (brush.gpencil_settings->flag2 & GP_BRUSH_USE_STROKE) {
1607 skip_point_attributes.add("vertex_color");
1609 attributes.lookup_or_add_for_write_span<ColorGeometry4f>("vertex_color",
1611 vertex_colors.span.fill(vertex_color);
1612 vertex_colors.finish();
1613 }
1614 }
1615
1616 /* Initialize the rest of the attributes with default values. */
1619 bke::attribute_filter_from_skip_ref(skip_curve_attributes),
1620 fill_curves.curves_range());
1623 bke::attribute_filter_from_skip_ref(skip_point_attributes),
1624 fill_curves.points_range());
1625}
1626
1627static bool grease_pencil_apply_fill(bContext &C, wmOperator &op, const wmEvent &event)
1628{
1632
1633 constexpr const ed::greasepencil::FillToolFitMethod fit_method =
1635 /* Debug setting: keep image data blocks for inspection. */
1636 constexpr const bool keep_images = false;
1637
1638 ARegion &region = *CTX_wm_region(&C);
1639 /* Perform bounds check. */
1640 const bool in_bounds = BLI_rcti_isect_pt_v(&region.winrct, event.xy);
1641 if (!in_bounds) {
1642 return false;
1643 }
1644
1645 wmWindow &win = *CTX_wm_window(&C);
1647 const Scene &scene = *CTX_data_scene(&C);
1648 Object &object = *CTX_data_active_object(&C);
1649 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object.data);
1650 auto &op_data = *static_cast<GreasePencilFillOpData *>(op.customdata);
1651 const ToolSettings &ts = *CTX_data_tool_settings(&C);
1652 Paint &paint = ts.gp_paint->paint;
1654 const float2 mouse_position = float2(event.mval);
1655 const int simplify_levels = brush.gpencil_settings->fill_simplylvl;
1656 const std::optional<float> opacity_threshold =
1657 (brush.gpencil_settings->flag & GP_BRUSH_FILL_HIDE) ?
1658 std::nullopt :
1659 std::make_optional(brush.gpencil_settings->fill_threshold);
1660 const bool on_back = (ts.gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK);
1661 const bool auto_remove_fill_guides = (brush.gpencil_settings->flag &
1663 const bool is_delaunay_method = brush.gpencil_settings->fill_solver == GP_FILL_SOLVER_DELAUNAY;
1664
1665 if (!grease_pencil.has_active_layer()) {
1666 return false;
1667 }
1668 /* Add drawings in the active layer if autokey is enabled. */
1670 scene, grease_pencil, *grease_pencil.get_active_layer());
1671
1672 const VArray<bool> boundary_layers = get_fill_boundary_layers(
1673 grease_pencil, eGP_FillLayerModes(brush.gpencil_settings->fill_layer_mode));
1674
1675 bool did_create_fill = false;
1676 for (const FillToolTargetInfo &info : target_drawings) {
1677 const Layer &layer = *grease_pencil.layers()[info.target.layer_index];
1678
1679 std::optional<bke::CurvesGeometry> op_fill_curves;
1680
1681 if (!is_delaunay_method) {
1683 C, op_data);
1684
1685 op_fill_curves = std::make_optional(pixel_fill_strokes(view_context,
1686 brush,
1687 scene,
1688 layer,
1689 boundary_layers,
1690 info.sources,
1691 op_data.invert,
1692 opacity_threshold,
1693 mouse_position,
1694 extensions,
1695 fit_method,
1696 keep_images));
1697 }
1698 else {
1699 /* Take the full mouse path. */
1700 const Array<int> fill_point_offset = {0, int(op_data.mouse_positions.size())};
1701 const GroupedSpan<float2> fill_points = GroupedSpan<float2>(
1702 OffsetIndices<int>(fill_point_offset), op_data.mouse_positions);
1703
1704 const bool internal_gaps = (brush.gpencil_settings->flag & GP_BRUSH_FILL_INTERNAL_GAPS) != 0;
1705 const float gap_factor = brush.gpencil_settings->fill_gap_factor;
1706
1707 op_fill_curves = delaunay_fill_strokes(view_context,
1708 scene,
1709 layer,
1710 boundary_layers,
1711 info.sources,
1712 op_data.invert,
1713 opacity_threshold,
1714 internal_gaps,
1715 gap_factor,
1716 fill_points);
1717 }
1718
1719 if (!op_fill_curves) {
1720 continue;
1721 }
1722
1723 bke::CurvesGeometry &fill_curves = *op_fill_curves;
1724
1725 /* TODO should use the same hardness as the paint brush. */
1726 const float stroke_hardness = 1.0f;
1727
1728 set_fill_attributes(fill_curves,
1729 view_context,
1730 paint,
1731 brush,
1732 scene,
1733 layer.to_world_space(object),
1734 op_data.material_index,
1735 stroke_hardness);
1736
1737 if (fill_curves.is_empty()) {
1738 continue;
1739 }
1740
1741 bke::MutableAttributeAccessor attributes = fill_curves.attributes_for_write();
1742
1743 /* Combine strokes into a single fill with the same fill ID. */
1744 attributes.add<int>("fill_id", bke::AttrDomain::Curve, bke::AttributeInitValue(1));
1745
1746 /* Only create fills. Users can change the appearance however they please afterwards. */
1747 attributes.add<bool>("hide_stroke", bke::AttrDomain::Curve, bke::AttributeInitValue(true));
1748
1749 if (!is_delaunay_method) {
1750 smooth_fill_strokes(fill_curves, fill_curves.curves_range());
1751
1752 if (simplify_levels > 0) {
1753 fill_curves = simplify_fixed(fill_curves, brush.gpencil_settings->fill_simplylvl);
1754 }
1755 }
1756
1757 bke::CurvesGeometry &dst_curves = info.target.drawing.strokes_for_write();
1758 if (auto_remove_fill_guides) {
1759 /* Remove strokes that were created using the fill tool as boundary strokes. */
1761 }
1762
1763 /* If the `fill_strokes` function creates the "fill_opacity" attribute, make sure that we
1764 * initialize this to full opacity on the target geometry. */
1765 if (fill_curves.attributes().contains("fill_opacity") &&
1766 !dst_curves.attributes().contains("fill_opacity"))
1767 {
1768 bke::SpanAttributeWriter<float> fill_opacities =
1770 "fill_opacity", bke::AttrDomain::Curve, bke::AttributeInitValue(1.0f));
1771 fill_opacities.finish();
1772 }
1773
1774 Curves *dst_curves_id = curves_new_nomain(dst_curves);
1775 Curves *fill_curves_id = curves_new_nomain(fill_curves);
1776 const Array<bke::GeometrySet> geometry_sets = {
1777 bke::GeometrySet::from_curves(on_back ? fill_curves_id : dst_curves_id),
1778 bke::GeometrySet::from_curves(on_back ? dst_curves_id : fill_curves_id)};
1779 const int num_new_curves = fill_curves.curves_num();
1780 const IndexRange new_curves_range = (on_back ?
1781 IndexRange(num_new_curves) :
1782 dst_curves.curves_range().after(num_new_curves));
1783
1784 bke::GeometrySet joined_geometry_set = geometry::join_geometries(geometry_sets, {});
1785 if (joined_geometry_set.has_curves()) {
1786 dst_curves = joined_geometry_set.get_curves_for_write()->geometry.wrap();
1787 info.target.drawing.tag_topology_changed();
1788
1789 /* Compute texture matrix for the new curves. */
1790 const ed::greasepencil::DrawingPlacement placement(
1791 scene, region, *view_context.v3d, object, &layer);
1793 &scene, &region, mouse_position, placement);
1794 Array<float4x2> texture_matrices(num_new_curves, texture_space);
1795 info.target.drawing.set_texture_matrices(texture_matrices, new_curves_range);
1796 }
1797
1798 did_create_fill = true;
1799 }
1800
1801 if (!did_create_fill) {
1802 /* Remove newly created keyframes again. */
1803 for (const FillToolTargetInfo &info : target_drawings) {
1804 if (info.is_new_keyframe) {
1805 Layer &layer = *grease_pencil.layers_for_write()[info.target.layer_index];
1806 grease_pencil.remove_frames(layer, {info.target.frame_number});
1807 }
1808 }
1809 BKE_report(op.reports, RPT_ERROR, "No fill created");
1810 }
1811
1813
1814 /* Save extend value for next operation. */
1815 brush.gpencil_settings->fill_extend_fac = op_data.extension_length /
1818
1819 return true;
1820}
1821
1823{
1825
1826 Main &bmain = *CTX_data_main(&C);
1827 Scene &scene = *CTX_data_scene(&C);
1829 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob.data);
1832
1833 Layer *layer = grease_pencil.get_active_layer();
1834 /* Cannot paint in locked layer. */
1835 if (layer && layer->is_locked()) {
1836 return false;
1837 }
1838 if (layer == nullptr) {
1839 layer = &grease_pencil.add_layer("GP_Layer");
1840 }
1841
1842 if (brush.gpencil_settings == nullptr) {
1844 }
1845 BKE_curvemapping_init(brush.gpencil_settings->curve_sensitivity);
1846 BKE_curvemapping_init(brush.gpencil_settings->curve_strength);
1847 BKE_curvemapping_init(brush.gpencil_settings->curve_jitter);
1848 BKE_curvemapping_init(brush.gpencil_settings->curve_rand_pressure);
1849 BKE_curvemapping_init(brush.gpencil_settings->curve_rand_strength);
1850 BKE_curvemapping_init(brush.gpencil_settings->curve_rand_uv);
1851 BKE_curvemapping_init(brush.curve_rand_hue);
1852 BKE_curvemapping_init(brush.curve_rand_saturation);
1853 BKE_curvemapping_init(brush.curve_rand_value);
1854
1856 const int material_index = BKE_object_material_index_get(&ob, material);
1857 if (material->gp_style->fill_rgba[3] == 0.0f) {
1858 BKE_report(op.reports, RPT_WARNING, "Fill is fully transparent");
1859 }
1860
1861 const bool invert = RNA_boolean_get(op.ptr, "invert");
1862 const bool precision = RNA_boolean_get(op.ptr, "precision");
1863
1864 op.customdata = MEM_new<GreasePencilFillOpData>(
1865 __func__,
1866 GreasePencilFillOpData::from_context(C, *layer, material_index, invert, precision));
1867 return true;
1868}
1869
1871{
1872 const ARegion &region = *CTX_wm_region(&C);
1874 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob.data);
1875
1877
1878 if (op.customdata) {
1879 auto &op_data = *static_cast<GreasePencilFillOpData *>(op.customdata);
1880
1881 if (op_data.overlay_cb_handle) {
1882 ED_region_draw_cb_exit(region.runtime->type, op_data.overlay_cb_handle);
1883 op_data.overlay_cb_handle = nullptr;
1884 }
1885
1886 MEM_delete(static_cast<GreasePencilFillOpData *>(op.customdata));
1887 op.customdata = nullptr;
1888 }
1889
1890 /* Clear status message area. */
1891 ED_workspace_status_text(&C, nullptr);
1892
1894
1897}
1898
1900 wmOperator *op,
1901 const wmEvent * /*event*/)
1902{
1903 const ARegion &region = *CTX_wm_region(C);
1907 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob.data);
1908
1909 /* Fill tool needs a material (cannot use default material). */
1910 if ((brush.gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) &&
1911 brush.gpencil_settings->material == nullptr)
1912 {
1913 BKE_report(op->reports, RPT_ERROR, "Fill tool needs active material");
1914 return OPERATOR_CANCELLED;
1915 }
1916 if (BKE_object_material_get(&ob, ob.actcol) == nullptr) {
1917 BKE_report(op->reports, RPT_ERROR, "Fill tool needs active material");
1918 return OPERATOR_CANCELLED;
1919 }
1922 {
1923 BKE_report(op->reports, RPT_ERROR, "Cannot create new material on linked object");
1924 return OPERATOR_CANCELLED;
1925 }
1926 if (!grease_pencil_fill_init(*C, *op)) {
1928 return OPERATOR_CANCELLED;
1929 }
1930 auto &op_data = *static_cast<GreasePencilFillOpData *>(op->customdata);
1931
1934 grease_pencil_fill_update_overlay(region, op_data);
1935
1938
1939 /* Add a modal handler for this operator. */
1941
1943}
1944
1956
1958 wmOperator *op,
1959 const wmEvent *event)
1960{
1961 auto &op_data = *static_cast<GreasePencilFillOpData *>(op->customdata);
1962 /* Extension line length increment, for normal and precise mode respectively. */
1963 const float extension_delta = (op_data.precision ? 0.002f : 0.02f);
1964
1965 switch (event->val) {
1966 case int(FillToolModalKey::Cancel):
1967 return OPERATOR_CANCELLED;
1968
1969 case int(FillToolModalKey::Confirm): {
1970 /* Ignore in extension mode. */
1971 if (op_data.is_extension_drag_active) {
1972 break;
1973 }
1974
1975 op_data.fill_mouse_pos = float2(event->mval);
1977 }
1978
1980 if (op_data.show_extension) {
1981 /* Toggle mode. */
1982 if (op_data.extension_mode == GP_FILL_EMODE_EXTEND) {
1983 op_data.extension_mode = GP_FILL_EMODE_RADIUS;
1984 }
1985 else {
1986 op_data.extension_mode = GP_FILL_EMODE_EXTEND;
1987 }
1988 grease_pencil_update_extend(*C, op_data);
1989 }
1990 break;
1991
1993 op_data.extension_length = op_data.extension_length + extension_delta;
1994 grease_pencil_update_extend(*C, op_data);
1995 break;
1996
1998 op_data.extension_length = std::max(op_data.extension_length - extension_delta, 0.0f);
1999 grease_pencil_update_extend(*C, op_data);
2000 break;
2001
2003 if (event->val == KM_PRESS) {
2004 /* Consider initial offset as zero position. */
2005 op_data.is_extension_drag_active = true;
2006 /* TODO This is the GPv2 logic and it's weird. Should be reconsidered, for now use the
2007 * same method. */
2008 const float2 base_pos = float2(event->mval);
2009 constexpr const float gap = 300.0f;
2010 op_data.extension_mouse_pos = (math::distance(base_pos, op_data.fill_mouse_pos) >= gap ?
2011 base_pos :
2012 base_pos - float2(gap, 0));
2014 }
2015 if (event->val == KM_RELEASE) {
2017 op_data.is_extension_drag_active = false;
2018 }
2019 /* Update cursor line. */
2022 break;
2023 }
2024
2026 if (op_data.show_extension) {
2027 op_data.extension_cut = !op_data.extension_cut;
2028 grease_pencil_update_extend(*C, op_data);
2029 }
2030 break;
2031
2032 case int(FillToolModalKey::Invert):
2033 op_data.invert = !op_data.invert;
2034 break;
2035
2037 op_data.precision = !op_data.precision;
2038 break;
2039
2040 default:
2042 break;
2043 }
2045}
2046
2048{
2049 const RegionView3D &rv3d = *CTX_wm_region_view3d(C);
2050
2051 auto &op_data = *static_cast<GreasePencilFillOpData *>(op->customdata);
2052
2054 if (op_data.is_delaunay_method) {
2055 op_data.mouse_positions.append(float2(event->mval));
2056 estate = OPERATOR_RUNNING_MODAL;
2057
2058 grease_pencil_update_extend(*C, op_data);
2059
2060 if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
2061 if (grease_pencil_apply_fill(*C, *op, *event)) {
2062 estate = OPERATOR_FINISHED;
2063 }
2064 else {
2065 estate = OPERATOR_CANCELLED;
2066 }
2067 }
2068 }
2069 else {
2070 if (!op_data.show_extension) {
2071 /* Apply fill immediately if "Visual Aids" (aka. extension lines) is disabled. */
2072 op_data.fill_mouse_pos = float2(event->mval);
2073 if (grease_pencil_apply_fill(*C, *op, *event)) {
2074 estate = OPERATOR_FINISHED;
2075 }
2076 else {
2077 estate = OPERATOR_CANCELLED;
2078 }
2079 }
2080 else {
2081 estate = OPERATOR_RUNNING_MODAL;
2082 switch (event->type) {
2083 case EVT_MODAL_MAP:
2084 estate = grease_pencil_fill_event_modal_map(C, op, event);
2085 break;
2086 case MOUSEMOVE: {
2087 if (!op_data.is_extension_drag_active) {
2088 break;
2089 }
2090
2091 const Object &ob = *CTX_data_active_object(C);
2092 const float pixel_size = ED_view3d_pixel_size(&rv3d, ob.loc);
2093 const float2 mouse_pos = float2(event->mval);
2094 const float initial_dist = math::distance(op_data.extension_mouse_pos,
2095 op_data.fill_mouse_pos);
2096 const float current_dist = math::distance(mouse_pos, op_data.fill_mouse_pos);
2097
2098 float delta = (current_dist - initial_dist) * pixel_size * 0.5f;
2099 op_data.extension_length = std::max(op_data.extension_length + delta, 0.0f);
2100
2101 /* Update cursor line and extend lines. */
2104
2105 grease_pencil_update_extend(*C, op_data);
2106 break;
2107 }
2108 default:
2109 break;
2110 }
2111 }
2112 }
2113
2114 /* Process last operations before exiting. */
2115 switch (estate) {
2116 case OPERATOR_FINISHED:
2119 break;
2120
2121 case OPERATOR_CANCELLED:
2123 break;
2124
2125 default:
2126 break;
2127 }
2128
2129 return estate;
2130}
2131
2133{
2135}
2136
2138{
2139 PropertyRNA *prop;
2140
2141 ot->name = "Grease Pencil Fill";
2142 ot->idname = "GREASE_PENCIL_OT_fill";
2143 ot->description = "Fill with color the shape formed by strokes";
2144
2149
2151
2152 prop = RNA_def_boolean(
2153 ot->srna, "invert", false, "Invert", "Find boundary of unfilled instead of filled regions");
2155
2156 prop = RNA_def_boolean(
2157 ot->srna, "precision", false, "Precision", "Use precision movement for extension lines");
2159}
2160
2161/* Ensure a drawing at the current frame up front. For erasing, we don't want the auto-key to
2162 * create an empty keyframe, so we duplicate the previous key. */
2164{
2165 const Scene *scene = CTX_data_scene(C);
2166
2167 if (bke::greasepencil::Layer *active_layer = grease_pencil.get_active_layer()) {
2168 bool inserted_keyframe = false;
2169 const bool use_duplicate_previous_key = true;
2170 if (active_layer->is_editable()) {
2172 *scene, grease_pencil, *active_layer, use_duplicate_previous_key, inserted_keyframe);
2173 }
2174 if (inserted_keyframe) {
2175 /* Select new keyframe (deselect others). */
2176 for (bke::greasepencil::Layer *layer : grease_pencil.layers_for_write()) {
2177 for (auto [frame_number, frame] : layer->frames_for_write().items()) {
2178 const bool select_keyframe = (frame_number == scene->r.cfra) && (layer == active_layer);
2179 SET_FLAG_FROM_TEST(frame.flag, select_keyframe, GP_FRAME_SELECTED);
2180 }
2181 }
2183 }
2184 }
2185}
2186
2189 const Span<IndexMask> points_to_remove_per_drawing)
2190{
2191 using namespace bke::greasepencil;
2192 using namespace ed::greasepencil;
2193 bool changed = false;
2194 for (const int drawing_i : drawings.index_range()) {
2195 const MutableDrawingInfo &info = drawings[drawing_i];
2196 const IndexMask points_to_remove = points_to_remove_per_drawing[drawing_i];
2197 if (points_to_remove.is_empty()) {
2198 continue;
2199 }
2200
2201 Drawing &drawing = info.drawing;
2203 drawing.strokes(), points_to_remove);
2204 drawing.tag_topology_changed();
2205 changed = true;
2206 }
2207
2208 return changed;
2209}
2210
2211static inline bool is_point_inside_bounds(const Bounds<int2> bounds, const int2 point)
2212{
2213 if (point.x < bounds.min.x) {
2214 return false;
2215 }
2216 if (point.x > bounds.max.x) {
2217 return false;
2218 }
2219 if (point.y < bounds.min.y) {
2220 return false;
2221 }
2222 if (point.y > bounds.max.y) {
2223 return false;
2224 }
2225 return true;
2226}
2227
2228static inline bool is_point_inside_lasso(const Array<int2> lasso, const int2 point)
2229{
2231 point, reinterpret_cast<const int (*)[2]>(lasso.data()), uint(lasso.size()));
2232}
2233
2235{
2236 using namespace bke::greasepencil;
2237 using namespace ed::greasepencil;
2238 const Scene *scene = CTX_data_scene(C);
2239 const Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
2240 const ARegion *region = CTX_wm_region(C);
2241 Object *object = CTX_data_active_object(C);
2242 const Object *ob_eval = DEG_get_evaluated(depsgraph, object);
2243 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
2244
2245 const Array<int2> lasso = WM_gesture_lasso_path_to_array(C, op);
2246 if (lasso.is_empty()) {
2247 return OPERATOR_FINISHED;
2248 }
2249
2250 const Bounds<int2> lasso_bounds_int = *bounds::min_max(lasso.as_span());
2251 const Bounds<float2> lasso_bounds(float2(lasso_bounds_int.min), float2(lasso_bounds_int.max));
2252
2254
2256 *scene, grease_pencil);
2257 Array<IndexMaskMemory> memories(drawings.size());
2258 Array<IndexMask> points_to_remove_per_drawing(drawings.size());
2259 threading::parallel_for(drawings.index_range(), 1, [&](const IndexRange range) {
2260 for (const int drawing_i : range) {
2261 const MutableDrawingInfo &info = drawings[drawing_i];
2262 const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
2263 const bke::crazyspace::GeometryDeformation deformation =
2264 bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
2265 ob_eval, *object, info.drawing);
2266 const float4x4 layer_to_world = layer.to_world_space(*ob_eval);
2267
2268 const bke::CurvesGeometry &curves = info.drawing.strokes();
2269 Array<float2> screen_space_positions(curves.points_num(), float2(0));
2270 IndexMaskMemory &memory = memories[drawing_i];
2271 const IndexMask editable_points = retrieve_editable_points(
2272 *object, info.drawing, info.layer_index, memory);
2273 editable_points.foreach_index(
2274 [&](const int point) {
2275 const float3 pos = math::transform_point(layer_to_world, deformation.positions[point]);
2276 ED_view3d_project_float_global(
2277 region, pos, screen_space_positions[point], V3D_PROJ_TEST_NOP);
2278 },
2279 exec_mode::grain_size(4096));
2280
2281 const IndexMask editable_strokes = retrieve_editable_strokes(
2282 *object, info.drawing, info.layer_index, memory);
2283 const OffsetIndices<int> points_by_curve = curves.points_by_curve();
2284 Array<Bounds<float2>> screen_space_curve_bounds(curves.curves_num(),
2285 {float2(0.0f), float2(0.0f)});
2286 editable_strokes.foreach_index(
2287 [&](const int curve) {
2288 Bounds<float2> bounds = *bounds::min_max(
2289 screen_space_positions.as_span().slice(points_by_curve[curve]));
2290 /* Pad to avoid empty bounds from horizontal, vertical and single-point strokes, as
2291 * such bounds would otherwise always fail the intersection test. */
2292 bounds.pad(1);
2293 screen_space_curve_bounds[curve] = bounds;
2294 },
2295 exec_mode::grain_size(512));
2296
2297 const IndexMask curve_selection = IndexMask::from_predicate(
2298 editable_strokes, memory, [&](const int64_t index) {
2299 return bounds::intersect(lasso_bounds, screen_space_curve_bounds[index]).has_value();
2300 });
2301
2302 if (curve_selection.is_empty()) {
2303 return;
2304 }
2305
2306 Array<bool> points_to_remove(curves.points_num(), false);
2307 curve_selection.foreach_index(
2308 [&](const int64_t curve_i) {
2309 for (const int point : points_by_curve[curve_i]) {
2310 points_to_remove[point] = is_point_inside_lasso(lasso,
2311 int2(screen_space_positions[point]));
2312 }
2313 },
2314 exec_mode::grain_size(512));
2315 points_to_remove_per_drawing[drawing_i] = IndexMask::from_bools(points_to_remove, memory);
2316 }
2317 });
2318
2319 const bool changed = remove_points_and_split_from_drawings(drawings.as_span(),
2320 points_to_remove_per_drawing);
2321 if (changed) {
2324 }
2325
2326 return OPERATOR_FINISHED;
2327}
2328
2330{
2331 ot->name = "Grease Pencil Erase Lasso";
2332 ot->idname = "GREASE_PENCIL_OT_erase_lasso";
2333 ot->description = "Erase points in the lasso region";
2334
2340
2342
2344}
2345
2347{
2348 using namespace bke::greasepencil;
2349 using namespace ed::greasepencil;
2350 const Scene *scene = CTX_data_scene(C);
2351 const Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
2352 const ARegion *region = CTX_wm_region(C);
2353 Object *object = CTX_data_active_object(C);
2354 const Object *ob_eval = DEG_get_evaluated(depsgraph, object);
2355 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
2356
2358 if (box_bounds.is_empty()) {
2359 return OPERATOR_FINISHED;
2360 }
2361
2363
2365 *scene, grease_pencil);
2366 Array<IndexMaskMemory> memories(drawings.size());
2367 Array<IndexMask> points_to_remove_per_drawing(drawings.size());
2368 threading::parallel_for(drawings.index_range(), 1, [&](const IndexRange range) {
2369 for (const int drawing_i : range) {
2370 const MutableDrawingInfo &info = drawings[drawing_i];
2371 const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
2372 const bke::crazyspace::GeometryDeformation deformation =
2373 bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
2374 ob_eval, *object, info.drawing);
2375 const float4x4 layer_to_world = layer.to_world_space(*ob_eval);
2376
2377 const bke::CurvesGeometry &curves = info.drawing.strokes();
2378 Array<float2> screen_space_positions(curves.points_num(), float2(0));
2379 IndexMaskMemory &memory = memories[drawing_i];
2380 const IndexMask editable_points = retrieve_editable_points(
2381 *object, info.drawing, info.layer_index, memory);
2382 editable_points.foreach_index(
2383 [&](const int point) {
2384 const float3 pos = math::transform_point(layer_to_world, deformation.positions[point]);
2385 ED_view3d_project_float_global(
2386 region, pos, screen_space_positions[point], V3D_PROJ_TEST_NOP);
2387 },
2388 exec_mode::grain_size(4096));
2389
2390 points_to_remove_per_drawing[drawing_i] = IndexMask::from_predicate(
2391 editable_points, memory, [&](const int64_t index) {
2392 return is_point_inside_bounds(box_bounds, int2(screen_space_positions[index]));
2393 });
2394 }
2395 });
2396
2397 const bool changed = remove_points_and_split_from_drawings(drawings.as_span(),
2398 points_to_remove_per_drawing);
2399 if (changed) {
2402 }
2403
2404 return OPERATOR_FINISHED;
2405}
2406
2408{
2409 ot->name = "Grease Pencil Box Erase";
2410 ot->idname = "GREASE_PENCIL_OT_erase_box";
2411 ot->description = "Erase points in the box region";
2412
2418
2420
2422}
2423
2425
2426} // namespace ed::sculpt_paint
2427
2428/* -------------------------------------------------------------------- */
2431
2443
2445{
2446 using namespace blender::ed::greasepencil;
2448
2449 static const EnumPropertyItem modal_items[] = {
2450 {int(FillToolModalKey::Cancel), "CANCEL", 0, "Cancel", ""},
2451 {int(FillToolModalKey::Confirm), "CONFIRM", 0, "Confirm", ""},
2453 "EXTENSION_MODE_TOGGLE",
2454 0,
2455 "Toggle Extension Mode",
2456 ""},
2458 "EXTENSION_LENGTHEN",
2459 0,
2460 "Lengthen Extensions",
2461 ""},
2462 {int(FillToolModalKey::ExtensionShorten), "EXTENSION_SHORTEN", 0, "Shorten Extensions", ""},
2463 {int(FillToolModalKey::ExtensionDrag), "EXTENSION_DRAG", 0, "Drag Extensions", ""},
2464 {int(FillToolModalKey::ExtensionCollide), "EXTENSION_COLLIDE", 0, "Collide Extensions", ""},
2465 {int(FillToolModalKey::Invert), "INVERT", 0, "Invert", ""},
2466 {int(FillToolModalKey::Precision), "PRECISION", 0, "Precision", ""},
2467 {0, nullptr, 0, nullptr, nullptr},
2468 };
2469
2470 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Fill Tool Modal Map");
2471
2472 /* This function is called for each space-type, only needs to add map once. */
2473 if (keymap && keymap->modal_items) {
2474 return;
2475 }
2476
2477 keymap = WM_modalkeymap_ensure(keyconf, "Fill Tool Modal Map", modal_items);
2478
2479 WM_modalkeymap_assign(keymap, "GREASE_PENCIL_OT_fill");
2480}
2481
2483
2484} // namespace blender
Functions to insert, delete or modify keyframes.
Low-level operations for curves.
support for deformation groups and hooks.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
Functions for dealing with objects and deform verts, used by painting and tools.
#define final(a, b, c)
Definition BLI_hash_c.hh:21
A KD-tree for nearest neighbor search.
#define BLI_SCOPED_DEFER(function_to_defer)
#define IFACE_(msgid)
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define OPERATOR_RETVAL_CHECK(ret)
#define REGION_DRAW_POST_VIEW
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define NA_EDITED
Definition WM_types.hh:634
#define NC_GPENCIL
Definition WM_types.hh:412
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
int64_t size() const
Definition BLI_array.hh:267
Span< T > as_span() const
Definition BLI_array.hh:254
const T * data() const
Definition BLI_array.hh:323
bool is_empty() const
Definition BLI_array.hh:275
ChannelStorageType a
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
constexpr int64_t first() const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr IndexRange()=default
constexpr IndexRange after(int64_t n) const
constexpr bool contains(int64_t value) const
constexpr IndexRange index_range() const
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
static VArray from_std_func(const int64_t size, std::function< T(int64_t index)> get_func)
static VArray from_single(T value, const int64_t size)
static VArray from_span(Span< T > values)
bool add(const Key &key)
bool contains(const Key &key) const
int64_t size() const
void append(const T &value)
bool is_empty() const
IndexRange index_range() const
void reserve(const int64_t min_capacity)
Span< T > as_span() const
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
Definition area.cc:1097
bool contains(StringRef name) const
AttributeAccessor attributes() const
Span< float3 > positions() const
IndexRange curves_range() const
IndexRange points_range() const
MutableAttributeAccessor attributes_for_write()
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
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)
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
const Map< FramesMapKeyT, GreasePencilFrame > & frames() const
std::optional< int > start_frame_at(int frame_number) const
constexpr IndexRange after(int64_t n) const
virtual void on_stroke_extended(const bContext &C, const InputSample &extension_sample)=0
virtual void on_stroke_done(const bContext &C)=0
#define FLT_MAX
#define layer
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
float2x2 invert(float2x2 mat)
bool is_autokey_on(const Scene *scene)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
constexpr float LEGACY_RADIUS_CONVERSION_FACTOR
CurvesGeometry curves_copy_point_selection(const CurvesGeometry &curves, const IndexMask &points_to_copy, const AttributeFilter &attribute_filter)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
void fill_attribute_range_default(MutableAttributeAccessor dst_attributes, AttrDomain domain, const AttributeFilter &attribute_filter, IndexRange range)
Curves * curves_new_nomain(int points_num, int curves_num)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
Definition BLI_bounds.hh:56
void draw_lines(const float4x4 &transform, IndexRange indices, Span< float3 > start_positions, Span< float3 > end_positions, const VArray< ColorGeometry4f > &colors, float line_width)
void draw_grease_pencil_strokes(const RegionView3D &rv3d, const int2 &win_size, const Object &object, const bke::greasepencil::Drawing &drawing, const float4x4 &transform, const IndexMask &strokes_mask, const VArray< ColorGeometry4f > &colors, const bool use_xray, const float radius_scale)
void draw_circles(const float4x4 &transform, const IndexRange indices, Span< float3 > centers, const VArray< float > &radii, const VArray< ColorGeometry4f > &colors, const float2 &viewport_size, const float line_width, const bool fill)
void draw_polyline(const float4x4 &transform, const IndexRange indices, Span< float3 > positions, const VArray< ColorGeometry4f > &colors, const bool cyclic, const float line_width)
bool grease_pencil_draw_operator_begin(bContext *C, wmOperator *op, const bool use_duplicate_previous_key)
float opacity_from_input_sample(const float pressure, const Paint &paint, const Brush *brush, const BrushGpencilSettings *settings)
bool ensure_active_keyframe(const Scene &scene, GreasePencil &grease_pencil, bke::greasepencil::Layer &layer, const bool duplicate_previous_key, bool &r_inserted_keyframe)
bool grease_pencil_vertex_painting_poll(bContext *C)
Vector< DrawingInfo > retrieve_visible_drawings(const Scene &scene, const GreasePencil &grease_pencil, const bool do_onion_skinning)
bool check_brush_needs_new_material(Object *ob, const Brush *brush)
bool has_editable_layer(const GreasePencil &grease_pencil)
bool grease_pencil_sculpting_poll(bContext *C)
bool grease_pencil_weight_painting_poll(bContext *C)
bool remove_fill_guides(bke::CurvesGeometry &curves)
Vector< MutableDrawingInfo > retrieve_editable_drawings(const Scene &scene, GreasePencil &grease_pencil)
float4x2 calculate_texture_space(const Scene *scene, const ARegion *region, const float2 &mouse, const DrawingPlacement &placement)
bool grease_pencil_painting_poll(bContext *C)
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)
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_replace_operation()
std::unique_ptr< GreasePencilStrokeOperation > new_erase_operation(const bool temp_eraser)
Definition erase.cc:1189
std::unique_ptr< GreasePencilStrokeOperation > new_weight_paint_average_operation()
std::unique_ptr< GreasePencilStrokeOperation > new_strength_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_grab_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_weight_paint_blur_operation()
std::unique_ptr< GreasePencilStrokeOperation > new_tint_operation(bool temp_eraser=false)
Definition tint.cc:344
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_paint_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_paint_operation(bool do_fill_guides=false)
std::unique_ptr< GreasePencilStrokeOperation > new_clone_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_randomize_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_blur_operation()
bool brush_using_vertex_color(const GpPaint *gp_paint, const Brush *brush)
std::unique_ptr< GreasePencilStrokeOperation > new_weight_paint_draw_operation(const BrushStrokeMode &stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_thickness_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_pinch_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_push_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_weight_paint_smear_operation()
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_average_operation()
std::unique_ptr< GreasePencilStrokeOperation > new_twist_operation(BrushStrokeMode stroke_mode)
std::unique_ptr< GreasePencilStrokeOperation > new_smooth_operation(BrushStrokeMode stroke_mode, bool temp_smooth=false)
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_smear_operation()
static void grease_pencil_fill_extension_lines_from_circles(const bContext &C, ed::greasepencil::ExtensionData &extension_data, Span< int >, Span< int >)
Definition draw_ops.cc:940
static bool is_point_inside_bounds(const Bounds< int2 > bounds, const int2 point)
Definition draw_ops.cc:2211
static bool is_point_inside_lasso(const Array< int2 > lasso, const int2 point)
Definition draw_ops.cc:2228
static bool grease_pencil_weight_brush_stroke_poll(bContext *C)
Definition draw_ops.cc:486
static void grease_pencil_sculpt_paint_cancel(bContext *C, wmOperator *op)
Definition draw_ops.cc:458
static wmOperatorStatus grease_pencil_weight_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:497
static void grease_pencil_fill_exit(bContext &C, wmOperator &op)
Definition draw_ops.cc:1870
static wmOperatorStatus grease_pencil_vertex_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:596
static void GREASE_PENCIL_OT_erase_lasso(wmOperatorType *ot)
Definition draw_ops.cc:2329
static wmOperatorStatus grease_pencil_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:297
static bool grease_pencil_sculpt_paint_poll(bContext *C)
Definition draw_ops.cc:372
static void grease_pencil_fill_cancel(bContext *C, wmOperator *op)
Definition draw_ops.cc:2132
static wmOperatorStatus grease_pencil_sculpt_paint_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:443
static void GREASE_PENCIL_OT_weight_brush_stroke(wmOperatorType *ot)
Definition draw_ops.cc:563
static wmOperatorStatus grease_pencil_vertex_brush_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:653
static void grease_pencil_brush_stroke_cancel(bContext *C, wmOperator *op)
Definition draw_ops.cc:341
static void GREASE_PENCIL_OT_brush_stroke(wmOperatorType *ot)
Definition draw_ops.cc:347
static void GREASE_PENCIL_OT_vertex_brush_stroke(wmOperatorType *ot)
Definition draw_ops.cc:673
static void GREASE_PENCIL_OT_sculpt_paint(wmOperatorType *ot)
Definition draw_ops.cc:464
static void grease_pencil_fill_overlay_delaunay_cb(const bContext &C, const GreasePencilFillOpData &op_data)
Definition draw_ops.cc:1283
static void grease_pencil_fill_status_indicators(bContext &C, const GreasePencilFillOpData &op_data)
Definition draw_ops.cc:1180
static wmOperatorStatus grease_pencil_fill_event_modal_map(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:1957
static bool grease_pencil_vertex_brush_stroke_poll(bContext *C)
Definition draw_ops.cc:585
static void grease_pencil_vertex_brush_stroke_cancel(bContext *C, wmOperator *op)
Definition draw_ops.cc:667
static wmOperatorStatus grease_pencil_sculpt_paint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:383
static wmOperatorStatus grease_pencil_weight_brush_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:543
static bke::CurvesGeometry simplify_fixed(bke::CurvesGeometry &curves, const int step)
Definition draw_ops.cc:1524
static wmOperatorStatus grease_pencil_erase_box_exec(bContext *C, wmOperator *op)
Definition draw_ops.cc:2346
static void GREASE_PENCIL_OT_erase_box(wmOperatorType *ot)
Definition draw_ops.cc:2407
static VArray< bool > get_fill_boundary_layers(const GreasePencil &grease_pencil, eGP_FillLayerModes fill_layer_mode)
Definition draw_ops.cc:1374
static Vector< FillToolTargetInfo > ensure_editable_drawings(const Scene &scene, GreasePencil &grease_pencil, bke::greasepencil::Layer &target_layer)
Definition draw_ops.cc:1420
static bool remove_points_and_split_from_drawings(const Span< ed::greasepencil::MutableDrawingInfo > drawings, const Span< IndexMask > points_to_remove_per_drawing)
Definition draw_ops.cc:2187
static void grease_pencil_weight_brush_stroke_cancel(bContext *C, wmOperator *op)
Definition draw_ops.cc:557
static void set_fill_attributes(bke::CurvesGeometry &fill_curves, const ViewContext &view_context, const Paint &paint, const Brush &brush, const Scene &scene, const float4x4 &to_world, const int material_index, const float hardness)
Definition draw_ops.cc:1544
static wmOperatorStatus grease_pencil_fill_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition draw_ops.cc:1899
static void GREASE_PENCIL_OT_fill(wmOperatorType *ot)
Definition draw_ops.cc:2137
static void grease_pencil_fill_overlay_cb(const bContext *C, ARegion *, void *arg)
Definition draw_ops.cc:1334
static wmOperatorStatus grease_pencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:2047
static bool use_duplicate_previous_key(bContext *C, wmOperator *op)
Definition draw_ops.cc:255
static wmOperatorStatus grease_pencil_erase_lasso_exec(bContext *C, wmOperator *op)
Definition draw_ops.cc:2234
static bool grease_pencil_apply_fill(bContext &C, wmOperator &op, const wmEvent &event)
Definition draw_ops.cc:1627
static wmOperatorStatus grease_pencil_brush_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition draw_ops.cc:327
static void grease_pencil_fill_update_overlay(const ARegion &region, GreasePencilFillOpData &op_data)
Definition draw_ops.cc:1346
static ed::greasepencil::ExtensionData grease_pencil_fill_get_extension_data(const bContext &C, const GreasePencilFillOpData &op_data)
Definition draw_ops.cc:1051
static void grease_pencil_fill_extension_cut(const bContext &C, ed::greasepencil::ExtensionData &extension_data, Span< int > origin_drawings, Span< int > origin_points)
Definition draw_ops.cc:771
static void ensure_drawing_for_autokey(bContext *C, GreasePencil &grease_pencil)
Definition draw_ops.cc:2163
static void smooth_fill_strokes(bke::CurvesGeometry &curves, const IndexMask &stroke_mask)
Definition draw_ops.cc:1495
static std::unique_ptr< GreasePencilStrokeOperation > get_stroke_operation(bContext &C, wmOperator *op)
Definition draw_ops.cc:104
static void grease_pencil_fill_overlay_pixel_cb(const bContext &C, const GreasePencilFillOpData &op_data)
Definition draw_ops.cc:1203
static bool grease_pencil_brush_stroke_poll(bContext *C)
Definition draw_ops.cc:244
static void grease_pencil_update_extend(bContext &C, GreasePencilFillOpData &op_data)
Definition draw_ops.cc:1366
static wmOperatorStatus grease_pencil_brush_stroke_exec(bContext *C, wmOperator *op)
Definition draw_ops.cc:278
static bool grease_pencil_fill_init(bContext &C, wmOperator &op)
Definition draw_ops.cc:1822
bke::GeometrySet join_geometries(Span< bke::GeometrySet > geometries, const bke::AttributeFilter &attribute_filter, const std::optional< Span< bke::GeometryComponent::Type > > &component_types_to_join=std::nullopt, bool allow_merging_instance_references=true)
void smooth_curve_attribute(const IndexMask &curves_to_smooth, const OffsetIndices< int > points_by_curve, const VArray< bool > &point_selection, const VArray< bool > &cyclic, int iterations, float influence, bool smooth_ends, bool keep_shape, GMutableSpan attribute_data)
bke::CurvesGeometry grease_pencil_remove_points_and_split(const bke::CurvesGeometry &curves, const IndexMask &mask)
T pow(const T &x, const T &power)
isect_result< VecBase< T, Size > > isect_seg_seg(const VecBase< T, Size > &v1, const VecBase< T, Size > &v2, const VecBase< T, Size > &v3, const VecBase< T, Size > &v4)
T distance(const T &a, const T &b)
QuaternionBase< T > normalize_and_get_length(const QuaternionBase< T > &q, T &out_length)
T average(const VecBase< T, Size > &a)
T interpolate(const T &a, const T &b, const FactorT &t)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
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
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void(*)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) BVHTree_RayCastCallback
void kdtree_balance(KDTree< CoordT > *tree)
__int64 int64_t
Definition BKE_text.h:90
int RNA_enum_get(PointerRNA *ptr, const char *name)
@ RPT_WARNING
Definition BKE_report.hh:40
@ GPWEIGHT_BRUSH_TYPE_SMEAR
@ GPWEIGHT_BRUSH_TYPE_DRAW
@ GPWEIGHT_BRUSH_TYPE_BLUR
@ GPWEIGHT_BRUSH_TYPE_AVERAGE
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:999
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], unsigned int nr)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3])
Material * BKE_object_material_get(Object *ob, short act)
void BLI_bvhtree_free(BVHTree *tree)
void WM_gesture_lasso_cancel(bContext *C, wmOperator *op)
void WM_cursor_modal_set(wmWindow *win, int val)
void kdtree_range_search_cb(const KDTree< CoordT > *tree, const CoordT &co, typename KDTree< CoordT >::ValueType range, Fn &&search_cb)
void BLI_bvhtree_balance(BVHTree *tree)
void WM_operator_properties_border(wmOperatorType *ot)
void BKE_brush_init_gpencil_settings(Brush *brush)
Definition brush.cc:719
wmWindow * CTX_wm_window(const bContext *C)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
wmOperatorStatus WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
MatBase< float, 4, 4 > float4x4
@ GP_FILL_SOLVER_DELAUNAY
int BLI_bvhtree_ray_cast(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
@ GPSCULPT_BRUSH_TYPE_CLONE
@ GPSCULPT_BRUSH_TYPE_PINCH
@ GPSCULPT_BRUSH_TYPE_PUSH
@ GPSCULPT_BRUSH_TYPE_THICKNESS
@ GPSCULPT_BRUSH_TYPE_RANDOMIZE
@ GPSCULPT_BRUSH_TYPE_GRAB
@ GPSCULPT_BRUSH_TYPE_STRENGTH
@ GPSCULPT_BRUSH_TYPE_SMOOTH
@ GPSCULPT_BRUSH_TYPE_TWIST
void BKE_brush_tag_unsaved_changes(Brush *brush)
Definition brush.cc:843
VecBase< float, 4 > float4
KDTree< CoordT > * kdtree_new(uint nodes_len_capacity)
Definition BLI_kdtree.hh:65
void BKE_curvemapping_init(CurveMapping *cumap)
void ED_operatortypes_grease_pencil_draw()
Definition draw_ops.cc:2432
@ GP_FILL_GPLMODE_ACTIVE
@ GP_FILL_GPLMODE_BELOW
@ GP_FILL_GPLMODE_VISIBLE
@ GP_FILL_GPLMODE_ALL_ABOVE
@ GP_FILL_GPLMODE_ABOVE
@ GP_FILL_GPLMODE_ALL_BELOW
@ GPAINT_BRUSH_TYPE_ERASE
@ GPAINT_BRUSH_TYPE_FILL
@ GPAINT_BRUSH_TYPE_TINT
@ GPAINT_BRUSH_TYPE_DRAW
@ GP_TOOL_FLAG_PAINT_ONBACK
@ GP_TOOL_FLAG_RETAIN_LAST
@ GP_USE_MULTI_FRAME_EDITING
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
MatBase< float, 4, 2 > float4x2
void kdtree_insert(KDTree< CoordT > *tree, int index, const CoordT &co)
Definition BLI_kdtree.hh:96
BVHTree * BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
void WM_cursor_modal_restore(wmWindow *win)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
int BKE_object_material_index_get(Object *ob, const Material *ma)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void paint_stroke_operator_properties(wmOperatorType *ot)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void kdtree_free(KDTree< CoordT > *tree)
Definition BLI_kdtree.hh:84
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
@ GPVERTEX_BRUSH_TYPE_REPLACE
@ GPVERTEX_BRUSH_TYPE_BLUR
@ GPVERTEX_BRUSH_TYPE_AVERAGE
@ GPVERTEX_BRUSH_TYPE_TINT
@ GPVERTEX_BRUSH_TYPE_SMEAR
@ GPVERTEX_BRUSH_TYPE_DRAW
@ WM_CURSOR_PAINT_BRUSH
Definition wm_cursors.hh:36
@ WM_CURSOR_EW_ARROW
Definition wm_cursors.hh:48
Main * CTX_data_main(const bContext *C)
wmOperatorStatus WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool WM_toolsystem_active_tool_is_brush(const bContext *C)
Paint * BKE_paint_get_active_from_context(const bContext *C)
bool BKE_object_defgroup_active_is_locked(const struct Object *ob)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
Array< int2 > WM_gesture_lasso_path_to_array(bContext *, wmOperator *op)
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints)
@ KM_RELEASE
Definition WM_types.hh:325
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
Brush * BKE_paint_brush(Paint *paint)
Material * BKE_grease_pencil_object_material_ensure_from_brush(Main *bmain, Object *ob, Brush *brush)
Scene * CTX_data_scene(const bContext *C)
float3 BKE_brush_color_get(const Paint *paint, const Brush *brush)
Definition brush.cc:1253
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void WM_cursor_set(wmWindow *win, int curs)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ GP_BRUSH_USE_STROKE
@ GP_BRUSH_FILL_SHOW_EXTENDLINES
@ GP_BRUSH_FILL_SHOW_HELPLINES
@ GP_BRUSH_FILL_STROKE_COLLIDE
@ GP_BRUSH_FILL_AUTO_REMOVE_FILL_GUIDES
@ GP_BRUSH_FILL_INTERNAL_GAPS
@ GP_BRUSH_MATERIAL_PINNED
void ED_filltool_modal_keymap(wmKeyConfig *keyconf)
Definition draw_ops.cc:2444
Object * CTX_data_active_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
signed char int8_t
Definition BKE_text.h:76
void WM_operator_properties_gesture_lasso(wmOperatorType *ot)
Bounds< int2 > WM_operator_properties_border_to_bounds(wmOperator *op)
int BKE_object_defgroup_active_index_get(const Object *ob)
Definition deform.cc:613
bke::ARegionRuntime * runtime
bool is_empty() const
struct RenderData r
struct ToolSettings * toolsettings
eGPencil_Flags gpencil_flags
RegionView3D * rv3d
Definition ED_view3d.hh:86
struct ARegionType * type
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const bke::greasepencil::Drawing & drawing
struct blender::ed::greasepencil::ExtensionData::@147343236172247015273153246111172323157377245354 lines
struct blender::ed::greasepencil::ExtensionData::@265020321004141327021164373252125002104130321223 circles
ed::greasepencil::MutableDrawingInfo target
Definition draw_ops.cc:1413
Vector< ed::greasepencil::DrawingInfo > sources
Definition draw_ops.cc:1414
static GreasePencilFillOpData from_context(bContext &C, bke::greasepencil::Layer &layer, const int material_index, const bool invert, const bool precision)
Definition draw_ops.cc:732
std::optional< float3 > get_location(float2 mouse, bool force_original) override
Definition draw_ops.cc:98
void done(bool is_cancel, bool stroke_started) override
Definition draw_ops.cc:229
void update_step(wmOperator *op, const StrokeStep &stroke_step) override
Definition draw_ops.cc:198
bool test_start(wmOperator *op, float2 mouse) override
Definition draw_ops.cc:193
GreasePencilPaintStroke(bContext *C, wmOperator *op, const wmEvent *event, PaintMode mode)
Definition draw_ops.cc:85
wmOperatorStatus modal(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus exec(bContext *C, wmOperator *op)
std::unique_ptr< PaintModeData > mode_data_
wmTabletData tablet
Definition WM_types.hh:846
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports
struct wmOperatorType * type