ggj2020

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.hellocld.com/ggj2020
Log | Files | Refs

commit 92722f404387149c8645f3d4afeb64af00b45d4f
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Fri, 31 Jan 2020 14:32:17 -0500

Init commit

Imported all the OpenVR stuff ahead of jamming so I'm good to, um, jam.

Diffstat:
A.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 | 3+++
A.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex | 0
A.import/icon.png-a89ecb8be28ea6c50eeae0c3cb0cd271.md5 | 3+++
A.import/icon.png-a89ecb8be28ea6c50eeae0c3cb0cd271.stex | 0
A.import/icon.png-fb3b2ecb55ac1327d82f6710eba4f8b4.md5 | 3+++
A.import/icon.png-fb3b2ecb55ac1327d82f6710eba4f8b4.stex | 0
A.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.etc.stex | 0
A.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.md5 | 3+++
A.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.s3tc.stex | 0
A.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.etc.stex | 0
A.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.md5 | 3+++
A.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.s3tc.stex | 0
Aaddons/godot-openvr/OpenVRConfig.gdns | 8++++++++
Aaddons/godot-openvr/OpenVROverlay.gdns | 8++++++++
Aaddons/godot-openvr/OpenVRRenderModel.gdns | 11+++++++++++
Aaddons/godot-openvr/bin/LICENSE | 27+++++++++++++++++++++++++++
Aaddons/godot-openvr/bin/osx/libgodot_openvr.dylib | 0
Aaddons/godot-openvr/bin/osx/libopenvr_api.dylib | 0
Aaddons/godot-openvr/bin/win64/libgodot_openvr.dll | 0
Aaddons/godot-openvr/bin/win64/openvr_api.dll | 0
Aaddons/godot-openvr/bin/x11/libgodot_openvr.so | 0
Aaddons/godot-openvr/bin/x11/libopenvr_api.so | 0
Aaddons/godot-openvr/godot_openvr.gdnlib | 20++++++++++++++++++++
Aaddons/godot-openvr/icon.png | 0
Aaddons/godot-openvr/icon.png.import | 34++++++++++++++++++++++++++++++++++
Aaddons/godot-openvr/scenes/framecounter_in_3d.tscn | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aaddons/godot-openvr/scenes/ovr_controller.gd | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aaddons/godot-openvr/scenes/ovr_controller.tscn | 8++++++++
Aaddons/godot-openvr/scenes/ovr_first_person.tscn | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/VERSIONS.md | 12++++++++++++
Aaddons/vr-common/functions/Function_Direct_movement.gd | 176+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/functions/Function_Direct_movement.tscn | 24++++++++++++++++++++++++
Aaddons/vr-common/functions/Function_Pickup.gd | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/functions/Function_Pickup.tscn | 15+++++++++++++++
Aaddons/vr-common/functions/Function_Teleport.gd | 245+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/functions/Function_Teleport.tscn | 39+++++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/functions/Function_pointer.tscn | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/images/icon.png | 0
Aaddons/vr-common/images/icon.png.import | 34++++++++++++++++++++++++++++++++++
Aaddons/vr-common/images/teleport_arrow.png | 0
Aaddons/vr-common/images/teleport_arrow.png.import | 36++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/images/teleport_target.png | 0
Aaddons/vr-common/images/teleport_target.png.import | 36++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/materials/capule.tres | 7+++++++
Aaddons/vr-common/materials/pointer.tres | 7+++++++
Aaddons/vr-common/materials/target.tres | 12++++++++++++
Aaddons/vr-common/materials/teleport.shader | 39+++++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/materials/teleport.tres | 13+++++++++++++
Aaddons/vr-common/misc/VR_Common_Shader_Cache.gd | 10++++++++++
Aaddons/vr-common/misc/VR_Common_Shader_Cache.tscn | 34++++++++++++++++++++++++++++++++++
Aaddons/vr-common/objects/Object_pickable.gd | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aaddons/vr-common/objects/Object_pickable.tscn | 10++++++++++
Adefault_env.tres | 5+++++
Aicon.png | 0
Aicon.png.import | 34++++++++++++++++++++++++++++++++++
Aproject.godot | 30++++++++++++++++++++++++++++++
56 files changed, 1449 insertions(+), 0 deletions(-)

diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 @@ -0,0 +1,3 @@ +source_md5="0167658bc4406f0d0fe437e0197c415a" +dest_md5="64b0613b3173e1e1c96dd18b6569e62d" + diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex Binary files differ. diff --git a/.import/icon.png-a89ecb8be28ea6c50eeae0c3cb0cd271.md5 b/.import/icon.png-a89ecb8be28ea6c50eeae0c3cb0cd271.md5 @@ -0,0 +1,3 @@ +source_md5="eafe02953c96cfe709ce402d99f14cc0" +dest_md5="62eccb88defcbb143c9e800ea785a081" + diff --git a/.import/icon.png-a89ecb8be28ea6c50eeae0c3cb0cd271.stex b/.import/icon.png-a89ecb8be28ea6c50eeae0c3cb0cd271.stex Binary files differ. diff --git a/.import/icon.png-fb3b2ecb55ac1327d82f6710eba4f8b4.md5 b/.import/icon.png-fb3b2ecb55ac1327d82f6710eba4f8b4.md5 @@ -0,0 +1,3 @@ +source_md5="eafe02953c96cfe709ce402d99f14cc0" +dest_md5="62eccb88defcbb143c9e800ea785a081" + diff --git a/.import/icon.png-fb3b2ecb55ac1327d82f6710eba4f8b4.stex b/.import/icon.png-fb3b2ecb55ac1327d82f6710eba4f8b4.stex Binary files differ. diff --git a/.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.etc.stex b/.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.etc.stex Binary files differ. diff --git a/.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.md5 b/.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.md5 @@ -0,0 +1,3 @@ +source_md5="9ea03e433db9dad93d17c6eba7c1738c" +dest_md5="296e77cfba5c07bc84966e4fbb5960be" + diff --git a/.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.s3tc.stex b/.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.s3tc.stex Binary files differ. diff --git a/.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.etc.stex b/.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.etc.stex Binary files differ. diff --git a/.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.md5 b/.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.md5 @@ -0,0 +1,3 @@ +source_md5="ddfe3a357d51b8ef8e98854462155f5e" +dest_md5="fcafa5bcb38d5f90fc959ce67c004b4f" + diff --git a/.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.s3tc.stex b/.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.s3tc.stex Binary files differ. diff --git a/addons/godot-openvr/OpenVRConfig.gdns b/addons/godot-openvr/OpenVRConfig.gdns @@ -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 = "OpenVRConfig" +class_name = "OpenVRConfig" +library = ExtResource( 1 ) diff --git a/addons/godot-openvr/OpenVROverlay.gdns b/addons/godot-openvr/OpenVROverlay.gdns @@ -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 = "OpenVROverlay" +class_name = "OpenVROverlay" +library = ExtResource( 1 ) diff --git a/addons/godot-openvr/OpenVRRenderModel.gdns b/addons/godot-openvr/OpenVRRenderModel.gdns @@ -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" ] + diff --git a/addons/godot-openvr/bin/LICENSE b/addons/godot-openvr/bin/LICENSE @@ -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. diff --git a/addons/godot-openvr/bin/osx/libgodot_openvr.dylib b/addons/godot-openvr/bin/osx/libgodot_openvr.dylib Binary files differ. diff --git a/addons/godot-openvr/bin/osx/libopenvr_api.dylib b/addons/godot-openvr/bin/osx/libopenvr_api.dylib Binary files differ. diff --git a/addons/godot-openvr/bin/win64/libgodot_openvr.dll b/addons/godot-openvr/bin/win64/libgodot_openvr.dll Binary files differ. diff --git a/addons/godot-openvr/bin/win64/openvr_api.dll b/addons/godot-openvr/bin/win64/openvr_api.dll Binary files differ. diff --git a/addons/godot-openvr/bin/x11/libgodot_openvr.so b/addons/godot-openvr/bin/x11/libgodot_openvr.so Binary files differ. diff --git a/addons/godot-openvr/bin/x11/libopenvr_api.so b/addons/godot-openvr/bin/x11/libopenvr_api.so Binary files differ. diff --git a/addons/godot-openvr/godot_openvr.gdnlib b/addons/godot-openvr/godot_openvr.gdnlib @@ -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/libgodot_openvr.dll" +Windows.64="res://addons/godot-openvr/bin/win64/libgodot_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" ] diff --git a/addons/godot-openvr/icon.png b/addons/godot-openvr/icon.png Binary files differ. diff --git a/addons/godot-openvr/icon.png.import b/addons/godot-openvr/icon.png.import @@ -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 diff --git a/addons/godot-openvr/scenes/framecounter_in_3d.tscn b/addons/godot-openvr/scenes/framecounter_in_3d.tscn @@ -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" ] + + diff --git a/addons/godot-openvr/scenes/ovr_controller.gd b/addons/godot-openvr/scenes/ovr_controller.gd @@ -0,0 +1,64 @@ +extends ARVRController + +signal controller_activated(controller) + +export var show_controller_mesh = true setget set_show_controller_mesh, get_show_controller_mesh + +func set_show_controller_mesh(p_show): + show_controller_mesh = p_show + if $Controller_mesh: + $Controller_mesh.visible = p_show + +func get_show_controller_mesh(): + return show_controller_mesh + +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() + + # set our starting vaule + $Controller_mesh.visible = show_controller_mesh + + # 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) diff --git a/addons/godot-openvr/scenes/ovr_controller.tscn b/addons/godot-openvr/scenes/ovr_controller.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/godot-openvr/scenes/ovr_controller.gd" type="Script" id=1] + +[node name="OVRController" type="ARVRController"] +script = ExtResource( 1 ) + +[node name="Controller_mesh" type="MeshInstance" parent="."] diff --git a/addons/godot-openvr/scenes/ovr_first_person.tscn b/addons/godot-openvr/scenes/ovr_first_person.tscn @@ -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 + diff --git a/addons/vr-common/VERSIONS.md b/addons/vr-common/VERSIONS.md @@ -0,0 +1,12 @@ +1.2 (in progress) +=== +- 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 + +1.1* +==== +- previous versions were not tracked + +* Note that version history before 1.2 was not kept and is thus incomplete diff --git a/addons/vr-common/functions/Function_Direct_movement.gd b/addons/vr-common/functions/Function_Direct_movement.gd @@ -0,0 +1,176 @@ +extends Node + +enum MOVEMENT_TYPE { MOVE_AND_ROTATE, MOVE_AND_STRAFE } + +# We don't know the name of the camera node... +export (NodePath) var camera = null + +# size of our player +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 max_speed = 5.0 +export var drag_factor = 0.1 + +# 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 +var isflying = false + +var turn_step = 0.0 +var origin_node = null +var camera_node = null +var velocity = Vector3(0.0, 0.0, 0.0) +var gravity = -30.0 +onready var collision_shape = get_node("KinematicBody/CollisionShape") +onready var tail = get_node("KinematicBody/Tail") + +func get_player_radius(): + return player_radius + +func set_player_radius(p_radius): + player_radius = p_radius + +func _ready(): + # origin node should always be the parent of our parent + origin_node = get_node("../..") + + if camera: + camera_node = get_node(camera) + else: + # see if we can find our default + camera_node = origin_node.get_node('ARVRCamera') + + set_player_radius(player_radius) + +func _physics_process(delta): + if !origin_node: + return + + if !camera_node: + return + + # Adjust the height of our player according to our camera position + var camera_height = camera_node.transform.origin.y + if camera_height < player_radius: + # not smaller than this + camera_height = player_radius + + collision_shape.shape.radius = player_radius + collision_shape.shape.height = camera_height - player_radius + collision_shape.transform.origin.y = (camera_height / 2.0) + player_radius + + # We should be the child or the controller on which the teleport is implemented + var controller = get_parent() + if controller.get_is_active(): + var left_right = controller.get_joystick_axis(0) + var forwards_backwards = controller.get_joystick_axis(1) + + # if fly_action_button_id is pressed it activates the FLY MODE + # if fly_action_button_id is released it deactivates the FLY MODE + if controller.is_button_pressed(fly_activate_button_id) && canFly: + isflying = true + else: + isflying = false + + # if player is flying, he moves following the controller's orientation + if isflying: + if controller.is_button_pressed(fly_move_button_id): + # is flying, so we will use the controller's transform to move the VR capsule follow its orientation + var curr_transform = $KinematicBody.global_transform + velocity = controller.global_transform.basis.z.normalized() * -delta * max_speed * ARVRServer.world_scale + velocity = $KinematicBody.move_and_slide(velocity) + var movement = ($KinematicBody.global_transform.origin - curr_transform.origin) + origin_node.global_transform.origin += movement + + ################################################################ + # first process turning, no problems there :) + # 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: + # 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 + + origin_node.transform *= t2 * rot * t1 + else: + turn_step = 0.0 + + ################################################################ + # now we do our movement + # We start with placing our KinematicBody in the right place + # by centering it on the camera but placing it on the ground + var curr_transform = $KinematicBody.global_transform + var camera_transform = camera_node.global_transform + curr_transform.origin = camera_transform.origin + curr_transform.origin.y = origin_node.global_transform.origin.y + $KinematicBody.global_transform = curr_transform + + # we'll handle gravity separately + var gravity_velocity = Vector3(0.0, velocity.y, 0.0) + velocity.y = 0.0 + + # Apply our drag + velocity *= (1.0 - drag_factor) + + if move_type == MOVEMENT_TYPE.MOVE_AND_ROTATE: + if (abs(forwards_backwards) > 0.1 and tail.is_colliding()): + var dir = camera_transform.basis.z + dir.y = 0.0 + velocity = dir.normalized() * -forwards_backwards * delta * max_speed * ARVRServer.world_scale + #velocity = velocity.linear_interpolate(dir, delta * 100.0) + elif move_type == MOVEMENT_TYPE.MOVE_AND_STRAFE: + if ((abs(forwards_backwards) > 0.1 || abs(left_right) > 0.1) and tail.is_colliding()): + var dir_forward = camera_transform.basis.z + dir_forward.y = 0.0 + # VR Capsule will strafe left and right + var dir_right = camera_transform.basis.x; + dir_right.y = 0.0 + velocity = (dir_forward * -forwards_backwards + dir_right * left_right).normalized() * delta * max_speed * ARVRServer.world_scale + + # apply move and slide to our kinematic body + velocity = $KinematicBody.move_and_slide(velocity, Vector3(0.0, 1.0, 0.0)) + + # apply our gravity + gravity_velocity.y += gravity * delta + gravity_velocity = $KinematicBody.move_and_slide(gravity_velocity, Vector3(0.0, 1.0, 0.0)) + velocity.y = gravity_velocity.y + + # now use our new position to move our origin point + var movement = ($KinematicBody.global_transform.origin - curr_transform.origin) + origin_node.global_transform.origin += movement + + # Return this back to where it was so we can use its collision shape for other things too + # $KinematicBody.global_transform.origin = curr_transform.origin + diff --git a/addons/vr-common/functions/Function_Direct_movement.tscn b/addons/vr-common/functions/Function_Direct_movement.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://addons/vr-common/functions/Function_Direct_movement.gd" type="Script" id=1] + +[sub_resource type="CapsuleShape" id=1] +radius = 0.3 +height = 1.2 + +[node name="Function_Direct_movement" type="Node"] +script = ExtResource( 1 ) +max_speed = 500.0 + +[node name="KinematicBody" type="KinematicBody" parent="."] +collision_mask = 1048574 + +[node name="CollisionShape" type="CollisionShape" parent="KinematicBody"] +transform = Transform( 1, 0, 0, 0, -4.37114e-008, -1, 0, 1, -4.37114e-008, 0, 0.9, 0 ) +shape = SubResource( 1 ) + +[node name="Tail" type="RayCast" parent="KinematicBody"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0 ) +enabled = true +cast_to = Vector3( 0, -0.6, 0 ) +collision_mask = 1048575 diff --git a/addons/vr-common/functions/Function_Pickup.gd b/addons/vr-common/functions/Function_Pickup.gd @@ -0,0 +1,97 @@ +extends Area + +signal has_picked_up(what) +signal has_dropped + +export var impulse_factor = 1.0 +export var pickup_button_id = 2 +export var action_button_id = 15 + +var object_in_area = Array() +var closest_object = null +var picked_up_object = null + +var last_position = Vector3(0.0, 0.0, 0.0) +var velocity = Vector3(0.0, 0.0, 0.0) + +func _on_Function_Pickup_body_entered(body): + # add our object to our array if required + if body.has_method('pick_up') and object_in_area.find(body) == -1: + object_in_area.push_back(body) + _update_closest_object() + +func _on_Function_Pickup_body_exited(body): + # remove our object from our array + if object_in_area.find(body) != -1: + object_in_area.erase(body) + _update_closest_object() + +func _update_closest_object(): + var new_closest_obj = null + if !picked_up_object: + var new_closest_distance = 1000 + for o in object_in_area: + # only check objects that aren't already picked up + if o.is_picked_up() == false: + var delta_pos = o.global_transform.origin - global_transform.origin + var distance = delta_pos.length() + if distance < new_closest_distance: + new_closest_obj = o + new_closest_distance = distance + + if closest_object != new_closest_obj: + # remove highlight on old object + if closest_object: + closest_object.decrease_is_closest() + + # add highlight to new object + closest_object = new_closest_obj + if closest_object: + closest_object.increase_is_closest() + +func drop_object(): + if picked_up_object: + # let go of this object + picked_up_object.let_go(velocity * impulse_factor) + picked_up_object = null + emit_signal("has_dropped") + +func _pick_up_object(p_object): + # already holding this object, nothing to do + if picked_up_object == p_object: + return + + # holding something else? drop it + if picked_up_object: + drop_object() + + # and pick up our new object + if p_object: + picked_up_object = p_object + picked_up_object.pick_up(self, get_parent()) + emit_signal("has_picked_up", picked_up_object) + +func _on_button_pressed(p_button): + if p_button == pickup_button_id: + if picked_up_object and !picked_up_object.press_to_hold: + drop_object() + elif closest_object: + _pick_up_object(closest_object) + elif p_button == action_button_id: + if picked_up_object and picked_up_object.has_method("action"): + picked_up_object.action() + +func _on_button_release(p_button): + if p_button == pickup_button_id: + if picked_up_object and picked_up_object.press_to_hold: + drop_object() + +func _ready(): + get_parent().connect("button_pressed", self, "_on_button_pressed") + get_parent().connect("button_release", self, "_on_button_release") + last_position = global_transform.origin + +func _process(delta): + velocity = (global_transform.origin - last_position) / delta + last_position = global_transform.origin + _update_closest_object() diff --git a/addons/vr-common/functions/Function_Pickup.tscn b/addons/vr-common/functions/Function_Pickup.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://addons/vr-common/functions/Function_Pickup.gd" type="Script" id=1] + +[sub_resource type="SphereShape" id=1] +radius = 0.5 + +[node name="Function_Pickup" type="Area"] +collision_mask = 2 +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] +shape = SubResource( 1 ) +[connection signal="body_entered" from="." to="." method="_on_Function_Pickup_body_entered"] +[connection signal="body_exited" from="." to="." method="_on_Function_Pickup_body_exited"] diff --git a/addons/vr-common/functions/Function_Teleport.gd b/addons/vr-common/functions/Function_Teleport.gd @@ -0,0 +1,245 @@ +extends KinematicBody +# should really change this to Spatial once #17401 is resolved + +# Add this scene as a sub scene of your ARVRController node to implement a teleport function on that controller. + +# button 15 is mapped to our trigger +export var teleport_button = 15 +export (Color) var can_teleport_color = Color(0.0, 1.0, 0.0, 1.0) +export (Color) var cant_teleport_color = Color(1.0, 0.0, 0.0, 1.0) +export (Color) var no_collision_color = Color(45.0 / 255.0, 80.0 / 255.0, 220.0 / 255.0, 1.0) +export var player_height = 1.8 setget set_player_height, get_player_height +export var player_radius = 0.4 setget set_player_radius, get_player_radius +export var strength = 5.0 +# once this is no longer a kinematic body, we'll need this.. +# export var collision_mask = 1 + +onready var ws = ARVRServer.world_scale +var origin_node = null +var is_on_floor = true +var is_teleporting = false +var can_teleport = true +var teleport_rotation = 0.0; +var floor_normal = Vector3(0.0, 1.0, 0.0) +var last_target_transform = Transform() +var collision_shape = null +var step_size = 0.5 + +# By default we show a capsule to indicate where the player lands. +# Turn on editable children, +# hide the capsule, +# and add your own player character as child. +onready var capsule = get_node("Target/Player_figure/Capsule") + +func get_player_height(): + return player_height + +func set_player_height(p_height): + player_height = p_height + + if collision_shape: + # for some reason collision shape height measurement is half up, half down from center + collision_shape.height = (player_height / 2.0) + 0.1 + + if capsule: + capsule.mesh.mid_height = player_height - (2.0 * player_radius) + capsule.translation = Vector3(0.0, player_height/2.0, 0.0) + +func get_player_radius(): + return player_radius + +func set_player_radius(p_radius): + player_radius = p_radius + + if collision_shape: + collision_shape.radius = player_radius + + if capsule: + capsule.mesh.mid_height = player_height - (2.0 * player_radius) + capsule.mesh.radius = player_radius + +func _ready(): + # We should be a child of an ARVRController and it should be a child or our ARVROrigin + origin_node = get_node("../..") + + # It's inactive when we start + $Teleport.visible = false + $Target.visible = false + + # Scale to our world scale + $Teleport.mesh.size = Vector2(0.05 * ws, 1.0) + $Target.mesh.size = Vector2(ws, ws) + $Target/Player_figure.scale = Vector3(ws, ws, ws) + + # create shape object + collision_shape = CapsuleShape.new() + + # call set player to ensure our collision shape is sized + set_player_height(player_height) + set_player_radius(player_radius) + +func _physics_process(delta): + # We should be the child or the controller on which the teleport is implemented + var controller = get_parent() + + # check if our world scale has changed.. + var new_ws = ARVRServer.world_scale + if ws != new_ws: + ws = new_ws + $Teleport.mesh.size = Vector2(0.05 * ws, 1.0) + $Target.mesh.size = Vector2(ws, ws) + $Target/Player_figure.scale = Vector3(ws, ws, ws) + + if controller and controller.get_is_active() and controller.is_button_pressed(teleport_button): + if !is_teleporting: + is_teleporting = true + $Teleport.visible = true + $Target.visible = true + teleport_rotation = 0.0 + + # get our physics engine state + var space = PhysicsServer.body_get_space(self.get_rid()) + var state = PhysicsServer.space_get_direct_state(space) + var query = PhysicsShapeQueryParameters.new() + + # init stuff about our query that doesn't change (note that safe margin and collision_mask need to change once we no longer use kinematic body) + query.collision_mask = collision_mask + query.margin = get_safe_margin() + query.shape_rid = collision_shape.get_rid() + + # make a transform for rotating and offseting our shape, it's always lying on its side by default... + var shape_transform = Transform(Basis(Vector3(1.0, 0.0, 0.0), deg2rad(90.0)), Vector3(0.0, player_height / 2.0, 0.0)) + + # update location + var teleport_global_transform = $Teleport.global_transform + var target_global_origin = teleport_global_transform.origin + var down = Vector3(0.0, -1.0 / ws, 0.0) + + ############################################################ + # New teleport logic + # We're going to use test move in steps to find out where we hit something... + # This can be optimised loads by determining the lenght based on the angle between sections extending the length when we're in a flat part of the arch + # Where we do get a collission we may want to fine tune the collision + var cast_length = 0.0 + var fine_tune = 1.0 + var hit_something = false + for i in range(1,26): + var new_cast_length = cast_length + (step_size / fine_tune) + var global_target = Vector3(0.0, 0.0, -new_cast_length) + + # our quadratic values + var t = global_target.z / strength + var t2 = t * t + + # target to world space + global_target = teleport_global_transform.xform(global_target) + + # adjust for gravity + global_target += down * t2 + + # test our new location for collisions + query.transform = Transform(Basis(), global_target) * shape_transform + var cast_result = state.collide_shape(query, 10) + if cast_result.empty(): + # we didn't collide with anything so check our next section... + cast_length = new_cast_length + target_global_origin = global_target + elif (fine_tune <= 16.0): + # try again with a small step size + fine_tune *= 2.0 + else: + var collided_at = target_global_origin + if global_target.y > target_global_origin.y: + # if we're moving up, we hit the ceiling of something, we don't really care what + is_on_floor = false + else: + # now we cast a ray downwards to see if we're on a surface + var up = Vector3(0.0, 1.0, 0.0) + var end_pos = target_global_origin - (up * 0.1) + var intersects = state.intersect_ray(target_global_origin, end_pos) + if intersects.empty(): + is_on_floor = false + else: + # did we collide with a floor or a wall? + floor_normal = intersects["normal"] + var dot = floor_normal.dot(up) + if dot > 0.9: + is_on_floor = true + else: + is_on_floor = false + + # and return the position at which we intersected + collided_at = intersects["position"] + + # we are colliding, find our if we're colliding on a wall or floor, one we can do, the other nope... + cast_length += (collided_at - target_global_origin).length() + target_global_origin = collided_at + hit_something = true + break + + # and just update our shader + $Teleport.get_surface_material(0).set_shader_param("scale_t", 1.0 / strength) + $Teleport.get_surface_material(0).set_shader_param("ws", ws) + $Teleport.get_surface_material(0).set_shader_param("length", cast_length) + if hit_something: + var color = can_teleport_color + var normal = Vector3(0.0, 1.0, 0.0) + if is_on_floor: + # if we're on the floor we'll reorientate our target to match. + normal = floor_normal + can_teleport = true + else: + can_teleport = false + color = cant_teleport_color + + # check our axis to see if we need to rotate + teleport_rotation += (delta * controller.get_joystick_axis(0) * -4.0) + + # update target and colour + var target_basis = Basis() + target_basis.z = Vector3(teleport_global_transform.basis.z.x, 0.0, teleport_global_transform.basis.z.z).normalized() + target_basis.y = normal + target_basis.x = target_basis.y.cross(target_basis.z) + target_basis.z = target_basis.x.cross(target_basis.y) + + target_basis = target_basis.rotated(normal, teleport_rotation) + last_target_transform.basis = target_basis + last_target_transform.origin = target_global_origin + Vector3(0.0, 0.02, 0.0) + $Target.global_transform = last_target_transform + + $Teleport.get_surface_material(0).set_shader_param("mix_color", color) + $Target.get_surface_material(0).albedo_color = color + $Target.visible = can_teleport + else: + can_teleport = false + $Target.visible = false + $Teleport.get_surface_material(0).set_shader_param("mix_color", no_collision_color) + elif is_teleporting: + if can_teleport: + + # make our target horizontal again + var new_transform = last_target_transform + new_transform.basis.y = Vector3(0.0, 1.0, 0.0) + new_transform.basis.x = new_transform.basis.y.cross(new_transform.basis.z).normalized() + new_transform.basis.z = new_transform.basis.x.cross(new_transform.basis.y).normalized() + + # find out our user's feet's transformation + var camera_node = origin_node.get_node("ARVRCamera") + var cam_transform = camera_node.transform + var user_feet_transform = Transform() + user_feet_transform.origin = cam_transform.origin + user_feet_transform.origin.y = 0 # the feet are on the ground, but have the same X,Z as the camera + + # ensure this transform is upright + user_feet_transform.basis.y = Vector3(0.0, 1.0, 0.0) + user_feet_transform.basis.x = user_feet_transform.basis.y.cross(cam_transform.basis.z).normalized() + user_feet_transform.basis.z = user_feet_transform.basis.x.cross(user_feet_transform.basis.y).normalized() + + # now move the origin such that the new global user_feet_transform would be == new_transform + origin_node.global_transform = new_transform * user_feet_transform.inverse() + + # and disable + is_teleporting = false; + $Teleport.visible = false + $Target.visible = false + diff --git a/addons/vr-common/functions/Function_Teleport.tscn b/addons/vr-common/functions/Function_Teleport.tscn @@ -0,0 +1,39 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://addons/vr-common/functions/Function_Teleport.gd" type="Script" id=1] +[ext_resource path="res://addons/vr-common/materials/teleport.tres" type="Material" id=2] +[ext_resource path="res://addons/vr-common/materials/target.tres" type="Material" id=3] +[ext_resource path="res://addons/vr-common/materials/capule.tres" type="Material" id=4] + +[sub_resource type="PlaneMesh" id=1] +size = Vector2( 0.05, 1 ) +subdivide_depth = 40 + +[sub_resource type="PlaneMesh" id=2] +size = Vector2( 1, 1 ) + +[sub_resource type="CapsuleMesh" id=4] +radius = 0.3 +mid_height = 1.2 + +[node name="Function_Teleport" type="KinematicBody"] +input_ray_pickable = false +collision/safe_margin = 0.01 +script = ExtResource( 1 ) +no_collision_color = Color( 0.176471, 0.313726, 0.862745, 1 ) + +[node name="Teleport" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) +material/0 = ExtResource( 2 ) + +[node name="Target" type="MeshInstance" parent="."] +mesh = SubResource( 2 ) +material/0 = ExtResource( 3 ) + +[node name="Player_figure" type="Position3D" parent="Target"] + +[node name="Capsule" type="MeshInstance" parent="Target/Player_figure"] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.9, 0 ) +mesh = SubResource( 4 ) +material/0 = ExtResource( 4 ) + diff --git a/addons/vr-common/functions/Function_pointer.tscn b/addons/vr-common/functions/Function_pointer.tscn @@ -0,0 +1,87 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://addons/vr-common/materials/pointer.tres" type="Material" id=1] + +[sub_resource type="GDScript" id=1] +script/source = "\"res://addons/vr-common/functions/Function_pointer.tscn\"extends Spatial + +var target = null +var last_collided_at = Vector3(0, 0, 0) +var laser_y = -0.05 +onready var ws = ARVRServer.world_scale + +func set_enabled(p_enabled): + $Laser.visible = p_enabled + $Laser/RayCast.enabled = p_enabled + +func _on_button_pressed(p_button): + if p_button == 15 and $Laser/RayCast.enabled: + if $Laser/RayCast.is_colliding(): + target = $Laser/RayCast.get_collider() + last_collided_at = $Laser/RayCast.get_collision_point() + # print(\"Button pressed on \" + target.get_name() + \" at \" + str(last_collided_at)) + if target.has_method(\"_on_pointer_pressed\"): + target._on_pointer_pressed(last_collided_at) + +func _on_button_release(p_button): + if p_button == 15 and target: + # let object know button was released + # print(\"Button released on \" + target.get_name()) + if target.has_method(\"_on_pointer_release\"): + target._on_pointer_release(last_collided_at) + + target = false + last_collided_at = Vector3(0, 0, 0) + +func _ready(): + # Get button press feedback from our parent (should be an ARVRController) + get_parent().connect(\"button_pressed\", self, \"_on_button_pressed\") + get_parent().connect(\"button_release\", self, \"_on_button_release\") + + # apply our world scale to our laser position + $Laser.translation.y = laser_y * ws + +func _process(delta): + var new_ws = ARVRServer.world_scale + if (ws != new_ws): + ws = new_ws + $Laser.translation.y = laser_y * ws + + if $Laser/RayCast.enabled and $Laser/RayCast.is_colliding(): + var new_at = $Laser/RayCast.get_collision_point() + var new_target = $Laser/RayCast.get_collider() + + if new_at == last_collided_at: + pass + elif target: + # if target is set our mouse must be down, we keep sending events to our target + if target.has_method(\"_on_pointer_moved\"): + target._on_pointer_moved(new_at, last_collided_at) + else: + if new_target.has_method(\"_on_pointer_moved\"): + new_target._on_pointer_moved(new_at, last_collided_at) + + last_collided_at = new_at + +" + +[sub_resource type="CubeMesh" id=2] +material = ExtResource( 1 ) +size = Vector3( 0.002, 0.002, 10 ) +subdivide_depth = 20 + +[node name="Function_pointer" type="Spatial"] +transform = Transform( 1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 0, 0 ) +script = SubResource( 1 ) + +[node name="Laser" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.05, -5 ) +cast_shadow = 0 +mesh = SubResource( 2 ) +material/0 = null + +[node name="RayCast" type="RayCast" parent="Laser"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5 ) +enabled = true +cast_to = Vector3( 0, 0, -10 ) + diff --git a/addons/vr-common/images/icon.png b/addons/vr-common/images/icon.png Binary files differ. diff --git a/addons/vr-common/images/icon.png.import b/addons/vr-common/images/icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-fb3b2ecb55ac1327d82f6710eba4f8b4.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/vr-common/images/icon.png" +dest_files=[ "res://.import/icon.png-fb3b2ecb55ac1327d82f6710eba4f8b4.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 diff --git a/addons/vr-common/images/teleport_arrow.png b/addons/vr-common/images/teleport_arrow.png Binary files differ. diff --git a/addons/vr-common/images/teleport_arrow.png.import b/addons/vr-common/images/teleport_arrow.png.import @@ -0,0 +1,36 @@ +[remap] + +importer="texture" +type="StreamTexture" +path.s3tc="res://.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.s3tc.stex" +path.etc="res://.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.etc.stex" +metadata={ +"imported_formats": [ "s3tc", "etc" ], +"vram_texture": true +} + +[deps] + +source_file="res://addons/vr-common/images/teleport_arrow.png" +dest_files=[ "res://.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.s3tc.stex", "res://.import/teleport_arrow.png-9ee8732a3d27e6e53f97efad743b9f9b.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=true +flags/filter=true +flags/mipmaps=true +flags/anisotropic=false +flags/srgb=1 +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=false +svg/scale=1.0 diff --git a/addons/vr-common/images/teleport_target.png b/addons/vr-common/images/teleport_target.png Binary files differ. diff --git a/addons/vr-common/images/teleport_target.png.import b/addons/vr-common/images/teleport_target.png.import @@ -0,0 +1,36 @@ +[remap] + +importer="texture" +type="StreamTexture" +path.s3tc="res://.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.s3tc.stex" +path.etc="res://.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.etc.stex" +metadata={ +"imported_formats": [ "s3tc", "etc" ], +"vram_texture": true +} + +[deps] + +source_file="res://addons/vr-common/images/teleport_target.png" +dest_files=[ "res://.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.s3tc.stex", "res://.import/teleport_target.png-779f853f62e0e2207f5821dfbc8b780c.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=true +flags/filter=true +flags/mipmaps=true +flags/anisotropic=false +flags/srgb=1 +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=false +svg/scale=1.0 diff --git a/addons/vr-common/materials/capule.tres b/addons/vr-common/materials/capule.tres @@ -0,0 +1,7 @@ +[gd_resource type="SpatialMaterial" format=2] + +[resource] +flags_transparent = true +albedo_color = Color( 0.0337219, 0.241112, 0.863281, 0.497255 ) +roughness = 0.0 + diff --git a/addons/vr-common/materials/pointer.tres b/addons/vr-common/materials/pointer.tres @@ -0,0 +1,7 @@ +[gd_resource type="SpatialMaterial" format=2] + +[resource] +flags_unshaded = true +params_diffuse_mode = 1 +albedo_color = Color( 1, 0.15625, 0.15625, 0.740314 ) + diff --git a/addons/vr-common/materials/target.tres b/addons/vr-common/materials/target.tres @@ -0,0 +1,12 @@ +[gd_resource type="SpatialMaterial" load_steps=2 format=2] + +[ext_resource path="res://addons/vr-common/images/teleport_target.png" type="Texture" id=1] + +[resource] +flags_transparent = true +flags_unshaded = true +params_diffuse_mode = 1 +params_cull_mode = 2 +albedo_color = Color( 0.176471, 0.313726, 0.862745, 1 ) +albedo_texture = ExtResource( 1 ) + diff --git a/addons/vr-common/materials/teleport.shader b/addons/vr-common/materials/teleport.shader @@ -0,0 +1,39 @@ +shader_type spatial; +render_mode unshaded, cull_disabled, skip_vertex_transform; + +uniform float scale_t = 0.2; +uniform float length = 20.0; +uniform float ws = 1.0; +uniform vec4 mix_color : hint_color; +uniform sampler2D arrow_texture : hint_albedo; + +void vertex() { + vec3 down = vec3(0.0, -1.0 / ws, 0.0); + + // offset our Z so we're projecting from our origin point + VERTEX.z -= 0.5; + VERTEX.z *= length; + + // now use that to create our arch + float t = VERTEX.z * scale_t; + float t2 = t * t; + + // translate to our world vector + VERTEX = (WORLD_MATRIX * vec4(VERTEX, 1.0)).xyz; + + // and now create our arch + VERTEX += down * t2; + + // and apply our camera matrix + VERTEX = (INV_CAMERA_MATRIX * vec4(VERTEX, 1.0)).xyz; +} + +void fragment() { + // and do our color + float offset = (TIME * 2.0); + vec4 col = texture(arrow_texture, vec2(UV.x, (UV.y * length * 4.0) + offset )).rgba; + ALBEDO = col.rgb * mix_color.rgb; + + // need to fix up our image and add an alpha channel + ALPHA = col.a; +} diff --git a/addons/vr-common/materials/teleport.tres b/addons/vr-common/materials/teleport.tres @@ -0,0 +1,13 @@ +[gd_resource type="ShaderMaterial" load_steps=3 format=2] + +[ext_resource path="res://addons/vr-common/materials/teleport.shader" type="Shader" id=1] +[ext_resource path="res://addons/vr-common/images/teleport_arrow.png" type="Texture" id=2] + +[resource] +shader = ExtResource( 1 ) +shader_param/scale_t = 0.2 +shader_param/length = 30.0 +shader_param/ws = 1.0 +shader_param/mix_color = Color( 0.176471, 0.313726, 0.862745, 1 ) +shader_param/arrow_texture = ExtResource( 2 ) + diff --git a/addons/vr-common/misc/VR_Common_Shader_Cache.gd b/addons/vr-common/misc/VR_Common_Shader_Cache.gd @@ -0,0 +1,10 @@ +extends Spatial + +var countdown = 2 + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + countdown = countdown - 1 + if countdown == 0: + visible = false + set_process(false) diff --git a/addons/vr-common/misc/VR_Common_Shader_Cache.tscn b/addons/vr-common/misc/VR_Common_Shader_Cache.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://addons/vr-common/misc/VR_Common_Shader_Cache.gd" type="Script" id=1] +[ext_resource path="res://addons/vr-common/materials/teleport.tres" type="Material" id=2] +[ext_resource path="res://addons/vr-common/materials/target.tres" type="Material" id=3] +[ext_resource path="res://addons/vr-common/materials/capule.tres" type="Material" id=4] +[ext_resource path="res://addons/vr-common/materials/pointer.tres" type="Material" id=5] + +[sub_resource type="PlaneMesh" id=2] +size = Vector2( 0.001, 0.001 ) + +[node name="vr_common_shader_cache" type="Spatial"] +script = ExtResource( 1 ) + +[node name="teleport" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -2 ) +mesh = SubResource( 2 ) +material/0 = ExtResource( 2 ) + +[node name="target" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -2 ) +mesh = SubResource( 2 ) +material/0 = ExtResource( 3 ) + +[node name="capsule" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -2 ) +mesh = SubResource( 2 ) +material/0 = ExtResource( 4 ) + +[node name="pointer" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -2 ) +mesh = SubResource( 2 ) +material/0 = ExtResource( 5 ) + diff --git a/addons/vr-common/objects/Object_pickable.gd b/addons/vr-common/objects/Object_pickable.gd @@ -0,0 +1,85 @@ +extends RigidBody + +# Set hold mode +export (bool) var press_to_hold = true +export (int, FLAGS, "layer_1", "layer_2", "layer_3", "layer_4", "layer_5") var picked_up_layer = 0 + +# Remember some state so we can return to it when the user drops the object +onready var original_parent = get_parent() +onready var original_collision_mask = collision_mask +onready var original_collision_layer = collision_layer + +# Who picked us up? +var picked_up_by = null +var by_controller : ARVRController = null +var closest_count = 0 + +# have we been picked up? +func is_picked_up(): + if picked_up_by: + return true + + return false + +func _update_highlight(): + # should probably implement this in our subclass + pass + +func increase_is_closest(): + closest_count += 1 + _update_highlight() + +func decrease_is_closest(): + closest_count -= 1 + _update_highlight() + +func drop_and_free(): + if picked_up_by: + picked_up_by.drop_object() + + queue_free() + +# we are being picked up by... +func pick_up(by, with_controller): + if picked_up_by == by: + return + + if picked_up_by: + let_go() + + # remember who picked us up + picked_up_by = by + by_controller = with_controller + + # turn off physics on our pickable object + mode = RigidBody.MODE_STATIC + collision_layer = picked_up_layer + collision_mask = 0 + + # now reparent it + original_parent.remove_child(self) + picked_up_by.add_child(self) + + # reset our transform + transform = Transform() + +# we are being let go +func let_go(impulse = Vector3(0.0, 0.0, 0.0)): + if picked_up_by: + # get our current global transform + var t = global_transform + + # reparent it + picked_up_by.remove_child(self) + original_parent.add_child(self) + + # reposition it and apply impulse + global_transform = t + mode = RigidBody.MODE_RIGID + collision_mask = original_collision_mask + collision_layer = original_collision_layer + apply_impulse(Vector3(0.0, 0.0, 0.0), impulse) + + # we are no longer picked up + picked_up_by = null + by_controller = null diff --git a/addons/vr-common/objects/Object_pickable.tscn b/addons/vr-common/objects/Object_pickable.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/vr-common/objects/Object_pickable.gd" type="Script" id=1] + +[node name="PickableObject" type="RigidBody"] +collision_layer = 6 +collision_mask = 6 +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] diff --git a/default_env.tres b/default_env.tres @@ -0,0 +1,5 @@ +[gd_resource type="Environment" load_steps=2 format=2] +[sub_resource type="ProceduralSky" id=1] +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/icon.png b/icon.png Binary files differ. diff --git a/icon.png.import b/icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.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 diff --git a/project.godot b/project.godot @@ -0,0 +1,30 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +_global_script_classes=[ ] +_global_script_class_icons={ + +} + +[application] + +config/name="ggj2020" +config/icon="res://icon.png" + +[gdnative] + +singletons=[ "res://addons/godot-openvr/godot_openvr.gdnlib" ] + +[rendering] + +quality/driver/driver_name="GLES2" +vram_compression/import_etc=true +vram_compression/import_etc2=false +environment/default_environment="res://default_env.tres"