Skip to content

Commit

Permalink
Add support for the Meta scene capture API
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Oct 25, 2023
1 parent a3499d9 commit 7c4abae
Show file tree
Hide file tree
Showing 70 changed files with 17,141 additions and 11 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build-addon-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ jobs:
uses: actions/checkout@v3
with:
path: aar
submodules: recursive
- name: Set up Python (for SCons)
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install scons
run: |
python -m pip install scons==4.0.0
- name: Setup java
uses: actions/setup-java@v3
with:
Expand All @@ -26,6 +34,10 @@ jobs:
- name: Create Godot OpenXR Vendors AARs
run: |
cd aar
cd thirdparty/godot-cpp
scons platform=android target=template_debug -j4
scons platform=android target=template_release -j4
cd ../..
./gradlew build
cd ..
# GODOT 4.2 ADDON GENERATION SECTION
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/mavencentral-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up Python (for SCons)
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install scons
run: |
python -m pip install scons==4.0.0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -23,7 +32,12 @@ jobs:

# Builds the release artifacts of the library
- name: Release build
run: ./gradlew -Prelease_version=${{ github.ref_name }} build
run: |
cd thirdparty/godot-cpp
scons platform=android target=template_debug -j4
scons platform=android target=template_release -j4
cd ../..
./gradlew -Prelease_version=${{ github.ref_name }} build
# Runs upload, and then closes & releases the repository
- name: Publish to MavenCentral
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "thirdparty/godot-cpp"]
path = thirdparty/godot-cpp
url = https://github.com/godotengine/godot-cpp
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
- Update Meta OpenXR mobile SDK to version 57
- Update the java version to 17
- Rename the plugin to 'Godot OpenXR Vendors'
- Add godot-cpp dependency
- Add OpenXR 1.0.30 headers
- Add support for the Meta scene capture API

## 1.1.0
- Update Meta OpenXR loader to version 54
Expand Down
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,47 @@ for support on prior versions of Godot 4.

## Building this asset

### Linux
You can build this asset after cloning by simply running:
After cloning this project, run the following command in the project root directory to initialize
the `godot-cpp` submodule:
```
git submodule update --init
```

### Building the Godot-CPP bindings
Build the Android C++ bindings using the following commands. To speed up compilation, add `-jN` at
the end of the SCons command line where `N` is the number of CPU threads you have on your system.
The example below uses 4 threads.
```
cd thirdparty/godot-cpp
scons target=template_debug -j4
scons target=template_release -j4
scons platform=android target=template_debug -j4
scons platform=android target=template_release -j4
```

When the command is completed, you should have static libraries stored in `thirdparty/godot-cpp/bin`
that will be used for compilation by the plugin.

### Building the Plugin

#### Linux / MacOS
Run the following command to build the plugin:
```
./gradlew build
cd godotopenxrmeta
scons target=template_debug -j4
scons target=template_release -j4
```

### Windows
You can build this asset after cloning by simply running:
#### Windows
Run the following command to build the plugin:
```
gradlew.bat build
cd godotopenxrmeta
scons target=template_debug -j4
scons target=template_release -j4
```

## Downloading this asset
Expand Down
1 change: 1 addition & 0 deletions common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
58 changes: 58 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.22.1)


## Default configs
# Default android abi is arm64-v8a
if (NOT ANDROID_ABI)
set(ANDROID_ABI "arm64-v8a")
endif (NOT ANDROID_ABI)

if (ANDROID_ABI STREQUAL "armeabi-v7a")
set(GODOT_CPP_LIB_ABI "arm32")
elseif (ANDROID_ABI STREQUAL "x86")
set(GODOT_CPP_LIB_ABI "x86_32")
elseif (ANDROID_ABI STREQUAL "x86_64")
set(GODOT_CPP_LIB_ABI "x86_64")
else ()
set(GODOT_CPP_LIB_ABI "arm64")
endif ()

# Default build type is Debug
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif (NOT CMAKE_BUILD_TYPE)

if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-D_DEBUG)
set(GODOT_CPP_LIB_BUILD_TYPE debug)
set(OPENXR_MOBILE_LIB_BUILD_TYPE Debug)
else ()
add_definitions(-DNDEBUG)
set(GODOT_CPP_LIB_BUILD_TYPE release)
set(OPENXR_MOBILE_LIB_BUILD_TYPE Release)
endif (CMAKE_BUILD_TYPE MATCHES Debug)


project(common LANGUAGES CXX)

## godot-cpp library
set(GODOT_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/godot-cpp")
set(GODOT-CPP "godot-cpp")

# Use the godot-cpp prebuilt static binary
set(GODOT_CPP_STATIC_LIB "${GODOT_CPP_DIR}/bin/libgodot-cpp.android.template_${GODOT_CPP_LIB_BUILD_TYPE}.${GODOT_CPP_LIB_ABI}.a")

list(APPEND GODOT_CPP_INCLUDE_DIRECTORIES "${GODOT_CPP_DIR}/include")
list(APPEND GODOT_CPP_INCLUDE_DIRECTORIES "${GODOT_CPP_DIR}/gen/include")
list(APPEND GODOT_CPP_INCLUDE_DIRECTORIES "${GODOT_CPP_DIR}/gdextension")

add_library(${GODOT-CPP}
STATIC
IMPORTED GLOBAL
INTERFACE_INCLUDE_DIRECTORIES "${GODOT_CPP_INCLUDE_DIRECTORIES}"
)
set_target_properties(${GODOT-CPP} PROPERTIES IMPORTED_LOCATION ${GODOT_CPP_STATIC_LIB})


## OpenXR headers
set(OPENXR_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/openxr/include")
36 changes: 36 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'org.godotengine.openxr.vendors.common'
compileSdk versions.compileSdk

defaultConfig {
minSdk versions.minSdk
targetSdk versions.targetSdk
}
externalNativeBuild {
cmake {
path file('CMakeLists.txt')
version versions.cmakeVersion
}
}

packagingOptions {
doNotStrip '**/*.so'
}

compileOptions {
sourceCompatibility versions.javaVersion
targetCompatibility versions.javaVersion
}
kotlinOptions {
jvmTarget = versions.javaVersion
}
}

dependencies {
implementation "androidx.core:core-ktx:$versions.coreKtxVersion"
}
4 changes: 4 additions & 0 deletions common/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
13 changes: 7 additions & 6 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ final stableGodotAndroidLib = "org.godotengine:godot:4.1.0.stable"

ext {
versions = [
gradlePluginVersion: '7.4.0',
compileSdk : 33,
minSdk : 21,
targetSdk : 33,
javaVersion : JavaVersion.VERSION_17,
nexusPublishVersion : '1.3.0',
gradlePluginVersion : '7.4.0',
compileSdk : 33,
minSdk : 21,
targetSdk : 33,
javaVersion : JavaVersion.VERSION_17,
nexusPublishVersion : '1.3.0',
kotlinVersion : '1.7.22',
coreKtxVersion : '1.12.0',
cmakeVersion : '3.22.1',
]

libraries = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ const PASSTHROUGH_OPTION = {
"update_visibility": false,
}

const USE_ANCHOR_API_OPTION = {
"option": {
"name": "meta_xr_features/use_anchor_api",
"class_name": "",
"type": TYPE_BOOL,
"hint": PROPERTY_HINT_NONE,
"hint_string": "",
"usage": PROPERTY_USAGE_DEFAULT,
},
"default_value": false,
"update_visibility": false,
}

const SUPPORT_QUEST_1_OPTION = {
"option": {
"name": "meta_xr_features/quest_1_support",
Expand Down Expand Up @@ -130,6 +143,7 @@ func _get_export_options(platform) -> Array[Dictionary]:
HAND_TRACKING_OPTION,
HAND_TRACKING_FREQUENCY_OPTION,
PASSTHROUGH_OPTION,
USE_ANCHOR_API_OPTION,
SUPPORT_QUEST_1_OPTION,
SUPPORT_QUEST_2_OPTION,
SUPPORT_QUEST_3_OPTION,
Expand Down Expand Up @@ -195,6 +209,10 @@ func _get_export_option_warning(platform, option) -> String:
if not(openxr_enabled) and _get_int_option(option, PASSTHROUGH_NONE_VALUE) > PASSTHROUGH_NONE_VALUE:
warning = "\"Passthrough\" requires \"XR Mode\" to be \"OpenXR\".\n"

"meta_xr_features/use_anchor_api":
if not(openxr_enabled) and _get_bool_option(option):
warning = "\"Use anchor API\" is only valid when \"XR Mode\" is \"OpenXR\"."

_:
warning = super._get_export_option_warning(platform, option)

Expand Down Expand Up @@ -234,6 +252,11 @@ func _get_android_manifest_element_contents(platform, debug) -> String:
elif passthrough_mode == PASSTHROUGH_REQUIRED_VALUE:
contents += " <uses-feature tools:node=\"replace\" android:name=\"com.oculus.feature.PASSTHROUGH\" android:required=\"true\" />\n"

# Check for anchor api
var use_anchor_api = _get_bool_option("meta_xr_features/use_anchor_api")
if use_anchor_api:
contents += " <uses-permission android:name=\"com.oculus.permission.USE_ANCHOR_API\" />\n"

return contents


Expand Down
20 changes: 20 additions & 0 deletions demo/addons/godotopenxrvendors/meta/plugin.gdextension
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[configuration]

entry_symbol = "plugin_library_init"
compatibility_minimum = "4.2"
android_aar_plugin = true

[libraries]

android.debug.arm64 = "res://addons/godotopenxrvendors/meta/.bin/debug/arm64-v8a/libgodotopenxrmeta.so"
android.release.arm64 = "res://addons/godotopenxrvendors/meta/.bin/release/arm64-v8a/libgodotopenxrmeta.so"
macos.debug = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.macos.template_debug.framework"
macos.release = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.macos.template_release.framework"
windows.debug.x86_64 = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.windows.template_debug.x86_64.dll"
windows.release.x86_64 = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.windows.template_release.x86_64.dll"
linux.debug.x86_64 = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.linux.template_debug.x86_64.so"
linux.release.x86_64 = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.linux.template_release.x86_64.so"
linux.debug.arm64 = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.linux.template_debug.arm64.so"
linux.release.arm64 = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.linux.template_release.arm64.so"
linux.debug.rv64 = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.linux.template_debug.rv64.so"
linux.release.rv64 = "res://addons/godotopenxrvendors/meta/.bin/libgodotopenxrmeta.linux.template_release.rv64.so"
1 change: 1 addition & 0 deletions demo/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,4 @@ meta_xr_features/quest_1_support=false
meta_xr_features/quest_2_support=true
meta_xr_features/quest_3_support=true
meta_xr_features/quest_pro_support=true
meta_xr_features/use_anchor_api=true
9 changes: 9 additions & 0 deletions demo/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ func _ready():
if xr_interface and xr_interface.is_initialized():
var vp: Viewport = get_viewport()
vp.use_xr = true

var scene_capture: OpenXRFbSceneCaptureExtensionWrapper = OpenXRFbSceneCaptureExtensionWrapper.get_singleton()
scene_capture.connect("scene_capture_completed", _on_scene_capture_completed)
scene_capture.request_scene_capture()



# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass


func _on_scene_capture_completed():
print("Scene Capture completed")
2 changes: 2 additions & 0 deletions godotopenxrkhronos/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ android {
}

dependencies {
implementation project(":common")

implementation "androidx.core:core-ktx:$versions.coreKtxVersion"
compileOnly libraries.godotAndroidLib
}
Expand Down
2 changes: 2 additions & 0 deletions godotopenxrlynx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ android {
}

dependencies {
implementation project(":common")

implementation "androidx.core:core-ktx:$versions.coreKtxVersion"
compileOnly libraries.godotAndroidLib
}
Expand Down
Loading

0 comments on commit 7c4abae

Please sign in to comment.