Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard Detecting and Auto Pause #114

Open
wants to merge 12 commits into
base: Godot-3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
.DS_Store
logs
Thumbs.db
.vscode/
13 changes: 13 additions & 0 deletions demo/Construct.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ func _ready():
get_tree().get_root().connect("size_changed", self, "on_window_size_change")
on_window_size_change();


# Manually toggle pause
func _on_Pause_released():
get_tree().paused = !get_tree().paused

# If the dashboard is open, hide the player to avoid depth confusion
# The dashboard renders its own models for the controllers
func _on_PauseOnDashboard_dashboard_opened():
$Viewport/Main/Player.visible = false

# Restore our player when the dashboard closes
func _on_PauseOnDashboard_dashboard_closed():
$Viewport/Main/Player.visible = true
29 changes: 25 additions & 4 deletions demo/Construct.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=7 format=2]

[ext_resource path="res://Main.tscn" type="PackedScene" id=1]
[ext_resource path="res://Construct.gd" type="Script" id=2]
[ext_resource path="res://addons/godot-openvr/OpenVRFocus.gdns" type="Script" id=3]
[ext_resource path="res://addons/godot-openvr/OpenVRAction.gdns" type="Script" id=4]

[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
Expand All @@ -15,7 +17,6 @@ void fragment() {

COLOR = color;
}"
custom_defines = ""

[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
Expand Down Expand Up @@ -45,13 +46,33 @@ shadow_atlas_size = 4096

[node name="Main" parent="Viewport" instance=ExtResource( 1 )]

[node name="Player" parent="Viewport/Main" index="1"]
viewport = NodePath("../..")
[node name="Left_Hand" parent="Viewport/Main/Player" index="1"]
pause_mode = 1

[node name="Right_Hand" parent="Viewport/Main/Player" index="2"]
pause_mode = 1

[node name="ovr_left_hand" parent="Viewport/Main/Player" index="6"]
pause_mode = 1
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1.25, 0 )

[node name="ovr_right_hand" parent="Viewport/Main/Player" index="7"]
pause_mode = 1
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 1.25, 0 )

[node name="Pause" type="Node" parent="Viewport/Main"]
pause_mode = 2
script = ExtResource( 4 )
pressed_action = "/actions/godot/in/button_ax"
on_hand = 1

[node name="PauseOnDashboard" type="Node" parent="Viewport/Main"]
pause_mode = 2
script = ExtResource( 3 )
use_auto_pause = true

[connection signal="released" from="Viewport/Main/Pause" to="." method="_on_Pause_released"]
[connection signal="dashboard_closed" from="Viewport/Main/PauseOnDashboard" to="." method="_on_PauseOnDashboard_dashboard_closed"]
[connection signal="dashboard_opened" from="Viewport/Main/PauseOnDashboard" to="." method="_on_PauseOnDashboard_dashboard_opened"]

[editable path="Viewport/Main"]
8 changes: 8 additions & 0 deletions demo/addons/godot-openvr/OpenVRFocus.gdns
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="NativeScript" load_steps=2 format=2]

[ext_resource path="res://addons/godot-openvr/godot_openvr.gdnlib" type="GDNativeLibrary" id=1]

[resource]
resource_name = "OpenVRFocus"
class_name = "OpenVRFocus"
library = ExtResource( 1 )
Binary file modified demo/addons/godot-openvr/bin/win64/libgodot_openvr.dll
Binary file not shown.
1 change: 1 addition & 0 deletions demo/misc/Box.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ size = Vector3( 1, 1, 1 )
extents = Vector3( 0.5, 0.5, 0.5 )

[node name="Box" type="RigidBody"]
pause_mode = 1
collision_layer = 2
collision_mask = 2

Expand Down
1 change: 1 addition & 0 deletions demo/misc/Cup.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ radius = 0.06
height = 0.109788

[node name="Cup" instance=ExtResource( 1 )]
pause_mode = 1
collision_layer = 4
reset_transform_on_pickup = false
highlight_mesh_instance = NodePath("MeshInstance")
Expand Down
228 changes: 114 additions & 114 deletions demo/player/Guardian.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,119 +6,119 @@ var ws : float = 0.0
var reference : Transform = Transform()

func _ready():
# todo subscribe to our play area changed signal
pass
# todo subscribe to our play area changed signal
pass

func _process(delta):
# if either of these change, our play area needs to be adjusted.
var new_ws = ARVRServer.world_scale
var new_reference = ARVRServer.get_reference_frame()
if ws!=new_ws or reference!=new_reference:
var openvr_config = get_parent().get_openvr_config()
if !openvr_config:
# can't update this yet
return
if !openvr_config.play_area_available():
# can't update this yet
return
# get our play area, ws and our reference frame have already been applied
var play_area = openvr_config.get_play_area()
var h = Vector3(0.0, height, 0.0)
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
# floor
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2])
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[1])
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[3])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2])
# ceiling
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[1] + h)
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0] + h)
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2] + h)
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[3] + h)
# side A
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[1] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[0] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[1])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[1] + h)
# side B
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[3])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[0] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[3] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[3])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[0])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[0] + h)
# side C
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[1])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[1] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[1])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[2])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2] + h)
# side D
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[2])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[3] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[2] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[2])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[3])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[3] + h)
st.generate_normals()
st.generate_tangents()
# we've updated it
mesh = st.commit()
ws = new_ws
reference = new_reference
# if either of these change, our play area needs to be adjusted.
var new_ws = ARVRServer.world_scale
var new_reference = ARVRServer.get_reference_frame()
if ws!=new_ws or reference!=new_reference:
var openvr_config = get_parent().get_openvr_config()
if !openvr_config:
# can't update this yet
return
if !openvr_config.play_area_available():
# can't update this yet
return
# get our play area, ws and our reference frame have already been applied
var play_area = openvr_config.get_play_area()
var h = Vector3(0.0, height, 0.0)
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
# floor
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2])
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[1])
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[3])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2])
# ceiling
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[1] + h)
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0] + h)
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2] + h)
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[3] + h)
# side A
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[1] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[0] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[0])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[1])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[1] + h)
# side B
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[3])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[0] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[3] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[3])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[0])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[0] + h)
# side C
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[1])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[1] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[1])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[2])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[2] + h)
# side D
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[2])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[3] + h)
st.add_uv(Vector2(1,0))
st.add_vertex(play_area[2] + h)
st.add_uv(Vector2(0,0))
st.add_vertex(play_area[2])
st.add_uv(Vector2(0,1))
st.add_vertex(play_area[3])
st.add_uv(Vector2(1,1))
st.add_vertex(play_area[3] + h)
st.generate_normals()
st.generate_tangents()
# we've updated it
mesh = st.commit()
ws = new_ws
reference = new_reference
1 change: 1 addition & 0 deletions src/godot_openvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ void GDN_EXPORT godot_openvr_nativescript_init(void *p_handle) {
godot::register_class<godot::OpenVRHaptics>();
godot::register_class<godot::OpenVRController>();
godot::register_class<godot::OpenVRSkeleton>();
godot::register_class<godot::OpenVRFocus>();
}
1 change: 1 addition & 0 deletions src/godot_openvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "OpenVRPose.h"
#include "OpenVRRenderModel.h"
#include "OpenVRSkeleton.h"
#include "OpenVRFocus.h"

#ifdef __cplusplus
extern "C" {
Expand Down
Loading