From ea3ce8558860f413317cf9c137f70502ff9dcc13 Mon Sep 17 00:00:00 2001 From: Malcolm Nixon Date: Sun, 3 Mar 2024 21:14:26 -0500 Subject: [PATCH] Modified demo to include controls for editing skeleton and world scales. --- demo.gd | 55 +++++++++++++++++++++++++++++++++++++++ demo.tscn | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 demo.gd diff --git a/demo.gd b/demo.gd new file mode 100644 index 0000000..d9f7684 --- /dev/null +++ b/demo.gd @@ -0,0 +1,55 @@ +extends Node3D + + +# Process movement based on keyboard +func _process(delta : float) -> void: + var xform : Transform3D = %Camera3D.global_transform + + # Handle normal W/A/S/D/Q/E buttons + if Input.is_key_pressed(KEY_A): + xform.origin -= xform.basis.x * delta * 2.0 + if Input.is_key_pressed(KEY_D): + xform.origin += xform.basis.x * delta * 2.0 + if Input.is_key_pressed(KEY_W): + xform.origin -= xform.basis.z * delta * 2.0 + if Input.is_key_pressed(KEY_S): + xform.origin += xform.basis.z * delta * 2.0 + if Input.is_key_pressed(KEY_Q): + xform.origin -= xform.basis.y * delta * 2.0 + if Input.is_key_pressed(KEY_E): + xform.origin += xform.basis.y * delta * 2.0 + + %Camera3D.global_transform = xform + + +# Process movement based on mouse events +func _input(event : InputEvent) -> void: + var xform : Transform3D = %Camera3D.global_transform + + # Handle rotation by right-mouse-drag + var motion := event as InputEventMouseMotion + if motion and motion.button_mask & MOUSE_BUTTON_MASK_RIGHT: + xform.basis = Basis(Vector3.UP, -motion.relative.x * 0.001) * xform.basis + xform.basis = Basis(xform.basis.x, -motion.relative.y * 0.001) * xform.basis + + # Handle mouse capture and mouse-wheel movement in/out + var button := event as InputEventMouseButton + if button and button.pressed and button.button_index == MOUSE_BUTTON_RIGHT: + Input.mouse_mode = Input.MOUSE_MODE_CAPTURED + if button and not button.pressed and button.button_index == MOUSE_BUTTON_RIGHT: + Input.mouse_mode = Input.MOUSE_MODE_VISIBLE + if button and button.button_index == MOUSE_BUTTON_WHEEL_UP: + xform.origin -= xform.basis.z * 0.1 + if button and button.button_index == MOUSE_BUTTON_WHEEL_DOWN: + xform.origin += xform.basis.z * 0.1 + + %Camera3D.global_transform = xform + + +func _on_skeleton_spin_box_value_changed(value: float) -> void: + %"Test-Chan/Armature/Skeleton3D".motion_scale = value + %"Test-Kun/Armature/Skeleton3D".motion_scale = value + + +func _on_world_spin_box_value_changed(value: float) -> void: + XRServer.world_scale = value diff --git a/demo.tscn b/demo.tscn index 0432840..277fba5 100644 --- a/demo.tscn +++ b/demo.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=11 format=3 uid="uid://dkkew3u3hi7md"] +[gd_scene load_steps=13 format=3 uid="uid://dkkew3u3hi7md"] +[ext_resource type="Script" path="res://demo.gd" id="1_dt0nj"] [ext_resource type="PackedScene" uid="uid://bhc6nngwjdvum" path="res://assets/test_chan/Test-Chan.fbx" id="1_lkeve"] [ext_resource type="Texture2D" uid="uid://drjoya1j38i21" path="res://assets/ambientcg.com/Carpet003_1K-JPG_Color.jpg" id="1_pfl7p"] [ext_resource type="PackedScene" uid="uid://cay8oh2ll7yxi" path="res://assets/test_kun/Test-Kun.fbx" id="2_67k0v"] @@ -34,7 +35,11 @@ outer_radius = 0.6 rings = 32 ring_segments = 8 +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kirwm"] +bg_color = Color(0, 0, 0, 0.498039) + [node name="Demo" type="Node3D"] +script = ExtResource("1_dt0nj") [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource("Environment_w0xf3") @@ -49,6 +54,7 @@ transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, mesh = SubResource("QuadMesh_0334b") [node name="Camera3D" type="Camera3D" parent="."] +unique_name_in_owner = true transform = Transform3D(0.939693, 0.0593911, -0.336824, 0, 0.984808, 0.173648, 0.34202, -0.163176, 0.925417, -1.2, 1.4, 2.2) [node name="Chan" type="Node3D" parent="."] @@ -61,6 +67,7 @@ bone_update = 1 show_when_tracked = false [node name="Test-Chan" parent="Chan/XRBodyModifier3D" instance=ExtResource("1_lkeve")] +unique_name_in_owner = true [node name="Body" parent="Chan/XRBodyModifier3D/Test-Chan/Armature/Skeleton3D" index="0"] blend_shapes/Cheek_Puff_Left = 1.28996e-05 @@ -120,6 +127,7 @@ bone_update = 1 show_when_tracked = false [node name="Test-Kun" parent="Kun/XRBodyModifier3D" instance=ExtResource("2_67k0v")] +unique_name_in_owner = true [node name="Body" parent="Kun/XRBodyModifier3D/Test-Kun/Armature/Skeleton3D" index="0"] blend_shapes/Cheek_Puff_Left = 1.28996e-05 @@ -169,5 +177,73 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0) mesh = SubResource("TorusMesh_rbtmk") skeleton = NodePath("") +[node name="PanelContainer" type="PanelContainer" parent="."] +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -360.0 +offset_top = -81.0 +offset_right = -5.0 +offset_bottom = -5.0 +grow_horizontal = 0 +grow_vertical = 0 +theme_override_styles/panel = SubResource("StyleBoxFlat_kirwm") + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 5 +theme_override_constants/margin_top = 5 +theme_override_constants/margin_right = 5 +theme_override_constants/margin_bottom = 5 + +[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer"] +layout_mode = 2 +text = "Godot XR Tracker +MVN" +horizontal_alignment = 1 + +[node name="VSeparator" type="VSeparator" parent="PanelContainer/MarginContainer/HBoxContainer"] +layout_mode = 2 + +[node name="GridContainer" type="GridContainer" parent="PanelContainer/MarginContainer/HBoxContainer"] +layout_mode = 2 +columns = 2 + +[node name="SkeletonLabel" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer/GridContainer"] +layout_mode = 2 +text = "Skeleton Scale +" +horizontal_alignment = 2 + +[node name="SkeletonSpinBox" type="SpinBox" parent="PanelContainer/MarginContainer/HBoxContainer/GridContainer"] +unique_name_in_owner = true +layout_mode = 2 +min_value = 0.1 +max_value = 2.0 +step = 0.1 +value = 1.0 + +[node name="WorldLabel" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer/GridContainer"] +layout_mode = 2 +text = "World Scale +" +horizontal_alignment = 2 + +[node name="WorldSpinBox" type="SpinBox" parent="PanelContainer/MarginContainer/HBoxContainer/GridContainer"] +unique_name_in_owner = true +layout_mode = 2 +min_value = 0.1 +max_value = 5.0 +step = 0.1 +value = 1.0 + +[connection signal="value_changed" from="PanelContainer/MarginContainer/HBoxContainer/GridContainer/SkeletonSpinBox" to="." method="_on_skeleton_spin_box_value_changed"] +[connection signal="value_changed" from="PanelContainer/MarginContainer/HBoxContainer/GridContainer/WorldSpinBox" to="." method="_on_world_spin_box_value_changed"] + [editable path="Chan/XRBodyModifier3D/Test-Chan"] [editable path="Kun/XRBodyModifier3D/Test-Kun"]