finish up heat and humidity in mini view

This commit is contained in:
Nitwel 2024-04-10 15:59:27 +02:00
parent 3e84b04c67
commit 139d9466ff
9 changed files with 242 additions and 75 deletions

View File

@ -6,6 +6,7 @@ const Entity = preload ("../entity.gd")
@onready var collision_shape = $CollisionShape3D
var sensor_data = {}
var unit = null
# Called when the node enters the scene tree for the first time.
func _ready():
@ -28,6 +29,7 @@ func set_text(stateInfo):
text = stateInfo["attributes"]["friendly_name"] + "\n" + text
if stateInfo["attributes"].has("unit_of_measurement")&&stateInfo["attributes"]["unit_of_measurement"] != null:
unit = stateInfo["attributes"]["unit_of_measurement"]
text += " " + stateInfo["attributes"]["unit_of_measurement"]
if stateInfo["attributes"].has("device_class"):
@ -49,3 +51,9 @@ func get_sensor_data(type: String):
return null
return sensor_data[type]
func get_sensor_unit(type: String):
if sensor_data.has(type) == false:
return null
return unit

View File

@ -0,0 +1,11 @@
[gd_resource type="GradientTexture1D" load_steps=2 format=3 uid="uid://gfemvrlwowg7"]
[sub_resource type="Gradient" id="Gradient_2jwis"]
interpolation_color_space = 2
offsets = PackedFloat32Array(0, 0.333333, 0.5, 1)
colors = PackedColorArray(0.999396, 0, 0.058647, 1, 1, 0.85, 0, 1, 0, 0.95, 1, 1, 0.0333333, 0, 1, 1)
metadata/_snap_enabled = true
metadata/_snap_count = 6
[resource]
gradient = SubResource("Gradient_2jwis")

View File

@ -1,16 +1,7 @@
[gd_resource type="ShaderMaterial" load_steps=4 format=3 uid="uid://bcfcough6ucvc"]
[gd_resource type="ShaderMaterial" load_steps=3 format=3 uid="uid://bcfcough6ucvc"]
[ext_resource type="Shader" path="res://content/system/house/mini/mini_wall_shader.gdshader" id="1_sbr3e"]
[sub_resource type="Gradient" id="Gradient_2jwis"]
interpolation_color_space = 2
offsets = PackedFloat32Array(0.00840336, 0.1, 0.4375, 0.5625, 1)
colors = PackedColorArray(0.533333, 0, 1, 1, 0, 0.45, 1, 1, 0, 0.95, 1, 1, 0.983333, 1, 0, 1, 0.999396, 0, 0.058647, 1)
metadata/_snap_enabled = true
metadata/_snap_count = 16
[sub_resource type="GradientTexture1D" id="GradientTexture1D_rrsal"]
gradient = SubResource("Gradient_2jwis")
[ext_resource type="Texture2D" uid="uid://bbuq4wn7e5o2q" path="res://content/system/house/mini/temp_gradient.tres" id="2_3lwi8"]
[resource]
render_priority = 0
@ -18,4 +9,4 @@ shader = ExtResource("1_sbr3e")
shader_parameter/data = PackedFloat32Array()
shader_parameter/data_size = 0
shader_parameter/alpha = 0.3
shader_parameter/color_gradient = SubResource("GradientTexture1D_rrsal")
shader_parameter/color_gradient = ExtResource("2_3lwi8")

View File

@ -59,5 +59,5 @@ void vertex() {
void fragment() {
ALBEDO = vec3(color.xyz);
ALPHA = 0.3;
ALPHA = alpha;
}

View File

@ -3,6 +3,9 @@ extends Node3D
const ConstructRoomMesh = preload ("res://lib/utils/mesh/construct_room_mesh.gd")
const wall_material = preload ("./mini_wall.tres")
const humidity_gradient = preload ("./humid_gradient.tres")
const temperature_gradient = preload ("./temp_gradient.tres")
@onready var body = $Body
@onready var model = $Body/Model
@onready var collision_shape = $Body/CollisionShape3D
@ -14,9 +17,19 @@ enum HeatmapType {
HUMIDITY = 2
}
# var temperature_scale := Vector2( - 20.0, 60.0)
var temperature_scale := Vector2(22.0, 26.0)
var heatmap_type_strings = {
HeatmapType.NONE: "none",
HeatmapType.TEMPERATURE: "temperature",
HeatmapType.HUMIDITY: "humidity"
}
var base_scale = {
HeatmapType.NONE: Vector2(0.0, 1.0),
HeatmapType.TEMPERATURE: Vector2( - 20.0, 60.0),
HeatmapType.HUMIDITY: Vector2(0.0, 100.0)
}
var selected_scale = R.state(Vector2(0.0, 1.0))
var opacity = R.state(30)
var heatmap_type = R.state(HeatmapType.NONE)
var small = R.state(false)
@ -100,27 +113,33 @@ func _ready():
R.effect(func(_arg):
if heatmap_type.value != HeatmapType.NONE:
EventSystem.on_slow_tick.connect(update_data)
if heatmap_type.value == HeatmapType.TEMPERATURE:
wall_material.set_shader_parameter("color_gradient", temperature_gradient)
else:
wall_material.set_shader_parameter("color_gradient", humidity_gradient)
else:
EventSystem.on_slow_tick.disconnect(update_data)
wall_material.set_shader_parameter("data", [])
wall_material.set_shader_parameter("data_size", 0)
)
R.effect(func(_arg):
wall_material.set_shader_parameter("alpha", opacity.value / 100.0)
)
const SensorEntity = preload ("res://content/entities/sensor/sensor.gd")
# func _process(delta):
# for mesh in model.get_children():
# if mesh is MeshInstance3D:
# mesh.material_override.set_shader_parameter("mesh_pos",
func get_base_scale() -> Vector2:
return base_scale[heatmap_type.value]
func update_data(_delta: float) -> void:
func get_sensor_data():
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")
var data = sensor.get_sensor_data(heatmap_type_strings[heatmap_type.value])
if data == null:
continue
@ -128,8 +147,40 @@ func update_data(_delta: float) -> void:
data_list.append(Vector4(sensor_pos.x, sensor_pos.y, sensor_pos.z, float(data)))
return data_list
func get_sensor_unit():
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 sensor_unit = sensor.get_sensor_unit(heatmap_type_strings[heatmap_type.value])
if sensor_unit != null:
return sensor_unit
return ""
func get_sensor_scale():
var data = get_sensor_data()
var minmax
for sensor in data:
if minmax == null:
minmax = Vector2(sensor.w, sensor.w)
else:
minmax.x = min(sensor.w, minmax.x)
minmax.y = max(sensor.w, minmax.y)
if minmax == null:
return Vector2(0.0, 1.0)
return minmax
func update_data(_delta: float) -> void:
var data_list = get_sensor_data()
data_list = data_list.map(func(data: Vector4) -> Vector4:
data.w=(data.w - temperature_scale.x) / (temperature_scale.y - temperature_scale.x)
data.w=clamp((data.w - selected_scale.value.x) / (selected_scale.value.y - selected_scale.value.x), 0.0, 1.0)
return data
)

View File

@ -0,0 +1,11 @@
[gd_resource type="GradientTexture1D" load_steps=2 format=3 uid="uid://bbuq4wn7e5o2q"]
[sub_resource type="Gradient" id="Gradient_2jwis"]
interpolation_color_space = 2
offsets = PackedFloat32Array(0.00840336, 0.1, 0.4375, 0.5625, 1)
colors = PackedColorArray(0.533333, 0, 1, 1, 0, 0.45, 1, 1, 0, 0.95, 1, 1, 0.983333, 1, 0, 1, 0.999396, 0, 0.058647, 1)
metadata/_snap_enabled = true
metadata/_snap_count = 16
[resource]
gradient = SubResource("Gradient_2jwis")

View File

@ -216,7 +216,6 @@ func add_corner(position: Vector3, index: int = -1):
moving.position=new_position
if room.wall_edges.get_child_count() == 0:
return
@ -247,7 +246,6 @@ func add_corner(position: Vector3, index: int = -1):
else:
get_edge(index - 1).align_to_corners(get_corner(index - 1).position, position)
func add_edge(from_pos: Vector3, to_pos: Vector3, index: int=- 1):
var edge: StaticBody3D = wall_edge_scene.instantiate()
edge.align_to_corners(from_pos, to_pos)
@ -258,7 +256,6 @@ func add_edge(from_pos: Vector3, to_pos: Vector3, index: int = -1):
add_corner(point, edge.get_index() + 1)
)
room.wall_edges.add_child(edge)
room.wall_edges.move_child(edge, index)
return edge
@ -277,4 +274,7 @@ func update_store():
store_room.corners = corners
store_room.height = room.room_ceiling.position.y
# Manually update the array
Store.house.state.rooms = Store.house.state.rooms
Store.house.save_local()

View File

@ -5,6 +5,9 @@ const Miniature = preload ("res://content/system/house/mini/miniature.gd")
@onready var mini_view_button = $Content/MiniView
@onready var heat_map_button = $Content/HeatMap
@onready var humudity_map_button = $Content/HumidityMap
@onready var min_slider = $Content/MinSlider
@onready var max_slider = $Content/MaxSlider
@onready var opacity_slider = $Content/OpacitySlider
@onready var background = $Background
func _ready():
@ -40,5 +43,51 @@ func _ready():
R.effect(func(_arg):
heat_map_button.active=mini_view.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE
humudity_map_button.active=mini_view.heatmap_type.value == Miniature.HeatmapType.HUMIDITY
)
min_slider.on_value_changed.connect(func(value):
if value >= mini_view.selected_scale.value.y:
min_slider.value=mini_view.selected_scale.value.y
return
mini_view.selected_scale.value.x=value
)
max_slider.on_value_changed.connect(func(value):
if value <= mini_view.selected_scale.value.x:
max_slider.value=mini_view.selected_scale.value.x
return
mini_view.selected_scale.value.y=value
)
R.effect(func(_arg):
min_slider.value=mini_view.selected_scale.value.x
max_slider.value=mini_view.selected_scale.value.y
)
# Update Slider
R.effect(func(_arg):
var minmax=mini_view.get_base_scale()
min_slider.min=minmax.x
min_slider.max=minmax.y
max_slider.min=minmax.x
max_slider.max=minmax.y
var sensor_minmax=mini_view.get_sensor_scale()
sensor_minmax.x=floor(sensor_minmax.x)
sensor_minmax.y=ceil(sensor_minmax.y)
mini_view.selected_scale.value=sensor_minmax
min_slider.value=sensor_minmax.x
max_slider.value=sensor_minmax.y
var unit=mini_view.get_sensor_unit()
min_slider.label_unit=unit
max_slider.label_unit=unit
)
R.bind(opacity_slider, "value", mini_view.opacity, opacity_slider.on_value_changed)

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=3 uid="uid://ddpxthb414unp"]
[gd_scene load_steps=6 format=3 uid="uid://ddpxthb414unp"]
[ext_resource type="Script" path="res://content/ui/menu/view/view_menu.gd" id="1_hxajx"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="2_qan1b"]
[ext_resource type="Material" uid="uid://bujy3egn1oqac" path="res://assets/materials/pri-500.material" id="2_se6ic"]
[ext_resource type="PackedScene" uid="uid://pk5k1q8bx0rj" path="res://content/ui/components/slider/slider.tscn" id="4_d3xhb"]
[sub_resource type="BoxMesh" id="BoxMesh_qr3bi"]
size = Vector3(0.3, 0.01, 0.3)
@ -58,3 +59,48 @@ text = "Humidity Map"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="MinSlider" parent="Content" instance=ExtResource("4_d3xhb")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0.01, 0.2)
step = 1.0
show_label = true
size = Vector3(10, 0.4, 1)
[node name="MinValue" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0.15, 0.01, 0.2)
pixel_size = 0.001
text = "Min Value"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="MaxSlider" parent="Content" instance=ExtResource("4_d3xhb")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0.01, 0.24)
step = 1.0
show_label = true
size = Vector3(10, 0.4, 1)
[node name="MaxValue" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0.15, 0.01, 0.24)
pixel_size = 0.001
text = "Max Value"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="OpacitySlider" parent="Content" instance=ExtResource("4_d3xhb")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0.01, 0.28)
max = 100.0
value = 30.0
step = 10.0
show_label = true
label_unit = "%"
size = Vector3(10, 0.4, 1)
[node name="OpacityLabel" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0.15, 0.01, 0.28)
pixel_size = 0.001
text = "Opacity"
font_size = 18
outline_size = 0
horizontal_alignment = 0