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

53 lines
1.5 KiB
GDScript3
Raw Normal View History

extends Node3D
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
@onready var wall_collisions = $WallCollisions
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):
if !is_node_ready(): await ready
if value:
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")
func get_corner(index: int) -> MeshInstance3D:
return wall_corners.get_child(index % wall_corners.get_child_count())
func get_edge(index: int) -> MeshInstance3D:
return wall_edges.get_child(index % wall_edges.get_child_count())
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)
func remove_corner(index: int):
get_corner(index).queue_free()
get_edge(index).queue_free()
2024-01-16 16:00:30 +02:00
func get_aabb():
if wall_corners.get_child_count() == 0:
return AABB()
var min_pos = wall_corners.get_child(0).position
var max_pos = wall_corners.get_child(0).position
for corner in wall_corners.get_children():
min_pos.x = min(min_pos.x, corner.position.x)
min_pos.z = min(min_pos.z, corner.position.z)
max_pos.x = max(max_pos.x, corner.position.x)
max_pos.z = max(max_pos.z, corner.position.z)
min_pos.y = room_floor.position.y
max_pos.y = room_ceiling.position.y
2024-01-25 13:23:07 +02:00
return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos))