+ buoyancy

This commit is contained in:
Dooho Yi 2023-10-29 00:44:49 +09:00
parent bb27973154
commit 93aa46f863
34 changed files with 2311 additions and 0 deletions

Binary file not shown.

16
buoyancy/FPSLabel.gd Normal file
View file

@ -0,0 +1,16 @@
extends Label
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
text = "FPS: %f" % Engine.get_frames_per_second()

144
buoyancy/Player.gd Normal file
View file

@ -0,0 +1,144 @@
extends RigidBody
onready var camera = $Head/Camera
onready var camera_base = $Head
onready var ground_ray_cast = $GroundRayCast
onready var state_label = $Head/Camera/StateLabel
onready var ocean = get_node("/root/Ocean")
var camera_x_rotation = 0
const mouse_sensitivity = 0.2
const SPEED = 1
const SPRINT_MOD = 1
var jump_impulse = 5
var paused = false
enum STATE {
FLOATING,
DIVING,
WALKING,
SAILING
}
var bound_object = null
var bound_offset = Vector2()
var state = STATE.WALKING
var _oldtf = Transform()
# Called when the node enters the scene tree for the first time.
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
# Mouse movement
if not paused:
if event is InputEventMouseMotion:
camera_base.rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
var x_delta = event.relative.y * mouse_sensitivity
if camera_x_rotation + x_delta > -90 and camera_x_rotation + x_delta < 90:
camera.rotate_x(deg2rad(-x_delta))
camera_x_rotation += x_delta
func grounded():
return ground_ray_cast.is_colliding()
func _integrate_forces(physics_state):
# State machine
state = swap_state()
if not paused:
var acc = Vector3()
var direction = Vector3()
var camera_base_basis = camera.get_global_transform().basis
var mod = SPRINT_MOD if Input.is_action_pressed("sprint") else 1
if Input.is_action_pressed("forward"):
direction -= camera_base_basis.z #forward is negative in Godot
if Input.is_action_pressed("backward"):
direction += camera_base_basis.z
# Strafe
if Input.is_action_pressed("left"):
direction -= camera_base_basis.x
if Input.is_action_pressed("right"):
direction += camera_base_basis.x
match state:
STATE.WALKING:
if Input.is_action_just_pressed("jump") and grounded():
physics_state.apply_central_impulse(Vector3.UP * jump_impulse)
else:
# Process inputs (only in the xz plane
acc.x = direction.x * SPEED * mod
acc.z = direction.z * SPEED * mod
if not grounded():
acc.y = -weight
STATE.DIVING:
# Process inputs in all directions
acc = direction * SPEED * mod
STATE.FLOATING:
physics_state.add_central_force(Vector3.DOWN * 9.8)
var wave = ocean.get_wave(translation.x, translation.z)
var wave_height = wave.y
var height = translation.y
acc = direction * SPEED * mod
if height < wave_height:
var buoyancy = clamp((wave_height - height) / 0.001, 0, 1) * 5
physics_state.add_central_force(Vector3(0, 9.8 * buoyancy, 0))
#physics_state.add_central_force(buoyancy * -physics_state.linear_velocity * 0.5)
#physics_state.add_torque(buoyancy * -physics_state.angular_velocity * 0.5)
STATE.SAILING:
self.transform = bound_object.transform
self.translate(bound_offset)
physics_state.add_central_force(acc * mass)
# emit signal - playerinfo_updated
var tf = $Head/Camera.get_global_transform_interpolated()
if tf != _oldtf:
Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y)
_oldtf = tf
func swap_state():
var wave_height = ocean.get_wave(translation.x, translation.z).y
var new_state = state
match state:
STATE.WALKING:
# Are we in water
if translation.y < wave_height:
if linear_velocity.y < -5:
new_state = STATE.DIVING
else:
new_state = STATE.FLOATING
STATE.DIVING:
# Are we on or above water
if translation.y >= wave_height:
new_state = STATE.FLOATING
STATE.FLOATING:
if grounded():
new_state = STATE.WALKING
if translation.y < wave_height - 0.1:
new_state = STATE.DIVING
return new_state
func _process(delta):
if Input.is_action_just_pressed("pause"):
toggle_pause()
state_label.text = "%s" % STATE.keys()[state]
func toggle_pause():
paused = !paused
if paused:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

55
buoyancy/Player.tscn Normal file
View file

@ -0,0 +1,55 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Player.gd" type="Script" id=1]
[ext_resource path="res://FPSLabel.gd" type="Script" id=2]
[ext_resource path="res://ocean/Floater.tscn" type="PackedScene" id=3]
[sub_resource type="CapsuleMesh" id=1]
radius = 0.5
[sub_resource type="CapsuleShape" id=2]
radius = 0.5
[node name="Player" type="RigidBody"]
custom_integrator = true
axis_lock_angular_x = true
axis_lock_angular_y = true
axis_lock_angular_z = true
linear_damp = 1.0
angular_damp = 1.0
script = ExtResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
mesh = SubResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
shape = SubResource( 2 )
[node name="Head" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.70418, 0 )
[node name="Camera" type="Camera" parent="Head"]
[node name="FPSLabel" type="Label" parent="Head/Camera"]
margin_right = 40.0
margin_bottom = 14.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="StateLabel" type="Label" parent="Head/Camera"]
margin_top = 14.5121
margin_right = 40.0
margin_bottom = 28.5121
__meta__ = {
"_edit_use_anchors_": false
}
[node name="GroundRayCast" type="RayCast" parent="."]
enabled = true
cast_to = Vector3( 0, -1.2, 0 )
[node name="Floater" parent="." instance=ExtResource( 3 )]

3
buoyancy/README.md Normal file
View file

@ -0,0 +1,3 @@
# Waves and Buoyancy
![waves](https://user-images.githubusercontent.com/22628069/150696317-69975dd7-7cf9-491a-aaa3-dc97c9a5dbe3.png)

263
buoyancy/SoundBoxLying.pd Normal file
View file

@ -0,0 +1,263 @@
#N canvas 67 146 456 518 12;
#X msg 361 51 \; pd dsp 1;
#X obj 21 22 r fromGodot\$0;
#X obj 21 46 list trim;
#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 obj 199 467 dac~ 1 2;
#X obj 200 408 *~;
#X obj 189 127 unpack f f;
#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 361 21 loadbang;
#X obj 21 70 route bang panvol param preset;
#N canvas 52 27 1207 801 Lying 0;
#X floatatom 26 425 5 0 0 0 - - - 0;
#X obj 25 179 metro 0.25 120 permin;
#X obj 25 153 tgl 15 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000 0 1;
#X obj 25 208 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000;
#X msg 78 149 tempo \$1 permin;
#X floatatom 78 124 5 0 300 2 BPM - - 0;
#X obj 25 234 f;
#X obj 69 233 + 1;
#X floatatom 25 282 5 0 0 0 - - - 0;
#X obj 25 305 hradio 15 1 0 16 empty empty empty 0 -8 0 10 #fcfcfc #000000 #000000 0;
#X obj 65 377 > 0;
#X obj 26 401 spigot;
#X obj 25 349 trigger f f;
#X obj 26 448 mtof;
#X floatatom 26 472 5 0 0 0 - - - 0;
#X obj 55 508 pack;
#X floatatom 190 213 5 0 0 1 Slew - - 0;
#X msg 55 538 \$1 \$2;
#X obj 55 562 line~;
#X obj 55 642 phasor~;
#X obj 125 612 *~ 1.003;
#X obj 125 642 phasor~;
#X obj 125 682 expr~ $v1 - 1;
#X obj 228 409 bob~;
#X floatatom 240 361 5 0 0 0 - - - 0;
#X floatatom 286 361 5 0 0 0 - - - 0;
#X obj 228 439 hip~ 5;
#X obj 551 795 *~ 0.1;
#X obj 331 512 delwrite~ \$0-buffer 1000;
#X obj 331 482 *~;
#X obj 352 456 hsl 128 15 0 5 0 0 empty empty gain -2 -8 0 10 #fcfcc4 #000000 #000000 0 1;
#X obj 429 601 delread~ \$0-buffer 10;
#X obj 475 761 *~;
#X obj 500 652 hsl 128 15 0 127 0 0 empty empty feedback -2 -8 0 10 #fcfcfc #000000 #000000 0 1;
#X floatatom 497 678 5 0 0 0 - - - 0;
#X floatatom 429 578 5 0 0 0 - - - 0;
#X obj 432 558 hsl 128 15 0 127 0 0 empty empty delay -2 -8 0 10 #fcfcfc #000000 #000000 0 1;
#X obj 107 15 inlet;
#X floatatom 107 69 5 0 0 0 - - - 0;
#X floatatom 151 69 5 0 0 0 - - - 0;
#X floatatom 196 69 5 0 0 0 - - - 0;
#X floatatom 240 69 5 0 0 0 - - - 0;
#X floatatom 370 482 5 0 0 0 - - - 0;
#X floatatom 285 69 5 0 5 0 - - - 0;
#X floatatom 329 69 5 0 0 0 - - - 0;
#X floatatom 374 69 5 0 2 0 - - - 0;
#X obj 25 14 loadbang;
#X msg 25 38 1;
#X obj 595 113 bng 19 250 50 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000;
#X obj 595 34 loadbang;
#X obj 25 258 % 16;
#X floatatom 591 586 5 0 0 0 - - - 0;
#X obj 107 39 unpack f f f f f f f f, f 45;
#X floatatom 419 69 5 0 0 0 - - - 0;
#X msg 595 253 111 56 116 75 115 92 118 101 110 104 94 106 112 98 113 82;
#X obj 595 229 list trim;
#X obj 595 205 list prepend set;
#X obj 595 161 t a b;
#X msg 649 180 set;
#X obj 551 819 outlet~;
#X obj 598 292 inlet;
#X obj 157 15 r \$0-preset;
#X obj 658 704 s \$0-preset;
#X obj 598 332 sel 1 2 3 4 5 6 7 8 9 10 11 12, f 54;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-pitches 16 float 3;
#A 0 7.32 9.26 105 9.35 9.94 8.81 9 8 9 12 62 15 15 16 16 18;
#X coords 0 127 16 0 50 50 1 0 0;
#X restore 786 143 graph;
#X obj 595 82 array set \$0-pitches;
#X obj 595 137 array get \$0-pitches;
#X obj 25 325 array get \$0-pitches;
#X msg 595 58 7.32 9.26 105 9.35 9.94 8.81 9 8 9 12 62 15 15 16 16 18;
#X msg 598 386 43 1000 316 3.04 2.45 2.06 0.67 0.2;
#X msg 608 410 43 834.7 212 4.11 0.7 74.1 0.63 0.21;
#X msg 618 434 39 165.9 607.2 2.2 2.35 15.93 0.5 0.2;
#X msg 628 458 28 513 134.1 4.54 1.27 0.53 0.78 0.13;
#X msg 638 482 57 32 319.4 3.15 0.17 129.5 0.96 0.22;
#X msg 648 506 6 782 197.6 1.75 1.16 92.26 0.37 0.19;
#X msg 658 530 296 1.4 330.6 1.6 2 17.92 0.566 0.23;
#X msg 668 554 98.46 388.2 196 4 3.2 1.67 0.97 0.21;
#X msg 678 578 67.01 399 338 5.04 4.43 0.113 0.251 0.18;
#X msg 688 602 17 0 267 2.13 1 80.15 0.88 0.18;
#X msg 698 626 43 995 298 4.04 2.45 2.88 0.63 0.33;
#X msg 709 650 8.7 23.23 1.69 53.26 0.96 0.19;
#X connect 0 0 13 0;
#X connect 1 0 3 0;
#X connect 2 0 1 0;
#X connect 3 0 6 0;
#X connect 4 0 1 0;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 6 0 50 0;
#X connect 7 0 6 1;
#X connect 8 0 9 0;
#X connect 9 0 67 0;
#X connect 10 0 11 1;
#X connect 11 0 0 0;
#X connect 12 0 11 0;
#X connect 12 1 10 0;
#X connect 13 0 14 0;
#X connect 14 0 15 0;
#X connect 15 0 17 0;
#X connect 16 0 15 1;
#X connect 17 0 18 0;
#X connect 18 0 19 0;
#X connect 18 0 20 0;
#X connect 19 0 22 0;
#X connect 20 0 21 0;
#X connect 21 0 22 0;
#X connect 22 0 23 0;
#X connect 23 0 26 0;
#X connect 24 0 23 1;
#X connect 25 0 23 2;
#X connect 26 0 27 0;
#X connect 26 0 29 0;
#X connect 27 0 59 0;
#X connect 29 0 28 0;
#X connect 30 0 29 1;
#X connect 30 0 42 0;
#X connect 31 0 32 0;
#X connect 32 0 28 0;
#X connect 32 0 27 0;
#X connect 33 0 32 1;
#X connect 33 0 34 0;
#X connect 35 0 31 0;
#X connect 36 0 35 0;
#X connect 37 0 52 0;
#X connect 38 0 5 0;
#X connect 39 0 16 0;
#X connect 40 0 24 0;
#X connect 41 0 25 0;
#X connect 43 0 30 0;
#X connect 44 0 36 0;
#X connect 45 0 33 0;
#X connect 46 0 47 0;
#X connect 47 0 2 0;
#X connect 48 0 66 0;
#X connect 49 0 68 0;
#X connect 50 0 8 0;
#X connect 51 0 27 1;
#X connect 52 0 38 0;
#X connect 52 1 39 0;
#X connect 52 2 40 0;
#X connect 52 3 41 0;
#X connect 52 4 43 0;
#X connect 52 5 44 0;
#X connect 52 6 45 0;
#X connect 52 7 53 0;
#X connect 53 0 51 0;
#X connect 55 0 54 0;
#X connect 56 0 55 0;
#X connect 57 0 56 0;
#X connect 57 1 58 0;
#X connect 58 0 54 0;
#X connect 60 0 63 0;
#X connect 61 0 52 0;
#X connect 63 0 69 0;
#X connect 63 1 70 0;
#X connect 63 2 71 0;
#X connect 63 3 72 0;
#X connect 63 4 73 0;
#X connect 63 5 74 0;
#X connect 63 6 75 0;
#X connect 63 7 76 0;
#X connect 63 8 77 0;
#X connect 63 9 78 0;
#X connect 63 10 79 0;
#X connect 63 11 80 0;
#X connect 66 0 57 0;
#X connect 67 0 12 0;
#X connect 68 0 65 0;
#X connect 69 0 62 0;
#X connect 70 0 62 0;
#X connect 71 0 62 0;
#X connect 72 0 62 0;
#X connect 73 0 62 0;
#X connect 74 0 62 0;
#X connect 75 0 62 0;
#X connect 76 0 62 0;
#X connect 77 0 62 0;
#X connect 78 0 62 0;
#X connect 79 0 62 0;
#X connect 80 0 62 0;
#X restore 18 269 pd Lying;
#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 132 238 > -0.3;
#X obj 203 336 *~;
#X connect 1 0 2 0;
#X connect 2 0 16 0;
#X connect 3 0 6 0;
#X connect 4 0 8 1;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 7 0 5 0;
#X connect 8 0 9 0;
#X connect 8 1 9 1;
#X connect 10 0 8 0;
#X connect 11 0 20 0;
#X connect 11 1 12 0;
#X connect 12 0 13 0;
#X connect 13 0 14 0;
#X connect 14 0 3 0;
#X connect 15 0 0 0;
#X connect 16 1 11 0;
#X connect 16 2 17 0;
#X connect 16 3 17 1;
#X connect 17 0 10 0;
#X connect 18 0 27 0;
#X connect 18 0 27 1;
#X connect 19 0 18 0;
#X connect 20 0 25 0;
#X connect 20 0 26 0;
#X connect 22 0 21 0;
#X connect 23 0 22 0;
#X connect 25 0 19 0;
#X connect 26 0 23 0;
#X connect 27 0 10 1;

View file

@ -0,0 +1,263 @@
#N canvas 527 149 456 518 12;
#X msg 361 51 \; pd dsp 1;
#X obj 21 22 r fromGodot\$0;
#X obj 21 46 list trim;
#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 obj 199 467 dac~ 1 2;
#X obj 199 407 *~;
#X obj 189 127 unpack f f;
#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 361 21 loadbang;
#X obj 21 70 route bang panvol param preset;
#N canvas 53 227 1207 801 Floating 0;
#X floatatom 26 425 5 0 0 0 - - - 0;
#X obj 25 179 metro 0.25 120 permin;
#X obj 25 153 tgl 15 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000 0 1;
#X obj 25 208 bng 15 250 50 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000;
#X msg 78 149 tempo \$1 permin;
#X floatatom 78 124 5 0 300 2 BPM - - 0;
#X obj 25 234 f;
#X obj 69 233 + 1;
#X floatatom 25 282 5 0 0 0 - - - 0;
#X obj 25 305 hradio 15 1 0 16 empty empty empty 0 -8 0 10 #fcfcfc #000000 #000000 0;
#X obj 65 377 > 0;
#X obj 26 401 spigot;
#X obj 25 349 trigger f f;
#X obj 26 448 mtof;
#X floatatom 26 472 5 0 0 0 - - - 0;
#X obj 55 508 pack;
#X floatatom 190 213 5 0 0 1 Slew - - 0;
#X msg 55 538 \$1 \$2;
#X obj 55 562 line~;
#X obj 55 642 phasor~;
#X obj 125 612 *~ 1.003;
#X obj 125 642 phasor~;
#X obj 125 682 expr~ $v1 - 1;
#X obj 228 409 bob~;
#X floatatom 240 361 5 0 0 0 - - - 0;
#X floatatom 286 361 5 0 0 0 - - - 0;
#X obj 228 439 hip~ 5;
#X obj 551 795 *~ 0.1;
#X obj 331 512 delwrite~ \$0-buffer 1000;
#X obj 331 482 *~;
#X obj 352 456 hsl 128 15 0 5 0 0 empty empty gain -2 -8 0 10 #fcfcc4 #000000 #000000 0 1;
#X obj 429 601 delread~ \$0-buffer 10;
#X obj 475 761 *~;
#X obj 500 652 hsl 128 15 0 127 0 0 empty empty feedback -2 -8 0 10 #fcfcfc #000000 #000000 0 1;
#X floatatom 497 678 5 0 0 0 - - - 0;
#X floatatom 429 578 5 0 0 0 - - - 0;
#X obj 432 558 hsl 128 15 0 127 0 0 empty empty delay -2 -8 0 10 #fcfcfc #000000 #000000 0 1;
#X obj 107 15 inlet;
#X floatatom 107 69 5 0 0 0 - - - 0;
#X floatatom 151 69 5 0 0 0 - - - 0;
#X floatatom 196 69 5 0 0 0 - - - 0;
#X floatatom 240 69 5 0 0 0 - - - 0;
#X floatatom 370 482 5 0 0 0 - - - 0;
#X floatatom 285 69 5 0 5 0 - - - 0;
#X floatatom 329 69 5 0 0 0 - - - 0;
#X floatatom 374 69 5 0 2 0 - - - 0;
#X obj 25 14 loadbang;
#X msg 25 38 1;
#X obj 595 113 bng 19 250 50 0 empty empty empty 0 -10 0 12 #fcfcfc #000000 #000000;
#X obj 595 34 loadbang;
#X obj 25 258 % 16;
#X floatatom 591 586 5 0 0 0 - - - 0;
#X obj 107 39 unpack f f f f f f f f, f 45;
#X floatatom 419 69 5 0 0 0 - - - 0;
#X msg 595 253 111 56 116 75 115 92 118 101 110 104 94 106 112 98 113 82;
#X obj 595 229 list trim;
#X obj 595 205 list prepend set;
#X obj 595 161 t a b;
#X msg 649 180 set;
#X obj 551 819 outlet~;
#X obj 598 292 inlet;
#X obj 157 15 r \$0-preset;
#X obj 658 704 s \$0-preset;
#X obj 598 332 sel 1 2 3 4 5 6 7 8 9 10 11 12, f 54;
#X msg 598 386 84 140 587 1.97 1.2 134.7 0.6 0.88;
#X msg 608 410 18.73 18 552 2.26 1.28 360 0.645 0.67;
#X msg 618 434 6 306 484.9 0.43 2.57 2.23 0.8 0.55;
#X msg 628 458 28 513 250 3.06 2.2 1.03 0.94 0.19;
#X msg 638 482 57 0 320 4.43 0.9 129.5 0.96 0.19;
#X msg 648 506 6 782 197.6 1.75 1.16 92.26 0.37 0.19;
#X msg 658 530 19 0 183.6 1.45 3.11 79.26 0.88 0.19;
#X msg 668 554 16.5 0 386 1.89 5 51.67 0.83 0.21;
#X msg 678 578 56 0 1665 1.06 0.64 1376 0.72 0.15;
#X msg 688 602 16.98 585 122 10.82 2 432 0.88 0.22;
#X msg 698 626 43 995 298 4.04 2.45 2.88 0.63 0.33;
#X msg 708 650 10 131 188.7 23.23 1.69 53.26 0.96 0.19;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-pitches 16 float 3;
#A 0 111 56 116 75 115 92 118 101 110 104 94 106 112 98 113 82;
#X coords 0 127 16 0 50 50 1 0 0;
#X restore 786 143 graph;
#X obj 595 82 array set \$0-pitches;
#X obj 595 137 array get \$0-pitches;
#X obj 25 325 array get \$0-pitches;
#X msg 595 58 111 56 116 75 115 92 118 101 110 104 94 106 112 98 113 82;
#X connect 0 0 13 0;
#X connect 1 0 3 0;
#X connect 2 0 1 0;
#X connect 3 0 6 0;
#X connect 4 0 1 0;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 6 0 50 0;
#X connect 7 0 6 1;
#X connect 8 0 9 0;
#X connect 9 0 79 0;
#X connect 10 0 11 1;
#X connect 11 0 0 0;
#X connect 12 0 11 0;
#X connect 12 1 10 0;
#X connect 13 0 14 0;
#X connect 14 0 15 0;
#X connect 15 0 17 0;
#X connect 16 0 15 1;
#X connect 17 0 18 0;
#X connect 18 0 19 0;
#X connect 18 0 20 0;
#X connect 19 0 22 0;
#X connect 20 0 21 0;
#X connect 21 0 22 0;
#X connect 22 0 23 0;
#X connect 23 0 26 0;
#X connect 24 0 23 1;
#X connect 25 0 23 2;
#X connect 26 0 27 0;
#X connect 26 0 29 0;
#X connect 27 0 59 0;
#X connect 29 0 28 0;
#X connect 30 0 29 1;
#X connect 30 0 42 0;
#X connect 31 0 32 0;
#X connect 32 0 28 0;
#X connect 32 0 27 0;
#X connect 33 0 32 1;
#X connect 33 0 34 0;
#X connect 35 0 31 0;
#X connect 36 0 35 0;
#X connect 37 0 52 0;
#X connect 38 0 5 0;
#X connect 39 0 16 0;
#X connect 40 0 24 0;
#X connect 41 0 25 0;
#X connect 43 0 30 0;
#X connect 44 0 36 0;
#X connect 45 0 33 0;
#X connect 46 0 47 0;
#X connect 47 0 2 0;
#X connect 48 0 78 0;
#X connect 49 0 80 0;
#X connect 50 0 8 0;
#X connect 51 0 27 1;
#X connect 52 0 38 0;
#X connect 52 1 39 0;
#X connect 52 2 40 0;
#X connect 52 3 41 0;
#X connect 52 4 43 0;
#X connect 52 5 44 0;
#X connect 52 6 45 0;
#X connect 52 7 53 0;
#X connect 53 0 51 0;
#X connect 55 0 54 0;
#X connect 56 0 55 0;
#X connect 57 0 56 0;
#X connect 57 1 58 0;
#X connect 58 0 54 0;
#X connect 60 0 63 0;
#X connect 61 0 52 0;
#X connect 63 0 64 0;
#X connect 63 1 65 0;
#X connect 63 2 66 0;
#X connect 63 3 67 0;
#X connect 63 4 68 0;
#X connect 63 5 69 0;
#X connect 63 6 70 0;
#X connect 63 7 71 0;
#X connect 63 8 72 0;
#X connect 63 9 73 0;
#X connect 63 10 74 0;
#X connect 63 11 75 0;
#X connect 64 0 62 0;
#X connect 65 0 62 0;
#X connect 66 0 62 0;
#X connect 67 0 62 0;
#X connect 68 0 62 0;
#X connect 69 0 62 0;
#X connect 70 0 62 0;
#X connect 71 0 62 0;
#X connect 72 0 62 0;
#X connect 73 0 62 0;
#X connect 74 0 62 0;
#X connect 75 0 62 0;
#X connect 78 0 57 0;
#X connect 79 0 12 0;
#X connect 80 0 77 0;
#X restore 18 269 pd Floating;
#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 132 238 > -0.3;
#X obj 203 336 *~;
#X connect 1 0 2 0;
#X connect 2 0 16 0;
#X connect 3 0 6 0;
#X connect 4 0 8 1;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 7 0 5 0;
#X connect 8 0 9 0;
#X connect 8 1 9 1;
#X connect 10 0 8 0;
#X connect 11 0 20 0;
#X connect 11 1 12 0;
#X connect 12 0 13 0;
#X connect 13 0 14 0;
#X connect 14 0 3 0;
#X connect 15 0 0 0;
#X connect 16 1 11 0;
#X connect 16 2 17 0;
#X connect 16 3 17 1;
#X connect 17 0 10 0;
#X connect 18 0 27 0;
#X connect 18 0 27 1;
#X connect 19 0 18 0;
#X connect 20 0 25 0;
#X connect 20 0 26 0;
#X connect 22 0 21 0;
#X connect 23 0 22 0;
#X connect 25 0 19 0;
#X connect 26 0 23 0;
#X connect 27 0 10 1;

95
buoyancy/SoundBuoyRand.gd Normal file
View file

@ -0,0 +1,95 @@
extends RigidBody
export (String, MULTILINE) var patch = ""
export (float, 0, 100) var audible_range_max = 10.0
export (float, 1, 12) var preset = 1
var _my_patch = "res://SoundBoxLying.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)
# _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)
pass
#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()

View file

@ -0,0 +1,23 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://SoundBuoyRand.gd" type="Script" id=1]
[sub_resource type="SpatialMaterial" id=3]
albedo_color = Color( 0.921569, 0.494118, 0.694118, 1 )
[sub_resource type="SphereMesh" id=1]
material = SubResource( 3 )
radius = 1.459
height = 1.083
[sub_resource type="ConvexPolygonShape" id=2]
points = PoolVector3Array( 0.14602, -0.102076, 1.42342, -0.219537, -0.0658975, -1.42853, -0.218843, 0.0803725, -1.42401, 1.42853, -0.0658975, -0.219537, 0.105642, 0.53546, 0.175801, -1.17876, -0.314129, 0.142673, 0.352377, -0.521109, -0.175919, -1.25567, 0.258471, 0.25097, 0.461951, 0.291547, 1.13684, 0.992575, 0.326336, -0.602528, -0.85013, 0.290827, -0.885845, -0.792132, 0.151385, 1.15232, 0.757919, -0.172957, -1.15507, 1.03698, -0.207188, 0.858142, -0.389239, -0.381989, 0.955797, -1.03684, -0.207215, -0.858252, 1.1369, 0.291563, 0.461705, -0.282969, -0.416976, -0.884008, 0.212696, 0.361742, -1.06321, -0.596437, 0.463472, 0.456036, -1.01224, -0.101075, 1.01252, -1.42401, 0.0803724, -0.218843, -0.634646, -0.486325, -0.0702769, 1.10137, -0.34791, -0.177412, 0.317427, -0.450965, 0.740393, 0.800108, 0.0800942, -1.2003, -0.596435, 0.46347, -0.456034, 1.13038, 0.043762, 0.911546, 0.389491, -0.381972, -0.955754, -0.21339, 0.3277, 1.13926, 0.491401, 0.49861, -0.280533, -0.911547, 0.043762, -1.13039, -1.35204, -0.0657389, 0.511516, 0.456279, 0.463446, 0.596404, 1.34784, 0.0802032, -0.509821, -0.401969, -0.0657613, 1.38931, 1.42853, -0.0658975, 0.219537, 0.955797, -0.381989, 0.389239, 0.400968, 0.080235, 1.38488, 1.15506, -0.172956, -0.757916, -0.421868, -0.484681, 0.491911, -1.06324, 0.361753, -0.212432, 0.467819, -0.2085, 1.25924, -1.38267, -0.101763, -0.363728, -0.919914, -0.346564, 0.636967, -1.03118, -0.348309, -0.426648, -0.143343, -0.243849, -1.29228, -1.07176, 0.221697, 0.785884, 1.37466, 0.152041, 0.253002, 0.990737, 0.396511, 0.035123, -0.461704, 0.291562, -1.1369, -0.176079, 0.500229, -0.527699, -0.0728398, 0.116527, 1.4201, 0.400968, 0.0802351, -1.38488, -1.26559, 0.115794, -0.65088, 0.813189, -0.381526, -0.63635, -0.0704785, 0.465277, 0.739756, -0.644202, -0.207409, -1.18126, -0.286048, -0.278611, 1.21543, -0.176192, -0.521119, -0.352115, 0.281713, -0.520755, 0.281444, 0.290362, -0.137785, -1.37894, 0.889028, 0.256232, 0.9246, 0.694799, -0.0291507, 1.27961 )
[node name="SoundBuoyRand" type="RigidBody"]
script = ExtResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = SubResource( 1 )
[node name="CollisionShape2" type="CollisionShape" parent="."]
shape = SubResource( 2 )

80
buoyancy/SoundBuoyy.gd Normal file
View file

@ -0,0 +1,80 @@
extends RigidBody
export (String, MULTILINE) var patch = ""
export (float, 0, 100) var audible_range_max = 10.0
export (float, 1, 12) var preset = 1
var _my_patch = "res://SoundBoxLying.pd"
var _my_id = 0
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 _ready():
# save patch (for export)
# _save_patch()
# load patch
_my_id = Global.load_patch(ProjectSettings.globalize_path(_my_patch))
# send a 'individual' bang.
Global._gdpd.start_message(1)
Global._gdpd.add_symbol('bang') # there's no 'add_bang', only 'add_symbol' => add_symbol('bang') is a pseudo-bang
Global._gdpd.finish_list("fromGodot" + String(_my_id)) # send msg. individually ($0)
# 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)
pass
#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()

33
buoyancy/SoundBuoyy.tscn Normal file
View file

@ -0,0 +1,33 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://ocean/Floater.tscn" type="PackedScene" id=1]
[ext_resource path="res://SoundBuoyy.gd" type="Script" id=2]
[sub_resource type="CylinderMesh" id=1]
top_radius = 0.541
[sub_resource type="ConvexPolygonShape" id=2]
points = PoolVector3Array( 1, 1, 0, 1, -1, 0, 0.995106, 1, -0.0980814, 0.995106, 1, 0.0978857, 0.995106, -1, 0.0978857, 0.995106, -1, -0.0980814, 0.980619, 1, -0.195184, 0.980619, 1, 0.194988, 0.980619, -1, 0.194988, 0.980619, -1, -0.195184, 0.95693, 1, -0.290329, 0.95693, 1, 0.290133, 0.95693, -1, 0.290133, 0.95693, -1, -0.290329, 0.923845, 1, -0.382733, 0.923845, 1, 0.382537, 0.923845, -1, 0.382537, 0.923845, -1, -0.382733, 0.881754, 1, -0.471417, 0.881754, 1, 0.471222, 0.881754, -1, 0.471222, 0.881754, -1, -0.471417, 0.831441, 1, -0.555599, 0.831441, 1, 0.555403, 0.831441, -1, 0.555403, 0.831441, -1, -0.555599, 0.772905, 1, -0.634495, 0.772905, 1, 0.634299, 0.772905, -1, 0.634299, 0.772905, -1, -0.634495, 0.70693, 1, -0.707126, 0.70693, 1, 0.70693, 0.70693, -1, 0.70693, 0.70693, -1, -0.707126, 0.634299, 1, -0.773101, 0.634299, 1, 0.772905, 0.634299, -1, 0.772905, 0.634299, -1, -0.773101, 0.555403, 1, -0.831637, 0.555403, 1, 0.831441, 0.555403, -1, 0.831441, 0.555403, -1, -0.831637, 0.471222, 1, -0.88195, 0.471222, 1, 0.881754, 0.471222, -1, 0.881754, 0.471222, -1, -0.88195, 0.382537, 1, -0.924041, 0.382537, 1, 0.923845, 0.382537, -1, 0.923845, 0.382537, -1, -0.924041, 0.290133, 1, -0.957126, 0.290133, 1, 0.95693, 0.290133, -1, 0.95693, 0.290133, -1, -0.957126, 0.194988, 1, -0.980814, 0.194988, 1, 0.980619, 0.194988, -1, 0.980619, 0.194988, -1, -0.980814, 0.0978857, 1, -0.995301, 0.0978857, 1, 0.995106, 0.0978857, -1, 0.995106, 0.0978857, -1, -0.995301, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0, -1, -1, -0.0980814, 1, -0.995301, -0.0980814, 1, 0.995106, -0.0980814, -1, 0.995106, -0.0980814, -1, -0.995301, -0.195184, 1, -0.980814, -0.195184, 1, 0.980619, -0.195184, -1, 0.980619, -0.195184, -1, -0.980814, -0.290329, 1, -0.957126, -0.290329, 1, 0.95693, -0.290329, -1, 0.95693, -0.290329, -1, -0.957126, -0.382733, 1, -0.924041, -0.382733, 1, 0.923845, -0.382733, -1, 0.923845, -0.382733, -1, -0.924041, -0.471417, 1, -0.88195, -0.471417, 1, 0.881754, -0.471417, -1, 0.881754, -0.471417, -1, -0.88195, -0.555599, 1, -0.831637, -0.555599, 1, 0.831441, -0.555599, -1, 0.831441, -0.555599, -1, -0.831637, -0.634495, 1, -0.773101, -0.634495, 1, 0.772905, -0.634495, -1, 0.772905, -0.634495, -1, -0.773101, -0.707126, 1, -0.707126, -0.707126, 1, 0.70693, -0.707126, -1, 0.70693, -0.707126, -1, -0.707126, -0.773101, 1, -0.634495, -0.773101, 1, 0.634299, -0.773101, -1, 0.634299, -0.773101, -1, -0.634495, -0.831637, 1, -0.555599, -0.831637, 1, 0.555403, -0.831637, -1, 0.555403, -0.831637, -1, -0.555599, -0.88195, 1, -0.471417, -0.88195, 1, 0.471222, -0.88195, -1, 0.471222, -0.88195, -1, -0.471417, -0.924041, 1, -0.382733, -0.924041, 1, 0.382537, -0.924041, -1, 0.382537, -0.924041, -1, -0.382733, -0.957126, 1, -0.290329, -0.957126, 1, 0.290133, -0.957126, -1, 0.290133, -0.957126, -1, -0.290329, -0.980814, 1, -0.195184, -0.980814, 1, 0.194988, -0.980814, -1, 0.194988, -0.980814, -1, -0.195184, -0.995301, 1, -0.0980814, -0.995301, 1, 0.0978857, -0.995301, -1, 0.0978857, -0.995301, -1, -0.0980814, -1, 1, 0, -1, -1, 0 )
[node name="SoundBuoyy1" type="RigidBody"]
script = ExtResource( 2 )
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1.91069e-15, 4.37114e-08, 1, 1, -4.37114e-08, 0, 4.37114e-08, 1, -4.37114e-08, 0, 0, 0 )
mesh = SubResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1.91069e-15, 4.37114e-08, 1, 1, -4.37114e-08, 0, 4.37114e-08, 1, -4.37114e-08, 0, 0, 0 )
shape = SubResource( 2 )
[node name="Floater" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 1 )
[node name="Floater2" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, -1 )
[node name="Floater3" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, -0.5, 0 )
[node name="Floater4" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, -0.5, 0 )

View file

@ -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 )

View file

@ -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=[ ]

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,5 @@
extends Node
signal player_transform_updated(position, heading)
# position : Vector3
# heading : Vector2 (projected x-z plane, and normalized)

View file

@ -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 )

View file

@ -0,0 +1,57 @@
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")

View file

@ -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 )

View file

@ -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 )

View file

@ -0,0 +1,73 @@
[preset.0]
name="Mac OSX"
platform="Mac OSX"
runnable=true
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="./Buoyancy and Waves.dmg"
script_export_mode=1
script_encryption_key=""
[preset.0.options]
custom_template/debug=""
custom_template/release=""
application/name=""
application/info="Made with Godot Engine"
application/icon=""
application/identifier="org.sandreceive.buoyancy"
application/signature=""
application/app_category="Games"
application/short_version="1.0"
application/version="1.0"
application/copyright=""
display/high_res=false
privacy/microphone_usage_description=""
privacy/camera_usage_description=""
privacy/location_usage_description=""
privacy/address_book_usage_description=""
privacy/calendar_usage_description=""
privacy/photos_library_usage_description=""
privacy/desktop_folder_usage_description=""
privacy/documents_folder_usage_description=""
privacy/downloads_folder_usage_description=""
privacy/network_volumes_usage_description=""
privacy/removable_volumes_usage_description=""
codesign/enable=true
codesign/identity=""
codesign/timestamp=false
codesign/hardened_runtime=false
codesign/replace_existing_signature=true
codesign/entitlements/custom_file=""
codesign/entitlements/allow_jit_code_execution=false
codesign/entitlements/allow_unsigned_executable_memory=false
codesign/entitlements/allow_dyld_environment_variables=false
codesign/entitlements/disable_library_validation=true
codesign/entitlements/audio_input=false
codesign/entitlements/camera=false
codesign/entitlements/location=false
codesign/entitlements/address_book=false
codesign/entitlements/calendars=false
codesign/entitlements/photos_library=false
codesign/entitlements/apple_events=false
codesign/entitlements/debugging=false
codesign/entitlements/app_sandbox/enabled=false
codesign/entitlements/app_sandbox/network_server=false
codesign/entitlements/app_sandbox/network_client=false
codesign/entitlements/app_sandbox/device_usb=false
codesign/entitlements/app_sandbox/device_bluetooth=false
codesign/entitlements/app_sandbox/files_downloads=0
codesign/entitlements/app_sandbox/files_pictures=0
codesign/entitlements/app_sandbox/files_music=0
codesign/entitlements/app_sandbox/files_movies=0
codesign/custom_options=PoolStringArray( )
notarization/enable=false
notarization/apple_id_name=""
notarization/apple_id_password=""
notarization/apple_team_id=""
texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false

BIN
buoyancy/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

16
buoyancy/ocean/Camera.gd Normal file
View file

@ -0,0 +1,16 @@
extends Camera
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

47
buoyancy/ocean/Floater.gd Normal file
View file

@ -0,0 +1,47 @@
extends Spatial
class_name Floater
var depth_before_submerged = 1.0
onready var ocean = get_node("/root/Ocean")
var last_position = Vector3()
var floater_count = 0
export var water_drag = 0.77
export var water_angular_drag = 0.2
export var enabled = true
# Called when the node enters the scene tree for the first time.
func _ready():
var parent_weight = get_parent().weight
# How many floater children does the parent have?
for c in get_parent().get_children():
if c.get_script() == get_script():
floater_count += 1
func get_position():
return get_global_transform().origin
func _physics_process(delta):
if not enabled:
return
# It had to be a world coord offset.... not just relative to the parent...
# reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
var world_coord_offset = get_position() - get_parent().translation
# Gravity
get_parent().add_force(Vector3.DOWN * 9.8, world_coord_offset)
var wave = ocean.get_wave(get_position().x, get_position().z)
var wave_height = wave.y / 2.0
var height = get_position().y
if height < wave_height:
var buoyancy = clamp((wave_height - height) / depth_before_submerged, 0, 1) * 2
get_parent().add_force(Vector3(0, 9.8 * buoyancy, 0), world_coord_offset)
get_parent().add_central_force(buoyancy * -get_parent().linear_velocity * water_drag)
get_parent().add_torque(buoyancy * -get_parent().angular_velocity * water_angular_drag)
if $Marker: $Marker.translation.y = wave_height

View file

@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://ocean/Floater.gd" type="Script" id=1]
[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 0.235294, 1, 0.0509804, 1 )
[sub_resource type="SphereMesh" id=2]
material = SubResource( 1 )
radius = 0.5
height = 1.0
[node name="Floater" type="Spatial"]
script = ExtResource( 1 )
[node name="Marker" type="MeshInstance" parent="."]
visible = false
mesh = SubResource( 2 )
material/0 = null

76
buoyancy/ocean/Ground.gd Normal file
View file

@ -0,0 +1,76 @@
extends StaticBody
tool
onready var mesh_instance = $MeshInstance
export(OpenSimplexNoise) var noise = OpenSimplexNoise.new() setget set_noise
export var amplitude = 10 setget set_amplitude
export var radius = 100 setget set_radius
# Called when the node enters the scene tree for the first time.
func _ready():
refresh_mesh()
if not Engine.editor_hint: mesh_instance.create_trimesh_collision()
func refresh_mesh():
if not Engine.editor_hint and not mesh_instance:
return
var mesh = ArrayMesh.new()
var plane = PlaneMesh.new()
plane.subdivide_width = 400
plane.subdivide_depth = 400
plane.size = Vector2(400, 400)
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, plane.get_mesh_arrays())
var mdt = MeshDataTool.new()
mdt.create_from_surface(mesh, 0)
for i in range(mdt.get_vertex_count()):
var vertex = mdt.get_vertex(i)
var height = noise.get_noise_2d(vertex.x, vertex.z) * amplitude
# Outside radius we ramp down
var r2_max = radius*radius
var r2 = vertex.x * vertex.x + vertex.z * vertex.z
if r2 > r2_max:
var drop_off_dist = 16000
var delta_h = clamp(r2-r2_max, 0, drop_off_dist)/drop_off_dist*amplitude
height -= delta_h
vertex.y += height
mdt.set_vertex(i, vertex)
# Calculate vertex normals, face-by-face.
for i in range(mdt.get_face_count()):
# Get the index in the vertex array.
var a = mdt.get_face_vertex(i, 0)
var b = mdt.get_face_vertex(i, 1)
var c = mdt.get_face_vertex(i, 2)
# Get vertex position using vertex index.
var ap = mdt.get_vertex(a)
var bp = mdt.get_vertex(b)
var cp = mdt.get_vertex(c)
# Calculate face normal.
var n = (bp - cp).cross(ap - bp).normalized()
# Add face normal to current vertex normal.
# This will not result in perfect normals, but it will be close.
mdt.set_vertex_normal(a, n + mdt.get_vertex_normal(a))
mdt.set_vertex_normal(b, n + mdt.get_vertex_normal(b))
mdt.set_vertex_normal(c, n + mdt.get_vertex_normal(c))
# Run through vertices one last time to normalize normals and
# set color to normal.
for i in range(mdt.get_vertex_count()):
var v = mdt.get_vertex_normal(i).normalized()
mdt.set_vertex_normal(i, v)
mesh.surface_remove(0)
mdt.commit_to_surface(mesh)
mesh_instance.mesh = mesh
func set_noise(n):
noise = n
if Engine.editor_hint: refresh_mesh()
func set_amplitude(a):
amplitude = a
if Engine.editor_hint: refresh_mesh()
func set_radius(r):
radius = r
if Engine.editor_hint: refresh_mesh()

112
buoyancy/ocean/Ocean.gd Normal file
View file

@ -0,0 +1,112 @@
extends Spatial
tool
var SBRtscn = load("res://SoundBuoyRand.tscn")
var time = 0
export var wave_a = Vector3(0.7, 1.0, 10.0) setget set_wave_a
export var wave_a_dir = Vector2(1.0, 0) setget set_wave_a_dir
export var wave_b = Vector3(0.4, 0.4, 16.0) setget set_wave_b
export var wave_b_dir = Vector2(1.0, 1.0) setget set_wave_b_dir
export var wave_c = Vector3(0.8, 0.4, 9) setget set_wave_c
export var wave_c_dir = Vector2(1.0, 0.5) setget set_wave_c_dir
onready var water_scene = preload("res://ocean/Water.tscn")
onready var water_resource = preload("res://ocean/Water.tres")
var water_material
var water_tiles = {}
const water_tile_width = 20
onready var player = $Player
# Called when the node enters the scene tree for the first time.
func _ready():
for i in range(-10, 10):
for j in range(-10, 10):
var water = water_scene.instance()
var pos = Vector2(i*water_tile_width, j*water_tile_width)
add_child(water)
water.translation.x = pos.x
water.translation.z = pos.y
water_tiles[pos] = water
water.set_surface_material(0, water_resource)
randomize()
for i in range(12):
var SBR = SBRtscn.instance()
# rstone.set_param(preset_grps[0][randi()%4])
# rstone.set_color(preset_colors[0])
SBR.set_preset(i)
SBR.audible_range_max = 20
add_child(SBR)
SBR.look_at_from_position(Vector3(rand_range(0, 100), -0.7, rand_range(-30, 30)), Vector3.ZERO, Vector3.UP)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
time += delta
if water_resource: water_resource.set_shader_param("time", time)
func _input(event):
pass
func dot(a, b):
return (a.x * b.x) + (a.y * b.y)
func P(wave: Vector3, wave_dir: Vector2, p: Vector2, t):
var amplitude = wave.x
var steepness = wave.y
var wavelength = wave.z
var k = 2.0 * PI / wavelength
var c = sqrt(9.8 / k)
var d = wave_dir.normalized()
var f = k * (dot(d, p) - (c * t))
var a = steepness / k
var dx = d.x * a * cos(f)
var dy = amplitude * a * sin(f)
var dz = d.y * a * cos(f)
return Vector3(dx, dy, dz)
func _get_wave(x, z):
var v = Vector3(x, 0, z)
v += P(wave_a, wave_a_dir, Vector2(x, z), time)
v += P(wave_b, wave_b_dir, Vector2(x, z), time)
v += P(wave_c, wave_c_dir, Vector2(x, z), time)
return v
func get_wave(x, z):
var v0 = _get_wave(x, z)
var offset = Vector2(x - v0.x, z - v0.z)
var v1 = _get_wave(x+offset.x/4.0, z+offset.y/4.0)
return v1
func set_wave_a(a):
wave_a = a
if water_resource: water_resource.set_shader_param("wave_a", a)
func set_wave_a_dir(a):
wave_a_dir = a
if water_resource: water_resource.set_shader_param("wave_a_dir", a)
func set_wave_b(b):
wave_b = b
if water_resource: water_resource.set_shader_param("wave_b", b)
func set_wave_b_dir(b):
wave_b_dir = b
if water_resource: water_resource.set_shader_param("wave_b_dir", b)
func set_wave_c(c):
wave_c = c
if water_resource: water_resource.set_shader_param("wave_c", c)
func set_wave_c_dir(c):
wave_c_dir = c
if water_resource: water_resource.set_shader_param("wave_c_dir", c)

105
buoyancy/ocean/Ocean.shader Normal file
View file

@ -0,0 +1,105 @@
shader_type spatial;
render_mode depth_draw_always, specular_phong, diffuse_burley, cull_disabled;
uniform vec4 water_colour: hint_color;
uniform vec4 deep_water_colour : hint_color;
// amplitude, steepness, wavelength
uniform vec3 wave_a = vec3(1.0, 1.0, 10.0);
uniform vec2 wave_a_dir = vec2(1.0, 0.0);
uniform vec3 wave_b = vec3(1.0, 0.25, 20.0);
uniform vec2 wave_b_dir = vec2(1.0, 1.0);
uniform vec3 wave_c = vec3(1.0, 0.15, 1.0);
uniform vec2 wave_c_dir = vec2(1.0, 0.5);
uniform sampler2D noise;
uniform float foam_level = 0.4;
uniform float time;
const float PI = 3.14159265358979323;
varying mat4 CAMERA;
varying float wave_height;
void fragment() {
float depthRaw = texture(DEPTH_TEXTURE, SCREEN_UV).r * 2.0 - 1.0;
float water_depth = PROJECTION_MATRIX[3][2] / (depthRaw + PROJECTION_MATRIX[2][2]);
// Normalmaps
vec2 direction = vec2(-1.0, 0.0);
NORMALMAP = texture(noise, UV + direction * TIME * 0.05).xyz;
NORMALMAP_DEPTH = 0.5;
// Refraction
vec2 offset = vec2(0.0);
// if (water_depth - VERTEX.z > 0.0) {
// offset = mix(NORMALMAP.xy - vec2(0.5), NORMAL.xz/10.0, 0.3);
// }
vec4 bg = texture(SCREEN_TEXTURE, SCREEN_UV + (offset * 0.2));
float foam_ammount = clamp((foam_level - water_depth - VERTEX.z) / foam_level, 0.0, 1.0);
vec4 colour = mix(water_colour, deep_water_colour, 1.0-clamp((wave_height)/1.0, 0, 1));
colour = mix(colour, vec4(1.0), foam_ammount);
float fog_factor = exp(-0.2 * water_depth/20.0);
// Set everything
EMISSION = mix(colour, bg, fog_factor).xyz * (1.0 - colour.a);
ALBEDO = colour.xyz;
ALPHA = 1.0;
SPECULAR = 0.4;
ROUGHNESS = 0.05;
}
vec3 gerstnerWave(vec3 wave, vec2 wave_dir, vec3 p, inout vec3 tangent, inout vec3 binormal, float t) {
float amplitude = wave.x;
float steepness = wave.y;
float wavelength = wave.z;
float k = 2.0 * PI / wavelength;
float c = sqrt(9.8 / k); // phase speed
vec2 d = normalize(wave_dir);
float f = k * (dot(d, p.xz) - (c * t));
float a = steepness / k;
tangent += normalize(vec3(
1.0 - d.x * d.x * steepness * sin(f),
d.x * steepness * cos(f),
-d.x * d.y * (steepness * sin(f))
));
binormal += normalize(vec3(
-d.x * d.y * (steepness * sin(f)),
d.y * steepness * cos(f),
1.0 - (d.y * d.y * steepness * sin(f))
));
return vec3(
d.x * (a * cos(f)),
amplitude * a * sin(f),
d.y * (a * cos(f))
);
}
void vertex() {
vec3 original_p = (WORLD_MATRIX * vec4(VERTEX.xyz, 1.0)).xyz;
vec3 p = VERTEX.xyz;
vec3 tangent = vec3(1.0, 0.0, 0.0);
vec3 binormal = vec3(0.0, 0.0, 1.0);
p += gerstnerWave(wave_a, wave_a_dir, original_p, tangent, binormal, time);
p += gerstnerWave(wave_b, wave_b_dir, original_p, tangent, binormal, time);
p += gerstnerWave(wave_c, wave_c_dir, original_p, tangent, binormal, time);
vec3 normal = normalize(cross(binormal, tangent));
VERTEX = p;
TANGENT = tangent;
BINORMAL = binormal;
NORMAL = normal;
CAMERA = CAMERA_MATRIX;
wave_height = p.y;
}

590
buoyancy/ocean/Ocean.tscn Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,75 @@
extends RigidBody
export (String, MULTILINE) var patch = ""
export (float, 0, 100) var audible_range_max = 10.0
export (float, 1, 12) var preset = 1
var _my_patch = "res://SoundBuoyFloating.pd"
var _my_id = 0
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 _ready():
# # 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()
# load patch
_my_id = Global.load_patch(ProjectSettings.globalize_path(_my_patch))
# send a 'individual' bang.
Global._gdpd.start_message(1)
Global._gdpd.add_symbol('bang') # there's no 'add_bang', only 'add_symbol' => add_symbol('bang') is a pseudo-bang
Global._gdpd.finish_list("fromGodot" + String(_my_id)) # send msg. individually ($0)
# 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 = max(1 - distance/audible_range_max, 0)
# 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)
pass

24
buoyancy/ocean/Water.tres Normal file
View file

@ -0,0 +1,24 @@
[gd_resource type="ShaderMaterial" load_steps=4 format=2]
[ext_resource path="res://ocean/Ocean.shader" type="Shader" id=1]
[sub_resource type="OpenSimplexNoise" id=1]
[sub_resource type="NoiseTexture" id=2]
seamless = true
as_normalmap = true
noise = SubResource( 1 )
[resource]
shader = ExtResource( 1 )
shader_param/water_colour = Color( 0.611765, 0.823529, 0.890196, 0.0980392 )
shader_param/deep_water_colour = Color( 0.521569, 0.117647, 0.647059, 0.45098 )
shader_param/wave_a = Vector3( 0.189, 0.477, 33 )
shader_param/wave_a_dir = Vector2( 1, 0 )
shader_param/wave_b = Vector3( 0.885, 0.25, 20 )
shader_param/wave_b_dir = Vector2( 1, 1 )
shader_param/wave_c = Vector3( 1, 0.15, 14 )
shader_param/wave_c_dir = Vector2( 1, 0.5 )
shader_param/foam_level = 0.4
shader_param/time = 116.641
shader_param/noise = SubResource( 2 )

View file

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[sub_resource type="PlaneMesh" id=1]
size = Vector2( 20, 20 )
subdivide_width = 20
subdivide_depth = 20
[node name="Water" type="MeshInstance"]
mesh = SubResource( 1 )

83
buoyancy/project.godot Normal file
View file

@ -0,0 +1,83 @@
; 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
_global_script_classes=[ {
"base": "Spatial",
"class": "Floater",
"language": "GDScript",
"path": "res://ocean/Floater.gd"
} ]
_global_script_class_icons={
"Floater": ""
}
[application]
config/name="Buoyancy and Waves"
run/main_scene="res://ocean/Ocean.tscn"
config/icon="res://icon.png"
[autoload]
Global="*res://autoload/Global.tscn"
Events="*res://autoload/Events.tscn"
[input]
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)
]
}
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)
]
}
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)
]
}
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)
]
}
pause={
"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)
]
}
jump={
"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":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
sprint={
"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":16777237,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
interact={
"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":69,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
[physics]
common/physics_fps=144
common/physics_jitter_fix=0.191
common/enable_pause_aware_picking=true
[rendering]
environment/default_environment="res://default_env.tres"