Skip to content

Commit

Permalink
Refactor the Godot OpenXR loader to match the new Android plugin pack…
Browse files Browse the repository at this point in the history
…aging format for Godot 4.2

The new format gives a lot of flexibility and allows each vendor plugin to provide its own set of parameters in the export window. Those parameters in turn influences how the Android manifest is generated.
  • Loading branch information
m4gr3d committed Jul 10, 2023
1 parent 547d542 commit 1d265cc
Show file tree
Hide file tree
Showing 30 changed files with 872 additions and 131 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/build-addon-on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Workflow to automatically create the godot openxr loaders addon
name: Build on push

on:
[push, pull_request]

jobs:
build:
name: Assembling artifacts
runs-on: ubuntu-20.04

# Note, to satisfy the asset library we need to make sure our zip files have a root folder
# this is why we checkout into aar and build into asset
steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: aar
- name: Setup java
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Create Godot OpenXR loader AARs
run: |
cd aar
./gradlew build
cd ..
# GODOT 4.2 ADDON GENERATION SECTION
- name: Create Godot OpenXR loader Addon
run: |
mkdir asset
cp -r aar/demo/addons asset
cp aar/CHANGES.md asset/addons/godotopenxr/GodotOpenXRLoaders_CHANGES.md
- name: Adding vendor licences
run: |
cp aar/godotopenxrmeta/LICENSE.txt asset/addons/godotopenxr/export/meta/
cp aar/godotopenxrpico/src/main/jniLibs/arm64-v8a/README.md asset/addons/godotopenxr/export/pico/LICENSE.md
cp aar/godotopenxrkhr/LICENSE asset/addons/godotopenxr/export/khr/LICENSE
- name: Create Godot OpenXR loader addon artifact
uses: actions/upload-artifact@v2
with:
name: GodotOpenXRLoadersAddon
path: |
asset
- name: Zip addon
run: |
zip -qq -r godotopenxrloadersaddon.zip asset
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
- name: Create and upload asset
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: "godotopenxrloadersaddon.zip"
omitNameDuringUpdate: true
omitBodyDuringUpdate: true
token: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

80 changes: 0 additions & 80 deletions .github/workflows/build-on-push.yml

This file was deleted.

3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change history for the Godot OpenXR loaders asset

## 2.0.0
- Update to the new Godot 4.2 Android plugin packaging format

## 1.1.0
- Update Meta OpenXR loader to version 54
- Bump dependencies versions to match the latest Godot 4.x stable version (v4.0.3)
Expand Down
7 changes: 0 additions & 7 deletions GodotOpenXRKHR.gdap

This file was deleted.

7 changes: 0 additions & 7 deletions GodotOpenXRLynx.gdap

This file was deleted.

7 changes: 0 additions & 7 deletions GodotOpenXRMeta.gdap

This file was deleted.

7 changes: 0 additions & 7 deletions GodotOpenXRPico.gdap

This file was deleted.

43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Godot OpenXR Loaders

This repository builds the AAR assets required for Godot 4 to export XR application to the Android devices.
This repository builds the Android plugin addon required for Godot 4 to export XR applications to
the Android devices.

## Building this asset

Expand All @@ -27,34 +28,34 @@ Work in progress builds are available under [actions](https://github.com/GodotVR

### Installing android build templates

Due to the use of AARs you will need to use the gradle build option in Godot.
Open your Godot XR project in Godot and open the `Project` menu and select `Install Android Build templates`.
This should create an `android` folder in your project folder.
The use of a Godot Android plugin requires the use of the gradle build option in Godot:
- Open your Godot XR project in Godot
- Open the `Project` menu
- Select `Install Android Build templates`

### Copying the plugin into place

When downloading this asset from Godot's asset library it should place the required files into `android/plugins`.
If you've downloaded the zip file from the releases page, copy the files in `aar/android/plugins` manually to `android/plugins` in your project. You may need to create the plugins folder.
When downloading this asset from Godot's asset library it should place the required files into
the `addons`directory.
If you've downloaded the zip file from the releases page, copy the files in `asset/addons`
manually to `addons` in your project. You may need to create the `addons` folder.

If you have build the asset from source, you need to create the `android/plugins` folder and then copy the following files:
- `GodotopenXRMeta.gdap` into `android/plugins`
- `godotopenxrmeta\build\outputs\aar\godotopenxrmeta-release.aar` into `android/plugins/godotopenxrmeta`
- `godotopenxrmeta\build\outputs\aar\godotopenxrmeta-debug.aar` into `android/plugins/godotopenxrmeta`
- `GodotOpenXRPico.gdap` into `android/plugins`
- `godotopenxrpico\build\outputs\aar\godotopenxrpico-release.aar` into `android/plugins/godotopenxrpico`
- `GodotOpenXRKHR.gdap` into `android/plugins`
- `godotopenxrkhr\build\outputs\aar\godotopenxrkhr-release.aar` into `android/plugins/godotopenxrkhr`
- `GodotOpenXRLynx.gdap` into `android/plugins`
- `godotopenxrlynx\build\outputs\aar\godotopenxrlynx-release.aar` into `android/plugins/godotopenxrlynx`
If you have build the asset from source, you need to create the `addons` folder in your project
if it doesn't exist already, and then copy the content of the `demo/addons` folder to `addons`
in your project.

### Configuring your export

Back in Godot open the `Project` menu and select `Export...`.
If it doesn't already exist create an Android export configuration by pressing `Add...` and selecting `Android`.
Tick the `Use Gradle Build` tickbox.
Now enable the loader you need to use. Do *not* select multiple loaders!
Back in Godot open the `Project` menu and select `Export...`:
- If it doesn't already exist, create an Android export configuration by pressing `Add...` and
selecting `Android`
- Tick the `Use Gradle Build` tickbox
- Select `OpenXR` as the **XR Mode** under the **XR Features** section
- Enable the loader you need to use

You can create multiple export templates, one for each loader.
**Note:**
**Do not** select multiple loaders in the same export template!
You can instead create multiple export templates, one for each loader.

## License

Expand Down
2 changes: 1 addition & 1 deletion config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ext {
compileSdk : 33,
minSdk : 21,
targetSdk : 33,
godotLibVersion : '4.0.3.stable',
godotLibVersion : '4.1.0.stable',
javaVersion : JavaVersion.VERSION_11,
nexusPublishVersion : '1.3.0'
]
Expand Down
2 changes: 2 additions & 0 deletions demo/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
4 changes: 4 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Godot 4+ specific ignores
.godot/
/addons/godotopenxr/export/*/*.aar
/android/
Empty file.
120 changes: 120 additions & 0 deletions demo/addons/godotopenxr/export/godot_openxr_editor_export_plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
@tool
class_name GodotOpenXREditorExportPlugin extends EditorExportPlugin

const OPENXR_MODE_VALUE = 1

var _vendor: String
var _plugin_version: String

func _init(vendor: String, version: String):
_vendor = vendor
_plugin_version = version


func _get_name() -> String:
return "GodotOpenXR" + _vendor.capitalize()


# Path to the Android library aar file
# If this is not available, we fall back to the maven central dependency
func _get_android_aar_file_path(debug: bool) -> String:
return "res://addons/godotopenxr/export/" + _vendor + "/godotopenxr" + _vendor + "-" + ("debug.aar" if debug else "release.aar")


# Maven central dependency used as fall back when the Android library aar file is not available
func _get_android_maven_central_dependency() -> String:
return "org.godotengine:godot-openxr-loaders-" + _vendor + ":" + _plugin_version


func _get_vendor_toggle_option_name() -> String:
return "xr_features/enable_" + _vendor + "_plugin"


func _get_vendor_toggle_option() -> Dictionary:
var toggle_option = {
"option": {
"name": _get_vendor_toggle_option_name(),
"class_name": "",
"type": TYPE_BOOL,
"hint": PROPERTY_HINT_NONE,
"hint_string": "",
"usage": PROPERTY_USAGE_DEFAULT,
},
"default_value": false,
"update_visibility": false,
}
return toggle_option


func _is_openxr_enabled() -> bool:
return _get_int_option("xr_features/xr_mode", 0) == OPENXR_MODE_VALUE


func _get_export_options(platform) -> Array[Dictionary]:
if not _supports_platform(platform):
return []

return [
_get_vendor_toggle_option(),
]


func _get_export_option_warning(platform, option) -> String:
if not _supports_platform(platform):
return ""

if option != _get_vendor_toggle_option_name():
return ""

if not(_is_openxr_enabled()) and _get_bool_option(option):
return "\"Enable " + _vendor.capitalize() + " Plugin\" requires \"XR Mode\" to be \"OpenXR\".\n"

return ""


func _supports_platform(platform) -> bool:
if platform is EditorExportPlatformAndroid:
return true
return false


func _get_bool_option(option: String) -> bool:
var option_enabled = get_option(option)
if option_enabled is bool:
return option_enabled
return false


func _get_int_option(option: String, default_value: int) -> int:
var option_value = get_option(option)
if option_value is int:
return option_value
return default_value


func _is_vendor_plugin_enabled() -> bool:
return _get_bool_option(_get_vendor_toggle_option_name())


func _is_android_aar_file_available(debug: bool) -> bool:
return FileAccess.file_exists(_get_android_aar_file_path(debug))


func _get_android_dependencies(platform, debug) -> PackedStringArray:
if not _supports_platform(platform):
return PackedStringArray()

if _is_vendor_plugin_enabled() and not _is_android_aar_file_available(debug):
return PackedStringArray([_get_android_maven_central_dependency()])

return PackedStringArray()


func _get_android_libraries(platform, debug) -> PackedStringArray:
if not _supports_platform(platform):
return PackedStringArray()

if _is_vendor_plugin_enabled() and _is_android_aar_file_available(debug):
return PackedStringArray([_get_android_aar_file_path(debug)])

return PackedStringArray()
Loading

0 comments on commit 1d265cc

Please sign in to comment.