From dfc85cb32b7f3be66cac1a88153c452514e4e67a Mon Sep 17 00:00:00 2001 From: copygirl Date: Thu, 19 Dec 2024 19:14:43 +0100 Subject: [PATCH] Turn landmark template into scene --- Resources/debug_landmark.tscn | 15 +++++++++++++++ copyMediaPipe.gd | 12 ++++-------- copyMediaPipe.tscn | 16 ---------------- 3 files changed, 19 insertions(+), 24 deletions(-) create mode 100644 Resources/debug_landmark.tscn diff --git a/Resources/debug_landmark.tscn b/Resources/debug_landmark.tscn new file mode 100644 index 0000000..06ed767 --- /dev/null +++ b/Resources/debug_landmark.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3 uid="uid://cpyvu3hjbn4rh"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_wrvph"] +shading_mode = 0 +albedo_color = Color(0, 1, 0, 1) + +[sub_resource type="SphereMesh" id="SphereMesh_xb663"] +material = SubResource("StandardMaterial3D_wrvph") +radius = 0.005 +height = 0.01 +radial_segments = 6 +rings = 3 + +[node name="DebugLandmark" type="MeshInstance3D"] +mesh = SubResource("SphereMesh_xb663") diff --git a/copyMediaPipe.gd b/copyMediaPipe.gd index 04a14b9..9ff5788 100644 --- a/copyMediaPipe.gd +++ b/copyMediaPipe.gd @@ -1,8 +1,6 @@ class_name copyMediaPipe extends Mod_Base -var Blendshapes = preload("res://Mods/MediaPipe/MediaPipeController_BlendShapes.gd") - # ----------------------------------------------------------------------------- # Potentially configurable variables. # ----------------------------------------------------------------------------- @@ -29,15 +27,12 @@ var camera_aspect_ratio := 4.0 / 3.0 # Logitech C920 default? var ik_chains: Array[copyMediaPipe_IKChain] = [] @onready var tracking_root: Node3D = $TrackingRoot -@onready var landmark_template: MeshInstance3D = $TrackingRoot/LandmarkTemplate - @onready var head := { last_data = null, # Most recent tracking data received. last_received = INF, # How long ago it was received (in seconds). tracker = $TrackingRoot/Head, # Node for visualizing tracking data. rest_pose = Transform3D.IDENTITY, # Rest position of the head. } - @onready var hands := { left = { last_data = null, @@ -95,12 +90,11 @@ func _process(delta: float) -> void: ## Sets up 21 nodes for the landmarks that make up hand/finger tracking. func setup_hand_landmarks() -> void: + const landmark_scene := preload("Resources/debug_landmark.tscn") for side in hands: var hand = hands[side] for i in 21: - var landmark: MeshInstance3D = landmark_template.duplicate(0) - landmark.position = Vector3.ZERO - landmark.visible = true + var landmark := landmark_scene.instantiate() hand.tracker.add_child(landmark) hand.landmarks.append(landmark) @@ -355,6 +349,8 @@ func update_ik_chains() -> void: chain.do_ik_chain() func update_blendshapes() -> void: + const Blendshapes := preload("res://Mods/MediaPipe/MediaPipeController_BlendShapes.gd") + var model := get_model() if (not model) or (not head.last_data): return var data: Dictionary = head.last_data.blendshapes diff --git a/copyMediaPipe.tscn b/copyMediaPipe.tscn index 390ed9c..865d349 100644 --- a/copyMediaPipe.tscn +++ b/copyMediaPipe.tscn @@ -6,17 +6,6 @@ [sub_resource type="BoxMesh" id="BoxMesh_wtdv4"] size = Vector3(0.2, 0.2, 0.2) -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_wrvph"] -shading_mode = 0 -albedo_color = Color(0, 1, 0, 1) - -[sub_resource type="SphereMesh" id="SphereMesh_xb663"] -material = SubResource("StandardMaterial3D_wrvph") -radius = 0.005 -height = 0.01 -radial_segments = 6 -rings = 3 - [node name="copyMediaPipe" type="Node"] script = ExtResource("1_0kpr8") @@ -43,8 +32,3 @@ transform = Transform3D(1.91069e-15, -1, 4.37114e-08, -4.37114e-08, -4.37114e-08 [node name="DebugVisuals" parent="TrackingRoot/RightHand" instance=ExtResource("2_8wmot")] visible = false - -[node name="LandmarkTemplate" type="MeshInstance3D" parent="TrackingRoot"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) -visible = false -mesh = SubResource("SphereMesh_xb663")