Blender V4.5
curves_sculpt_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include <algorithm>
6
7#include "BLI_kdtree.h"
8#include "BLI_listbase.h"
9#include "BLI_rand.hh"
10#include "BLI_task.hh"
11#include "BLI_utildefines.h"
12#include "BLI_vector_set.hh"
13
14#include "BKE_attribute.hh"
15#include "BKE_brush.hh"
16#include "BKE_bvhutils.hh"
17#include "BKE_context.hh"
18#include "BKE_curves.hh"
19#include "BKE_modifier.hh"
20#include "BKE_object.hh"
21#include "BKE_paint.hh"
22
23#include "BLT_translation.hh"
24
25#include "WM_api.hh"
26#include "WM_message.hh"
27#include "WM_toolsystem.hh"
28
29#include "ED_curves.hh"
30#include "ED_curves_sculpt.hh"
31#include "ED_image.hh"
32#include "ED_object.hh"
33#include "ED_screen.hh"
34#include "ED_space_api.hh"
35#include "ED_view3d.hh"
36
37#include "DEG_depsgraph.hh"
39
40#include "DNA_brush_types.h"
41#include "DNA_curves_types.h"
42#include "DNA_mesh_types.h"
43#include "DNA_screen_types.h"
44
45#include "RNA_access.hh"
46#include "RNA_define.hh"
47#include "RNA_enum_types.hh"
48
50#include "paint_intern.hh"
51
52#include "UI_interface.hh"
53#include "UI_resources.hh"
54
55#include "GPU_immediate.hh"
56#include "GPU_immediate_util.hh"
57#include "GPU_matrix.hh"
58#include "GPU_state.hh"
59
61
62/* -------------------------------------------------------------------- */
65
67{
68 const Object *ob = CTX_data_active_object(C);
69 return ob && ob->mode & OB_MODE_SCULPT_CURVES;
70}
71
73{
74 if (!curves_sculpt_poll(C)) {
75 return false;
76 }
77 if (CTX_wm_region_view3d(C) == nullptr) {
78 return false;
79 }
80 return true;
81}
82
84
85/* -------------------------------------------------------------------- */
88
89float brush_radius_factor(const Brush &brush, const StrokeExtension &stroke_extension)
90{
91 if (BKE_brush_use_size_pressure(&brush)) {
92 return stroke_extension.pressure;
93 }
94 return 1.0f;
95}
96
97float brush_radius_get(const Scene &scene,
98 const Brush &brush,
99 const StrokeExtension &stroke_extension)
100{
101 return BKE_brush_size_get(&scene, &brush) * brush_radius_factor(brush, stroke_extension);
102}
103
104float brush_strength_factor(const Brush &brush, const StrokeExtension &stroke_extension)
105{
106 if (BKE_brush_use_alpha_pressure(&brush)) {
107 return stroke_extension.pressure;
108 }
109 return 1.0f;
110}
111
112float brush_strength_get(const Scene &scene,
113 const Brush &brush,
114 const StrokeExtension &stroke_extension)
115{
116 return BKE_brush_alpha_get(&scene, &brush) * brush_strength_factor(brush, stroke_extension);
117}
118
119static std::unique_ptr<CurvesSculptStrokeOperation> start_brush_operation(
120 bContext &C, wmOperator &op, const StrokeExtension &stroke_start)
121{
122 const BrushStrokeMode mode = BrushStrokeMode(RNA_enum_get(op.ptr, "mode"));
123
124 const Scene &scene = *CTX_data_scene(&C);
125 const CurvesSculpt &curves_sculpt = *scene.toolsettings->curves_sculpt;
126 const Brush &brush = *BKE_paint_brush_for_read(&curves_sculpt.paint);
127 switch (brush.curves_sculpt_brush_type) {
129 return new_comb_operation();
131 return new_delete_operation();
135 return new_add_operation();
137 return new_grow_shrink_operation(mode, C);
139 return new_selection_paint_operation(mode, C);
141 return new_pinch_operation(mode, C);
143 return new_smooth_operation();
145 return new_puff_operation();
147 return new_density_operation(mode, C, stroke_start);
149 return new_slide_operation();
150 }
152 return {};
153}
154
156 std::unique_ptr<CurvesSculptStrokeOperation> operation;
158};
159
161 float out[3],
162 const float mouse[2],
163 bool /*force_original*/)
164{
165 out[0] = mouse[0];
166 out[1] = mouse[1];
167 out[2] = 0;
168 UNUSED_VARS(C);
169 return true;
170}
171
172static bool stroke_test_start(bContext *C, wmOperator *op, const float mouse[2])
173{
174 UNUSED_VARS(C, op, mouse);
175 return true;
176}
177
179 wmOperator *op,
180 PaintStroke * /*stroke*/,
181 PointerRNA *stroke_element)
182{
184 op->customdata);
185
186 StrokeExtension stroke_extension;
187 RNA_float_get_array(stroke_element, "mouse", stroke_extension.mouse_position);
188 stroke_extension.pressure = RNA_float_get(stroke_element, "pressure");
189 stroke_extension.reports = op->reports;
190
191 if (!op_data->operation) {
192 stroke_extension.is_first = true;
193 op_data->operation = start_brush_operation(*C, *op, stroke_extension);
194 }
195 else {
196 stroke_extension.is_first = false;
197 }
198
199 if (op_data->operation) {
200 op_data->operation->on_stroke_extended(*C, stroke_extension);
201 }
202}
203
204static void stroke_done(const bContext *C, PaintStroke *stroke)
205{
206 UNUSED_VARS(C, stroke);
207}
208
210 wmOperator *op,
211 const wmEvent *event)
212{
213 Scene *scene = CTX_data_scene(C);
215 const Brush *brush = paint ? BKE_paint_brush_for_read(paint) : nullptr;
216 if (brush == nullptr) {
217 return OPERATOR_CANCELLED;
218 }
219
220 SculptCurvesBrushStrokeData *op_data = MEM_new<SculptCurvesBrushStrokeData>(__func__);
221 op_data->stroke = paint_stroke_new(C,
222 op,
226 nullptr,
228 event->type);
229 op->customdata = op_data;
230
231 const wmOperatorStatus retval = op->type->modal(C, op, event);
232 OPERATOR_RETVAL_CHECK(retval);
233
234 if (retval == OPERATOR_FINISHED) {
235 if (op->customdata != nullptr) {
236 paint_stroke_free(C, op, op_data->stroke);
237 MEM_delete(op_data);
238 }
239 return OPERATOR_FINISHED;
240 }
241
244}
245
247 wmOperator *op,
248 const wmEvent *event)
249{
251 op->customdata);
252 wmOperatorStatus retval = paint_stroke_modal(C, op, event, &op_data->stroke);
254 MEM_delete(op_data);
255 op->customdata = nullptr;
256 }
257 return retval;
258}
259
261{
262 if (op->customdata != nullptr) {
264 op->customdata);
265 paint_stroke_cancel(C, op, op_data->stroke);
266 MEM_delete(op_data);
267 }
268}
269
271{
272 ot->name = "Stroke Curves Sculpt";
273 ot->idname = "SCULPT_CURVES_OT_brush_stroke";
274 ot->description = "Sculpt curves using a brush";
275
279
281
283}
284
286
287/* -------------------------------------------------------------------- */
290
292{
293 Scene *scene = CTX_data_scene(C);
295
298 CurvesSculpt *curves_sculpt = scene->toolsettings->curves_sculpt;
299
301
303
305
306 /* Setup cursor color. BKE_paint_init() could be used, but creates an additional brush. */
308 paint->paint_cursor_col[3] = 128;
309
311 paint_init_pivot(ob, scene);
312
313 /* Necessary to change the object mode on the evaluated object. */
315 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
317}
318
320{
322 ob->mode = OB_MODE_OBJECT;
323}
324
326{
329
330 const bool is_mode_set = ob->mode == OB_MODE_SCULPT_CURVES;
331
332 if (is_mode_set) {
334 return OPERATOR_CANCELLED;
335 }
336 }
337
338 if (is_mode_set) {
340 }
341 else {
343 }
344
346
347 /* Necessary to change the object mode on the evaluated object. */
349 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
351 return OPERATOR_FINISHED;
352}
353
355{
356 ot->name = "Curve Sculpt Mode Toggle";
357 ot->idname = "CURVES_OT_sculptmode_toggle";
358 ot->description = "Enter/Exit sculpt mode for curves";
359
361 ot->poll = curves::curves_poll;
362
364}
365
367
368namespace select_random {
369
371{
373
374 const int seed = RNA_int_get(op->ptr, "seed");
375 RandomNumberGenerator rng{uint32_t(seed)};
376
377 const bool partial = RNA_boolean_get(op->ptr, "partial");
378 const bool constant_per_curve = RNA_boolean_get(op->ptr, "constant_per_curve");
379 const float probability = RNA_float_get(op->ptr, "probability");
380 const float min_value = RNA_float_get(op->ptr, "min");
381 const auto next_partial_random_value = [&]() {
382 return rng.get_float() * (1.0f - min_value) + min_value;
383 };
384 const auto next_bool_random_value = [&]() { return rng.get_float() <= probability; };
385
386 for (Curves *curves_id : unique_curves) {
387 CurvesGeometry &curves = curves_id->geometry.wrap();
388 const bool was_anything_selected = curves::has_anything_selected(curves);
389
391 MutableSpan<float> selection = attribute.span;
392 if (!was_anything_selected) {
393 selection.fill(1.0f);
394 }
395 const OffsetIndices points_by_curve = curves.points_by_curve();
396 switch (bke::AttrDomain(curves_id->selection_domain)) {
398 if (partial) {
399 if (constant_per_curve) {
400 for (const int curve_i : curves.curves_range()) {
401 const float random_value = next_partial_random_value();
402 const IndexRange points = points_by_curve[curve_i];
403 for (const int point_i : points) {
404 selection[point_i] *= random_value;
405 }
406 }
407 }
408 else {
409 for (const int point_i : selection.index_range()) {
410 const float random_value = next_partial_random_value();
411 selection[point_i] *= random_value;
412 }
413 }
414 }
415 else {
416 if (constant_per_curve) {
417 for (const int curve_i : curves.curves_range()) {
418 const bool random_value = next_bool_random_value();
419 const IndexRange points = points_by_curve[curve_i];
420 if (!random_value) {
421 selection.slice(points).fill(0.0f);
422 }
423 }
424 }
425 else {
426 for (const int point_i : selection.index_range()) {
427 const bool random_value = next_bool_random_value();
428 if (!random_value) {
429 selection[point_i] = 0.0f;
430 }
431 }
432 }
433 }
434 break;
435 }
437 if (partial) {
438 for (const int curve_i : curves.curves_range()) {
439 const float random_value = next_partial_random_value();
440 selection[curve_i] *= random_value;
441 }
442 }
443 else {
444 for (const int curve_i : curves.curves_range()) {
445 const bool random_value = next_bool_random_value();
446 if (!random_value) {
447 selection[curve_i] = 0.0f;
448 }
449 }
450 }
451 break;
452 }
453 default:
455 break;
456 }
457
458 attribute.finish();
459
460 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
461 * attribute for now. */
462 DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY);
463 WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id);
464 }
465 return OPERATOR_FINISHED;
466}
467
468static void select_random_ui(bContext * /*C*/, wmOperator *op)
469{
470 uiLayout *layout = op->layout;
471
472 layout->prop(op->ptr, "seed", UI_ITEM_NONE, std::nullopt, ICON_NONE);
473 layout->prop(op->ptr, "constant_per_curve", UI_ITEM_NONE, std::nullopt, ICON_NONE);
474 layout->prop(op->ptr, "partial", UI_ITEM_NONE, std::nullopt, ICON_NONE);
475
476 if (RNA_boolean_get(op->ptr, "partial")) {
477 layout->prop(op->ptr, "min", UI_ITEM_R_SLIDER, IFACE_("Min"), ICON_NONE);
478 }
479 else {
480 layout->prop(op->ptr, "probability", UI_ITEM_R_SLIDER, IFACE_("Probability"), ICON_NONE);
481 }
482}
483
484} // namespace select_random
485
487{
488 ot->name = "Select Random";
489 ot->idname = __func__;
490 ot->description = "Randomizes existing selection or create new random selection";
491
495
497
498 RNA_def_int(ot->srna,
499 "seed",
500 0,
501 INT32_MIN,
502 INT32_MAX,
503 "Seed",
504 "Source of randomness",
505 INT32_MIN,
506 INT32_MAX);
508 ot->srna, "partial", false, "Partial", "Allow points or curves to be selected partially");
509 RNA_def_float(ot->srna,
510 "probability",
511 0.5f,
512 0.0f,
513 1.0f,
514 "Probability",
515 "Chance of every point or curve being included in the selection",
516 0.0f,
517 1.0f);
518 RNA_def_float(ot->srna,
519 "min",
520 0.0f,
521 0.0f,
522 1.0f,
523 "Min",
524 "Minimum value for the random selection",
525 0.0f,
526 1.0f);
527 RNA_def_boolean(ot->srna,
528 "constant_per_curve",
529 true,
530 "Constant per Curve",
531 "The generated random number is the same for every control point of a curve");
532}
533namespace select_grow {
534
547
552
554 const float distance,
555 MutableSpan<float> points_selection)
556{
557 if (distance > 0.0f) {
558 data.unselected_points.foreach_index(
559 GrainSize(256), [&](const int point_i, const int index_pos) {
560 const float distance_to_selected = data.distances_to_selected[index_pos];
561 const float selection = distance_to_selected <= distance ? 1.0f : 0.0f;
562 points_selection[point_i] = selection;
563 });
564 data.selected_points.foreach_index(
565 GrainSize(512), [&](const int point_i) { points_selection[point_i] = 1.0f; });
566 }
567 else {
568 data.selected_points.foreach_index(
569 GrainSize(256), [&](const int point_i, const int index_pos) {
570 const float distance_to_unselected = data.distances_to_unselected[index_pos];
571 const float selection = distance_to_unselected <= -distance ? 0.0f : 1.0f;
572 points_selection[point_i] = selection;
573 });
574 data.unselected_points.foreach_index(
575 GrainSize(512), [&](const int point_i) { points_selection[point_i] = 0.0f; });
576 }
577}
578
579static int select_grow_update(bContext *C, wmOperator *op, const float mouse_diff_x)
580{
581 GrowOperatorData &op_data = *static_cast<GrowOperatorData *>(op->customdata);
582
583 for (std::unique_ptr<GrowOperatorDataPerCurve> &curve_op_data : op_data.per_curve) {
584 Curves &curves_id = *curve_op_data->curves_id;
585 CurvesGeometry &curves = curves_id.geometry.wrap();
586 const float distance = curve_op_data->pixel_to_distance_factor * mouse_diff_x;
587
589 const OffsetIndices points_by_curve = curves.points_by_curve();
590
591 /* Grow or shrink selection based on precomputed distances. */
592 switch (selection.domain) {
594 update_points_selection(*curve_op_data, distance, selection.span);
595 break;
596 }
598 Array<float> new_points_selection(curves.points_num());
599 update_points_selection(*curve_op_data, distance, new_points_selection);
600 /* Propagate grown point selection to the curve selection. */
601 MutableSpan<float> curves_selection = selection.span;
602 for (const int curve_i : curves.curves_range()) {
603 const IndexRange points = points_by_curve[curve_i];
604 const Span<float> points_selection = new_points_selection.as_span().slice(points);
605 const float max_selection = *std::max_element(points_selection.begin(),
606 points_selection.end());
607 curves_selection[curve_i] = max_selection;
608 }
609 break;
610 }
611 default:
613 }
614
615 selection.finish();
616
617 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
618 * attribute for now. */
620 WM_event_add_notifier(C, NC_GEOM | ND_DATA, &curves_id);
621 }
622
623 return OPERATOR_FINISHED;
624}
625
626static void select_grow_invoke_per_curve(const Curves &curves_id,
627 const Object &curves_ob,
628 const ARegion &region,
629 const View3D &v3d,
630 const RegionView3D &rv3d,
631 GrowOperatorDataPerCurve &curve_op_data)
632{
633 const CurvesGeometry &curves = curves_id.geometry.wrap();
634 const Span<float3> positions = curves.positions();
635
636 if (const bke::GAttributeReader original_selection = curves.attributes().lookup(".selection")) {
637 curve_op_data.original_selection = GArray<>(original_selection.varray.type(),
638 original_selection.varray.size());
639 original_selection.varray.materialize(curve_op_data.original_selection.data());
640 }
641
642 /* Find indices of selected and unselected points. */
644 curves_id, curve_op_data.selected_points_memory);
645 curve_op_data.unselected_points = curve_op_data.selected_points.complement(
646 curves.points_range(), curve_op_data.unselected_points_memory);
647
649 1024 < curve_op_data.selected_points.size() + curve_op_data.unselected_points.size(),
650 [&]() {
651 /* Build KD-tree for the selected points. */
652 KDTree_3d *kdtree = BLI_kdtree_3d_new(curve_op_data.selected_points.size());
653 BLI_SCOPED_DEFER([&]() { BLI_kdtree_3d_free(kdtree); });
654 curve_op_data.selected_points.foreach_index([&](const int point_i) {
655 const float3 &position = positions[point_i];
656 BLI_kdtree_3d_insert(kdtree, point_i, position);
657 });
658 BLI_kdtree_3d_balance(kdtree);
659
660 /* For each unselected point, compute the distance to the closest selected point. */
661 curve_op_data.distances_to_selected.reinitialize(curve_op_data.unselected_points.size());
663 curve_op_data.unselected_points.index_range(), 256, [&](const IndexRange range) {
664 for (const int i : range) {
665 const int point_i = curve_op_data.unselected_points[i];
666 const float3 &position = positions[point_i];
667 KDTreeNearest_3d nearest;
668 BLI_kdtree_3d_find_nearest(kdtree, position, &nearest);
669 curve_op_data.distances_to_selected[i] = nearest.dist;
670 }
671 });
672 },
673 [&]() {
674 /* Build KD-tree for the unselected points. */
675 KDTree_3d *kdtree = BLI_kdtree_3d_new(curve_op_data.unselected_points.size());
676 BLI_SCOPED_DEFER([&]() { BLI_kdtree_3d_free(kdtree); });
677 curve_op_data.unselected_points.foreach_index([&](const int point_i) {
678 const float3 &position = positions[point_i];
679 BLI_kdtree_3d_insert(kdtree, point_i, position);
680 });
681 BLI_kdtree_3d_balance(kdtree);
682
683 /* For each selected point, compute the distance to the closest unselected point. */
684 curve_op_data.distances_to_unselected.reinitialize(curve_op_data.selected_points.size());
686 curve_op_data.selected_points.index_range(), 256, [&](const IndexRange range) {
687 for (const int i : range) {
688 const int point_i = curve_op_data.selected_points[i];
689 const float3 &position = positions[point_i];
690 KDTreeNearest_3d nearest;
691 BLI_kdtree_3d_find_nearest(kdtree, position, &nearest);
692 curve_op_data.distances_to_unselected[i] = nearest.dist;
693 }
694 });
695 });
696
697 const float4x4 &curves_to_world_mat = curves_ob.object_to_world();
698 float4x4 world_to_curves_mat = math::invert(curves_to_world_mat);
699
700 const float4x4 projection = ED_view3d_ob_project_mat_get(&rv3d, &curves_ob);
701
702 /* Compute how mouse movements in screen space are converted into grow/shrink distances in
703 * object space. */
704 curve_op_data.pixel_to_distance_factor = threading::parallel_reduce(
705 curve_op_data.selected_points.index_range(),
706 256,
707 FLT_MAX,
708 [&](const IndexRange range, float pixel_to_distance_factor) {
709 for (const int i : range) {
710 const int point_i = curve_op_data.selected_points[i];
711 const float3 &pos_cu = positions[point_i];
712
713 const float2 pos_re = ED_view3d_project_float_v2_m4(&region, pos_cu, projection);
714 if (pos_re.x < 0 || pos_re.y < 0 || pos_re.x > region.winx || pos_re.y > region.winy) {
715 continue;
716 }
717 /* Compute how far this point moves in curve space when it moves one unit in screen
718 * space. */
719 const float2 pos_offset_re = pos_re + float2(1, 0);
720 float3 pos_offset_wo;
721 ED_view3d_win_to_3d(&v3d,
722 &region,
723 math::transform_point(curves_to_world_mat, pos_cu),
724 pos_offset_re,
725 pos_offset_wo);
726 const float3 pos_offset_cu = math::transform_point(world_to_curves_mat, pos_offset_wo);
727 const float dist_cu = math::distance(pos_cu, pos_offset_cu);
728 const float dist_re = math::distance(pos_re, pos_offset_re);
729 const float factor = dist_cu / dist_re;
730 math::min_inplace(pixel_to_distance_factor, factor);
731 }
732 return pixel_to_distance_factor;
733 },
734 [](const float a, const float b) { return std::min(a, b); });
735}
736
738{
739 Object *active_ob = CTX_data_active_object(C);
740 ARegion *region = CTX_wm_region(C);
741 View3D *v3d = CTX_wm_view3d(C);
743
744 GrowOperatorData *op_data = MEM_new<GrowOperatorData>(__func__);
745 op->customdata = op_data;
746
747 op_data->initial_mouse_x = event->xy[0];
748
749 Curves &curves_id = *static_cast<Curves *>(active_ob->data);
750 auto curve_op_data = std::make_unique<GrowOperatorDataPerCurve>();
751 curve_op_data->curves_id = &curves_id;
752 select_grow_invoke_per_curve(curves_id, *active_ob, *region, *v3d, *rv3d, *curve_op_data);
753 op_data->per_curve.append(std::move(curve_op_data));
754
757}
758
760{
761 GrowOperatorData &op_data = *static_cast<GrowOperatorData *>(op->customdata);
762 const int mouse_x = event->xy[0];
763 const int mouse_diff_x = mouse_x - op_data.initial_mouse_x;
764 switch (event->type) {
765 case MOUSEMOVE: {
766 select_grow_update(C, op, mouse_diff_x);
767 break;
768 }
769 case LEFTMOUSE: {
770 MEM_delete(&op_data);
771 return OPERATOR_FINISHED;
772 }
773 case EVT_ESCKEY:
774 case RIGHTMOUSE: {
775 /* Undo operator by resetting the selection to the original value. */
776 for (std::unique_ptr<GrowOperatorDataPerCurve> &curve_op_data : op_data.per_curve) {
777 Curves &curves_id = *curve_op_data->curves_id;
778 CurvesGeometry &curves = curves_id.geometry.wrap();
779 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
780
781 attributes.remove(".selection");
782 if (!curve_op_data->original_selection.is_empty()) {
783 attributes.add(
784 ".selection",
786 bke::cpp_type_to_custom_data_type(curve_op_data->original_selection.type()),
787 bke::AttributeInitVArray(GVArray::ForSpan(curve_op_data->original_selection)));
788 }
789
790 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
791 * attribute for now. */
793 WM_event_add_notifier(C, NC_GEOM | ND_DATA, &curves_id);
794 }
795 MEM_delete(&op_data);
796 return OPERATOR_CANCELLED;
797 }
798 default: {
799 break;
800 }
801 }
803}
804
805} // namespace select_grow
806
808{
809 ot->name = "Select Grow";
810 ot->idname = __func__;
811 ot->description = "Select curves which are close to curves that are selected already";
812
816
818
819 PropertyRNA *prop;
820 prop = RNA_def_float(ot->srna,
821 "distance",
822 0.1f,
823 -FLT_MAX,
824 FLT_MAX,
825 "Distance",
826 "By how much to grow the selection",
827 -10.0f,
828 10.0f);
830}
831
833
835{
837 return false;
838 }
839 Scene *scene = CTX_data_scene(C);
841 if (brush == nullptr) {
842 return false;
843 }
845 return false;
846 }
847 return true;
848}
849
870
872{
873 Scene *scene = CTX_data_scene(C);
874 ARegion *region = op_data.region;
875
876 const float min_distance = op_data.brush->curves_sculpt_settings->minimum_distance;
877 const float brush_radius = BKE_brush_size_get(scene, op_data.brush);
878
879 float3 tangent_x_cu = math::cross(op_data.normal_cu, float3{0, 0, 1});
880 if (math::is_zero(tangent_x_cu)) {
881 tangent_x_cu = math::cross(op_data.normal_cu, float3{0, 1, 0});
882 }
883 tangent_x_cu = math::normalize(tangent_x_cu);
884 const float3 tangent_y_cu = math::normalize(math::cross(op_data.normal_cu, tangent_x_cu));
885
886 /* Sample a few points to get a good estimate of how large the grid has to be. */
887 Vector<float3> points_wo;
888 points_wo.append(op_data.pos_cu + min_distance * tangent_x_cu);
889 points_wo.append(op_data.pos_cu + min_distance * tangent_y_cu);
890 points_wo.append(op_data.pos_cu - min_distance * tangent_x_cu);
891 points_wo.append(op_data.pos_cu - min_distance * tangent_y_cu);
892
893 Vector<float2> points_re;
894 for (const float3 &pos_wo : points_wo) {
895 float2 pos_re;
896 ED_view3d_project_v2(region, pos_wo, pos_re);
897 points_re.append(pos_re);
898 }
899
900 float2 origin_re;
901 ED_view3d_project_v2(region, op_data.pos_cu, origin_re);
902
903 int needed_points = 0;
904 for (const float2 &pos_re : points_re) {
905 const float distance = math::length(pos_re - origin_re);
906 const int needed_points_iter = (brush_radius * 2.0f) / distance;
907
908 needed_points = std::max(needed_points_iter, needed_points);
909 }
910
911 /* Limit to a hard-coded number since it only adds noise at some point. */
912 return std::min(300, needed_points);
913}
914
916 const blender::int2 & /*xy*/,
917 const blender::float2 & /*tilt*/,
918 void *customdata)
919{
920 Scene *scene = CTX_data_scene(C);
921 MinDistanceEditData &op_data = *static_cast<MinDistanceEditData *>(customdata);
922
923 const float min_distance = op_data.brush->curves_sculpt_settings->minimum_distance;
924
925 float3 tangent_x_cu = math::cross(op_data.normal_cu, float3{0, 0, 1});
926 if (math::is_zero(tangent_x_cu)) {
927 tangent_x_cu = math::cross(op_data.normal_cu, float3{0, 1, 0});
928 }
929 tangent_x_cu = math::normalize(tangent_x_cu);
930 const float3 tangent_y_cu = math::normalize(math::cross(op_data.normal_cu, tangent_x_cu));
931
932 const int points_per_side = calculate_points_per_side(C, op_data);
933 const int points_per_axis_num = 2 * points_per_side + 1;
934
935 Vector<float3> points_wo;
936 for (const int x_i : IndexRange(points_per_axis_num)) {
937 for (const int y_i : IndexRange(points_per_axis_num)) {
938 const float x_iter = min_distance * (x_i - (points_per_axis_num - 1) / 2.0f);
939 const float y_iter = min_distance * (y_i - (points_per_axis_num - 1) / 2.0f);
940
941 const float3 point_pos_cu = op_data.pos_cu + op_data.normal_cu * 0.0001f +
942 x_iter * tangent_x_cu + y_iter * tangent_y_cu;
943 const float3 point_pos_wo = math::transform_point(op_data.curves_to_world_mat, point_pos_cu);
944 points_wo.append(point_pos_wo);
945 }
946 }
947
948 float4 circle_col = float4(op_data.brush->add_col);
949 float circle_alpha = op_data.brush->cursor_overlay_alpha;
950 float brush_radius_re = BKE_brush_size_get(scene, op_data.brush);
951
952 /* Draw the grid. */
956
957 ARegion *region = op_data.region;
958 RegionView3D *rv3d = op_data.rv3d;
959 wmWindow *win = CTX_wm_window(C);
960
961 /* It does the same as: `view3d_operator_needs_gpu(C);`. */
962 wmViewport(&region->winrct);
964 GPU_matrix_set(rv3d->viewmat);
965
966 GPUVertFormat *format3d = immVertexFormat();
967
968 const uint pos3d = GPU_vertformat_attr_add(format3d, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
969 const uint col3d = GPU_vertformat_attr_add(format3d, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
970 const uint siz3d = GPU_vertformat_attr_add(format3d, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
971
974 immBegin(GPU_PRIM_POINTS, points_wo.size());
975
976 float3 brush_origin_wo = math::transform_point(op_data.curves_to_world_mat, op_data.pos_cu);
977 float2 brush_origin_re;
978 ED_view3d_project_v2(region, brush_origin_wo, brush_origin_re);
979
980 /* Smooth alpha transition until the brush edge. */
981 const int alpha_border_re = 20;
982 const float dist_to_inner_border_re = brush_radius_re - alpha_border_re;
983
984 for (const float3 &pos_wo : points_wo) {
985 float2 pos_re;
986 ED_view3d_project_v2(region, pos_wo, pos_re);
987
988 const float dist_to_point_re = math::distance(pos_re, brush_origin_re);
989 const float alpha = 1.0f - ((dist_to_point_re - dist_to_inner_border_re) / alpha_border_re);
990
991 immAttr1f(siz3d, 3.0f);
992 immAttr4f(col3d, 0.9f, 0.9f, 0.9f, alpha);
993 immVertex3fv(pos3d, pos_wo);
994 }
995 immEnd();
997
998 /* Reset the drawing settings. */
999 GPU_point_size(1.0f);
1002
1003 int4 scissor;
1004 GPU_scissor_get(scissor);
1005 wmWindowViewport(win);
1006 GPU_scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
1007
1008 /* Draw the brush circle. */
1009 GPU_matrix_translate_2f(float(op_data.initial_mouse.x), float(op_data.initial_mouse.y));
1010
1013
1015
1016 immUniformColor3fvAlpha(circle_col, circle_alpha);
1017 imm_draw_circle_wire_2d(pos2d, 0.0f, 0.0f, brush_radius_re, 80);
1018
1021}
1022
1024{
1026 ARegion *region = CTX_wm_region(C);
1027 View3D *v3d = CTX_wm_view3d(C);
1028 Scene *scene = CTX_data_scene(C);
1029
1030 Object &curves_ob_orig = *CTX_data_active_object(C);
1031 Curves &curves_id_orig = *static_cast<Curves *>(curves_ob_orig.data);
1032 Object &surface_ob_orig = *curves_id_orig.surface;
1033 Object *surface_ob_eval = DEG_get_evaluated(depsgraph, &surface_ob_orig);
1034 if (surface_ob_eval == nullptr) {
1035 return OPERATOR_CANCELLED;
1036 }
1037 Mesh *surface_me_eval = BKE_object_get_evaluated_mesh(surface_ob_eval);
1038 if (surface_me_eval == nullptr) {
1039 return OPERATOR_CANCELLED;
1040 }
1041
1042 bke::BVHTreeFromMesh surface_bvh_eval = surface_me_eval->bvh_corner_tris();
1043
1044 const int2 mouse_pos_int_re{event->mval};
1045 const float2 mouse_pos_re{mouse_pos_int_re};
1046
1047 float3 ray_start_wo, ray_end_wo;
1049 depsgraph, region, v3d, mouse_pos_re, ray_start_wo, ray_end_wo, true);
1050
1051 const CurvesSurfaceTransforms transforms{curves_ob_orig, &surface_ob_orig};
1052
1053 const float3 ray_start_su = math::transform_point(transforms.world_to_surface, ray_start_wo);
1054 const float3 ray_end_su = math::transform_point(transforms.world_to_surface, ray_end_wo);
1055 const float3 ray_direction_su = math::normalize(ray_end_su - ray_start_su);
1056
1057 BVHTreeRayHit ray_hit;
1058 ray_hit.dist = FLT_MAX;
1059 ray_hit.index = -1;
1060 BLI_bvhtree_ray_cast(surface_bvh_eval.tree,
1061 ray_start_su,
1062 ray_direction_su,
1063 0.0f,
1064 &ray_hit,
1065 surface_bvh_eval.raycast_callback,
1066 &surface_bvh_eval);
1067 if (ray_hit.index == -1) {
1068 WM_global_report(RPT_ERROR, "Cursor must be over the surface mesh");
1069 return OPERATOR_CANCELLED;
1070 }
1071
1072 const float3 hit_pos_su = ray_hit.co;
1073 const float3 hit_normal_su = ray_hit.no;
1074
1075 const float3 hit_pos_cu = math::transform_point(transforms.surface_to_curves, hit_pos_su);
1076 const float3 hit_normal_cu = math::normalize(
1077 math::transform_direction(transforms.surface_to_curves_normal, hit_normal_su));
1078
1079 MinDistanceEditData *op_data = MEM_new<MinDistanceEditData>(__func__);
1080 op_data->curves_to_world_mat = transforms.curves_to_world;
1081 op_data->normal_cu = hit_normal_cu;
1082 op_data->pos_cu = hit_pos_cu;
1083 op_data->initial_mouse = event->xy;
1086
1087 if (op_data->initial_minimum_distance <= 0.0f) {
1088 op_data->initial_minimum_distance = 0.01f;
1089 }
1090
1091 op->customdata = op_data;
1092
1093 /* Temporarily disable other paint cursors. */
1095 op_data->orig_paintcursors = wm->paintcursors;
1096 BLI_listbase_clear(&wm->paintcursors);
1097
1098 /* Add minimum distance paint cursor. */
1101
1102 op_data->region = CTX_wm_region(C);
1103 op_data->rv3d = CTX_wm_region_view3d(C);
1104
1106 ED_region_tag_redraw(region);
1108}
1109
1111{
1112 ARegion *region = CTX_wm_region(C);
1113 MinDistanceEditData &op_data = *static_cast<MinDistanceEditData *>(op->customdata);
1114
1115 auto finish = [&]() {
1117
1118 /* Remove cursor. */
1119 WM_paint_cursor_end(static_cast<wmPaintCursor *>(op_data.cursor));
1120 /* Restore original paint cursors. */
1121 wm->paintcursors = op_data.orig_paintcursors;
1122
1123 ED_region_tag_redraw(region);
1124 MEM_delete(&op_data);
1125 };
1126
1127 switch (event->type) {
1128 case MOUSEMOVE: {
1129 const int2 mouse_pos_int_re{event->xy};
1130 const float2 mouse_pos_re{mouse_pos_int_re};
1131
1132 const float mouse_diff_x = mouse_pos_int_re.x - op_data.initial_mouse.x;
1133 const float factor = powf(2, mouse_diff_x / UI_UNIT_X / 10.0f);
1135 factor;
1136
1137 ED_region_tag_redraw(region);
1139 break;
1140 }
1141 case LEFTMOUSE: {
1142 if (event->val == KM_PRESS) {
1144 finish();
1145 return OPERATOR_FINISHED;
1146 }
1147 break;
1148 }
1149 case RIGHTMOUSE:
1150 case EVT_ESCKEY: {
1152 finish();
1154 return OPERATOR_CANCELLED;
1155 }
1156 default: {
1157 break;
1158 }
1159 }
1160
1162}
1163
1164} // namespace min_distance_edit
1165
1167{
1168 ot->name = "Edit Minimum Distance";
1169 ot->idname = __func__;
1170 ot->description = "Change the minimum distance used by the density brush";
1171
1175
1177}
1178
1179} // namespace blender::ed::sculpt_paint
1180
1181/* -------------------------------------------------------------------- */
1184
1194
bool BKE_brush_use_alpha_pressure(const Brush *brush)
Definition brush.cc:1231
int BKE_brush_size_get(const Scene *scene, const Brush *brush)
Definition brush.cc:1210
bool BKE_brush_use_size_pressure(const Brush *brush)
Definition brush.cc:1226
float BKE_brush_alpha_get(const Scene *scene, const Brush *brush)
Definition brush.cc:1269
void BKE_brush_tag_unsaved_changes(Brush *brush)
Definition brush.cc:720
wmWindow * CTX_wm_window(const bContext *C)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
Low-level operations for curves.
General operations, lookup, etc. for blender objects.
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
Definition paint.cc:1752
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:641
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:365
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
Definition paint.cc:1675
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:636
const uchar PAINT_CURSOR_SCULPT_CURVES[3]
Definition paint.cc:244
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
int BLI_bvhtree_ray_cast(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
A KD-tree for nearest neighbor search.
BLI_INLINE void BLI_listbase_clear(ListBase *lb)
MINLINE void copy_v3_v3_uchar(unsigned char r[3], const unsigned char a[3])
#define BLI_SCOPED_DEFER(function_to_defer)
unsigned int uint
#define UNUSED_VARS(...)
#define ELEM(...)
#define IFACE_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1026
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:982
@ CURVES_SCULPT_BRUSH_TYPE_SMOOTH
@ CURVES_SCULPT_BRUSH_TYPE_PUFF
@ CURVES_SCULPT_BRUSH_TYPE_GROW_SHRINK
@ CURVES_SCULPT_BRUSH_TYPE_PINCH
@ CURVES_SCULPT_BRUSH_TYPE_SNAKE_HOOK
@ CURVES_SCULPT_BRUSH_TYPE_ADD
@ CURVES_SCULPT_BRUSH_TYPE_COMB
@ CURVES_SCULPT_BRUSH_TYPE_DENSITY
@ CURVES_SCULPT_BRUSH_TYPE_DELETE
@ CURVES_SCULPT_BRUSH_TYPE_SLIDE
@ CURVES_SCULPT_BRUSH_TYPE_SELECTION_PAINT
@ OB_MODE_SCULPT_CURVES
@ OB_MODE_OBJECT
#define RGN_TYPE_ANY
#define SPACE_TYPE_ANY
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
#define OPERATOR_RETVAL_CHECK(ret)
void ED_paint_cursor_start(Paint *paint, bool(*poll)(bContext *C))
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:639
void ED_view3d_project_v2(const ARegion *region, const float world[3], float r_region_co[2])
blender::float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob)
bool ED_view3d_win_to_segment_clipped(const Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], bool do_clip_planes)
void immEnd()
void immUnbindProgram()
void immAttr1f(uint attr_id, float x)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
GPUVertFormat * immVertexFormat()
void immAttr4f(uint attr_id, float x, float y, float z, float w)
void immVertex3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
void immUniformColor3fvAlpha(const float rgb[3], float a)
void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
#define GPU_matrix_set(x)
void GPU_matrix_push()
void GPU_matrix_push_projection()
void GPU_matrix_pop_projection()
#define GPU_matrix_projection_set(x)
void GPU_matrix_pop()
void GPU_matrix_translate_2f(float x, float y)
@ GPU_PRIM_POINTS
@ GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:180
@ GPU_BLEND_NONE
Definition GPU_state.hh:85
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:87
void GPU_blend(eGPUBlend blend)
Definition gpu_state.cc:42
void GPU_scissor(int x, int y, int width, int height)
Definition gpu_state.cc:193
void GPU_point_size(float size)
Definition gpu_state.cc:172
void GPU_scissor_get(int coords[4])
Definition gpu_state.cc:268
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ PROP_DISTANCE
Definition RNA_types.hh:244
#define C
Definition RandGen.cpp:29
#define UI_UNIT_X
@ UI_ITEM_R_SLIDER
#define UI_ITEM_NONE
#define NC_GEOM
Definition WM_types.hh:390
#define ND_DATA
Definition WM_types.hh:506
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:218
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define ND_MODE
Definition WM_types.hh:442
#define NC_SCENE
Definition WM_types.hh:375
#define ND_TOOLSETTINGS
Definition WM_types.hh:446
@ KM_PRESS
Definition WM_types.hh:308
BMesh const char void * data
BPy_StructRNA * depsgraph
static unsigned long seed
Definition btSoftBody.h:39
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:398
Span< T > as_span() const
Definition BLI_array.hh:232
const void * data() const
static GVArray ForSpan(GSpan span)
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:573
constexpr void fill(const T &value) const
Definition BLI_span.hh:517
constexpr IndexRange index_range() const
Definition BLI_span.hh:670
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
constexpr const T * end() const
Definition BLI_span.hh:224
constexpr const T * begin() const
Definition BLI_span.hh:220
int64_t size() const
void append(const T &value)
bool remove(const StringRef attribute_id)
bool add(const StringRef attribute_id, const AttrDomain domain, const eCustomDataType data_type, const AttributeInit &initializer)
IndexMask complement(const IndexMask &universe, IndexMaskMemory &memory) const
void foreach_index(Fn &&fn) const
void ED_operatortypes_sculpt_curves()
#define powf(x, y)
#define INT32_MAX
#define INT32_MIN
VecBase< float, 4 > float4
MatBase< 4, 4 > float4x4
#define out
float distance(VecOp< float, D >, VecOp< float, D >) RET
format
eCustomDataType cpp_type_to_custom_data_type(const CPPType &type)
static bool has_anything_selected(const Span< Curves * > curves_ids)
VectorSet< Curves * > get_unique_editable_curves(const bContext &C)
Definition curves_ops.cc:91
bool editable_curves_poll(bContext *C)
bool curves_with_surface_poll(bContext *C)
bool curves_poll(bContext *C)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, IndexMaskMemory &memory)
bool mode_compat_set(bContext *C, Object *ob, eObjectMode mode, ReportList *reports)
static wmOperatorStatus min_distance_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void min_distance_edit_draw(bContext *C, const blender::int2 &, const blender::float2 &, void *customdata)
static int calculate_points_per_side(bContext *C, MinDistanceEditData &op_data)
static wmOperatorStatus min_distance_edit_modal(bContext *C, wmOperator *op, const wmEvent *event)
static int select_grow_update(bContext *C, wmOperator *op, const float mouse_diff_x)
static void update_points_selection(const GrowOperatorDataPerCurve &data, const float distance, MutableSpan< float > points_selection)
static wmOperatorStatus select_grow_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void select_grow_invoke_per_curve(const Curves &curves_id, const Object &curves_ob, const ARegion &region, const View3D &v3d, const RegionView3D &rv3d, GrowOperatorDataPerCurve &curve_op_data)
static wmOperatorStatus select_grow_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus select_random_exec(bContext *C, wmOperator *op)
static void select_random_ui(bContext *, wmOperator *op)
bool curves_sculpt_poll(bContext *C)
static bool stroke_test_start(bContext *C, wmOperator *op, const float mouse[2])
std::unique_ptr< CurvesSculptStrokeOperation > new_add_operation()
static wmOperatorStatus sculpt_curves_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void curves_sculptmode_exit(bContext *C)
std::unique_ptr< CurvesSculptStrokeOperation > new_pinch_operation(const BrushStrokeMode brush_mode, const bContext &C)
static void stroke_update_step(bContext *C, wmOperator *op, PaintStroke *, PointerRNA *stroke_element)
std::unique_ptr< CurvesSculptStrokeOperation > new_comb_operation()
float brush_radius_get(const Scene &scene, const Brush &brush, const StrokeExtension &stroke_extension)
static bool stroke_get_location(bContext *C, float out[3], const float mouse[2], bool)
void paint_stroke_cancel(bContext *C, wmOperator *op, PaintStroke *stroke)
static void SCULPT_CURVES_OT_select_grow(wmOperatorType *ot)
bke::SpanAttributeWriter< float > float_selection_ensure(Curves &curves_id)
static std::unique_ptr< CurvesSculptStrokeOperation > start_brush_operation(bContext &C, wmOperator &op, const StrokeExtension &stroke_start)
static void stroke_done(const bContext *C, PaintStroke *stroke)
static wmOperatorStatus curves_sculptmode_toggle_exec(bContext *C, wmOperator *op)
static void CURVES_OT_sculptmode_toggle(wmOperatorType *ot)
static void curves_sculptmode_enter(bContext *C)
std::unique_ptr< CurvesSculptStrokeOperation > new_snake_hook_operation()
std::unique_ptr< CurvesSculptStrokeOperation > new_grow_shrink_operation(const BrushStrokeMode brush_mode, const bContext &C)
bool curves_sculpt_poll_view3d(bContext *C)
wmOperatorStatus paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintStroke **stroke_p)
static wmOperatorStatus sculpt_curves_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
std::unique_ptr< CurvesSculptStrokeOperation > new_smooth_operation()
std::unique_ptr< CurvesSculptStrokeOperation > new_delete_operation()
std::unique_ptr< CurvesSculptStrokeOperation > new_selection_paint_operation(const BrushStrokeMode brush_mode, const bContext &C)
float brush_strength_get(const Scene &scene, const Brush &brush, const StrokeExtension &stroke_extension)
static void SCULPT_CURVES_OT_select_random(wmOperatorType *ot)
static void SCULPT_CURVES_OT_min_distance_edit(wmOperatorType *ot)
static void sculpt_curves_stroke_cancel(bContext *C, wmOperator *op)
void paint_stroke_free(bContext *C, wmOperator *op, PaintStroke *stroke)
PaintStroke * paint_stroke_new(bContext *C, wmOperator *op, StrokeGetLocation get_location, StrokeTestStart test_start, StrokeUpdateStep update_step, StrokeRedraw redraw, StrokeDone done, int event_type)
std::unique_ptr< CurvesSculptStrokeOperation > new_slide_operation()
std::unique_ptr< CurvesSculptStrokeOperation > new_puff_operation()
float brush_strength_factor(const Brush &brush, const StrokeExtension &stroke_extension)
float brush_radius_factor(const Brush &brush, const StrokeExtension &stroke_extension)
std::unique_ptr< CurvesSculptStrokeOperation > new_density_operation(const BrushStrokeMode brush_mode, const bContext &C, const StrokeExtension &stroke_start)
static void SCULPT_CURVES_OT_brush_stroke(wmOperatorType *ot)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
bool is_zero(const T &a)
CartesianBasis invert(const CartesianBasis &basis)
AxisSigned cross(const AxisSigned a, const AxisSigned b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_invoke(Functions &&...functions)
Definition BLI_task.hh:221
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:93
VecBase< int32_t, 4 > int4
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
void paint_init_pivot(Object *ob, Scene *scene)
BrushStrokeMode
void paint_stroke_operator_properties(wmOperatorType *ot)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
int RNA_int_get(PointerRNA *ptr, const char *name)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
#define FLT_MAX
Definition stdcycles.h:14
float add_col[4]
int cursor_overlay_alpha
struct BrushCurvesSculptSettings * curves_sculpt_settings
char curves_sculpt_brush_type
CurvesGeometry geometry
char selection_domain
struct Object * surface
float viewmat[4][4]
float winmat[4][4]
struct ToolSettings * toolsettings
CurvesSculpt * curves_sculpt
VecBase< T, 2 > xy() const
BVHTree_RayCastCallback raycast_callback
std::unique_ptr< CurvesSculptStrokeOperation > operation
Vector< std::unique_ptr< GrowOperatorDataPerCurve > > per_curve
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
wmEventType type
Definition WM_types.hh:754
short val
Definition WM_types.hh:756
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1086
wmOperatorStatus(* modal)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1078
struct ReportList * reports
struct uiLayout * layout
struct wmOperatorType * type
struct PointerRNA * ptr
void WM_global_report(eReportType type, const char *message)
void WM_main_add_notifier(uint type, void *reference)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
@ RIGHTMOUSE
@ MOUSEMOVE
@ LEFTMOUSE
@ EVT_ESCKEY
wmOperatorType * ot
Definition wm_files.cc:4225
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
bool WM_paint_cursor_end(wmPaintCursor *handle)
wmPaintCursor * WM_paint_cursor_activate(short space_type, short region_type, bool(*poll)(bContext *C), wmPaintCursorDraw draw, void *customdata)
void wmViewport(const rcti *winrct)
void wmWindowViewport(const wmWindow *win)
void WM_toolsystem_update_from_context_view3d(bContext *C)