-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eed925
commit 4a4b46c
Showing
42 changed files
with
1,469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Normalize EOL for all files that Git considers text files. | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Godot 4+ specific ignores | ||
.godot/ | ||
|
||
# Ignore our Android build folder, should be installed by user if needed | ||
android/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# XR Character Body Centric Movement demo | ||
|
||
This is a demo for an OpenXR project where player movement is handled with a CharacterBody3D as a base node. | ||
This is based on the [Character body centric solution as explained in the room scale manual page](https://docs.godotengine.org/en/stable/tutorials/xr/xr_room_scale.html#character-body-centric-solution). | ||
|
||
Godot version: 4.1.x | ||
Language: GDScript | ||
Renderer: compatibility | ||
|
||
## How does it work? | ||
|
||
With modern VR equipment the user is able to move around a large playspace. | ||
This is often refered to as roomscale VR. | ||
The position of the headset and controllers are tracked in reference to a fixed point within this playspace. | ||
This is often a point on the ground at the center of the playspace mapped out by the user when setting up their guardian. | ||
|
||
In Godot the center of this playspace is represented by the `XROrigin3D` node with camera and controllers being tracked through resp. `XRCamera3D` and `XRController3D` child nodes which can thus not be positioned by the user. | ||
The misunderstandings this causes in handling player movement is described in detail in [the XR room scale manual page](https://docs.godotengine.org/en/stable/tutorials/xr/xr_room_scale.html), a highly recommended read before continuing with this demo. | ||
|
||
This demo implements the character body centric solution to the player movement problem. | ||
Virtual movement by the player (e.g. movement through controller input) in this demo is handled similarly to a non-XR Godot game. | ||
Physical movement by the player will result in the character body attempting to move to the players new location. | ||
If successful the XROrigin node is moved in the opposite direction of the players movement. | ||
If unsuccessful the character body stays behind, the further the player moves the more we black out the screen. | ||
|
||
## Action map | ||
|
||
This project does not use the default action map but instead configures an action map that just contains the actions required for this example to work. This so we remove any clutter and just focus on the functionality being demonstrated. | ||
|
||
There are only two actions needed for this example: | ||
- aim_pose is used to position the XR controllers | ||
- move is used as the input for our movement | ||
|
||
"Move" being the hero here. This action is only bound to one of the two controllers, by default making it a right hand option. Godot will always associate the move action with the controller that is bound to it. | ||
|
||
The code example assumes either controller could trigger the move action. Switching from right to left hand is a separate topic out of scope of this demonstration. | ||
|
||
Also following OpenXR guidelines only bindings for controllers with which the project has been tested are supplied. XR Runtimes should provide proper re-mapping however not all follow this guideline. You may need to add a binding for the platform you are using to the action map. | ||
|
||
## Running on PCVR | ||
|
||
This project can be run as normal for PCVR. Ensure that an OpenXR runtime has been installed. | ||
This project has been tested with the Oculus client and SteamVR OpenXR runtimes. | ||
Note that Godot currently can't run using the WMR OpenXR runtime. Install SteamVR with WMR support. | ||
|
||
## Running on standalone VR | ||
|
||
You must install the Android build templates and OpenXR loader plugin and configure an export template for your device. | ||
Please follow [the instructions for deploying on Android in the manual](https://docs.godotengine.org/en/stable/tutorials/xr/deploying_to_android.html). | ||
|
||
## Screenshots | ||
|
||
![Screenshot](screenshots/character_movement_demo.png) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions
36
xr/openxr_character_centric_movement/assets/pattern.png.import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://rek0t7kubpx4" | ||
path.s3tc="res://.godot/imported/pattern.png-cf6f03dfd1cdd4bc35da3414e912103d.s3tc.ctex" | ||
path.etc2="res://.godot/imported/pattern.png-cf6f03dfd1cdd4bc35da3414e912103d.etc2.ctex" | ||
metadata={ | ||
"imported_formats": ["s3tc_bptc", "etc2_astc"], | ||
"vram_texture": true | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://assets/pattern.png" | ||
dest_files=["res://.godot/imported/pattern.png-cf6f03dfd1cdd4bc35da3414e912103d.s3tc.ctex", "res://.godot/imported/pattern.png-cf6f03dfd1cdd4bc35da3414e912103d.etc2.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=2 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=true | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://8i0kfiat0t8f" | ||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://icon.svg" | ||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 | ||
svg/scale=1.0 | ||
editor/scale_with_editor_scale=false | ||
editor/convert_colors_with_editor_theme=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[gd_scene load_steps=4 format=3 uid="uid://gvmfk4owutdm"] | ||
|
||
[ext_resource type="Script" path="res://start_vr.gd" id="1_mbbqq"] | ||
[ext_resource type="PackedScene" uid="uid://cpj7vtj6gr3tv" path="res://player.tscn" id="2_igeja"] | ||
[ext_resource type="PackedScene" uid="uid://bymbq2ruecbhn" path="res://world.tscn" id="2_m075s"] | ||
|
||
[node name="Main" type="Node3D"] | ||
script = ExtResource("1_mbbqq") | ||
|
||
[node name="World" parent="." instance=ExtResource("2_m075s")] | ||
|
||
[node name="CharacterBody3D" parent="." instance=ExtResource("2_igeja")] | ||
|
||
[connection signal="pose_recentered" from="." to="CharacterBody3D" method="recenter"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@tool | ||
extends Node3D | ||
|
||
@export_range(0, 1, 0.1) var fade = 0.0: | ||
set(value): | ||
fade = value | ||
if is_inside_tree(): | ||
_update_fade() | ||
|
||
var material : ShaderMaterial | ||
|
||
func _update_fade(): | ||
if fade == 0.0: | ||
$MeshInstance3D.visible = false | ||
else: | ||
if material: | ||
material.set_shader_parameter("albedo", Color(0.0, 0.0, 0.0, fade)) | ||
$MeshInstance3D.visible = true | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
material = $MeshInstance3D.material_override | ||
_update_fade() |
12 changes: 12 additions & 0 deletions
12
xr/openxr_character_centric_movement/objects/black_out.gdshader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
shader_type spatial; | ||
render_mode blend_mix,depth_draw_opaque,cull_disabled,unshaded,depth_test_disabled; | ||
uniform vec4 albedo : source_color; | ||
|
||
void vertex() { | ||
POSITION = vec4(VERTEX.xy * 2.0, -1.0, 1.0); | ||
} | ||
|
||
void fragment() { | ||
ALBEDO = albedo.rgb; | ||
ALPHA = albedo.a; | ||
} |
21 changes: 21 additions & 0 deletions
21
xr/openxr_character_centric_movement/objects/black_out.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[gd_scene load_steps=5 format=3 uid="uid://bbvciliw3xnf6"] | ||
|
||
[ext_resource type="Script" path="res://objects/black_out.gd" id="1_1r6dl"] | ||
[ext_resource type="Shader" path="res://objects/black_out.gdshader" id="2_xc5vy"] | ||
|
||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ve0hd"] | ||
resource_local_to_scene = true | ||
render_priority = -99 | ||
shader = ExtResource("2_xc5vy") | ||
shader_parameter/albedo = Color(1, 1, 1, 0.1) | ||
|
||
[sub_resource type="QuadMesh" id="QuadMesh_iv1ir"] | ||
|
||
[node name="BlackOut" type="Node3D"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1) | ||
script = ExtResource("1_1r6dl") | ||
|
||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."] | ||
visible = false | ||
material_override = SubResource("ShaderMaterial_ve0hd") | ||
mesh = SubResource("QuadMesh_iv1ir") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[gd_scene load_steps=5 format=3 uid="uid://c3wwlb4huytmt"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://rek0t7kubpx4" path="res://assets/pattern.png" id="1_qv1d7"] | ||
|
||
[sub_resource type="BoxShape3D" id="BoxShape3D_v7wcs"] | ||
size = Vector3(5, 1, 3) | ||
|
||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_n2enf"] | ||
albedo_color = Color(1, 0.658824, 0.321569, 1) | ||
albedo_texture = ExtResource("1_qv1d7") | ||
|
||
[sub_resource type="BoxMesh" id="BoxMesh_m8cmi"] | ||
size = Vector3(5, 1, 3) | ||
|
||
[node name="Ramp" type="StaticBody3D"] | ||
|
||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] | ||
shape = SubResource("BoxShape3D_v7wcs") | ||
|
||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."] | ||
material_override = SubResource("StandardMaterial3D_n2enf") | ||
mesh = SubResource("BoxMesh_m8cmi") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[gd_scene load_steps=5 format=3 uid="uid://dpn6187qjqo75"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://rek0t7kubpx4" path="res://assets/pattern.png" id="1_mflpj"] | ||
|
||
[sub_resource type="BoxShape3D" id="BoxShape3D_r4qvg"] | ||
size = Vector3(5, 3, 0.5) | ||
|
||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_qi3if"] | ||
albedo_color = Color(0.690196, 0.556863, 0.909804, 1) | ||
albedo_texture = ExtResource("1_mflpj") | ||
uv1_scale = Vector3(3, 2, 1) | ||
|
||
[sub_resource type="BoxMesh" id="BoxMesh_ns54c"] | ||
material = SubResource("StandardMaterial3D_qi3if") | ||
size = Vector3(5, 3, 0.5) | ||
|
||
[node name="Wall" type="StaticBody3D"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0) | ||
|
||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] | ||
shape = SubResource("BoxShape3D_r4qvg") | ||
|
||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."] | ||
mesh = SubResource("BoxMesh_ns54c") | ||
skeleton = NodePath("../..") |
44 changes: 44 additions & 0 deletions
44
xr/openxr_character_centric_movement/openxr_action_map.tres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[gd_resource type="OpenXRActionMap" load_steps=9 format=3 uid="uid://dha3ympcdeka1"] | ||
|
||
[sub_resource type="OpenXRAction" id="OpenXRAction_f5o14"] | ||
resource_name = "aim_pose" | ||
localized_name = "Aim pose" | ||
action_type = 3 | ||
toplevel_paths = PackedStringArray("/user/hand/left", "/user/hand/right") | ||
|
||
[sub_resource type="OpenXRAction" id="OpenXRAction_xocvg"] | ||
resource_name = "haptic" | ||
localized_name = "Haptic" | ||
action_type = 4 | ||
toplevel_paths = PackedStringArray("/user/hand/left", "/user/hand/right", "/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") | ||
|
||
[sub_resource type="OpenXRAction" id="OpenXRAction_j46lb"] | ||
resource_name = "move" | ||
localized_name = "Move player" | ||
action_type = 2 | ||
toplevel_paths = PackedStringArray("/user/hand/right") | ||
|
||
[sub_resource type="OpenXRActionSet" id="OpenXRActionSet_jpkx2"] | ||
resource_name = "godot" | ||
localized_name = "Godot action set" | ||
actions = [SubResource("OpenXRAction_f5o14"), SubResource("OpenXRAction_xocvg"), SubResource("OpenXRAction_j46lb")] | ||
|
||
[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_i1vot"] | ||
action = SubResource("OpenXRAction_f5o14") | ||
paths = PackedStringArray("/user/hand/left/input/aim/pose", "/user/hand/right/input/aim/pose") | ||
|
||
[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_6t5tt"] | ||
action = SubResource("OpenXRAction_xocvg") | ||
paths = PackedStringArray("/user/hand/left/output/haptic", "/user/hand/right/output/haptic") | ||
|
||
[sub_resource type="OpenXRIPBinding" id="OpenXRIPBinding_a1aut"] | ||
action = SubResource("OpenXRAction_j46lb") | ||
paths = PackedStringArray("/user/hand/right/input/thumbstick") | ||
|
||
[sub_resource type="OpenXRInteractionProfile" id="OpenXRInteractionProfile_7f3ni"] | ||
interaction_profile_path = "/interaction_profiles/oculus/touch_controller" | ||
bindings = [SubResource("OpenXRIPBinding_i1vot"), SubResource("OpenXRIPBinding_6t5tt"), SubResource("OpenXRIPBinding_a1aut")] | ||
|
||
[resource] | ||
action_sets = [SubResource("OpenXRActionSet_jpkx2")] | ||
interaction_profiles = [SubResource("OpenXRInteractionProfile_7f3ni")] |
Oops, something went wrong.