From a8da79707c6a57e3a32dbe0b96e312b3774eaa38 Mon Sep 17 00:00:00 2001 From: teatov Date: Tue, 8 Oct 2024 03:06:06 +1000 Subject: [PATCH] create `AudioStreamPlayerPolyphonic` --- scenes/units/ant_gatherer.tscn | 2 +- scenes/units/ant_nitwit.tscn | 23 ++++++++++++++++++++++- scenes/units/components/gathering.tscn | 6 +++++- scripts/audio_stream_player_polyphonic.gd | 23 +++++++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 scripts/audio_stream_player_polyphonic.gd diff --git a/scenes/units/ant_gatherer.tscn b/scenes/units/ant_gatherer.tscn index 1ad1455..5914d51 100644 --- a/scenes/units/ant_gatherer.tscn +++ b/scenes/units/ant_gatherer.tscn @@ -37,7 +37,7 @@ callback_mode_process = 1 [node name="Gathering" parent="." index="8" instance=ExtResource("3_7b5q8")] -[node name="NearbyItemsSearch" parent="Gathering" index="0"] +[node name="NearbyItemsSearch" parent="Gathering" index="1"] shape = SubResource("SphereShape3D_f7l1n") [node name="GatheringRadius" parent="Gathering/NearbyItemsSearch" index="0"] diff --git a/scenes/units/ant_nitwit.tscn b/scenes/units/ant_nitwit.tscn index ee1af23..3a7d2a8 100644 --- a/scenes/units/ant_nitwit.tscn +++ b/scenes/units/ant_nitwit.tscn @@ -10,9 +10,30 @@ radius = 4.0 [node name="AntNitwit" instance=ExtResource("1_w0xhf")] script = ExtResource("2_rfn2k") +[node name="Skeleton3D" parent="AntModel/Armature" index="0"] +bones/4/rotation = Quaternion(0.587858, -5.43255e-07, -3.94772e-07, 0.808964) +bones/6/rotation = Quaternion(0.330686, -3.0116e-14, -4.44141e-07, 0.943741) +bones/9/rotation = Quaternion(0.587858, 5.43255e-07, 3.94772e-07, 0.808964) +bones/11/rotation = Quaternion(0.330686, 3.0116e-14, 4.44141e-07, 0.943741) +bones/14/rotation = Quaternion(4.60304e-08, 0.0294697, 0.999566, -5.43234e-07) +bones/15/rotation = Quaternion(4.55913e-08, 0.0294697, 0.999566, -4.34329e-07) +bones/16/rotation = Quaternion(4.55913e-08, 0.0294697, 0.999566, -4.34329e-07) +bones/26/rotation = Quaternion(-0.221628, 0.221633, -0.671475, 0.671477) +bones/27/rotation = Quaternion(0.583948, -8.29882e-08, 2.36539e-06, 0.811791) +bones/28/rotation = Quaternion(-0.84146, 6.60837e-08, -6.26108e-06, 0.54032) +bones/30/rotation = Quaternion(0.583949, -2.24752e-07, 2.46641e-06, 0.811791) +bones/31/rotation = Quaternion(-0.84146, 1.69298e-07, -6.42962e-06, 0.54032) +bones/34/rotation = Quaternion(-0.841459, 1.31575e-07, -6.3826e-06, 0.540321) +bones/35/rotation = Quaternion(-0.221628, -0.221633, 0.671475, 0.671477) +bones/36/rotation = Quaternion(0.583948, 8.29882e-08, -2.36539e-06, 0.811791) +bones/37/rotation = Quaternion(-0.84146, -6.60837e-08, 6.26108e-06, 0.54032) +bones/39/rotation = Quaternion(0.583949, 2.24752e-07, -2.46641e-06, 0.811791) +bones/40/rotation = Quaternion(-0.84146, -1.69298e-07, 6.42962e-06, 0.54032) +bones/43/rotation = Quaternion(-0.841459, -1.31575e-07, 6.3826e-06, 0.540321) + [node name="Gathering" parent="." index="8" instance=ExtResource("4_k3phm")] -[node name="NearbyItemsSearch" parent="Gathering" index="0"] +[node name="NearbyItemsSearch" parent="Gathering" index="1"] shape = SubResource("SphereShape3D_dwl4o") [node name="GatheringRadius" parent="Gathering/NearbyItemsSearch" index="0"] diff --git a/scenes/units/components/gathering.tscn b/scenes/units/components/gathering.tscn index 5558b07..dd1b952 100644 --- a/scenes/units/components/gathering.tscn +++ b/scenes/units/components/gathering.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=4 format=3 uid="uid://fal1ond30jey"] +[gd_scene load_steps=5 format=3 uid="uid://fal1ond30jey"] [ext_resource type="Script" path="res://scripts/units/components/gathering.gd" id="1_ciwtf"] [ext_resource type="Material" uid="uid://jkh5iskawwry" path="res://resources/materials/indicators/gathering_radius_mat.tres" id="2_r26em"] +[ext_resource type="Script" path="res://scripts/audio_stream_player_polyphonic.gd" id="4_alybx"] [sub_resource type="QuadMesh" id="QuadMesh_ks8es"] material = ExtResource("2_r26em") @@ -20,3 +21,6 @@ script = ExtResource("1_ciwtf") cast_shadow = 0 mesh = SubResource("QuadMesh_ks8es") skeleton = NodePath("../..") + +[node name="AudioStreamPlayerPolyphonic" type="AudioStreamPlayer3D" parent="."] +script = ExtResource("4_alybx") diff --git a/scripts/audio_stream_player_polyphonic.gd b/scripts/audio_stream_player_polyphonic.gd new file mode 100644 index 0000000..3a694f1 --- /dev/null +++ b/scripts/audio_stream_player_polyphonic.gd @@ -0,0 +1,23 @@ +extends AudioStreamPlayer3D +class_name AudioStreamPlayerPolyphonic + +var playback: AudioStreamPlaybackPolyphonic + + +func _ready() -> void: + stream = AudioStreamPolyphonic.new() + play() + playback = get_stream_playback() + +func play_polyphonic( + new_stream: AudioStream, + from_offset: float = 0, + new_volume_db: float = 0, + new_pitch_scale: float = 1.0, +) -> void: + playback.play_stream( + new_stream, + from_offset, + new_volume_db, + new_pitch_scale, + )