Skip to content

Commit

Permalink
Merge pull request #93 from BastiaanOlij/update_to_godot_xr_tools
Browse files Browse the repository at this point in the history
Updated from the old vr-common library to the new godot-xr-tools library
  • Loading branch information
BastiaanOlij authored May 23, 2020
2 parents f1296c9 + e48a8aa commit d259a25
Show file tree
Hide file tree
Showing 41 changed files with 584 additions and 230 deletions.
22 changes: 16 additions & 6 deletions demo/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
[gd_scene load_steps=26 format=2]
[gd_scene load_steps=27 format=2]

[ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://assets/wahooney.itch.io/green_grid.tres" type="Material" id=2]
[ext_resource path="res://addons/vr-common/misc/VR_Common_Shader_Cache.tscn" type="PackedScene" id=3]
[ext_resource path="res://addons/godot-xr-tools/misc/VR_Common_Shader_Cache.tscn" type="PackedScene" id=3]
[ext_resource path="res://misc/Table.tscn" type="PackedScene" id=4]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_controller.tscn" type="PackedScene" id=5]
[ext_resource path="res://addons/vr-common/functions/Function_Direct_movement.tscn" type="PackedScene" id=6]
[ext_resource path="res://addons/vr-common/functions/Function_Teleport.tscn" type="PackedScene" id=7]
[ext_resource path="res://addons/godot-xr-tools/functions/Function_Direct_movement.tscn" type="PackedScene" id=6]
[ext_resource path="res://addons/godot-xr-tools/functions/Function_Teleport.tscn" type="PackedScene" id=7]
[ext_resource path="res://misc/Box.tscn" type="PackedScene" id=8]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_render_model.tscn" type="PackedScene" id=9]
[ext_resource path="res://addons/vr-common/objects/Viewport_2D_in_3D.tscn" type="PackedScene" id=10]
[ext_resource path="res://addons/godot-xr-tools/objects/Viewport_2D_in_3D.tscn" type="PackedScene" id=10]
[ext_resource path="res://player/ButtonStates.tscn" type="PackedScene" id=11]
[ext_resource path="res://addons/godot-openvr/OpenVRController.gdns" type="Script" id=12]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_main.gd" type="Script" id=13]
[ext_resource path="res://addons/godot-openvr/OpenVRPose.gdns" type="Script" id=14]
[ext_resource path="res://misc/SmallCube.tscn" type="PackedScene" id=15]
[ext_resource path="res://player/HandInteraction.tscn" type="PackedScene" id=16]
[ext_resource path="res://addons/vr-common/functions/Function_Pickup.tscn" type="PackedScene" id=17]
[ext_resource path="res://addons/godot-xr-tools/functions/Function_Pickup.tscn" type="PackedScene" id=17]
[ext_resource path="res://addons/godot-openvr/OpenVRAction.gdns" type="Script" id=18]
[ext_resource path="res://player/Guardian.tscn" type="PackedScene" id=19]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_left_hand.tscn" type="PackedScene" id=20]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_right_hand.tscn" type="PackedScene" id=21]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_shader_cache.tscn" type="PackedScene" id=22]
[ext_resource path="res://misc/Cup.tscn" type="PackedScene" id=23]

[sub_resource type="ArrayMesh" id=1]

Expand Down Expand Up @@ -138,6 +139,15 @@ shape = SubResource( 3 )
[node name="SmallCube" parent="Misc/Table" instance=ExtResource( 15 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.16215, 0.429381 )

[node name="Cup01" parent="Misc/Table" instance=ExtResource( 23 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.264883, 1.1647, 0.494545 )

[node name="Cup02" parent="Misc/Table" instance=ExtResource( 23 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.435989, 1.1647, 0.494545 )

[node name="Cup03" parent="Misc/Table" instance=ExtResource( 23 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.581078, 1.1647, 0.494545 )

[node name="Box01" parent="Misc" instance=ExtResource( 8 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 1, -4 )

Expand Down
12 changes: 10 additions & 2 deletions demo/addons/godot-openvr/scenes/ovr_main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export (String) var default_action_set = "/actions/godot"
# If we render to a custom viewport give our node path here.
export (NodePath) var viewport = null

# Convenience setting for setting physics update rate to a multiple of our HMDs frame rate (set to 0 to ignore)
export var physics_factor = 2

var arvr_interface : ARVRInterface = null
var openvr_config = null

Expand All @@ -34,6 +37,10 @@ func _ready():
# Find the interface and initialise
arvr_interface = ARVRServer.find_interface("OpenVR")
if arvr_interface and arvr_interface.initialize():
# We can't query our HMDs refresh rate just yet so we hardcode this to 90
var refresh_rate = 90

# check our viewport
var vp : Viewport = null
if viewport:
vp = get_node(viewport)
Expand All @@ -56,6 +63,7 @@ func _ready():
# make sure vsync is disabled or we'll be limited to 60fps
OS.vsync_enabled = false

# up our physics to 90fps to get in sync with our rendering
Engine.iterations_per_second = 90
if physics_factor > 0:
# Set our physics to a multiple of our refresh rate to get in sync with our rendering
Engine.iterations_per_second = refresh_rate * physics_factor

13 changes: 13 additions & 0 deletions demo/addons/godot-xr-tools/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Contributors
============

The main author of this project is [Bastiaan Olij](https://github.com/BastiaanOlij) who manages the source repository found at:
https://github.com/GodotVR/godot-xr-tools

Other people who have helped out by submitting fixes, enhancements, etc are:
- [Florian Jung](https://github.com/Windfisch)
- [RMKD](https://github.com/RMKD)
- [Alessandro Schillaci](https://github.com/silverslade)
- [jtank4](https://github.com/jtank4)

Want to be on this list? We would love your help.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2019 Bastiaan Olij
Copyright (c) 2018-2020 Bastiaan Olij

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 30 additions & 0 deletions demo/addons/godot-xr-tools/VERSIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
2.1 (in progress)
=================
- added option to highlight object that can be picked up
- added option to snap object to given location (if reset transform is true)

2.0
===
- Renamed add on to **godot-xr-tools**
- Add enums to our export variables
- Add a switch on pickable objects to keep their current positioning when picked up
- Move direct movement player collision slightly backwards based on player radius
- Added switch between step turning and smooth turning
- Fixed sizing issue with teleport
- Added option to change pickup range

1.2
===
- Assign button to teleport function and no longer need to set origin
- Added pickable object support
- Fixed positioning of direct movement collision shape
- Added strafe and fly mode for directional
- Added ability to enable/disable the movement functions
- Added 2D in 3D viewport for UI
- Improved throwing by assigning linear velocity

1.1*
====
- previous versions were not tracked

* Note that version history before 1.2 was not kept and is thus incomplete
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,39 @@ export (NodePath) var camera = null
export var player_radius = 0.4 setget set_player_radius, get_player_radius

# to combat motion sickness we'll 'step' our left/right turning
export var turn_delay = 0.2
export var turn_angle = 20.0
export var smooth_rotation = false
export var smooth_turn_speed = 2.0
export var step_turn_delay = 0.2
export var step_turn_angle = 20.0

# and movement
export var max_speed = 5.0
export var drag_factor = 0.1

# enum our buttons, should find a way to put this more central
enum Buttons {
VR_BUTTON_BY = 1,
VR_GRIP = 2,
VR_BUTTON_3 = 3,
VR_BUTTON_4 = 4,
VR_BUTTON_5 = 5,
VR_BUTTON_6 = 6,
VR_BUTTON_AX = 7,
VR_BUTTON_8 = 8,
VR_BUTTON_9 = 9,
VR_BUTTON_10 = 10,
VR_BUTTON_11 = 11,
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15
}

# fly mode and strafe movement management
export (MOVEMENT_TYPE) var move_type = MOVEMENT_TYPE.MOVE_AND_ROTATE
export var canFly = true
export var fly_move_button_id = 15
export var fly_activate_button_id = 2
export (Buttons) var fly_move_button_id = Buttons.VR_TRIGGER
export (Buttons) var fly_activate_button_id = Buttons.VR_GRIP
var isflying = false

var turn_step = 0.0
Expand All @@ -32,6 +55,13 @@ var gravity = -30.0
onready var collision_shape: CollisionShape = get_node("KinematicBody/CollisionShape")
onready var tail : RayCast = get_node("KinematicBody/Tail")

# Set our collision layer (need to change this once we can add the proper UI)
export (int, FLAGS, "Layer 1", "Layer 2", "Layer 3", "Layer 4", "Layer 5", "Layer 6", "Layer 7", "Layer 8", "Layer 9", "Layer 10", "Layer 11", "Layer 12", "Layer 13", "Layer 14", "Layer 15", "Layer 16", "Layer 17", "Layer 18", "Layer 19", "Layer 20") var collision_layer = 1 setget set_collision_layer, get_collision_layer

# Set our collision mask (need to change this once we can add the proper UI)
export (int, FLAGS, "Layer 1", "Layer 2", "Layer 3", "Layer 4", "Layer 5", "Layer 6", "Layer 7", "Layer 8", "Layer 9", "Layer 10", "Layer 11", "Layer 12", "Layer 13", "Layer 14", "Layer 15", "Layer 16", "Layer 17", "Layer 18", "Layer 19", "Layer 20") var collision_mask = 1022 setget set_collision_mask, get_collision_mask


func set_enabled(new_value):
enabled = new_value
if collision_shape:
Expand All @@ -48,6 +78,23 @@ func set_enabled(new_value):
func get_enabled():
return enabled

func set_collision_layer(new_layer):
collision_layer = new_layer
if $KinematicBody:
$KinematicBody.collision_layer = collision_layer

func get_collision_layer():
return collision_layer

func set_collision_mask(new_mask):
collision_mask = new_mask
if $KinematicBody:
$KinematicBody.collision_mask = collision_mask
$KinematicBody/Tail.collision_mask = collision_mask

func get_collision_mask():
return collision_mask

func get_player_radius():
return player_radius

Expand All @@ -64,6 +111,9 @@ func _ready():
# see if we can find our default
camera_node = origin_node.get_node('ARVRCamera')

# Our properties are set before our children are constructed so just re-issue
set_collision_layer(collision_layer)
set_collision_mask(collision_mask)
set_player_radius(player_radius)

collision_shape.disabled = !enabled
Expand Down Expand Up @@ -118,39 +168,54 @@ func _physics_process(delta):
# move_type == MOVEMENT_TYPE.move_and_strafe
else:
if(move_type == MOVEMENT_TYPE.MOVE_AND_ROTATE && abs(left_right) > 0.1):
if left_right > 0.0:
if turn_step < 0.0:
# reset step
turn_step = 0

turn_step += left_right * delta
else:
if turn_step > 0.0:
# reset step
turn_step = 0

turn_step += left_right * delta

if abs(turn_step) > turn_delay:
if smooth_rotation:
# we rotate around our Camera, but we adjust our origin, so we need a little bit of trickery
var t1 = Transform()
var t2 = Transform()
var rot = Transform()

t1.origin = -camera_node.transform.origin
t2.origin = camera_node.transform.origin

# Rotating
while abs(turn_step) > turn_delay:
if (turn_step > 0.0):
rot = rot.rotated(Vector3(0.0,-1.0,0.0),turn_angle * PI / 180.0)
turn_step -= turn_delay
else:
rot = rot.rotated(Vector3(0.0,1.0,0.0),turn_angle * PI / 180.0)
turn_step += turn_delay

rot = rot.rotated(Vector3(0.0, -1.0, 0.0), smooth_turn_speed * delta * left_right)
origin_node.transform *= t2 * rot * t1

# reset turn step, doesn't apply
turn_step = 0.0
else:
if left_right > 0.0:
if turn_step < 0.0:
# reset step
turn_step = 0

turn_step += left_right * delta
else:
if turn_step > 0.0:
# reset step
turn_step = 0

turn_step += left_right * delta

if abs(turn_step) > step_turn_delay:
# we rotate around our Camera, but we adjust our origin, so we need a little bit of trickery
var t1 = Transform()
var t2 = Transform()
var rot = Transform()

t1.origin = -camera_node.transform.origin
t2.origin = camera_node.transform.origin

# Rotating
while abs(turn_step) > step_turn_delay:
if (turn_step > 0.0):
rot = rot.rotated(Vector3(0.0, -1.0, 0.0), step_turn_angle * PI / 180.0)
turn_step -= step_turn_delay
else:
rot = rot.rotated(Vector3(0.0, 1.0, 0.0), step_turn_angle * PI / 180.0)
turn_step += step_turn_delay

origin_node.transform *= t2 * rot * t1
else:
# reset turn step, no longer turning
turn_step = 0.0

################################################################
Expand All @@ -161,6 +226,13 @@ func _physics_process(delta):
var camera_transform = camera_node.global_transform
curr_transform.origin = camera_transform.origin
curr_transform.origin.y = origin_node.global_transform.origin.y

# now we move it slightly back
var forward_dir = -camera_transform.basis.z
forward_dir.y = 0.0
if forward_dir.length() > 0.01:
curr_transform.origin += forward_dir.normalized() * -0.75 * player_radius

$KinematicBody.global_transform = curr_transform

# we'll handle gravity separately
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://addons/vr-common/functions/Function_Direct_movement.gd" type="Script" id=1]
[ext_resource path="res://addons/godot-xr-tools/functions/Function_Direct_movement.gd" type="Script" id=1]


[sub_resource type="CapsuleShape" id=1]
radius = 0.3
Expand Down
Loading

0 comments on commit d259a25

Please sign in to comment.