~sircmpwn/gdwlroots

07803cabba84175954dd129338ef18c5dba5b9e5 — Drew DeVault 9 months ago ba79e80
Move threeston into VR
A threeston/.gitattributes => threeston/.gitattributes +6 -0
@@ 0,0 1,6 @@
*.gd eol=lf
*.tscn eol=lf
*.cfg eol=lf
*.godot eol=lf
*.tres eol=lf
*.import eol=lf

A threeston/.gitignore => threeston/.gitignore +10 -0
@@ 0,0 1,10 @@
*.o
*.os
.import/
*.dblite
*.exp
*.lib
*.obj
*.TMP
logs
Thumbs.db

A threeston/CHANGES.md => threeston/CHANGES.md +20 -0
@@ 0,0 1,20 @@
Changes to the Godot OpenVR asset
=================================

Note, version numbers listed here are the version number assigned to the asset. Each time a new version is uploaded to the asset store we will increase the version number.
More frequent updates may be available on the source repository.

1.0.4 - 27 March 2019
---------------------
- Build for Godot 3.1
- Now using OpenVR 1.2.10
- Added Mac binaries (untested)

1.0.3 - 23 June 2018
--------------------
- Now using OpenVR 1.0.15
- Fixed crash issue related to new reloadable property in GDNative

1.0.2 - 4 May 2018
------------------
Changes were not tracked

A threeston/addons/godot-openvr/OpenVRRenderModel.gdns => threeston/addons/godot-openvr/OpenVRRenderModel.gdns +11 -0
@@ 0,0 1,11 @@
[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 = "OpenVRRenderModel"
class_name = "OpenVRRenderModel"
library = ExtResource( 1 )
_sections_unfolded = [ "Resource" ]


A threeston/addons/godot-openvr/bin/LICENSE => threeston/addons/godot-openvr/bin/LICENSE +27 -0
@@ 0,0 1,27 @@
Copyright (c) 2015, Valve Corporation
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

A threeston/addons/godot-openvr/bin/osx/libgodot_openvr.dylib => threeston/addons/godot-openvr/bin/osx/libgodot_openvr.dylib +0 -0

A threeston/addons/godot-openvr/bin/osx/libopenvr_api.dylib => threeston/addons/godot-openvr/bin/osx/libopenvr_api.dylib +0 -0

A threeston/addons/godot-openvr/bin/win64/godot_openvr.dll => threeston/addons/godot-openvr/bin/win64/godot_openvr.dll +0 -0

A threeston/addons/godot-openvr/bin/win64/openvr_api.dll => threeston/addons/godot-openvr/bin/win64/openvr_api.dll +0 -0

A threeston/addons/godot-openvr/bin/x11/libgodot_openvr.so => threeston/addons/godot-openvr/bin/x11/libgodot_openvr.so +0 -0

A threeston/addons/godot-openvr/bin/x11/libopenvr_api.so => threeston/addons/godot-openvr/bin/x11/libopenvr_api.so +0 -0

A threeston/addons/godot-openvr/godot_openvr.gdnlib => threeston/addons/godot-openvr/godot_openvr.gdnlib +20 -0
@@ 0,0 1,20 @@
[general]

singleton=true
load_once=true
symbol_prefix="godot_openvr_"
reloadable=false

[entry]

X11.64="res://addons/godot-openvr/bin/x11/libgodot_openvr.so"
Windows.32="res://addons/godot-openvr/bin/win32/godot_openvr.dll"
Windows.64="res://addons/godot-openvr/bin/win64/godot_openvr.dll"
OSX.64="res://addons/godot-openvr/bin/osx/libgodot_openvr.dylib"

[dependencies]

X11.64=[ "res://addons/godot-openvr/bin/x11/libopenvr_api.so" ]
Windows.32=[ "res://addons/godot-openvr/bin/win32/openvr_api.dll" ]
Windows.64=[ "res://addons/godot-openvr/bin/win64/openvr_api.dll" ]
OSX.64=[ "res://addons/godot-openvr/bin/osx/libopenvr_api.dylib" ]

A threeston/addons/godot-openvr/icon.png => threeston/addons/godot-openvr/icon.png +0 -0

A threeston/addons/godot-openvr/icon.png.import => threeston/addons/godot-openvr/icon.png.import +34 -0
@@ 0,0 1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/icon.png-a89ecb8be28ea6c50eeae0c3cb0cd271.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/godot-openvr/icon.png"
dest_files=[ "res://.import/icon.png-a89ecb8be28ea6c50eeae0c3cb0cd271.stex" ]

[params]

compress/mode=0
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
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

A threeston/addons/godot-openvr/scenes/framecounter_in_3d.tscn => threeston/addons/godot-openvr/scenes/framecounter_in_3d.tscn +112 -0
@@ 0,0 1,112 @@
[gd_scene load_steps=5 format=2]

[sub_resource type="PlaneMesh" id=1]

size = Vector2( 0.3, 0.15 )
subdivide_width = 10
subdivide_depth = 10

[sub_resource type="Shader" id=2]

code = "shader_type spatial;
render_mode unshaded;

uniform sampler2D viewport_texture : hint_albedo;

void vertex() {
	VERTEX.y = 1.0 - cos(VERTEX.x + 0.3) * 0.5 - cos(VERTEX.z + 0.15) * 0.5;
}

void fragment() {
	vec4 col = texture(viewport_texture, vec2(1.0-UV.x, UV.y));
	ALBEDO = col.rgb;
	ALPHA = col.a;
}"

[sub_resource type="ShaderMaterial" id=3]

render_priority = 0
shader = SubResource( 2 )
_sections_unfolded = [ "Resource", "shader_param" ]

[sub_resource type="GDScript" id=4]

script/source = "extends MeshInstance

func _ready():
	get_surface_material(0).set_shader_param(\"viewport_texture\", $Viewport.get_texture())

func _process(delta):
	$Viewport/World/Label.text = str(Engine.get_frames_per_second()) + \" FPS\""

[node name="FPS" type="MeshInstance" index="0"]

transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
layers = 1
material_override = null
cast_shadow = 1
extra_cull_margin = 0.0
use_in_baked_light = false
lod_min_distance = 0.0
lod_min_hysteresis = 0.0
lod_max_distance = 0.0
lod_max_hysteresis = 0.0
mesh = SubResource( 1 )
skeleton = NodePath("..")
material/0 = SubResource( 3 )
script = SubResource( 4 )
_sections_unfolded = [ "Transform", "material" ]

[node name="Viewport" type="Viewport" parent="." index="0"]

arvr = false
size = Vector2( 200, 100 )
own_world = false
world = null
transparent_bg = true
msaa = 0
hdr = false
disable_3d = false
usage = 0
debug_draw = 0
render_target_v_flip = false
render_target_clear_mode = 0
render_target_update_mode = 3
audio_listener_enable_2d = false
audio_listener_enable_3d = false
physics_object_picking = false
gui_disable_input = false
gui_snap_controls_to_pixels = true
shadow_atlas_size = 0
shadow_atlas_quad_0 = 2
shadow_atlas_quad_1 = 2
shadow_atlas_quad_2 = 3
shadow_atlas_quad_3 = 4
_sections_unfolded = [ "Render Target", "Rendering" ]

[node name="World" type="Node2D" parent="Viewport" index="0"]

_sections_unfolded = [ "Transform", "Z" ]

[node name="Label" type="Label" parent="Viewport/World" index="0"]

anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 200.0
margin_bottom = 100.0
rect_scale = Vector2( 3, 3 )
rect_pivot_offset = Vector2( 0, 0 )
mouse_filter = 2
size_flags_horizontal = 1
size_flags_vertical = 4
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_shadow = Color( 0, 0, 0, 1 )
text = "FPS"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Anchor", "Grow Direction", "Margin", "Material", "Rect", "Visibility", "custom_colors" ]



A threeston/addons/godot-openvr/scenes/ovr_controller.tscn => threeston/addons/godot-openvr/scenes/ovr_controller.tscn +79 -0
@@ 0,0 1,79 @@
[gd_scene load_steps=2 format=2]

[sub_resource type="GDScript" id=1]

script/source = "extends ARVRController

signal controller_activated(controller)

var ovr_render_model
var components = Array()
var ws = 0

func _ready():
	# instance our render model object
	ovr_render_model = preload(\"res://addons/godot-openvr/OpenVRRenderModel.gdns\").new()
	
	# hide to begin with
	visible = false

func apply_world_scale():
	var new_ws = ARVRServer.world_scale
	if (ws != new_ws):
		ws = new_ws
		$Controller_mesh.scale = Vector3(ws, ws, ws)

func load_controller_mesh(controller_name):
	if ovr_render_model.load_model(controller_name.substr(0, controller_name.length()-2)):
		return ovr_render_model
	
	if ovr_render_model.load_model(\"generic_controller\"):
		return ovr_render_model
	
	return Mesh.new()

func _process(delta):
	if !get_is_active():
		visible = false
		return
	
	# always set our world scale, user may end up changing this
	apply_world_scale()
	
	if visible:
		return
	
	# became active? lets handle it...
	var controller_name = get_controller_name()
	print(\"Controller \" + controller_name + \" became active\")
			
	# attempt to load a mesh for this
	$Controller_mesh.mesh = load_controller_mesh(controller_name)
			
	# make it visible
	visible = true
	emit_signal(\"controller_activated\", self)
"

[node name="OVRController" type="ARVRController" index="0"]

controller_id = 1
rumble = 0.0
script = SubResource( 1 )
_sections_unfolded = [ "Transform" ]

[node name="Controller_mesh" type="MeshInstance" parent="." index="0"]

layers = 1
material_override = null
cast_shadow = 1
extra_cull_margin = 0.0
use_in_baked_light = false
lod_min_distance = 0.0
lod_min_hysteresis = 0.0
lod_max_distance = 0.0
lod_max_hysteresis = 0.0
mesh = null
skeleton = NodePath("..")



A threeston/addons/godot-openvr/scenes/ovr_first_person.tscn => threeston/addons/godot-openvr/scenes/ovr_first_person.tscn +55 -0
@@ 0,0 1,55 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://addons/vr-common/misc/VR_Common_Shader_Cache.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_controller.tscn" type="PackedScene" id=2]

[sub_resource type="PlaneMesh" id=1]
size = Vector2( 0.001, 0.001 )

[sub_resource type="SpatialMaterial" id=2]

[sub_resource type="GDScript" id=3]
script/source = "extends Spatial

func _physics_process(delta):
	# we keep this in line with our camera but we remove the tilt
	var new_transform = get_node(\"../ARVRCamera\").transform
	
	var new_basis = Basis()
	new_basis.z = Vector3(new_transform.basis.z.x, 0.0, new_transform.basis.z.z).normalized()
	if new_basis.z.length() > 0.5:
		new_basis.y - Vector3(0.0, 1.0, 0.0)
		new_basis.x = new_basis.y.cross(new_basis.z)
		new_transform.basis = new_basis
	
		transform = new_transform
	else:
		# we're looking straight up or down, ignore this
		pass"

[node name="OVRFirstPerson" type="ARVROrigin"]

[node name="ARVRCamera" type="ARVRCamera" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.85, 0 )
fov = 65.0
near = 0.01
far = 1000.01

[node name="shader_cache" parent="ARVRCamera" instance=ExtResource( 1 )]

[node name="Controller" type="MeshInstance" parent="ARVRCamera/shader_cache"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -2 )
mesh = SubResource( 1 )
material/0 = SubResource( 2 )

[node name="HUD_Anchor" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.85, 0 )
script = SubResource( 3 )

[node name="Left_Hand" parent="." instance=ExtResource( 2 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1.25, 0 )

[node name="Right_Hand" parent="." instance=ExtResource( 2 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 1.25, 0 )
controller_id = 2


M threeston/prefabs/surface/Surface_Node2D.gd => threeston/prefabs/surface/Surface_Node2D.gd +1 -0
@@ 35,6 35,7 @@ func _draw_surface(surface, sx, sy):
	if texture == null:
		return
	var state = xdg_surface.get_wlr_surface().get_current_state()
	draw_rect(Rect2(0, 0, get_viewport().size.x, get_viewport().size.y), Color.red)
	draw_texture(texture, Vector2(0, 0))
	surface.send_frame_done()


M threeston/project.godot => threeston/project.godot +4 -0
@@ 19,6 19,10 @@ config/name="First_Person_Character"
run/main_scene="res://scenes/Main.tscn"
config/icon="res://icon_fpc.PNG"

[gdnative]

singletons=[ "res://addons/godot-openvr/godot_openvr.gdnlib" ]

[input]

space={

M threeston/scenes/Game_Manager.gd => threeston/scenes/Game_Manager.gd +12 -11
@@ 6,6 6,12 @@ onready var spawn_point = $Spawn_Point

func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	var VR = ARVRServer.find_interface("OpenVR")
	if VR and VR.initialize():
		get_viewport().arvr = true
		get_viewport().hdr = false
		OS.vsync_enabled = false
		Engine.target_fps = 90
	var display = $WaylandDisplay
	display.run()



@@ 22,6 28,7 @@ func _on_WlrXdgShell_new_surface(xdg_surface):
	if xdg_surface.get_role() != WlrXdgSurface.XDG_SURFACE_ROLE_TOPLEVEL:
		return
	var surface = Surface.instance()
	surface.set_scale(Vector3(0.1, 0.1, 0.1)) # Resize to approximate human scales
	surface.xdg_surface = xdg_surface
	surface.connect("map", self, "_on_surface_map")
	surface.connect("unmap", self, "_on_surface_unmap")


@@ 33,19 40,13 @@ func _on_surface_map(surface):
	var wlr_surface = surface.xdg_surface.get_wlr_surface()
	wlr_surface.send_enter($WaylandDisplay/WlrBackend/WlrOutput)
	var state = wlr_surface.get_current_state()
	var z = tan(deg2rad($Player/Camera.fov)) * (state.get_width() / state.get_scale()) / 2
	var z = tan(deg2rad($ARVROrigin/ARVRCamera.fov)) * (state.get_width() / state.get_scale()) / 2
	z = get_viewport().size.x / z
	var pos = $Player/Camera.to_global(Vector3(0, 0, -z))
	surface.transform = (
		Transform.translated(pos) *
		Transform.rotated(Vector3(0, 1, 0), $Player.rotation.y) *
		Transform.rotated(Vector3(1, 0, 0), $Player/Camera.rotation.x))
	var pos = $ARVROrigin/ARVRCamera.to_global(Vector3(0, 0, -z))
	surface.set_translation(pos)
	surface.set_rotation(Vector3(
		$ARVROrigin/ARVRCamera.rotation.x, $ARVROrigin/ARVRCamera.rotation.y, 0))
	add_child(surface)
	
func _on_surface_unmap(surface):
	remove_child(surface)






M threeston/scenes/Main.tscn => threeston/scenes/Main.tscn +12 -1
@@ 1,10 1,11 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 format=2]

[ext_resource path="res://scenes/Game_Manager.gd" type="Script" id=1]
[ext_resource path="res://prefabs/player_demo/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://sprites/crosshair.png" type="Texture" id=3]
[ext_resource path="res://prefabs/environment/Environment.tscn" type="PackedScene" id=4]
[ext_resource path="res://prefabs/player_demo/bullet_mat.tres" type="Material" id=5]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_controller.tscn" type="PackedScene" id=6]

[sub_resource type="BoxShape" id=1]
extents = Vector3( 300, 1, 300 )


@@ 59,8 60,18 @@ material/0 = ExtResource( 5 )
[node name="WlrSeat" type="WlrSeat" parent="WaylandDisplay"]

[node name="WlrXdgShell" type="WlrXdgShell" parent="WaylandDisplay"]

[node name="ARVROrigin" type="ARVROrigin" parent="."]

[node name="ARVRCamera" type="ARVRCamera" parent="ARVROrigin"]

[node name="LeftContrller" parent="ARVROrigin" instance=ExtResource( 6 )]

[node name="RightController" parent="ARVROrigin" instance=ExtResource( 6 )]
controller_id = 2
[connection signal="body_entered" from="Dead_Zone" to="." method="_on_Dead_Zone_body_entered"]
[connection signal="new_surface" from="WaylandDisplay/WlrXdgShell" to="." method="_on_WlrXdgShell_new_surface"]
[connection signal="button_pressed" from="ARVROrigin/RightController" to="." method="_on_RightController_button_pressed"]

[editable path="Environment"]