From 03359ccd04a19b0983609aefe570696f7b2e6946 Mon Sep 17 00:00:00 2001 From: Snorre Date: Sat, 5 Apr 2025 02:54:16 +0200 Subject: [PATCH] added the ability to grab bananer --- flake.nix | 3 ++ project.godot | 2 +- scenes/XrOrigin3d.cs | 19 -------- scenes/test.tscn | 63 +++++++++++++++++++++++++-- scripts/XRHand.cs | 41 +++++++++++++++++ scripts/XRHand.cs.uid | 1 + scripts/XrOrigin3d.cs | 19 ++++++++ {scenes => scripts}/XrOrigin3d.cs.uid | 0 8 files changed, 124 insertions(+), 24 deletions(-) delete mode 100644 scenes/XrOrigin3d.cs create mode 100644 scripts/XRHand.cs create mode 100644 scripts/XRHand.cs.uid create mode 100644 scripts/XrOrigin3d.cs rename {scenes => scripts}/XrOrigin3d.cs.uid (100%) diff --git a/flake.nix b/flake.nix index 8143f76..ed08aa8 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,9 @@ godot_4-mono ]; }; + shellHook = '' + godot4-mono -e 2>/dev/null 1>&2 & disown + ''; }; }; } diff --git a/project.godot b/project.godot index 76a7581..d44c7b3 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="nordic25" -config/features=PackedStringArray("4.4", "Forward Plus") +config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/icon="res://icon.svg" [dotnet] diff --git a/scenes/XrOrigin3d.cs b/scenes/XrOrigin3d.cs deleted file mode 100644 index 795ef7f..0000000 --- a/scenes/XrOrigin3d.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Godot; -using System; - -public partial class XrOrigin3d : XROrigin3D -{ - private XRInterface _xrInterface; - - public override void _Ready() - { - _xrInterface = XRServer.FindInterface("OpenXR"); - if (_xrInterface == null || !_xrInterface.IsInitialized()) - GD.PushError("Failed to initialize OpenXR"); - - GD.PushError("OpenXR Initialized successfully"); - - DisplayServer.WindowSetVsyncMode(DisplayServer.VSyncMode.Disabled); - GetViewport().UseXR = true; - } -} diff --git a/scenes/test.tscn b/scenes/test.tscn index 2ff2825..6128f33 100644 --- a/scenes/test.tscn +++ b/scenes/test.tscn @@ -1,27 +1,82 @@ -[gd_scene load_steps=3 format=3 uid="uid://din25343yu8wv"] +[gd_scene load_steps=11 format=3 uid="uid://din25343yu8wv"] -[ext_resource type="Script" uid="uid://dglj0x0bpkx5i" path="res://scenes/XrOrigin3d.cs" id="1_errlg"] +[ext_resource type="PackedScene" uid="uid://csh2n73hb2co8" path="res://models/banana.fbx" id="2_bl13t"] +[ext_resource type="Script" uid="uid://bf27rxigs8b22" path="res://scripts/XRHand.cs" id="2_iyx0m"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_ij1v8"] +radius = 0.1 +height = 0.2 + +[sub_resource type="SphereShape3D" id="SphereShape3D_iyx0m"] radius = 0.01 -height = 0.02 + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_bl13t"] + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_iyx0m"] +noise = SubResource("FastNoiseLite_bl13t") + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_74lek"] +albedo_texture = SubResource("NoiseTexture2D_iyx0m") + +[sub_resource type="PlaneMesh" id="PlaneMesh_j5jx5"] +material = SubResource("StandardMaterial3D_74lek") +size = Vector2(20, 20) + +[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_lpvoh"] + +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_74lek"] +radius = 0.02 +height = 0.113069 [node name="Node3D" type="Node3D"] [node name="XROrigin3D" type="XROrigin3D" parent="."] current = true -script = ExtResource("1_errlg") [node name="LeftHand" type="XRController3D" parent="XROrigin3D"] tracker = &"left_hand" +script = ExtResource("2_iyx0m") [node name="MeshInstance3D" type="MeshInstance3D" parent="XROrigin3D/LeftHand"] mesh = SubResource("CapsuleMesh_ij1v8") +[node name="StaticBody3D" type="StaticBody3D" parent="XROrigin3D/LeftHand"] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="XROrigin3D/LeftHand/StaticBody3D"] +shape = SubResource("SphereShape3D_iyx0m") + [node name="RightHand" type="XRController3D" parent="XROrigin3D"] tracker = &"right_hand" [node name="MeshInstance3D" type="MeshInstance3D" parent="XROrigin3D/RightHand"] mesh = SubResource("CapsuleMesh_ij1v8") +[node name="StaticBody3D" type="StaticBody3D" parent="XROrigin3D/RightHand"] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="XROrigin3D/RightHand/StaticBody3D"] +shape = SubResource("SphereShape3D_iyx0m") + [node name="XRCamera3D" type="XRCamera3D" parent="XROrigin3D"] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +mesh = SubResource("PlaneMesh_j5jx5") +skeleton = NodePath("../XROrigin3D") + +[node name="StaticBody3D" type="StaticBody3D" parent="MeshInstance3D"] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="MeshInstance3D/StaticBody3D"] +shape = SubResource("WorldBoundaryShape3D_lpvoh") + +[node name="Bananan" type="RigidBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0676612, 0.724976, -0.380918) + +[node name="banana" parent="Bananan" instance=ExtResource("2_bl13t")] +transform = Transform3D(0.02, 0, 0, 0, 0.02, 0, 0, 0, 0.02, 0, 0, 0) + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Bananan"] +transform = Transform3D(1, 0, 0, 0, 0.816107, -0.5779, 0, 0.5779, 0.816107, 0, -0.0504407, -0.0107305) +shape = SubResource("CapsuleShape3D_74lek") + +[node name="CollisionShape3D2" type="CollisionShape3D" parent="Bananan"] +transform = Transform3D(1, 0, 0, 0, -0.837394, -0.546599, 0, 0.546599, -0.837394, 0, 0.025557, -0.00612295) +shape = SubResource("CapsuleShape3D_74lek") diff --git a/scripts/XRHand.cs b/scripts/XRHand.cs new file mode 100644 index 0000000..b6685d9 --- /dev/null +++ b/scripts/XRHand.cs @@ -0,0 +1,41 @@ +using Godot; +using System.Collections.Generic; + +public partial class XRHand : XRController3D +{ + List joints = new(); + + [Export] + StaticBody3D body; + + [Export] + float strength = 1.0f; + + public void _Update(float delta) + { + if ((bool)GetInput("trigger_click")) + { + var query = new PhysicsShapeQueryParameters3D(); + var sphere = new SphereShape3D(); + sphere.Radius = 0.1f; + query.Shape = sphere; + query.CollideWithBodies = true; + query.CollideWithAreas = false; + query.Transform = ((Node3D)GetParent()).GlobalTransform; + var overlaps = GetWorld3D().DirectSpaceState.IntersectShape(query); + foreach (var fuckingcollider in overlaps) + { + var collider = (Node3D)fuckingcollider["collider"]; + Generic6DofJoint3D joint = new(); + joint.NodeA = GetPathTo(body); + joint.NodeB = collider.GetPath(); + joints.Add(joint); + AddChild(joint); + } + } else if (joints.Count > 0) { + foreach (var joint in joints) + joint.QueueFree(); + joints.Clear(); + } + } +} diff --git a/scripts/XRHand.cs.uid b/scripts/XRHand.cs.uid new file mode 100644 index 0000000..293c6cf --- /dev/null +++ b/scripts/XRHand.cs.uid @@ -0,0 +1 @@ +uid://bf27rxigs8b22 diff --git a/scripts/XrOrigin3d.cs b/scripts/XrOrigin3d.cs new file mode 100644 index 0000000..acd7033 --- /dev/null +++ b/scripts/XrOrigin3d.cs @@ -0,0 +1,19 @@ +using Godot; +using System; + +public partial class XrOrigin3d : XROrigin3D +{ + private XRInterface _xrInterface; + + public override void _Ready() + { + _xrInterface = XRServer.FindInterface("OpenXR"); + if (_xrInterface == null || !_xrInterface.IsInitialized()) + GD.PushError("Failed to initialize OpenXR"); + + GD.PushError("OpenXR Initialized successfully"); + + DisplayServer.WindowSetVsyncMode(DisplayServer.VSyncMode.Disabled); + GetViewport().UseXR = true; + } +} diff --git a/scenes/XrOrigin3d.cs.uid b/scripts/XrOrigin3d.cs.uid similarity index 100% rename from scenes/XrOrigin3d.cs.uid rename to scripts/XrOrigin3d.cs.uid