35 return (centered * this->cell_size_px) +
center;
42 return pos + ((this->size + 1) / 2);
50 return pos.y * this->size +
pos.x;
69void VertexSmearOperation::init_color_grid(
const bContext &
C,
const float2 start_position)
81 color_grid_.
center = start_position;
85 const int grid_array_length = color_grid_.
size * color_grid_.
size;
86 color_grid_.
colors.reinitialize(grid_array_length);
93 params, use_selection_masking, memory);
102 Array<int> points_per_cell(grid_array_length, 0);
104 const float2 view_pos = view_positions[point_i];
105 const float view_radius = radii[point_i];
110 const int2 bounds_min = bounds_center - (bounds_size / 2);
111 const int2 bounds_max = bounds_center + (bounds_size / 2);
112 if (!(bounds_min.x < color_grid_.
size && bounds_max.x >= 0 &&
113 bounds_min.y < color_grid_.
size && bounds_max.y >= 0))
118 for (
int y = bounds_min.y;
y <= bounds_max.y;
y++) {
119 for (
int x = bounds_min.x;
x <= bounds_max.x;
x++) {
128 points_per_cell[cell_i]++;
134 for (
const int cell_i : color_grid_.colors.index_range()) {
135 if (points_per_cell[cell_i] > 0) {
136 color_grid_.colors[cell_i] *= 1.0f / float(points_per_cell[cell_i]);
164 params, use_selection_masking, memory);
171 const float2 view_pos = view_positions[point_i];
172 const int2 grid_pos = color_grid_.coords_to_pos(view_pos, extension_sample.
mouse_position);
173 const int cell_i = color_grid_.pos_to_index(grid_pos);
174 if (cell_i == -1 || color_grid_.colors[cell_i][3] == 0.0f) {
180 1.0f - (
math::distance(color_grid_.center, view_pos) / radius * 2), 0.0f, 1.0f);
185 params.multi_frame_falloff) *
187 if (influence > 0.0f) {
189 const float alpha =
color.a;
202 return std::make_unique<VertexSmearOperation>();
Scene * CTX_data_scene(const bContext *C)
Low-level operations for grease pencil.
Paint * BKE_paint_get_active_from_context(const bContext *C)
Brush * BKE_paint_brush(Paint *paint)
#define GPENCIL_ANY_VERTEX_MASK(flag)
eGP_vertex_SelectMaskFlag
GreasePencilStrokeOperationCommon()=default
void init_stroke(const bContext &C, const InputSample &start_sample)
void foreach_editable_drawing(const bContext &C, FunctionRef< bool(const GreasePencilStrokeParams ¶ms, const DeltaProjectionFunc &projection_fn)> fn) const
void on_stroke_done(const bContext &C) override
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
Array< float > calculate_view_radii(const GreasePencilStrokeParams ¶ms, const IndexMask &selection)
IndexMask point_mask_for_stroke_operation(const GreasePencilStrokeParams ¶ms, bool use_selection_masking, IndexMaskMemory &memory)
Array< float2 > calculate_view_positions(const GreasePencilStrokeParams ¶ms, const IndexMask &selection)
float brush_point_influence(const Scene &scene, const Brush &brush, const float2 &co, const InputSample &sample, float multi_frame_falloff)
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_smear_operation()
float brush_radius(const Scene &scene, const Brush &brush, float pressure)
T clamp(const T &a, const T &min, const T &max)
T distance(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
struct ToolSettings * toolsettings
int pos_to_index(const int2 pos) const
float2 pos_to_coords(const int2 pos, const float2 center) const
int2 coords_to_pos(const float2 coord, const float2 center) const