Blender  V2.93
snap3d_gizmo.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
30 #include "BLI_listbase.h"
31 #include "BLI_math.h"
32 
33 #include "DNA_scene_types.h"
34 
35 #include "BKE_context.h"
36 #include "BKE_global.h"
37 #include "BKE_main.h"
38 
39 #include "GPU_immediate.h"
40 #include "GPU_state.h"
41 
42 #include "ED_gizmo_library.h"
43 #include "ED_screen.h"
45 #include "ED_view3d.h"
46 
47 #include "UI_resources.h" /* icons */
48 
49 #include "RNA_access.h"
50 #include "RNA_define.h"
51 
52 #include "DEG_depsgraph_query.h"
53 
54 #include "WM_api.h"
55 #include "WM_types.h"
56 
57 /* own includes */
58 #include "../gizmo_geometry.h"
59 #include "../gizmo_library_intern.h"
60 
61 typedef struct SnapGizmo3D {
63 
64  /* We could have other snap contexts, for now only support 3D view. */
66 
67  /* Copy of the parameters of the last event state in order to detect updates. */
68  struct {
69  int x;
70  int y;
71  short shift, ctrl, alt, oskey;
73 
74 #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
76  int snap_on;
78 #endif
79 
80  /* Setup. */
82  float *prevpoint;
83  float prevpoint_stack[3];
85 
86  /* Return values. */
87  short snap_elem;
88  float loc[3];
89  float nor[3];
90  int elem_index[3];
91 
93  bool is_enabled;
95 
96 /* Checks if the current event is different from the one captured in the last update. */
97 static bool eventstate_has_changed(SnapGizmo3D *snap_gizmo, const wmWindowManager *wm)
98 {
99  if (wm && wm->winactive) {
100  const wmEvent *event = wm->winactive->eventstate;
101  if ((event->x != snap_gizmo->last_eventstate.x) ||
102  (event->y != snap_gizmo->last_eventstate.y) ||
103  (event->ctrl != snap_gizmo->last_eventstate.ctrl) ||
104  (event->shift != snap_gizmo->last_eventstate.shift) ||
105  (event->alt != snap_gizmo->last_eventstate.alt) ||
106  (event->oskey != snap_gizmo->last_eventstate.oskey)) {
107  return true;
108  }
109  }
110  return false;
111 }
112 
113 /* Copies the current eventstate. */
114 static void eventstate_save(SnapGizmo3D *snap_gizmo, const wmWindowManager *wm)
115 {
116  if (wm && wm->winactive) {
117  const wmEvent *event = wm->winactive->eventstate;
118  snap_gizmo->last_eventstate.x = event->x;
119  snap_gizmo->last_eventstate.y = event->y;
120  snap_gizmo->last_eventstate.ctrl = event->ctrl;
121  snap_gizmo->last_eventstate.shift = event->shift;
122  snap_gizmo->last_eventstate.alt = event->alt;
123  snap_gizmo->last_eventstate.oskey = event->oskey;
124  }
125 }
126 
127 #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
128 static bool invert_snap(SnapGizmo3D *snap_gizmo, const wmWindowManager *wm)
129 {
130  if (!wm || !wm->winactive) {
131  return false;
132  }
133 
134  const wmEvent *event = wm->winactive->eventstate;
135  if ((event->ctrl == snap_gizmo->last_eventstate.ctrl) &&
136  (event->shift == snap_gizmo->last_eventstate.shift) &&
137  (event->alt == snap_gizmo->last_eventstate.alt) &&
138  (event->oskey == snap_gizmo->last_eventstate.oskey)) {
139  /* Nothing has changed. */
140  return snap_gizmo->invert_snap;
141  }
142 
143  const int snap_on = snap_gizmo->snap_on;
144 
145  wmKeyMap *keymap = WM_keymap_active(wm, snap_gizmo->keymap);
146  for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
147  if (kmi->flag & KMI_INACTIVE) {
148  continue;
149  }
150 
151  if (kmi->propvalue == snap_on) {
152  if ((ELEM(kmi->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY) && event->ctrl) ||
153  (ELEM(kmi->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY) && event->shift) ||
154  (ELEM(kmi->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY) && event->alt) ||
155  ((kmi->type == EVT_OSKEY) && event->oskey)) {
156  return true;
157  }
158  }
159  }
160  return false;
161 }
162 #endif
163 
164 static short snap_gizmo_snap_elements(SnapGizmo3D *snap_gizmo)
165 {
166  int snap_elements = snap_gizmo->snap_elem_force;
167 
168  wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(&snap_gizmo->gizmo, "snap_elements");
169  if (gz_prop->prop) {
170  snap_elements |= RNA_property_enum_get(&gz_prop->ptr, gz_prop->prop);
171  }
174  return (ushort)snap_elements;
175 }
176 
177 /* -------------------------------------------------------------------- */
182  const float loc_prev[3],
183  const float loc_curr[3],
184  const float normal[3],
185  const uchar color_line[4],
186  const uchar color_point[4],
187  const short snap_elem_type)
188 {
189  if (!loc_prev && !loc_curr) {
190  return;
191  }
192 
193  float view_inv[4][4];
194  copy_m4_m4(view_inv, rv3d->viewinv);
195 
196  /* The size of the circle is larger than the vertex size.
197  * This prevents a drawing overlaps the other. */
198  float radius = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE);
200 
202 
203  if (loc_curr) {
204  immUniformColor4ubv(color_point);
205  imm_drawcircball(loc_curr, ED_view3d_pixel_size(rv3d, loc_curr) * radius, view_inv, pos);
206 
207  /* draw normal if needed */
208  if (normal) {
210  immVertex3fv(pos, loc_curr);
211  immVertex3f(pos, loc_curr[0] + normal[0], loc_curr[1] + normal[1], loc_curr[2] + normal[2]);
212  immEnd();
213  }
214  }
215 
216  if (loc_prev) {
217  /* Draw an "X" indicating where the previous snap point is.
218  * This is useful for indicating perpendicular snap. */
219 
220  /* v1, v2, v3 and v4 indicate the coordinates of the ends of the "X". */
221  float vx[3], vy[3], v1[3], v2[3], v3[3], v4[4];
222 
223  /* Multiply by 0.75f so that the final size of the "X" is close to that of
224  * the circle.
225  * (A closer value is 0.7071f, but we don't need to be exact here). */
226  float x_size = 0.75f * radius * ED_view3d_pixel_size(rv3d, loc_prev);
227 
228  mul_v3_v3fl(vx, view_inv[0], x_size);
229  mul_v3_v3fl(vy, view_inv[1], x_size);
230 
231  add_v3_v3v3(v1, vx, vy);
232  sub_v3_v3v3(v2, vx, vy);
233  negate_v3_v3(v3, v1);
234  negate_v3_v3(v4, v2);
235 
236  add_v3_v3(v1, loc_prev);
237  add_v3_v3(v2, loc_prev);
238  add_v3_v3(v3, loc_prev);
239  add_v3_v3(v4, loc_prev);
240 
241  immUniformColor4ubv(color_line);
243  immVertex3fv(pos, v3);
244  immVertex3fv(pos, v1);
245  immVertex3fv(pos, v4);
246  immVertex3fv(pos, v2);
247  immEnd();
248 
249  if (loc_curr && (snap_elem_type & SCE_SNAP_MODE_EDGE_PERPENDICULAR)) {
250  /* Dashed line. */
252 
254  float viewport_size[4];
255  GPU_viewport_size_get_f(viewport_size);
256  immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
257  immUniform1f("dash_width", 6.0f * U.pixelsize);
258  immUniform1f("dash_factor", 1.0f / 4.0f);
259  immUniformColor4ubv(color_line);
260 
262  immVertex3fv(pos, loc_prev);
263  immVertex3fv(pos, loc_curr);
264  immEnd();
265  }
266  }
267 
269 }
270 
272  const ARegion *region,
273  const View3D *v3d,
274  wmGizmo *gz)
275 {
276  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
277  if (snap_gizmo->snap_context_v3d == NULL) {
279  scene, 0, region, v3d);
280  }
281  return snap_gizmo->snap_context_v3d;
282 }
283 
285 {
286  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
287  snap_gizmo->flag |= flag;
288 }
289 
291 {
292  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
293  snap_gizmo->flag &= ~flag;
294 }
295 
297 {
298  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
299  return (snap_gizmo->flag & flag) != 0;
300 }
301 
303 {
304 #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
305  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
306  return snap_gizmo->invert_snap;
307 #else
308  return false;
309 #endif
310 }
311 
313 {
314  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
315  return snap_gizmo->is_enabled;
316 }
317 
319  struct Depsgraph *depsgraph,
320  const ARegion *region,
321  const View3D *v3d,
322  const wmWindowManager *wm,
323  const float mval_fl[2])
324 {
325  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
326  snap_gizmo->is_enabled = false;
327 
329 
330 #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
331  if ((snap_gizmo->flag & ED_SNAPGIZMO_TOGGLE_ALWAYS_TRUE) == 0) {
332  bool invert_snap_toggle = invert_snap(snap_gizmo, wm);
333  if (invert_snap_toggle != snap_gizmo->invert_snap) {
334  snap_gizmo->invert_snap = invert_snap_toggle;
335 
336  /* Status has changed, be sure to save before early return. */
337  eventstate_save(snap_gizmo, wm);
338  }
339 
340  const ToolSettings *ts = scene->toolsettings;
341  if (invert_snap_toggle != !(ts->snap_flag & SCE_SNAP)) {
342  snap_gizmo->snap_elem = 0;
343  return 0;
344  }
345  }
346 #endif
347  eventstate_save(snap_gizmo, wm);
348 
349  snap_gizmo->is_enabled = true;
350 
351  float co[3], no[3];
352  short snap_elem = 0;
353  int snap_elem_index[3] = {-1, -1, -1};
354  int index = -1;
355 
356  ushort snap_elements = snap_gizmo_snap_elements(snap_gizmo);
357 
358  if (snap_elements) {
359  float prev_co[3] = {0.0f};
360  if (snap_gizmo->prevpoint) {
361  copy_v3_v3(prev_co, snap_gizmo->prevpoint);
362  }
363  else {
364  snap_elements &= ~SCE_SNAP_MODE_EDGE_PERPENDICULAR;
365  }
366 
367  float dist_px = 12.0f * U.pixelsize;
368 
371  depsgraph,
372  snap_elements,
373  &(const struct SnapObjectParams){
374  .snap_select = SNAP_ALL,
375  .use_object_edit_cage = true,
376  .use_occlusion_test = true,
377  },
378  mval_fl,
379  prev_co,
380  &dist_px,
381  co,
382  no,
383  &index,
384  NULL,
385  NULL);
386  }
387 
388  if (snap_elem == 0) {
389  RegionView3D *rv3d = region->regiondata;
390  ED_view3d_win_to_3d(v3d, region, rv3d->ofs, mval_fl, co);
391  zero_v3(no);
392  }
393  else if (snap_elem == SCE_SNAP_MODE_VERTEX) {
394  snap_elem_index[0] = index;
395  }
396  else if (snap_elem &
398  snap_elem_index[1] = index;
399  }
400  else if (snap_elem == SCE_SNAP_MODE_FACE) {
401  snap_elem_index[2] = index;
402  }
403 
404  snap_gizmo->snap_elem = snap_elem;
405  copy_v3_v3(snap_gizmo->loc, co);
406  copy_v3_v3(snap_gizmo->nor, no);
407  copy_v3_v3_int(snap_gizmo->elem_index, snap_elem_index);
408 
409  return snap_elem;
410 }
411 
413  wmGizmo *gz, float r_loc[3], float r_nor[3], int r_elem_index[3], int *r_snap_elem)
414 {
415  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
416  BLI_assert(snap_gizmo->is_enabled);
417  if (r_loc) {
418  copy_v3_v3(r_loc, snap_gizmo->loc);
419  }
420  if (r_nor) {
421  copy_v3_v3(r_nor, snap_gizmo->nor);
422  }
423  if (r_elem_index) {
424  copy_v3_v3_int(r_elem_index, snap_gizmo->elem_index);
425  }
426  if (r_snap_elem) {
427  *r_snap_elem = snap_gizmo->snap_elem;
428  }
429 }
430 
433 /* -------------------------------------------------------------------- */
437 /* Based on 'rna_GizmoProperties_find_operator'. */
439 {
440  IDProperty *properties = ptr->data;
441  for (bScreen *screen = G_MAIN->screens.first; screen; screen = screen->id.next) {
442  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
443  if (area->spacetype != SPACE_VIEW3D) {
444  continue;
445  }
446  LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
447  if (region->regiontype == RGN_TYPE_WINDOW && region->gizmo_map) {
448  wmGizmoMap *gzmap = region->gizmo_map;
450  LISTBASE_FOREACH (wmGizmo *, gz, &gzgroup->gizmos) {
451  if (gz->properties == properties) {
452  return (SnapGizmo3D *)gz;
453  }
454  }
455  }
456  }
457  }
458  }
459  }
460  return NULL;
461 }
462 
464  struct PropertyRNA *UNUSED(prop))
465 {
467  if (snap_gizmo) {
468  return snap_gizmo->snap_elem_force;
469  }
470  return 0;
471 }
472 
474  struct PropertyRNA *UNUSED(prop),
475  int value)
476 {
478  if (snap_gizmo) {
479  snap_gizmo->snap_elem_force = (short)value;
480  }
481 }
482 
484  struct PropertyRNA *UNUSED(prop),
485  float *values)
486 {
488  if (snap_gizmo) {
489  copy_v3_v3(values, snap_gizmo->prevpoint_stack);
490  }
491 }
492 
494  struct PropertyRNA *UNUSED(prop),
495  const float *values)
496 {
498  if (snap_gizmo) {
499  if (values) {
500  copy_v3_v3(snap_gizmo->prevpoint_stack, values);
501  snap_gizmo->prevpoint = snap_gizmo->prevpoint_stack;
502  }
503  else {
504  snap_gizmo->prevpoint = NULL;
505  }
506  }
507 }
508 
510  struct PropertyRNA *UNUSED(prop),
511  float *values)
512 {
514  if (snap_gizmo) {
515  copy_v3_v3(values, snap_gizmo->loc);
516  }
517 }
518 
520  struct PropertyRNA *UNUSED(prop),
521  const float *values)
522 {
524  if (snap_gizmo) {
525  copy_v3_v3(snap_gizmo->loc, values);
526  }
527 }
528 
530  struct PropertyRNA *UNUSED(prop),
531  float *values)
532 {
534  if (snap_gizmo) {
535  copy_v3_v3(values, snap_gizmo->nor);
536  }
537 }
538 
540  struct PropertyRNA *UNUSED(prop),
541  int *values)
542 {
544  if (snap_gizmo) {
545  copy_v3_v3_int(values, snap_gizmo->elem_index);
546  }
547 }
548 
551 /* -------------------------------------------------------------------- */
555 static void snap_gizmo_setup(wmGizmo *gz)
556 {
557  gz->flag |= WM_GIZMO_NO_TOOLTIP;
558 
559 #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
560  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
562  "Generic Gizmo Tweak Modal Map");
563  RNA_enum_value_from_id(snap_gizmo->keymap->modal_items, "SNAP_ON", &snap_gizmo->snap_on);
564 #endif
565 }
566 
567 static void snap_gizmo_draw(const bContext *C, wmGizmo *gz)
568 {
569  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
570  if (snap_gizmo->snap_elem == 0) {
571  return;
572  }
573 
575  if (eventstate_has_changed(snap_gizmo, wm)) {
576  /* The eventstate has changed but the snap has not been updated.
577  * This means that the current position is no longer valid. */
578  snap_gizmo->snap_elem = 0;
579  return;
580  }
581 
583  if (rv3d->rflag & RV3D_NAVIGATING) {
584  /* Don't draw the gizmo while navigating. It can be distracting. */
585  snap_gizmo->snap_elem = 0;
586  return;
587  }
588 
589  uchar color_line[4], color_point[4];
590  UI_GetThemeColor3ubv(TH_TRANSFORM, color_line);
591  color_line[3] = 128;
592 
593  rgba_float_to_uchar(color_point, gz->color);
594 
595  GPU_line_smooth(false);
596 
597  GPU_line_width(1.0f);
598 
599  const float *prev_point = snap_gizmo_snap_elements(snap_gizmo) &
601  snap_gizmo->prevpoint :
602  NULL;
603 
605  rv3d, prev_point, snap_gizmo->loc, NULL, color_line, color_point, snap_gizmo->snap_elem);
606 }
607 
608 static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2])
609 {
610  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
612  ARegion *region = CTX_wm_region(C);
613 
614  /* FIXME: this hack is to ignore drag events, otherwise drag events
615  * cause momentary snap gizmo re-positioning at the drag-start location, see: T87511. */
616  if (wm && wm->winactive) {
617  const wmEvent *event = wm->winactive->eventstate;
618  int mval_compare[2] = {event->x - region->winrct.xmin, event->y - region->winrct.ymin};
619  if (!equals_v2v2_int(mval_compare, mval)) {
620  return snap_gizmo->snap_elem ? 0 : -1;
621  }
622  }
623 
624  if (!eventstate_has_changed(snap_gizmo, wm)) {
625  /* Performance, do not update. */
626  return snap_gizmo->snap_elem ? 0 : -1;
627  }
628 
629  View3D *v3d = CTX_wm_view3d(C);
630  const float mval_fl[2] = {UNPACK2(mval)};
632  gz, CTX_data_ensure_evaluated_depsgraph(C), region, v3d, wm, mval_fl);
633 
634  if (snap_elem) {
636  return 0;
637  }
638 
639  return -1;
640 }
641 
643  wmGizmo *UNUSED(gz),
644  const wmEvent *UNUSED(event),
645  eWM_GizmoFlagTweak UNUSED(tweak_flag))
646 {
647  return OPERATOR_RUNNING_MODAL;
648 }
649 
651  wmGizmo *UNUSED(gz),
652  const wmEvent *UNUSED(event))
653 {
654  return OPERATOR_RUNNING_MODAL;
655 }
656 
657 static void snap_gizmo_free(wmGizmo *gz)
658 {
659  SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz;
660  if (snap_gizmo->snap_context_v3d) {
662  snap_gizmo->snap_context_v3d = NULL;
663  }
664 }
665 
666 static void GIZMO_GT_snap_3d(wmGizmoType *gzt)
667 {
668  /* identifiers */
669  gzt->idname = "GIZMO_GT_snap_3d";
670 
671  /* api callbacks */
672  gzt->setup = snap_gizmo_setup;
673  gzt->draw = snap_gizmo_draw;
675  gzt->modal = snap_gizmo_modal;
676  gzt->invoke = snap_gizmo_invoke;
677  gzt->free = snap_gizmo_free;
678 
679  gzt->struct_size = sizeof(SnapGizmo3D);
680 
682  {
683  /* Get Snap Element Items enum. */
684  bool free;
685  PointerRNA toolsettings_ptr;
686  RNA_pointer_create(NULL, &RNA_ToolSettings, NULL, &toolsettings_ptr);
687  PropertyRNA *prop = RNA_struct_find_property(&toolsettings_ptr, "snap_elements");
689  NULL, &toolsettings_ptr, prop, &rna_enum_snap_element_items, NULL, &free);
690 
691  BLI_assert(free == false);
692  }
693 
694  /* Setup. */
695  PropertyRNA *prop;
696  prop = RNA_def_enum_flag(gzt->srna,
697  "snap_elements_force",
700  "Snap Elements",
701  "");
702 
706  NULL);
707 
708  prop = RNA_def_float_array(gzt->srna,
709  "prev_point",
710  3,
711  NULL,
712  FLT_MIN,
713  FLT_MAX,
714  "Previous Point",
715  "Point that defines the location of the perpendicular snap",
716  FLT_MIN,
717  FLT_MAX);
718 
721 
722  /* Returns. */
723  prop = RNA_def_float_translation(gzt->srna,
724  "location",
725  3,
726  NULL,
727  FLT_MIN,
728  FLT_MAX,
729  "Location",
730  "Snap Point Location",
731  FLT_MIN,
732  FLT_MAX);
733 
736 
737  prop = RNA_def_float_vector_xyz(gzt->srna,
738  "normal",
739  3,
740  NULL,
741  FLT_MIN,
742  FLT_MAX,
743  "Normal",
744  "Snap Point Normal",
745  FLT_MIN,
746  FLT_MAX);
747 
749 
750  prop = RNA_def_int_vector(gzt->srna,
751  "snap_elem_index",
752  3,
753  NULL,
754  INT_MIN,
755  INT_MAX,
756  "Snap Element",
757  "Array index of face, edge and vert snapped",
758  INT_MIN,
759  INT_MAX);
760 
763 
764  /* Read/Write. */
765  WM_gizmotype_target_property_def(gzt, "snap_elements", PROP_ENUM, 1);
766 }
767 
769 {
771 }
772 
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
void * CTX_wm_region_data(const bContext *C)
Definition: context.c:730
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
#define G_MAIN
Definition: BKE_global.h:232
#define BLI_assert(a)
Definition: BLI_assert.h:58
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:116
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
Definition: math_color.c:427
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void zero_v3(float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE bool equals_v2v2_int(const int v1[2], const int v2[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3(float r[3], const float a[3])
unsigned char uchar
Definition: BLI_sys_types.h:86
unsigned int uint
Definition: BLI_sys_types.h:83
unsigned short ushort
Definition: BLI_sys_types.h:84
#define UNPACK2(a)
#define UNUSED(x)
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
#define SCE_SNAP
#define SCE_SNAP_MODE_FACE
#define SCE_SNAP_MODE_EDGE_PERPENDICULAR
#define SCE_SNAP_MODE_EDGE_MIDPOINT
#define SCE_SNAP_MODE_VERTEX
#define SCE_SNAP_MODE_EDGE
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
#define RV3D_NAVIGATING
@ OPERATOR_RUNNING_MODAL
eSnapGizmo
@ ED_SNAPGIZMO_TOGGLE_ALWAYS_TRUE
void ED_region_tag_redraw_editor_overlays(struct ARegion *region)
Definition: area.c:706
SnapObjectContext * ED_transform_snap_object_context_create_view3d(struct Scene *scene, int flag, const struct ARegion *region, const struct View3D *v3d)
short ED_transform_snap_object_project_view3d_ex(struct SnapObjectContext *sctx, struct Depsgraph *depsgraph, const unsigned short snap_to, const struct SnapObjectParams *params, const float mval[2], const float prev_co[3], float *dist_px, float r_loc[3], float r_no[3], int *r_index, struct Object **r_ob, float r_obmat[4][4])
void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx)
float ED_view3d_pixel_size(const struct RegionView3D *rv3d, const float co[3])
void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned int pos)
Definition: drawobject.c:90
void ED_view3d_win_to_3d(const struct View3D *v3d, const struct ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
void immUniformColor4ubv(const unsigned char rgba[4])
void immUniform2f(const char *name, float x, float y)
void immUnbindProgram(void)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immVertex3f(uint attr_id, float x, float y, float z)
void immUniform1f(const char *name, float x)
GPUVertFormat * immVertexFormat(void)
void immVertex3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
void immEnd(void)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:36
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
Definition: GPU_shader.h:366
@ GPU_SHADER_3D_UNIFORM_COLOR
Definition: GPU_shader.h:200
void GPU_line_width(float width)
Definition: gpu_state.cc:173
void GPU_line_smooth(bool enable)
Definition: gpu_state.cc:85
void GPU_viewport_size_get_f(float coords[4])
Definition: gpu_state.cc:279
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
StructRNA RNA_ToolSettings
@ PROP_ENUM
Definition: RNA_types.h:77
#define C
Definition: RandGen.cpp:39
@ TH_TRANSFORM
Definition: UI_resources.h:92
@ TH_VERTEX_SIZE
Definition: UI_resources.h:97
void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
Definition: resources.c:1350
float UI_GetThemeValuef(int colorid)
Definition: resources.c:1164
eWM_GizmoFlagTweak
Gizmo tweak flag. Bitflag passed to gizmo while tweaking.
@ WM_GIZMO_NO_TOOLTIP
ATTR_WARN_UNUSED_RESULT const BMVert * v2
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
const Depsgraph * depsgraph
uint pos
IconTextureDrawCall normal
static void area(int d1, int d2, int e1, int e2, float weights[2])
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
Definition: rna_access.c:6474
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
Definition: rna_access.c:1657
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3795
PropertyRNA * RNA_def_float_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:4065
void RNA_def_property_enum_funcs_runtime(PropertyRNA *prop, EnumPropertyGetFunc getfunc, EnumPropertySetFunc setfunc, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3285
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3611
PropertyRNA * RNA_def_float_translation(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3975
void RNA_def_property_int_array_funcs_runtime(PropertyRNA *prop, IntArrayPropertyGetFunc getfunc, IntArrayPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc)
Definition: rna_define.c:3126
void RNA_def_property_float_array_funcs_runtime(PropertyRNA *prop, FloatArrayPropertyGetFunc getfunc, FloatArrayPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc)
Definition: rna_define.c:3224
PropertyRNA * RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3883
const EnumPropertyItem rna_enum_snap_element_items[]
Definition: rna_scene.c:158
short ED_gizmotypes_snap_3d_update(wmGizmo *gz, struct Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const wmWindowManager *wm, const float mval_fl[2])
Definition: snap3d_gizmo.c:318
bool ED_gizmotypes_snap_3d_flag_test(struct wmGizmo *gz, eSnapGizmo flag)
Definition: snap3d_gizmo.c:296
static void gizmo_snap_rna_snap_elements_force_set_fn(struct PointerRNA *ptr, struct PropertyRNA *UNUSED(prop), int value)
Definition: snap3d_gizmo.c:473
static struct SnapGizmo3D * gizmo_snap_rna_find_operator(PointerRNA *ptr)
Definition: snap3d_gizmo.c:438
static void gizmo_snap_rna_normal_get_fn(struct PointerRNA *ptr, struct PropertyRNA *UNUSED(prop), float *values)
Definition: snap3d_gizmo.c:529
bool ED_gizmotypes_snap_3d_invert_snap_get(struct wmGizmo *gz)
Definition: snap3d_gizmo.c:302
void ED_gizmotypes_snap_3d_draw_util(RegionView3D *rv3d, const float loc_prev[3], const float loc_curr[3], const float normal[3], const uchar color_line[4], const uchar color_point[4], const short snap_elem_type)
Definition: snap3d_gizmo.c:181
static int gizmo_snap_rna_snap_elements_force_get_fn(struct PointerRNA *ptr, struct PropertyRNA *UNUSED(prop))
Definition: snap3d_gizmo.c:463
static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2])
Definition: snap3d_gizmo.c:608
void ED_gizmotypes_snap_3d_data_get(wmGizmo *gz, float r_loc[3], float r_nor[3], int r_elem_index[3], int *r_snap_elem)
Definition: snap3d_gizmo.c:412
static int snap_gizmo_invoke(bContext *UNUSED(C), wmGizmo *UNUSED(gz), const wmEvent *UNUSED(event))
Definition: snap3d_gizmo.c:650
static int snap_gizmo_modal(bContext *UNUSED(C), wmGizmo *UNUSED(gz), const wmEvent *UNUSED(event), eWM_GizmoFlagTweak UNUSED(tweak_flag))
Definition: snap3d_gizmo.c:642
void ED_gizmotypes_snap_3d_flag_clear(struct wmGizmo *gz, eSnapGizmo flag)
Definition: snap3d_gizmo.c:290
static void snap_gizmo_free(wmGizmo *gz)
Definition: snap3d_gizmo.c:657
struct SnapGizmo3D SnapGizmo3D
static void gizmo_snap_rna_prevpoint_set_fn(struct PointerRNA *ptr, struct PropertyRNA *UNUSED(prop), const float *values)
Definition: snap3d_gizmo.c:493
void ED_gizmotypes_snap_3d(void)
Definition: snap3d_gizmo.c:768
static void eventstate_save(SnapGizmo3D *snap_gizmo, const wmWindowManager *wm)
Definition: snap3d_gizmo.c:114
bool ED_gizmotypes_snap_3d_is_enabled(wmGizmo *gz)
Definition: snap3d_gizmo.c:312
static bool eventstate_has_changed(SnapGizmo3D *snap_gizmo, const wmWindowManager *wm)
Definition: snap3d_gizmo.c:97
static void snap_gizmo_setup(wmGizmo *gz)
Definition: snap3d_gizmo.c:555
SnapObjectContext * ED_gizmotypes_snap_3d_context_ensure(Scene *scene, const ARegion *region, const View3D *v3d, wmGizmo *gz)
Definition: snap3d_gizmo.c:271
static void gizmo_snap_rna_location_set_fn(struct PointerRNA *ptr, struct PropertyRNA *UNUSED(prop), const float *values)
Definition: snap3d_gizmo.c:519
static void gizmo_snap_rna_location_get_fn(struct PointerRNA *ptr, struct PropertyRNA *UNUSED(prop), float *values)
Definition: snap3d_gizmo.c:509
void ED_gizmotypes_snap_3d_flag_set(struct wmGizmo *gz, eSnapGizmo flag)
Definition: snap3d_gizmo.c:284
static short snap_gizmo_snap_elements(SnapGizmo3D *snap_gizmo)
Definition: snap3d_gizmo.c:164
static bool invert_snap(SnapGizmo3D *snap_gizmo, const wmWindowManager *wm)
Definition: snap3d_gizmo.c:128
static void gizmo_snap_rna_snap_elem_index_get_fn(struct PointerRNA *ptr, struct PropertyRNA *UNUSED(prop), int *values)
Definition: snap3d_gizmo.c:539
static void snap_gizmo_draw(const bContext *C, wmGizmo *gz)
Definition: snap3d_gizmo.c:567
static void gizmo_snap_rna_prevpoint_get_fn(struct PointerRNA *ptr, struct PropertyRNA *UNUSED(prop), float *values)
Definition: snap3d_gizmo.c:483
static void GIZMO_GT_snap_3d(wmGizmoType *gzt)
Definition: snap3d_gizmo.c:666
void * regiondata
void * first
Definition: DNA_listBase.h:47
void * data
Definition: RNA_types.h:52
float viewinv[4][4]
struct ToolSettings * toolsettings
int elem_index[3]
Definition: snap3d_gizmo.c:90
float * prevpoint
Definition: snap3d_gizmo.c:82
float prevpoint_stack[3]
Definition: snap3d_gizmo.c:83
float nor[3]
Definition: snap3d_gizmo.c:89
wmKeyMap * keymap
Definition: snap3d_gizmo.c:75
struct SnapGizmo3D::@325 last_eventstate
float loc[3]
Definition: snap3d_gizmo.c:88
wmGizmo gizmo
Definition: snap3d_gizmo.c:62
bool invert_snap
Definition: snap3d_gizmo.c:77
short snap_elem
Definition: snap3d_gizmo.c:87
short snap_elem_force
Definition: snap3d_gizmo.c:84
SnapObjectContext * snap_context_v3d
Definition: snap3d_gizmo.c:65
eSnapGizmo flag
Definition: snap3d_gizmo.c:81
bool is_enabled
Definition: snap3d_gizmo.c:93
int ymin
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int x
Definition: WM_types.h:581
struct wmKeyConfig * keyconf
struct wmGizmoGroupType * type
PropertyRNA * prop
wmGizmoFnDraw draw
wmGizmoFnModal modal
wmGizmoFnSetup setup
const char * idname
wmGizmoFnTestSelect test_select
struct StructRNA * srna
wmGizmoFnInvoke invoke
wmGizmoFnFree free
struct wmGizmoGroup * parent_gzgroup
float color[4]
eWM_GizmoFlag flag
const void * modal_items
struct wmWindow * winactive
struct wmEvent * eventstate
@ EVT_RIGHTCTRLKEY
@ EVT_OSKEY
@ EVT_LEFTCTRLKEY
@ EVT_RIGHTALTKEY
@ EVT_LEFTALTKEY
@ EVT_RIGHTSHIFTKEY
@ EVT_LEFTSHIFTKEY
PointerRNA * ptr
Definition: wm_files.c:3157
const ListBase * WM_gizmomap_group_list(wmGizmoMap *gzmap)
Definition: wm_gizmo_map.c:239
wmGizmoProperty * WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
void WM_gizmotype_target_property_def(wmGizmoType *gzt, const char *idname, int data_type, int array_length)
void WM_gizmotype_append(void(*gtfunc)(struct wmGizmoType *))
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition: wm_keymap.c:914
wmKeyMap * WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap)
Definition: wm_keymap.c:1895