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

49 lines
1.4 KiB
GDScript3
Raw Normal View History

2023-12-19 00:15:48 +02:00
extends RoomState
2024-03-07 15:21:31 +02:00
const RoomState = preload ("./room_state.gd")
2023-12-19 00:15:48 +02:00
func _on_enter():
2024-01-27 16:13:43 +02:00
var room_store = Store.house.get_room(room.name)
2023-12-19 00:15:48 +02:00
2024-03-07 15:21:31 +02:00
if room_store == null||room_store.corners.size() < 3:
2023-12-19 00:15:48 +02:00
return
2024-01-30 18:47:38 +02:00
room.wall_mesh.visible = false
room.ceiling_mesh.visible = false
2024-01-27 16:13:43 +02:00
room.wall_mesh.mesh = Room.generate_wall_mesh(room_store)
2023-12-19 00:15:48 +02:00
if room.wall_mesh.mesh == null:
return
2024-03-07 15:21:31 +02:00
room.room_ceiling.position.y = room_store.height
2024-01-25 13:36:33 +02:00
var ceiling_shape = room.room_ceiling.get_node("CollisionShape3D")
var floor_shape = room.room_floor.get_node("CollisionShape3D")
ceiling_shape.disabled = false
floor_shape.disabled = false
2024-01-27 16:13:43 +02:00
room.ceiling_mesh.mesh = Room.generate_ceiling_mesh(room_store)
2024-01-25 13:36:33 +02:00
ceiling_shape.shape = room.ceiling_mesh.mesh.create_trimesh_shape()
floor_shape.shape = room.ceiling_mesh.mesh.create_trimesh_shape()
ceiling_shape.shape.backface_collision = true
2023-12-19 00:15:48 +02:00
2024-04-05 20:29:18 +03:00
var collision = CollisionShape3D.new()
collision.shape = room.wall_mesh.mesh.create_trimesh_shape()
var static_body = StaticBody3D.new()
static_body.set_collision_layer_value(4, true)
static_body.set_collision_layer_value(5, true)
static_body.collision_mask = 0
static_body.add_child(collision)
room.wall_collisions.add_child(static_body)
2023-12-19 00:15:48 +02:00
func _on_leave():
2024-01-25 13:36:33 +02:00
room.room_ceiling.get_node("CollisionShape3D").disabled = true
room.room_floor.get_node("CollisionShape3D").disabled = true
2023-12-19 00:15:48 +02:00
for collision in room.wall_collisions.get_children():
collision.queue_free()
2024-01-27 16:13:43 +02:00
await collision.tree_exited