immersive-home/app/content/main.gd

124 lines
3.5 KiB
GDScript3
Raw Permalink Normal View History

2023-11-02 02:22:48 +02:00
extends Node3D
const VoiceAssistant = preload ("res://content/system/assist/assist.tscn")
2024-04-29 18:18:15 +03:00
const environment_passthrough_material = preload ("res://assets/environment_passthrough.tres")
2024-05-22 19:38:28 +03:00
const Menu = preload ("res://content/ui/menu/menu.gd")
const OnboardingScene = preload ("res://content/ui/onboarding/onboarding.tscn")
2024-05-23 20:03:37 +03:00
const MetaSceneEntity = preload ("res://content/system/house/meta_scene_entity/meta_scene_entity.tscn")
2023-11-02 02:22:48 +02:00
@onready var environment: WorldEnvironment = $WorldEnvironment
2024-05-22 19:38:28 +03:00
@onready var camera: XRCamera3D = %XRCamera3D
@onready var controller_left = %XRControllerLeft
@onready var controller_right = %XRControllerRight
@onready var house = $House
2024-05-22 19:38:28 +03:00
@onready var menu: Menu = $Menu
@onready var xr: XRToolsStartXR = $StartXR
2024-05-23 20:03:37 +03:00
@onready var xr_origin: XROrigin3D = $XROrigin3D
var voice_assistant = null
2024-05-23 20:03:37 +03:00
var meta_scene_manager = null
2023-11-02 02:22:48 +02:00
func _ready():
2023-11-03 00:13:55 +02:00
if OS.get_name() == "Android":
2023-12-01 22:37:36 +02:00
# OS.request_permissions()
2024-04-29 18:18:15 +03:00
environment.environment = environment_passthrough_material
get_viewport().transparent_bg = true
else:
RenderingServer.set_debug_generate_wireframes(true)
2024-04-09 18:46:59 +03:00
create_voice_assistant()
2024-05-22 19:38:28 +03:00
xr.xr_started.connect(func():
if HomeApi.has_connected() == false:
HomeApi.start()
2024-01-15 17:47:09 +02:00
)
2024-05-23 20:03:37 +03:00
if OS.get_model_name() == "Quest":
meta_scene_manager = OpenXRFbSceneManager.new()
meta_scene_manager.auto_create = false
meta_scene_manager.visible = false
meta_scene_manager.default_scene = MetaSceneEntity
meta_scene_manager.openxr_fb_scene_data_missing.connect(func():
meta_scene_manager.request_scene_capture()
)
xr_origin.add_child(meta_scene_manager)
2024-05-22 19:38:28 +03:00
HomeApi.on_connect.connect(func():
start_setup_flow.call_deferred()
2024-01-15 17:47:09 +02:00
)
2024-05-22 19:38:28 +03:00
func start_setup_flow():
var onboarding = OnboardingScene.instantiate()
add_child(onboarding)
2024-01-15 17:47:09 +02:00
2024-05-22 19:38:28 +03:00
await onboarding.tree_exited
2024-01-15 17:47:09 +02:00
2024-05-22 19:38:28 +03:00
if Store.house.state.rooms.size() == 0:
house.create_room("Room 1")
2024-04-09 18:46:59 +03:00
func create_voice_assistant():
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
2024-04-09 18:46:59 +03:00
var settings_store = Store.settings.state
R.effect(func(_arg):
if settings_store.voice_assistant == true&&voice_assistant == null:
voice_assistant=VoiceAssistant.instantiate()
add_child(voice_assistant)
elif settings_store.voice_assistant == false&&voice_assistant != null:
remove_child(voice_assistant)
voice_assistant.queue_free()
)
func _process(delta):
2024-05-22 19:38:28 +03:00
_move_camera_pc(delta)
func _input(event):
2024-05-22 19:38:28 +03:00
# Debugging Features
if event is InputEventKey and Input.is_key_pressed(KEY_F10):
var vp = get_viewport()
vp.debug_draw = (vp.debug_draw + 1) % 5
if event is InputEventKey and Input.is_key_pressed(KEY_M):
2024-05-22 19:38:28 +03:00
menu.toggle_open()
func _move_camera_pc(delta):
if OS.get_name() == "Android": return
var camera_basis = camera.get_global_transform().basis
camera_basis.x.y = 0
camera_basis.z.y = 0
camera_basis.y = Vector3(0, 1, 0)
camera_basis.x = camera_basis.x.normalized()
camera_basis.z = camera_basis.z.normalized()
var movement = camera_basis * _vector_key_mapping(KEY_D, KEY_A, KEY_S, KEY_W) * delta
camera.position += movement
controller_left.position += movement
controller_right.position += movement
2024-01-15 17:47:09 +02:00
2024-05-22 19:38:28 +03:00
func _vector_key_mapping(key_positive_x: int, key_negative_x: int, key_positive_y: int, key_negative_y: int):
var x = 0
var y = 0
if Input.is_physical_key_pressed(key_positive_y):
y = 1
elif Input.is_physical_key_pressed(key_negative_y):
y = -1
if Input.is_physical_key_pressed(key_positive_x):
x = 1
elif Input.is_physical_key_pressed(key_negative_x):
x = -1
2024-03-11 19:09:50 +02:00
var vec = Vector3(x, 0, y)
if vec:
vec = vec.normalized()
2024-05-09 13:40:41 +03:00
return vec