33 return (centered * this->cell_size_px) +
center;
40 return pos + ((this->size + 1) / 2);
47 if (
pos.x >= 0 &&
pos.x < this->size &&
pos.y >= 0 &&
pos.y < this->size) {
48 return pos.y * this->size +
pos.x;
67void VertexSmearOperation::init_color_grid(
const bContext &
C,
const float2 start_position)
79 color_grid_.
center = start_position;
83 const int grid_array_length = color_grid_.
size * color_grid_.
size;
84 color_grid_.
colors.reinitialize(grid_array_length);
91 params, use_selection_masking, memory);
100 Array<int> points_per_cell(grid_array_length, 0);
102 const float2 view_pos = view_positions[point_i];
103 const float view_radius = radii[point_i];
108 const int2 bounds_min = bounds_center - (bounds_size / 2);
109 const int2 bounds_max = bounds_center + (bounds_size / 2);
110 if (!(bounds_min.x < color_grid_.
size && bounds_max.x >= 0 &&
111 bounds_min.y < color_grid_.
size && bounds_max.y >= 0))
116 for (
int y = bounds_min.y;
y <= bounds_max.y;
y++) {
117 for (
int x = bounds_min.x;
x <= bounds_max.x;
x++) {
126 points_per_cell[cell_i]++;
132 for (
const int cell_i : color_grid_.colors.index_range()) {
133 if (points_per_cell[cell_i] > 0) {
134 color_grid_.colors[cell_i] *= 1.0f /
float(points_per_cell[cell_i]);
162 params, use_selection_masking, memory);
169 const float2 view_pos = view_positions[point_i];
170 const int2 grid_pos = color_grid_.coords_to_pos(view_pos, extension_sample.
mouse_position);
171 const int cell_i = color_grid_.pos_to_index(grid_pos);
172 if (cell_i == -1 || color_grid_.colors[cell_i][3] == 0.0f) {
178 1.0f - (
math::distance(color_grid_.center, view_pos) / radius * 2), 0.0f, 1.0f);
183 params.multi_frame_falloff) *
185 if (influence > 0.0f) {
187 const float alpha =
color.a;
200 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)
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
bool ED_grease_pencil_any_vertex_mask_selection(const ToolSettings *tool_settings)
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)
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 ¶ms, const IndexMask &selection)
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_smear_operation()
float brush_radius(const Paint &paint, 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