immersive-home/app/content/system/house/mini/miniature.gd

85 lines
2.3 KiB
GDScript3
Raw Normal View History

2024-04-05 20:29:18 +03:00
extends Node3D
const ConstructRoomMesh = preload ("res://lib/utils/mesh/construct_room_mesh.gd")
const wall_material = preload ("./mini_wall.tres")
2024-04-07 15:17:52 +03:00
@onready var walls_mesh = $Body/Model/WallsMesh
@onready var floor_mesh = $Body/Model/FloorMesh
@onready var collision_shape = $Body/CollisionShape3D
2024-04-05 20:29:18 +03:00
@onready var toggle_heatmap = $HeatmapButton
2024-04-07 15:17:52 +03:00
# var temperature_scale := Vector2( - 20.0, 60.0)
var temperature_scale := Vector2(22.0, 25.0)
2024-04-05 20:29:18 +03:00
var enabled = true:
set(value):
enabled = value
update()
func _ready():
update()
if Store.house.is_loaded() == false:
await Store.house.on_loaded
2024-04-09 18:46:59 +03:00
if Store.house.state.rooms.size() == 0:
2024-04-07 15:17:52 +03:00
return
2024-04-09 18:46:59 +03:00
var room = Store.house.state.rooms[0]
2024-04-05 20:29:18 +03:00
var corners = room.corners
var height = room.height
walls_mesh.mesh = ConstructRoomMesh.generate_wall_mesh_grid(corners, height)
floor_mesh.mesh = ConstructRoomMesh.generate_ceiling_mesh_grid(corners)
walls_mesh.material_override = wall_material
floor_mesh.material_override = wall_material
active = true
2024-04-07 15:17:52 +03:00
EventSystem.on_slow_tick.connect(update_data)
2024-04-05 20:29:18 +03:00
toggle_heatmap.on_button_down.connect(func():
active=true
EventSystem.on_slow_tick.connect(update_data)
)
toggle_heatmap.on_button_up.connect(func():
wall_material.set_shader_parameter("data", [])
wall_material.set_shader_parameter("data_size", 0)
active=false
EventSystem.on_slow_tick.disconnect(update_data)
)
func update():
walls_mesh.visible = enabled
floor_mesh.visible = enabled
collision_shape.disabled = not enabled
const SensorEntity = preload ("res://content/entities/sensor/sensor.gd")
var active: bool = false
2024-04-09 18:11:24 +03:00
func update_data(_delta: float) -> void:
2024-04-05 20:29:18 +03:00
var data_list = []
for room in House.body.get_rooms(0):
for entity in room.get_node("Entities").get_children():
if entity is SensorEntity:
var sensor = entity as SensorEntity
var data = sensor.get_sensor_data("temperature")
if data == null:
continue
var sensor_pos = sensor.global_position
data_list.append(Vector4(sensor_pos.x, sensor_pos.y, sensor_pos.z, float(data)))
2024-04-07 15:17:52 +03:00
data_list = data_list.map(func(data: Vector4) -> Vector4:
data.w=(data.w - temperature_scale.x) / (temperature_scale.y - temperature_scale.x)
return data
)
2024-04-05 20:29:18 +03:00
wall_material.set_shader_parameter("data", data_list)
wall_material.set_shader_parameter("data_size", data_list.size())