Skip to content

Commit

Permalink
Apply new 4.2 plugin and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Aug 27, 2023
1 parent 0c52e54 commit 2b1886f
Show file tree
Hide file tree
Showing 30 changed files with 784 additions and 459 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.import/
.godot/
build/
android/build/
android/.build_version
android/
2 changes: 1 addition & 1 deletion addons/godot-xr-tools/staging/staging.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ size = Vector2(2, 2)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_snlak"]
render_priority = 0
shader = ExtResource("4")
shader_parameter/alpha = 0.0
shader_parameter/alpha = null

[node name="Staging" type="Node3D"]
script = ExtResource("1")
Expand Down
1 change: 1 addition & 0 deletions addons/godot-xr-tools/xr/start_xr.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

[node name="StartXR" type="Node"]
script = ExtResource("1_ljt1b")
physics_rate_multiplier = 1.0

[node name="EnterWebXR" type="CanvasLayer" parent="."]
visible = false
Expand Down
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
- Update PICO OpenXR loader to version 2.2.0
Expand Down
Empty file.
120 changes: 120 additions & 0 deletions 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 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
File renamed without changes.
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
Binary file not shown.
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
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
@tool
extends "../godot_openxr_editor_export_plugin.gd"

const PASSTHROUGH_NONE_VALUE = 0
const PASSTHROUGH_OPTIONAL_VALUE = 1
const PASSTHROUGH_REQUIRED_VALUE = 2

const HAND_TRACKING_NONE_VALUE = 0
const HAND_TRACKING_OPTIONAL_VALUE = 1
const HAND_TRACKING_REQUIRED_VALUE = 2

const HAND_TRACKING_FREQUENCY_LOW_VALUE = 0
const HAND_TRACKING_FREQUENCY_HIGH_VALUE = 1

const HAND_TRACKING_OPTION = {
"option": {
"name": "meta_xr_features/hand_tracking",
"class_name": "",
"type": TYPE_INT,
"hint": PROPERTY_HINT_ENUM,
"hint_string": "None,Optional,Required",
"usage": PROPERTY_USAGE_DEFAULT,
},
"default_value": HAND_TRACKING_NONE_VALUE,
"update_visibility": false,
}

const HAND_TRACKING_FREQUENCY_OPTION = {
"option": {
"name": "meta_xr_features/hand_tracking_frequency",
"class_name": "",
"type": TYPE_INT,
"hint": PROPERTY_HINT_ENUM,
"hint_string": "Low,High",
"usage": PROPERTY_USAGE_DEFAULT,
},
"default_value": HAND_TRACKING_FREQUENCY_LOW_VALUE,
"update_visibility": false,
}

const PASSTHROUGH_OPTION = {
"option": {
"name": "meta_xr_features/passthrough",
"class_name": "",
"type": TYPE_INT,
"hint": PROPERTY_HINT_ENUM,
"hint_string": "None,Optional,Required",
"usage": PROPERTY_USAGE_DEFAULT,
},
"default_value": PASSTHROUGH_NONE_VALUE,
"update_visibility": false,
}


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

return [
_get_vendor_toggle_option(),
HAND_TRACKING_OPTION,
HAND_TRACKING_FREQUENCY_OPTION,
PASSTHROUGH_OPTION,
]


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

var warning = ""
var openxr_enabled = _is_openxr_enabled()
match (option):
"meta_xr_features/hand_tracking":
if not(openxr_enabled) and _get_int_option(option, HAND_TRACKING_NONE_VALUE) > HAND_TRACKING_NONE_VALUE:
warning = "\"Hand Tracking\" requires \"XR Mode\" to be \"OpenXR\".\n"

"meta_xr_features/passthrough":
if not(openxr_enabled) and _get_int_option(option, PASSTHROUGH_NONE_VALUE) > PASSTHROUGH_NONE_VALUE:
warning = "\"Passthrough\" requires \"XR Mode\" to be \"OpenXR\".\n"

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

return warning


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

var contents = ""

# Check for hand tracking
var hand_tracking_value = _get_int_option("meta_xr_features/hand_tracking", HAND_TRACKING_NONE_VALUE)
if hand_tracking_value > HAND_TRACKING_NONE_VALUE:
contents += " <uses-permission android:name=\"com.oculus.permission.HAND_TRACKING\" />\n"
if hand_tracking_value == HAND_TRACKING_OPTIONAL_VALUE:
contents += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"false\" />\n"
elif hand_tracking_value == HAND_TRACKING_REQUIRED_VALUE:
contents += " <uses-feature tools:node=\"replace\" android:name=\"oculus.software.handtracking\" android:required=\"true\" />\n"

# Check for passthrough
var passthrough_mode = _get_int_option("meta_xr_features/passthrough", PASSTHROUGH_NONE_VALUE)
if passthrough_mode == PASSTHROUGH_OPTIONAL_VALUE:
contents += " <uses-feature tools:node=\"replace\" android:name=\"com.oculus.feature.PASSTHROUGH\" android:required=\"false\" />\n"
elif passthrough_mode == PASSTHROUGH_REQUIRED_VALUE:
contents += " <uses-feature tools:node=\"replace\" android:name=\"com.oculus.feature.PASSTHROUGH\" android:required=\"true\" />\n"

return contents


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

var contents = ""

var hand_tracking_enabled = _get_int_option("meta_xr_features/hand_tracking", HAND_TRACKING_NONE_VALUE) > HAND_TRACKING_NONE_VALUE
if hand_tracking_enabled:
var hand_tracking_frequency = _get_int_option("meta_xr_features/hand_tracking_frequency", HAND_TRACKING_FREQUENCY_LOW_VALUE)
var hand_tracking_frequency_label = "LOW" if hand_tracking_frequency == HAND_TRACKING_FREQUENCY_LOW_VALUE else "HIGH"
contents += " <meta-data tools:node=\"replace\" android:name=\"com.oculus.handtracking.frequency\" android:value=\"%s\" />\n" % hand_tracking_frequency_label
contents += " <meta-data tools:node=\"replace\" android:name=\"com.oculus.handtracking.version\" android:value=\"V2.0\" />\n"

return contents

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
<!-- Enable access to OpenXR on Oculus mobile devices, no-op on other Android\n
platforms. -->\n
<category android:name=\"com.oculus.intent.category.VR\" />\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
File renamed without changes.
Loading

0 comments on commit 2b1886f

Please sign in to comment.