58 float2 last_mouse_position_re_;
144 if (brush_3d.has_value()) {
145 self_->brush_3d_ = *brush_3d;
171 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
188 const float brush_radius_sq_re =
pow2f(brush_radius_re);
191 for (const int curve_i : curves_range) {
192 const IndexRange points = curves_->points_for_curve(curve_i);
193 const int last_point_i = points.last();
194 const float3 old_pos_cu = deformation.positions[last_point_i];
195 const float3 old_symm_pos_cu = brush_transform_inv * old_pos_cu;
197 float2 old_symm_pos_re;
198 ED_view3d_project_float_v2_m4(
199 ctx_.region, old_symm_pos_cu, old_symm_pos_re, projection.values);
201 const float distance_to_brush_sq_re = math::distance_squared(old_symm_pos_re,
203 if (distance_to_brush_sq_re > brush_radius_sq_re) {
207 const float radius_falloff = BKE_brush_curve_strength(
208 brush_, std::sqrt(distance_to_brush_sq_re), brush_radius_re);
209 const float weight = brush_strength_ * radius_falloff * curve_factors_[curve_i];
211 const float2 new_symm_pos_re = old_symm_pos_re + brush_pos_diff_re_ * weight;
212 float3 new_symm_pos_wo;
213 ED_view3d_win_to_3d(ctx_.v3d,
215 transforms_.curves_to_world * old_symm_pos_cu,
218 const float3 new_pos_cu = brush_transform *
219 (transforms_.world_to_curves * new_symm_pos_wo);
220 const float3 translation_eval = new_pos_cu - old_pos_cu;
221 const float3 translation_orig = deformation.translation_from_deformed_to_original(
222 last_point_i, translation_eval);
224 move_last_point_and_resample(positions_cu.slice(points),
225 positions_cu[last_point_i] + translation_orig);
235 float3 brush_start_wo, brush_end_wo;
238 transforms_.curves_to_world * self_->brush_3d_.position_cu,
243 transforms_.curves_to_world * self_->brush_3d_.position_cu,
246 const float3 brush_start_cu = transforms_.world_to_curves * brush_start_wo;
247 const float3 brush_end_cu = transforms_.world_to_curves * brush_end_wo;
249 const float brush_radius_cu = self_->brush_3d_.radius_cu * brush_radius_factor_;
253 for (
const float4x4 &brush_transform : symmetry_brush_transforms) {
254 this->spherical_snake_hook(
255 brush_transform * brush_start_cu, brush_transform * brush_end_cu, brush_radius_cu);
260 const float3 &brush_end_cu,
261 const float brush_radius_cu)
267 const float3 brush_diff_cu = brush_end_cu - brush_start_cu;
268 const float brush_radius_sq_cu =
pow2f(brush_radius_cu);
271 for (const int curve_i : curves_range) {
272 const IndexRange points = curves_->points_for_curve(curve_i);
273 const int last_point_i = points.last();
274 const float3 old_pos_cu = deformation.positions[last_point_i];
276 const float distance_to_brush_sq_cu = dist_squared_to_line_segment_v3(
277 old_pos_cu, brush_start_cu, brush_end_cu);
278 if (distance_to_brush_sq_cu > brush_radius_sq_cu) {
282 const float distance_to_brush_cu = std::sqrt(distance_to_brush_sq_cu);
284 const float radius_falloff = BKE_brush_curve_strength(
285 brush_, distance_to_brush_cu, brush_radius_cu);
286 const float weight = brush_strength_ * radius_falloff * curve_factors_[curve_i];
288 const float3 translation_eval = weight * brush_diff_cu;
289 const float3 translation_orig = deformation.translation_from_deformed_to_original(
290 last_point_i, translation_eval);
292 move_last_point_and_resample(positions_cu.slice(points),
293 positions_cu[last_point_i] + translation_orig);
299 void SnakeHookOperation::on_stroke_extended(
const bContext &
C,
303 executor.execute(*
this,
C, stroke_extension);
308 return std::make_unique<SnakeHookOperation>();
int BKE_brush_size_get(const struct Scene *scene, const struct Brush *brush)
struct Object * CTX_data_active_object(const bContext *C)
Low-level operations for curves.
const struct Brush * BKE_paint_brush_for_read(const struct Paint *p)
#define BLI_assert_unreachable()
A KD-tree for nearest neighbor search.
MINLINE float pow2f(float x)
#define BLI_SCOPED_DEFER(function_to_defer)
void DEG_id_tag_update(struct ID *id, int flag)
@ PAINT_FALLOFF_SHAPE_SPHERE
@ PAINT_FALLOFF_SHAPE_TUBE
struct CurvesGeometry CurvesGeometry
Object is a sort of wrapper for general info.
void ED_region_tag_redraw(struct ARegion *region)
void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, const struct Object *ob, float r_pmat[4][4])
void ED_view3d_win_to_3d(const struct View3D *v3d, const struct ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
Platform independent time functions.
MutableSpan< float3 > positions_for_write()
IndexRange curves_range() const
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
void tag_positions_changed()
const Depsgraph * depsgraph
void on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) override
GeometryDeformation get_evaluated_curves_deformation(const Depsgraph &depsgraph, const Object &ob_orig)
VArray< float > get_curves_selection(const Curves &curves_id)
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)
std::unique_ptr< CurvesSculptStrokeOperation > new_snake_hook_operation()
static IndexMask retrieve_selected_curves(const CurvesGeometry &curves, const eAttrDomain domain, Vector< int64_t > &r_indices)
float brush_strength_get(const Scene &scene, const Brush &brush, const StrokeExtension &stroke_extension)
Vector< float4x4 > get_symmetry_brush_transforms(const eCurvesSymmetryType symmetry)
float brush_radius_factor(const Brush &brush, const StrokeExtension &stroke_extension)
void parallel_for(IndexRange range, int64_t grain_size, const Function &function)
struct ToolSettings * toolsettings
SnakeHookOperatorExecutor(const bContext &C)
void spherical_snake_hook(const float3 &brush_start_cu, const float3 &brush_end_cu, const float brush_radius_cu)
void spherical_snake_hook_with_symmetry()
void execute(SnakeHookOperation &self, const bContext &C, const StrokeExtension &stroke_extension)
const CurvesSculpt * curves_sculpt_
void projected_snake_hook_with_symmetry()
CurvesSculptCommonContext ctx_
IndexMask curve_selection_
SnakeHookOperation * self_
eBrushFalloffShape falloff_shape_
Vector< int64_t > selected_curve_indices_
VArray< float > curve_factors_
float brush_radius_base_re_
float2 brush_pos_diff_re_
void projected_snake_hook(const float4x4 &brush_transform)
float brush_radius_factor_
CurvesSurfaceTransforms transforms_
float2 brush_pos_prev_re_
float4x4 inverted() const
void WM_main_add_notifier(unsigned int type, void *reference)