add color picker

This commit is contained in:
Nitwel 2024-01-28 17:13:32 +01:00
parent 04f00fd262
commit 0f824b99ef
5 changed files with 108 additions and 2 deletions

3
assets/canvas.png Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f523eb87489026aa87814b63b31e0ce83ca91a0729ef7d93079e39a67e348fb5
size 237647

34
assets/canvas.png.import Normal file
View File

@ -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

View File

@ -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

View File

@ -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")

View File

@ -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