40using geometry::ReverseUVSampler;
62 float2 initial_brush_pos_re_;
142 "Curves do not have surface attachment information");
236 if (!brush_3d.has_value()) {
249 const float brush_radius_sq_cu =
pow2f(brush_3d->radius_cu);
252 for (
const int brush_i : brush_transforms.
index_range()) {
254 brush_3d->position_cu);
256 for (
const int curve_i : segment) {
257 const int first_point_i = offsets[curve_i];
258 const float3 old_pos_cu =
self_->initial_deformed_positions_cu_[first_point_i];
261 if (dist_sq <= brush_radius_sq_cu && dist_sq < min_dist_sq[curve_i]) {
262 min_dist_sq[curve_i] = dist_sq;
263 best_brush[curve_i] = brush_i;
270 for (
const int brush_i : brush_transforms.
index_range()) {
271 self_->slide_info_.append_as();
277 reverse_uv_sampler_orig,
285 const float brush_radius_cu,
295 for (
const int curve_i : segment) {
297 if (best_brush[curve_i] != brush_i) {
301 const int first_point_i = offsets[curve_i];
302 const float3 old_pos_cu =
self_->initial_deformed_positions_cu_[first_point_i];
305 const float dist_to_brush_cu =
math::distance(old_pos_cu, brush_pos_cu);
307 brush_, dist_to_brush_cu, brush_radius_cu);
309 const float2 uv = surface_uv_coords[curve_i];
311 if (
result.type != ReverseUVSampler::ResultType::Ok) {
324 r_curves_to_slide.
append({curve_i, radius_falloff, normal_cu});
361 for (const SlideCurveInfo &slide_curve_info : slide_curves.slice(range)) {
362 const int curve_i = slide_curve_info.curve_i;
363 const IndexRange points = points_by_curve[curve_i];
364 const int first_point_i = points[0];
366 const float3 old_first_pos_eval_cu = self_->initial_deformed_positions_cu_[first_point_i];
367 const float3 old_first_symm_pos_eval_cu = math::transform_point(brush_transform_inv,
368 old_first_pos_eval_cu);
369 const float3 old_first_pos_eval_su = math::transform_point(transforms_.curves_to_surface,
370 old_first_pos_eval_cu);
372 const float2 old_first_symm_pos_eval_re = ED_view3d_project_float_v2_m4(
373 ctx_.region, old_first_symm_pos_eval_cu, projection);
375 const float radius_falloff = slide_curve_info.radius_falloff;
376 const float curve_weight = brush_strength_ * radius_falloff * curve_factors_[curve_i];
377 const float2 new_first_symm_pos_eval_re = old_first_symm_pos_eval_re +
378 curve_weight * brush_pos_diff_re;
381 float3 ray_start_wo, ray_end_wo;
382 ED_view3d_win_to_segment_clipped(ctx_.depsgraph,
385 new_first_symm_pos_eval_re,
389 const float3 ray_start_su = math::transform_point(world_to_surface_with_symmetry_mat,
391 const float3 ray_end_su = math::transform_point(world_to_surface_with_symmetry_mat,
393 const float3 ray_direction_su = math::normalize(ray_end_su - ray_start_su);
397 float3 hit_pos_eval_su;
398 if (!this->find_closest_ray_hit(ray_start_su,
400 old_first_pos_eval_su,
408 const int3 &tri_eval = surface_corner_tris_eval_[tri_index_eval];
409 const float3 bary_weights_eval = bke::mesh_surface_sample::compute_bary_coord_in_triangle(
410 surface_positions_eval_, surface_corner_verts_eval_, tri_eval, hit_pos_eval_su);
411 const float2 uv = bke::attribute_math::mix3(bary_weights_eval,
412 surface_uv_map_eval_[tri_eval[0]],
413 surface_uv_map_eval_[tri_eval[1]],
414 surface_uv_map_eval_[tri_eval[2]]);
417 const ReverseUVSampler::Result result = reverse_uv_sampler_orig.sample(uv);
418 if (result.type != ReverseUVSampler::ResultType::Ok) {
419 found_invalid_uv_mapping_.store(true);
422 const int3 &tri_orig = surface_corner_tris_orig_[result.tri_index];
423 const float3 &bary_weights_orig = result.bary_weights;
426 const float3 &initial_normal_cu = slide_curve_info.initial_normal_cu;
427 const float3 new_normal_cu = math::normalize(
428 math::transform_point(transforms_.surface_to_curves_normal,
429 geometry::compute_surface_point_normal(
430 tri_orig, result.bary_weights, corner_normals_orig_su_)));
433 const float3 new_first_pos_orig_su = bke::attribute_math::mix3<float3>(
435 positions_orig_su[corner_verts_orig[tri_orig[0]]],
436 positions_orig_su[corner_verts_orig[tri_orig[1]]],
437 positions_orig_su[corner_verts_orig[tri_orig[2]]]);
438 const float3 old_first_pos_orig_cu = self_->initial_positions_cu_[first_point_i];
439 const float3 new_first_pos_orig_cu = math::transform_point(transforms_.surface_to_curves,
440 new_first_pos_orig_su);
443 const float4x4 slide_transform = this->get_slide_transform(
444 old_first_pos_orig_cu, new_first_pos_orig_cu, initial_normal_cu, new_normal_cu);
445 for (const int point_i : points) {
446 positions_orig_cu[point_i] = math::transform_point(
447 slide_transform, self_->initial_positions_cu_[point_i]);
449 surface_uv_coords[curve_i] = uv;
455 const float3 &ray_direction_su,
460 float best_dist_sq_su =
FLT_MAX;
461 int best_tri_index_eval;
467 if (dist_sq_su < best_dist_sq_su) {
468 best_dist_sq_su = dist_sq_su;
469 best_hit_pos_su = hit_pos_su;
470 best_tri_index_eval = hit.
index;
474 if (best_dist_sq_su ==
FLT_MAX) {
477 r_tri_index = best_tri_index_eval;
478 r_hit_pos = best_hit_pos_su;
483 const float3 &new_root_pos,
502 executor.
execute(*
this, stroke_extension);
507 return std::make_unique<SlideOperation>();
Low-level operations for curves.
General operations, lookup, etc. for blender objects.
constexpr IndexRange index_range() const
void append(const T &value)
IndexRange index_range() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
MutableSpan< float3 > positions_for_write()
AttributeAccessor attributes() const
Span< float3 > positions() const
MutableSpan< float2 > surface_uv_coords_for_write()
std::optional< Span< float2 > > surface_uv_coords() const
Span< int > offsets() const
void tag_positions_changed()
OffsetIndices< int > points_by_curve() const
constexpr bool is_empty() const
const Depsgraph * depsgraph
void on_stroke_extended(const PaintStroke &stroke, const StrokeExtension &stroke_extension) override
friend struct SlideOperationExecutor
Result sample(const float2 &query_uv) const
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
void report_empty_evaluated_surface(ReportList *reports)
std::optional< CurvesBrush3D > sample_curves_surface_3d_brush(const Depsgraph &depsgraph, const ARegion ®ion, const View3D &v3d, const CurvesSurfaceTransforms &transforms, const bke::bvh::Tree &surface_bvh, const float2 &brush_pos_re, const float brush_radius_re)
void report_missing_uv_map_on_original_surface(ReportList *reports)
void remember_stroke_position(CurvesSculpt &curves_sculpt, const float3 &brush_position_wo)
void report_missing_uv_map_on_evaluated_surface(ReportList *reports)
void report_missing_surface(ReportList *reports)
void report_empty_original_surface(ReportList *reports)
Vector< float4x4 > get_symmetry_brush_transforms(const eCurvesSymmetryType symmetry)
std::unique_ptr< CurvesSculptStrokeOperation > new_slide_operation()
float brush_radius_factor(const Brush &brush, const StrokeExtension &stroke_extension)
float3 compute_surface_point_normal(const int3 &tri, const float3 &bary_coord, Span< float3 > corner_normals)
T distance(const T &a, const T &b)
CartesianBasis invert(const CartesianBasis &basis)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
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)
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)
void BKE_report(ReportList *reports, eReportType type, const char *message)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
float BKE_brush_curve_strength(eBrushCurvePreset preset, const CurveMapping *cumap, float distance, float brush_radius)
MatBase< float, 3, 3 > float3x3
const Brush * BKE_paint_brush_for_read(const Paint *paint)
VecBase< float, 3 > float3
void rotation_between_vecs_to_mat3(float m[3][3], const float v1[3], const float v2[3])
float BKE_brush_alpha_get(const Paint *paint, const Brush *brush)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
const c_style_mat & ptr() const
static MatBase identity()
struct ToolSettings * toolsettings
float3 position(const Ray &ray) const
Vector< SlideCurveInfo > curves_to_slide
const Mesh * surface_orig_
const bke::bvh::Tree * surface_bvh_eval_
CurvesSurfaceTransforms transforms_
VArraySpan< float2 > surface_uv_map_orig_
void execute(SlideOperation &self, const StrokeExtension &stroke_extension)
VArraySpan< float2 > surface_uv_map_eval_
IndexMaskMemory selected_curve_memory_
void find_curves_to_slide_with_symmetry()
Span< float3 > corner_normals_orig_su_
Object * surface_ob_orig_
Span< int3 > surface_corner_tris_eval_
CurvesSculptCommonContext ctx_
Span< float3 > surface_positions_eval_
Span< int > surface_corner_verts_eval_
VArray< float > curve_factors_
CurvesSculpt * curves_sculpt_
void slide(const Span< SlideCurveInfo > slide_curves, const ReverseUVSampler &reverse_uv_sampler_orig, const float4x4 &brush_transform)
float brush_radius_factor_
bool find_closest_ray_hit(const float3 &ray_start_su, const float3 &ray_direction_su, const float3 &point_su, int &r_tri_index, float3 &r_hit_pos)
SlideOperationExecutor(const PaintStroke &stroke)
void slide_with_symmetry()
std::atomic< bool > found_invalid_uv_mapping_
void find_curves_to_slide(const float3 &brush_pos_cu, const float brush_radius_cu, const ReverseUVSampler &reverse_uv_sampler_orig, Vector< SlideCurveInfo > &r_curves_to_slide, const Span< int > best_brush, const int brush_i)
Span< int3 > surface_corner_tris_orig_
float4x4 get_slide_transform(const float3 &old_root_pos, const float3 &new_root_pos, const float3 &old_normal, const float3 &new_normal)
float brush_radius_base_re_
CurvesGeometry * curves_orig_
IndexMask curve_selection_
Object * surface_ob_eval_