add entity settings and color_wheel component

This commit is contained in:
Nitwel 2024-05-24 21:08:27 +02:00
parent ef9f82682e
commit 69258c3bd8
25 changed files with 603 additions and 219 deletions

View File

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

View File

@ -1,36 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://hy2f6is7qjyv"
path.s3tc="res://.godot/imported/canvas.png-aa470cb9edfe91c0a54e6c5fa29d4c26.s3tc.ctex"
path.etc2="res://.godot/imported/canvas.png-aa470cb9edfe91c0a54e6c5fa29d4c26.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://assets/canvas.png"
dest_files=["res://.godot/imported/canvas.png-aa470cb9edfe91c0a54e6c5fa29d4c26.s3tc.ctex", "res://.godot/imported/canvas.png-aa470cb9edfe91c0a54e6c5fa29d4c26.etc2.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
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=0

View File

@ -11,3 +11,6 @@ func _ready():
movable.on_moved.connect(func():
App.house.save_all_entities()
)
func get_options():
return {}

View File

@ -1,7 +1,6 @@
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)
@ -9,17 +8,24 @@ const color_wheel_img := preload ("res://assets/canvas.png")
@onready var lightbulb = $Lightbulb
@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
@onready var snap_sound = $SnapSound
@onready var settings = $Settings
@onready var movable = $Movable
@onready var camera_follower = $CameraFollower
var active = R.state(false)
var brightness = R.state(0) # 0-255
var color = R.state(color_on)
var color_supported = false
var show_color_wheel = R.state(true)
var color_wheel_supported = R.state(false)
var show_brightness = R.state(true)
var show_modes = R.state(true)
var modes_supported = R.state(false)
var show_settings = R.state(false)
# Called when the node enters the scene tree for the first time.
func _ready():
@ -32,7 +38,41 @@ func _ready():
var stateInfo = await HomeApi.get_state(entity_id)
set_state(stateInfo)
remove_child(settings)
R.effect(func(_arg):
if show_settings.value:
add_child(settings)
elif settings.is_inside_tree():
remove_child(settings)
camera_follower.reset()
App.house.save_all_entities()
)
R.effect(func(_arg):
if show_color_wheel.value&&color_wheel_supported.value:
add_child(color_wheel)
else:
remove_child(color_wheel)
)
R.effect(func(_arg):
if show_brightness.value:
add_child(slider)
else:
remove_child(slider)
)
R.effect(func(_arg):
if show_modes.value&&modes_supported.value:
add_child(modes)
else:
remove_child(modes)
)
if stateInfo.has("attributes")&&stateInfo["attributes"].has("effect_list")&&stateInfo["attributes"]["effect_list"].size() > 0:
modes_supported.value = true
if stateInfo["attributes"].has("effect")&&stateInfo["attributes"]["effect"] != null:
mode_label.text = stateInfo["attributes"]["effect"]
@ -59,36 +99,27 @@ func _ready():
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())
color_wheel_supported.value = true
var delta=Vector2(target_point.x, target_point.z) * (1.0 / 0.08)
if delta.length() > 1:
delta=delta.normalized()
await HomeApi.watch_state(entity_id, func(new_state):
set_state(new_state)
)
var picked_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=picked_color
color_puck.position=Vector3(target_point.x, color_puck.position.y, target_point.z)
color_wheel.on_color_changed.connect(func(new_color):
if color.value == new_color:
return
var attributes={
"rgb_color": [int(picked_color.r * 255), int(picked_color.g * 255), int(picked_color.b * 255)],
"rgb_color": [int(new_color.r * 255), int(new_color.g * 255), int(new_color.b * 255)],
}
snap_sound.play()
HomeApi.set_state(entity_id, "on", attributes)
)
color_supported = true
else:
remove_child(color_wheel)
print("set color", new_color, attributes["rgb_color"])
await HomeApi.watch_state(entity_id, func(new_state):
set_state(new_state)
HomeApi.set_state(entity_id, "on", attributes)
)
slider.on_value_changed.connect(func(new_value):
@ -110,6 +141,8 @@ func set_state(stateInfo):
if attributes.has("rgb_color")&&attributes["rgb_color"] != null:
color.value = Color(attributes["rgb_color"][0] / 255.0, attributes["rgb_color"][1] / 255.0, attributes["rgb_color"][2] / 255.0, 1)
print("got color", color.value, attributes["rgb_color"])
color_wheel.color = color.value
var tween = create_tween()
@ -117,9 +150,9 @@ func set_state(stateInfo):
if active.value:
if brightness.value == null:
target_color = color.value if color_supported else color_on
target_color = color.value if show_color_wheel.value else color_on
else:
target_color = color_off.lerp(color.value if color_supported else color_on, brightness.value / 255.0)
target_color = color_off.lerp(color.value if show_color_wheel.value else color_on, brightness.value / 255.0)
icon_color.value = target_color
tween.tween_property(lightbulb, "material_override:albedo_color", target_color, 0.3)
@ -134,3 +167,22 @@ func quick_action():
func _toggle():
HomeApi.set_state(entity_id, "off" if active.value else "on")
func toggle_settings():
if show_settings.value == false:
show_settings.value = true
camera_follower.enabled = true
else:
show_settings.value = false
func get_options():
return {
"color_wheel": show_color_wheel.value,
"brightness": show_brightness.value,
"modes": show_modes.value,
}
func set_options(options):
show_color_wheel.value = options["color_wheel"]
show_brightness.value = options["brightness"]
show_modes.value = options["modes"]

View File

@ -1,35 +1,18 @@
[gd_scene load_steps=15 format=3 uid="uid://cw86rc42dv2d8"]
[gd_scene load_steps=11 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="PackedScene" uid="uid://chrjqr4l7atrc" path="res://content/ui/components/color_wheel/color_wheel.tscn" id="5_qj75k"]
[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="AudioStream" uid="uid://du7ur0lu28cvn" path="res://assets/sound/finger-snap.mp3" id="8_3togy"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="8_nhcff"]
[ext_resource type="Script" path="res://content/functions/camera_follower.gd" id="9_a7u7m"]
[ext_resource type="PackedScene" uid="uid://de34yde00ngkv" path="res://content/entities/light/settings.tscn" id="10_su84f"]
[sub_resource type="SphereShape3D" id="SphereShape3D_ukj14"]
radius = 0.05
[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"]
resource_local_to_scene = true
[sub_resource type="CylinderMesh" id="CylinderMesh_x68ys"]
top_radius = 0.01
bottom_radius = 0.01
height = 0.005
[node name="Light" type="StaticBody3D"]
collision_mask = 0
script = ExtResource("1_ykxy3")
@ -62,31 +45,10 @@ max = 100.0
value = 100.0
step = 1.0
[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="Sprite3D" type="Sprite3D" parent="ColorWheel"]
transform = Transform3D(0.15, 0, 0, 0, -6.55671e-09, -0.15, 0, 0.15, -6.55671e-09, 0, 0.004, 0)
flip_v = true
pixel_size = 0.001
texture = ExtResource("7_ximu1")
[node name="MeshInstance3D" type="MeshInstance3D" parent="ColorWheel"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.002, 0)
material_override = SubResource("StandardMaterial3D_7p762")
mesh = SubResource("CylinderMesh_c10un")
skeleton = NodePath("../..")
[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")
[node name="ColorWheel" parent="." instance=ExtResource("5_qj75k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.15, 0, 0)
color = Color(0, 0.616667, 1, 1)
size = Vector3(0.15, 0.2, 0.01)
[node name="Modes" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.11, 0)
@ -110,3 +72,15 @@ horizontal_alignment = 0
[node name="SnapSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("8_3togy")
volume_db = -20.0
[node name="CameraFollower" type="Node" parent="." node_paths=PackedStringArray("focus_point")]
script = ExtResource("9_a7u7m")
enabled = false
focus_point = NodePath("../FocusPoint")
[node name="FocusPoint" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.29, 0, 0)
gizmo_extents = 0.1
[node name="Settings" parent="." instance=ExtResource("10_su84f")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.29, 0, 0)

View File

@ -0,0 +1,36 @@
extends Node3D
const Light = preload ("./light.gd")
@onready var close_button: Button3D = $Close
@onready var id_input: Input3D = $IDInput
@onready var color_wheel_button: Button3D = $ColorWheelButton
@onready var brightness_button: Button3D = $BrightnessButton
@onready var modes_button: Button3D = $ModesButton
var light: Light
func _ready():
light = get_parent()
close_button.on_button_up.connect(func():
light.show_settings.value=false
)
id_input.text = light.entity_id
R.effect(func(_arg):
color_wheel_button.label="check" if light.show_color_wheel.value else "close"
)
R.effect(func(_arg):
brightness_button.label="check" if light.show_brightness.value else "close"
)
R.effect(func(_arg):
modes_button.label="check" if light.show_modes.value else "close"
)
R.bind(color_wheel_button, "active", light.show_color_wheel, color_wheel_button.on_toggled)
R.bind(brightness_button, "active", light.show_brightness, brightness_button.on_toggled)
R.bind(modes_button, "active", light.show_modes, modes_button.on_toggled)

View File

@ -0,0 +1,112 @@
[gd_scene load_steps=8 format=3 uid="uid://de34yde00ngkv"]
[ext_resource type="PackedScene" uid="uid://dnam3fe36gg62" path="res://content/ui/components/panel/panel.tscn" id="1_78ups"]
[ext_resource type="Script" path="res://content/entities/light/settings.gd" id="1_gw2gi"]
[ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="2_m4moa"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="3_2gpr3"]
[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="4_upyp3"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_vmdy0"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("2_m4moa")
shader_parameter/color = Color(1, 1, 1, 0.3)
shader_parameter/border_color = Color(1, 1, 1, 1)
shader_parameter/edge_color = Color(0, 0, 0, 1)
shader_parameter/size = Vector2(7.5, 6.25)
shader_parameter/border_size = 0.01
shader_parameter/border_fade_in = 0.05
shader_parameter/border_fade_out = 0.0
shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_qu5ku"]
size = Vector2(0.3, 0.25)
[node name="Settings" type="Node3D"]
script = ExtResource("1_gw2gi")
[node name="Panel" parent="." instance=ExtResource("1_78ups")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -7.45058e-09, 0)
material_override = SubResource("ShaderMaterial_vmdy0")
mesh = SubResource("QuadMesh_qu5ku")
skeleton = NodePath("../..")
size = Vector2(0.3, 0.25)
[node name="Close" parent="." instance=ExtResource("3_2gpr3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.1, 0)
label = "close"
icon = true
[node name="Name" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.14, 0.1, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Light Settings"
font_size = 24
outline_size = 0
horizontal_alignment = 0
[node name="IDLabel" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.14, 0.06, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "ID:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="IDInput" parent="." instance=ExtResource("4_upyp3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0.06, 0)
disabled = true
[node name="ColorWheelLabel" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.14, 0.02, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Color Wheel:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="ColorWheelButton" parent="." instance=ExtResource("3_2gpr3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00999999, 0.02, 0)
label = "check"
icon = true
toggleable = true
[node name="BrightnessLabel" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.14, -0.03, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Brightness:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="BrightnessButton" parent="." instance=ExtResource("3_2gpr3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00999999, -0.03, 0)
label = "check"
icon = true
toggleable = true
[node name="ModesLabel" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.14, -0.08, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Modes:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="ModesButton" parent="." instance=ExtResource("3_2gpr3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00999999, -0.08, 0)
label = "check"
icon = true
toggleable = true

View File

@ -0,0 +1,55 @@
extends Function
class_name CameraFollower
@export var enabled = true:
set(value):
enabled = value
if enabled:
_update_initial_transform()
EventSystem.on_slow_tick.connect(_slow_tick)
else:
EventSystem.on_slow_tick.disconnect(_slow_tick)
@export var focus_point: Node3D = null
var next_new_transform = null
var initial_transform = null
func _ready():
next_new_transform = get_parent().global_transform
_update_initial_transform()
func _update_initial_transform():
if get_parent() == null||get_parent().is_inside_tree() == false:
return
initial_transform = get_parent().global_transform
func reset():
enabled = false
if initial_transform != null:
get_parent().global_transform = initial_transform
func reset_animated():
enabled = false
if initial_transform == null:
var tween = create_tween()
tween.set_trans(Tween.TransitionType.TRANS_QUAD)
tween.tween_property(get_parent(), "global_transform", initial_transform, 0.6)
func _slow_tick(delta):
if get_parent().is_inside_tree() == false:
return
var new_transform = App.camera.global_transform.translated_local(Vector3(0, 0, -0.5))
if focus_point != null:
new_transform = new_transform * (get_parent().global_transform.affine_inverse() * focus_point.global_transform).affine_inverse()
if next_new_transform.origin.distance_to(new_transform.origin) > 0.2:
next_new_transform = new_transform
var tween = create_tween()
tween.set_parallel(true)
tween.set_trans(Tween.TransitionType.TRANS_QUAD)
tween.tween_property(get_parent(), "global_transform", new_transform, 0.6)

View File

@ -0,0 +1,12 @@
extends Function
class_name FacingCamera
@export var enabled = true
@export var upright = true
func _process(_delta):
if enabled == false||get_parent().is_inside_tree() == false:
return
var basis = Basis.looking_at( - App.camera.global_transform.basis.z, Vector3.UP if upright else App.camera.global_transform.basis.y)
get_parent().global_transform.basis = basis

View File

@ -25,11 +25,20 @@ var initial_up = Vector3()
var initial_transform = Transform3D()
var distances = Vector2()
# For Resetting
var initial_global_transform = Transform3D()
func _process(delta):
if get_tree().debug_collisions_hint&&initiator2 != null:
DebugDraw3D.draw_line(initial_position, initial_position + initial_direction, Color(1, 0, 0))
DebugDraw3D.draw_line(initial_position, initial_position + initial_up, Color(0, 1, 0))
func reset():
get_parent().global_transform = initial_global_transform
initiator = null
initiator2 = null
on_moved.emit()
func _on_grab_down(event: EventPointer):
if disabled:
return
@ -57,6 +66,7 @@ func _on_grab_down(event: EventPointer):
initiator = event.initiator
_update_relative_transform()
initial_global_transform = get_parent().global_transform
if lock_rotation:
initial_point = get_parent().to_local(event.ray.get_collision_point())

View File

@ -45,9 +45,6 @@ transform = Transform3D(0.967043, 0.24582, -0.0663439, -0.0663439, 0.494837, 0.8
[node name="MiddleTip" parent="XROrigin3D/XRControllerLeft" index="6"]
transform = Transform3D(0.98042, 0.196912, 0.00149799, 0.001498, -0.015065, 0.999885, 0.196912, -0.980305, -0.0150651, -0.00327212, -0.00771427, -0.176318)
[node name="Palm" parent="XROrigin3D/XRControllerLeft" index="7"]
transform = Transform3D(1, 3.12364e-06, -3.13861e-06, -3.12371e-06, 1, -1.97886e-05, 3.13854e-06, 1.97889e-05, 1, 0.0307807, -0.0419721, -0.0399505)
[node name="XRControllerRight" parent="XROrigin3D" instance=ExtResource("7_0b3tc")]
unique_name_in_owner = true
transform = Transform3D(0.999999, -1.39635e-11, 0, 1.31553e-10, 1, 0, 0, 0, 1, 0.336726, 0.575093, -0.437942)

View File

@ -6,6 +6,7 @@ const Finger = preload ("res://lib/utils/touch/finger.gd")
const Touch = preload ("res://lib/utils/touch/touch.gd")
const Collide = preload ("res://lib/utils/touch/collide.gd")
const Miniature = preload ("res://content/system/miniature/miniature.gd")
const Entity = preload ("res://content/entities/entity.gd")
@onready var hand = $hand_l
@onready var hand_mesh = $hand_l/Armature/Skeleton3D/mesh_Hand_L
@ -22,6 +23,8 @@ const Miniature = preload ("res://content/system/miniature/miniature.gd")
@onready var palm = $Palm
@onready var ray: RayCast3D = $Raycast
@onready var quick_actions = $Palm/QuickActions
@onready var entity_settings = $Palm/Settings
@onready var entity_settings_button = $Palm/Settings/SettingsButton
@export var show_grid = false:
set(value):
@ -46,6 +49,8 @@ var grip_distance = 0.02
var pressed = false
var grabbed = false
var moving_entity = null
func _ready():
button_pressed.connect(func(action_name):
EventSystem.emit_action(action_name, true, false)
@ -57,6 +62,35 @@ func _ready():
_setup_hand()
palm.remove_child(entity_settings)
EventSystem.on_ray_enter.connect(func(event: EventPointer):
if event.initiator.is_right() == true: return
if moving_entity != null: return
var entity=_get_entity(event.target)
if entity != null&&entity.has_method("toggle_settings")&&entity_settings.is_inside_tree() == false:
palm.add_child(entity_settings)
moving_entity=entity
)
EventSystem.on_ray_leave.connect(func(event: EventPointer):
if event.initiator.is_right() == true: return
var entity=_get_entity(event.target)
if moving_entity != null&&moving_entity == entity&&entity_settings.is_inside_tree():
palm.remove_child(entity_settings)
moving_entity=null
)
entity_settings_button.on_button_up.connect(func():
if moving_entity == null:
return
moving_entity.toggle_settings()
)
func _process(_delta):
if !hand_active:
if quick_actions.is_inside_tree(): palm.remove_child(quick_actions)
@ -128,3 +162,12 @@ func _setup_hand():
pointer = Pointer.new(initiator, ray)
add_child(pointer)
func _get_entity(node: Node):
if node is Entity:
return node
if node.get_parent() == null:
return null
return _get_entity(node.get_parent())

View File

@ -115,6 +115,14 @@ transform = Transform3D(1, 1.73472e-18, 0, 0, 1, 0, 0, 0, 1, 0.0600001, -5.68873
label = "humidity_mid"
icon = true
[node name="Settings" type="Node3D" parent="Palm"]
transform = Transform3D(-4.37114e-08, -1, 0, -4.37114e-08, 0, 1, -1, 4.37114e-08, -4.37114e-08, -0.02, 0.09, 0.09)
[node name="SettingsButton" parent="Palm/Settings" instance=ExtResource("6_x5vuc")]
transform = Transform3D(0.499999, 0, 0, 0, 0.499999, 0, 0, 0, 0.5, 0, 0, 0)
label = "settings"
icon = true
[node name="TrashBin" parent="." instance=ExtResource("7_vigb6")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.109418, -0.126353, 0.0278937)

View File

@ -48,6 +48,9 @@ func update_house():
entity_instance.global_rotation = entity.rotation
entity_instance.scale = Vector3(entity.scale, entity.scale, entity.scale) if entity.has("scale") else Vector3(1, 1, 1)
if entity.has("options")&&entity_instance.has_method("set_options"):
entity_instance.set_options(entity.options)
loaded.value = true
func create_room(room_name: String) -> RoomType:
@ -243,12 +246,15 @@ func save_all_entities():
"position": entity.global_position,
"rotation": entity.global_rotation,
"scale": entity.scale.x,
"room": String(room.name),
"room": String(room.name)
}
if entity.has_method("get_interface"):
entity_data["interface"] = entity.get_interface()
if entity.has_method("get_options"):
entity_data["options"] = entity.get_options()
Store.house.state.entities.append(entity_data)
Store.house.state.entities = Store.house.state.entities

View File

@ -79,5 +79,5 @@ void fragment() {
//ALBEDO = mix(edge_color.rgb * edge_color.a, ALBEDO, a);
ROUGHNESS = roughness;
//SPECULAR = 0.5 * inversesqrt(ALPHA);
DEPTH = FRAGCOORD.z - 0.00001;
DEPTH = FRAGCOORD.z + 0.0001;
}

View File

@ -17,8 +17,6 @@ const ECHO_WAIT_REPEAT = 0.1
@onready var label_node: Label3D = $Body/Label
@onready var finger_area: Area3D = $FingerArea
@onready var finger_area_collision: CollisionShape3D = $FingerArea/CollisionShape3D
@onready var touch_collision: CollisionShape3D = $TouchBody/CollisionShape3D
@onready var touch: StaticBody3D = $TouchBody
@onready var click_sound = $ClickSound
@export var focusable: bool = true:
@ -71,12 +69,11 @@ const ECHO_WAIT_REPEAT = 0.1
var active: bool = false:
set(value):
if active == value:
return
if active != value:
on_toggled.emit(value)
active = value
if !is_inside_tree(): return
if !is_node_ready(): return
panel.active = active
update_animation(1.0 if active else 0.0)
@ -202,24 +199,15 @@ func _on_touch_leave(event: EventTouch):
on_button_up.emit()
func _touch_change(event: EventTouch):
var click_pos = to_local(event.fingers[0].area.global_position)
var pos = Vector3(0, 1, 0)
for finger in event.fingers:
var finger_pos = to_local(finger.area.global_position)
if pos.z > finger_pos.z:
pos = finger_pos
var button_height = 0.2
var button_center = 0.1
var percent = clamp((button_center + button_height / 2 - pos.z) / (button_height / 2), 0, 1)
var percent = (click_pos.z - size.z / 2) / (size.z / 2)
percent = clamp(percent, 0.0, 1.0)
update_animation(percent)
func _update():
body.position = Vector3(0, 0, size.z / 2)
finger_area.position = Vector3(0, 0, -0.015)
touch.position = Vector3(0, 0, size.z / 2)
panel.size = Vector2(size.x, size.y)
panel.position = Vector3(0, 0, size.z / 2)
@ -227,4 +215,5 @@ func _update():
label_node.width = size.x / label_node.pixel_size
label_node.position = Vector3(0, 0, size.z / 2 + 0.001)
finger_area_collision.shape.size = Vector3(size.x, size.y, 0.03)
finger_area.position = Vector3(0, 0, size.z * 0.75)
finger_area_collision.shape.size = Vector3(size.x, size.y, size.z / 2)

View File

@ -5,7 +5,7 @@
[ext_resource type="Script" path="res://content/ui/components/panel/panel.gd" id="3_skm86"]
[ext_resource type="AudioStream" uid="uid://c1yu80uj3fsn7" path="res://assets/sound/click.wav" id="4_51sb0"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_826v7"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_syops"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("2_db5by")
@ -20,7 +20,7 @@ shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_02501"]
[sub_resource type="QuadMesh" id="QuadMesh_btecp"]
size = Vector2(0.04, 0.04)
[sub_resource type="BoxShape3D" id="BoxShape3D_xwopm"]
@ -29,7 +29,7 @@ size = Vector3(0.04, 0.04, 0.01)
[sub_resource type="BoxShape3D" id="BoxShape3D_bqjii"]
resource_local_to_scene = true
size = Vector3(0.04, 0.04, 0.03)
size = Vector3(0.04, 0.04, 0.005)
[node name="Button" type="Node3D" groups=["ui_focus"]]
script = ExtResource("1_74x7g")
@ -38,13 +38,13 @@ size = Vector3(0.04, 0.04, 0.01)
[node name="Body" type="StaticBody3D" parent="." groups=["ui_focus_skip"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.005)
collision_layer = 2
collision_layer = 6
collision_mask = 0
[node name="Panel3D" type="MeshInstance3D" parent="Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.005)
material_override = SubResource("ShaderMaterial_826v7")
mesh = SubResource("QuadMesh_02501")
material_override = SubResource("ShaderMaterial_syops")
mesh = SubResource("QuadMesh_btecp")
skeleton = NodePath("../..")
script = ExtResource("3_skm86")
size = Vector2(0.04, 0.04)
@ -64,7 +64,7 @@ autowrap_mode = 3
width = 40.0
[node name="FingerArea" type="Area3D" parent="." groups=["ui_focus_skip"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.015)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.0075)
collision_layer = 4
collision_mask = 0
monitoring = false
@ -72,14 +72,6 @@ monitoring = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="FingerArea"]
shape = SubResource("BoxShape3D_bqjii")
[node name="TouchBody" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.005)
collision_layer = 4
collision_mask = 0
[node name="CollisionShape3D" type="CollisionShape3D" parent="TouchBody"]
shape = SubResource("BoxShape3D_xwopm")
[node name="ClickSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("4_51sb0")
volume_db = -18.0

View File

@ -0,0 +1,111 @@
@tool
extends Container3D
class_name ColorPicker3D
signal on_color_changed(color: Color)
@onready var puck = $Puck
@onready var touch_area = $TouchArea
@onready var touch_area_collision = $TouchArea/CollisionShape3D
@onready var collision = $Body/CollisionShape3D
@onready var sprite: Sprite3D = $Body/Sprite3D
var move_plane: Plane
@export var color: Color = Color(1, 1, 1, 1):
set(value):
if color != value:
on_color_changed.emit(value)
color = value
if is_node_ready() == false: return
_update_puck()
func _ready():
Update.props(self, ["color"])
move_plane = Plane(Vector3.BACK, Vector3(0, 0, size.z))
_update()
func _update_puck():
var coords = _color_to_coords(color) * (size.x / 2.0)
var tween = create_tween()
tween.set_trans(Tween.TRANS_BOUNCE)
tween.set_parallel(true)
tween.tween_property(puck, "position", Vector3(coords.x, coords.y, size.z), 0.2)
tween.tween_property(puck.material_override, "albedo_color", color, 0.2)
func _on_press_down(event: EventPointer):
_handle_press(event)
func _on_press_move(event: EventPointer):
_handle_press(event)
func _on_touch_enter(event: EventTouch):
_handle_touch(event)
func _handle_press(event: EventPointer):
var ray_pos = event.ray.global_position
var ray_dir = -event.ray.global_transform.basis.z
var local_pos = to_local(ray_pos)
var local_dir = global_transform.basis.inverse() * ray_dir
var click_pos = move_plane.intersects_ray(local_pos, local_dir)
if click_pos == null:
return
color = _coords_to_color(Vector2(click_pos.x, click_pos.y) / (size.x / 2.0))
func _handle_touch(event: EventTouch):
var click_pos = to_local(event.fingers[0].area.global_position)
if click_pos == null:
return
color = _coords_to_color(Vector2(click_pos.x, click_pos.y) / (size.x / 2.0))
func _coords_to_color(coords: Vector2) -> Color:
if coords.length() > 1:
coords = coords.normalized()
var hue = (atan2(coords.y, coords.x) + PI) / (2 * PI)
var saturation = coords.length()
var value = 1.0
return Color.from_hsv(hue, saturation, value)
func _color_to_coords(color: Color) -> Vector2:
var hue = color.h * 2 * PI - PI
var saturation = color.s
var coords = Vector2(cos(hue), sin(hue)) * saturation
return coords
func _generate_color_wheel():
var image = Image.create(1000, 1000, true, Image.FORMAT_RGBA8)
for x in range(1000):
for y in range(1000):
var delta = Vector2(x, y) / 1000 * 2 - Vector2(1, 1)
if delta.length() <= 1:
image.set_pixel(x, y, _coords_to_color(delta))
ResourceSaver.save(ImageTexture.create_from_image(image), "res://content/ui/components/color_wheel/color_wheel.tres")
func _update():
sprite.pixel_size = size.x / 1000
collision.shape.height = size.z
collision.shape.radius = size.x / 2
collision.position.z = size.z / 2
sprite.position.z = size.z
puck.position.z = size.z
touch_area_collision.shape.height = size.z + 0.02
touch_area_collision.shape.radius = size.x / 2
touch_area_collision.position.z = (size.z + 0.02) / 2

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -268,7 +268,6 @@ script = ExtResource("6_7rntr")
tabs = NodePath("../Tabs")
[node name="ViewMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("8_71pkg")]
visible = false
[node name="EditMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("4_r2raj")]
visible = false

View File

@ -2,10 +2,8 @@ extends Node3D
@onready var getting_started_button = $GettingStartedButton
@onready var close_button = $CloseButton
var next_new_position = null
func _ready():
next_new_position = global_position
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
@ -21,23 +19,7 @@ func _ready():
close()
)
EventSystem.on_slow_tick.connect(_slow_tick)
func close():
Store.settings.state.onboarding_complete = true
Store.settings.save_local()
queue_free()
func _slow_tick(delta):
var new_position = App.camera.global_position + App.camera.global_transform.basis.z * - 0.5
if next_new_position.distance_to(new_position) > 0.2:
next_new_position = new_position
var new_direction = Basis.looking_at((App.camera.global_position - new_position) * - 1)
var tween = create_tween()
tween.set_parallel(true)
tween.set_trans(Tween.TransitionType.TRANS_QUAD)
tween.tween_property(self, "global_position", new_position, 0.6)
tween.tween_property(self, "global_transform:basis", new_direction, 0.6)

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=7 format=3 uid="uid://bhyddd1f0ry1x"]
[gd_scene load_steps=8 format=3 uid="uid://bhyddd1f0ry1x"]
[ext_resource type="Script" path="res://content/ui/onboarding/onboarding.gd" id="1_k4yvw"]
[ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="2_87aan"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="3_hlpow"]
[ext_resource type="Script" path="res://content/functions/camera_follower.gd" id="4_u1o74"]
[sub_resource type="BoxShape3D" id="BoxShape3D_nfwtf"]
size = Vector3(0.5, 0.3, 0.01)
@ -86,3 +87,7 @@ outline_size = 0
horizontal_alignment = 2
autowrap_mode = 3
width = 470.0
[node name="CameraFollower" type="Node" parent="."]
script = ExtResource("4_u1o74")
enabled = null

View File

@ -1 +0,0 @@
extends Node3D

View File

@ -1,42 +0,0 @@
[gd_scene load_steps=6 format=3 uid="uid://cmtp5kof0ah2b"]
[ext_resource type="Material" uid="uid://bnwimm214q67g" path="res://assets/materials/sec-500.material" id="1_mxydb"]
[ext_resource type="Script" path="res://content/ui/sub_menu/sub_menu.gd" id="1_xpjuw"]
[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="2_64uue"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ti5t2"]
[sub_resource type="BoxMesh" id="BoxMesh_aisgf"]
material = SubResource("StandardMaterial3D_ti5t2")
size = Vector3(0.3, 0.01, 0.3)
[node name="SubMenu" type="Node3D"]
script = ExtResource("1_xpjuw")
[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("1_mxydb")
mesh = SubResource("BoxMesh_aisgf")
skeleton = NodePath("../..")
[node name="Content" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.006, 0)
[node name="Label3D" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.01, 0, 0.02)
pixel_size = 0.001
text = "Entity Name"
font_size = 24
outline_size = 0
horizontal_alignment = 0
[node name="Label3D2" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.01, 0, 0.06)
pixel_size = 0.001
text = "ID:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="Input" parent="Content" instance=ExtResource("2_64uue")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0, 0.06)