Skip to content

Commit dc202c8

Browse files
committed
Draft Flow Fields
1 parent f641a51 commit dc202c8

15 files changed

+2340
-71
lines changed

LICENSE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/==================================================================
2+
3+
Fluid HTN AI
4+
5+
==================================================================/
6+
17
MIT License
28

39
Copyright (c) 2019 Pål Trefall
@@ -19,3 +25,29 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1925
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2026
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2127
SOFTWARE.
28+
29+
/==================================================================
30+
31+
Fast Marching Method
32+
33+
==================================================================/
34+
35+
Copyright 2017 Tommy Hinks
36+
37+
Permission is hereby granted, free of charge, to any person obtaining a
38+
copy of this software and associated documentation files (the "Software"),
39+
to deal in the Software without restriction, including without limitation
40+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
41+
and/or sell copies of the Software, and to permit persons to whom the
42+
Software is furnished to do so, subject to the following conditions:
43+
44+
The above copyright notice and this permission notice shall be included in
45+
all copies or substantial portions of the Software.
46+
47+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
48+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
49+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
50+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
51+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
52+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
53+
DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Interaction with smart objects only if they are in range or available.
414414

415415
The execution will check conditions of a task when it starts, run execution conditions every tick, run the task operator every tick and apply "executing" effects upon task success.
416416

417-
# Liscening
417+
# Licensing
418418

419419
The FLuid HTN Code comes from :
420420

SConstruct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})
4040

4141
env.Append(CPPPATH=["src/"])
4242
# TODO Add Nested Folders as a new Glob
43-
sources = [Glob("src/*.cpp"), Glob("src/Example/*.cpp"), Glob("src/Agents/**/*.cpp"), Glob("src/FluidHTN/**/*.cpp")]
43+
sources = [Glob("src/*.cpp"), Glob("src/Flow/*.cpp"), Glob("src/Agents/**/*.cpp"), Glob("src/FluidHTN/**/*.cpp")]
4444

4545
if env["target"] in ["editor", "template_debug"]:
4646
try:

demo/Test.tscn

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
[gd_scene load_steps=2 format=3 uid="uid://cs6xj3i70yh0f"]
22

3-
[ext_resource type="Script" uid="uid://ba0phkf16vg6l" path="res://hello_world_gdextention_function.gd" id="1_myinc"]
3+
[sub_resource type="GDScript" id="GDScript_rvu7i"]
4+
script/source = "extends HelloWorld
5+
6+
func _ready():
7+
hello_message();
8+
"
49

510
[node name="Test" type="Node3D"]
611

712
[node name="HelloWorld" type="HelloWorld" parent="."]
8-
script = ExtResource("1_myinc")
13+
_import_path = NodePath("")
14+
unique_name_in_owner = false
15+
process_mode = 0
16+
process_priority = 0
17+
process_physics_priority = 0
18+
process_thread_group = 0
19+
physics_interpolation_mode = 0
20+
auto_translate_mode = 0
21+
editor_description = ""
22+
script = SubResource("GDScript_rvu7i")

demo/hello_world_gdextention_function.gd

Lines changed: 0 additions & 4 deletions
This file was deleted.

demo/hello_world_gdextention_function.gd.uid

Lines changed: 0 additions & 1 deletion
This file was deleted.

demo/scenes/Level/flow_field.tscn

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
[gd_scene load_steps=15 format=3 uid="uid://bu2bnqb7jbvdv"]
2+
3+
[ext_resource type="Script" uid="uid://co51i1xik6ibh" path="res://scripts/Levels/LevelScript.gd" id="1_twb67"]
4+
[ext_resource type="Script" uid="uid://basfttxylkrle" path="res://scripts/SteeringBehaviors/FlowField.gd" id="2_70utq"]
5+
[ext_resource type="Script" uid="uid://bydjrl4wumi6y" path="res://scripts/Spawners/Spawning.gd" id="2_o5lst"]
6+
[ext_resource type="PackedScene" uid="uid://d37wo3mvlcmia" path="res://spawner/AgentSpawner.tscn" id="3_70utq"]
7+
[ext_resource type="Texture2D" uid="uid://l0ib77o0wncj" path="res://assets/textures/Prototype/Dark/texture_08.png" id="4_sf0pg"]
8+
9+
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_qstfa"]
10+
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
11+
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
12+
13+
[sub_resource type="Sky" id="Sky_irks6"]
14+
sky_material = SubResource("ProceduralSkyMaterial_qstfa")
15+
16+
[sub_resource type="Environment" id="Environment_heqyn"]
17+
background_mode = 2
18+
sky = SubResource("Sky_irks6")
19+
tonemap_mode = 2
20+
glow_enabled = true
21+
22+
[sub_resource type="QuadMesh" id="QuadMesh_706t6"]
23+
size = Vector2(200, 200)
24+
orientation = 1
25+
26+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5wmcq"]
27+
albedo_texture = ExtResource("4_sf0pg")
28+
29+
[sub_resource type="BoxShape3D" id="BoxShape3D_6wtjj"]
30+
size = Vector3(200, 1, 200)
31+
32+
[sub_resource type="BoxMesh" id="BoxMesh_31y8d"]
33+
size = Vector3(6, 6, 6)
34+
35+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_brjmj"]
36+
albedo_color = Color(0.345098, 0.517647, 0.65098, 1)
37+
38+
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_ukqwy"]
39+
data = PackedVector3Array(-3, 3, 3, 3, 3, 3, -3, -3, 3, 3, 3, 3, 3, -3, 3, -3, -3, 3, 3, 3, -3, -3, 3, -3, 3, -3, -3, -3, 3, -3, -3, -3, -3, 3, -3, -3, 3, 3, 3, 3, 3, -3, 3, -3, 3, 3, 3, -3, 3, -3, -3, 3, -3, 3, -3, 3, -3, -3, 3, 3, -3, -3, -3, -3, 3, 3, -3, -3, 3, -3, -3, -3, 3, 3, 3, -3, 3, 3, 3, 3, -3, -3, 3, 3, -3, 3, -3, 3, 3, -3, -3, -3, 3, 3, -3, 3, -3, -3, -3, 3, -3, 3, 3, -3, -3, -3, -3, -3)
40+
41+
[node name="TestLevel" type="Node3D"]
42+
script = ExtResource("1_twb67")
43+
44+
[node name="FlowField" type="FlowField" parent="."]
45+
script = ExtResource("2_70utq")
46+
47+
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
48+
transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0)
49+
shadow_enabled = true
50+
51+
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
52+
environment = SubResource("Environment_heqyn")
53+
54+
[node name="Spawning" type="Node3D" parent="."]
55+
script = ExtResource("2_o5lst")
56+
57+
[node name="PlayerSpawner" type="MultiplayerSpawner" parent="Spawning"]
58+
_spawnable_scenes = PackedStringArray("uid://6s5rk0xolkxi")
59+
spawn_path = NodePath("../SpawnedPlayers")
60+
61+
[node name="PlayerSpawnPoints" type="Node3D" parent="Spawning"]
62+
63+
[node name="Marker3D" type="Marker3D" parent="Spawning/PlayerSpawnPoints"]
64+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.220346, -6.96668)
65+
66+
[node name="Marker3D2" type="Marker3D" parent="Spawning/PlayerSpawnPoints"]
67+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.220346, 7.19992)
68+
69+
[node name="Marker3D3" type="Marker3D" parent="Spawning/PlayerSpawnPoints"]
70+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.22954, 0.220346, -0.233832)
71+
72+
[node name="Marker3D4" type="Marker3D" parent="Spawning/PlayerSpawnPoints"]
73+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.39961, 0.220346, -0.233832)
74+
75+
[node name="SpawnedPlayers" type="Node3D" parent="Spawning"]
76+
77+
[node name="AgentSpawner" type="MultiplayerSpawner" parent="Spawning"]
78+
_spawnable_scenes = PackedStringArray("uid://d1l8jr35roq11")
79+
spawn_path = NodePath("../SpawnedAgents")
80+
81+
[node name="AgentSpawners" type="Node3D" parent="Spawning"]
82+
83+
[node name="AgentSpawner" parent="Spawning/AgentSpawners" instance=ExtResource("3_70utq")]
84+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 15.2856, 81.8714)
85+
86+
[node name="SpawnedAgents" type="Node3D" parent="Spawning"]
87+
88+
[node name="Ground" type="StaticBody3D" parent="." groups=["Ground"]]
89+
90+
[node name="MeshInstance3D" type="MeshInstance3D" parent="Ground"]
91+
mesh = SubResource("QuadMesh_706t6")
92+
surface_material_override/0 = SubResource("StandardMaterial3D_5wmcq")
93+
94+
[node name="CollisionShape3D" type="CollisionShape3D" parent="Ground"]
95+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.49, 0)
96+
shape = SubResource("BoxShape3D_6wtjj")
97+
98+
[node name="Obstacles" type="Node3D" parent="."]
99+
100+
[node name="MeshInstance3D" type="MeshInstance3D" parent="Obstacles"]
101+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -48.3205, 2.93985, 0)
102+
mesh = SubResource("BoxMesh_31y8d")
103+
skeleton = NodePath("")
104+
surface_material_override/0 = SubResource("StandardMaterial3D_brjmj")
105+
106+
[node name="StaticBody3D" type="StaticBody3D" parent="Obstacles/MeshInstance3D"]
107+
108+
[node name="CollisionShape3D" type="CollisionShape3D" parent="Obstacles/MeshInstance3D/StaticBody3D"]
109+
shape = SubResource("ConcavePolygonShape3D_ukqwy")
110+
111+
[node name="MeshInstance3D2" type="MeshInstance3D" parent="Obstacles"]
112+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 38.5944, 2.93985, 0)
113+
mesh = SubResource("BoxMesh_31y8d")
114+
skeleton = NodePath("")
115+
surface_material_override/0 = SubResource("StandardMaterial3D_brjmj")
116+
117+
[node name="StaticBody3D" type="StaticBody3D" parent="Obstacles/MeshInstance3D2"]
118+
119+
[node name="CollisionShape3D" type="CollisionShape3D" parent="Obstacles/MeshInstance3D2/StaticBody3D"]
120+
shape = SubResource("ConcavePolygonShape3D_ukqwy")
121+
122+
[node name="MeshInstance3D3" type="MeshInstance3D" parent="Obstacles"]
123+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -21.78, 2.93985, -44.8711)
124+
mesh = SubResource("BoxMesh_31y8d")
125+
skeleton = NodePath("")
126+
surface_material_override/0 = SubResource("StandardMaterial3D_brjmj")
127+
128+
[node name="StaticBody3D" type="StaticBody3D" parent="Obstacles/MeshInstance3D3"]
129+
130+
[node name="CollisionShape3D" type="CollisionShape3D" parent="Obstacles/MeshInstance3D3/StaticBody3D"]
131+
shape = SubResource("ConcavePolygonShape3D_ukqwy")
132+
133+
[node name="MeshInstance3D4" type="MeshInstance3D" parent="Obstacles"]
134+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -21.78, 2.93985, 40.8336)
135+
mesh = SubResource("BoxMesh_31y8d")
136+
skeleton = NodePath("")
137+
surface_material_override/0 = SubResource("StandardMaterial3D_brjmj")
138+
139+
[node name="StaticBody3D" type="StaticBody3D" parent="Obstacles/MeshInstance3D4"]
140+
141+
[node name="CollisionShape3D" type="CollisionShape3D" parent="Obstacles/MeshInstance3D4/StaticBody3D"]
142+
shape = SubResource("ConcavePolygonShape3D_ukqwy")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
extends Node
2+
3+
var grid_origin: Vector3 = Vector3(-100.0, 0.0, -100.0); # Example for a 200×200 area centered at (0,0,0)
4+
var cell_size: float = 1.0;
5+
6+
var myFlowField: FlowField = FlowField.new();
7+
8+
func _ready():
9+
var all_occupied_cells := []
10+
11+
for child in $"../Obstacles".get_children():
12+
if child is MeshInstance3D:
13+
var mesh_instance: MeshInstance3D = child
14+
var local_aabb: AABB = mesh_instance.get_aabb()
15+
var global_aabb: AABB = mesh_instance.global_transform * mesh_instance.get_aabb()
16+
17+
# Shift the global AABB to grid-local coordinates by offsetting with grid_origin.
18+
var aabb_min: Vector3 = global_aabb.position - grid_origin
19+
var aabb_max: Vector3 = (global_aabb.position + global_aabb.size) - grid_origin
20+
21+
# Convert the X and Z coordinates to grid cell indices (using floor() for proper rounding).
22+
var min_cell_x: int = int(floor(aabb_min.x / cell_size))
23+
var min_cell_y: int = int(floor(aabb_min.z / cell_size)) # We use Z as our grid’s "y" index.
24+
var max_cell_x: int = int(floor(aabb_max.x / cell_size))
25+
var max_cell_y: int = int(floor(aabb_max.z / cell_size))
26+
27+
# Loop over the cells covered by this AABB and add them.
28+
for x in range(min_cell_x, max_cell_x + 1):
29+
for y in range(min_cell_y, max_cell_y + 1):
30+
all_occupied_cells.append(Vector2(x, y))
31+
32+
myFlowField.compute_flow(200, 200, 0, 0, all_occupied_cells);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://basfttxylkrle

src/Example/Hello_World.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)