Blender V5.3
transform_gizmo_3d.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13#include "BLI_array_utils_c.hh"
14#include "BLI_bounds.hh"
15#include "BLI_function_ref.hh"
16#include "BLI_listbase.hh"
17#include "BLI_math_geom_c.hh"
18#include "BLI_math_matrix_c.hh"
19
20#include "DNA_armature_types.h"
21#include "DNA_lattice_types.h"
22#include "DNA_meta_types.h"
24
25#include "BKE_action.hh"
26#include "BKE_armature.hh"
27#include "BKE_context.hh"
28#include "BKE_crazyspace.hh"
29#include "BKE_curve.hh"
30#include "BKE_curves_utils.hh"
31#include "BKE_editmesh.hh"
32#include "BKE_global.hh"
33#include "BKE_grease_pencil.hh"
34#include "BKE_layer.hh"
35#include "BKE_library.hh"
36#include "BKE_object.hh"
37#include "BKE_object_types.hh"
38#include "BKE_paint.hh"
39#include "BKE_pointcache.h"
40#include "BKE_scene.hh"
41#include "BKE_screen.hh"
42
43#include "WM_api.hh"
44#include "WM_message.hh"
45
46#include "ED_armature.hh"
47#include "ED_curves.hh"
48#include "ED_gizmo_library.hh"
49#include "ED_gizmo_utils.hh"
50#include "ED_gpencil_legacy.hh"
51#include "ED_grease_pencil.hh"
52#include "ED_object.hh"
53#include "ED_particle.hh"
54#include "ED_screen.hh"
55
56#include "UI_resources.hh"
57
58#include "RNA_access.hh"
59#include "RNA_define.hh"
60
61#include "ANIM_armature.hh"
62
63/* Local module include. */
64#include "transform.hh"
65#include "transform_convert.hh"
66#include "transform_gizmo.hh"
67#include "transform_snap.hh"
68
69namespace blender::ed::transform {
70
71/* -------------------------------------------------------------------- */
74
77
79 const float twmat[4][4],
80 const float scale[3],
81 const bool ignore_hidden);
82
83/* Return codes for select, and drawing flags. */
84
85#define MAN_TRANS_X (1 << 0)
86#define MAN_TRANS_Y (1 << 1)
87#define MAN_TRANS_Z (1 << 2)
88#define MAN_TRANS_C (MAN_TRANS_X | MAN_TRANS_Y | MAN_TRANS_Z)
89
90#define MAN_ROT_X (1 << 3)
91#define MAN_ROT_Y (1 << 4)
92#define MAN_ROT_Z (1 << 5)
93#define MAN_ROT_C (MAN_ROT_X | MAN_ROT_Y | MAN_ROT_Z)
94
95#define MAN_SCALE_X (1 << 8)
96#define MAN_SCALE_Y (1 << 9)
97#define MAN_SCALE_Z (1 << 10)
98#define MAN_SCALE_C (MAN_SCALE_X | MAN_SCALE_Y | MAN_SCALE_Z)
99
100/* Threshold for testing view aligned gizmo axis. */
101static struct {
102 float min, max;
103} g_tw_axis_range[2] = {
104 /* Regular range. */
105 {0.02f, 0.1f},
106 /* Use a different range because we flip the dot product,
107 * also the view aligned planes are harder to see so hiding early is preferred. */
108 {0.175f, 0.25f},
110
111/* Axes as index. */
112enum {
117
121#define MAN_AXIS_RANGE_TRANS_START MAN_AXIS_TRANS_X
122#define MAN_AXIS_RANGE_TRANS_END (MAN_AXIS_TRANS_ZX + 1)
123
128 MAN_AXIS_ROT_T, /* Trackball rotation. */
129#define MAN_AXIS_RANGE_ROT_START MAN_AXIS_ROT_X
130#define MAN_AXIS_RANGE_ROT_END (MAN_AXIS_ROT_T + 1)
131
139#define MAN_AXIS_RANGE_SCALE_START MAN_AXIS_SCALE_X
140#define MAN_AXIS_RANGE_SCALE_END (MAN_AXIS_SCALE_ZX + 1)
141
143};
144
145/* Axis types. */
146enum {
151};
152
156
157 /* Users may change the twtype, detect changes to re-setup gizmo options. */
161
162 /* Only for view orientation. */
163 struct {
164 float viewinv_m3[3][3];
166
167 /* Only for Rotate operator. */
168 float rotation;
169
171};
172
174
175/* -------------------------------------------------------------------- */
178
179/* Loop over axes. */
180#define MAN_ITER_AXES_BEGIN(axis, axis_idx) \
181 { \
182 wmGizmo *axis; \
183 int axis_idx; \
184 for (axis_idx = 0; axis_idx < MAN_AXIS_LAST; axis_idx++) { \
185 axis = gizmo_get_axis_from_index(ggd, axis_idx);
186
187#define MAN_ITER_AXES_END \
188 } \
189 } \
190 ((void)0)
191
192static wmGizmo *gizmo_get_axis_from_index(const GizmoGroup *ggd, const short axis_idx)
193{
194 BLI_assert(IN_RANGE_INCL(axis_idx, float(MAN_AXIS_TRANS_X), float(MAN_AXIS_LAST)));
195 return ggd->gizmos[axis_idx];
196}
197
198static short gizmo_get_axis_type(const int axis_idx)
199{
200 if (axis_idx >= MAN_AXIS_RANGE_TRANS_START && axis_idx < MAN_AXIS_RANGE_TRANS_END) {
201 return MAN_AXES_TRANSLATE;
202 }
203 if (axis_idx >= MAN_AXIS_RANGE_ROT_START && axis_idx < MAN_AXIS_RANGE_ROT_END) {
204 return MAN_AXES_ROTATE;
205 }
206 if (axis_idx >= MAN_AXIS_RANGE_SCALE_START && axis_idx < MAN_AXIS_RANGE_SCALE_END) {
207 return MAN_AXES_SCALE;
208 }
209 BLI_assert(0);
210 return -1;
211}
212
213static uint gizmo_orientation_axis(const int axis_idx, bool *r_is_plane)
214{
215 switch (axis_idx) {
218 if (r_is_plane) {
219 *r_is_plane = true;
220 }
222 case MAN_AXIS_TRANS_X:
223 case MAN_AXIS_ROT_X:
224 case MAN_AXIS_SCALE_X:
225 return 0;
226
229 if (r_is_plane) {
230 *r_is_plane = true;
231 }
233 case MAN_AXIS_TRANS_Y:
234 case MAN_AXIS_ROT_Y:
235 case MAN_AXIS_SCALE_Y:
236 return 1;
237
240 if (r_is_plane) {
241 *r_is_plane = true;
242 }
244 case MAN_AXIS_TRANS_Z:
245 case MAN_AXIS_ROT_Z:
246 case MAN_AXIS_SCALE_Z:
247 return 2;
248 }
249 return 3;
250}
251
252static bool gizmo_is_axis_visible(const RegionView3D *rv3d,
253 const int twtype,
254 const float idot[3],
255 const int axis_type,
256 const int axis_idx)
257{
258 if ((axis_idx >= MAN_AXIS_RANGE_ROT_START && axis_idx < MAN_AXIS_RANGE_ROT_END) == 0) {
259 bool is_plane = false;
260 const uint aidx_norm = gizmo_orientation_axis(axis_idx, &is_plane);
261 /* Don't draw axis perpendicular to the view. */
262 if (aidx_norm < 3) {
263 float idot_axis = idot[aidx_norm];
264 if (is_plane) {
265 idot_axis = 1.0f - idot_axis;
266 }
267 if (idot_axis < g_tw_axis_range[is_plane].min) {
268 return false;
269 }
270 }
271 }
272
273 if ((axis_type == MAN_AXES_TRANSLATE && !(twtype & V3D_GIZMO_SHOW_OBJECT_TRANSLATE)) ||
274 (axis_type == MAN_AXES_ROTATE && !(twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE)) ||
275 (axis_type == MAN_AXES_SCALE && !(twtype & V3D_GIZMO_SHOW_OBJECT_SCALE)))
276 {
277 return false;
278 }
279
280 switch (axis_idx) {
281 case MAN_AXIS_TRANS_X:
282 return (rv3d->twdrawflag & MAN_TRANS_X);
283 case MAN_AXIS_TRANS_Y:
284 return (rv3d->twdrawflag & MAN_TRANS_Y);
285 case MAN_AXIS_TRANS_Z:
286 return (rv3d->twdrawflag & MAN_TRANS_Z);
287 case MAN_AXIS_TRANS_C:
288 return (rv3d->twdrawflag & MAN_TRANS_C);
289 case MAN_AXIS_ROT_X:
290 return (rv3d->twdrawflag & MAN_ROT_X);
291 case MAN_AXIS_ROT_Y:
292 return (rv3d->twdrawflag & MAN_ROT_Y);
293 case MAN_AXIS_ROT_Z:
294 return (rv3d->twdrawflag & MAN_ROT_Z);
295 case MAN_AXIS_ROT_C:
296 case MAN_AXIS_ROT_T:
297 return (rv3d->twdrawflag & MAN_ROT_C);
298 case MAN_AXIS_SCALE_X:
299 return (rv3d->twdrawflag & MAN_SCALE_X);
300 case MAN_AXIS_SCALE_Y:
301 return (rv3d->twdrawflag & MAN_SCALE_Y);
302 case MAN_AXIS_SCALE_Z:
303 return (rv3d->twdrawflag & MAN_SCALE_Z);
304 case MAN_AXIS_SCALE_C:
305 return (rv3d->twdrawflag & MAN_SCALE_C && (twtype & V3D_GIZMO_SHOW_OBJECT_TRANSLATE) == 0);
307 return (rv3d->twdrawflag & MAN_TRANS_X && rv3d->twdrawflag & MAN_TRANS_Y &&
308 (twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) == 0);
310 return (rv3d->twdrawflag & MAN_TRANS_Y && rv3d->twdrawflag & MAN_TRANS_Z &&
311 (twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) == 0);
313 return (rv3d->twdrawflag & MAN_TRANS_Z && rv3d->twdrawflag & MAN_TRANS_X &&
314 (twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) == 0);
316 return (rv3d->twdrawflag & MAN_SCALE_X && rv3d->twdrawflag & MAN_SCALE_Y &&
317 (twtype & V3D_GIZMO_SHOW_OBJECT_TRANSLATE) == 0 &&
318 (twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) == 0);
320 return (rv3d->twdrawflag & MAN_SCALE_Y && rv3d->twdrawflag & MAN_SCALE_Z &&
321 (twtype & V3D_GIZMO_SHOW_OBJECT_TRANSLATE) == 0 &&
322 (twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) == 0);
324 return (rv3d->twdrawflag & MAN_SCALE_Z && rv3d->twdrawflag & MAN_SCALE_X &&
325 (twtype & V3D_GIZMO_SHOW_OBJECT_TRANSLATE) == 0 &&
326 (twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) == 0);
327 }
328 return false;
329}
330
331static void gizmo_get_axis_color(const int axis_idx,
332 const float idot[3],
333 float r_col[4],
334 float r_col_hi[4])
335{
336 /* Alpha values for normal/highlighted states. */
337 const float alpha = 0.6f;
338 const float alpha_hi = 1.0f;
339 float alpha_fac;
340
341 if (axis_idx >= MAN_AXIS_RANGE_ROT_START && axis_idx < MAN_AXIS_RANGE_ROT_END) {
342 /* Never fade rotation rings. */
343 /* Trackball rotation axis is a special case, we only draw a slight overlay. */
344 alpha_fac = (axis_idx == MAN_AXIS_ROT_T) ? 0.05f : 1.0f;
345 }
346 else {
347 bool is_plane = false;
348 const int axis_idx_norm = gizmo_orientation_axis(axis_idx, &is_plane);
349 /* Get alpha fac based on axis angle,
350 * to fade axis out when hiding it because it points towards view. */
351 if (axis_idx_norm < 3) {
352 const float idot_min = g_tw_axis_range[is_plane].min;
353 const float idot_max = g_tw_axis_range[is_plane].max;
354 float idot_axis = idot[axis_idx_norm];
355 if (is_plane) {
356 idot_axis = 1.0f - idot_axis;
357 }
358 alpha_fac = ((idot_axis > idot_max) ? 1.0f :
359 (idot_axis < idot_min) ? 0.0f :
360 ((idot_axis - idot_min) / (idot_max - idot_min)));
361 }
362 else {
363 alpha_fac = 1.0f;
364 }
365 }
366
367 switch (axis_idx) {
368 case MAN_AXIS_TRANS_X:
369 case MAN_AXIS_ROT_X:
370 case MAN_AXIS_SCALE_X:
374 break;
375 case MAN_AXIS_TRANS_Y:
376 case MAN_AXIS_ROT_Y:
377 case MAN_AXIS_SCALE_Y:
381 break;
382 case MAN_AXIS_TRANS_Z:
383 case MAN_AXIS_ROT_Z:
384 case MAN_AXIS_SCALE_Z:
388 break;
389 case MAN_AXIS_TRANS_C:
390 case MAN_AXIS_ROT_C:
391 case MAN_AXIS_SCALE_C:
392 case MAN_AXIS_ROT_T:
394 break;
395 }
396
397 copy_v4_v4(r_col_hi, r_col);
398
399 r_col[3] = alpha * alpha_fac;
400 r_col_hi[3] = alpha_hi * alpha_fac;
401}
402
403static void gizmo_get_axis_constraint(const int axis_idx, bool r_axis[3])
404{
405 ARRAY_SET_ITEMS(r_axis, 0, 0, 0);
406
407 switch (axis_idx) {
408 case MAN_AXIS_TRANS_X:
409 case MAN_AXIS_ROT_X:
410 case MAN_AXIS_SCALE_X:
411 r_axis[0] = true;
412 break;
413 case MAN_AXIS_TRANS_Y:
414 case MAN_AXIS_ROT_Y:
415 case MAN_AXIS_SCALE_Y:
416 r_axis[1] = true;
417 break;
418 case MAN_AXIS_TRANS_Z:
419 case MAN_AXIS_ROT_Z:
420 case MAN_AXIS_SCALE_Z:
421 r_axis[2] = true;
422 break;
425 r_axis[0] = r_axis[1] = true;
426 break;
429 r_axis[1] = r_axis[2] = true;
430 break;
433 r_axis[2] = r_axis[0] = true;
434 break;
435 default:
436 break;
437 }
438}
439
441
442/* -------------------------------------------------------------------- */
445
446static void reset_tw_center(TransformBounds *tbounds)
447{
448 INIT_MINMAX(tbounds->min, tbounds->max);
449 zero_v3(tbounds->center);
450
451 for (int i = 0; i < 3; i++) {
452 tbounds->axis_min[i] = +FLT_MAX;
453 tbounds->axis_max[i] = -FLT_MAX;
454 }
455}
456
460static void calc_tw_center(TransformBounds *tbounds, const float co[3])
461{
462 minmax_v3v3_v3(tbounds->min, tbounds->max, co);
463 add_v3_v3(tbounds->center, co);
464
465 for (int i = 0; i < 3; i++) {
466 const float d = dot_v3v3(tbounds->axis[i], co);
467 tbounds->axis_min[i] = min_ff(d, tbounds->axis_min[i]);
468 tbounds->axis_max[i] = max_ff(d, tbounds->axis_max[i]);
469 }
470}
471
472static void protectflag_to_drawflags(short protectflag, short *drawflags)
473{
474 if (protectflag & OB_LOCK_LOCX) {
475 *drawflags &= ~MAN_TRANS_X;
476 }
477 if (protectflag & OB_LOCK_LOCY) {
478 *drawflags &= ~MAN_TRANS_Y;
479 }
480 if (protectflag & OB_LOCK_LOCZ) {
481 *drawflags &= ~MAN_TRANS_Z;
482 }
483
484 if (protectflag & OB_LOCK_ROTX) {
485 *drawflags &= ~MAN_ROT_X;
486 }
487 if (protectflag & OB_LOCK_ROTY) {
488 *drawflags &= ~MAN_ROT_Y;
489 }
490 if (protectflag & OB_LOCK_ROTZ) {
491 *drawflags &= ~MAN_ROT_Z;
492 }
493
494 if (protectflag & OB_LOCK_SCALEX) {
495 *drawflags &= ~MAN_SCALE_X;
496 }
497 if (protectflag & OB_LOCK_SCALEY) {
498 *drawflags &= ~MAN_SCALE_Y;
499 }
500 if (protectflag & OB_LOCK_SCALEZ) {
501 *drawflags &= ~MAN_SCALE_Z;
502 }
503}
504
505/* Similar to #transform_object_deform_pose_armature_get but does not check visibility. */
507 Scene *scene,
508 ViewLayer *view_layer)
509{
510 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
512 if (ob && ob->mode & OB_MODE_WEIGHT_PAINT) {
513 /* It is assumed that when the object is in Weight Paint mode, it is not in Edit mode. So we
514 * don't need to check the #OB_MODE_EDIT flag. */
515 BLI_assert(!(ob->mode & OB_MODE_EDIT));
517 if (obpose != nullptr) {
518 ob = obpose;
519 }
520 }
521 return ob;
522}
523
537 const short orient_index,
538 const bool use_curve_handles,
539 const bool use_only_center,
540 FunctionRef<void(const float3 &)> user_fn,
541 const float (**r_mat)[4],
542 short *r_drawflags)
543{
544 const auto run_coord_with_matrix =
545 [&](const float co[3], const bool use_matrix, const float matrix[4][4]) {
546 float co_world[3];
547 if (use_matrix) {
548 mul_v3_m4v3(co_world, matrix, co);
549 co = co_world;
550 }
551 user_fn(co);
552 };
553
554 ScrArea *area = CTX_wm_area(C);
555 const Main *bmain = CTX_data_main(C);
556 Scene *scene = CTX_data_scene(C);
557 /* TODO(sergey): This function is used from operator's modal() and from gizmo's refresh().
558 * Is it fine to possibly evaluate dependency graph here? */
559 Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C);
560 ViewLayer *view_layer = CTX_data_view_layer(C);
561 View3D *v3d = area->spacedata.first_as<View3D>();
562 int a, totsel = 0;
563
564 Object *ob = gizmo_3d_transform_space_object_get(*bmain, scene, view_layer);
565
566 if (Object *obedit = OBEDIT_FROM_OBACT(ob)) {
567
568#define FOREACH_EDIT_OBJECT_BEGIN(ob_iter, use_mat_local) \
569 { \
570 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr()); \
571 Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode( \
572 *bmain, scene, view_layer, CTX_wm_view3d(C)); \
573 for (Object *ob_iter : objects) { \
574 const bool use_mat_local = (ob_iter != obedit);
575
576#define FOREACH_EDIT_OBJECT_END() \
577 } \
578 } \
579 ((void)0)
580
581 ob = obedit;
582 if (obedit->type == OB_MESH) {
583 FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) {
585 if (bm->totvertsel == 0) {
586 continue;
587 }
588
589 BMVert *eve;
590 BMIter iter;
591
592 float mat_local[4][4];
593 if (use_mat_local) {
595 mat_local, obedit->world_to_object().ptr(), ob_iter->object_to_world().ptr());
596 }
597
598 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
601 run_coord_with_matrix(eve->co, use_mat_local, mat_local);
602 totsel++;
603 }
604 }
605 }
606 }
608 } /* End editmesh. */
609 else if (obedit->type == OB_ARMATURE) {
610 FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) {
611 bArmature *arm = id_cast<bArmature *>(ob_iter->data);
612
613 float mat_local[4][4];
614 if (use_mat_local) {
616 mat_local, obedit->world_to_object().ptr(), ob_iter->object_to_world().ptr());
617 }
618 for (EditBone &ebo : *arm->edbo) {
619 if (animrig::bone_is_visible(arm, &ebo)) {
620 if (ebo.flag & BONE_TIPSEL) {
621 run_coord_with_matrix(ebo.tail, use_mat_local, mat_local);
622 totsel++;
623 }
624 if ((ebo.flag & BONE_ROOTSEL) &&
625 /* Don't include same point multiple times. */
626 ((ebo.flag & BONE_CONNECTED) && (ebo.parent != nullptr) &&
627 (ebo.parent->flag & BONE_TIPSEL) && animrig::bone_is_visible(arm, ebo.parent)) ==
628 0)
629 {
630 run_coord_with_matrix(ebo.head, use_mat_local, mat_local);
631 totsel++;
632
633 if (r_drawflags) {
634 if (ebo.flag & (BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL)) {
635 if (ebo.flag & BONE_EDITMODE_LOCKED) {
637 r_drawflags);
638 }
639 }
640 }
641 }
642 }
643 }
644 }
646 }
647 else if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) {
648 FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) {
649 Curve *cu = id_cast<Curve *>(ob_iter->data);
650 BezTriple *bezt;
651 BPoint *bp;
652 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(cu);
653
654 float mat_local[4][4];
655 if (use_mat_local) {
657 mat_local, obedit->world_to_object().ptr(), ob_iter->object_to_world().ptr());
658 }
659
660 Nurb *nu = nurbs->first();
661 while (nu) {
662 if (nu->type == CU_BEZIER) {
663 bezt = nu->bezt;
664 a = nu->pntsu;
665 while (a--) {
666 /* Exceptions:
667 * - If handles are hidden then only check the center points.
668 * - If the center knot is selected then only use this as the center point.
669 */
671 if (bezt->f2 & SELECT) {
672 run_coord_with_matrix(bezt->vec[1], use_mat_local, mat_local);
673 totsel++;
674 }
675 }
676 else if (bezt->f2 & SELECT) {
677 run_coord_with_matrix(bezt->vec[1], use_mat_local, mat_local);
678 totsel++;
679 }
680 else {
681 if (bezt->f1 & SELECT) {
682 const float *co = bezt->vec[!use_curve_handles ? 1 : 0];
683 run_coord_with_matrix(co, use_mat_local, mat_local);
684 totsel++;
685 }
686 if (bezt->f3 & SELECT) {
687 const float *co = bezt->vec[!use_curve_handles ? 1 : 2];
688 run_coord_with_matrix(co, use_mat_local, mat_local);
689 totsel++;
690 }
691 }
692 bezt++;
693 }
694 }
695 else {
696 bp = nu->bp;
697 a = nu->pntsu * nu->pntsv;
698 while (a--) {
699 if (bp->f1 & SELECT) {
700 run_coord_with_matrix(bp->vec, use_mat_local, mat_local);
701 totsel++;
702 }
703 bp++;
704 }
705 }
706 nu = nu->next;
707 }
708 }
710 }
711 else if (obedit->type == OB_MBALL) {
712 FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) {
713 MetaBall *mb = id_cast<MetaBall *>(ob_iter->data);
714
715 float mat_local[4][4];
716 if (use_mat_local) {
718 mat_local, obedit->world_to_object().ptr(), ob_iter->object_to_world().ptr());
719 }
720
721 for (MetaElem &ml : *mb->editelems) {
722 if (ml.flag & SELECT) {
723 run_coord_with_matrix(&ml.x, use_mat_local, mat_local);
724 totsel++;
725 }
726 }
727 }
729 }
730 else if (obedit->type == OB_LATTICE) {
731 FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) {
732 Lattice *lt = (id_cast<Lattice *>(ob_iter->data))->editlatt->latt;
733 BPoint *bp = lt->def;
734 a = lt->pntsu * lt->pntsv * lt->pntsw;
735
736 float mat_local[4][4];
737 if (use_mat_local) {
739 mat_local, obedit->world_to_object().ptr(), ob_iter->object_to_world().ptr());
740 }
741
742 while (a--) {
743 if (bp->f1 & SELECT) {
744 run_coord_with_matrix(bp->vec, use_mat_local, mat_local);
745 totsel++;
746 }
747 bp++;
748 }
749 }
751 }
752 else if (obedit->type == OB_CURVES) {
753 FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) {
754 const Curves &curves_id = *id_cast<Curves *>(ob_iter->data);
755 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
756 const bke::crazyspace::GeometryDeformation deformation =
758
759 float4x4 mat_local;
760 if (use_mat_local) {
761 mat_local = obedit->world_to_object() * ob_iter->object_to_world();
762 }
763
764 IndexMaskMemory memory;
766 curves, CURVE_TYPE_BEZIER, memory);
767
768 auto run_points = [&](const Span<float3> positions, const StringRef selection_name) {
769 const IndexMask selected_points = ed::curves::retrieve_selected_points(
770 curves, selection_name, bezier_points, memory);
771
772 totsel += selected_points.size();
773 selected_points.foreach_index([&](const int point_i) {
774 run_coord_with_matrix(positions[point_i], use_mat_local, mat_local.ptr());
775 });
776 };
777
778 run_points(deformation.positions, ".selection");
779
780 if (curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
781 run_points(*curves.handle_positions_left(), ".selection_handle_left");
782 run_points(*curves.handle_positions_right(), ".selection_handle_right");
783 }
784 }
786 }
787 else if (obedit->type == OB_POINTCLOUD) {
788 FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) {
789 const PointCloud &pointcloud = *id_cast<const PointCloud *>(ob_iter->data);
790
791 float4x4 mat_local;
792 if (use_mat_local) {
793 mat_local = obedit->world_to_object() * ob_iter->object_to_world();
794 }
795
796 const bke::AttributeAccessor attributes = pointcloud.attributes();
797 const VArray selection = *attributes.lookup_or_default<bool>(
798 ".selection", bke::AttrDomain::Point, true);
799
800 IndexMaskMemory memory;
801 const IndexMask mask = IndexMask::from_bools(selection, memory);
802 const Span<float3> positions = pointcloud.positions();
803 totsel += mask.size();
804 mask.foreach_index([&](const int point) {
805 run_coord_with_matrix(positions[point], use_mat_local, mat_local.ptr());
806 });
807 }
809 }
810 else if (obedit->type == OB_GREASE_PENCIL) {
811 FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) {
812 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob_iter->data);
813
814 float4x4 mat_local = float4x4::identity();
815 if (use_mat_local) {
816 mat_local = obedit->world_to_object() * ob_iter->object_to_world();
817 }
818
822 drawings, [&](const ed::greasepencil::MutableDrawingInfo &info) {
824
825 const bke::crazyspace::GeometryDeformation deformation =
827 *depsgraph, *ob, info.drawing);
828
829 const float4x4 layer_transform =
830 mat_local * grease_pencil.layer(info.layer_index).to_object_space(*ob_iter);
831
832 IndexMaskMemory memory;
834 *ob, info.drawing, info.layer_index, memory);
836 curves, CURVE_TYPE_BEZIER, memory);
837
838 auto run_points = [&](const Span<float3> positions, const StringRef selection_name) {
839 const IndexMask selected_points = ed::curves::retrieve_selected_points(
840 curves, selection_name, bezier_points, memory);
841 const IndexMask selected_editable_points = IndexMask::from_intersection(
842 editable_points, selected_points, memory);
843
844 totsel += selected_editable_points.size();
845 selected_editable_points.foreach_index([&](const int point_i) {
846 run_coord_with_matrix(positions[point_i], true, layer_transform.ptr());
847 });
848 };
849
850 run_points(deformation.positions, ".selection");
851
852 if (curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
853 run_points(*curves.handle_positions_left(), ".selection_handle_left");
854 run_points(*curves.handle_positions_right(), ".selection_handle_right");
855 }
856 });
857 }
859 }
860
861#undef FOREACH_EDIT_OBJECT_BEGIN
862#undef FOREACH_EDIT_OBJECT_END
863 }
864 else if (ob && (ob->mode & OB_MODE_POSE)) {
865 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
866
867 const Main *bmain = CTX_data_main(C);
868 Vector<Object *> objects = BKE_object_pose_array_get(*bmain, scene, view_layer, v3d);
869
870 for (Object *ob_iter : objects) {
871 const bool use_mat_local = (ob_iter != ob);
872 /* Mislead counting bones... bah. We don't know the gizmo mode, could be mixed. */
873 const int mode = TFM_ROTATION;
874
876
877 float mat_local[4][4];
878 if (use_mat_local) {
879 mul_m4_m4m4(mat_local, ob->world_to_object().ptr(), ob_iter->object_to_world().ptr());
880 }
881
882 bArmature *arm = id_cast<bArmature *>(ob_iter->data);
883 /* Use channels to get stats. */
884 for (bPoseChannel &pchan : ob_iter->pose->chanbase) {
885 if (!(pchan.runtime.flag & POSE_RUNTIME_TRANSFORM)) {
886 continue;
887 }
888
889 float pchan_pivot[3];
890 BKE_pose_channel_transform_location(arm, &pchan, pchan_pivot);
891 run_coord_with_matrix(pchan_pivot, use_mat_local, mat_local);
892 totsel++;
893
894 if (r_drawflags) {
895 /* Protect-flags apply to local space in pose mode, so only let them influence axis
896 * visibility if we show the global orientation, otherwise it's confusing. */
897 if (ELEM(orient_index, V3D_ORIENT_LOCAL, V3D_ORIENT_GIMBAL)) {
898 protectflag_to_drawflags(pchan.protectflag, r_drawflags);
899 }
900 }
901 }
902 }
903 }
904 else if (ob && (ob->mode & OB_MODE_ALL_PAINT_MESH)) {
905 if (ob->mode & OB_MODE_SCULPT) {
906 totsel = 1;
907 run_coord_with_matrix(
908 ob->runtime->sculpt_session->pivot_pos, false, ob->object_to_world().ptr());
909 }
910 }
911 else if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) {
912 PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob);
913 PTCacheEditPoint *point;
914 PTCacheEditKey *ek;
915 int k;
916
917 if (edit) {
918 point = edit->points;
919 for (a = 0; a < edit->totpoint; a++, point++) {
920 if (point->flag & PEP_HIDE) {
921 continue;
922 }
923
924 for (k = 0, ek = point->keys; k < point->totkey; k++, ek++) {
925 if (ek->flag & PEK_SELECT) {
926 user_fn((ek->flag & PEK_USE_WCO) ? ek->world_co : ek->co);
927 totsel++;
928 }
929 }
930 }
931 }
932 }
933 else {
934 const Main *bmain = CTX_data_main(C);
935
936 /* We need the one selected object, if its not active. */
937 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
938 {
939 Base *base = BKE_view_layer_active_base_get(view_layer);
940 ob = base ? base->object : nullptr;
941 if (base && ((base->flag & BASE_SELECTED) == 0)) {
942 ob = nullptr;
943 }
944 }
945
946 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
947 if (!BASE_SELECTED_EDITABLE(v3d, &base)) {
948 continue;
949 }
950 if (ob == nullptr) {
951 ob = base.object;
952 }
953
954 /* Get the boundbox out of the evaluated object. */
955 std::optional<std::array<float3, 8>> bb;
956 if (use_only_center == false) {
957 if (std::optional<Bounds<float3>> bounds = BKE_object_boundbox_get(base.object)) {
958 bb.emplace(bounds::corners(*bounds));
959 }
960 }
961
962 if (use_only_center || !bb) {
963 user_fn(base.object->object_to_world().location());
964 }
965 else {
966 for (uint j = 0; j < 8; j++) {
967 float co[3];
968 mul_v3_m4v3(co, base.object->object_to_world().ptr(), (*bb)[j]);
969 user_fn(co);
970 }
971 }
972 totsel++;
973 if (r_drawflags) {
974 if (orient_index == V3D_ORIENT_GLOBAL) {
975 /* Ignore scale/rotate lock flag while global orientation is active.
976 * Otherwise when object is rotated, global and local axes are misaligned, implying wrong
977 * axis as hidden/locked, see: !133286. */
978 protectflag_to_drawflags(base.object->protectflag & OB_LOCK_LOC, r_drawflags);
979 }
980 else if (ELEM(orient_index, V3D_ORIENT_LOCAL, V3D_ORIENT_GIMBAL)) {
981 protectflag_to_drawflags(base.object->protectflag, r_drawflags);
982 }
983 }
984 }
985 }
986
987 if (r_mat && ob) {
988 *r_mat = ob->object_to_world().ptr();
989 }
990
991 return totsel;
992}
993
995 const TransformCalcParams *params,
996 TransformBounds *tbounds,
997 RegionView3D *rv3d)
998{
999 const Main *bmain = CTX_data_main(C);
1000 ScrArea *area = CTX_wm_area(C);
1001 Scene *scene = CTX_data_scene(C);
1002 ViewLayer *view_layer = CTX_data_view_layer(C);
1003 View3D *v3d = area->spacedata.first_as<View3D>();
1004 int totsel = 0;
1005
1006 const int pivot_point = scene->toolsettings->transform_pivot_point;
1007 const short orient_index = params->orientation_index ?
1008 (params->orientation_index - 1) :
1010
1011 Object *ob = gizmo_3d_transform_space_object_get(*bmain, scene, view_layer);
1012 Object *obedit = OBEDIT_FROM_OBACT(ob);
1013
1014 tbounds->use_matrix_space = false;
1015 unit_m3(tbounds->axis);
1016
1017 /* Global, local or normal orientation?
1018 * if we could check 'totsel' now, this should be skipped with no selection. */
1019 if (ob) {
1020 float mat[3][3];
1022 *bmain, scene, view_layer, v3d, rv3d, ob, obedit, orient_index, pivot_point, mat);
1023 copy_m3_m3(tbounds->axis, mat);
1024 }
1025
1026 reset_tw_center(tbounds);
1027
1028 if (rv3d) {
1029 /* Transform widget centroid/center. */
1030 copy_m4_m3(rv3d->twmat, tbounds->axis);
1031 rv3d->twdrawflag = short(0xFFFF);
1032 }
1033
1034 if (params->use_local_axis && (ob && ob->mode & (OB_MODE_EDIT | OB_MODE_POSE))) {
1035 const float4x4 &ob_mat = ob->object_to_world();
1036 float diff_mat[3][3];
1037 copy_m3_m4(diff_mat, ob_mat.ptr());
1038 normalize_m3(diff_mat);
1039 invert_m3(diff_mat);
1040 mul_m3_m3_pre(tbounds->axis, diff_mat);
1041 normalize_m3(tbounds->axis);
1042
1043 tbounds->use_matrix_space = true;
1044 copy_m4_m4(tbounds->matrix_space, ob_mat.ptr());
1045 }
1046
1047 const auto gizmo_3d_tbounds_calc_fn = [&](const float3 &co) { calc_tw_center(tbounds, co); };
1048
1050 orient_index,
1051 (pivot_point != V3D_AROUND_LOCAL_ORIGINS),
1052 params->use_only_center,
1053 gizmo_3d_tbounds_calc_fn,
1054 nullptr,
1055 rv3d ? &rv3d->twdrawflag : nullptr);
1056
1057 if (totsel) {
1058 mul_v3_fl(tbounds->center, 1.0f / float(totsel)); /* Centroid! */
1059
1060 if (obedit || (ob && (ob->mode & (OB_MODE_POSE | OB_MODE_SCULPT)))) {
1061 const float4x4 &ob_mat = ob->object_to_world();
1062 if (ob->mode & OB_MODE_POSE) {
1063 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob_mat.ptr());
1064 }
1065 mul_m4_v3(ob_mat.ptr(), tbounds->center);
1066 mul_m4_v3(ob_mat.ptr(), tbounds->min);
1067 mul_m4_v3(ob_mat.ptr(), tbounds->max);
1068 }
1069 }
1070
1071 if (rv3d) {
1072 if (totsel == 0) {
1073 unit_m4(rv3d->twmat);
1074 unit_m3(rv3d->tw_axis_matrix);
1075 zero_v3(rv3d->tw_axis_min);
1076 zero_v3(rv3d->tw_axis_max);
1077 }
1078 else {
1079 copy_m3_m3(rv3d->tw_axis_matrix, tbounds->axis);
1080 copy_v3_v3(rv3d->tw_axis_min, tbounds->axis_min);
1081 copy_v3_v3(rv3d->tw_axis_max, tbounds->axis_max);
1082 }
1083 }
1084
1085 return totsel;
1086}
1087
1089
1090/* -------------------------------------------------------------------- */
1093
1094static void gizmo_get_idot(const RegionView3D *rv3d, float r_idot[3])
1095{
1096 float view_vec[3], axis_vec[3];
1097 ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], view_vec);
1098 for (int i = 0; i < 3; i++) {
1099 normalize_v3_v3(axis_vec, rv3d->twmat[i]);
1100 r_idot[i] = 1.0f - fabsf(dot_v3v3(view_vec, axis_vec));
1101 }
1102}
1103
1104static bool gizmo_3d_calc_pos(const bContext *C,
1105 const Scene *scene,
1106 const TransformBounds *tbounds,
1107 const short pivot_type,
1108 float r_pivot_pos[3])
1109{
1110 switch (pivot_type) {
1111 case V3D_AROUND_CURSOR:
1112 copy_v3_v3(r_pivot_pos, scene->cursor.location);
1113 return true;
1114 case V3D_AROUND_ACTIVE: {
1115 const Main *bmain = CTX_data_main(C);
1116 ViewLayer *view_layer = CTX_data_view_layer(C);
1117 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1118 Object *ob = BKE_view_layer_active_object_get(view_layer);
1119 if (ob != nullptr) {
1120 if ((ob->mode & OB_MODE_SCULPT) && ob->runtime->sculpt_session) {
1122 copy_v3_v3(r_pivot_pos, ss->pivot_pos);
1123 return true;
1124 }
1125 if (object::calc_active_center(ob, false, r_pivot_pos)) {
1126 return true;
1127 }
1128 }
1129 }
1130 [[fallthrough]];
1132 TransformBounds tbounds_stack;
1133 if (tbounds == nullptr) {
1134 TransformCalcParams calc_params{};
1135 calc_params.use_only_center = true;
1136 if (calc_gizmo_stats(C, &calc_params, &tbounds_stack, nullptr)) {
1137 tbounds = &tbounds_stack;
1138 }
1139 }
1140 if (tbounds) {
1141 mid_v3_v3v3(r_pivot_pos, tbounds->min, tbounds->max);
1142 return true;
1143 }
1144 break;
1145 }
1148 if (tbounds) {
1149 copy_v3_v3(r_pivot_pos, tbounds->center);
1150 return true;
1151 }
1152
1153 float co_sum[3] = {0.0f, 0.0f, 0.0f};
1154 const auto gizmo_3d_calc_center_fn = [&](const float3 &co) { add_v3_v3(co_sum, co); };
1155 const float (*r_mat)[4] = nullptr;
1156 int totsel;
1158 0,
1159 (pivot_type != V3D_AROUND_LOCAL_ORIGINS),
1160 true,
1161 gizmo_3d_calc_center_fn,
1162 &r_mat,
1163 nullptr);
1164 if (totsel) {
1165 mul_v3_v3fl(r_pivot_pos, co_sum, 1.0f / float(totsel));
1166 if (r_mat) {
1167 mul_m4_v3(r_mat, r_pivot_pos);
1168 }
1169 return true;
1170 }
1171 }
1172 }
1173
1174 return false;
1175}
1176
1177void gizmo_prepare_mat(const bContext *C, RegionView3D *rv3d, const TransformBounds *tbounds)
1178{
1179 Scene *scene = CTX_data_scene(C);
1180 gizmo_3d_calc_pos(C, scene, tbounds, scene->toolsettings->transform_pivot_point, rv3d->twmat[3]);
1181}
1182
1187static void gizmo_line_range(const int twtype, const short axis_type, float *r_start, float *r_end)
1188{
1189 float start = 0.2f;
1190 float end = 1.0f;
1191
1192 switch (axis_type) {
1193 case MAN_AXES_TRANSLATE:
1194 if (twtype & V3D_GIZMO_SHOW_OBJECT_SCALE) {
1195 start = end - 0.125f;
1196 }
1197 if (twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) {
1198 /* Avoid rotate and translate gizmos overlap. */
1199 const float rotate_offset = 0.215f;
1200 start += rotate_offset;
1201 end += rotate_offset + 0.2f;
1202 }
1203 break;
1204 case MAN_AXES_SCALE:
1206 end -= 0.225f;
1207 }
1208 break;
1209 }
1210
1211 if (r_start) {
1212 *r_start = start;
1213 }
1214 if (r_end) {
1215 *r_end = end;
1216 }
1217}
1218
1220
1221/* -------------------------------------------------------------------- */
1224
1226 wmMsgBus *mbus,
1227 Scene *scene,
1228 bScreen *screen,
1229 ScrArea *area,
1230 ARegion *region,
1231 void (*type_fn)(wmGizmoGroupType *))
1232{
1233 /* Subscribe to view properties. */
1234 wmMsgSubscribeValue msg_sub_value_gz_tag_refresh{};
1235 msg_sub_value_gz_tag_refresh.owner = region;
1236 msg_sub_value_gz_tag_refresh.user_data = gzgroup->parent_gzmap;
1237 msg_sub_value_gz_tag_refresh.notify = WM_gizmo_do_msg_notify_tag_refresh;
1238
1239 int orient_flag = 0;
1240 if (type_fn == VIEW3D_GGT_xform_gizmo) {
1241 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
1242 orient_flag = ggd->twtype_init;
1243 }
1244 else if (type_fn == VIEW3D_GGT_xform_cage) {
1245 orient_flag = V3D_GIZMO_SHOW_OBJECT_SCALE;
1246 /* Pass. */
1247 }
1248 else if (type_fn == VIEW3D_GGT_xform_shear) {
1249 orient_flag = V3D_GIZMO_SHOW_OBJECT_ROTATE;
1250 }
1252 orient_flag);
1253 PointerRNA orient_ref_ptr = RNA_pointer_create_discrete(
1254 &scene->id, RNA_TransformOrientationSlot, orient_slot);
1255 const ToolSettings *ts = scene->toolsettings;
1256
1257 PointerRNA scene_ptr = RNA_id_pointer_create(&scene->id);
1258 {
1259 const PropertyRNA *props[] = {
1260 &rna_Scene_transform_orientation_slots,
1261 };
1262 for (int i = 0; i < ARRAY_SIZE(props); i++) {
1263 WM_msg_subscribe_rna(mbus, &scene_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
1264 }
1265 }
1266
1267 if ((ts->transform_pivot_point == V3D_AROUND_CURSOR) || (orient_slot->type == V3D_ORIENT_CURSOR))
1268 {
1269 /* We could be more specific here, for now subscribe to any cursor change. */
1271 &scene->id, RNA_View3DCursor, &scene->cursor);
1272 WM_msg_subscribe_rna(mbus, &cursor_ptr, nullptr, &msg_sub_value_gz_tag_refresh, __func__);
1273 }
1274
1275 {
1276 const PropertyRNA *props[] = {
1277 &rna_TransformOrientationSlot_type,
1278 &rna_TransformOrientationSlot_use,
1279 };
1280 for (int i = 0; i < ARRAY_SIZE(props); i++) {
1281 if (props[i]) {
1283 mbus, &orient_ref_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
1284 }
1285 }
1286 }
1287
1288 PointerRNA toolsettings_ptr = RNA_pointer_create_discrete(
1289 &scene->id, RNA_ToolSettings, scene->toolsettings);
1290
1292 const PropertyRNA *props[] = {
1293 &rna_ToolSettings_transform_pivot_point,
1294 };
1295 for (int i = 0; i < ARRAY_SIZE(props); i++) {
1297 mbus, &toolsettings_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
1298 }
1299 }
1300
1301 {
1302 const PropertyRNA *props[] = {
1303 &rna_ToolSettings_workspace_tool_type,
1304 };
1305 for (int i = 0; i < ARRAY_SIZE(props); i++) {
1307 mbus, &toolsettings_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
1308 }
1309 }
1310
1312 &screen->id, RNA_SpaceView3D, area->spacedata.first_);
1313
1314 if (type_fn == VIEW3D_GGT_xform_gizmo) {
1315 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
1316 if (ggd->use_twtype_refresh) {
1317 const PropertyRNA *props[] = {
1318 &rna_SpaceView3D_show_gizmo_object_translate,
1319 &rna_SpaceView3D_show_gizmo_object_rotate,
1320 &rna_SpaceView3D_show_gizmo_object_scale,
1321 };
1322 for (int i = 0; i < ARRAY_SIZE(props); i++) {
1323 WM_msg_subscribe_rna(mbus, &view3d_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
1324 }
1325 }
1326 }
1327 else if (type_fn == VIEW3D_GGT_xform_cage) {
1328 /* Pass. */
1329 }
1330 else if (type_fn == VIEW3D_GGT_xform_shear) {
1331 /* Pass. */
1332 }
1333 else {
1334 BLI_assert(0);
1335 }
1336
1337 WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_gz_tag_refresh);
1338 WM_msg_subscribe_rna_anon_prop(mbus, EditBone, lock, &msg_sub_value_gz_tag_refresh);
1339}
1340
1342
1343/* -------------------------------------------------------------------- */
1346
1347static void gizmo_3d_dial_matrixbasis_calc(const ARegion *region,
1348 const float axis[3],
1349 const float center_global[3],
1350 const float mval_init[2],
1351 float r_mat_basis[4][4])
1352{
1353 plane_from_point_normal_v3(r_mat_basis[2], center_global, axis);
1354 copy_v3_v3(r_mat_basis[3], center_global);
1355
1356 if (ED_view3d_win_to_3d_on_plane(region, r_mat_basis[2], mval_init, false, r_mat_basis[1])) {
1357 sub_v3_v3(r_mat_basis[1], center_global);
1358 normalize_v3(r_mat_basis[1]);
1359 cross_v3_v3v3(r_mat_basis[0], r_mat_basis[1], r_mat_basis[2]);
1360 }
1361 else {
1362 /* The plane and the mouse direction are parallel.
1363 * Calculate a matrix orthogonal to the axis. */
1364 ortho_basis_v3v3_v3(r_mat_basis[0], r_mat_basis[1], r_mat_basis[2]);
1365 }
1366
1367 r_mat_basis[0][3] = 0.0f;
1368 r_mat_basis[1][3] = 0.0f;
1369 r_mat_basis[2][3] = 0.0f;
1370 r_mat_basis[3][3] = 1.0f;
1371}
1372
1374#define MAN_AXIS_SCALE_PLANE_SCALE 0.7f
1375
1376static void rotation_get_fn(const wmGizmo * /*gz*/, wmGizmoProperty *gz_prop, void *value)
1377{
1378 const GizmoGroup *ggd = static_cast<const GizmoGroup *>(gz_prop->custom_func.user_data);
1379 *static_cast<float *>(value) = ggd->rotation;
1380}
1381
1382static void rotation_set_fn(const wmGizmo * /*gz*/, wmGizmoProperty *gz_prop, const void *value)
1383{
1384 GizmoGroup *ggd = static_cast<GizmoGroup *>(gz_prop->custom_func.user_data);
1385 ggd->rotation = *static_cast<const float *>(value);
1386}
1387
1388static void gizmo_3d_setup_default_matrix(wmGizmo *axis, const int axis_idx)
1389{
1390 float matrix[3][3];
1391
1392 switch (axis_idx) {
1393 /* Arrow. */
1394 case MAN_AXIS_TRANS_X:
1395 case MAN_AXIS_SCALE_X:
1396 case MAN_AXIS_ROT_X:
1397 copy_v3_fl3(matrix[0], 0.0f, -1.0f, 0.0f);
1398 copy_v3_fl3(matrix[1], 0.0f, 0.0f, -1.0f);
1399 copy_v3_fl3(matrix[2], 1.0f, 0.0f, 0.0f);
1400 break;
1401 case MAN_AXIS_TRANS_Y:
1402 case MAN_AXIS_SCALE_Y:
1403 case MAN_AXIS_ROT_Y:
1404 copy_v3_fl3(matrix[0], 1.0f, 0.0f, 0.0f);
1405 copy_v3_fl3(matrix[1], 0.0f, 0.0f, -1.0f);
1406 copy_v3_fl3(matrix[2], 0.0f, 1.0f, 0.0f);
1407 break;
1408 case MAN_AXIS_TRANS_Z:
1409 case MAN_AXIS_SCALE_Z:
1410 case MAN_AXIS_ROT_Z:
1411 copy_v3_fl3(matrix[0], 1.0f, 0.0f, 0.0f);
1412 copy_v3_fl3(matrix[1], 0.0f, 1.0f, 0.0f);
1413 copy_v3_fl3(matrix[2], 0.0f, 0.0f, 1.0f);
1414 break;
1415
1416 case MAN_AXIS_TRANS_XY:
1417 case MAN_AXIS_SCALE_XY:
1418 copy_v3_fl3(matrix[0], -M_SQRT1_2, M_SQRT1_2, 0.0f);
1419 copy_v3_fl3(matrix[1], 0.0f, 0.0f, 1.0f);
1420 copy_v3_fl3(matrix[2], M_SQRT1_2, M_SQRT1_2, 0.0f);
1421 break;
1422 case MAN_AXIS_TRANS_YZ:
1423 case MAN_AXIS_SCALE_YZ:
1424 copy_v3_fl3(matrix[0], 0.0f, -M_SQRT1_2, M_SQRT1_2);
1425 copy_v3_fl3(matrix[1], 1.0f, 0.0f, 0.0f);
1426 copy_v3_fl3(matrix[2], 0, M_SQRT1_2, M_SQRT1_2);
1427 break;
1428 case MAN_AXIS_SCALE_ZX:
1429 case MAN_AXIS_TRANS_ZX:
1430 copy_v3_fl3(matrix[0], M_SQRT1_2, 0.0f, -M_SQRT1_2);
1431 copy_v3_fl3(matrix[1], 0.0f, 1.0f, 0.0f);
1432 copy_v3_fl3(matrix[2], M_SQRT1_2, 0.0f, M_SQRT1_2);
1433 break;
1434
1435 case MAN_AXIS_TRANS_C:
1436 case MAN_AXIS_SCALE_C:
1437 case MAN_AXIS_ROT_C:
1438 case MAN_AXIS_ROT_T:
1439 default:
1440 return;
1441 }
1442
1443 copy_m4_m3(axis->matrix_offset, matrix);
1444}
1445
1446static void gizmo_3d_setup_draw_default(wmGizmo *axis, const int axis_idx)
1447{
1448 gizmo_3d_setup_default_matrix(axis, axis_idx);
1449
1450 switch (axis_idx) {
1451 /* Arrow. */
1452 case MAN_AXIS_TRANS_X:
1453 case MAN_AXIS_TRANS_Y:
1454 case MAN_AXIS_TRANS_Z:
1455 RNA_enum_set(axis->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_NORMAL);
1456 break;
1457 case MAN_AXIS_SCALE_X:
1458 case MAN_AXIS_SCALE_Y:
1459 case MAN_AXIS_SCALE_Z:
1460 RNA_enum_set(axis->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX);
1461 RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_ARROW_DRAW_FLAG_STEM);
1462 break;
1463 case MAN_AXIS_TRANS_XY:
1464 case MAN_AXIS_TRANS_YZ:
1465 case MAN_AXIS_TRANS_ZX:
1466 case MAN_AXIS_SCALE_XY:
1467 case MAN_AXIS_SCALE_YZ:
1468 case MAN_AXIS_SCALE_ZX:
1469 RNA_enum_set(axis->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_PLANE);
1470 RNA_enum_set(axis->ptr, "draw_options", 0);
1472 break;
1473
1474 /* Primitive. */
1475 case MAN_AXIS_TRANS_C:
1476 RNA_enum_set(axis->ptr, "draw_style", ED_GIZMO_PRIMITIVE_STYLE_CIRCLE);
1477 RNA_boolean_set(axis->ptr, "draw_inner", false);
1478 WM_gizmo_set_scale(axis, 0.2f);
1479
1480 /* Prevent axis gizmos overlapping the center point, see: #63744. */
1481 axis->select_bias = 2.0f;
1482 break;
1483 case MAN_AXIS_SCALE_C:
1485 RNA_boolean_set(axis->ptr, "draw_inner", false);
1486
1487 /* Use 6 since this is '1.2' if the main scale is 0.2. */
1488 RNA_float_set(axis->ptr, "arc_inner_factor", 6.0f);
1489 WM_gizmo_set_scale(axis, 0.2f);
1490
1491 /* Prevent axis gizmos overlapping the center point, see: #63744. */
1492 axis->select_bias = -2.0f;
1493 break;
1494
1495 /* Dial. */
1496 case MAN_AXIS_ROT_X:
1497 case MAN_AXIS_ROT_Y:
1498 case MAN_AXIS_ROT_Z:
1499 RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_CLIP);
1501 break;
1502 case MAN_AXIS_ROT_C:
1503 RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_NOP);
1505 WM_gizmo_set_scale(axis, 1.2f);
1506 break;
1507 case MAN_AXIS_ROT_T:
1508 RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_FILL);
1511 break;
1512 }
1513
1514 switch (axis_idx) {
1515 case MAN_AXIS_TRANS_X:
1516 case MAN_AXIS_TRANS_Y:
1517 case MAN_AXIS_TRANS_Z:
1518 case MAN_AXIS_SCALE_X:
1519 case MAN_AXIS_SCALE_Y:
1521 break;
1522 case MAN_AXIS_TRANS_XY:
1523 case MAN_AXIS_TRANS_YZ:
1524 case MAN_AXIS_TRANS_ZX:
1525 case MAN_AXIS_SCALE_XY:
1526 case MAN_AXIS_SCALE_YZ:
1527 case MAN_AXIS_SCALE_ZX:
1528 WM_gizmo_set_line_width(axis, 1.0f);
1529 break;
1530 case MAN_AXIS_ROT_X:
1531 case MAN_AXIS_ROT_Y:
1532 case MAN_AXIS_ROT_Z:
1533 /* Increased line width for better display. */
1535 break;
1536 default:
1538 break;
1539 }
1540
1541 const short axis_type = gizmo_get_axis_type(axis_idx);
1542 switch (axis_type) {
1543 case MAN_AXES_ROTATE: {
1544 RNA_float_set(axis->ptr, "incremental_angle", 0.0f);
1545 axis->select_bias = 0.0f;
1546 break;
1547 }
1548 default:
1549 break;
1550 }
1551}
1552
1553static void gizmo_3d_setup_draw_from_twtype(wmGizmo *axis, const int axis_idx, const int twtype)
1554{
1555 switch (axis_idx) {
1556 case MAN_AXIS_TRANS_X:
1557 case MAN_AXIS_TRANS_Y:
1558 case MAN_AXIS_TRANS_Z:
1559 RNA_enum_set(axis->ptr,
1560 "draw_options",
1562 0 :
1564 break;
1565 default:
1566 break;
1567 }
1568
1569 const short axis_type = gizmo_get_axis_type(axis_idx);
1570 switch (axis_idx) {
1571 case MAN_AXIS_TRANS_X:
1572 case MAN_AXIS_TRANS_Y:
1573 case MAN_AXIS_TRANS_Z:
1574 case MAN_AXIS_SCALE_X:
1575 case MAN_AXIS_SCALE_Y:
1576 case MAN_AXIS_SCALE_Z: {
1577 float start;
1578 float end;
1579 gizmo_line_range(twtype, axis_type, &start, &end);
1580 mul_v3_v3fl(axis->matrix_offset[3], axis->matrix_offset[2], start);
1581
1582 RNA_float_set(axis->ptr, "length", end - start);
1584 break;
1585 }
1586 default:
1587 break;
1588 }
1589
1590 switch (axis_type) {
1591 case MAN_AXES_ROTATE: {
1592 if ((twtype & V3D_GIZMO_SHOW_OBJECT_SCALE) && twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) {
1593 axis->select_bias = -2.0f;
1594 }
1595 }
1596 }
1597}
1598
1599static void gizmo_3d_setup_draw_modal(wmGizmo *axis, const int axis_idx, const int twtype)
1600{
1601 const short axis_type = gizmo_get_axis_type(axis_idx);
1602 switch (axis_idx) {
1603 case MAN_AXIS_TRANS_X:
1604 case MAN_AXIS_TRANS_Y:
1605 case MAN_AXIS_TRANS_Z:
1606 case MAN_AXIS_SCALE_X:
1607 case MAN_AXIS_SCALE_Y:
1608 case MAN_AXIS_SCALE_Z: {
1609
1610 float end, start_co[3] = {0.0f, 0.0f, 0.0f};
1611 gizmo_line_range(twtype, axis_type, nullptr, &end);
1612 RNA_float_set(axis->ptr, "length", end);
1613 RNA_enum_set(axis->ptr,
1614 "draw_options",
1618 break;
1619 }
1620 case MAN_AXIS_TRANS_XY:
1621 case MAN_AXIS_TRANS_YZ:
1622 case MAN_AXIS_TRANS_ZX:
1623 case MAN_AXIS_SCALE_XY:
1624 case MAN_AXIS_SCALE_YZ:
1625 case MAN_AXIS_SCALE_ZX:
1626 RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_ARROW_DRAW_FLAG_ORIGIN);
1627 break;
1628 case MAN_AXIS_SCALE_C:
1629 RNA_enum_set(axis->ptr, "draw_style", ED_GIZMO_PRIMITIVE_STYLE_CIRCLE);
1630 break;
1631 default:
1632 break;
1633 }
1634
1635 switch (axis_type) {
1636 case MAN_AXES_ROTATE: {
1637 PropertyRNA *prop = RNA_struct_find_property(axis->ptr, "draw_options");
1638 const int dial_flag = RNA_property_enum_get(axis->ptr, prop);
1640 break;
1641 }
1642 default:
1643 break;
1644 }
1645}
1646
1648{
1649 GizmoGroup *ggd = MEM_new_zeroed<GizmoGroup>(__func__);
1650
1651 const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
1652 const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true);
1653 const wmGizmoType *gzt_prim = WM_gizmotype_find("GIZMO_GT_primitive_3d", true);
1654
1655 wmGizmoPropertyFnParams params{};
1658 params.user_data = ggd;
1659
1660#define GIZMO_NEW_ARROW(v) \
1661 { \
1662 ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_arrow, gzgroup, nullptr); \
1663 } \
1664 ((void)0)
1665#define GIZMO_NEW_DIAL(v) \
1666 { \
1667 ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_dial, gzgroup, nullptr); \
1668 WM_gizmo_target_property_def_func(ggd->gizmos[v], "offset", &params); \
1669 } \
1670 ((void)0)
1671#define GIZMO_NEW_PRIM(v) \
1672 { \
1673 ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_prim, gzgroup, nullptr); \
1674 } \
1675 ((void)0)
1676
1677 /* Add/init widgets - order matters! */
1679
1681
1685
1689
1693
1694 /* Initialize screen aligned widget last here, looks better, behaves better. */
1696
1698
1702
1706
1707 MAN_ITER_AXES_BEGIN (axis, axis_idx) {
1708 gizmo_3d_setup_draw_default(axis, axis_idx);
1709 }
1711
1712 return ggd;
1713}
1714
1719 wmGizmo *widget,
1720 const wmEvent *event,
1721 eWM_GizmoFlagTweak /*tweak_flag*/)
1722{
1723 /* Avoid unnecessary updates, partially address: #55458. */
1724 if (ELEM(event->type, TIMER, INBETWEEN_MOUSEMOVE)) {
1726 }
1727
1728 ARegion *region = CTX_wm_region(C);
1729 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1730 wmGizmoGroup *gzgroup = widget->parent_gzgroup;
1731
1732 /* Recalculating the orientation has two problems.
1733 * - The matrix calculated based on the transformed selection may not match the matrix
1734 * that was set when transform started.
1735 * - Inspecting the selection for every update is expensive (for *every* redraw).
1736 *
1737 * Instead, use #transform_apply_matrix to transform `rv3d->twmat` or the final scale value
1738 * when scaling.
1739 */
1740 if (false) {
1741 TransformBounds tbounds;
1742
1743 TransformCalcParams calc_params{};
1744 calc_params.use_only_center = true;
1745 if (calc_gizmo_stats(C, &calc_params, &tbounds, rv3d)) {
1746 gizmo_prepare_mat(C, rv3d, &tbounds);
1747 for (wmGizmo &gz : gzgroup->gizmos) {
1748 WM_gizmo_set_matrix_location(&gz, rv3d->twmat[3]);
1749 }
1750 }
1751 }
1752 else {
1753 wmWindow *win = CTX_wm_window(C);
1754 wmOperator *op = nullptr;
1755 for (const wmGizmoOpElem &gzop : widget->op_data) {
1756 op = WM_operator_find_modal_by_type(win, gzop.type);
1757 if (op != nullptr) {
1758 break;
1759 }
1760 }
1761
1762 if (op != nullptr) {
1763 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
1764 const int axis_idx = BLI_array_findindex(ggd->gizmos, ARRAY_SIZE(ggd->gizmos), &widget);
1765 const short axis_type = gizmo_get_axis_type(axis_idx);
1766
1767 float twmat[4][4];
1768 float scale_buf[3];
1769 float *scale = nullptr;
1770 bool update = false;
1771 copy_m4_m4(twmat, rv3d->twmat);
1772
1773 if (axis_type == MAN_AXES_SCALE) {
1774 scale = scale_buf;
1775 transform_final_value_get(static_cast<const TransInfo *>(op->customdata), scale, 3);
1776 update = true;
1777 }
1778 else if (axis_type == MAN_AXES_ROTATE) {
1780 static_cast<const TransInfo *>(op->customdata), &ggd->rotation, 1);
1781 if (widget != ggd->gizmos[MAN_AXIS_ROT_C]) {
1782 ggd->rotation *= -1;
1783 }
1785 widget->ptr,
1786 "incremental_angle",
1787 transform_snap_increment_get(static_cast<const TransInfo *>(op->customdata)));
1788 }
1789 else if (transform_apply_matrix(static_cast<TransInfo *>(op->customdata), twmat)) {
1790 update = true;
1791 }
1792
1793 if (update) {
1794 gizmogroup_refresh_from_matrix(gzgroup, twmat, scale, true);
1796 }
1797 }
1798 }
1799
1801}
1802
1804{
1805 struct {
1806 wmOperatorType *translate, *rotate, *trackball, *resize;
1807 } ot_store = {nullptr};
1808 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
1809
1810 MAN_ITER_AXES_BEGIN (axis, axis_idx) {
1811 const short axis_type = gizmo_get_axis_type(axis_idx);
1812 bool constraint_axis[3] = {true, false, false};
1813 PointerRNA *ptr = nullptr;
1814
1815 gizmo_get_axis_constraint(axis_idx, constraint_axis);
1816
1817 /* Custom handler! */
1819
1820 gizmo_3d_setup_draw_from_twtype(axis, axis_idx, ggd->twtype);
1821
1822 switch (axis_type) {
1823 case MAN_AXES_TRANSLATE:
1824 if (ot_store.translate == nullptr) {
1825 ot_store.translate = WM_operatortype_find("TRANSFORM_OT_translate", true);
1826 }
1827 ptr = WM_gizmo_operator_set(axis, 0, ot_store.translate, nullptr);
1828 break;
1829 case MAN_AXES_ROTATE: {
1830 wmOperatorType *ot_rotate;
1831 if (axis_idx == MAN_AXIS_ROT_T) {
1832 if (ot_store.trackball == nullptr) {
1833 ot_store.trackball = WM_operatortype_find("TRANSFORM_OT_trackball", true);
1834 }
1835 ot_rotate = ot_store.trackball;
1836 }
1837 else {
1838 if (ot_store.rotate == nullptr) {
1839 ot_store.rotate = WM_operatortype_find("TRANSFORM_OT_rotate", true);
1840 }
1841 ot_rotate = ot_store.rotate;
1842 }
1843 ptr = WM_gizmo_operator_set(axis, 0, ot_rotate, nullptr);
1844 break;
1845 }
1846 case MAN_AXES_SCALE: {
1847 if (ot_store.resize == nullptr) {
1848 ot_store.resize = WM_operatortype_find("TRANSFORM_OT_resize", true);
1849 }
1850 ptr = WM_gizmo_operator_set(axis, 0, ot_store.resize, nullptr);
1851 break;
1852 }
1853 }
1854
1855 if (ptr) {
1856 PropertyRNA *prop;
1857 if (ELEM(true, UNPACK3(constraint_axis))) {
1858 if ((prop = RNA_struct_find_property(ptr, "constraint_axis"))) {
1859 RNA_property_boolean_set_array(ptr, prop, constraint_axis);
1860 }
1861 }
1862
1863 RNA_boolean_set(ptr, "release_confirm", true);
1864 }
1865 }
1867}
1868
1869static void WIDGETGROUP_gizmo_setup(const bContext *C, wmGizmoGroup *gzgroup)
1870{
1871 GizmoGroup *ggd = gizmogroup_init(gzgroup);
1872
1873 gzgroup->customdata = ggd;
1874
1875 {
1876 ScrArea *area = CTX_wm_area(C);
1877 const bToolRef *tref = area->runtime.tool;
1878
1879 ggd->twtype = 0;
1880 if (tref && STREQ(tref->idname, "builtin.move")) {
1882 }
1883 else if (tref && STREQ(tref->idname, "builtin.rotate")) {
1885 }
1886 else if (tref && STREQ(tref->idname, "builtin.scale")) {
1888 }
1889 else if (tref && STREQ(tref->idname, "builtin.transform")) {
1892 }
1893 else {
1894 /* This is also correct logic for 'builtin.transform', no special check needed. */
1895 /* Setup all gizmos, they can be toggled via #ToolSettings::gizmo_flag. */
1898 ggd->use_twtype_refresh = true;
1899 }
1900 BLI_assert(ggd->twtype != 0);
1901 ggd->twtype_init = ggd->twtype;
1902 }
1903
1904 /* *** set properties for axes *** */
1906}
1907
1915 const int axis_idx,
1916 const int twtype,
1917 const float twmat[4][4],
1918 const float scale[3])
1919{
1920 const short axis_type = gizmo_get_axis_type(axis_idx);
1921 const int aidx_norm = gizmo_orientation_axis(axis_idx, nullptr);
1922
1923 switch (axis_idx) {
1924 case MAN_AXIS_TRANS_XY:
1925 case MAN_AXIS_TRANS_YZ:
1926 case MAN_AXIS_TRANS_ZX:
1927 case MAN_AXIS_SCALE_XY:
1928 case MAN_AXIS_SCALE_YZ:
1929 case MAN_AXIS_SCALE_ZX:
1930 copy_m4_m4(axis->matrix_basis, twmat);
1931 if (scale) {
1932 RNA_float_set(axis->ptr,
1933 "length",
1934 MAN_AXIS_SCALE_PLANE_SCALE * scale[aidx_norm == 2 ? 0 : aidx_norm + 1]);
1935 }
1936 break;
1937 case MAN_AXIS_SCALE_X:
1938 case MAN_AXIS_SCALE_Y:
1939 case MAN_AXIS_SCALE_Z:
1940 copy_m4_m4(axis->matrix_basis, twmat);
1941 if (scale) {
1942 float end;
1943 gizmo_line_range(twtype, axis_type, nullptr, &end);
1944 RNA_float_set(axis->ptr, "length", end * scale[aidx_norm]);
1945 }
1946
1947 break;
1948 case MAN_AXIS_TRANS_X:
1949 case MAN_AXIS_TRANS_Y:
1950 case MAN_AXIS_TRANS_Z:
1951 copy_m4_m4(axis->matrix_basis, twmat);
1952 break;
1953 case MAN_AXIS_SCALE_C:
1954 WM_gizmo_set_matrix_location(axis, twmat[3]);
1955 if (scale) {
1956 WM_gizmo_set_scale(axis, 0.2f * scale[0]);
1957 }
1958 break;
1959 case MAN_AXIS_ROT_X:
1960 case MAN_AXIS_ROT_Y:
1961 case MAN_AXIS_ROT_Z:
1962 copy_m4_m4(axis->matrix_basis, twmat);
1963 orthogonalize_m4(axis->matrix_basis, aidx_norm);
1964 break;
1965 case MAN_AXIS_ROT_C:
1966 case MAN_AXIS_ROT_T:
1967 default:
1968 WM_gizmo_set_matrix_location(axis, twmat[3]);
1969 break;
1970 }
1971}
1972
1974 const float twmat[4][4],
1975 const float scale[3],
1976 const bool ignore_hidden)
1977{
1978 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
1979
1980 MAN_ITER_AXES_BEGIN (axis, axis_idx) {
1981 if (ignore_hidden && axis->flag & WM_GIZMO_HIDDEN) {
1982 continue;
1983 }
1984 gizmo_refresh_from_matrix(axis, axis_idx, ggd->twtype, twmat, scale);
1985 }
1987}
1988
1990{
1991 if (WM_gizmo_group_is_modal(gzgroup)) {
1992 return;
1993 }
1994
1995 ARegion *region = CTX_wm_region(C);
1996 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
1997 Scene *scene = CTX_data_scene(C);
1998 ScrArea *area = CTX_wm_area(C);
1999 View3D *v3d = area->spacedata.first_as<View3D>();
2000 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
2001 TransformBounds tbounds;
2002
2003 if (ggd->use_twtype_refresh) {
2004 ggd->twtype = v3d->gizmo_show_object & ggd->twtype_init;
2005 if (ggd->twtype != ggd->twtype_prev) {
2006 ggd->twtype_prev = ggd->twtype;
2008 }
2009 }
2010
2011 const int orient_index = BKE_scene_orientation_get_index_from_flag(scene, ggd->twtype_init);
2012
2013 /* Skip, we don't draw anything anyway. */
2014 TransformCalcParams calc_params{};
2015 calc_params.use_only_center = true;
2016 calc_params.orientation_index = orient_index + 1;
2017 if ((ggd->all_hidden = (calc_gizmo_stats(C, &calc_params, &tbounds, rv3d) == 0))) {
2018 return;
2019 }
2020
2022 C, scene, &tbounds, scene->toolsettings->transform_pivot_point, rv3d->twmat[3]);
2023
2024 gizmogroup_refresh_from_matrix(gzgroup, rv3d->twmat, nullptr, false);
2025}
2026
2028 wmGizmoGroup *gzgroup,
2029 wmMsgBus *mbus)
2030{
2031 Scene *scene = CTX_data_scene(C);
2032 bScreen *screen = CTX_wm_screen(C);
2033 ScrArea *area = CTX_wm_area(C);
2034 ARegion *region = CTX_wm_region(C);
2036 gzgroup, mbus, scene, screen, area, region, VIEW3D_GGT_xform_gizmo);
2037}
2038
2040{
2041 MAN_ITER_AXES_BEGIN (axis, axis_idx) {
2043 }
2045}
2046
2048{
2049 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
2050 // ScrArea *area = CTX_wm_area(C);
2051 ARegion *region = CTX_wm_region(C);
2052 // View3D *v3d =static_cast< View3D *> (area->spacedata.first);
2053 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
2054 float viewinv_m3[3][3];
2055 copy_m3_m4(viewinv_m3, rv3d->viewinv);
2056 float idot[3];
2057
2058 /* Re-calculate hidden unless modal. */
2059 const bool is_modal = WM_gizmo_group_is_modal(gzgroup);
2060
2061 /* When looking through a selected camera, the gizmo can be at the
2062 * exact same position as the view, skip so we don't break selection. */
2063 if (ggd->all_hidden || fabsf(ED_view3d_pixel_size(rv3d, rv3d->twmat[3])) < 5e-7f) {
2064 if (!is_modal) {
2066 }
2067 return;
2068 }
2069 gizmo_get_idot(rv3d, idot);
2070
2071 /* *** set properties for axes *** */
2072 MAN_ITER_AXES_BEGIN (axis, axis_idx) {
2073 if (is_modal) {
2074 if (axis->flag & WM_GIZMO_HIDDEN) {
2075 continue;
2076 }
2077 }
2078 else {
2079 const short axis_type = gizmo_get_axis_type(axis_idx);
2080 if (gizmo_is_axis_visible(rv3d, ggd->twtype, idot, axis_type, axis_idx)) {
2081 /* XXX maybe unset _HIDDEN flag on redraw? */
2082 WM_gizmo_set_flag(axis, WM_GIZMO_HIDDEN, false);
2083 }
2084 else {
2086 continue;
2087 }
2088
2089 /* Align to view. */
2090 switch (axis_idx) {
2091 case MAN_AXIS_TRANS_C:
2092 case MAN_AXIS_ROT_C:
2093 case MAN_AXIS_SCALE_C:
2094 case MAN_AXIS_ROT_T:
2096 break;
2097 }
2098 }
2099
2100 float color[4], color_hi[4];
2101 gizmo_get_axis_color(axis_idx, idot, color, color_hi);
2103 WM_gizmo_set_color_highlight(axis, color_hi);
2104 }
2106
2107 /* Refresh handled above when using view orientation. */
2108 if (!equals_m3m3(viewinv_m3, ggd->prev.viewinv_m3)) {
2109 {
2110 Scene *scene = CTX_data_scene(C);
2112 scene, ggd->twtype_init);
2113 switch (orient_slot->type) {
2114 case V3D_ORIENT_VIEW: {
2115 WIDGETGROUP_gizmo_refresh(C, gzgroup);
2116 break;
2117 }
2118 }
2119 }
2120 copy_m3_m4(ggd->prev.viewinv_m3, rv3d->viewinv);
2121 }
2122}
2123
2125 const ARegion *region,
2126 const int axis_idx_active,
2127 const float mval[2])
2128{
2129 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
2130 const RegionView3D *rv3d = static_cast<const RegionView3D *>(region->regiondata);
2131
2132 wmGizmo *axis_active = ggd->gizmos[axis_idx_active];
2133
2134 const short axis_active_type = gizmo_get_axis_type(axis_idx_active);
2135
2136 /* Display only the active gizmo. */
2138 WM_gizmo_set_flag(axis_active, WM_GIZMO_HIDDEN, false);
2139 gizmo_refresh_from_matrix(axis_active, axis_idx_active, ggd->twtype, rv3d->twmat, nullptr);
2140
2143 }
2144
2145 gizmo_3d_setup_draw_modal(axis_active, axis_idx_active, ggd->twtype);
2146
2147 if (axis_active_type == MAN_AXES_TRANSLATE) {
2148 /* Arrows are used for visual reference, so keep all visible. */
2149 for (int axis_idx = MAN_AXIS_TRANS_X; axis_idx <= MAN_AXIS_TRANS_Z; axis_idx++) {
2150 if (axis_idx == axis_idx_active) {
2151 continue;
2152 }
2153 wmGizmo *axis = ggd->gizmos[axis_idx];
2154 WM_gizmo_set_flag(axis, WM_GIZMO_HIDDEN, false);
2155 gizmo_refresh_from_matrix(axis, axis_idx, ggd->twtype, rv3d->twmat, nullptr);
2156 gizmo_3d_setup_draw_default(axis, axis_idx);
2157 gizmo_3d_setup_draw_from_twtype(axis, axis_idx, ggd->twtype);
2158 RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_ARROW_DRAW_FLAG_STEM);
2159 }
2160 }
2161 else if (axis_active_type == MAN_AXES_ROTATE && axis_idx_active != MAN_AXIS_ROT_T) {
2162 float mat[3][3];
2163 mul_m3_m4m4(mat, axis_active->matrix_basis, axis_active->matrix_offset);
2165 region, mat[2], axis_active->matrix_basis[3], mval, axis_active->matrix_offset);
2166
2167 copy_m3_m4(mat, axis_active->matrix_basis);
2168 invert_m3(mat);
2169 mul_m4_m3m4(axis_active->matrix_offset, mat, axis_active->matrix_offset);
2170 zero_v3(axis_active->matrix_offset[3]);
2171 }
2172}
2173
2175 wmGizmoGroup *gzgroup,
2176 wmGizmo *gz,
2177 const wmEvent *event)
2178{
2179 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
2180 const int axis_idx = BLI_array_findindex(ggd->gizmos, ARRAY_SIZE(ggd->gizmos), &gz);
2181
2182 const float mval[2] = {float(event->mval[0]), float(event->mval[1])};
2183 gizmo_3d_draw_invoke(gzgroup, CTX_wm_region(C), axis_idx, mval);
2184
2185 /* Support gizmo specific orientation. */
2186 if (gz != ggd->gizmos[MAN_AXIS_ROT_T]) {
2187 Scene *scene = CTX_data_scene(C);
2188 wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, 0);
2189 PointerRNA *ptr = &gzop->ptr;
2190 PropertyRNA *prop_orient_type = RNA_struct_find_property(ptr, "orient_type");
2192 scene, ggd->twtype_init);
2193 if ((gz == ggd->gizmos[MAN_AXIS_ROT_C]) ||
2194 (orient_slot == &scene->orientation_slots[SCE_ORIENT_DEFAULT]))
2195 {
2196 /* #MAN_AXIS_ROT_C always uses the #V3D_ORIENT_VIEW orientation,
2197 * optionally we could set this orientation instead of unset the property. */
2198 RNA_property_unset(ptr, prop_orient_type);
2199 }
2200 else {
2201 /* TODO: API function. */
2203 RNA_property_enum_set(ptr, prop_orient_type, index);
2204 }
2205 }
2206
2207 /* Support shift click to constrain axis. */
2208 int axis = -1;
2209 switch (axis_idx) {
2210 case MAN_AXIS_TRANS_X:
2211 case MAN_AXIS_TRANS_Y:
2212 case MAN_AXIS_TRANS_Z:
2213 axis = axis_idx - MAN_AXIS_TRANS_X;
2214 break;
2215 case MAN_AXIS_SCALE_X:
2216 case MAN_AXIS_SCALE_Y:
2217 case MAN_AXIS_SCALE_Z:
2218 axis = axis_idx - MAN_AXIS_SCALE_X;
2219 break;
2220 }
2221
2222 if (axis != -1) {
2223 /* Swap single axis for two-axis constraint. */
2224 const bool flip = (event->modifier & KM_SHIFT) != 0;
2225 BLI_assert(axis_idx != -1);
2226 const short axis_type = gizmo_get_axis_type(axis_idx);
2227 if (axis_type != MAN_AXES_ROTATE) {
2228 wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, 0);
2229 PointerRNA *ptr = &gzop->ptr;
2230 PropertyRNA *prop_constraint_axis = RNA_struct_find_property(ptr, "constraint_axis");
2231 if (prop_constraint_axis) {
2232 bool constraint[3] = {false};
2233 constraint[axis] = true;
2234 if (flip) {
2235 for (int i = 0; i < ARRAY_SIZE(constraint); i++) {
2236 constraint[i] = !constraint[i];
2237 }
2238 }
2239 RNA_property_boolean_set_array(ptr, prop_constraint_axis, constraint);
2240 }
2241 }
2242 }
2243}
2244
2246{
2247 if (v3d->gizmo_flag & V3D_GIZMO_HIDE) {
2248 return false;
2249 }
2250 if (G.moving & (G_TRANSFORM_OBJ | G_TRANSFORM_EDIT)) {
2251 return false;
2252 }
2253 return true;
2254}
2255
2257{
2258 ScrArea *area = CTX_wm_area(C);
2259 View3D *v3d = area->spacedata.first_as<View3D>();
2261 return false;
2262 }
2263
2264 const bToolRef *tref = area->runtime.tool;
2266 return false;
2267 }
2270 {
2271 return false;
2272 }
2273
2274 /* Don't show if the tool has a gizmo. */
2275 if (tref && tref->runtime && tref->runtime->gizmo_group[0]) {
2276 return false;
2277 }
2278 return true;
2279}
2280
2282{
2284 return false;
2285 }
2286
2287 ScrArea *area = CTX_wm_area(C);
2288 View3D *v3d = area->spacedata.first_as<View3D>();
2290 return false;
2291 }
2292
2293 if (v3d->gizmo_flag & V3D_GIZMO_HIDE_TOOL) {
2294 return false;
2295 }
2296
2297 return true;
2298}
2299
2300/* Expose as multiple gizmos so tools use one, persistent context another.
2301 * Needed because they use different options which isn't so simple to dynamically update. */
2302
2304{
2305 gzgt->name = "3D View: Transform Gizmo";
2306 gzgt->idname = "VIEW3D_GGT_xform_gizmo";
2307
2310
2313
2321
2322 static const EnumPropertyItem rna_enum_gizmo_items[] = {
2323 {V3D_GIZMO_SHOW_OBJECT_TRANSLATE, "TRANSLATE", 0, "Move", ""},
2324 {V3D_GIZMO_SHOW_OBJECT_ROTATE, "ROTATE", 0, "Rotate", ""},
2325 {V3D_GIZMO_SHOW_OBJECT_SCALE, "SCALE", 0, "Scale", ""},
2326 {0, "NONE", 0, "None", ""},
2327 {0, nullptr, 0, nullptr, nullptr},
2328 };
2329 RNA_def_enum(gzgt->srna,
2330 "drag_action",
2331 rna_enum_gizmo_items,
2333 "Drag Action",
2334 "");
2335
2336 g_GGT_xform_gizmo = gzgt;
2337}
2338
2357
2359
2360/* -------------------------------------------------------------------- */
2363
2365{
2366 wmGizmoMap *gizmo_map = t->region->runtime->gizmo_map;
2367 if (gizmo_map == nullptr) {
2368 BLI_assert_msg(false, "#T_NO_GIZMO should already be set to return early before.");
2369 return nullptr;
2370 }
2371
2372 wmGizmo *gizmo_modal_current = WM_gizmomap_get_modal(gizmo_map);
2373 if (gizmo_modal_current) {
2374 wmGizmoGroup *gzgroup = gizmo_modal_current->parent_gzgroup;
2375 /* Check #wmGizmoGroup::customdata to make sure the GizmoGroup has been initialized. */
2376 if (gzgroup->customdata && ELEM(gzgroup->type, g_GGT_xform_gizmo, g_GGT_xform_gizmo_context)) {
2377 return gzgroup;
2378 }
2379 }
2380 else {
2381 /* See #WM_gizmomap_group_find_ptr. */
2382 for (wmGizmoGroup &gzgroup : *WM_gizmomap_group_list(gizmo_map)) {
2384 /* Choose the one that has been initialized. */
2385 if (gzgroup.customdata) {
2386 return &gzgroup;
2387 }
2388 }
2389 }
2390 }
2391
2392 return nullptr;
2393}
2394
2396{
2397 wmGizmo *gizmo_modal_current = t->region && t->region->runtime->gizmo_map ?
2399 nullptr;
2400 if (!gizmo_modal_current || !ELEM(gizmo_modal_current->parent_gzgroup->type,
2403 {
2404 t->flag |= T_NO_GIZMO;
2405 }
2406}
2407
2409{
2410 if (t->flag & T_NO_GIZMO) {
2411 return;
2412 }
2413
2414 wmGizmoGroup *gzgroup_xform = gizmogroup_xform_find(t);
2415 if (gzgroup_xform == nullptr) {
2416 return;
2417 }
2418
2419 int axis_idx = -1;
2420 if (t->mode == TFM_TRACKBALL) {
2421 /* Pass. Do not display gizmo. */
2422 }
2424 const int axis_map[3][7] = {
2446 };
2447
2449 /* Assert mode values. */
2451 /* Assert constrain values. */
2452 (CON_AXIS0 == (1 << 1)) && (CON_AXIS1 == (1 << 2)) && (CON_AXIS2 == (1 << 3))),
2453 "");
2454
2455 const int trans_mode = t->mode - TFM_TRANSLATION;
2456 int con_mode = ((CON_AXIS0 | CON_AXIS1 | CON_AXIS2) >> 1) - 1;
2457 if (t->con.mode & CON_APPLY) {
2458 con_mode = ((t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2)) >> 1) - 1;
2459 }
2460
2461 axis_idx = axis_map[trans_mode][con_mode];
2462 }
2463
2464 wmGizmo *gizmo_modal_current = WM_gizmomap_get_modal(t->region->runtime->gizmo_map);
2465 if (axis_idx != -1) {
2466 RegionView3D *rv3d = static_cast<RegionView3D *>(t->region->regiondata);
2467 float (*mat_cmp)[3] = t->orient[t->orient_curr != O_DEFAULT ? t->orient_curr : O_SCENE].matrix;
2468
2469 bool update_orientation = !(equals_v3v3(rv3d->twmat[0], mat_cmp[0]) &&
2470 equals_v3v3(rv3d->twmat[1], mat_cmp[1]) &&
2471 equals_v3v3(rv3d->twmat[2], mat_cmp[2]));
2472
2473 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup_xform->customdata);
2474 wmGizmo *gizmo_expected = ggd->gizmos[axis_idx];
2475 if (update_orientation || gizmo_modal_current != gizmo_expected) {
2476 if (update_orientation) {
2477 copy_m4_m3(rv3d->twmat, mat_cmp);
2478 copy_v3_v3(rv3d->twmat[3], t->center_global);
2479 }
2480
2481 wmEvent event = {nullptr};
2482
2483 /* Set the initial mouse value. Used for rotation gizmos. */
2484 copy_v2_v2_int(event.mval, int2(t->mouse.imval));
2485
2486 /* We need to update the position of the gizmo before invoking otherwise
2487 * #wmGizmo::scale_final could be calculated wrong. */
2488 gizmo_refresh_from_matrix(gizmo_expected, axis_idx, ggd->twtype, rv3d->twmat, nullptr);
2489
2490 BLI_assert_msg(!gizmo_modal_current || gizmo_modal_current->highlight_part == 0,
2491 "Avoid changing the highlight part");
2492 gizmo_expected->highlight_part = 0;
2494 t->region->runtime->gizmo_map, t->context, gizmo_expected, &event);
2495 WM_gizmo_highlight_set(t->region->runtime->gizmo_map, gizmo_expected);
2496 }
2497 }
2498 else if (gizmo_modal_current) {
2500 }
2501}
2502
2504{
2505 if (t->flag & T_NO_GIZMO) {
2506 return;
2507 }
2508
2509 wmGizmoGroup *gzgroup_xform = gizmogroup_xform_find(t);
2510 if (gzgroup_xform == nullptr) {
2511 return;
2512 }
2513
2514 GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup_xform->customdata);
2515
2516 /* #wmGizmoGroup::draw_prepare will handle the rest. */
2517 MAN_ITER_AXES_BEGIN (axis, axis_idx) {
2518 gizmo_3d_setup_draw_default(axis, axis_idx);
2519 gizmo_3d_setup_draw_from_twtype(axis, axis_idx, ggd->twtype);
2520 }
2522}
2523
2525
2526/* -------------------------------------------------------------------- */
2529
2530bool calc_pivot_pos(const bContext *C, const short pivot_type, float r_pivot_pos[3])
2531{
2532 Scene *scene = CTX_data_scene(C);
2533 return gizmo_3d_calc_pos(C, scene, nullptr, pivot_type, r_pivot_pos);
2534}
2535
2537
2538} // namespace blender::ed::transform
Functions to deal with Armatures.
Blender kernel action and pose functionality.
Low-level operations for curves.
Low-level operations for grease pencil.
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
#define PEP_HIDE
#define PEK_SELECT
#define PEK_USE_WCO
#define ATTR_FALLTHROUGH
Generic array manipulation API.
#define BLI_array_findindex(arr, arr_len, p)
#define M_SQRT1_2
#define OB_MODE_ALL_PAINT_MESH
#define BASE_SELECTED_EDITABLE(v3d, base)
#define OBEDIT_FROM_OBACT(ob)
#define Window
#define C
Definition RandGen.cpp:29
volatile int lock
#define INIT_MINMAX(min, max)
#define ARRAY_SET_ITEMS(...)
#define UNPACK3(a)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define IN_RANGE_INCL(a, b, c)
#define STREQ(a, b)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
static IndexMask from_intersection(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
const bke::CurvesGeometry & strokes() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define FLT_MAX
float3x3 scale(float3x3 mat, float2 scale)
float4x4 translate(float4x4 mat, float3 translation)
float3x3 rotate(float3x3 mat, AxisAngle rotation)
bool bone_is_visible(const bArmature *armature, const Bone *bone)
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval, const Object &ob_orig, const bke::greasepencil::Drawing &drawing_orig)
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
IndexMask curve_type_point_selection(const bke::CurvesGeometry &curves, CurveType curve_type, LinearAllocator<> &memory)
std::array< VecBase< T, 3 >, 8 > corners(const Bounds< VecBase< T, 3 > > &bounds)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
IndexMask retrieve_editable_points(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
Vector< MutableDrawingInfo > retrieve_editable_drawings(const Scene &scene, GreasePencil &grease_pencil)
bool calc_active_center(Object *ob, bool select_only, float r_center[3])
static void WIDGETGROUP_gizmo_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup, wmMsgBus *mbus, Scene *scene, bScreen *screen, ScrArea *area, ARegion *region, void(*type_fn)(wmGizmoGroupType *))
static void gizmo_get_axis_color(const int axis_idx, const float idot[3], float r_col[4], float r_col_hi[4])
static bool WIDGETGROUP_gizmo_poll_tool(const bContext *C, wmGizmoGroupType *gzgt)
static void protectflag_to_drawflags(short protectflag, short *drawflags)
static wmGizmoGroup * gizmogroup_xform_find(TransInfo *t)
static void rotation_get_fn(const wmGizmo *, wmGizmoProperty *gz_prop, void *value)
static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup)
static void calc_tw_center(TransformBounds *tbounds, const float co[3])
static wmGizmo * gizmo_get_axis_from_index(const GizmoGroup *ggd, const short axis_idx)
void VIEW3D_GGT_xform_gizmo_context(wmGizmoGroupType *gzgt)
static bool WIDGETGROUP_gizmo_poll_generic(View3D *v3d)
static void rotation_set_fn(const wmGizmo *, wmGizmoProperty *gz_prop, const void *value)
static void gizmo_get_idot(const RegionView3D *rv3d, float r_idot[3])
static void WIDGETGROUP_gizmo_message_subscribe(const bContext *C, wmGizmoGroup *gzgroup, wmMsgBus *mbus)
static void gizmogroup_init_properties_from_twtype(wmGizmoGroup *gzgroup)
static void gizmo_get_axis_constraint(const int axis_idx, bool r_axis[3])
static void gizmogroup_refresh_from_matrix(wmGizmoGroup *gzgroup, const float twmat[4][4], const float scale[3], const bool ignore_hidden)
void VIEW3D_GGT_xform_gizmo(wmGizmoGroupType *gzgt)
void gizmo_prepare_mat(const bContext *C, RegionView3D *rv3d, const TransformBounds *tbounds)
static void gizmo_line_range(const int twtype, const short axis_type, float *r_start, float *r_end)
static Object * gizmo_3d_transform_space_object_get(const Main &bmain, Scene *scene, ViewLayer *view_layer)
static wmGizmoGroupType * g_GGT_xform_gizmo_context
static GizmoGroup * gizmogroup_init(wmGizmoGroup *gzgroup)
void VIEW3D_GGT_xform_cage(wmGizmoGroupType *gzgt)
void transform_gizmo_3d_model_from_constraint_and_mode_init(TransInfo *t)
void VIEW3D_GGT_xform_shear(wmGizmoGroupType *gzgt)
static void gizmo_refresh_from_matrix(wmGizmo *axis, const int axis_idx, const int twtype, const float twmat[4][4], const float scale[3])
static bool WIDGETGROUP_gizmo_poll_context(const bContext *C, wmGizmoGroupType *)
static void gizmo_3d_setup_draw_from_twtype(wmGizmo *axis, const int axis_idx, const int twtype)
static void gizmo_3d_dial_matrixbasis_calc(const ARegion *region, const float axis[3], const float center_global[3], const float mval_init[2], float r_mat_basis[4][4])
static wmOperatorStatus gizmo_modal(bContext *C, wmGizmo *widget, const wmEvent *event, eWM_GizmoFlagTweak)
static void gizmogroup_hide_all(GizmoGroup *ggd)
void transform_convert_pose_transflags_update(Object *ob, int mode, short around)
static void gizmo_3d_setup_default_matrix(wmGizmo *axis, const int axis_idx)
void transform_gizmo_3d_model_from_constraint_and_mode_set(TransInfo *t)
short calc_orientation_from_type_ex(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d, const RegionView3D *rv3d, Object *ob, Object *obedit, short orientation_index, int pivot_point, float r_mat[3][3])
bool calc_pivot_pos(const bContext *C, const short pivot_type, float r_pivot_pos[3])
static void WIDGETGROUP_gizmo_invoke_prepare(const bContext *C, wmGizmoGroup *gzgroup, wmGizmo *gz, const wmEvent *event)
static bool gizmo_3d_calc_pos(const bContext *C, const Scene *scene, const TransformBounds *tbounds, const short pivot_type, float r_pivot_pos[3])
static void gizmo_3d_draw_invoke(wmGizmoGroup *gzgroup, const ARegion *region, const int axis_idx_active, const float mval[2])
static void gizmo_3d_setup_draw_modal(wmGizmo *axis, const int axis_idx, const int twtype)
void transform_final_value_get(const TransInfo *t, float *value, const int value_num)
static short gizmo_get_axis_type(const int axis_idx)
static void reset_tw_center(TransformBounds *tbounds)
static int gizmo_3d_foreach_selected(const bContext *C, const short orient_index, const bool use_curve_handles, const bool use_only_center, FunctionRef< void(const float3 &)> user_fn, const float(**r_mat)[4], short *r_drawflags)
static wmGizmoGroupType * g_GGT_xform_gizmo
static void gizmo_3d_setup_draw_default(wmGizmo *axis, const int axis_idx)
static void WIDGETGROUP_gizmo_setup(const bContext *C, wmGizmoGroup *gzgroup)
static bool gizmo_is_axis_visible(const RegionView3D *rv3d, const int twtype, const float idot[3], const int axis_type, const int axis_idx)
bool transform_apply_matrix(TransInfo *t, float mat[4][4])
static struct blender::ed::transform::@037211103306221152000132102042016246256161162141 g_tw_axis_range[2]
void transform_gizmo_3d_model_from_constraint_and_mode_restore(TransInfo *t)
int calc_gizmo_stats(const bContext *C, const TransformCalcParams *params, TransformBounds *tbounds, RegionView3D *rv3d)
float transform_snap_increment_get(const TransInfo *t)
static uint gizmo_orientation_axis(const int axis_idx, bool *r_is_plane)
void parallel_for_each(Range &&range, const Function &function)
Definition BLI_task.hh:31
void get_color_4fv(int colorid, float col[4])
MINLINE float min_ff(float a, float b)
void WM_gizmo_set_matrix_rotation_from_z_axis(wmGizmo *gz, const float z_axis[3])
Definition wm_gizmo.cc:273
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ScrArea * CTX_wm_area(const bContext *C)
void mul_m3_m3_pre(float R[3][3], const float A[3][3])
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
void orthogonalize_m4(float R[4][4], int axis)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
const ListBaseT< wmGizmoGroup > * WM_gizmomap_group_list(wmGizmoMap *gzmap)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
wmGizmo * WM_gizmomap_get_modal(const wmGizmoMap *gzmap)
void WM_gizmo_do_msg_notify_tag_refresh(bContext *, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
@ V3D_GIZMO_SHOW_OBJECT_TRANSLATE
@ V3D_GIZMO_SHOW_OBJECT_SCALE
@ V3D_GIZMO_SHOW_OBJECT_ROTATE
wmOperator * WM_operator_find_modal_by_type(wmWindow *win, const wmOperatorType *ot)
void copy_m3_m3(float m1[3][3], const float m2[3][3])
PointerRNA RNA_id_pointer_create(ID *id)
void copy_m4_m3(float m1[4][4], const float m2[3][3])
void WM_gizmo_set_color(wmGizmo *gz, const float color[4])
Definition wm_gizmo.cc:327
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void WM_gizmo_modal_set_while_modal(wmGizmoMap *gzmap, bContext *C, wmGizmo *gz, const wmEvent *event)
Definition wm_gizmo.cc:430
const wmGizmoType * WM_gizmotype_find(const StringRef idname, bool quiet)
float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3])
void normalize_m3(float R[3][3]) ATTR_NONNULL()
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
@ V3D_AROUND_CENTER_BOUNDS
@ V3D_AROUND_LOCAL_ORIGINS
@ V3D_AROUND_CENTER_MEDIAN
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int BKE_scene_orientation_get_index(Scene *scene, int slot_index)
Definition scene.cc:2678
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
wmWindow * CTX_wm_window(const bContext *C)
void WM_gizmo_set_color_highlight(wmGizmo *gz, const float color_hi[4])
Definition wm_gizmo.cc:336
@ ED_GIZMO_ARROW_DRAW_FLAG_ORIGIN
@ ED_GIZMO_ARROW_DRAW_FLAG_STEM
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
@ TH_GIZMO_VIEW_ALIGN
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
void WM_gizmo_set_matrix_offset_location(wmGizmo *gz, const float offset[3])
Definition wm_gizmo.cc:298
void mul_m3_m4m4(float R[3][3], const float A[4][4], const float B[4][4])
MatBase< float, 4, 4 > float4x4
void ED_region_tag_redraw_editor_overlays(ARegion *region)
Definition area.cc:745
bool WM_gizmo_highlight_set(wmGizmoMap *gzmap, wmGizmo *gz)
Definition wm_gizmo.cc:401
void WM_gizmo_set_line_width(wmGizmo *gz, const float line_width)
Definition wm_gizmo.cc:318
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
Definition math_geom.cc:225
void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], float r_out[3])
ViewLayer * CTX_data_view_layer(const bContext *C)
MINLINE void mul_v3_fl(float r[3], float f)
void WM_gizmo_set_scale(wmGizmo *gz, const float scale)
Definition wm_gizmo.cc:313
@ INBETWEEN_MOUSEMOVE
Global G
Definition blender.cc:57
MINLINE void sub_v3_v3(float r[3], const float a[3])
@ ED_GIZMO_PRIMITIVE_STYLE_ANNULUS
@ ED_GIZMO_PRIMITIVE_STYLE_CIRCLE
void mul_m4_v3(const float M[4][4], float r[3])
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition wm_gizmo.cc:303
VecBase< int32_t, 2 > int2
void BKE_pose_channel_transform_location(const bArmature *arm, const bPoseChannel *pose_bone, float r_pose_space_pivot[3])
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
PTCacheEdit * PE_get_current(Depsgraph *depsgraph, Scene *scene, Object *ob)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
eWM_GizmoFlagTweak
Gizmo tweak flag. Bit-flag passed to gizmo while tweaking.
int BKE_scene_orientation_get_index_from_flag(Scene *scene, int flag)
Definition scene.cc:2684
@ OB_MODE_PARTICLE_EDIT
void WM_gizmo_set_fn_custom_modal(wmGizmo *gz, wmGizmoFnModal fn)
Definition wm_gizmo.cc:347
bool ED_view3d_win_to_3d_on_plane(const ARegion *region, const float plane[4], const float mval[2], bool do_clip, float r_out[3])
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
void RNA_property_unset(PointerRNA *ptr, PropertyRNA *prop)
PointerRNA * WM_gizmo_operator_set(wmGizmo *gz, int part_index, wmOperatorType *ot, IDProperty *properties)
Definition wm_gizmo.cc:199
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void unit_m4(float m[4][4])
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool WM_gizmo_group_is_modal(const wmGizmoGroup *gzgroup)
Definition wm_gizmo.cc:716
MINLINE void zero_v3(float r[3])
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
@ ED_GIZMO_ARROW_STYLE_NORMAL
@ ED_GIZMO_ARROW_STYLE_PLANE
@ ED_GIZMO_ARROW_STYLE_BOX
MINLINE float normalize_v3_v3(float r[3], const float a[3])
bool invert_m3(float mat[3][3])
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
@ WM_GIZMOGROUPTYPE_PERSISTENT
@ WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK
@ WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
@ WM_GIZMO_DRAW_HOVER
@ WM_GIZMO_DRAW_OFFSET_SCALE
@ WM_GIZMO_DRAW_VALUE
@ WM_GIZMO_SELECT_BACKGROUND
MINLINE float normalize_v3(float n[3])
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
MINLINE void add_v3_v3(float r[3], const float a[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
Main * CTX_data_main(const bContext *C)
void unit_m3(float m[3][3])
MINLINE float max_ff(float a, float b)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
TransformOrientationSlot * BKE_scene_orientation_slot_get_from_flag(Scene *scene, int flag)
Definition scene.cc:2647
@ G_TRANSFORM_OBJ
@ G_TRANSFORM_EDIT
ListBaseT< Nurb > * BKE_curve_editNurbs_get(Curve *cu)
Definition curve.cc:441
int BKE_scene_orientation_slot_get_index(const TransformOrientationSlot *orient_slot)
Definition scene.cc:2671
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
wmKeyMap * WM_gizmogroup_setup_keymap_generic_maybe_drag(const wmGizmoGroupType *, wmKeyConfig *kc)
std::optional< Bounds< float3 > > BKE_object_boundbox_get(const Object *ob)
Definition object.cc:3726
MINLINE void copy_v4_v4(float r[4], const float a[4])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
wmGizmoOpElem * WM_gizmo_operator_get(wmGizmo *gz, int part_index)
Definition wm_gizmo.cc:191
void ortho_basis_v3v3_v3(float r_n1[3], float r_n2[3], const float n[3])
bool ED_gizmo_poll_or_unlink_delayed_from_tool(const bContext *C, wmGizmoGroupType *gzgt)
void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3])
Definition wm_gizmo.cc:283
Vector< Object * > BKE_object_pose_array_get(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
Definition object.cc:2594
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ARegion * CTX_wm_region(const bContext *C)
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4])
@ ED_GIZMO_DIAL_DRAW_FLAG_CLIP
@ ED_GIZMO_DIAL_DRAW_FLAG_FILL
@ ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE
@ ED_GIZMO_DIAL_DRAW_FLAG_NOP
bool equals_m3m3(const float mat1[3][3], const float mat2[3][3])
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
bke::ARegionRuntime * runtime
struct Object * object
eBezTriple_Flag f2
eBezTriple_Flag f3
eBezTriple_Flag f1
struct BPoint * def
const c_style_mat & ptr() const
ListBaseT< MetaElem > * editelems
eMetaElem_Flag flag
BezTriple * bezt
struct Nurb * next
bke::ObjectRuntime * runtime
struct PTCacheEditKey * keys
PTCacheEditPoint * points
TransformOrientationSlot orientation_slots[4]
View3DCursor cursor
struct ToolSettings * toolsettings
ScrArea_Runtime runtime
ListBaseT< SpaceLink > spacedata
eHandleDisplay handle_display
eView3D_GizmoShowObject gizmo_show_object
View3DOverlay overlay
eView3D_GizmoFlag gizmo_flag
ListBaseT< EditBone > * edbo
bPoseChannelRuntimeFlag flag
struct bPoseChannel_Runtime runtime
bToolRef_Runtime * runtime
struct blender::ed::transform::GizmoGroup::@132061275200025353161301327365316067222226361307 prev
struct blender::ed::transform::TransInfo::@074260112357037217233016050204226071352346123342 orient[3]
wmEventType type
Definition WM_types.hh:817
wmGizmoGroupFnMsgBusSubscribe message_subscribe
wmGizmoGroupFnRefresh refresh
wmGizmoGroupFnInvokePrepare invoke_prepare
wmGizmoGroupFnSetupKeymap setup_keymap
wmGizmoMapType_Params gzmap_params
wmGizmoGroupFnDrawPrepare draw_prepare
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupType * type
ListBaseT< wmGizmo > gizmos
wmGizmoPropertyFnSet value_set_fn
wmGizmoPropertyFnGet value_get_fn
struct blender::wmGizmoProperty::@216011055122204070127377170176223170047224321165 custom_func
float matrix_basis[4][4]
float matrix_offset[4][4]
wmGizmoGroup * parent_gzgroup
Vector< wmGizmoOpElem, 4 > op_data
conversion and adaptation of different datablocks to a common struct.
#define GIZMO_AXIS_LINE_WIDTH
#define MAN_AXIS_RANGE_SCALE_START
#define MAN_AXIS_RANGE_ROT_END
#define MAN_TRANS_C
#define MAN_SCALE_Z
#define MAN_ROT_X
#define MAN_SCALE_X
#define FOREACH_EDIT_OBJECT_BEGIN(ob_iter, use_mat_local)
#define GIZMO_NEW_DIAL(v)
#define MAN_ROT_Y
#define MAN_ROT_C
#define MAN_ITER_AXES_END
#define MAN_AXIS_RANGE_TRANS_END
#define MAN_TRANS_X
#define GIZMO_NEW_PRIM(v)
#define GIZMO_NEW_ARROW(v)
#define FOREACH_EDIT_OBJECT_END()
#define MAN_AXIS_RANGE_ROT_START
#define MAN_AXIS_SCALE_PLANE_SCALE
#define MAN_AXIS_RANGE_SCALE_END
#define MAN_ROT_Z
#define MAN_TRANS_Z
#define MAN_ITER_AXES_BEGIN(axis, axis_idx)
#define MAN_SCALE_C
#define MAN_SCALE_Y
#define MAN_TRANS_Y
#define MAN_AXIS_RANGE_TRANS_START
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)