Improves control over the XR reference space by using the stage ref space (user-defined tracking bounds) instead of local ref space (position at application launch), if available. Also adds an "absolute tracking" session option to skip applying eye offsets that are normally added for placing users exactly at landmarks. By enabling absolute tracking, users can define the tracking origin in a way that is not linked to the headset position. Instead, the tracking values given by the XR runtime are left unadjusted and a user can manually calibrate an "origin" landmark object to adjust to their real world space. Can be useful for applications that use external tracking systems and those that primarily only need to use controllers and not the headset (e.g. motion capture). The absolute tracking option requires an update to the VR Scene Inspection addon to be accessible by regular users. Reviewed By: Julian Eisel Differential Revision: http://developer.blender.org/D10946
298 lines
11 KiB
C
298 lines
11 KiB
C
/*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
/** \file
|
|
* \ingroup RNA
|
|
*/
|
|
|
|
#include "DNA_view3d_types.h"
|
|
#include "DNA_xr_types.h"
|
|
|
|
#include "RNA_define.h"
|
|
#include "RNA_enum_types.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
#include "rna_internal.h"
|
|
|
|
#ifdef RNA_RUNTIME
|
|
|
|
# include "BLI_math.h"
|
|
|
|
# include "WM_api.h"
|
|
|
|
# ifdef WITH_XR_OPENXR
|
|
static wmXrData *rna_XrSession_wm_xr_data_get(PointerRNA *ptr)
|
|
{
|
|
/* Callers could also get XrSessionState pointer through ptr->data, but prefer if we just
|
|
* consistently pass wmXrData pointers to the WM_xr_xxx() API. */
|
|
|
|
BLI_assert((ptr->type == &RNA_XrSessionSettings) || (ptr->type == &RNA_XrSessionState));
|
|
|
|
wmWindowManager *wm = (wmWindowManager *)ptr->owner_id;
|
|
BLI_assert(wm && (GS(wm->id.name) == ID_WM));
|
|
|
|
return &wm->xr;
|
|
}
|
|
# endif
|
|
|
|
static bool rna_XrSessionSettings_use_positional_tracking_get(PointerRNA *ptr)
|
|
{
|
|
# ifdef WITH_XR_OPENXR
|
|
const wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
|
|
return (xr->session_settings.flag & XR_SESSION_USE_POSITION_TRACKING) != 0;
|
|
# else
|
|
UNUSED_VARS(ptr);
|
|
return false;
|
|
# endif
|
|
}
|
|
|
|
static void rna_XrSessionSettings_use_positional_tracking_set(PointerRNA *ptr, bool value)
|
|
{
|
|
# ifdef WITH_XR_OPENXR
|
|
wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
|
|
SET_FLAG_FROM_TEST(xr->session_settings.flag, value, XR_SESSION_USE_POSITION_TRACKING);
|
|
# else
|
|
UNUSED_VARS(ptr, value);
|
|
# endif
|
|
}
|
|
|
|
static bool rna_XrSessionSettings_use_absolute_tracking_get(PointerRNA *ptr)
|
|
{
|
|
# ifdef WITH_XR_OPENXR
|
|
const wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
|
|
return (xr->session_settings.flag & XR_SESSION_USE_ABSOLUTE_TRACKING) != 0;
|
|
# else
|
|
UNUSED_VARS(ptr);
|
|
return false;
|
|
# endif
|
|
}
|
|
|
|
static void rna_XrSessionSettings_use_absolute_tracking_set(PointerRNA *ptr, bool value)
|
|
{
|
|
# ifdef WITH_XR_OPENXR
|
|
wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
|
|
SET_FLAG_FROM_TEST(xr->session_settings.flag, value, XR_SESSION_USE_ABSOLUTE_TRACKING);
|
|
# else
|
|
UNUSED_VARS(ptr, value);
|
|
# endif
|
|
}
|
|
|
|
static bool rna_XrSessionState_is_running(bContext *C)
|
|
{
|
|
# ifdef WITH_XR_OPENXR
|
|
const wmWindowManager *wm = CTX_wm_manager(C);
|
|
return WM_xr_session_exists(&wm->xr);
|
|
# else
|
|
UNUSED_VARS(C);
|
|
return false;
|
|
# endif
|
|
}
|
|
|
|
static void rna_XrSessionState_reset_to_base_pose(bContext *C)
|
|
{
|
|
# ifdef WITH_XR_OPENXR
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
WM_xr_session_base_pose_reset(&wm->xr);
|
|
# else
|
|
UNUSED_VARS(C);
|
|
# endif
|
|
}
|
|
|
|
static void rna_XrSessionState_viewer_pose_location_get(PointerRNA *ptr, float *r_values)
|
|
{
|
|
# ifdef WITH_XR_OPENXR
|
|
const wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
|
|
WM_xr_session_state_viewer_pose_location_get(xr, r_values);
|
|
# else
|
|
UNUSED_VARS(ptr);
|
|
zero_v3(r_values);
|
|
# endif
|
|
}
|
|
|
|
static void rna_XrSessionState_viewer_pose_rotation_get(PointerRNA *ptr, float *r_values)
|
|
{
|
|
# ifdef WITH_XR_OPENXR
|
|
const wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
|
|
WM_xr_session_state_viewer_pose_rotation_get(xr, r_values);
|
|
# else
|
|
UNUSED_VARS(ptr);
|
|
unit_qt(r_values);
|
|
# endif
|
|
}
|
|
|
|
#else /* RNA_RUNTIME */
|
|
|
|
static void rna_def_xr_session_settings(BlenderRNA *brna)
|
|
{
|
|
StructRNA *srna;
|
|
PropertyRNA *prop;
|
|
|
|
static const EnumPropertyItem base_pose_types[] = {
|
|
{XR_BASE_POSE_SCENE_CAMERA,
|
|
"SCENE_CAMERA",
|
|
0,
|
|
"Scene Camera",
|
|
"Follow the active scene camera to define the VR view's base pose"},
|
|
{XR_BASE_POSE_OBJECT,
|
|
"OBJECT",
|
|
0,
|
|
"Object",
|
|
"Follow the transformation of an object to define the VR view's base pose"},
|
|
{XR_BASE_POSE_CUSTOM,
|
|
"CUSTOM",
|
|
0,
|
|
"Custom",
|
|
"Follow a custom transformation to define the VR view's base pose"},
|
|
{0, NULL, 0, NULL, NULL},
|
|
};
|
|
|
|
srna = RNA_def_struct(brna, "XrSessionSettings", NULL);
|
|
RNA_def_struct_ui_text(srna, "XR Session Settings", "");
|
|
|
|
prop = RNA_def_property(srna, "shading", PROP_POINTER, PROP_NONE);
|
|
RNA_def_property_flag(prop, PROP_NEVER_NULL);
|
|
RNA_def_property_ui_text(prop, "Shading Settings", "");
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
|
|
|
prop = RNA_def_property(srna, "base_pose_type", PROP_ENUM, PROP_NONE);
|
|
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
|
RNA_def_property_enum_items(prop, base_pose_types);
|
|
RNA_def_property_ui_text(
|
|
prop,
|
|
"Base Pose Type",
|
|
"Define where the location and rotation for the VR view come from, to which "
|
|
"translation and rotation deltas from the VR headset will be applied to");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "base_pose_object", PROP_POINTER, PROP_NONE);
|
|
RNA_def_property_flag(prop, PROP_EDITABLE);
|
|
RNA_def_property_ui_text(prop,
|
|
"Base Pose Object",
|
|
"Object to take the location and rotation to which translation and "
|
|
"rotation deltas from the VR headset will be applied to");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "base_pose_location", PROP_FLOAT, PROP_TRANSLATION);
|
|
RNA_def_property_ui_text(prop,
|
|
"Base Pose Location",
|
|
"Coordinates to apply translation deltas from the VR headset to");
|
|
RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "base_pose_angle", PROP_FLOAT, PROP_AXISANGLE);
|
|
RNA_def_property_ui_text(
|
|
prop,
|
|
"Base Pose Angle",
|
|
"Rotation angle around the Z-Axis to apply the rotation deltas from the VR headset to");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "show_floor", PROP_BOOLEAN, PROP_NONE);
|
|
RNA_def_property_boolean_sdna(prop, NULL, "draw_flags", V3D_OFSDRAW_SHOW_GRIDFLOOR);
|
|
RNA_def_property_ui_text(prop, "Display Grid Floor", "Show the ground plane grid");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "show_annotation", PROP_BOOLEAN, PROP_NONE);
|
|
RNA_def_property_boolean_sdna(prop, NULL, "draw_flags", V3D_OFSDRAW_SHOW_ANNOTATION);
|
|
RNA_def_property_ui_text(prop, "Show Annotation", "Show annotations for this view");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_DISTANCE);
|
|
RNA_def_property_range(prop, 1e-6f, FLT_MAX);
|
|
RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
|
|
RNA_def_property_ui_text(prop, "Clip Start", "VR viewport near clipping distance");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_DISTANCE);
|
|
RNA_def_property_range(prop, 1e-6f, FLT_MAX);
|
|
RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
|
|
RNA_def_property_ui_text(prop, "Clip End", "VR viewport far clipping distance");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "use_positional_tracking", PROP_BOOLEAN, PROP_NONE);
|
|
RNA_def_property_boolean_funcs(prop,
|
|
"rna_XrSessionSettings_use_positional_tracking_get",
|
|
"rna_XrSessionSettings_use_positional_tracking_set");
|
|
RNA_def_property_ui_text(
|
|
prop,
|
|
"Positional Tracking",
|
|
"Allow VR headsets to affect the location in virtual space, in addition to the rotation");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
|
|
prop = RNA_def_property(srna, "use_absolute_tracking", PROP_BOOLEAN, PROP_NONE);
|
|
RNA_def_property_boolean_funcs(prop,
|
|
"rna_XrSessionSettings_use_absolute_tracking_get",
|
|
"rna_XrSessionSettings_use_absolute_tracking_set");
|
|
RNA_def_property_ui_text(
|
|
prop, "Absolute Tracking", "Use unadjusted location/rotation as defined by the XR runtime");
|
|
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
|
|
}
|
|
|
|
static void rna_def_xr_session_state(BlenderRNA *brna)
|
|
{
|
|
StructRNA *srna;
|
|
FunctionRNA *func;
|
|
PropertyRNA *parm, *prop;
|
|
|
|
srna = RNA_def_struct(brna, "XrSessionState", NULL);
|
|
RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
|
|
RNA_def_struct_ui_text(srna, "Session State", "Runtime state information about the VR session");
|
|
|
|
func = RNA_def_function(srna, "is_running", "rna_XrSessionState_is_running");
|
|
RNA_def_function_ui_description(func, "Query if the VR session is currently running");
|
|
RNA_def_function_flag(func, FUNC_NO_SELF);
|
|
parm = RNA_def_pointer(func, "context", "Context", "", "");
|
|
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
|
|
parm = RNA_def_boolean(func, "result", 0, "Result", "");
|
|
RNA_def_function_return(func, parm);
|
|
|
|
func = RNA_def_function(srna, "reset_to_base_pose", "rna_XrSessionState_reset_to_base_pose");
|
|
RNA_def_function_ui_description(func, "Force resetting of position and rotation deltas");
|
|
RNA_def_function_flag(func, FUNC_NO_SELF);
|
|
parm = RNA_def_pointer(func, "context", "Context", "", "");
|
|
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
|
|
|
|
prop = RNA_def_property(srna, "viewer_pose_location", PROP_FLOAT, PROP_TRANSLATION);
|
|
RNA_def_property_array(prop, 3);
|
|
RNA_def_property_float_funcs(prop, "rna_XrSessionState_viewer_pose_location_get", NULL, NULL);
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
|
RNA_def_property_ui_text(
|
|
prop,
|
|
"Viewer Pose Location",
|
|
"Last known location of the viewer pose (center between the eyes) in world space");
|
|
|
|
prop = RNA_def_property(srna, "viewer_pose_rotation", PROP_FLOAT, PROP_QUATERNION);
|
|
RNA_def_property_array(prop, 4);
|
|
RNA_def_property_float_funcs(prop, "rna_XrSessionState_viewer_pose_rotation_get", NULL, NULL);
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
|
RNA_def_property_ui_text(
|
|
prop,
|
|
"Viewer Pose Rotation",
|
|
"Last known rotation of the viewer pose (center between the eyes) in world space");
|
|
}
|
|
|
|
void RNA_def_xr(BlenderRNA *brna)
|
|
{
|
|
RNA_define_animate_sdna(false);
|
|
|
|
rna_def_xr_session_settings(brna);
|
|
rna_def_xr_session_state(brna);
|
|
|
|
RNA_define_animate_sdna(true);
|
|
}
|
|
|
|
#endif /* RNA_RUNTIME */
|