diff --git a/override.cfg b/override.cfg index 0d1998e..4cd32b3 100644 --- a/override.cfg +++ b/override.cfg @@ -1,3 +1,3 @@ [xr] -openxr/enabled=false +openxr/enabled=true diff --git a/project.godot b/project.godot index f3f5a01..e78137e 100644 --- a/project.godot +++ b/project.godot @@ -63,6 +63,9 @@ trigger_left={ [layer_names] +3d_render/layer_1="static geometry" +3d_render/layer_2="manipulators" +3d_render/layer_3="targets" 3d_render/layer_20="particle_collision_proxy" 3d_physics/layer_1="Static World" 3d_physics/layer_2="Dynamic World" diff --git a/scenes/manipulator.gd b/scenes/manipulator.gd new file mode 100644 index 0000000..7fe3144 --- /dev/null +++ b/scenes/manipulator.gd @@ -0,0 +1,38 @@ +# keeps the visual mesh in sync with the attractor radius, and allows the +# attractor radius to be scaled by joystick input of the controller holding the +# object. +extends Node3D + +@onready var mesh: MeshInstance3D = $Bounds +@onready var attractor: GPUParticlesAttractorSphere3D = $GPUParticlesAttractorSphere3D + +var held_controller: XRController3D = null +const MIN_SCALE = 0.5 +const MAX_SCALE = 10 +const SCALE_SPEED = 1.0 + +var initial_rotation: Vector3 = Vector3.ZERO + +func _ready() -> void: + initial_rotation = attractor.global_rotation + +func _process(delta: float) -> void: + # Keep attractor radius in sync with mesh scale + mesh.scale = Vector3(attractor.radius, attractor.radius, attractor.radius) + + # Keep attractor's global rotation fixed + attractor.global_rotation = initial_rotation + + # Adjust scale based on controller input if being held + if held_controller: + var joystick_y = held_controller.get_vector2("primary").y + if abs(joystick_y) > 0.1: + var new_radius = attractor.radius + (joystick_y * SCALE_SPEED * delta) + attractor.radius = clamp(new_radius, MIN_SCALE, MAX_SCALE) + + +func _on_pickable_object_picked_up(pickable: XRToolsPickable) -> void: + held_controller = pickable.get_picked_up_by_controller() + +func _on_pickable_object_dropped(_pickable: XRToolsPickable) -> void: + held_controller = null diff --git a/scenes/manipulator.tscn b/scenes/manipulator.tscn new file mode 100644 index 0000000..44600af --- /dev/null +++ b/scenes/manipulator.tscn @@ -0,0 +1,62 @@ +[gd_scene load_steps=11 format=3 uid="uid://bixan352mi1j6"] + +[ext_resource type="PackedScene" uid="uid://c8l60rnugru40" path="res://addons/godot-xr-tools/objects/pickable.tscn" id="1_dshke"] +[ext_resource type="PackedScene" uid="uid://c25yxb0vt53vc" path="res://addons/godot-xr-tools/objects/grab_points/grab_point_hand_left.tscn" id="2_m3e5t"] +[ext_resource type="PackedScene" uid="uid://ctw7nbntd5pcj" path="res://addons/godot-xr-tools/objects/grab_points/grab_point_hand_right.tscn" id="3_1s35s"] +[ext_resource type="Script" path="res://scenes/manipulator.gd" id="4_25j3l"] +[ext_resource type="Shader" uid="uid://dilr5r6k3ik7t" path="res://scenes/manipulatorsphere.tres" id="4_ewjtf"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_f261g"] +radius = 0.1 + +[sub_resource type="SphereMesh" id="SphereMesh_mou0a"] +radius = 0.1 +height = 0.2 + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ljyno"] +albedo_color = Color(0, 0.470085, 0.308113, 1) +emission_enabled = true +emission = Color(1.44392e-06, 0.591371, 0.38197, 1) +emission_energy_multiplier = 0.22 + +[sub_resource type="SphereMesh" id="SphereMesh_56y52"] +radius = 1.0 +height = 2.0 + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_1u5an"] +render_priority = 0 +shader = ExtResource("4_ewjtf") +shader_parameter/Albedo = Color(1, 1, 1, 1) + +[node name="Manipulator" instance=ExtResource("1_dshke")] +lock_rotation = true +freeze = true +release_mode = 1 +ranged_grab_method = 0 +second_hand_grab = 1 + +[node name="CollisionShape3D" parent="." index="0"] +shape = SubResource("SphereShape3D_f261g") + +[node name="Visual" type="MeshInstance3D" parent="." index="1"] +layers = 2 +mesh = SubResource("SphereMesh_mou0a") +surface_material_override/0 = SubResource("StandardMaterial3D_ljyno") + +[node name="GrabPointHandLeft" parent="." index="2" instance=ExtResource("2_m3e5t")] + +[node name="GrabPointHandRight" parent="." index="3" instance=ExtResource("3_1s35s")] + +[node name="ManipulatorSync" type="Node3D" parent="." index="4"] +script = ExtResource("4_25j3l") + +[node name="Bounds" type="MeshInstance3D" parent="ManipulatorSync" index="0"] +layers = 2 +mesh = SubResource("SphereMesh_56y52") +skeleton = NodePath("../..") +surface_material_override/0 = SubResource("ShaderMaterial_1u5an") + +[node name="GPUParticlesAttractorSphere3D" type="GPUParticlesAttractorSphere3D" parent="ManipulatorSync" index="1"] + +[connection signal="dropped" from="." to="ManipulatorSync" method="_on_pickable_object_dropped"] +[connection signal="picked_up" from="." to="ManipulatorSync" method="_on_pickable_object_picked_up"] diff --git a/scenes/manipulatorsphere.tres b/scenes/manipulatorsphere.tres new file mode 100644 index 0000000..da6c4f5 --- /dev/null +++ b/scenes/manipulatorsphere.tres @@ -0,0 +1,80 @@ +[gd_resource type="VisualShader" load_steps=7 format=3 uid="uid://dilr5r6k3ik7t"] + +[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_5b52k"] +input_name = "normal" + +[sub_resource type="VisualShaderNodeDotProduct" id="VisualShaderNodeDotProduct_ktfjh"] + +[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_s5g41"] +input_name = "view" + +[sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_1sq4e"] +default_input_values = [0, 1.0, 1, 0.0] +operator = 1 + +[sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_sui6q"] +default_input_values = [0, 0.0, 1, 5.0] +operator = 5 + +[sub_resource type="VisualShaderNodeColorParameter" id="VisualShaderNodeColorParameter_mm7j8"] +parameter_name = "Albedo" +default_value_enabled = true + +[resource] +code = "shader_type spatial; +render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx; + +uniform vec4 Albedo : source_color = vec4(1.000000, 1.000000, 1.000000, 1.000000); + + + +void fragment() { +// ColorParameter:8 + vec4 n_out8p0 = Albedo; + + +// Input:2 + vec3 n_out2p0 = NORMAL; + + +// Input:4 + vec3 n_out4p0 = VIEW; + + +// DotProduct:3 + float n_out3p0 = dot(n_out2p0, n_out4p0); + + +// FloatOp:5 + float n_in5p0 = 1.00000; + float n_out5p0 = n_in5p0 - n_out3p0; + + +// FloatOp:6 + float n_in6p1 = 5.00000; + float n_out6p0 = pow(n_out5p0, n_in6p1); + + +// Output:0 + ALBEDO = vec3(n_out8p0.xyz); + ALPHA = n_out6p0; + EMISSION = vec3(n_out6p0); + + +} +" +graph_offset = Vector2(-471.144, 48.9653) +nodes/fragment/0/position = Vector2(620, 180) +nodes/fragment/2/node = SubResource("VisualShaderNodeInput_5b52k") +nodes/fragment/2/position = Vector2(-940, 280) +nodes/fragment/3/node = SubResource("VisualShaderNodeDotProduct_ktfjh") +nodes/fragment/3/position = Vector2(-420, 280) +nodes/fragment/4/node = SubResource("VisualShaderNodeInput_s5g41") +nodes/fragment/4/position = Vector2(-940, 500) +nodes/fragment/5/node = SubResource("VisualShaderNodeFloatOp_1sq4e") +nodes/fragment/5/position = Vector2(-80, 180) +nodes/fragment/6/node = SubResource("VisualShaderNodeFloatOp_sui6q") +nodes/fragment/6/position = Vector2(280, 180) +nodes/fragment/8/node = SubResource("VisualShaderNodeColorParameter_mm7j8") +nodes/fragment/8/position = Vector2(-940, 720) +nodes/fragment/connections = PackedInt32Array(2, 0, 3, 0, 4, 0, 3, 1, 3, 0, 5, 1, 6, 0, 0, 1, 5, 0, 6, 0, 8, 0, 0, 0, 6, 0, 0, 5) diff --git a/scenes/particle_test.gdshader b/scenes/particle_test.gdshader index 0d7f114..4194e34 100644 --- a/scenes/particle_test.gdshader +++ b/scenes/particle_test.gdshader @@ -62,5 +62,5 @@ void vertex() { void fragment() { ALBEDO = vec3(1.0, 0.0, 0.0); - ALPHA = 0.05f; + ALPHA = 0.01f; } diff --git a/scenes/proxy_collision_detector.gd b/scenes/proxy_collision_detector.gd index 4ca54e7..ddf1155 100644 --- a/scenes/proxy_collision_detector.gd +++ b/scenes/proxy_collision_detector.gd @@ -62,9 +62,11 @@ func _ready(): # Clone the source particles and set the shader material. clone_particles = source_particles.duplicate() - # duplicate the draw pass so we don't affect the original. - clone_particles.draw_pass_1 = clone_particles.draw_pass_1.duplicate() - # replace with the special material + # diable trails since they add extra meshes. + clone_particles.trail_enabled = false + # replace the draw pass with a simple quad mesh. + clone_particles.draw_pass_1 = QuadMesh.new() + # and set the special material clone_particles.draw_pass_1.surface_set_material(0, shader_material) # set visual layer to 20 so it doesn't draw on main camera clone_particles.layers = 0 diff --git a/scenes/title_scene.GPUParticlesCollisionSDF3D_data.exr b/scenes/title_scene.GPUParticlesCollisionSDF3D_data.exr index daa0577..878c13e 100644 Binary files a/scenes/title_scene.GPUParticlesCollisionSDF3D_data.exr and b/scenes/title_scene.GPUParticlesCollisionSDF3D_data.exr differ diff --git a/scenes/title_scene.tscn b/scenes/title_scene.tscn index 1e3eafb..63b5de5 100644 --- a/scenes/title_scene.tscn +++ b/scenes/title_scene.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=31 format=3 uid="uid://bd86thqpujh3p"] +[gd_scene load_steps=32 format=3 uid="uid://bd86thqpujh3p"] [ext_resource type="Script" path="res://addons/godot-xr-tools/staging/scene_base.gd" id="1_t86sx"] [ext_resource type="PackedScene" uid="uid://7uc6tf2tvn1k" path="res://scenes/xr_origin_3d.tscn" id="2_xk21l"] @@ -9,6 +9,7 @@ [ext_resource type="PackedScene" uid="uid://rsrnbs08nv1n" path="res://scenes/proxy_collision_detector.tscn" id="7_1kkxh"] [ext_resource type="PackedScene" uid="uid://c20kawop2lrv" path="res://assets/Arcane Source 2.glb" id="8_h17hj"] [ext_resource type="Script" path="res://scenes/target_highlight_test.gd" id="9_jig6v"] +[ext_resource type="PackedScene" uid="uid://bixan352mi1j6" path="res://scenes/manipulator.tscn" id="10_dms3y"] [sub_resource type="Sky" id="Sky_c23dr"] @@ -115,7 +116,7 @@ transparency = 1 albedo_color = Color(1, 1, 1, 0.3) emission_enabled = true emission = Color(1, 1, 1, 1) -emission_energy_multiplier = 7.57 +emission_energy_multiplier = 0.61 rim = 0.38 refraction_scale = 0.88 @@ -128,11 +129,12 @@ emission_energy_multiplier = 0.61 rim = 0.38 refraction_scale = 0.88 -[sub_resource type="QuadMesh" id="QuadMesh_2imrf"] +[sub_resource type="PrismMesh" id="PrismMesh_be80n"] +size = Vector3(0.2, 0.2, 0.2) -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_6ry38"] -resource_local_to_scene = true -shading_mode = 0 +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_hyt1m"] +emission_enabled = true +emission = Color(0.208505, 0.70691, 0.626474, 1) [node name="TitleScene" type="Node3D"] script = ExtResource("1_t86sx") @@ -177,7 +179,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.26492, 1.52311, -8.99933) cast_shadow = 0 gi_mode = 2 amount = 1000 -lifetime = 10.0 +lifetime = 15.0 randomness = 0.18 visibility_aabb = AABB(-100, -100, -100, 200, 200, 200) transform_align = 2 @@ -188,18 +190,11 @@ draw_pass_1 = SubResource("TubeTrailMesh_xiw4w") [node name="GPUParticlesCollisionSDF3D" type="GPUParticlesCollisionSDF3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.171387, 1.63794, -9.15827) -visible = false size = Vector3(13.1045, 5.27588, 4.47766) +bake_mask = 4293918721 texture = ExtResource("6_l378m") -[node name="GPUParticlesAttractorBox3D" type="GPUParticlesAttractorBox3D" parent="."] -transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 3.63926, -9.75923) -strength = 50.13 -attenuation = 4.43828 -size = Vector3(6, 6, 6) - [node name="ProxyCollisionDetector" parent="." instance=ExtResource("7_1kkxh")] -debug_mesh_path = NodePath("../DebugMesh") source_particles_path = NodePath("../GPUParticles3D") target_collision_shapes_paths = Array[NodePath]([NodePath("../Target/CollisionShape3D"), NodePath("../Target2/CollisionShape3D")]) @@ -214,6 +209,7 @@ script = ExtResource("9_jig6v") shape = SubResource("BoxShape3D_gofwq") [node name="MeshInstance3D" type="MeshInstance3D" parent="Target"] +layers = 4 mesh = SubResource("BoxMesh_0cc1r") skeleton = NodePath("../..") surface_material_override/0 = SubResource("StandardMaterial3D_fof64") @@ -227,14 +223,38 @@ index = 1 shape = SubResource("BoxShape3D_gofwq") [node name="MeshInstance3D" type="MeshInstance3D" parent="Target2"] +layers = 4 mesh = SubResource("BoxMesh_0cc1r") skeleton = NodePath("../..") surface_material_override/0 = SubResource("StandardMaterial3D_n0pd7") -[node name="DebugMesh" type="MeshInstance3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.74113, 5.01477, -10.7979) -mesh = SubResource("QuadMesh_2imrf") -surface_material_override/0 = SubResource("StandardMaterial3D_6ry38") +[node name="Manipulator0" parent="." instance=ExtResource("10_dms3y")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.63926, -9.75923) + +[node name="Bounds" parent="Manipulator0/ManipulatorSync" index="0"] +transform = Transform3D(3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0) + +[node name="GPUParticlesAttractorSphere3D" parent="Manipulator0/ManipulatorSync" index="1"] +strength = 19.33 +attenuation = 2.82316 +radius = 3.0 + +[node name="Manipulator1" parent="." instance=ExtResource("10_dms3y")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.6324, 2.25799, -6.74718) + +[node name="GPUParticlesAttractorSphere3D" parent="Manipulator1/ManipulatorSync" index="1"] +strength = 19.33 +attenuation = 2.82316 +directionality = 1.0 + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Manipulator1/ManipulatorSync/GPUParticlesAttractorSphere3D" index="0"] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, -0.141177) +mesh = SubResource("PrismMesh_be80n") +skeleton = NodePath("../../..") +surface_material_override/0 = SubResource("StandardMaterial3D_hyt1m") [connection signal="target_occupancy_changed" from="ProxyCollisionDetector" to="Target" method="_on_proxy_collision_detector_target_occupancy_changed"] [connection signal="target_occupancy_changed" from="ProxyCollisionDetector" to="Target2" method="_on_proxy_collision_detector_target_occupancy_changed"] + +[editable path="Manipulator0"] +[editable path="Manipulator1"] diff --git a/scenes/xr_origin_3d.tscn b/scenes/xr_origin_3d.tscn index 8276a83..991ece9 100644 --- a/scenes/xr_origin_3d.tscn +++ b/scenes/xr_origin_3d.tscn @@ -33,6 +33,8 @@ tracker = &"left_hand" [node name="LeftHand" parent="LeftHand" instance=ExtResource("1_gehoc")] [node name="FunctionPickup" parent="LeftHand" instance=ExtResource("2_sqnjc")] +grab_distance = 0.1 +ranged_enable = false [node name="RightHand" type="XRController3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, 1, 0) @@ -41,6 +43,8 @@ tracker = &"right_hand" [node name="RightHand" parent="RightHand" instance=ExtResource("3_7rd4f")] [node name="FunctionPickup" parent="RightHand" instance=ExtResource("2_sqnjc")] +grab_distance = 0.1 +ranged_enable = false [node name="MovementWorldGrab" parent="." instance=ExtResource("4_ou5a5")] order = 5