Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #include <algorithm> | #include <algorithm> | ||||
| #include <numeric> | #include <numeric> | ||||
| #include "BLI_memory_utils.hh" | #include "BLI_memory_utils.hh" | ||||
| #include "BLI_task.hh" | #include "BLI_task.hh" | ||||
| #include "DNA_brush_types.h" | #include "DNA_brush_types.h" | ||||
| #include "BKE_attribute.hh" | |||||
| #include "BKE_brush.h" | #include "BKE_brush.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curves.hh" | #include "BKE_curves.hh" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| Show All 33 Lines | |||||
| struct SelectionPaintOperationExecutor { | struct SelectionPaintOperationExecutor { | ||||
| SelectionPaintOperation *self_ = nullptr; | SelectionPaintOperation *self_ = nullptr; | ||||
| CurvesSculptCommonContext ctx_; | CurvesSculptCommonContext ctx_; | ||||
| Object *object_ = nullptr; | Object *object_ = nullptr; | ||||
| Curves *curves_id_ = nullptr; | Curves *curves_id_ = nullptr; | ||||
| CurvesGeometry *curves_ = nullptr; | CurvesGeometry *curves_ = nullptr; | ||||
| bke::SpanAttributeWriter<float> selection_; | |||||
| const Brush *brush_ = nullptr; | const Brush *brush_ = nullptr; | ||||
| float brush_radius_base_re_; | float brush_radius_base_re_; | ||||
| float brush_radius_factor_; | float brush_radius_factor_; | ||||
| float brush_strength_; | float brush_strength_; | ||||
| float selection_goal_; | float selection_goal_; | ||||
| float2 brush_pos_re_; | float2 brush_pos_re_; | ||||
| Show All 11 Lines | void execute(SelectionPaintOperation &self, | ||||
| self_ = &self; | self_ = &self; | ||||
| object_ = CTX_data_active_object(&C); | object_ = CTX_data_active_object(&C); | ||||
| curves_id_ = static_cast<Curves *>(object_->data); | curves_id_ = static_cast<Curves *>(object_->data); | ||||
| curves_ = &CurvesGeometry::wrap(curves_id_->geometry); | curves_ = &CurvesGeometry::wrap(curves_id_->geometry); | ||||
| if (curves_->curves_num() == 0) { | if (curves_->curves_num() == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| selection_ = float_selection_ensure(*curves_id_); | |||||
| if (!selection_) { | |||||
| return; | |||||
| } | |||||
| brush_ = BKE_paint_brush_for_read(&ctx_.scene->toolsettings->curves_sculpt->paint); | brush_ = BKE_paint_brush_for_read(&ctx_.scene->toolsettings->curves_sculpt->paint); | ||||
| brush_radius_base_re_ = BKE_brush_size_get(ctx_.scene, brush_); | brush_radius_base_re_ = BKE_brush_size_get(ctx_.scene, brush_); | ||||
| brush_radius_factor_ = brush_radius_factor(*brush_, stroke_extension); | brush_radius_factor_ = brush_radius_factor(*brush_, stroke_extension); | ||||
| brush_strength_ = BKE_brush_alpha_get(ctx_.scene, brush_); | brush_strength_ = BKE_brush_alpha_get(ctx_.scene, brush_); | ||||
| brush_pos_re_ = stroke_extension.mouse_position; | brush_pos_re_ = stroke_extension.mouse_position; | ||||
| if (self.clear_selection_) { | if (self.clear_selection_) { | ||||
| if (stroke_extension.is_first) { | if (stroke_extension.is_first) { | ||||
| if (curves_id_->selection_domain == ATTR_DOMAIN_POINT) { | curves::fill_selection_false(selection_.span); | ||||
| curves_->selection_point_float_for_write().fill(0.0f); | |||||
| } | |||||
| else if (curves_id_->selection_domain == ATTR_DOMAIN_CURVE) { | |||||
| curves_->selection_curve_float_for_write().fill(0.0f); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); | transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); | ||||
| const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>( | const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>( | ||||
| brush_->falloff_shape); | brush_->falloff_shape); | ||||
| selection_goal_ = self_->use_select_ ? 1.0f : 0.0f; | selection_goal_ = self_->use_select_ ? 1.0f : 0.0f; | ||||
| if (stroke_extension.is_first) { | if (stroke_extension.is_first) { | ||||
| if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { | if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { | ||||
| this->initialize_spherical_brush_reference_point(); | this->initialize_spherical_brush_reference_point(); | ||||
| } | } | ||||
| } | } | ||||
| if (curves_id_->selection_domain == ATTR_DOMAIN_POINT) { | if (selection_.domain == ATTR_DOMAIN_POINT) { | ||||
| MutableSpan<float> selection = curves_->selection_point_float_for_write(); | |||||
| if (falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | if (falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | ||||
| this->paint_point_selection_projected_with_symmetry(selection); | this->paint_point_selection_projected_with_symmetry(selection_.span); | ||||
| } | } | ||||
| else if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { | else if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { | ||||
| this->paint_point_selection_spherical_with_symmetry(selection); | this->paint_point_selection_spherical_with_symmetry(selection_.span); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| MutableSpan<float> selection = curves_->selection_curve_float_for_write(); | |||||
| if (falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | if (falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | ||||
| this->paint_curve_selection_projected_with_symmetry(selection); | this->paint_curve_selection_projected_with_symmetry(selection_.span); | ||||
| } | } | ||||
| else if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { | else if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { | ||||
| this->paint_curve_selection_spherical_with_symmetry(selection); | this->paint_curve_selection_spherical_with_symmetry(selection_.span); | ||||
| } | } | ||||
| } | } | ||||
| selection_.finish(); | |||||
| /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because | /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because | ||||
| * selection is handled as a generic attribute for now. */ | * selection is handled as a generic attribute for now. */ | ||||
| DEG_id_tag_update(&curves_id_->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&curves_id_->id, ID_RECALC_GEOMETRY); | ||||
| WM_main_add_notifier(NC_GEOM | ND_DATA, &curves_id_->id); | WM_main_add_notifier(NC_GEOM | ND_DATA, &curves_id_->id); | ||||
| ctx_.rv3d->rflag &= ~RV3D_PAINTING; | ctx_.rv3d->rflag &= ~RV3D_PAINTING; | ||||
| ED_region_tag_redraw(ctx_.region); | ED_region_tag_redraw(ctx_.region); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 254 Lines • Show Last 20 Lines | |||||