diff --git a/project.godot b/project.godot index 677580d..919db0b 100644 --- a/project.godot +++ b/project.godot @@ -30,9 +30,9 @@ drag_camera={ [layer_names] -3d_physics/layer_1="Drag" -3d_physics/layer_2="Interaction" -3d_physics/layer_3="FlaskInteraction" +3d_physics/layer_1="Environment" +3d_physics/layer_2="Drag" +3d_physics/layer_3="Interaction" [rendering] diff --git a/scenes/flask.tscn b/scenes/flask.tscn index e1a9c60..c279371 100644 --- a/scenes/flask.tscn +++ b/scenes/flask.tscn @@ -1,98 +1,25 @@ -[gd_scene load_steps=12 format=3 uid="uid://bjxjcx2qu16q5"] +[gd_scene load_steps=5 format=3 uid="uid://bjxjcx2qu16q5"] [ext_resource type="Script" uid="uid://bjnv2g1ni0525" path="res://src/drag/draggable_object.gd" id="1_0xufn"] [ext_resource type="PackedScene" uid="uid://b6ydpkle2ol20" path="res://assets/models/FlaskNew.glb" id="2_h7awq"] -[ext_resource type="Script" uid="uid://mjx50qh1bwv3" path="res://src/interactible/interaction_reciever.gd" id="3_ailwx"] -[ext_resource type="Script" uid="uid://ctu7escah5lo1" path="res://src/interactible/interaction_source.gd" id="4_kkw7a"] -[ext_resource type="Script" uid="uid://e8xu57ewvb5a" path="res://src/interactible/proximity_rotator.gd" id="5_rqua0"] -[ext_resource type="Script" uid="uid://dteb2xxl8gixp" path="res://src/ui/slider_display.gd" id="6_wadb5"] [ext_resource type="Script" uid="uid://82ettbegollp" path="res://src/inventory.gd" id="7_h7awq"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_vcwhe"] radius = 0.1 height = 0.9921875 -[sub_resource type="CylinderShape3D" id="CylinderShape3D_0xufn"] -height = 0.16210938 -radius = 0.625 - -[sub_resource type="SphereShape3D" id="SphereShape3D_vcwhe"] -radius = 0.49649125 - -[sub_resource type="Curve" id="Curve_qb0nw"] -_data = [Vector2(0, 0), 0.0, 0.067761436, 0, 0, Vector2(0.75, 1), 0.0, 0.0, 0, 0] -point_count = 2 - [node name="Flask" type="Area3D"] script = ExtResource("1_0xufn") [node name="DragArea" type="CollisionShape3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) shape = SubResource("CapsuleShape3D_vcwhe") [node name="FlaskNew" parent="." instance=ExtResource("2_h7awq")] -transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, -0.38859487, 0) - -[node name="InteractibleArea" type="Area3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6011598, 0) -collision_layer = 6 -collision_mask = 0 -script = ExtResource("3_ailwx") -metadata/_custom_type_script = "uid://mjx50qh1bwv3" - -[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractibleArea"] -shape = SubResource("CylinderShape3D_0xufn") - -[node name="InteractionArea" type="Area3D" parent="." node_paths=PackedStringArray("interaction_dialog")] -collision_layer = 2 -collision_mask = 2 -input_ray_pickable = false -script = ExtResource("4_kkw7a") -interaction_dialog = NodePath("../InteractionDialog") - -[node name="InteractionArea" type="CollisionShape3D" parent="InteractionArea"] -shape = SubResource("SphereShape3D_vcwhe") - -[node name="ProximityRotator" type="Node" parent="." node_paths=PackedStringArray("rotated")] -script = ExtResource("5_rqua0") -rotated = NodePath("..") -proximity_radius = 0.1 -modification_curve = SubResource("Curve_qb0nw") - -[node name="InteractionDialog" type="ConfirmationDialog" parent="."] -oversampling_override = 1.0 -position = Vector2i(0, 36) -size = Vector2i(200, 131) -borderless = true - -[node name="VBoxContainer" type="VBoxContainer" parent="InteractionDialog"] -offset_left = 8.0 -offset_top = 8.0 -offset_right = 192.0 -offset_bottom = 82.0 - -[node name="Label" type="Label" parent="InteractionDialog/VBoxContainer"] -layout_mode = 2 -text = "Введите количество" - -[node name="HBoxContainer" type="HBoxContainer" parent="InteractionDialog/VBoxContainer"] -layout_mode = 2 - -[node name="AmountLabel" type="Label" parent="InteractionDialog/VBoxContainer/HBoxContainer" node_paths=PackedStringArray("slider")] -layout_mode = 2 -script = ExtResource("6_wadb5") -slider = NodePath("../HSlider") -suffix = "%" - -[node name="HSlider" type="HSlider" parent="InteractionDialog/VBoxContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 3 +transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0.1, 0) [node name="Inventory" type="Node" parent="."] unique_name_in_owner = true script = ExtResource("7_h7awq") open_on_top = true metadata/_custom_type_script = "uid://82ettbegollp" - -[connection signal="drag_ended" from="." to="InteractionArea" method="request_interaction"] -[connection signal="interaction_reciever_entered" from="InteractionArea" to="ProximityRotator" method="_on_interaction_area_interaction_reciever_entered"] -[connection signal="interaction_reciever_exited" from="InteractionArea" to="ProximityRotator" method="_on_interaction_area_interaction_reciever_exited"] diff --git a/scenes/lab.tscn b/scenes/lab.tscn index 0e4b2ec..2e94d4b 100644 --- a/scenes/lab.tscn +++ b/scenes/lab.tscn @@ -1,15 +1,13 @@ -[gd_scene load_steps=9 format=3 uid="uid://c7r4rhgj3ucao"] +[gd_scene load_steps=6 format=3 uid="uid://c7r4rhgj3ucao"] -[ext_resource type="PackedScene" uid="uid://bjxjcx2qu16q5" path="res://scenes/flask.tscn" id="1_bb6uc"] [ext_resource type="Script" uid="uid://crjao0jjv5yqs" path="res://src/drag/draggable_camera.gd" id="1_hem3r"] [ext_resource type="PackedScene" uid="uid://dfxlr4svnsdyx" path="res://scenes/ui.tscn" id="3_hflkp"] -[ext_resource type="PackedScene" uid="uid://bx5wihgk668w1" path="res://assets/models/Chemistry.glb" id="5_q4uld"] -[ext_resource type="PackedScene" uid="uid://bg8y4u2a4hx3p" path="res://assets/models/Drip.glb" id="6_gipex"] -[ext_resource type="PackedScene" uid="uid://dwtaqdacgcysa" path="res://assets/models/FlaskHolder.glb" id="7_064jp"] [ext_resource type="Environment" uid="uid://clgblxkcf822n" path="res://assets/Environment.tres" id="8_4kvtl"] [sub_resource type="BoxMesh" id="BoxMesh_cbcd7"] -size = Vector3(3.535, 1, 1) +size = Vector3(4, 1, 2) + +[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_hflkp"] [node name="Lab" type="Node3D"] @@ -18,11 +16,11 @@ transform = Transform3D(2.4088485, 0, 0, 0, 1, 0, 0, 0, 2.8214846, 0, 0, 0) mesh = SubResource("BoxMesh_cbcd7") [node name="Camera3D" type="Camera3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.236948, 0.9448395, 1.8294222) +transform = Transform3D(1, 0, 0, 0, 0.86602545, 0.5, 0, -0.5, 0.8660253, -1.236948, 2.5364435, 3.1829531) script = ExtResource("1_hem3r") -[node name="Flask" parent="." instance=ExtResource("1_bb6uc")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.6518283, 1.0920403, 0.0039073825) +[node name="DragRaycast" type="RayCast3D" parent="Camera3D"] +target_position = Vector3(0, 0, -10) [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.8403207, 0.5420896, 0, -0.5420896, 0.8403207, 0, 1.9293891, 0) @@ -33,14 +31,11 @@ layer = 100 [node name="UserInterface" parent="UI" instance=ExtResource("3_hflkp")] -[node name="Chemistry" parent="." instance=ExtResource("5_q4uld")] -transform = Transform3D(-1.0927847e-08, 0, -0.25, 0, 0.25, 0, 0.25, 0, -1.0927847e-08, -3.030859, 0.55043614, -0.9607215) - -[node name="Drip2" parent="." instance=ExtResource("6_gipex")] -transform = Transform3D(0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 1.3666252, 0.06701976, 0.014619827) - -[node name="FlaskHolder2" parent="." instance=ExtResource("7_064jp")] -transform = Transform3D(0.09002048, 0, -0.04354668, 0, 0.1, 0, 0.04354668, 0, 0.09002048, -3.3602376, 1.0968089, 0.2888375) - [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = ExtResource("8_4kvtl") + +[node name="StaticBody3D" type="StaticBody3D" parent="."] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) +shape = SubResource("WorldBoundaryShape3D_hflkp") diff --git a/scenes/substance_jar.tscn b/scenes/substance_jar.tscn index d5994a1..e6da02d 100644 --- a/scenes/substance_jar.tscn +++ b/scenes/substance_jar.tscn @@ -1,11 +1,8 @@ -[gd_scene load_steps=12 format=3 uid="uid://cw6v8kbi76qak"] +[gd_scene load_steps=7 format=3 uid="uid://cw6v8kbi76qak"] [ext_resource type="Script" uid="uid://bjnv2g1ni0525" path="res://src/drag/draggable_object.gd" id="1_o7vug"] [ext_resource type="ArrayMesh" uid="uid://dddqboph2ygmw" path="res://assets/meshes/jar.res" id="2_o7vug"] -[ext_resource type="Script" uid="uid://ctu7escah5lo1" path="res://src/interactible/interaction_source.gd" id="3_00jpx"] -[ext_resource type="Script" uid="uid://e8xu57ewvb5a" path="res://src/interactible/proximity_rotator.gd" id="4_ymvgp"] [ext_resource type="ArrayMesh" uid="uid://dxeseuqcwne1m" path="res://assets/meshes/jar_fill.res" id="6_kfk5m"] -[ext_resource type="Script" uid="uid://co33kqhl3n06u" path="res://src/interactible/destructor.gd" id="7_00jpx"] [ext_resource type="Script" uid="uid://c8epd7gguvyop" path="res://src/substance_holder.gd" id="7_ymvgp"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_pcpcb"] @@ -15,79 +12,21 @@ resource_local_to_scene = true height = 0.5024414 radius = 0.22460938 -[sub_resource type="SphereShape3D" id="SphereShape3D_vcwhe"] -radius = 0.49649125 - -[sub_resource type="Curve" id="Curve_qb0nw"] -_data = [Vector2(0, 0), 0.0, 0.067761436, 0, 0, Vector2(0.75, 1), 0.0, 0.0, 0, 0] -point_count = 2 - [node name="Flask" type="Area3D"] script = ExtResource("1_o7vug") [node name="Jar" type="MeshInstance3D" parent="."] -transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, -0.20877336, 0) +transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0) mesh = ExtResource("2_o7vug") [node name="JarFill" type="MeshInstance3D" parent="."] -transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, -0.20759426, 0) +transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0) material_override = SubResource("StandardMaterial3D_pcpcb") mesh = ExtResource("6_kfk5m") [node name="DragArea" type="CollisionShape3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.04284668, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.25, 0) shape = SubResource("CylinderShape3D_kfk5m") -[node name="InteractionArea" type="Area3D" parent="." node_paths=PackedStringArray("interaction_dialog")] -collision_layer = 4 -collision_mask = 4 -input_ray_pickable = false -script = ExtResource("3_00jpx") -interaction_dialog = NodePath("../InteractionDialog") - -[node name="InteractionArea" type="CollisionShape3D" parent="InteractionArea"] -shape = SubResource("SphereShape3D_vcwhe") - -[node name="ProximityRotator" type="Node" parent="." node_paths=PackedStringArray("rotated")] -script = ExtResource("4_ymvgp") -rotated = NodePath("..") -proximity_radius = 0.1 -modification_curve = SubResource("Curve_qb0nw") - -[node name="InteractionDialog" type="ConfirmationDialog" parent="."] -oversampling_override = 1.0 -position = Vector2i(0, 36) -size = Vector2i(200, 131) -borderless = true - -[node name="VBoxContainer" type="VBoxContainer" parent="InteractionDialog"] -offset_left = 8.0 -offset_top = 8.0 -offset_right = 192.0 -offset_bottom = 82.0 - -[node name="Label" type="Label" parent="InteractionDialog/VBoxContainer"] -layout_mode = 2 -text = "Введите объём" - -[node name="HBoxContainer" type="HBoxContainer" parent="InteractionDialog/VBoxContainer"] -layout_mode = 2 - -[node name="SpinBox" type="SpinBox" parent="InteractionDialog/VBoxContainer/HBoxContainer"] -layout_mode = 2 -max_value = 10.0 -step = 0.01 -allow_greater = true -suffix = "мг" - -[node name="DestructorOnStop" type="Node" parent="." node_paths=PackedStringArray("node")] -script = ExtResource("7_00jpx") -node = NodePath("..") - [node name="SubstanceData" type="Node" parent="."] script = ExtResource("7_ymvgp") - -[connection signal="drag_ended" from="." to="InteractionArea" method="request_interaction"] -[connection signal="interaction_closed" from="InteractionArea" to="DestructorOnStop" method="destruct"] -[connection signal="interaction_reciever_entered" from="InteractionArea" to="ProximityRotator" method="_on_interaction_area_interaction_reciever_entered"] -[connection signal="interaction_reciever_exited" from="InteractionArea" to="ProximityRotator" method="_on_interaction_area_interaction_reciever_exited"] diff --git a/src/drag/draggable_camera.gd b/src/drag/draggable_camera.gd index 6c89dae..051823e 100644 --- a/src/drag/draggable_camera.gd +++ b/src/drag/draggable_camera.gd @@ -2,7 +2,15 @@ extends Camera3D const SENSITIVITY = 0.01 +var plane_position: Vector3 +@onready var drag_raycast: RayCast3D = $DragRaycast + +func _process(_delta: float) -> void: + drag_raycast.target_position = project_local_ray_normal(get_viewport().get_mouse_position()) * 10.0 + if drag_raycast.is_colliding(): + plane_position = drag_raycast.get_collision_point() + func _input(event: InputEvent) -> void: if Input.is_action_pressed("drag_camera") and event is InputEventMouseMotion: - global_position -= global_basis.x * event.relative.x * SENSITIVITY - global_position += global_basis.y * event.relative.y * SENSITIVITY + global_position -= Vector3.RIGHT * event.relative.x * SENSITIVITY + global_position += Vector3.FORWARD * event.relative.y * SENSITIVITY diff --git a/src/drag/draggable_object.gd b/src/drag/draggable_object.gd index b4434fe..e698997 100644 --- a/src/drag/draggable_object.gd +++ b/src/drag/draggable_object.gd @@ -18,8 +18,8 @@ func _process(_delta: float) -> void: if dragged == false: return var camera: Camera3D = get_viewport().get_camera_3d() - var new_position: Vector3 = camera.project_position(get_viewport().get_mouse_position(),(-camera.basis.z).dot(camera.to_local(global_position))) - global_position = new_position + #var new_position: Vector3 = camera.project_position(get_viewport().get_mouse_position(),(-camera.basis.z).dot(camera.to_local(global_position))) + global_position = camera.plane_position func _input(event: InputEvent) -> void: if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT: diff --git a/src/interactible/destructor.gd b/src/interactible/destructor.gd deleted file mode 100644 index 332e2e6..0000000 --- a/src/interactible/destructor.gd +++ /dev/null @@ -1,6 +0,0 @@ -extends Node - -@export var node: Node3D - -func destruct() -> void: - node.queue_free() diff --git a/src/interactible/destructor.gd.uid b/src/interactible/destructor.gd.uid deleted file mode 100644 index 763f7f6..0000000 --- a/src/interactible/destructor.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://co33kqhl3n06u diff --git a/src/interactible/interactible.gd b/src/interactible/interactible.gd new file mode 100644 index 0000000..7c95d06 --- /dev/null +++ b/src/interactible/interactible.gd @@ -0,0 +1,11 @@ +extends ConfirmationDialog + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/src/interactible/interactible.gd.uid b/src/interactible/interactible.gd.uid new file mode 100644 index 0000000..d5638f6 --- /dev/null +++ b/src/interactible/interactible.gd.uid @@ -0,0 +1 @@ +uid://bl0ojhc0thk1p diff --git a/src/interactible/interaction_reciever.gd b/src/interactible/interaction_reciever.gd deleted file mode 100644 index 79e3fc9..0000000 --- a/src/interactible/interaction_reciever.gd +++ /dev/null @@ -1,17 +0,0 @@ -extends Area3D - -class_name InteractionReciever - -signal interaction_start(source: InteractionSource) - -func _ready() -> void: - area_entered.connect(on_area_entered) - area_exited.connect(on_area_exited) - -func on_area_entered(area: Area3D): - if area is InteractionSource: - area.interaction_requested.connect(interaction_start.emit) - -func on_area_exited(area: Area3D): - if area is InteractionSource: - area.interaction_requested.disconnect(interaction_start.emit) diff --git a/src/interactible/interaction_reciever.gd.uid b/src/interactible/interaction_reciever.gd.uid deleted file mode 100644 index 6cce45d..0000000 --- a/src/interactible/interaction_reciever.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://mjx50qh1bwv3 diff --git a/src/interactible/interaction_source.gd b/src/interactible/interaction_source.gd deleted file mode 100644 index cdb842f..0000000 --- a/src/interactible/interaction_source.gd +++ /dev/null @@ -1,34 +0,0 @@ -extends Area3D - -class_name InteractionSource - -@export var interaction_dialog: ConfirmationDialog -var recievers: int = 0 - -signal interaction_requested -signal interaction_closed -signal interaction_reciever_entered(reicever: InteractionReciever) -signal interaction_reciever_exited(reicever: InteractionReciever) - -func _ready() -> void: - area_entered.connect(on_area_entered) - area_exited.connect(on_area_exited) - interaction_dialog.canceled.connect(interaction_closed.emit) - interaction_dialog.confirmed.connect(interaction_closed.emit) - -func on_area_entered(area: Area3D): - if area is InteractionReciever: - interaction_reciever_entered.emit(area) - recievers += 1 - -func on_area_exited(area: Area3D): - if area is InteractionReciever: - interaction_reciever_exited.emit(area) - recievers -= 1 - -func request_interaction() -> void: - if recievers == 0: - interaction_closed.emit() - return - interaction_requested.emit() - interaction_dialog.popup_centered() diff --git a/src/interactible/interaction_source.gd.uid b/src/interactible/interaction_source.gd.uid deleted file mode 100644 index 0e8571e..0000000 --- a/src/interactible/interaction_source.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ctu7escah5lo1 diff --git a/src/interactible/proximity_rotator.gd b/src/interactible/proximity_rotator.gd deleted file mode 100644 index 3000d9f..0000000 --- a/src/interactible/proximity_rotator.gd +++ /dev/null @@ -1,32 +0,0 @@ -extends Node - -@export var rotated: Node3D -@export var proximity_radius: float -@export var modification_curve: Curve -var start_rotation -var reciever: InteractionReciever - -func _ready() -> void: - start_rotation = rotated.quaternion - -func _on_interaction_area_interaction_reciever_entered(rec: InteractionReciever) -> void: - if reciever == null: - reciever = rec - - -func _on_interaction_area_interaction_reciever_exited(rec: InteractionReciever) -> void: - if reciever == rec: - reciever = null - rotated.quaternion = start_rotation - -func _process(_delta: float) -> void: - if reciever == null: - rotated.quaternion = start_rotation - return - - var camera: Camera3D = get_viewport().get_camera_3d() - var rotation_direction : float = -sign(camera.basis.x.dot(reciever.global_position - rotated.global_position)) - var result_quaternion: Quaternion = Quaternion(-camera.basis.z,PI + 1.5707963267948966 * rotation_direction) - var distance_without_y: float = Vector2(rotated.global_position.x,rotated.global_position.z).distance_to(Vector2(reciever.global_position.x,reciever.global_position.z)) - var calculated_angle: Quaternion = start_rotation.slerp(result_quaternion,modification_curve.sample(clamp(proximity_radius/distance_without_y,0,1))) - rotated.quaternion = calculated_angle diff --git a/src/interactible/proximity_rotator.gd.uid b/src/interactible/proximity_rotator.gd.uid deleted file mode 100644 index 6f976ae..0000000 --- a/src/interactible/proximity_rotator.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://e8xu57ewvb5a diff --git a/src/interactible/returner.gd b/src/interactible/returner.gd deleted file mode 100644 index 1a87ba3..0000000 --- a/src/interactible/returner.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends Node - -@export var node: Node3D -@onready var start_position: Vector3 = node.global_position - -func return_to_start() -> void: - node.global_position = start_position diff --git a/src/interactible/returner.gd.uid b/src/interactible/returner.gd.uid deleted file mode 100644 index d4eee65..0000000 --- a/src/interactible/returner.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://b1gv6dt8bwj2p