From b3474b16a0dafbb0957e405503f9ad4f299aea59 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 30 Apr 2024 09:01:10 +0200 Subject: [PATCH 1/3] remove proximity grab --- app/content/system/hands/hands.gd | 72 +++++++++++-------------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/app/content/system/hands/hands.gd b/app/content/system/hands/hands.gd index 26e378a..69a6c09 100644 --- a/app/content/system/hands/hands.gd +++ b/app/content/system/hands/hands.gd @@ -25,7 +25,6 @@ var left_pointer: Pointer var right_pointer: Pointer var press_distance = 0.03 var grip_distance = 0.03 -var close_distance = 0.1 var pressed_left = false var pressed_right = false @@ -99,55 +98,34 @@ func _process_hand(hand: OpenXRHand): 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 distance_target = _ray.get_collision_point().distance_to(_ray.global_position) - var trigger_close = distance_trigger <= press_distance var grab_close = distance_grab <= grip_distance - var distance_close = distance_target <= close_distance if hand == hand_left: - - if !distance_close: - 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 - else: - if trigger_close&&!grabbed_left: - initiator.on_press.emit(Initiator.EventType.GRIP) - grabbed_left = true - elif !trigger_close&&grabbed_left: - initiator.on_release.emit(Initiator.EventType.GRIP) - grabbed_left = false + 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 else: - if !distance_close: - 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 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 - - else: - if trigger_close&&!grabbed_right: - initiator.on_press.emit(Initiator.EventType.GRIP) - grabbed_right = true - elif !trigger_close&&grabbed_right: - initiator.on_release.emit(Initiator.EventType.GRIP) - grabbed_right = false \ No newline at end of file + 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 \ No newline at end of file From f65216463735bbcc154beadaf34053b6525cf019 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 30 Apr 2024 19:18:49 +0200 Subject: [PATCH 2/3] rewrite movable to allow for resizing --- app/.gitignore | 1 + app/content/functions/function.gd | 2 +- app/content/functions/movable.gd | 114 ++++++++++++++---- app/content/main.tscn | 6 +- app/content/system/house/house.tscn | 16 +-- app/content/system/house/mini/miniature.tscn | 1 + app/content/ui/components/input/input.gd | 2 +- app/content/ui/components/panel/panel.gd | 2 +- app/content/ui/components/panel/panel.tscn | 12 +- app/content/ui/console.tscn | 35 ------ app/content/ui/menu/menu.tscn | 11 +- app/content/ui/{console.gd => ui_console.gd} | 6 +- app/content/ui/ui_console.tscn | 53 ++++++++ app/lib/globals/console.gd | 27 ++--- app/lib/globals/home_api.gd | 2 +- app/lib/stores/devices.gd | 2 +- app/lib/utils/transform_tools.gd | 58 +++++++++ app/project.godot | 18 +-- .../transform_tools/calc_delta_transform.gd | 20 +++ .../transform_tools/calc_delta_transform.tscn | 76 ++++++++++++ .../transform_tools/rotate_around_point.gd | 10 ++ .../transform_tools/rotate_around_point.tscn | 45 +++++++ 22 files changed, 389 insertions(+), 130 deletions(-) delete mode 100644 app/content/ui/console.tscn rename app/content/ui/{console.gd => ui_console.gd} (69%) create mode 100644 app/content/ui/ui_console.tscn create mode 100644 app/lib/utils/transform_tools.gd create mode 100644 app/test/lib/utils/transform_tools/calc_delta_transform.gd create mode 100644 app/test/lib/utils/transform_tools/calc_delta_transform.tscn create mode 100644 app/test/lib/utils/transform_tools/rotate_around_point.gd create mode 100644 app/test/lib/utils/transform_tools/rotate_around_point.tscn diff --git a/app/.gitignore b/app/.gitignore index 4f9264f..b60e493 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,6 +1,7 @@ # Godot 4+ specific ignores .godot/ android/build/ +!android/build/AndroidManifest.xml builds/ reference/ diff --git a/app/content/functions/function.gd b/app/content/functions/function.gd index 41e24be..020e09d 100644 --- a/app/content/functions/function.gd +++ b/app/content/functions/function.gd @@ -1,2 +1,2 @@ extends Node -class_name Function +class_name Function \ No newline at end of file diff --git a/app/content/functions/movable.gd b/app/content/functions/movable.gd index 8d3c33a..be203c0 100644 --- a/app/content/functions/movable.gd +++ b/app/content/functions/movable.gd @@ -6,11 +6,30 @@ signal on_move(position: Vector3, rotation: Vector3) signal on_moved() @export var restricted: bool = false -@export var restrict_movement: Callable +@export var resizable: bool = false @export var lock_rotation: bool = false +@export var restrict_movement: Callable @export var disabled: bool = false -var hit_node := Node3D.new() + var initiator = null +var initiator2 = null +var resizing = false + +var relative_transform = Transform3D() +var initial_point = Vector3() +var initial_rotation = Vector3() + +# For Scaling +var initial_position = Vector3() +var initial_direction = Vector3() +var initial_up = Vector3() +var initial_transform = Transform3D() +var distances = Vector2() + +func _process(delta): + if get_tree().debug_collisions_hint&&resizing: + 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 _on_grab_down(event: EventPointer): if disabled: @@ -19,42 +38,87 @@ func _on_grab_down(event: EventPointer): if restricted&&event.target != get_parent(): return + if resizing&&initiator2 != null: + return + + if resizable&&initiator != null: + initiator2 = event.initiator + resizing = true + + distances.y = event.ray.get_collision_point().distance_to(event.ray.global_position) + + initial_position = _get_first_ray_point() + initial_direction = _get_second_ray_point() - initial_position + initial_up = -initiator.node.global_transform.basis.z.normalized() * distances.x + initial_transform = get_parent().global_transform + + return + + if resizable: + distances.x = event.ray.get_collision_point().distance_to(event.ray.global_position) + initiator = event.initiator - if hit_node.get_parent() != null: - hit_node.get_parent().remove_child(hit_node) + _update_relative_transform() - initiator.node.add_child(hit_node) - hit_node.global_transform = get_parent().global_transform + if lock_rotation: + initial_point = get_parent().to_local(event.ray.get_collision_point()) + initial_rotation = get_parent().global_rotation func _on_grab_move(event: EventPointer): - if hit_node.get_parent() == null: - return - if event.initiator != initiator: return - - if restrict_movement: - get_parent().global_position = restrict_movement.call(hit_node.global_position) - else: - get_parent().global_position = hit_node.global_position - if !lock_rotation: - get_parent().global_basis = hit_node.global_basis - on_move.emit(get_parent().global_position, get_parent().global_rotation) - else: - on_move.emit(get_parent().global_position, Vector3(0, 0, 0)) + if resizing: + 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 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)) + + get_parent().global_transform = TransformTools.calc_delta_transform(initial_position, initial_direction, initial_up, new_position, new_direction, new_up) * initial_transform + return + + get_parent().global_transform = initiator.node.global_transform * relative_transform + + if lock_rotation: + get_parent().global_transform = TransformTools.rotate_around_point(get_parent().global_transform, get_parent().to_global(initial_point), initial_rotation - get_parent().global_rotation) func _on_grab_up(event: EventPointer): - if event.initiator != initiator: + if event.initiator == initiator2: + initiator2 = null + resizing = false + _update_relative_transform() return - if hit_node.get_parent() == null: - return + if event.initiator == initiator: + if initiator2 != null: + initiator = initiator2 + initiator2 = null + resizing = false + _update_relative_transform() + else: + initiator = null + initiator2 = null + resizing = false + on_moved.emit() - initiator = null - hit_node.get_parent().remove_child(hit_node) - on_moved.emit() +func _get_first_ray_point(): + if initiator == null: + return Vector3() + + return initiator.node.global_position - initiator.node.global_transform.basis.z.normalized() * distances.x + +func _get_second_ray_point(): + if initiator2 == null: + return Vector3() + + return initiator2.node.global_position - initiator2.node.global_transform.basis.z.normalized() * distances.y + +func _update_relative_transform(): + relative_transform = initiator.node.global_transform.affine_inverse() * get_parent().global_transform func _get_configuration_warnings() -> PackedStringArray: var warnings := PackedStringArray() diff --git a/app/content/main.tscn b/app/content/main.tscn index 025c61f..78b7fc1 100644 --- a/app/content/main.tscn +++ b/app/content/main.tscn @@ -31,6 +31,9 @@ environment = ExtResource("2_lsndp") transform = Transform3D(1, -2.51787e-05, 0.000567105, -0.000567105, 4.3985e-08, 1, -2.51784e-05, -1, 2.97105e-08, -4.65661e-10, 7.21041, 2.06458) shadow_enabled = true +[node name="StartXR" parent="." instance=ExtResource("1_i4c04")] +enable_passthrough = true + [node name="XROrigin3D" type="XROrigin3D" parent="."] [node name="XRCamera3D" parent="XROrigin3D" instance=ExtResource("3_rj4ac")] @@ -53,9 +56,6 @@ transform = Transform3D(0.999968, -1.39576e-11, 0, 9.52038e-12, 0.999984, -2.592 ray_left = NodePath("../XRControllerLeft/Raycast") ray_right = NodePath("../XRControllerRight/Raycast") -[node name="StartXR" parent="." instance=ExtResource("1_i4c04")] -enable_passthrough = true - [node name="XRSimulator" parent="." instance=ExtResource("5_3qc8g")] min_camera_height = 0.01 xr_origin = NodePath("../XROrigin3D") diff --git a/app/content/system/house/house.tscn b/app/content/system/house/house.tscn index e69fa0a..405b470 100644 --- a/app/content/system/house/house.tscn +++ b/app/content/system/house/house.tscn @@ -1,29 +1,17 @@ -[gd_scene load_steps=7 format=3 uid="uid://cbemihbxkd4ll"] +[gd_scene load_steps=5 format=3 uid="uid://cbemihbxkd4ll"] [ext_resource type="Script" path="res://content/system/house/house.gd" id="1_p8amj"] -[ext_resource type="Script" path="res://content/functions/movable.gd" id="2_w1auk"] [ext_resource type="PackedScene" uid="uid://jls16btb8nko" path="res://content/system/house/align_reference.tscn" id="3_e1tcn"] [ext_resource type="PackedScene" uid="uid://c8nh8582vwc8u" path="res://content/system/house/doors/doors.tscn" id="4_bb3c2"] [ext_resource type="PackedScene" uid="uid://ds60i5n211hi3" path="res://content/system/house/mini/miniature.tscn" id="4_qjbly"] -[sub_resource type="BoxShape3D" id="BoxShape3D_x81up"] - [node name="House" type="Node3D"] script = ExtResource("1_p8amj") -[node name="Levels" type="StaticBody3D" parent="."] +[node name="Levels" type="Node3D" parent="."] [node name="Level0" type="Node3D" parent="Levels"] -[node name="CollisionShape3D" type="CollisionShape3D" parent="Levels"] -shape = SubResource("BoxShape3D_x81up") -disabled = true - -[node name="Movable" type="Node" parent="Levels"] -script = ExtResource("2_w1auk") -restricted = true -lock_rotation = true - [node name="Miniature" parent="Levels" instance=ExtResource("4_qjbly")] [node name="Doors" parent="Levels" instance=ExtResource("4_bb3c2")] diff --git a/app/content/system/house/mini/miniature.tscn b/app/content/system/house/mini/miniature.tscn index b59783c..e40b9d3 100644 --- a/app/content/system/house/mini/miniature.tscn +++ b/app/content/system/house/mini/miniature.tscn @@ -27,6 +27,7 @@ disabled = true [node name="Movable" type="Node" parent="Body"] script = ExtResource("2_x7oed") restricted = true +resizable = true [node name="Small" type="Node3D" parent="Body"] diff --git a/app/content/ui/components/input/input.gd b/app/content/ui/components/input/input.gd index 2189c19..e358066 100644 --- a/app/content/ui/components/input/input.gd +++ b/app/content/ui/components/input/input.gd @@ -86,7 +86,7 @@ func _process(_delta): if Engine.is_editor_hint(): return - if get_tree().debug_collisions_hint&&OS.get_name() != "Android": + if get_tree().debug_collisions_hint: _draw_debug_text_gaps() func _on_press_down(event): diff --git a/app/content/ui/components/panel/panel.gd b/app/content/ui/components/panel/panel.gd index e881274..c6ee11f 100644 --- a/app/content/ui/components/panel/panel.gd +++ b/app/content/ui/components/panel/panel.gd @@ -64,4 +64,4 @@ func _update_style(): func _update_size(): mesh.size = size - material_override.set_shader_parameter("size", size * 25) \ No newline at end of file + material_override.set_shader_parameter("size", size * 25) diff --git a/app/content/ui/components/panel/panel.tscn b/app/content/ui/components/panel/panel.tscn index b5cf52a..c095ac1 100644 --- a/app/content/ui/components/panel/panel.tscn +++ b/app/content/ui/components/panel/panel.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://content/ui/components/panel/panel.gd" id="1_2jq4a"] [ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="1_mpdsy"] -[sub_resource type="ShaderMaterial" id="ShaderMaterial_2wxf7"] +[sub_resource type="ShaderMaterial" id="ShaderMaterial_koby5"] resource_local_to_scene = true render_priority = 10 shader = ExtResource("1_mpdsy") @@ -14,17 +14,15 @@ shader_parameter/size = Vector2(1, 1) 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.04 +shader_parameter/corner_radius = 0.2 shader_parameter/roughness = 0.3 shader_parameter/grain_amount = 0.02 -[sub_resource type="QuadMesh" id="QuadMesh_r8ntw"] +[sub_resource type="QuadMesh" id="QuadMesh_1r1mq"] size = Vector2(0.04, 0.04) [node name="Panel" type="MeshInstance3D"] -material_override = SubResource("ShaderMaterial_2wxf7") -mesh = SubResource("QuadMesh_r8ntw") +material_override = SubResource("ShaderMaterial_koby5") +mesh = SubResource("QuadMesh_1r1mq") script = ExtResource("1_2jq4a") size = Vector2(0.04, 0.04) -corner_radius = null -border = null diff --git a/app/content/ui/console.tscn b/app/content/ui/console.tscn deleted file mode 100644 index 3cbf0c6..0000000 --- a/app/content/ui/console.tscn +++ /dev/null @@ -1,35 +0,0 @@ -[gd_scene load_steps=6 format=3 uid="uid://6jhh4qy74px3"] - -[ext_resource type="Script" path="res://content/ui/console.gd" id="1_ullcc"] -[ext_resource type="Script" path="res://content/functions/movable.gd" id="2_gfjlg"] - -[sub_resource type="BoxShape3D" id="BoxShape3D_6xl4b"] -size = Vector3(1, 0.05, 1) - -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_087gr"] -cull_mode = 2 - -[sub_resource type="QuadMesh" id="QuadMesh_chf50"] - -[node name="Console" type="StaticBody3D"] -script = ExtResource("1_ullcc") - -[node name="CollisionShape3D" type="CollisionShape3D" parent="."] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) -shape = SubResource("BoxShape3D_6xl4b") - -[node name="MeshInstance3D" type="MeshInstance3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 1.06581e-14, 0, -1.06581e-14, 1, 0.01, 0, 0) -material_override = SubResource("StandardMaterial3D_087gr") -mesh = SubResource("QuadMesh_chf50") - -[node name="Label3D" type="Label3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.477979, 0.492319, 0.001) -pixel_size = 0.001 -text = "Texst -aaa" -horizontal_alignment = 0 -vertical_alignment = 0 - -[node name="Movable" type="Node" parent="."] -script = ExtResource("2_gfjlg") diff --git a/app/content/ui/menu/menu.tscn b/app/content/ui/menu/menu.tscn index f5e5027..9829a71 100644 --- a/app/content/ui/menu/menu.tscn +++ b/app/content/ui/menu/menu.tscn @@ -198,6 +198,7 @@ shape = SubResource("BoxShape3D_e1esh") [node name="Movable" type="Node" parent="."] script = ExtResource("2_8coxu") +resizable = false [node name="AnimationContainer" type="Node3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.23, 0.15, 0) @@ -225,38 +226,38 @@ size = Vector3(0.05, 0.4, 1) [node name="View" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.025, 0) label = "visibility" +size = Vector3(0.05, 0.05, 0.01) icon = true toggleable = true disabled = true -size = Vector3(0.05, 0.05, 0.01) [node name="Edit" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.085, 0) label = "widgets" +size = Vector3(0.05, 0.05, 0.01) icon = true toggleable = true -size = Vector3(0.05, 0.05, 0.01) [node name="Room" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.145, 0) label = "view_in_ar" +size = Vector3(0.05, 0.05, 0.01) icon = true toggleable = true -size = Vector3(0.05, 0.05, 0.01) [node name="Automate" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.205, 0) label = "schema" +size = Vector3(0.05, 0.05, 0.01) icon = true toggleable = true -size = Vector3(0.05, 0.05, 0.01) [node name="Settings" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.265, 0) label = "settings" +size = Vector3(0.05, 0.05, 0.01) icon = true toggleable = true -size = Vector3(0.05, 0.05, 0.01) [node name="TabsContent" type="Node3D" parent="AnimationContainer" node_paths=PackedStringArray("tabs")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, 0.00999999, 0) diff --git a/app/content/ui/console.gd b/app/content/ui/ui_console.gd similarity index 69% rename from app/content/ui/console.gd rename to app/content/ui/ui_console.gd index 9f9c6c7..73a05f9 100644 --- a/app/content/ui/console.gd +++ b/app/content/ui/ui_console.gd @@ -6,11 +6,9 @@ var max_message = 30 var messages: Array = ["aaa", "bbb"] func log(text: Variant) -> void: - messages.push_front(str(text)) + messages.append(str(text)) if messages.size() > max_message: - messages.pop_back() - -func _process(_delta: float) -> void: + messages.pop_front() label.text = "\n".join(messages) diff --git a/app/content/ui/ui_console.tscn b/app/content/ui/ui_console.tscn new file mode 100644 index 0000000..ce0a54f --- /dev/null +++ b/app/content/ui/ui_console.tscn @@ -0,0 +1,53 @@ +[gd_scene load_steps=8 format=3 uid="uid://87utftwh8lr6"] + +[ext_resource type="PackedScene" uid="uid://dnam3fe36gg62" path="res://content/ui/components/panel/panel.tscn" id="1_3t6cp"] +[ext_resource type="Script" path="res://content/ui/ui_console.gd" id="1_ullcc"] +[ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="2_dbrjx"] +[ext_resource type="Script" path="res://content/functions/movable.gd" id="3_2a4np"] + +[sub_resource type="BoxShape3D" id="BoxShape3D_mfp33"] +size = Vector3(1, 1, 0.01) + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_p0lm6"] +resource_local_to_scene = true +render_priority = 10 +shader = ExtResource("2_dbrjx") +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(25, 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_drxk8"] + +[node name="Console" type="StaticBody3D"] +collision_layer = 2 +collision_mask = 2 +script = ExtResource("1_ullcc") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("BoxShape3D_mfp33") + +[node name="Label3D" type="Label3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.48, -0.49, 0) +pixel_size = 0.001 +text = "aaadddddddddddddddd dad addddddddddd ad awd ddddd dawd aw dwadaw wd dawdwdawd dwd dwdddd +aaa +aaa" +horizontal_alignment = 0 +vertical_alignment = 2 +autowrap_mode = 3 +width = 980.0 + +[node name="Movable" type="Node" parent="."] +script = ExtResource("3_2a4np") + +[node name="Panel" parent="." instance=ExtResource("1_3t6cp")] +material_override = SubResource("ShaderMaterial_p0lm6") +mesh = SubResource("QuadMesh_drxk8") +size = Vector2(1, 1) diff --git a/app/lib/globals/console.gd b/app/lib/globals/console.gd index 1574eff..f65e9a5 100644 --- a/app/lib/globals/console.gd +++ b/app/lib/globals/console.gd @@ -1,28 +1,17 @@ extends Node const console_scene = preload ("res://content/ui/console.tscn") -var _console: Node3D = null -@onready var main = get_node_or_null("/root/Main") +@onready var main = $"/root/Main" +@onready var console = $"/root/Main/Console" func _ready(): - if main == null: - return + await main.ready - main.tree_entered.connect(func(): - init_console() - ) - -func init_console(): - _console = console_scene.instantiate() - main.add_child(_console) - var camera = get_node("/root/Main/XROrigin3D/XRCamera3D") - - _console.global_position = camera.global_position + camera.global_transform.basis.z * - 1 - _console.global_transform.basis = Basis.looking_at(_console.global_position - camera.global_position) + main.remove_child(console) func log(message): - print(message, _console) - if _console == null: - init_console() + print(message) + if console.get_parent() == null: + main.add_child(console) - _console.log(message) + console.log(message) diff --git a/app/lib/globals/home_api.gd b/app/lib/globals/home_api.gd index d7155f0..618ca1f 100644 --- a/app/lib/globals/home_api.gd +++ b/app/lib/globals/home_api.gd @@ -154,4 +154,4 @@ func get_history(entity_id, start, end=null): if groups.is_group(entity_id): return null - return await api.get_history(entity_id, start, end) \ No newline at end of file + return await api.get_history(entity_id, start, end) diff --git a/app/lib/stores/devices.gd b/app/lib/stores/devices.gd index 0eb1917..e9c5de5 100644 --- a/app/lib/stores/devices.gd +++ b/app/lib/stores/devices.gd @@ -26,4 +26,4 @@ func _init(): ) func clear(): - pass \ No newline at end of file + pass diff --git a/app/lib/utils/transform_tools.gd b/app/lib/utils/transform_tools.gd new file mode 100644 index 0000000..1469928 --- /dev/null +++ b/app/lib/utils/transform_tools.gd @@ -0,0 +1,58 @@ +class_name TransformTools + +## Calculate the transform that would transform the source position, direction and up vector to the target position, direction and up vector +## Basically a bit more fancy Inputs for a Transform3D +static func calc_delta_transform(source_pos: Vector3, source_dir: Vector3, source_up: Vector3, target_pos: Vector3, target_dir: Vector3, target_up: Vector3) -> Transform3D: + var source_transform = Transform3D() + source_transform.basis = Basis(source_dir, source_up, source_dir.cross(source_up)).orthonormalized() * (1.0 / source_dir.length()) + source_transform.origin = source_pos + + var target_transform = Transform3D() + target_transform.basis = Basis(target_dir, target_up, target_dir.cross(target_up)).orthonormalized() * (target_dir.length()) + target_transform.origin = target_pos + + return target_transform * source_transform.inverse() + +## Rotate a transform around a point by an angle around an axis +static func rotate_around_point_axis(transform: Transform3D, point: Vector3, axis: Vector3, angle: float) -> Transform3D: + return transform.translated( - point).rotated(axis, angle).translated(point) + +static func rotate_around_point(transform: Transform3D, point: Vector3, rotation: Vector3, rotation_order: EulerOrder=EULER_ORDER_YXZ) -> Transform3D: + transform = transform.translated( - point) + var axis1 = Vector3() + var axis2 = Vector3() + var axis3 = Vector3() + + match rotation_order: + EULER_ORDER_XYZ: + axis1 = Vector3(1, 0, 0) + axis2 = Vector3(0, 1, 0) + axis3 = Vector3(0, 0, 1) + EULER_ORDER_XZY: + axis1 = Vector3(1, 0, 0) + axis2 = Vector3(0, 0, 1) + axis3 = Vector3(0, 1, 0) + rotation = Vector3(rotation.x, rotation.z, rotation.y) + EULER_ORDER_YXZ: + axis1 = Vector3(0, 1, 0) + axis2 = Vector3(1, 0, 0) + axis3 = Vector3(0, 0, 1) + rotation = Vector3(rotation.y, rotation.x, rotation.z) + EULER_ORDER_YZX: + axis1 = Vector3(0, 1, 0) + axis2 = Vector3(0, 0, 1) + axis3 = Vector3(1, 0, 0) + rotation = Vector3(rotation.y, rotation.z, rotation.x) + EULER_ORDER_ZXY: + axis1 = Vector3(0, 0, 1) + axis2 = Vector3(1, 0, 0) + axis3 = Vector3(0, 1, 0) + rotation = Vector3(rotation.z, rotation.x, rotation.y) + EULER_ORDER_ZYX: + axis1 = Vector3(0, 0, 1) + axis2 = Vector3(0, 1, 0) + axis3 = Vector3(1, 0, 0) + rotation = Vector3(rotation.z, rotation.y, rotation.x) + + transform = transform.rotated(axis1, rotation.x).rotated(axis2, rotation.y).rotated(axis3, rotation.z) + return transform.translated(point) diff --git a/app/project.godot b/app/project.godot index b526861..a53401f 100644 --- a/app/project.godot +++ b/app/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="ImmersiveHome" run/main_scene="res://content/main.tscn" -config/features=PackedStringArray("4.2", "Mobile") +config/features=PackedStringArray("4.2", "GL Compatibility") config/icon="res://assets/logo.png" [audio] @@ -22,21 +22,16 @@ driver/enable_input=true [autoload] XRToolsUserSettings="*res://addons/godot-xr-tools/user_settings/user_settings.gd" -Request="*res://lib/globals/request.gd" -HomeApi="*res://lib/globals/home_api.gd" AudioPlayer="*res://lib/globals/audio_player.gd" -EventSystem="*res://lib/globals/event_system.gd" +HomeApi="*res://lib/globals/home_api.gd" Store="*res://lib/globals/main_store.gd" +EventSystem="*res://lib/globals/event_system.gd" House="*res://lib/globals/house_body.gd" -console="*res://lib/globals/console.gd" - -[display] - -window/vsync/vsync_mode=0 +Request="*res://lib/globals/request.gd" [editor_plugins] -enabled=PackedStringArray("res://addons/godot-xr-tools/plugin.cfg", "res://addons/godotopenxrvendors/plugin.cfg") +enabled=PackedStringArray("res://addons/godot-xr-tools/plugin.cfg") [file_customization] @@ -71,9 +66,6 @@ common/physics_ticks_per_second=30 renderer/rendering_method="gl_compatibility" renderer/rendering_method.mobile="gl_compatibility" textures/vram_compression/import_etc2_astc=true -lights_and_shadows/directional_shadow/soft_shadow_filter_quality=4 -lights_and_shadows/directional_shadow/soft_shadow_filter_quality.mobile=4 -anti_aliasing/quality/msaa_3d=1 viewport/transparent_background=true [xr] diff --git a/app/test/lib/utils/transform_tools/calc_delta_transform.gd b/app/test/lib/utils/transform_tools/calc_delta_transform.gd new file mode 100644 index 0000000..7ade3c8 --- /dev/null +++ b/app/test/lib/utils/transform_tools/calc_delta_transform.gd @@ -0,0 +1,20 @@ +extends Node3D + +@onready var source = $Source +@onready var target = $Target +@onready var soruce_point = $SourcePoint +@onready var target_point = $TargetPoint + +func _process(delta): + source.rotate_y(deg_to_rad(10) * delta) + source.rotate_x(deg_to_rad(20) * delta) + source.scale = Vector3(1, 1, 1) * 0.75 + Vector3(1, 1, 1) * 0.25 * sin(Time.get_ticks_msec() * 0.001) + + var source_pos = source.global_position + var source_dir = source.global_transform.basis.z + var source_up = Vector3.UP + var target_pos = target.global_position + var target_dir = target.global_transform.basis.z + var target_up = Vector3.UP + + target_point.global_position = TransformTools.calc_delta_transform(source_pos, source_dir, source_up, target_pos, target_dir, target_up) * soruce_point.global_position diff --git a/app/test/lib/utils/transform_tools/calc_delta_transform.tscn b/app/test/lib/utils/transform_tools/calc_delta_transform.tscn new file mode 100644 index 0000000..6536754 --- /dev/null +++ b/app/test/lib/utils/transform_tools/calc_delta_transform.tscn @@ -0,0 +1,76 @@ +[gd_scene load_steps=9 format=3 uid="uid://cru8oxovmssaf"] + +[ext_resource type="Script" path="res://test/lib/utils/transform_tools/calc_delta_transform.gd" id="1_26n8o"] + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_c35o8"] +sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) +ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) + +[sub_resource type="Sky" id="Sky_gaxug"] +sky_material = SubResource("ProceduralSkyMaterial_c35o8") + +[sub_resource type="Environment" id="Environment_gr63f"] +background_mode = 2 +sky = SubResource("Sky_gaxug") +tonemap_mode = 2 + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_2hoe7"] +albedo_color = Color(1, 0, 0, 1) + +[sub_resource type="CylinderMesh" id="CylinderMesh_g2kmn"] +top_radius = 0.01 +bottom_radius = 0.06 +height = 1.0 + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gj3vb"] +albedo_color = Color(0, 1, 0, 1) + +[sub_resource type="BoxMesh" id="BoxMesh_3dprm"] +size = Vector3(0.02, 0.02, 0.02) + +[node name="Node3D" type="Node3D"] +script = ExtResource("1_26n8o") + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_gr63f") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0) +shadow_enabled = true + +[node name="Source" type="Node3D" parent="."] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Source"] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.5) +material_override = SubResource("StandardMaterial3D_2hoe7") +mesh = SubResource("CylinderMesh_g2kmn") +skeleton = NodePath("../..") + +[node name="Target" type="Node3D" parent="."] +transform = Transform3D(-0.5, 0, 0.866025, 0, 1, 0, -0.866025, 0, -0.5, 0.3, 0, -0.3) + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Target"] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.5) +material_override = SubResource("StandardMaterial3D_gj3vb") +mesh = SubResource("CylinderMesh_g2kmn") +skeleton = NodePath("../..") + +[node name="SourcePoint" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1) + +[node name="MeshInstance3D" type="MeshInstance3D" parent="SourcePoint"] +material_override = SubResource("StandardMaterial3D_2hoe7") +mesh = SubResource("BoxMesh_3dprm") +skeleton = NodePath("../..") + +[node name="TargetPoint" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.19661, 0, 0.240314) + +[node name="MeshInstance3D" type="MeshInstance3D" parent="TargetPoint"] +material_override = SubResource("StandardMaterial3D_gj3vb") +mesh = SubResource("BoxMesh_3dprm") +skeleton = NodePath("../../SourcePoint") + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(0.760406, -0.30989, 0.570746, 0, 0.878817, 0.477159, -0.649448, -0.362834, 0.668258, 1.40734, 1.17657, 1.64778) +current = true diff --git a/app/test/lib/utils/transform_tools/rotate_around_point.gd b/app/test/lib/utils/transform_tools/rotate_around_point.gd new file mode 100644 index 0000000..3c61aac --- /dev/null +++ b/app/test/lib/utils/transform_tools/rotate_around_point.gd @@ -0,0 +1,10 @@ +extends Node3D + +@onready var box = $Box +@onready var box2 = $Box2 + +func _process(delta): + var rad = deg_to_rad(20) * delta + + box.global_transform = TransformTools.rotate_around_point_axis(box.global_transform, Vector3(0.5, 0.5, 0.5), Vector3(0, 1, 0), rad) + box2.global_transform = TransformTools.rotate_around_point(box2.global_transform, Vector3(0.5, 0.5, 0.5), Vector3( - rad, -rad, 0)) \ No newline at end of file diff --git a/app/test/lib/utils/transform_tools/rotate_around_point.tscn b/app/test/lib/utils/transform_tools/rotate_around_point.tscn new file mode 100644 index 0000000..9dffea5 --- /dev/null +++ b/app/test/lib/utils/transform_tools/rotate_around_point.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=8 format=3 uid="uid://cy8qeuw1q8jk0"] + +[ext_resource type="Script" path="res://test/lib/utils/transform_tools/rotate_around_point.gd" id="1_k7wsf"] + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_p5i6n"] +sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) +ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) + +[sub_resource type="Sky" id="Sky_oxf7q"] +sky_material = SubResource("ProceduralSkyMaterial_p5i6n") + +[sub_resource type="Environment" id="Environment_l7w2l"] +background_mode = 2 +sky = SubResource("Sky_oxf7q") +tonemap_mode = 2 + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_pssmf"] +albedo_color = Color(1, 0, 0, 1) + +[sub_resource type="BoxMesh" id="BoxMesh_gomx4"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_xf20j"] +albedo_color = Color(0, 1, 0, 1) + +[node name="Node3D" type="Node3D"] +script = ExtResource("1_k7wsf") + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_l7w2l") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0) +shadow_enabled = true + +[node name="Box" type="MeshInstance3D" parent="."] +material_override = SubResource("StandardMaterial3D_pssmf") +mesh = SubResource("BoxMesh_gomx4") + +[node name="Box2" type="MeshInstance3D" parent="."] +material_override = SubResource("StandardMaterial3D_xf20j") +mesh = SubResource("BoxMesh_gomx4") + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(0.877583, -0.229849, 0.420735, 0, 0.877583, 0.479426, -0.479426, -0.420736, 0.770151, 1.68294, 1.9177, 3.0806) +current = true From 109ad103a05575d9d962a56cbc834cf819e9b6f3 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 30 Apr 2024 19:25:55 +0200 Subject: [PATCH 3/3] fix collision shape of mini view --- app/content/system/house/mini/miniature.gd | 1 + 1 file changed, 1 insertion(+) diff --git a/app/content/system/house/mini/miniature.gd b/app/content/system/house/mini/miniature.gd index 2b8f3f6..70d0e26 100644 --- a/app/content/system/house/mini/miniature.gd +++ b/app/content/system/house/mini/miniature.gd @@ -96,6 +96,7 @@ func _ready(): var center=aabb.position + aabb.size / 2 collision_shape.shape.size=aabb.size * 0.1 + collision_shape.position=center * 0.1 entity_select.position=Vector3(0, height * 0.1 + 0.1, 0) var camera=$"/root/Main/XROrigin3D/XRCamera3D"