37using bke::CurvesGeometry;
42 bool clear_selection_;
50 : use_select_(use_select), clear_selection_(clear_selection)
104 if (self.clear_selection_) {
153 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
169 const float brush_radius_sq_re =
pow2f(brush_radius_re);
172 for (const int point_i : point_range) {
173 const float3 pos_cu = math::transform_point(brush_transform_inv,
174 deformation.positions[point_i]);
177 const float2 pos_re = ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, projection);
179 const float distance_to_brush_sq_re = math::distance_squared(pos_re, brush_pos_re_);
180 if (distance_to_brush_sq_re > brush_radius_sq_re) {
185 const float distance_to_brush_re = std::sqrt(distance_to_brush_sq_re);
187 const float radius_falloff = BKE_brush_curve_strength(
188 brush_, distance_to_brush_re, brush_radius_re);
190 const float weight = brush_strength_ * radius_falloff;
192 selection[point_i] = math::interpolate(selection[point_i], selection_goal_, weight);
211 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
222 const float brush_radius_cu =
self_->brush_3d_.radius_cu;
223 const float brush_radius_sq_cu =
pow2f(brush_radius_cu);
226 for (const int i : point_range) {
227 const float3 pos_old_cu = deformation.positions[i];
230 const float distance_to_brush_sq_cu = math::distance_squared(pos_old_cu, brush_cu);
231 if (distance_to_brush_sq_cu > brush_radius_sq_cu) {
236 const float distance_to_brush_cu = std::sqrt(distance_to_brush_sq_cu);
239 const float radius_falloff = BKE_brush_curve_strength(
240 brush_, distance_to_brush_cu, brush_radius_cu);
242 const float weight = brush_strength_ * radius_falloff;
244 selection[i] = math::interpolate(selection[i], selection_goal_, weight);
253 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
270 const float brush_radius_sq_re =
pow2f(brush_radius_re);
273 for (const int curve_i : curves_range) {
274 const float max_weight = threading::parallel_reduce(
275 points_by_curve[curve_i].drop_back(1),
278 [&](const IndexRange segment_range, const float init) {
279 float max_weight = init;
280 for (const int segment_i : segment_range) {
281 const float3 pos1_cu = math::transform_point(brush_transform_inv,
282 deformation.positions[segment_i]);
283 const float3 pos2_cu = math::transform_point(brush_transform_inv,
284 deformation.positions[segment_i + 1]);
286 const float2 pos1_re = ED_view3d_project_float_v2_m4(
287 ctx_.region, pos1_cu, projection);
288 const float2 pos2_re = ED_view3d_project_float_v2_m4(
289 ctx_.region, pos2_cu, projection);
291 const float distance_sq_re = dist_squared_to_line_segment_v2(
292 brush_pos_re_, pos1_re, pos2_re);
293 if (distance_sq_re > brush_radius_sq_re) {
296 const float radius_falloff = BKE_brush_curve_strength(
297 brush_, std::sqrt(distance_sq_re), brush_radius_re);
298 const float weight = brush_strength_ * radius_falloff;
299 max_weight = std::max(max_weight, weight);
303 [](float a, float b) { return std::max(a, b); });
304 selection[curve_i] = math::interpolate(selection[curve_i], selection_goal_, max_weight);
323 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
335 const float brush_radius_cu =
self_->brush_3d_.radius_cu;
336 const float brush_radius_sq_cu =
pow2f(brush_radius_cu);
339 for (const int curve_i : curves_range) {
340 const float max_weight = threading::parallel_reduce(
341 points_by_curve[curve_i].drop_back(1),
344 [&](const IndexRange segment_range, const float init) {
345 float max_weight = init;
346 for (const int segment_i : segment_range) {
347 const float3 &pos1_cu = deformation.positions[segment_i];
348 const float3 &pos2_cu = deformation.positions[segment_i + 1];
350 const float distance_sq_cu = dist_squared_to_line_segment_v3(
351 brush_cu, pos1_cu, pos2_cu);
352 if (distance_sq_cu > brush_radius_sq_cu) {
355 const float radius_falloff = BKE_brush_curve_strength(
356 brush_, std::sqrt(distance_sq_cu), brush_radius_cu);
357 const float weight = brush_strength_ * radius_falloff;
358 max_weight = std::max(max_weight, weight);
362 [](float a, float b) { return std::max(a, b); });
363 selection[curve_i] = math::interpolate(selection[curve_i], selection_goal_, max_weight);
377 if (brush_3d.has_value()) {
378 self_->brush_3d_ = *brush_3d;
390 executor.
execute(*
this, stroke_extension);
401 return std::make_unique<SelectionPaintOperation>(use_select, clear_selection);
Low-level operations for curves.
IndexRange points_range() const
const Depsgraph * depsgraph
friend struct SelectionPaintOperationExecutor
void on_stroke_extended(const PaintStroke &stroke, const StrokeExtension &stroke_extension) override
SelectionPaintOperation(const bool use_select, const bool clear_selection)
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
void fill_selection_false(GMutableSpan selection)
float brush_strength_get(const Paint &paint, const Brush &brush, const StrokeExtension &stroke_extension)
std::unique_ptr< CurvesSculptStrokeOperation > new_selection_paint_operation(BrushStrokeMode brush_mode, BrushSwitchMode brush_switch_mode, const Scene &scene)
std::optional< CurvesBrush3D > sample_curves_3d_brush(const Depsgraph &depsgraph, const ARegion ®ion, const View3D &v3d, const RegionView3D &rv3d, const Object &curves_object, const float2 &brush_pos_re, const float brush_radius_re)
bke::SpanAttributeWriter< float > float_selection_ensure(Curves &curves_id)
void remember_stroke_position(CurvesSculpt &curves_sculpt, const float3 &brush_position_wo)
Vector< float4x4 > get_symmetry_brush_transforms(const eCurvesSymmetryType symmetry)
float brush_radius_factor(const Brush &brush, const StrokeExtension &stroke_extension)
CartesianBasis invert(const CartesianBasis &basis)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void WM_main_add_notifier(uint type, void *reference)
float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob)
float BKE_brush_radius_get(const Paint *paint, const Brush *brush)
@ PAINT_FALLOFF_SHAPE_SPHERE
@ PAINT_FALLOFF_SHAPE_TUBE
MatBase< float, 4, 4 > float4x4
void ED_region_tag_redraw(ARegion *region)
MINLINE float pow2f(float x)
VecBase< float, 2 > float2
void DEG_id_tag_update(ID *id, unsigned int flags)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Brush * BKE_paint_brush(Paint *paint)
VecBase< float, 3 > float3
void ED_view3d_win_to_3d(const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
eBrushFalloffShape falloff_shape
struct ToolSettings * toolsettings
MutableVArraySpan< T > span
bke::SpanAttributeWriter< float > selection_
CurvesSculptCommonContext ctx_
void paint_point_selection_spherical_with_symmetry(MutableSpan< float > selection)
CurvesSurfaceTransforms transforms_
SelectionPaintOperationExecutor(const PaintStroke &stroke)
void paint_point_selection_spherical(MutableSpan< float > selection, const float3 &brush_cu)
void paint_curve_selection_projected(const float4x4 &brush_transform, MutableSpan< float > selection)
float brush_radius_factor_
SelectionPaintOperation * self_
void paint_point_selection_projected_with_symmetry(MutableSpan< float > selection)
void paint_curve_selection_spherical(MutableSpan< float > selection, const float3 &brush_cu)
void paint_point_selection_projected(const float4x4 &brush_transform, MutableSpan< float > selection)
float brush_radius_base_re_
void paint_curve_selection_spherical_with_symmetry(MutableSpan< float > selection)
void paint_curve_selection_projected_with_symmetry(MutableSpan< float > selection)
void initialize_spherical_brush_reference_point()
void execute(SelectionPaintOperation &self, const StrokeExtension &stroke_extension)
CurvesSculpt * curves_sculpt_