diff --git a/.gitignore b/.gitignore index b6666c7..79d12a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ *.o *.os -*.so -*.dylib .import *.import *.dblite *.exp *.lib -*.obj logs +builddir +subprojects/* +!subprojects/*.wrap diff --git a/.gitmodules b/.gitmodules index 4eb6fcd..828a556 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,3 @@ [submodule "godot_headers"] path = godot_headers url = https://github.com/GodotNativeTools/godot_headers -[submodule "OpenHMD"] - path = OpenHMD - url = https://github.com/OpenHMD/OpenHMD -[submodule "hidapi"] - path = hidapi - url = https://github.com/OpenHMD/hidapi -[submodule "libusb"] - path = libusb - url = https://github.com/libusb/libusb diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..7f05907 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,10 @@ +Contributors +============ + +This plugin has mostly been developed by [Bastiaan Olij](https://github.com/BastiaanOlij). + +Other people who have helped out by submitting fixes, enhancements, etc are: +- [Douglas Xie](https://github.com/Douglas-3Glasses) +- [Joey](https://github.com/TheOnlyJoey) +- [Benedikt](https://github.com/beniwtv) +- [Jan Schmidt](https://github.com/thaytan) diff --git a/LICENSE b/LICENSE index 726d706..efc47ee 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Bastiaan Olij +Copyright (c) 2018-2020 Bastiaan Olij and Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/OpenHMD b/OpenHMD deleted file mode 160000 index d337a15..0000000 --- a/OpenHMD +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d337a154ad1d156722499234c205a9c2e5d3f4f9 diff --git a/README.md b/README.md index ef72ef2..278fb2b 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,13 @@ If you want to build this module for Godot 3.0 please checkout the 3.0 branch. Building this module -------------------- -In order to compile this module you will have to clone the source code to disk. You will need a C/C++ compiler, python and scons installed. This is the same toolchain you will need in order to compile Godot from master. The documentation on Godot is a very good place to read up on this. It is too much information to duplicate here. +This module uses meson and ninja for building and dependency management. -When cloning this repository make sure you also install all the submodules. +You can find instructions for installing meson here: https://mesonbuild.com/Quick-guide.html + +You can find instructions for installing ninja here: https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages + +We do still use submodules to bring our `godot_headers` repository in. Either clone with `git clone --recursive` or execute: ``` git submodules init @@ -23,14 +27,17 @@ git submodules update ``` after cloning. -If you're pulling a newer version (re)execute the `git submodules update` command to make sure the modules are up to date. If you're interested in using different branches of the 3rd party modules just CD into their subfolder and you can execute git commands on those repositories. +If you're pulling a newer version (re)execute the `git submodules update` command to make sure the modules are up to date. If you're interested in using different branches of the 3rd party modules just CD into their subfolder and you can execute git commands on those repositories. *Compiling* If everything into place compiling should be pretty straight forward +``` +meson builddir +cd builddir +ninja +``` -For Linux: ```scons platform=linux``` -For OSX: ```scons platform=osx``` -For Windows: ```scons platform=windows``` +Now copy `builddir\subprojects\hidapi\hidapi.dll`, `builddir\subprojects\OpenHMD\openhmd-0.dll` and `builddir\godot_openhmd-0.dll` into `demo\addons\godot-openhmd\bin\win64` (or equivelent step on other platforms), still looking into how to automate this. License ------- @@ -57,9 +64,9 @@ I'm leaving these instructions in the readme file because this is what we do wan ## X11 (Linux) -Clone this repository using `git clone --recursive` so all the needed packages will be cloned together with the source code. +Clone this repository using `git clone --recursive` so all the needed packages will be cloned together with the source code. -After that build libusb, openhmd and hidapi, using the following commands: +After that build libusb, openhmd and hidapi, using the following commands: ``` export CORES=$(grep processor /proc/cpuinfo | wc -l) @@ -68,13 +75,13 @@ cd hidapi ; ./bootstrap ; ./configure ; make -j $CORES ; cd .. cd OpenHMD ; ./autogen.sh ; ./configure ; make -j $CORES ; cd .. ``` -To make things easier, set the `GODOT_ROOT` environment variable with the folder that holds the GODOT source code, for example, like this: +To make things easier, set the `GODOT_ROOT` environment variable with the folder that holds the GODOT source code, for example, like this: ``` export GODOT_ROOT=../godot.git ``` -The you can build by issuing the followin command: +The you can build by issuing the followin command: ```GODOT_HEADERS=$GODOT_ROOT/modules/gdnative/include/ /bin/scons -j $CORES``` @@ -83,7 +90,7 @@ Last, you can test your build by issuing: `$GODOT_ROOT/bin/godot.x11.tools.64 demo/project.godot` or - + `godot demo/project.godot` ## Windows diff --git a/SConstruct b/SConstruct deleted file mode 100644 index d5b21aa..0000000 --- a/SConstruct +++ /dev/null @@ -1,186 +0,0 @@ -#!python -import os, subprocess - -# Local dependency paths, adapt them to your setup -godot_glad_path = ARGUMENTS.get("glad", "glad") -godot_headers_path = ARGUMENTS.get("headers", "godot_headers/") -libusb_path = ARGUMENTS.get("libusb", os.getenv("LIBUSB_PATH", "libusb/")) -hidapi_path = ARGUMENTS.get("hidapi", os.getenv("HIDAPI_PATH", "hidapi/")) -openhmd_path = ARGUMENTS.get("openhmd", os.getenv("OPENHMD_PATH", "OpenHMD/")) - -target = ARGUMENTS.get("target", "debug") - -# platform= makes it in line with Godots scons file, keeping p for backwards compatibility -platform = ARGUMENTS.get("p", "linux") -platform = ARGUMENTS.get("platform", platform) - -# destination path -godot_openhmd_path = 'demo/addons/godot-openhmd/bin/' - -# This makes sure to keep the session environment variables on windows, -# that way you can run scons in a vs 2017 prompt and it will find all the required tools -env = Environment() -if platform == "windows": - env = Environment(ENV = os.environ) - -if ARGUMENTS.get("use_llvm", "no") == "yes": - env["CXX"] = "clang++" - -def add_sources(sources, directory): - for file in os.listdir(directory): - if file.endswith('.c'): - sources.append(directory + '/' + file) - elif file.endswith('.cpp'): - sources.append(directory + '/' + file) - -sources = [] - -platform_dir = '' -if platform == "osx": - platform_dir = 'osx' - godot_openhmd_path = godot_openhmd_path + 'osx/' - env.Append(CCFLAGS = ['-g','-O3', '-arch', 'x86_64']) - env.Append(LINKFLAGS = ['-arch', 'x86_64']) - env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'OpenGL', '-framework', 'IOKit']) - env.Append(LIBS=['pthread']) - -if platform == "linux": - platform_dir = 'linux' - godot_openhmd_path = godot_openhmd_path + 'linux/' - env.Append(CCFLAGS = ['-fPIC', '-g','-O3']) - env.Append(CXXFLAGS='-std=c++0x') - env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\'']) - -if platform == "windows": - platform_dir = 'win' - godot_openhmd_path = godot_openhmd_path + 'win64/' - if target == "debug": - env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '/MDd']) - else: - env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '/MD']) - env.Append(LIBS=["opengl32", "setupapi", "advapi32.lib"]) - -#################################################################################################################################### -# Link in glad -sources.append(godot_glad_path + "/glad.c") - -#################################################################################################################################### -# Link in libusb, but for now just for linux -if platform == 'linux': - env.Append(CPPPATH=[libusb_path]) - env.Append(CPPPATH=[libusb_path + "libusb"]) - env.Append(CPPPATH=[libusb_path + "libusb/os"]) - - libusb_sources = [ - "core.c", - "descriptor.c", - "hotplug.c", - "io.c", - "strerror.c", - "sync.c" - ] - - sources.append([libusb_path + "libusb/" + file for file in libusb_sources]) - -if platform == 'linux': -# sources.append(libusb_path + "libusb/os/linux_netlink.c") - sources.append(libusb_path + "libusb/os/linux_usbfs.c") - sources.append(libusb_path + "libusb/os/linux_udev.c") - sources.append(libusb_path + "libusb/os/poll_posix.c") - sources.append(libusb_path + "libusb/os/threads_posix.c") - env.Append(CPPDEFINES=["OS_LINUX", "USE_UDEV", "HAVE_LIBUDEV"]) - env.Append(LIBS = ['udev']) -#elif platform == 'windows': -# sources.append(libusb_path + "libusb/os/windows_nt_common.c") -# sources.append(libusb_path + "libusb/os/windows_usbdk.c") -# sources.append(libusb_path + "libusb/os/windows_winusb.c") -# sources.append(libusb_path + "libusb/os/poll_windows.c") -# sources.append(libusb_path + "libusb/os/threads_windows.c") -# env,Append(CPPDEFINES=["OS_WINDOWS"]) -#elif platform == 'osx': -# sources.append(libusb_path + "libusb/os/darwin_usb.c") -# sources.append(libusb_path + "libusb/os/poll_posix.c") -# sources.append(libusb_path + "libusb/os/threads_posix.c") -# env.Append(CPPDEFINES=["OS_DARWIN"]) - -#################################################################################################################################### -# Link in hidapi -hidapi_headers = hidapi_path + "hidapi/" -env.Append(CPPPATH=[hidapi_headers]) - -if platform == 'windows': - sources.append(hidapi_path + "windows/hid.c" ) -elif platform == 'linux': - # If we can use the libusb version it should allow us to undo our detect.py changes - # See thirdparty/hidapi/linux/README.txt and thirdparty/hidapi/udev/99-hid-rules for more info - # env_openhmd.add_source_files(env.modules_sources, [ "#thirdparty/hidapi/linux/hid.c" ]) - sources.append(hidapi_path + "libusb/hid.c") -elif platform == 'osx': - sources.append(hidapi_path + "mac/hid.c") - -#################################################################################################################################### -# Link in openhmd, we're linking in static. -env.Append(CFLAGS=["-DOHMD_STATIC"]) -env.Append(CPPFLAGS=["-DOHMD_STATIC"]) - -# We don't include android because we're not compiling this for android at this time. -# Our native mobile VR class already handles android. -# We do include the Vive so we have basic native support even though we have an OpenVR implementation -env.Append(CFLAGS=["-DDRIVER_XGVR"]) -#env.Append(CFLAGS=["-DDRIVER_ANDROID"]) -env.Append(CFLAGS=["-DDRIVER_DEEPOON"]) -#env.Append(CFLAGS=["-DDRIVER_EXTERNAL"]) -env.Append(CFLAGS=["-DDRIVER_HTC_VIVE"]) -env.Append(CFLAGS=["-DDRIVER_NOLO"]) -env.Append(CFLAGS=["-DDRIVER_OCULUS_RIFT"]) -env.Append(CFLAGS=["-DDRIVER_PSVR"]) -env.Append(CFLAGS=["-DDRIVER_WMR"]) -env.Append(CFLAGS=["-DDRIVER_VRTEK"]) - -openhmd_headers = openhmd_path + "include/" -env.Append(CPPPATH=[openhmd_headers]) - -openhmd_sources = [ - "fusion.c", - "omath.c", - "openhmd.c", - "shaders.c", - "drv_3glasses/packet.c", - "drv_3glasses/xgvr.c", -# "drv_android/android.c", - "drv_deepoon/deepoon.c", - "drv_deepoon/packet.c", - "drv_dummy/dummy.c", -# "drv_external/external.c", - "drv_htc_vive/packet.c", - "drv_htc_vive/vive.c", - "drv_nolo/nolo.c", - "drv_nolo/packet.c", - "drv_oculus_rift/packet.c", - "drv_oculus_rift/rift-hmd-radio.c", - "drv_oculus_rift/rift.c", - "drv_psvr/packet.c", - "drv_psvr/psvr.c", - "drv_vrtek/packet.c", - "drv_vrtek/vrtek.c", - "drv_wmr/wmr.c", - "drv_wmr/packet.c", -# "ext_deps/miniz.c", - "ext_deps/nxjson.c", -] - -sources.append([openhmd_path + "src/" + file for file in openhmd_sources]) - -if platform == 'windows': - sources.append(openhmd_path + "src/platform-win32.c" ) -else: - sources.append(openhmd_path + "src/platform-posix.c" ) - -#################################################################################################################################### -# and add our main project -env.Append(CPPPATH=['.', godot_headers_path, godot_glad_path]) - -add_sources(sources, "src") - -library = env.SharedLibrary(target=godot_openhmd_path + 'godot_openhmd', source=sources) -Default(library) diff --git a/VERSION.md b/VERSION.md new file mode 100644 index 0000000..ea4eccc --- /dev/null +++ b/VERSION.md @@ -0,0 +1 @@ +See CHANGES.md in `demo/addons/godot-openhmd` for change/version history diff --git a/demo/Box.tscn b/demo/Box.tscn new file mode 100644 index 0000000..2dcfcb1 --- /dev/null +++ b/demo/Box.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://assets/wahooney.itch.io/blue_grid.tres" type="Material" id=1] + +[sub_resource type="CubeMesh" id=1] +material = ExtResource( 1 ) +size = Vector3( 1, 1, 1 ) + +[sub_resource type="BoxShape" id=2] +extents = Vector3( 0.5, 0.5, 0.5 ) + +[node name="Box" type="RigidBody"] + +[node name="MeshInstance" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) +material/0 = null + +[node name="CollisionShape" type="CollisionShape" parent="."] +shape = SubResource( 2 ) diff --git a/demo/Main.gd b/demo/Main.gd index 2a5834a..b14e1ee 100644 --- a/demo/Main.gd +++ b/demo/Main.gd @@ -32,7 +32,6 @@ func _ready(): # and tell our viewport to render get_viewport().arvr = true - func _process(delta): diff --git a/demo/Main.tscn b/demo/Main.tscn index b2379d7..0377032 100644 --- a/demo/Main.tscn +++ b/demo/Main.tscn @@ -1,42 +1,27 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://Main.gd" type="Script" id=1] -[ext_resource path="res://Milkyway.png" type="Texture" id=2] +[ext_resource path="res://assets/wahooney.itch.io/green_grid.tres" type="Material" id=2] [ext_resource path="res://Table.tscn" type="PackedScene" id=3] +[ext_resource path="res://Box.tscn" type="PackedScene" id=4] -[sub_resource type="PanoramaSky" id=1] - -panorama = ExtResource( 2 ) - -[sub_resource type="Environment" id=2] - -background_mode = 2 -background_sky = SubResource( 1 ) -background_color = Color( 0, 0.53833, 0.703125, 1 ) -ambient_light_color = Color( 0.328125, 0.328125, 0.328125, 1 ) -ssao_blur = 1 - -[sub_resource type="SpatialMaterial" id=3] - -params_diffuse_mode = 1 -albedo_color = Color( 0.0342134, 0.992188, 0.116539, 1 ) -roughness = 0.0 - -[sub_resource type="PlaneMesh" id=4] - -material = SubResource( 3 ) -size = Vector2( 10, 10 ) +[sub_resource type="PlaneMesh" id=1] +material = ExtResource( 2 ) +size = Vector2( 50, 50 ) subdivide_width = 10 subdivide_depth = 10 +[sub_resource type="BoxShape" id=2] +extents = Vector3( 500, 1, 500 ) + [node name="Main" type="Spatial"] script = ExtResource( 1 ) -[node name="WorldEnvironment" type="WorldEnvironment" parent="."] -environment = SubResource( 2 ) - [node name="DirectionalLight" type="DirectionalLight" parent="."] -transform = Transform( 0.623013, -0.733525, 0.271654, 0.321394, 0.55667, 0.766044, -0.713134, -0.389948, 0.582563, 0, 100, 0 ) +transform = Transform( 0.821741, 0.208431, -0.530376, 0.0742327, 0.883628, 0.462267, 0.565006, -0.419235, 0.71064, 0.000575226, 10, 2.24113e-05 ) +shadow_enabled = true +shadow_bias = 0.01 +directional_shadow_max_distance = 20.0 [node name="ARVROrigin" type="ARVROrigin" parent="."] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.85, 0 ) @@ -45,10 +30,28 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.85, 0 ) fov = 65.0 near = 0.1 -[node name="Ground" type="MeshInstance" parent="."] +[node name="LeftHand" type="ARVRController" parent="ARVROrigin"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1, 0 ) + +[node name="RightHand" type="ARVRController" parent="ARVROrigin"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 1, 0 ) +controller_id = 2 + +[node name="Table" parent="." instance=ExtResource( 3 )] + +[node name="Ground" type="StaticBody" parent="."] + +[node name="MeshInstance" type="MeshInstance" parent="Ground"] transform = Transform( 100, 0, 0, 0, 100, 0, 0, 0, 100, 0, 0, 0 ) -mesh = SubResource( 4 ) +mesh = SubResource( 1 ) material/0 = null -[node name="Table" parent="." instance=ExtResource( 3 )] +[node name="CollisionShape" type="CollisionShape" parent="Ground"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 ) +shape = SubResource( 2 ) + +[node name="Box01" parent="." instance=ExtResource( 4 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 0.5, -3 ) +[node name="Box02" parent="." instance=ExtResource( 4 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 1.5, -3 ) diff --git a/demo/Table.tscn b/demo/Table.tscn index c821ea8..ea49467 100644 --- a/demo/Table.tscn +++ b/demo/Table.tscn @@ -1,217 +1,41 @@ [gd_scene load_steps=5 format=2] -[sub_resource type="SpatialMaterial" id=4] - -resource_name = "LegMat" -render_priority = 0 -flags_transparent = false -flags_unshaded = false -flags_vertex_lighting = false -flags_no_depth_test = false -flags_use_point_size = false -flags_world_triplanar = false -flags_fixed_size = false -vertex_color_use_as_albedo = false -vertex_color_is_srgb = false -params_diffuse_mode = 1 -params_specular_mode = 0 -params_blend_mode = 0 -params_cull_mode = 0 -params_depth_draw_mode = 0 -params_line_width = 1.0 -params_point_size = 1.0 -params_billboard_mode = 0 -params_grow = false -params_use_alpha_scissor = false -albedo_color = Color( 0.714844, 0.552887, 0, 1 ) -metallic = 0.0 -metallic_specular = 0.5 -metallic_texture_channel = 0 -roughness = 0.0 -roughness_texture_channel = 0 -emission_enabled = false -normal_enabled = false -rim_enabled = false -clearcoat_enabled = false -anisotropy_enabled = false -ao_enabled = false -depth_enabled = false -subsurf_scatter_enabled = false -transmission_enabled = false -refraction_enabled = false -detail_enabled = false -uv1_scale = Vector3( 1, 1, 1 ) -uv1_offset = Vector3( 0, 0, 0 ) -uv1_triplanar = false -uv1_triplanar_sharpness = 1.0 -uv2_scale = Vector3( 1, 1, 1 ) -uv2_offset = Vector3( 0, 0, 0 ) -uv2_triplanar = false -uv2_triplanar_sharpness = 1.0 -proximity_fade_enable = false -proximity_fade_distance = 1.0 -distance_fade_enable = false -_sections_unfolded = [ "Albedo", "Parameters", "Resource" ] - -[sub_resource type="CubeMesh" id=5] +[ext_resource path="res://assets/texturehaven.com/brown_planks_03/brown_planks_03.tres" type="Material" id=1] +[ext_resource path="res://assets/texturehaven.com/green_metal_rust/green_metal_rust.tres" type="Material" id=2] +[sub_resource type="CubeMesh" id=1] resource_name = "Leg" -material = SubResource( 4 ) +material = ExtResource( 1 ) size = Vector3( 0.2, 1, 0.2 ) -subdivide_width = 0 -subdivide_height = 0 -subdivide_depth = 0 -_sections_unfolded = [ "Resource" ] - -[sub_resource type="SpatialMaterial" id=6] - -resource_name = "TableMat" -render_priority = 0 -flags_transparent = false -flags_unshaded = false -flags_vertex_lighting = false -flags_no_depth_test = false -flags_use_point_size = false -flags_world_triplanar = false -flags_fixed_size = false -vertex_color_use_as_albedo = false -vertex_color_is_srgb = false -params_diffuse_mode = 1 -params_specular_mode = 0 -params_blend_mode = 0 -params_cull_mode = 0 -params_depth_draw_mode = 0 -params_line_width = 1.0 -params_point_size = 1.0 -params_billboard_mode = 0 -params_grow = false -params_use_alpha_scissor = false -albedo_color = Color( 1, 1, 1, 1 ) -metallic = 0.4 -metallic_specular = 0.5 -metallic_texture_channel = 0 -roughness = 0.0 -roughness_texture_channel = 0 -emission_enabled = false -normal_enabled = false -rim_enabled = false -clearcoat_enabled = false -anisotropy_enabled = false -ao_enabled = false -depth_enabled = false -subsurf_scatter_enabled = false -transmission_enabled = false -refraction_enabled = false -detail_enabled = false -uv1_scale = Vector3( 1, 1, 1 ) -uv1_offset = Vector3( 0, 0, 0 ) -uv1_triplanar = false -uv1_triplanar_sharpness = 1.0 -uv2_scale = Vector3( 1, 1, 1 ) -uv2_offset = Vector3( 0, 0, 0 ) -uv2_triplanar = false -uv2_triplanar_sharpness = 1.0 -proximity_fade_enable = false -proximity_fade_distance = 1.0 -distance_fade_enable = false -_sections_unfolded = [ "Metallic", "Resource" ] -[sub_resource type="CubeMesh" id=7] - -material = SubResource( 6 ) +[sub_resource type="CubeMesh" id=2] +material = ExtResource( 2 ) size = Vector3( 2.2, 0.1, 1.2 ) -subdivide_width = 0 -subdivide_height = 0 -subdivide_depth = 0 [node name="Table" type="Spatial"] - transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -6 ) -_sections_unfolded = [ "Transform" ] [node name="Leg1" type="MeshInstance" parent="."] - transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0.5, 0.5 ) -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( 5 ) -skeleton = NodePath("..") +mesh = SubResource( 1 ) material/0 = null -_sections_unfolded = [ "Transform" ] [node name="Leg2" type="MeshInstance" parent="."] - transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0.5, 0.5 ) -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( 5 ) -skeleton = NodePath("..") +mesh = SubResource( 1 ) material/0 = null -_sections_unfolded = [ "Transform" ] [node name="Leg3" type="MeshInstance" parent="."] - transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0.5, -0.5 ) -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( 5 ) -skeleton = NodePath("..") +mesh = SubResource( 1 ) material/0 = null -_sections_unfolded = [ "Transform" ] [node name="Leg4" type="MeshInstance" parent="."] - transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0.5, -0.5 ) -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( 5 ) -skeleton = NodePath("..") +mesh = SubResource( 1 ) material/0 = null -_sections_unfolded = [ "Transform" ] [node name="Surface" type="MeshInstance" parent="."] - transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.05, 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( 7 ) -skeleton = NodePath("..") +mesh = SubResource( 2 ) material/0 = null -_sections_unfolded = [ "Transform" ] - - diff --git a/demo/addons/godot-openhmd/CHANGES.md b/demo/addons/godot-openhmd/CHANGES.md new file mode 100644 index 0000000..abc3b19 --- /dev/null +++ b/demo/addons/godot-openhmd/CHANGES.md @@ -0,0 +1,14 @@ +Changes to the Godot OpenHMD 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. + +0.1.1 - In progress +------------------- +* Changed build system to meson + +0.1.0 - 4 May 2018 +------------------ +Changes were not tracked diff --git a/demo/addons/godot-openhmd/bin/win64/godot_openhmd-0.dll b/demo/addons/godot-openhmd/bin/win64/godot_openhmd-0.dll new file mode 100644 index 0000000..e88df36 Binary files /dev/null and b/demo/addons/godot-openhmd/bin/win64/godot_openhmd-0.dll differ diff --git a/demo/addons/godot-openhmd/bin/win64/godot_openhmd.dll b/demo/addons/godot-openhmd/bin/win64/godot_openhmd.dll deleted file mode 100644 index a2402f4..0000000 Binary files a/demo/addons/godot-openhmd/bin/win64/godot_openhmd.dll and /dev/null differ diff --git a/demo/addons/godot-openhmd/bin/win64/hidapi.dll b/demo/addons/godot-openhmd/bin/win64/hidapi.dll new file mode 100644 index 0000000..58736a0 Binary files /dev/null and b/demo/addons/godot-openhmd/bin/win64/hidapi.dll differ diff --git a/demo/addons/godot-openhmd/bin/win64/openhmd-0.dll b/demo/addons/godot-openhmd/bin/win64/openhmd-0.dll new file mode 100644 index 0000000..dd1f3a1 Binary files /dev/null and b/demo/addons/godot-openhmd/bin/win64/openhmd-0.dll differ diff --git a/demo/addons/godot-openhmd/godot_openhmd.gdnlib b/demo/addons/godot-openhmd/godot_openhmd.gdnlib index e139ad8..dd4b156 100644 --- a/demo/addons/godot-openhmd/godot_openhmd.gdnlib +++ b/demo/addons/godot-openhmd/godot_openhmd.gdnlib @@ -8,11 +8,11 @@ reloadable=false [entry] X11.64="res://addons/godot-openhmd/bin/linux/libgodot_openhmd.so" -Windows.64="res://addons/godot-openhmd/bin/win64/godot_openhmd.dll" +Windows.64="res://addons/godot-openhmd/bin/win64/godot_openhmd-0.dll" OSX="res://addons/godot-openhmd/bin/osx/libgodot_openhmd.dylib" [dependencies] X11.64=[ ] -Windows=[ ] +Windows=[ "res://addons/godot-openhmd/bin/win64/openhmd-0.dll", "res://addons/godot-openhmd/bin/win64/hidapi.dll" ] OSX.64=[ ] diff --git a/demo/addons/vr-common/LICENSE b/demo/addons/vr-common/LICENSE new file mode 100644 index 0000000..94f3df6 --- /dev/null +++ b/demo/addons/vr-common/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018-2019 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 +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/demo/addons/vr-common/VERSIONS.md b/demo/addons/vr-common/VERSIONS.md new file mode 100644 index 0000000..0606fcb --- /dev/null +++ b/demo/addons/vr-common/VERSIONS.md @@ -0,0 +1,15 @@ +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 diff --git a/demo/addons/vr-common/functions/Function_Direct_movement.gd b/demo/addons/vr-common/functions/Function_Direct_movement.gd index 56d184c..9a61426 100644 --- a/demo/addons/vr-common/functions/Function_Direct_movement.gd +++ b/demo/addons/vr-common/functions/Function_Direct_movement.gd @@ -1,11 +1,14 @@ -extends Spatial +extends Node -# some handy nodes... -export (NodePath) var origin = null +enum MOVEMENT_TYPE { MOVE_AND_ROTATE, MOVE_AND_STRAFE } + +# Is this active? +export var enabled = true setget set_enabled, get_enabled + +# We don't know the name of the camera node... export (NodePath) var camera = null # size of our player -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 # to combat motion sickness we'll 'step' our left/right turning @@ -14,126 +17,186 @@ 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") +onready var collision_shape: CollisionShape = get_node("KinematicBody/CollisionShape") +onready var tail : RayCast = get_node("KinematicBody/Tail") -func get_player_height(): - return player_height - -func set_player_height(p_height): - player_height = p_height - +func set_enabled(new_value): + enabled = new_value if collision_shape: - # for some reason collision shape height measurement is half up, half down from center - collision_shape.shape.height = (player_height / 2.0) - collision_shape.translation = Vector3(0.0, player_height / 2.0, 0.0) + collision_shape.disabled = !enabled + if tail: + tail.enabled = enabled + if enabled: + # make sure our physics process is on + set_physics_process(true) + else: + # we turn this off in physics process just in case we want to do some cleanup + pass + +func get_enabled(): + return enabled func get_player_radius(): return player_radius func set_player_radius(p_radius): player_radius = p_radius - - if collision_shape: - collision_shape.shape.height = (player_height / 2.0) - collision_shape.shape.radius = player_radius func _ready(): - origin_node = get_node(origin) - camera_node = get_node(camera) + # 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_height(player_height) set_player_radius(player_radius) + + collision_shape.disabled = !enabled + tail.enabled = enabled func _physics_process(delta): + if !origin_node: + return + + if !camera_node: + return + + if !enabled: + set_physics_process(false) + return + + # Adjust the height of our player according to our camera position + var player_height = camera_node.transform.origin.y + player_radius + if player_height < player_radius: + # not smaller than this + player_height = player_radius + + collision_shape.shape.radius = player_radius + collision_shape.shape.height = player_height - (player_radius * 2.0) + collision_shape.transform.origin.y = (player_height / 2.0) + # 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 :) - if (abs(left_right) > 0.1): - if left_right > 0.0: - if turn_step < 0.0: - # reset step - turn_step = 0 + # 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 - 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: - if turn_step > 0.0: - # reset step - turn_step = 0 - - turn_step += left_right * delta + turn_step = 0.0 - 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() + ################################################################ + # 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 - t1.origin = -camera_node.transform.origin - t2.origin = camera_node.transform.origin + # we'll handle gravity separately + var gravity_velocity = Vector3(0.0, velocity.y, 0.0) + velocity.y = 0.0 - # 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 + # Apply our drag + velocity *= (1.0 - drag_factor) - 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 new_transform = $KinematicBody.global_transform - var camera_transform = camera_node.global_transform - new_transform.origin = camera_transform.origin - new_transform.origin.y = origin_node.global_transform.origin.y - $KinematicBody.global_transform = new_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 (abs(forwards_backwards) > 0.1 and tail.is_colliding()): - var dir = camera_transform.basis.z - dir.y = 0.0 + 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 - velocity = dir.normalized() * -forwards_backwards * delta * max_speed * ARVRServer.world_scale -# velocity = velocity.linear_interpolate(dir, delta * 100.0) - - # 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 - new_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 = new_transform.origin - - # We can't use move and collide here because we're moving our world center and thus our kinematic body indirectly. - # Need to improve on that... - # origin_node.translation -= dir.normalized() * delta * forwards_backwards * 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/demo/addons/vr-common/functions/Function_Direct_movement.tscn b/demo/addons/vr-common/functions/Function_Direct_movement.tscn index 7ccf3c4..6fc829f 100644 --- a/demo/addons/vr-common/functions/Function_Direct_movement.tscn +++ b/demo/addons/vr-common/functions/Function_Direct_movement.tscn @@ -3,51 +3,22 @@ [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="Spatial" index="0"] - +[node name="Function_Direct_movement" type="Node"] script = ExtResource( 1 ) -origin = null -camera = null -player_height = 1.8 -player_radius = 0.4 -turn_delay = 0.2 -turn_angle = 20.0 max_speed = 500.0 -drag_factor = 0.1 - -[node name="KinematicBody" type="KinematicBody" parent="." index="0"] - -input_ray_pickable = true -input_capture_on_drag = false -collision_layer = 524288 -collision_mask = 1 -axis_lock_linear_x = false -axis_lock_linear_y = false -axis_lock_linear_z = false -axis_lock_angular_x = false -axis_lock_angular_y = false -axis_lock_angular_z = false -collision/safe_margin = 0.001 -_sections_unfolded = [ "Collision", "Transform" ] -[node name="CollisionShape" type="CollisionShape" parent="KinematicBody" index="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-08, -1, 0, 1, -4.37114e-08, 0, 0.9, 0 ) shape = SubResource( 1 ) -disabled = false -_sections_unfolded = [ "Transform" ] - -[node name="Tail" type="RayCast" parent="KinematicBody" index="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 -exclude_parent = true cast_to = Vector3( 0, -0.6, 0 ) -collision_mask = 1 -_sections_unfolded = [ "Transform" ] - - +collision_mask = 1048574 diff --git a/demo/addons/vr-common/functions/Function_Pickup.gd b/demo/addons/vr-common/functions/Function_Pickup.gd new file mode 100644 index 0000000..8694e3f --- /dev/null +++ b/demo/addons/vr-common/functions/Function_Pickup.gd @@ -0,0 +1,113 @@ +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 +export var max_samples = 5 + +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 velocities = Array() + +func _get_velocity(): + var velocity = Vector3(0.0, 0.0, 0.0) + var count = velocities.size() + + if count > 0: + for v in velocities: + velocity = velocity + v + + velocity = velocity / count + + return velocity + +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(_get_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): + velocities.push_back((global_transform.origin - last_position) / delta) + if velocities.size() > max_samples: + velocities.pop_front() + + last_position = global_transform.origin + _update_closest_object() diff --git a/demo/addons/vr-common/functions/Function_Pickup.tscn b/demo/addons/vr-common/functions/Function_Pickup.tscn new file mode 100644 index 0000000..c5f00b7 --- /dev/null +++ b/demo/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/demo/addons/vr-common/functions/Function_Teleport.gd b/demo/addons/vr-common/functions/Function_Teleport.gd index f8d3be6..f7c9062 100644 --- a/demo/addons/vr-common/functions/Function_Teleport.gd +++ b/demo/addons/vr-common/functions/Function_Teleport.gd @@ -2,9 +2,12 @@ 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. -# Then set origin to your ARVROrigin node -export (NodePath) var origin = null +# Is this active? +export var enabled = true setget set_enabled, get_enabled + +# 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) @@ -14,8 +17,12 @@ export var strength = 5.0 # once this is no longer a kinematic body, we'll need this.. # export var collision_mask = 1 +# We don't know the name of the camera node... +export (NodePath) var camera = null + onready var ws = ARVRServer.world_scale var origin_node = null +var camera_node = null var is_on_floor = true var is_teleporting = false var can_teleport = true @@ -31,6 +38,18 @@ var step_size = 0.5 # and add your own player character as child. onready var capsule = get_node("Target/Player_figure/Capsule") +func set_enabled(new_value): + enabled = new_value + if enabled: + # make sure our physics process is on + set_physics_process(true) + else: + # we turn this off in physics process just in case we want to do some cleanup + pass + +func get_enabled(): + return enabled + func get_player_height(): return player_height @@ -59,8 +78,8 @@ func set_player_radius(p_radius): capsule.mesh.radius = player_radius func _ready(): - # And its parent should be our origin point - origin_node = get_node(origin) + # 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 @@ -69,7 +88,14 @@ func _ready(): # 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) + if camera: + camera_node = get_node(camera) + else: + # see if we can find our default + camera_node = origin_node.get_node('ARVRCamera') + # create shape object collision_shape = CapsuleShape.new() @@ -77,20 +103,36 @@ func _ready(): 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() + if !origin_node: + return + + if !camera_node: + return + + # if we're not enabled no point in doing mode + if !enabled: + # reset these + is_teleporting = false; + $Teleport.visible = false + $Target.visible = false + + # and stop this from running until we enable again + set_physics_process(false) + return + # 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) - # button 15 is mapped to our trigger - if controller and controller.get_is_active() and controller.is_button_pressed(15): + if controller and controller.get_is_active() and controller.is_button_pressed(teleport_button): if !is_teleporting: is_teleporting = true $Teleport.visible = true @@ -209,24 +251,33 @@ func _physics_process(delta): $Teleport.get_surface_material(0).set_shader_param("mix_color", color) $Target.get_surface_material(0).albedo_color = color - $Target.visible = true + $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: - # reset our player position to center - ARVRServer.center_on_hmd(true, true) # 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) - new_transform.basis.z = new_transform.basis.x.cross(new_transform.basis.y) + 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 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() - # and change our location - origin_node.global_transform = new_transform + # 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; diff --git a/demo/addons/vr-common/functions/Function_Teleport.tscn b/demo/addons/vr-common/functions/Function_Teleport.tscn index f498d29..0ce9f9c 100644 --- a/demo/addons/vr-common/functions/Function_Teleport.tscn +++ b/demo/addons/vr-common/functions/Function_Teleport.tscn @@ -1,259 +1,38 @@ -[gd_scene load_steps=11 format=2] +[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/images/teleport_arrow.png" type="Texture" id=2] -[ext_resource path="res://addons/vr-common/images/teleport_target.png" type="Texture" id=3] +[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_width = 0 subdivide_depth = 40 -[sub_resource type="Shader" id=2] - -code = "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; -} -" - -[sub_resource type="ShaderMaterial" id=3] - -render_priority = 0 -shader = SubResource( 2 ) -shader_param/scale_t = 0.2 -shader_param/length = 30.0 -shader_param/ws = null -shader_param/mix_color = Color( 0.176471, 0.313726, 0.862745, 1 ) -shader_param/arrow_texture = ExtResource( 2 ) -_sections_unfolded = [ "shader_param" ] - -[sub_resource type="PlaneMesh" id=4] - +[sub_resource type="PlaneMesh" id=2] size = Vector2( 1, 1 ) -subdivide_width = 0 -subdivide_depth = 0 - -[sub_resource type="SpatialMaterial" id=5] - -render_priority = 0 -flags_transparent = true -flags_unshaded = true -flags_vertex_lighting = false -flags_no_depth_test = false -flags_use_point_size = false -flags_world_triplanar = false -flags_fixed_size = false -flags_albedo_tex_force_srgb = false -vertex_color_use_as_albedo = false -vertex_color_is_srgb = false -params_diffuse_mode = 1 -params_specular_mode = 0 -params_blend_mode = 0 -params_cull_mode = 2 -params_depth_draw_mode = 0 -params_line_width = 1.0 -params_point_size = 1.0 -params_billboard_mode = 0 -params_grow = false -params_use_alpha_scissor = false -albedo_color = Color( 0.176471, 0.313726, 0.862745, 1 ) -albedo_texture = ExtResource( 3 ) -metallic = 0.0 -metallic_specular = 0.5 -metallic_texture_channel = 0 -roughness = 0.0 -roughness_texture_channel = 0 -emission_enabled = false -normal_enabled = false -rim_enabled = false -clearcoat_enabled = false -anisotropy_enabled = false -ao_enabled = false -depth_enabled = false -subsurf_scatter_enabled = false -transmission_enabled = false -refraction_enabled = false -detail_enabled = false -uv1_scale = Vector3( 1, 1, 1 ) -uv1_offset = Vector3( 0, 0, 0 ) -uv1_triplanar = false -uv1_triplanar_sharpness = 1.0 -uv2_scale = Vector3( 1, 1, 1 ) -uv2_offset = Vector3( 0, 0, 0 ) -uv2_triplanar = false -uv2_triplanar_sharpness = 1.0 -proximity_fade_enable = false -distance_fade_enable = false -_sections_unfolded = [ "Albedo", "Flags", "Parameters" ] - -[sub_resource type="CapsuleMesh" id=6] +[sub_resource type="CapsuleMesh" id=3] radius = 0.3 mid_height = 1.2 -radial_segments = 64 -rings = 8 - -[sub_resource type="SpatialMaterial" id=7] - -render_priority = 0 -flags_transparent = true -flags_unshaded = false -flags_vertex_lighting = false -flags_no_depth_test = false -flags_use_point_size = false -flags_world_triplanar = false -flags_fixed_size = false -flags_albedo_tex_force_srgb = false -vertex_color_use_as_albedo = false -vertex_color_is_srgb = false -params_diffuse_mode = 0 -params_specular_mode = 0 -params_blend_mode = 0 -params_cull_mode = 0 -params_depth_draw_mode = 0 -params_line_width = 1.0 -params_point_size = 1.0 -params_billboard_mode = 0 -params_grow = false -params_use_alpha_scissor = false -albedo_color = Color( 0.0337219, 0.241112, 0.863281, 0.497255 ) -metallic = 0.0 -metallic_specular = 0.5 -metallic_texture_channel = 0 -roughness = 0.0 -roughness_texture_channel = 0 -emission_enabled = false -normal_enabled = false -rim_enabled = false -clearcoat_enabled = false -anisotropy_enabled = false -ao_enabled = false -depth_enabled = false -subsurf_scatter_enabled = false -transmission_enabled = false -refraction_enabled = false -detail_enabled = false -uv1_scale = Vector3( 1, 1, 1 ) -uv1_offset = Vector3( 0, 0, 0 ) -uv1_triplanar = false -uv1_triplanar_sharpness = 1.0 -uv2_scale = Vector3( 1, 1, 1 ) -uv2_offset = Vector3( 0, 0, 0 ) -uv2_triplanar = false -uv2_triplanar_sharpness = 1.0 -proximity_fade_enable = false -distance_fade_enable = false -_sections_unfolded = [ "Albedo", "Flags" ] - -[node name="Function_Teleport" type="KinematicBody" index="0"] +[node name="Function_Teleport" type="KinematicBody"] input_ray_pickable = false -input_capture_on_drag = false -collision_layer = 1 -collision_mask = 1 -axis_lock_linear_x = false -axis_lock_linear_y = false -axis_lock_linear_z = false -axis_lock_angular_x = false -axis_lock_angular_y = false -axis_lock_angular_z = false collision/safe_margin = 0.01 script = ExtResource( 1 ) -_sections_unfolded = [ "Axis Lock", "Collision", "Transform", "collision" ] -origin = null -can_teleport_color = Color( 0, 1, 0, 1 ) -cant_teleport_color = Color( 1, 0, 0, 1 ) no_collision_color = Color( 0.176471, 0.313726, 0.862745, 1 ) -player_height = 1.8 -player_radius = 0.4 -strength = 5.0 -[node name="Teleport" 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 +[node name="Teleport" type="MeshInstance" parent="."] mesh = SubResource( 1 ) -skeleton = NodePath("..") -material/0 = SubResource( 3 ) -_sections_unfolded = [ "Transform", "material" ] - -[node name="Target" type="MeshInstance" parent="." index="1"] - -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( 4 ) -skeleton = NodePath("..") -material/0 = SubResource( 5 ) -_sections_unfolded = [ "material" ] +material/0 = ExtResource( 2 ) -[node name="Player_figure" type="Position3D" parent="Target" index="0"] +[node name="Target" type="MeshInstance" parent="."] +mesh = SubResource( 2 ) +material/0 = ExtResource( 3 ) -[node name="Capsule" type="MeshInstance" parent="Target/Player_figure" index="0"] +[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 ) -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( 6 ) -skeleton = NodePath("..") -material/0 = SubResource( 7 ) -_sections_unfolded = [ "Transform", "material" ] - - +mesh = SubResource( 3 ) +material/0 = ExtResource( 4 ) diff --git a/demo/addons/vr-common/functions/Function_pointer.gd b/demo/addons/vr-common/functions/Function_pointer.gd new file mode 100644 index 0000000..e849711 --- /dev/null +++ b/demo/addons/vr-common/functions/Function_pointer.gd @@ -0,0 +1,147 @@ +extends Spatial + +signal pointer_pressed(on, at) +signal pointer_released(on, at) +signal pointer_moved(on, from, to) + +signal pointer_entered(body) +signal pointer_exited(body) + +export var enabled = true setget set_enabled, get_enabled +export var ducktyped_body = true +export var active_button = 15 +export var distance = 10 setget set_distance, get_distance + +# Need to replace this with proper solution once support for layer selection has been added +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 = 15 setget set_collision_mask, get_collision_mask + +var target = null +var last_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): + enabled = p_enabled + + # this gets called before our scene is ready, we'll call this again in _ready to enable this + if $Laser: + $Laser.visible = p_enabled + + $Laser/RayCast.enabled = p_enabled + +func get_enabled(): + return enabled + +func set_collision_mask(p_new_mask): + collision_mask = p_new_mask + + if $Laser: + $Laser/RayCast.collision_mask = collision_mask + +func get_collision_mask(): + return collision_mask + +func set_distance(p_new_value): + distance = p_new_value + if $Laser: + $Laser.mesh.size.z = distance + $Laser.translation.z = distance * -0.5 + $Laser/RayCast.translation.z = distance * 0.5 + $Laser/RayCast.cast_to.z = -distance + +func get_distance(): + return distance + +func _on_button_pressed(p_button): + if p_button == active_button and enabled: + if $Laser/RayCast.is_colliding(): + target = $Laser/RayCast.get_collider() + last_collided_at = $Laser/RayCast.get_collision_point() + + emit_signal("pointer_pressed", target, last_collided_at) + + if ducktyped_body and target.has_method("pointer_pressed"): + target.pointer_pressed(last_collided_at) + +func _on_button_release(p_button): + if p_button == active_button and target: + emit_signal("pointer_released", target, last_collided_at) + + if ducktyped_body and target.has_method("pointer_released"): + target.pointer_released(last_collided_at) + + # unset target + target = null + 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 + + # init our state + set_distance(distance) + set_collision_mask(collision_mask) + set_enabled(enabled) + +func _process(delta): + if !is_inside_tree(): + return + + var new_ws = ARVRServer.world_scale + if (ws != new_ws): + ws = new_ws + $Laser.translation.y = laser_y * ws + + if enabled and $Laser/RayCast.is_colliding(): + var new_at = $Laser/RayCast.get_collision_point() + + if is_instance_valid(target): + # if target is set our mouse must be down, we keep "focus" on our target + if new_at != last_collided_at: + emit_signal("pointer_moved", target, last_collided_at, new_at) + + if ducktyped_body and target.has_method("pointer_moved"): + target.pointer_moved(last_collided_at, new_at) + else: + var new_target = $Laser/RayCast.get_collider() + + # are we pointing to a new target? + if new_target != last_target: + # exit the old + if is_instance_valid(last_target): + emit_signal("pointer_exited", last_target) + + if ducktyped_body and last_target.has_method("pointer_exited"): + last_target.pointer_exited() + + # enter the new + if is_instance_valid(new_target): + emit_signal("pointer_entered", new_target) + + if ducktyped_body and new_target.has_method("pointer_entered"): + new_target.pointer_entered() + + last_target = new_target + + if new_at != last_collided_at: + emit_signal("pointer_moved", new_target, last_collided_at, new_at) + + if ducktyped_body and new_target.has_method("pointer_moved"): + new_target.pointer_moved(last_collided_at, new_at) + + # remember our new position + last_collided_at = new_at + elif is_instance_valid(last_target): + emit_signal("pointer_exited", last_target) + + if ducktyped_body and last_target.has_method("pointer_exited"): + last_target.pointer_exited() + + last_target = null + diff --git a/demo/addons/vr-common/functions/Function_pointer.tscn b/demo/addons/vr-common/functions/Function_pointer.tscn index 908619d..9663337 100644 --- a/demo/addons/vr-common/functions/Function_pointer.tscn +++ b/demo/addons/vr-common/functions/Function_pointer.tscn @@ -1,162 +1,27 @@ [gd_scene load_steps=4 format=2] -[sub_resource type="GDScript" id=1] +[ext_resource path="res://addons/vr-common/materials/pointer.tres" type="Material" id=1] +[ext_resource path="res://addons/vr-common/functions/Function_pointer.gd" type="Script" id=2] -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="SpatialMaterial" id=2] - -render_priority = 0 -flags_transparent = false -flags_unshaded = true -flags_vertex_lighting = false -flags_no_depth_test = false -flags_use_point_size = false -flags_world_triplanar = false -flags_fixed_size = false -flags_albedo_tex_force_srgb = false -vertex_color_use_as_albedo = false -vertex_color_is_srgb = false -params_diffuse_mode = 1 -params_specular_mode = 0 -params_blend_mode = 0 -params_cull_mode = 0 -params_depth_draw_mode = 0 -params_line_width = 1.0 -params_point_size = 1.0 -params_billboard_mode = 0 -params_grow = false -params_use_alpha_scissor = false -albedo_color = Color( 1, 0.15625, 0.15625, 0.740314 ) -metallic = 0.0 -metallic_specular = 0.5 -metallic_texture_channel = 0 -roughness = 0.0 -roughness_texture_channel = 0 -emission_enabled = true -emission = Color( 1, 0.171875, 0.171875, 1 ) -emission_energy = 1.0 -emission_operator = 0 -emission_on_uv2 = false -normal_enabled = false -rim_enabled = false -clearcoat_enabled = false -anisotropy_enabled = false -ao_enabled = false -depth_enabled = false -subsurf_scatter_enabled = false -transmission_enabled = false -refraction_enabled = false -detail_enabled = false -uv1_scale = Vector3( 1, 1, 1 ) -uv1_offset = Vector3( 0, 0, 0 ) -uv1_triplanar = false -uv1_triplanar_sharpness = 1.0 -uv2_scale = Vector3( 1, 1, 1 ) -uv2_offset = Vector3( 0, 0, 0 ) -uv2_triplanar = false -uv2_triplanar_sharpness = 1.0 -proximity_fade_enable = false -distance_fade_enable = false -_sections_unfolded = [ "Albedo", "Emission", "Flags", "Metallic", "Vertex Color" ] - -[sub_resource type="CubeMesh" id=3] - -material = SubResource( 2 ) +[sub_resource type="CubeMesh" id=1] +resource_local_to_scene = true +material = ExtResource( 1 ) size = Vector3( 0.002, 0.002, 10 ) -subdivide_width = 0 -subdivide_height = 0 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 ) -_sections_unfolded = [ "Transform" ] - -[node name="Laser" type="MeshInstance" parent="." index="0"] +script = ExtResource( 2 ) +collision_mask = 1048575 +[node name="Laser" type="MeshInstance" parent="."] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.05, -5 ) -layers = 1 -material_override = null cast_shadow = 0 -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( 3 ) -skeleton = NodePath("..") +mesh = SubResource( 1 ) material/0 = null -_sections_unfolded = [ "Geometry", "Transform" ] - -[node name="RayCast" type="RayCast" parent="Laser" index="0"] +[node name="RayCast" type="RayCast" parent="Laser"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5 ) enabled = true -exclude_parent = true cast_to = Vector3( 0, 0, -10 ) -collision_mask = 1 - - +collision_mask = 1048575 diff --git a/demo/addons/vr-common/images/Thumbs.db b/demo/addons/vr-common/images/Thumbs.db new file mode 100644 index 0000000..a446c46 Binary files /dev/null and b/demo/addons/vr-common/images/Thumbs.db differ diff --git a/demo/addons/vr-common/images/icon.png b/demo/addons/vr-common/images/icon.png new file mode 100644 index 0000000..9aec441 Binary files /dev/null and b/demo/addons/vr-common/images/icon.png differ diff --git a/demo/addons/vr-common/images/teleport_target.png b/demo/addons/vr-common/images/teleport_target.png index 2ce0c83..68518ee 100644 Binary files a/demo/addons/vr-common/images/teleport_target.png and b/demo/addons/vr-common/images/teleport_target.png differ diff --git a/demo/addons/vr-common/materials/capule.tres b/demo/addons/vr-common/materials/capule.tres new file mode 100644 index 0000000..feaeba3 --- /dev/null +++ b/demo/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/demo/addons/vr-common/materials/pointer.tres b/demo/addons/vr-common/materials/pointer.tres new file mode 100644 index 0000000..fea0522 --- /dev/null +++ b/demo/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/demo/addons/vr-common/materials/target.tres b/demo/addons/vr-common/materials/target.tres new file mode 100644 index 0000000..d72f86c --- /dev/null +++ b/demo/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/demo/addons/vr-common/materials/teleport.shader b/demo/addons/vr-common/materials/teleport.shader new file mode 100644 index 0000000..4e91468 --- /dev/null +++ b/demo/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/demo/addons/vr-common/materials/teleport.tres b/demo/addons/vr-common/materials/teleport.tres new file mode 100644 index 0000000..56d73af --- /dev/null +++ b/demo/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/demo/addons/vr-common/misc/VR_Common_Shader_Cache.gd b/demo/addons/vr-common/misc/VR_Common_Shader_Cache.gd new file mode 100644 index 0000000..4484c3e --- /dev/null +++ b/demo/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/demo/addons/vr-common/misc/VR_Common_Shader_Cache.tscn b/demo/addons/vr-common/misc/VR_Common_Shader_Cache.tscn new file mode 100644 index 0000000..35f23dc --- /dev/null +++ b/demo/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/demo/addons/vr-common/objects/Object_pickable.gd b/demo/addons/vr-common/objects/Object_pickable.gd new file mode 100644 index 0000000..85eb92d --- /dev/null +++ b/demo/addons/vr-common/objects/Object_pickable.gd @@ -0,0 +1,89 @@ +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(starting_linear_velocity = 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 + + # set our starting velocity + linear_velocity = starting_linear_velocity + +# 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/demo/addons/vr-common/objects/Object_pickable.tscn b/demo/addons/vr-common/objects/Object_pickable.tscn new file mode 100644 index 0000000..c2ec3ee --- /dev/null +++ b/demo/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/demo/addons/vr-common/objects/Viewport_2D_in_3D.gd b/demo/addons/vr-common/objects/Viewport_2D_in_3D.gd new file mode 100644 index 0000000..01d61f2 --- /dev/null +++ b/demo/addons/vr-common/objects/Viewport_2D_in_3D.gd @@ -0,0 +1,84 @@ +tool +extends Spatial + +export var screen_size = Vector2(3.0, 2.0) setget set_screen_size, get_screen_size +export var viewport_size = Vector2(300.0, 200.0) setget set_viewport_size, get_viewport_size +export var transparent = true setget set_transparent, get_transparent +export (PackedScene) var scene = null setget set_scene, get_scene + +# Need to replace this with proper solution once support for layer selection has been added +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 = 15 setget set_collision_layer, get_collision_layer + +var is_ready = false +var scene_node = null + +func set_screen_size(new_size: Vector2): + screen_size = new_size + if is_ready: + $Screen.mesh.size = screen_size + $StaticBody.screen_size = screen_size + $StaticBody/CollisionShape.shape.extents = Vector3(screen_size.x * 0.5, screen_size.y * 0.5, 0.01) + +func get_screen_size(): + return screen_size + +func set_viewport_size(new_size: Vector2): + viewport_size = new_size + if is_ready: + $Viewport.size = new_size + $StaticBody.viewport_size = new_size + var material : SpatialMaterial = $Screen.get_surface_material(0) + material.albedo_texture = $Viewport.get_texture() + +func get_viewport_size(): + return viewport_size + +func set_transparent(new_transparent: bool): + transparent = new_transparent + if is_ready: + var material : SpatialMaterial = $Screen.get_surface_material(0) + material.flags_transparent = transparent + $Viewport.transparent_bg = transparent + +func get_transparent(): + return transparent + +func set_collision_layer(new_layer: int): + collision_layer = new_layer + if is_ready: + $StaticBody.collision_layer = collision_layer + +func get_collision_layer(): + return collision_layer + +func set_scene(new_scene: PackedScene): + scene = new_scene + if is_ready: + # out with the old + if scene_node: + $Viewport.remove_child(scene_node) + scene_node.queue_free() + + # in with the new + if scene: + scene_node = scene.instance() + $Viewport.add_child(scene_node) + +func get_scene(): + return scene + +func get_scene_instance(): + return scene_node + +func connect_scene_signal(which, on, callback): + if scene_node: + scene_node.connect(which, on, callback) + +# Called when the node enters the scene tree for the first time. +func _ready(): + # apply properties + is_ready = true + set_screen_size(screen_size) + set_viewport_size(viewport_size) + set_scene(scene) + set_collision_layer(collision_layer) diff --git a/demo/addons/vr-common/objects/Viewport_2D_in_3D.tscn b/demo/addons/vr-common/objects/Viewport_2D_in_3D.tscn new file mode 100644 index 0000000..4fd899e --- /dev/null +++ b/demo/addons/vr-common/objects/Viewport_2D_in_3D.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://addons/vr-common/objects/Viewport_2D_in_3D.gd" type="Script" id=1] +[ext_resource path="res://addons/vr-common/objects/Viewport_2D_in_3D_body.gd" type="Script" id=2] + +[sub_resource type="QuadMesh" id=1] +resource_local_to_scene = true +size = Vector2( 3, 2 ) + +[sub_resource type="ViewportTexture" id=2] + +[sub_resource type="SpatialMaterial" id=3] +resource_local_to_scene = true +flags_transparent = true +flags_unshaded = true +params_cull_mode = 2 +albedo_texture = SubResource( 2 ) + +[sub_resource type="BoxShape" id=4] +resource_local_to_scene = true +extents = Vector3( 1.5, 1, 0.01 ) + +[node name="Viewport2Din3D" type="Spatial"] +script = ExtResource( 1 ) + +[node name="Screen" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) +material/0 = SubResource( 3 ) + +[node name="StaticBody" type="StaticBody" parent="."] +collision_mask = 0 +script = ExtResource( 2 ) +viewport = NodePath("../Viewport") + +[node name="CollisionShape" type="CollisionShape" parent="StaticBody"] +shape = SubResource( 4 ) + +[node name="Viewport" type="Viewport" parent="."] +size = Vector2( 300, 200 ) +transparent_bg = true +usage = 0 +render_target_v_flip = true +render_target_update_mode = 3 diff --git a/demo/addons/vr-common/objects/Viewport_2D_in_3D_body.gd b/demo/addons/vr-common/objects/Viewport_2D_in_3D_body.gd new file mode 100644 index 0000000..3ef300f --- /dev/null +++ b/demo/addons/vr-common/objects/Viewport_2D_in_3D_body.gd @@ -0,0 +1,70 @@ +extends StaticBody + +export (NodePath) var viewport = null +export var screen_size = Vector2(3.0, 2.0) +export var viewport_size = Vector2(100.0, 100.0) + +var vp = null +var mouse_mask = 0 + +# Called when the node enters the scene tree for the first time. +func _ready(): + if viewport: + vp = get_node(viewport) + else: + vp = null + +# Convert intersection point to screen coordinate +func global_to_viewport(p_at): + var t = $CollisionShape.global_transform + var at = t.xform_inv(p_at) + + # Convert to screen space + at.x = ((at.x / screen_size.x) + 0.5) * viewport_size.x + at.y = (0.5 - (at.y / screen_size.y)) * viewport_size.y + + return Vector2(at.x, at.y) + +func pointer_moved(from, to): + var local_from = global_to_viewport(from) + var local_to = global_to_viewport(to) + + # Let's mimic a mouse + var event = InputEventMouseMotion.new() + event.set_position(local_to) + event.set_global_position(local_to) + event.set_relative(local_to - local_from) # should this be scaled/warped? + event.set_button_mask(mouse_mask) + + if vp: + vp.input(event) + +func pointer_pressed(at): + var local_at = global_to_viewport(at) + + # Let's mimic a mouse + mouse_mask = 1 + var event = InputEventMouseButton.new() + event.set_button_index(1) + event.set_pressed(true) + event.set_position(local_at) + event.set_global_position(local_at) + event.set_button_mask(mouse_mask) + + if vp: + vp.input(event) + +func pointer_released(at): + var local_at = global_to_viewport(at) + + # Let's mimic a mouse + mouse_mask = 0 + var event = InputEventMouseButton.new() + event.set_button_index(1) + event.set_pressed(false) + event.set_position(local_at) + event.set_global_position(local_at) + event.set_button_mask(mouse_mask) + + if vp: + vp.input(event) diff --git a/demo/assets/.gitignore b/demo/assets/.gitignore new file mode 100644 index 0000000..435be22 --- /dev/null +++ b/demo/assets/.gitignore @@ -0,0 +1 @@ +!*.obj \ No newline at end of file diff --git a/demo/assets/hdrihaven.com/License.txt b/demo/assets/hdrihaven.com/License.txt new file mode 100644 index 0000000..cf6cb90 --- /dev/null +++ b/demo/assets/hdrihaven.com/License.txt @@ -0,0 +1,22 @@ +** from https://hdrihaven.com ** + +HDRI License + +All HDRIs on this site are licensed as CC0 - which is the most liberal license I know of. + +Here's an exerpt from the CC0 FAQ page to clarify: +"Once the creator or a subsequent owner of a work applies CC0 to a work, the work is no longer his or hers in any meaningful sense under copyright law. Anyone can then use the work in any way and for any purpose, including commercial purposes, subject to other laws and the rights others may have in the work or how the work is used. Think of CC0 as the "no rights reserved" option. CC0 is a useful tool for clarifying that you do not claim copyright in a work anywhere in the world." + +In other words: + + You can use the HDRIs for any purpose, including commercial work. + You do not need to give credit or attribution when using them (although it is appreciated). + You can redistribute them, share them around, include them when sharing your own work, or in a product you sell. + +The only thing you can't do is claim to be the original author of the HDRIs. + +More info: CC0 summary, CC0 wiki, CC0 FAQ. + +If you have any questions, feel free to email me at info@hdrihaven.com + +Disclaimer: occasionally a brand name, logo or other copyrighted design may appear in the HDRIs. It is the responsibility of the user not to infringe on these copyrights in their own work. diff --git a/demo/assets/hdrihaven.com/README.md b/demo/assets/hdrihaven.com/README.md new file mode 100644 index 0000000..9ec23b4 --- /dev/null +++ b/demo/assets/hdrihaven.com/README.md @@ -0,0 +1,6 @@ +Included here are HDRI downloaded from hdrihaven.com + +To save space in this repository low quality images are included. +Much higher resolution textures can be sourced from this website. + +See license.txt for licensing around these images. \ No newline at end of file diff --git a/demo/assets/hdrihaven.com/wasteland_clouds/wasteland_clouds_2k.hdr b/demo/assets/hdrihaven.com/wasteland_clouds/wasteland_clouds_2k.hdr new file mode 100644 index 0000000..0882f5b Binary files /dev/null and b/demo/assets/hdrihaven.com/wasteland_clouds/wasteland_clouds_2k.hdr differ diff --git a/demo/assets/texturehaven.com/License.txt b/demo/assets/texturehaven.com/License.txt new file mode 100644 index 0000000..25f6ad3 --- /dev/null +++ b/demo/assets/texturehaven.com/License.txt @@ -0,0 +1,22 @@ +** from https://texturehaven.com ** + +Texture License + +All textures on this site are licensed as CC0 - which is the most liberal license I know of. + +Here's an exerpt from the CC0 FAQ page to clarify: +"Once the creator or a subsequent owner of a work applies CC0 to a work, the work is no longer his or hers in any meaningful sense under copyright law. Anyone can then use the work in any way and for any purpose, including commercial purposes, subject to other laws and the rights others may have in the work or how the work is used. Think of CC0 as the "no rights reserved" option. CC0 is a useful tool for clarifying that you do not claim copyright in a work anywhere in the world." + +In other words: + + You can use the textures for any purpose, including commercial work. + You do not need to give credit or attribution when using them (although it is appreciated). + You can redistribute them, share them around, include them when sharing your own work, or in a product you sell. + +The only thing you can't do is claim to be the original author of the textures. + +More info: CC0 summary, CC0 wiki, CC0 FAQ. + +If you have any questions, feel free to email me at info@texturehaven.com + +Disclaimer: occasionally a brand name, logo or other copyrighted design may appear in the textures. It is the responsibility of the user not to infringe on these copyrights in their own work. diff --git a/demo/assets/texturehaven.com/README.md b/demo/assets/texturehaven.com/README.md new file mode 100644 index 0000000..5945164 --- /dev/null +++ b/demo/assets/texturehaven.com/README.md @@ -0,0 +1,6 @@ +Included here are texture packs downloaded from texturehaven.com + +To save space in this repository low quality textures are included. +Much higher resolution textures can be sourced from this website. + +See license.txt for licensing around these textures. \ No newline at end of file diff --git a/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03.tres b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03.tres new file mode 100644 index 0000000..19814d5 --- /dev/null +++ b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03.tres @@ -0,0 +1,16 @@ +[gd_resource type="SpatialMaterial" load_steps=5 format=2] + +[ext_resource path="res://assets/texturehaven.com/brown_planks_03/brown_planks_03_diff_1k.jpg" type="Texture" id=1] +[ext_resource path="res://assets/texturehaven.com/brown_planks_03/brown_planks_03_Nor_1k.jpg" type="Texture" id=2] +[ext_resource path="res://assets/texturehaven.com/brown_planks_03/brown_planks_03_rough_1k.jpg" type="Texture" id=3] +[ext_resource path="res://assets/texturehaven.com/brown_planks_03/brown_planks_03_spec_1k.jpg" type="Texture" id=4] + +[resource] +albedo_texture = ExtResource( 1 ) +metallic = 1.0 +metallic_texture = ExtResource( 4 ) +roughness_texture = ExtResource( 3 ) +normal_enabled = true +normal_scale = 1.0 +normal_texture = ExtResource( 2 ) +uv1_triplanar = true diff --git a/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_AO_1k.jpg b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_AO_1k.jpg new file mode 100644 index 0000000..8ec5b56 Binary files /dev/null and b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_AO_1k.jpg differ diff --git a/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_Disp_1k.jpg b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_Disp_1k.jpg new file mode 100644 index 0000000..347cf6d Binary files /dev/null and b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_Disp_1k.jpg differ diff --git a/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_Nor_1k.jpg b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_Nor_1k.jpg new file mode 100644 index 0000000..06d8d30 Binary files /dev/null and b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_Nor_1k.jpg differ diff --git a/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_bump_1k.jpg b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_bump_1k.jpg new file mode 100644 index 0000000..8b84082 Binary files /dev/null and b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_bump_1k.jpg differ diff --git a/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_diff_1k.jpg b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_diff_1k.jpg new file mode 100644 index 0000000..a0a6340 Binary files /dev/null and b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_diff_1k.jpg differ diff --git a/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_rough_1k.jpg b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_rough_1k.jpg new file mode 100644 index 0000000..dffd4fa Binary files /dev/null and b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_rough_1k.jpg differ diff --git a/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_spec_1k.jpg b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_spec_1k.jpg new file mode 100644 index 0000000..a342269 Binary files /dev/null and b/demo/assets/texturehaven.com/brown_planks_03/brown_planks_03_spec_1k.jpg differ diff --git a/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust.tres b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust.tres new file mode 100644 index 0000000..de1dff4 --- /dev/null +++ b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust.tres @@ -0,0 +1,16 @@ +[gd_resource type="SpatialMaterial" load_steps=5 format=2] + +[ext_resource path="res://assets/texturehaven.com/green_metal_rust/green_metal_rust_diff_1k.jpg" type="Texture" id=1] +[ext_resource path="res://assets/texturehaven.com/green_metal_rust/green_metal_rust_spec_1k.jpg" type="Texture" id=2] +[ext_resource path="res://assets/texturehaven.com/green_metal_rust/green_metal_rust_Nor_1k.jpg" type="Texture" id=3] +[ext_resource path="res://assets/texturehaven.com/green_metal_rust/green_metal_rust_rough_1k.jpg" type="Texture" id=4] + +[resource] +albedo_texture = ExtResource( 1 ) +metallic = 0.99 +metallic_texture = ExtResource( 2 ) +roughness_texture = ExtResource( 4 ) +normal_enabled = true +normal_scale = 1.0 +normal_texture = ExtResource( 3 ) +uv1_triplanar = true diff --git a/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_AO_1k.jpg b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_AO_1k.jpg new file mode 100644 index 0000000..d6a69ff Binary files /dev/null and b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_AO_1k.jpg differ diff --git a/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_Disp_1k.jpg b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_Disp_1k.jpg new file mode 100644 index 0000000..955de1a Binary files /dev/null and b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_Disp_1k.jpg differ diff --git a/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_Nor_1k.jpg b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_Nor_1k.jpg new file mode 100644 index 0000000..5f0bf98 Binary files /dev/null and b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_Nor_1k.jpg differ diff --git a/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_bump_1k.jpg b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_bump_1k.jpg new file mode 100644 index 0000000..4d6d90f Binary files /dev/null and b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_bump_1k.jpg differ diff --git a/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_diff_1k.jpg b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_diff_1k.jpg new file mode 100644 index 0000000..9047f67 Binary files /dev/null and b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_diff_1k.jpg differ diff --git a/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_rough_1k.jpg b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_rough_1k.jpg new file mode 100644 index 0000000..f11c470 Binary files /dev/null and b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_rough_1k.jpg differ diff --git a/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_spec_1k.jpg b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_spec_1k.jpg new file mode 100644 index 0000000..aea6dd0 Binary files /dev/null and b/demo/assets/texturehaven.com/green_metal_rust/green_metal_rust_spec_1k.jpg differ diff --git a/demo/assets/wahooney.itch.io/README.md b/demo/assets/wahooney.itch.io/README.md new file mode 100644 index 0000000..5b4d5c3 --- /dev/null +++ b/demo/assets/wahooney.itch.io/README.md @@ -0,0 +1 @@ +Textures were created with: https://wahooney.itch.io/texture-grid-generator \ No newline at end of file diff --git a/demo/assets/wahooney.itch.io/blue_grid.png b/demo/assets/wahooney.itch.io/blue_grid.png new file mode 100644 index 0000000..cdadf9e Binary files /dev/null and b/demo/assets/wahooney.itch.io/blue_grid.png differ diff --git a/demo/assets/wahooney.itch.io/blue_grid.tres b/demo/assets/wahooney.itch.io/blue_grid.tres new file mode 100644 index 0000000..aaea265 --- /dev/null +++ b/demo/assets/wahooney.itch.io/blue_grid.tres @@ -0,0 +1,8 @@ +[gd_resource type="SpatialMaterial" load_steps=2 format=2] + +[ext_resource path="res://assets/wahooney.itch.io/blue_grid.png" type="Texture" id=1] + +[resource] +albedo_texture = ExtResource( 1 ) +uv1_offset = Vector3( 0.5, 0.5, 0.5 ) +uv1_triplanar = true diff --git a/demo/assets/wahooney.itch.io/brown_grid.png b/demo/assets/wahooney.itch.io/brown_grid.png new file mode 100644 index 0000000..81e9a12 Binary files /dev/null and b/demo/assets/wahooney.itch.io/brown_grid.png differ diff --git a/demo/assets/wahooney.itch.io/green_grid.png b/demo/assets/wahooney.itch.io/green_grid.png new file mode 100644 index 0000000..7fc031e Binary files /dev/null and b/demo/assets/wahooney.itch.io/green_grid.png differ diff --git a/demo/assets/wahooney.itch.io/green_grid.tres b/demo/assets/wahooney.itch.io/green_grid.tres new file mode 100644 index 0000000..dc3a1b2 --- /dev/null +++ b/demo/assets/wahooney.itch.io/green_grid.tres @@ -0,0 +1,10 @@ +[gd_resource type="SpatialMaterial" load_steps=2 format=2] + +[ext_resource path="res://assets/wahooney.itch.io/green_grid.png" type="Texture" id=1] + +[resource] +params_diffuse_mode = 1 +albedo_texture = ExtResource( 1 ) +roughness = 0.8 +uv1_scale = Vector3( 25, 25, 25 ) +uv1_triplanar = true diff --git a/demo/assets/wahooney.itch.io/white_grid.png b/demo/assets/wahooney.itch.io/white_grid.png new file mode 100644 index 0000000..8dbde7e Binary files /dev/null and b/demo/assets/wahooney.itch.io/white_grid.png differ diff --git a/demo/default_env.tres b/demo/default_env.tres index 5a972e2..c2f33a9 100644 --- a/demo/default_env.tres +++ b/demo/default_env.tres @@ -1,17 +1,14 @@ -[gd_resource type="Environment" load_steps=2 format=2] +[gd_resource type="Environment" load_steps=3 format=2] -[sub_resource type="ProceduralSky" id=1] +[ext_resource path="res://assets/hdrihaven.com/wasteland_clouds/wasteland_clouds_2k.hdr" type="Texture" id=1] -sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 ) -sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 ) -sky_curve = 0.25 -ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 ) -ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 ) -ground_curve = 0.01 +[sub_resource type="PanoramaSky" id=1] +panorama = ExtResource( 1 ) [resource] - background_mode = 2 background_sky = SubResource( 1 ) +tonemap_mode = 2 +tonemap_exposure = 0.84 +tonemap_white = 13.44 ssao_blur = 1 - diff --git a/hidapi b/hidapi deleted file mode 160000 index 747309e..0000000 --- a/hidapi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 747309e7bea847e874ac6e81ab652872b095dd3c diff --git a/libusb b/libusb deleted file mode 160000 index 2a7372d..0000000 --- a/libusb +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2a7372db54094a406a755f0b8548b614ba8c78ec diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..b48a297 --- /dev/null +++ b/meson.build @@ -0,0 +1,52 @@ +project( + 'godot_openhmd', 'c', + default_options: 'c_std=c99', + version: '0.1.1', + meson_version: '>= 0.44', +) +library_version = '0.1.1' + +godot_openhmd_path = 'demo/addons/godot-openhmd/bin/' + +# Local dependency paths, adapt them to your setup +godot_glad_path = 'glad' # ARGUMENTS.get("glad", "glad") +godot_headers_path = 'godot_headers' # ARGUMENTS.get("headers", "godot_headers/") + +include_dirs = ['.', godot_headers_path, godot_glad_path] + +# +# Dependencies +# + +openhmd_proj = subproject('OpenHMD') # dependency('openhmd', required : true) +openhmd_dep = openhmd_proj.get_variable('openhmd_dep') + +deps = [ + openhmd_dep, +] + +sources = [ + 'src/ARVRInterface.c', + 'src/GodotCalls.c', + 'src/godot_openhmd.c', + 'src/openhmd_config.c', + 'src/openhmd_data.c', + 'src/openhmd_shader.c', +] + +sources += [ + godot_glad_path + '/glad.c' +] + +c_args = [] +godot_openhmd_lib = library( + 'godot_openhmd', + sources, + include_directories: include_directories(include_dirs), + c_args: c_args, + cpp_args: c_args, + dependencies: deps, + install: true, + install_dir: godot_openhmd_path, + version: library_version, +) diff --git a/subprojects/OpenHMD.wrap b/subprojects/OpenHMD.wrap new file mode 100644 index 0000000..72036d0 --- /dev/null +++ b/subprojects/OpenHMD.wrap @@ -0,0 +1,5 @@ +[wrap-git] +directory=OpenHMD +url=https://github.com/OpenHMD/OpenHMD.git +push-url=git@github.com:OpenHMD/OpenHMD.git +revision=master diff --git a/subprojects/hidapi.wrap b/subprojects/hidapi.wrap new file mode 100644 index 0000000..af50b3e --- /dev/null +++ b/subprojects/hidapi.wrap @@ -0,0 +1,4 @@ +[wrap-git] +directory = hidapi +url = https://github.com/OpenHMD/hidapi +revision = b245d332914021c420001292ddea1769eff17f6d