Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/curves_sculpt_delete.cc
| Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | private: | ||||
| CurvesBrush3D brush_3d_; | CurvesBrush3D brush_3d_; | ||||
| friend struct DeleteOperationExecutor; | friend struct DeleteOperationExecutor; | ||||
| public: | public: | ||||
| void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) override; | void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) override; | ||||
| }; | }; | ||||
| static float segments_distance_sq(const float3 &a_1, | |||||
| const float3 &a_2, | |||||
| const float3 &b_1, | |||||
| const float3 &b_2) | |||||
| { | |||||
| float3 closest_a, closest_b; | |||||
| isect_seg_seg_v3(b_1, b_2, a_1, a_2, closest_a, closest_b); | |||||
| return math::distance_squared(closest_a, closest_b); | |||||
| } | |||||
| struct DeleteOperationExecutor { | struct DeleteOperationExecutor { | ||||
| DeleteOperation *self_ = nullptr; | DeleteOperation *self_ = nullptr; | ||||
| bContext *C_ = nullptr; | bContext *C_ = nullptr; | ||||
| Depsgraph *depsgraph_ = nullptr; | Depsgraph *depsgraph_ = nullptr; | ||||
| Scene *scene_ = nullptr; | Scene *scene_ = nullptr; | ||||
| Object *object_ = nullptr; | Object *object_ = nullptr; | ||||
| ARegion *region_ = nullptr; | ARegion *region_ = nullptr; | ||||
| View3D *v3d_ = nullptr; | View3D *v3d_ = nullptr; | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | struct DeleteOperationExecutor { | ||||
| { | { | ||||
| const float4x4 brush_transform_inv = brush_transform.inverted(); | const float4x4 brush_transform_inv = brush_transform.inverted(); | ||||
| float4x4 projection; | float4x4 projection; | ||||
| ED_view3d_ob_project_mat_get(rv3d_, object_, projection.values); | ED_view3d_ob_project_mat_get(rv3d_, object_, projection.values); | ||||
| Span<float3> positions_cu = curves_->positions(); | Span<float3> positions_cu = curves_->positions(); | ||||
| const float brush_radius_sq_re = pow2f(brush_radius_re_); | |||||
| threading::parallel_for(curves_->curves_range(), 512, [&](IndexRange curve_range) { | threading::parallel_for(curves_->curves_range(), 512, [&](IndexRange curve_range) { | ||||
| for (const int curve_i : curve_range) { | for (const int curve_i : curve_range) { | ||||
| const IndexRange points = curves_->points_for_curve(curve_i); | const IndexRange points = curves_->points_for_curve(curve_i); | ||||
| if (points.size() == 1) { | |||||
| const float3 pos_cu = brush_transform_inv * positions_cu[points.first()]; | |||||
| float2 pos_re; | |||||
| ED_view3d_project_float_v2_m4(region_, pos_cu, pos_re, projection.values); | |||||
| if (math::distance_squared(brush_pos_re_, pos_re) < brush_radius_sq_re) { | |||||
| curves_to_delete[curve_i] = true; | |||||
| } | |||||
| continue; | |||||
| } | |||||
| for (const int segment_i : IndexRange(points.size() - 1)) { | for (const int segment_i : IndexRange(points.size() - 1)) { | ||||
| const float3 pos1_cu = brush_transform_inv * positions_cu[points[segment_i]]; | const float3 pos1_cu = brush_transform_inv * positions_cu[points[segment_i]]; | ||||
| const float3 pos2_cu = brush_transform_inv * positions_cu[points[segment_i + 1]]; | const float3 pos2_cu = brush_transform_inv * positions_cu[points[segment_i + 1]]; | ||||
| float2 pos1_re, pos2_re; | float2 pos1_re, pos2_re; | ||||
| ED_view3d_project_float_v2_m4(region_, pos1_cu, pos1_re, projection.values); | ED_view3d_project_float_v2_m4(region_, pos1_cu, pos1_re, projection.values); | ||||
| ED_view3d_project_float_v2_m4(region_, pos2_cu, pos2_re, projection.values); | ED_view3d_project_float_v2_m4(region_, pos2_cu, pos2_re, projection.values); | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | void delete_spherical(MutableSpan<bool> curves_to_delete, | ||||
| Span<float3> positions_cu = curves_->positions(); | Span<float3> positions_cu = curves_->positions(); | ||||
| const float brush_radius_cu = self_->brush_3d_.radius_cu; | const float brush_radius_cu = self_->brush_3d_.radius_cu; | ||||
| const float brush_radius_sq_cu = pow2f(brush_radius_cu); | const float brush_radius_sq_cu = pow2f(brush_radius_cu); | ||||
| threading::parallel_for(curves_->curves_range(), 512, [&](IndexRange curve_range) { | threading::parallel_for(curves_->curves_range(), 512, [&](IndexRange curve_range) { | ||||
| for (const int curve_i : curve_range) { | for (const int curve_i : curve_range) { | ||||
| const IndexRange points = curves_->points_for_curve(curve_i); | const IndexRange points = curves_->points_for_curve(curve_i); | ||||
| for (const int segment_i : IndexRange(points.size() - 1)) { | |||||
| const float3 pos1_cu = positions_cu[points[segment_i]]; | |||||
| const float3 pos2_cu = positions_cu[points[segment_i] + 1]; | |||||
| float3 closest_segment_cu, closest_brush_cu; | if (points.size() == 1) { | ||||
| isect_seg_seg_v3(pos1_cu, | const float3 &pos_cu = positions_cu[points.first()]; | ||||
| pos2_cu, | const float distance_sq_cu = segments_distance_sq( | ||||
| brush_start_cu, | pos_cu, pos_cu, brush_start_cu, brush_end_cu); | ||||
| brush_end_cu, | if (distance_sq_cu < brush_radius_sq_cu) { | ||||
| closest_segment_cu, | curves_to_delete[curve_i] = true; | ||||
| closest_brush_cu); | } | ||||
| const float distance_to_brush_sq_cu = math::distance_squared(closest_segment_cu, | |||||
| closest_brush_cu); | |||||
| if (distance_to_brush_sq_cu > brush_radius_sq_cu) { | |||||
| continue; | continue; | ||||
| } | } | ||||
| for (const int segment_i : IndexRange(points.size() - 1)) { | |||||
| const float distance_sq_cu = segments_distance_sq(positions_cu[points[segment_i]], | |||||
| positions_cu[points[segment_i] + 1], | |||||
| brush_start_cu, | |||||
| brush_end_cu); | |||||
| if (distance_sq_cu < brush_radius_sq_cu) { | |||||
| curves_to_delete[curve_i] = true; | curves_to_delete[curve_i] = true; | ||||
| break; | break; | ||||
JacquesLucke: Why is this removed? | |||||
Done Inline ActionsErr, not sure, thanks for catching that. HooglyBoogly: Err, not sure, thanks for catching that. | |||||
| } | } | ||||
| } | } | ||||
| } | |||||
| }); | }); | ||||
| } | } | ||||
| void initialize_spherical_brush_reference_point() | void initialize_spherical_brush_reference_point() | ||||
| { | { | ||||
| std::optional<CurvesBrush3D> brush_3d = sample_curves_3d_brush( | std::optional<CurvesBrush3D> brush_3d = sample_curves_3d_brush( | ||||
| *C_, *object_, brush_pos_re_, brush_radius_re_); | *C_, *object_, brush_pos_re_, brush_radius_re_); | ||||
| if (brush_3d.has_value()) { | if (brush_3d.has_value()) { | ||||
| Show All 17 Lines | |||||
Why is this removed?