Skip to content

Commit

Permalink
Adding HTC tracker support
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Apr 25, 2022
1 parent 35b870b commit d45b7d6
Show file tree
Hide file tree
Showing 20 changed files with 1,108 additions and 389 deletions.
33 changes: 32 additions & 1 deletion 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 All @@ -24,6 +24,7 @@
[ext_resource path="res://scenes/BallCourt.tscn" type="PackedScene" id=22]
[ext_resource path="res://addons/godot-openxr/scenes/controller.gd" type="Script" id=23]
[ext_resource path="res://scenes/AimPointer.tscn" type="PackedScene" id=24]
[ext_resource path="res://assets/htc/vr_tracker_vive_3_0/vr_tracker_vive_3_0.obj" type="ArrayMesh" id=25]

[sub_resource type="CapsuleMesh" id=1]
radius = 0.1
Expand Down Expand Up @@ -139,6 +140,12 @@ 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="vr_glove_left_slim" parent="FPController/LeftHand/HandModel/Armature001/Skeleton" index="0"]
material/0 = null

[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 )

Expand All @@ -151,6 +158,12 @@ material/0 = null
motion_range = 1
albedo_texture = ExtResource( 5 )

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

[node name="vr_glove_right_slim" parent="FPController/RightHand/HandModel/Armature/Skeleton" index="0"]
material/0 = null

[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 )

Expand Down Expand Up @@ -203,6 +216,24 @@ show_target = true
active_button = 7
collide_with_areas = true

[node name="HTCTrackerCamera" parent="FPController" instance=ExtResource( 7 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0 )
action = "godot/aim_pose"
path = "/user/vive_tracker_htcx/role/camera"

[node name="MeshInstance" type="MeshInstance" parent="FPController/HTCTrackerCamera"]
mesh = ExtResource( 25 )
material/0 = null

[node name="HTCTrackerKeyboard" parent="FPController" instance=ExtResource( 7 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0 )
action = "godot/aim_pose"
path = "/user/vive_tracker_htcx/role/keyboard"

[node name="MeshInstance" type="MeshInstance" parent="FPController/HTCTrackerKeyboard"]
mesh = ExtResource( 25 )
material/0 = null

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

Expand Down
37 changes: 37 additions & 0 deletions demo/assets/htc/vr_tracker_vive_3_0/vr_tracker_vive_3_0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"thumbnail": "vive_controller_thumbnail.png",
"components": {
"body": {
"filename": "vr_tracker_vive_3_0.obj",
"component_local": {
"origin": [ 0.0, 0.0, 0.0 ],
"rotate_xyz": [ 0.0, 0.0, 0.0 ]
}
},
"back": {
"component_local": {
"origin": [ 0.0, 0.0, 0.0 ],
"rotate_xyz": [ 0.0, 0.0, 180.0 ]
}
},
"pistol": {
"component_local": {
"origin": [ 0.0, 0.0, 0.0 ],
"rotate_xyz": [ -30.0, 0.0, 180.0 ]
}
},
"front_rolled": {
"component_local": {
"origin": [ 0.0, 0.0, 0.01 ],
"rotate_xyz": [ 90.0, 180.0, 0.0 ]
}
},
"front": {
"component_local": {
"origin": [ 0.0, 0.0, 0.01 ],
"rotate_xyz": [ 90.0, 0.0, 0.0 ]
}
}
}
}
}
28 changes: 28 additions & 0 deletions demo/assets/htc/vr_tracker_vive_3_0/vr_tracker_vive_3_0.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
newmtl VIVE_Tracker_3_0_
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl VIVE_Tracker_CUI__
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl initialShadingGroup
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl vr_tracker_vive_3_0_SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd vr_tracker_vive_3_0_diff.png
Ni 1.00
Ks 0.00 0.00 0.00
map_Ks vr_tracker_vive_3_0_Spec.png
Ns 18.00
20 changes: 20 additions & 0 deletions demo/assets/htc/vr_tracker_vive_3_0/vr_tracker_vive_3_0.obj.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[remap]

importer="wavefront_obj"
type="Mesh"
path="res://.import/vr_tracker_vive_3_0.obj-a53b4a08c4f66629a29ada7de74481d0.mesh"

[deps]

files=[ "res://.import/vr_tracker_vive_3_0.obj-a53b4a08c4f66629a29ada7de74481d0.mesh" ]

source_file="res://assets/htc/vr_tracker_vive_3_0/vr_tracker_vive_3_0.obj"
dest_files=[ "res://.import/vr_tracker_vive_3_0.obj-a53b4a08c4f66629a29ada7de74481d0.mesh", "res://.import/vr_tracker_vive_3_0.obj-a53b4a08c4f66629a29ada7de74481d0.mesh" ]

[params]

generate_tangents=true
scale_mesh=Vector3( 1, 1, 1 )
offset_mesh=Vector3( 0, 0, 0 )
octahedral_compression=true
optimize_mesh_flags=4286
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[remap]

importer="texture"
type="StreamTexture"
path.s3tc="res://.import/vr_tracker_vive_3_0_Spec.png-5f0e428f46dc6136a4fa36515f0fab6c.s3tc.stex"
path.etc2="res://.import/vr_tracker_vive_3_0_Spec.png-5f0e428f46dc6136a4fa36515f0fab6c.etc2.stex"
path.etc="res://.import/vr_tracker_vive_3_0_Spec.png-5f0e428f46dc6136a4fa36515f0fab6c.etc.stex"
metadata={
"imported_formats": [ "s3tc", "etc2", "etc" ],
"vram_texture": true
}

[deps]

source_file="res://assets/htc/vr_tracker_vive_3_0/vr_tracker_vive_3_0_Spec.png"
dest_files=[ "res://.import/vr_tracker_vive_3_0_Spec.png-5f0e428f46dc6136a4fa36515f0fab6c.s3tc.stex", "res://.import/vr_tracker_vive_3_0_Spec.png-5f0e428f46dc6136a4fa36515f0fab6c.etc2.stex", "res://.import/vr_tracker_vive_3_0_Spec.png-5f0e428f46dc6136a4fa36515f0fab6c.etc.stex" ]

[params]

compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[remap]

importer="texture"
type="StreamTexture"
path.s3tc="res://.import/vr_tracker_vive_3_0_diff.png-073876868edc19f3fac2656e5573f296.s3tc.stex"
path.etc2="res://.import/vr_tracker_vive_3_0_diff.png-073876868edc19f3fac2656e5573f296.etc2.stex"
path.etc="res://.import/vr_tracker_vive_3_0_diff.png-073876868edc19f3fac2656e5573f296.etc.stex"
metadata={
"imported_formats": [ "s3tc", "etc2", "etc" ],
"vram_texture": true
}

[deps]

source_file="res://assets/htc/vr_tracker_vive_3_0/vr_tracker_vive_3_0_diff.png"
dest_files=[ "res://.import/vr_tracker_vive_3_0_diff.png-073876868edc19f3fac2656e5573f296.s3tc.stex", "res://.import/vr_tracker_vive_3_0_diff.png-073876868edc19f3fac2656e5573f296.etc2.stex", "res://.import/vr_tracker_vive_3_0_diff.png-073876868edc19f3fac2656e5573f296.etc.stex" ]

[params]

compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
4 changes: 4 additions & 0 deletions demo/scenes/Screen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ func _on_ToggleBounds_pressed():
func _on_TogglePassthrough_pressed():
if fp_controller:
fp_controller.enable_passthrough = !fp_controller.enable_passthrough


func _on_Quit_pressed():
get_tree().quit()
12 changes: 9 additions & 3 deletions demo/scenes/Screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ margin_right = 267.0
margin_bottom = 338.0
custom_fonts/font = ExtResource( 1 )
text = "Press me!!"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Count" type="Label" parent="."]
margin_left = 290.0
Expand Down Expand Up @@ -78,6 +75,15 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Quit" type="Button" parent="."]
margin_left = 470.0
margin_top = 347.0
margin_right = 587.0
margin_bottom = 385.0
custom_fonts/font = ExtResource( 1 )
text = "Quit"

[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
[connection signal="pressed" from="ToggleBounds" to="." method="_on_ToggleBounds_pressed"]
[connection signal="pressed" from="TogglePassthrough" to="." method="_on_TogglePassthrough_pressed"]
[connection signal="pressed" from="Quit" to="." method="_on_Quit_pressed"]
2 changes: 2 additions & 0 deletions src/ARVRInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "openxr/extensions/xr_fb_foveation_extension_wrapper.h"
#include "openxr/extensions/xr_fb_passthrough_extension_wrapper.h"
#include "openxr/extensions/xr_fb_swapchain_update_state_extension_wrapper.h"
#include "openxr/extensions/xr_htc_vive_tracker_extension_wrapper.h"
#include <ARVRInterface.hpp>
#include <MainLoop.hpp>

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<XRHTCViveTrackerExtensionWrapper>();

// not initialise
arvr_data->openxr_api->initialize();
Expand Down
39 changes: 37 additions & 2 deletions src/gdclasses/OpenXRPose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ void OpenXRPose::_register_methods() {
&OpenXRPose::get_invisible_if_inactive,
true);

register_method("get_invisible_if_no_confidence", &OpenXRPose::get_invisible_if_no_confidence);
register_method("set_invisible_if_no_confidence", &OpenXRPose::set_invisible_if_no_confidence);
register_property<OpenXRPose, bool>(
"invisible_if_no_confidence",
&OpenXRPose::set_invisible_if_no_confidence,
&OpenXRPose::get_invisible_if_no_confidence,
true);

// For now these are hard coded based on our actions
// As our actions JSON is parsed after initialisation we can't really present the dropdown (yet)
// For now this will do
Expand Down Expand Up @@ -45,7 +53,15 @@ void OpenXRPose::_register_methods() {
GODOT_METHOD_RPC_MODE_DISABLED,
GODOT_PROPERTY_USAGE_DEFAULT,
GODOT_PROPERTY_HINT_ENUM,
"/user/hand/left,/user/hand/right,/user/treadmill");
"/user/hand/left,/user/hand/right,/user/treadmill"
",/user/vive_tracker_htcx/role/left_foot,/user/vive_tracker_htcx/role/right_foot"
",/user/vive_tracker_htcx/role/left_shoulder,/user/vive_tracker_htcx/role/right_shoulder"
",/user/vive_tracker_htcx/role/left_elbow,/user/vive_tracker_htcx/role/right_elbow"
",/user/vive_tracker_htcx/role/left_knee,/user/vive_tracker_htcx/role/right_knee"
",/user/vive_tracker_htcx/role/waist"
",/user/vive_tracker_htcx/role/chest"
",/user/vive_tracker_htcx/role/camera"
",/user/vive_tracker_htcx/role/keyboard");

register_method("is_active", &OpenXRPose::is_active);
register_method("get_tracking_confidence", &OpenXRPose::get_tracking_confidence);
Expand Down Expand Up @@ -119,14 +135,16 @@ bool OpenXRPose::check_action_and_path() {
}

void OpenXRPose::_physics_process(float delta) {
bool visible = true;

if (openxr_api == nullptr || hand_tracking_wrapper == nullptr) {
return;
} else if (!openxr_api->is_initialised()) {
return;
}

if (invisible_if_inactive) {
set_visible(is_active());
visible = is_active();
}

ARVRServer *server = ARVRServer::get_singleton();
Expand All @@ -149,7 +167,16 @@ void OpenXRPose::_physics_process(float delta) {
Transform t;
confidence = _action->get_as_pose(_path, ws, t);
set_transform(reference_frame * t);
} else {
// we're not tracking anything...
confidence = TRACKING_CONFIDENCE_NONE;
}

if (invisible_if_no_confidence && confidence == TRACKING_CONFIDENCE_NONE) {
visible = false;
}

set_visible(visible);
}

bool OpenXRPose::is_active() {
Expand Down Expand Up @@ -184,6 +211,14 @@ void OpenXRPose::set_invisible_if_inactive(bool hide) {
invisible_if_inactive = hide;
}

bool OpenXRPose::get_invisible_if_no_confidence() const {
return invisible_if_no_confidence;
}

void OpenXRPose::set_invisible_if_no_confidence(bool hide) {
invisible_if_no_confidence = hide;
}

String OpenXRPose::get_action() const {
return action;
}
Expand Down
3 changes: 3 additions & 0 deletions src/gdclasses/OpenXRPose.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class OpenXRPose : public Spatial {
TrackingConfidence confidence = TRACKING_CONFIDENCE_NONE;
XRExtHandTrackingExtensionWrapper *hand_tracking_wrapper = nullptr;
bool invisible_if_inactive = true;
bool invisible_if_no_confidence = true;
String action;
String path;

Expand All @@ -39,6 +40,8 @@ class OpenXRPose : public Spatial {

bool get_invisible_if_inactive() const;
void set_invisible_if_inactive(bool hide);
bool get_invisible_if_no_confidence() const;
void set_invisible_if_no_confidence(bool hide);

String get_action() const;
void set_action(const String p_action);
Expand Down
Loading

0 comments on commit d45b7d6

Please sign in to comment.