fix bugs in Rdot, Movable and Hands

This commit is contained in:
Nitwel 2024-05-09 18:19:39 +02:00
parent 653d3251e4
commit 5d4f62c34d
11 changed files with 25 additions and 311 deletions

View File

@ -64,6 +64,9 @@ static func effect(callback: Callable):
if !deconstructor.is_null():
deconstructor.call()
if callback.is_valid() == false:
return
var result=callback.call(_arg)
if result is Callable:

View File

@ -29,6 +29,7 @@ animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
_subresources={}
fbx/importer=0

View File

@ -29,6 +29,7 @@ animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
_subresources={}
fbx/importer=0

View File

@ -29,6 +29,7 @@ animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
_subresources={}
fbx/importer=0

View File

@ -10,7 +10,7 @@
[sub_resource type="BoxShape3D" id="BoxShape3D_3qyo4"]
size = Vector3(0.32, 0.16, 0.02)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mb0u1"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_v0oi8"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("6_40cd1")
@ -25,7 +25,7 @@ shader_parameter/corner_radius = 0.8
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_ysurb"]
[sub_resource type="QuadMesh" id="QuadMesh_pbdeb"]
size = Vector2(0.32, 0.16)
[node name="Timer" type="StaticBody3D" groups=["entity"]]
@ -78,7 +78,7 @@ label = "stop"
icon = true
[node name="Panel" parent="." instance=ExtResource("5_j3gsb")]
material_override = SubResource("ShaderMaterial_mb0u1")
mesh = SubResource("QuadMesh_ysurb")
material_override = SubResource("ShaderMaterial_v0oi8")
mesh = SubResource("QuadMesh_pbdeb")
size = Vector2(0.32, 0.16)
corner_radius = 0.8

View File

@ -13,7 +13,6 @@ signal on_moved()
var initiator = null
var initiator2 = null
var resizing = false
var relative_transform = Transform3D()
var initial_point = Vector3()
@ -27,7 +26,7 @@ var initial_transform = Transform3D()
var distances = Vector2()
func _process(delta):
if get_tree().debug_collisions_hint&&resizing:
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))
@ -38,12 +37,11 @@ func _on_grab_down(event: EventPointer):
if restricted&&event.target != get_parent():
return
if resizing&&initiator2 != null:
if initiator != null&&initiator2 != null:
return
if resizable&&initiator != null:
if initiator != null&&initiator2 == null&&initiator != event.initiator:
initiator2 = event.initiator
resizing = true
distances.y = event.ray.get_collision_point().distance_to(event.ray.global_position)
@ -54,8 +52,7 @@ func _on_grab_down(event: EventPointer):
return
if resizable:
distances.x = event.ray.get_collision_point().distance_to(event.ray.global_position)
distances.x = event.ray.get_collision_point().distance_to(event.ray.global_position)
initiator = event.initiator
@ -69,11 +66,14 @@ func _on_grab_move(event: EventPointer):
if event.initiator != initiator:
return
if resizing:
if initiator != null&&initiator2 != null:
var new_position = _get_first_ray_point()
var new_direction = _get_second_ray_point() - new_position
var new_up = -initiator.node.global_transform.basis.z.normalized() * distances.x
if resizable == false:
new_direction = new_direction.normalized() * initial_direction.length()
if get_tree().debug_collisions_hint:
DebugDraw3D.draw_line(new_position, new_position + new_direction, Color(1, 0, 0))
DebugDraw3D.draw_line(new_position, new_position + new_up, Color(0, 1, 0))
@ -93,7 +93,6 @@ func _on_grab_move(event: EventPointer):
func _on_grab_up(event: EventPointer):
if event.initiator == initiator2:
initiator2 = null
resizing = false
_update_relative_transform()
return
@ -101,12 +100,10 @@ func _on_grab_up(event: EventPointer):
if initiator2 != null:
initiator = initiator2
initiator2 = null
resizing = false
_update_relative_transform()
else:
initiator = null
initiator2 = null
resizing = false
on_moved.emit()
func _get_first_ray_point():

View File

@ -16,7 +16,7 @@ material = SubResource("StandardMaterial3D_m58yb")
size = Vector3(0.01, 0.01, 0.01)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ca85m"]
render_priority = 0
render_priority = 50
shader = ExtResource("6_wk733")
shader_parameter/albedo = Color(1, 1, 1, 0.4)
shader_parameter/fade_offset = 0.0

View File

@ -3,7 +3,7 @@
[ext_resource type="Shader" path="res://assets/materials/hands.gdshader" id="1_kyekt"]
[resource]
render_priority = 0
render_priority = 50
shader = ExtResource("1_kyekt")
shader_parameter/albedo = Color(1, 1, 1, 0.4)
shader_parameter/fade_offset = 0.0

View File

@ -1,289 +0,0 @@
[gd_scene load_steps=4 format=3 uid="uid://byj36o0boo1v2"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="3_te2p8"]
[sub_resource type="GDScript" id="GDScript_4kea7"]
script/source = "extends Node3D
const Pointer = preload (\"res://lib/utils/pointer/pointer.gd\")
const Initiator = preload (\"res://lib/utils/pointer/initiator.gd\")
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/house/mini/miniature.gd\")
@onready var main = $\"/root/Main\"
@onready var palm = $XRHandLeft/Palm
@onready var quick_actions = $XRHandLeft/Palm/QuickActions
@onready var mini_view_button = $XRHandLeft/Palm/QuickActions/MiniView
@onready var temperature_button = $XRHandLeft/Palm/QuickActions/Temperature
@onready var humidity_button = $XRHandLeft/Palm/QuickActions/Humidity
@export var ray_left: RayCast3D
@export var ray_right: RayCast3D
@export var hand_left: Node3D
@export var hand_right: Node3D
@onready var bone_attachments_right = [$XRHandRight/IndexTip, $XRHandRight/ThumbTip, $XRHandRight/MiddleTip]
@onready var bone_attachments_left = [$XRHandLeft/IndexTip, $XRHandLeft/ThumbTip, $XRHandLeft/MiddleTip]
enum Fingers {INDEX, THUMB, MIDDLE}
var left_initiator: Initiator = Initiator.new()
var right_initiator: Initiator = Initiator.new()
var touch: Touch
var collide: Collide
var left_pointer: Pointer
var right_pointer: Pointer
var press_distance = 0.03
var grip_distance = 0.03
var pressed_left = false
var pressed_right = false
var grabbed_left = false
var grabbed_right = false
func _ready():
var fingers = {
Finger.Type.INDEX_RIGHT: $XRHandRight/IndexTip/TouchArea,
Finger.Type.INDEX_LEFT: $XRHandLeft/IndexTip/TouchArea,
Finger.Type.MIDDLE_RIGHT: $XRHandRight/MiddleTip/TouchArea,
Finger.Type.MIDDLE_LEFT: $XRHandLeft/MiddleTip/TouchArea
}
touch = Touch.new(fingers)
collide = Collide.new(hand_left, hand_right, $XRHandLeft/IndexTip/TouchArea, $XRHandRight/IndexTip/TouchArea)
add_child(touch)
add_child(collide)
_ready_hand()
mini_view_button.on_button_up.connect(func():
House.body.mini_view.small.value=!House.body.mini_view.small.value
)
temperature_button.on_button_up.connect(func():
if House.body.mini_view.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE:
House.body.mini_view.heatmap_type.value=Miniature.HeatmapType.NONE
else:
House.body.mini_view.heatmap_type.value=Miniature.HeatmapType.TEMPERATURE
)
humidity_button.on_button_up.connect(func():
if House.body.mini_view.heatmap_type.value == Miniature.HeatmapType.HUMIDITY:
House.body.mini_view.heatmap_type.value=Miniature.HeatmapType.NONE
else:
House.body.mini_view.heatmap_type.value=Miniature.HeatmapType.HUMIDITY
)
func _ready_hand():
left_initiator.type = Initiator.Type.HAND_LEFT
left_initiator.node = ray_left.get_parent()
left_pointer = Pointer.new(left_initiator, ray_left)
add_child(left_pointer)
right_initiator.type = Initiator.Type.HAND_RIGHT
right_initiator.node = ray_right.get_parent()
right_pointer = Pointer.new(right_initiator, ray_right)
add_child(right_pointer)
func _process(_delta):
if main.camera.global_transform.basis.z.dot(palm.global_transform.basis.y) > 0.85:
if quick_actions.is_inside_tree() == false: palm.add_child(quick_actions)
else:
if quick_actions.is_inside_tree(): palm.remove_child(quick_actions)
func _physics_process(_delta):
_process_hand_left(hand_left)
_process_hand_right(hand_right)
func _process_hand_left(hand: Node3D):
var index_tip = bone_attachments_left[Fingers.INDEX].get_node(\"Marker3D\")
var thumb_tip = bone_attachments_left[Fingers.THUMB].get_node(\"Marker3D\")
var middle_tip = bone_attachments_left[Fingers.MIDDLE].get_node(\"Marker3D\")
var _ray = ray_left if hand == hand_left else ray_right
var initiator = left_initiator if hand == hand_left else right_initiator
var distance_trigger = index_tip.global_position.distance_to(thumb_tip.global_position)
var distance_grab = middle_tip.global_position.distance_to(thumb_tip.global_position)
var trigger_close = distance_trigger <= press_distance
var grab_close = distance_grab <= grip_distance
if trigger_close&&!pressed_left:
initiator.on_press.emit(Initiator.EventType.TRIGGER)
pressed_left = true
elif !trigger_close&&pressed_left:
initiator.on_release.emit(Initiator.EventType.TRIGGER)
pressed_left = false
if grab_close&&!grabbed_left:
initiator.on_press.emit(Initiator.EventType.GRIP)
grabbed_left = true
elif !grab_close&&grabbed_left:
initiator.on_release.emit(Initiator.EventType.GRIP)
grabbed_left = false
func _process_hand_right(hand: Node3D):
var index_tip = bone_attachments_right[Fingers.INDEX].get_node(\"Marker3D\")
var thumb_tip = bone_attachments_right[Fingers.THUMB].get_node(\"Marker3D\")
var middle_tip = bone_attachments_right[Fingers.MIDDLE].get_node(\"Marker3D\")
var _ray = ray_left if hand == hand_left else ray_right
var initiator = left_initiator if hand == hand_left else right_initiator
var distance_trigger = index_tip.global_position.distance_to(thumb_tip.global_position)
var distance_grab = middle_tip.global_position.distance_to(thumb_tip.global_position)
var trigger_close = distance_trigger <= press_distance
var grab_close = distance_grab <= grip_distance
if trigger_close&&!pressed_right:
initiator.on_press.emit(Initiator.EventType.TRIGGER)
pressed_right = true
elif !trigger_close&&pressed_right:
initiator.on_release.emit(Initiator.EventType.TRIGGER)
pressed_right = false
if grab_close&&!grabbed_right:
initiator.on_press.emit(Initiator.EventType.GRIP)
grabbed_right = true
elif !grab_close&&grabbed_right:
initiator.on_release.emit(Initiator.EventType.GRIP)
grabbed_right = false
"
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dopke"]
radius = 0.001
height = 0.02
[node name="Hands" type="Node3D"]
script = SubResource("GDScript_4kea7")
[node name="XRHandLeft" type="Node3D" parent="."]
transform = Transform3D(0.999999, -1.39628e-11, 0, 9.48119e-12, 0.999999, -4.54747e-13, 0, 0, 0.999999, -0.25, 0, 0)
[node name="IndexTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.967526, 0.252326, -0.0150302, -0.0150302, 0.116784, 0.993043, 0.252326, -0.960569, 0.116784, -0.00665802, 0.0427913, -0.169868)
bone_name = "Index_Tip_L"
bone_idx = 9
use_external_skeleton = true
external_skeleton = NodePath("")
[node name="Marker3D" type="Marker3D" parent="XRHandLeft/IndexTip"]
gizmo_extents = 0.02
[node name="TouchArea" type="Area3D" parent="XRHandLeft/IndexTip"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.01)
collision_layer = 0
collision_mask = 4
monitorable = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandLeft/IndexTip/TouchArea"]
transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, 1, 0, 0, 0)
shape = SubResource("CapsuleShape3D_dopke")
[node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.967043, 0.24582, -0.0663439, -0.0663439, 0.494837, 0.86645, 0.24582, -0.833492, 0.494837, 0.0261569, 0.0891964, -0.0934418)
bone_name = "Thumb_Tip_L"
bone_idx = 4
use_external_skeleton = true
external_skeleton = NodePath("")
[node name="Marker3D" type="Marker3D" parent="XRHandLeft/ThumbTip"]
gizmo_extents = 0.02
[node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.98042, 0.196912, 0.00149799, 0.001498, -0.015065, 0.999885, 0.196912, -0.980305, -0.0150651, -0.00327212, -0.00771424, -0.176318)
bone_name = "Middle_Tip_L"
bone_idx = 14
use_external_skeleton = true
external_skeleton = NodePath("")
[node name="Marker3D" type="Marker3D" parent="XRHandLeft/MiddleTip"]
gizmo_extents = 0.02
[node name="TouchArea" type="Area3D" parent="XRHandLeft/MiddleTip"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.01)
collision_layer = 0
collision_mask = 4
monitorable = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandLeft/MiddleTip/TouchArea"]
transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, 1, 0, 0, 0)
shape = SubResource("CapsuleShape3D_dopke")
[node name="Palm" type="Node3D" parent="XRHandLeft"]
transform = Transform3D(-0.707107, -8.74228e-08, -0.707107, 6.18173e-08, -1, 6.18173e-08, -0.707107, -8.29045e-24, 0.707107, 0.01, -0.04, -5.58794e-09)
[node name="QuickActions" type="Node3D" parent="XRHandLeft/Palm"]
transform = Transform3D(0.5, -4.47035e-08, -4.37114e-08, 4.37114e-08, -2.18557e-08, 0.5, -4.47035e-08, -0.5, -2.18557e-08, 0.005, 0, 0.005)
[node name="MiniView" parent="XRHandLeft/Palm/QuickActions" instance=ExtResource("3_te2p8")]
transform = Transform3D(1, -3.55271e-15, -4.33681e-19, 3.55271e-15, 1, 3.5525e-15, -4.33681e-19, -3.55291e-15, 1, -0.0600001, 0, 0)
label = "nest_multi_room"
icon = true
[node name="Temperature" parent="XRHandLeft/Palm/QuickActions" instance=ExtResource("3_te2p8")]
label = "device_thermostat"
icon = true
[node name="Humidity" parent="XRHandLeft/Palm/QuickActions" instance=ExtResource("3_te2p8")]
transform = Transform3D(1, 1.73472e-18, 0, 0, 1, 0, 0, 0, 1, 0.0600001, -5.68873e-13, 0)
label = "humidity_mid"
icon = true
[node name="XRHandRight" type="Node3D" parent="."]
transform = Transform3D(0.999998, 0, 0, 0, 0.999999, 0, 0, 0, 0.999999, 0.264391, 0, 0)
[node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"]
transform = Transform3D(0.967526, -0.252326, 0.0150302, 0.0150302, 0.116784, 0.993043, -0.252326, -0.960569, 0.116784, 0.00665802, 0.0427913, -0.169868)
bone_name = "Index_Tip_R"
bone_idx = 9
use_external_skeleton = true
external_skeleton = NodePath("")
[node name="Marker3D" type="Marker3D" parent="XRHandRight/IndexTip"]
gizmo_extents = 0.02
[node name="TouchArea" type="Area3D" parent="XRHandRight/IndexTip"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.01)
collision_layer = 0
collision_mask = 4
monitorable = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandRight/IndexTip/TouchArea"]
transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, 1, 0, 0, 0)
shape = SubResource("CapsuleShape3D_dopke")
[node name="ThumbTip" type="BoneAttachment3D" parent="XRHandRight"]
transform = Transform3D(0.967042, -0.24582, 0.0663439, 0.0663439, 0.494837, 0.866449, -0.24582, -0.833492, 0.494837, -0.0261569, 0.0891963, -0.0934418)
bone_name = "Thumb_Tip_R"
bone_idx = 4
use_external_skeleton = true
external_skeleton = NodePath("")
[node name="Marker3D" type="Marker3D" parent="XRHandRight/ThumbTip"]
gizmo_extents = 0.02
[node name="MiddleTip" type="BoneAttachment3D" parent="XRHandRight"]
transform = Transform3D(0.98042, -0.196912, -0.00149799, -0.001498, -0.015065, 0.999885, -0.196912, -0.980305, -0.0150651, 0.00327212, -0.00771424, -0.176318)
bone_name = "Middle_Tip_R"
bone_idx = 14
use_external_skeleton = true
external_skeleton = NodePath("")
[node name="Marker3D" type="Marker3D" parent="XRHandRight/MiddleTip"]
gizmo_extents = 0.02
[node name="TouchArea" type="Area3D" parent="XRHandRight/MiddleTip"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.01)
collision_layer = 0
collision_mask = 4
monitorable = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandRight/MiddleTip/TouchArea"]
transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, 1, 0, 0, 0)
shape = SubResource("CapsuleShape3D_dopke")

View File

@ -5,7 +5,7 @@
[ext_resource type="FontVariation" uid="uid://d2ofyimg5s65q" path="res://assets/fonts/ui_font_500.tres" id="3_ij5fh"]
[ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="3_nl02b"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_w3y4s"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_46adm"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("3_nl02b")
@ -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_rsne0"]
[sub_resource type="QuadMesh" id="QuadMesh_1me1o"]
size = Vector2(0.15, 0.03)
[sub_resource type="BoxShape3D" id="BoxShape3D_x4yp8"]
@ -83,8 +83,8 @@ collision_mask = 6
[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_w3y4s")
mesh = SubResource("QuadMesh_rsne0")
material_override = SubResource("ShaderMaterial_46adm")
mesh = SubResource("QuadMesh_1me1o")
script = ExtResource("3_3bvrj")
size = Vector2(0.15, 0.03)