finish basic mini view and heatmap part
This commit is contained in:
parent
d07a7b924f
commit
3e84b04c67
|
@ -47,7 +47,7 @@ func _ready():
|
||||||
if action.name == "menu_button":
|
if action.name == "menu_button":
|
||||||
toggle_menu()
|
toggle_menu()
|
||||||
elif action.name == "by_button":
|
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):
|
EventSystem.on_focus_in.connect(func(event):
|
||||||
|
|
|
@ -2,11 +2,13 @@ extends Node3D
|
||||||
|
|
||||||
const Room = preload ("./room/room.tscn")
|
const Room = preload ("./room/room.tscn")
|
||||||
const RoomType = preload ("./room/room.gd")
|
const RoomType = preload ("./room/room.gd")
|
||||||
|
const Miniature = preload ("./mini/miniature.gd")
|
||||||
|
const AlignReference = preload ("./align_reference.gd")
|
||||||
|
|
||||||
@onready var levels = $Levels
|
@onready var levels = $Levels
|
||||||
@onready var collision_shape = $Levels/CollisionShape3D
|
@onready var collision_shape = $Levels/CollisionShape3D
|
||||||
@onready var align_reference = $AlignReference
|
@onready var align_reference: AlignReference = $AlignReference
|
||||||
@onready var mini_view = $Levels/Miniature
|
@onready var mini_view: Miniature = $Levels/Miniature
|
||||||
|
|
||||||
var fixing_reference: bool = false
|
var fixing_reference: bool = false
|
||||||
var editing_room: RoomType = null
|
var editing_room: RoomType = null
|
||||||
|
|
|
@ -18,10 +18,9 @@ float sphere_weight(int index, vec3 world_pos, float r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vertex() {
|
void vertex() {
|
||||||
// Calculate Global Coordinates
|
|
||||||
vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
|
|
||||||
|
|
||||||
color = vec3(1.0, 1.0, 1.0);
|
color = vec3(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
if(data_size > 0) {
|
||||||
float distances[100];
|
float distances[100];
|
||||||
float dist_sum = 0.0;
|
float dist_sum = 0.0;
|
||||||
float data_sum = 0.0;
|
float data_sum = 0.0;
|
||||||
|
@ -29,16 +28,18 @@ void vertex() {
|
||||||
float closest_dist = -1.0;
|
float closest_dist = -1.0;
|
||||||
int closest_index = 0;
|
int closest_index = 0;
|
||||||
|
|
||||||
if(data_size > 0) {
|
// Calculate Global Coordinates
|
||||||
closest_dist = distance(data[0].xyz, world_position);
|
//vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
|
||||||
|
|
||||||
|
closest_dist = distance(data[0].xyz, VERTEX);
|
||||||
|
|
||||||
// Inverse distance weighting using Shepard's method
|
// Inverse distance weighting using Shepard's method
|
||||||
for(int i = 0; i < data_size; i++) {
|
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];
|
dist_sum += distances[i];
|
||||||
data_sum += distances[i] * data[i].w;
|
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) {
|
if(dist < closest_dist) {
|
||||||
closest_dist = dist;
|
closest_dist = dist;
|
||||||
|
|
|
@ -5,42 +5,58 @@ const wall_material = preload ("./mini_wall.tres")
|
||||||
|
|
||||||
@onready var body = $Body
|
@onready var body = $Body
|
||||||
@onready var model = $Body/Model
|
@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 collision_shape = $Body/CollisionShape3D
|
||||||
@onready var toggle_heatmap = $Body/HeatmapButton
|
@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( - 20.0, 60.0)
|
||||||
var temperature_scale := Vector2(22.0, 26.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)
|
var small = R.state(false)
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
wall_material.set_shader_parameter("data", [])
|
||||||
|
wall_material.set_shader_parameter("data_size", 0)
|
||||||
|
|
||||||
if Store.house.is_loaded() == false:
|
if Store.house.is_loaded() == false:
|
||||||
await Store.house.on_loaded
|
await Store.house.on_loaded
|
||||||
|
|
||||||
|
# Update Room Mesh
|
||||||
R.effect(func(_arg):
|
R.effect(func(_arg):
|
||||||
if Store.house.state.rooms.size() == 0:
|
if Store.house.state.rooms.size() == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
if heatmap.value == false:
|
if heatmap_type.value == HeatmapType.NONE&&small.value == false:
|
||||||
return
|
return
|
||||||
|
|
||||||
for room in Store.house.state.rooms:
|
for child in model.get_children():
|
||||||
var corners=room.corners
|
model.remove_child(child)
|
||||||
var height=room.height
|
child.free()
|
||||||
|
|
||||||
walls_mesh.mesh=ConstructRoomMesh.generate_wall_mesh_grid(corners, height)
|
for room in Store.house.state.rooms:
|
||||||
floor_mesh.mesh=ConstructRoomMesh.generate_ceiling_mesh_grid(corners)
|
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
|
walls_mesh.material_override=wall_material
|
||||||
floor_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):
|
R.effect(func(_arg):
|
||||||
|
collision_shape.disabled=small.value == false
|
||||||
|
|
||||||
var tween:=create_tween()
|
var tween:=create_tween()
|
||||||
tween.set_parallel(true)
|
tween.set_parallel(true)
|
||||||
if small.value:
|
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(model, "scale", Vector3(0.1, 0.1, 0.1), 0.5)
|
||||||
tween.tween_property(body, "position", new_position, 0.5)
|
tween.tween_property(body, "position", new_position, 0.5)
|
||||||
else:
|
else:
|
||||||
tween.tween_property(model, "scale", Vector3(1, 1, 1), 0.5)
|
tween.tween_property(model, "scale", Vector3.ONE, 0.5)
|
||||||
tween.tween_property(body, "position", Vector3(0, 0, 0), 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):
|
R.effect(func(_arg):
|
||||||
walls_mesh.visible=heatmap.value
|
var show_map=heatmap_type.value != HeatmapType.NONE
|
||||||
floor_mesh.visible=heatmap.value
|
var show_small=small.value
|
||||||
collision_shape.disabled=!heatmap.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)
|
EventSystem.on_slow_tick.connect(update_data)
|
||||||
else:
|
else:
|
||||||
EventSystem.on_slow_tick.disconnect(update_data)
|
EventSystem.on_slow_tick.disconnect(update_data)
|
||||||
|
@ -85,6 +108,11 @@ func _ready():
|
||||||
|
|
||||||
const SensorEntity = preload ("res://content/entities/sensor/sensor.gd")
|
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:
|
func update_data(_delta: float) -> void:
|
||||||
var data_list = []
|
var data_list = []
|
||||||
|
|
||||||
|
@ -96,7 +124,7 @@ func update_data(_delta: float) -> void:
|
||||||
if data == null:
|
if data == null:
|
||||||
continue
|
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)))
|
data_list.append(Vector4(sensor_pos.x, sensor_pos.y, sensor_pos.z, float(data)))
|
||||||
|
|
||||||
|
|
|
@ -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/system/house/mini/miniature.gd" id="1_b53yn"]
|
||||||
[ext_resource type="Script" path="res://content/functions/movable.gd" id="2_x7oed"]
|
[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"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_bckw3"]
|
||||||
|
|
||||||
|
@ -18,14 +17,3 @@ shape = SubResource("BoxShape3D_bckw3")
|
||||||
script = ExtResource("2_x7oed")
|
script = ExtResource("2_x7oed")
|
||||||
|
|
||||||
[node name="Model" type="Node3D" parent="Body"]
|
[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
|
|
||||||
|
|
|
@ -58,7 +58,9 @@ const ECHO_WAIT_REPEAT = 0.1
|
||||||
|
|
||||||
var active: bool = false:
|
var active: bool = false:
|
||||||
set(value):
|
set(value):
|
||||||
if active != value:
|
if active == value:
|
||||||
|
return
|
||||||
|
|
||||||
on_toggled.emit(value)
|
on_toggled.emit(value)
|
||||||
active = value
|
active = value
|
||||||
if !is_inside_tree(): return
|
if !is_inside_tree(): return
|
||||||
|
|
|
@ -1,11 +1,44 @@
|
||||||
extends Node3D
|
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
|
@onready var background = $Background
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
background.visible = false
|
background.visible = false
|
||||||
|
|
||||||
mini_view.on_button_down.connect(func():
|
if !House.body.is_node_ready():
|
||||||
House.body.mini_view.small.value=!House.body.mini_view.small.value
|
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
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -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="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="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"]
|
[sub_resource type="BoxMesh" id="BoxMesh_qr3bi"]
|
||||||
size = Vector3(0.3, 0.01, 0.3)
|
size = Vector3(0.3, 0.01, 0.3)
|
||||||
|
@ -11,6 +12,7 @@ script = ExtResource("1_hxajx")
|
||||||
|
|
||||||
[node name="Background" type="MeshInstance3D" parent="."]
|
[node name="Background" type="MeshInstance3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15)
|
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")
|
mesh = SubResource("BoxMesh_qr3bi")
|
||||||
|
|
||||||
[node name="Content" type="Node3D" parent="."]
|
[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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.03)
|
||||||
label = "view_comfy"
|
label = "view_comfy"
|
||||||
icon = true
|
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
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
extends Node
|
extends Node
|
||||||
## Shortcut to get the House node from the Main scene
|
## Shortcut to get the House node from the Main scene
|
||||||
|
|
||||||
@onready var body = get_node_or_null("/root/Main/House")
|
const HouseClass = preload ("res://content/system/house/house.gd")
|
||||||
|
|
||||||
|
@onready var body: HouseClass = get_node_or_null("/root/Main/House")
|
Loading…
Reference in New Issue
Block a user