From 04f00fd262172c4c1407e6943bc9e35009be7cc2 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Sun, 28 Jan 2024 15:22:08 +0100 Subject: [PATCH 1/5] center mini-view in front of player --- content/system/house/house.gd | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/content/system/house/house.gd b/content/system/house/house.gd index ab335a6..b6e4df0 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -189,6 +189,17 @@ func update_mini_view(): collision_shape.global_position = center collision_shape.shape.size = aabb.size + + var camera = get_node("/root/Main/XROrigin3D/XRCamera3D") + var camera_position = camera.global_position + var camera_direction = -camera.global_transform.basis.z + + camera_position.y *= 0.5 + camera_direction.y = 0.0 + + + var target_position = camera_position + camera_direction.normalized() * 0.2 + levels.global_position = target_position - center * 0.1 else: levels.position = Vector3(0, 0, 0) From 0f824b99ef9d3e0fabae10282b53189f6f1c0f95 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Sun, 28 Jan 2024 17:13:32 +0100 Subject: [PATCH 2/5] add color picker --- assets/canvas.png | 3 ++ assets/canvas.png.import | 34 ++++++++++++++++++++++ content/entities/light/light.gd | 25 ++++++++++++++++ content/entities/light/light.tscn | 47 +++++++++++++++++++++++++++++-- project.godot | 1 + 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 assets/canvas.png create mode 100644 assets/canvas.png.import diff --git a/assets/canvas.png b/assets/canvas.png new file mode 100644 index 0000000..83588d5 --- /dev/null +++ b/assets/canvas.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f523eb87489026aa87814b63b31e0ce83ca91a0729ef7d93079e39a67e348fb5 +size 237647 diff --git a/assets/canvas.png.import b/assets/canvas.png.import new file mode 100644 index 0000000..56156bb --- /dev/null +++ b/assets/canvas.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://hy2f6is7qjyv" +path="res://.godot/imported/canvas.png-aa470cb9edfe91c0a54e6c5fa29d4c26.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/canvas.png" +dest_files=["res://.godot/imported/canvas.png-aa470cb9edfe91c0a54e6c5fa29d4c26.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/content/entities/light/light.gd b/content/entities/light/light.gd index 5406ee4..7ceec8a 100644 --- a/content/entities/light/light.gd +++ b/content/entities/light/light.gd @@ -1,12 +1,15 @@ extends Entity const Entity = preload("../entity.gd") +const color_wheel_img := preload("res://assets/canvas.png") @export var color_off = Color(0.23, 0.23, 0.23) @export var color_on = Color(1.0, 0.85, 0.0) @onready var animation: AnimationPlayer = $AnimationPlayer @onready var slider: Slider3D = $Slider +@onready var color_wheel = $ColorWheel +@onready var color_puck = $ColorWheel/Puck var state = true var brightness = 0 # 0-255 @@ -18,6 +21,28 @@ func _ready(): var stateInfo = await HomeApi.get_state(entity_id) set_state(stateInfo["state"] == "on") + if stateInfo.has("attributes") && stateInfo["attributes"].has("supported_color_modes") && stateInfo["attributes"]["supported_color_modes"].has("rgb"): + color_wheel.get_node("Clickable").on_press_down.connect(func(event: EventPointer): + var target_point = color_wheel.to_local(event.ray.get_collision_point()) + + var delta = Vector2(target_point.x, target_point.z) * (1.0 / 0.08) + if delta.length() > 1: + delta = delta.normalized() + + var color = color_wheel_img.get_image().get_pixel((delta.x * 0.5 + 0.5) * 1000, (delta.y * 0.5 + 0.5) * 1000) + + color_puck.material_override.albedo_color = color + color_puck.position = Vector3(target_point.x, color_puck.position.y, target_point.z) + + var attributes = { + "rgb_color": [int(color.r * 255), int(color.g * 255), int(color.b * 255)] + } + + HomeApi.set_state(entity_id, "on", attributes) + ) + else: + remove_child(color_wheel) + await HomeApi.watch_state(entity_id, func(new_state): if (new_state["state"] == "on") == state: return diff --git a/content/entities/light/light.tscn b/content/entities/light/light.tscn index cedeac3..2cfb355 100644 --- a/content/entities/light/light.tscn +++ b/content/entities/light/light.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=10 format=3 uid="uid://cw86rc42dv2d8"] +[gd_scene load_steps=17 format=3 uid="uid://cw86rc42dv2d8"] [ext_resource type="Script" path="res://content/entities/light/light.gd" id="1_ykxy3"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="4_4sfxb"] [ext_resource type="Material" uid="uid://vce66e7sbc3n" path="res://content/entities/light/light_on.tres" id="5_50gph"] [ext_resource type="Script" path="res://content/functions/occludable.gd" id="5_oh4jg"] [ext_resource type="PackedScene" uid="uid://pk5k1q8bx0rj" path="res://content/ui/components/slider/slider.tscn" id="6_mhjlm"] +[ext_resource type="Texture2D" uid="uid://hy2f6is7qjyv" path="res://assets/canvas.png" id="7_ximu1"] +[ext_resource type="Script" path="res://content/functions/clickable.gd" id="8_1sfll"] [sub_resource type="SphereShape3D" id="SphereShape3D_ukj14"] radius = 0.05 @@ -46,6 +48,23 @@ _data = { "light": SubResource("Animation_7o31s") } +[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_k3ob2"] +points = PackedVector3Array(0, -0.005, -0.08, -0.00784652, -0.005, -0.0796241, 0, 0.005, -0.08, 0.00783085, -0.005, -0.0796241, -0.00784652, 0.005, -0.0796241, -0.0156147, -0.005, -0.0784651, 0.00783085, 0.005, -0.0796241, 0.0155991, -0.005, -0.0784651, -0.0156147, 0.005, -0.0784651, -0.0232263, -0.005, -0.0765701, 0.0155991, 0.005, -0.0784651, 0.0232106, -0.005, -0.0765701, -0.0232263, 0.005, -0.0765701, -0.0306186, -0.005, -0.0739233, 0.0232106, 0.005, -0.0765701, 0.030603, -0.005, -0.0739233, -0.0306186, 0.005, -0.0739233, -0.0377134, -0.005, -0.070556, 0.030603, 0.005, -0.0739233, 0.0376977, -0.005, -0.070556, -0.0377134, 0.005, -0.070556, -0.0444479, -0.005, -0.0665309, 0.0376977, 0.005, -0.070556, 0.0444323, -0.005, -0.0665309, -0.0444479, 0.005, -0.0665309, -0.0507596, -0.005, -0.0618481, 0.0444323, 0.005, -0.0665309, 0.0507439, -0.005, -0.0618481, -0.0507596, 0.005, -0.0618481, -0.0565701, -0.005, -0.0565701, 0.0507439, 0.005, -0.0618481, 0.0565544, -0.005, -0.0565701, -0.0565701, 0.005, -0.0565701, -0.0618481, -0.005, -0.0507596, 0.0565544, 0.005, -0.0565701, 0.0618324, -0.005, -0.0507596, -0.0618481, 0.005, -0.0507596, -0.0665309, -0.005, -0.0444479, 0.0618324, 0.005, -0.0507596, 0.0665153, -0.005, -0.0444479, -0.0665309, 0.005, -0.0444479, -0.070556, -0.005, -0.0377134, 0.0665153, 0.005, -0.0444479, 0.0705403, -0.005, -0.0377134, -0.070556, 0.005, -0.0377134, -0.0739233, -0.005, -0.0306186, 0.0705403, 0.005, -0.0377134, 0.0739076, -0.005, -0.0306186, -0.0739233, 0.005, -0.0306186, -0.0765701, -0.005, -0.0232263, 0.0739076, 0.005, -0.0306186, 0.0765544, -0.005, -0.0232263, -0.0765701, 0.005, -0.0232263, -0.0784651, -0.005, -0.0156147, 0.0765544, 0.005, -0.0232263, 0.0784495, -0.005, -0.0156147, -0.0784651, 0.005, -0.0156147, -0.0796241, -0.005, -0.00784652, 0.0784495, 0.005, -0.0156147, 0.0796085, -0.005, -0.00784652, -0.0796241, 0.005, -0.00784652, -0.08, -0.005, 0, 0.0796085, 0.005, -0.00784652, 0.08, -0.005, 0, -0.08, 0.005, 0, -0.0796241, -0.005, 0.00783085, 0.08, 0.005, 0, 0.0796085, -0.005, 0.00783085, -0.0796241, 0.005, 0.00783085, -0.0784651, -0.005, 0.0155991, 0.0796085, 0.005, 0.00783085, 0.0784495, -0.005, 0.0155991, -0.0784651, 0.005, 0.0155991, -0.0765701, -0.005, 0.0232106, 0.0784495, 0.005, 0.0155991, 0.0765544, -0.005, 0.0232106, -0.0765701, 0.005, 0.0232106, -0.0739233, -0.005, 0.030603, 0.0765544, 0.005, 0.0232106, 0.0739076, -0.005, 0.030603, -0.0739233, 0.005, 0.030603, -0.070556, -0.005, 0.0376977, 0.0739076, 0.005, 0.030603, 0.0705403, -0.005, 0.0376977, -0.070556, 0.005, 0.0376977, -0.0665309, -0.005, 0.0444323, 0.0705403, 0.005, 0.0376977, 0.0665153, -0.005, 0.0444323, -0.0665309, 0.005, 0.0444323, -0.0618481, -0.005, 0.0507439, 0.0665153, 0.005, 0.0444323, 0.0618324, -0.005, 0.0507439, -0.0618481, 0.005, 0.0507439, -0.0565701, -0.005, 0.0565544, 0.0618324, 0.005, 0.0507439, 0.0565544, -0.005, 0.0565544, -0.0565701, 0.005, 0.0565544, -0.0507596, -0.005, 0.0618324, 0.0565544, 0.005, 0.0565544, 0.0507439, -0.005, 0.0618324, -0.0507596, 0.005, 0.0618324, -0.0444479, -0.005, 0.0665153, 0.0507439, 0.005, 0.0618324, 0.0444323, -0.005, 0.0665153, -0.0444479, 0.005, 0.0665153, -0.0377134, -0.005, 0.0705403, 0.0444323, 0.005, 0.0665153, 0.0376977, -0.005, 0.0705403, -0.0377134, 0.005, 0.0705403, -0.0306186, -0.005, 0.0739076, 0.0376977, 0.005, 0.0705403, 0.030603, -0.005, 0.0739076, -0.0306186, 0.005, 0.0739076, -0.0232263, -0.005, 0.0765544, 0.030603, 0.005, 0.0739076, 0.0232106, -0.005, 0.0765544, -0.0232263, 0.005, 0.0765544, -0.0156147, -0.005, 0.0784495, 0.0232106, 0.005, 0.0765544, 0.0155991, -0.005, 0.0784495, -0.0156147, 0.005, 0.0784495, -0.00784652, -0.005, 0.0796085, 0.0155991, 0.005, 0.0784495, 0.00783085, -0.005, 0.0796085, -0.00784652, 0.005, 0.0796085, 0, -0.005, 0.08, 0.00783085, 0.005, 0.0796085, 0, 0.005, 0.08) + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_7p762"] + +[sub_resource type="CylinderMesh" id="CylinderMesh_c10un"] +top_radius = 0.08 +bottom_radius = 0.08 +height = 0.01 + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1jd14"] + +[sub_resource type="CylinderMesh" id="CylinderMesh_x68ys"] +top_radius = 0.01 +bottom_radius = 0.01 +height = 0.005 + [node name="Light" type="StaticBody3D" groups=["entity"]] collision_mask = 0 script = ExtResource("1_ykxy3") @@ -80,8 +99,32 @@ libraries = { } [node name="Slider" parent="." instance=ExtResource("6_mhjlm")] -transform = Transform3D(-4.37114e-08, 1, 0, 1, 4.37114e-08, 8.74228e-08, 8.74228e-08, 3.82137e-15, -1, 0.00190757, -0.00579122, -0.0914348) +transform = Transform3D(1.91069e-15, 4.37114e-08, 1, 1, -4.37114e-08, 0, 4.37114e-08, 1, -4.37114e-08, 0.08, 0, 0) max = 100.0 value = 100.0 step = 1.0 size = Vector3(10, 0.4, 1) + +[node name="ColorWheel" type="StaticBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, -0.15, 0, 0) + +[node name="CollisionShape3D" type="CollisionShape3D" parent="ColorWheel"] +shape = SubResource("ConvexPolygonShape3D_k3ob2") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="ColorWheel"] +material_override = SubResource("StandardMaterial3D_7p762") +mesh = SubResource("CylinderMesh_c10un") +skeleton = NodePath("../..") + +[node name="Decal" type="Decal" parent="ColorWheel/MeshInstance3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.005, 0) +size = Vector3(0.15, 0.001, 0.15) +texture_albedo = ExtResource("7_ximu1") + +[node name="Clickable" type="Node" parent="ColorWheel"] +script = ExtResource("8_1sfll") + +[node name="Puck" type="MeshInstance3D" parent="ColorWheel"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.65661e-10, 0.01, 0) +material_override = SubResource("StandardMaterial3D_1jd14") +mesh = SubResource("CylinderMesh_x68ys") diff --git a/project.godot b/project.godot index e9cdb56..90f7f4c 100644 --- a/project.godot +++ b/project.godot @@ -63,4 +63,5 @@ lights_and_shadows/directional_shadow/soft_shadow_filter_quality.mobile=4 [xr] openxr/enabled=true +openxr/startup_alert=false shaders/enabled=true From 1fc6abb5f38cc99c0d2edc0e7a563ffc8546d2d1 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Sun, 28 Jan 2024 17:30:01 +0100 Subject: [PATCH 3/5] add modes to light --- content/entities/light/light.gd | 38 +++++++++++++++++++++++++++++-- content/entities/light/light.tscn | 25 +++++++++++++++++++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/content/entities/light/light.gd b/content/entities/light/light.gd index 7ceec8a..7535a73 100644 --- a/content/entities/light/light.gd +++ b/content/entities/light/light.gd @@ -10,6 +10,10 @@ const color_wheel_img := preload("res://assets/canvas.png") @onready var slider: Slider3D = $Slider @onready var color_wheel = $ColorWheel @onready var color_puck = $ColorWheel/Puck +@onready var modes = $Modes +@onready var mode_next = $Modes/Next +@onready var mode_before = $Modes/Previous +@onready var mode_label = $Modes/Label var state = true var brightness = 0 # 0-255 @@ -21,6 +25,36 @@ func _ready(): var stateInfo = await HomeApi.get_state(entity_id) set_state(stateInfo["state"] == "on") + if stateInfo.has("attributes") && stateInfo["attributes"].has("effect_list") && stateInfo["attributes"]["effect_list"].size() > 0: + mode_label.text = stateInfo["attributes"]["effect"] + + mode_next.on_button_down.connect(func(): + var index = stateInfo["attributes"]["effect_list"].find(stateInfo["attributes"]["effect"]) + if index == -1: + index = 0 + else: + index = (index + 1) % stateInfo["attributes"]["effect_list"].size() + + mode_label.text = stateInfo["attributes"]["effect_list"][index] + + HomeApi.set_state(entity_id, "on", {"effect": stateInfo["attributes"]["effect_list"][index]}) + ) + + mode_before.on_button_down.connect(func(): + var index = stateInfo["attributes"]["effect_list"].find(stateInfo["attributes"]["effect"]) + if index == -1: + index = 0 + else: + index = (index - 1) % stateInfo["attributes"]["effect_list"].size() + + mode_label.text = stateInfo["attributes"]["effect_list"][index] + + HomeApi.set_state(entity_id, "on", {"effect": stateInfo["attributes"]["effect_list"][index]}) + ) + else: + remove_child(modes) + + if stateInfo.has("attributes") && stateInfo["attributes"].has("supported_color_modes") && stateInfo["attributes"]["supported_color_modes"].has("rgb"): color_wheel.get_node("Clickable").on_press_down.connect(func(event: EventPointer): var target_point = color_wheel.to_local(event.ray.get_collision_point()) @@ -35,7 +69,7 @@ func _ready(): color_puck.position = Vector3(target_point.x, color_puck.position.y, target_point.z) var attributes = { - "rgb_color": [int(color.r * 255), int(color.g * 255), int(color.b * 255)] + "rgb_color": [int(color.r * 255), int(color.g * 255), int(color.b * 255)], } HomeApi.set_state(entity_id, "on", attributes) @@ -83,4 +117,4 @@ func _on_click(event): attributes["brightness"] = int(brightness) HomeApi.set_state(entity_id, "on" if !state else "off", attributes) - set_state(!state, brightness) \ No newline at end of file + set_state(!state, brightness) diff --git a/content/entities/light/light.tscn b/content/entities/light/light.tscn index 2cfb355..33f586e 100644 --- a/content/entities/light/light.tscn +++ b/content/entities/light/light.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=3 uid="uid://cw86rc42dv2d8"] +[gd_scene load_steps=18 format=3 uid="uid://cw86rc42dv2d8"] [ext_resource type="Script" path="res://content/entities/light/light.gd" id="1_ykxy3"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="4_4sfxb"] @@ -7,6 +7,7 @@ [ext_resource type="PackedScene" uid="uid://pk5k1q8bx0rj" path="res://content/ui/components/slider/slider.tscn" id="6_mhjlm"] [ext_resource type="Texture2D" uid="uid://hy2f6is7qjyv" path="res://assets/canvas.png" id="7_ximu1"] [ext_resource type="Script" path="res://content/functions/clickable.gd" id="8_1sfll"] +[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="8_nhcff"] [sub_resource type="SphereShape3D" id="SphereShape3D_ukj14"] radius = 0.05 @@ -59,6 +60,7 @@ bottom_radius = 0.08 height = 0.01 [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1jd14"] +resource_local_to_scene = true [sub_resource type="CylinderMesh" id="CylinderMesh_x68ys"] top_radius = 0.01 @@ -68,6 +70,8 @@ height = 0.005 [node name="Light" type="StaticBody3D" groups=["entity"]] collision_mask = 0 script = ExtResource("1_ykxy3") +color_off = null +color_on = null [node name="CollisionShape3D" type="CollisionShape3D" parent="."] shape = SubResource("SphereShape3D_ukj14") @@ -128,3 +132,22 @@ script = ExtResource("8_1sfll") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.65661e-10, 0.01, 0) material_override = SubResource("StandardMaterial3D_1jd14") mesh = SubResource("CylinderMesh_x68ys") + +[node name="Modes" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.11, 0) + +[node name="Next" parent="Modes" instance=ExtResource("8_nhcff")] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, -0.04, 0, 0) +label = "navigate_next" +icon = true + +[node name="Previous" parent="Modes" instance=ExtResource("8_nhcff")] +transform = Transform3D(1, 0, 0, 0, 2.98023e-08, -1, 0, 1, 2.98023e-08, -0.1, 0, 0) +label = "navigate_before" +icon = true + +[node name="Label" type="Label3D" parent="Modes"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.01, 0, 0) +pixel_size = 0.001 +text = "Default" +horizontal_alignment = 0 From a47d4c204028e5b7c208532e88583c08b4814a47 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Sun, 28 Jan 2024 17:37:26 +0100 Subject: [PATCH 4/5] fix bug saving multiple entities --- content/system/house/house.gd | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/content/system/house/house.gd b/content/system/house/house.gd index b6e4df0..c1fd636 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -37,7 +37,11 @@ func update_house(): var new_room = Store.house.rooms[index] create_room(new_room.name, 0) - for entity in Store.house.entities: + print(Store.house.entities) + + for entity_index in range(Store.house.entities.size()): + var entity = Store.house.entities[entity_index] + var entity_instance = create_entity_in(entity.id, entity.room) if entity_instance == null: @@ -174,8 +178,6 @@ func create_entity_in(entity_id: String, room_name: String): room.get_node("Entities").add_child(entity) entity.global_position = room.get_aabb().position + room.get_aabb().size / 2.0 - save_all_entities() - return entity func update_mini_view(): From e6791432d2f9297eaf9122c20de5563ac5258ec3 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Sun, 28 Jan 2024 17:38:55 +0100 Subject: [PATCH 5/5] remove leftover print --- content/system/house/house.gd | 2 -- 1 file changed, 2 deletions(-) diff --git a/content/system/house/house.gd b/content/system/house/house.gd index c1fd636..c02470c 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -37,8 +37,6 @@ func update_house(): var new_room = Store.house.rooms[index] create_room(new_room.name, 0) - print(Store.house.entities) - for entity_index in range(Store.house.entities.size()): var entity = Store.house.entities[entity_index]