diff --git a/cosmic/Player.gd b/cosmic/Player.gd new file mode 100644 index 0000000..4a19fce --- /dev/null +++ b/cosmic/Player.gd @@ -0,0 +1,79 @@ +extends KinematicBody + +var camera_angle = 0 +var mouse_sensitivity = 0.3 +var camera_change = Vector2() + +var velocity = Vector3() +var direction = Vector3() + +#fly variables +#const FLY_SPEED = 20 +#const FLY_ACCEL = 4 +const FLY_SPEED = 8 +const FLY_ACCEL = 4 + +var mouse_captured = true + +func _ready(): + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + +func _physics_process(delta): + + if mouse_captured: + aim() + fly(delta) + + if Input.is_action_just_pressed('toggle_mouse'): + if mouse_captured: + mouse_captured = false + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + else: + mouse_captured = true + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + + # emit signal - playerinfo_updated + Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y) + + +func _input(event): + if event is InputEventMouseMotion: + camera_change = event.relative + +func fly(delta): + # reset the direction of the player + direction = Vector3() + + # get the rotation of the camera + var aim = $Head/Camera.get_global_transform().basis + + # check input and change direction + if Input.is_action_pressed("move_forward"): + direction -= aim.z + if Input.is_action_pressed("move_backward"): + direction += aim.z + if Input.is_action_pressed("move_left"): + direction -= aim.x + if Input.is_action_pressed("move_right"): + direction += aim.x + + direction = direction.normalized() + + # where would the player go at max speed + var target = direction * FLY_SPEED + + # calculate a portion of the distance to go + velocity = velocity.linear_interpolate(target, FLY_ACCEL * delta) + + # move + move_and_slide(velocity) + +func aim(): + if camera_change.length() > 0: + $Head.rotate_y(deg2rad(-camera_change.x * mouse_sensitivity)) + + var change = -camera_change.y * mouse_sensitivity + if change + camera_angle < 90 and change + camera_angle > -90: + $Head/Camera.rotate_x(deg2rad(change)) + camera_angle += change + camera_change = Vector2() diff --git a/cosmic/Player.tscn b/cosmic/Player.tscn new file mode 100644 index 0000000..4dba86f --- /dev/null +++ b/cosmic/Player.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Player.gd" type="Script" id=1] + +[sub_resource type="CapsuleShape" id=1] +radius = 0.6 +height = 2.0 + +[node name="Player" type="KinematicBody"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.52113, 0.98772 ) +collision_layer = 2 +script = ExtResource( 1 ) + +[node name="Capsule" type="CollisionShape" parent="."] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) +shape = SubResource( 1 ) + +[node name="Head" type="Spatial" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0 ) + +[node name="Camera" type="Camera" parent="Head"] +current = true +far = 10000.0 diff --git a/cosmic/Region.gd b/cosmic/Region.gd new file mode 100644 index 0000000..fb9fa13 --- /dev/null +++ b/cosmic/Region.gd @@ -0,0 +1,60 @@ +extends Spatial + +var sub = load("res://osc.tscn") + +var _rot_speed_origin + +var gain1 = 40 # for $main +var range1 = 80 # for $main + +var gain2 = 0.1 # for osc +var range2 = 20 # for osc + +var ratio = 0.4 + +func _ready(): + # 'main' at center. + $main.set_size(rand_range(10, 15)) + $main.audible_range_max = range1 + $main.set_freq(rand_range(100, 300)) + $main.set_gain(gain1) + + # many 'sub' surrounds 'main' like satellites + for i in range(18): + var s = sub.instance() + $main.add_child(s) + s.set_size(rand_range(0.2, 1.2)) + s.set_color(Color.black) + var d = polar2cartesian(rand_range(20, 54), rand_range(0, 2*PI)) + s.translate(Vector3(d.x, rand_range(-2, 2), d.y)) + s.audible_range_max = range2 + s.set_freq(rand_range(200, 2000)) + s.set_gain(gain2) + + # listen 'player_transform_updated' event + Events.connect("player_transform_updated", self, "_on_Events_player_transform_updated") + + # + _rot_speed_origin = $main._rot_speed + +func _on_Events_player_transform_updated(playerpos, playerheading): + var mypos = $main.get_global_translation() + var mypos2d = Vector2(mypos.x, mypos.z) + var playerpos2d = Vector2(playerpos.x, playerpos.z) + # calculate distance + var distance = mypos.distance_to(playerpos) + if distance < $main/CollisionShape.shape.radius: + $main._rot_speed = _rot_speed_origin * pow(distance/$main/CollisionShape.shape.radius, 2) + for c in $main.get_children(): + if c.is_in_group('sounders'): + c.audible_range_max = range2 * pow($main/CollisionShape.shape.radius/(distance + 0.1), 2) + c.set_gain(gain2 * pow(distance/$main/CollisionShape.shape.radius, 2)) + $main.set_gain(gain1 * pow(distance/$main/CollisionShape.shape.radius, ratio)) + else: + $main._rot_speed = _rot_speed_origin + for c in $main.get_children(): + if c.is_in_group('sounders'): + c.audible_range_max = range2 + c.set_gain(gain2) + $main.set_gain(gain1) + diff --git a/cosmic/Region.tscn b/cosmic/Region.tscn new file mode 100644 index 0000000..b14b79f --- /dev/null +++ b/cosmic/Region.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Region.gd" type="Script" id=1] +[ext_resource path="res://main.tscn" type="PackedScene" id=2] + +[node name="Region" type="Spatial" groups=["regions"]] +script = ExtResource( 1 ) + +[node name="main" parent="." instance=ExtResource( 2 )] diff --git a/cosmic/Scene.gd b/cosmic/Scene.gd new file mode 100644 index 0000000..077bee9 --- /dev/null +++ b/cosmic/Scene.gd @@ -0,0 +1,28 @@ +extends Node + +func _ready(): + for r in get_tree().get_nodes_in_group('regions'): + r.get_node('main')._rot_speed = r._rot_speed_origin + r.get_node('main/center').material_override = SpatialMaterial.new() + r.get_node('main/center').material_override.albedo_color = Color.from_hsv((randi() % 12) / 12.0, 1, 1) + + $Region._rot_speed_origin = rand_range(0.002, 0.005) + $Region.ratio = 3 + $Region/main.audible_range_max = 30 + for c in $Region/main.get_children(): + if c.is_in_group('sounders'): + c.set_freq(rand_range(20, 200)) + + $Region3._rot_speed_origin = rand_range(-0.01, -0.1) + for c in $Region3/main.get_children(): + if c.is_in_group('sounders'): + c.set_freq(rand_range(200, 2000)) + + $Region2._rot_speed_origin = rand_range(0.01, 0.1) + for c in $Region2/main.get_children(): + if c.is_in_group('sounders'): + c.set_freq(rand_range(2000, 20000)) + $Region2.gain1 = 5 + $Region2.gain2 = 0.05 + $Region2.ratio = 3 +# $Region2/main.set_freq(rand_range(20, 80)) diff --git a/cosmic/Scene.tscn b/cosmic/Scene.tscn new file mode 100644 index 0000000..8897e59 --- /dev/null +++ b/cosmic/Scene.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://Region.tscn" type="PackedScene" id=1] +[ext_resource path="res://Player.tscn" type="PackedScene" id=2] +[ext_resource path="res://Scene.gd" type="Script" id=3] + +[sub_resource type="BoxShape" id=1] +extents = Vector3( 300, 1, 300 ) + +[sub_resource type="CubeMesh" id=2] +size = Vector3( 600, 2, 600 ) + +[sub_resource type="Environment" id=3] +fog_enabled = true + +[node name="Scene" type="Node"] +script = ExtResource( 3 ) + +[node name="StaticBody" type="StaticBody" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 ) + +[node name="CollisionShape" type="CollisionShape" parent="StaticBody"] +shape = SubResource( 1 ) + +[node name="MeshInstance" type="MeshInstance" parent="StaticBody"] +mesh = SubResource( 2 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="."] +transform = Transform( 1, 0, 0, 0, 0.158589, 0.987345, 0, -0.987345, 0.158589, 0, 57.3999, 0 ) +shadow_enabled = true + +[node name="Player" parent="." instance=ExtResource( 2 )] +transform = Transform( -1, 0, 5.96046e-08, 0, 1, 0, -5.96046e-08, 0, -1, -46.6135, 49.5715, -99.5295 ) + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource( 3 ) + +[node name="Region" parent="." instance=ExtResource( 1 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 30, 0 ) + +[node name="Region2" parent="." instance=ExtResource( 1 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -115.897, 63.8199, 95.9651 ) + +[node name="Region3" parent="." instance=ExtResource( 1 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 67.7793, 64.9703, -27.1477 ) diff --git a/cosmic/addons/gdpd/bin/gdpd.gdns b/cosmic/addons/gdpd/bin/gdpd.gdns new file mode 100644 index 0000000..869b3c3 --- /dev/null +++ b/cosmic/addons/gdpd/bin/gdpd.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://addons/gdpd/bin/libgdpd.gdnlib" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "gdpd" +class_name = "Gdpd" +library = ExtResource( 1 ) diff --git a/cosmic/addons/gdpd/bin/libgdpd.gdnlib b/cosmic/addons/gdpd/bin/libgdpd.gdnlib new file mode 100644 index 0000000..048e4af --- /dev/null +++ b/cosmic/addons/gdpd/bin/libgdpd.gdnlib @@ -0,0 +1,18 @@ +[general] + +singleton=false +load_once=false +symbol_prefix="godot_" +reloadable=true + +[entry] + +X11.64="res://addons/gdpd/bin/x11/libgdpd.so" +Windows.64="res://addons/gdpd/bin/win/libgdpd.dll" +OSX.64="res://addons/gdpd/bin/osx/libgdpd.dylib" + +[dependencies] + +X11.64=[ ] +Windows.64=[ ] +OSX.64=[ ] diff --git a/cosmic/addons/gdpd/bin/osx/libgdpd.dylib b/cosmic/addons/gdpd/bin/osx/libgdpd.dylib new file mode 100755 index 0000000..a8021de Binary files /dev/null and b/cosmic/addons/gdpd/bin/osx/libgdpd.dylib differ diff --git a/cosmic/autoload/Events.gd b/cosmic/autoload/Events.gd new file mode 100644 index 0000000..b212a61 --- /dev/null +++ b/cosmic/autoload/Events.gd @@ -0,0 +1,5 @@ +extends Node + +signal player_transform_updated(position, heading) +# position : Vector3 +# heading : Vector2 (projected x-z plane, and normalized) diff --git a/cosmic/autoload/Events.tscn b/cosmic/autoload/Events.tscn new file mode 100644 index 0000000..00dabc1 --- /dev/null +++ b/cosmic/autoload/Events.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://autoload/Events.gd" type="Script" id=1] + +[node name="Events" type="Node"] +script = ExtResource( 1 ) diff --git a/cosmic/autoload/Global.gd b/cosmic/autoload/Global.gd new file mode 100644 index 0000000..c971dfb --- /dev/null +++ b/cosmic/autoload/Global.gd @@ -0,0 +1,93 @@ +extends Node + + +#gdpd (pd interface with godot) +var _gdpd +var _patches = [] + +export (bool) var _enable_gui = false +export (String) var _gui_path = "/Applications/Pd-0.53-1.app/Contents/Resources" +export (bool) var _verbose = false +export (int) var _sample_rate = 48000 +export (int) var _blocksize = 256 + +func _ready(): + _gdpd = load("res://addons/gdpd/bin/gdpd.gdns").new() + if _enable_gui: + # set gui path to activate gui window (otherwise, nogui) + _gdpd.set_gui_path(_gui_path) + _gdpd.set_volume(1) # by default, volume(gain) == 0 + _gdpd.set_verbose(_verbose) # by default, suppress 'print' + _gdpd.init(0, 2, _sample_rate, _blocksize) + _gdpd.computeAudio(true) # [; pd dsp 1 ( + _gdpd.subscribe("toGodot") + # delayed 'stream start' to prevent start-up 'pop' noise. + yield(get_tree().create_timer(0.3), "timeout") + _gdpd.streamstart() + +func _exit_tree(): + if _patches.size() != 0: + print() + print("! ======== * purging leftover opened patches ... * ======== !") + print() + for id in _patches: + _gdpd.closePatch(id) + _patches.clear() + _gdpd.stop() + +func load_patch(pd_patch) -> int: + #the patch path should be the absolute one + #separate file name from directory + var patch_name = pd_patch.split("/")[-1] + var patch_dir = pd_patch.trim_suffix(patch_name) + var id = _gdpd.openPatch(patch_name, patch_dir) + _patches.append(id) + return id + +func close_patch(id): + if id in _patches: + _gdpd.closePatch(id) + _patches.erase(id) + +func _process(_delta) : + while _gdpd.has_message(): + var msg = _gdpd.get_next() + print(msg) +# if msg[0] == "random": +# print("r") + + + + + +# ==== archived. ==== + + + # duplicate "res://" into 'user://' ==> we need godot 4 for this approach.. +# _copydirectory_recursive("res://", "user://") + + +## copy directory recursively ==> we need godot 4 for this approach.. +#func _copydirectory_recursive(src, dst): +# var dotfolders = RegEx.new() +# dotfolders.compile("^\\.\\w*") +# var pdfiles = RegEx.new() +# pdfiles.compile("\\w+\\.pd$") +# var dir = Directory.new() +# if dir.open(src) == OK: +# dir.list_dir_begin() +# var file_name = dir.get_next() +# while file_name != "": +# if dir.current_is_dir(): +# print("Found directory: " + file_name) +# if not dotfolders.search(file_name): +# dir.make_dir(dst + "/" + file_name) +# _copydirectory_recursive(dir.get_current_dir() + "/" + file_name, dst + "/" + file_name) +# else: +# if pdfiles.search(file_name): +# print("Found puredata file: " + file_name) +# dir.copy(src + "/" + file_name, dst + "/" + file_name) +# +# file_name = dir.get_next() +# else: +# print("An error occurred when trying to access the path. : " + src) diff --git a/cosmic/autoload/Global.tscn b/cosmic/autoload/Global.tscn new file mode 100644 index 0000000..a00373d --- /dev/null +++ b/cosmic/autoload/Global.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://autoload/Global.gd" type="Script" id=1] + +[node name="Global" type="Node"] +script = ExtResource( 1 ) diff --git a/cosmic/default_env.tres b/cosmic/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/cosmic/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/cosmic/icon.png b/cosmic/icon.png new file mode 100644 index 0000000..c98fbb6 Binary files /dev/null and b/cosmic/icon.png differ diff --git a/cosmic/main.gd b/cosmic/main.gd new file mode 100644 index 0000000..bc3e307 --- /dev/null +++ b/cosmic/main.gd @@ -0,0 +1,104 @@ +extends RigidBody + +export (float, 0, 100) var audible_range_max = 10.0 +export (int, 1, 12) var preset = 1 + +export (bool) var use_embeded_patch = false +export (String, MULTILINE) var patch = "" + +var _my_patch = "res://main.pd" +var _my_id = 0 + +var _rot_speed = 0.1 + +func set_size(size): + $CollisionShape.shape.radius = size + $MeshInstance.mesh.radius = size + $MeshInstance.mesh.height = size * 2 + +func set_freq(freq): + Global._gdpd.start_message(2) + Global._gdpd.add_symbol('freq') + Global._gdpd.add_float(freq) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_gain(gain): + Global._gdpd.start_message(2) + Global._gdpd.add_symbol('gain') + Global._gdpd.add_float(gain) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_param(param): + Global._gdpd.start_message(param.size()+1) + Global._gdpd.add_symbol("param") + for i in range(param.size()): + Global._gdpd.add_float(param[i]) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_preset(prs): + preset = prs + Global._gdpd.start_message(2) + Global._gdpd.add_symbol("preset") + Global._gdpd.add_float(prs) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_color(color): + $MeshInstance.material_override = SpatialMaterial.new() + $MeshInstance.material_override.albedo_color = color + +func _ready(): + # save patch (for export) + if use_embeded_patch: + assert(_my_patch.substr(0, 7) == "user://", "use userpath with embeded_patch enabled !") + assert(patch != "", "patch is empty?") + _save_patch() + + # load patch + _my_id = Global.load_patch(ProjectSettings.globalize_path(_my_patch)) + + # listen 'player_transform_updated' event + Events.connect("player_transform_updated", self, "_on_Events_player_transform_updated") + + # send 'preset' + set_preset(preset) + +func _integrate_forces(state): + state.set_angular_velocity(Vector3.UP * (_rot_speed / state.get_step())) + +func _on_Events_player_transform_updated(playerpos, playerheading): + var mypos = get_global_translation() + var mypos2d = Vector2(mypos.x, mypos.z) + var playerpos2d = Vector2(playerpos.x, playerpos.z) + # calculate distance + var distance = mypos.distance_to(playerpos) + # calculate angle + var angle = fmod(fmod(playerpos2d.angle_to_point(mypos2d) + playerheading - PI/2, PI*2) + PI*2, PI*2) + if angle > PI: + angle = angle - PI*2 + # (check) +# print(str(_my_id) +" : ("+ str(distance) +","+ str(angle) +")") + # calculate gain + var gain = 1 - distance/audible_range_max + # send to the patch + Global._gdpd.start_message(3) + Global._gdpd.add_symbol("panvol") + Global._gdpd.add_float(gain) + Global._gdpd.add_float(angle) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + + +func _exit_tree(): + Global.close_patch(_my_id) + +func _save_patch(): + # save patch + # prepare directory + var patch_name = _my_patch.split("/")[-1] + var patch_dir = _my_patch.trim_suffix(patch_name) + var dir = Directory.new() + dir.make_dir_recursive(patch_dir) + # save to file + var file = File.new() + file.open(_my_patch, File.WRITE) + file.store_string(patch) + file.close() diff --git a/cosmic/main.pd b/cosmic/main.pd new file mode 100644 index 0000000..0dc582c --- /dev/null +++ b/cosmic/main.pd @@ -0,0 +1,81 @@ +#N canvas 190 223 456 518 12; +#X floatatom 21 198 5 0 0 0 - - - 0; +#X obj 21 22 r fromGodot\$0; +#X obj 21 46 list trim; +#X obj 199 467 dac~ 1 2; +#X obj 199 407 *~; +#X obj 189 264 line~; +#X msg 189 240 \$1 100; +#X obj 189 127 unpack f f; +#X floatatom 189 177 5 0 0 0 - - - 0; +#X obj 21 256 noise~; +#X obj 21 286 bp~ 500 1000; +#X obj 21 70 route freq gain panvol; +#X obj 21 316 *~; +#X obj 132 310 switch~; +#X obj 132 286 tgl 19 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 132 262 change; +#X text 89 155 switch on/off before 0 to stop startup pops, f 12; +#X obj 189 216 max 0; +#X obj 132 238 > -0.3; +#X obj 303 253 hsl 100 20 -1 1 0 0 empty empty empty -2 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 300 349 line~; +#X msg 300 325 \$1 100; +#X obj 300 278 expr ($f1 + 1)/8; +#X floatatom 300 302 5 0 0 0 - - - 0; +#N canvas 68 97 450 300 pan2~ 0; +#X obj 51 98 cos~; +#X obj 111 98 cos~; +#X obj 33 128 *~; +#X obj 93 128 *~; +#X obj 33 158 outlet~; +#X obj 93 158 outlet~; +#X obj 33 24 inlet~; +#X obj 111 24 inlet~; +#X obj 111 74 +~ 0.75; +#X connect 0 0 2 1; +#X connect 1 0 3 1; +#X connect 2 0 4 0; +#X connect 3 0 5 0; +#X connect 6 0 2 0; +#X connect 6 0 3 0; +#X connect 7 0 8 0; +#X connect 7 0 0 0; +#X connect 8 0 1 0; +#X restore 199 437 pd pan2~; +#X floatatom 296 159 5 0 0 0 - - - 0; +#X obj 296 182 sin; +#X floatatom 296 206 5 0 0 0 - - - 0; +#X obj 203 336 *~; +#X connect 0 0 10 1; +#X connect 1 0 2 0; +#X connect 2 0 11 0; +#X connect 4 0 24 0; +#X connect 5 0 28 0; +#X connect 5 0 28 1; +#X connect 6 0 5 0; +#X connect 7 0 8 0; +#X connect 7 1 25 0; +#X connect 8 0 17 0; +#X connect 8 0 18 0; +#X connect 9 0 10 0; +#X connect 10 0 12 0; +#X connect 11 0 0 0; +#X connect 11 1 12 1; +#X connect 11 2 7 0; +#X connect 12 0 4 0; +#X connect 14 0 13 0; +#X connect 15 0 14 0; +#X connect 17 0 6 0; +#X connect 18 0 15 0; +#X connect 19 0 22 0; +#X connect 20 0 24 1; +#X connect 21 0 20 0; +#X connect 22 0 23 0; +#X connect 23 0 21 0; +#X connect 24 0 3 0; +#X connect 24 1 3 1; +#X connect 25 0 26 0; +#X connect 26 0 27 0; +#X connect 27 0 19 0; +#X connect 28 0 4 1; diff --git a/cosmic/main.tscn b/cosmic/main.tscn new file mode 100644 index 0000000..2d34b3e --- /dev/null +++ b/cosmic/main.tscn @@ -0,0 +1,53 @@ +[gd_scene load_steps=10 format=2] + +[ext_resource path="res://main.gd" type="Script" id=1] + +[sub_resource type="PhysicsMaterial" id=3] + +[sub_resource type="SphereShape" id=5] + +[sub_resource type="SpatialMaterial" id=4] + +[sub_resource type="SphereMesh" id=2] +resource_local_to_scene = true +material = SubResource( 4 ) +radius = 20.0 +height = 40.0 + +[sub_resource type="SpatialMaterial" id=6] +albedo_color = Color( 0.894118, 1, 0, 1 ) + +[sub_resource type="SphereMesh" id=7] +material = SubResource( 6 ) +radius = 0.1 +height = 0.2 + +[sub_resource type="SpatialMaterial" id=8] + +[sub_resource type="CylinderMesh" id=9] +material = SubResource( 8 ) +top_radius = 0.003 +bottom_radius = 0.003 +height = 0.5 + +[node name="main" type="RigidBody" groups=["sounders"]] +collision_layer = 4 +collision_mask = 0 +physics_material_override = SubResource( 3 ) +gravity_scale = 0.0 +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] +shape = SubResource( 5 ) + +[node name="MeshInstance" type="MeshInstance" parent="."] +mesh = SubResource( 2 ) + +[node name="center" type="MeshInstance" parent="."] +mesh = SubResource( 7 ) + +[node name="pin" type="MeshInstance" parent="center"] +mesh = SubResource( 9 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="."] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 1, 0 ) diff --git a/cosmic/osc.gd b/cosmic/osc.gd new file mode 100644 index 0000000..bd0e7f5 --- /dev/null +++ b/cosmic/osc.gd @@ -0,0 +1,99 @@ +extends RigidBody + +export (float, 0, 100) var audible_range_max = 10.0 +export (int, 1, 12) var preset = 1 + +export (bool) var use_embeded_patch = false +export (String, MULTILINE) var patch = "" + +var _my_patch = "res://osc.pd" +var _my_id = 0 + +func set_size(size): + $CollisionShape.shape.radius = size + $MeshInstance.mesh.radius = size + $MeshInstance.mesh.height = size * 2 + +func set_freq(freq): + Global._gdpd.start_message(2) + Global._gdpd.add_symbol('freq') + Global._gdpd.add_float(freq) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_gain(gain): + Global._gdpd.start_message(2) + Global._gdpd.add_symbol('gain') + Global._gdpd.add_float(gain) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_param(param): + Global._gdpd.start_message(param.size()+1) + Global._gdpd.add_symbol("param") + for i in range(param.size()): + Global._gdpd.add_float(param[i]) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_preset(prs): + preset = prs + Global._gdpd.start_message(2) + Global._gdpd.add_symbol("preset") + Global._gdpd.add_float(prs) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + +func set_color(color): + $MeshInstance.material_override = SpatialMaterial.new() + $MeshInstance.material_override.albedo_color = color + +func _ready(): + # save patch (for export) + if use_embeded_patch: + assert(_my_patch.substr(0, 7) == "user://", "use userpath with embeded_patch enabled !") + assert(patch != "", "patch is empty?") + _save_patch() + + # load patch + _my_id = Global.load_patch(ProjectSettings.globalize_path(_my_patch)) + + # listen 'player_transform_updated' event + Events.connect("player_transform_updated", self, "_on_Events_player_transform_updated") + + # send 'preset' + set_preset(preset) + +func _on_Events_player_transform_updated(playerpos, playerheading): + var mypos = get_global_translation() + var mypos2d = Vector2(mypos.x, mypos.z) + var playerpos2d = Vector2(playerpos.x, playerpos.z) + # calculate distance + var distance = mypos.distance_to(playerpos) + # calculate angle + var angle = fmod(fmod(playerpos2d.angle_to_point(mypos2d) + playerheading - PI/2, PI*2) + PI*2, PI*2) + if angle > PI: + angle = angle - PI*2 + # (check) +# print(str(_my_id) +" : ("+ str(distance) +","+ str(angle) +")") + # calculate gain + var gain = 1 - distance/audible_range_max + # send to the patch + Global._gdpd.start_message(3) + Global._gdpd.add_symbol("panvol") + Global._gdpd.add_float(gain) + Global._gdpd.add_float(angle) + Global._gdpd.finish_list("fromGodot" + String(_my_id)) + + +func _exit_tree(): + Global.close_patch(_my_id) + +func _save_patch(): + # save patch + # prepare directory + var patch_name = _my_patch.split("/")[-1] + var patch_dir = _my_patch.trim_suffix(patch_name) + var dir = Directory.new() + dir.make_dir_recursive(patch_dir) + # save to file + var file = File.new() + file.open(_my_patch, File.WRITE) + file.store_string(patch) + file.close() diff --git a/cosmic/osc.pd b/cosmic/osc.pd new file mode 100644 index 0000000..ae40b98 --- /dev/null +++ b/cosmic/osc.pd @@ -0,0 +1,79 @@ +#N canvas 116 274 456 518 12; +#X obj 50 277 osc~ 440; +#X floatatom 21 198 5 0 0 0 - - - 0; +#X obj 21 22 r fromGodot\$0; +#X obj 21 46 list trim; +#X obj 199 467 dac~ 1 2; +#X obj 199 407 *~; +#X obj 189 127 unpack f f; +#X obj 21 70 route freq gain panvol; +#X obj 50 301 *~; +#X obj 189 264 line~; +#X msg 189 240 \$1 100; +#X floatatom 189 177 5 0 0 0 - - - 0; +#X obj 132 310 switch~; +#X obj 132 286 tgl 19 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 132 262 change; +#X text 89 155 switch on/off before 0 to stop startup pops, f 12; +#X obj 189 216 max 0; +#X obj 303 253 hsl 100 20 -1 1 0 0 empty empty empty -2 -10 0 12 #fcfcfc #000000 #000000 0 1; +#X obj 300 349 line~; +#X msg 300 325 \$1 100; +#X obj 300 278 expr ($f1 + 1)/8; +#X floatatom 300 302 5 0 0 0 - - - 0; +#N canvas 68 97 450 300 pan2~ 0; +#X obj 51 98 cos~; +#X obj 111 98 cos~; +#X obj 33 128 *~; +#X obj 93 128 *~; +#X obj 33 158 outlet~; +#X obj 93 158 outlet~; +#X obj 33 24 inlet~; +#X obj 111 24 inlet~; +#X obj 111 74 +~ 0.75; +#X connect 0 0 2 1; +#X connect 1 0 3 1; +#X connect 2 0 4 0; +#X connect 3 0 5 0; +#X connect 6 0 2 0; +#X connect 6 0 3 0; +#X connect 7 0 8 0; +#X connect 7 0 0 0; +#X connect 8 0 1 0; +#X restore 199 437 pd pan2~; +#X floatatom 296 159 5 0 0 0 - - - 0; +#X obj 296 182 sin; +#X floatatom 296 206 5 0 0 0 - - - 0; +#X obj 132 238 1; +#X obj 203 336 *~; +#X connect 0 0 8 0; +#X connect 1 0 0 0; +#X connect 2 0 3 0; +#X connect 3 0 7 0; +#X connect 5 0 22 0; +#X connect 6 0 11 0; +#X connect 6 1 23 0; +#X connect 7 0 1 0; +#X connect 7 1 8 1; +#X connect 7 2 6 0; +#X connect 8 0 5 0; +#X connect 9 0 27 0; +#X connect 9 0 27 1; +#X connect 10 0 9 0; +#X connect 11 0 16 0; +#X connect 11 0 26 0; +#X connect 13 0 12 0; +#X connect 14 0 13 0; +#X connect 16 0 10 0; +#X connect 17 0 20 0; +#X connect 18 0 22 1; +#X connect 19 0 18 0; +#X connect 20 0 21 0; +#X connect 21 0 19 0; +#X connect 22 0 4 0; +#X connect 22 1 4 1; +#X connect 23 0 24 0; +#X connect 24 0 25 0; +#X connect 25 0 17 0; +#X connect 26 0 14 0; +#X connect 27 0 5 1; diff --git a/cosmic/osc.tscn b/cosmic/osc.tscn new file mode 100644 index 0000000..45c2780 --- /dev/null +++ b/cosmic/osc.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://osc.gd" type="Script" id=1] + +[sub_resource type="PhysicsMaterial" id=3] + +[sub_resource type="SphereShape" id=1] + +[sub_resource type="SphereMesh" id=2] +resource_local_to_scene = true + +[node name="osc" type="RigidBody" groups=["sounders"]] +collision_layer = 4 +collision_mask = 0 +physics_material_override = SubResource( 3 ) +gravity_scale = 0.0 +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] +shape = SubResource( 1 ) + +[node name="MeshInstance" type="MeshInstance" parent="."] +mesh = SubResource( 2 ) diff --git a/cosmic/project.godot b/cosmic/project.godot new file mode 100644 index 0000000..056cc70 --- /dev/null +++ b/cosmic/project.godot @@ -0,0 +1,70 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +[application] + +config/name="Sands and Waves (cosmic runner)" +run/main_scene="res://Scene.tscn" +config/icon="res://icon.png" + +[autoload] + +Global="*res://autoload/Global.tscn" +Events="*res://autoload/Events.tscn" + +[display] + +window/size/fullscreen=true + +[gui] + +common/drop_mouse_on_gui_input_disabled=true + +[input] + +move_right={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +move_left={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +move_forward={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +move_backward={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +toggle_mouse={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} + +[layer_names] + +3d_physics/layer_1="world" +3d_physics/layer_2="player" +3d_physics/layer_3="sounder" + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +environment/default_environment="res://default_env.tres"