Blender  V2.93
rna_xr.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 
21 #include "DNA_view3d_types.h"
22 #include "DNA_xr_types.h"
23 
24 #include "RNA_define.h"
25 #include "RNA_enum_types.h"
26 
27 #include "WM_types.h"
28 
29 #include "rna_internal.h"
30 
31 #ifdef RNA_RUNTIME
32 
33 # include "BLI_math.h"
34 
35 # include "WM_api.h"
36 
37 static bool rna_XrSessionState_is_running(bContext *C)
38 {
39 # ifdef WITH_XR_OPENXR
40  const wmWindowManager *wm = CTX_wm_manager(C);
41  return WM_xr_session_exists(&wm->xr);
42 # else
43  UNUSED_VARS(C);
44  return false;
45 # endif
46 }
47 
48 static void rna_XrSessionState_reset_to_base_pose(bContext *C)
49 {
50 # ifdef WITH_XR_OPENXR
53 # else
54  UNUSED_VARS(C);
55 # endif
56 }
57 
58 # ifdef WITH_XR_OPENXR
59 static wmXrData *rna_XrSessionState_wm_xr_data_get(PointerRNA *ptr)
60 {
61  /* Callers could also get XrSessionState pointer through ptr->data, but prefer if we just
62  * consistently pass wmXrData pointers to the WM_xr_xxx() API. */
63 
65 
67  BLI_assert(wm && (GS(wm->id.name) == ID_WM));
68 
69  return &wm->xr;
70 }
71 # endif
72 
73 static void rna_XrSessionState_viewer_pose_location_get(PointerRNA *ptr, float *r_values)
74 {
75 # ifdef WITH_XR_OPENXR
76  const wmXrData *xr = rna_XrSessionState_wm_xr_data_get(ptr);
78 # else
80  zero_v3(r_values);
81 # endif
82 }
83 
84 static void rna_XrSessionState_viewer_pose_rotation_get(PointerRNA *ptr, float *r_values)
85 {
86 # ifdef WITH_XR_OPENXR
87  const wmXrData *xr = rna_XrSessionState_wm_xr_data_get(ptr);
89 # else
91  unit_qt(r_values);
92 # endif
93 }
94 
95 #else /* RNA_RUNTIME */
96 
98 {
99  StructRNA *srna;
100  PropertyRNA *prop;
101 
102  static const EnumPropertyItem base_pose_types[] = {
104  "SCENE_CAMERA",
105  0,
106  "Scene Camera",
107  "Follow the active scene camera to define the VR view's base pose"},
109  "OBJECT",
110  0,
111  "Object",
112  "Follow the transformation of an object to define the VR view's base pose"},
114  "CUSTOM",
115  0,
116  "Custom",
117  "Follow a custom transformation to define the VR view's base pose"},
118  {0, NULL, 0, NULL, NULL},
119  };
120 
121  srna = RNA_def_struct(brna, "XrSessionSettings", NULL);
122  RNA_def_struct_ui_text(srna, "XR Session Settings", "");
123 
124  prop = RNA_def_property(srna, "shading", PROP_POINTER, PROP_NONE);
126  RNA_def_property_ui_text(prop, "Shading Settings", "");
128 
129  prop = RNA_def_property(srna, "base_pose_type", PROP_ENUM, PROP_NONE);
131  RNA_def_property_enum_items(prop, base_pose_types);
133  prop,
134  "Base Pose Type",
135  "Define where the location and rotation for the VR view come from, to which "
136  "translation and rotation deltas from the VR headset will be applied to");
138 
139  prop = RNA_def_property(srna, "base_pose_object", PROP_POINTER, PROP_NONE);
142  "Base Pose Object",
143  "Object to take the location and rotation to which translation and "
144  "rotation deltas from the VR headset will be applied to");
146 
147  prop = RNA_def_property(srna, "base_pose_location", PROP_FLOAT, PROP_TRANSLATION);
149  "Base Pose Location",
150  "Coordinates to apply translation deltas from the VR headset to");
151  RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
153 
154  prop = RNA_def_property(srna, "base_pose_angle", PROP_FLOAT, PROP_AXISANGLE);
156  prop,
157  "Base Pose Angle",
158  "Rotation angle around the Z-Axis to apply the rotation deltas from the VR headset to");
160 
161  prop = RNA_def_property(srna, "show_floor", PROP_BOOLEAN, PROP_NONE);
163  RNA_def_property_ui_text(prop, "Display Grid Floor", "Show the ground plane grid");
165 
166  prop = RNA_def_property(srna, "show_annotation", PROP_BOOLEAN, PROP_NONE);
168  RNA_def_property_ui_text(prop, "Show Annotation", "Show annotations for this view");
170 
171  prop = RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_DISTANCE);
172  RNA_def_property_range(prop, 1e-6f, FLT_MAX);
173  RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
174  RNA_def_property_ui_text(prop, "Clip Start", "VR viewport near clipping distance");
176 
177  prop = RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_DISTANCE);
178  RNA_def_property_range(prop, 1e-6f, FLT_MAX);
179  RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
180  RNA_def_property_ui_text(prop, "Clip End", "VR viewport far clipping distance");
182 
183  prop = RNA_def_property(srna, "use_positional_tracking", PROP_BOOLEAN, PROP_NONE);
186  prop,
187  "Positional Tracking",
188  "Allow VR headsets to affect the location in virtual space, in addition to the rotation");
190 }
191 
193 {
194  StructRNA *srna;
195  FunctionRNA *func;
196  PropertyRNA *parm, *prop;
197 
198  srna = RNA_def_struct(brna, "XrSessionState", NULL);
200  RNA_def_struct_ui_text(srna, "Session State", "Runtime state information about the VR session");
201 
202  func = RNA_def_function(srna, "is_running", "rna_XrSessionState_is_running");
203  RNA_def_function_ui_description(func, "Query if the VR session is currently running");
205  parm = RNA_def_pointer(func, "context", "Context", "", "");
207  parm = RNA_def_boolean(func, "result", 0, "Result", "");
208  RNA_def_function_return(func, parm);
209 
210  func = RNA_def_function(srna, "reset_to_base_pose", "rna_XrSessionState_reset_to_base_pose");
211  RNA_def_function_ui_description(func, "Force resetting of position and rotation deltas");
213  parm = RNA_def_pointer(func, "context", "Context", "", "");
215 
216  prop = RNA_def_property(srna, "viewer_pose_location", PROP_FLOAT, PROP_TRANSLATION);
217  RNA_def_property_array(prop, 3);
218  RNA_def_property_float_funcs(prop, "rna_XrSessionState_viewer_pose_location_get", NULL, NULL);
221  prop,
222  "Viewer Pose Location",
223  "Last known location of the viewer pose (center between the eyes) in world space");
224 
225  prop = RNA_def_property(srna, "viewer_pose_rotation", PROP_FLOAT, PROP_QUATERNION);
226  RNA_def_property_array(prop, 4);
227  RNA_def_property_float_funcs(prop, "rna_XrSessionState_viewer_pose_rotation_get", NULL, NULL);
230  prop,
231  "Viewer Pose Rotation",
232  "Last known rotation of the viewer pose (center between the eyes) in world space");
233 }
234 
236 {
238 
241 
243 }
244 
245 #endif /* RNA_RUNTIME */
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
#define BLI_assert(a)
Definition: BLI_assert.h:58
void unit_qt(float q[4])
Definition: math_rotation.c:46
MINLINE void zero_v3(float r[3])
#define UNUSED_VARS(...)
@ ID_WM
Definition: DNA_ID_enums.h:84
@ V3D_OFSDRAW_SHOW_GRIDFLOOR
@ V3D_OFSDRAW_SHOW_ANNOTATION
@ XR_SESSION_USE_POSITION_TRACKING
Definition: DNA_xr_types.h:52
@ XR_BASE_POSE_CUSTOM
Definition: DNA_xr_types.h:58
@ XR_BASE_POSE_SCENE_CAMERA
Definition: DNA_xr_types.h:56
@ XR_BASE_POSE_OBJECT
Definition: DNA_xr_types.h:57
StructRNA RNA_XrSessionState
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_NO_SELF
Definition: RNA_types.h:571
@ STRUCT_UNDO
Definition: RNA_types.h:623
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_POINTER
Definition: RNA_types.h:78
#define RNA_TRANSLATION_PREC_DEFAULT
Definition: RNA_types.h:104
@ PROP_ANIMATABLE
Definition: RNA_types.h:188
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_DISTANCE
Definition: RNA_types.h:135
@ PROP_AXISANGLE
Definition: RNA_types.h:147
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_TRANSLATION
Definition: RNA_types.h:140
@ PROP_QUATERNION
Definition: RNA_types.h:146
#define C
Definition: RandGen.cpp:39
#define NC_WM
Definition: WM_types.h:276
#define ND_XR_DATA_CHANGED
Definition: WM_types.h:317
#define GS(x)
Definition: iris.c:241
void RNA_define_animate_sdna(bool animate)
Definition: rna_define.c:766
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4159
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2257
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3153
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
Definition: rna_define.c:1157
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1757
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
Definition: rna_define.c:1706
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
static void rna_def_xr_session_settings(BlenderRNA *brna)
Definition: rna_xr.c:97
static void rna_def_xr_session_state(BlenderRNA *brna)
Definition: rna_xr.c:192
void RNA_def_xr(BlenderRNA *brna)
Definition: rna_xr.c:235
char name[66]
Definition: DNA_ID.h:283
struct StructRNA * type
Definition: RNA_types.h:51
struct ID * owner_id
Definition: RNA_types.h:50
PointerRNA * ptr
Definition: wm_files.c:3157
void WM_xr_session_base_pose_reset(wmXrData *xr)
bool WM_xr_session_state_viewer_pose_location_get(const wmXrData *xr, float r_location[3])
bool WM_xr_session_exists(const wmXrData *xr)
Definition: wm_xr_session.c:99
bool WM_xr_session_state_viewer_pose_rotation_get(const wmXrData *xr, float r_rotation[4])