fixes to hands and buttons

This commit is contained in:
Nitwel 2024-03-07 14:21:31 +01:00
parent 1a47406e9f
commit 8bf3c5ce3d
10 changed files with 61 additions and 71 deletions

View File

@ -1,6 +1,6 @@
extends Entity extends Entity
const Entity = preload("../entity.gd") const Entity = preload ("../entity.gd")
@export var image_width = 0.15 @export var image_width = 0.15
@ -16,7 +16,6 @@ const Entity = preload("../entity.gd")
var playing = false var playing = false
var volume = 50 var volume = 50
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
super() super()
@ -45,12 +44,14 @@ func _ready():
slider.on_value_changed.connect(set_volume) slider.on_value_changed.connect(set_volume)
func set_volume(value): func set_volume(value):
volume = value volume = value
HomeApi.set_state(entity_id, "volume", {"volume_level": value / 100}) HomeApi.set_state(entity_id, "volume", {"volume_level": value / 100})
func set_state(stateInfo): func set_state(stateInfo):
if stateInfo == null:
return
var state = stateInfo["state"] var state = stateInfo["state"]
if state == "playing": if state == "playing":

View File

@ -53,7 +53,7 @@ transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0,
shape = SubResource("CapsuleShape3D_dopke") shape = SubResource("CapsuleShape3D_dopke")
[node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"] [node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928488, 0.0498668, 0.0560917, -0.112777) transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928487, 0.0498668, 0.0560917, -0.112777)
bone_name = "Thumb_Tip_L" bone_name = "Thumb_Tip_L"
bone_idx = 4 bone_idx = 4
use_external_skeleton = true use_external_skeleton = true
@ -63,7 +63,7 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D")
gizmo_extents = 0.02 gizmo_extents = 0.02
[node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"] [node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996577, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653568, 0.032112, 0.00654224, -0.171612) transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996576, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653567, 0.032112, 0.00654224, -0.171612)
bone_name = "Middle_Tip_L" bone_name = "Middle_Tip_L"
bone_idx = 14 bone_idx = 14
use_external_skeleton = true use_external_skeleton = true
@ -106,7 +106,7 @@ transform = Transform3D(1, 0, 4.7579e-13, 0, 1, 0, -1.34149e-12, 1.77636e-15, 1,
material_override = SubResource("StandardMaterial3D_n27ki") material_override = SubResource("StandardMaterial3D_n27ki")
[node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"] [node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"]
transform = Transform3D(0.19221, 0.669966, 0.717079, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345977, -0.164767, -0.0355401) transform = Transform3D(0.19221, 0.669966, 0.717078, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345978, -0.164767, -0.0355401)
bone_name = "Index_Tip_R" bone_name = "Index_Tip_R"
bone_idx = 9 bone_idx = 9
use_external_skeleton = true use_external_skeleton = true
@ -136,7 +136,7 @@ external_skeleton = NodePath("../right_hand/Armature/Skeleton3D")
gizmo_extents = 0.02 gizmo_extents = 0.02
[node name="MiddleTip" type="BoneAttachment3D" parent="XRHandRight"] [node name="MiddleTip" type="BoneAttachment3D" parent="XRHandRight"]
transform = Transform3D(0.0812011, 0.650531, 0.755126, -0.0155557, -0.756709, 0.653568, 0.996576, -0.0648169, -0.0513262, -0.032112, -0.171612, -0.00654216) transform = Transform3D(0.0812011, 0.650531, 0.755126, -0.0155557, -0.756708, 0.653568, 0.996576, -0.0648169, -0.0513262, -0.032112, -0.171612, -0.00654216)
bone_name = "Middle_Tip_R" bone_name = "Middle_Tip_R"
bone_idx = 14 bone_idx = 14
use_external_skeleton = true use_external_skeleton = true

View File

@ -4,6 +4,9 @@ class_name TouchBody3D
@export var plane = Plane.PLANE_XZ @export var plane = Plane.PLANE_XZ
func _ready(): func _ready():
set_collision_layer_value(1, false)
set_collision_layer_value(3, true)
var collisionShape = null var collisionShape = null
for child in get_children(): for child in get_children():

View File

@ -1,12 +1,11 @@
extends RoomState extends RoomState
const RoomState = preload("./room_state.gd") const RoomState = preload ("./room_state.gd")
func _on_enter(): func _on_enter():
var room_store = Store.house.get_room(room.name) var room_store = Store.house.get_room(room.name)
if room_store == null || room_store.corners.size() < 3: if room_store == null||room_store.corners.size() < 3:
return return
room.wall_mesh.visible = false room.wall_mesh.visible = false
@ -17,6 +16,8 @@ func _on_enter():
if room.wall_mesh.mesh == null: if room.wall_mesh.mesh == null:
return return
room.room_ceiling.position.y = room_store.height
var ceiling_shape = room.room_ceiling.get_node("CollisionShape3D") var ceiling_shape = room.room_ceiling.get_node("CollisionShape3D")
var floor_shape = room.room_floor.get_node("CollisionShape3D") var floor_shape = room.room_floor.get_node("CollisionShape3D")

View File

@ -6,7 +6,7 @@ class_name Button3D
signal on_button_down() signal on_button_down()
signal on_button_up() signal on_button_up()
const IconFont = preload("res://assets/icons/icons.tres") const IconFont = preload ("res://assets/icons/icons.tres")
@onready var label_node: Label3D = $Body/Label @onready var label_node: Label3D = $Body/Label
@onready var finger_area: Area3D = $FingerArea @onready var finger_area: Area3D = $FingerArea
@ -73,6 +73,7 @@ var active: bool = false:
update_animation() update_animation()
@onready var animation_player: AnimationPlayer = $AnimationPlayer @onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var console = get_node("/root/Main/Console")
func _ready(): func _ready():
if initial_active: if initial_active:
@ -81,9 +82,9 @@ func _ready():
func update_animation(): func update_animation():
var length = animation_player.get_animation("down").length var length = animation_player.get_animation("down").length
if active && animation_player.current_animation_position != length: if active&&animation_player.current_animation_position != length:
animation_player.play("down") animation_player.play("down")
elif !active && animation_player.current_animation_position != 0: elif !active&&animation_player.current_animation_position != 0:
animation_player.play_backwards("down") animation_player.play_backwards("down")
func _on_press_down(event): func _on_press_down(event):
@ -116,6 +117,9 @@ func _on_press_up(event):
on_button_up.emit() on_button_up.emit()
func _on_touch_enter(event: EventTouch): func _on_touch_enter(event: EventTouch):
if event.target != finger_area:
return
animation_player.stop() animation_player.stop()
animation_player.speed_scale = 0 animation_player.speed_scale = 0
animation_player.current_animation = "down" animation_player.current_animation = "down"
@ -136,7 +140,6 @@ func _on_touch_leave(_event: EventTouch):
else: else:
on_button_down.emit() on_button_down.emit()
func _touch_change(event: EventTouch): func _touch_change(event: EventTouch):
if disabled: if disabled:
event.bubbling = false event.bubbling = false
@ -148,14 +151,14 @@ func _touch_change(event: EventTouch):
if pos.y > finger_pos.y: if pos.y > finger_pos.y:
pos = finger_pos pos = finger_pos
var button_height = finger_area.get_node("CollisionShape3D").shape.size.y var button_height = 0.2
var button_center = finger_area.position.y var button_center = 0.1
var percent = clamp((button_center + button_height / 2 - pos.y) / (button_height / 2), 0, 1) var percent = clamp((button_center + button_height / 2 - pos.y) / (button_height / 2), 0, 1)
if !active && percent < 1: if !active&&percent < 1:
on_button_down.emit() on_button_down.emit()
elif active && percent >= 1: elif active&&percent >= 1:
on_button_up.emit() on_button_up.emit()
animation_player.seek(percent * animation_player.current_animation_length, true) animation_player.seek(percent * animation_player.current_animation_length, true)
@ -164,4 +167,3 @@ func _touch_change(event: EventTouch):
return return
active = percent < 1 active = percent < 1

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=9 format=3 uid="uid://bsjqdvkt0u87c"] [gd_scene load_steps=11 format=3 uid="uid://bsjqdvkt0u87c"]
[ext_resource type="Script" path="res://content/ui/components/button/button.gd" id="1_74x7g"] [ext_resource type="Script" path="res://content/ui/components/button/button.gd" id="1_74x7g"]
[ext_resource type="ArrayMesh" uid="uid://iv4lk77axlk4" path="res://assets/immersive_home/button.obj" id="2_cve3l"] [ext_resource type="ArrayMesh" uid="uid://iv4lk77axlk4" path="res://assets/immersive_home/button.obj" id="2_cve3l"]
[ext_resource type="Material" uid="uid://bujy3egn1oqac" path="res://assets/materials/pri-500.material" id="2_wx7av"] [ext_resource type="Material" uid="uid://bujy3egn1oqac" path="res://assets/materials/pri-500.material" id="2_wx7av"]
[ext_resource type="Script" path="res://content/system/hands/touch_area.gd" id="4_b27lx"]
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_o4j7g"] [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_o4j7g"]
points = PackedVector3Array(-0.025, -0.01, -0.025, -0.025, 0.01, -0.025, 0.025, -0.01, -0.025, -0.025, -0.01, 0.025, -0.025, 0.01, 0.025, 0.025, 0.01, -0.025, 0.025, -0.01, 0.025, 0.025, 0.01, 0.025) points = PackedVector3Array(-0.025, -0.01, -0.025, -0.025, 0.01, -0.025, 0.025, -0.01, -0.025, -0.025, -0.01, 0.025, -0.025, 0.01, 0.025, 0.025, 0.01, -0.025, 0.025, -0.01, 0.025, 0.025, 0.01, 0.025)
@ -66,7 +67,10 @@ _data = {
} }
[sub_resource type="BoxShape3D" id="BoxShape3D_bqjii"] [sub_resource type="BoxShape3D" id="BoxShape3D_bqjii"]
size = Vector3(0.0501598, 0.0195937, 0.0501598) size = Vector3(0.0501598, 0.0390937, 0.0501598)
[sub_resource type="BoxShape3D" id="BoxShape3D_dfbn3"]
size = Vector3(0.05, 0.029126, 0.05)
[node name="Button" type="Node3D" groups=["ui_focus"]] [node name="Button" type="Node3D" groups=["ui_focus"]]
script = ExtResource("1_74x7g") script = ExtResource("1_74x7g")
@ -107,4 +111,12 @@ collision_mask = 0
monitoring = false monitoring = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="FingerArea"] [node name="CollisionShape3D" type="CollisionShape3D" parent="FingerArea"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.00975001, 0)
shape = SubResource("BoxShape3D_bqjii") shape = SubResource("BoxShape3D_bqjii")
[node name="TouchBody3D" type="Area3D" parent="."]
script = ExtResource("4_b27lx")
[node name="CollisionShape3D" type="CollisionShape3D" parent="TouchBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.00453955, 0)
shape = SubResource("BoxShape3D_dfbn3")

View File

@ -14,10 +14,10 @@
[ext_resource type="PackedScene" uid="uid://c6r4higceibif" path="res://content/ui/menu/settings/settings_menu.tscn" id="11_7wm6b"] [ext_resource type="PackedScene" uid="uid://c6r4higceibif" path="res://content/ui/menu/settings/settings_menu.tscn" id="11_7wm6b"]
[sub_resource type="BoxShape3D" id="BoxShape3D_fgcdq"] [sub_resource type="BoxShape3D" id="BoxShape3D_fgcdq"]
size = Vector3(1, 0.51, 1) size = Vector3(0.38, 0.0634595, 0.32)
[sub_resource type="BoxShape3D" id="BoxShape3D_e1esh"] [sub_resource type="BoxShape3D" id="BoxShape3D_e1esh"]
size = Vector3(0.38, 0.01, 0.32) size = Vector3(0.38, 0.0128076, 0.32)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ti5t2"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ti5t2"]
@ -169,16 +169,16 @@ _data = {
script = ExtResource("1_ng4u3") script = ExtResource("1_ng4u3")
[node name="TouchBody3D" type="Area3D" parent="."] [node name="TouchBody3D" type="Area3D" parent="."]
collision_layer = 13311 collision_layer = 4
collision_mask = 0 collision_mask = 0
script = ExtResource("2_fxtnc") script = ExtResource("2_fxtnc")
[node name="CollisionShape3D" type="CollisionShape3D" parent="TouchBody3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="TouchBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.245, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.02, -0.0282703, 2.98023e-08)
shape = SubResource("BoxShape3D_fgcdq") shape = SubResource("BoxShape3D_fgcdq")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.02, -0.00426685, 1.49012e-08) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.02, -0.00286309, 1.49012e-08)
shape = SubResource("BoxShape3D_e1esh") shape = SubResource("BoxShape3D_e1esh")
[node name="Movable" type="Node" parent="."] [node name="Movable" type="Node" parent="."]

View File

@ -1,9 +1,7 @@
extends Node3D extends Node3D
const ball_scene = preload("./ball.tscn") const credits_scene = preload ("./credits.tscn")
const credits_scene = preload("./credits.tscn")
@onready var ball_button = $Content/Button
@onready var connection_status = $Content/ConnectionStatus @onready var connection_status = $Content/ConnectionStatus
@onready var input_url = $Content/InputURL @onready var input_url = $Content/InputURL
@ -17,20 +15,11 @@ const credits_scene = preload("./credits.tscn")
func _ready(): func _ready():
background.visible = false background.visible = false
ball_button.on_button_down.connect(func():
var ball = ball_scene.instantiate()
var controller = XRHelpers.get_right_controller(self)
ball.transform = controller.transform
ball.linear_velocity = -controller.transform.basis.z * 5 + Vector3(0, 5, 0)
get_tree().root.add_child(ball)
)
credits.on_click.connect(func(_event): credits.on_click.connect(func(_event):
var credits_instance = credits_scene.instantiate() var credits_instance=credits_scene.instantiate()
get_tree().root.add_child(credits_instance) get_tree().root.add_child(credits_instance)
var label = $Content/Credits/Label var label=$Content/Credits/Label
credits_instance.global_position = + label.to_global(label.position + Vector3(0.1, 0, -0.15)) credits_instance.global_position=+ label.to_global(label.position + Vector3(0.1, 0, -0.15))
) )
if Store.settings.is_loaded(): if Store.settings.is_loaded():
@ -38,18 +27,18 @@ func _ready():
input_token.text = Store.settings.token input_token.text = Store.settings.token
else: else:
Store.settings.on_loaded.connect(func(): Store.settings.on_loaded.connect(func():
input_url.text = Store.settings.url input_url.text=Store.settings.url
input_token.text = Store.settings.token input_token.text=Store.settings.token
) )
button_connect.on_button_down.connect(func(): button_connect.on_button_down.connect(func():
var url = input_url.text var url=input_url.text
var token = input_token.text var token=input_token.text
HomeApi.start_adapter("hass_ws", url, token) HomeApi.start_adapter("hass_ws", url, token)
Store.settings.url = url Store.settings.url=url
Store.settings.token = token Store.settings.token=token
Store.settings.save_local() Store.settings.save_local()
) )
@ -65,10 +54,9 @@ func _ready():
) )
HomeApi.on_connect.connect(func(): HomeApi.on_connect.connect(func():
connection_status.text = "Connected" connection_status.text="Connected"
) )
HomeApi.on_disconnect.connect(func(): HomeApi.on_disconnect.connect(func():
connection_status.text = "Disconnected" connection_status.text="Disconnected"
) )

View File

@ -22,21 +22,6 @@ mesh = SubResource("BoxMesh_e51x8")
[node name="Content" type="Node3D" parent="."] [node name="Content" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.007, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.007, 0)
[node name="Label3D" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.124377, 0, 0.263575)
pixel_size = 0.001
text = "Spawn Ball"
font_size = 18
outline_size = 0
[node name="Button" parent="Content" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0358097, 0, 0.263575)
label = "sports_basketball"
icon = true
[node name="Clickable" type="Node" parent="Content/Button"]
script = ExtResource("3_qmg6q")
[node name="ConnectionStatus" type="Label3D" parent="Content"] [node name="ConnectionStatus" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.250698, 0, 0.151303) transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.250698, 0, 0.151303)
pixel_size = 0.001 pixel_size = 0.001

View File

@ -10,8 +10,6 @@ var bodies_entered = {}
var hand_left: Node3D var hand_left: Node3D
var hand_right: Node3D var hand_right: Node3D
@onready var console = get_node("/root/Main/Console")
func _init(hand_left: OpenXRHand, hand_right: OpenXRHand, finger_areas: Dictionary): func _init(hand_left: OpenXRHand, hand_right: OpenXRHand, finger_areas: Dictionary):
self.finger_areas = finger_areas self.finger_areas = finger_areas
self.hand_left = hand_left.get_node("left_hand/Armature_001/Skeleton3D/vr_glove_left_slim") self.hand_left = hand_left.get_node("left_hand/Armature_001/Skeleton3D/vr_glove_left_slim")
@ -39,13 +37,13 @@ func _physics_process(_delta):
for finger in fingers: for finger in fingers:
if finger == Finger.Type.INDEX_LEFT: if finger == Finger.Type.INDEX_LEFT:
var start_pos = finger_areas[finger].global_position var start_pos = finger_areas[finger].get_parent().global_position
var end_pos = body.to_global(body.plane.project(body.to_local(start_pos))) var end_pos = body.to_global(body.plane.project(body.to_local(start_pos)))
hand_left.global_position = end_pos + (hand_left.global_position - start_pos) hand_left.global_position = end_pos + (hand_left.global_position - start_pos)
elif finger == Finger.Type.INDEX_RIGHT: elif finger == Finger.Type.INDEX_RIGHT:
var start_pos = finger_areas[finger].global_position var start_pos = finger_areas[finger].get_parent().global_position
var end_pos = body.to_global(body.plane.project(body.to_local(start_pos))) var end_pos = body.to_global(body.plane.project(body.to_local(start_pos)))
hand_right.global_position = end_pos + (hand_right.global_position - start_pos) hand_right.global_position = end_pos + (hand_right.global_position - start_pos)