Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*.lib
*.obj
logs
.vscode
*.pdb
*.ilk
compile_commands.json
Expand All @@ -19,6 +18,9 @@ compile_commands.json
# Ignore Gradle build output directory
android/build
.cxx
.project
.settings
.classpath

# Ignore intellij configuration files and directories
.idea
Expand All @@ -27,7 +29,9 @@ android/build
# Local configuration file (sdk path, etc)
local.properties

# Ignore build folder, need to fix gradlew config because this should be android/build
# Ignore build folder (moved to android/build so can probably be removed)
build

# Godot metadata files
# Ignore local parts of vscode
.vscode/settings.json
.vscode/launch.json
52 changes: 52 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build godot-cpp debug",
"type": "shell",
"command": "scons",
"group": "build",
"options": {
"cwd": "${workspaceFolder}/godot-cpp"
},
"windows": {
"args": [
"target=debug",
"platform=windows",
"generate_bindings=yes",
"-j8"
]
},
"linux": {
"args": [
"target=debug",
"platform=x11",
"generate_bindings=yes",
"-j8"
]
},
"problemMatcher": "$msCompile"
},
{
"label": "build desktop plugin debug",
"type": "shell",
"command": "scons",
"group": "build",
"windows": {
"args": [
"target=debug",
"platform=windows"
]
},
"linux": {
"args": [
"target=debug",
"platform=x11"
]
},
"problemMatcher": "$msCompile"
}
]
}
52 changes: 17 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Versions

Requires Godot 3.4, does not (yet) work with Godot 4.
Requires Godot 4.x, you'll need to build this from master.

See [Branches, Tags and versions](https://github.com/GodotVR/godot_openxr/issues/81) for more info on stable and development branches in this repository.

Expand All @@ -19,14 +19,16 @@ You will also need cmake if you're compiling the OpenXR SDK loader

### Godot-cpp

Currently this project includes the godot-cpp repository as a submodule.
This project includes the godot-cpp repository as a submodule.
If you do not already have this repositories downloaded you can execute:
```
git submodule update --init --recursive
```
To download the required version.
This will also include the `godot-headers` submodule.

> Note that as we're using the new GD Extensions system. You may need to update the `extension_api.json` in the `godot-cpp/godot-headers` folder with a version build from your copy of Godot by running `godot --dump-extension-api`.

This submodule needs to be compiled with the following
```
cd thirdparty/godot-cpp
Expand All @@ -44,8 +46,12 @@ On Linux the loader and include files should be installed system wide via packag
On Windows a precompiled version of the loaded can be found in `openxr_loader`, currently only the x86 version is used.
You can download the latest version from: https://github.com/KhronosGroup/OpenXR-SDK/releases

On Android we're currently including a copy of Oculus' loader for Quest found in `openxr_loader/oculus_mobile_sdk`.

### Compiling the plugin

> IMPORTANT GD Extensions require the plugin, including `godot-cpp` to be compiled with `debug` settings when used in the editor. If you do not do so it will crash. The build system will soon be altered to maintain both release and debug versions of the plugin side by side. It is important to note that even if you intent to use the plugin on Android/Quest you must build a desktop version of the plugin so the editor can load it or you will not be able to interact with the plugin withing the IDE.

If everything is in place compiling should be pretty straight forward

For Windows: ```scons platform=windows```
Expand All @@ -72,7 +78,7 @@ scons platform=linux use_llvm=yes

### Compiling for Android

For Android (Oculus Quest) the build process is slightly different. Note that currently the build process assumes that `godot-cpp` was build for either windows or linux plugin, if not you will need to manually run the python script that creates the wrapper code.
For Android (Oculus Quest) the build process is slightly different. Note that currently the build process assumes that `godot-cpp` was build for either windows or linux plugin, if not you will need to manually run the python script that creates the wrapper code (see `android\generate.py`).

On Android we use `gradlew` instead of `scons` for building the library. The toolset should be installed automatically if you install Android Studio.

Expand All @@ -82,7 +88,7 @@ gradlew generateSharedLibs
```

## Prebuild libraries
If you do not want to compile the OpenXR plugin yourself you will find releases with prebuild copies of the plugin.
If you do not want to compile the OpenXR plugin yourself you will find releases with prebuild copies of the plugin [here](https://github.com/GodotVR/godot_openxr/releases).
Simply download and unzip the contents into your Godot project.

## Running on Android/Quest
Expand Down Expand Up @@ -123,11 +129,10 @@ To do so:

### using VS code

I've only tested debugging using VS code on Windows with the MSVC C++ compiler but VS Code has good templates to get you up and running on Linux or on MinGW as well. Make sure you have the C/C++ extensions installed and the debugger installed.

Either manually create a .vscode folder or let vs code do this for you and setup the following two files:
For those who like to use vscode I've included a `tasks.json` configuration for compiling `godot-cpp` and compiling the plugin on Windows and Linux.

`launch.json`
You can use these to configure a `launch.json` to compile and run the plugin and debug it.
Below is a sample `launch.json` file:
```
{
"version": "0.2.0",
Expand All @@ -145,7 +150,7 @@ Either manually create a .vscode folder or let vs code do this for you and setup
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build"
"preLaunchTask": "build desktop plugin debug"
},
{
"name": "Editor Launch",
Expand All @@ -161,37 +166,14 @@ Either manually create a .vscode folder or let vs code do this for you and setup
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "build"
"preLaunchTask": "build desktop plugin debug"
}
]
}
```
Be sure to change `path-to-godot` to the actual path that contains your godot source and adjust the name of the godot executable as it may change depending on your compiler settings.
Note that two options are provided, launching the demo project, or opening the demo project in the Godot editor.

`tasks.json`
```
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "scons",
"group": "build",
"args": [
"platform=windows",
"target=debug",
"-j8"
],
"problemMatcher": "$msCompile"
}
]
}
```
Note that our build script does *not* build godot-cpp!
> Note that two options are provided, launching the demo project, or opening the demo project in the Godot editor. Also only the plugin is compiled as you'll only need to compile `godot-cpp` if a new version is available.

## Testing

Expand All @@ -207,7 +189,7 @@ Example: Converting a godot-openvr project

1. Remove the `addons/godot-openvr` directory from the project.
2. Copy the `godot-openxr/demo/addons/godot-openxr` directory to `your_project/addons/`.
3. If your project was already set up to use OpenVR, find `ARVRServer.find_interface("OpenVR")` and replace `"OpenVR"` with `"OpenXR"`.
3. If your project was already set up to use OpenVR, find `XRServer.find_interface("OpenVR")` and replace `"OpenVR"` with `"OpenXR"`.

Since the module is laid out like godot-openvr, the basic documentation for integrating OpenVR into a project also applies to OpenXR.

Expand Down
46 changes: 32 additions & 14 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ if cdb_supported:
opts.Update(env)

# Other needed paths
godot_glad_path = "thirdparty/glad/"
glad_path = "thirdparty/glad/"
volk_path = "thirdparty/volk/"
vulkan_path = "thirdparty/vulkan/"
godot_headers_path = "thirdparty/godot-cpp/godot-headers/"
godot_cpp_path = "thirdparty/godot-cpp/"
godot_cpp_library = "libgodot-cpp"
Expand Down Expand Up @@ -69,30 +71,37 @@ if env['platform'] == "windows":
env['CXX'] = 'clang++'
env['CC'] = 'clang'

env.Append(CPPDEFINES=["WIN32", "_WIN32", "_WINDOWS", "_CRT_SECURE_NO_WARNINGS"])
env.Append(CCFLAGS=["-W3", "-GR"])
env.Append(CXXFLAGS=["-std:c++20"])

if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-fPIC', '-g3','-Og'])
env.Append(CXXFLAGS = ['-fPIC', '-g3','-Og', '-std=c++17'])
else:
env.Append(CCFLAGS = ['-fPIC','-O3'])
env.Append(CXXFLAGS = ['-fPIC','-O3', '-std=c++17'])
env.Append(CCFLAGS = ['-fPIC', '-g','-O3'])
else:
# 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.Append(ENV = os.environ)

env.Append(CCFLAGS = ['-DWIN32', '-D_WIN32', '-D_WINDOWS', '-W3', '-GR', '-D_CRT_SECURE_NO_WARNINGS','-std:c++latest'])
env.Append(CPPDEFINES=["WIN32", "_WIN32", "_WINDOWS", "_CRT_SECURE_NO_WARNINGS", "TYPED_METHOD_BIND"])
env.Append(CCFLAGS=["-W3", "-GR"])
env.Append(CXXFLAGS=["-std:c++20"])

if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-Od', '-EHsc', '-D_DEBUG', '/MDd', '/Zi', '/FS'])
env.Append(LINKFLAGS = ['/DEBUG'])
env.Append(CPPDEFINES=["_DEBUG"])
env.Append(CCFLAGS = ['-Od', '-EHsc', '/MDd', '/Zi', '/FS'])
env.Append(LINKFLAGS = ['-DEBUG'])
else:
env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '/MD'])
env.Append(CPPDEFINES=["NDEBUG"])
env.Append(CCFLAGS = ['-O2', '-EHsc', '/MD'])

# Do we need these?
env.Append(LIBS = ["opengl32", "setupapi", "advapi32.lib"])

# For now just include Glad on Windows, but maybe also use with Linux?
env.Append(CPPPATH = [godot_glad_path])
sources += Glob(godot_glad_path + '*.c')
env.Append(CPPPATH = [glad_path])
sources += Glob(glad_path + '*.c')

elif env['platform'] == "linux":
target_path += "linux/"
Expand Down Expand Up @@ -130,20 +139,29 @@ elif env['platform'] == "linux":
# Complete godot-cpp library path
if env['target'] in ('debug', 'd'):
godot_cpp_library += '.debug.64'
env.Append(CCFLAGS = [ '-DDEBUG' ])
env.Append(CPPDEFINES=["DEBUG", "DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"])
else:
godot_cpp_library += '.release.64'

# Add volk
env.Append(CPPPATH = [volk_path, vulkan_path + "include/"])
sources += Glob(volk_path + '*.c')

####################################################################################################################################
# and add our main project

target_name = env['target_name']
if env['target'] in ('debug', 'd'):
target_name += "_debug"
else:
target_name += "_release"

env.Append(CPPPATH=[
'.',
'src/',
godot_headers_path,
godot_cpp_path + 'include/',
godot_cpp_path + 'include/core/',
godot_cpp_path + 'include/gen/'
godot_cpp_path + 'gen/include'
])

# Add our godot-cpp library
Expand All @@ -163,7 +181,7 @@ sources += Glob('src/*.cpp')
sources += Glob('src/*/*.cpp')
sources += Glob('src/*/*/*.cpp')

library = env.SharedLibrary(target=target_path + env['target_name'], source=sources)
library = env.SharedLibrary(target=target_path + target_name, source=sources)
Default(library)

if openxr_loader_dll_target != '':
Expand Down
2 changes: 1 addition & 1 deletion android/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
sys.path.insert(0, '../godot-cpp')
import binding_generator

json_api_file = os.path.join(os.getcwd(), 'godot-headers', 'api.json')
json_api_file = os.path.join(os.getcwd(), 'godot-headers', 'extension_api.json')
binding_generator.generate_bindings(json_api_file, True)
1 change: 1 addition & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ignore our import cache folder
.import
.godot

# export can have local file names and such
export_presets.cfg
Expand Down
36 changes: 17 additions & 19 deletions demo/ControllerInfo.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends Node2D

var controller : ARVRController = null;
var controller : XRController3D = null;

# Called when the node enters the scene tree for the first time.
func _ready():
Expand All @@ -9,27 +9,25 @@ func _ready():

func _process(_delta : float):
if controller:
var trigger = controller.get_joystick_axis(JOY_VR_ANALOG_TRIGGER)
var trigger = controller.get_value("analog_trigger")
$Container/TriggerInput.value = int(trigger * 100.0)

var grip = controller.get_joystick_axis(JOY_VR_ANALOG_GRIP)
var grip = controller.get_value("analog_grip")
$Container/GripInput.value = int(grip * 100.0)

var joy_x = controller.get_joystick_axis(JOY_AXIS_0)
var joy_y = controller.get_joystick_axis(JOY_AXIS_1)
$Container/Joysticks/Primary/Background.color = Color(1.0, 1.0, 1.0, 1.0) if controller.is_button_pressed(JOY_BUTTON_12) else Color(0.7, 0.7, 0.7, 1.0)
$Container/Joysticks/Primary/Background/Puck.rect_position = Vector2(23 + joy_x * 23, 23 - joy_y * 23)
$Container/Joysticks/Primary/Background/Puck.color = Color(0.0, 0.0, 1.0, 1.0) if controller.is_button_pressed(JOY_BUTTON_14) else Color(0.0, 0.0, 0.0, 1.0)
var joy = controller.get_axis("primary")
$Container/Joysticks/Primary/Background.color = Color(1.0, 1.0, 1.0, 1.0) if controller.is_button_pressed("primary_touch") else Color(0.7, 0.7, 0.7, 1.0)
$Container/Joysticks/Primary/Background/Puck.rect_position = Vector2(23 + joy.x * 23, 23 - joy.y * 23)
$Container/Joysticks/Primary/Background/Puck.color = Color(0.0, 0.0, 1.0, 1.0) if controller.is_button_pressed("primary_click") else Color(0.0, 0.0, 0.0, 1.0)

joy_x = controller.get_joystick_axis(JOY_AXIS_6)
joy_y = controller.get_joystick_axis(JOY_AXIS_7)
$Container/Joysticks/Secondary/Background.color = Color(1.0, 1.0, 1.0, 1.0) if controller.is_button_pressed(JOY_BUTTON_11) else Color(0.7, 0.7, 0.7, 1.0)
$Container/Joysticks/Secondary/Background/Puck.rect_position = Vector2(23 + joy_x * 23, 23 - joy_y * 23)
$Container/Joysticks/Secondary/Background/Puck.color = Color(0.0, 0.0, 1.0, 1.0) if controller.is_button_pressed(JOY_BUTTON_13) else Color(0.0, 0.0, 0.0, 1.0)
joy = controller.get_axis("secondary")
$Container/Joysticks/Secondary/Background.color = Color(1.0, 1.0, 1.0, 1.0) if controller.is_button_pressed("secondary_touch") else Color(0.7, 0.7, 0.7, 1.0)
$Container/Joysticks/Secondary/Background/Puck.rect_position = Vector2(23 + joy.x * 23, 23 - joy.y * 23)
$Container/Joysticks/Secondary/Background/Puck.color = Color(0.0, 0.0, 1.0, 1.0) if controller.is_button_pressed("secondary_click") else Color(0.0, 0.0, 0.0, 1.0)

$Container/AXButton/Value.pressed = controller.is_button_pressed(JOY_BUTTON_7)
$Container/BYButton/Value.pressed = controller.is_button_pressed(JOY_BUTTON_1)
$Container/MenuButton/Value.pressed = controller.is_button_pressed(JOY_BUTTON_3)
$Container/SelectButton/Value.pressed = controller.is_button_pressed(JOY_BUTTON_4)
$Container/TriggerButton/Value.pressed = controller.is_button_pressed(JOY_VR_TRIGGER)
$Container/SideButton/Value.pressed = controller.is_button_pressed(JOY_VR_GRIP)
$Container/AXButton/Value.pressed = controller.is_button_pressed("button_ax")
$Container/BYButton/Value.pressed = controller.is_button_pressed("button_by")
$Container/MenuButton/Value.pressed = controller.is_button_pressed("button_menu")
$Container/SelectButton/Value.pressed = controller.is_button_pressed("button_select")
$Container/TriggerButton/Value.pressed = controller.is_button_pressed("trigger")
$Container/SideButton/Value.pressed = controller.is_button_pressed("grip")
Loading