add light model and brightness slider

This commit is contained in:
Nitwel 2023-11-12 17:36:23 +01:00
parent 79e9d37295
commit 0208905123
8 changed files with 163 additions and 19 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d9423ef5121871fe9f60a673f76728265d2618f318a14e73affb4257cb42f73d
size 3906893
oid sha256:991ebe1738a0621dd536436b99a7b5149d10e6b185008ec533eb2c5ca79fec0c
size 3087839

View File

@ -1,4 +1,3 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://bertj8bp8b5l1"]
[resource]
albedo_color = Color(0.286275, 0.309804, 0.439216, 1)
version https://git-lfs.github.com/spec/v1
oid sha256:55d5f30db336a8f8f7633743c23e41077d5c1a1b900c475a6d3811746eba3d1b
size 141

View File

@ -2,22 +2,53 @@ extends StaticBody3D
@export var entity_id = "switch.plug_printer_2"
@onready var sprite: AnimatedSprite3D = $Icon
@onready var animation: AnimationPlayer = $AnimationPlayer
@onready var shape = $CSGCombiner3D
@onready var rod_top = $RodTop
@onready var rod_bottom = $RodBottom
@onready var slider_knob = $Knob
var state = false
# Called when the node enters the scene tree for the first time.
func _ready():
var stateInfo = await HomeAdapters.adapter.get_state(entity_id)
if stateInfo["state"] == "on":
sprite.set_frame(0)
else:
sprite.set_frame(1)
set_state(stateInfo["state"] == "on")
await HomeAdapters.adapter.watch_state(entity_id, func(new_state):
if (new_state["state"] == "on") == state:
return
set_state(new_state["state"] == "on")
)
func set_state(state: bool):
self.state = state
if state:
animation.play_backwards("light")
else:
animation.play("light")
func _on_click(event):
HomeAdapters.adapter.set_state(entity_id, "off" if sprite.get_frame() == 0 else "on")
if sprite.get_frame() == 0:
sprite.set_frame(1)
if event.target == self:
HomeAdapters.adapter.set_state(entity_id, "on" if !state else "off")
set_state(!state)
else:
sprite.set_frame(0)
_on_clickable_on_click(event)
func _on_request_completed():
pass
func _on_clickable_on_click(event):
var click_pos: Vector3 = to_local(event.ray.get_collision_point())
var vec_bottom_to_top = rod_top.position - rod_bottom.position
var length_click = click_pos.y - rod_bottom.position.y
var length_total = vec_bottom_to_top.y
var ratio = length_click / length_total
var new_pos = rod_bottom.position.lerp(rod_top.position, ratio)
slider_knob.position = new_pos
HomeAdapters.adapter.set_state(entity_id, "on" if state else "off", {"brightness_pct": int(ratio * 100)})

View File

@ -1,12 +1,13 @@
[gd_scene load_steps=7 format=3 uid="uid://cw86rc42dv2d8"]
[gd_scene load_steps=14 format=3 uid="uid://cw86rc42dv2d8"]
[ext_resource type="Script" path="res://content/entities/light/light.gd" id="1_ykxy3"]
[ext_resource type="Texture2D" uid="uid://b72vsbcvqqxg7" path="res://assets/materials/swich_on.png" id="2_6gn2e"]
[ext_resource type="Texture2D" uid="uid://cvc0o6dsktnvl" path="res://assets/materials/switch_off.png" id="3_qlm62"]
[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"]
[sub_resource type="SphereShape3D" id="SphereShape3D_ukj14"]
radius = 0.1
radius = 0.06
[sub_resource type="SpriteFrames" id="SpriteFrames_ldpuo"]
animations = [{
@ -22,6 +23,69 @@ animations = [{
"speed": 5.0
}]
[sub_resource type="Animation" id="Animation_7o31s"]
resource_name = "light"
length = 0.3
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("CSGCombiner3D:material_override:albedo_color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.3),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 0.85098, 0, 1), Color(0.231373, 0.231373, 0.231373, 1)]
}
[sub_resource type="Animation" id="Animation_afofi"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("CSGCombiner3D:material_override:albedo_color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 0.85098, 0, 1)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Knob:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(0, 0.0492394, -0.0903599)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_8a76q"]
_data = {
"RESET": SubResource("Animation_afofi"),
"light": SubResource("Animation_7o31s")
}
[sub_resource type="CylinderMesh" id="CylinderMesh_j3pn3"]
top_radius = 0.002
bottom_radius = 0.002
height = 0.1
[sub_resource type="CylinderShape3D" id="CylinderShape3D_tysib"]
height = 0.1
radius = 0.006
[sub_resource type="CylinderMesh" id="CylinderMesh_s8215"]
top_radius = 0.004
bottom_radius = 0.004
height = 0.002
[node name="Light" type="StaticBody3D"]
script = ExtResource("1_ykxy3")
@ -29,9 +93,50 @@ script = ExtResource("1_ykxy3")
shape = SubResource("SphereShape3D_ukj14")
[node name="Icon" type="AnimatedSprite3D" parent="."]
visible = false
pixel_size = 0.0005
billboard = 1
sprite_frames = SubResource("SpriteFrames_ldpuo")
[node name="Movable" type="Node" parent="."]
script = ExtResource("4_4sfxb")
[node name="CSGCombiner3D" type="CSGCombiner3D" parent="."]
transform = Transform3D(1, 9.69949e-05, 0.000589194, -9.77749e-05, 0.999999, 0.00135802, -0.000589065, -0.00135808, 0.999999, 0, 0, 0)
material_override = ExtResource("5_50gph")
[node name="CSGSphere3D" type="CSGSphere3D" parent="CSGCombiner3D"]
radius = 0.05
radial_segments = 36
rings = 12
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="CSGCombiner3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0485739, 0)
radius = 0.02
height = 0.03
sides = 36
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_8a76q")
}
[node name="Rod" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.0903599)
[node name="MeshInstance3D" type="MeshInstance3D" parent="Rod"]
mesh = SubResource("CylinderMesh_j3pn3")
skeleton = NodePath("../..")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Rod"]
shape = SubResource("CylinderShape3D_tysib")
[node name="Knob" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0492394, -0.0903599)
mesh = SubResource("CylinderMesh_s8215")
[node name="RodBottom" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0501399, -0.090675)
[node name="RodTop" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0498752, -0.090942)

View File

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

View File

@ -5,6 +5,8 @@ var sky_passthrough = preload("res://assets/materials/sky_passthrough.material")
@onready var environment: WorldEnvironment = $WorldEnvironment
@onready var camera: XRCamera3D = $XROrigin3D/XRCamera3D
@onready var controller_left = $XROrigin3D/XRControllerLeft
@onready var controller_right = $XROrigin3D/XRControllerRight
@onready var house = $House
func _ready():
@ -26,7 +28,11 @@ func _process(delta):
camera_basis.x = camera_basis.x.normalized()
camera_basis.z = camera_basis.z.normalized()
camera.position += camera_basis * vector_key_mapping(KEY_D, KEY_A, KEY_S, KEY_W) * delta
var movement = camera_basis * vector_key_mapping(KEY_D, KEY_A, KEY_S, KEY_W) * delta
camera.position += movement
controller_left.position += movement
controller_right.position += movement
func vector_key_mapping(key_positive_x: int, key_negative_x: int, key_positive_y: int, key_negative_y: int):

View File

@ -81,4 +81,4 @@ shadow_enabled = true
xr_origin = NodePath("../XROrigin3D")
[node name="House" parent="." instance=ExtResource("8_qkrg7")]
transform = Transform3D(0.999999, -1.39634e-11, 0, 9.48053e-12, 1, 0, 0, 0, 1, -1.83323, 0.000545101, 0.477467)
transform = Transform3D(0.404247, 0.000180645, 0.914648, 0.00017221, 0.999999, -0.000273614, -0.914648, 0.00026812, 0.404247, -0.343479, 0.000110551, 1.91547)

View File

@ -113,7 +113,7 @@ func start_subscriptions():
if packet.event.c[entity]["+"].has("s"):
entities[entity]["state"] = packet.event.c[entity]["+"]["s"]
if packet.event.c[entity]["+"].has("a"):
entities[entity]["attributes"].merge(packet.event.c[entity]["+"]["a"])
entities[entity]["attributes"].merge(packet.event.c[entity]["+"]["a"], true)
entitiy_callbacks.call_key(entity, [entities[entity]])
)