init
This commit is contained in:
commit
c48eb08725
23 changed files with 737 additions and 0 deletions
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
.DS_Store
|
||||||
|
.import/
|
||||||
|
*.import
|
||||||
|
|
||||||
|
**/.DS_Store
|
||||||
|
**/.import/
|
||||||
|
**/*.import
|
||||||
78
templates/worldscene1/Player.gd
Normal file
78
templates/worldscene1/Player.gd
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
var mouse_captured = true
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
||||||
|
func _physics_process(delta):
|
||||||
|
|
||||||
|
if mouse_captured:
|
||||||
|
aim()
|
||||||
|
fly(delta)
|
||||||
|
# emit signal - playerinfo_updated
|
||||||
|
var tf = $Head/Camera.get_global_transform_interpolated()
|
||||||
|
if tf != Events.player_tf_old:
|
||||||
|
Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y)
|
||||||
|
Events.player_tf_old = tf
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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()
|
||||||
21
templates/worldscene1/Player.tscn
Normal file
21
templates/worldscene1/Player.tscn
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[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 )
|
||||||
|
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"]
|
||||||
|
far = 10000.0
|
||||||
24
templates/worldscene1/Region.gd
Normal file
24
templates/worldscene1/Region.gd
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
extends Spatial
|
||||||
|
|
||||||
|
var main = load("res://main.tscn")
|
||||||
|
var sub = load("res://osc.tscn")
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# 'main' at center.
|
||||||
|
var m = main.instance()
|
||||||
|
add_child(m)
|
||||||
|
m.set_size(rand_range(10, 15))
|
||||||
|
m.audible_range_max = 80
|
||||||
|
m.set_freq(rand_range(100, 300))
|
||||||
|
m.set_gain(40)
|
||||||
|
|
||||||
|
# many 'sub' surrounds 'main' like satellites
|
||||||
|
for i in range(18):
|
||||||
|
var s = sub.instance()
|
||||||
|
add_child(s)
|
||||||
|
s.set_size(rand_range(0.2, 1.2))
|
||||||
|
s.set_color(Color.black)
|
||||||
|
var d = polar2cartesian(rand_range(20, 24), rand_range(0, 2*PI))
|
||||||
|
s.translate(Vector3(d.x, rand_range(-2, 2), d.y))
|
||||||
|
s.set_freq(rand_range(200, 2000))
|
||||||
|
s.set_gain(0.1)
|
||||||
6
templates/worldscene1/Region.tscn
Normal file
6
templates/worldscene1/Region.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Region.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="Region" type="Spatial"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
11
templates/worldscene1/Scene.gd
Normal file
11
templates/worldscene1/Scene.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
#var region = load("res://Region.tscn")
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
# for i in range(18):
|
||||||
|
# var oscnode = osctscn.instance()
|
||||||
|
# oscnode.set_size(randf()*5 + 0.2)
|
||||||
|
# oscnode.set_freq(randf()*800 + 200)
|
||||||
|
# add_child(oscnode)
|
||||||
44
templates/worldscene1/Scene.tscn
Normal file
44
templates/worldscene1/Scene.tscn
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
[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 )]
|
||||||
|
|
||||||
|
[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, -193.573, 78.9511, 112.625 )
|
||||||
|
|
||||||
|
[node name="Region3" parent="." instance=ExtResource( 1 )]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 67.7793, 64.9703, -27.1477 )
|
||||||
8
templates/worldscene1/addons/gdpd/bin/gdpd.gdns
Normal file
8
templates/worldscene1/addons/gdpd/bin/gdpd.gdns
Normal 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 )
|
||||||
18
templates/worldscene1/addons/gdpd/bin/libgdpd.gdnlib
Normal file
18
templates/worldscene1/addons/gdpd/bin/libgdpd.gdnlib
Normal 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=[ ]
|
||||||
BIN
templates/worldscene1/addons/gdpd/bin/osx/libgdpd.dylib
Executable file
BIN
templates/worldscene1/addons/gdpd/bin/osx/libgdpd.dylib
Executable file
Binary file not shown.
6
templates/worldscene1/autoload/Events.gd
Normal file
6
templates/worldscene1/autoload/Events.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
var player_tf_old = Transform()
|
||||||
|
signal player_transform_updated(position, heading)
|
||||||
|
# position : Vector3
|
||||||
|
# heading : Vector2 (projected x-z plane, and normalized)
|
||||||
6
templates/worldscene1/autoload/Events.tscn
Normal file
6
templates/worldscene1/autoload/Events.tscn
Normal 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 )
|
||||||
92
templates/worldscene1/autoload/Global.gd
Normal file
92
templates/worldscene1/autoload/Global.gd
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
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 (float) 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.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)
|
||||||
6
templates/worldscene1/autoload/Global.tscn
Normal file
6
templates/worldscene1/autoload/Global.tscn
Normal 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 )
|
||||||
7
templates/worldscene1/default_env.tres
Normal file
7
templates/worldscene1/default_env.tres
Normal 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 )
|
||||||
BIN
templates/worldscene1/icon.png
Normal file
BIN
templates/worldscene1/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
60
templates/worldscene1/main.gd
Normal file
60
templates/worldscene1/main.gd
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
extends RigidBody
|
||||||
|
|
||||||
|
export (String, MULTILINE) var patch = ""
|
||||||
|
export (float, 0, 100) var audible_range_max = 10.0
|
||||||
|
|
||||||
|
var _my_patch = "res://main.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_color(color):
|
||||||
|
$MeshInstance.material_override = SpatialMaterial.new()
|
||||||
|
$MeshInstance.material_override.albedo_color = color
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# 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")
|
||||||
|
|
||||||
|
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)
|
||||||
69
templates/worldscene1/main.pd
Normal file
69
templates/worldscene1/main.pd
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
#N canvas 574 271 456 518 12;
|
||||||
|
#X obj 361 21 loadbang;
|
||||||
|
#X msg 361 51 \; pd dsp 1;
|
||||||
|
#X floatatom 21 198 5 0 0 0 - - - 0;
|
||||||
|
#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 230 line~;
|
||||||
|
#X msg 189 206 \$1 100;
|
||||||
|
#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 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 connect 2 0 21 1;
|
||||||
|
#X connect 3 0 4 0;
|
||||||
|
#X connect 4 0 22 0;
|
||||||
|
#X connect 5 0 8 0;
|
||||||
|
#X connect 6 0 10 1;
|
||||||
|
#X connect 7 0 6 0;
|
||||||
|
#X connect 8 0 9 0;
|
||||||
|
#X connect 9 0 7 0;
|
||||||
|
#X connect 10 0 11 0;
|
||||||
|
#X connect 10 1 11 1;
|
||||||
|
#X connect 12 0 10 0;
|
||||||
|
#X connect 13 0 12 1;
|
||||||
|
#X connect 14 0 13 0;
|
||||||
|
#X connect 15 0 19 0;
|
||||||
|
#X connect 15 1 16 0;
|
||||||
|
#X connect 16 0 17 0;
|
||||||
|
#X connect 17 0 18 0;
|
||||||
|
#X connect 18 0 5 0;
|
||||||
|
#X connect 19 0 14 0;
|
||||||
|
#X connect 20 0 21 0;
|
||||||
|
#X connect 21 0 23 0;
|
||||||
|
#X connect 22 0 2 0;
|
||||||
|
#X connect 22 1 23 1;
|
||||||
|
#X connect 22 2 15 0;
|
||||||
|
#X connect 23 0 12 0;
|
||||||
23
templates/worldscene1/main.tscn
Normal file
23
templates/worldscene1/main.tscn
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://main.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="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( 1 )
|
||||||
|
|
||||||
|
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||||
|
mesh = SubResource( 2 )
|
||||||
95
templates/worldscene1/osc.gd
Normal file
95
templates/worldscene1/osc.gd
Normal 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://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)
|
||||||
|
# _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 = 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
|
||||||
|
|
||||||
|
#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()
|
||||||
67
templates/worldscene1/osc.pd
Normal file
67
templates/worldscene1/osc.pd
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#N canvas 116 274 456 518 12;
|
||||||
|
#X obj 361 21 loadbang;
|
||||||
|
#X msg 361 51 \; pd dsp 1;
|
||||||
|
#X obj 80 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 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 230 line~;
|
||||||
|
#X msg 189 206 \$1 100;
|
||||||
|
#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 floatatom 189 177 5 0 0 0 - - - 0;
|
||||||
|
#X obj 21 70 route freq gain panvol;
|
||||||
|
#X obj 80 301 *~;
|
||||||
|
#X connect 2 0 22 0;
|
||||||
|
#X connect 3 0 2 0;
|
||||||
|
#X connect 4 0 5 0;
|
||||||
|
#X connect 5 0 21 0;
|
||||||
|
#X connect 6 0 9 0;
|
||||||
|
#X connect 7 0 11 1;
|
||||||
|
#X connect 8 0 7 0;
|
||||||
|
#X connect 9 0 10 0;
|
||||||
|
#X connect 10 0 8 0;
|
||||||
|
#X connect 11 0 12 0;
|
||||||
|
#X connect 11 1 12 1;
|
||||||
|
#X connect 13 0 11 0;
|
||||||
|
#X connect 14 0 13 1;
|
||||||
|
#X connect 15 0 14 0;
|
||||||
|
#X connect 16 0 20 0;
|
||||||
|
#X connect 16 1 17 0;
|
||||||
|
#X connect 17 0 18 0;
|
||||||
|
#X connect 18 0 19 0;
|
||||||
|
#X connect 19 0 6 0;
|
||||||
|
#X connect 20 0 15 0;
|
||||||
|
#X connect 21 0 3 0;
|
||||||
|
#X connect 21 1 22 1;
|
||||||
|
#X connect 21 2 16 0;
|
||||||
|
#X connect 22 0 13 0;
|
||||||
23
templates/worldscene1/osc.tscn
Normal file
23
templates/worldscene1/osc.tscn
Normal file
|
|
@ -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 )
|
||||||
66
templates/worldscene1/project.godot
Normal file
66
templates/worldscene1/project.godot
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
; 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 (worldscene1)"
|
||||||
|
run/main_scene="res://Scene.tscn"
|
||||||
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
Global="*res://autoload/Global.tscn"
|
||||||
|
Events="*res://autoload/Events.tscn"
|
||||||
|
|
||||||
|
[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"
|
||||||
Loading…
Reference in a new issue