Blender V5.0
grease_pencil_sculpt_push.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_context.hh"
6#include "BKE_crazyspace.hh"
7#include "BKE_curves.hh"
9#include "BKE_paint.hh"
10
11#include "ED_grease_pencil.hh"
12#include "ED_view3d.hh"
13
14#include "WM_api.hh"
15#include "WM_types.hh"
16
18#include "paint_intern.hh"
19
21
23 public:
25
26 void on_stroke_begin(const bContext &C, const InputSample &start_sample) override;
27 void on_stroke_extended(const bContext &C, const InputSample &extension_sample) override;
28 void on_stroke_done(const bContext & /*C*/) override {}
29};
30
31void PushOperation::on_stroke_begin(const bContext &C, const InputSample &start_sample)
32{
33 this->init_stroke(C, start_sample);
34 this->init_auto_masking(C, start_sample);
35}
36
37void PushOperation::on_stroke_extended(const bContext &C, const InputSample &extension_sample)
38{
40 const Brush &brush = *BKE_paint_brush(&paint);
41
43 C,
45 const IndexMask &point_mask,
46 const DeltaProjectionFunc &projection_fn) {
48 Array<float2> view_positions = calculate_view_positions(params, point_mask);
49 bke::CurvesGeometry &curves = params.drawing.strokes_for_write();
50 MutableSpan<float3> positions = curves.positions_for_write();
51
52 const float2 mouse_delta = this->mouse_delta(extension_sample);
53
54 point_mask.foreach_index(GrainSize(4096), [&](const int64_t point_i) {
55 const float2 &co = view_positions[point_i];
56 const float influence = brush_point_influence(
57 paint, brush, co, extension_sample, params.multi_frame_falloff);
58 if (influence <= 0.0f) {
59 return;
60 }
61
62 positions[point_i] += compute_orig_delta(
63 projection_fn, deformation, point_i, mouse_delta * influence);
64 });
65
66 params.drawing.tag_positions_changed();
67 return true;
68 });
69 this->stroke_extended(extension_sample);
70}
71
72std::unique_ptr<GreasePencilStrokeOperation> new_push_operation(const BrushStrokeMode stroke_mode)
73{
74 return std::make_unique<PushOperation>(stroke_mode);
75}
76
77} // namespace blender::ed::sculpt_paint::greasepencil
Low-level operations for curves.
Low-level operations for grease pencil.
Paint * BKE_paint_get_active_from_context(const bContext *C)
Definition paint.cc:476
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:645
#define C
Definition RandGen.cpp:29
long long int int64_t
void foreach_editable_drawing_with_automask(const bContext &C, FunctionRef< bool(const GreasePencilStrokeParams &params, const IndexMask &points)> fn) const
void init_auto_masking(const bContext &C, const InputSample &start_sample)
void on_stroke_extended(const bContext &C, const InputSample &extension_sample) override
void on_stroke_begin(const bContext &C, const InputSample &start_sample) override
void foreach_index(Fn &&fn) const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
float brush_point_influence(const Paint &paint, const Brush &brush, const float2 &co, const InputSample &sample, float multi_frame_falloff)
Array< float2 > calculate_view_positions(const GreasePencilStrokeParams &params, const IndexMask &selection)
std::unique_ptr< GreasePencilStrokeOperation > new_push_operation(BrushStrokeMode stroke_mode)
bke::crazyspace::GeometryDeformation get_drawing_deformation(const GreasePencilStrokeParams &params)
float3 compute_orig_delta(const DeltaProjectionFunc &projection_fn, const bke::crazyspace::GeometryDeformation &deformation, int index, const float2 &screen_delta)
std::function< float3(const float3 position, const float2 &screen_delta)> DeltaProjectionFunc
VecBase< float, 2 > float2
BrushStrokeMode