immersive-home/app/content/system/house/room/room.gd

85 lines
2.0 KiB
GDScript3
Raw Normal View History

extends Node3D
2024-04-05 20:29:18 +03:00
const ConstructRoomMesh = preload ("res://lib/utils/mesh/construct_room_mesh.gd")
2023-12-19 00:15:48 +02:00
@onready var wall_corners = $Ceiling/WallCorners
@onready var wall_edges = $Ceiling/WallEdges
2023-12-20 02:54:22 +02:00
@onready var wall_mesh: MeshInstance3D = $WallMesh
@onready var ceiling_mesh: MeshInstance3D = $CeilingMesh
2024-04-10 17:52:23 +03:00
@onready var wall_collision = $WallCollision/CollisionShape3D
2023-12-19 00:15:48 +02:00
@onready var room_floor = $Floor
@onready var room_ceiling = $Ceiling
2024-05-23 20:03:37 +03:00
@onready var state_machine: StateMachine = $StateMachine
2023-12-19 00:15:48 +02:00
var editable: bool = false:
set(value):
2024-03-21 11:51:58 +02:00
editable = value
2024-03-21 14:29:10 +02:00
if !is_inside_tree(): return
2024-04-29 18:18:15 +03:00
update()
2024-03-21 14:29:10 +02:00
func _ready():
Update.props(self, ["editable"])
2023-12-20 02:54:22 +02:00
func has_point(point: Vector3) -> bool:
2024-01-16 16:00:30 +02:00
return get_aabb().has_point(point)
2024-04-29 18:18:15 +03:00
func update():
if editable:
state_machine.change_to("Edit")
else:
state_machine.change_to("View")
2024-01-16 16:00:30 +02:00
func get_aabb():
2024-01-27 16:13:43 +02:00
var room_store = Store.house.get_room(name)
2024-03-12 12:35:15 +02:00
if room_store == null:
return AABB()
2024-01-27 16:13:43 +02:00
var corners = room_store.corners
if corners.size() == 0:
2024-01-16 16:00:30 +02:00
return AABB()
2024-01-27 16:13:43 +02:00
var min_pos = Vector3(corners[0].x, 0, corners[0].y)
var max_pos = min_pos
2024-01-16 16:00:30 +02:00
2024-01-27 16:13:43 +02:00
for corner in corners:
min_pos.x = min(min_pos.x, corner.x)
min_pos.z = min(min_pos.z, corner.y)
2024-01-16 16:00:30 +02:00
2024-01-27 16:13:43 +02:00
max_pos.x = max(max_pos.x, corner.x)
max_pos.z = max(max_pos.z, corner.y)
2024-01-16 16:00:30 +02:00
2024-01-27 16:13:43 +02:00
min_pos.y = 0
max_pos.y = room_store.height
2024-01-16 16:00:30 +02:00
2024-01-25 17:29:33 +02:00
return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos))
2024-04-29 18:18:15 +03:00
func generate_wall_mesh():
var room = Store.house.get_room(name)
2024-01-27 16:13:43 +02:00
2024-04-29 18:18:15 +03:00
if room == null||room.corners.size() < 3:
return null
2024-01-27 16:13:43 +02:00
2024-04-29 18:18:15 +03:00
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
2024-01-27 16:13:43 +02:00
2024-04-10 17:52:23 +03:00
return ConstructRoomMesh.generate_ceiling_mesh(corners)