Blender V5.3
wm_xr_operators.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_kdopbvh.hh"
14#include "BLI_listbase.hh"
15#include "BLI_math_matrix_c.hh"
19#include "BLI_math_vector.hh"
20#include "BLI_math_vector_c.hh"
22#include "BLI_time.hh"
23
24#include "BLT_translation.hh"
25
26#include "BKE_context.hh"
27#include "BKE_curves.hh"
28#include "BKE_global.hh"
29#include "BKE_idprop.hh"
30#include "BKE_main.hh"
31#include "BKE_screen.hh"
32
33#include "DEG_depsgraph.hh"
34
35#include "ED_screen.hh"
36#include "ED_space_api.hh"
38#include "ED_view3d.hh"
39
40#include "GHOST_Types.hh"
41
42#include "GPU_immediate.hh"
43#include "GPU_state.hh"
44
45#include "GPU_batch_presets.hh"
46#include "GPU_matrix.hh"
47
48#include "MEM_guardedalloc.h"
49
50#include "RNA_access.hh"
51#include "RNA_define.hh"
52
53#include "WM_api.hh"
54#include "WM_types.hh"
55
56#include "wm_xr_intern.hh"
57
58namespace blender {
59
60/* -------------------------------------------------------------------- */
63
64/* `op->poll`. */
70
71static bool wm_xr_operator_test_event(const wmOperator *op, const wmEvent *event)
72{
73 if (event->type != EVT_XR_ACTION) {
74 return false;
75 }
76
77 BLI_assert(event->custom == EVT_DATA_XR);
78 BLI_assert(event->customdata);
79
80 wmXrActionData *actiondata = static_cast<wmXrActionData *>(event->customdata);
81 return (actiondata->ot == op->type &&
82 IDP_EqualsProperties(actiondata->op_properties, op->properties));
83}
84
86
87/* -------------------------------------------------------------------- */
92
93static void wm_xr_session_update_screen(Main *bmain, const wmXrData *xr_data)
94{
95 const bool session_exists = WM_xr_session_exists(xr_data);
96
97 for (bScreen *screen = bmain->screens.first(); screen;
98 screen = static_cast<bScreen *>(screen->id.next))
99 {
100 for (ScrArea &area : screen->areabase) {
101 for (SpaceLink &slink : area.spacedata) {
102 if (slink.spacetype == SPACE_VIEW3D) {
103 View3D *v3d = (View3D *)&slink;
104
105 if (v3d->flag & V3D_XR_SESSION_MIRROR) {
106 ED_view3d_xr_mirror_update(&area, v3d, session_exists);
107 }
108
109 if (session_exists) {
110 wmWindowManager *wm = bmain->wm.first();
111 const Scene *scene = WM_windows_scene_get_from_screen(wm, screen);
112
113 ED_view3d_xr_shading_update(wm, v3d, scene);
114 }
115 /* Ensure no 3D View is tagged as session root. */
116 else {
118 }
119 }
120 }
121 }
122 }
123
125}
126
128{
129 /* Just use G_MAIN here, storing main isn't reliable enough on file read or exit. */
131}
132
134{
135 Main *bmain = CTX_data_main(C);
137 View3D *v3d = CTX_wm_view3d(C);
138
139 /* Lazily-create XR context - tries to dynamic-link to the runtime,
140 * reading `active_runtime.json`. */
141 if (wm_xr_init(C) == false) {
142 return OPERATOR_CANCELLED;
143 }
144
147 wm_xr_session_update_screen(bmain, &wm->xr);
148
150
151 return OPERATOR_FINISHED;
152}
153
155{
156 /* Identifiers. */
157 ot->name = "Toggle VR Session";
158 ot->idname = "WM_OT_xr_session_toggle";
159 ot->description =
160 "Open a view for use with virtual reality headsets, or close it if already "
161 "opened";
162
163 /* Callbacks. */
166
167 /* XXX INTERNAL just to hide it from the search menu by default, an Add-on will expose it in the
168 * UI instead. Not meant as a permanent solution. */
169 ot->flag = OPTYPE_INTERNAL;
170}
171
173
174/* -------------------------------------------------------------------- */
177
184
186{
187 BLI_assert(op->customdata == nullptr);
188
190}
191
193{
194 XrGrabData *data = static_cast<XrGrabData *>(op->customdata);
195 MEM_SAFE_DELETE(data);
196 op->customdata = nullptr;
197}
198
199static void wm_xr_grab_update(wmOperator *op, const wmXrActionData *actiondata)
200{
201 XrGrabData *data = static_cast<XrGrabData *>(op->customdata);
202
203 quat_to_mat4(data->mat_prev, actiondata->controller_rot);
204 copy_v3_v3(data->mat_prev[3], actiondata->controller_loc);
205
206 if (actiondata->bimanual) {
207 quat_to_mat4(data->mat_other_prev, actiondata->controller_rot_other);
208 copy_v3_v3(data->mat_other_prev[3], actiondata->controller_loc_other);
209 data->bimanual_prev = true;
210 }
211 else {
212 data->bimanual_prev = false;
213 }
214}
215
216static void orient_mat_z_normalized(float R[4][4], const float z_axis[3])
217{
218 const float scale = len_v3(R[0]);
219 float x_axis[3], y_axis[3];
220
221 cross_v3_v3v3(y_axis, z_axis, R[0]);
222 normalize_v3(y_axis);
223 mul_v3_v3fl(R[1], y_axis, scale);
224
225 cross_v3_v3v3(x_axis, R[1], z_axis);
226 normalize_v3(x_axis);
227 mul_v3_v3fl(R[0], x_axis, scale);
228
229 mul_v3_v3fl(R[2], z_axis, scale);
230}
231
232static void wm_xr_navlocks_apply(const float nav_mat[4][4],
233 const float nav_inv[4][4],
234 bool loc_lock,
235 bool locz_lock,
236 bool rotz_lock,
237 float r_prev[4][4],
238 float r_curr[4][4])
239{
240 /* Locked in base pose coordinates. */
241 float prev_base[4][4], curr_base[4][4];
242
243 mul_m4_m4m4(prev_base, nav_inv, r_prev);
244 mul_m4_m4m4(curr_base, nav_inv, r_curr);
245
246 if (rotz_lock) {
247 const float z_axis[3] = {0.0f, 0.0f, 1.0f};
248 orient_mat_z_normalized(prev_base, z_axis);
249 orient_mat_z_normalized(curr_base, z_axis);
250 }
251
252 if (loc_lock) {
253 copy_v3_v3(curr_base[3], prev_base[3]);
254 }
255 else if (locz_lock) {
256 curr_base[3][2] = prev_base[3][2];
257 }
258
259 mul_m4_m4m4(r_prev, nav_mat, prev_base);
260 mul_m4_m4m4(r_curr, nav_mat, curr_base);
261}
262
272static void wm_xr_grab_compute(const wmXrActionData *actiondata,
273 const XrGrabData *data,
274 const float nav_mat[4][4],
275 const float nav_inv[4][4],
276 bool reverse,
277 float r_delta[4][4])
278{
279 const bool nav_lock = (nav_mat && nav_inv);
280 float prev[4][4], curr[4][4];
281
282 if (!data->rot_lock) {
283 copy_m4_m4(prev, data->mat_prev);
284 zero_v3(prev[3]);
285 quat_to_mat4(curr, actiondata->controller_rot);
286 }
287 else {
288 unit_m4(prev);
289 unit_m4(curr);
290 }
291
292 if (!data->loc_lock || nav_lock) {
293 copy_v3_v3(prev[3], data->mat_prev[3]);
294 copy_v3_v3(curr[3], actiondata->controller_loc);
295 }
296
297 if (nav_lock) {
299 nav_mat, nav_inv, data->loc_lock, data->locz_lock, data->rotz_lock, prev, curr);
300 }
301
302 if (reverse) {
303 invert_m4(curr);
304 mul_m4_m4m4(r_delta, prev, curr);
305 }
306 else {
307 invert_m4(prev);
308 mul_m4_m4m4(r_delta, curr, prev);
309 }
310}
311
324static void wm_xr_grab_compute_bimanual(const wmXrActionData *actiondata,
325 const XrGrabData *data,
326 const float nav_mat[4][4],
327 const float nav_inv[4][4],
328 bool reverse,
329 float r_delta[4][4])
330{
331 const bool nav_lock = (nav_mat && nav_inv);
332 float prev[4][4], curr[4][4];
333 unit_m4(prev);
334 unit_m4(curr);
335
336 if (!data->rot_lock) {
337 /* Rotation. */
338 float x_axis_prev[3], x_axis_curr[3], y_axis_prev[3], y_axis_curr[3], z_axis_prev[3],
339 z_axis_curr[3];
340 float m0[3][3], m1[3][3];
341 quat_to_mat3(m0, actiondata->controller_rot);
342 quat_to_mat3(m1, actiondata->controller_rot_other);
343
344 /* X-axis is the base line between the two controllers. */
345 sub_v3_v3v3(x_axis_prev, data->mat_prev[3], data->mat_other_prev[3]);
346 sub_v3_v3v3(x_axis_curr, actiondata->controller_loc, actiondata->controller_loc_other);
347 /* Y-axis is the average of the controllers' y-axes. */
348 add_v3_v3v3(y_axis_prev, data->mat_prev[1], data->mat_other_prev[1]);
349 mul_v3_fl(y_axis_prev, 0.5f);
350 add_v3_v3v3(y_axis_curr, m0[1], m1[1]);
351 mul_v3_fl(y_axis_curr, 0.5f);
352 /* Z-axis is the cross product of the two. */
353 cross_v3_v3v3(z_axis_prev, x_axis_prev, y_axis_prev);
354 cross_v3_v3v3(z_axis_curr, x_axis_curr, y_axis_curr);
355 /* Fix the y-axis to be orthogonal. */
356 cross_v3_v3v3(y_axis_prev, z_axis_prev, x_axis_prev);
357 cross_v3_v3v3(y_axis_curr, z_axis_curr, x_axis_curr);
358 /* Normalize. */
359 normalize_v3_v3(prev[0], x_axis_prev);
360 normalize_v3_v3(prev[1], y_axis_prev);
361 normalize_v3_v3(prev[2], z_axis_prev);
362 normalize_v3_v3(curr[0], x_axis_curr);
363 normalize_v3_v3(curr[1], y_axis_curr);
364 normalize_v3_v3(curr[2], z_axis_curr);
365 }
366
367 if (!data->loc_lock || nav_lock) {
368 /* Translation: translation of the averaged controller locations. */
369 add_v3_v3v3(prev[3], data->mat_prev[3], data->mat_other_prev[3]);
370 mul_v3_fl(prev[3], 0.5f);
371 add_v3_v3v3(curr[3], actiondata->controller_loc, actiondata->controller_loc_other);
372 mul_v3_fl(curr[3], 0.5f);
373 }
374
375 if (!data->scale_lock) {
376 /* Scaling: distance between controllers. */
377 float scale, v[3];
378
379 sub_v3_v3v3(v, data->mat_prev[3], data->mat_other_prev[3]);
380 scale = len_v3(v);
381 mul_v3_fl(prev[0], scale);
382 mul_v3_fl(prev[1], scale);
383 mul_v3_fl(prev[2], scale);
384
385 sub_v3_v3v3(v, actiondata->controller_loc, actiondata->controller_loc_other);
386 scale = len_v3(v);
387 mul_v3_fl(curr[0], scale);
388 mul_v3_fl(curr[1], scale);
389 mul_v3_fl(curr[2], scale);
390 }
391
392 if (nav_lock) {
394 nav_mat, nav_inv, data->loc_lock, data->locz_lock, data->rotz_lock, prev, curr);
395 }
396
397 if (reverse) {
398 invert_m4(curr);
399 mul_m4_m4m4(r_delta, prev, curr);
400 }
401 else {
402 invert_m4(prev);
403 mul_m4_m4m4(r_delta, curr, prev);
404 }
405}
406
408
409/* -------------------------------------------------------------------- */
414
416 wmOperator *op,
417 const wmEvent *event)
418{
419 if (!wm_xr_operator_test_event(op, event)) {
421 }
422
425 }
426
427 const wmXrActionData *actiondata = static_cast<const wmXrActionData *>(event->customdata);
428
429 wm_xr_grab_init(op);
430 wm_xr_grab_update(op, actiondata);
431
433
435}
436
441
442static bool wm_xr_navigation_grab_can_do_bimanual(const wmXrActionData *actiondata,
443 const XrGrabData *data)
444{
445 /* Returns true if: 1) Bimanual interaction is currently occurring (i.e. inputs on both
446 * controllers are pressed) and 2) bimanual interaction occurred on the last update. This second
447 * part is needed to avoid "jumpy" navigation changes when transitioning from one-handed to
448 * two-handed interaction (see #wm_xr_grab_compute/compute_bimanual() for how navigation deltas
449 * are calculated). */
450 return (actiondata->bimanual && data->bimanual_prev);
451}
452
453static bool wm_xr_navigation_grab_is_bimanual_ending(const wmXrActionData *actiondata,
454 const XrGrabData *data)
455{
456 return (!actiondata->bimanual && data->bimanual_prev);
457}
458
459static bool wm_xr_navigation_grab_is_locked(const XrGrabData *data, const bool bimanual)
460{
461 if (bimanual) {
462 return data->loc_lock && data->rot_lock && data->scale_lock;
463 }
464 /* Ignore scale lock, as one-handed interaction cannot change navigation scale. */
465 return data->loc_lock && data->rot_lock;
466}
467
469 const wmXrActionData *actiondata,
470 const XrGrabData *data,
471 bool bimanual)
472{
473 GHOST_XrPose nav_pose;
474 float nav_scale;
475 float nav_mat[4][4], nav_inv[4][4], delta[4][4], out[4][4];
476
477 const bool need_navinv = (data->loc_lock || data->locz_lock || data->rotz_lock);
478
479 WM_xr_session_state_nav_location_get(xr, nav_pose.position);
480 WM_xr_session_state_nav_rotation_get(xr, nav_pose.orientation_quat);
481 WM_xr_session_state_nav_scale_get(xr, &nav_scale);
482
483 wm_xr_pose_scale_to_mat(&nav_pose, nav_scale, nav_mat);
484 if (need_navinv) {
485 wm_xr_pose_scale_to_imat(&nav_pose, nav_scale, nav_inv);
486 }
487
488 if (bimanual) {
490 data,
491 need_navinv ? nav_mat : nullptr,
492 need_navinv ? nav_inv : nullptr,
493 true,
494 delta);
495 }
496 else {
497 wm_xr_grab_compute(actiondata,
498 data,
499 need_navinv ? nav_mat : nullptr,
500 need_navinv ? nav_inv : nullptr,
501 true,
502 delta);
503 }
504
505 mul_m4_m4m4(out, delta, nav_mat);
506
507 /* Limit scale to reasonable values. */
508 nav_scale = len_v3(out[0]);
509
510 if (!(nav_scale < xr->session_settings.clip_start || nav_scale > xr->session_settings.clip_end))
511 {
513 if (!data->rot_lock) {
514 mat4_to_quat(nav_pose.orientation_quat, out);
515 normalize_qt(nav_pose.orientation_quat);
516 WM_xr_session_state_nav_rotation_set(xr, nav_pose.orientation_quat);
517 }
518 if (!data->scale_lock && bimanual) {
520 }
521 }
522}
523
524static void wm_xr_navigation_grab_bimanual_state_update(const wmXrActionData *actiondata,
526{
527 if (actiondata->bimanual) {
528 if (!data->bimanual_prev) {
529 quat_to_mat4(data->mat_prev, actiondata->controller_rot);
530 copy_v3_v3(data->mat_prev[3], actiondata->controller_loc);
531 quat_to_mat4(data->mat_other_prev, actiondata->controller_rot_other);
532 copy_v3_v3(data->mat_other_prev[3], actiondata->controller_loc_other);
533 }
534 data->bimanual_prev = true;
535 }
536 else {
537 if (data->bimanual_prev) {
538 quat_to_mat4(data->mat_prev, actiondata->controller_rot);
539 copy_v3_v3(data->mat_prev[3], actiondata->controller_loc);
540 }
541 data->bimanual_prev = false;
542 }
543}
544
546{
548}
549
551 wmOperator *op,
552 const wmEvent *event)
553{
554 if (!wm_xr_operator_test_event(op, event)) {
556 }
557
558 const wmXrActionData *actiondata = static_cast<const wmXrActionData *>(event->customdata);
559 XrGrabData *data = static_cast<XrGrabData *>(op->customdata);
561 wmXrData *xr = &wm->xr;
562
564
565 const bool do_bimanual = wm_xr_navigation_grab_can_do_bimanual(actiondata, data);
566
567 data->loc_lock = RNA_boolean_get(op->ptr, "lock_location");
568 data->locz_lock = RNA_boolean_get(op->ptr, "lock_location_z");
569 data->rot_lock = RNA_boolean_get(op->ptr, "lock_rotation");
570 data->rotz_lock = RNA_boolean_get(op->ptr, "lock_rotation_z");
571 data->scale_lock = RNA_boolean_get(op->ptr, "lock_scale");
572
573 /* Check if navigation is locked. */
574 if (!wm_xr_navigation_grab_is_locked(data, do_bimanual)) {
575 /* Prevent unwanted snapping (i.e. "jumpy" navigation changes when transitioning from
576 * two-handed to one-handed interaction) at the end of a bimanual interaction. */
578 wm_xr_navigation_grab_apply(xr, actiondata, data, do_bimanual);
579 }
580 }
581
583
584 /* NOTE: #KM_PRESS and #KM_RELEASE are the only two values supported by XR events during event
585 * dispatching (see #wm_xr_session_action_states_interpret()). For modal XR operators, modal
586 * handling starts when an input is "pressed" (action state exceeds the action threshold) and
587 * ends when the input is "released" (state falls below the threshold). */
588 switch (event->val) {
589 case KM_PRESS:
591 case KM_RELEASE:
593 return OPERATOR_FINISHED;
594 default:
597 return OPERATOR_CANCELLED;
598 }
599}
600
602{
603 /* Identifiers. */
604 ot->name = "XR Navigation Grab";
605 ot->idname = "WM_OT_xr_navigation_grab";
606 ot->description = "Navigate the VR scene by grabbing with controllers";
607
608 /* Callbacks. */
614
615 /* Properties. */
617 ot->srna, "lock_location", false, "Lock Location", "Prevent changes to viewer location");
619 ot->srna, "lock_location_z", false, "Lock Elevation", "Prevent changes to viewer elevation");
621 ot->srna, "lock_rotation", false, "Lock Rotation", "Prevent changes to viewer rotation");
623 "lock_rotation_z",
624 false,
625 "Lock Up Orientation",
626 "Prevent changes to viewer up orientation");
627 RNA_def_boolean(ot->srna, "lock_scale", false, "Lock Scale", "Prevent changes to viewer scale");
628}
629
631
632/* -------------------------------------------------------------------- */
638
654
655struct XrFlyData {
656 float viewer_rot[4];
657 double time_prev;
658
659 /* Only used for snap turn, where the action should be executed only once. */
661};
662
663static void wm_xr_fly_init(wmOperator *op, const wmXrData *xr)
664{
665 BLI_assert(op->customdata == nullptr);
666
668 op->customdata = data;
669
671 data->time_prev = BLI_time_now_seconds();
672}
673
675{
676 XrFlyData *data = static_cast<XrFlyData *>(op->customdata);
677 MEM_SAFE_DELETE(data);
678 op->customdata = nullptr;
679}
680
682 float speed,
683 const float ref_quat[4],
684 const float nav_mat[4][4],
685 bool locz_lock,
686 float r_delta[4][4])
687{
688 float ref_axes[3][3];
689 quat_to_mat3(ref_axes, ref_quat);
690
691 unit_m4(r_delta);
692
693 switch (mode) {
694 /* Navigation space reference. */
695 case XR_FLY_FORWARD:
696 madd_v3_v3fl(r_delta[3], ref_axes[1], speed);
697 return;
698 case XR_FLY_BACK:
699 madd_v3_v3fl(r_delta[3], ref_axes[1], -speed);
700 return;
701 case XR_FLY_LEFT:
702 madd_v3_v3fl(r_delta[3], ref_axes[0], -speed);
703 return;
704 case XR_FLY_RIGHT:
705 madd_v3_v3fl(r_delta[3], ref_axes[0], speed);
706 return;
707 case XR_FLY_UP:
708 case XR_FLY_DOWN:
709 if (!locz_lock) {
710 madd_v3_v3fl(r_delta[3], ref_axes[2], (mode == XR_FLY_UP) ? speed : -speed);
711 }
712 return;
713 /* Viewer/controller space reference. */
716 negate_v3_v3(r_delta[3], ref_axes[2]);
717 break;
719 copy_v3_v3(r_delta[3], ref_axes[2]);
720 break;
722 negate_v3_v3(r_delta[3], ref_axes[0]);
723 break;
725 copy_v3_v3(r_delta[3], ref_axes[0]);
726 break;
727 /* Unused. */
728 case XR_FLY_TURNLEFT:
729 case XR_FLY_TURNRIGHT:
731 return;
732 }
733
734 if (locz_lock) {
735 /* Lock elevation in navigation space. */
736 float z_axis[3], projected[3];
737
738 normalize_v3_v3(z_axis, nav_mat[2]);
739 project_v3_v3v3_normalized(projected, r_delta[3], z_axis);
740 sub_v3_v3(r_delta[3], projected);
741
742 normalize_v3(r_delta[3]);
743 }
744
745 mul_v3_fl(r_delta[3], speed);
746}
747
749 float speed,
750 const float viewer_mat[4][4],
751 const float nav_mat[4][4],
752 const float nav_inv[4][4],
753 float r_delta[4][4])
754{
756
757 float z_axis[3], m[3][3], prev[4][4], curr[4][4];
758
759 /* Turn around Z-axis in navigation space. */
760 normalize_v3_v3(z_axis, nav_mat[2]);
761 axis_angle_normalized_to_mat3(m, z_axis, (mode == XR_FLY_TURNLEFT) ? speed : -speed);
762 copy_m4_m3(r_delta, m);
763
764 copy_m4_m4(prev, viewer_mat);
765 mul_m4_m4m4(curr, r_delta, viewer_mat);
766
767 /* Lock location in base pose space. */
768 wm_xr_navlocks_apply(nav_mat, nav_inv, true, false, false, prev, curr);
769
770 invert_m4(prev);
771 mul_m4_m4m4(r_delta, curr, prev);
772}
773
775 const float nav_rotation[4],
776 float r_rotation[4])
777{
778 /* Apply nav rotation to base pose Z-rotation. */
779 float base_eul[3], base_quatz[4];
780 quat_to_eul(base_eul, xr->runtime->session_state.prev_base_pose.orientation_quat);
781 axis_angle_to_quat_single(base_quatz, 'Z', base_eul[2]);
782 mul_qt_qtqt(r_rotation, nav_rotation, base_quatz);
783}
784
786 wmOperator *op,
787 const wmEvent *event)
788{
789 if (!wm_xr_operator_test_event(op, event)) {
791 }
792
794 wmXrData *xr = &wm->xr;
795
797 const bool swap_hands = xr->runtime->session_state.swap_hands;
798 const eXrFlyMode mode = eXrFlyMode(RNA_enum_get(op->ptr, swap_hands ? "alt_mode" : "mode"));
799 const eXrViewfinderHand viewfinder_hand = eXrViewfinderHand(
801
802 const bool clashes_with_viewfinder = (ELEM(mode, XR_FLY_VIEWER_LEFT, XR_FLY_VIEWER_RIGHT) &&
803 viewfinder_hand == XR_VIEWFINDER_HAND_LEFT) ||
805 viewfinder_hand == XR_VIEWFINDER_HAND_RIGHT);
806
807 if (clashes_with_viewfinder) {
809 }
810 }
811
812 wm_xr_fly_init(op, xr);
813
815
817}
818
823
825{
827}
828
830 wmOperator *op,
831 const wmEvent *event)
832{
833 if (!wm_xr_operator_test_event(op, event)) {
835 }
836
837 if (event->val == KM_RELEASE) {
839 return OPERATOR_FINISHED;
840 }
841
842 const wmXrActionData *actiondata = static_cast<const wmXrActionData *>(event->customdata);
843 XrFlyData *data = static_cast<XrFlyData *>(op->customdata);
845 wmXrData *xr = &wm->xr;
846 eXrFlyMode mode;
847 bool turn, snap_turn, invert_rotation, swap_hands, locz_lock, dir_lock, speed_frame_based;
848 bool speed_interp_cubic = false;
849 float speed, speed_max, speed_p0[2], speed_p1[2], button_state;
850 GHOST_XrPose nav_pose;
851 float nav_mat[4][4], delta[4][4], out[4][4];
852
853 const double time_now = BLI_time_now_seconds(), delta_time = time_now - data->time_prev;
854 data->time_prev = time_now;
855
856 swap_hands = xr->runtime->session_state.swap_hands;
857 mode = eXrFlyMode(RNA_enum_get(op->ptr, swap_hands ? "alt_mode" : "mode"));
859 snap_turn = U.xr_navigation.flag & USER_XR_NAV_SNAP_TURN;
860 invert_rotation = U.xr_navigation.flag & USER_XR_NAV_INVERT_ROTATION;
861
862 locz_lock = RNA_boolean_get(op->ptr, swap_hands ? "alt_lock_location_z" : "lock_location_z");
863 dir_lock = RNA_boolean_get(op->ptr, swap_hands ? "alt_lock_direction" : "lock_direction");
864
865 if (turn) {
866 speed_frame_based = false;
867
868 if (snap_turn) {
869 speed_max = U.xr_navigation.turn_amount;
870 speed = speed_max;
871 }
872 else {
873 speed_max = U.xr_navigation.turn_speed;
874 speed = speed_max * RNA_float_get(op->ptr, "turn_speed_factor");
875 }
876 }
877 else {
878 speed_frame_based = RNA_boolean_get(op->ptr, "speed_frame_based");
879 speed_max = xr->session_settings.fly_speed;
880 speed = speed_max * RNA_float_get(op->ptr, "fly_speed_factor");
881 }
882
883 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "speed_interpolation0");
884 if (prop && RNA_property_is_set(op->ptr, prop)) {
885 RNA_property_float_get_array(op->ptr, prop, speed_p0);
886 speed_interp_cubic = true;
887 }
888 else {
889 speed_p0[0] = speed_p0[1] = 0.0f;
890 }
891
892 prop = RNA_struct_find_property(op->ptr, "speed_interpolation1");
893 if (prop && RNA_property_is_set(op->ptr, prop)) {
894 RNA_property_float_get_array(op->ptr, prop, speed_p1);
895 speed_interp_cubic = true;
896 }
897 else {
898 speed_p1[0] = speed_p1[1] = 1.0f;
899 }
900
901 /* Ensure valid interpolation. */
902 if (speed_max < speed) {
903 speed_max = speed;
904 }
905
906 /* Interpolate between min/max speeds based on button state. */
907 switch (actiondata->type) {
908 case XR_BOOLEAN_INPUT:
909 button_state = 1.0f;
910 speed = speed_max;
911 break;
912 case XR_FLOAT_INPUT:
913 case XR_VECTOR2F_INPUT: {
914 button_state = (actiondata->type == XR_FLOAT_INPUT) ? fabsf(actiondata->state[0]) :
915 len_v2(actiondata->state);
916 float speed_t = (actiondata->float_threshold < 1.0f) ?
917 (button_state - actiondata->float_threshold) /
918 (1.0f - actiondata->float_threshold) :
919 1.0f;
920 if (speed_interp_cubic) {
921 float start[2], end[2], p[2];
922
923 start[0] = 0.0f;
924 start[1] = speed;
925 speed_p0[1] = speed + speed_p0[1] * (speed_max - speed);
926 speed_p1[1] = speed + speed_p1[1] * (speed_max - speed);
927 end[0] = 1.0f;
928 end[1] = speed_max;
929
930 interp_v2_v2v2v2v2_cubic(p, start, speed_p0, speed_p1, end, speed_t);
931 speed = p[1];
932 }
933 else {
934 speed += speed_t * (speed_max - speed);
935 }
936 break;
937 }
938 case XR_POSE_INPUT:
941 break;
942 }
943
944 WM_xr_session_state_nav_location_get(xr, nav_pose.position);
945 WM_xr_session_state_nav_rotation_get(xr, nav_pose.orientation_quat);
946 wm_xr_pose_to_mat(&nav_pose, nav_mat);
947
948 if (turn) {
949 if (dir_lock || (snap_turn && data->is_finished) ||
950 (snap_turn && button_state < RNA_float_get(op->ptr, "snap_turn_threshold")))
951 {
952 unit_m4(delta);
953 }
954 else {
955 if (!snap_turn) {
957 speed *= delta_time;
958 }
959 else {
960 data->is_finished = true;
961 }
962
963 if (invert_rotation) {
964 speed *= -1.0f;
965 }
966
967 GHOST_XrPose viewer_pose;
968 float viewer_mat[4][4], nav_inv[4][4];
969
970 WM_xr_session_state_viewer_pose_location_get(xr, viewer_pose.position);
971 WM_xr_session_state_viewer_pose_rotation_get(xr, viewer_pose.orientation_quat);
972 wm_xr_pose_to_mat(&viewer_pose, viewer_mat);
973 wm_xr_pose_to_imat(&nav_pose, nav_inv);
974
975 wm_xr_fly_compute_turn(mode, speed, viewer_mat, nav_mat, nav_inv, delta);
976 }
977 }
978 else {
979 float viewer_scale, ref_quat[4];
980
982
983 /* Adjust speed for base and navigation scale. */
984 WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
985 speed *= xr->session_settings.base_scale * viewer_scale;
986
987 if (!speed_frame_based) {
988 speed *= delta_time;
989 }
990
991 switch (mode) {
992 /* Move relative to navigation space. */
993 case XR_FLY_FORWARD:
994 case XR_FLY_BACK:
995 case XR_FLY_LEFT:
996 case XR_FLY_RIGHT:
997 case XR_FLY_UP:
998 case XR_FLY_DOWN:
999 wm_xr_basenav_rotation_calc(xr, nav_pose.orientation_quat, ref_quat);
1000 break;
1001 /* Move relative to viewer. */
1003 case XR_FLY_VIEWER_BACK:
1004 case XR_FLY_VIEWER_LEFT:
1006 if (dir_lock) {
1007 copy_qt_qt(ref_quat, data->viewer_rot);
1008 }
1009 else {
1011 }
1012 break;
1013 /* Move relative to controller. */
1015 copy_qt_qt(ref_quat, actiondata->controller_rot);
1016 break;
1017 /* Unused. */
1018 case XR_FLY_TURNLEFT:
1019 case XR_FLY_TURNRIGHT:
1021 break;
1022 }
1023
1024 wm_xr_fly_compute_move(mode, speed, ref_quat, nav_mat, locz_lock, delta);
1025 }
1026
1027 mul_m4_m4m4(out, delta, nav_mat);
1028
1030 if (turn) {
1031 mat4_to_quat(nav_pose.orientation_quat, out);
1032 WM_xr_session_state_nav_rotation_set(xr, nav_pose.orientation_quat);
1033 }
1034
1035 if (event->val == KM_PRESS) {
1037 }
1038
1039 /* XR events currently only support press and release. */
1041 wm_xr_fly_uninit(op);
1042 return OPERATOR_CANCELLED;
1043}
1044
1046{
1047 PropertyRNA *prop;
1048
1049 /* Identifiers. */
1050 ot->name = "XR Navigation Fly";
1051 ot->idname = "WM_OT_xr_navigation_fly";
1052 ot->description = "Move/turn relative to the VR viewer or controller";
1053
1054 /* Callbacks. */
1060
1061 /* Properties. */
1062 static const EnumPropertyItem fly_modes[] = {
1063 {XR_FLY_FORWARD, "FORWARD", 0, "Forward", "Move along navigation forward axis"},
1064 {XR_FLY_BACK, "BACK", 0, "Back", "Move along navigation back axis"},
1065 {XR_FLY_LEFT, "LEFT", 0, "Left", "Move along navigation left axis"},
1066 {XR_FLY_RIGHT, "RIGHT", 0, "Right", "Move along navigation right axis"},
1067 {XR_FLY_UP, "UP", 0, "Up", "Move along navigation up axis"},
1068 {XR_FLY_DOWN, "DOWN", 0, "Down", "Move along navigation down axis"},
1070 "TURNLEFT",
1071 0,
1072 "Turn Left",
1073 "Turn counter-clockwise around navigation up axis"},
1074 {XR_FLY_TURNRIGHT, "TURNRIGHT", 0, "Turn Right", "Turn clockwise around navigation up axis"},
1076 "VIEWER_FORWARD",
1077 0,
1078 "Viewer Forward",
1079 "Move along viewer's forward axis"},
1080 {XR_FLY_VIEWER_BACK, "VIEWER_BACK", 0, "Viewer Back", "Move along viewer's back axis"},
1081 {XR_FLY_VIEWER_LEFT, "VIEWER_LEFT", 0, "Viewer Left", "Move along viewer's left axis"},
1082 {XR_FLY_VIEWER_RIGHT, "VIEWER_RIGHT", 0, "Viewer Right", "Move along viewer's right axis"},
1084 "CONTROLLER_FORWARD",
1085 0,
1086 "Controller Forward",
1087 "Move along controller's forward axis"},
1088 {0, nullptr, 0, nullptr, nullptr},
1089 };
1090
1091 static const float default_speed_p0[2] = {0.0f, 0.0f};
1092 static const float default_speed_p1[2] = {1.0f, 1.0f};
1093
1094 prop = RNA_def_enum(ot->srna, "mode", fly_modes, XR_FLY_VIEWER_FORWARD, "Mode", "Fly mode");
1096
1097 RNA_def_float(ot->srna,
1098 "snap_turn_threshold",
1099 0.95f,
1100 0.0f,
1101 1.0f,
1102 "Snap Turn Threshold",
1103 "Input state threshold when using snap turn",
1104 0.0f,
1105 1.0f);
1107 ot->srna, "lock_location_z", false, "Lock Elevation", "Prevent changes to viewer elevation");
1109 "lock_direction",
1110 false,
1111 "Lock Direction",
1112 "Limit movement to viewer's initial direction");
1114 "speed_frame_based",
1115 false,
1116 "Frame Based Speed",
1117 "Apply fixed movement deltas every update");
1118 RNA_def_float(ot->srna,
1119 "turn_speed_factor",
1120 1.0 / 3.0f,
1121 0.0f,
1122 1.0f,
1123 "Turn Speed Factor",
1124 "Ratio between the min and max turn speed",
1125 0.0f,
1126 1.0f);
1127 RNA_def_float(ot->srna,
1128 "fly_speed_factor",
1129 1.0 / 3.0f,
1130 0.0f,
1131 1.0f,
1132 "Fly Speed Factor",
1133 "Ratio between the min and max fly speed",
1134 0.0f,
1135 1.0f);
1137 "speed_interpolation0",
1138 2,
1139 default_speed_p0,
1140 0.0f,
1141 1.0f,
1142 "Speed Interpolation 0",
1143 "First cubic spline control point between min/max speeds",
1144 0.0f,
1145 1.0f);
1147 "speed_interpolation1",
1148 2,
1149 default_speed_p1,
1150 0.0f,
1151 1.0f,
1152 "Speed Interpolation 1",
1153 "Second cubic spline control point between min/max speeds",
1154 0.0f,
1155 1.0f);
1156
1157 RNA_def_enum(ot->srna,
1158 "alt_mode",
1159 fly_modes,
1161 "Mode (Alt)",
1162 "Fly mode when hands are swapped");
1164 "alt_lock_location_z",
1165 false,
1166 "Lock Elevation (Alt)",
1167 "When hands are swapped, prevent changes to viewer elevation");
1169 "alt_lock_direction",
1170 false,
1171 "Lock Direction (Alt)",
1172 "When hands are swapped, limit movement to viewer's initial direction");
1173}
1174
1176
1177/* -------------------------------------------------------------------- */
1182
1184
1190
1206
1208{
1210 GPU_matrix_translate_3fv(data->arc_points[data->endpoint_idx]);
1211 GPU_matrix_scale_1f(data->teleportation_scale);
1212
1213 const float dest_width = data->destination_indicator_width;
1214
1215 if (data->ray_result == XR_TELEPORT_RAY_MISS) {
1216 /* Draw a simple sphere. */
1217 gpu::Batch *sphere_batch = GPU_batch_preset_sphere(2);
1219 GPU_batch_uniform_4fv(sphere_batch, "color", data->ray_color);
1220
1221 const float sphere_width = dest_width * 0.4f;
1222 GPU_matrix_scale_1f(sphere_width);
1223 GPU_batch_draw(sphere_batch);
1224 }
1225 else {
1226 /* Draw a destination ring. */
1228 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32_32);
1229
1231 immUniformColor4fv(data->ray_color);
1232
1233 const float ring_rad_exter = dest_width;
1234 const float ring_rad_inner = dest_width * 0.85f;
1235 const float circle_rad = dest_width * 0.65f;
1236
1237 const float top_height = dest_width * 0.2f;
1238 const float bottom_height = top_height * 0.4f;
1239 constexpr int resolution = 64;
1240
1241 /* Outer ring. */
1242 imm_draw_cylinder_fill_3d(pos, dest_width, dest_width, top_height, resolution, 1);
1244 pos, 0.0f, 0.0f, bottom_height, ring_rad_exter, ring_rad_inner, resolution, 0.0f, 360.0f);
1245
1246 /* Inner circle. */
1247 GPU_matrix_translate_3f(0.0f, 0.0f, bottom_height);
1248 imm_draw_circle_fill_3d(pos, 0.0f, 0.0f, circle_rad, resolution);
1249
1251 }
1252
1254}
1255
1257{
1258 /* Compute the Catmull-Rom spline, first get a span of the used arc control points. */
1259 const int num_control_points = data->endpoint_idx + 1;
1260 const Span<float3> arc_control_points = data->arc_points.as_span().take_front(
1261 num_control_points);
1262
1263 /* Calculate the number of evaluated points that interpolation is expected to produce. */
1264 constexpr int segment_samples = 8;
1266 num_control_points, false, segment_samples);
1267
1268 /* Evaluate the interpolated spline into a new array. */
1269 Array<float3> spline_points(spline_size);
1271 arc_control_points, false, segment_samples, spline_points.as_mutable_span());
1272
1273 float viewport[4];
1274 GPU_viewport_size_get_f(viewport);
1275 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32_32);
1276
1277 /* Draw the evaluated points. */
1279
1280 immUniformColor4fv(data->ray_color);
1281 immUniform2fv("viewportSize", &viewport[2]);
1282 immUniform1f("lineWidth", data->ray_line_width);
1283 immUniform1i("lineSmooth", true);
1284
1285 immBegin(GPU_PRIM_LINE_STRIP, spline_points.size());
1286 for (int64_t i = 0; i < spline_points.size(); i++) {
1287 immVertex3fv(pos, spline_points[i]);
1288 }
1289 immEnd();
1290
1292}
1293
1295 ARegion * /*region*/,
1296 void *customdata)
1297{
1300
1301 /* Draw the destination ring and computed arc spline. */
1302 const XrTeleportData *data = static_cast<const XrTeleportData *>(customdata);
1305
1308}
1309
1311{
1312 BLI_assert(op->customdata == nullptr);
1313
1314 op->customdata = MEM_new<XrTeleportData>(__func__);
1315
1317 if (!st) {
1318 return;
1319 }
1320
1322 if (!art) {
1323 return;
1324 }
1325
1326 XrTeleportData *data = static_cast<XrTeleportData *>(op->customdata);
1327 data->draw_handle = ED_region_draw_cb_activate(
1329}
1330
1332{
1333 if (!op->customdata) {
1334 return;
1335 }
1336
1337 XrTeleportData *data = static_cast<XrTeleportData *>(op->customdata);
1338
1340 if (st) {
1342 if (art) {
1343 ED_region_draw_cb_exit(art, data->draw_handle);
1344 }
1345 }
1346
1347 MEM_SAFE_DELETE(data);
1348 op->customdata = nullptr;
1349}
1350
1352 const wmXrData *xr,
1354 const wmXrActionData *actiondata)
1355{
1358
1359 const math::Quaternion controller_quat(actiondata->controller_rot);
1360 data->init_direction = transform_point(controller_quat, {0.0f, 0.0f, -1.0f});
1361 data->init_location = actiondata->controller_loc;
1362
1363 data->ray_line_width = RNA_float_get(op->ptr, "ray_line_width");
1364 data->destination_indicator_width = RNA_float_get(op->ptr, "destination_indicator_width");
1365
1366 float viewer_scale;
1367 WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
1368 data->teleportation_scale = viewer_scale;
1369}
1370
1371static void wm_xr_navigation_teleport_raycast(Depsgraph *depsgraph,
1372 const float origin[3],
1373 const float direction[3],
1374 float *ray_dist,
1375 bool selectable_only,
1376 float r_location[3],
1377 float r_normal[3],
1378 int *r_index,
1379 const Object **r_ob,
1380 float r_obmat[4][4])
1381{
1382 /* Uses same raycast method as Scene.ray_cast(). */
1384
1386 params.snap_target_select = (selectable_only ? SCE_SNAP_TARGET_ONLY_SELECTABLE :
1389 depsgraph,
1390 nullptr,
1391 &params,
1392 origin,
1393 direction,
1394 ray_dist,
1395 r_location,
1396 r_normal,
1397 r_index,
1398 r_ob,
1399 r_obmat);
1400
1402}
1403
1405{
1406 const float gravity = 9.81f;
1407 const float time_step = RNA_float_get(op->ptr, "range");
1408 const float velocity = RNA_float_get(op->ptr, "force");
1409
1410 data->arc_points[0] = data->init_location;
1411 const float3 direction = data->init_direction;
1412
1413 for (int i = 1; i < g_xr_teleportation_arc_num_control_points; ++i) {
1414 const float t = i * time_step;
1415
1416 const float3 velocity_offset = direction * (velocity * t);
1417 const float3 gravity_offset = float3(0, 0, -0.5f * gravity * t * t);
1418
1419 const float3 offset = (velocity_offset + gravity_offset) * data->teleportation_scale;
1420
1421 data->arc_points[i] = data->init_location + offset;
1422 }
1423}
1424
1426{
1427 /* Check if the hit surface is a wall. */
1428 const float3 up_vector = {0.0f, 0.0f, 1.0f};
1429 const float min_ground_dot = M_SQRT3 / 2.0f; /* Cosine of 30 degrees. */
1430
1431 if (math::dot(hit_normal, up_vector) < min_ground_dot) {
1432 return true;
1433 }
1434
1435 return false;
1436}
1437
1438static bool wm_xr_navigation_teleport_arc_clip_to_ground(Array<float3> &points, int &end_point_idx)
1439{
1440 /* Truncate the arc to the ground plane (Z=0). */
1441 for (int i = 1; i < g_xr_teleportation_arc_num_control_points; ++i) {
1442 const float3 &startpoint = points[i - 1];
1443 const float3 &endpoint = points[i];
1444
1445 /* Iterate until we find the point where we cross the ground plane downward. */
1446 if (!(startpoint.z > 0 && endpoint.z < 0)) {
1447 continue;
1448 }
1449
1450 /* Adjust the last point to intersect with the ground plane. */
1451 const float alpha = math::safe_divide(startpoint.z, (startpoint.z - endpoint.z));
1452 points[i] = math::interpolate(startpoint, endpoint, alpha);
1453
1454 /* Terminate the arc at the adjusted point. */
1455 end_point_idx = i;
1456
1457 return true;
1458 }
1459
1460 return false;
1461}
1462
1464 wmOperator *op,
1466{
1467 const bool selectable_only = RNA_boolean_get(op->ptr, "selectable_only");
1468
1469 /* Ray-cast along the pre-computed arc to find the first collision point with a scene object. */
1470 for (int i = 1; i < g_xr_teleportation_arc_num_control_points; ++i) {
1471 const float3 segment_start = data->arc_points[i - 1];
1472 const float3 segment_end = data->arc_points[i];
1473
1474 const float3 segment_direction = math::normalize(segment_end - segment_start);
1475 const float segment_length = math::distance(segment_start, segment_end);
1476
1477 /* Extend the ray in both directions to avoid ray-cast precision issues when ray-casting
1478 * close to surfaces or with short segment lengths. */
1479 const float ray_precision_margin = segment_length * 0.25f;
1480 float3 segment_origin = segment_start;
1481 if (i > 1) {
1482 segment_origin += segment_direction * -ray_precision_margin;
1483 }
1484
1485 float segment_ray_length = segment_length + (ray_precision_margin * 2.0f);
1486
1487 float3 hit_location;
1488 float3 hit_normal;
1489 const Object *ob = nullptr;
1491 segment_origin,
1492 segment_direction,
1493 &segment_ray_length,
1494 selectable_only,
1495 hit_location,
1496 hit_normal,
1497 nullptr,
1498 &ob,
1499 nullptr);
1500
1501 if (ob) {
1502 /* Object hit, truncate the arc at this point. */
1503 data->arc_points[i] = hit_location;
1504 data->endpoint_idx = i;
1505
1506 /* Ensure normal face the correct direction. */
1507 if (math::dot(segment_direction, hit_normal) > 0) {
1508 hit_normal *= -1.0f;
1509 }
1510
1511 /* Disallow wall hits. */
1512 if (wm_xr_navigation_teleport_is_wall_hit(hit_normal)) {
1513 return XR_TELEPORT_RAY_MISS;
1514 }
1515
1516 return XR_TELEPORT_RAY_HIT;
1517 }
1518 }
1519
1520 /* Fallback to world ground intersection if no objects were hit. */
1521 if (wm_xr_navigation_teleport_arc_clip_to_ground(data->arc_points, data->endpoint_idx)) {
1523 }
1524
1525 /* Complete miss. */
1527 return XR_TELEPORT_RAY_MISS;
1528}
1529
1532{
1533 float viewer_scale;
1534 WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
1535
1536 const float xr_head_height = xr->runtime->session_state.prev_local_pose.position[1];
1537 const float view_height_offset = xr_head_height * viewer_scale;
1538
1539 const float3 ray_destination = data->arc_points[data->endpoint_idx];
1540 const float3 view_destination = ray_destination + float3(0.0f, 0.0f, view_height_offset);
1541
1542 float3 nav_location, viewer_location;
1543 WM_xr_session_state_nav_location_get(xr, nav_location);
1545
1546 const float3 nav_destination = nav_location + (view_destination - viewer_location);
1547
1548 return nav_destination;
1549}
1550
1552 wmOperator *op,
1553 const wmXrData *xr,
1555 float3 &r_nav_destination)
1556{
1557 /* Generate the initial parabolic arc. */
1559
1560 /* Find intersection between the arc and scene objects using raycast. */
1562
1563 /* Calculate the teleportation destination in navigation space. */
1564 r_nav_destination = wm_xr_navigation_teleport_get_nav_destination(xr, data);
1565
1566 return result;
1567}
1568
1570 wmOperator *op,
1571 const wmEvent *event)
1572{
1573 if (!wm_xr_operator_test_event(op, event)) {
1574 return OPERATOR_PASS_THROUGH;
1575 }
1576
1578 return OPERATOR_PASS_THROUGH;
1579 }
1580
1582
1583 const wmOperatorStatus retval = op->type->modal(C, op, event);
1584 OPERATOR_RETVAL_CHECK(retval);
1585
1586 if (retval & OPERATOR_RUNNING_MODAL) {
1588 }
1589
1590 return retval;
1591}
1592
1597
1602
1604 wmOperator *op,
1605 const wmEvent *event)
1606{
1607 if (!wm_xr_operator_test_event(op, event)) {
1608 return OPERATOR_PASS_THROUGH;
1609 }
1610
1611 const wmXrActionData *actiondata = static_cast<const wmXrActionData *>(event->customdata);
1612
1613 wmXrData *xr = &CTX_wm_manager(C)->xr;
1614 XrTeleportData *data = static_cast<XrTeleportData *>(op->customdata);
1615
1616 wm_xr_navigation_teleport_data_update(op, xr, data, actiondata);
1617
1618 /* Teleport using an arc, computing both the final destination and the visual curve. */
1619 float3 nav_destination = {};
1620 data->ray_result = wm_xr_navigation_teleport_main(C, op, xr, data, nav_destination);
1621
1622 /* Update ray color. */
1623 switch (data->ray_result) {
1625 RNA_float_get_array(op->ptr, "miss_color", data->ray_color);
1626 break;
1628 RNA_float_get_array(op->ptr, "hit_color", data->ray_color);
1629 break;
1631 RNA_float_get_array(op->ptr, "fallback_color", data->ray_color);
1632 break;
1633 default:
1635 break;
1636 }
1637
1638 /* Apply teleportation on release. */
1639 switch (event->val) {
1640 case KM_PRESS:
1642 case KM_RELEASE: {
1643 if (data->ray_result != XR_TELEPORT_RAY_MISS) {
1644 WM_xr_session_state_nav_location_set(xr, nav_destination);
1645 }
1646
1648 return OPERATOR_FINISHED;
1649 }
1650 default:
1651 /* XR events currently only support press and release. */
1654 return OPERATOR_CANCELLED;
1655 }
1656}
1657
1659{
1660 /* Identifiers. */
1661 ot->name = "XR Navigation Teleport";
1662 ot->idname = "WM_OT_xr_navigation_teleport";
1663 ot->description = "Set VR viewer location to controller raycast hit location";
1664
1665 /* Callbacks. */
1671
1672 /* Properties. */
1674 "selectable_only",
1675 true,
1676 "Selectable Only",
1677 "Only allow selectable objects to influence raycast result");
1678
1679 /* Teleportation arc parabola parameters. */
1680 RNA_def_float(ot->srna,
1681 "force",
1682 8.5f,
1683 0.0f,
1684 FLT_MAX,
1685 "Force",
1686 "Velocity force controlling the teleportation arc parabola in m/s",
1687 0.0f,
1688 100.0f);
1689 RNA_def_float(ot->srna,
1690 "range",
1691 0.15f,
1692 0.0f,
1693 FLT_MAX,
1694 "Range",
1695 "Time step range controlling the teleportation arc parabola",
1696 0.0f,
1697 1.0f);
1698
1699 /* Visual parameters. */
1700 RNA_def_float(ot->srna,
1701 "ray_line_width",
1702 6.0f,
1703 0.0f,
1704 FLT_MAX,
1705 "Ray Line Width",
1706 "Visual width of the teleportation ray line",
1707 0.5f,
1708 10.0f);
1709 RNA_def_float(ot->srna,
1710 "destination_indicator_width",
1711 0.18f,
1712 0.0f,
1713 FLT_MAX,
1714 "Destination Indicator Width",
1715 "Visual width of the hit destination indicator",
1716 0.0f,
1717 5.0f);
1718
1719 /* Ray colors. */
1720 static const float default_teleport_ray_hit_color[4] = {0.4f, 0.6f, 0.9f, 1.0f};
1721 static const float default_teleport_ray_miss_color[4] = {1.0f, 0.35f, 0.35f, 1.0f};
1722 static const float default_teleport_ray_fallback_color[4] = {0.5f, 0.45f, 0.8f, 1.0f};
1724 "hit_color",
1725 4,
1726 default_teleport_ray_hit_color,
1727 0.0f,
1728 1.0f,
1729 "Hit Color",
1730 "Color of raycast when it succeeds",
1731 0.0f,
1732 1.0f);
1734 "miss_color",
1735 4,
1736 default_teleport_ray_miss_color,
1737 0.0f,
1738 1.0f,
1739 "Miss Color",
1740 "Color of raycast when it misses",
1741 0.0f,
1742 1.0f);
1744 "fallback_color",
1745 4,
1746 default_teleport_ray_fallback_color,
1747 0.0f,
1748 1.0f,
1749 "Fallback Color",
1750 "Color of raycast when a fallback case succeeds",
1751 0.0f,
1752 1.0f);
1753}
1754
1756
1757/* -------------------------------------------------------------------- */
1762
1764{
1766 wmXrData *xr = &wm->xr;
1767 bool reset_loc, reset_rot, reset_scale;
1768
1769 reset_loc = RNA_boolean_get(op->ptr, "location");
1770 reset_rot = RNA_boolean_get(op->ptr, "rotation");
1771 reset_scale = RNA_boolean_get(op->ptr, "scale");
1772
1773 if (reset_loc) {
1774 float loc[3];
1775 if (!reset_scale) {
1776 float nav_rotation[4], viewer_scale;
1777
1778 WM_xr_session_state_nav_rotation_get(xr, nav_rotation);
1779 WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
1780
1781 /* Adjust location based on scale. */
1782 mul_v3_v3fl(loc, xr->runtime->session_state.prev_base_pose.position, viewer_scale);
1783 sub_v3_v3(loc, xr->runtime->session_state.prev_base_pose.position);
1784 mul_qt_v3(nav_rotation, loc);
1785 negate_v3(loc);
1786 }
1787 else {
1788 zero_v3(loc);
1789 }
1791 }
1792
1793 if (reset_rot) {
1794 float rot[4];
1795 unit_qt(rot);
1797 }
1798
1799 if (reset_scale) {
1800 if (!reset_loc) {
1801 float nav_location[3], nav_rotation[4], viewer_scale;
1802 float nav_axes[3][3], v[3];
1803
1804 WM_xr_session_state_nav_location_get(xr, nav_location);
1805 WM_xr_session_state_nav_rotation_get(xr, nav_rotation);
1806 WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
1807
1808 /* Offset any location changes when changing scale. */
1809 mul_v3_v3fl(v, xr->runtime->session_state.prev_base_pose.position, viewer_scale);
1811 mul_qt_v3(nav_rotation, v);
1812 add_v3_v3(nav_location, v);
1813
1814 /* Reset elevation to base pose value. */
1815 quat_to_mat3(nav_axes, nav_rotation);
1816 project_v3_v3v3_normalized(v, nav_location, nav_axes[2]);
1817 sub_v3_v3(nav_location, v);
1818
1819 WM_xr_session_state_nav_location_set(xr, nav_location);
1820 }
1822 }
1823
1824 return OPERATOR_FINISHED;
1825}
1826
1828 wmOperator *op,
1829 const wmEvent *event)
1830{
1832 return OPERATOR_CANCELLED;
1833 }
1834
1835 return wm_xr_navigation_reset_exec(C, op);
1836}
1837
1839{
1840 /* Identifiers. */
1841 ot->name = "XR Navigation Reset";
1842 ot->idname = "WM_OT_xr_navigation_reset";
1843 ot->description = "Reset VR navigation deltas relative to session base pose";
1844
1845 /* Callbacks. */
1849
1850 /* Properties. */
1851 RNA_def_boolean(ot->srna, "location", true, "Location", "Reset location deltas");
1852 RNA_def_boolean(ot->srna, "rotation", true, "Rotation", "Reset rotation deltas");
1853 RNA_def_boolean(ot->srna, "scale", true, "Scale", "Reset scale deltas");
1854}
1855
1857
1858/* -------------------------------------------------------------------- */
1863
1865 wmOperator *op,
1866 const wmEvent *event)
1867{
1868 if (!wm_xr_operator_test_event(op, event)) {
1869 return OPERATOR_PASS_THROUGH;
1870 }
1871
1873
1875 wmXrData *xr = &wm->xr;
1876
1877 xr->runtime->session_state.swap_hands = true;
1878
1880}
1881
1886
1888 wmOperator *op,
1889 const wmEvent *event)
1890{
1891 if (!wm_xr_operator_test_event(op, event)) {
1892 return OPERATOR_PASS_THROUGH;
1893 }
1894
1896 wmXrData *xr = &wm->xr;
1897
1898 switch (event->val) {
1899 case KM_PRESS:
1901 case KM_RELEASE:
1902 xr->runtime->session_state.swap_hands = false;
1903 return OPERATOR_FINISHED;
1904 default:
1906 return OPERATOR_CANCELLED;
1907 }
1908}
1909
1911{
1912 /* Identifiers. */
1913 ot->name = "XR Navigation Swap Hands";
1914 ot->idname = "WM_OT_xr_navigation_swap_hands";
1915 ot->description = "Swap VR navigation controls between left / right controllers";
1916
1917 /* Callbacks. */
1922}
1923
1925
1926/* -------------------------------------------------------------------- */
1929
1939
1941
1942} // namespace blender
Low-level operations for curves.
#define G_MAIN
#define M_SQRT3
Platform independent time functions.
#define BLT_I18NCONTEXT_NAVIGATION
#define OPERATOR_RETVAL_CHECK(ret)
#define REGION_DRAW_POST_VIEW
#define GPU_batch_uniform_4fv(batch, name, val)
Definition GPU_batch.hh:275
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_WM
Definition WM_types.hh:387
#define ND_XR_DATA_CHANGED
Definition WM_types.hh:434
#define BLI_assert_unreachable()
#define ELEM(...)
int64_t size() const
Definition BLI_array.hh:267
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:259
#define rot(x, k)
#define FLT_MAX
void invert_rotation(float4 rotation, float4 &result)
float3x3 scale(float3x3 mat, float2 scale)
float3 transform_point(float3x3 mat, float3 point)
#define R
int calculate_evaluated_num(int points_num, bool cyclic, int resolution)
void interpolate_to_evaluated(GSpan src, bool cyclic, int resolution, GMutableSpan dst)
bool snap_object_project_ray_ex(SnapObjectContext *sctx, Depsgraph *depsgraph, const View3D *v3d, const SnapObjectParams *params, const float ray_start[3], const float ray_normal[3], float *ray_depth, float r_loc[3], float r_no[3], int *r_index, const Object **r_ob, float r_obmat[4][4])
void snap_object_context_destroy(SnapObjectContext *sctx)
SnapObjectContext * snap_object_context_create()
QuaternionBase< float > Quaternion
T safe_divide(const T &a, const T &b)
T distance(const T &a, const T &b)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T interpolate(const T &a, const T &b, const FactorT &t)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
UserDef U
Definition blender.cc:58
static void wm_xr_navlocks_apply(const float nav_mat[4][4], const float nav_inv[4][4], bool loc_lock, bool locz_lock, bool rotz_lock, float r_prev[4][4], float r_curr[4][4])
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ XR_POSE_INPUT
@ XR_BOOLEAN_INPUT
@ XR_FLOAT_INPUT
@ XR_VIBRATION_OUTPUT
@ XR_VECTOR2F_INPUT
MINLINE void negate_v3_v3(float r[3], const float a[3])
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void wm_xr_pose_to_mat(const GHOST_XrPose *pose, float r_mat[4][4])
Definition wm_xr_draw.cc:44
@ V3D_RUNTIME_XR_SESSION_ROOT
static void wm_xr_navigation_teleport_uninit(wmOperator *op)
static void wm_xr_navigation_grab_bimanual_state_update(const wmXrActionData *actiondata, XrGrabData *data)
static wmOperatorStatus wm_xr_navigation_reset_invoke(bContext *C, wmOperator *op, const wmEvent *event)
__int64 int64_t
Definition BKE_text.h:90
static void wm_xr_navigation_teleport_draw_destination(const XrTeleportData *data)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static void wm_xr_grab_compute(const wmXrActionData *actiondata, const XrGrabData *data, const float nav_mat[4][4], const float nav_inv[4][4], bool reverse, float r_delta[4][4])
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
static void WM_OT_xr_navigation_swap_hands(wmOperatorType *ot)
void immEnd()
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void GPU_matrix_scale_1f(float factor)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void mat4_to_quat(float q[4], const float mat[4][4])
void imm_draw_cylinder_fill_3d(uint pos, float base, float top, float height, int slices, int stacks)
void WM_xr_session_state_nav_location_set(wmXrData *xr, const float location[3])
void wm_xr_operatortypes_register()
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
PropertyRNA * RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
static void wm_xr_fly_compute_turn(eXrFlyMode mode, float speed, const float viewer_mat[4][4], const float nav_mat[4][4], const float nav_inv[4][4], float r_delta[4][4])
void copy_m4_m3(float m1[4][4], const float m2[3][3])
bool WM_xr_session_exists(const wmXrData *xr)
static void wm_xr_fly_compute_move(eXrFlyMode mode, float speed, const float ref_quat[4], const float nav_mat[4][4], bool locz_lock, float r_delta[4][4])
bool wm_xr_viewfinder_operator_event_match_hand(bContext *C, const wmEvent *event)
void project_v3_v3v3_normalized(float out[3], const float p[3], const float v_proj[3])
static void wm_xr_navigation_teleport_cancel(bContext *, wmOperator *op)
bool WM_xr_session_state_nav_rotation_get(const wmXrData *xr, float r_rotation[4])
GPUVertFormat * immVertexFormat()
float normalize_qt(float q[4])
void immBegin(GPUPrimType, uint vertex_len)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void quat_to_eul(float eul[3], const float quat[4])
static void wm_xr_navigation_teleport_draw(const bContext *, ARegion *, void *customdata)
static void wm_xr_grab_update(wmOperator *op, const wmXrActionData *actiondata)
@ GPU_PRIM_LINE_STRIP
static float3 wm_xr_navigation_teleport_get_nav_destination(const wmXrData *xr, XrTeleportData *data)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
@ V3D_XR_SESSION_MIRROR
bool invert_m4(float mat[4][4])
static void wm_xr_navigation_grab_cancel(bContext *, wmOperator *op)
static constexpr int g_xr_teleportation_arc_num_control_points
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
ATTR_WARN_UNUSED_RESULT const BMVert * v
void immUniformColor4fv(const float rgba[4])
bool WM_xr_session_state_viewer_scale_get(const wmXrData *xr, float *r_scale)
static void WM_OT_xr_navigation_teleport(wmOperatorType *ot)
static XrTeleportRayResult wm_xr_navigation_teleport_arc_scene_intersect(bContext *C, wmOperator *op, XrTeleportData *data)
void immUnbindProgram()
bool WM_xr_session_state_nav_location_get(const wmXrData *xr, float r_location[3])
bool wm_xr_init(bContext *C)
Definition wm_xr.cc:61
static void wm_xr_basenav_rotation_calc(const wmXrData *xr, const float nav_rotation[4], float r_rotation[4])
MINLINE void mul_v3_fl(float r[3], float f)
static void wm_xr_grab_init(wmOperator *op)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
static wmOperatorStatus wm_xr_navigation_teleport_exec(bContext *, wmOperator *)
MINLINE void sub_v3_v3(float r[3], const float a[3])
static wmOperatorStatus wm_xr_navigation_teleport_modal(bContext *C, wmOperator *op, const wmEvent *event)
void mul_qt_v3(const float q[4], float r[3])
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
static bool wm_xr_navigation_teleport_is_wall_hit(float3 &hit_normal)
static bool wm_xr_navigation_grab_can_do_bimanual(const wmXrActionData *actiondata, const XrGrabData *data)
void GPU_matrix_translate_3fv(const float vec[3])
@ XR_VIEWFINDER_HAND_LEFT
@ XR_VIEWFINDER_HAND_RIGHT
void unit_qt(float q[4])
void quat_to_mat3(float m[3][3], const float q[4])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
@ SCE_SNAP_TARGET_ONLY_SELECTABLE
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
void immUniform1f(const char *name, float x)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
static bool wm_xr_navigation_grab_is_locked(const XrGrabData *data, const bool bimanual)
void imm_draw_disk_partial_fill_3d(uint pos, float x, float y, float z, float rad_inner, float rad_outer, int nsegments, float start, float sweep)
@ XR_FLY_CONTROLLER_FORWARD
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
static wmOperatorStatus wm_xr_navigation_fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
void copy_qt_qt(float q[4], const float a[4])
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
void WM_xr_session_state_vignette_activate(wmXrData *xr)
BMesh const char void * data
static void wm_xr_navigation_teleport_raycast(Depsgraph *depsgraph, const float origin[3], const float direction[3], float *ray_dist, bool selectable_only, float r_location[3], float r_normal[3], int *r_index, const Object **r_ob, float r_obmat[4][4])
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
static wmOperatorStatus wm_xr_navigation_grab_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void axis_angle_to_quat_single(float q[4], char axis, float angle)
unsigned char uint8_t
Definition BKE_text.h:79
static void wm_xr_fly_init(wmOperator *op, const wmXrData *xr)
static void wm_xr_grab_compute_bimanual(const wmXrActionData *actiondata, const XrGrabData *data, const float nav_mat[4][4], const float nav_inv[4][4], bool reverse, float r_delta[4][4])
MINLINE void negate_v3(float r[3])
bool WM_xr_session_state_viewer_pose_location_get(const wmXrData *xr, float r_location[3])
static void WM_OT_xr_navigation_grab(wmOperatorType *ot)
static wmOperatorStatus wm_xr_navigation_swap_hands_exec(bContext *, wmOperator *)
void GPU_batch_draw(gpu::Batch *batch)
bool WM_xr_session_is_ready(const wmXrData *xr)
void unit_m4(float m[4][4])
bool ED_operator_view3d_active(bContext *C)
void wm_xr_pose_scale_to_mat(const GHOST_XrPose *pose, float scale, float r_mat[4][4])
Definition wm_xr_draw.cc:50
ARegionType * BKE_regiontype_from_id(const SpaceType *st, int regionid)
Definition screen.cc:364
SpaceType * BKE_spacetype_from_id(int spaceid)
Definition screen.cc:354
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
static wmOperatorStatus wm_xr_navigation_teleport_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static bool wm_xr_operator_test_event(const wmOperator *op, const wmEvent *event)
void WM_xr_session_state_nav_scale_set(wmXrData *xr, float scale)
void imm_draw_circle_fill_3d(uint pos, float x, float y, float radius, int nsegments)
@ USER_XR_NAV_INVERT_ROTATION
static wmOperatorStatus wm_xr_navigation_fly_exec(bContext *, wmOperator *)
static wmOperatorStatus wm_xr_navigation_fly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
static void wm_xr_session_update_screen_on_exit_cb(const wmXrData *xr_data)
static void wm_xr_fly_uninit(wmOperator *op)
static void orient_mat_z_normalized(float R[4][4], const float z_axis[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
static void wm_xr_navigation_teleport_generate_arc(wmOperator *op, XrTeleportData *data)
static void wm_xr_navigation_teleport_data_update(wmOperator *op, const wmXrData *xr, XrTeleportData *data, const wmXrActionData *actiondata)
static wmOperatorStatus wm_xr_navigation_grab_exec(bContext *, wmOperator *)
MINLINE float normalize_v3(float n[3])
static void WM_OT_xr_navigation_fly(wmOperatorType *ot)
MINLINE void add_v3_v3(float r[3], const float a[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void immVertex3fv(uint attr_id, const float data[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
Main * CTX_data_main(const bContext *C)
static wmOperatorStatus wm_xr_navigation_swap_hands_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void wm_xr_pose_to_imat(const GHOST_XrPose *pose, float r_imat[4][4])
Definition wm_xr_draw.cc:60
Scene * WM_windows_scene_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
static void WM_OT_xr_session_toggle(wmOperatorType *ot)
void interp_v2_v2v2v2v2_cubic(float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2], float u)
static XrTeleportRayResult wm_xr_navigation_teleport_main(bContext *C, wmOperator *op, const wmXrData *xr, XrTeleportData *data, float3 &r_nav_destination)
void WM_xr_session_state_nav_rotation_set(wmXrData *xr, const float rotation[4])
static void wm_xr_session_update_screen(Main *bmain, const wmXrData *xr_data)
@ KM_RELEASE
Definition WM_types.hh:325
bool WM_xr_session_state_viewer_pose_rotation_get(const wmXrData *xr, float r_rotation[4])
double BLI_time_now_seconds()
Definition time.cc:30
static wmOperatorStatus wm_xr_navigation_swap_hands_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void wm_xr_grab_uninit(wmOperator *op)
void wm_xr_session_toggle(wmWindowManager *wm, wmXrSessionExitFn session_exit_fn)
void immUniform2fv(const char *name, const float data[2])
gpu::Batch * GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT
static bool wm_xr_navigation_teleport_arc_clip_to_ground(Array< float3 > &points, int &end_point_idx)
static void wm_xr_navigation_grab_apply(wmXrData *xr, const wmXrActionData *actiondata, const XrGrabData *data, bool bimanual)
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
static void WM_OT_xr_navigation_reset(wmOperatorType *ot)
void wm_xr_pose_scale_to_imat(const GHOST_XrPose *pose, float scale, float r_imat[4][4])
Definition wm_xr_draw.cc:68
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void GPU_matrix_translate_3f(float x, float y, float z)
static void wm_xr_navigation_teleport_draw_ray(const XrTeleportData *data)
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
void immUniform1i(const char *name, int x)
static wmOperatorStatus wm_xr_session_toggle_exec(bContext *C, wmOperator *)
static wmOperatorStatus wm_xr_navigation_reset_exec(bContext *C, wmOperator *op)
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void GPU_matrix_pop()
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], float angle)
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
static bool wm_xr_navigation_grab_is_bimanual_ending(const wmXrActionData *actiondata, const XrGrabData *data)
bool IDP_EqualsProperties(const IDProperty *prop1, const IDProperty *prop2) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:1127
static void wm_xr_navigation_teleport_init(wmOperator *op)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
static wmOperatorStatus wm_xr_navigation_grab_modal(bContext *C, wmOperator *op, const wmEvent *event)
View3D * CTX_wm_view3d(const bContext *C)
static void wm_xr_navigation_fly_cancel(bContext *, wmOperator *op)
void GPU_matrix_push()
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void quat_to_mat4(float m[4][4], const float q[4])
bool WM_xr_session_state_nav_scale_get(const wmXrData *xr, float *r_scale)
static bool wm_xr_operator_sessionactive(bContext *C)
#define fabsf
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
ListBaseT< SpaceLink > spacedata
View3D_Runtime runtime
XrTeleportRayResult ray_result
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct wmOperatorType * type
XrSessionSettings session_settings
struct wmXrRuntimeData * runtime
wmXrSessionState session_state