From 5520ea42980704b90c590bc06e016cbfdc1a1512 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 23 May 2024 19:03:37 +0200 Subject: [PATCH] allow for importing rooms from meta --- app/assets/materials/wall.tres | 17 +++++ .../entities/media_player/media_player.gd | 2 +- app/content/main.gd | 16 +++++ app/content/main.tscn | 8 +-- app/content/system/house/doors/doors.gd | 9 +++ .../meta_scene_entity/meta_scene_entity.gd | 20 ++++++ .../meta_scene_entity/meta_scene_entity.tscn | 12 ++++ app/content/system/house/room/room.gd | 2 +- app/content/system/house/room/states/edit.gd | 65 ++++++++++--------- app/content/ui/menu/menu.gd | 2 +- app/content/ui/menu/room/room_menu.tscn | 2 +- app/content/ui/menu/room/views/doors.tscn | 1 + app/content/ui/menu/room/views/rooms.gd | 35 ++++++++++ app/content/ui/menu/room/views/rooms.tscn | 18 +++++ app/export_presets.cfg | 32 +++++++-- app/lib/utils/meta/meta_tools.gd | 3 + app/lib/utils/meta/spatial_entites.gd | 44 +++++++++++++ 17 files changed, 244 insertions(+), 44 deletions(-) create mode 100644 app/assets/materials/wall.tres create mode 100644 app/content/system/house/meta_scene_entity/meta_scene_entity.gd create mode 100644 app/content/system/house/meta_scene_entity/meta_scene_entity.tscn create mode 100644 app/lib/utils/meta/meta_tools.gd create mode 100644 app/lib/utils/meta/spatial_entites.gd diff --git a/app/assets/materials/wall.tres b/app/assets/materials/wall.tres new file mode 100644 index 0000000..d183453 --- /dev/null +++ b/app/assets/materials/wall.tres @@ -0,0 +1,17 @@ +[gd_resource type="StandardMaterial3D" load_steps=4 format=3 uid="uid://ce6lspn6sno1o"] + +[sub_resource type="Gradient" id="Gradient_jxq6i"] +offsets = PackedFloat32Array(0, 0.492147, 1) +colors = PackedColorArray(1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1) +metadata/_snap_count = 2 + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_ihydr"] + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_qcr8e"] +color_ramp = SubResource("Gradient_jxq6i") +noise = SubResource("FastNoiseLite_ihydr") + +[resource] +albedo_texture = SubResource("NoiseTexture2D_qcr8e") +metallic = 0.38 +roughness = 0.29 diff --git a/app/content/entities/media_player/media_player.gd b/app/content/entities/media_player/media_player.gd index ffc59d1..6452057 100644 --- a/app/content/entities/media_player/media_player.gd +++ b/app/content/entities/media_player/media_player.gd @@ -93,4 +93,4 @@ func load_image(url: String): var texture = ImageTexture.create_from_image(image) logo.texture = texture - logo.pixel_size = pixel_size \ No newline at end of file + logo.pixel_size = pixel_size diff --git a/app/content/main.gd b/app/content/main.gd index d60e637..88a2809 100644 --- a/app/content/main.gd +++ b/app/content/main.gd @@ -4,6 +4,7 @@ const VoiceAssistant = preload ("res://content/system/assist/assist.tscn") const environment_passthrough_material = preload ("res://assets/environment_passthrough.tres") const Menu = preload ("res://content/ui/menu/menu.gd") const OnboardingScene = preload ("res://content/ui/onboarding/onboarding.tscn") +const MetaSceneEntity = preload ("res://content/system/house/meta_scene_entity/meta_scene_entity.tscn") @onready var environment: WorldEnvironment = $WorldEnvironment @onready var camera: XRCamera3D = %XRCamera3D @@ -12,7 +13,10 @@ const OnboardingScene = preload ("res://content/ui/onboarding/onboarding.tscn") @onready var house = $House @onready var menu: Menu = $Menu @onready var xr: XRToolsStartXR = $StartXR +@onready var xr_origin: XROrigin3D = $XROrigin3D + var voice_assistant = null +var meta_scene_manager = null func _ready(): if OS.get_name() == "Android": @@ -29,6 +33,18 @@ func _ready(): HomeApi.start() ) + 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) + HomeApi.on_connect.connect(func(): start_setup_flow.call_deferred() ) diff --git a/app/content/main.tscn b/app/content/main.tscn index d88c93b..5c9216d 100644 --- a/app/content/main.tscn +++ b/app/content/main.tscn @@ -36,11 +36,6 @@ unique_name_in_owner = true unique_name_in_owner = true transform = Transform3D(0.999999, -1.39633e-11, 0, 9.48075e-12, 1, 0, 0, 0, 1, -0.355145, 0.550439, -0.477945) -[node name="AutoHandtracker" parent="XROrigin3D/XRControllerLeft" index="2"] -applymiddlefingerfix = null -applyscaling = null -coincidewristorknuckle = null - [node name="IndexTip" parent="XROrigin3D/XRControllerLeft" index="4"] transform = Transform3D(0.967526, 0.252326, -0.0150302, -0.0150302, 0.116784, 0.993043, 0.252326, -0.960569, 0.116784, -0.00665802, 0.0427912, -0.169868) @@ -50,6 +45,9 @@ transform = Transform3D(0.967043, 0.24582, -0.0663439, -0.0663439, 0.494837, 0.8 [node name="MiddleTip" parent="XROrigin3D/XRControllerLeft" index="6"] transform = Transform3D(0.98042, 0.196912, 0.00149799, 0.001498, -0.015065, 0.999885, 0.196912, -0.980305, -0.0150651, -0.00327212, -0.00771427, -0.176318) +[node name="Palm" parent="XROrigin3D/XRControllerLeft" index="7"] +transform = Transform3D(1, 3.12364e-06, -3.13861e-06, -3.12371e-06, 1, -1.97886e-05, 3.13854e-06, 1.97889e-05, 1, 0.0307807, -0.0419721, -0.0399505) + [node name="XRControllerRight" parent="XROrigin3D" instance=ExtResource("7_0b3tc")] unique_name_in_owner = true transform = Transform3D(0.999999, -1.39635e-11, 0, 1.31553e-10, 1, 0, 0, 0, 1, 0.336726, 0.575093, -0.437942) diff --git a/app/content/system/house/doors/doors.gd b/app/content/system/house/doors/doors.gd index f658a2a..055de55 100644 --- a/app/content/system/house/doors/doors.gd +++ b/app/content/system/house/doors/doors.gd @@ -38,6 +38,9 @@ func delete(door): Store.house.state.doors = Store.house.state.doors.filter(func(d): return d.id != door) Store.house.save_local() + App.controller_left.show_grid = false + App.controller_right.show_grid = false + func edit(door): var doors = Store.house.state.doors editing_door = door @@ -49,6 +52,9 @@ func edit(door): existing_door = doors[i] break + App.controller_left.show_grid = true + App.controller_right.show_grid = true + if existing_door != null: room1 = App.house.find_room(existing_door.room1) room2 = App.house.find_room(existing_door.room2) @@ -131,6 +137,9 @@ func _clear(): room1 = null room2 = null + App.controller_left.show_grid = true + App.controller_right.show_grid = true + if room1_corner1 != null: remove_child(room1_corner1) room1_corner1.queue_free() diff --git a/app/content/system/house/meta_scene_entity/meta_scene_entity.gd b/app/content/system/house/meta_scene_entity/meta_scene_entity.gd new file mode 100644 index 0000000..6fc752d --- /dev/null +++ b/app/content/system/house/meta_scene_entity/meta_scene_entity.gd @@ -0,0 +1,20 @@ +extends Node3D + +const Wall = preload ("res://assets/materials/wall.tres") + +var wall_mesh + +func setup_scene(entity: OpenXRFbSpatialEntity): + var name = entity.get_semantic_labels()[0] + + if name == "invisible_wall_face": + name = "wall_face" + + if name != "wall_face": + return + + add_to_group("meta_" + name) + + wall_mesh = entity.create_mesh_instance() + wall_mesh.material_override = Wall + add_child(wall_mesh) \ No newline at end of file diff --git a/app/content/system/house/meta_scene_entity/meta_scene_entity.tscn b/app/content/system/house/meta_scene_entity/meta_scene_entity.tscn new file mode 100644 index 0000000..508ad54 --- /dev/null +++ b/app/content/system/house/meta_scene_entity/meta_scene_entity.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=3 format=3 uid="uid://d12n8fxqsjhah"] + +[ext_resource type="Script" path="res://content/system/house/meta_scene_entity/meta_scene_entity.gd" id="1_crxvl"] + +[sub_resource type="PlaneMesh" id="PlaneMesh_wxifi"] + +[node name="MetaSceneEntity" type="Node3D"] +script = ExtResource("1_crxvl") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) +mesh = SubResource("PlaneMesh_wxifi") diff --git a/app/content/system/house/room/room.gd b/app/content/system/house/room/room.gd index 1c67057..c5355ff 100644 --- a/app/content/system/house/room/room.gd +++ b/app/content/system/house/room/room.gd @@ -11,7 +11,7 @@ const ConstructRoomMesh = preload ("res://lib/utils/mesh/construct_room_mesh.gd" @onready var room_floor = $Floor @onready var room_ceiling = $Ceiling -@onready var state_machine = $StateMachine +@onready var state_machine: StateMachine = $StateMachine var editable: bool = false: set(value): diff --git a/app/content/system/house/room/states/edit.gd b/app/content/system/house/room/states/edit.gd index 208917f..ce16061 100644 --- a/app/content/system/house/room/states/edit.gd +++ b/app/content/system/house/room/states/edit.gd @@ -16,19 +16,7 @@ func _on_enter(): if room_store == null: return - var corners = room_store.corners - - if corners.size() > 0: - add_floor_corner(room.to_local(Vector3(corners[0].x, 0, corners[0].y))) - add_height_corner(room.to_local(Vector3(corners[0].x, 0, corners[0].y))) - room.room_ceiling.position.y = room_store.height - height_edge.align_to_corners(floor_corner.position, floor_corner.position + Vector3.UP * room.room_ceiling.position.y) - - for i in range(1, corners.size()): - add_corner(room.to_local(Vector3(corners[i].x, 0, corners[i].y))) - - room.room_ceiling.get_node("CollisionShape3D").disabled = (floor_corner == null&&height_corner == null) - room.room_floor.get_node("CollisionShape3D").disabled = false + create_from_corners(room_store.corners, room_store.height) var ceiling_shape = WorldBoundaryShape3D.new() ceiling_shape.plane = Plane(Vector3.DOWN, 0) @@ -41,7 +29,40 @@ func _on_enter(): func _on_leave(): update_store() + clear() + room.room_ceiling.get_node("CollisionShape3D").disabled = true + room.room_floor.get_node("CollisionShape3D").disabled = true + + room.room_ceiling.get_node("Clickable").on_click.disconnect(_on_click_ceiling) + room.room_floor.get_node("Clickable").on_click.disconnect(_on_click_floor) + +func create_from_corners(corners, height): + clear() + + if corners.size() > 0: + add_floor_corner(room.to_local(Vector3(corners[0].x, 0, corners[0].y))) + add_height_corner(room.to_local(Vector3(corners[0].x, 0, corners[0].y))) + room.room_ceiling.position.y = height + height_edge.align_to_corners(floor_corner.position, floor_corner.position + Vector3.UP * room.room_ceiling.position.y) + + for i in range(1, corners.size()): + add_corner(room.to_local(Vector3(corners[i].x, 0, corners[i].y))) + + room.room_ceiling.get_node("CollisionShape3D").disabled = (floor_corner == null&&height_corner == null) + room.room_floor.get_node("CollisionShape3D").disabled = false + +func get_corner(index: int) -> MeshInstance3D: + return room.wall_corners.get_child(index % room.wall_corners.get_child_count()) + +func get_edge(index: int) -> MeshInstance3D: + return room.wall_edges.get_child(index % room.wall_edges.get_child_count()) + +func remove_corner(index: int): + get_corner(index).queue_free() + get_edge(index).queue_free() + +func clear(): for child in room.wall_corners.get_children(): room.wall_corners.remove_child(child) child.queue_free() @@ -53,24 +74,10 @@ func _on_leave(): if floor_corner != null: room.remove_child(floor_corner) floor_corner.queue_free() + floor_corner = null room.remove_child(height_edge) height_edge.queue_free() - - room.room_ceiling.get_node("CollisionShape3D").disabled = true - room.room_floor.get_node("CollisionShape3D").disabled = true - - room.room_ceiling.get_node("Clickable").on_click.disconnect(_on_click_ceiling) - room.room_floor.get_node("Clickable").on_click.disconnect(_on_click_floor) - -func get_corner(index: int) -> MeshInstance3D: - return room.wall_corners.get_child(index % room.wall_corners.get_child_count()) - -func get_edge(index: int) -> MeshInstance3D: - return room.wall_edges.get_child(index % room.wall_edges.get_child_count()) - -func remove_corner(index: int): - get_corner(index).queue_free() - get_edge(index).queue_free() + height_edge = null func _on_click_floor(event): if floor_corner != null&&height_corner != null: diff --git a/app/content/ui/menu/menu.gd b/app/content/ui/menu/menu.gd index 755e07a..24ab315 100644 --- a/app/content/ui/menu/menu.gd +++ b/app/content/ui/menu/menu.gd @@ -10,7 +10,7 @@ const Notification = preload ("res://content/ui/components/notification/notifica var show_menu = R.state(false) func _ready(): - App.main.remove_child(self) + App.main.remove_child.call_deferred(self) R.effect(func(_arg): if show_menu.value: diff --git a/app/content/ui/menu/room/room_menu.tscn b/app/content/ui/menu/room/room_menu.tscn index 3bd69c7..1bad18e 100644 --- a/app/content/ui/menu/room/room_menu.tscn +++ b/app/content/ui/menu/room/room_menu.tscn @@ -60,9 +60,9 @@ tabs = NodePath("../Tabs3D") visible = false [node name="Rooms" parent="Interface/TabsContent3D" instance=ExtResource("7_2f8e0")] -visible = false [node name="Doors" parent="Interface/TabsContent3D" instance=ExtResource("7_fl4l8")] +visible = false [node name="Background" type="MeshInstance3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 1.06581e-14, 0, -1.06581e-14, 1, 0.21, -0.16, 0) diff --git a/app/content/ui/menu/room/views/doors.tscn b/app/content/ui/menu/room/views/doors.tscn index d5ce7d6..871276b 100644 --- a/app/content/ui/menu/room/views/doors.tscn +++ b/app/content/ui/menu/room/views/doors.tscn @@ -53,6 +53,7 @@ icon = true [node name="Background" type="MeshInstance3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 1.06581e-14, 0, -1.06581e-14, 1, 0.21, -0.16, 0) +visible = false material_override = SubResource("ShaderMaterial_dah0r") mesh = SubResource("QuadMesh_fq44b") skeleton = NodePath("../..") diff --git a/app/content/ui/menu/room/views/rooms.gd b/app/content/ui/menu/room/views/rooms.gd index 07d7ea1..c6e898f 100644 --- a/app/content/ui/menu/room/views/rooms.gd +++ b/app/content/ui/menu/room/views/rooms.gd @@ -6,6 +6,9 @@ const RoomsMap = preload ("rooms_map.gd") @onready var room_button = $Button @onready var input = $Input @onready var rooms_map: RoomsMap = $Rooms +@onready var sync_room_button: Button3D = $SyncRoomsButton +@onready var delete_button: Button3D = $DeleteButton +@onready var sync_room_label: Label3D = $SyncRoomsLabel var editing_room = R.state(false) @@ -35,8 +38,40 @@ func _ready(): input.text=rooms_map.selected_room.value ) + R.effect(func(_arg): + sync_room_button.visible=editing_room.value + sync_room_label.visible=editing_room.value + sync_room_button.disabled=!editing_room.value + delete_button.visible=editing_room.value + delete_button.disabled=!editing_room.value + ) + if !Store.house.is_loaded(): await Store.house.on_loaded + if App.main.meta_scene_manager == null: + remove_child(sync_room_button) + remove_child(sync_room_label) + else: + sync_room_button.on_button_up.connect(func(): + App.main.meta_scene_manager.create_scene_anchors() + + await get_tree().create_timer(1.0).timeout + + var data=MetaTools.spatial_entites.get_corners_and_height() + + App.house.editing_room.state_machine.current_state.create_from_corners(data.corners, data.height) + ) + + delete_button.on_button_up.connect(func(): + var selected_room=rooms_map.selected_room + + if selected_room.value != null: + App.house.delete_room(selected_room.value) + selected_room.value=null + editing_room.value=false + rooms_map.selectable.value=true + ) + room_button.on_button_down.connect(func(): var selected_room=rooms_map.selected_room diff --git a/app/content/ui/menu/room/views/rooms.tscn b/app/content/ui/menu/room/views/rooms.tscn index 9b15b75..93954a0 100644 --- a/app/content/ui/menu/room/views/rooms.tscn +++ b/app/content/ui/menu/room/views/rooms.tscn @@ -53,3 +53,21 @@ visible = false material_override = SubResource("ShaderMaterial_dah0r") mesh = SubResource("QuadMesh_fq44b") skeleton = NodePath("../..") + +[node name="SyncRoomsLabel" type="Label3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, -0.23, 0) +pixel_size = 0.001 +text = "Sync Room" +font_size = 18 +outline_size = 0 +horizontal_alignment = 0 + +[node name="SyncRoomsButton" parent="." instance=ExtResource("1_y3lty")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.38, -0.23, 0) +label = "sync" +icon = true + +[node name="DeleteButton" parent="." instance=ExtResource("1_y3lty")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, -0.28, 0) +label = "delete" +icon = true diff --git a/app/export_presets.cfg b/app/export_presets.cfg index 75dff01..a4b0206 100644 --- a/app/export_presets.cfg +++ b/app/export_presets.cfg @@ -217,7 +217,7 @@ meta_xr_features/eye_tracking=0 meta_xr_features/hand_tracking=1 meta_xr_features/hand_tracking_frequency=1 meta_xr_features/passthrough=2 -meta_xr_features/use_anchor_api=false +meta_xr_features/use_anchor_api=true meta_xr_features/quest_1_support=false meta_xr_features/quest_2_support=true meta_xr_features/quest_3_support=true @@ -225,12 +225,17 @@ meta_xr_features/quest_pro_support=true xr_features/enable_pico_plugin=false xr_features/enable_lynx_plugin=false xr_features/enable_khronos_plugin=false -meta_xr_features/use_scene_api=false +meta_xr_features/use_scene_api=true meta_xr_features/face_tracking=0 meta_xr_features/render_model=0 meta_xr_features/use_overlay_keyboard=false meta_xr_features/use_experimental_features=false -meta_xr_features/boundary_mode=0 +meta_xr_features/boundary_mode=2 +khronos_xr_features/htc/hand_tracking=0 +khronos_xr_features/htc/tracker=0 +khronos_xr_features/htc/eye_tracking=0 +khronos_xr_features/htc/lip_expression=0 +meta_xr_features/body_tracking=0 [preset.1] @@ -451,7 +456,7 @@ meta_xr_features/eye_tracking=0 meta_xr_features/hand_tracking=1 meta_xr_features/hand_tracking_frequency=1 meta_xr_features/passthrough=2 -meta_xr_features/use_anchor_api=false +meta_xr_features/use_anchor_api=true meta_xr_features/quest_1_support=false meta_xr_features/quest_2_support=true meta_xr_features/quest_3_support=true @@ -459,12 +464,17 @@ meta_xr_features/quest_pro_support=true xr_features/enable_pico_plugin=false xr_features/enable_lynx_plugin=false xr_features/enable_khronos_plugin=false -meta_xr_features/use_scene_api=false +meta_xr_features/use_scene_api=true meta_xr_features/face_tracking=0 meta_xr_features/render_model=0 meta_xr_features/use_overlay_keyboard=false meta_xr_features/use_experimental_features=false -meta_xr_features/boundary_mode=1 +meta_xr_features/boundary_mode=0 +khronos_xr_features/htc/hand_tracking=0 +khronos_xr_features/htc/tracker=0 +khronos_xr_features/htc/eye_tracking=0 +khronos_xr_features/htc/lip_expression=0 +meta_xr_features/body_tracking=0 [preset.2] @@ -699,6 +709,11 @@ meta_xr_features/render_model=0 meta_xr_features/use_overlay_keyboard=false meta_xr_features/use_experimental_features=false meta_xr_features/boundary_mode=0 +khronos_xr_features/htc/hand_tracking=0 +khronos_xr_features/htc/tracker=0 +khronos_xr_features/htc/eye_tracking=0 +khronos_xr_features/htc/lip_expression=0 +meta_xr_features/body_tracking=0 [preset.3] @@ -933,3 +948,8 @@ meta_xr_features/render_model=0 meta_xr_features/use_overlay_keyboard=false meta_xr_features/use_experimental_features=false meta_xr_features/boundary_mode=0 +khronos_xr_features/htc/hand_tracking=0 +khronos_xr_features/htc/tracker=0 +khronos_xr_features/htc/eye_tracking=0 +khronos_xr_features/htc/lip_expression=0 +meta_xr_features/body_tracking=0 diff --git a/app/lib/utils/meta/meta_tools.gd b/app/lib/utils/meta/meta_tools.gd new file mode 100644 index 0000000..f5ee030 --- /dev/null +++ b/app/lib/utils/meta/meta_tools.gd @@ -0,0 +1,3 @@ +class_name MetaTools + +const spatial_entites = preload ("res://lib/utils/meta/spatial_entites.gd") \ No newline at end of file diff --git a/app/lib/utils/meta/spatial_entites.gd b/app/lib/utils/meta/spatial_entites.gd new file mode 100644 index 0000000..5ce6852 --- /dev/null +++ b/app/lib/utils/meta/spatial_entites.gd @@ -0,0 +1,44 @@ +extends RefCounted + +static func get_corners_and_height() -> Dictionary: + print("get corners") + + var lines = [] + var height = 2.8 + + var walls = App.main.get_tree().get_nodes_in_group("meta_wall_face") + + for wall in walls: + var mesh: MeshInstance3D = wall.wall_mesh + + var corner2 = mesh.to_global(Vector3( - mesh.mesh.size.x / 2.0, 0, 0)) + var corner1 = mesh.to_global(Vector3(mesh.mesh.size.x / 2.0, 0, 0)) + + corner1 = Vector2(corner1.x, corner1.z) + corner2 = Vector2(corner2.x, corner2.z) + + height = mesh.mesh.size.y + lines.append([corner1, corner2]) + + return { + "corners": lines_to_polygon(lines), + "height": height + } + +static func lines_to_polygon(lines: Array) -> Array: + var polygon = [lines[0][0],lines[0][1]] + var added_lines = [0] + + while len(polygon) < len(lines): + for i in range(len(lines)): + if i in added_lines: + continue + + if polygon[- 1].distance_to(lines[i][0]) < 0.01: + polygon.append(lines[i][1]) + added_lines.append(i) + elif polygon[- 1].distance_to(lines[i][1]) < 0.01: + polygon.append(lines[i][0]) + added_lines.append(i) + + return polygon \ No newline at end of file