diff --git a/app/assets/environment.tres b/app/assets/environment.tres new file mode 100644 index 0000000..1655b28 --- /dev/null +++ b/app/assets/environment.tres @@ -0,0 +1,15 @@ +[gd_resource type="Environment" load_steps=3 format=3 uid="uid://cfm0g4r0h2n1p"] + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_i4xao"] + +[sub_resource type="Sky" id="Sky_vhymk"] +sky_material = SubResource("ProceduralSkyMaterial_i4xao") + +[resource] +background_mode = 1 +background_color = Color(1, 1, 1, 1) +sky = SubResource("Sky_vhymk") +ambient_light_source = 2 +ambient_light_color = Color(1, 1, 1, 1) +ssao_radius = 6.52 +ssao_intensity = 5.68 diff --git a/app/assets/environment_passthrough.tres b/app/assets/environment_passthrough.tres new file mode 100644 index 0000000..043b190 --- /dev/null +++ b/app/assets/environment_passthrough.tres @@ -0,0 +1,15 @@ +[gd_resource type="Environment" load_steps=3 format=3 uid="uid://gljmitbkl86b"] + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_i4xao"] + +[sub_resource type="Sky" id="Sky_vhymk"] +sky_material = SubResource("ProceduralSkyMaterial_i4xao") + +[resource] +background_color = Color(0, 0, 0, 0) +background_energy_multiplier = 0.0 +sky = SubResource("Sky_vhymk") +ambient_light_source = 2 +ambient_light_color = Color(1, 1, 1, 1) +ssao_radius = 6.52 +ssao_intensity = 5.68 diff --git a/app/assets/materials/sky.material b/app/assets/materials/sky.material deleted file mode 100644 index 4d08c74..0000000 --- a/app/assets/materials/sky.material +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ae8276428c45d39d78153880ad4133705f61063edbc26bea163fec23119bbfc1 -size 302 diff --git a/app/assets/materials/sky_passthrough.material b/app/assets/materials/sky_passthrough.material deleted file mode 100644 index f846ea8..0000000 --- a/app/assets/materials/sky_passthrough.material +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9bac0d498144e58cd467f8db75da57f71b519523ac08799d2e3d75b22ba2401f -size 361 diff --git a/app/content/main.gd b/app/content/main.gd index 0746948..5732423 100644 --- a/app/content/main.gd +++ b/app/content/main.gd @@ -1,8 +1,7 @@ extends Node3D -var sky = preload ("res://assets/materials/sky.material") -var sky_passthrough = preload ("res://assets/materials/sky_passthrough.material") const VoiceAssistant = preload ("res://content/system/assist/assist.tscn") +const environment_passthrough_material = preload ("res://assets/environment_passthrough.tres") @onready var environment: WorldEnvironment = $WorldEnvironment @onready var camera: XRCamera3D = $XROrigin3D/XRCamera3D @@ -15,9 +14,10 @@ var voice_assistant = null func _ready(): # In case we're running on the headset, use the passthrough sky + if OS.get_name() == "Android": # OS.request_permissions() - environment.environment.sky.set_material(sky_passthrough) + environment.environment = environment_passthrough_material get_viewport().transparent_bg = true else: RenderingServer.set_debug_generate_wireframes(true) diff --git a/app/content/main.tscn b/app/content/main.tscn index 47079ed..025c61f 100644 --- a/app/content/main.tscn +++ b/app/content/main.tscn @@ -1,31 +1,18 @@ -[gd_scene load_steps=17 format=3 uid="uid://eecv28y6jxk4"] +[gd_scene load_steps=15 format=3 uid="uid://eecv28y6jxk4"] [ext_resource type="PackedScene" uid="uid://clc5dre31iskm" path="res://addons/godot-xr-tools/xr/start_xr.tscn" id="1_i4c04"] [ext_resource type="Script" path="res://content/main.gd" id="1_uvrd4"] [ext_resource type="PackedScene" uid="uid://b30w6tywfj4fp" path="res://content/system/controller_left/controller_left.tscn" id="2_2lraw"] +[ext_resource type="Environment" uid="uid://cfm0g4r0h2n1p" path="res://assets/environment.tres" id="2_lsndp"] [ext_resource type="PackedScene" uid="uid://dscp8x0ari57n" path="res://content/system/raycast/raycast.tscn" id="3_67lii"] [ext_resource type="PackedScene" uid="uid://b2kjh1fpjptdr" path="res://content/system/camera/camera.tscn" id="3_rj4ac"] [ext_resource type="PackedScene" uid="uid://bsx12q23v8apy" path="res://content/system/hands/hands.tscn" id="4_v8xu6"] [ext_resource type="PackedScene" uid="uid://ctltchlf2j2r4" path="res://addons/xr-simulator/XRSimulator.tscn" id="5_3qc8g"] -[ext_resource type="Material" uid="uid://bf5ina366dwm6" path="res://assets/materials/sky.material" id="5_wgwf8"] [ext_resource type="PackedScene" uid="uid://c3kdssrmv84kv" path="res://content/ui/menu/menu.tscn" id="8_du83w"] [ext_resource type="PackedScene" uid="uid://lrehk38exd5n" path="res://content/system/keyboard/keyboard.tscn" id="9_e5n3p"] [ext_resource type="PackedScene" uid="uid://cbemihbxkd4ll" path="res://content/system/house/house.tscn" id="9_np6mw"] [ext_resource type="PackedScene" uid="uid://bhyddd1f0ry1x" path="res://content/ui/onboarding/onboarding.tscn" id="12_uq2nj"] -[sub_resource type="Sky" id="Sky_vhymk"] -sky_material = ExtResource("5_wgwf8") - -[sub_resource type="Environment" id="Environment_7ghp0"] -background_mode = 1 -background_color = Color(0, 0, 0, 0) -background_energy_multiplier = 0.0 -sky = SubResource("Sky_vhymk") -ambient_light_source = 2 -ambient_light_color = Color(1, 1, 1, 1) -ssao_radius = 6.52 -ssao_intensity = 5.68 - [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_m58yb"] ao_enabled = true @@ -38,7 +25,7 @@ transform = Transform3D(1, -0.000296142, 0.000270963, 0.000296143, 1, -4.5899e-0 script = ExtResource("1_uvrd4") [node name="WorldEnvironment" type="WorldEnvironment" parent="."] -environment = SubResource("Environment_7ghp0") +environment = ExtResource("2_lsndp") [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(1, -2.51787e-05, 0.000567105, -0.000567105, 4.3985e-08, 1, -2.51784e-05, -1, 2.97105e-08, -4.65661e-10, 7.21041, 2.06458) diff --git a/app/content/system/house/doors/doors.gd b/app/content/system/house/doors/doors.gd index f59e218..ee8952a 100644 --- a/app/content/system/house/doors/doors.gd +++ b/app/content/system/house/doors/doors.gd @@ -3,6 +3,7 @@ extends Node3D const WallCornerScene = preload ("../room/wall_corner.tscn") const WallEdgeScene = preload ("../room/wall_edge.tscn") +## int | null var editing_door = null var room1 = null @@ -23,9 +24,57 @@ func is_editing(): func is_valid(): return room1 != null&&room2 != null&&room1_corner1 != null&&room1_corner2 != null&&room2_corner1 != null&&room2_corner2 != null +func add(): + var doors = Store.house.state.doors + + var next_index = 0 + for i in range(doors.size()): + next_index = max(next_index, doors[i].id) + edit(next_index + 1) + + return next_index + 1 + func edit(door): + var doors = Store.house.state.doors editing_door = door + var existing_door = null + + for i in range(doors.size()): + if doors[i].id == door: + existing_door = doors[i] + break + + if existing_door != null: + room1 = House.body.find_room(existing_door.room1) + room2 = House.body.find_room(existing_door.room2) + + room1_corner1 = WallCornerScene.instantiate() + room1_corner1.global_position = existing_door.room1_position1 + room1_corner1.get_node("Clickable").on_grab_move.connect(_move_corner.bind(room1, room1_corner1)) + add_child(room1_corner1) + + room1_corner2 = WallCornerScene.instantiate() + room1_corner2.global_position = existing_door.room1_position2 + room1_corner2.get_node("Clickable").on_grab_move.connect(_move_corner.bind(room1, room1_corner2)) + add_child(room1_corner2) + + room2_corner1 = WallCornerScene.instantiate() + room2_corner1.global_position = existing_door.room2_position1 + room2_corner1.get_node("Clickable").on_grab_move.connect(_move_corner.bind(room2, room2_corner1)) + add_child(room2_corner1) + + room2_corner2 = WallCornerScene.instantiate() + room2_corner2.global_position = existing_door.room2_position2 + room2_corner2.get_node("Clickable").on_grab_move.connect(_move_corner.bind(room2, room2_corner2)) + add_child(room2_corner2) + + for room in House.body.get_rooms(0): + if room != room1&&room != room2: + room.get_node("WallCollision/Clickable").on_click.connect(_add_corner.bind(room)) + else: + room.get_node("WallCollision/Clickable").on_click.disconnect(_add_corner.bind(room)) + for room in House.body.get_rooms(0): if door != null: room.get_node("WallCollision/Clickable").on_click.connect(_add_corner.bind(room)) @@ -33,10 +82,70 @@ func edit(door): room.get_node("WallCollision/Clickable").on_click.disconnect(_add_corner.bind(room)) func discard(): - pass + _clear() func save(): - pass + var doors = Store.house.state.doors + + if is_valid() == false: + EventSystem.notify("Door is not valid", EventNotify.Type.WARNING) + return + + var existing_door_index = -1 + for i in range(doors.size()): + + if doors[i].id == editing_door: + existing_door_index = i + break + + var door = { + "id": editing_door, + "room1": room1.name, + "room2": room2.name, + "room1_position1": room1_corner1.global_position, + "room1_position2": room1_corner2.global_position, + "room2_position1": room2_corner1.global_position, + "room2_position2": room2_corner2.global_position + } + + if existing_door_index == - 1: + doors.append(door) + else: + doors[existing_door_index] = door + + Store.house.state.doors = Store.house.state.doors + + room1.update() + room2.update() + + Store.house.save_local() + + _clear() + +func _clear(): + editing_door = null + room1 = null + room2 = null + + if room1_corner1 != null: + remove_child(room1_corner1) + room1_corner1.queue_free() + room1_corner1 = null + + if room1_corner2 != null: + remove_child(room1_corner2) + room1_corner2.queue_free() + room1_corner2 = null + + if room2_corner1 != null: + remove_child(room2_corner1) + room2_corner1.queue_free() + room2_corner1 = null + + if room2_corner2 != null: + remove_child(room2_corner2) + room2_corner2.queue_free() + room2_corner2 = null func _add_corner(event: EventPointer, room): _match_connected_room(event.ray.get_collision_point(), event.ray.get_collision_normal() * - 1) diff --git a/app/content/system/house/doors/doors.tscn b/app/content/system/house/doors/doors.tscn index dc69882..ee08ba9 100644 --- a/app/content/system/house/doors/doors.tscn +++ b/app/content/system/house/doors/doors.tscn @@ -10,24 +10,3 @@ top_level = true enabled = false collision_mask = 16 hit_from_inside = true - -[node name="CSGCombiner3D" type="CSGCombiner3D" parent="."] - -[node name="CSGPolygon3D2" type="CSGPolygon3D" parent="CSGCombiner3D"] -transform = Transform3D(1, 0, 0, 0, 2.98023e-08, -1, 0, 1, 2.98023e-08, -3.32523, 0, -0.681036) -snap = 1e-06 -flip_faces = true -polygon = PackedVector2Array(1.44028, 2.37318, 1.98957, 0.544275, 0.705633, -0.829152, -0.559752, 0.530294, -0.933822, 2.4059) -depth = 2.5 - -[node name="CSGPolygon3D" type="CSGPolygon3D" parent="CSGCombiner3D"] -transform = Transform3D(1, 0, 0, 0, 2.98023e-08, -1, 0, 1, 2.98023e-08, 0, 0, 0) -snap = 1e-06 -flip_faces = true -polygon = PackedVector2Array(1.44028, 2.37318, 1.98957, 0.544275, 0.705633, -0.829152, -0.559752, 0.530294, -0.933822, 2.4059) -depth = 2.5 - -[node name="CSGBox3D" type="CSGBox3D" parent="CSGCombiner3D"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.767542, 0.804975, 0.629865) -flip_faces = true -size = Vector3(2.00439, 1, 1) diff --git a/app/content/system/house/room/room.gd b/app/content/system/house/room/room.gd index f2ed2f6..1c67057 100644 --- a/app/content/system/house/room/room.gd +++ b/app/content/system/house/room/room.gd @@ -19,10 +19,7 @@ var editable: bool = false: if !is_inside_tree(): return - if editable: - state_machine.change_to("Edit") - else: - state_machine.change_to("View") + update() func _ready(): Update.props(self, ["editable"]) @@ -30,6 +27,12 @@ func _ready(): func has_point(point: Vector3) -> bool: return get_aabb().has_point(point) +func update(): + if editable: + state_machine.change_to("Edit") + else: + state_machine.change_to("View") + func get_aabb(): var room_store = Store.house.get_room(name) @@ -56,13 +59,26 @@ func get_aabb(): return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos)) -static func generate_wall_mesh(room_store: Dictionary): - var corners = room_store.corners - var height = room_store.height +func generate_wall_mesh(): + var room = Store.house.get_room(name) - return ConstructRoomMesh.generate_wall_mesh(corners, height) + if room == null||room.corners.size() < 3: + return null -static func generate_ceiling_mesh(room_store: Dictionary): - var corners = room_store.corners + var corners = room.corners + var height = room.height + var doors = [] + + for door in Store.house.state.doors: + if door.room1 == name: + doors.append([door.room1_position1, door.room1_position2]) + elif door.room2 == name: + doors.append([door.room2_position1, door.room2_position2]) + + # return ConstructRoomMesh.generate_wall_mesh(corners, height) + return ConstructRoomMesh.generate_wall_mesh_with_doors(corners, height, doors) + +static func generate_ceiling_mesh(room: Dictionary): + var corners = room.corners return ConstructRoomMesh.generate_ceiling_mesh(corners) diff --git a/app/content/system/house/room/states/view.gd b/app/content/system/house/room/states/view.gd index 521cf36..7a9eaf6 100644 --- a/app/content/system/house/room/states/view.gd +++ b/app/content/system/house/room/states/view.gd @@ -5,10 +5,10 @@ const RoomState = preload ("./room_state.gd") func _on_enter(): var room_store = Store.house.get_room(room.name) - if room_store == null||room_store.corners.size() < 3: + if room_store == null: return - room.wall_mesh.mesh = Room.generate_wall_mesh(room_store) + room.wall_mesh.mesh = room.generate_wall_mesh() if room.wall_mesh.mesh == null: return diff --git a/app/content/ui/menu/edit/edit_menu.tscn b/app/content/ui/menu/edit/edit_menu.tscn index aa3c032..5a21003 100644 --- a/app/content/ui/menu/edit/edit_menu.tscn +++ b/app/content/ui/menu/edit/edit_menu.tscn @@ -127,6 +127,7 @@ size = Vector3(0.14, 0.03, 0.01) [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_hstwo") mesh = SubResource("QuadMesh_4pj6f") skeleton = NodePath("../..") diff --git a/app/content/ui/menu/menu.tscn b/app/content/ui/menu/menu.tscn index c1c7045..f5e5027 100644 --- a/app/content/ui/menu/menu.tscn +++ b/app/content/ui/menu/menu.tscn @@ -269,7 +269,6 @@ visible = false [node name="EditMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("4_r2raj")] [node name="RoomMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("10_u4i1x")] -visible = false [node name="AutomateMenu" type="Node3D" parent="AnimationContainer/TabsContent"] visible = false diff --git a/app/content/ui/menu/room/views/doors.gd b/app/content/ui/menu/room/views/doors.gd index 702fddb..cf252af 100644 --- a/app/content/ui/menu/room/views/doors.gd +++ b/app/content/ui/menu/room/views/doors.gd @@ -10,16 +10,43 @@ const material_unselected = preload ("../room_unselected.tres") @onready var rooms_map = $Rooms @onready var doors_map = $Doors -var selected_door = R.state(null) var editing_door = R.state(false) func _ready(): - # Generate Room Mesh - R.effect(func(_arg): - pass + rooms_map.selectable.value = false + + var button_icon = R.computed(func(_arg): + if doors_map.selected_door.value == null: + return "add" + elif editing_door.value == false: + return "edit" + else: + return "save" ) + R.bind(door_button, "label", button_icon) + + var button_label = R.computed(func(_arg): + if doors_map.selected_door.value == null: + return "Add Door" + elif editing_door.value == false: + return "Edit Door" + else: + return "Save Door" + ) + + R.bind(door_label, "text", button_label) + door_button.on_button_up.connect(func(): - House.body.doors.edit(1) + if doors_map.selected_door.value == null: + var id=House.body.doors.add() + editing_door.value=true + doors_map.selected_door.value=id + elif editing_door.value == false: + editing_door.value=true + House.body.doors.edit(doors_map.selected_door.value) + else: + House.body.doors.save() + editing_door.value=false ) \ No newline at end of file diff --git a/app/content/ui/menu/room/views/doors.tscn b/app/content/ui/menu/room/views/doors.tscn index e9faf17..e22abbe 100644 --- a/app/content/ui/menu/room/views/doors.tscn +++ b/app/content/ui/menu/room/views/doors.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=8 format=3 uid="uid://biwinf4360f10"] +[gd_scene load_steps=9 format=3 uid="uid://biwinf4360f10"] [ext_resource type="Script" path="res://content/ui/menu/room/views/doors.gd" id="1_22w4h"] [ext_resource type="Script" path="res://content/ui/menu/room/views/rooms_map.gd" id="2_to21g"] [ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="2_v01ty"] +[ext_resource type="Script" path="res://content/ui/menu/room/views/doors_map.gd" id="3_0k2cc"] [ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="4_eorpn"] [sub_resource type="QuadMesh" id="QuadMesh_lkxbm"] @@ -30,14 +31,15 @@ size = Vector2(0.42, 0.32) script = ExtResource("1_22w4h") [node name="Rooms" type="Node3D" parent="."] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0.12, -0.16, 0) +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0.12, -0.16, 0.005) script = ExtResource("2_to21g") [node name="MeshInstance3D" type="MeshInstance3D" parent="Rooms"] mesh = SubResource("QuadMesh_lkxbm") [node name="Doors" type="Node3D" parent="."] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0.12, -0.16, 0) +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0.12, -0.16, 0.006) +script = ExtResource("3_0k2cc") [node name="Button" parent="." instance=ExtResource("2_v01ty")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.04, -0.28, 0) @@ -46,6 +48,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/doors_map.gd b/app/content/ui/menu/room/views/doors_map.gd new file mode 100644 index 0000000..1bf949a --- /dev/null +++ b/app/content/ui/menu/room/views/doors_map.gd @@ -0,0 +1,87 @@ +extends Node3D + +const BoundingBoxTools = preload ("res://lib/utils/mesh/bounding_box_tools.gd") +const ConstructRoomMesh = preload ("res://lib/utils/mesh/construct_room_mesh.gd") + +const material_selected = preload ("../room_selected.tres") +const material_unselected = preload ("../room_unselected.tres") + +var selectable = R.state(true) +var selected_door = R.state(null) + +func _ready(): + R.effect(func(_arg): + var rooms=Store.house.state.rooms + var doors=Store.house.state.doors + + for old_room in get_children(): + remove_child(old_room) + old_room.queue_free() + + if rooms.size() == 0: + return + + var target_rect=Rect2(0.0, 0.0, 0.2, 0.2) + var rooms_rect=Rect2() + + for room in rooms: + rooms_rect=rooms_rect.merge(BoundingBoxTools.get_bounding_box_2d(room.corners)) + + var box_transform=BoundingBoxTools.resize_bounding_box_2d(rooms_rect, target_rect) + + for door in doors: + var door_points=[ + Vector2(door.room1_position1.x, door.room1_position1.z), + Vector2(door.room1_position2.x, door.room1_position2.z), + Vector2(door.room2_position2.x, door.room2_position2.z), + Vector2(door.room2_position1.x, door.room2_position1.z) + ] + var mesh=ConstructRoomMesh.generate_ceiling_mesh(door_points) + + if mesh == null: + continue + + var body=StaticBody3D.new() + body.name=str(door.id) + body.position.x=box_transform.origin.x + body.position.z=box_transform.origin.y + body.set_collision_layer_value(1, false) + body.set_collision_layer_value(2, true) + + var mesh_instance=MeshInstance3D.new() + mesh_instance.name="Mesh" + mesh_instance.mesh=mesh + mesh_instance.material_override=material_unselected if selected_door.value != door.id else material_selected + + body.add_child(mesh_instance) + + var collision_shape=CollisionShape3D.new() + collision_shape.shape=mesh.create_trimesh_shape() + body.add_child(collision_shape) + + add_child(body) + + var box_scale=box_transform.get_scale() + var min_scale=min(box_scale.x, box_scale.y) + scale=Vector3(min_scale, min_scale, min_scale) + ) + +func _on_click(event: EventPointer): + if selectable.value == false: + return + + var door_id = int(str(event.target.name)) + + if selected_door.value == door_id: + selected_door.value = null + return + + selected_door.value = door_id + +func get_room(door_id): + if door_id == null: + return null + + if has_node(str(door_id)): + return get_node(str(door_id)) + return null diff --git a/app/content/ui/menu/room/views/rooms.tscn b/app/content/ui/menu/room/views/rooms.tscn index 28cca58..9b15b75 100644 --- a/app/content/ui/menu/room/views/rooms.tscn +++ b/app/content/ui/menu/room/views/rooms.tscn @@ -31,7 +31,7 @@ size = Vector2(0.42, 0.32) script = ExtResource("1_3a1oa") [node name="Rooms" type="Node3D" parent="."] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0.12, -0.16, 0) +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0.12, -0.16, 0.005) script = ExtResource("2_2t24u") [node name="MeshInstance3D" type="MeshInstance3D" parent="Rooms"] @@ -49,6 +49,7 @@ disabled = 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_map.gd b/app/content/ui/menu/room/views/rooms_map.gd index 0fe4975..3635f1e 100644 --- a/app/content/ui/menu/room/views/rooms_map.gd +++ b/app/content/ui/menu/room/views/rooms_map.gd @@ -37,7 +37,9 @@ func _ready(): var body=StaticBody3D.new() body.name=room.name body.position.x=box_transform.origin.x - body.position.y=- box_transform.origin.y + body.position.z=box_transform.origin.y + body.set_collision_layer_value(1, false) + body.set_collision_layer_value(2, true) var mesh_instance=MeshInstance3D.new() mesh_instance.name="Mesh" @@ -79,6 +81,6 @@ func get_room(room_name): if room_name == null: return null - if has_node("%s"% room_name): - return get_node("%s"% room_name) + if has_node(str(room_name)): + return get_node(str(room_name)) return null diff --git a/app/lib/utils/mesh/construct_room_mesh.gd b/app/lib/utils/mesh/construct_room_mesh.gd index 2ee9f5f..5f8857d 100644 --- a/app/lib/utils/mesh/construct_room_mesh.gd +++ b/app/lib/utils/mesh/construct_room_mesh.gd @@ -25,6 +25,94 @@ static func generate_wall_mesh(corners, height): return mesh +## Generate a wall mesh with doors +## corners: Array of Vector2 +## height: float +## doors: Array[Array[Vector3, Vector3]] +static func generate_wall_mesh_with_doors(corners, height, doors): + print("Generating wall mesh with doors") + if corners.size() < 3: + return null + + var mesh = ArrayMesh.new() + + for i in range(0, corners.size()): + var corner = corners[i] + var next_corner = corners[(i + 1) % corners.size()] + print("Corner ", corner, " Next corner ", next_corner) + + var forward = Vector3(next_corner.x - corner.x, 0, next_corner.y - corner.y).normalized() + + var points := PackedVector2Array() + + points.append(Vector2(0, 0)) + points.append(Vector2(0, height)) + points.append(Vector2(corner.distance_to(next_corner), height)) + points.append(Vector2(corner.distance_to(next_corner), 0)) + + for door in doors: + var door_point1 = Vector2(door[0].x, door[0].z) + var door_point2 = Vector2(door[1].x, door[1].z) + var proj_point1 = Geometry2D.get_closest_point_to_segment_uncapped(door_point1, corner, next_corner) + var proj_point2 = Geometry2D.get_closest_point_to_segment_uncapped(door_point2, corner, next_corner) + + print("Door points ", door_point1, " ", door_point2) + print("Projected points ", proj_point1, " ", proj_point2) + + if proj_point1.distance_to(door_point1) > 0.02&&proj_point2.distance_to(door_point2) > 0.02: + print("Door is not on the wall") + continue + + if proj_point1.distance_to(proj_point2) < 0.02: + print("Door is too small") + continue + + var point1_distance = corner.distance_to(proj_point1) + var point2_distance = corner.distance_to(proj_point2) + + var door_points := PackedVector2Array() + + door_points.append(Vector2(point1_distance, -1)) + door_points.append(Vector2(point1_distance, door[0].y)) + door_points.append(Vector2(point2_distance, door[1].y)) + door_points.append(Vector2(point2_distance, -1)) + + var clip = Geometry2D.clip_polygons(points, door_points) + if clip.size() == 0: + continue + + assert(clip.size() != 2, "Door clip should not create holes") + + points = clip[0] + + var edges = PackedInt32Array() + for k in range(points.size()): + edges.append(k) + edges.append((k + 1) % points.size()) + + var cdt: ConstrainedTriangulation = ConstrainedTriangulation.new() + cdt.init(true, true, 0.1) + + cdt.insert_vertices(points) + cdt.insert_edges(edges) + + cdt.erase_outer_triangles() + + points = cdt.get_all_vertices() + var triangles: PackedInt32Array = cdt.get_all_triangles() + + print(points.size(), triangles.size()) + + var points_3d = PackedVector3Array() + + for k in range(points.size()): + points_3d.append(Vector3(corner.x, 0, corner.y) + points[k].x * forward + Vector3(0, points[k].y, 0)) + print(points_3d[k]) + + mesh = _create_mesh_3d(points_3d, triangles, mesh) + + return mesh + static func generate_ceiling_mesh(corners): var points: PackedVector2Array = PackedVector2Array() var edges: PackedInt32Array = PackedInt32Array() @@ -51,7 +139,7 @@ static func generate_ceiling_mesh(corners): points = cdt.get_all_vertices() triangles = cdt.get_all_triangles() - return _create_mesh(points, triangles) + return _create_mesh_2d(points, triangles) static func generate_wall_mesh_grid(corners, height, grid: Vector2=Vector2(0.1, 0.1)): if corners.size() < 3: @@ -186,9 +274,29 @@ static func generate_ceiling_mesh_grid(corners, grid: Vector2=Vector2(0.1, 0.1)) points = cdt.get_all_vertices() triangles = cdt.get_all_triangles() - return _create_mesh(points, triangles) + return _create_mesh_2d(points, triangles) -static func _create_mesh(points: PackedVector2Array, triangles: PackedInt32Array): +static func _create_mesh_3d(points: PackedVector3Array, triangles: PackedInt32Array, existing=null): + var st = SurfaceTool.new() + + st.begin(Mesh.PRIMITIVE_TRIANGLES) + + for i in range(points.size()): + st.add_vertex(Vector3(points[i].x, points[i].y, points[i].z)) + + for i in range(triangles.size()): + st.add_index(triangles[i]) + + st.index() + st.generate_normals() + st.generate_tangents() + + if existing != null: + return st.commit(existing) + + return st.commit() + +static func _create_mesh_2d(points: PackedVector2Array, triangles: PackedInt32Array): var st = SurfaceTool.new() st.begin(Mesh.PRIMITIVE_TRIANGLES) diff --git a/app/lib/utils/variant_serializer.gd b/app/lib/utils/variant_serializer.gd index 636ee7d..3b2cf83 100644 --- a/app/lib/utils/variant_serializer.gd +++ b/app/lib/utils/variant_serializer.gd @@ -14,6 +14,8 @@ static func stringify_value(value): ) TYPE_BOOL, TYPE_INT, TYPE_FLOAT, TYPE_STRING, TYPE_NIL: return value + TYPE_STRING_NAME: + return str(value) TYPE_VECTOR2: return { "x": value.x,