jtatman commited on
Commit
3a3791d
1 Parent(s): f595c44

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +11 -58
  2. .gitignore +2 -0
  3. AIController3D.gd +61 -0
  4. GridSensor3DExample.csproj +10 -0
  5. GridSensor3DExample.sln +25 -0
  6. PathFollower.gd +8 -0
  7. Player.gd +84 -0
  8. README.md +25 -0
  9. Ships.onnx +3 -0
  10. UIBasicsEnvironment.tres +64 -0
  11. WaterShader.tres +561 -0
  12. addons/godot_rl_agents/controller/ai_controller_2d.gd +113 -0
  13. addons/godot_rl_agents/controller/ai_controller_3d.gd +114 -0
  14. addons/godot_rl_agents/godot_rl_agents.gd +16 -0
  15. addons/godot_rl_agents/icon.png +3 -0
  16. addons/godot_rl_agents/onnx/csharp/ONNXInference.cs +103 -0
  17. addons/godot_rl_agents/onnx/csharp/SessionConfigurator.cs +131 -0
  18. addons/godot_rl_agents/onnx/csharp/docs/ONNXInference.xml +31 -0
  19. addons/godot_rl_agents/onnx/csharp/docs/SessionConfigurator.xml +29 -0
  20. addons/godot_rl_agents/onnx/wrapper/ONNX_wrapper.gd +27 -0
  21. addons/godot_rl_agents/plugin.cfg +7 -0
  22. addons/godot_rl_agents/sensors/sensors_2d/ExampleRaycastSensor2D.tscn +48 -0
  23. addons/godot_rl_agents/sensors/sensors_2d/GridSensor2D.gd +235 -0
  24. addons/godot_rl_agents/sensors/sensors_2d/ISensor2D.gd +25 -0
  25. addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.gd +118 -0
  26. addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.tscn +7 -0
  27. addons/godot_rl_agents/sensors/sensors_3d/ExampleRaycastSensor3D.tscn +6 -0
  28. addons/godot_rl_agents/sensors/sensors_3d/GridSensor3D.gd +258 -0
  29. addons/godot_rl_agents/sensors/sensors_3d/ISensor3D.gd +25 -0
  30. addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.gd +21 -0
  31. addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.tscn +41 -0
  32. addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.gd +185 -0
  33. addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.tscn +27 -0
  34. addons/godot_rl_agents/sync.gd +540 -0
  35. assets/bar_green.png +3 -0
  36. assets/bar_red.png +3 -0
  37. assets/bar_yellow.png +3 -0
  38. assets/boat_large.bin +3 -0
  39. assets/chest.bin +3 -0
  40. assets/chest.gltf +367 -0
  41. assets/island.blend +0 -0
  42. assets/islands.blend +0 -0
  43. assets/mine.blend +0 -0
  44. assets/ship_light.bin +3 -0
  45. assets/ship_light.gltf +1725 -0
  46. assets/sunflowers_puresky_2k.hdr +3 -0
  47. chest.gd +22 -0
  48. chest.tscn +0 -0
  49. deque.gd +84 -0
  50. game.gd +88 -0
.gitattributes CHANGED
@@ -1,58 +1,11 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.lz4 filter=lfs diff=lfs merge=lfs -text
12
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
13
- *.model filter=lfs diff=lfs merge=lfs -text
14
- *.msgpack filter=lfs diff=lfs merge=lfs -text
15
- *.npy filter=lfs diff=lfs merge=lfs -text
16
- *.npz filter=lfs diff=lfs merge=lfs -text
17
- *.onnx filter=lfs diff=lfs merge=lfs -text
18
- *.ot filter=lfs diff=lfs merge=lfs -text
19
- *.parquet filter=lfs diff=lfs merge=lfs -text
20
- *.pb filter=lfs diff=lfs merge=lfs -text
21
- *.pickle filter=lfs diff=lfs merge=lfs -text
22
- *.pkl filter=lfs diff=lfs merge=lfs -text
23
- *.pt filter=lfs diff=lfs merge=lfs -text
24
- *.pth filter=lfs diff=lfs merge=lfs -text
25
- *.rar filter=lfs diff=lfs merge=lfs -text
26
- *.safetensors filter=lfs diff=lfs merge=lfs -text
27
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
28
- *.tar.* filter=lfs diff=lfs merge=lfs -text
29
- *.tar filter=lfs diff=lfs merge=lfs -text
30
- *.tflite filter=lfs diff=lfs merge=lfs -text
31
- *.tgz filter=lfs diff=lfs merge=lfs -text
32
- *.wasm filter=lfs diff=lfs merge=lfs -text
33
- *.xz filter=lfs diff=lfs merge=lfs -text
34
- *.zip filter=lfs diff=lfs merge=lfs -text
35
- *.zst filter=lfs diff=lfs merge=lfs -text
36
- *tfevents* filter=lfs diff=lfs merge=lfs -text
37
- # Audio files - uncompressed
38
- *.pcm filter=lfs diff=lfs merge=lfs -text
39
- *.sam filter=lfs diff=lfs merge=lfs -text
40
- *.raw filter=lfs diff=lfs merge=lfs -text
41
- # Audio files - compressed
42
- *.aac filter=lfs diff=lfs merge=lfs -text
43
- *.flac filter=lfs diff=lfs merge=lfs -text
44
- *.mp3 filter=lfs diff=lfs merge=lfs -text
45
- *.ogg filter=lfs diff=lfs merge=lfs -text
46
- *.wav filter=lfs diff=lfs merge=lfs -text
47
- # Image files - uncompressed
48
- *.bmp filter=lfs diff=lfs merge=lfs -text
49
- *.gif filter=lfs diff=lfs merge=lfs -text
50
- *.png filter=lfs diff=lfs merge=lfs -text
51
- *.tiff filter=lfs diff=lfs merge=lfs -text
52
- # Image files - compressed
53
- *.jpg filter=lfs diff=lfs merge=lfs -text
54
- *.jpeg filter=lfs diff=lfs merge=lfs -text
55
- *.webp filter=lfs diff=lfs merge=lfs -text
56
- # Video files - compressed
57
- *.mp4 filter=lfs diff=lfs merge=lfs -text
58
- *.webm filter=lfs diff=lfs merge=lfs -text
 
1
+ # Normalize EOL for all files that Git considers text files.
2
+ * text=auto eol=lf
3
+ Ships.onnx filter=lfs diff=lfs merge=lfs -text
4
+ addons/godot_rl_agents/icon.png filter=lfs diff=lfs merge=lfs -text
5
+ assets/bar_green.png filter=lfs diff=lfs merge=lfs -text
6
+ assets/bar_red.png filter=lfs diff=lfs merge=lfs -text
7
+ assets/bar_yellow.png filter=lfs diff=lfs merge=lfs -text
8
+ assets/boat_large.bin filter=lfs diff=lfs merge=lfs -text
9
+ assets/chest.bin filter=lfs diff=lfs merge=lfs -text
10
+ assets/ship_light.bin filter=lfs diff=lfs merge=lfs -text
11
+ assets/sunflowers_puresky_2k.hdr filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Godot 4+ specific ignores
2
+ .godot/
AIController3D.gd ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends AIController3D
2
+
3
+
4
+ @onready var grid_sensor_3d = $GridSensor3D
5
+
6
+ var fb_action : float = 0.0
7
+ var turn_action : float = 0.0
8
+ var _player_positions : = Deque.new()
9
+
10
+
11
+ func _ready():
12
+ super._ready()
13
+ _player_positions.max_size = 80 # 10 steps with repeat of 8
14
+
15
+ func get_obs() -> Dictionary:
16
+ var obs = grid_sensor_3d.get_observation()
17
+ return {"obs": obs}
18
+
19
+ func get_reward() -> float:
20
+ return reward + keep_moving_reward()
21
+
22
+ func keep_moving_reward() -> float:
23
+ var mean_position = Vector3.ZERO
24
+ for pos in _player_positions:
25
+ mean_position += pos
26
+ mean_position /= _player_positions.size()
27
+
28
+ var penalty = 0.0
29
+
30
+ for pos in _player_positions:
31
+ penalty += (pos-mean_position).length()
32
+
33
+ #prints("penalty", 0.01*(penalty / _player_positions.size()))
34
+
35
+ return 0.005*(penalty / _player_positions.size())
36
+
37
+ func _physics_process(delta):
38
+ _player_positions.push_back(_player.position)
39
+
40
+ func reset():
41
+ super.reset()
42
+ _player_positions.clear()
43
+ _player_positions.push_back(_player.position)
44
+
45
+
46
+
47
+ func get_action_space() -> Dictionary:
48
+ return {
49
+ "fb" : {
50
+ "size": 1,
51
+ "action_type": "continuous"
52
+ },
53
+ "turn" : {
54
+ "size": 1,
55
+ "action_type": "continuous"
56
+ },
57
+ }
58
+
59
+ func set_action(action) -> void:
60
+ fb_action = clamp(action["fb"][0], -1.0, 1.0)
61
+ turn_action = clamp(action["turn"][0], -1.0, 1.0)
GridSensor3DExample.csproj ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <Project Sdk="Godot.NET.Sdk/4.0.3">
2
+ <PropertyGroup>
3
+ <TargetFramework>net6.0</TargetFramework>
4
+ <EnableDynamicLoading>true</EnableDynamicLoading>
5
+ <RootNamespace>GodotRLAgents</RootNamespace>
6
+ </PropertyGroup>
7
+ <ItemGroup>
8
+ <PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.15.1" />
9
+ </ItemGroup>
10
+ </Project>
GridSensor3DExample.sln ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 12.00
3
+ # Visual Studio Version 17
4
+ VisualStudioVersion = 17.5.33530.505
5
+ MinimumVisualStudioVersion = 10.0.40219.1
6
+ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Godot RL Agents", "Godot RL Agents.csproj", "{055E8CBC-A3EC-41A8-BC53-EC3010682AE4}"
7
+ EndProject
8
+ Global
9
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
+ Debug|Any CPU = Debug|Any CPU
11
+ ExportDebug|Any CPU = ExportDebug|Any CPU
12
+ ExportRelease|Any CPU = ExportRelease|Any CPU
13
+ EndGlobalSection
14
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
15
+ {055E8CBC-A3EC-41A8-BC53-EC3010682AE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16
+ {055E8CBC-A3EC-41A8-BC53-EC3010682AE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
17
+ {055E8CBC-A3EC-41A8-BC53-EC3010682AE4}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
18
+ {055E8CBC-A3EC-41A8-BC53-EC3010682AE4}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
19
+ {055E8CBC-A3EC-41A8-BC53-EC3010682AE4}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
20
+ {055E8CBC-A3EC-41A8-BC53-EC3010682AE4}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
21
+ EndGlobalSection
22
+ GlobalSection(SolutionProperties) = preSolution
23
+ HideSolutionNode = FALSE
24
+ EndGlobalSection
25
+ EndGlobal
PathFollower.gd ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ extends PathFollow3D
2
+
3
+
4
+
5
+ @export var speed:=0.3
6
+
7
+ func _physics_process(delta):
8
+ progress_ratio += delta * speed
Player.gd ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends CharacterBody3D
2
+ class_name Player
3
+
4
+ signal reset_signal
5
+
6
+ const SPEED := 30.0
7
+ const JUMP_VELOCITY := 4.5
8
+ const TURN_SENS := 2.0
9
+
10
+ @onready var ai_controller_3d = $AIController3D
11
+ @onready var health_bar = $HealthBar
12
+
13
+ var score := 0
14
+ var health := 3:
15
+ set(value):
16
+ health = value
17
+ health_bar.update_health(health)
18
+ if health == 0:
19
+ game_over()
20
+
21
+
22
+ func _ready():
23
+ ai_controller_3d.init(self)
24
+
25
+ func game_over():
26
+ ai_controller_3d.done = true
27
+ ai_controller_3d.needs_reset = true
28
+
29
+ func _physics_process(delta):
30
+ if ai_controller_3d.needs_reset:
31
+ reset()
32
+ ai_controller_3d.reset()
33
+ return
34
+
35
+ var fb : float
36
+ var turn : float
37
+
38
+ if ai_controller_3d.heuristic == "human":
39
+ fb = Input.get_action_strength("move_backward") - Input.get_action_strength("move_forward")
40
+ turn = Input.get_action_strength("turn_left") - Input.get_action_strength("turn_right")
41
+ else:
42
+ fb = ai_controller_3d.fb_action
43
+ turn = ai_controller_3d.turn_action
44
+
45
+ fb = clamp(fb, -1.0, 0.5) # limit reverse speed
46
+ #prints(ai_controller_3d.reward, ai_controller_3d.done, fb)
47
+ rotation.y += deg_to_rad(turn*TURN_SENS)
48
+ var direction = (transform.basis * Vector3(0.0, 0, fb)) # .normalized()
49
+ if direction:
50
+ velocity.x = direction.x * SPEED
51
+ velocity.z = direction.z * SPEED
52
+ else:
53
+ velocity.x = move_toward(velocity.x, 0, SPEED)
54
+ velocity.z = move_toward(velocity.z, 0, SPEED)
55
+
56
+ var collided = move_and_slide()
57
+ if collided:
58
+ obstacle_hit()
59
+
60
+ func reset():
61
+ position = Vector3.ZERO
62
+ health = 3
63
+ score = 0
64
+ reset_signal.emit()
65
+
66
+ func chest_collected():
67
+ #print("chest collected")
68
+ score += 1
69
+ ai_controller_3d.reward += 1.0
70
+
71
+ func mine_hit():
72
+ #print("mine hit")
73
+ score -= 1
74
+ health -= 1
75
+ ai_controller_3d.reward -= 1.0
76
+
77
+ func obstacle_hit():
78
+ #print("obstacle hit")
79
+ pass
80
+ #ai_controller_3d.reward -= 0.01
81
+
82
+ func _on_game_area_body_exited(body):
83
+ #print("left game area")
84
+ game_over()
README.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: godot-rl
3
+ tags:
4
+ - deep-reinforcement-learning
5
+ - reinforcement-learning
6
+ - godot-rl
7
+ - environments
8
+ - video-games
9
+ ---
10
+
11
+ A RL environment called Ships for the Godot Game Engine.
12
+
13
+ This environment was created with: https://github.com/edbeeching/godot_rl_agents
14
+
15
+
16
+ ## Downloading the environment
17
+
18
+ After installing Godot RL Agents, download the environment with:
19
+
20
+ ```
21
+ gdrl.env_from_hub -r jtatman/godot_rl_Ships
22
+ ```
23
+
24
+
25
+
Ships.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99bdc5e53587e307d0e54c001a04becf09320283825fb6b140bec84a7107f2e5
3
+ size 191953
UIBasicsEnvironment.tres ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_resource type="Environment" load_steps=8 format=3 uid="uid://bsg17rom7hmrb"]
2
+
3
+ [sub_resource type="Shader" id="Shader_18b1f"]
4
+ code = "// NOTE: Shader automatically converted from Godot Engine 4.0.alpha3's PanoramaSkyMaterial.
5
+ shader_type sky;
6
+
7
+ uniform sampler2D sky_texture : filter_linear;
8
+ uniform sampler2D flow_texture : hint_normal;
9
+ uniform sampler2D noise_texture;
10
+
11
+ void sky() {
12
+ float noise = texture(noise_texture, SKY_COORDS).r;
13
+ float time = TIME * .1 + noise;
14
+
15
+ vec2 flow_vectors = (texture(flow_texture, SKY_COORDS).rg - .5) * 2.0;
16
+ float timer1 = fract(time);
17
+ float timer2 = fract(time + 0.5);
18
+ float mix_timer = min(fract(time), 1.0 - fract(time)) * 2.0;
19
+
20
+ vec4 color1 = texture(sky_texture, SKY_COORDS + flow_vectors * timer1 * .03);
21
+ vec4 color2 = texture(sky_texture, SKY_COORDS + flow_vectors * timer2 * .03);
22
+
23
+ vec4 final_color = mix(color2, color1, mix_timer);
24
+
25
+ COLOR = final_color.rgb;
26
+ }"
27
+
28
+ [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_edjfr"]
29
+
30
+ [sub_resource type="FastNoiseLite" id="FastNoiseLite_naxpu"]
31
+
32
+ [sub_resource type="NoiseTexture2D" id="NoiseTexture2D_a2b1s"]
33
+ noise = SubResource("FastNoiseLite_naxpu")
34
+
35
+ [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_nda5t"]
36
+
37
+ [sub_resource type="ShaderMaterial" id="ShaderMaterial_gaoht"]
38
+ shader = SubResource("Shader_18b1f")
39
+ shader_parameter/sky_texture = SubResource("CompressedTexture2D_nda5t")
40
+ shader_parameter/flow_texture = SubResource("CompressedTexture2D_edjfr")
41
+ shader_parameter/noise_texture = SubResource("NoiseTexture2D_a2b1s")
42
+
43
+ [sub_resource type="Sky" id="Sky_xke1b"]
44
+ sky_material = SubResource("ShaderMaterial_gaoht")
45
+
46
+ [resource]
47
+ background_mode = 2
48
+ sky = SubResource("Sky_xke1b")
49
+ ambient_light_source = 3
50
+ reflected_light_source = 2
51
+ tonemap_mode = 2
52
+ tonemap_white = 1.2
53
+ ssao_enabled = true
54
+ ssao_light_affect = 0.3
55
+ ssil_enabled = true
56
+ glow_enabled = true
57
+ glow_normalized = true
58
+ glow_strength = 0.5
59
+ glow_bloom = 0.04
60
+ glow_blend_mode = 0
61
+ volumetric_fog_density = 0.04
62
+ volumetric_fog_albedo = Color(0.662745, 0.866667, 1, 1)
63
+ volumetric_fog_emission = Color(0, 0.537255, 0.890196, 1)
64
+ volumetric_fog_sky_affect = 0.8
WaterShader.tres ADDED
@@ -0,0 +1,561 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_resource type="VisualShader" load_steps=57 format=3 uid="uid://8su6ti3hlgpy"]
2
+
3
+ [sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_eslgf"]
4
+ operator = 2
5
+
6
+ [sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_u8qml"]
7
+
8
+ [sub_resource type="VisualShaderNodeComment" id="VisualShaderNodeComment_1n6h4"]
9
+ size = Vector2(1961.08, 947.632)
10
+ title = "Detail Noise"
11
+
12
+ [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_7wfef"]
13
+ input_name = "time"
14
+
15
+ [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_y60id"]
16
+ input_name = "uv"
17
+
18
+ [sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_pt86f"]
19
+ default_input_values = [0, Vector2(0, 0), 1, Vector2(0, 0)]
20
+ op_type = 0
21
+ operator = 2
22
+
23
+ [sub_resource type="VisualShaderNodeFloatParameter" id="VisualShaderNodeFloatParameter_p2bsf"]
24
+ parameter_name = "detail_water_speed"
25
+ default_value_enabled = true
26
+ default_value = 0.002
27
+
28
+ [sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_ml4ab"]
29
+ default_input_values = [0, Vector2(0, 0), 1, Vector2(0, 0)]
30
+ op_type = 0
31
+
32
+ [sub_resource type="FastNoiseLite" id="FastNoiseLite_ql8q5"]
33
+ noise_type = 2
34
+ frequency = 0.75
35
+ fractal_type = 0
36
+ cellular_distance_function = 1
37
+ cellular_jitter = 1.0
38
+
39
+ [sub_resource type="NoiseTexture2D" id="NoiseTexture2D_kb3i2"]
40
+ seamless = true
41
+ noise = SubResource("FastNoiseLite_ql8q5")
42
+
43
+ [sub_resource type="VisualShaderNodeTexture" id="VisualShaderNodeTexture_ngw8e"]
44
+ texture = SubResource("NoiseTexture2D_kb3i2")
45
+
46
+ [sub_resource type="VisualShaderNodeFloatParameter" id="VisualShaderNodeFloatParameter_a6mhs"]
47
+ parameter_name = "foam_threshold"
48
+ default_value_enabled = true
49
+ default_value = 0.5
50
+
51
+ [sub_resource type="VisualShaderNodeStep" id="VisualShaderNodeStep_07sk8"]
52
+ default_input_values = [0, 0.666, 1, 0.0]
53
+
54
+ [sub_resource type="VisualShaderNodeMix" id="VisualShaderNodeMix_5gm3l"]
55
+ default_input_values = [0, Quaternion(0, 0, 0, 0), 1, Quaternion(1, 1, 1, 1), 2, 0.5]
56
+ op_type = 6
57
+
58
+ [sub_resource type="VisualShaderNodeColorParameter" id="VisualShaderNodeColorParameter_amub1"]
59
+ parameter_name = "water_color"
60
+ default_value_enabled = true
61
+ default_value = Color(0, 0.341783, 0.638043, 1)
62
+
63
+ [sub_resource type="VisualShaderNodeColorParameter" id="VisualShaderNodeColorParameter_3evsr"]
64
+ parameter_name = "foam_color"
65
+ default_value_enabled = true
66
+
67
+ [sub_resource type="VisualShaderNodeFloatConstant" id="VisualShaderNodeFloatConstant_40p55"]
68
+ constant = 0.6
69
+
70
+ [sub_resource type="VisualShaderNodeFloatFunc" id="VisualShaderNodeFloatFunc_lxkfi"]
71
+ function = 31
72
+
73
+ [sub_resource type="VisualShaderNodeTexture" id="VisualShaderNodeTexture_ke10c"]
74
+
75
+ [sub_resource type="VisualShaderNodeTexture" id="VisualShaderNodeTexture_28lt2"]
76
+
77
+ [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_0vuo8"]
78
+ input_name = "time"
79
+
80
+ [sub_resource type="VisualShaderNodeUVFunc" id="VisualShaderNodeUVFunc_shc2h"]
81
+ default_input_values = [1, Vector2(3, 3), 2, Vector2(0, 0)]
82
+
83
+ [sub_resource type="VisualShaderNodeMix" id="VisualShaderNodeMix_s8e8r"]
84
+ default_input_values = [0, Quaternion(0, 0, 0, 0), 1, Quaternion(1, 1, 1, 1), 2, Quaternion(0.5, 0.5, 0.5, 0.5)]
85
+ op_type = 5
86
+
87
+ [sub_resource type="VisualShaderNodeUVFunc" id="VisualShaderNodeUVFunc_ak4iq"]
88
+ default_input_values = [1, Vector2(-3, -3), 2, Vector2(0, 0)]
89
+
90
+ [sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_3yjg7"]
91
+ default_input_values = [0, 0.0, 1, 0.002]
92
+ operator = 2
93
+
94
+ [sub_resource type="VisualShaderNodeFloatConstant" id="VisualShaderNodeFloatConstant_j2cca"]
95
+ constant = 1.0
96
+
97
+ [sub_resource type="VisualShaderNodeFloatConstant" id="VisualShaderNodeFloatConstant_5gqkt"]
98
+ constant = 0.6
99
+
100
+ [sub_resource type="VisualShaderNodeMix" id="VisualShaderNodeMix_d4ulh"]
101
+ default_input_values = [0, 0.94, 1, 1.0, 2, 0.5]
102
+
103
+ [sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_hfs2o"]
104
+ default_input_values = [0, Quaternion(0, 0, 0, 0), 1, Quaternion(1, 1, 1, 1)]
105
+ op_type = 2
106
+ operator = 5
107
+
108
+ [sub_resource type="VisualShaderNodeProximityFade" id="VisualShaderNodeProximityFade_n4hcr"]
109
+
110
+ [sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_07qnl"]
111
+ default_input_values = [0, 0.0, 1, 48.0]
112
+ operator = 5
113
+
114
+ [sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_thkes"]
115
+
116
+ [sub_resource type="VisualShaderNodeMultiplyAdd" id="VisualShaderNodeMultiplyAdd_71wjw"]
117
+ default_input_values = [0, 0.0, 1, 0.4, 2, 0.0]
118
+
119
+ [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_e10nc"]
120
+ input_name = "time"
121
+
122
+ [sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_sxt31"]
123
+ default_input_values = [0, 0.0, 1, 4.0]
124
+ operator = 2
125
+
126
+ [sub_resource type="VisualShaderNodeFloatFunc" id="VisualShaderNodeFloatFunc_xo62c"]
127
+ function = 0
128
+
129
+ [sub_resource type="VisualShaderNodeFloatFunc" id="VisualShaderNodeFloatFunc_drpvc"]
130
+ function = 12
131
+
132
+ [sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_papeo"]
133
+ operator = 2
134
+
135
+ [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_l6qxq"]
136
+ input_name = "normal"
137
+
138
+ [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_bjwgk"]
139
+ input_name = "vertex"
140
+
141
+ [sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_u6vmt"]
142
+ operator = 1
143
+
144
+ [sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_qt6m8"]
145
+ operator = 2
146
+
147
+ [sub_resource type="VisualShaderNodeVectorDecompose" id="VisualShaderNodeVectorDecompose_qovlt"]
148
+
149
+ [sub_resource type="VisualShaderNodeFloatParameter" id="VisualShaderNodeFloatParameter_t2kaa"]
150
+ parameter_name = "wave_scale"
151
+ default_value_enabled = true
152
+ default_value = 0.2
153
+
154
+ [sub_resource type="VisualShaderNodeFloatOp" id="VisualShaderNodeFloatOp_relvm"]
155
+ operator = 2
156
+
157
+ [sub_resource type="VisualShaderNodeFloatFunc" id="VisualShaderNodeFloatFunc_ub24v"]
158
+ function = 12
159
+
160
+ [sub_resource type="VisualShaderNodeComment" id="VisualShaderNodeComment_4o8y1"]
161
+ size = Vector2(2029.8, 1308.18)
162
+ title = "Scrolling Noise"
163
+
164
+ [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_gu7qa"]
165
+ input_name = "time"
166
+
167
+ [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_k2mpj"]
168
+ input_name = "uv"
169
+
170
+ [sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_6vl07"]
171
+ default_input_values = [0, Vector2(0, 0), 1, Vector2(0, 0)]
172
+ op_type = 0
173
+
174
+ [sub_resource type="VisualShaderNodeFloatParameter" id="VisualShaderNodeFloatParameter_a03y7"]
175
+ parameter_name = "water_speed2"
176
+ default_value_enabled = true
177
+ default_value = 0.003
178
+
179
+ [sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_w7nrt"]
180
+ default_input_values = [0, Vector2(0, 0), 1, Vector2(0, 0)]
181
+ op_type = 0
182
+ operator = 2
183
+
184
+ [sub_resource type="FastNoiseLite" id="FastNoiseLite_11yi2"]
185
+ fractal_type = 3
186
+ domain_warp_enabled = true
187
+
188
+ [sub_resource type="NoiseTexture2D" id="NoiseTexture2D_8rwkj"]
189
+ seamless = true
190
+ noise = SubResource("FastNoiseLite_11yi2")
191
+
192
+ [sub_resource type="VisualShaderNodeTexture" id="VisualShaderNodeTexture_5gkum"]
193
+ source = 5
194
+ texture = SubResource("NoiseTexture2D_8rwkj")
195
+
196
+ [sub_resource type="VisualShaderNodeTexture2DParameter" id="VisualShaderNodeTexture2DParameter_mjb0g"]
197
+ parameter_name = "main_noise2"
198
+
199
+ [resource]
200
+ code = "shader_type spatial;
201
+ render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_toon, specular_schlick_ggx;
202
+
203
+ uniform float wave_scale = 0.20000000298023;
204
+ uniform float water_speed2 = 0.00300000002608;
205
+ uniform sampler2D main_noise2;
206
+ uniform vec4 water_color : source_color = vec4(0.000000, 0.341783, 0.638043, 1.000000);
207
+ uniform vec4 foam_color : source_color = vec4(1.000000, 1.000000, 1.000000, 1.000000);
208
+ uniform float foam_threshold = 0.5;
209
+ uniform float detail_water_speed = 0.00200000009499;
210
+ uniform sampler2D tex_frg_36;
211
+ uniform sampler2D depth_tex_frg_91 : hint_depth_texture;
212
+ uniform sampler2D tex_frg_63;
213
+ uniform sampler2D tex_frg_64;
214
+
215
+
216
+
217
+ void vertex() {
218
+ // FloatParameter:15
219
+ float n_out15p0 = wave_scale;
220
+
221
+
222
+ // FloatParameter:6
223
+ float n_out6p0 = water_speed2;
224
+
225
+
226
+ // Input:3
227
+ float n_out3p0 = TIME;
228
+
229
+
230
+ // VectorOp:7
231
+ vec2 n_out7p0 = vec2(n_out6p0) * vec2(n_out3p0);
232
+
233
+
234
+ // Input:4
235
+ vec2 n_out4p0 = UV;
236
+
237
+
238
+ // VectorOp:5
239
+ vec2 n_out5p0 = n_out7p0 + n_out4p0;
240
+
241
+
242
+ vec4 n_out8p0;
243
+ // Texture2D:8
244
+ n_out8p0 = texture(main_noise2, n_out5p0);
245
+
246
+
247
+ // VectorDecompose:14
248
+ float n_out14p0 = vec3(n_out8p0.xyz).x;
249
+ float n_out14p1 = vec3(n_out8p0.xyz).y;
250
+ float n_out14p2 = vec3(n_out8p0.xyz).z;
251
+
252
+
253
+ // FloatFunc:17
254
+ float n_out17p0 = abs(n_out14p0);
255
+
256
+
257
+ // FloatOp:16
258
+ float n_out16p0 = n_out15p0 * n_out17p0;
259
+
260
+
261
+ // Input:10
262
+ vec3 n_out10p0 = NORMAL;
263
+
264
+
265
+ // VectorOp:13
266
+ vec3 n_out13p0 = vec3(n_out16p0) * n_out10p0;
267
+
268
+
269
+ // Input:11
270
+ vec3 n_out11p0 = VERTEX;
271
+
272
+
273
+ // VectorOp:12
274
+ vec3 n_out12p0 = n_out13p0 - n_out11p0;
275
+
276
+
277
+ // Output:0
278
+ VERTEX = n_out12p0;
279
+
280
+
281
+ }
282
+
283
+ void fragment() {
284
+ // ColorParameter:59
285
+ vec4 n_out59p0 = water_color;
286
+
287
+
288
+ // ColorParameter:60
289
+ vec4 n_out60p0 = foam_color;
290
+
291
+
292
+ // FloatParameter:39
293
+ float n_out39p0 = foam_threshold;
294
+
295
+
296
+ // FloatParameter:34
297
+ float n_out34p0 = detail_water_speed;
298
+
299
+
300
+ // Input:31
301
+ float n_out31p0 = TIME;
302
+
303
+
304
+ // VectorOp:33
305
+ vec2 n_out33p0 = vec2(n_out34p0) * vec2(n_out31p0);
306
+
307
+
308
+ // Input:32
309
+ vec2 n_out32p0 = UV;
310
+
311
+
312
+ // VectorOp:35
313
+ vec2 n_out35p0 = n_out33p0 + n_out32p0;
314
+
315
+
316
+ // Texture2D:36
317
+ vec4 n_out36p0 = texture(tex_frg_36, n_out35p0);
318
+
319
+
320
+ float n_out91p0;
321
+ // ProximityFade:91
322
+ float n_in91p0 = 1.00000;
323
+ {
324
+ float __depth_tex = texture(depth_tex_frg_91, SCREEN_UV).r;
325
+ vec4 __depth_world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, __depth_tex, 1.0);
326
+ __depth_world_pos.xyz /= __depth_world_pos.w;
327
+ n_out91p0 = clamp(1.0 - smoothstep(__depth_world_pos.z + n_in91p0, __depth_world_pos.z, VERTEX.z), 0.0, 1.0);
328
+ }
329
+
330
+
331
+ // FloatFunc:62
332
+ float n_out62p0 = 1.0 - n_out91p0;
333
+
334
+
335
+ // FloatOp:100
336
+ float n_out100p0 = n_out36p0.x * n_out62p0;
337
+
338
+
339
+ // Input:95
340
+ float n_out95p0 = TIME;
341
+
342
+
343
+ // MultiplyAdd:94
344
+ float n_in94p1 = 0.40000;
345
+ float n_out94p0 = fma(n_out95p0, n_in94p1, n_out62p0);
346
+
347
+
348
+ // FloatOp:96
349
+ float n_in96p1 = 4.00000;
350
+ float n_out96p0 = n_out94p0 * n_in96p1;
351
+
352
+
353
+ // FloatFunc:97
354
+ float n_out97p0 = sin(n_out96p0);
355
+
356
+
357
+ // FloatFunc:98
358
+ float n_out98p0 = abs(n_out97p0);
359
+
360
+
361
+ // FloatOp:99
362
+ float n_out99p0 = n_out98p0 * n_out62p0;
363
+
364
+
365
+ // FloatOp:92
366
+ float n_in92p1 = 48.00000;
367
+ float n_out92p0 = pow(n_out62p0, n_in92p1);
368
+
369
+
370
+ // FloatOp:93
371
+ float n_out93p0 = n_out99p0 + n_out92p0;
372
+
373
+
374
+ // FloatOp:101
375
+ float n_out101p0 = n_out100p0 + n_out93p0;
376
+
377
+
378
+ // Step:55
379
+ float n_out55p0 = step(n_out39p0, n_out101p0);
380
+
381
+
382
+ // Mix:56
383
+ vec4 n_out56p0 = mix(n_out59p0, n_out60p0, n_out55p0);
384
+
385
+
386
+ // Mix:75
387
+ float n_in75p0 = 0.94000;
388
+ float n_in75p1 = 1.00000;
389
+ float n_out75p0 = mix(n_in75p0, n_in75p1, n_out55p0);
390
+
391
+
392
+ // FloatConstant:61
393
+ float n_out61p0 = 0.600000;
394
+
395
+
396
+ // FloatConstant:74
397
+ float n_out74p0 = 0.600000;
398
+
399
+
400
+ // FloatConstant:72
401
+ float n_out72p0 = 1.000000;
402
+
403
+
404
+ // Input:66
405
+ float n_out66p0 = TIME;
406
+
407
+
408
+ // FloatOp:71
409
+ float n_in71p1 = 0.00200;
410
+ float n_out71p0 = n_out66p0 * n_in71p1;
411
+
412
+
413
+ // UVFunc:70
414
+ vec2 n_in70p1 = vec2(-3.00000, -3.00000);
415
+ vec2 n_out70p0 = vec2(n_out71p0) * n_in70p1 + UV;
416
+
417
+
418
+ // Texture2D:63
419
+ vec4 n_out63p0 = texture(tex_frg_63, n_out70p0);
420
+
421
+
422
+ // UVFunc:68
423
+ vec2 n_in68p1 = vec2(3.00000, 3.00000);
424
+ vec2 n_out68p0 = vec2(n_out71p0) * n_in68p1 + UV;
425
+
426
+
427
+ // Texture2D:64
428
+ vec4 n_out64p0 = texture(tex_frg_64, n_out68p0);
429
+
430
+
431
+ // Mix:69
432
+ vec4 n_in69p2 = vec4(0.50000, 0.50000, 0.50000, 0.50000);
433
+ vec4 n_out69p0 = mix(n_out63p0, n_out64p0, n_in69p2);
434
+
435
+
436
+ // VectorOp:90
437
+ vec4 n_in90p1 = vec4(1.00000, 1.00000, 1.00000, 1.00000);
438
+ vec4 n_out90p0 = pow(n_out69p0, n_in90p1);
439
+
440
+
441
+ // Output:0
442
+ ALBEDO = vec3(n_out56p0.xyz);
443
+ ALPHA = n_out75p0;
444
+ METALLIC = n_out61p0;
445
+ ROUGHNESS = n_out74p0;
446
+ SPECULAR = n_out72p0;
447
+ NORMAL_MAP = vec3(n_out90p0.xyz);
448
+
449
+
450
+ }
451
+ "
452
+ graph_offset = Vector2(1284.03, -340.084)
453
+ modes/diffuse = 3
454
+ nodes/vertex/0/position = Vector2(6740, -20)
455
+ nodes/vertex/2/node = SubResource("VisualShaderNodeComment_4o8y1")
456
+ nodes/vertex/2/position = Vector2(1924.58, -428.571)
457
+ nodes/vertex/3/node = SubResource("VisualShaderNodeInput_gu7qa")
458
+ nodes/vertex/3/position = Vector2(2004.58, 131.429)
459
+ nodes/vertex/4/node = SubResource("VisualShaderNodeInput_k2mpj")
460
+ nodes/vertex/4/position = Vector2(1964.58, 291.429)
461
+ nodes/vertex/5/node = SubResource("VisualShaderNodeVectorOp_6vl07")
462
+ nodes/vertex/5/position = Vector2(3124.58, -148.571)
463
+ nodes/vertex/6/node = SubResource("VisualShaderNodeFloatParameter_a03y7")
464
+ nodes/vertex/6/position = Vector2(2004.58, -308.571)
465
+ nodes/vertex/7/node = SubResource("VisualShaderNodeVectorOp_w7nrt")
466
+ nodes/vertex/7/position = Vector2(2764.58, -308.571)
467
+ nodes/vertex/8/node = SubResource("VisualShaderNodeTexture_5gkum")
468
+ nodes/vertex/8/position = Vector2(3504.58, -148.571)
469
+ nodes/vertex/9/node = SubResource("VisualShaderNodeTexture2DParameter_mjb0g")
470
+ nodes/vertex/9/position = Vector2(2824.58, 351.429)
471
+ nodes/vertex/10/node = SubResource("VisualShaderNodeInput_l6qxq")
472
+ nodes/vertex/10/position = Vector2(4060, 200)
473
+ nodes/vertex/11/node = SubResource("VisualShaderNodeInput_bjwgk")
474
+ nodes/vertex/11/position = Vector2(4040, 540)
475
+ nodes/vertex/12/node = SubResource("VisualShaderNodeVectorOp_u6vmt")
476
+ nodes/vertex/12/position = Vector2(6080, -40)
477
+ nodes/vertex/13/node = SubResource("VisualShaderNodeVectorOp_qt6m8")
478
+ nodes/vertex/13/position = Vector2(5760, -400)
479
+ nodes/vertex/14/node = SubResource("VisualShaderNodeVectorDecompose_qovlt")
480
+ nodes/vertex/14/position = Vector2(4180, -400)
481
+ nodes/vertex/15/node = SubResource("VisualShaderNodeFloatParameter_t2kaa")
482
+ nodes/vertex/15/position = Vector2(3980, -900)
483
+ nodes/vertex/16/node = SubResource("VisualShaderNodeFloatOp_relvm")
484
+ nodes/vertex/16/position = Vector2(5340, -620)
485
+ nodes/vertex/17/node = SubResource("VisualShaderNodeFloatFunc_ub24v")
486
+ nodes/vertex/17/position = Vector2(4680, -400)
487
+ nodes/vertex/connections = PackedInt32Array(5, 0, 8, 0, 4, 0, 5, 1, 6, 0, 7, 0, 3, 0, 7, 1, 7, 0, 5, 0, 9, 0, 8, 2, 10, 0, 13, 1, 13, 0, 12, 0, 11, 0, 12, 1, 12, 0, 0, 0, 8, 0, 14, 0, 15, 0, 16, 0, 16, 0, 13, 0, 14, 0, 17, 0, 17, 0, 16, 1)
488
+ nodes/fragment/0/position = Vector2(9060, -1560)
489
+ nodes/fragment/30/node = SubResource("VisualShaderNodeComment_1n6h4")
490
+ nodes/fragment/30/position = Vector2(780, -2960)
491
+ nodes/fragment/31/node = SubResource("VisualShaderNodeInput_7wfef")
492
+ nodes/fragment/31/position = Vector2(860, -2400)
493
+ nodes/fragment/32/node = SubResource("VisualShaderNodeInput_y60id")
494
+ nodes/fragment/32/position = Vector2(820, -2240)
495
+ nodes/fragment/33/node = SubResource("VisualShaderNodeVectorOp_pt86f")
496
+ nodes/fragment/33/position = Vector2(1620, -2840)
497
+ nodes/fragment/34/node = SubResource("VisualShaderNodeFloatParameter_p2bsf")
498
+ nodes/fragment/34/position = Vector2(940, -2860)
499
+ nodes/fragment/35/node = SubResource("VisualShaderNodeVectorOp_ml4ab")
500
+ nodes/fragment/35/position = Vector2(1980, -2680)
501
+ nodes/fragment/36/node = SubResource("VisualShaderNodeTexture_ngw8e")
502
+ nodes/fragment/36/position = Vector2(2300, -2640)
503
+ nodes/fragment/39/node = SubResource("VisualShaderNodeFloatParameter_a6mhs")
504
+ nodes/fragment/39/position = Vector2(5040, -2920)
505
+ nodes/fragment/55/node = SubResource("VisualShaderNodeStep_07sk8")
506
+ nodes/fragment/55/position = Vector2(5820, -2560)
507
+ nodes/fragment/56/node = SubResource("VisualShaderNodeMix_5gm3l")
508
+ nodes/fragment/56/position = Vector2(6780, -2740)
509
+ nodes/fragment/59/node = SubResource("VisualShaderNodeColorParameter_amub1")
510
+ nodes/fragment/59/position = Vector2(5960, -3440)
511
+ nodes/fragment/60/node = SubResource("VisualShaderNodeColorParameter_3evsr")
512
+ nodes/fragment/60/position = Vector2(6040, -3000)
513
+ nodes/fragment/61/node = SubResource("VisualShaderNodeFloatConstant_40p55")
514
+ nodes/fragment/61/position = Vector2(6940, -1700)
515
+ nodes/fragment/62/node = SubResource("VisualShaderNodeFloatFunc_lxkfi")
516
+ nodes/fragment/62/position = Vector2(2420, -1320)
517
+ nodes/fragment/63/node = SubResource("VisualShaderNodeTexture_ke10c")
518
+ nodes/fragment/63/position = Vector2(7260, -980)
519
+ nodes/fragment/64/node = SubResource("VisualShaderNodeTexture_28lt2")
520
+ nodes/fragment/64/position = Vector2(7320, -320)
521
+ nodes/fragment/66/node = SubResource("VisualShaderNodeInput_0vuo8")
522
+ nodes/fragment/66/position = Vector2(5300, -700)
523
+ nodes/fragment/68/node = SubResource("VisualShaderNodeUVFunc_shc2h")
524
+ nodes/fragment/68/position = Vector2(6600, -120)
525
+ nodes/fragment/69/node = SubResource("VisualShaderNodeMix_s8e8r")
526
+ nodes/fragment/69/position = Vector2(7760, -640)
527
+ nodes/fragment/70/node = SubResource("VisualShaderNodeUVFunc_ak4iq")
528
+ nodes/fragment/70/position = Vector2(6580, -960)
529
+ nodes/fragment/71/node = SubResource("VisualShaderNodeFloatOp_3yjg7")
530
+ nodes/fragment/71/position = Vector2(6040, -500)
531
+ nodes/fragment/72/node = SubResource("VisualShaderNodeFloatConstant_j2cca")
532
+ nodes/fragment/72/position = Vector2(7100, -1340)
533
+ nodes/fragment/74/node = SubResource("VisualShaderNodeFloatConstant_5gqkt")
534
+ nodes/fragment/74/position = Vector2(6980, -1520)
535
+ nodes/fragment/75/node = SubResource("VisualShaderNodeMix_d4ulh")
536
+ nodes/fragment/75/position = Vector2(6940, -2400)
537
+ nodes/fragment/90/node = SubResource("VisualShaderNodeVectorOp_hfs2o")
538
+ nodes/fragment/90/position = Vector2(8320, -1120)
539
+ nodes/fragment/91/node = SubResource("VisualShaderNodeProximityFade_n4hcr")
540
+ nodes/fragment/91/position = Vector2(1820, -1240)
541
+ nodes/fragment/92/node = SubResource("VisualShaderNodeFloatOp_07qnl")
542
+ nodes/fragment/92/position = Vector2(4020, -1340)
543
+ nodes/fragment/93/node = SubResource("VisualShaderNodeFloatOp_thkes")
544
+ nodes/fragment/93/position = Vector2(5120, -1680)
545
+ nodes/fragment/94/node = SubResource("VisualShaderNodeMultiplyAdd_71wjw")
546
+ nodes/fragment/94/position = Vector2(3000, -1720)
547
+ nodes/fragment/95/node = SubResource("VisualShaderNodeInput_e10nc")
548
+ nodes/fragment/95/position = Vector2(2100, -1740)
549
+ nodes/fragment/96/node = SubResource("VisualShaderNodeFloatOp_sxt31")
550
+ nodes/fragment/96/position = Vector2(3320, -1800)
551
+ nodes/fragment/97/node = SubResource("VisualShaderNodeFloatFunc_xo62c")
552
+ nodes/fragment/97/position = Vector2(3620, -1780)
553
+ nodes/fragment/98/node = SubResource("VisualShaderNodeFloatFunc_drpvc")
554
+ nodes/fragment/98/position = Vector2(4160, -1780)
555
+ nodes/fragment/99/node = SubResource("VisualShaderNodeFloatOp_papeo")
556
+ nodes/fragment/99/position = Vector2(4540, -1700)
557
+ nodes/fragment/100/node = SubResource("VisualShaderNodeFloatOp_eslgf")
558
+ nodes/fragment/100/position = Vector2(4900, -2200)
559
+ nodes/fragment/101/node = SubResource("VisualShaderNodeFloatOp_u8qml")
560
+ nodes/fragment/101/position = Vector2(5460, -2100)
561
+ nodes/fragment/connections = PackedInt32Array(35, 0, 36, 0, 32, 0, 35, 1, 34, 0, 33, 0, 31, 0, 33, 1, 33, 0, 35, 0, 60, 0, 56, 1, 59, 0, 56, 0, 68, 0, 64, 0, 63, 0, 69, 0, 64, 0, 69, 1, 70, 0, 63, 0, 66, 0, 71, 0, 71, 0, 70, 2, 71, 0, 68, 2, 55, 0, 75, 2, 69, 0, 90, 0, 90, 0, 0, 9, 74, 0, 0, 3, 72, 0, 0, 4, 61, 0, 0, 2, 56, 0, 0, 0, 75, 0, 0, 1, 91, 0, 62, 0, 62, 0, 92, 0, 92, 0, 93, 1, 95, 0, 94, 0, 62, 0, 94, 2, 94, 0, 96, 0, 96, 0, 97, 0, 97, 0, 98, 0, 98, 0, 99, 0, 62, 0, 99, 1, 99, 0, 93, 0, 36, 0, 100, 0, 62, 0, 100, 1, 100, 0, 101, 0, 93, 0, 101, 1, 101, 0, 55, 1, 55, 0, 56, 2, 39, 0, 55, 0)
addons/godot_rl_agents/controller/ai_controller_2d.gd ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node2D
2
+ class_name AIController2D
3
+
4
+ enum ControlModes { INHERIT_FROM_SYNC, HUMAN, TRAINING, ONNX_INFERENCE, RECORD_EXPERT_DEMOS }
5
+ @export var control_mode: ControlModes = ControlModes.INHERIT_FROM_SYNC
6
+ @export var onnx_model_path := ""
7
+ @export var reset_after := 1000
8
+
9
+ @export_group("Record expert demos mode options")
10
+ ## Path where the demos will be saved. The file can later be used for imitation learning.
11
+ @export var expert_demo_save_path: String
12
+ ## The action that erases the last recorded episode from the currently recorded data.
13
+ @export var remove_last_episode_key: InputEvent
14
+ ## Action will be repeated for n frames. Will introduce control lag if larger than 1.
15
+ ## Can be used to ensure that action_repeat on inference and training matches
16
+ ## the recorded demonstrations.
17
+ @export var action_repeat: int = 1
18
+
19
+ var onnx_model: ONNXModel
20
+
21
+ var heuristic := "human"
22
+ var done := false
23
+ var reward := 0.0
24
+ var n_steps := 0
25
+ var needs_reset := false
26
+
27
+ var _player: Node2D
28
+
29
+
30
+ func _ready():
31
+ add_to_group("AGENT")
32
+
33
+
34
+ func init(player: Node2D):
35
+ _player = player
36
+
37
+
38
+ #-- Methods that need implementing using the "extend script" option in Godot --#
39
+ func get_obs() -> Dictionary:
40
+ assert(false, "the get_obs method is not implemented when extending from ai_controller")
41
+ return {"obs": []}
42
+
43
+
44
+ func get_reward() -> float:
45
+ assert(false, "the get_reward method is not implemented when extending from ai_controller")
46
+ return 0.0
47
+
48
+
49
+ func get_action_space() -> Dictionary:
50
+ assert(
51
+ false,
52
+ "the get get_action_space method is not implemented when extending from ai_controller"
53
+ )
54
+ return {
55
+ "example_actions_continous": {"size": 2, "action_type": "continuous"},
56
+ "example_actions_discrete": {"size": 2, "action_type": "discrete"},
57
+ }
58
+
59
+
60
+ func set_action(action) -> void:
61
+ assert(false, "the get set_action method is not implemented when extending from ai_controller")
62
+
63
+
64
+ #-----------------------------------------------------------------------------#
65
+
66
+
67
+ #-- Methods that sometimes need implementing using the "extend script" option in Godot --#
68
+ # Only needed if you are recording expert demos with this AIController
69
+ func get_action() -> Array:
70
+ assert(false, "the get set_action method is not implemented in extended AIController but demo_recorder is used")
71
+ return []
72
+
73
+ # -----------------------------------------------------------------------------#
74
+
75
+ func _physics_process(delta):
76
+ n_steps += 1
77
+ if n_steps > reset_after:
78
+ needs_reset = true
79
+
80
+
81
+ func get_obs_space():
82
+ # may need overriding if the obs space is complex
83
+ var obs = get_obs()
84
+ return {
85
+ "obs": {"size": [len(obs["obs"])], "space": "box"},
86
+ }
87
+
88
+
89
+ func reset():
90
+ n_steps = 0
91
+ needs_reset = false
92
+
93
+
94
+ func reset_if_done():
95
+ if done:
96
+ reset()
97
+
98
+
99
+ func set_heuristic(h):
100
+ # sets the heuristic from "human" or "model" nothing to change here
101
+ heuristic = h
102
+
103
+
104
+ func get_done():
105
+ return done
106
+
107
+
108
+ func set_done_false():
109
+ done = false
110
+
111
+
112
+ func zero_reward():
113
+ reward = 0.0
addons/godot_rl_agents/controller/ai_controller_3d.gd ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node3D
2
+ class_name AIController3D
3
+
4
+ enum ControlModes { INHERIT_FROM_SYNC, HUMAN, TRAINING, ONNX_INFERENCE, RECORD_EXPERT_DEMOS }
5
+ @export var control_mode: ControlModes = ControlModes.INHERIT_FROM_SYNC
6
+ @export var onnx_model_path := ""
7
+ @export var reset_after := 1000
8
+
9
+ @export_group("Record expert demos mode options")
10
+ ## Path where the demos will be saved. The file can later be used for imitation learning.
11
+ @export var expert_demo_save_path: String
12
+ ## The action that erases the last recorded episode from the currently recorded data.
13
+ @export var remove_last_episode_key: InputEvent
14
+ ## Action will be repeated for n frames. Will introduce control lag if larger than 1.
15
+ ## Can be used to ensure that action_repeat on inference and training matches
16
+ ## the recorded demonstrations.
17
+ @export var action_repeat: int = 1
18
+
19
+ var onnx_model: ONNXModel
20
+
21
+ var heuristic := "human"
22
+ var done := false
23
+ var reward := 0.0
24
+ var n_steps := 0
25
+ var needs_reset := false
26
+
27
+ var _player: Node3D
28
+
29
+
30
+ func _ready():
31
+ add_to_group("AGENT")
32
+
33
+
34
+ func init(player: Node3D):
35
+ _player = player
36
+
37
+
38
+ #-- Methods that need implementing using the "extend script" option in Godot --#
39
+ func get_obs() -> Dictionary:
40
+ assert(false, "the get_obs method is not implemented when extending from ai_controller")
41
+ return {"obs": []}
42
+
43
+
44
+ func get_reward() -> float:
45
+ assert(false, "the get_reward method is not implemented when extending from ai_controller")
46
+ return 0.0
47
+
48
+
49
+ func get_action_space() -> Dictionary:
50
+ assert(
51
+ false,
52
+ "the get get_action_space method is not implemented when extending from ai_controller"
53
+ )
54
+ return {
55
+ "example_actions_continous": {"size": 2, "action_type": "continuous"},
56
+ "example_actions_discrete": {"size": 2, "action_type": "discrete"},
57
+ }
58
+
59
+
60
+ func set_action(action) -> void:
61
+ assert(false, "the get set_action method is not implemented when extending from ai_controller")
62
+
63
+
64
+ #-----------------------------------------------------------------------------#
65
+
66
+
67
+ #-- Methods that sometimes need implementing using the "extend script" option in Godot --#
68
+ # Only needed if you are recording expert demos with this AIController
69
+ func get_action() -> Array:
70
+ assert(false, "the get set_action method is not implemented in extended AIController but demo_recorder is used")
71
+ return []
72
+
73
+ # -----------------------------------------------------------------------------#
74
+
75
+
76
+ func _physics_process(delta):
77
+ n_steps += 1
78
+ if n_steps > reset_after:
79
+ needs_reset = true
80
+
81
+
82
+ func get_obs_space():
83
+ # may need overriding if the obs space is complex
84
+ var obs = get_obs()
85
+ return {
86
+ "obs": {"size": [len(obs["obs"])], "space": "box"},
87
+ }
88
+
89
+
90
+ func reset():
91
+ n_steps = 0
92
+ needs_reset = false
93
+
94
+
95
+ func reset_if_done():
96
+ if done:
97
+ reset()
98
+
99
+
100
+ func set_heuristic(h):
101
+ # sets the heuristic from "human" or "model" nothing to change here
102
+ heuristic = h
103
+
104
+
105
+ func get_done():
106
+ return done
107
+
108
+
109
+ func set_done_false():
110
+ done = false
111
+
112
+
113
+ func zero_reward():
114
+ reward = 0.0
addons/godot_rl_agents/godot_rl_agents.gd ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends EditorPlugin
3
+
4
+
5
+ func _enter_tree():
6
+ # Initialization of the plugin goes here.
7
+ # Add the new type with a name, a parent type, a script and an icon.
8
+ add_custom_type("Sync", "Node", preload("sync.gd"), preload("icon.png"))
9
+ #add_custom_type("RaycastSensor2D2", "Node", preload("raycast_sensor_2d.gd"), preload("icon.png"))
10
+
11
+
12
+ func _exit_tree():
13
+ # Clean-up of the plugin goes here.
14
+ # Always remember to remove it from the engine when deactivated.
15
+ remove_custom_type("Sync")
16
+ #remove_custom_type("RaycastSensor2D2")
addons/godot_rl_agents/icon.png ADDED

Git LFS Details

  • SHA256: e3a8bc372d3313ce1ede4e7554472e37b322178b9488bfb709e296585abd3c44
  • Pointer size: 128 Bytes
  • Size of remote file: 198 Bytes
addons/godot_rl_agents/onnx/csharp/ONNXInference.cs ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Godot;
2
+ using Microsoft.ML.OnnxRuntime;
3
+ using Microsoft.ML.OnnxRuntime.Tensors;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+
7
+ namespace GodotONNX
8
+ {
9
+ /// <include file='docs/ONNXInference.xml' path='docs/members[@name="ONNXInference"]/ONNXInference/*'/>
10
+ public partial class ONNXInference : GodotObject
11
+ {
12
+
13
+ private InferenceSession session;
14
+ /// <summary>
15
+ /// Path to the ONNX model. Use Initialize to change it.
16
+ /// </summary>
17
+ private string modelPath;
18
+ private int batchSize;
19
+
20
+ private SessionOptions SessionOpt;
21
+
22
+ //init function
23
+ /// <include file='docs/ONNXInference.xml' path='docs/members[@name="ONNXInference"]/Initialize/*'/>
24
+ public void Initialize(string Path, int BatchSize)
25
+ {
26
+ modelPath = Path;
27
+ batchSize = BatchSize;
28
+ SessionOpt = SessionConfigurator.MakeConfiguredSessionOptions();
29
+ session = LoadModel(modelPath);
30
+
31
+ }
32
+ /// <include file='docs/ONNXInference.xml' path='docs/members[@name="ONNXInference"]/Run/*'/>
33
+ public Godot.Collections.Dictionary<string, Godot.Collections.Array<float>> RunInference(Godot.Collections.Array<float> obs, int state_ins)
34
+ {
35
+ //Current model: Any (Godot Rl Agents)
36
+ //Expects a tensor of shape [batch_size, input_size] type float named obs and a tensor of shape [batch_size] type float named state_ins
37
+
38
+ //Fill the input tensors
39
+ // create span from inputSize
40
+ var span = new float[obs.Count]; //There's probably a better way to do this
41
+ for (int i = 0; i < obs.Count; i++)
42
+ {
43
+ span[i] = obs[i];
44
+ }
45
+
46
+ IReadOnlyCollection<NamedOnnxValue> inputs = new List<NamedOnnxValue>
47
+ {
48
+ NamedOnnxValue.CreateFromTensor("obs", new DenseTensor<float>(span, new int[] { batchSize, obs.Count })),
49
+ NamedOnnxValue.CreateFromTensor("state_ins", new DenseTensor<float>(new float[] { state_ins }, new int[] { batchSize }))
50
+ };
51
+ IReadOnlyCollection<string> outputNames = new List<string> { "output", "state_outs" }; //ONNX is sensible to these names, as well as the input names
52
+
53
+ IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results;
54
+ //We do not use "using" here so we get a better exception explaination later
55
+ try
56
+ {
57
+ results = session.Run(inputs, outputNames);
58
+ }
59
+ catch (OnnxRuntimeException e)
60
+ {
61
+ //This error usually means that the model is not compatible with the input, beacause of the input shape (size)
62
+ GD.Print("Error at inference: ", e);
63
+ return null;
64
+ }
65
+ //Can't convert IEnumerable<float> to Variant, so we have to convert it to an array or something
66
+ Godot.Collections.Dictionary<string, Godot.Collections.Array<float>> output = new Godot.Collections.Dictionary<string, Godot.Collections.Array<float>>();
67
+ DisposableNamedOnnxValue output1 = results.First();
68
+ DisposableNamedOnnxValue output2 = results.Last();
69
+ Godot.Collections.Array<float> output1Array = new Godot.Collections.Array<float>();
70
+ Godot.Collections.Array<float> output2Array = new Godot.Collections.Array<float>();
71
+
72
+ foreach (float f in output1.AsEnumerable<float>())
73
+ {
74
+ output1Array.Add(f);
75
+ }
76
+
77
+ foreach (float f in output2.AsEnumerable<float>())
78
+ {
79
+ output2Array.Add(f);
80
+ }
81
+
82
+ output.Add(output1.Name, output1Array);
83
+ output.Add(output2.Name, output2Array);
84
+
85
+ //Output is a dictionary of arrays, ex: { "output" : [0.1, 0.2, 0.3, 0.4, ...], "state_outs" : [0.5, ...]}
86
+ results.Dispose();
87
+ return output;
88
+ }
89
+ /// <include file='docs/ONNXInference.xml' path='docs/members[@name="ONNXInference"]/Load/*'/>
90
+ public InferenceSession LoadModel(string Path)
91
+ {
92
+ using Godot.FileAccess file = FileAccess.Open(Path, Godot.FileAccess.ModeFlags.Read);
93
+ byte[] model = file.GetBuffer((int)file.GetLength());
94
+ //file.Close(); file.Dispose(); //Close the file, then dispose the reference.
95
+ return new InferenceSession(model, SessionOpt); //Load the model
96
+ }
97
+ public void FreeDisposables()
98
+ {
99
+ session.Dispose();
100
+ SessionOpt.Dispose();
101
+ }
102
+ }
103
+ }
addons/godot_rl_agents/onnx/csharp/SessionConfigurator.cs ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Godot;
2
+ using Microsoft.ML.OnnxRuntime;
3
+
4
+ namespace GodotONNX
5
+ {
6
+ /// <include file='docs/SessionConfigurator.xml' path='docs/members[@name="SessionConfigurator"]/SessionConfigurator/*'/>
7
+
8
+ public static class SessionConfigurator
9
+ {
10
+ public enum ComputeName
11
+ {
12
+ CUDA,
13
+ ROCm,
14
+ DirectML,
15
+ CoreML,
16
+ CPU
17
+ }
18
+
19
+ /// <include file='docs/SessionConfigurator.xml' path='docs/members[@name="SessionConfigurator"]/GetSessionOptions/*'/>
20
+ public static SessionOptions MakeConfiguredSessionOptions()
21
+ {
22
+ SessionOptions sessionOptions = new();
23
+ SetOptions(sessionOptions);
24
+ return sessionOptions;
25
+ }
26
+
27
+ private static void SetOptions(SessionOptions sessionOptions)
28
+ {
29
+ sessionOptions.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_WARNING;
30
+ ApplySystemSpecificOptions(sessionOptions);
31
+ }
32
+
33
+ /// <include file='docs/SessionConfigurator.xml' path='docs/members[@name="SessionConfigurator"]/SystemCheck/*'/>
34
+ static public void ApplySystemSpecificOptions(SessionOptions sessionOptions)
35
+ {
36
+ //Most code for this function is verbose only, the only reason it exists is to track
37
+ //implementation progress of the different compute APIs.
38
+
39
+ //December 2022: CUDA is not working.
40
+
41
+ string OSName = OS.GetName(); //Get OS Name
42
+
43
+ //ComputeName ComputeAPI = ComputeCheck(); //Get Compute API
44
+ // //TODO: Get CPU architecture
45
+
46
+ //Linux can use OpenVINO (C#) on x64 and ROCm on x86 (GDNative/C++)
47
+ //Windows can use OpenVINO (C#) on x64
48
+ //TODO: try TensorRT instead of CUDA
49
+ //TODO: Use OpenVINO for Intel Graphics
50
+
51
+ // Temporarily using CPU on all platforms to avoid errors detected with DML
52
+ ComputeName ComputeAPI = ComputeName.CPU;
53
+
54
+ //match OS and Compute API
55
+ GD.Print($"OS: {OSName} Compute API: {ComputeAPI}");
56
+
57
+ // CPU is set by default without appending necessary
58
+ // sessionOptions.AppendExecutionProvider_CPU(0);
59
+
60
+ /*
61
+ switch (OSName)
62
+ {
63
+ case "Windows": //Can use CUDA, DirectML
64
+ if (ComputeAPI is ComputeName.CUDA)
65
+ {
66
+ //CUDA
67
+ //sessionOptions.AppendExecutionProvider_CUDA(0);
68
+ //sessionOptions.AppendExecutionProvider_DML(0);
69
+ }
70
+ else if (ComputeAPI is ComputeName.DirectML)
71
+ {
72
+ //DirectML
73
+ //sessionOptions.AppendExecutionProvider_DML(0);
74
+ }
75
+ break;
76
+ case "X11": //Can use CUDA, ROCm
77
+ if (ComputeAPI is ComputeName.CUDA)
78
+ {
79
+ //CUDA
80
+ //sessionOptions.AppendExecutionProvider_CUDA(0);
81
+ }
82
+ if (ComputeAPI is ComputeName.ROCm)
83
+ {
84
+ //ROCm, only works on x86
85
+ //Research indicates that this has to be compiled as a GDNative plugin
86
+ //GD.Print("ROCm not supported yet, using CPU.");
87
+ //sessionOptions.AppendExecutionProvider_CPU(0);
88
+ }
89
+ break;
90
+ case "macOS": //Can use CoreML
91
+ if (ComputeAPI is ComputeName.CoreML)
92
+ { //CoreML
93
+ //TODO: Needs testing
94
+ //sessionOptions.AppendExecutionProvider_CoreML(0);
95
+ //CoreML on ARM64, out of the box, on x64 needs .tar file from GitHub
96
+ }
97
+ break;
98
+ default:
99
+ GD.Print("OS not Supported.");
100
+ break;
101
+ }
102
+ */
103
+ }
104
+
105
+
106
+ /// <include file='docs/SessionConfigurator.xml' path='docs/members[@name="SessionConfigurator"]/ComputeCheck/*'/>
107
+ public static ComputeName ComputeCheck()
108
+ {
109
+ string adapterName = Godot.RenderingServer.GetVideoAdapterName();
110
+ //string adapterVendor = Godot.RenderingServer.GetVideoAdapterVendor();
111
+ adapterName = adapterName.ToUpper(new System.Globalization.CultureInfo(""));
112
+ //TODO: GPU vendors for MacOS, what do they even use these days?
113
+
114
+ if (adapterName.Contains("INTEL"))
115
+ {
116
+ return ComputeName.DirectML;
117
+ }
118
+ if (adapterName.Contains("AMD") || adapterName.Contains("RADEON"))
119
+ {
120
+ return ComputeName.DirectML;
121
+ }
122
+ if (adapterName.Contains("NVIDIA"))
123
+ {
124
+ return ComputeName.CUDA;
125
+ }
126
+
127
+ GD.Print("Graphics Card not recognized."); //Should use CPU
128
+ return ComputeName.CPU;
129
+ }
130
+ }
131
+ }
addons/godot_rl_agents/onnx/csharp/docs/ONNXInference.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <docs>
2
+ <members name="ONNXInference">
3
+ <ONNXInference>
4
+ <summary>
5
+ The main <c>ONNXInference</c> Class that handles the inference process.
6
+ </summary>
7
+ </ONNXInference>
8
+ <Initialize>
9
+ <summary>
10
+ Starts the inference process.
11
+ </summary>
12
+ <param name="Path">Path to the ONNX model, expects a path inside resources.</param>
13
+ <param name="BatchSize">How many observations will the model recieve.</param>
14
+ </Initialize>
15
+ <Run>
16
+ <summary>
17
+ Runs the given input through the model and returns the output.
18
+ </summary>
19
+ <param name="obs">Dictionary containing all observations.</param>
20
+ <param name="state_ins">How many different agents are creating these observations.</param>
21
+ <returns>A Dictionary of arrays, containing instructions based on the observations.</returns>
22
+ </Run>
23
+ <Load>
24
+ <summary>
25
+ Loads the given model into the inference process, using the best Execution provider available.
26
+ </summary>
27
+ <param name="Path">Path to the ONNX model, expects a path inside resources.</param>
28
+ <returns>InferenceSession ready to run.</returns>
29
+ </Load>
30
+ </members>
31
+ </docs>
addons/godot_rl_agents/onnx/csharp/docs/SessionConfigurator.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <docs>
2
+ <members name="SessionConfigurator">
3
+ <SessionConfigurator>
4
+ <summary>
5
+ The main <c>SessionConfigurator</c> Class that handles the execution options and providers for the inference process.
6
+ </summary>
7
+ </SessionConfigurator>
8
+ <GetSessionOptions>
9
+ <summary>
10
+ Creates a SessionOptions with all available execution providers.
11
+ </summary>
12
+ <returns>SessionOptions with all available execution providers.</returns>
13
+ </GetSessionOptions>
14
+ <SystemCheck>
15
+ <summary>
16
+ Appends any execution provider available in the current system.
17
+ </summary>
18
+ <remarks>
19
+ This function is mainly verbose for tracking implementation progress of different compute APIs.
20
+ </remarks>
21
+ </SystemCheck>
22
+ <ComputeCheck>
23
+ <summary>
24
+ Checks for available GPUs.
25
+ </summary>
26
+ <returns>An integer identifier for each compute platform.</returns>
27
+ </ComputeCheck>
28
+ </members>
29
+ </docs>
addons/godot_rl_agents/onnx/wrapper/ONNX_wrapper.gd ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Resource
2
+ class_name ONNXModel
3
+ var inferencer_script = load("res://addons/godot_rl_agents/onnx/csharp/ONNXInference.cs")
4
+
5
+ var inferencer = null
6
+
7
+
8
+ # Must provide the path to the model and the batch size
9
+ func _init(model_path, batch_size):
10
+ inferencer = inferencer_script.new()
11
+ inferencer.Initialize(model_path, batch_size)
12
+
13
+
14
+ # This function is the one that will be called from the game,
15
+ # requires the observation as an array and the state_ins as an int
16
+ # returns an Array containing the action the model takes.
17
+ func run_inference(obs: Array, state_ins: int) -> Dictionary:
18
+ if inferencer == null:
19
+ printerr("Inferencer not initialized")
20
+ return {}
21
+ return inferencer.RunInference(obs, state_ins)
22
+
23
+
24
+ func _notification(what):
25
+ if what == NOTIFICATION_PREDELETE:
26
+ inferencer.FreeDisposables()
27
+ inferencer.free()
addons/godot_rl_agents/plugin.cfg ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [plugin]
2
+
3
+ name="GodotRLAgents"
4
+ description="Custom nodes for the godot rl agents toolkit "
5
+ author="Edward Beeching"
6
+ version="0.1"
7
+ script="godot_rl_agents.gd"
addons/godot_rl_agents/sensors/sensors_2d/ExampleRaycastSensor2D.tscn ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=5 format=3 uid="uid://ddeq7mn1ealyc"]
2
+
3
+ [ext_resource type="Script" path="res://addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.gd" id="1"]
4
+
5
+ [sub_resource type="GDScript" id="2"]
6
+ script/source = "extends Node2D
7
+
8
+
9
+
10
+ func _physics_process(delta: float) -> void:
11
+ print(\"step start\")
12
+
13
+ "
14
+
15
+ [sub_resource type="GDScript" id="1"]
16
+ script/source = "extends RayCast2D
17
+
18
+ var steps = 1
19
+
20
+ func _physics_process(delta: float) -> void:
21
+ print(\"processing raycast\")
22
+ steps += 1
23
+ if steps % 2:
24
+ force_raycast_update()
25
+
26
+ print(is_colliding())
27
+ "
28
+
29
+ [sub_resource type="CircleShape2D" id="3"]
30
+
31
+ [node name="ExampleRaycastSensor2D" type="Node2D"]
32
+ script = SubResource("2")
33
+
34
+ [node name="ExampleAgent" type="Node2D" parent="."]
35
+ position = Vector2(573, 314)
36
+ rotation = 0.286234
37
+
38
+ [node name="RaycastSensor2D" type="Node2D" parent="ExampleAgent"]
39
+ script = ExtResource("1")
40
+
41
+ [node name="TestRayCast2D" type="RayCast2D" parent="."]
42
+ script = SubResource("1")
43
+
44
+ [node name="StaticBody2D" type="StaticBody2D" parent="."]
45
+ position = Vector2(1, 52)
46
+
47
+ [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
48
+ shape = SubResource("3")
addons/godot_rl_agents/sensors/sensors_2d/GridSensor2D.gd ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends ISensor2D
3
+ class_name GridSensor2D
4
+
5
+ @export var debug_view := false:
6
+ get:
7
+ return debug_view
8
+ set(value):
9
+ debug_view = value
10
+ _update()
11
+
12
+ @export_flags_2d_physics var detection_mask := 0:
13
+ get:
14
+ return detection_mask
15
+ set(value):
16
+ detection_mask = value
17
+ _update()
18
+
19
+ @export var collide_with_areas := false:
20
+ get:
21
+ return collide_with_areas
22
+ set(value):
23
+ collide_with_areas = value
24
+ _update()
25
+
26
+ @export var collide_with_bodies := true:
27
+ get:
28
+ return collide_with_bodies
29
+ set(value):
30
+ collide_with_bodies = value
31
+ _update()
32
+
33
+ @export_range(1, 200, 0.1) var cell_width := 20.0:
34
+ get:
35
+ return cell_width
36
+ set(value):
37
+ cell_width = value
38
+ _update()
39
+
40
+ @export_range(1, 200, 0.1) var cell_height := 20.0:
41
+ get:
42
+ return cell_height
43
+ set(value):
44
+ cell_height = value
45
+ _update()
46
+
47
+ @export_range(1, 21, 2, "or_greater") var grid_size_x := 3:
48
+ get:
49
+ return grid_size_x
50
+ set(value):
51
+ grid_size_x = value
52
+ _update()
53
+
54
+ @export_range(1, 21, 2, "or_greater") var grid_size_y := 3:
55
+ get:
56
+ return grid_size_y
57
+ set(value):
58
+ grid_size_y = value
59
+ _update()
60
+
61
+ var _obs_buffer: PackedFloat64Array
62
+ var _rectangle_shape: RectangleShape2D
63
+ var _collision_mapping: Dictionary
64
+ var _n_layers_per_cell: int
65
+
66
+ var _highlighted_cell_color: Color
67
+ var _standard_cell_color: Color
68
+
69
+
70
+ func get_observation():
71
+ return _obs_buffer
72
+
73
+
74
+ func _update():
75
+ if Engine.is_editor_hint():
76
+ if is_node_ready():
77
+ _spawn_nodes()
78
+
79
+
80
+ func _ready() -> void:
81
+ _set_colors()
82
+
83
+ if Engine.is_editor_hint():
84
+ if get_child_count() == 0:
85
+ _spawn_nodes()
86
+ else:
87
+ _spawn_nodes()
88
+
89
+
90
+ func _set_colors() -> void:
91
+ _standard_cell_color = Color(100.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0)
92
+ _highlighted_cell_color = Color(255.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0)
93
+
94
+
95
+ func _get_collision_mapping() -> Dictionary:
96
+ # defines which layer is mapped to which cell obs index
97
+ var total_bits = 0
98
+ var collision_mapping = {}
99
+ for i in 32:
100
+ var bit_mask = 2 ** i
101
+ if (detection_mask & bit_mask) > 0:
102
+ collision_mapping[i] = total_bits
103
+ total_bits += 1
104
+
105
+ return collision_mapping
106
+
107
+
108
+ func _spawn_nodes():
109
+ for cell in get_children():
110
+ cell.name = "_%s" % cell.name # Otherwise naming below will fail
111
+ cell.queue_free()
112
+
113
+ _collision_mapping = _get_collision_mapping()
114
+ #prints("collision_mapping", _collision_mapping, len(_collision_mapping))
115
+ # allocate memory for the observations
116
+ _n_layers_per_cell = len(_collision_mapping)
117
+ _obs_buffer = PackedFloat64Array()
118
+ _obs_buffer.resize(grid_size_x * grid_size_y * _n_layers_per_cell)
119
+ _obs_buffer.fill(0)
120
+ #prints(len(_obs_buffer), _obs_buffer )
121
+
122
+ _rectangle_shape = RectangleShape2D.new()
123
+ _rectangle_shape.set_size(Vector2(cell_width, cell_height))
124
+
125
+ var shift := Vector2(
126
+ -(grid_size_x / 2) * cell_width,
127
+ -(grid_size_y / 2) * cell_height,
128
+ )
129
+
130
+ for i in grid_size_x:
131
+ for j in grid_size_y:
132
+ var cell_position = Vector2(i * cell_width, j * cell_height) + shift
133
+ _create_cell(i, j, cell_position)
134
+
135
+
136
+ func _create_cell(i: int, j: int, position: Vector2):
137
+ var cell := Area2D.new()
138
+ cell.position = position
139
+ cell.name = "GridCell %s %s" % [i, j]
140
+ cell.modulate = _standard_cell_color
141
+
142
+ if collide_with_areas:
143
+ cell.area_entered.connect(_on_cell_area_entered.bind(i, j))
144
+ cell.area_exited.connect(_on_cell_area_exited.bind(i, j))
145
+
146
+ if collide_with_bodies:
147
+ cell.body_entered.connect(_on_cell_body_entered.bind(i, j))
148
+ cell.body_exited.connect(_on_cell_body_exited.bind(i, j))
149
+
150
+ cell.collision_layer = 0
151
+ cell.collision_mask = detection_mask
152
+ cell.monitorable = true
153
+ add_child(cell)
154
+ cell.set_owner(get_tree().edited_scene_root)
155
+
156
+ var col_shape := CollisionShape2D.new()
157
+ col_shape.shape = _rectangle_shape
158
+ col_shape.name = "CollisionShape2D"
159
+ cell.add_child(col_shape)
160
+ col_shape.set_owner(get_tree().edited_scene_root)
161
+
162
+ if debug_view:
163
+ var quad = MeshInstance2D.new()
164
+ quad.name = "MeshInstance2D"
165
+ var quad_mesh = QuadMesh.new()
166
+
167
+ quad_mesh.set_size(Vector2(cell_width, cell_height))
168
+
169
+ quad.mesh = quad_mesh
170
+ cell.add_child(quad)
171
+ quad.set_owner(get_tree().edited_scene_root)
172
+
173
+
174
+ func _update_obs(cell_i: int, cell_j: int, collision_layer: int, entered: bool):
175
+ for key in _collision_mapping:
176
+ var bit_mask = 2 ** key
177
+ if (collision_layer & bit_mask) > 0:
178
+ var collison_map_index = _collision_mapping[key]
179
+
180
+ var obs_index = (
181
+ (cell_i * grid_size_x * _n_layers_per_cell)
182
+ + (cell_j * _n_layers_per_cell)
183
+ + collison_map_index
184
+ )
185
+ #prints(obs_index, cell_i, cell_j)
186
+ if entered:
187
+ _obs_buffer[obs_index] += 1
188
+ else:
189
+ _obs_buffer[obs_index] -= 1
190
+
191
+
192
+ func _toggle_cell(cell_i: int, cell_j: int):
193
+ var cell = get_node_or_null("GridCell %s %s" % [cell_i, cell_j])
194
+
195
+ if cell == null:
196
+ print("cell not found, returning")
197
+
198
+ var n_hits = 0
199
+ var start_index = (cell_i * grid_size_x * _n_layers_per_cell) + (cell_j * _n_layers_per_cell)
200
+ for i in _n_layers_per_cell:
201
+ n_hits += _obs_buffer[start_index + i]
202
+
203
+ if n_hits > 0:
204
+ cell.modulate = _highlighted_cell_color
205
+ else:
206
+ cell.modulate = _standard_cell_color
207
+
208
+
209
+ func _on_cell_area_entered(area: Area2D, cell_i: int, cell_j: int):
210
+ #prints("_on_cell_area_entered", cell_i, cell_j)
211
+ _update_obs(cell_i, cell_j, area.collision_layer, true)
212
+ if debug_view:
213
+ _toggle_cell(cell_i, cell_j)
214
+ #print(_obs_buffer)
215
+
216
+
217
+ func _on_cell_area_exited(area: Area2D, cell_i: int, cell_j: int):
218
+ #prints("_on_cell_area_exited", cell_i, cell_j)
219
+ _update_obs(cell_i, cell_j, area.collision_layer, false)
220
+ if debug_view:
221
+ _toggle_cell(cell_i, cell_j)
222
+
223
+
224
+ func _on_cell_body_entered(body: Node2D, cell_i: int, cell_j: int):
225
+ #prints("_on_cell_body_entered", cell_i, cell_j)
226
+ _update_obs(cell_i, cell_j, body.collision_layer, true)
227
+ if debug_view:
228
+ _toggle_cell(cell_i, cell_j)
229
+
230
+
231
+ func _on_cell_body_exited(body: Node2D, cell_i: int, cell_j: int):
232
+ #prints("_on_cell_body_exited", cell_i, cell_j)
233
+ _update_obs(cell_i, cell_j, body.collision_layer, false)
234
+ if debug_view:
235
+ _toggle_cell(cell_i, cell_j)
addons/godot_rl_agents/sensors/sensors_2d/ISensor2D.gd ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node2D
2
+ class_name ISensor2D
3
+
4
+ var _obs: Array = []
5
+ var _active := false
6
+
7
+
8
+ func get_observation():
9
+ pass
10
+
11
+
12
+ func activate():
13
+ _active = true
14
+
15
+
16
+ func deactivate():
17
+ _active = false
18
+
19
+
20
+ func _update_observation():
21
+ pass
22
+
23
+
24
+ func reset():
25
+ pass
addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.gd ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends ISensor2D
3
+ class_name RaycastSensor2D
4
+
5
+ @export_flags_2d_physics var collision_mask := 1:
6
+ get:
7
+ return collision_mask
8
+ set(value):
9
+ collision_mask = value
10
+ _update()
11
+
12
+ @export var collide_with_areas := false:
13
+ get:
14
+ return collide_with_areas
15
+ set(value):
16
+ collide_with_areas = value
17
+ _update()
18
+
19
+ @export var collide_with_bodies := true:
20
+ get:
21
+ return collide_with_bodies
22
+ set(value):
23
+ collide_with_bodies = value
24
+ _update()
25
+
26
+ @export var n_rays := 16.0:
27
+ get:
28
+ return n_rays
29
+ set(value):
30
+ n_rays = value
31
+ _update()
32
+
33
+ @export_range(5, 3000, 5.0) var ray_length := 200:
34
+ get:
35
+ return ray_length
36
+ set(value):
37
+ ray_length = value
38
+ _update()
39
+ @export_range(5, 360, 5.0) var cone_width := 360.0:
40
+ get:
41
+ return cone_width
42
+ set(value):
43
+ cone_width = value
44
+ _update()
45
+
46
+ @export var debug_draw := true:
47
+ get:
48
+ return debug_draw
49
+ set(value):
50
+ debug_draw = value
51
+ _update()
52
+
53
+ var _angles = []
54
+ var rays := []
55
+
56
+
57
+ func _update():
58
+ if Engine.is_editor_hint():
59
+ if debug_draw:
60
+ _spawn_nodes()
61
+ else:
62
+ for ray in get_children():
63
+ if ray is RayCast2D:
64
+ remove_child(ray)
65
+
66
+
67
+ func _ready() -> void:
68
+ _spawn_nodes()
69
+
70
+
71
+ func _spawn_nodes():
72
+ for ray in rays:
73
+ ray.queue_free()
74
+ rays = []
75
+
76
+ _angles = []
77
+ var step = cone_width / (n_rays)
78
+ var start = step / 2 - cone_width / 2
79
+
80
+ for i in n_rays:
81
+ var angle = start + i * step
82
+ var ray = RayCast2D.new()
83
+ ray.set_target_position(
84
+ Vector2(ray_length * cos(deg_to_rad(angle)), ray_length * sin(deg_to_rad(angle)))
85
+ )
86
+ ray.set_name("node_" + str(i))
87
+ ray.enabled = false
88
+ ray.collide_with_areas = collide_with_areas
89
+ ray.collide_with_bodies = collide_with_bodies
90
+ ray.collision_mask = collision_mask
91
+ add_child(ray)
92
+ rays.append(ray)
93
+
94
+ _angles.append(start + i * step)
95
+
96
+
97
+ func get_observation() -> Array:
98
+ return self.calculate_raycasts()
99
+
100
+
101
+ func calculate_raycasts() -> Array:
102
+ var result = []
103
+ for ray in rays:
104
+ ray.enabled = true
105
+ ray.force_raycast_update()
106
+ var distance = _get_raycast_distance(ray)
107
+ result.append(distance)
108
+ ray.enabled = false
109
+ return result
110
+
111
+
112
+ func _get_raycast_distance(ray: RayCast2D) -> float:
113
+ if !ray.is_colliding():
114
+ return 0.0
115
+
116
+ var distance = (global_position - ray.get_collision_point()).length()
117
+ distance = clamp(distance, 0.0, ray_length)
118
+ return (ray_length - distance) / ray_length
addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.tscn ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=2 format=3 uid="uid://drvfihk5esgmv"]
2
+
3
+ [ext_resource type="Script" path="res://addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.gd" id="1"]
4
+
5
+ [node name="RaycastSensor2D" type="Node2D"]
6
+ script = ExtResource("1")
7
+ n_rays = 17.0
addons/godot_rl_agents/sensors/sensors_3d/ExampleRaycastSensor3D.tscn ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [gd_scene format=3 uid="uid://biu787qh4woik"]
2
+
3
+ [node name="ExampleRaycastSensor3D" type="Node3D"]
4
+
5
+ [node name="Camera3D" type="Camera3D" parent="."]
6
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.804183, 0, 2.70146)
addons/godot_rl_agents/sensors/sensors_3d/GridSensor3D.gd ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends ISensor3D
3
+ class_name GridSensor3D
4
+
5
+ @export var debug_view := false:
6
+ get:
7
+ return debug_view
8
+ set(value):
9
+ debug_view = value
10
+ _update()
11
+
12
+ @export_flags_3d_physics var detection_mask := 0:
13
+ get:
14
+ return detection_mask
15
+ set(value):
16
+ detection_mask = value
17
+ _update()
18
+
19
+ @export var collide_with_areas := false:
20
+ get:
21
+ return collide_with_areas
22
+ set(value):
23
+ collide_with_areas = value
24
+ _update()
25
+
26
+ @export var collide_with_bodies := false:
27
+ # NOTE! The sensor will not detect StaticBody3D, add an area to static bodies to detect them
28
+ get:
29
+ return collide_with_bodies
30
+ set(value):
31
+ collide_with_bodies = value
32
+ _update()
33
+
34
+ @export_range(0.1, 2, 0.1) var cell_width := 1.0:
35
+ get:
36
+ return cell_width
37
+ set(value):
38
+ cell_width = value
39
+ _update()
40
+
41
+ @export_range(0.1, 2, 0.1) var cell_height := 1.0:
42
+ get:
43
+ return cell_height
44
+ set(value):
45
+ cell_height = value
46
+ _update()
47
+
48
+ @export_range(1, 21, 2, "or_greater") var grid_size_x := 3:
49
+ get:
50
+ return grid_size_x
51
+ set(value):
52
+ grid_size_x = value
53
+ _update()
54
+
55
+ @export_range(1, 21, 2, "or_greater") var grid_size_z := 3:
56
+ get:
57
+ return grid_size_z
58
+ set(value):
59
+ grid_size_z = value
60
+ _update()
61
+
62
+ var _obs_buffer: PackedFloat64Array
63
+ var _box_shape: BoxShape3D
64
+ var _collision_mapping: Dictionary
65
+ var _n_layers_per_cell: int
66
+
67
+ var _highlighted_box_material: StandardMaterial3D
68
+ var _standard_box_material: StandardMaterial3D
69
+
70
+
71
+ func get_observation():
72
+ return _obs_buffer
73
+
74
+
75
+ func reset():
76
+ _obs_buffer.fill(0)
77
+
78
+
79
+ func _update():
80
+ if Engine.is_editor_hint():
81
+ if is_node_ready():
82
+ _spawn_nodes()
83
+
84
+
85
+ func _ready() -> void:
86
+ _make_materials()
87
+
88
+ if Engine.is_editor_hint():
89
+ if get_child_count() == 0:
90
+ _spawn_nodes()
91
+ else:
92
+ _spawn_nodes()
93
+
94
+
95
+ func _make_materials() -> void:
96
+ if _highlighted_box_material != null and _standard_box_material != null:
97
+ return
98
+
99
+ _standard_box_material = StandardMaterial3D.new()
100
+ _standard_box_material.set_transparency(1) # ALPHA
101
+ _standard_box_material.albedo_color = Color(
102
+ 100.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0
103
+ )
104
+
105
+ _highlighted_box_material = StandardMaterial3D.new()
106
+ _highlighted_box_material.set_transparency(1) # ALPHA
107
+ _highlighted_box_material.albedo_color = Color(
108
+ 255.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0, 100.0 / 255.0
109
+ )
110
+
111
+
112
+ func _get_collision_mapping() -> Dictionary:
113
+ # defines which layer is mapped to which cell obs index
114
+ var total_bits = 0
115
+ var collision_mapping = {}
116
+ for i in 32:
117
+ var bit_mask = 2 ** i
118
+ if (detection_mask & bit_mask) > 0:
119
+ collision_mapping[i] = total_bits
120
+ total_bits += 1
121
+
122
+ return collision_mapping
123
+
124
+
125
+ func _spawn_nodes():
126
+ for cell in get_children():
127
+ cell.name = "_%s" % cell.name # Otherwise naming below will fail
128
+ cell.queue_free()
129
+
130
+ _collision_mapping = _get_collision_mapping()
131
+ #prints("collision_mapping", _collision_mapping, len(_collision_mapping))
132
+ # allocate memory for the observations
133
+ _n_layers_per_cell = len(_collision_mapping)
134
+ _obs_buffer = PackedFloat64Array()
135
+ _obs_buffer.resize(grid_size_x * grid_size_z * _n_layers_per_cell)
136
+ _obs_buffer.fill(0)
137
+ #prints(len(_obs_buffer), _obs_buffer )
138
+
139
+ _box_shape = BoxShape3D.new()
140
+ _box_shape.set_size(Vector3(cell_width, cell_height, cell_width))
141
+
142
+ var shift := Vector3(
143
+ -(grid_size_x / 2) * cell_width,
144
+ 0,
145
+ -(grid_size_z / 2) * cell_width,
146
+ )
147
+
148
+ for i in grid_size_x:
149
+ for j in grid_size_z:
150
+ var cell_position = Vector3(i * cell_width, 0.0, j * cell_width) + shift
151
+ _create_cell(i, j, cell_position)
152
+
153
+
154
+ func _create_cell(i: int, j: int, position: Vector3):
155
+ var cell := Area3D.new()
156
+ cell.position = position
157
+ cell.name = "GridCell %s %s" % [i, j]
158
+
159
+ if collide_with_areas:
160
+ cell.area_entered.connect(_on_cell_area_entered.bind(i, j))
161
+ cell.area_exited.connect(_on_cell_area_exited.bind(i, j))
162
+
163
+ if collide_with_bodies:
164
+ cell.body_entered.connect(_on_cell_body_entered.bind(i, j))
165
+ cell.body_exited.connect(_on_cell_body_exited.bind(i, j))
166
+
167
+ # cell.body_shape_entered.connect(_on_cell_body_shape_entered.bind(i, j))
168
+ # cell.body_shape_exited.connect(_on_cell_body_shape_exited.bind(i, j))
169
+
170
+ cell.collision_layer = 0
171
+ cell.collision_mask = detection_mask
172
+ cell.monitorable = true
173
+ cell.input_ray_pickable = false
174
+ add_child(cell)
175
+ cell.set_owner(get_tree().edited_scene_root)
176
+
177
+ var col_shape := CollisionShape3D.new()
178
+ col_shape.shape = _box_shape
179
+ col_shape.name = "CollisionShape3D"
180
+ cell.add_child(col_shape)
181
+ col_shape.set_owner(get_tree().edited_scene_root)
182
+
183
+ if debug_view:
184
+ var box = MeshInstance3D.new()
185
+ box.name = "MeshInstance3D"
186
+ var box_mesh = BoxMesh.new()
187
+
188
+ box_mesh.set_size(Vector3(cell_width, cell_height, cell_width))
189
+ box_mesh.material = _standard_box_material
190
+
191
+ box.mesh = box_mesh
192
+ cell.add_child(box)
193
+ box.set_owner(get_tree().edited_scene_root)
194
+
195
+
196
+ func _update_obs(cell_i: int, cell_j: int, collision_layer: int, entered: bool):
197
+ for key in _collision_mapping:
198
+ var bit_mask = 2 ** key
199
+ if (collision_layer & bit_mask) > 0:
200
+ var collison_map_index = _collision_mapping[key]
201
+
202
+ var obs_index = (
203
+ (cell_i * grid_size_x * _n_layers_per_cell)
204
+ + (cell_j * _n_layers_per_cell)
205
+ + collison_map_index
206
+ )
207
+ #prints(obs_index, cell_i, cell_j)
208
+ if entered:
209
+ _obs_buffer[obs_index] += 1
210
+ else:
211
+ _obs_buffer[obs_index] -= 1
212
+
213
+
214
+ func _toggle_cell(cell_i: int, cell_j: int):
215
+ var cell = get_node_or_null("GridCell %s %s" % [cell_i, cell_j])
216
+
217
+ if cell == null:
218
+ print("cell not found, returning")
219
+
220
+ var n_hits = 0
221
+ var start_index = (cell_i * grid_size_x * _n_layers_per_cell) + (cell_j * _n_layers_per_cell)
222
+ for i in _n_layers_per_cell:
223
+ n_hits += _obs_buffer[start_index + i]
224
+
225
+ var cell_mesh = cell.get_node_or_null("MeshInstance3D")
226
+ if n_hits > 0:
227
+ cell_mesh.mesh.material = _highlighted_box_material
228
+ else:
229
+ cell_mesh.mesh.material = _standard_box_material
230
+
231
+
232
+ func _on_cell_area_entered(area: Area3D, cell_i: int, cell_j: int):
233
+ #prints("_on_cell_area_entered", cell_i, cell_j)
234
+ _update_obs(cell_i, cell_j, area.collision_layer, true)
235
+ if debug_view:
236
+ _toggle_cell(cell_i, cell_j)
237
+ #print(_obs_buffer)
238
+
239
+
240
+ func _on_cell_area_exited(area: Area3D, cell_i: int, cell_j: int):
241
+ #prints("_on_cell_area_exited", cell_i, cell_j)
242
+ _update_obs(cell_i, cell_j, area.collision_layer, false)
243
+ if debug_view:
244
+ _toggle_cell(cell_i, cell_j)
245
+
246
+
247
+ func _on_cell_body_entered(body: Node3D, cell_i: int, cell_j: int):
248
+ #prints("_on_cell_body_entered", cell_i, cell_j)
249
+ _update_obs(cell_i, cell_j, body.collision_layer, true)
250
+ if debug_view:
251
+ _toggle_cell(cell_i, cell_j)
252
+
253
+
254
+ func _on_cell_body_exited(body: Node3D, cell_i: int, cell_j: int):
255
+ #prints("_on_cell_body_exited", cell_i, cell_j)
256
+ _update_obs(cell_i, cell_j, body.collision_layer, false)
257
+ if debug_view:
258
+ _toggle_cell(cell_i, cell_j)
addons/godot_rl_agents/sensors/sensors_3d/ISensor3D.gd ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node3D
2
+ class_name ISensor3D
3
+
4
+ var _obs: Array = []
5
+ var _active := false
6
+
7
+
8
+ func get_observation():
9
+ pass
10
+
11
+
12
+ func activate():
13
+ _active = true
14
+
15
+
16
+ func deactivate():
17
+ _active = false
18
+
19
+
20
+ func _update_observation():
21
+ pass
22
+
23
+
24
+ func reset():
25
+ pass
addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.gd ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node3D
2
+ class_name RGBCameraSensor3D
3
+ var camera_pixels = null
4
+
5
+ @onready var camera_texture := $Control/TextureRect/CameraTexture as Sprite2D
6
+ @onready var sub_viewport := $SubViewport as SubViewport
7
+
8
+
9
+ func get_camera_pixel_encoding():
10
+ return camera_texture.get_texture().get_image().get_data().hex_encode()
11
+
12
+
13
+ func get_camera_shape() -> Array:
14
+ assert(
15
+ sub_viewport.size.x >= 36 and sub_viewport.size.y >= 36,
16
+ "SubViewport size must be 36x36 or larger."
17
+ )
18
+ if sub_viewport.transparent_bg:
19
+ return [4, sub_viewport.size.y, sub_viewport.size.x]
20
+ else:
21
+ return [3, sub_viewport.size.y, sub_viewport.size.x]
addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.tscn ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=3 format=3 uid="uid://baaywi3arsl2m"]
2
+
3
+ [ext_resource type="Script" path="res://addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.gd" id="1"]
4
+
5
+ [sub_resource type="ViewportTexture" id="1"]
6
+ viewport_path = NodePath("SubViewport")
7
+
8
+ [node name="RGBCameraSensor3D" type="Node3D"]
9
+ script = ExtResource("1")
10
+
11
+ [node name="RemoteTransform3D" type="RemoteTransform3D" parent="."]
12
+ remote_path = NodePath("../SubViewport/Camera3D")
13
+
14
+ [node name="SubViewport" type="SubViewport" parent="."]
15
+ size = Vector2i(32, 32)
16
+ render_target_update_mode = 3
17
+
18
+ [node name="Camera3D" type="Camera3D" parent="SubViewport"]
19
+ near = 0.5
20
+
21
+ [node name="Control" type="Control" parent="."]
22
+ layout_mode = 3
23
+ anchors_preset = 15
24
+ anchor_right = 1.0
25
+ anchor_bottom = 1.0
26
+ grow_horizontal = 2
27
+ grow_vertical = 2
28
+
29
+ [node name="TextureRect" type="ColorRect" parent="Control"]
30
+ layout_mode = 0
31
+ offset_left = 1096.0
32
+ offset_top = 534.0
33
+ offset_right = 1114.0
34
+ offset_bottom = 552.0
35
+ scale = Vector2(10, 10)
36
+ color = Color(0.00784314, 0.00784314, 0.00784314, 1)
37
+
38
+ [node name="CameraTexture" type="Sprite2D" parent="Control/TextureRect"]
39
+ texture = SubResource("1")
40
+ offset = Vector2(9, 9)
41
+ flip_v = true
addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.gd ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends ISensor3D
3
+ class_name RayCastSensor3D
4
+ @export_flags_3d_physics var collision_mask = 1:
5
+ get:
6
+ return collision_mask
7
+ set(value):
8
+ collision_mask = value
9
+ _update()
10
+ @export_flags_3d_physics var boolean_class_mask = 1:
11
+ get:
12
+ return boolean_class_mask
13
+ set(value):
14
+ boolean_class_mask = value
15
+ _update()
16
+
17
+ @export var n_rays_width := 6.0:
18
+ get:
19
+ return n_rays_width
20
+ set(value):
21
+ n_rays_width = value
22
+ _update()
23
+
24
+ @export var n_rays_height := 6.0:
25
+ get:
26
+ return n_rays_height
27
+ set(value):
28
+ n_rays_height = value
29
+ _update()
30
+
31
+ @export var ray_length := 10.0:
32
+ get:
33
+ return ray_length
34
+ set(value):
35
+ ray_length = value
36
+ _update()
37
+
38
+ @export var cone_width := 60.0:
39
+ get:
40
+ return cone_width
41
+ set(value):
42
+ cone_width = value
43
+ _update()
44
+
45
+ @export var cone_height := 60.0:
46
+ get:
47
+ return cone_height
48
+ set(value):
49
+ cone_height = value
50
+ _update()
51
+
52
+ @export var collide_with_areas := false:
53
+ get:
54
+ return collide_with_areas
55
+ set(value):
56
+ collide_with_areas = value
57
+ _update()
58
+
59
+ @export var collide_with_bodies := true:
60
+ get:
61
+ return collide_with_bodies
62
+ set(value):
63
+ collide_with_bodies = value
64
+ _update()
65
+
66
+ @export var class_sensor := false
67
+
68
+ var rays := []
69
+ var geo = null
70
+
71
+
72
+ func _update():
73
+ if Engine.is_editor_hint():
74
+ if is_node_ready():
75
+ _spawn_nodes()
76
+
77
+
78
+ func _ready() -> void:
79
+ if Engine.is_editor_hint():
80
+ if get_child_count() == 0:
81
+ _spawn_nodes()
82
+ else:
83
+ _spawn_nodes()
84
+
85
+
86
+ func _spawn_nodes():
87
+ print("spawning nodes")
88
+ for ray in get_children():
89
+ ray.queue_free()
90
+ if geo:
91
+ geo.clear()
92
+ #$Lines.remove_points()
93
+ rays = []
94
+
95
+ var horizontal_step = cone_width / (n_rays_width)
96
+ var vertical_step = cone_height / (n_rays_height)
97
+
98
+ var horizontal_start = horizontal_step / 2 - cone_width / 2
99
+ var vertical_start = vertical_step / 2 - cone_height / 2
100
+
101
+ var points = []
102
+
103
+ for i in n_rays_width:
104
+ for j in n_rays_height:
105
+ var angle_w = horizontal_start + i * horizontal_step
106
+ var angle_h = vertical_start + j * vertical_step
107
+ #angle_h = 0.0
108
+ var ray = RayCast3D.new()
109
+ var cast_to = to_spherical_coords(ray_length, angle_w, angle_h)
110
+ ray.set_target_position(cast_to)
111
+
112
+ points.append(cast_to)
113
+
114
+ ray.set_name("node_" + str(i) + " " + str(j))
115
+ ray.enabled = true
116
+ ray.collide_with_bodies = collide_with_bodies
117
+ ray.collide_with_areas = collide_with_areas
118
+ ray.collision_mask = collision_mask
119
+ add_child(ray)
120
+ ray.set_owner(get_tree().edited_scene_root)
121
+ rays.append(ray)
122
+ ray.force_raycast_update()
123
+
124
+
125
+ # if Engine.editor_hint:
126
+ # _create_debug_lines(points)
127
+
128
+
129
+ func _create_debug_lines(points):
130
+ if not geo:
131
+ geo = ImmediateMesh.new()
132
+ add_child(geo)
133
+
134
+ geo.clear()
135
+ geo.begin(Mesh.PRIMITIVE_LINES)
136
+ for point in points:
137
+ geo.set_color(Color.AQUA)
138
+ geo.add_vertex(Vector3.ZERO)
139
+ geo.add_vertex(point)
140
+ geo.end()
141
+
142
+
143
+ func display():
144
+ if geo:
145
+ geo.display()
146
+
147
+
148
+ func to_spherical_coords(r, inc, azimuth) -> Vector3:
149
+ return Vector3(
150
+ r * sin(deg_to_rad(inc)) * cos(deg_to_rad(azimuth)),
151
+ r * sin(deg_to_rad(azimuth)),
152
+ r * cos(deg_to_rad(inc)) * cos(deg_to_rad(azimuth))
153
+ )
154
+
155
+
156
+ func get_observation() -> Array:
157
+ return self.calculate_raycasts()
158
+
159
+
160
+ func calculate_raycasts() -> Array:
161
+ var result = []
162
+ for ray in rays:
163
+ ray.set_enabled(true)
164
+ ray.force_raycast_update()
165
+ var distance = _get_raycast_distance(ray)
166
+
167
+ result.append(distance)
168
+ if class_sensor:
169
+ var hit_class: float = 0
170
+ if ray.get_collider():
171
+ var hit_collision_layer = ray.get_collider().collision_layer
172
+ hit_collision_layer = hit_collision_layer & collision_mask
173
+ hit_class = (hit_collision_layer & boolean_class_mask) > 0
174
+ result.append(float(hit_class))
175
+ ray.set_enabled(false)
176
+ return result
177
+
178
+
179
+ func _get_raycast_distance(ray: RayCast3D) -> float:
180
+ if !ray.is_colliding():
181
+ return 0.0
182
+
183
+ var distance = (global_transform.origin - ray.get_collision_point()).length()
184
+ distance = clamp(distance, 0.0, ray_length)
185
+ return (ray_length - distance) / ray_length
addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.tscn ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=2 format=3 uid="uid://b803cbh1fmy66"]
2
+
3
+ [ext_resource type="Script" path="res://addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.gd" id="1"]
4
+
5
+ [node name="RaycastSensor3D" type="Node3D"]
6
+ script = ExtResource("1")
7
+ n_rays_width = 4.0
8
+ n_rays_height = 2.0
9
+ ray_length = 11.0
10
+
11
+ [node name="node_1 0" type="RayCast3D" parent="."]
12
+ target_position = Vector3(-1.38686, -2.84701, 10.5343)
13
+
14
+ [node name="node_1 1" type="RayCast3D" parent="."]
15
+ target_position = Vector3(-1.38686, 2.84701, 10.5343)
16
+
17
+ [node name="node_2 0" type="RayCast3D" parent="."]
18
+ target_position = Vector3(1.38686, -2.84701, 10.5343)
19
+
20
+ [node name="node_2 1" type="RayCast3D" parent="."]
21
+ target_position = Vector3(1.38686, 2.84701, 10.5343)
22
+
23
+ [node name="node_3 0" type="RayCast3D" parent="."]
24
+ target_position = Vector3(4.06608, -2.84701, 9.81639)
25
+
26
+ [node name="node_3 1" type="RayCast3D" parent="."]
27
+ target_position = Vector3(4.06608, 2.84701, 9.81639)
addons/godot_rl_agents/sync.gd ADDED
@@ -0,0 +1,540 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node
2
+
3
+ # --fixed-fps 2000 --disable-render-loop
4
+
5
+ enum ControlModes { HUMAN, TRAINING, ONNX_INFERENCE }
6
+ @export var control_mode: ControlModes = ControlModes.TRAINING
7
+ @export_range(1, 10, 1, "or_greater") var action_repeat := 8
8
+ @export_range(0, 10, 0.1, "or_greater") var speed_up := 1.0
9
+ @export var onnx_model_path := ""
10
+
11
+ # Onnx model stored for each requested path
12
+ var onnx_models: Dictionary
13
+
14
+ @onready var start_time = Time.get_ticks_msec()
15
+
16
+ const MAJOR_VERSION := "0"
17
+ const MINOR_VERSION := "7"
18
+ const DEFAULT_PORT := "11008"
19
+ const DEFAULT_SEED := "1"
20
+ var stream: StreamPeerTCP = null
21
+ var connected = false
22
+ var message_center
23
+ var should_connect = true
24
+
25
+ var all_agents: Array
26
+ var agents_training: Array
27
+ var agents_inference: Array
28
+ var agents_heuristic: Array
29
+
30
+ ## For recording expert demos
31
+ var agent_demo_record: Node
32
+ ## Stores recorded trajectories
33
+ var demo_trajectories: Array
34
+ ## A trajectory includes obs: Array, acts: Array, terminal (set in Python env instead)
35
+ var current_demo_trajectory: Array
36
+
37
+ var need_to_send_obs = false
38
+ var args = null
39
+ var initialized = false
40
+ var just_reset = false
41
+ var onnx_model = null
42
+ var n_action_steps = 0
43
+
44
+ var _action_space: Dictionary
45
+ var _action_space_inference: Array[Dictionary] = []
46
+ var _obs_space: Dictionary
47
+
48
+
49
+ # Called when the node enters the scene tree for the first time.
50
+ func _ready():
51
+ await get_tree().root.ready
52
+ get_tree().set_pause(true)
53
+ _initialize()
54
+ await get_tree().create_timer(1.0).timeout
55
+ get_tree().set_pause(false)
56
+
57
+
58
+ func _initialize():
59
+ _get_agents()
60
+ args = _get_args()
61
+ Engine.physics_ticks_per_second = _get_speedup() * 60 # Replace with function body.
62
+ Engine.time_scale = _get_speedup() * 1.0
63
+ prints(
64
+ "physics ticks",
65
+ Engine.physics_ticks_per_second,
66
+ Engine.time_scale,
67
+ _get_speedup(),
68
+ speed_up
69
+ )
70
+
71
+ _set_heuristic("human", all_agents)
72
+
73
+ _initialize_training_agents()
74
+ _initialize_inference_agents()
75
+ _initialize_demo_recording()
76
+
77
+ _set_seed()
78
+ _set_action_repeat()
79
+ initialized = true
80
+
81
+
82
+ func _initialize_training_agents():
83
+ if agents_training.size() > 0:
84
+ _obs_space = agents_training[0].get_obs_space()
85
+ _action_space = agents_training[0].get_action_space()
86
+ connected = connect_to_server()
87
+ if connected:
88
+ _set_heuristic("model", agents_training)
89
+ _handshake()
90
+ _send_env_info()
91
+ else:
92
+ push_warning(
93
+ "Couldn't connect to Python server, using human controls instead. ",
94
+ "Did you start the training server using e.g. `gdrl` from the console?"
95
+ )
96
+
97
+
98
+ func _initialize_inference_agents():
99
+ if agents_inference.size() > 0:
100
+ if control_mode == ControlModes.ONNX_INFERENCE:
101
+ assert(
102
+ FileAccess.file_exists(onnx_model_path),
103
+ "Onnx Model Path set on Sync node does not exist: %s" % onnx_model_path
104
+ )
105
+ onnx_models[onnx_model_path] = ONNXModel.new(onnx_model_path, 1)
106
+
107
+ for agent in agents_inference:
108
+ _action_space_inference.append(agent.get_action_space())
109
+
110
+ var agent_onnx_model: ONNXModel
111
+ if agent.onnx_model_path.is_empty():
112
+ assert(
113
+ onnx_models.has(onnx_model_path),
114
+ (
115
+ "Node %s has no onnx model path set " % agent.get_path()
116
+ + "and sync node's control mode is not set to OnnxInference. "
117
+ + "Either add the path to the AIController, "
118
+ + "or if you want to use the path set on sync node instead, "
119
+ + "set control mode to OnnxInference."
120
+ )
121
+ )
122
+ prints(
123
+ "Info: AIController %s" % agent.get_path(),
124
+ "has no onnx model path set.",
125
+ "Using path set on the sync node instead."
126
+ )
127
+ agent_onnx_model = onnx_models[onnx_model_path]
128
+ else:
129
+ if not onnx_models.has(agent.onnx_model_path):
130
+ assert(
131
+ FileAccess.file_exists(agent.onnx_model_path),
132
+ (
133
+ "Onnx Model Path set on %s node does not exist: %s"
134
+ % [agent.get_path(), agent.onnx_model_path]
135
+ )
136
+ )
137
+ onnx_models[agent.onnx_model_path] = ONNXModel.new(agent.onnx_model_path, 1)
138
+ agent_onnx_model = onnx_models[agent.onnx_model_path]
139
+
140
+ agent.onnx_model = agent_onnx_model
141
+ _set_heuristic("model", agents_inference)
142
+
143
+
144
+ func _initialize_demo_recording():
145
+ if agent_demo_record:
146
+ InputMap.add_action("RemoveLastDemoEpisode")
147
+ InputMap.action_add_event(
148
+ "RemoveLastDemoEpisode", agent_demo_record.remove_last_episode_key
149
+ )
150
+ current_demo_trajectory.resize(2)
151
+ current_demo_trajectory[0] = []
152
+ current_demo_trajectory[1] = []
153
+ agent_demo_record.heuristic = "demo_record"
154
+
155
+
156
+ func _physics_process(_delta):
157
+ # two modes, human control, agent control
158
+ # pause tree, send obs, get actions, set actions, unpause tree
159
+
160
+ _demo_record_process()
161
+
162
+ if n_action_steps % action_repeat != 0:
163
+ n_action_steps += 1
164
+ return
165
+
166
+ n_action_steps += 1
167
+
168
+ _training_process()
169
+ _inference_process()
170
+ _heuristic_process()
171
+
172
+
173
+ func _training_process():
174
+ if connected:
175
+ get_tree().set_pause(true)
176
+
177
+ if just_reset:
178
+ just_reset = false
179
+ var obs = _get_obs_from_agents(agents_training)
180
+
181
+ var reply = {"type": "reset", "obs": obs}
182
+ _send_dict_as_json_message(reply)
183
+ # this should go straight to getting the action and setting it checked the agent, no need to perform one phyics tick
184
+ get_tree().set_pause(false)
185
+ return
186
+
187
+ if need_to_send_obs:
188
+ need_to_send_obs = false
189
+ var reward = _get_reward_from_agents()
190
+ var done = _get_done_from_agents()
191
+ #_reset_agents_if_done() # this ensures the new observation is from the next env instance : NEEDS REFACTOR
192
+
193
+ var obs = _get_obs_from_agents(agents_training)
194
+
195
+ var reply = {"type": "step", "obs": obs, "reward": reward, "done": done}
196
+ _send_dict_as_json_message(reply)
197
+
198
+ var handled = handle_message()
199
+
200
+
201
+ func _inference_process():
202
+ if agents_inference.size() > 0:
203
+ var obs: Array = _get_obs_from_agents(agents_inference)
204
+ var actions = []
205
+
206
+ for agent_id in range(0, agents_inference.size()):
207
+ var action = agents_inference[agent_id].onnx_model.run_inference(
208
+ obs[agent_id]["obs"], 1.0
209
+ )
210
+ action["output"] = clamp_array(action["output"], -1.0, 1.0)
211
+ var action_dict = _extract_action_dict(
212
+ action["output"], _action_space_inference[agent_id]
213
+ )
214
+ actions.append(action_dict)
215
+
216
+ _set_agent_actions(actions, agents_inference)
217
+ _reset_agents_if_done(agents_inference)
218
+ get_tree().set_pause(false)
219
+
220
+
221
+ func _demo_record_process():
222
+ if not agent_demo_record:
223
+ return
224
+
225
+ if Input.is_action_just_pressed("RemoveLastDemoEpisode"):
226
+ print("[Sync script][Demo recorder] Removing last recorded episode.")
227
+ demo_trajectories.remove_at(demo_trajectories.size() - 1)
228
+ print("Remaining episode count: %d" % demo_trajectories.size())
229
+
230
+ if n_action_steps % agent_demo_record.action_repeat != 0:
231
+ return
232
+
233
+ var obs_dict: Dictionary = agent_demo_record.get_obs()
234
+
235
+ # Get the current obs from the agent
236
+ assert(
237
+ obs_dict.has("obs"),
238
+ "Demo recorder needs an 'obs' key in get_obs() returned dictionary to record obs from."
239
+ )
240
+ current_demo_trajectory[0].append(obs_dict.obs)
241
+
242
+ # Get the action applied for the current obs from the agent
243
+ agent_demo_record.set_action()
244
+ var acts = agent_demo_record.get_action()
245
+
246
+ var terminal = agent_demo_record.get_done()
247
+ # Record actions only for non-terminal states
248
+ if terminal:
249
+ agent_demo_record.set_done_false()
250
+ else:
251
+ current_demo_trajectory[1].append(acts)
252
+
253
+ if terminal:
254
+ #current_demo_trajectory[2].append(true)
255
+ demo_trajectories.append(current_demo_trajectory.duplicate(true))
256
+ print("[Sync script][Demo recorder] Recorded episode count: %d" % demo_trajectories.size())
257
+ current_demo_trajectory[0].clear()
258
+ current_demo_trajectory[1].clear()
259
+
260
+
261
+ func _heuristic_process():
262
+ for agent in agents_heuristic:
263
+ _reset_agents_if_done(agents_heuristic)
264
+
265
+
266
+ func _extract_action_dict(action_array: Array, action_space: Dictionary):
267
+ var index = 0
268
+ var result = {}
269
+ for key in action_space.keys():
270
+ var size = action_space[key]["size"]
271
+ if action_space[key]["action_type"] == "discrete":
272
+ result[key] = round(action_array[index])
273
+ else:
274
+ result[key] = action_array.slice(index, index + size)
275
+ index += size
276
+
277
+ return result
278
+
279
+
280
+ ## For AIControllers that inherit mode from sync, sets the correct mode.
281
+ func _set_agent_mode(agent: Node):
282
+ var agent_inherits_mode: bool = agent.control_mode == agent.ControlModes.INHERIT_FROM_SYNC
283
+
284
+ if agent_inherits_mode:
285
+ match control_mode:
286
+ ControlModes.HUMAN:
287
+ agent.control_mode = agent.ControlModes.HUMAN
288
+ ControlModes.TRAINING:
289
+ agent.control_mode = agent.ControlModes.TRAINING
290
+ ControlModes.ONNX_INFERENCE:
291
+ agent.control_mode = agent.ControlModes.ONNX_INFERENCE
292
+
293
+
294
+ func _get_agents():
295
+ all_agents = get_tree().get_nodes_in_group("AGENT")
296
+ for agent in all_agents:
297
+ _set_agent_mode(agent)
298
+
299
+ if agent.control_mode == agent.ControlModes.TRAINING:
300
+ agents_training.append(agent)
301
+ elif agent.control_mode == agent.ControlModes.ONNX_INFERENCE:
302
+ agents_inference.append(agent)
303
+ elif agent.control_mode == agent.ControlModes.HUMAN:
304
+ agents_heuristic.append(agent)
305
+ elif agent.control_mode == agent.ControlModes.RECORD_EXPERT_DEMOS:
306
+ assert(
307
+ not agent_demo_record,
308
+ "Currently only a single AIController can be used for recording expert demos."
309
+ )
310
+ agent_demo_record = agent
311
+
312
+
313
+ func _set_heuristic(heuristic, agents: Array):
314
+ for agent in agents:
315
+ agent.set_heuristic(heuristic)
316
+
317
+
318
+ func _handshake():
319
+ print("performing handshake")
320
+
321
+ var json_dict = _get_dict_json_message()
322
+ assert(json_dict["type"] == "handshake")
323
+ var major_version = json_dict["major_version"]
324
+ var minor_version = json_dict["minor_version"]
325
+ if major_version != MAJOR_VERSION:
326
+ print("WARNING: major verison mismatch ", major_version, " ", MAJOR_VERSION)
327
+ if minor_version != MINOR_VERSION:
328
+ print("WARNING: minor verison mismatch ", minor_version, " ", MINOR_VERSION)
329
+
330
+ print("handshake complete")
331
+
332
+
333
+ func _get_dict_json_message():
334
+ # returns a dictionary from of the most recent message
335
+ # this is not waiting
336
+ while stream.get_available_bytes() == 0:
337
+ stream.poll()
338
+ if stream.get_status() != 2:
339
+ print("server disconnected status, closing")
340
+ get_tree().quit()
341
+ return null
342
+
343
+ OS.delay_usec(10)
344
+
345
+ var message = stream.get_string()
346
+ var json_data = JSON.parse_string(message)
347
+
348
+ return json_data
349
+
350
+
351
+ func _send_dict_as_json_message(dict):
352
+ stream.put_string(JSON.stringify(dict, "", false))
353
+
354
+
355
+ func _send_env_info():
356
+ var json_dict = _get_dict_json_message()
357
+ assert(json_dict["type"] == "env_info")
358
+
359
+ var message = {
360
+ "type": "env_info",
361
+ "observation_space": _obs_space,
362
+ "action_space": _action_space,
363
+ "n_agents": len(agents_training)
364
+ }
365
+ _send_dict_as_json_message(message)
366
+
367
+
368
+ func connect_to_server():
369
+ print("Waiting for one second to allow server to start")
370
+ OS.delay_msec(1000)
371
+ print("trying to connect to server")
372
+ stream = StreamPeerTCP.new()
373
+
374
+ # "localhost" was not working on windows VM, had to use the IP
375
+ var ip = "127.0.0.1"
376
+ var port = _get_port()
377
+ var connect = stream.connect_to_host(ip, port)
378
+ stream.set_no_delay(true) # TODO check if this improves performance or not
379
+ stream.poll()
380
+ # Fetch the status until it is either connected (2) or failed to connect (3)
381
+ while stream.get_status() < 2:
382
+ stream.poll()
383
+ return stream.get_status() == 2
384
+
385
+
386
+ func _get_args():
387
+ print("getting command line arguments")
388
+ var arguments = {}
389
+ for argument in OS.get_cmdline_args():
390
+ print(argument)
391
+ if argument.find("=") > -1:
392
+ var key_value = argument.split("=")
393
+ arguments[key_value[0].lstrip("--")] = key_value[1]
394
+ else:
395
+ # Options without an argument will be present in the dictionary,
396
+ # with the value set to an empty string.
397
+ arguments[argument.lstrip("--")] = ""
398
+
399
+ return arguments
400
+
401
+
402
+ func _get_speedup():
403
+ print(args)
404
+ return args.get("speedup", str(speed_up)).to_float()
405
+
406
+
407
+ func _get_port():
408
+ return args.get("port", DEFAULT_PORT).to_int()
409
+
410
+
411
+ func _set_seed():
412
+ var _seed = args.get("env_seed", DEFAULT_SEED).to_int()
413
+ seed(_seed)
414
+
415
+
416
+ func _set_action_repeat():
417
+ action_repeat = args.get("action_repeat", str(action_repeat)).to_int()
418
+
419
+
420
+ func disconnect_from_server():
421
+ stream.disconnect_from_host()
422
+
423
+
424
+ func handle_message() -> bool:
425
+ # get json message: reset, step, close
426
+ var message = _get_dict_json_message()
427
+ if message["type"] == "close":
428
+ print("received close message, closing game")
429
+ get_tree().quit()
430
+ get_tree().set_pause(false)
431
+ return true
432
+
433
+ if message["type"] == "reset":
434
+ print("resetting all agents")
435
+ _reset_agents()
436
+ just_reset = true
437
+ get_tree().set_pause(false)
438
+ #print("resetting forcing draw")
439
+ # RenderingServer.force_draw()
440
+ # var obs = _get_obs_from_agents()
441
+ # print("obs ", obs)
442
+ # var reply = {
443
+ # "type": "reset",
444
+ # "obs": obs
445
+ # }
446
+ # _send_dict_as_json_message(reply)
447
+ return true
448
+
449
+ if message["type"] == "call":
450
+ var method = message["method"]
451
+ var returns = _call_method_on_agents(method)
452
+ var reply = {"type": "call", "returns": returns}
453
+ print("calling method from Python")
454
+ _send_dict_as_json_message(reply)
455
+ return handle_message()
456
+
457
+ if message["type"] == "action":
458
+ var action = message["action"]
459
+ _set_agent_actions(action, agents_training)
460
+ need_to_send_obs = true
461
+ get_tree().set_pause(false)
462
+ return true
463
+
464
+ print("message was not handled")
465
+ return false
466
+
467
+
468
+ func _call_method_on_agents(method):
469
+ var returns = []
470
+ for agent in all_agents:
471
+ returns.append(agent.call(method))
472
+
473
+ return returns
474
+
475
+
476
+ func _reset_agents_if_done(agents = all_agents):
477
+ for agent in agents:
478
+ if agent.get_done():
479
+ agent.set_done_false()
480
+
481
+
482
+ func _reset_agents(agents = all_agents):
483
+ for agent in agents:
484
+ agent.needs_reset = true
485
+ #agent.reset()
486
+
487
+
488
+ func _get_obs_from_agents(agents: Array = all_agents):
489
+ var obs = []
490
+ for agent in agents:
491
+ obs.append(agent.get_obs())
492
+ return obs
493
+
494
+
495
+ func _get_reward_from_agents(agents: Array = agents_training):
496
+ var rewards = []
497
+ for agent in agents:
498
+ rewards.append(agent.get_reward())
499
+ agent.zero_reward()
500
+ return rewards
501
+
502
+
503
+ func _get_done_from_agents(agents: Array = agents_training):
504
+ var dones = []
505
+ for agent in agents:
506
+ var done = agent.get_done()
507
+ if done:
508
+ agent.set_done_false()
509
+ dones.append(done)
510
+ return dones
511
+
512
+
513
+ func _set_agent_actions(actions, agents: Array = all_agents):
514
+ for i in range(len(actions)):
515
+ agents[i].set_action(actions[i])
516
+
517
+
518
+ func clamp_array(arr: Array, min: float, max: float):
519
+ var output: Array = []
520
+ for a in arr:
521
+ output.append(clamp(a, min, max))
522
+ return output
523
+
524
+
525
+ ## Save recorded export demos on window exit (Close window instead of "Stop" button in Godot Editor)
526
+ func _notification(what):
527
+ if not agent_demo_record:
528
+ return
529
+
530
+ if what == NOTIFICATION_PREDELETE:
531
+ var json_string = JSON.stringify(demo_trajectories, "", false)
532
+ var file = FileAccess.open(agent_demo_record.expert_demo_save_path, FileAccess.WRITE)
533
+
534
+ if not file:
535
+ var error: Error = FileAccess.get_open_error()
536
+ assert(not error, "There was an error opening the file: %d" % error)
537
+
538
+ file.store_line(json_string)
539
+ var error = file.get_error()
540
+ assert(not error, "There was an error after trying to write to the file: %d" % error)
assets/bar_green.png ADDED

Git LFS Details

  • SHA256: 586cb8b83a7523a4fa87d3c9b42d2286d45b7e8815a9d0f88f7f2223878eaf7b
  • Pointer size: 128 Bytes
  • Size of remote file: 292 Bytes
assets/bar_red.png ADDED

Git LFS Details

  • SHA256: 1ce60bf8c34ebd6f789d442c7102d55537dc83d5155f3a2d6976ec5a2525ff9a
  • Pointer size: 128 Bytes
  • Size of remote file: 360 Bytes
assets/bar_yellow.png ADDED

Git LFS Details

  • SHA256: dfe17845287f879b1e7bc0feadaabab77f4e65bae21eb52dec58e81f8665d0e4
  • Pointer size: 128 Bytes
  • Size of remote file: 360 Bytes
assets/boat_large.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29c3e0cc6e37b33d252e21d5aa7506cdf6b736fd617bfa03ae06f71234aa9f01
3
+ size 9210
assets/chest.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fb50255571a664695fe07a0f87b94a09577d81d12dbdcad4fd7c5fb60f6a54d4
3
+ size 35460
assets/chest.gltf ADDED
@@ -0,0 +1,367 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "accessors": [
3
+ {
4
+ "bufferView": 0,
5
+ "componentType": 5126,
6
+ "count": 138,
7
+ "type": "VEC3",
8
+ "max": [
9
+ 0.35749998688697815,
10
+ 0.5189443826675415,
11
+ 0.31499999761581421
12
+ ],
13
+ "min": [
14
+ -0.35749998688697815,
15
+ -2.3023550782357022E-18,
16
+ -0.3182252049446106
17
+ ]
18
+ },
19
+ {
20
+ "bufferView": 1,
21
+ "componentType": 5126,
22
+ "count": 138,
23
+ "type": "VEC3",
24
+ "max": [
25
+ 1.0,
26
+ 1.0,
27
+ 1.0
28
+ ],
29
+ "min": [
30
+ -1.0,
31
+ -1.0,
32
+ -1.0
33
+ ]
34
+ },
35
+ {
36
+ "bufferView": 2,
37
+ "componentType": 5126,
38
+ "count": 138,
39
+ "type": "VEC4",
40
+ "max": [
41
+ 1.0,
42
+ 0.0,
43
+ 1.0,
44
+ 1.0
45
+ ],
46
+ "min": [
47
+ -1.0,
48
+ 0.0,
49
+ -1.0,
50
+ 1.0
51
+ ]
52
+ },
53
+ {
54
+ "bufferView": 3,
55
+ "componentType": 5126,
56
+ "count": 138,
57
+ "type": "VEC2",
58
+ "max": [
59
+ 28.149606704711914,
60
+ 25.803150177001953
61
+ ],
62
+ "min": [
63
+ -28.149606704711914,
64
+ -39.861763000488281
65
+ ]
66
+ },
67
+ {
68
+ "bufferView": 4,
69
+ "componentType": 5121,
70
+ "count": 228,
71
+ "type": "SCALAR",
72
+ "max": [
73
+ 117.0
74
+ ],
75
+ "min": [
76
+ 0.0
77
+ ]
78
+ },
79
+ {
80
+ "bufferView": 5,
81
+ "componentType": 5121,
82
+ "count": 48,
83
+ "type": "SCALAR",
84
+ "max": [
85
+ 137.0
86
+ ],
87
+ "min": [
88
+ 22.0
89
+ ]
90
+ },
91
+ {
92
+ "bufferView": 6,
93
+ "componentType": 5126,
94
+ "count": 550,
95
+ "type": "VEC3",
96
+ "max": [
97
+ 0.38249999284744263,
98
+ 0.34314814209938049,
99
+ 0.077209904789924622
100
+ ],
101
+ "min": [
102
+ -0.38249999284744263,
103
+ 0.0,
104
+ -0.60640990734100342
105
+ ]
106
+ },
107
+ {
108
+ "bufferView": 7,
109
+ "componentType": 5126,
110
+ "count": 550,
111
+ "type": "VEC3",
112
+ "max": [
113
+ 1.0,
114
+ 1.0,
115
+ 0.99144488573074341
116
+ ],
117
+ "min": [
118
+ -1.0,
119
+ -1.0,
120
+ -0.99144488573074341
121
+ ]
122
+ },
123
+ {
124
+ "bufferView": 8,
125
+ "componentType": 5126,
126
+ "count": 550,
127
+ "type": "VEC4",
128
+ "max": [
129
+ 1.0,
130
+ 0.0,
131
+ 1.0,
132
+ 1.0
133
+ ],
134
+ "min": [
135
+ -1.0,
136
+ 0.0,
137
+ -1.0,
138
+ 1.0
139
+ ]
140
+ },
141
+ {
142
+ "bufferView": 9,
143
+ "componentType": 5126,
144
+ "count": 550,
145
+ "type": "VEC2",
146
+ "max": [
147
+ 47.748813629150391,
148
+ 42.669292449951172
149
+ ],
150
+ "min": [
151
+ -47.748813629150391,
152
+ -46.444786071777344
153
+ ]
154
+ },
155
+ {
156
+ "bufferView": 10,
157
+ "componentType": 5123,
158
+ "count": 624,
159
+ "type": "SCALAR",
160
+ "max": [
161
+ 341.0
162
+ ],
163
+ "min": [
164
+ 0.0
165
+ ]
166
+ },
167
+ {
168
+ "bufferView": 11,
169
+ "componentType": 5123,
170
+ "count": 456,
171
+ "type": "SCALAR",
172
+ "max": [
173
+ 549.0
174
+ ],
175
+ "min": [
176
+ 33.0
177
+ ]
178
+ }
179
+ ],
180
+ "asset": {
181
+ "version": "2.0"
182
+ },
183
+ "buffers": [
184
+ {
185
+ "uri": "chest.bin",
186
+ "byteLength": 35460
187
+ }
188
+ ],
189
+ "bufferViews": [
190
+ {
191
+ "buffer": 0,
192
+ "byteLength": 1656
193
+ },
194
+ {
195
+ "buffer": 0,
196
+ "byteOffset": 1656,
197
+ "byteLength": 1656
198
+ },
199
+ {
200
+ "buffer": 0,
201
+ "byteOffset": 3312,
202
+ "byteLength": 2208
203
+ },
204
+ {
205
+ "buffer": 0,
206
+ "byteOffset": 5520,
207
+ "byteLength": 1104
208
+ },
209
+ {
210
+ "buffer": 0,
211
+ "byteOffset": 6624,
212
+ "byteLength": 228
213
+ },
214
+ {
215
+ "buffer": 0,
216
+ "byteOffset": 6852,
217
+ "byteLength": 48
218
+ },
219
+ {
220
+ "buffer": 0,
221
+ "byteOffset": 6900,
222
+ "byteLength": 6600
223
+ },
224
+ {
225
+ "buffer": 0,
226
+ "byteOffset": 13500,
227
+ "byteLength": 6600
228
+ },
229
+ {
230
+ "buffer": 0,
231
+ "byteOffset": 20100,
232
+ "byteLength": 8800
233
+ },
234
+ {
235
+ "buffer": 0,
236
+ "byteOffset": 28900,
237
+ "byteLength": 4400
238
+ },
239
+ {
240
+ "buffer": 0,
241
+ "byteOffset": 33300,
242
+ "byteLength": 1248
243
+ },
244
+ {
245
+ "buffer": 0,
246
+ "byteOffset": 34548,
247
+ "byteLength": 912
248
+ }
249
+ ],
250
+ "materials": [
251
+ {
252
+ "pbrMetallicRoughness": {
253
+ "baseColorFactor": [
254
+ 0.7294118,
255
+ 0.4627451,
256
+ 0.2784314,
257
+ 1.0
258
+ ],
259
+ "metallicFactor": 0.25,
260
+ "roughnessFactor": 0.84999999403953552
261
+ },
262
+ "name": "wood"
263
+ },
264
+ {
265
+ "pbrMetallicRoughness": {
266
+ "baseColorFactor": [
267
+ 0.58431375,
268
+ 0.6862745,
269
+ 0.75686276,
270
+ 1.0
271
+ ],
272
+ "metallicFactor": 0.25,
273
+ "roughnessFactor": 0.84999999403953552
274
+ },
275
+ "name": "stone"
276
+ }
277
+ ],
278
+ "meshes": [
279
+ {
280
+ "primitives": [
281
+ {
282
+ "attributes": {
283
+ "POSITION": 0,
284
+ "NORMAL": 1,
285
+ "TANGENT": 2,
286
+ "TEXCOORD_0": 3
287
+ },
288
+ "indices": 4,
289
+ "material": 0
290
+ },
291
+ {
292
+ "attributes": {
293
+ "POSITION": 0,
294
+ "NORMAL": 1,
295
+ "TANGENT": 2,
296
+ "TEXCOORD_0": 3
297
+ },
298
+ "indices": 5,
299
+ "material": 1
300
+ }
301
+ ],
302
+ "name": "chest"
303
+ },
304
+ {
305
+ "primitives": [
306
+ {
307
+ "attributes": {
308
+ "POSITION": 6,
309
+ "NORMAL": 7,
310
+ "TANGENT": 8,
311
+ "TEXCOORD_0": 9
312
+ },
313
+ "indices": 10,
314
+ "material": 0
315
+ },
316
+ {
317
+ "attributes": {
318
+ "POSITION": 6,
319
+ "NORMAL": 7,
320
+ "TANGENT": 8,
321
+ "TEXCOORD_0": 9
322
+ },
323
+ "indices": 11,
324
+ "material": 1
325
+ }
326
+ ],
327
+ "name": "lid"
328
+ }
329
+ ],
330
+ "nodes": [
331
+ {
332
+ "children": [
333
+ 1
334
+ ],
335
+ "mesh": 0,
336
+ "scale": [
337
+ 0.64,
338
+ 0.64,
339
+ 0.64
340
+ ],
341
+ "translation": [
342
+ -2.62998271,
343
+ 7.21911464E-16,
344
+ -6.29410934
345
+ ],
346
+ "name": "chest"
347
+ },
348
+ {
349
+ "mesh": 1,
350
+ "translation": [
351
+ 0.0,
352
+ 0.515,
353
+ 0.2646
354
+ ],
355
+ "name": "lid"
356
+ }
357
+ ],
358
+ "scene": 0,
359
+ "scenes": [
360
+ {
361
+ "nodes": [
362
+ 0
363
+ ],
364
+ "name": "chest"
365
+ }
366
+ ]
367
+ }
assets/island.blend ADDED
Binary file (891 kB). View file
 
assets/islands.blend ADDED
Binary file (957 kB). View file
 
assets/mine.blend ADDED
Binary file (967 kB). View file
 
assets/ship_light.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ca919f496cfd21ee0ce744484486cc64424adfbf5df90c96945506f6bc78da0
3
+ size 506820
assets/ship_light.gltf ADDED
@@ -0,0 +1,1725 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "accessors": [
3
+ {
4
+ "bufferView": 0,
5
+ "componentType": 5126,
6
+ "count": 4820,
7
+ "type": "VEC3",
8
+ "max": [
9
+ 1.4250975847244263,
10
+ 6.545872688293457,
11
+ 3.2479171752929688
12
+ ],
13
+ "min": [
14
+ -1.4250975847244263,
15
+ -1.8047785270195561E-16,
16
+ -4.8496489524841309
17
+ ]
18
+ },
19
+ {
20
+ "bufferView": 1,
21
+ "componentType": 5126,
22
+ "count": 4820,
23
+ "type": "VEC3",
24
+ "max": [
25
+ 1.0,
26
+ 1.0,
27
+ 1.0
28
+ ],
29
+ "min": [
30
+ -1.0,
31
+ -1.0,
32
+ -1.0
33
+ ]
34
+ },
35
+ {
36
+ "bufferView": 2,
37
+ "componentType": 5126,
38
+ "count": 4820,
39
+ "type": "VEC4",
40
+ "max": [
41
+ 1.0,
42
+ 0.052688907831907272,
43
+ 1.0,
44
+ 1.0
45
+ ],
46
+ "min": [
47
+ -1.0,
48
+ -0.052688851952552795,
49
+ -1.0,
50
+ -1.0
51
+ ]
52
+ },
53
+ {
54
+ "bufferView": 3,
55
+ "componentType": 5126,
56
+ "count": 4820,
57
+ "type": "VEC2",
58
+ "max": [
59
+ 375.39724731445313,
60
+ 326.95660400390625
61
+ ],
62
+ "min": [
63
+ -375.39724731445313,
64
+ -519.82818603515625
65
+ ]
66
+ },
67
+ {
68
+ "bufferView": 4,
69
+ "componentType": 5123,
70
+ "count": 5949,
71
+ "type": "SCALAR",
72
+ "max": [
73
+ 2954.0
74
+ ],
75
+ "min": [
76
+ 0.0
77
+ ]
78
+ },
79
+ {
80
+ "bufferView": 5,
81
+ "componentType": 5123,
82
+ "count": 1254,
83
+ "type": "SCALAR",
84
+ "max": [
85
+ 3628.0
86
+ ],
87
+ "min": [
88
+ 2955.0
89
+ ]
90
+ },
91
+ {
92
+ "bufferView": 6,
93
+ "componentType": 5123,
94
+ "count": 864,
95
+ "type": "SCALAR",
96
+ "max": [
97
+ 3916.0
98
+ ],
99
+ "min": [
100
+ 367.0
101
+ ]
102
+ },
103
+ {
104
+ "bufferView": 7,
105
+ "componentType": 5123,
106
+ "count": 156,
107
+ "type": "SCALAR",
108
+ "max": [
109
+ 3976.0
110
+ ],
111
+ "min": [
112
+ 3917.0
113
+ ]
114
+ },
115
+ {
116
+ "bufferView": 8,
117
+ "componentType": 5123,
118
+ "count": 1296,
119
+ "type": "SCALAR",
120
+ "max": [
121
+ 4816.0
122
+ ],
123
+ "min": [
124
+ 3977.0
125
+ ]
126
+ },
127
+ {
128
+ "bufferView": 9,
129
+ "componentType": 5123,
130
+ "count": 3,
131
+ "type": "SCALAR",
132
+ "max": [
133
+ 4819.0
134
+ ],
135
+ "min": [
136
+ 4817.0
137
+ ]
138
+ },
139
+ {
140
+ "bufferView": 10,
141
+ "componentType": 5126,
142
+ "count": 216,
143
+ "type": "VEC3",
144
+ "max": [
145
+ 0.21723608672618866,
146
+ 0.38839432597160339,
147
+ 0.11717912554740906
148
+ ],
149
+ "min": [
150
+ -0.21723608672618866,
151
+ 0.0,
152
+ -0.11717912554740906
153
+ ]
154
+ },
155
+ {
156
+ "bufferView": 11,
157
+ "componentType": 5126,
158
+ "count": 216,
159
+ "type": "VEC3",
160
+ "max": [
161
+ 1.0,
162
+ 1.0,
163
+ 1.0
164
+ ],
165
+ "min": [
166
+ -1.0,
167
+ -1.0,
168
+ -1.0
169
+ ]
170
+ },
171
+ {
172
+ "bufferView": 12,
173
+ "componentType": 5126,
174
+ "count": 216,
175
+ "type": "VEC4",
176
+ "max": [
177
+ 1.0,
178
+ 0.0,
179
+ 1.0,
180
+ 1.0
181
+ ],
182
+ "min": [
183
+ -1.0,
184
+ 0.0,
185
+ -1.0,
186
+ 1.0
187
+ ]
188
+ },
189
+ {
190
+ "bufferView": 13,
191
+ "componentType": 5126,
192
+ "count": 216,
193
+ "type": "VEC2",
194
+ "max": [
195
+ 17.105203628540039,
196
+ 10.226702690124512
197
+ ],
198
+ "min": [
199
+ -17.105203628540039,
200
+ -29.582231521606445
201
+ ]
202
+ },
203
+ {
204
+ "bufferView": 14,
205
+ "componentType": 5121,
206
+ "count": 144,
207
+ "type": "SCALAR",
208
+ "max": [
209
+ 95.0
210
+ ],
211
+ "min": [
212
+ 0.0
213
+ ]
214
+ },
215
+ {
216
+ "bufferView": 15,
217
+ "componentType": 5121,
218
+ "count": 288,
219
+ "type": "SCALAR",
220
+ "max": [
221
+ 215.0
222
+ ],
223
+ "min": [
224
+ 96.0
225
+ ]
226
+ },
227
+ {
228
+ "bufferView": 16,
229
+ "componentType": 5126,
230
+ "count": 1344,
231
+ "type": "VEC3",
232
+ "max": [
233
+ 0.13824114203453064,
234
+ 0.13824114203453064,
235
+ 0.21974015235900879
236
+ ],
237
+ "min": [
238
+ -0.13824114203453064,
239
+ -0.13824114203453064,
240
+ -0.35504752397537231
241
+ ]
242
+ },
243
+ {
244
+ "bufferView": 17,
245
+ "componentType": 5126,
246
+ "count": 1344,
247
+ "type": "VEC3",
248
+ "max": [
249
+ 1.0,
250
+ 1.0,
251
+ 1.0
252
+ ],
253
+ "min": [
254
+ -1.0,
255
+ -1.0,
256
+ -1.0
257
+ ]
258
+ },
259
+ {
260
+ "bufferView": 18,
261
+ "componentType": 5126,
262
+ "count": 1344,
263
+ "type": "VEC4",
264
+ "max": [
265
+ 1.0,
266
+ 0.1078750342130661,
267
+ 1.0,
268
+ 1.0
269
+ ],
270
+ "min": [
271
+ -1.0,
272
+ -0.1078750416636467,
273
+ -1.0,
274
+ -1.0
275
+ ]
276
+ },
277
+ {
278
+ "bufferView": 19,
279
+ "componentType": 5126,
280
+ "count": 1344,
281
+ "type": "VEC2",
282
+ "max": [
283
+ 27.956497192382813,
284
+ 15.244912147521973
285
+ ],
286
+ "min": [
287
+ -27.956497192382813,
288
+ -13.244912147521973
289
+ ]
290
+ },
291
+ {
292
+ "bufferView": 20,
293
+ "componentType": 5123,
294
+ "count": 2568,
295
+ "type": "SCALAR",
296
+ "max": [
297
+ 1343.0
298
+ ],
299
+ "min": [
300
+ 0.0
301
+ ]
302
+ },
303
+ {
304
+ "bufferView": 21,
305
+ "componentType": 5126,
306
+ "count": 252,
307
+ "type": "VEC3",
308
+ "max": [
309
+ 0.21723608672618866,
310
+ 0.55602347850799561,
311
+ 0.3171791136264801
312
+ ],
313
+ "min": [
314
+ -0.21723608672618866,
315
+ 0.10180000215768814,
316
+ -0.26217913627624512
317
+ ]
318
+ },
319
+ {
320
+ "bufferView": 22,
321
+ "componentType": 5126,
322
+ "count": 252,
323
+ "type": "VEC3",
324
+ "max": [
325
+ 1.0,
326
+ 1.0,
327
+ 1.0
328
+ ],
329
+ "min": [
330
+ -1.0,
331
+ -1.0,
332
+ -1.0
333
+ ]
334
+ },
335
+ {
336
+ "bufferView": 23,
337
+ "componentType": 5126,
338
+ "count": 252,
339
+ "type": "VEC4",
340
+ "max": [
341
+ 1.0,
342
+ 0.0,
343
+ 1.0,
344
+ 1.0
345
+ ],
346
+ "min": [
347
+ -1.0,
348
+ 0.0,
349
+ -1.0,
350
+ 1.0
351
+ ]
352
+ },
353
+ {
354
+ "bufferView": 24,
355
+ "componentType": 5126,
356
+ "count": 252,
357
+ "type": "VEC2",
358
+ "max": [
359
+ 24.974733352661133,
360
+ 21.644025802612305
361
+ ],
362
+ "min": [
363
+ -24.974733352661133,
364
+ -42.781375885009766
365
+ ]
366
+ },
367
+ {
368
+ "bufferView": 25,
369
+ "componentType": 5121,
370
+ "count": 144,
371
+ "type": "SCALAR",
372
+ "max": [
373
+ 95.0
374
+ ],
375
+ "min": [
376
+ 0.0
377
+ ]
378
+ },
379
+ {
380
+ "bufferView": 26,
381
+ "componentType": 5121,
382
+ "count": 360,
383
+ "type": "SCALAR",
384
+ "max": [
385
+ 251.0
386
+ ],
387
+ "min": [
388
+ 96.0
389
+ ]
390
+ },
391
+ {
392
+ "bufferView": 27,
393
+ "componentType": 5126,
394
+ "count": 288,
395
+ "type": "VEC3",
396
+ "max": [
397
+ 1.1550582572925159E-14,
398
+ 0.12839999794960022,
399
+ 0.12839999794960022
400
+ ],
401
+ "min": [
402
+ -0.09920000284910202,
403
+ -0.12839999794960022,
404
+ -0.12839999794960022
405
+ ]
406
+ },
407
+ {
408
+ "bufferView": 28,
409
+ "componentType": 5126,
410
+ "count": 288,
411
+ "type": "VEC3",
412
+ "max": [
413
+ 1.0,
414
+ 1.0,
415
+ 1.0
416
+ ],
417
+ "min": [
418
+ -1.0,
419
+ -1.0,
420
+ -1.0
421
+ ]
422
+ },
423
+ {
424
+ "bufferView": 29,
425
+ "componentType": 5126,
426
+ "count": 288,
427
+ "type": "VEC4",
428
+ "max": [
429
+ 1.0,
430
+ 0.0,
431
+ 1.0,
432
+ 1.0
433
+ ],
434
+ "min": [
435
+ -1.0,
436
+ 0.0,
437
+ -1.0,
438
+ 1.0
439
+ ]
440
+ },
441
+ {
442
+ "bufferView": 30,
443
+ "componentType": 5126,
444
+ "count": 288,
445
+ "type": "VEC2",
446
+ "max": [
447
+ 10.110236167907715,
448
+ 11.110236167907715
449
+ ],
450
+ "min": [
451
+ -10.110236167907715,
452
+ -9.1102361679077148
453
+ ]
454
+ },
455
+ {
456
+ "bufferView": 31,
457
+ "componentType": 5121,
458
+ "count": 144,
459
+ "type": "SCALAR",
460
+ "max": [
461
+ 95.0
462
+ ],
463
+ "min": [
464
+ 0.0
465
+ ]
466
+ },
467
+ {
468
+ "bufferView": 32,
469
+ "componentType": 5123,
470
+ "count": 420,
471
+ "type": "SCALAR",
472
+ "max": [
473
+ 287.0
474
+ ],
475
+ "min": [
476
+ 96.0
477
+ ]
478
+ },
479
+ {
480
+ "bufferView": 33,
481
+ "componentType": 5126,
482
+ "count": 304,
483
+ "type": "VEC3",
484
+ "max": [
485
+ 0.0,
486
+ 2.9721910953521729,
487
+ 0.66404557228088379
488
+ ],
489
+ "min": [
490
+ -2.7077615261077881,
491
+ 0.0,
492
+ 0.020585935562849045
493
+ ]
494
+ },
495
+ {
496
+ "bufferView": 34,
497
+ "componentType": 5126,
498
+ "count": 304,
499
+ "type": "VEC3",
500
+ "max": [
501
+ 1.0,
502
+ 1.0,
503
+ 1.0
504
+ ],
505
+ "min": [
506
+ -1.0,
507
+ -1.0,
508
+ -1.0
509
+ ]
510
+ },
511
+ {
512
+ "bufferView": 35,
513
+ "componentType": 5126,
514
+ "count": 304,
515
+ "type": "VEC4",
516
+ "max": [
517
+ 1.0,
518
+ 0.0,
519
+ 1.0,
520
+ 1.0
521
+ ],
522
+ "min": [
523
+ -1.0,
524
+ 0.0,
525
+ -1.0,
526
+ -1.0
527
+ ]
528
+ },
529
+ {
530
+ "bufferView": 36,
531
+ "componentType": 5126,
532
+ "count": 304,
533
+ "type": "VEC2",
534
+ "max": [
535
+ 217.34634399414063,
536
+ 204.70127868652344
537
+ ],
538
+ "min": [
539
+ -218.55166625976563,
540
+ -252.76840209960938
541
+ ]
542
+ },
543
+ {
544
+ "bufferView": 37,
545
+ "componentType": 5121,
546
+ "count": 360,
547
+ "type": "SCALAR",
548
+ "max": [
549
+ 235.0
550
+ ],
551
+ "min": [
552
+ 0.0
553
+ ]
554
+ },
555
+ {
556
+ "bufferView": 38,
557
+ "componentType": 5123,
558
+ "count": 120,
559
+ "type": "SCALAR",
560
+ "max": [
561
+ 303.0
562
+ ],
563
+ "min": [
564
+ 236.0
565
+ ]
566
+ },
567
+ {
568
+ "bufferView": 39,
569
+ "componentType": 5126,
570
+ "count": 304,
571
+ "type": "VEC3",
572
+ "max": [
573
+ 0.0,
574
+ 2.397191047668457,
575
+ 0.60904556512832642
576
+ ],
577
+ "min": [
578
+ -2.7076854705810547,
579
+ 0.0,
580
+ 0.0
581
+ ]
582
+ },
583
+ {
584
+ "bufferView": 40,
585
+ "componentType": 5126,
586
+ "count": 304,
587
+ "type": "VEC3",
588
+ "max": [
589
+ 1.0,
590
+ 1.0,
591
+ 1.0
592
+ ],
593
+ "min": [
594
+ -1.0,
595
+ -1.0,
596
+ -1.0
597
+ ]
598
+ },
599
+ {
600
+ "bufferView": 41,
601
+ "componentType": 5126,
602
+ "count": 304,
603
+ "type": "VEC4",
604
+ "max": [
605
+ 1.0,
606
+ 0.0,
607
+ 1.0,
608
+ 1.0
609
+ ],
610
+ "min": [
611
+ -1.0,
612
+ 0.0,
613
+ -1.0,
614
+ -1.0
615
+ ]
616
+ },
617
+ {
618
+ "bufferView": 42,
619
+ "componentType": 5126,
620
+ "count": 304,
621
+ "type": "VEC2",
622
+ "max": [
623
+ 217.38507080078125,
624
+ 206.31678771972656
625
+ ],
626
+ "min": [
627
+ -217.440185546875,
628
+ -236.98951721191406
629
+ ]
630
+ },
631
+ {
632
+ "bufferView": 43,
633
+ "componentType": 5121,
634
+ "count": 360,
635
+ "type": "SCALAR",
636
+ "max": [
637
+ 235.0
638
+ ],
639
+ "min": [
640
+ 0.0
641
+ ]
642
+ },
643
+ {
644
+ "bufferView": 44,
645
+ "componentType": 5123,
646
+ "count": 120,
647
+ "type": "SCALAR",
648
+ "max": [
649
+ 303.0
650
+ ],
651
+ "min": [
652
+ 236.0
653
+ ]
654
+ },
655
+ {
656
+ "bufferView": 45,
657
+ "componentType": 5126,
658
+ "count": 304,
659
+ "type": "VEC3",
660
+ "max": [
661
+ 0.0,
662
+ 2.9721910953521729,
663
+ 0.60904556512832642
664
+ ],
665
+ "min": [
666
+ -2.7076854705810547,
667
+ 0.0,
668
+ 0.0
669
+ ]
670
+ },
671
+ {
672
+ "bufferView": 46,
673
+ "componentType": 5126,
674
+ "count": 304,
675
+ "type": "VEC3",
676
+ "max": [
677
+ 1.0,
678
+ 1.0,
679
+ 1.0
680
+ ],
681
+ "min": [
682
+ -1.0,
683
+ -1.0,
684
+ -1.0
685
+ ]
686
+ },
687
+ {
688
+ "bufferView": 47,
689
+ "componentType": 5126,
690
+ "count": 304,
691
+ "type": "VEC4",
692
+ "max": [
693
+ 1.0,
694
+ 0.0,
695
+ 1.0,
696
+ 1.0
697
+ ],
698
+ "min": [
699
+ -1.0,
700
+ 0.0,
701
+ -1.0,
702
+ -1.0
703
+ ]
704
+ },
705
+ {
706
+ "bufferView": 48,
707
+ "componentType": 5126,
708
+ "count": 304,
709
+ "type": "VEC2",
710
+ "max": [
711
+ 217.38507080078125,
712
+ 202.53703308105469
713
+ ],
714
+ "min": [
715
+ -217.440185546875,
716
+ -252.85726928710938
717
+ ]
718
+ },
719
+ {
720
+ "bufferView": 49,
721
+ "componentType": 5121,
722
+ "count": 360,
723
+ "type": "SCALAR",
724
+ "max": [
725
+ 235.0
726
+ ],
727
+ "min": [
728
+ 0.0
729
+ ]
730
+ },
731
+ {
732
+ "bufferView": 50,
733
+ "componentType": 5123,
734
+ "count": 120,
735
+ "type": "SCALAR",
736
+ "max": [
737
+ 303.0
738
+ ],
739
+ "min": [
740
+ 236.0
741
+ ]
742
+ },
743
+ {
744
+ "bufferView": 51,
745
+ "componentType": 5126,
746
+ "count": 1984,
747
+ "type": "VEC3",
748
+ "max": [
749
+ 0.32805001735687256,
750
+ 0.32805001735687256,
751
+ 0.212290957570076
752
+ ],
753
+ "min": [
754
+ -0.32805001735687256,
755
+ -0.32805001735687256,
756
+ 0.0
757
+ ]
758
+ },
759
+ {
760
+ "bufferView": 52,
761
+ "componentType": 5126,
762
+ "count": 1984,
763
+ "type": "VEC3",
764
+ "max": [
765
+ 1.0,
766
+ 1.0,
767
+ 1.0
768
+ ],
769
+ "min": [
770
+ -1.0,
771
+ -1.0,
772
+ -1.0
773
+ ]
774
+ },
775
+ {
776
+ "bufferView": 53,
777
+ "componentType": 5126,
778
+ "count": 1984,
779
+ "type": "VEC4",
780
+ "max": [
781
+ 1.0,
782
+ 0.075392015278339386,
783
+ 1.0,
784
+ 1.0
785
+ ],
786
+ "min": [
787
+ -1.0,
788
+ -0.075392015278339386,
789
+ -1.0,
790
+ -1.0
791
+ ]
792
+ },
793
+ {
794
+ "bufferView": 54,
795
+ "componentType": 5126,
796
+ "count": 1984,
797
+ "type": "VEC2",
798
+ "max": [
799
+ 25.830709457397461,
800
+ 26.830709457397461
801
+ ],
802
+ "min": [
803
+ -25.830709457397461,
804
+ -24.830709457397461
805
+ ]
806
+ },
807
+ {
808
+ "bufferView": 55,
809
+ "componentType": 5123,
810
+ "count": 3540,
811
+ "type": "SCALAR",
812
+ "max": [
813
+ 1823.0
814
+ ],
815
+ "min": [
816
+ 0.0
817
+ ]
818
+ },
819
+ {
820
+ "bufferView": 56,
821
+ "componentType": 5123,
822
+ "count": 336,
823
+ "type": "SCALAR",
824
+ "max": [
825
+ 1983.0
826
+ ],
827
+ "min": [
828
+ 1824.0
829
+ ]
830
+ }
831
+ ],
832
+ "asset": {
833
+ "version": "2.0"
834
+ },
835
+ "buffers": [
836
+ {
837
+ "uri": "ship_light.bin",
838
+ "byteLength": 506820
839
+ }
840
+ ],
841
+ "bufferViews": [
842
+ {
843
+ "buffer": 0,
844
+ "byteLength": 57840
845
+ },
846
+ {
847
+ "buffer": 0,
848
+ "byteOffset": 57840,
849
+ "byteLength": 57840
850
+ },
851
+ {
852
+ "buffer": 0,
853
+ "byteOffset": 115680,
854
+ "byteLength": 77120
855
+ },
856
+ {
857
+ "buffer": 0,
858
+ "byteOffset": 192800,
859
+ "byteLength": 38560
860
+ },
861
+ {
862
+ "buffer": 0,
863
+ "byteOffset": 231360,
864
+ "byteLength": 11898
865
+ },
866
+ {
867
+ "buffer": 0,
868
+ "byteOffset": 243258,
869
+ "byteLength": 2508
870
+ },
871
+ {
872
+ "buffer": 0,
873
+ "byteOffset": 245766,
874
+ "byteLength": 1728
875
+ },
876
+ {
877
+ "buffer": 0,
878
+ "byteOffset": 247494,
879
+ "byteLength": 312
880
+ },
881
+ {
882
+ "buffer": 0,
883
+ "byteOffset": 247806,
884
+ "byteLength": 2592
885
+ },
886
+ {
887
+ "buffer": 0,
888
+ "byteOffset": 250398,
889
+ "byteLength": 6
890
+ },
891
+ {
892
+ "buffer": 0,
893
+ "byteOffset": 250404,
894
+ "byteLength": 2592
895
+ },
896
+ {
897
+ "buffer": 0,
898
+ "byteOffset": 252996,
899
+ "byteLength": 2592
900
+ },
901
+ {
902
+ "buffer": 0,
903
+ "byteOffset": 255588,
904
+ "byteLength": 3456
905
+ },
906
+ {
907
+ "buffer": 0,
908
+ "byteOffset": 259044,
909
+ "byteLength": 1728
910
+ },
911
+ {
912
+ "buffer": 0,
913
+ "byteOffset": 260772,
914
+ "byteLength": 144
915
+ },
916
+ {
917
+ "buffer": 0,
918
+ "byteOffset": 260916,
919
+ "byteLength": 288
920
+ },
921
+ {
922
+ "buffer": 0,
923
+ "byteOffset": 261204,
924
+ "byteLength": 16128
925
+ },
926
+ {
927
+ "buffer": 0,
928
+ "byteOffset": 277332,
929
+ "byteLength": 16128
930
+ },
931
+ {
932
+ "buffer": 0,
933
+ "byteOffset": 293460,
934
+ "byteLength": 21504
935
+ },
936
+ {
937
+ "buffer": 0,
938
+ "byteOffset": 314964,
939
+ "byteLength": 10752
940
+ },
941
+ {
942
+ "buffer": 0,
943
+ "byteOffset": 325716,
944
+ "byteLength": 5136
945
+ },
946
+ {
947
+ "buffer": 0,
948
+ "byteOffset": 330852,
949
+ "byteLength": 3024
950
+ },
951
+ {
952
+ "buffer": 0,
953
+ "byteOffset": 333876,
954
+ "byteLength": 3024
955
+ },
956
+ {
957
+ "buffer": 0,
958
+ "byteOffset": 336900,
959
+ "byteLength": 4032
960
+ },
961
+ {
962
+ "buffer": 0,
963
+ "byteOffset": 340932,
964
+ "byteLength": 2016
965
+ },
966
+ {
967
+ "buffer": 0,
968
+ "byteOffset": 342948,
969
+ "byteLength": 144
970
+ },
971
+ {
972
+ "buffer": 0,
973
+ "byteOffset": 343092,
974
+ "byteLength": 360
975
+ },
976
+ {
977
+ "buffer": 0,
978
+ "byteOffset": 343452,
979
+ "byteLength": 3456
980
+ },
981
+ {
982
+ "buffer": 0,
983
+ "byteOffset": 346908,
984
+ "byteLength": 3456
985
+ },
986
+ {
987
+ "buffer": 0,
988
+ "byteOffset": 350364,
989
+ "byteLength": 4608
990
+ },
991
+ {
992
+ "buffer": 0,
993
+ "byteOffset": 354972,
994
+ "byteLength": 2304
995
+ },
996
+ {
997
+ "buffer": 0,
998
+ "byteOffset": 357276,
999
+ "byteLength": 144
1000
+ },
1001
+ {
1002
+ "buffer": 0,
1003
+ "byteOffset": 357420,
1004
+ "byteLength": 840
1005
+ },
1006
+ {
1007
+ "buffer": 0,
1008
+ "byteOffset": 358260,
1009
+ "byteLength": 3648
1010
+ },
1011
+ {
1012
+ "buffer": 0,
1013
+ "byteOffset": 361908,
1014
+ "byteLength": 3648
1015
+ },
1016
+ {
1017
+ "buffer": 0,
1018
+ "byteOffset": 365556,
1019
+ "byteLength": 4864
1020
+ },
1021
+ {
1022
+ "buffer": 0,
1023
+ "byteOffset": 370420,
1024
+ "byteLength": 2432
1025
+ },
1026
+ {
1027
+ "buffer": 0,
1028
+ "byteOffset": 372852,
1029
+ "byteLength": 360
1030
+ },
1031
+ {
1032
+ "buffer": 0,
1033
+ "byteOffset": 373212,
1034
+ "byteLength": 240
1035
+ },
1036
+ {
1037
+ "buffer": 0,
1038
+ "byteOffset": 373452,
1039
+ "byteLength": 3648
1040
+ },
1041
+ {
1042
+ "buffer": 0,
1043
+ "byteOffset": 377100,
1044
+ "byteLength": 3648
1045
+ },
1046
+ {
1047
+ "buffer": 0,
1048
+ "byteOffset": 380748,
1049
+ "byteLength": 4864
1050
+ },
1051
+ {
1052
+ "buffer": 0,
1053
+ "byteOffset": 385612,
1054
+ "byteLength": 2432
1055
+ },
1056
+ {
1057
+ "buffer": 0,
1058
+ "byteOffset": 388044,
1059
+ "byteLength": 360
1060
+ },
1061
+ {
1062
+ "buffer": 0,
1063
+ "byteOffset": 388404,
1064
+ "byteLength": 240
1065
+ },
1066
+ {
1067
+ "buffer": 0,
1068
+ "byteOffset": 388644,
1069
+ "byteLength": 3648
1070
+ },
1071
+ {
1072
+ "buffer": 0,
1073
+ "byteOffset": 392292,
1074
+ "byteLength": 3648
1075
+ },
1076
+ {
1077
+ "buffer": 0,
1078
+ "byteOffset": 395940,
1079
+ "byteLength": 4864
1080
+ },
1081
+ {
1082
+ "buffer": 0,
1083
+ "byteOffset": 400804,
1084
+ "byteLength": 2432
1085
+ },
1086
+ {
1087
+ "buffer": 0,
1088
+ "byteOffset": 403236,
1089
+ "byteLength": 360
1090
+ },
1091
+ {
1092
+ "buffer": 0,
1093
+ "byteOffset": 403596,
1094
+ "byteLength": 240
1095
+ },
1096
+ {
1097
+ "buffer": 0,
1098
+ "byteOffset": 403836,
1099
+ "byteLength": 23808
1100
+ },
1101
+ {
1102
+ "buffer": 0,
1103
+ "byteOffset": 427644,
1104
+ "byteLength": 23808
1105
+ },
1106
+ {
1107
+ "buffer": 0,
1108
+ "byteOffset": 451452,
1109
+ "byteLength": 31744
1110
+ },
1111
+ {
1112
+ "buffer": 0,
1113
+ "byteOffset": 483196,
1114
+ "byteLength": 15872
1115
+ },
1116
+ {
1117
+ "buffer": 0,
1118
+ "byteOffset": 499068,
1119
+ "byteLength": 7080
1120
+ },
1121
+ {
1122
+ "buffer": 0,
1123
+ "byteOffset": 506148,
1124
+ "byteLength": 672
1125
+ }
1126
+ ],
1127
+ "materials": [
1128
+ {
1129
+ "pbrMetallicRoughness": {
1130
+ "baseColorFactor": [
1131
+ 0.7294118,
1132
+ 0.4627451,
1133
+ 0.2784314,
1134
+ 1.0
1135
+ ],
1136
+ "metallicFactor": 0.25,
1137
+ "roughnessFactor": 0.84999999403953552
1138
+ },
1139
+ "name": "wood"
1140
+ },
1141
+ {
1142
+ "pbrMetallicRoughness": {
1143
+ "baseColorFactor": [
1144
+ 0.521568656,
1145
+ 0.329411775,
1146
+ 0.196078435,
1147
+ 1.0
1148
+ ],
1149
+ "metallicFactor": 0.25,
1150
+ "roughnessFactor": 0.84999999403953552
1151
+ },
1152
+ "name": "woodDark"
1153
+ },
1154
+ {
1155
+ "pbrMetallicRoughness": {
1156
+ "baseColorFactor": [
1157
+ 0.3764706,
1158
+ 0.3764706,
1159
+ 0.3764706,
1160
+ 1.0
1161
+ ],
1162
+ "metallicFactor": 0.25,
1163
+ "roughnessFactor": 0.84999999403953552
1164
+ },
1165
+ "name": "iron"
1166
+ },
1167
+ {
1168
+ "pbrMetallicRoughness": {
1169
+ "baseColorFactor": [
1170
+ 0.6627451,
1171
+ 0.7372549,
1172
+ 0.768627465,
1173
+ 1.0
1174
+ ],
1175
+ "metallicFactor": 0.25,
1176
+ "roughnessFactor": 0.84999999403953552
1177
+ },
1178
+ "name": "window"
1179
+ },
1180
+ {
1181
+ "pbrMetallicRoughness": {
1182
+ "baseColorFactor": [
1183
+ 0.819607854,
1184
+ 0.7529412,
1185
+ 0.670588255,
1186
+ 1.0
1187
+ ],
1188
+ "metallicFactor": 0.25,
1189
+ "roughnessFactor": 0.84999999403953552
1190
+ },
1191
+ "name": "textile"
1192
+ },
1193
+ {
1194
+ "pbrMetallicRoughness": {
1195
+ "metallicFactor": 0.0,
1196
+ "roughnessFactor": 0.5
1197
+ },
1198
+ "name": "_defaultMat"
1199
+ }
1200
+ ],
1201
+ "meshes": [
1202
+ {
1203
+ "primitives": [
1204
+ {
1205
+ "attributes": {
1206
+ "POSITION": 0,
1207
+ "NORMAL": 1,
1208
+ "TANGENT": 2,
1209
+ "TEXCOORD_0": 3
1210
+ },
1211
+ "indices": 4,
1212
+ "material": 0
1213
+ },
1214
+ {
1215
+ "attributes": {
1216
+ "POSITION": 0,
1217
+ "NORMAL": 1,
1218
+ "TANGENT": 2,
1219
+ "TEXCOORD_0": 3
1220
+ },
1221
+ "indices": 5,
1222
+ "material": 1
1223
+ },
1224
+ {
1225
+ "attributes": {
1226
+ "POSITION": 0,
1227
+ "NORMAL": 1,
1228
+ "TANGENT": 2,
1229
+ "TEXCOORD_0": 3
1230
+ },
1231
+ "indices": 6,
1232
+ "material": 2
1233
+ },
1234
+ {
1235
+ "attributes": {
1236
+ "POSITION": 0,
1237
+ "NORMAL": 1,
1238
+ "TANGENT": 2,
1239
+ "TEXCOORD_0": 3
1240
+ },
1241
+ "indices": 7,
1242
+ "material": 3
1243
+ },
1244
+ {
1245
+ "attributes": {
1246
+ "POSITION": 0,
1247
+ "NORMAL": 1,
1248
+ "TANGENT": 2,
1249
+ "TEXCOORD_0": 3
1250
+ },
1251
+ "indices": 8,
1252
+ "material": 4
1253
+ },
1254
+ {
1255
+ "attributes": {
1256
+ "POSITION": 0,
1257
+ "NORMAL": 1,
1258
+ "TANGENT": 2,
1259
+ "TEXCOORD_0": 3
1260
+ },
1261
+ "indices": 9,
1262
+ "material": 5
1263
+ }
1264
+ ],
1265
+ "name": "ship_light_8angles"
1266
+ },
1267
+ {
1268
+ "primitives": [
1269
+ {
1270
+ "attributes": {
1271
+ "POSITION": 10,
1272
+ "NORMAL": 11,
1273
+ "TANGENT": 12,
1274
+ "TEXCOORD_0": 13
1275
+ },
1276
+ "indices": 14,
1277
+ "material": 2
1278
+ },
1279
+ {
1280
+ "attributes": {
1281
+ "POSITION": 10,
1282
+ "NORMAL": 11,
1283
+ "TANGENT": 12,
1284
+ "TEXCOORD_0": 13
1285
+ },
1286
+ "indices": 15,
1287
+ "material": 0
1288
+ }
1289
+ ],
1290
+ "name": "cannon_front 1"
1291
+ },
1292
+ {
1293
+ "primitives": [
1294
+ {
1295
+ "attributes": {
1296
+ "POSITION": 16,
1297
+ "NORMAL": 17,
1298
+ "TANGENT": 18,
1299
+ "TEXCOORD_0": 19
1300
+ },
1301
+ "indices": 20,
1302
+ "material": 2
1303
+ }
1304
+ ],
1305
+ "name": "cannon_front 1"
1306
+ },
1307
+ {
1308
+ "primitives": [
1309
+ {
1310
+ "attributes": {
1311
+ "POSITION": 21,
1312
+ "NORMAL": 22,
1313
+ "TANGENT": 23,
1314
+ "TEXCOORD_0": 24
1315
+ },
1316
+ "indices": 25,
1317
+ "material": 2
1318
+ },
1319
+ {
1320
+ "attributes": {
1321
+ "POSITION": 21,
1322
+ "NORMAL": 22,
1323
+ "TANGENT": 23,
1324
+ "TEXCOORD_0": 24
1325
+ },
1326
+ "indices": 26,
1327
+ "material": 0
1328
+ }
1329
+ ],
1330
+ "name": "cannon_left 1"
1331
+ },
1332
+ {
1333
+ "primitives": [
1334
+ {
1335
+ "attributes": {
1336
+ "POSITION": 27,
1337
+ "NORMAL": 28,
1338
+ "TANGENT": 29,
1339
+ "TEXCOORD_0": 30
1340
+ },
1341
+ "indices": 31,
1342
+ "material": 2
1343
+ },
1344
+ {
1345
+ "attributes": {
1346
+ "POSITION": 27,
1347
+ "NORMAL": 28,
1348
+ "TANGENT": 29,
1349
+ "TEXCOORD_0": 30
1350
+ },
1351
+ "indices": 32,
1352
+ "material": 0
1353
+ }
1354
+ ],
1355
+ "name": "cannon_left 1"
1356
+ },
1357
+ {
1358
+ "primitives": [
1359
+ {
1360
+ "attributes": {
1361
+ "POSITION": 33,
1362
+ "NORMAL": 34,
1363
+ "TANGENT": 35,
1364
+ "TEXCOORD_0": 36
1365
+ },
1366
+ "indices": 37,
1367
+ "material": 4
1368
+ },
1369
+ {
1370
+ "attributes": {
1371
+ "POSITION": 33,
1372
+ "NORMAL": 34,
1373
+ "TANGENT": 35,
1374
+ "TEXCOORD_0": 36
1375
+ },
1376
+ "indices": 38,
1377
+ "material": 0
1378
+ }
1379
+ ],
1380
+ "name": "sail_back 1"
1381
+ },
1382
+ {
1383
+ "primitives": [
1384
+ {
1385
+ "attributes": {
1386
+ "POSITION": 39,
1387
+ "NORMAL": 40,
1388
+ "TANGENT": 41,
1389
+ "TEXCOORD_0": 42
1390
+ },
1391
+ "indices": 43,
1392
+ "material": 4
1393
+ },
1394
+ {
1395
+ "attributes": {
1396
+ "POSITION": 39,
1397
+ "NORMAL": 40,
1398
+ "TANGENT": 41,
1399
+ "TEXCOORD_0": 42
1400
+ },
1401
+ "indices": 44,
1402
+ "material": 0
1403
+ }
1404
+ ],
1405
+ "name": "sail_front 1"
1406
+ },
1407
+ {
1408
+ "primitives": [
1409
+ {
1410
+ "attributes": {
1411
+ "POSITION": 45,
1412
+ "NORMAL": 46,
1413
+ "TANGENT": 47,
1414
+ "TEXCOORD_0": 48
1415
+ },
1416
+ "indices": 49,
1417
+ "material": 4
1418
+ },
1419
+ {
1420
+ "attributes": {
1421
+ "POSITION": 45,
1422
+ "NORMAL": 46,
1423
+ "TANGENT": 47,
1424
+ "TEXCOORD_0": 48
1425
+ },
1426
+ "indices": 50,
1427
+ "material": 0
1428
+ }
1429
+ ],
1430
+ "name": "sail_middle 1"
1431
+ },
1432
+ {
1433
+ "primitives": [
1434
+ {
1435
+ "attributes": {
1436
+ "POSITION": 51,
1437
+ "NORMAL": 52,
1438
+ "TANGENT": 53,
1439
+ "TEXCOORD_0": 54
1440
+ },
1441
+ "indices": 55,
1442
+ "material": 0
1443
+ },
1444
+ {
1445
+ "attributes": {
1446
+ "POSITION": 51,
1447
+ "NORMAL": 52,
1448
+ "TANGENT": 53,
1449
+ "TEXCOORD_0": 54
1450
+ },
1451
+ "indices": 56,
1452
+ "material": 2
1453
+ }
1454
+ ],
1455
+ "name": "steering 1"
1456
+ }
1457
+ ],
1458
+ "nodes": [
1459
+ {
1460
+ "children": [
1461
+ 1,
1462
+ 3,
1463
+ 9,
1464
+ 15,
1465
+ 16,
1466
+ 17,
1467
+ 18
1468
+ ],
1469
+ "mesh": 0,
1470
+ "translation": [
1471
+ -0.715097547,
1472
+ 2.14768643E-14,
1473
+ 0.0144567313
1474
+ ],
1475
+ "name": "ship_light_8angles"
1476
+ },
1477
+ {
1478
+ "children": [
1479
+ 2
1480
+ ],
1481
+ "mesh": 1,
1482
+ "translation": [
1483
+ 8.662937E-15,
1484
+ 1.43707323,
1485
+ -3.61592531
1486
+ ],
1487
+ "name": "cannon_front 1"
1488
+ },
1489
+ {
1490
+ "mesh": 2,
1491
+ "rotation": [
1492
+ 0.0366437137,
1493
+ 0.0,
1494
+ 0.0,
1495
+ 0.9993284
1496
+ ],
1497
+ "scale": [
1498
+ 1.0,
1499
+ 0.99999994,
1500
+ 0.99999994
1501
+ ],
1502
+ "translation": [
1503
+ -1.44382282E-15,
1504
+ 0.277633131,
1505
+ -0.0673608
1506
+ ],
1507
+ "name": "cannon_front 1"
1508
+ },
1509
+ {
1510
+ "children": [
1511
+ 4,
1512
+ 5,
1513
+ 6,
1514
+ 7,
1515
+ 8
1516
+ ],
1517
+ "mesh": 3,
1518
+ "rotation": [
1519
+ 0.0,
1520
+ 0.7071068,
1521
+ 0.0,
1522
+ 0.7071068
1523
+ ],
1524
+ "translation": [
1525
+ -0.760400534,
1526
+ 1.27739835,
1527
+ -1.681064
1528
+ ],
1529
+ "name": "cannon_left 1"
1530
+ },
1531
+ {
1532
+ "mesh": 2,
1533
+ "rotation": [
1534
+ 0.04623474,
1535
+ -1.00726774E-28,
1536
+ 1.65558261E-30,
1537
+ 0.998930633
1538
+ ],
1539
+ "translation": [
1540
+ -2.88764564E-15,
1541
+ 0.443967849,
1542
+ -0.06746836
1543
+ ],
1544
+ "name": "cannon_left 1"
1545
+ },
1546
+ {
1547
+ "mesh": 4,
1548
+ "translation": [
1549
+ -0.217236087,
1550
+ 0.1284,
1551
+ 0.262179136
1552
+ ],
1553
+ "name": "cannon_left 1"
1554
+ },
1555
+ {
1556
+ "mesh": 4,
1557
+ "rotation": [
1558
+ 0.0,
1559
+ -1.0,
1560
+ 0.0,
1561
+ 7.45057749E-09
1562
+ ],
1563
+ "translation": [
1564
+ 0.217236087,
1565
+ 0.1284,
1566
+ 0.262179136
1567
+ ],
1568
+ "name": "cannon_left 1"
1569
+ },
1570
+ {
1571
+ "mesh": 4,
1572
+ "translation": [
1573
+ -0.217236087,
1574
+ 0.1284,
1575
+ -0.197179124
1576
+ ],
1577
+ "name": "cannon_left 1"
1578
+ },
1579
+ {
1580
+ "mesh": 4,
1581
+ "rotation": [
1582
+ 0.0,
1583
+ -1.0,
1584
+ 0.0,
1585
+ 7.45057749E-09
1586
+ ],
1587
+ "translation": [
1588
+ 0.217236087,
1589
+ 0.1284,
1590
+ -0.197179124
1591
+ ],
1592
+ "name": "cannon_left 1"
1593
+ },
1594
+ {
1595
+ "children": [
1596
+ 10,
1597
+ 11,
1598
+ 12,
1599
+ 13,
1600
+ 14
1601
+ ],
1602
+ "mesh": 3,
1603
+ "rotation": [
1604
+ 0.0,
1605
+ -0.7071068,
1606
+ 0.0,
1607
+ 0.7071068
1608
+ ],
1609
+ "translation": [
1610
+ 0.760400534,
1611
+ 1.27739835,
1612
+ -1.681064
1613
+ ],
1614
+ "name": "cannon_right 1"
1615
+ },
1616
+ {
1617
+ "mesh": 2,
1618
+ "rotation": [
1619
+ 0.04623474,
1620
+ -1.00726774E-28,
1621
+ 1.65558261E-30,
1622
+ 0.998930633
1623
+ ],
1624
+ "translation": [
1625
+ -2.88764564E-15,
1626
+ 0.443967849,
1627
+ -0.06746836
1628
+ ],
1629
+ "name": "cannon_right 1"
1630
+ },
1631
+ {
1632
+ "mesh": 4,
1633
+ "translation": [
1634
+ -0.217236087,
1635
+ 0.1284,
1636
+ 0.262179136
1637
+ ],
1638
+ "name": "cannon_right 1"
1639
+ },
1640
+ {
1641
+ "mesh": 4,
1642
+ "rotation": [
1643
+ 0.0,
1644
+ -1.0,
1645
+ 0.0,
1646
+ 7.45057749E-09
1647
+ ],
1648
+ "translation": [
1649
+ 0.217236087,
1650
+ 0.1284,
1651
+ 0.262179136
1652
+ ],
1653
+ "name": "cannon_right 1"
1654
+ },
1655
+ {
1656
+ "mesh": 4,
1657
+ "translation": [
1658
+ -0.217236087,
1659
+ 0.1284,
1660
+ -0.197179124
1661
+ ],
1662
+ "name": "cannon_right 1"
1663
+ },
1664
+ {
1665
+ "mesh": 4,
1666
+ "rotation": [
1667
+ 0.0,
1668
+ -1.0,
1669
+ 0.0,
1670
+ 7.45057749E-09
1671
+ ],
1672
+ "translation": [
1673
+ 0.217236087,
1674
+ 0.1284,
1675
+ -0.197179124
1676
+ ],
1677
+ "name": "cannon_right 1"
1678
+ },
1679
+ {
1680
+ "mesh": 5,
1681
+ "translation": [
1682
+ 1.35384274,
1683
+ 3.03424788,
1684
+ 1.8643955
1685
+ ],
1686
+ "name": "sail_back 1"
1687
+ },
1688
+ {
1689
+ "mesh": 6,
1690
+ "translation": [
1691
+ 1.35384274,
1692
+ 1.604248,
1693
+ -3.20060444
1694
+ ],
1695
+ "name": "sail_front 1"
1696
+ },
1697
+ {
1698
+ "mesh": 7,
1699
+ "translation": [
1700
+ 1.35384274,
1701
+ 1.604248,
1702
+ -1.54560447
1703
+ ],
1704
+ "name": "sail_middle 1"
1705
+ },
1706
+ {
1707
+ "mesh": 8,
1708
+ "translation": [
1709
+ -2.88764564E-15,
1710
+ 2.775925,
1711
+ 1.05056143
1712
+ ],
1713
+ "name": "steering 1"
1714
+ }
1715
+ ],
1716
+ "scene": 0,
1717
+ "scenes": [
1718
+ {
1719
+ "nodes": [
1720
+ 0
1721
+ ],
1722
+ "name": "ship_light"
1723
+ }
1724
+ ]
1725
+ }
assets/sunflowers_puresky_2k.hdr ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:430861cb722951c1eeff3b3c5762e7e73a610fcffc4186b5d828c5e7557fe1b4
3
+ size 5658712
chest.gd ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends MeshInstance3D
2
+ @onready var area_3d = $Area3D
3
+
4
+ func _on_area_3d_body_entered(body):
5
+ if body is Player:
6
+ body.chest_collected()
7
+ call_deferred("respawn")
8
+
9
+ func respawn():
10
+ hide()
11
+ area_3d.set_monitoring(false)
12
+ area_3d.set_monitorable(false)
13
+ await get_tree().create_timer(10.0).timeout
14
+ area_3d.set_monitoring(true)
15
+ area_3d.set_monitorable(true)
16
+ show()
17
+
18
+ func get_mesh_aabb() -> AABB:
19
+ var aabb = mesh.get_aabb()
20
+ aabb.position *= scale.x
21
+ aabb.size *= scale.x
22
+ return aabb
chest.tscn ADDED
The diff for this file is too large to render. See raw diff
 
deque.gd ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class_name Deque
2
+
3
+ var _data : Array = []
4
+ var _current_index : int = 0
5
+ var max_size : int = -1:
6
+ set(value):
7
+ # Sets the maximum size and ensures the deque conforms to this size.
8
+ max_size = value
9
+ _current_index = 0
10
+ while _data.size() > max_size:
11
+ _data.pop_back()
12
+
13
+ # Appends an element to the end of the deque.
14
+ func push_back(value) -> void:
15
+ if max_size > -1 and _data.size() >= max_size:
16
+ _data.pop_front()
17
+ _data.append(value)
18
+
19
+ # Adds an element to the beginning of the deque.
20
+ func push_front(value) -> void:
21
+ if max_size > -1 and _data.size() >= max_size:
22
+ _data.pop_back()
23
+ _data.insert(0, value)
24
+
25
+ # Removes and returns the last element of the deque.
26
+ func pop_back() -> Variant:
27
+ if _data.size() == 0:
28
+ return null
29
+ return _data.pop_back()
30
+
31
+ # Removes and returns the first element of the deque.
32
+ func pop_front() -> Variant:
33
+ if _data.size() == 0:
34
+ return null
35
+ return _data.pop_front()
36
+
37
+ # Returns the last element of the deque without removing it.
38
+ func back() -> Variant:
39
+ if _data.size() == 0:
40
+ return null
41
+ return _data[_data.size() - 1]
42
+
43
+ # Returns the first element of the deque without removing it.
44
+ func front() -> Variant:
45
+ if _data.size() == 0:
46
+ return null
47
+ return _data[0]
48
+
49
+ # Returns the number of elements in the deque.
50
+ func size() -> int:
51
+ return _data.size()
52
+
53
+ # Checks if the deque is empty.
54
+ func is_empty() -> bool:
55
+ return _data.size() == 0
56
+
57
+ # Clears the deque.
58
+ func clear() -> void:
59
+ _data.clear()
60
+
61
+ # Start of iteration. Resets the current index.
62
+ func _iter_init(arg) -> bool:
63
+ _current_index = 0
64
+ return _current_index < _data.size()
65
+
66
+ # Moves to the next item in the sequence.
67
+ func _iter_next(arg) -> bool:
68
+ _current_index += 1
69
+ return _current_index < _data.size()
70
+
71
+ # Returns the current item in the sequence.
72
+ func _iter_get(arg) -> Variant:
73
+ if _current_index < _data.size():
74
+ return _data[_current_index]
75
+ return null
76
+
77
+ # Reset current index when setting max size
78
+ func set_max_size(value: int) -> void:
79
+ max_size = value
80
+ _current_index = 0
81
+ while _data.size() > max_size:
82
+ _data.pop_back()
83
+
84
+
game.gd ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node3D
2
+
3
+ @onready var islands = $Islands
4
+ @onready var mines = $Mines
5
+ @onready var chests = $Chests
6
+
7
+ @export var n_islands := 100
8
+ @export var n_chests := 100
9
+ @export var n_mines := 100
10
+
11
+ @export var world_size := Rect2(-50, -50, 100, 100)
12
+ @export var spawn_zone := Rect2(-5, -5, 10, 10)
13
+
14
+ var island_scenes = [preload("res://islands.tscn")]
15
+ var chest_scenes = [preload("res://chest.tscn")]
16
+ var mine_scenes = [preload("res://mine.tscn")]
17
+
18
+ var bbs : Array[Rect2]= []
19
+ # Called when the node enters the scene tree for the first time.
20
+ func _ready():
21
+ randomize()
22
+ spawn_world()
23
+ $Player.reset_signal.connect(spawn_world)
24
+
25
+
26
+ func spawn_world():
27
+ bbs.clear()
28
+ bbs.append(spawn_zone)
29
+ spawn_islands()
30
+ spawn_chests()
31
+ spawn_mines()
32
+
33
+
34
+ func bb_overlaps(rect: Rect2, border:float)->bool:
35
+ var expanded_rect = rect.grow(border)
36
+ for bb in bbs:
37
+ if bb.intersects(expanded_rect):
38
+ return true
39
+
40
+ return false
41
+
42
+
43
+ func find_valid_position(aabb, border:float) -> Vector2:
44
+ var x_pos = randf_range(world_size.position.x, world_size.end.x)
45
+ var z_pos = randf_range(world_size.position.y, world_size.end.y)
46
+ var aabb2d = Rect2(Vector2(aabb.position.x+x_pos, aabb.position.z+z_pos), Vector2(aabb.size.x, aabb.size.z))
47
+
48
+ while bb_overlaps(aabb2d, border): # change to n_tries
49
+ x_pos = randf_range(world_size.position.x, world_size.end.x)
50
+ z_pos = randf_range(world_size.position.y, world_size.end.y)
51
+ aabb2d = Rect2(Vector2(aabb.position.x+x_pos, aabb.position.z+z_pos), Vector2(aabb.size.x, aabb.size.z))
52
+
53
+ return Vector2(aabb.position.x+x_pos, aabb.position.z+z_pos)
54
+
55
+ func spawn_scene(scene, border:float):
56
+ var instance = scene.instantiate()
57
+ var aabb = instance.get_mesh_aabb()
58
+ var spawn_position = find_valid_position(aabb,border)
59
+ var aabb2d = Rect2(spawn_position, Vector2(aabb.size.x, aabb.size.z))
60
+
61
+ bbs.append(aabb2d)
62
+ instance.position = Vector3(spawn_position.x, 0.0, spawn_position.y)
63
+
64
+ instance.rotate_y(randf_range(0,2*PI))
65
+
66
+ return instance
67
+
68
+
69
+ func clear_and_spawn(parent, scenes: Array, count, border: float=5.0):
70
+ for child in parent.get_children():
71
+ child.queue_free()
72
+
73
+ for i in count:
74
+ var scene = scenes.pick_random()
75
+ var instance = spawn_scene(scene, border)
76
+ parent.add_child(instance)
77
+ instance.set_owner(get_tree().edited_scene_root)
78
+
79
+ func spawn_islands():
80
+ clear_and_spawn(islands, island_scenes, n_islands, 10.0)
81
+
82
+ func spawn_chests():
83
+ clear_and_spawn(chests, chest_scenes, n_chests)
84
+
85
+ func spawn_mines():
86
+ clear_and_spawn(mines, mine_scenes, n_mines)
87
+
88
+