Skip to content

Commit

Permalink
Pushing towards a more useable prerelease version
Browse files Browse the repository at this point in the history
Added plugin stuff like plugin.cfg/.gd
plugin.gd now takes care of the autoload
Moved low level event handling to T5Interface.
T5Manager becomes a class whose main purpose is to create XR glasses rig in the scene. This hopefully allow the advanced user to more easily create their own manager classes.
Add T5Gameboard to visualize the T5 gameboard in the scene. The T5Gameboard can also be registered with the T5Manager to be a start location for the T5Origin in the scene.
Added some node icons.
  • Loading branch information
patrickdown committed Oct 10, 2023
1 parent 2a64a7e commit db9562d
Show file tree
Hide file tree
Showing 34 changed files with 1,010 additions and 1,034 deletions.
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,24 @@ Scons should be run from an environment that has the Microsoft x64 development t
> `scons example target=[template_debug | template_release]` Copy build products to the `example\addons\tilt-five\bin`
## Basic usage

- Open the project in the examples directory
- Run the default scene

## Starting with a new project

To use this plugin in your own project:
- Copy the add on into your project
- Copy the `addons/tiltfive` folder into your project
- Open Project->Project Settings
- On the Autoload tab add `res://addons/tiltfive/T5Interface.gd`
- Create a main scene and add a T5Manager node
- Click on the Plugins tab
- Make sure the Tilt Five plugin is enabled
- You may need to restart Godot
- In the main scene add a T5Manager node
- In the main scene add a T5Gameboard node
- On the T5Manager node set the start location to the T5Gameboard node
- Add lights and other items to your scene

See example project for futher details.
Running should now show your scene on the Tilt Five system

## Dependencies

- Uses the godot-cpp headers
- Uses the Tilt Five NDK

## TODO

- API for tangible camera on the glasses
- Better docs
- Examples


## Acknowledgments

This was written by referring a lot to [GodotVR](https://github.com/GodotVR) code and reading
[Godot's](https://github.com/godotengine/godot) source code.
1 change: 0 additions & 1 deletion example/T5Glasses.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ albedo_color = Color(0.862745, 0, 0.0235294, 1)
[node name="T5Glasses" instance=ExtResource("1_uq4nw")]

[node name="Origin" parent="." index="0"]
gameboard_scale = 16.0
script = ExtResource("1_qprko")

[node name="T5-glasses" parent="Origin/Camera" index="0" instance=ExtResource("3_xuir6")]
Expand Down
5 changes: 1 addition & 4 deletions example/XROrigin3D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ extends T5Origin3D

var elapsed = 0.0

func _init():
print(gameboard_scale)

func _process(delta):
elapsed += delta
position.x = sin(elapsed) * 1
position.y = sin(elapsed) * 1

147 changes: 118 additions & 29 deletions example/addons/tiltfive/T5Interface.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@tool
extends Node

## This script should be configured as an autoload script.
Expand All @@ -12,50 +11,140 @@ extends Node
## in editor. This will allow the Godot editor to request
## action information from the interface.

var tilt_five_xr_interface: TiltFiveXRInterface
const T5ManagerBase = preload("res://addons/tiltfive/T5ManagerBase.gd")

func get_tilt_five_xr_interface() -> TiltFiveXRInterface:
return tilt_five_xr_interface
enum GameboardType {
LE = TiltFiveXRInterface.LE_GAMEBOARD,
XE = TiltFiveXRInterface.XE_GAMEBOARD,
XE_Raised = TiltFiveXRInterface.XE_RAISED_GAMEBOARD,
Unknown = TiltFiveXRInterface.NO_GAMEBOARD_SET
}

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!!
# State of a set of glasses.
class GlassesState:
var available := false
var attempting_to_reserve := false
var reserved := false
var glasses_scene : Node
var gameboard_type := GameboardType.Unknown
func can_attempt_to_reserve():
return available and (not attempting_to_reserve) and (not reserved)

# Dictionary maps glasses_id -> GlassesState
var glasses_dict: Dictionary

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

var property_info : Dictionary = {
"name" : p_name,
"type" : p_type,
"hint" : p_hint,
"hint_string" : p_hint_string
}
var t5_manager : T5ManagerBase:
set(value):
t5_manager = value

ProjectSettings.add_property_info(property_info)
ProjectSettings.set_as_basic(p_name, true)
ProjectSettings.set_initial_value(p_name, p_default_val)
func get_tilt_five_xr_interface() -> TiltFiveXRInterface:
return tilt_five_xr_interface

func get_setting_or_default(name : String, default):
var val = ProjectSettings.get_setting_with_override(name)
if not val:
val = default
return val

# Called when the manager is loaded and added to our scene
func _enter_tree():
_define_project_setting("xr/tilt_five/application_id", TYPE_STRING, PROPERTY_HINT_NONE, "", "my.game.com")
_define_project_setting("xr/tilt_five/application_version", TYPE_STRING, PROPERTY_HINT_NONE, "", "0.1.0")
_define_project_setting("xr/tilt_five/default_display_name", TYPE_STRING, PROPERTY_HINT_NONE, "", "Game: Player One")

tilt_five_xr_interface = TiltFiveXRInterface.new();
if tilt_five_xr_interface:
tilt_five_xr_interface.application_id = ProjectSettings.get_setting_with_override("xr/tilt_five/application_id")
tilt_five_xr_interface.application_version = ProjectSettings.get_setting_with_override("xr/tilt_five/application_version")
tilt_five_xr_interface.application_id = T5ProjectSettings.application_id
tilt_five_xr_interface.application_version = T5ProjectSettings.application_version

XRServer.add_interface(tilt_five_xr_interface)
tilt_five_xr_interface.glasses_event.connect(_on_glasses_event)

func _exit_tree():
if tilt_five_xr_interface:
tilt_five_xr_interface.glasses_event.disconnect(_on_glasses_event)
if tilt_five_xr_interface.is_initialized():
tilt_five_xr_interface.uninitialize()

XRServer.remove_interface(tilt_five_xr_interface)
tilt_five_xr_interface = null

func _ready():
if not t5_manager:
push_error("T5Manager is not set in T5Interface")
return
if !tilt_five_xr_interface.is_initialized():
tilt_five_xr_interface.initialize()

func _start_display(glasses_id : StringName, glasses_scene : Node):
var viewport := t5_manager.get_glasses_scene_viewport(glasses_scene)
var xr_origin := t5_manager.get_glasses_scene_origin(glasses_scene)
tilt_five_xr_interface.start_display(glasses_id, viewport, xr_origin)
var t5_camera := t5_manager.get_glasses_scene_camera(glasses_scene)
if t5_camera:
t5_camera.tracker = "/user/%s/head" % glasses_id
for idx in range(4):
var controller = t5_manager.get_glasses_scene_wand(glasses_scene, idx)
if not controller: break
controller.tracker = "/user/%s/wand_%d" % [glasses_id, idx + 1]

func _process_glasses():
for glasses_id in glasses_dict:
var glasses_state = glasses_dict.get(glasses_id) as GlassesState
if glasses_state.can_attempt_to_reserve() and t5_manager.should_use_glasses(glasses_id):
glasses_state.attempting_to_reserve = true
tilt_five_xr_interface.reserve_glasses(glasses_id, t5_manager.get_glasses_display_name(glasses_id))

func _on_glasses_event(glasses_id, event_num):
var glasses_state = glasses_dict.get(glasses_id) as GlassesState
if not glasses_state:
glasses_state = GlassesState.new()
glasses_dict[glasses_id] = glasses_state
match event_num:
TiltFiveXRInterface.E_AVAILABLE:
print_verbose(glasses_id, " E_AVAILABLE")
glasses_state.available = true
_process_glasses()

TiltFiveXRInterface.E_UNAVAILABLE:
print_verbose(glasses_id, " E_UNAVAILABLE")
glasses_state.available = false
if glasses_state.attempting_to_reserve:
glasses_state.attempting_to_reserve = false
_process_glasses()

TiltFiveXRInterface.E_RESERVED:
print_verbose(glasses_id, " E_RESERVED")
glasses_state.reserved = true
glasses_state.attempting_to_reserve = false

var glasses_scene = t5_manager.create_glasses_scene(glasses_id)

# instance our scene
if glasses_scene:
glasses_state.glasses_scene = glasses_scene
_start_display(glasses_id, glasses_scene)
else:
tilt_five_xr_interface.release_glasses(glasses_id)

TiltFiveXRInterface.E_DROPPED:
print_verbose(glasses_id, " E_DROPPED")
glasses_state.reserved = false

var glasses_scene = glasses_state.glasses_scene
if glasses_scene:
tilt_five_xr_interface.stop_display(glasses_id)
glasses_state.glasses_scene = null
t5_manager.release_glasses_scene(glasses_scene)

TiltFiveXRInterface.E_TRACKING:
var gbt = tilt_five_xr_interface.get_gameboard_type(glasses_id)
if glasses_state.gameboard_type != gbt:
glasses_state.gameboard_type = gbt
if glasses_state.glasses_scene:
t5_manager.set_glasses_scene_gameboard_type(glasses_state.glasses_scene, glasses_state.gameboard_type)
print_verbose(glasses_id, " E_TRACKING, Gameboard size = ", tilt_five_xr_interface.get_gameboard_extents(gbt))

TiltFiveXRInterface.E_NOT_TRACKING:
print_verbose(glasses_id, " E_NOT_TRACKING")

_:
print_verbose(glasses_id, " - unknown event: ", event_num)
Loading

0 comments on commit db9562d

Please sign in to comment.