Skip to content

Commit

Permalink
Adding palm pose support
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij authored and m4gr3d committed Oct 17, 2022
1 parent 48c3d72 commit d1c647f
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 10 deletions.
26 changes: 19 additions & 7 deletions demo/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=29 format=2]
[gd_scene load_steps=30 format=2]

[ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://scenes/Ground.tscn" type="PackedScene" id=2]
Expand Down Expand Up @@ -42,6 +42,9 @@ height = 0.05
radius = 0.01
height = 0.02

[sub_resource type="CubeMesh" id=5]
size = Vector3( 0.02, 0.02, 0.02 )

[node name="Main" type="Spatial"]
script = ExtResource( 1 )

Expand All @@ -63,13 +66,11 @@ far = 1000.0
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, -0.0187781, 0.103895 )
layers = 524288
mesh = SubResource( 1 )
material/0 = null

[node name="ShadowHMD" type="MeshInstance" parent="FPController/ARVRCamera" index="1"]
transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.44924e-09, 0, 0.00889538 )
layers = 524288
mesh = SubResource( 2 )
material/0 = null

[node name="FPS" parent="FPController/ARVRCamera" index="2" instance=ExtResource( 8 )]
transform = Transform( 0.974339, 0, -0.225087, -0.0292084, 0.991545, -0.126435, 0.223184, 0.129765, 0.9661, 0.256799, 0.257084, -0.989923 )
Expand Down Expand Up @@ -123,41 +124,45 @@ max_samples = 10

[node name="Left_grip_pose" parent="FPController" instance=ExtResource( 7 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1, -0.5 )
action = "godot/grip_pose"

[node name="Grip" type="MeshInstance" parent="FPController/Left_grip_pose"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 )
mesh = SubResource( 3 )
material/0 = null

[node name="Right_aim_pose" parent="FPController" instance=ExtResource( 7 )]
action = "godot/grip_pose"

[node name="Grip" type="MeshInstance" parent="FPController/Right_aim_pose"]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 )
mesh = SubResource( 3 )
material/0 = null

[node name="LeftHand" parent="FPController" instance=ExtResource( 14 )]
motion_range = 1

[node name="Skeleton" parent="FPController/LeftHand/HandModel/Armature001" index="0"]
motion_range = 1

[node name="IndexTip" parent="FPController/LeftHand/HandModel/Armature001/Skeleton" index="1"]
transform = Transform( 0.19221, -0.669965, -0.717079, 0.977075, 0.19881, 0.076153, 0.0915428, -0.715277, 0.692819, 0.0345973, 0.0355402, -0.164767 )

[node name="ShowIndexTip" type="MeshInstance" parent="FPController/LeftHand/HandModel/Armature001/Skeleton/IndexTip" index="0"]
visible = false
mesh = SubResource( 4 )
material/0 = null

[node name="RightHand" parent="FPController" instance=ExtResource( 15 )]
motion_range = 1
albedo_texture = ExtResource( 5 )

[node name="Skeleton" parent="FPController/RightHand/HandModel/Armature" index="0"]
motion_range = 1

[node name="IndexTip" parent="FPController/RightHand/HandModel/Armature/Skeleton" index="1"]
transform = Transform( 0.19221, 0.669966, 0.717078, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345978, -0.164767, -0.0355401 )

[node name="ShowIndexTip" type="MeshInstance" parent="FPController/RightHand/HandModel/Armature/Skeleton/IndexTip" index="0"]
visible = false
mesh = SubResource( 4 )
material/0 = null

[node name="ShowBounds" parent="FPController" instance=ExtResource( 16 )]
visible = false
Expand Down Expand Up @@ -203,6 +208,13 @@ show_target = true
active_button = 7
collide_with_areas = true

[node name="LeftHandPalm" parent="FPController" instance=ExtResource( 7 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.460559, 1, -0.438722 )
action = "godot/palm_pose"

[node name="MeshInstance" type="MeshInstance" parent="FPController/LeftHandPalm"]
mesh = SubResource( 5 )

[node name="Table" parent="." instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -6 )

Expand Down
4 changes: 4 additions & 0 deletions demo/addons/godot-openxr/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes to the Godot OpenXR asset
=================================

1.4.0
-------------------
- Add support for palm pose

1.3.0
-------------------
- Added default interaction profiles for Samsung Odyssey, HTC Cosmos, HTC Focus and Huawei controllers.
Expand Down
Binary file not shown.
Binary file modified demo/addons/godot-openxr/assets/valve_hand_models/glove.material
Binary file not shown.
2 changes: 1 addition & 1 deletion demo/addons/godot-xr-tools/materials/highlight.tres
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ operator = 2

[sub_resource type="VisualShader" id=6]
code = "shader_type spatial;
render_mode specular_schlick_ggx;
render_mode specular_schlick_ggx, async_visible;

uniform vec4 Color : hint_color;

Expand Down
2 changes: 2 additions & 0 deletions src/ARVRInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "ARVRInterface.h"
#include "openxr/extensions/xr_ext_hand_tracking_extension_wrapper.h"
#include "openxr/extensions/xr_ext_palm_pose_extension_wrapper.h"
#include "openxr/extensions/xr_ext_performance_settings_extension_wrapper.h"
#include "openxr/extensions/xr_fb_color_space_extension_wrapper.h"
#include "openxr/extensions/xr_fb_display_refresh_rate_extension_wrapper.h"
Expand Down Expand Up @@ -128,6 +129,7 @@ godot_bool godot_arvr_initialize(void *p_data) {
arvr_data->openxr_api->register_extension_wrapper<XRFbDisplayRefreshRateExtensionWrapper>();
arvr_data->openxr_api->register_extension_wrapper<XRExtHandTrackingExtensionWrapper>();
arvr_data->openxr_api->register_extension_wrapper<XRFbPassthroughExtensionWrapper>();
arvr_data->openxr_api->register_extension_wrapper<XRExtPalmPoseExtensionWrapper>();

// not initialise
arvr_data->openxr_api->initialize();
Expand Down
2 changes: 1 addition & 1 deletion src/gdclasses/OpenXRPose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void OpenXRPose::_register_methods() {
GODOT_METHOD_RPC_MODE_DISABLED,
GODOT_PROPERTY_USAGE_DEFAULT,
GODOT_PROPERTY_HINT_ENUM,
"SkeletonBase,godot/aim_pose,godot/grip_pose");
"SkeletonBase,godot/aim_pose,godot/grip_pose,godot/palm_pose");

// For now this is hard coded, these are fixed entries based on the OpenXR spec
register_method("get_path", &OpenXRPose::get_path);
Expand Down
111 changes: 110 additions & 1 deletion src/openxr/OpenXRApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ const char *OpenXRApi::default_action_sets_json = R"===(
"/user/hand/right"
]
},
{
"type": "pose",
"name": "palm_pose",
"localised_name": "Palm Pose",
"paths": [
"/user/hand/left",
"/user/hand/right"
]
},
{
"type": "float",
"name": "front_trigger",
Expand Down Expand Up @@ -244,6 +253,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "menu_button",
Expand Down Expand Up @@ -289,6 +306,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "select_button",
Expand Down Expand Up @@ -390,6 +415,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "front_trigger",
Expand Down Expand Up @@ -499,6 +532,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "front_trigger",
Expand Down Expand Up @@ -608,6 +649,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "front_trigger",
Expand Down Expand Up @@ -709,6 +758,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "front_trigger",
Expand Down Expand Up @@ -826,6 +883,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "front_trigger",
Expand Down Expand Up @@ -952,6 +1017,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "front_trigger",
Expand Down Expand Up @@ -1021,6 +1094,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "front_trigger",
Expand Down Expand Up @@ -1153,6 +1234,14 @@ const char *OpenXRApi::default_interaction_profiles_json = R"===(
"/user/hand/right/input/grip/pose"
]
},
{
"set": "godot",
"action": "palm_pose",
"paths": [
"/user/hand/left/input/palm_ext/pose",
"/user/hand/right/input/palm_ext/pose"
]
},
{
"set": "godot",
"action": "front_trigger",
Expand Down Expand Up @@ -2850,10 +2939,30 @@ bool OpenXRApi::parse_interaction_profiles(const godot::String &p_json) {
}
for (int p = 0; p < io_paths.size(); p++) {
String io_path_str = io_paths[p];
XrPath io_path;
XrPath io_path = XR_NULL_PATH;

bool is_supported = true;
for (XRExtensionWrapper *wrapper : registered_extension_wrappers) {
if (!wrapper->path_is_supported(io_path_str)) {
// Only the extension that controlls optional io paths will return false if the path is not supported.
is_supported = false;
break;
}
}

if (!is_supported) {
// If we include these interaction profiles can be rejected.
// This kind of makes sense but in our case seeing we're using a fixed action set we will exclude the entries.
Godot::print_warning(String("OpenXR ") + io_path_str + String(" is not supported by this runtime."), __FUNCTION__, __FILE__, __LINE__);
continue;
}

XrResult res = xrStringToPath(instance, io_path_str.utf8().get_data(), &io_path);
if (!xr_result(res, "OpenXR couldn't create path for {0}", io_path_str)) {
continue;
} else if (io_path == XR_NULL_PATH) {
Godot::print_warning(String("OpenXR ") + io_path_str + String(" is not supported by this runtime."), __FUNCTION__, __FILE__, __LINE__);
continue;
}

XrActionSuggestedBinding bind = { xr_action, io_path };
Expand Down
37 changes: 37 additions & 0 deletions src/openxr/extensions/xr_ext_palm_pose_extension_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "xr_ext_palm_pose_extension_wrapper.h"

#include <core/Variant.hpp>

using namespace godot;

XRExtPalmPoseExtensionWrapper *XRExtPalmPoseExtensionWrapper::singleton = nullptr;

XRExtPalmPoseExtensionWrapper *XRExtPalmPoseExtensionWrapper::get_singleton() {
if (!singleton) {
singleton = new XRExtPalmPoseExtensionWrapper();
}

return singleton;
}

XRExtPalmPoseExtensionWrapper::XRExtPalmPoseExtensionWrapper() {
openxr_api = OpenXRApi::openxr_get_api();
request_extensions[XR_EXT_PALM_POSE_EXTENSION_NAME] = &palm_pose_ext;
}

XRExtPalmPoseExtensionWrapper::~XRExtPalmPoseExtensionWrapper() {
OpenXRApi::openxr_release_api();
}

bool XRExtPalmPoseExtensionWrapper::path_is_supported(const String &p_io_path) {
if (p_io_path == "/user/hand/left/input/palm_ext/pose") {
return palm_pose_ext;
}

if (p_io_path == "/user/hand/right/input/palm_ext/pose") {
return palm_pose_ext;
}

// Not a path under this extensions control, so we return true;
return true;
}
Loading

0 comments on commit d1c647f

Please sign in to comment.