29using bke::CurvesGeometry;
44 float distance = std::numeric_limits<float>::max();
125 const bool selection_has_cyclic = curve_selection_without_cyclic.
size() <
143 this->
cut_curves(brush_projection_info, curves_to_keep, ends);
162 if (selection_has_cyclic) {
176 for (
const int brush_transform_index : symmetry_brush_transforms.
index_range()) {
177 const float4x4 &brush_transform = symmetry_brush_transforms[brush_transform_index];
179 math::invert(brush_transform), brush_transform_index, r_brush_projection_info);
184 const int brush_transform_index,
194 const IndexRange points = points_by_curve[curve_i];
196 const int point_i = points[i];
202 if (dist_to_brush_sq_re < r_brush_projection_info[point_i].
distance) {
203 r_brush_projection_info[point_i].distance = dist_to_brush_sq_re;
204 r_brush_projection_info[point_i].brush_transform_index = brush_transform_index;
224 for (
const int brush_transform_index : symmetry_brush_transforms.
index_range()) {
225 const float4x4 &brush_transform = symmetry_brush_transforms[brush_transform_index];
228 r_brush_projection_info);
233 const float3 &brush_pos_cu,
241 const IndexRange points = points_by_curve[curve_i];
243 const int point_i = points[i];
247 if (dist_to_brush_sq_cu < r_brush_projection_info[point_i].
distance) {
248 r_brush_projection_info[point_i].distance = dist_to_brush_sq_cu;
249 r_brush_projection_info[point_i].brush_transform_index = brush_transform_index;
281 const float3 &point_inside_cu,
282 const float2 &brush_pos_re,
283 const float brush_radius_re,
287 ctx_.
region, point_outside_cu, transform_cu_to_re);
289 ctx_.
region, point_inside_cu, transform_cu_to_re);
293 point_outside_re, point_inside_re, brush_pos_re, brush_radius_re);
295 const float3 line_cu = point_inside_cu - point_outside_cu;
296 const float3 intersection_cu = point_outside_cu + t * line_cu;
297 return intersection_cu;
307 const float2 &line_segment_end,
308 const float2 &sphere_position,
309 const float sphere_radius)
311 const float2 line_re = line_segment_end - line_segment_start;
312 const float2 brush_to_outside_re = line_segment_start - sphere_position;
315 const float a =
math::dot(line_re, line_re);
316 const float b = 2.0f *
math::dot(line_re, brush_to_outside_re);
317 const float c =
math::dot(brush_to_outside_re, brush_to_outside_re) -
318 sphere_radius * sphere_radius;
320 float d =
b *
b - 4.0f * a * c;
324 const float t = (-
b -
sqrtf(d)) / (2.0f * a);
333 const float3 &point_inside_cu,
334 const float3 &brush_pos_cu,
335 const float brush_radius_cu)
337 const float3 line_cu = point_inside_cu - point_outside_cu;
338 const float3 brush_to_outside_cu = point_outside_cu - brush_pos_cu;
341 const float a =
math::dot(line_cu, line_cu);
342 const float b = 2.0f *
math::dot(line_cu, brush_to_outside_cu);
343 const float c =
math::dot(brush_to_outside_cu, brush_to_outside_cu) -
344 brush_radius_cu * brush_radius_cu;
346 float d =
b *
b - 4.0f * a * c;
351 const float t = (-
b -
sqrtf(d)) / (2.0f * a);
353 const float3 intersection_cu = point_outside_cu + t * line_cu;
354 return intersection_cu;
367 for (
const int curve_i : segment) {
368 const IndexRange points = points_by_curve[curve_i];
369 float accumulated_length = 0.0f;
371 const int point_i = points[i];
373 segment_lengths[point_i] = 0.0f;
376 const float3 &p1 = positions[point_i - 1];
377 const float3 &p2 = positions[point_i];
379 segment_lengths[point_i] = accumulated_length;
395 switch (falloff_shape) {
415 const float brush_radius_sq =
pow2f(brush_radius);
421 [&](
const int curve_i) {
422 const IndexRange points = points_by_curve[curve_i];
424 brush_projection_info.
slice(points);
427 brush_projection_info_slice.
begin(),
428 brush_projection_info_slice.
end(),
430 return projection_info.distance <= brush_radius_sq;
432 if (first_point_in_stroke_bpi == brush_projection_info_slice.
end()) {
436 const int first_point_in_stroke = std::distance(brush_projection_info_slice.
begin(),
437 first_point_in_stroke_bpi);
445 points.
begin(), points.
end(), [&](
const int point_i) {
446 const BrushProjectionInfo &bpi = brush_projection_info[point_i];
447 if (bpi.distance > brush_radius_sq) {
452 if (point_to_cut_iter == points.end()) {
455 const int point_to_cut = std::distance(points.begin(), point_to_cut_iter);
457 if (point_to_cut == 0) {
459 r_curves_to_keep[curve_i] =
false;
461 else if (first_point_in_stroke == point_to_cut) {
464 const int current_point = points[point_to_cut];
465 const int previous_point = points[point_to_cut - 1];
491 const float boundary_length =
math::distance(curr_pos_cu, boundary_cu);
492 r_ends[curve_i] = segment_lengths[current_point] - boundary_length;
496 const int previous_point = points[point_to_cut - 1];
497 r_ends[curve_i] = segment_lengths[previous_point];
508 executor.
execute(*
this, stroke_extension);
513 return std::make_unique<CutOperation>();
#define BLI_assert_unreachable()
Span< T > as_span() const
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
static IndexMask from_bools_inverse(Span< bool > bools, LinearAllocator<> &memory)
constexpr Iterator end() const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr Iterator begin() const
constexpr IndexRange index_range() const
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T * end() const
constexpr const T * begin() const
static VArray from_single(T value, const int64_t size)
static VArray from_span(Span< T > values)
IndexRange index_range() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
VArray< bool > cyclic() const
AttributeAccessor attributes() const
Span< float3 > positions() const
OffsetIndices< int > points_by_curve() const
const Depsgraph * depsgraph
void on_stroke_extended(const PaintStroke &stroke, const StrokeExtension &stroke_extension) override
friend struct CutOperationExecutor
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
float distance(float, float) RET
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
CurvesGeometry curves_copy_curve_selection(const CurvesGeometry &curves, const IndexMask &curves_to_copy, const AttributeFilter &attribute_filter)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
void report_cyclic_not_supported(ReportList *reports)
float brush_strength_get(const Paint &paint, const Brush &brush, const StrokeExtension &stroke_extension)
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)
void remember_stroke_position(CurvesSculpt &curves_sculpt, const float3 &brush_position_wo)
std::unique_ptr< CurvesSculptStrokeOperation > new_cut_operation()
Vector< float4x4 > get_symmetry_brush_transforms(const eCurvesSymmetryType symmetry)
float brush_radius_factor(const Brush &brush, const StrokeExtension &stroke_extension)
constexpr ParallelGrainSize grain_size(int grain_size)
bke::CurvesGeometry trim_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const VArray< float > &starts, const VArray< float > &ends, GeometryNodeCurveSampleMode mode, const bke::AttributeFilter &attribute_filter)
T distance(const T &a, const T &b)
T dot(const QuaternionBase< T > &a, const QuaternionBase< 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_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
uint32_t hash_float(float kx)
uint32_t hash(uint32_t kx)
float hash_to_float(uint32_t kx)
void WM_main_add_notifier(uint type, void *reference)
unsigned __int64 uint64_t
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
float2 ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], const float4x4 &mat)
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)
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])
@ GEO_NODE_CURVE_SAMPLE_LENGTH
eBrushFalloffShape falloff_shape
struct ToolSettings * toolsettings
constexpr uint64_t hash() const
int brush_transform_index
bool should_point_be_cut(const int point_i, const uint32_t stroke_hash)
float brush_radius_base_re_
void find_projected_points_in_stroke_with_symmetry(MutableSpan< BrushProjectionInfo > r_brush_projection_info)
CutOperationExecutor(const PaintStroke &stroke)
float3 find_projected_cut_boundary(const float3 &point_outside_cu, const float3 &point_inside_cu, const float2 &brush_pos_re, const float brush_radius_re, const float4x4 &transform_cu_to_re)
void find_spherical_points_in_stroke_with_symmetry(MutableSpan< BrushProjectionInfo > r_brush_projection_info)
VArray< float > point_factors_
IndexMaskMemory selected_curve_memory_
float intersect_line_segment_sphere_2d(const float2 &line_segment_start, const float2 &line_segment_end, const float2 &sphere_position, const float sphere_radius)
IndexMask curve_selection_
void find_spherical_points_in_stroke(const int brush_transform_index, const float3 &brush_pos_cu, MutableSpan< BrushProjectionInfo > r_brush_projection_info)
void cut_curves(const Span< BrushProjectionInfo > brush_projection_info, MutableSpan< bool > r_curves_to_keep, MutableSpan< float > r_ends)
void find_projected_points_in_stroke(const float4x4 &brush_transform_inv, const int brush_transform_index, MutableSpan< BrushProjectionInfo > r_brush_projection_info)
void execute(CutOperation &self, const StrokeExtension &stroke_extension)
CurvesSurfaceTransforms transforms_
CurvesSculpt * curves_sculpt_
float3 find_spherical_cut_boundary(const float3 &point_outside_cu, const float3 &point_inside_cu, const float3 &brush_pos_cu, const float brush_radius_cu)
float brush_radius_factor_
CurvesSculptCommonContext ctx_