Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
decacis committed Jun 3, 2024
0 parents commit 8ee96bf
Show file tree
Hide file tree
Showing 25 changed files with 1,586 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

# Only include the addons folder when downloading from the Asset Library.
/** export-ignore
/addons !export-ignore
/addons/** !export-ignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Daniel Castellanos and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Godot XR Toggle

The Godot XR Toggle is a simple toggle to run with VR enabled or not, from the editor.

This repository also includes an example of a project that can run VR and non-VR, thought the main focus is the XR Toggle plugin.


## Installing

After downloading asset from the [GitHub releases page](https://github.com/decacis/godot_xr_toggle/releases), just place it into your project.

Once you put the files in your project, head on to the Project Settings -> Plugins and enable the plugin there:

![enable-plugin](./assets/screenshots/plugin_enable.png)

## Force toggle XR when exporting

You can force XR being enabled/disabled when exporting for certain platforms. This is useful because when you are in the editor, you could have the XR Toggle disabled, but when exporting for the Quest (android) you want to have OpenXR always enabled, so you can add the platform to the "Platforms Force Mode" section like this:

![plugin_settings](./assets/screenshots/plugin_settings.png)
21 changes: 21 additions & 0 deletions addons/godot-xr-toggle/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Daniel Castellanos and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions addons/godot-xr-toggle/export_plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@tool
extends EditorExportPlugin


func _get_name() -> String:
return "GodotXRToggleExport"


func _export_begin(features : PackedStringArray, _is_debug : bool, _path : String, _flags : int) -> void:

var platforms_force_mode : Dictionary = ProjectSettings.get_setting("godot_xr_toggle/export/platforms_force_mode", [])
for platform_name : String in platforms_force_mode.keys():
if features.has(platform_name):
ProjectSettings.set_setting("xr/openxr/enabled", platforms_force_mode[platform_name])
break


func _export_file(path : String, _type : String, _features : PackedStringArray) -> void:
# Remove editor-only override file before exporting
if path == "res://override.cfg":
skip()
7 changes: 7 additions & 0 deletions addons/godot-xr-toggle/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="Godot XR Toggle"
description="A simple toggle to run with VR enabled or not, from the editor."
author="Daniel Castellanos (decacis)"
version="1.0"
script="plugin.gd"
82 changes: 82 additions & 0 deletions addons/godot-xr-toggle/plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@tool
extends EditorPlugin

var xr_toggle : CheckButton
var export_plugin : EditorExportPlugin


func _define_project_setting(
p_name : String,
p_type : int,
p_hint : int = PROPERTY_HINT_NONE,
p_hint_string : String = "",
p_default_val = "") -> void:
# p_default_val can be any type!!

if !ProjectSettings.has_setting(p_name):
ProjectSettings.set_setting(p_name, p_default_val)

var property_info : Dictionary = {
"name" : p_name,
"type" : p_type,
"hint" : p_hint,
"hint_string" : p_hint_string
}

ProjectSettings.add_property_info(property_info)
if ProjectSettings.has_method("set_as_basic"):
ProjectSettings.call("set_as_basic", p_name, true)
ProjectSettings.set_initial_value(p_name, p_default_val)


func _enter_tree() -> void:
_create_export_plugin()
_create_toggle_control()

# Add input grip threshold to the project settings
_define_project_setting(
"godot_xr_toggle/export/platforms_force_mode",
TYPE_DICTIONARY,
PROPERTY_HINT_NONE ,
"",
{"android": true})

add_export_plugin(export_plugin)
add_control_to_container(EditorPlugin.CONTAINER_TOOLBAR, xr_toggle)

# Initialize
_toggle_xr_mode(xr_toggle.button_pressed)


func _create_export_plugin() -> void:
if not export_plugin:
export_plugin = EditorExportPlugin.new()
export_plugin.set_script(load("res://addons/godot-xr-toggle/export_plugin.gd"))

func _create_toggle_control() -> void:
if not xr_toggle:
xr_toggle = CheckButton.new()
xr_toggle.text = "XR Enabled"
xr_toggle.toggled.connect(_toggle_xr_mode)


func _toggle_xr_mode(toggled_on : bool) -> void:
if FileAccess.file_exists("res://override.cfg"):
DirAccess.remove_absolute("res://override.cfg")

var config = ConfigFile.new()
# Enable OpenXR
config.set_value("xr", "openxr/enabled", toggled_on)
# Save override file
config.save("res://override.cfg")


func _exit_tree() -> void:
if FileAccess.file_exists("res://override.cfg"):
DirAccess.remove_absolute("res://override.cfg")

if xr_toggle:
xr_toggle.queue_free()

remove_export_plugin(export_plugin)
export_plugin = null
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions assets/icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://swejx0mk83uw"
path="res://.godot/imported/icon.png-b6a7fb2db36edd3d95dc42f1dc8c1c5d.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/icon.png"
dest_files=["res://.godot/imported/icon.png-b6a7fb2db36edd3d95dc42f1dc8c1c5d.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
161 changes: 161 additions & 0 deletions assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8ee96bf

Please sign in to comment.