diff --git a/app/content/main.gd b/app/content/main.gd index 75a43b2..86af213 100644 --- a/app/content/main.gd +++ b/app/content/main.gd @@ -47,7 +47,7 @@ func _ready(): if action.name == "menu_button": toggle_menu() elif action.name == "by_button": - House.body.mini_view=!House.body.mini_view + House.body.mini_view.small.value=!House.body.mini_view.small.value ) EventSystem.on_focus_in.connect(func(event): diff --git a/app/content/system/house/house.gd b/app/content/system/house/house.gd index d7891c0..92b2877 100644 --- a/app/content/system/house/house.gd +++ b/app/content/system/house/house.gd @@ -2,11 +2,13 @@ extends Node3D const Room = preload ("./room/room.tscn") const RoomType = preload ("./room/room.gd") +const Miniature = preload ("./mini/miniature.gd") +const AlignReference = preload ("./align_reference.gd") @onready var levels = $Levels @onready var collision_shape = $Levels/CollisionShape3D -@onready var align_reference = $AlignReference -@onready var mini_view = $Levels/Miniature +@onready var align_reference: AlignReference = $AlignReference +@onready var mini_view: Miniature = $Levels/Miniature var fixing_reference: bool = false var editing_room: RoomType = null diff --git a/app/content/system/house/mini/mini_wall_shader.gdshader b/app/content/system/house/mini/mini_wall_shader.gdshader index 0af72f6..34e3bf1 100644 --- a/app/content/system/house/mini/mini_wall_shader.gdshader +++ b/app/content/system/house/mini/mini_wall_shader.gdshader @@ -18,27 +18,28 @@ float sphere_weight(int index, vec3 world_pos, float r) { } void vertex() { - // Calculate Global Coordinates - vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; - color = vec3(1.0, 1.0, 1.0); - float distances[100]; - float dist_sum = 0.0; - float data_sum = 0.0; - - float closest_dist = -1.0; - int closest_index = 0; if(data_size > 0) { - closest_dist = distance(data[0].xyz, world_position); + float distances[100]; + float dist_sum = 0.0; + float data_sum = 0.0; + + float closest_dist = -1.0; + int closest_index = 0; + + // Calculate Global Coordinates + //vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; + + closest_dist = distance(data[0].xyz, VERTEX); // Inverse distance weighting using Shepard's method for(int i = 0; i < data_size; i++) { - distances[i] = sphere_weight(i, world_position, 5.0); + distances[i] = sphere_weight(i, VERTEX, 5.0); dist_sum += distances[i]; data_sum += distances[i] * data[i].w; - float dist = distance(data[i].xyz, world_position); + float dist = distance(data[i].xyz, VERTEX); if(dist < closest_dist) { closest_dist = dist; diff --git a/app/content/system/house/mini/miniature.gd b/app/content/system/house/mini/miniature.gd index 3efc769..1a97d62 100644 --- a/app/content/system/house/mini/miniature.gd +++ b/app/content/system/house/mini/miniature.gd @@ -5,42 +5,58 @@ const wall_material = preload ("./mini_wall.tres") @onready var body = $Body @onready var model = $Body/Model -@onready var walls_mesh = $Body/Model/WallsMesh -@onready var floor_mesh = $Body/Model/FloorMesh @onready var collision_shape = $Body/CollisionShape3D @onready var toggle_heatmap = $Body/HeatmapButton +enum HeatmapType { + NONE = 0, + TEMPERATURE = 1, + HUMIDITY = 2 +} + # var temperature_scale := Vector2( - 20.0, 60.0) var temperature_scale := Vector2(22.0, 26.0) -var heatmap = R.state(false) +var heatmap_type = R.state(HeatmapType.NONE) var small = R.state(false) func _ready(): + wall_material.set_shader_parameter("data", []) + wall_material.set_shader_parameter("data_size", 0) + if Store.house.is_loaded() == false: await Store.house.on_loaded + # Update Room Mesh R.effect(func(_arg): if Store.house.state.rooms.size() == 0: return - if heatmap.value == false: + if heatmap_type.value == HeatmapType.NONE&&small.value == false: return - for room in Store.house.state.rooms: - var corners=room.corners - var height=room.height + for child in model.get_children(): + model.remove_child(child) + child.free() - walls_mesh.mesh=ConstructRoomMesh.generate_wall_mesh_grid(corners, height) - floor_mesh.mesh=ConstructRoomMesh.generate_ceiling_mesh_grid(corners) + for room in Store.house.state.rooms: + var walls_mesh=MeshInstance3D.new() + var floor_mesh=MeshInstance3D.new() + + model.add_child(walls_mesh) + model.add_child(floor_mesh) + + walls_mesh.mesh=ConstructRoomMesh.generate_wall_mesh_grid(room.corners, room.height) + floor_mesh.mesh=ConstructRoomMesh.generate_ceiling_mesh_grid(room.corners) walls_mesh.material_override=wall_material floor_mesh.material_override=wall_material ) - R.bind(toggle_heatmap, "active", heatmap, toggle_heatmap.on_toggled) - + # Update Size R.effect(func(_arg): + collision_shape.disabled=small.value == false + var tween:=create_tween() tween.set_parallel(true) if small.value: @@ -66,16 +82,23 @@ func _ready(): tween.tween_property(model, "scale", Vector3(0.1, 0.1, 0.1), 0.5) tween.tween_property(body, "position", new_position, 0.5) else: - tween.tween_property(model, "scale", Vector3(1, 1, 1), 0.5) - tween.tween_property(body, "position", Vector3(0, 0, 0), 0.5) + tween.tween_property(model, "scale", Vector3.ONE, 0.5) + tween.tween_property(body, "position", Vector3.ZERO, 0.5) + tween.tween_property(body, "quaternion", Quaternion.IDENTITY, 0.5) ) + # Update Walls R.effect(func(_arg): - walls_mesh.visible=heatmap.value - floor_mesh.visible=heatmap.value - collision_shape.disabled=!heatmap.value + var show_map=heatmap_type.value != HeatmapType.NONE + var show_small=small.value - if heatmap.value: + for child in model.get_children(): + child.visible=show_map||show_small + ) + + # Update Heatmap + R.effect(func(_arg): + if heatmap_type.value != HeatmapType.NONE: EventSystem.on_slow_tick.connect(update_data) else: EventSystem.on_slow_tick.disconnect(update_data) @@ -85,6 +108,11 @@ func _ready(): 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 update_data(_delta: float) -> void: var data_list = [] @@ -96,7 +124,7 @@ func update_data(_delta: float) -> void: if data == null: continue - var sensor_pos = sensor.global_position + var sensor_pos = House.body.to_local(sensor.global_position) data_list.append(Vector4(sensor_pos.x, sensor_pos.y, sensor_pos.z, float(data))) diff --git a/app/content/system/house/mini/miniature.tscn b/app/content/system/house/mini/miniature.tscn index eba1d0d..885837a 100644 --- a/app/content/system/house/mini/miniature.tscn +++ b/app/content/system/house/mini/miniature.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=5 format=3 uid="uid://ds60i5n211hi3"] +[gd_scene load_steps=4 format=3 uid="uid://ds60i5n211hi3"] [ext_resource type="Script" path="res://content/system/house/mini/miniature.gd" id="1_b53yn"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="2_x7oed"] -[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="3_tgdcf"] [sub_resource type="BoxShape3D" id="BoxShape3D_bckw3"] @@ -18,14 +17,3 @@ shape = SubResource("BoxShape3D_bckw3") script = ExtResource("2_x7oed") [node name="Model" type="Node3D" parent="Body"] - -[node name="WallsMesh" type="MeshInstance3D" parent="Body/Model"] -skeleton = NodePath("../../..") - -[node name="FloorMesh" type="MeshInstance3D" parent="Body/Model"] -skeleton = NodePath("../../..") - -[node name="HeatmapButton" parent="Body" instance=ExtResource("3_tgdcf")] -label = "heat" -icon = true -toggleable = true diff --git a/app/content/ui/components/button/button.gd b/app/content/ui/components/button/button.gd index 4fc6ff9..740f69e 100644 --- a/app/content/ui/components/button/button.gd +++ b/app/content/ui/components/button/button.gd @@ -58,8 +58,10 @@ const ECHO_WAIT_REPEAT = 0.1 var active: bool = false: set(value): - if active != value: - on_toggled.emit(value) + if active == value: + return + + on_toggled.emit(value) active = value if !is_inside_tree(): return update_animation(1.0 if active else 0.0) diff --git a/app/content/ui/menu/view/view_menu.gd b/app/content/ui/menu/view/view_menu.gd index 0eab8fb..d22a003 100644 --- a/app/content/ui/menu/view/view_menu.gd +++ b/app/content/ui/menu/view/view_menu.gd @@ -1,11 +1,44 @@ extends Node3D -@onready var mini_view = $Content/MiniView +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 background = $Background func _ready(): background.visible = false - mini_view.on_button_down.connect(func(): - House.body.mini_view.small.value=!House.body.mini_view.small.value + if !House.body.is_node_ready(): + await House.body.ready + + var mini_view = House.body.mini_view + + mini_view_button.on_toggled.connect(func(active): + mini_view.small.value=active + ) + + heat_map_button.on_toggled.connect(func(active): + if active == false: + if mini_view.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE: + mini_view.heatmap_type.value=Miniature.HeatmapType.NONE + return + + mini_view.heatmap_type.value=Miniature.HeatmapType.TEMPERATURE + ) + + humudity_map_button.on_toggled.connect(func(active): + if active == false: + if mini_view.heatmap_type.value == Miniature.HeatmapType.HUMIDITY: + mini_view.heatmap_type.value=Miniature.HeatmapType.NONE + return + + mini_view.heatmap_type.value=Miniature.HeatmapType.HUMIDITY + ) + + 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 + ) diff --git a/app/content/ui/menu/view/view_menu.tscn b/app/content/ui/menu/view/view_menu.tscn index 986c50b..a69710f 100644 --- a/app/content/ui/menu/view/view_menu.tscn +++ b/app/content/ui/menu/view/view_menu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=4 format=3 uid="uid://ddpxthb414unp"] +[gd_scene load_steps=5 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"] [sub_resource type="BoxMesh" id="BoxMesh_qr3bi"] size = Vector3(0.3, 0.01, 0.3) @@ -11,6 +12,7 @@ script = ExtResource("1_hxajx") [node name="Background" type="MeshInstance3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15) +material_override = ExtResource("2_se6ic") mesh = SubResource("BoxMesh_qr3bi") [node name="Content" type="Node3D" parent="."] @@ -19,3 +21,40 @@ mesh = SubResource("BoxMesh_qr3bi") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.03) label = "view_comfy" icon = true +toggleable = true + +[node name="MiniViewLabel" type="Label3D" parent="Content"] +transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0.07, 0.01, 0.03) +pixel_size = 0.001 +text = "Mini View" +font_size = 18 +outline_size = 0 +horizontal_alignment = 0 + +[node name="HeatMap" parent="Content" instance=ExtResource("2_qan1b")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.09) +label = "device_thermostat" +icon = true +toggleable = true + +[node name="HeatMapLabel" type="Label3D" parent="Content"] +transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0.07, 0.01, 0.09) +pixel_size = 0.001 +text = "Heat Map" +font_size = 18 +outline_size = 0 +horizontal_alignment = 0 + +[node name="HumidityMap" parent="Content" instance=ExtResource("2_qan1b")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.15) +label = "humidity_mid" +icon = true +toggleable = true + +[node name="HumidityMapLabel" type="Label3D" parent="Content"] +transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0.07, 0.01, 0.15) +pixel_size = 0.001 +text = "Humidity Map" +font_size = 18 +outline_size = 0 +horizontal_alignment = 0 diff --git a/app/lib/globals/house_body.gd b/app/lib/globals/house_body.gd index 5ea5d3c..2339687 100644 --- a/app/lib/globals/house_body.gd +++ b/app/lib/globals/house_body.gd @@ -1,4 +1,6 @@ extends Node ## Shortcut to get the House node from the Main scene -@onready var body = get_node_or_null("/root/Main/House") \ No newline at end of file +const HouseClass = preload ("res://content/system/house/house.gd") + +@onready var body: HouseClass = get_node_or_null("/root/Main/House") \ No newline at end of file