Blender V5.3
view3d_buttons.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cfloat>
11#include <cmath>
12#include <cstring>
13#include <optional>
14
15#include "DNA_armature_types.h"
16#include "DNA_curve_types.h"
17#include "DNA_lattice_types.h"
18#include "DNA_mesh_types.h"
19#include "DNA_meshdata_types.h"
20#include "DNA_meta_types.h"
21#include "DNA_object_types.h"
22#include "DNA_scene_types.h"
23
24#include "MEM_guardedalloc.h"
25
26#include "BLT_translation.hh"
27
28#include "BLI_array.hh"
29#include "BLI_array_utils_c.hh"
30#include "BLI_bit_vector.hh"
31#include "BLI_bounds.hh"
32#include "BLI_listbase.hh"
33#include "BLI_math_matrix.hh"
34#include "BLI_math_matrix_c.hh"
36#include "BLI_math_vector.hh"
37#include "BLI_math_vector_c.hh"
38#include "BLI_string_utf8.hh"
39#include "BLI_utildefines.hh"
40#include "BLI_vector.hh"
41
42#include "BKE_action.hh"
43#include "BKE_armature.hh"
44#include "BKE_context.hh"
45#include "BKE_curve.hh"
46#include "BKE_curves.hh"
47#include "BKE_curves_utils.hh"
48#include "BKE_customdata.hh"
49#include "BKE_deform.hh"
50#include "BKE_editmesh.hh"
51#include "BKE_layer.hh"
52#include "BKE_library.hh"
53#include "BKE_mesh_types.hh"
54#include "BKE_object.hh"
55#include "BKE_object_deform.h"
56#include "BKE_object_types.hh"
57#include "BKE_report.hh"
58#include "BKE_screen.hh"
59
60#include "DEG_depsgraph.hh"
61
62#include "WM_api.hh"
63#include "WM_types.hh"
64
65#include "RNA_access.hh"
66#include "RNA_prototypes.hh"
67
68#include "ED_curves.hh"
69#include "ED_grease_pencil.hh"
70#include "ED_mesh.hh"
71#include "ED_object.hh"
72#include "ED_object_vgroup.hh"
73#include "ED_screen.hh"
74#include "ED_transform.hh"
75
77
78#include "UI_interface.hh"
80#include "UI_resources.hh"
81
82#include "view3d_intern.hh" /* own include */
83
84namespace blender {
85
86/* -------------------------------------------------------------------- */
89
90enum {
98};
99
100/* All must start w/ location */
101
103 float location[3];
104};
105
109
113
117
121
129
143
151 /* For the drag as a whole. */
152
158
159 /* For the update in progress. */
160
164 bool is_stored = false;
165
172 void apply(const float4x4 &mat, float3 &co);
173};
174
175/* temporary struct for storing transform properties */
176
178 float ob_obmat_orig[4][4];
179 float ob_dims_orig[3];
181 float ob_dims[3];
183
185
186 /* Floats only (treated as an array). */
188
189 /* Selection size, in the same space as `ve_median`. */
200 /* Only set while dragging a dimension. */
201 std::optional<TransformCoordsOrig> coords_orig;
202
204};
205
206#define TRANSFORM_MEDIAN_ARRAY_LEN (sizeof(TransformMedian) / sizeof(float))
207
209
210static TransformProperties *v3d_transform_props_ensure(View3D *v3d);
211
212/* -------------------------------------------------------------------- */
217
219static void coords_orig_free(const bContext *C)
220{
221 if (View3D *v3d = CTX_wm_view3d(C)) {
223 }
224}
225
227 const ui::BlockInteraction_Params *params,
228 void *arg1)
229{
230 const int retval_median = B_TRANSFORM_PANEL_MEDIAN;
231 const int retval_elem_dims = B_TRANSFORM_PANEL_ELEM_DIMS;
232 const bool is_median = BLI_array_findindex(params->unique_retval_ids,
233 params->unique_retval_ids_len,
234 &retval_median) != -1;
235 const bool is_elem_dims = BLI_array_findindex(params->unique_retval_ids,
236 params->unique_retval_ids_len,
237 &retval_elem_dims) != -1;
238 if (!(is_median || is_elem_dims)) {
239 return nullptr;
240 }
241
242 /* Paranoid, an unfinished drag would scale from stale coordinates. */
244
245 Object *ob = static_cast<Object *>(arg1);
246 if (ob->type != OB_MESH) {
247 return nullptr;
248 }
250 if (bm == nullptr) {
251 return nullptr;
252 }
253
254 int verts_mask_count = 0;
255 BMIter iter;
256 BMVert *eve;
257 int i;
258
259 BitVector<> verts_mask(bm->totvert);
260 BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
262 continue;
263 }
264 verts_mask[i].set();
265 verts_mask_count += 1;
266 }
267
268 BMPartialUpdate_Params update_params{};
269 update_params.do_tessellate = true;
270 update_params.do_normals = true;
271 /* Translation keeps the normals of faces inside the selection,
272 * a non-uniform scale doesn't, so every face touching the selection is needed. */
273 BMPartialUpdate *bmpinfo;
274 if (is_elem_dims) {
275 bmpinfo = BM_mesh_partial_create_from_verts(*bm, update_params, verts_mask, verts_mask_count);
276 }
277 else {
278 /* The mask is looked up by vertex index. */
281 *bm, update_params, verts_mask, verts_mask_count);
282 }
283
284 return bmpinfo;
285}
286
288 const ui::BlockInteraction_Params * /*params*/,
289 void * /*arg1*/,
290 void *user_data)
291{
293
294 BMPartialUpdate *bmpinfo = static_cast<BMPartialUpdate *>(user_data);
295 if (bmpinfo == nullptr) {
296 return;
297 }
299}
300
302 const ui::BlockInteraction_Params * /*params*/,
303 void *arg1,
304 void *user_data)
305{
306 BMPartialUpdate *bmpinfo = static_cast<BMPartialUpdate *>(user_data);
307 if (bmpinfo == nullptr) {
308 return;
309 }
310
311 View3D *v3d = CTX_wm_view3d(C);
313 if (tfp->tag_for_update == false) {
314 return;
315 }
316 tfp->tag_for_update = false;
317
318 Object *ob = static_cast<Object *>(arg1);
320
322 em, BKE_editmesh_bmesh_get_for_write(ob), bmpinfo);
323}
324
326
327/* -------------------------------------------------------------------- */
330
333{
334 return {
336 float3(-FLT_MAX),
337 };
338}
339
346{
347 return bounds.min.x <= bounds.max.x;
348}
349
361static void median_bounds_add(float location[3],
363 const float4x4 *matrix,
364 const float co[3])
365{
366 add_v3_v3(location, co);
367
368 float3 co_test(co);
369 if (matrix) {
370 co_test = math::transform_point(*matrix, co_test);
371 }
372 math::min_max(co_test, bounds.min, bounds.max);
373}
374
376static void dims_apply_store(TransformCoordsOrig &coords_orig, const float4x4 &mat, float3 &co)
377{
378 const float3 co_orig = co;
379 coords_orig.coords[coords_orig.coords_index++] = co_orig;
380 co = math::transform_point(mat, co_orig);
381}
382
384static void dims_apply_restore(TransformCoordsOrig &coords_orig, const float4x4 &mat, float3 &co)
385{
386 co = math::transform_point(mat, coords_orig.coords[coords_orig.coords_index++]);
387}
388
390{
391 this->is_stored ? dims_apply_restore(*this, mat, co) : dims_apply_store(*this, mat, co);
392}
393
409static std::optional<float4x4> median_dims_scale_matrix_calc(const Object &ob,
410 const float4x4 *matrix,
411 const float3 &pivot_world,
412 const float3 &dims_orig,
413 const float3 &dims_new)
414{
415 float3 scale(1.0f);
416 for (const int axis : IndexRange(3)) {
417 const float scale_axis = dims_new[axis] / dims_orig[axis];
418 if (!std::isfinite(scale_axis)) {
419 /* Flat on this axis, no scale can give it a size.
420 * #BKE_object_dimensions_set_ex discards a non-finite scale for the same reason. */
421 continue;
422 }
423 scale[axis] = scale_axis;
424 }
425
426 const float4x4 object_to_measure = matrix ? *matrix : float4x4::identity();
427 bool is_invertible;
428 const float4x4 measure_to_object = math::invert(object_to_measure, is_invertible);
429 if (!is_invertible) {
430 /* The object has a zero scale on some axis (global space only), the zero matrix
431 * #math::invert returns would collapse the selection onto the object origin. */
432 return std::nullopt;
433 }
434
435 /* The pivot is always in global space, the dimensions may not be.
436 * A pseudo inverse maps the pivot even when the object has a zero scaled axis,
437 * it only positions the scale so a true inverse isn't needed. */
438 const float3 pivot = math::transform_point(
439 object_to_measure * math::pseudo_invert(ob.object_to_world()), pivot_world);
440
441 /* Scale about the pivot in the measured space, wrapped to apply to object coordinates. */
442 const float4x4 mat = math::from_loc_scale<float4x4>(pivot - (scale * pivot), scale);
443 return measure_to_object * mat * object_to_measure;
444}
445
446/* Helper function to compute a median changed value,
447 * when the value should be clamped in [0.0, 1.0].
448 * Returns either 0.0, 1.0 (both can be applied directly), a positive scale factor
449 * for scale down, or a negative one for scale up.
450 */
451static float compute_scale_factor(const float ve_median, const float median)
452{
453 if (ve_median <= 0.0f) {
454 return 0.0f;
455 }
456 if (ve_median >= 1.0f) {
457 return 1.0f;
458 }
459
460 /* Scale value to target median. */
461 float median_new = ve_median;
462 float median_orig = ve_median - median; /* Previous median value. */
463
464 /* In case of floating point error. */
465 CLAMP(median_orig, 0.0f, 1.0f);
466 CLAMP(median_new, 0.0f, 1.0f);
467
468 if (median_new <= median_orig) {
469 /* Scale down. */
470 return median_new / median_orig;
471 }
472
473 /* Scale up, negative to indicate it... */
474 return -(1.0f - median_new) / (1.0f - median_orig);
475}
476
483static void apply_raw_diff(float *val, const int tot, const float ve_median, const float median)
484{
485 *val = (tot == 1) ? ve_median : (*val + median);
486}
487
488static void apply_raw_diff_v3(float val[3],
489 const int tot,
490 const float ve_median[3],
491 const float median[3])
492{
493 if (tot == 1) {
494 copy_v3_v3(val, ve_median);
495 }
496 else {
497 add_v3_v3(val, median);
498 }
499}
500
502 float *val, const int tot, const float ve_median, const float median, const float sca)
503{
504 if (tot == 1 || ve_median == median) {
505 *val = ve_median;
506 }
507 else {
508 *val *= sca;
509 }
510}
511
512static void apply_scale_factor_clamp(float *val,
513 const int tot,
514 const float ve_median,
515 const float sca)
516{
517 if (tot == 1) {
518 *val = ve_median;
519 CLAMP(*val, 0.0f, 1.0f);
520 }
521 else if (ELEM(sca, 0.0f, 1.0f)) {
522 *val = sca;
523 }
524 else {
525 *val = (sca > 0.0f) ? (*val * sca) : (1.0f + ((1.0f - *val) * sca));
526 CLAMP(*val, 0.0f, 1.0f);
527 }
528}
529
531
532/* -------------------------------------------------------------------- */
535
537{
538 if (v3d->runtime.properties_storage == nullptr) {
539 TransformProperties *tfp = MEM_new<TransformProperties>("TransformProperties");
540 /* Construct C++ structures in otherwise zero initialized struct. */
541 new (tfp) TransformProperties();
542
543 v3d->runtime.properties_storage = tfp;
544 v3d->runtime.properties_storage_free = [](void *properties_storage) {
545 MEM_delete(static_cast<TransformProperties *>(properties_storage));
546 };
547 }
548 return static_cast<TransformProperties *>(v3d->runtime.properties_storage);
549}
550
552
553/* -------------------------------------------------------------------- */
556
560 int total = 0;
563
566 {
568 add_v3_v3v3(result.median.location, a.median.location, b.median.location);
569 result.select_bounds = bounds::merge(a.select_bounds, b.select_bounds);
570 result.median.nurbs_weight = a.median.nurbs_weight + b.median.nurbs_weight;
571 result.median.radius = a.median.radius + b.median.radius;
572 result.median.tilt = a.median.tilt + b.median.tilt;
573 result.total = a.total + b.total;
574 result.total_curve_points = a.total_curve_points + b.total_curve_points;
575 result.total_nurbs_weights = a.total_nurbs_weights + b.total_nurbs_weights;
576 return result;
577 }
578};
579
584static bool grease_pencil_layer_is_skipped(const float4x4 &grease_pencil_layer_to_object)
585{
586 return math::determinant(float3x3(grease_pencil_layer_to_object)) == 0.0f;
587}
588
595 const float4x4 *grease_pencil_layer_to_object,
596 const float4x4 *bounds_matrix)
597{
598 using namespace ed::curves;
599
600 if (curves.is_empty()) {
602 }
603 auto to_object_space = [&](const float3 &co) {
604 return grease_pencil_layer_to_object ?
605 math::transform_point(*grease_pencil_layer_to_object, co) :
606 co;
607 };
608 const OffsetIndices points_by_curve = curves.points_by_curve();
609 const VArray<int8_t> curve_types = curves.curve_types();
610 const std::optional<Span<float>> nurbs_weights = curves.nurbs_weights();
611 const VArray<float> radius = curves.radius();
612 const VArray<float> tilt = curves.tilt();
613 const Span<float3> positions = curves.positions();
614
615 IndexMaskMemory memory;
616 const IndexMask selection = retrieve_selected_points(curves, memory);
617
619 curves.curves_range(),
620 512,
622 [&](const IndexRange range, const CurvesPointSelectionStatus &acc) {
623 CurvesPointSelectionStatus value = acc;
624
625 for (const int curve : range) {
626 const IndexRange points = points_by_curve[curve];
627 const CurveType curve_type = CurveType(curve_types[curve]);
628 const bool is_nurbs = curve_type == CURVE_TYPE_NURBS;
629 const IndexMask curve_selection = selection.slice_content(points);
630
631 value.total += curve_selection.size();
632 value.total_curve_points += curve_selection.size();
633
634 curve_selection.foreach_index([&](const int point) {
636 value.select_bounds,
637 bounds_matrix,
638 to_object_space(positions[point]));
639 value.total_nurbs_weights += is_nurbs;
640 value.median.nurbs_weight += is_nurbs ?
641 (nurbs_weights ? (*nurbs_weights)[point] : 1.0f) :
642 0;
643 value.median.radius += radius[point];
644 value.median.tilt += tilt[point];
645 });
646 }
647 return value;
648 },
650
651 if (!curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
652 return status;
653 }
654
656 curves, CURVE_TYPE_BEZIER, memory);
657
658 auto add_handles = [&](StringRef selection_attribute, std::optional<Span<float3>> positions) {
659 if (!positions) {
660 return;
661 }
662 const IndexMask selection = retrieve_selected_points(
663 curves, selection_attribute, bezier_points, memory);
664 if (selection.is_empty()) {
665 return;
666 }
667
668 status.total += selection.size();
669
670 selection.foreach_index_optimized<int>([&](const int point) {
672 status.select_bounds,
673 bounds_matrix,
674 to_object_space((*positions)[point]));
675 });
676 };
677
678 add_handles(".selection_handle_left", curves.handle_positions_left());
679 add_handles(".selection_handle_right", curves.handle_positions_right());
680 return status;
681}
682
689static float4x4 object_to_grease_pencil_layer_calc(const float4x4 &grease_pencil_layer_to_object)
690{
691 float4x4 object_to_grease_pencil_layer;
692 invert_m4_m4_safe_ortho(object_to_grease_pencil_layer.ptr(),
693 grease_pencil_layer_to_object.ptr());
694 return object_to_grease_pencil_layer;
695}
696
701static bool apply_to_curves_point_selection(const int tot,
702 const TransformMedian_Curves &median,
703 const TransformMedian_Curves &ve_median,
704 const std::optional<float4x4> &dims_mat_object,
705 const float4x4 *grease_pencil_layer_to_object,
706 TransformCoordsOrig *coords_orig,
708{
709 using namespace ed::curves;
710 if (curves.is_empty()) {
711 return false;
712 }
713
714 /* The median is a delta, with a single point selected it's absolute, see #apply_raw_diff_v3. */
715 float3 median_location = median.location;
716 float3 ve_median_location = ve_median.location;
717 std::optional<float4x4> dims_mat = dims_mat_object;
718 if (grease_pencil_layer_to_object) {
719 const float4x4 object_to_grease_pencil_layer = object_to_grease_pencil_layer_calc(
720 *grease_pencil_layer_to_object);
721 median_location = math::transform_direction(object_to_grease_pencil_layer, median_location);
722 ve_median_location = math::transform_point(object_to_grease_pencil_layer, ve_median_location);
723 if (dims_mat) {
724 dims_mat = object_to_grease_pencil_layer * (*dims_mat) * (*grease_pencil_layer_to_object);
725 }
726 }
727
728 bool changed = false;
729
730 const OffsetIndices points_by_curve = curves.points_by_curve();
731 const VArray<int8_t> curve_types = curves.curve_types();
732 const MutableSpan<float> nurbs_weights = median.nurbs_weight ? curves.nurbs_weights_for_write() :
734 const MutableSpan<float> radius = median.radius ? curves.radius_for_write() :
736 const MutableSpan<float> tilt = median.tilt ? curves.tilt_for_write() : MutableSpan<float>{};
737
738 IndexMaskMemory memory;
739 const IndexMask selection = retrieve_selected_points(curves, memory);
740 const bool update_dims = dims_mat.has_value();
741 const bool update_location = !update_dims && (math::length_manhattan(median_location) > 0);
742 MutableSpan<float3> positions = (update_location || update_dims) && !selection.is_empty() ?
743 curves.positions_for_write() :
745
746 threading::parallel_for(curves.curves_range(), 512, [&](const IndexRange range) {
747 for (const int curve : range) {
748 const IndexRange points = points_by_curve[curve];
749 const CurveType curve_type = CurveType(curve_types[curve]);
750 const bool is_nurbs = curve_type == CURVE_TYPE_NURBS;
751 const IndexMask curve_selection = selection.slice_content(points);
752
753 if (!curve_selection.is_empty()) {
754 changed = true;
755 }
756
757 curve_selection.foreach_index([&](const int point) {
758 if (is_nurbs && median.nurbs_weight) {
759 apply_raw_diff(&nurbs_weights[point], tot, ve_median.nurbs_weight, median.nurbs_weight);
760 nurbs_weights[point] = math::clamp(nurbs_weights[point], 0.01f, 100.0f);
761 }
762 if (median.radius) {
763 apply_raw_diff(&radius[point], tot, ve_median.radius, median.radius);
764 }
765 if (median.tilt) {
766 apply_raw_diff(&tilt[point], tot, ve_median.tilt, median.tilt);
767 }
768 if (update_location) {
769 apply_raw_diff_v3(positions[point], tot, ve_median_location, median_location);
770 }
771 });
772 }
773 });
774
775 /* Serial, coordinates are stored & restored in visit order. */
776 if (update_dims) {
777 selection.foreach_index(
778 [&](const int point) { coords_orig->apply(*dims_mat, positions[point]); });
779 }
780
781 /* Only location can be changed for Bezier handles. */
782 if ((!update_location && !update_dims) || !curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
783 return changed;
784 }
785
787 curves, CURVE_TYPE_BEZIER, memory);
788
789 auto apply_to_handles = [&](StringRef selection_attribute, StringRef handles_attribute) {
790 const IndexMask selection = retrieve_selected_points(
791 curves, selection_attribute, bezier_points, memory);
792 if (selection.is_empty()) {
793 return;
794 }
795
797 curves.attributes_for_write().lookup_for_write_span<float3>(handles_attribute);
798 if (update_location) {
799 selection.foreach_index(
800 [&](const int point) {
801 apply_raw_diff_v3(handles.span[point], tot, ve_median_location, median_location);
802 },
804 }
805 if (update_dims) {
806 selection.foreach_index(
807 [&](const int point) { coords_orig->apply(*dims_mat, handles.span[point]); });
808 }
809 handles.finish();
810
811 changed = true;
812 };
813
814 apply_to_handles(".selection_handle_left", "handle_left");
815 apply_to_handles(".selection_handle_right", "handle_right");
816
817 if (changed) {
818 curves.calculate_bezier_auto_handles();
819 }
820
821 return changed;
822}
823
824template<typename T> struct StatusValue {
827
828 static StatusValue sum(const StatusValue &a, const StatusValue &b)
829 {
830 return {
831 a.value_sum + b.value_sum,
832 math::max(a.value_max, b.value_max),
833 };
834 }
835};
836
838 int curve_count = 0;
839 int nurbs_count = 0;
841 int poly_count = 0;
842
846 int order_sum = 0;
847 int order_max = 0;
850
852 /* Use int for start_cap and end_cap, even though the underlying
853 * attribute is int8_t. The statusvalue is used to hold the
854 * summation of the value over all curves, so it needs the headroom.
855 */
861
863 {
864 return {
865 a.curve_count + b.curve_count,
866 a.nurbs_count + b.nurbs_count,
867 a.bezier_count + b.bezier_count,
868 a.poly_count + b.poly_count,
869 a.cyclic_count + b.cyclic_count,
870 a.nurbs_knot_mode_sum + b.nurbs_knot_mode_sum,
871 std::max(a.nurbs_knot_mode_max, b.nurbs_knot_mode_max),
872 a.order_sum + b.order_sum,
873 std::max(a.order_max, b.order_max),
874 a.resolution_sum + b.resolution_sum,
875 std::max(a.resolution_max, b.resolution_max),
876 StatusValue<float>::sum(a.fill_opacity, b.fill_opacity),
877 StatusValue<int>::sum(a.start_cap, b.start_cap),
878 StatusValue<int>::sum(a.end_cap, b.end_cap),
881 StatusValue<float>::sum(a.aspect_ratio, b.aspect_ratio),
882 };
883 }
884};
885
887{
888 using namespace ed::curves;
889
890 if (curves.is_empty()) {
891 return CurvesSelectionStatus();
892 }
893 const VArray<int8_t> curve_types = curves.curve_types();
894 const VArray<bool> cyclic = curves.cyclic();
895 const VArray<int8_t> nurbs_knot_modes = curves.nurbs_knots_modes();
896 const VArray<int8_t> orders = curves.nurbs_orders();
897 const VArray<int> resolution = curves.resolution();
898
899 IndexMaskMemory memory;
900 const IndexMask selection = retrieve_selected_curves(curves, memory);
901
903 curves.curves_range(),
904 512,
906 [&](const IndexRange range, const CurvesSelectionStatus &acc) {
907 CurvesSelectionStatus value = acc;
908
909 selection.slice_content(range).foreach_index([&](const int curve) {
910 const CurveType curve_type = CurveType(curve_types[curve]);
911 const bool is_nurbs = curve_type == CURVE_TYPE_NURBS;
912 const bool is_bezier = curve_type == CURVE_TYPE_BEZIER;
913 const bool is_poly = curve_type == CURVE_TYPE_POLY;
914
915 value.curve_count++;
916 value.nurbs_count += is_nurbs;
917 value.bezier_count += is_bezier;
918 value.poly_count += is_poly;
919
920 value.cyclic_count += cyclic[curve];
921
922 const int order = is_nurbs ? orders[curve] : 0;
923 value.order_sum += order;
924 value.order_max = std::max(value.order_max, order);
925
926 const int nurbs_knot_mode = is_nurbs ? nurbs_knot_modes[curve] : 0;
927 value.nurbs_knot_mode_sum += nurbs_knot_mode;
928 value.nurbs_knot_mode_max = std::max(value.nurbs_knot_mode_max, nurbs_knot_mode);
929
930 const int res = resolution[curve];
931 value.resolution_sum += res;
932 value.resolution_max = std::max(value.resolution_max, res);
933 });
934 return value;
935 },
937}
938
939template<typename T>
941 const blender::IndexMask &selection,
942 const T &default_value)
943{
944 using namespace blender;
945 if (!attribute) {
946 if (selection.is_empty()) {
947 return {T(0), T(0)};
948 }
949 return {T(default_value * selection.size()), default_value};
950 }
951
953 selection.index_range(),
954 512,
956 [&](const IndexRange range, const StatusValue<T> &acc) {
957 StatusValue<T> value = acc;
958
959 selection.slice(range).foreach_index([&](const int curve) {
960 const T attribute_value = attribute[curve];
961 value.value_sum += attribute_value;
962 value.value_max = math::max(value.value_max, attribute_value);
963 });
964 return value;
965 },
967}
968
971{
972 using namespace blender;
973 using namespace ed::curves;
974
975 if (curves.is_empty()) {
976 return CurvesSelectionStatus();
977 }
978
979 IndexMaskMemory memory;
980 const IndexMask selection = retrieve_selected_curves(curves, memory);
981 const bke::AttributeAccessor attributes = curves.attributes();
982
984
986 *attributes.lookup<float>("fill_opacity", bke::AttrDomain::Curve), selection, 1.0f);
988 *attributes.lookup<int>("start_cap", bke::AttrDomain::Curve),
989 selection,
992 *attributes.lookup<int>("end_cap", bke::AttrDomain::Curve),
993 selection,
996 *attributes.lookup<float>("softness", bke::AttrDomain::Curve), selection, 0.0f);
998 *attributes.lookup<float>("u_scale", bke::AttrDomain::Curve), selection, 1.0f);
1000 *attributes.lookup<float>("aspect_ratio", bke::AttrDomain::Curve), selection, 1.0f);
1001
1002 return status;
1003}
1004
1006
1007/* -------------------------------------------------------------------- */
1010
1012 const float4x4 *bounds_matrix,
1013 TransformMedian_Mesh &median,
1014 Bounds<float3> &r_select_bounds,
1015 int &tot,
1016 int &totedgedata)
1017{
1018 BMVert *eve;
1019 BMEdge *eed;
1020 BMIter iter;
1021
1022 const int cd_vert_bweight_offset = CustomData_get_offset_named(
1023 &bm.vdata, CD_PROP_FLOAT, "bevel_weight_vert");
1024 const int cd_vert_crease_offset = CustomData_get_offset_named(
1025 &bm.vdata, CD_PROP_FLOAT, "crease_vert");
1026 const int cd_vert_skin_offset = CustomData_get_offset_named(
1027 &bm.vdata, CD_PROP_FLOAT2, "skin_modifier_radius");
1028 const int cd_edge_bweight_offset = CustomData_get_offset_named(
1029 &bm.edata, CD_PROP_FLOAT, "bevel_weight_edge");
1030 const int cd_edge_crease_offset = CustomData_get_offset_named(
1031 &bm.edata, CD_PROP_FLOAT, "crease_edge");
1032
1033 if (bm.totvertsel) {
1034 BM_ITER_MESH (eve, &iter, &bm, BM_VERTS_OF_MESH) {
1036 tot++;
1037 median_bounds_add(median.location, r_select_bounds, bounds_matrix, eve->co);
1038
1039 if (cd_vert_bweight_offset != -1) {
1040 median.bv_weight += BM_ELEM_CD_GET_FLOAT(eve, cd_vert_bweight_offset);
1041 }
1042
1043 if (cd_vert_crease_offset != -1) {
1044 median.v_crease += BM_ELEM_CD_GET_FLOAT(eve, cd_vert_crease_offset);
1045 }
1046
1047 if (cd_vert_skin_offset != -1) {
1048 const float2 *radius = static_cast<const float2 *>(
1049 BM_ELEM_CD_GET_VOID_P(eve, cd_vert_skin_offset));
1050 add_v2_v2(median.skin, *radius);
1051 }
1052 }
1053 }
1054 }
1055
1056 if ((cd_edge_bweight_offset != -1) || (cd_edge_crease_offset != -1)) {
1057 if (bm.totedgesel) {
1058 BM_ITER_MESH (eed, &iter, &bm, BM_EDGES_OF_MESH) {
1060 if (cd_edge_bweight_offset != -1) {
1061 median.be_weight += BM_ELEM_CD_GET_FLOAT(eed, cd_edge_bweight_offset);
1062 }
1063
1064 if (cd_edge_crease_offset != -1) {
1065 median.e_crease += BM_ELEM_CD_GET_FLOAT(eed, cd_edge_crease_offset);
1066 }
1067
1068 totedgedata++;
1069 }
1070 }
1071 }
1072 }
1073 else {
1074 totedgedata = bm.totedgesel;
1075 }
1076}
1077
1079 const TransformMedian_Mesh &median,
1080 const TransformMedian_Mesh &ve_median,
1081 const int tot,
1082 const bool apply_vcos,
1083 const FunctionRef<void(float co[3])> apply_coord_fn)
1084{
1085 BMIter iter;
1086 BMVert *eve;
1087 BMEdge *eed;
1088
1089 int cd_vert_bweight_offset = -1;
1090 int cd_vert_crease_offset = -1;
1091 int cd_vert_skin_offset = -1;
1092 int cd_edge_bweight_offset = -1;
1093 int cd_edge_crease_offset = -1;
1094
1095 float scale_bv_weight = 1.0f;
1096 float scale_v_crease = 1.0f;
1097 float scale_skin[2] = {1.0f, 1.0f};
1098 float scale_be_weight = 1.0f;
1099 float scale_e_crease = 1.0f;
1100
1101 /* Vertices */
1102
1103 if (apply_vcos || median.bv_weight || median.v_crease || median.skin[0] || median.skin[1]) {
1104 if (median.bv_weight) {
1105 if (!CustomData_has_layer_named(&bm.vdata, CD_PROP_FLOAT, "bevel_weight_vert")) {
1106 BM_data_layer_add_named(&bm, &bm.vdata, CD_PROP_FLOAT, "bevel_weight_vert");
1107 }
1108 cd_vert_bweight_offset = CustomData_get_offset_named(
1109 &bm.vdata, CD_PROP_FLOAT, "bevel_weight_vert");
1110 BLI_assert(cd_vert_bweight_offset != -1);
1111
1112 scale_bv_weight = compute_scale_factor(ve_median.bv_weight, median.bv_weight);
1113 }
1114
1115 if (median.v_crease) {
1116 if (!CustomData_has_layer_named(&bm.vdata, CD_PROP_FLOAT, "crease_vert")) {
1117 BM_data_layer_add_named(&bm, &bm.vdata, CD_PROP_FLOAT, "crease_vert");
1118 }
1119 cd_vert_crease_offset = CustomData_get_offset_named(&bm.vdata, CD_PROP_FLOAT, "crease_vert");
1120 BLI_assert(cd_vert_crease_offset != -1);
1121
1122 scale_v_crease = compute_scale_factor(ve_median.v_crease, median.v_crease);
1123 }
1124
1125 for (int i = 0; i < 2; i++) {
1126 if (median.skin[i]) {
1127 cd_vert_skin_offset = CustomData_get_offset_named(
1128 &bm.vdata, CD_PROP_FLOAT2, "skin_modifier_radius");
1129 BLI_assert(cd_vert_skin_offset != -1);
1130
1131 if (ve_median.skin[i] != median.skin[i]) {
1132 scale_skin[i] = ve_median.skin[i] / (ve_median.skin[i] - median.skin[i]);
1133 }
1134 }
1135 }
1136
1137 BM_ITER_MESH (eve, &iter, &bm, BM_VERTS_OF_MESH) {
1139 apply_coord_fn(eve->co);
1140
1141 if (cd_vert_bweight_offset != -1) {
1142 float *b_weight = static_cast<float *>(
1143 BM_ELEM_CD_GET_VOID_P(eve, cd_vert_bweight_offset));
1144 apply_scale_factor_clamp(b_weight, tot, ve_median.bv_weight, scale_bv_weight);
1145 }
1146
1147 if (cd_vert_crease_offset != -1) {
1148 float *crease = static_cast<float *>(BM_ELEM_CD_GET_VOID_P(eve, cd_vert_crease_offset));
1149 apply_scale_factor_clamp(crease, tot, ve_median.v_crease, scale_v_crease);
1150 }
1151
1152 if (cd_vert_skin_offset != -1) {
1153 float2 *radius = static_cast<float2 *>(BM_ELEM_CD_GET_VOID_P(eve, cd_vert_skin_offset));
1154
1155 /* That one is not clamped to [0.0, 1.0]. */
1156 for (int i = 0; i < 2; i++) {
1157 if (median.skin[i] != 0.0f) {
1159 &(*radius)[i], tot, ve_median.skin[i], median.skin[i], scale_skin[i]);
1160 }
1161 }
1162 }
1163 }
1164 }
1165 }
1166
1167 /* Edges */
1168
1169 if (median.be_weight || median.e_crease) {
1170 if (median.be_weight) {
1171 if (!CustomData_has_layer_named(&bm.edata, CD_PROP_FLOAT, "bevel_weight_edge")) {
1172 BM_data_layer_add_named(&bm, &bm.edata, CD_PROP_FLOAT, "bevel_weight_edge");
1173 }
1174 cd_edge_bweight_offset = CustomData_get_offset_named(
1175 &bm.edata, CD_PROP_FLOAT, "bevel_weight_edge");
1176 BLI_assert(cd_edge_bweight_offset != -1);
1177
1178 scale_be_weight = compute_scale_factor(ve_median.be_weight, median.be_weight);
1179 }
1180
1181 if (median.e_crease) {
1182 if (!CustomData_has_layer_named(&bm.edata, CD_PROP_FLOAT, "crease_edge")) {
1183 BM_data_layer_add_named(&bm, &bm.edata, CD_PROP_FLOAT, "crease_edge");
1184 }
1185 cd_edge_crease_offset = CustomData_get_offset_named(&bm.edata, CD_PROP_FLOAT, "crease_edge");
1186 BLI_assert(cd_edge_crease_offset != -1);
1187
1188 scale_e_crease = compute_scale_factor(ve_median.e_crease, median.e_crease);
1189 }
1190
1191 BM_ITER_MESH (eed, &iter, &bm, BM_EDGES_OF_MESH) {
1193 if (median.be_weight != 0.0f) {
1194 float *b_weight = static_cast<float *>(
1195 BM_ELEM_CD_GET_VOID_P(eed, cd_edge_bweight_offset));
1196 apply_scale_factor_clamp(b_weight, tot, ve_median.be_weight, scale_be_weight);
1197 }
1198
1199 if (median.e_crease != 0.0f) {
1200 float *crease = static_cast<float *>(BM_ELEM_CD_GET_VOID_P(eed, cd_edge_crease_offset));
1201 apply_scale_factor_clamp(crease, tot, ve_median.e_crease, scale_e_crease);
1202 }
1203 }
1204 }
1205 }
1206}
1207
1209 const bContext *C, ui::Layout *layout, View3D *v3d, Object *ob, float lim)
1210{
1211 ui::Block *block = (layout) ? layout->absolute().block() : nullptr;
1213 TransformMedian median_basis, ve_median_basis;
1214 int tot, totedgedata, totcurvedata, totlattdata, totcurvebweight;
1215 /* Knots whose handles move with them, storing three coordinates not one. */
1216 int totcurvebezt = 0;
1217 int total_curve_points_data = 0;
1218 bool has_meshdata = false;
1219 bool has_skinradius = false;
1220 PointerRNA data_ptr;
1221
1222 std::fill_n(reinterpret_cast<float *>(&median_basis), TRANSFORM_MEDIAN_ARRAY_LEN, 0.0f);
1223 tot = totedgedata = totcurvedata = totlattdata = totcurvebweight = 0;
1224
1225 /* Measure the bounds in the space the dimensions are shown in, null for local. */
1226 const float4x4 *bounds_matrix = (v3d->flag & V3D_GLOBAL_STATS) ? &ob->object_to_world() :
1227 nullptr;
1228 Bounds<float3> select_bounds = median_bounds_init();
1229
1230 if (ob->type == OB_MESH) {
1231 TransformMedian_Mesh &median = median_basis.mesh;
1232 Mesh *mesh = id_cast<Mesh *>(ob->data);
1234 calc_median_bmesh(*bm, bounds_matrix, median, select_bounds, tot, totedgedata);
1235
1236 has_meshdata = (tot || totedgedata);
1237 has_skinradius = CustomData_has_layer_named(
1238 &bm->vdata, CD_PROP_FLOAT2, "skin_modifier_radius");
1239 }
1240 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
1241 TransformMedian_Curve *median = &median_basis.curve;
1242 Curve *cu = id_cast<Curve *>(ob->data);
1243 BPoint *bp;
1244 BezTriple *bezt;
1245 int a;
1246 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(cu);
1247 StructRNA *seltype = nullptr;
1248 void *selp = nullptr;
1249
1250 for (Nurb &nu : *nurbs) {
1251 if (nu.type == CU_BEZIER) {
1252 bezt = nu.bezt;
1253 a = nu.pntsu;
1254 while (a--) {
1255 if (bezt->f2 & SELECT) {
1256 median_bounds_add(median->location, select_bounds, bounds_matrix, bezt->vec[1]);
1257 tot++;
1258 totcurvebezt++;
1259 median->weight += bezt->weight;
1260 median->radius += bezt->radius;
1261 median->tilt += bezt->tilt;
1262 if (!totcurvedata) { /* I.e. first time... */
1263 selp = bezt;
1264 seltype = RNA_BezierSplinePoint;
1265 }
1266 totcurvedata++;
1267 }
1268 else {
1269 if (bezt->f1 & SELECT) {
1270 median_bounds_add(median->location, select_bounds, bounds_matrix, bezt->vec[0]);
1271 tot++;
1272 }
1273 if (bezt->f3 & SELECT) {
1274 median_bounds_add(median->location, select_bounds, bounds_matrix, bezt->vec[2]);
1275 tot++;
1276 }
1277 }
1278 bezt++;
1279 }
1280 }
1281 else {
1282 bp = nu.bp;
1283 a = nu.pntsu * nu.pntsv;
1284 while (a--) {
1285 if (bp->f1 & SELECT) {
1286 median_bounds_add(median->location, select_bounds, bounds_matrix, bp->vec);
1287 median->b_weight += bp->vec[3];
1288 totcurvebweight++;
1289 tot++;
1290 median->weight += bp->weight;
1291 median->radius += bp->radius;
1292 median->tilt += bp->tilt;
1293 if (!totcurvedata) { /* I.e. first time... */
1294 selp = bp;
1295 seltype = RNA_SplinePoint;
1296 }
1297 totcurvedata++;
1298 }
1299 bp++;
1300 }
1301 }
1302 }
1303
1304 if (totcurvedata == 1) {
1305 data_ptr = RNA_pointer_create_discrete(&cu->id, seltype, selp);
1306 }
1307 }
1308 else if (ob->type == OB_LATTICE) {
1309 Lattice *lt = id_cast<Lattice *>(ob->data);
1310 TransformMedian_Lattice *median = &median_basis.lattice;
1311 BPoint *bp;
1312 int a;
1313 StructRNA *seltype = nullptr;
1314 void *selp = nullptr;
1315
1316 a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
1317 bp = lt->editlatt->latt->def;
1318 while (a--) {
1319 if (bp->f1 & SELECT) {
1320 median_bounds_add(median->location, select_bounds, bounds_matrix, bp->vec);
1321 tot++;
1322 median->weight += bp->weight;
1323 if (!totlattdata) { /* I.e. first time... */
1324 selp = bp;
1325 seltype = RNA_LatticePoint;
1326 }
1327 totlattdata++;
1328 }
1329 bp++;
1330 }
1331
1332 if (totlattdata == 1) {
1333 data_ptr = RNA_pointer_create_discrete(&lt->id, seltype, selp);
1334 }
1335 }
1336 else if (ELEM(ob->type, OB_GREASE_PENCIL, OB_CURVES)) {
1338
1339 if (ob->type == OB_GREASE_PENCIL) {
1340 using namespace ed::greasepencil;
1341 using namespace ed::curves;
1342 Scene &scene = *CTX_data_scene(C);
1343 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob->data);
1344 Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(scene, grease_pencil);
1345
1347 drawings.index_range(),
1348 1L,
1350 [&](const IndexRange range, const CurvesPointSelectionStatus &acc) {
1351 CurvesPointSelectionStatus value = acc;
1352 for (const int drawing : range) {
1353 const MutableDrawingInfo &info = drawings[drawing];
1354 const float4x4 grease_pencil_layer_to_object =
1355 grease_pencil.layer(info.layer_index).to_object_space(*ob);
1356 if (grease_pencil_layer_is_skipped(grease_pencil_layer_to_object)) {
1357 continue;
1358 }
1360 value,
1362 info.drawing.strokes(), &grease_pencil_layer_to_object, bounds_matrix));
1363 }
1364 return value;
1365 },
1367 }
1368 else {
1369 using namespace ed::curves;
1370 const Curves &curves_id = *id_cast<Curves *>(ob->data);
1372 curves_id.geometry.wrap(), nullptr, bounds_matrix);
1373 }
1374
1375 TransformMedian_Curves &median = median_basis.curves;
1376 median = status.median;
1377 select_bounds = status.select_bounds;
1378 tot = status.total;
1379 total_curve_points_data = status.total_curve_points;
1380 totcurvebweight = status.total_nurbs_weights;
1381 }
1382
1383 if (tot == 0) {
1384 uiDefBut(block,
1386 IFACE_("Nothing selected"),
1387 0,
1388 130,
1389 200,
1390 20,
1391 nullptr,
1392 0,
1393 0,
1394 "");
1395 return;
1396 }
1397
1398 /* Location, X/Y/Z */
1399 mul_v3_fl(median_basis.generic.location, 1.0f / float(tot));
1400 if (v3d->flag & V3D_GLOBAL_STATS) {
1401 mul_m4_v3(ob->object_to_world().ptr(), median_basis.generic.location);
1402 }
1403
1404 if (has_meshdata) {
1405 TransformMedian_Mesh *median = &median_basis.mesh;
1406 if (totedgedata) {
1407 median->e_crease /= float(totedgedata);
1408 median->be_weight /= float(totedgedata);
1409 }
1410 if (tot) {
1411 median->bv_weight /= float(tot);
1412 median->v_crease /= float(tot);
1413 if (has_skinradius) {
1414 median->skin[0] /= float(tot);
1415 median->skin[1] /= float(tot);
1416 }
1417 }
1418 }
1419 else if (total_curve_points_data) {
1420 TransformMedian_Curves &median = median_basis.curves;
1421 if (totcurvebweight) {
1422 median.nurbs_weight /= totcurvebweight;
1423 }
1424 median.radius /= total_curve_points_data;
1425 median.tilt /= total_curve_points_data;
1426 }
1427 else if (totcurvedata) {
1428 TransformMedian_Curve *median = &median_basis.curve;
1429 if (totcurvebweight) {
1430 median->b_weight /= float(totcurvebweight);
1431 }
1432 median->weight /= float(totcurvedata);
1433 median->radius /= float(totcurvedata);
1434 median->tilt /= float(totcurvedata);
1435 }
1436 else if (totlattdata) {
1437 TransformMedian_Lattice *median = &median_basis.lattice;
1438 median->weight /= float(totlattdata);
1439 }
1440
1441 if (block) { /* buttons */
1442 ui::Button *but;
1443 int yi = 200;
1444 const float tilt_limit = DEG2RADF(21600.0f);
1445 const int butw = 200;
1446 const int buth = 20 * UI_SCALE_FAC;
1447 const int but_margin = 2;
1448 const char *c;
1449
1450 memcpy(&tfp->ve_median, &median_basis, sizeof(tfp->ve_median));
1451 /* Refresh both even when the buttons below are hidden,
1452 * any difference between them reads as an edit, see `ve_dims_prev`. */
1453 tfp->ve_dims = select_bounds.size();
1454 tfp->ve_dims_prev = tfp->ve_dims;
1455
1456 block_align_begin(block);
1457 if (tot == 1) {
1458 if (totcurvedata) {
1459 /* Curve */
1460 c = IFACE_("Control Point:");
1461 }
1462 else if (ELEM(ob->type, OB_CURVES, OB_GREASE_PENCIL)) {
1463 c = IFACE_("Point:");
1464 }
1465 else {
1466 /* Mesh or lattice */
1467 c = IFACE_("Vertex:");
1468 }
1469 }
1470 else {
1471 c = IFACE_("Median:");
1472 }
1473 uiDefBut(block, ui::ButtonType::Label, c, 0, yi -= buth, butw, buth, nullptr, 0, 0, "");
1474
1475 block_align_begin(block);
1476
1477 /* Should be no need to translate these. */
1478 but = uiDefButV(block,
1480 IFACE_("X:"),
1481 0,
1482 yi -= buth,
1483 butw,
1484 buth,
1485 &tfp->ve_median.generic.location[0],
1486 -lim,
1487 lim,
1488 "");
1489 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1490 button_number_step_size_set(but, 10);
1491 button_number_precision_set(but, RNA_TRANSLATION_PREC_DEFAULT);
1492 button_unit_type_set(but, PROP_UNIT_LENGTH);
1493 but = uiDefButV(block,
1495 IFACE_("Y:"),
1496 0,
1497 yi -= buth,
1498 butw,
1499 buth,
1500 &tfp->ve_median.generic.location[1],
1501 -lim,
1502 lim,
1503 "");
1504 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1505 button_number_step_size_set(but, 10);
1506 button_number_precision_set(but, RNA_TRANSLATION_PREC_DEFAULT);
1507 button_unit_type_set(but, PROP_UNIT_LENGTH);
1508 but = uiDefButV(block,
1510 IFACE_("Z:"),
1511 0,
1512 yi -= buth,
1513 butw,
1514 buth,
1515 &tfp->ve_median.generic.location[2],
1516 -lim,
1517 lim,
1518 "");
1519 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1520 button_number_step_size_set(but, 10);
1521 button_number_precision_set(but, RNA_TRANSLATION_PREC_DEFAULT);
1522 button_unit_type_set(but, PROP_UNIT_LENGTH);
1523
1524 if (totcurvebweight == tot) {
1525 float &weight = ELEM(ob->type, OB_CURVES, OB_GREASE_PENCIL) ?
1528 but = uiDefButV(block,
1530 IFACE_("W:"),
1531 0,
1532 yi -= buth,
1533 butw,
1534 buth,
1535 &weight,
1536 0.01,
1537 100.0,
1538 "");
1539 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1540 button_number_step_size_set(but, 1);
1541 button_number_precision_set(but, 3);
1542 }
1543 block_align_end(block);
1544
1545 /* A single point always has a zero size, the buttons would only show zeros. */
1546 if (tot > 1) {
1547 const StringRef dims_tip = TIP_(
1548 "Size of the selection, editing scales it about the transform pivot point");
1549 uiDefBut(block,
1551 IFACE_("Dimensions:"),
1552 0,
1553 yi -= buth + but_margin,
1554 butw,
1555 buth,
1556 nullptr,
1557 0,
1558 0,
1559 "");
1560
1561 block_align_begin(block);
1562 for (int i = 0; i < 3; i++) {
1563 const char text[3] = {char('X' + i), ':', '\0'};
1564 but = uiDefButV(block,
1566 text,
1567 0,
1568 yi -= buth,
1569 butw,
1570 buth,
1571 &tfp->ve_dims[i],
1572 0.0f,
1573 lim,
1574 dims_tip);
1575 button_retval_set(but, B_TRANSFORM_PANEL_ELEM_DIMS);
1576 button_number_step_size_set(but, 10);
1577 button_number_precision_set(but, 3);
1578 button_unit_type_set(but, PROP_UNIT_LENGTH);
1579 }
1580 block_align_end(block);
1581 }
1582
1583 block_align_begin(block);
1584 but = uiDefButBit(block,
1587 IFACE_("Global"),
1588 0,
1589 yi -= buth + but_margin,
1590 100,
1591 buth,
1592 &v3d->flag,
1593 0,
1594 0,
1595 TIP_("Displays global values"));
1597 but = uiDefButBit(block,
1600 IFACE_("Local"),
1601 100,
1602 yi,
1603 100,
1604 buth,
1605 &v3d->flag,
1606 0,
1607 0,
1608 TIP_("Displays local values"));
1610 block_align_end(block);
1611
1612 /* Meshes... */
1613 if (has_meshdata) {
1614 TransformMedian_Mesh *ve_median = &tfp->ve_median.mesh;
1615 if (tot) {
1616 uiDefBut(block,
1618 tot == 1 ? IFACE_("Vertex Data:") : IFACE_("Vertices Data:"),
1619 0,
1620 yi -= buth + but_margin,
1621 butw,
1622 buth,
1623 nullptr,
1624 0.0,
1625 0.0,
1626 "");
1627 /* customdata layer added on demand */
1628 but = uiDefButV(block,
1630 tot == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"),
1631 0,
1632 yi -= buth + but_margin,
1633 butw,
1634 buth,
1635 &ve_median->bv_weight,
1636 0.0,
1637 1.0,
1638 TIP_("Vertex weight used by Bevel modifier"));
1639 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1640 button_number_step_size_set(but, 1);
1641 button_number_precision_set(but, 2);
1642 /* customdata layer added on demand */
1643 but = uiDefButV(block,
1645 tot == 1 ? IFACE_("Vertex Crease:") : IFACE_("Mean Vertex Crease:"),
1646 0,
1647 yi -= buth + but_margin,
1648 butw,
1649 buth,
1650 &ve_median->v_crease,
1651 0.0,
1652 1.0,
1653 TIP_("Weight used by the Subdivision Surface modifier"));
1654 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1655 button_number_step_size_set(but, 1);
1656 button_number_precision_set(but, 2);
1657 }
1658 if (has_skinradius) {
1659 block_align_begin(block);
1660 but = uiDefButV(block,
1662 tot == 1 ? IFACE_("Radius X:") : IFACE_("Mean Radius X:"),
1663 0,
1664 yi -= buth + but_margin,
1665 butw,
1666 buth,
1667 &ve_median->skin[0],
1668 0.0,
1669 100.0,
1670 TIP_("X radius used by Skin modifier"));
1671 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1672 button_number_step_size_set(but, 1);
1673 button_number_precision_set(but, 3);
1674 but = uiDefButV(block,
1676 tot == 1 ? IFACE_("Radius Y:") : IFACE_("Mean Radius Y:"),
1677 0,
1678 yi -= buth + but_margin,
1679 butw,
1680 buth,
1681 &ve_median->skin[1],
1682 0.0,
1683 100.0,
1684 TIP_("Y radius used by Skin modifier"));
1685 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1686 button_number_step_size_set(but, 1);
1687 button_number_precision_set(but, 3);
1688 block_align_end(block);
1689 }
1690 if (totedgedata) {
1691 uiDefBut(block,
1693 totedgedata == 1 ? IFACE_("Edge Data:") : IFACE_("Edges Data:"),
1694 0,
1695 yi -= buth + but_margin,
1696 butw,
1697 buth,
1698 nullptr,
1699 0.0,
1700 0.0,
1701 "");
1702 /* customdata layer added on demand */
1703 but = uiDefButV(block,
1705 totedgedata == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"),
1706 0,
1707 yi -= buth + but_margin,
1708 butw,
1709 buth,
1710 &ve_median->be_weight,
1711 0.0,
1712 1.0,
1713 TIP_("Edge weight used by Bevel modifier"));
1714 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1715 button_number_step_size_set(but, 1);
1716 button_number_precision_set(but, 2);
1717 /* customdata layer added on demand */
1718 but = uiDefButV(block,
1720 totedgedata == 1 ? IFACE_("Crease:") : IFACE_("Mean Crease:"),
1721 0,
1722 yi -= buth + but_margin,
1723 butw,
1724 buth,
1725 &ve_median->e_crease,
1726 0.0,
1727 1.0,
1728 TIP_("Weight used by the Subdivision Surface modifier"));
1729 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1730 button_number_step_size_set(but, 1);
1731 button_number_precision_set(but, 2);
1732 }
1733 }
1734 /* Curve or GP... */
1735 else if (total_curve_points_data) {
1736 const bool is_single = total_curve_points_data == 1;
1737 TransformMedian_Curves *ve_median = &tfp->ve_median.curves;
1738
1739 but = uiDefButV(block,
1741 is_single ? IFACE_("Radius:") : IFACE_("Mean Radius:"),
1742 0,
1743 yi -= buth + but_margin,
1744 butw,
1745 buth,
1746 &ve_median->radius,
1747 0.0,
1748 100.0,
1749 is_single ?
1750 std::nullopt :
1751 std::optional<StringRef>{TIP_("Radius of curve control points")});
1752 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1753 button_number_step_size_set(but, 1);
1754 button_number_precision_set(but, 3);
1755 but = uiDefButV(block,
1757 is_single ? IFACE_("Tilt:") : IFACE_("Mean Tilt:"),
1758 0,
1759 yi -= buth + but_margin,
1760 butw,
1761 buth,
1762 &ve_median->tilt,
1763 -tilt_limit,
1764 tilt_limit,
1765 is_single ? std::nullopt :
1766 std::optional<StringRef>{TIP_("Tilt of curve control points")});
1767 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1768 button_number_step_size_set(but, 1);
1769 button_number_precision_set(but, 3);
1770 button_unit_type_set(but, PROP_UNIT_ROTATION);
1771 }
1772 /* Curve... */
1773 else if (totcurvedata) {
1774 TransformMedian_Curve *ve_median = &tfp->ve_median.curve;
1775 if (totcurvedata == 1) {
1776 but = uiDefButR(block,
1778 IFACE_("Weight:"),
1779 0,
1780 yi -= buth + but_margin,
1781 butw,
1782 buth,
1783 &data_ptr,
1784 "weight_softbody",
1785 0,
1786 0.0,
1787 1.0,
1788 std::nullopt);
1789 button_number_step_size_set(but, 1);
1790 button_number_precision_set(but, 3);
1791 but = uiDefButR(block,
1793 IFACE_("Radius:"),
1794 0,
1795 yi -= buth + but_margin,
1796 butw,
1797 buth,
1798 &data_ptr,
1799 "radius",
1800 0,
1801 0.0,
1802 100.0,
1803 std::nullopt);
1804 button_number_step_size_set(but, 1);
1805 button_number_precision_set(but, 3);
1806 but = uiDefButR(block,
1808 IFACE_("Tilt:"),
1809 0,
1810 yi -= buth + but_margin,
1811 butw,
1812 buth,
1813 &data_ptr,
1814 "tilt",
1815 0,
1816 -tilt_limit,
1817 tilt_limit,
1818 std::nullopt);
1819 button_number_step_size_set(but, 1);
1820 button_number_precision_set(but, 3);
1821 }
1822 else if (totcurvedata > 1) {
1823 but = uiDefButV(block,
1825 IFACE_("Mean Weight:"),
1826 0,
1827 yi -= buth + but_margin,
1828 butw,
1829 buth,
1830 &ve_median->weight,
1831 0.0,
1832 1.0,
1833 TIP_("Weight used for Soft Body Goal"));
1834 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1835 button_number_step_size_set(but, 1);
1836 button_number_precision_set(but, 3);
1837 but = uiDefButV(block,
1839 IFACE_("Mean Radius:"),
1840 0,
1841 yi -= buth + but_margin,
1842 butw,
1843 buth,
1844 &ve_median->radius,
1845 0.0,
1846 100.0,
1847 TIP_("Radius of curve control points"));
1848 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1849 button_number_step_size_set(but, 1);
1850 button_number_precision_set(but, 3);
1851 but = uiDefButV(block,
1853 IFACE_("Mean Tilt:"),
1854 0,
1855 yi -= buth + but_margin,
1856 butw,
1857 buth,
1858 &ve_median->tilt,
1859 -tilt_limit,
1860 tilt_limit,
1861 TIP_("Tilt of curve control points"));
1862 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1863 button_number_step_size_set(but, 1);
1864 button_number_precision_set(but, 3);
1865 button_unit_type_set(but, PROP_UNIT_ROTATION);
1866 }
1867 }
1868 /* Lattice... */
1869 else if (totlattdata) {
1870 TransformMedian_Lattice *ve_median = &tfp->ve_median.lattice;
1871 if (totlattdata == 1) {
1872 but = uiDefButR(block,
1874 IFACE_("Weight:"),
1875 0,
1876 yi -= buth + but_margin,
1877 butw,
1878 buth,
1879 &data_ptr,
1880 "weight_softbody",
1881 0,
1882 0.0,
1883 1.0,
1884 std::nullopt);
1885 button_number_step_size_set(but, 1);
1886 button_number_precision_set(but, 3);
1887 }
1888 else if (totlattdata > 1) {
1889 but = uiDefButV(block,
1891 IFACE_("Mean Weight:"),
1892 0,
1893 yi -= buth + but_margin,
1894 butw,
1895 buth,
1896 &ve_median->weight,
1897 0.0,
1898 1.0,
1899 TIP_("Weight used for Soft Body Goal"));
1900 button_retval_set(but, B_TRANSFORM_PANEL_MEDIAN);
1901 button_number_step_size_set(but, 1);
1902 button_number_precision_set(but, 3);
1903 }
1904 }
1905
1906 block_align_end(block);
1907
1908 /* Not only for meshes, the callbacks also free the original coordinates. */
1909 ui::BlockInteraction_CallbackData callback_data{};
1913 callback_data.arg1 = ob;
1914 block_interaction_set(block, &callback_data);
1915 }
1916 else {
1917 /* Getting here (via #do_view3d_region_buttons()) if the above buttons return
1918 * B_TRANSFORM_PANEL_MEDIAN, so either when multiple elements are selected or no RNA buttons
1919 * are used. Either way, we are now setting values directly (not via RNA buttons) and thus lack
1920 * automatic RNA updates. We could run the actual RNA updates (creating a PointerRNA, finding
1921 * the specific PropertyRNA and calling #RNA_property_update()), but for one, this creates a
1922 * lot of noisy code and secondly, it also would not work for bmesh (since that has no RNA
1923 * updates). Instead, just run the corresponding notifiers and dependency graph tagging (see
1924 * for each object type below). */
1925 memcpy(&ve_median_basis, &tfp->ve_median, sizeof(tfp->ve_median));
1926
1927 if (v3d->flag & V3D_GLOBAL_STATS) {
1928 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
1929 mul_m4_v3(ob->world_to_object().ptr(), median_basis.generic.location);
1930 mul_m4_v3(ob->world_to_object().ptr(), ve_median_basis.generic.location);
1931 }
1932 sub_vn_vnvn(reinterpret_cast<float *>(&median_basis),
1933 reinterpret_cast<float *>(&ve_median_basis),
1934 reinterpret_cast<float *>(&median_basis),
1936
1937 /* None unless a dimension button was edited. The bounds check is paranoid, a non-zero `tot`
1938 * implies they're set, however an unset range reads as a negative (infinite) size. */
1939 std::optional<float4x4> dims_mat;
1940 TransformCoordsOrig *coords_orig = tfp->coords_orig ? &*tfp->coords_orig : nullptr;
1941 if (median_bounds_is_set(select_bounds)) {
1942 const float3 dims_new = tfp->ve_dims;
1943 if ((coords_orig == nullptr) && (dims_new != tfp->ve_dims_prev)) {
1944 /* The first update runs before anything is scaled, so this size is the original. */
1945 const Scene *scene = CTX_data_scene(C);
1946 float3 pivot;
1948 coords_orig = &tfp->coords_orig.emplace();
1949 coords_orig->dims = select_bounds.size();
1950 coords_orig->pivot = pivot;
1951 coords_orig->coords.reinitialize(tot + (totcurvebezt * 2));
1952 }
1953 }
1954 if (coords_orig) {
1956 *ob, bounds_matrix, coords_orig->pivot, coords_orig->dims, dims_new);
1957 if (dims_mat) {
1958 coords_orig->coords_index = 0;
1959 }
1960 }
1961 }
1962
1963 /* Note with a single element selected, we always do. */
1964 const bool apply_vcos = (tot == 1) || dims_mat.has_value() ||
1965 (len_squared_v3(median_basis.generic.location) != 0.0f);
1966
1967 /* Scaling takes the coordinate from the drag start.
1968 *
1969 * NOTE(@ideasman42): dragging location & dimensions together isn't supported,
1970 * dimensions take priority and location edits are ignored.
1971 * Preventing both being dragged at once is possible, however the buttons are far apart
1972 * so this is unlikely in practice and not worth the hassle. */
1973 auto apply_coord_fn = [&](float co[3]) {
1974 if (dims_mat) {
1975 coords_orig->apply(*dims_mat, *reinterpret_cast<float3 *>(co));
1976 }
1977 else if (apply_vcos) {
1979 co, tot, ve_median_basis.generic.location, median_basis.generic.location);
1980 }
1981 };
1982
1983 if ((ob->type == OB_MESH) &&
1984 (apply_vcos || median_basis.mesh.bv_weight || median_basis.mesh.v_crease ||
1985 median_basis.mesh.skin[0] || median_basis.mesh.skin[1] || median_basis.mesh.be_weight ||
1986 median_basis.mesh.e_crease))
1987 {
1988 const TransformMedian_Mesh &median = median_basis.mesh;
1989 const TransformMedian_Mesh &ve_median = ve_median_basis.mesh;
1990 Mesh *mesh = id_cast<Mesh *>(ob->data);
1992 apply_median_to_bmesh(*bm, median, ve_median, tot, apply_vcos, apply_coord_fn);
1993
1994 if (apply_vcos) {
1995 /* Tell the update callback to run. */
1996 tfp->tag_for_update = true;
1997 }
1998
1999 /* We basically want the same update as in #EDBM_update(), so keep in sync. */
2001 }
2002 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF) &&
2003 (apply_vcos || median_basis.curve.b_weight || median_basis.curve.weight ||
2004 median_basis.curve.radius || median_basis.curve.tilt))
2005 {
2006 const TransformMedian_Curve *median = &median_basis.curve,
2007 *ve_median = &ve_median_basis.curve;
2008 Curve *cu = id_cast<Curve *>(ob->data);
2009 BPoint *bp;
2010 BezTriple *bezt;
2011 int a;
2012 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(cu);
2013 const float scale_w = compute_scale_factor(ve_median->weight, median->weight);
2014
2015 for (Nurb &nu : *nurbs) {
2016 if (nu.type == CU_BEZIER) {
2017 for (a = nu.pntsu, bezt = nu.bezt; a--; bezt++) {
2018 if (bezt->f2 & SELECT) {
2019 if (dims_mat) {
2020 for (const int i : IndexRange(3)) {
2021 coords_orig->apply(*dims_mat, *reinterpret_cast<float3 *>(bezt->vec[i]));
2022 }
2023 }
2024 else if (apply_vcos) {
2025 /* Here we always have to use the diff... :/
2026 * Cannot avoid some glitches when going e.g. from 3 to 0.0001 (see #37327),
2027 * unless we use doubles.
2028 */
2029 add_v3_v3(bezt->vec[0], median->location);
2030 add_v3_v3(bezt->vec[1], median->location);
2031 add_v3_v3(bezt->vec[2], median->location);
2032 }
2033 if (median->weight) {
2034 apply_scale_factor_clamp(&bezt->weight, tot, ve_median->weight, scale_w);
2035 }
2036 if (median->radius) {
2037 apply_raw_diff(&bezt->radius, tot, ve_median->radius, median->radius);
2038 }
2039 if (median->tilt) {
2040 apply_raw_diff(&bezt->tilt, tot, ve_median->tilt, median->tilt);
2041 }
2042 }
2043 else if (apply_vcos) {
2044 /* Handles can only have their coordinates changed here. */
2045 if (bezt->f1 & SELECT) {
2046 apply_coord_fn(bezt->vec[0]);
2047 }
2048 if (bezt->f3 & SELECT) {
2049 apply_coord_fn(bezt->vec[2]);
2050 }
2051 }
2052 }
2053 }
2054 else {
2055 for (a = nu.pntsu * nu.pntsv, bp = nu.bp; a--; bp++) {
2056 if (bp->f1 & SELECT) {
2057 apply_coord_fn(bp->vec);
2058 if (median->b_weight) {
2059 apply_raw_diff(&bp->vec[3], tot, ve_median->b_weight, median->b_weight);
2060 }
2061 if (median->weight) {
2062 apply_scale_factor_clamp(&bp->weight, tot, ve_median->weight, scale_w);
2063 }
2064 if (median->radius) {
2065 apply_raw_diff(&bp->radius, tot, ve_median->radius, median->radius);
2066 }
2067 if (median->tilt) {
2068 apply_raw_diff(&bp->tilt, tot, ve_median->tilt, median->tilt);
2069 }
2070 }
2071 }
2072 }
2073 if (CU_IS_2D(cu)) {
2075 }
2076 /* In the case of weight, tilt or radius (these don't change positions),
2077 * don't change handle types. */
2078 if ((nu.type == CU_BEZIER) && apply_vcos) {
2079 BKE_nurb_handles_test(&nu, NURB_HANDLE_TEST_EACH, false); /* test for bezier too */
2080 }
2081 /* We basically want the same update as in #rna_Curve_update_data_id(), so keep in sync. */
2083 }
2084 }
2085 else if ((ob->type == OB_LATTICE) && (apply_vcos || median_basis.lattice.weight)) {
2086 const TransformMedian_Lattice *median = &median_basis.lattice,
2087 *ve_median = &ve_median_basis.lattice;
2088 Lattice *lt = id_cast<Lattice *>(ob->data);
2089 BPoint *bp;
2090 int a;
2091 const float scale_w = compute_scale_factor(ve_median->weight, median->weight);
2092
2093 a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
2094 bp = lt->editlatt->latt->def;
2095 while (a--) {
2096 if (bp->f1 & SELECT) {
2097 apply_coord_fn(bp->vec);
2098 if (median->weight) {
2099 apply_scale_factor_clamp(&bp->weight, tot, ve_median->weight, scale_w);
2100 }
2101 }
2102 bp++;
2103 }
2104 /* We basically want the same update as in #rna_Lattice_update_data(), so keep in sync. */
2106 }
2107 else if (ob->type == OB_GREASE_PENCIL &&
2108 (apply_vcos || median_basis.curves.nurbs_weight || median_basis.curves.radius ||
2109 median_basis.curves.tilt))
2110 {
2111 using namespace ed::greasepencil;
2112 using namespace ed::curves;
2113 Scene &scene = *CTX_data_scene(C);
2114 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob->data);
2115 Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(scene, grease_pencil);
2116
2117 auto apply_drawing = [&](const MutableDrawingInfo &info) {
2118 bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
2119 const float4x4 grease_pencil_layer_to_object =
2120 grease_pencil.layer(info.layer_index).to_object_space(*ob);
2121 /* Must match the measurement, #tot and #coords_orig only count these points. */
2122 if (grease_pencil_layer_is_skipped(grease_pencil_layer_to_object)) {
2123 return;
2124 }
2126 median_basis.curves,
2127 ve_median_basis.curves,
2128 dims_mat,
2129 &grease_pencil_layer_to_object,
2130 coords_orig,
2131 curves))
2132 {
2133 info.drawing.tag_positions_changed();
2134 }
2135 };
2136 if (dims_mat) {
2137 /* `coords_orig` stores one coordinate per point in visit order, so `drawings`
2138 * must be visited serially and in the same order on every update. */
2139 for (const MutableDrawingInfo &info : drawings) {
2140 apply_drawing(info);
2141 }
2142 }
2143 else {
2144 threading::parallel_for_each(drawings, apply_drawing);
2145 }
2146 /* We basically want the same update as in #rna_grease_pencil_update(), so keep in sync. */
2148 }
2149 else if (ob->type == OB_CURVES && (apply_vcos || median_basis.curves.nurbs_weight ||
2150 median_basis.curves.radius || median_basis.curves.tilt))
2151 {
2152 using namespace ed::curves;
2153 Curves &curves_id = *id_cast<Curves *>(ob->data);
2154 bke::CurvesGeometry &curves = curves_id.geometry.wrap();
2156 median_basis.curves,
2157 ve_median_basis.curves,
2158 dims_mat,
2159 nullptr,
2160 coords_orig,
2161 curves))
2162 {
2163 curves.tag_positions_changed();
2164 }
2165 /* We basically want the same update as in #rna_Curves_update_data(), so keep in sync. */
2166 WM_main_add_notifier(NC_GEOM | ND_DATA, &curves_id.id);
2167 }
2168
2169 if (dims_mat) {
2170 /* A shortfall means an element type is measured but never scaled. */
2171 BLI_assert(coords_orig->coords_index == coords_orig->coords.size());
2172 coords_orig->is_stored = true;
2173 }
2174
2176 }
2177
2178 // ED_undo_push(C, "Transform properties");
2179}
2180
2181#undef TRANSFORM_MEDIAN_ARRAY_LEN
2182
2184
2185/* -------------------------------------------------------------------- */
2188
2190{
2191 ui::Block *block = (layout) ? layout->block() : nullptr;
2192 ui::Layout *sub_layout = layout ? &layout->absolute(false) : nullptr;
2194 const bool is_editable = ID_IS_EDITABLE(&ob->id);
2195
2196 if (block) {
2197 BLI_assert(C == nullptr);
2198 int yi = 200;
2199 const int butw = 200;
2200 const int buth = 20 * UI_SCALE_FAC;
2201
2203 copy_v3_v3(tfp->ob_dims_orig, tfp->ob_dims);
2204 copy_v3_v3(tfp->ob_scale_orig, ob->scale);
2205 copy_m4_m4(tfp->ob_obmat_orig, ob->object_to_world().ptr());
2206
2207 if (!is_editable && sub_layout) {
2208 sub_layout->enabled_set(false);
2209 }
2210
2211 uiDefBut(block,
2213 IFACE_("Dimensions:"),
2214 0,
2215 yi -= buth,
2216 butw,
2217 buth,
2218 nullptr,
2219 0,
2220 0,
2221 "");
2222 block_align_begin(block);
2223 const float lim = FLT_MAX;
2224 for (int i = 0; i < 3; i++) {
2225 ui::Button *but;
2226 const char text[3] = {char('X' + i), ':', '\0'};
2227 but = uiDefButV(block,
2229 text,
2230 0,
2231 yi -= buth,
2232 butw,
2233 buth,
2234 &(tfp->ob_dims[i]),
2235 0.0f,
2236 lim,
2237 "");
2238 button_retval_set(but, B_TRANSFORM_PANEL_OBJECT_DIMS);
2239 button_number_step_size_set(but, 10);
2240 button_number_precision_set(but, 3);
2241 button_unit_type_set(but, PROP_UNIT_LENGTH);
2242 if (!is_editable) {
2243 button_disable(but, "Cannot edit this property from a linked data-block");
2244 }
2245 }
2246 block_align_end(block);
2247 }
2248 else { /* apply */
2249 int axis_mask = 0;
2250 for (int i = 0; i < 3; i++) {
2251 if (tfp->ob_dims[i] == tfp->ob_dims_orig[i]) {
2252 axis_mask |= (1 << i);
2253 }
2254 }
2256 ob, tfp->ob_dims, axis_mask, tfp->ob_scale_orig, tfp->ob_obmat_orig);
2257
2258 PointerRNA obptr = RNA_id_pointer_create(&ob->id);
2259 PropertyRNA *prop = RNA_struct_find_property(&obptr, "scale");
2260 RNA_property_update(C, &obptr, prop);
2261 }
2262}
2263
2265
2266/* -------------------------------------------------------------------- */
2269
2270#define B_VGRP_PNL_EDIT_SINGLE 8 /* or greater */
2271
2272static void do_view3d_vgroup_buttons(bContext *C, void * /*arg*/, int event)
2273{
2274 if (event < B_VGRP_PNL_EDIT_SINGLE) {
2275 /* not for me */
2276 return;
2277 }
2278
2279 const Main *bmain = CTX_data_main(C);
2280 const Scene *scene = CTX_data_scene(C);
2281 ViewLayer *view_layer = CTX_data_view_layer(C);
2282 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2283 Object *ob = BKE_view_layer_active_object_get(view_layer);
2287}
2288
2289static bool view3d_panel_vgroup_poll(const bContext *C, PanelType * /*pt*/)
2290{
2291 const Main *bmain = CTX_data_main(C);
2292 const Scene *scene = CTX_data_scene(C);
2293 ViewLayer *view_layer = CTX_data_view_layer(C);
2294 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2295 Object *ob = BKE_view_layer_active_object_get(view_layer);
2298 if (dvert_act) {
2299 return (dvert_act->totweight != 0);
2300 }
2301 }
2302
2303 return false;
2304}
2305
2306static void update_active_vertex_weight(bContext *C, void *arg1, void * /*arg2*/)
2307{
2308 View3D *v3d = CTX_wm_view3d(C);
2310 ViewLayer *view_layer = CTX_data_view_layer(C);
2311 Object *ob = BKE_view_layer_active_object_get(view_layer);
2313 const int vertex_group_index = POINTER_AS_INT(arg1);
2314 MDeformWeight *dw = BKE_defvert_find_index(dv, vertex_group_index);
2315 dw->weight = tfp->vertex_weights[vertex_group_index];
2316}
2317
2318static void view3d_panel_vgroup(const bContext *C, Panel *panel)
2319{
2320 ui::Block *block = panel->layout->absolute().block();
2321 const Main *bmain = CTX_data_main(C);
2322 Scene *scene = CTX_data_scene(C);
2323 ViewLayer *view_layer = CTX_data_view_layer(C);
2324 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2325 Object *ob = BKE_view_layer_active_object_get(view_layer);
2326 View3D *v3d = CTX_wm_view3d(C);
2328
2329 MDeformVert *dv;
2330
2332
2333 if (dv && dv->totweight) {
2334 ToolSettings *ts = scene->toolsettings;
2335
2336 wmOperatorType *ot;
2337 PointerRNA op_ptr;
2338 PointerRNA *but_ptr;
2339
2340 ui::Layout *col, *bcol;
2341 ui::Layout *row;
2342 ui::Button *but;
2343 bDeformGroup *dg;
2344 uint i;
2345 int subset_count, vgroup_tot;
2346 const bool *vgroup_validmap;
2347 eVGroupSelect subset_type = eVGroupSelect(ts->vgroupsubset);
2348 int yco = 0;
2349 int lock_count = 0;
2350
2351 block_func_handle_set(block, do_view3d_vgroup_buttons, nullptr);
2352
2353 bcol = &panel->layout->column(true);
2354 row = &bcol->row(true); /* The filter button row */
2355
2356 PointerRNA tools_ptr = RNA_pointer_create_discrete(nullptr, RNA_ToolSettings, ts);
2357 row->prop(&tools_ptr, "vertex_group_subset", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
2358
2359 col = &bcol->column(true);
2360
2362 ob, subset_type, &vgroup_tot, &subset_count);
2363 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
2364 const int vgroup_num = defbase->count();
2365 tfp->vertex_weights.resize(vgroup_num);
2366
2367 for (i = 0, dg = defbase->first(); dg; i++, dg = dg->next) {
2368 bool locked = (dg->flag & DG_LOCK_WEIGHT) != 0;
2369 if (vgroup_validmap[i]) {
2371 if (dw) {
2372 int x, xco = 0;
2373 int icon;
2374 ui::Layout &split = col->split(0.45, true);
2375 row = &split.row(true);
2376
2377 /* The Weight Group Name */
2378
2379 ot = WM_operatortype_find("OBJECT_OT_vertex_weight_set_active", true);
2380 but = uiDefButO_ptr(block,
2382 ot,
2384 dg->name,
2385 xco,
2386 yco,
2387 (x = UI_UNIT_X * 5),
2388 UI_UNIT_Y,
2389 "");
2390 but_ptr = button_operator_ptr_ensure(but);
2391 RNA_int_set(but_ptr, "weight_group", i);
2392 button_drawflag_enable(but, ui::BUT_TEXT_RIGHT);
2393 if (BKE_object_defgroup_active_index_get(ob) != i + 1) {
2394 button_flag_enable(but, ui::BUT_INACTIVE);
2395 }
2396 xco += x;
2397
2398 row = &split.row(true);
2399 row->enabled_set(!locked);
2400
2401 /* The weight group value */
2402 /* To be reworked still */
2403 float &vertex_weight = tfp->vertex_weights[i];
2404 vertex_weight = dw->weight;
2405 but = uiDefButV(block,
2407 "",
2408 xco,
2409 yco,
2410 (x = UI_UNIT_X * 4),
2411 UI_UNIT_Y,
2412 &vertex_weight,
2413 0.0,
2414 1.0,
2415 "");
2416 button_retval_set(but, B_VGRP_PNL_EDIT_SINGLE + i);
2417 button_number_step_size_set(but, 1);
2418 button_number_precision_set(but, 3);
2419 button_drawflag_enable(but, ui::BUT_TEXT_LEFT);
2420 button_func_set(but, update_active_vertex_weight, POINTER_FROM_INT(i), nullptr);
2421 if (locked) {
2422 lock_count++;
2423 }
2424 xco += x;
2425
2426 /* The weight group paste function */
2427 icon = (locked) ? ICON_BLANK1 : ICON_PASTEDOWN;
2428 op_ptr = row->op("OBJECT_OT_vertex_weight_paste",
2429 "",
2430 icon,
2432 UI_ITEM_NONE);
2433 RNA_int_set(&op_ptr, "weight_group", i);
2434
2435 /* The weight entry delete function */
2436 icon = (locked) ? ICON_LOCKED : ICON_X;
2437 op_ptr = row->op("OBJECT_OT_vertex_weight_delete",
2438 "",
2439 icon,
2441 UI_ITEM_NONE);
2442 RNA_int_set(&op_ptr, "weight_group", i);
2443
2444 yco -= UI_UNIT_Y;
2445 }
2446 }
2447 }
2448 MEM_delete(vgroup_validmap);
2449
2450 yco -= 2;
2451
2452 col = &panel->layout->column(true);
2453 row = &col->row(true);
2454
2455 ot = WM_operatortype_find("OBJECT_OT_vertex_weight_normalize_active_vertex", true);
2456 but = uiDefButO_ptr(
2457 block,
2459 ot,
2461 IFACE_("Normalize"),
2462 0,
2463 yco,
2464 UI_UNIT_X * 5,
2465 UI_UNIT_Y,
2466 TIP_("Normalize weights of active vertex (if affected groups are unlocked)"));
2467
2468 ot = WM_operatortype_find("OBJECT_OT_vertex_weight_copy", true);
2469 but = uiDefButO_ptr(
2470 block,
2472 ot,
2474 IFACE_("Copy"),
2475 UI_UNIT_X * 5,
2476 yco,
2477 UI_UNIT_X * 5,
2478 UI_UNIT_Y,
2479 TIP_("Copy active vertex to other selected vertices (if affected groups are unlocked)"));
2480 if (lock_count) {
2481 button_flag_enable(but, ui::BUT_DISABLED);
2482 }
2483 }
2484}
2485
2487
2488/* -------------------------------------------------------------------- */
2491
2493{
2494 ui::Layout *split = &layout.split(0.8f, false);
2495
2496 if (ptr->type == RNA_PoseBone) {
2497 PointerRNA boneptr;
2498 Bone *bone;
2499
2500 boneptr = RNA_pointer_get(ptr, "bone");
2501 bone = static_cast<Bone *>(boneptr.data);
2502 split->active_set(!(bone->parent && bone->flag & BONE_CONNECTED));
2503 }
2504 ui::Layout *colsub = &split->column(true);
2505 colsub->prop(ptr, "location", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2506 colsub = &split->column(true);
2508 colsub->label("", ICON_NONE);
2509 colsub->prop(
2510 ptr, "lock_location", ui::ITEM_R_TOGGLE | ui::ITEM_R_ICON_ONLY, "", ICON_DECORATE_UNLOCKED);
2511
2512 split = &layout.split(0.8f, false);
2513
2514 switch (RNA_enum_get(ptr, "rotation_mode")) {
2515 case ROT_MODE_QUAT: /* quaternion */
2516 colsub = &split->column(true);
2517 colsub->prop(ptr, "rotation_quaternion", UI_ITEM_NONE, IFACE_("Rotation"), ICON_NONE);
2518 colsub = &split->column(true);
2520 colsub->prop(ptr, "lock_rotations_4d", ui::ITEM_R_TOGGLE, IFACE_("4L"), ICON_NONE);
2521 if (RNA_boolean_get(ptr, "lock_rotations_4d")) {
2522 colsub->prop(ptr,
2523 "lock_rotation_w",
2525 "",
2526 ICON_DECORATE_UNLOCKED);
2527 }
2528 else {
2529 colsub->label("", ICON_NONE);
2530 }
2531 colsub->prop(ptr,
2532 "lock_rotation",
2534 "",
2535 ICON_DECORATE_UNLOCKED);
2536 break;
2537 case ROT_MODE_AXISANGLE: /* axis angle */
2538 colsub = &split->column(true);
2539 colsub->prop(ptr, "rotation_axis_angle", UI_ITEM_NONE, IFACE_("Rotation"), ICON_NONE);
2540 colsub = &split->column(true);
2542 colsub->prop(ptr, "lock_rotations_4d", ui::ITEM_R_TOGGLE, IFACE_("4L"), ICON_NONE);
2543 if (RNA_boolean_get(ptr, "lock_rotations_4d")) {
2544 colsub->prop(ptr,
2545 "lock_rotation_w",
2547 "",
2548 ICON_DECORATE_UNLOCKED);
2549 }
2550 else {
2551 colsub->label("", ICON_NONE);
2552 }
2553 colsub->prop(ptr,
2554 "lock_rotation",
2556 "",
2557 ICON_DECORATE_UNLOCKED);
2558 break;
2559 default: /* euler rotations */
2560 colsub = &split->column(true);
2561 colsub->prop(ptr, "rotation_euler", UI_ITEM_NONE, IFACE_("Rotation"), ICON_NONE);
2562 colsub = &split->column(true);
2564 colsub->label("", ICON_NONE);
2565 colsub->prop(ptr,
2566 "lock_rotation",
2568 "",
2569 ICON_DECORATE_UNLOCKED);
2570 break;
2571 }
2572
2573 ui::Layout &row = layout.row(/*align=*/true);
2574 row.prop(ptr, "rotation_mode", UI_ITEM_NONE, "", ICON_NONE);
2575 row.menu("ANIM_MT_rotation_mode_convert", "", ICON_DOWNARROW_HLT);
2576
2577 split = &layout.split(0.8f, false);
2578 colsub = &split->column(true);
2579 colsub->prop(ptr, "scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2580 colsub = &split->column(true);
2582 colsub->label("", ICON_NONE);
2583 colsub->prop(
2584 ptr, "lock_scale", ui::ITEM_R_TOGGLE | ui::ITEM_R_ICON_ONLY, "", ICON_DECORATE_UNLOCKED);
2585}
2586
2587static void v3d_posearmature_buts(ui::Layout &layout, Object *ob)
2588{
2590
2591 if (!pchan) {
2592 layout.label(IFACE_("No Bone Active"), ICON_NONE);
2593 return;
2594 }
2595
2596 PointerRNA pchanptr = RNA_pointer_create_discrete(&ob->id, RNA_PoseBone, pchan);
2597
2598 ui::Layout &col = layout.column(false);
2599
2600 /* XXX: RNA buts show data in native types (i.e. quaternion, 4-component axis/angle, etc.)
2601 * but old-school UI shows in eulers always. Do we want to be able to still display in Eulers?
2602 * Maybe needs RNA/UI options to display rotations as different types. */
2603 v3d_transform_butsR(col, &pchanptr);
2604}
2605
2606static void v3d_editarmature_buts(ui::Layout &layout, Object *ob)
2607{
2608 bArmature *arm = id_cast<bArmature *>(ob->data);
2609 EditBone *ebone = arm->act_edbone;
2610
2611 if (!ebone || !ANIM_bonecoll_is_visible_editbone(arm, ebone)) {
2612 layout.label(IFACE_("Nothing selected"), ICON_NONE);
2613 return;
2614 }
2615
2616 PointerRNA eboneptr = RNA_pointer_create_discrete(&arm->id, RNA_EditBone, ebone);
2617
2618 ui::Layout &col = layout.column(false);
2619 col.prop(&eboneptr, "head", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2620 if (ebone->parent && ebone->flag & BONE_CONNECTED) {
2621 PointerRNA parptr = RNA_pointer_get(&eboneptr, "parent");
2622 col.prop(&parptr, "tail_radius", UI_ITEM_NONE, IFACE_("Radius (Parent)"), ICON_NONE);
2623 }
2624 else {
2625 col.prop(&eboneptr, "head_radius", UI_ITEM_NONE, IFACE_("Radius"), ICON_NONE);
2626 }
2627
2628 col.prop(&eboneptr, "tail", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2629 col.prop(&eboneptr, "tail_radius", UI_ITEM_NONE, IFACE_("Radius"), ICON_NONE);
2630
2631 col.prop(&eboneptr, "roll", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2632 col.prop(&eboneptr, "length", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2633 col.prop(&eboneptr, "envelope_distance", UI_ITEM_NONE, IFACE_("Envelope"), ICON_NONE);
2634}
2635
2636static void v3d_editmetaball_buts(ui::Layout &layout, Object *ob)
2637{
2638 MetaBall *mball = id_cast<MetaBall *>(ob->data);
2639
2640 if (!mball || !(mball->lastelem)) {
2641 layout.label(IFACE_("Nothing selected"), ICON_NONE);
2642 return;
2643 }
2644
2645 PointerRNA ptr = RNA_pointer_create_discrete(&mball->id, RNA_MetaElement, mball->lastelem);
2646
2647 ui::Layout *col = &layout.column(false);
2648 col->prop(&ptr, "co", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2649
2650 col->prop(&ptr, "radius", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2651 col->prop(&ptr, "stiffness", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2652
2653 col->prop(&ptr, "type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2654
2655 col = &layout.column(true);
2656 switch (RNA_enum_get(&ptr, "type")) {
2657 case MB_BALL:
2658 break;
2659 case MB_CUBE:
2660 col->label(IFACE_("Size:"), ICON_NONE);
2661 col->prop(&ptr, "size_x", UI_ITEM_NONE, IFACE_("X"), ICON_NONE);
2662 col->prop(&ptr, "size_y", UI_ITEM_NONE, IFACE_("Y"), ICON_NONE);
2663 col->prop(&ptr, "size_z", UI_ITEM_NONE, IFACE_("Z"), ICON_NONE);
2664 break;
2665 case MB_TUBE:
2666 col->label(IFACE_("Size:"), ICON_NONE);
2667 col->prop(&ptr, "size_x", UI_ITEM_NONE, IFACE_("X"), ICON_NONE);
2668 break;
2669 case MB_PLANE:
2670 col->label(IFACE_("Size:"), ICON_NONE);
2671 col->prop(&ptr, "size_x", UI_ITEM_NONE, IFACE_("X"), ICON_NONE);
2672 col->prop(&ptr, "size_y", UI_ITEM_NONE, IFACE_("Y"), ICON_NONE);
2673 break;
2674 case MB_ELLIPSOID:
2675 col->label(IFACE_("Size:"), ICON_NONE);
2676 col->prop(&ptr, "size_x", UI_ITEM_NONE, IFACE_("X"), ICON_NONE);
2677 col->prop(&ptr, "size_y", UI_ITEM_NONE, IFACE_("Y"), ICON_NONE);
2678 col->prop(&ptr, "size_z", UI_ITEM_NONE, IFACE_("Z"), ICON_NONE);
2679 break;
2680 }
2681}
2682
2684
2685/* -------------------------------------------------------------------- */
2688
2689static void do_view3d_region_buttons(bContext *C, void * /*index*/, int event)
2690{
2691 const Main *bmain = CTX_data_main(C);
2692 Scene *scene = CTX_data_scene(C);
2693 ViewLayer *view_layer = CTX_data_view_layer(C);
2694 View3D *v3d = CTX_wm_view3d(C);
2695 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2696 Object *ob = BKE_view_layer_active_object_get(view_layer);
2697
2698 switch (event) {
2701 if (ob) {
2702 v3d_editvertex_buts(C, nullptr, v3d, ob, 1.0);
2703 }
2704 break;
2706 if (ob) {
2707 v3d_object_dimension_buts(C, nullptr, v3d, ob);
2708 }
2709 break;
2710 }
2711
2712 /* default for now */
2714}
2715
2717{
2718 const Main *bmain = CTX_data_main(C);
2719 const Scene *scene = CTX_data_scene(C);
2720 ViewLayer *view_layer = CTX_data_view_layer(C);
2721 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2722 return (BKE_view_layer_active_base_get(view_layer) != nullptr);
2723}
2724
2725static void view3d_panel_transform(const bContext *C, Panel *panel)
2726{
2727 ui::Block *block;
2728 const Main *bmain = CTX_data_main(C);
2729 const Scene *scene = CTX_data_scene(C);
2730 ViewLayer *view_layer = CTX_data_view_layer(C);
2731 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2732 Object *ob = BKE_view_layer_active_object_get(view_layer);
2733 Object *obedit = OBEDIT_FROM_OBACT(ob);
2734
2735 block = panel->layout->block();
2736 block_func_handle_set(block, do_view3d_region_buttons, nullptr);
2737
2738 ui::Layout &col = panel->layout->column(false);
2739
2740 if (ob == obedit) {
2741 if (ob->type == OB_ARMATURE) {
2742 v3d_editarmature_buts(col, ob);
2743 }
2744 else if (ob->type == OB_MBALL) {
2745 v3d_editmetaball_buts(col, ob);
2746 }
2747 else {
2748 View3D *v3d = CTX_wm_view3d(C);
2749 v3d_editvertex_buts(C, &col, v3d, ob, FLT_MAX);
2750 }
2751 }
2752 else if (ob->mode & OB_MODE_POSE) {
2753 v3d_posearmature_buts(col, ob);
2754 }
2755 else {
2756 PointerRNA obptr = RNA_id_pointer_create(&ob->id);
2757 v3d_transform_butsR(col, &obptr);
2758
2759 /* Dimensions and editmode are mostly the same check. */
2761 View3D *v3d = CTX_wm_view3d(C);
2762 v3d_object_dimension_buts(nullptr, &col, v3d, ob);
2763 }
2764 }
2765}
2766
2768
2769/* -------------------------------------------------------------------- */
2772
2774{
2775 const Main *bmain = CTX_data_main(C);
2776 const Scene *scene = CTX_data_scene(C);
2777 ViewLayer *view_layer = CTX_data_view_layer(C);
2778 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2779 Object *ob = BKE_view_layer_active_object_get(view_layer);
2780 return (ob && ELEM(ob->type, OB_GREASE_PENCIL, OB_CURVES) && BKE_object_is_in_editmode(ob));
2781}
2782
2784 bContext *C,
2785 FunctionRef<void(const CurvesDataPanelState &modified_state,
2786 const IndexMask &selection,
2787 bke::CurvesGeometry &curves)> curves_geometry_handler)
2788{
2789 const Main *bmain = CTX_data_main(C);
2790 const Scene *scene = CTX_data_scene(C);
2791 ViewLayer *view_layer = CTX_data_view_layer(C);
2792 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2793 Object *ob = BKE_view_layer_active_object_get(view_layer);
2794
2795 View3D *v3d = CTX_wm_view3d(C);
2797 const CurvesDataPanelState &modified = tfp.modified;
2798
2799 if (ob->type == OB_GREASE_PENCIL) {
2800 using namespace ed::greasepencil;
2801 Scene &scene = *CTX_data_scene(C);
2802 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob->data);
2803 Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(scene, grease_pencil);
2804
2805 threading::parallel_for_each(drawings, [&](const MutableDrawingInfo &info) {
2806 bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
2807 IndexMaskMemory memory;
2808 const IndexMask selection = ed::curves::retrieve_selected_curves(curves, memory);
2809 if (selection.is_empty()) {
2810 return;
2811 }
2812
2813 curves_geometry_handler(modified, selection, curves);
2814 info.drawing.tag_topology_changed();
2815 });
2816 }
2817 else {
2818 Curves &curves_id = *id_cast<Curves *>(ob->data);
2819 bke::CurvesGeometry &curves = curves_id.geometry.wrap();
2820 IndexMaskMemory memory;
2821 const IndexMask selection = ed::curves::retrieve_selected_curves(curves, memory);
2822
2823 if (!selection.is_empty()) {
2824 curves_geometry_handler(modified, selection, curves);
2825 curves.tag_topology_changed();
2826 }
2827 }
2828
2831}
2832
2833static void handle_curves_cyclic(bContext *C, void * /*arg1*/, void * /*arg2*/)
2834{
2836 [](const CurvesDataPanelState &modified_state,
2837 const IndexMask &selection,
2840 curves.cyclic_for_write(), bool(modified_state.cyclic), selection);
2841 });
2842}
2843
2844static void update_custom_knots(const OffsetIndices<int> &src_custom_knots_by_curve,
2845 const Span<int8_t> src_knot_modes,
2846 const Span<float> src_custom_knots,
2848{
2849 curves.nurbs_custom_knots_update_size();
2850 IndexMaskMemory memory;
2851 const IndexMask custom_knot_curves = curves.nurbs_custom_knot_curves(memory);
2852 if (!custom_knot_curves.is_empty()) {
2853 const OffsetIndices points_by_curve = curves.points_by_curve();
2854 const OffsetIndices<int> custom_knots_by_curve = curves.nurbs_custom_knots_by_curve();
2855 const VArray<int8_t> orders = curves.nurbs_orders();
2856 const VArray<bool> cyclic = curves.cyclic();
2857 MutableSpan<float> custom_knots = curves.nurbs_custom_knots_for_write();
2858
2859 custom_knot_curves.foreach_index(
2860 [&](const int curve) {
2861 const IndexRange dst_knots = custom_knots_by_curve[curve];
2862 const IndexRange src_knots = src_custom_knots_by_curve[curve];
2863 if (src_knots.is_empty()) {
2864 const int points_num = points_by_curve[curve].size();
2865 const int order = orders[curve];
2866 const bool is_cyclic = cyclic[curve];
2867 Array<float> knots_buffer(bke::curves::nurbs::knots_num(points_num, order, is_cyclic));
2869 points_num, KnotsMode(src_knot_modes[curve]), order, is_cyclic, knots_buffer);
2870 custom_knots.slice(dst_knots).copy_from(
2871 knots_buffer.as_span().take_front(dst_knots.size()));
2872 }
2873 else {
2874 custom_knots.slice(dst_knots).copy_from(src_custom_knots.slice(src_knots));
2875 }
2876 },
2878 }
2879}
2880
2881static void handle_curves_knot_mode(bContext *C, void * /*arg1*/, void * /*arg2*/)
2882{
2884 C,
2885 [](const CurvesDataPanelState &modified_state,
2886 const IndexMask &selection,
2888 const OffsetIndices<int> src_custom_knots_by_curve = curves.nurbs_custom_knots_by_curve();
2889 /* Ensure `src_custom_knots_by_curve` will not get deleted. */
2890 const SharedCache<Vector<int>> custom_knot_offsets_cache =
2891 curves.runtime->custom_knot_offsets_cache;
2892 const Span<float> src_custom_knots = curves.nurbs_custom_knots();
2893 const ImplicitSharingInfo *knots_sharing_info = curves.runtime->custom_knots_sharing_info;
2894 if (knots_sharing_info != nullptr) {
2895 knots_sharing_info->add_user();
2896 }
2897
2898 Array<int8_t> src_knot_modes;
2899 if (!src_custom_knots.is_empty() ||
2900 modified_state.nurbs_knot_mode == NURBS_KNOT_MODE_CUSTOM) {
2901 src_knot_modes.reinitialize(curves.curves_num());
2902 curves.nurbs_knots_modes().materialize(src_knot_modes);
2903 }
2904
2905 const MutableSpan<int8_t> nurbs_knot_modes = curves.nurbs_knots_modes_for_write();
2906
2908 nurbs_knot_modes, int8_t(modified_state.nurbs_knot_mode), selection);
2914 update_custom_knots(src_custom_knots_by_curve, src_knot_modes, src_custom_knots, curves);
2915
2916 if (knots_sharing_info != nullptr) {
2917 knots_sharing_info->remove_user_and_delete_if_last();
2918 }
2919 });
2920}
2921
2922static void handle_curves_order(bContext *C, void * /*arg1*/, void * /*arg2*/)
2923{
2925 C,
2926 [](const CurvesDataPanelState &modified_state,
2927 const IndexMask &selection,
2929 const MutableSpan<int8_t> nurbs_knot_modes = curves.nurbs_knots_modes_for_write();
2930 const MutableSpan<int8_t> orders = curves.nurbs_orders_for_write();
2931
2932 const OffsetIndices<int> src_custom_knots_by_curve = curves.nurbs_custom_knots_by_curve();
2933 /* Ensure `src_custom_knots_by_curve` will not get deleted. */
2934 const SharedCache<Vector<int>> custom_knot_offsets_cache =
2935 curves.runtime->custom_knot_offsets_cache;
2936 const Span<float> src_custom_knots = curves.nurbs_custom_knots();
2937 const ImplicitSharingInfo *knots_sharing_info = curves.runtime->custom_knots_sharing_info;
2938 if (knots_sharing_info != nullptr) {
2939 knots_sharing_info->add_user();
2940 }
2941
2942 bool knot_modes_changed = false;
2943
2944 selection.foreach_index(
2945 [&](const int curve) {
2946 if (orders[curve] != modified_state.order &&
2947 nurbs_knot_modes[curve] == NURBS_KNOT_MODE_CUSTOM)
2948 {
2949 nurbs_knot_modes[curve] = NURBS_KNOT_MODE_NORMAL;
2950 knot_modes_changed = true;
2951 }
2952 orders[curve] = modified_state.order;
2953 },
2955
2959 if (knot_modes_changed) {
2960 update_custom_knots(src_custom_knots_by_curve, {}, src_custom_knots, curves);
2961 }
2962
2963 if (knots_sharing_info != nullptr) {
2964 knots_sharing_info->remove_user_and_delete_if_last();
2965 }
2966 });
2967}
2968
2969static void handle_curves_resolution(bContext *C, void * /*arg1*/, void * /*arg2*/)
2970{
2972 [](const CurvesDataPanelState &modified_state,
2973 const IndexMask &selection,
2975 index_mask::masked_fill(curves.resolution_for_write(),
2976 modified_state.resolution,
2977 selection);
2978 });
2979}
2980
2981static void handle_curves_aspect_ratio(bContext *C, void * /*arg1*/, void * /*arg2*/)
2982{
2983 using namespace blender;
2984
2986 C,
2987 [](const CurvesDataPanelState &modified_state,
2988 const IndexMask &selection,
2990 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
2991 bke::SpanAttributeWriter<float> aspect_ratio =
2992 attributes.lookup_or_add_for_write_span<float>(
2993 "aspect_ratio",
2996 index_mask::masked_fill(aspect_ratio.span, modified_state.aspect_ratio, selection);
2997 aspect_ratio.finish();
2998 });
2999}
3000
3001static void handle_curves_softness(bContext *C, void * /*arg1*/, void * /*arg2*/)
3002{
3003 using namespace blender;
3004
3006 C,
3007 [](const CurvesDataPanelState &modified_state,
3008 const IndexMask &selection,
3010 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
3012 "softness", bke::AttrDomain::Curve);
3013 index_mask::masked_fill(softness.span, modified_state.softness, selection);
3014 softness.finish();
3015 });
3016}
3017
3018static void handle_curves_u_scale(bContext *C, void * /*arg1*/, void * /*arg2*/)
3019{
3020 using namespace blender;
3021
3023 C,
3024 [](const CurvesDataPanelState &modified_state,
3025 const IndexMask &selection,
3027 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
3029 "u_scale",
3032 index_mask::masked_fill(u_scale.span, modified_state.u_scale, selection);
3033 u_scale.finish();
3034 });
3035}
3036
3037static void handle_curves_fill_opacity(bContext *C, void * /*arg1*/, void * /*arg2*/)
3038{
3039 using namespace blender;
3040
3042 C,
3043 [](const CurvesDataPanelState &modified_state,
3044 const IndexMask &selection,
3046 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
3047 if (bke::SpanAttributeWriter<float> fill_opacity =
3048 attributes.lookup_or_add_for_write_span<float>(
3049 "fill_opacity", bke::AttrDomain::Curve, bke::AttributeInitValue(1.0f)))
3050 {
3051 index_mask::masked_fill(fill_opacity.span, modified_state.fill_opacity, selection);
3052 fill_opacity.finish();
3053 }
3054 });
3055}
3056
3057static void handle_curves_end_cap(bContext *C, void * /*arg1*/, void * /*arg2*/)
3058{
3059 using namespace blender;
3060
3062 C,
3063 [](const CurvesDataPanelState &modified_state,
3064 const IndexMask &selection,
3066 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
3068 "end_cap",
3072 if (end_cap) {
3073 index_mask::masked_fill(end_cap.span, modified_state.end_cap, selection);
3074 end_cap.finish();
3075 }
3076 });
3077}
3078
3079static void handle_curves_start_cap(bContext *C, void * /*arg1*/, void * /*arg2*/)
3080{
3081 using namespace blender;
3082
3084 C,
3085 [](const CurvesDataPanelState &modified_state,
3086 const IndexMask &selection,
3088 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
3091 "start_cap",
3095 if (start_cap) {
3096 index_mask::masked_fill(start_cap.span, modified_state.start_cap, selection);
3097 start_cap.finish();
3098 }
3099 });
3100}
3101
3102constexpr std::array<EnumPropertyItem, 5> enum_curve_knot_mode_items{{
3104 "NORMAL",
3105 ICON_NONE,
3107 ""},
3109 "ENDPOINT",
3110 ICON_NONE,
3112 ""},
3114 "BEZIER",
3115 ICON_NONE,
3116 CTX_N_(BLT_I18NCONTEXT_ID_GPENCIL, "Bézier"),
3117 ""},
3119 "ENDPOINT_BEZIER",
3120 ICON_NONE,
3121 CTX_N_(BLT_I18NCONTEXT_ID_GPENCIL, "Endpoint Bézier"),
3122 ""},
3124 "CUSTOM",
3125 ICON_NONE,
3127 ""},
3128}};
3129
3130static void knot_modes_menu(bContext * /*C*/, ui::Layout *layout, void *knot_mode_p)
3131{
3132 ui::Block *block = layout->block();
3133 ui::block_layout_set_current(block, layout);
3134 layout->column(false);
3135
3136 for (const EnumPropertyItem &item : enum_curve_knot_mode_items) {
3137 ui::Button *but = uiDefButV(block,
3140 0,
3141 0,
3142 UI_UNIT_X * 5,
3143 UI_UNIT_Y,
3144 reinterpret_cast<int *>(knot_mode_p),
3145 0.0,
3146 0.0,
3147 "");
3148 button_enum_prop_value_set(but, item.value);
3149 }
3150}
3151
3152constexpr std::array<EnumPropertyItem, 2> enum_grease_pencil_cap_items{{
3153 {GP_STROKE_CAP_TYPE_ROUND, "ROUND", ICON_GP_CAPS_ROUND, "Round", ""},
3154 {GP_STROKE_CAP_TYPE_FLAT, "FLAT", ICON_GP_CAPS_FLAT, "Flat", ""},
3155}};
3156
3157static void grease_pencil_cap_menu(bContext * /*C*/, ui::Layout *layout, void *cap_type_p)
3158{
3159 ui::Block *block = layout->block();
3161 layout->column(false);
3162
3164 ui::Button *but = uiDefButV(block,
3167 0,
3168 0,
3169 UI_UNIT_X * 5,
3170 UI_UNIT_Y,
3171 reinterpret_cast<int *>(cap_type_p),
3172 0.0,
3173 0.0,
3174 "");
3175 button_enum_prop_value_set(but, item.value);
3176 }
3177}
3178
3179static void view3d_panel_curve_data(const bContext *C, Panel *panel)
3180{
3181 using namespace ed::curves;
3182
3183 const Main *bmain = CTX_data_main(C);
3184 const Scene *scene = CTX_data_scene(C);
3185 ViewLayer *view_layer = CTX_data_view_layer(C);
3186 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
3187 Object *ob = BKE_view_layer_active_object_get(view_layer);
3188 ui::Block *block = panel->layout->block();
3189
3190 CurvesSelectionStatus status;
3191
3192 if (ob->type == OB_GREASE_PENCIL) {
3193 using namespace ed::greasepencil;
3194 Scene &scene = *CTX_data_scene(C);
3195 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob->data);
3196 Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(scene, grease_pencil);
3197
3199 drawings.index_range(),
3200 1L,
3202 [&](const IndexRange range, const CurvesSelectionStatus &acc) {
3203 CurvesSelectionStatus value = acc;
3204 for (const int drawing : range) {
3205 const bke::CurvesGeometry &curves = drawings[drawing].drawing.strokes();
3208 }
3209 return value;
3210 },
3212 }
3213 else {
3214 const Curves &curves_id = *id_cast<Curves *>(ob->data);
3215 status = init_curves_selection_status(curves_id.geometry.wrap());
3216 }
3217
3218 if (status.curve_count == 0) {
3219 uiDefBut(block,
3221 IFACE_("Nothing selected"),
3222 0,
3223 130,
3224 200,
3225 20,
3226 nullptr,
3227 0,
3228 0,
3229 "");
3230 return;
3231 }
3232
3233 View3D *v3d = CTX_wm_view3d(C);
3235 CurvesDataPanelState &modified = tfp.modified;
3236 CurvesDataPanelState &current = tfp.current;
3237
3238 current.cyclic = status.cyclic_count > 0;
3239 current.nurbs_knot_mode = KnotsMode(
3241 current.order = math::safe_divide(status.order_sum, status.nurbs_count);
3242 current.resolution = math::safe_divide(status.resolution_sum, status.curve_count);
3243
3245 float(status.curve_count));
3246 current.start_cap = math::safe_divide(status.start_cap.value_sum, status.curve_count);
3247 current.end_cap = math::safe_divide(status.end_cap.value_sum, status.curve_count);
3248 current.u_scale = math::safe_divide(status.u_scale.value_sum, float(status.curve_count));
3249 current.softness = math::safe_divide(status.softness.value_sum, float(status.curve_count));
3251 float(status.curve_count));
3252
3253 modified = current;
3254
3255 panel->layout->use_property_split_set(true);
3256 ui::Layout &bcol = panel->layout->column(false);
3257
3258 auto add_labeled_field =
3259 [&](const StringRef label, const bool active, FunctionRef<ui::Button *()> add_button) {
3260 ui::Layout &row = bcol.row(true);
3262 ui::Layout &col = split.column(true);
3264 col.label(label, ICON_NONE);
3265 split.column(false);
3266 ui::Button *but = add_button();
3267 if (active) {
3268 button_drawflag_disable(but, ui::BUT_INDETERMINATE);
3269 }
3270 else {
3271 button_drawflag_enable(but, ui::BUT_INDETERMINATE);
3272 }
3273 };
3274
3275 auto is_equal = [&](const float a, const float b, const float epsilon = 1e-4f) {
3276 return math::abs(a - b) <= epsilon;
3277 };
3278
3279 const int butw = 10 * UI_UNIT_X;
3280 const int buth = 20 * UI_SCALE_FAC;
3281
3282 add_labeled_field(
3283 IFACE_("Cyclic"),
3284 status.cyclic_count == 0 || status.cyclic_count == status.curve_count,
3285 [&]() {
3286 ui::Button *but = uiDefButV(
3287 block, ui::ButtonType::Checkbox, "", 0, 0, butw, buth, &modified.cyclic, 0, 1, "");
3288 button_func_set(but, handle_curves_cyclic, nullptr, nullptr);
3289 return but;
3290 });
3291
3292 if (status.nurbs_count == status.curve_count) {
3293 add_labeled_field(IFACE_("Knot Mode"),
3294 status.nurbs_knot_mode_max * status.nurbs_count ==
3295 status.nurbs_knot_mode_sum,
3296 [&]() {
3297 ui::Button *but = uiDefMenuBut(
3298 block,
3299 knot_modes_menu,
3300 &modified.nurbs_knot_mode,
3301 CTX_IFACE_(BLT_I18NCONTEXT_ID_GPENCIL,
3302 enum_curve_knot_mode_items[modified.nurbs_knot_mode].name),
3303 0,
3304 0,
3305 butw,
3306 buth,
3307 "");
3308 button_type_set_menu_from_pulldown(but);
3309 button_func_set(but, handle_curves_knot_mode, nullptr, nullptr);
3310 return but;
3311 });
3312
3313 add_labeled_field(
3314 IFACE_("Order"), status.order_max * status.nurbs_count == status.order_sum, [&]() {
3315 ui::Button *but = uiDefButV(
3316 block, ui::ButtonType::Num, "", 0, 0, butw, buth, &modified.order, 2, 6, "");
3317 button_number_step_size_set(but, 1);
3318 button_number_precision_set(but, -1);
3319 button_func_set(but, handle_curves_order, nullptr, nullptr);
3320 return but;
3321 });
3322 }
3323
3324 if (status.poly_count == 0) {
3325 add_labeled_field(
3326 IFACE_("Resolution"),
3327 status.resolution_max * status.curve_count == status.resolution_sum,
3328 [&]() {
3329 ui::Button *but = uiDefButV(
3330 block, ui::ButtonType::Num, "", 0, 0, butw, buth, &modified.resolution, 1, 64, "");
3331 button_number_step_size_set(but, 1);
3332 button_number_precision_set(but, -1);
3333 button_func_set(but, handle_curves_resolution, nullptr, nullptr);
3334 return but;
3335 });
3336 }
3337
3338 if (ob->type == OB_GREASE_PENCIL) {
3339 add_labeled_field(IFACE_("Fill Opacity"),
3341 status.fill_opacity.value_sum),
3342 [&]() {
3343 ui::Button *but = uiDefButV(block,
3344 ui::ButtonType::Num,
3345 "",
3346 0,
3347 0,
3348 butw,
3349 buth,
3350 &modified.fill_opacity,
3351 0.0f,
3352 1.0f,
3353 "");
3354 button_number_step_size_set(but, 1);
3355 button_number_precision_set(but, 3);
3356 button_func_set(but, handle_curves_fill_opacity, nullptr, nullptr);
3357 return but;
3358 });
3359
3360 add_labeled_field(IFACE_("Start Cap"),
3361 status.start_cap.value_max * status.curve_count ==
3362 status.start_cap.value_sum,
3363 [&]() {
3364 ui::Button *but = uiDefMenuBut(
3365 block,
3366 grease_pencil_cap_menu,
3367 &modified.start_cap,
3368 CTX_IFACE_(BLT_I18NCONTEXT_ID_GPENCIL,
3369 enum_grease_pencil_cap_items[modified.start_cap].name),
3370 0,
3371 0,
3372 butw,
3373 buth,
3374 "");
3375 button_type_set_menu_from_pulldown(but);
3376 button_func_set(but, handle_curves_start_cap, nullptr, nullptr);
3377 return but;
3378 });
3379
3380 add_labeled_field(IFACE_("End Cap"),
3381 status.end_cap.value_max * status.curve_count == status.end_cap.value_sum,
3382 [&]() {
3383 ui::Button *but = uiDefMenuBut(
3384 block,
3385 grease_pencil_cap_menu,
3386 &modified.end_cap,
3387 CTX_IFACE_(BLT_I18NCONTEXT_ID_GPENCIL,
3388 enum_grease_pencil_cap_items[modified.end_cap].name),
3389 0,
3390 0,
3391 butw,
3392 buth,
3393 "");
3394 button_type_set_menu_from_pulldown(but);
3395 button_func_set(but, handle_curves_end_cap, nullptr, nullptr);
3396 return but;
3397 });
3398
3399 add_labeled_field(
3400 IFACE_("Softness"),
3401 is_equal(status.softness.value_max * status.curve_count, status.softness.value_sum),
3402 [&]() {
3403 ui::Button *but = uiDefButV(block,
3404 ui::ButtonType::Num,
3405 "",
3406 0,
3407 0,
3408 butw,
3409 buth,
3410 &modified.softness,
3411 0.0f,
3412 1.0f,
3413 "");
3414 button_number_step_size_set(but, 1);
3415 button_number_precision_set(but, 3);
3416 button_func_set(but, handle_curves_softness, nullptr, nullptr);
3417 return but;
3418 });
3419
3420 add_labeled_field(
3421 IFACE_("U Scale"),
3422 is_equal(status.u_scale.value_max * status.curve_count, status.u_scale.value_sum),
3423 [&]() {
3424 ui::Button *but = uiDefButV(block,
3425 ui::ButtonType::Num,
3426 "",
3427 0,
3428 0,
3429 butw,
3430 buth,
3431 &modified.u_scale,
3432 0.0f,
3433 1000.0f,
3434 "");
3435 button_number_step_size_set(but, 1);
3436 button_number_precision_set(but, 3);
3437 button_func_set(but, handle_curves_u_scale, nullptr, nullptr);
3438 return but;
3439 });
3440
3441 add_labeled_field(IFACE_("Aspect Ratio"),
3443 status.aspect_ratio.value_sum),
3444 [&]() {
3445 ui::Button *but = uiDefButV(block,
3446 ui::ButtonType::Num,
3447 "",
3448 0,
3449 0,
3450 butw,
3451 buth,
3452 &modified.aspect_ratio,
3453 0.0f,
3454 1000.0f,
3455 "");
3456 button_number_step_size_set(but, 1);
3457 button_number_precision_set(but, 3);
3458 button_func_set(but, handle_curves_aspect_ratio, nullptr, nullptr);
3459 return but;
3460 });
3461 }
3462}
3463
3465
3466/* -------------------------------------------------------------------- */
3469
3471{
3472 PanelType *pt;
3473
3474 pt = MEM_new_zeroed<PanelType>("spacetype view3d panel object");
3475 STRNCPY_UTF8(pt->idname, "VIEW3D_PT_transform");
3476 STRNCPY_UTF8(pt->label, N_("Transform")); /* XXX C panels unavailable through RNA bpy.types! */
3477 STRNCPY_UTF8(pt->category, "Item");
3481 BLI_addtail(&art->paneltypes, pt);
3482
3483 pt = MEM_new_zeroed<PanelType>("spacetype view3d panel vgroup");
3484 STRNCPY_UTF8(pt->idname, "VIEW3D_PT_vgroup");
3485 STRNCPY_UTF8(pt->label,
3486 N_("Vertex Weights")); /* XXX C panels unavailable through RNA bpy.types! */
3487 STRNCPY_UTF8(pt->category, "Item");
3491 BLI_addtail(&art->paneltypes, pt);
3492
3493 pt = MEM_new_zeroed<PanelType>("spacetype view3d panel curves");
3494 STRNCPY_UTF8(pt->idname, "VIEW3D_PT_curves");
3495 STRNCPY_UTF8(pt->label, N_("Curve Data")); /* XXX C panels unavailable through RNA bpy.types! */
3496 STRNCPY_UTF8(pt->category, "Item");
3500 BLI_addtail(&art->paneltypes, pt);
3501}
3502
3504
3505/* -------------------------------------------------------------------- */
3508
3510{
3512 if (ob == nullptr) {
3513 BKE_report(op->reports, RPT_WARNING, "No active object found");
3514 return OPERATOR_CANCELLED;
3515 }
3516 if (((ob->mode & OB_MODE_EDIT) == 0) && ELEM(ob->type, OB_ARMATURE)) {
3518 return OPERATOR_CANCELLED;
3519 }
3520
3521 ui::pie_menu_invoke(C, "VIEW3D_MT_object_mode_pie", CTX_wm_window(C)->runtime->eventstate);
3522 return OPERATOR_CANCELLED;
3523}
3524
3526{
3527 ot->name = "Object Mode Menu";
3528 ot->idname = "VIEW3D_OT_object_mode_pie_or_toggle";
3529
3532
3533 /* flags */
3534 ot->flag = 0;
3535}
3536
3538
3539} // namespace blender
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Blender kernel action and pose functionality.
#define CU_IS_2D(cu)
Definition BKE_curve.hh:93
Low-level operations for curves.
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
Functions for dealing with objects and deform verts, used by painting and tools.
Generic array manipulation API.
#define BLI_array_findindex(arr, arr_len, p)
#define DEG2RADF(_deg)
#define STRNCPY_UTF8(dst, src)
#define CTX_N_(context, msgid)
#define TIP_(msgid)
#define BLT_I18NCONTEXT_ID_GPENCIL
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
Object is a sort of wrapper for general info.
#define OB_TYPE_SUPPORT_EDITMODE(_type)
#define OBEDIT_FROM_OBACT(ob)
#define UI_SCALE_FAC
Read Blender memory allocation and freeing.
#define RNA_TRANSLATION_PREC_DEFAULT
Definition RNA_types.hh:272
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
#define UI_ITEM_NONE
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define NA_EDITED
Definition WM_types.hh:634
#define NC_GPENCIL
Definition WM_types.hh:412
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define NC_SPACE
Definition WM_types.hh:405
#define CLAMP(a, b, c)
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
#define ELEM(...)
#define BM_ELEM_CD_GET_FLOAT(ele, offset)
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
int64_t size() const
Definition BLI_array.hh:267
Span< T > as_span() const
Definition BLI_array.hh:254
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr IndexRange()=default
constexpr MutableSpan()=default
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:745
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr bool is_empty() const
Definition BLI_span.hh:264
static VArray from_single(T value, const int64_t size)
IndexRange index_range() const
GAttributeReader lookup(const StringRef name) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask slice_content(IndexRange range) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define FLT_MAX
#define attribute(slot)
bool is_equal(float a, float b, const float epsilon)
float3x3 scale(float3x3 mat, float2 scale)
#define T
void calculate_knots(int points_num, KnotsMode mode, int8_t order, bool cyclic, MutableSpan< float > knots)
int knots_num(int points_num, int8_t order, bool cyclic)
IndexMask curve_type_point_selection(const bke::CurvesGeometry &curves, CurveType curve_type, LinearAllocator<> &memory)
Bounds< T > merge(const Bounds< T > &a, const Bounds< T > &b)
Definition BLI_bounds.hh:27
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
bool mode_set(bContext *C, eObjectMode mode)
void vgroup_vert_active_mirror(Object *ob, int def_nr)
bool calc_pivot_pos(const bContext *C, const short pivot_type, float r_pivot_pos[3])
constexpr ParallelGrainSize grain_size(int grain_size)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
T safe_divide(const T &a, const T &b)
MatT from_loc_scale(const typename MatT::loc_type &location, const VecBase< typename MatT::base_type, ScaleDim > &scale)
MatBase< T, Size, Size > pseudo_invert(const MatBase< T, Size, Size > &mat, T epsilon=1e-8)
T length_manhattan(const VecBase< T, Size > &a)
CartesianBasis invert(const CartesianBasis &basis)
void min_max(const T &value, T &min, T &max)
T max(const T &a, const T &b)
T abs(const T &a)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
T determinant(const MatBase< T, Size, Size > &mat)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for_each(Range &&range, const Function &function)
Definition BLI_task.hh:31
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:69
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Definition BLI_task.hh:127
void button_func_set(Button *but, std::function< void(bContext &)> func)
wmOperatorStatus pie_menu_invoke(bContext *C, const char *idname, const wmEvent *event)
void block_layout_set_current(Block *block, Layout *layout)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
static void handle_curves_fill_opacity(bContext *C, void *, void *)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void handle_curves_knot_mode(bContext *C, void *, void *)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
bool BKE_object_is_in_editmode_vgroup(const Object *ob)
Definition object.cc:1927
ScrArea * CTX_wm_area(const bContext *C)
static bool view3d_panel_curve_data_poll(const bContext *C, PanelType *)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static void handle_curves_softness(bContext *C, void *, void *)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
static void do_view3d_region_buttons(bContext *C, void *, int event)
static CurvesSelectionStatus init_curves_selection_status(const bke::CurvesGeometry &curves)
@ RPT_WARNING
Definition BKE_report.hh:40
static float compute_scale_factor(const float ve_median, const float median)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
const ListBaseT< bDeformGroup > * BKE_object_defgroup_list(const Object *ob)
Definition deform.cc:591
static void grease_pencil_cap_menu(bContext *, ui::Layout *layout, void *cap_type_p)
static bool median_bounds_is_set(const Bounds< float3 > &bounds)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
static void handle_curves_cyclic(bContext *C, void *, void *)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
static void handle_curves_aspect_ratio(bContext *C, void *, void *)
static StatusValue< T > init_status_from_attribute(const blender::VArray< T > &attribute, const blender::IndexMask &selection, const T &default_value)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
PointerRNA RNA_id_pointer_create(ID *id)
static void apply_scale_factor(float *val, const int tot, const float ve_median, const float median, const float sca)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static void apply_median_to_bmesh(BMesh &bm, const TransformMedian_Mesh &median, const TransformMedian_Mesh &ve_median, const int tot, const bool apply_vcos, const FunctionRef< void(float co[3])> apply_coord_fn)
@ PROP_UNIT_LENGTH
Definition RNA_types.hh:222
@ PROP_UNIT_ROTATION
Definition RNA_types.hh:226
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void VIEW3D_OT_object_mode_pie_or_toggle(wmOperatorType *ot)
constexpr std::array< EnumPropertyItem, 2 > enum_grease_pencil_cap_items
static void knot_modes_menu(bContext *, ui::Layout *layout, void *knot_mode_p)
wmWindow * CTX_wm_window(const bContext *C)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
@ NURB_HANDLE_TEST_EACH
Definition BKE_curve.hh:65
MatBase< float, 4, 4 > float4x4
static void view3d_panel_vgroup(const bContext *C, Panel *panel)
void BKE_nurb_project_2d(Nurb *nu)
Definition curve.cc:707
@ B_TRANSFORM_PANEL_MEDIAN
@ B_TRANSFORM_PANEL_ELEM_DIMS
@ B_TRANSFORM_PANEL_OBJECT_DIMS
static float4x4 object_to_grease_pencil_layer_calc(const float4x4 &grease_pencil_layer_to_object)
ViewLayer * CTX_data_view_layer(const bContext *C)
MINLINE void mul_v3_fl(float r[3], float f)
static void handle_curves_order(bContext *C, void *, void *)
@ NURBS_KNOT_MODE_ENDPOINT_BEZIER
@ NURBS_KNOT_MODE_BEZIER
@ NURBS_KNOT_MODE_ENDPOINT
@ NURBS_KNOT_MODE_NORMAL
@ NURBS_KNOT_MODE_CUSTOM
static void handle_curves_resolution(bContext *C, void *, void *)
void mul_m4_v3(const float M[4][4], float r[3])
static bool apply_to_curves_point_selection(const int tot, const TransformMedian_Curves &median, const TransformMedian_Curves &ve_median, const std::optional< float4x4 > &dims_mat_object, const float4x4 *grease_pencil_layer_to_object, TransformCoordsOrig *coords_orig, bke::CurvesGeometry &curves)
static void calc_median_bmesh(BMesh &bm, const float4x4 *bounds_matrix, TransformMedian_Mesh &median, Bounds< float3 > &r_select_bounds, int &tot, int &totedgedata)
static void median_bounds_add(float location[3], Bounds< float3 > &bounds, const float4x4 *matrix, const float co[3])
void BKE_object_dimensions_set_ex(Object *ob, const float value[3], int axis_mask, const float ob_scale_orig[3], const float ob_obmat_orig[4][4])
Definition object.cc:3809
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void add_v2_v2(float r[2], const float a[2])
static void apply_to_active_object(bContext *C, FunctionRef< void(const CurvesDataPanelState &modified_state, const IndexMask &selection, bke::CurvesGeometry &curves)> curves_geometry_handler)
static void apply_scale_factor_clamp(float *val, const int tot, const float ve_median, const float sca)
static bool grease_pencil_layer_is_skipped(const float4x4 &grease_pencil_layer_to_object)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
bool ANIM_bonecoll_is_visible_editbone(const bArmature *armature, const EditBone *ebone)
static void handle_curves_start_cap(bContext *C, void *, void *)
static void update_custom_knots(const OffsetIndices< int > &src_custom_knots_by_curve, const Span< int8_t > src_knot_modes, const Span< float > src_custom_knots, bke::CurvesGeometry &curves)
static void v3d_editarmature_buts(ui::Layout &layout, Object *ob)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void BKE_editmesh_looptris_and_normals_calc_with_partial(BMEditMesh *em, BMesh *bm, BMPartialUpdate *bmpinfo)
Definition editmesh.cc:150
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool ED_operator_view3d_active(bContext *C)
static void handle_curves_end_cap(bContext *C, void *, void *)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static bool view3d_panel_vgroup_poll(const bContext *C, PanelType *)
MatBase< float, 3, 3 > float3x3
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static bool view3d_panel_transform_poll(const bContext *C, PanelType *)
static wmOperatorStatus view3d_object_mode_menu_exec(bContext *C, wmOperator *op)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
static void dims_apply_restore(TransformCoordsOrig &coords_orig, const float4x4 &mat, float3 &co)
static CurvesPointSelectionStatus init_curves_point_selection_status(const bke::CurvesGeometry &curves, const float4x4 *grease_pencil_layer_to_object, const float4x4 *bounds_matrix)
static void do_view3d_vgroup_buttons(bContext *C, void *, int event)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
MINLINE void add_v3_v3(float r[3], const float a[3])
static std::optional< float4x4 > median_dims_scale_matrix_calc(const Object &ob, const float4x4 *matrix, const float3 &pivot_world, const float3 &dims_orig, const float3 &dims_new)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
void BKE_nurb_handles_test(Nurb *nu, eNurbHandleTest_Mode handle_mode, bool use_around_local)
Definition curve.cc:4119
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
bool BKE_object_is_in_wpaint_select_vert(const Object *ob)
Definition object.cc:2012
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
static void update_active_vertex_weight(bContext *C, void *arg1, void *)
void BM_mesh_partial_destroy(BMPartialUpdate *bmpinfo)
static void handle_curves_u_scale(bContext *C, void *, void *)
ListBaseT< Nurb > * BKE_curve_editNurbs_get(Curve *cu)
Definition curve.cc:441
bPoseChannel * BKE_pose_channel_active_if_bonecoll_visible(Object *ob) ATTR_WARN_UNUSED_RESULT
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const StringRef name)
Scene * CTX_data_scene(const bContext *C)
static void v3d_object_dimension_buts(bContext *C, ui::Layout *layout, View3D *v3d, Object *ob)
MDeformVert * ED_mesh_active_dvert_get_only(Object *ob)
Definition meshtools.cc:886
bool * BKE_object_defgroup_subset_from_select_type(struct Object *ob, enum eVGroupSelect subset_type, int *r_defgroup_tot, int *r_subset_count)
static void v3d_editvertex_buts(const bContext *C, ui::Layout *layout, View3D *v3d, Object *ob, float lim)
static void transform_panel_interaction_end_fn(bContext *C, const ui::BlockInteraction_Params *, void *, void *user_data)
static void view3d_panel_curve_data(const bContext *C, Panel *panel)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
static Bounds< float3 > median_bounds_init()
static void apply_raw_diff(float *val, const int tot, const float ve_median, const float median)
static void v3d_transform_butsR(ui::Layout &layout, PointerRNA *ptr)
BMPartialUpdate * BM_mesh_partial_create_from_verts(BMesh &bm, const BMPartialUpdate_Params &params, const BitSpan verts_mask, const int verts_mask_count)
bool CustomData_has_layer_named(const CustomData *data, eCustomDataType type, StringRef name)
static void v3d_editmetaball_buts(ui::Layout &layout, Object *ob)
void BKE_object_dimensions_eval_cached_get(const Object *ob, float r_vec[3])
Definition object.cc:3804
static void coords_orig_free(const bContext *C)
BMPartialUpdate * BM_mesh_partial_create_from_verts_group_single(BMesh &bm, const BMPartialUpdate_Params &params, const BitSpan verts_mask, const int verts_mask_count)
static void dims_apply_store(TransformCoordsOrig &coords_orig, const float4x4 &mat, float3 &co)
void view3d_buttons_register(ARegionType *art)
Object * CTX_data_active_object(const bContext *C)
static void transform_panel_interaction_update_fn(bContext *C, const ui::BlockInteraction_Params *, void *arg1, void *user_data)
static void v3d_posearmature_buts(ui::Layout &layout, Object *ob)
static void apply_raw_diff_v3(float val[3], const int tot, const float ve_median[3], const float median[3])
static CurvesSelectionStatus init_grease_pencil_selection_status(const blender::bke::CurvesGeometry &curves)
View3D * CTX_wm_view3d(const bContext *C)
static TransformProperties * v3d_transform_props_ensure(View3D *v3d)
signed char int8_t
Definition BKE_text.h:76
constexpr std::array< EnumPropertyItem, 5 > enum_curve_knot_mode_items
void invert_m4_m4_safe_ortho(float inverse[4][4], const float mat[4][4])
MDeformWeight * BKE_defvert_find_index(const MDeformVert *dv, int defgroup)
Definition deform.cc:811
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
static void * transform_panel_interaction_begin_fn(bContext *C, const ui::BlockInteraction_Params *params, void *arg1)
int BKE_object_defgroup_active_index_get(const Object *ob)
Definition deform.cc:613
static void view3d_panel_transform(const bContext *C, Panel *panel)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< PanelType > paneltypes
CustomData vdata
CustomData edata
eBezTriple_Flag f2
eBezTriple_Flag f3
eBezTriple_Flag f1
struct Bone * parent
static CurvesPointSelectionStatus sum(const CurvesPointSelectionStatus &a, const CurvesPointSelectionStatus &b)
StatusValue< float > fill_opacity
static CurvesSelectionStatus sum(const CurvesSelectionStatus &a, const CurvesSelectionStatus &b)
StatusValue< float > aspect_ratio
struct Lattice * latt
struct EditLatt * editlatt
struct BPoint * def
const c_style_mat & ptr() const
bke::ObjectRuntime * runtime
char translation_context[BKE_ST_MAXNAME]
void(*) draw(const bContext *C, Panel *panel)
char category[BKE_ST_MAXNAME]
bool(*) poll(const bContext *C, PanelType *pt)
char idname[BKE_ST_MAXNAME]
char label[BKE_ST_MAXNAME]
ui::Layout * layout
StructRNA * type
Definition RNA_types.hh:63
struct ToolSettings * toolsettings
static StatusValue sum(const StatusValue &a, const StatusValue &b)
void apply(const float4x4 &mat, float3 &co)
CurvesDataPanelState modified
CurvesDataPanelState current
std::optional< TransformCoordsOrig > coords_orig
void(*) properties_storage_free(void *properties_storage)
View3D_Runtime runtime
struct EditBone * act_edbone
struct bDeformGroup * next
ebDeformGroup_Flag flag
void enabled_set(bool enabled)
void alignment_set(LayoutAlign alignment)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void menu(MenuType *mt, std::optional< StringRef > name, int icon)
Layout & split(float percentage, bool align)
Layout & column(bool align)
Layout & absolute(bool align=false)
Layout & row(bool align)
static constexpr float PROPERTY_SPLIT_FACTOR
void emboss_set(EmbossType emboss)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
struct ReportList * reports
void resize(int new_size)
Definition vector.hh:94
TransformMedian_Generic generic
TransformMedian_Mesh mesh
TransformMedian_Lattice lattice
TransformMedian_Curves curves
TransformMedian_Curve curve
#define N_(msgid)
#define TRANSFORM_MEDIAN_ARRAY_LEN
#define B_VGRP_PNL_EDIT_SINGLE