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 08c8d30
Show file tree
Hide file tree
Showing 24 changed files with 848 additions and 2 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')

1 change: 1 addition & 0 deletions .github/workflows/build-on-push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Workflow to automatically create deliverables
# TODO: Deprecate after Godot 4.2 is stable
name: Build on push

on:
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()
36 changes: 36 additions & 0 deletions demo/addons/godotopenxr/export/godot_openxr_editor_plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@tool
extends EditorPlugin

# A class member to hold the export plugin during its lifecycle.
var meta_export_plugin : EditorExportPlugin
var pico_export_plugin : EditorExportPlugin
var lynx_export_plugin : EditorExportPlugin
var khr_export_plugin : EditorExportPlugin


func _enter_tree():
var plugin_version = get_plugin_version()

# Initializing the export plugins
meta_export_plugin = preload("meta/godot_openxr_meta_editor_export_plugin.gd").new("meta", plugin_version)
pico_export_plugin = preload("pico/godot_openxr_pico_editor_export_plugin.gd").new("pico", plugin_version)
lynx_export_plugin = preload("lynx/godot_openxr_lynx_editor_export_plugin.gd").new("lynx", plugin_version)
khr_export_plugin = preload("khr/godot_openxr_khr_editor_export_plugin.gd").new("khr", plugin_version)

add_export_plugin(meta_export_plugin)
add_export_plugin(pico_export_plugin)
add_export_plugin(lynx_export_plugin)
add_export_plugin(khr_export_plugin)


func _exit_tree():
# Cleaning up the export plugins
remove_export_plugin(meta_export_plugin)
remove_export_plugin(pico_export_plugin)
remove_export_plugin(lynx_export_plugin)
remove_export_plugin(khr_export_plugin)

meta_export_plugin = null
pico_export_plugin = null
lynx_export_plugin = null
khr_export_plugin = null
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@tool
extends "../godot_openxr_editor_export_plugin.gd"


func _get_android_manifest_activity_element_contents(platform, debug) -> String:
if not _supports_platform(platform) or not(_is_vendor_plugin_enabled()):
return ""

var contents = """
<intent-filter>\n
<action android:name=\"android.intent.action.MAIN\" />\n
<category android:name=\"android.intent.category.LAUNCHER\" />\n
\n
<!-- OpenXR category tag to indicate the activity starts in an immersive OpenXR mode. \n
See https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#android-runtime-category. -->\n
<category android:name=\"org.khronos.openxr.intent.category.IMMERSIVE_HMD\" />\n
\n
<!-- Enable VR access on HTC Vive Focus devices. -->\n
<category android:name=\"com.htc.intent.category.VRAPP\" />\n
</intent-filter>\n
"""

return contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@tool
extends "../godot_openxr_editor_export_plugin.gd"


func _get_android_manifest_activity_element_contents(platform, debug) -> String:
if not _supports_platform(platform) or not(_is_vendor_plugin_enabled()):
return ""

var contents = """
<intent-filter>\n
<action android:name=\"android.intent.action.MAIN\" />\n
<category android:name=\"android.intent.category.LAUNCHER\" />\n
\n
<!-- OpenXR category tag to indicate the activity starts in an immersive OpenXR mode. \n
See https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#android-runtime-category. -->\n
<category android:name=\"org.khronos.openxr.intent.category.IMMERSIVE_HMD\" />\n
</intent-filter>\n
"""

return contents
Loading

0 comments on commit 08c8d30

Please sign in to comment.