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

69 lines
1.7 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
2023-12-19 00:15:48 +02:00
@onready var state_machine = $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
if editable:
2023-12-19 00:15:48 +02:00
state_machine.change_to("Edit")
else:
2023-12-19 00:15:48 +02:00
state_machine.change_to("View")
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-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-01-27 16:13:43 +02:00
static func generate_wall_mesh(room_store: Dictionary):
2024-04-05 20:29:18 +03:00
var corners = room_store.corners
var height = room_store.height
2024-01-27 16:13:43 +02:00
2024-04-10 17:52:23 +03:00
return ConstructRoomMesh.generate_wall_mesh(corners, height)
2024-01-27 16:13:43 +02:00
static func generate_ceiling_mesh(room_store: Dictionary):
var corners = room_store.corners
2024-04-10 17:52:23 +03:00
return ConstructRoomMesh.generate_ceiling_mesh(corners)