57 if (active_layer_masking) {
73 if (
brush.gpencil_settings ==
nullptr) {
102 const float multi_frame_falloff)
115 return influence_base * brush_falloff;
120 int j = verts.
size() - 1;
123 for (
int i = 0; i < verts.
size(); i++) {
125 if (((verts[i].
y > pt.y) != (verts[j].y > pt.y)) &&
127 (verts[j].x - verts[i].x) * (pt.y - verts[i].y) / (verts[j].y - verts[i].y) + verts[i].x))
141 const float multi_frame_falloff)
154 return influence_base * brush_falloff;
159 const float2 &mouse_position,
160 const float pressure,
161 const float multi_frame_falloff,
172 const float radius_squared = radius * radius;
180 selection, memory, [&](
const int point) {
181 const float2 &co = view_positions[point];
190 all_influences[point] = 0.0f;
196 all_influences[point] = influence_base * brush_falloff;
197 return all_influences[point] > 0.0f;
202 return influence_mask;
207 const int brush_draw_mode =
brush->gpencil_settings->brush_draw_mode;
209 if (brush_use_pinned_mode) {
227 const float4x4 layer_to_world =
layer.to_world_space(
object);
230 auto screen_to_world = [=](
const float3 &world_pos,
const float2 &screen_delta) {
240 world_normal = view_to_world.
z_axis();
244 world_normal = layer_to_world.
x_axis();
248 world_normal = layer_to_world.
y_axis();
252 world_normal = layer_to_world.
z_axis();
267 const float3 world_delta = screen_to_world(world_pos, screen_delta);
269 world_to_layer, world_delta - world_normal *
math::dot(world_delta, world_normal));
277 const float2 &screen_delta)
280 const float3 new_position_eval = projection_fn(old_position_eval, screen_delta);
281 const float3 translation_eval = new_position_eval - old_position_eval;
283 index, translation_eval);
284 return translation_orig;
289 Depsgraph &depsgraph,
316 const bool use_selection_masking,
326 const bool use_selection_masking,
336 const bool use_selection_masking,
343 if (!use_selection_masking) {
353 for (const int curve_i : fills[i]) {
354 if (!editable_strokes.contains(curve_i)) {
384 view_positions[point_i],
392 return view_positions;
407 const IndexRange points = points_by_curve[curve_i];
408 for (
const int point_i : points) {
412 view_positions[point_i],
421 return view_positions;
431 if (handle_positions_left.
is_empty()) {
432 return view_positions;
442 view_positions[point_i],
450 return view_positions;
460 if (handle_positions_right.
is_empty()) {
461 return view_positions;
471 view_positions[point_i],
479 return view_positions;
496 view_radii[point_i] = radii[point_i] / pixel_size;
505 return brush.gpencil_settings !=
nullptr &&
511 return brush.gpencil_settings !=
nullptr &&
539 std::atomic<bool> changed =
false;
543 const AutoMaskingInfo &auto_mask_info = this->auto_masking_info_per_drawing[i];
555 if (
fn(params, auto_mask_info.point_mask)) {
566void GreasePencilStrokeOperationCommon::foreach_editable_drawing_with_automask(
568 FunctionRef<
bool(
const GreasePencilStrokeParams ¶ms,
582 std::atomic<bool> changed =
false;
585 const MutableDrawingInfo &info = drawings[i];
586 const Layer &layer = grease_pencil.layer(info.layer_index);
587 const AutoMaskingInfo &auto_mask_info = this->auto_masking_info_per_drawing[i];
588 const GreasePencilStrokeParams params = GreasePencilStrokeParams::from_context(
596 info.multi_frame_falloff,
599 const DeltaProjectionFunc projection_fn = get_screen_projection_fn(params, object_eval, layer);
600 if (fn(params, auto_mask_info.point_mask, projection_fn)) {
625 std::atomic<bool> changed =
false;
631 for (const int64_t i : range) {
632 const MutableDrawingInfo &info = drawings[i];
633 GreasePencilStrokeParams params = GreasePencilStrokeParams::from_context(
641 info.multi_frame_falloff,
689 bool changed =
false;
706 if (
fn(params, projection_fn)) {
740 const bool use_sculpt_selection_masking = (sculpt_selection_flag &
748 const bool use_auto_mask_layer = (sculpt_settings_flag &
750 const bool use_auto_mask_material = (sculpt_settings_flag &
752 const bool use_auto_mask_active_material = (sculpt_settings_flag &
755 const float stroke_distance_threshold = 20.0f;
757 const int active_material_index =
math::max(
object.actcol - 1, 0);
764 for (
const int drawing_i : drawings.
index_range()) {
778 params, use_sculpt_selection_masking, automask_info.
memory);
787 if (use_auto_mask_active_material) {
793 return active_material_index == materials[point_i];
802 if (use_auto_mask_layer || use_auto_mask_stroke || use_auto_mask_material) {
805 params, use_sculpt_selection_masking, memory);
809 stroke_selection, memory, [&](
const int curve_i) {
810 for (
const int point_i : points_by_curve[curve_i]) {
812 if (
distance <= stroke_distance_threshold) {
819 if (use_auto_mask_layer && !strokes_under_brush.
is_empty()) {
823 if (use_auto_mask_stroke) {
830 if (use_auto_mask_material) {
834 [&](
const int curve_i) { masked_material_indices.
add(material_indices[curve_i]); });
841 if (use_auto_mask_stroke) {
846 const MutableDrawingInfo &drawing_info = drawings[drawing_i];
847 AutoMaskingInfo &automask_info = this->auto_masking_info_per_drawing[drawing_i];
849 if (use_auto_mask_layer && !masked_layer_indices.contains(drawing_info.layer_index)) {
850 automask_info.point_mask = {};
854 if (use_auto_mask_material) {
860 curves.curves_range(), memory, [&](
const int curve_i) {
861 return masked_material_indices.contains(material_indices[curve_i]);
865 automask_info.point_mask,
867 automask_info.memory);
Low-level operations for curves.
Low-level operations for grease pencil.
#define BLI_assert_unreachable()
Span< T > as_span() const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_ranges(OffsetIndices< T > offsets, const IndexMask &mask, LinearAllocator<> &memory)
static IndexMask from_intersection(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
constexpr int64_t size() const
constexpr bool is_empty() const
IndexRange index_range() const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
std::optional< Span< float3 > > handle_positions_right() const
std::optional< Span< float3 > > handle_positions_left() const
OffsetIndices< int > points_by_curve() const
std::optional< GroupedSpan< int > > fills() const
const bke::CurvesGeometry & strokes() const
VArray< float > radii() const
float4x4 to_world_space(const Object &object) const
ed::greasepencil::MutableDrawingInfo MutableDrawingInfo
Array< AutoMaskingInfo > auto_masking_info_per_drawing
float2 prev_mouse_position
bool is_inverted(const Brush &brush) const
float2 mouse_delta(const InputSample &input_sample) const
void foreach_editable_drawing_with_automask(const bContext &C, FunctionRef< bool(const GreasePencilStrokeParams ¶ms, const IndexMask &points)> fn) const
void stroke_extended(const InputSample &extension_sample)
void init_stroke(const bContext &C, const InputSample &start_sample)
float2 start_mouse_position
void init_auto_masking(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
BrushStrokeMode stroke_mode
int64_t min_array_size() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
float distance(float, float) RET
float distance_squared(VecT a, VecT b)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval, const Object &ob_orig, const bke::greasepencil::Drawing &drawing_orig)
IndexMask retrieve_editable_and_selected_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
IndexMask retrieve_editable_points(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
Vector< MutableDrawingInfo > retrieve_editable_drawings_from_layer_with_falloff(const Scene &scene, GreasePencil &grease_pencil, const bke::greasepencil::Layer &layer)
IndexMask retrieve_editable_and_selected_points(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
Vector< MutableDrawingInfo > retrieve_editable_drawings_with_falloff(const Scene &scene, GreasePencil &grease_pencil)
IndexMask retrieve_editable_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
IndexMask curve_mask_for_stroke_operation(const GreasePencilStrokeParams ¶ms, bool use_selection_masking, IndexMaskMemory &memory)
Vector< ed::greasepencil::MutableDrawingInfo > get_drawings_for_stroke_operation(const bContext &C)
Array< float2 > view_positions_left_from_point_mask(const GreasePencilStrokeParams ¶ms, const IndexMask &selection)
bool is_brush_inverted(const Brush &brush, BrushStrokeMode stroke_mode)
float closest_distance_to_surface_2d(const float2 pt, const Span< float2 > verts)
Array< float2 > view_positions_right_from_point_mask(const GreasePencilStrokeParams ¶ms, const IndexMask &selection)
IndexMask fill_mask_for_stroke_operation(const GreasePencilStrokeParams ¶ms, bool use_selection_masking, IndexMaskMemory &memory)
bool do_vertex_color_fill(const Brush &brush)
Array< float2 > view_positions_from_curve_mask(const GreasePencilStrokeParams ¶ms, const IndexMask &curve_mask)
IndexMask point_mask_for_stroke_operation(const GreasePencilStrokeParams ¶ms, bool use_selection_masking, IndexMaskMemory &memory)
void init_brush(Brush &brush)
IndexMask brush_point_influence_mask(const Paint &paint, const Brush &brush, const float2 &mouse_position, float pressure, float multi_frame_falloff, const IndexMask &selection, Span< float2 > view_positions, Vector< float > &influences, IndexMaskMemory &memory)
float brush_point_influence(const Paint &paint, const Brush &brush, const float2 &co, const InputSample &sample, float multi_frame_falloff)
constexpr float invalid_screen_position
Array< float2 > view_positions_from_point_mask(const GreasePencilStrokeParams ¶ms, const IndexMask &point_mask)
bool brush_using_vertex_color(const GpPaint *gp_paint, const Brush *brush)
Vector< ed::greasepencil::MutableDrawingInfo > get_drawings_with_masking_for_stroke_operation(const bContext &C)
float brush_fill_influence(const Paint &paint, const Brush &brush, Span< float2 > fill_positions, const InputSample &sample, float multi_frame_falloff)
bke::crazyspace::GeometryDeformation get_drawing_deformation(const GreasePencilStrokeParams ¶ms)
Array< float > view_radii_from_point_selection(const GreasePencilStrokeParams ¶ms, const IndexMask &selection)
DeltaProjectionFunc get_screen_projection_fn(const GreasePencilStrokeParams ¶ms, const Object &object, const bke::greasepencil::Layer &layer)
bool do_vertex_color_points(const Brush &brush)
float3 compute_orig_delta(const DeltaProjectionFunc &projection_fn, const bke::crazyspace::GeometryDeformation &deformation, int index, const float2 &screen_delta)
float brush_radius(const Paint &paint, const Brush &brush, float pressure)
std::function< float3(const float3 position, const float2 &screen_delta)> DeltaProjectionFunc
constexpr ParallelGrainSize grain_size(int grain_size)
T distance(const T &a, const T &b)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
CartesianBasis invert(const CartesianBasis &basis)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T max(const T &a, const T &b)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for_each(Range &&range, const Function &function)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ GP_SCULPT_SETT_FLAG_AUTOMASK_LAYER_ACTIVE
@ GP_SCULPT_SETT_FLAG_AUTOMASK_STROKE
@ GP_SCULPT_SETT_FLAG_AUTOMASK_MATERIAL_ACTIVE
@ GP_SCULPT_SETT_FLAG_AUTOMASK_LAYER_STROKE
@ GP_SCULPT_SETT_FLAG_AUTOMASK_MATERIAL_STROKE
@ GP_BRUSH_MODE_VERTEXCOLOR
eGP_Sculpt_SelectMaskFlag
@ GP_SCULPT_MASK_SELECTMODE_POINT
@ GP_SCULPT_MASK_SELECTMODE_STROKE
@ GP_SCULPT_MASK_SELECTMODE_SEGMENT
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3])
float BKE_brush_radius_get(const Paint *paint, const Brush *brush)
void BKE_brush_init_gpencil_settings(Brush *brush)
MatBase< float, 4, 4 > float4x4
bool BKE_brush_use_alpha_pressure(const Brush *brush)
void BKE_curvemapping_init(CurveMapping *cumap)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void DEG_id_tag_update(ID *id, unsigned int flags)
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
eV3DProjStatus ED_view3d_project_float_global(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
float BKE_brush_curve_strength(eBrushCurvePreset preset, const CurveMapping *cumap, float distance, float brush_radius)
float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3])
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
MatBase< float, 3, 3 > float3x3
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool BKE_brush_use_size_pressure(const Brush *brush)
Paint * BKE_paint_get_active_from_context(const bContext *C)
@ V3D_PROJ_TEST_CLIP_NEAR
Brush * BKE_paint_brush(Paint *paint)
@ GPPAINT_FLAG_USE_VERTEXCOLOR
Scene * CTX_data_scene(const bContext *C)
VecBase< float, 3 > float3
Object * CTX_data_active_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
void ED_view3d_win_to_delta(const ARegion *region, const float xy_delta[2], float zfac, float r_out[3], bool precise=false)
float BKE_brush_alpha_get(const Paint *paint, const Brush *brush)
eGP_Lockaxis_Types lock_axis
eGP_Sculpt_SettingsFlag flag
struct ToolSettings * toolsettings
const float multi_frame_falloff
bke::greasepencil::Drawing & drawing
float multi_frame_falloff
const RegionView3D & rv3d
const bke::greasepencil::Layer & layer
static GreasePencilStrokeParams from_context(const Scene &scene, Depsgraph &depsgraph, ARegion ®ion, RegionView3D &rv3d, Object &object, int layer_index, int frame_number, float multi_frame_falloff, bke::greasepencil::Drawing &drawing)
bke::greasepencil::Drawing & drawing
const ToolSettings & toolsettings
constexpr int grain_size(const int fallback) const
IndexRange index_range() const