Skip to content

Commit 9acb552

Browse files
authored
Update NavigationChunk demos (#1221)
Updates NavigationChunk demos for `NavigationMeshSourceGeometryData2D.get_bounds()` function and new NavigationAgent no post-processing option.
1 parent 1280ef6 commit 9acb552

File tree

4 files changed

+55
-70
lines changed

4 files changed

+55
-70
lines changed

2d/navigation_mesh_chunks/navmesh_chhunks_demo_2d.gd

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func _ready() -> void:
4545
static func create_region_chunks(chunks_root_node: Node, p_source_geometry: NavigationMeshSourceGeometryData2D, p_chunk_size: float, p_agent_radius: float) -> void:
4646
# We need to know how many chunks are required for the input geometry.
4747
# So first get an axis aligned bounding box that covers all vertices.
48-
var input_geometry_bounds: Rect2 = calculate_source_geometry_bounds(p_source_geometry)
48+
var input_geometry_bounds: Rect2 = p_source_geometry.get_bounds()
4949

5050
# Rasterize bounding box into chunk grid to know range of required chunks.
5151
var start_chunk: Vector2 = floor(
@@ -94,43 +94,6 @@ static func create_region_chunks(chunks_root_node: Node, p_source_geometry: Navi
9494
chunk_id_to_region[chunk_id] = chunk_region
9595

9696

97-
static func calculate_source_geometry_bounds(p_source_geometry: NavigationMeshSourceGeometryData2D) -> Rect2:
98-
if p_source_geometry.has_method("get_bounds"):
99-
# Godot 4.3 Patch added get_bounds() function that does the same but faster.
100-
return p_source_geometry.call("get_bounds")
101-
102-
var bounds: Rect2 = Rect2()
103-
var first_vertex: bool = true
104-
105-
for traversable_outline: PackedVector2Array in p_source_geometry.get_traversable_outlines():
106-
for traversable_point: Vector2 in traversable_outline:
107-
if first_vertex:
108-
first_vertex = false
109-
bounds.position = traversable_point
110-
else:
111-
bounds = bounds.expand(traversable_point)
112-
113-
for obstruction_outline: PackedVector2Array in p_source_geometry.get_obstruction_outlines():
114-
for obstruction_point: Vector2 in obstruction_outline:
115-
if first_vertex:
116-
first_vertex = false
117-
bounds.position = obstruction_point
118-
else:
119-
bounds = bounds.expand(obstruction_point)
120-
121-
for projected_obstruction: Dictionary in p_source_geometry.get_projected_obstructions():
122-
var projected_obstruction_vertices: PackedFloat32Array = projected_obstruction["vertices"]
123-
for i in projected_obstruction_vertices.size() / 2:
124-
var vertex: Vector2 = Vector2(projected_obstruction_vertices[i * 2], projected_obstruction_vertices[i * 2 + 1])
125-
if first_vertex:
126-
first_vertex = false
127-
bounds.position = vertex
128-
else:
129-
bounds = bounds.expand(vertex)
130-
131-
return bounds
132-
133-
13497
func _process(_delta: float) -> void:
13598
var mouse_cursor_position: Vector2 = get_global_mouse_position()
13699

@@ -151,6 +114,8 @@ func _process(_delta: float) -> void:
151114

152115
%PathDebugCorridorFunnel.target_position = closest_point_on_navmesh
153116
%PathDebugEdgeCentered.target_position = closest_point_on_navmesh
117+
%PathDebugNoPostProcessing.target_position = closest_point_on_navmesh
154118

155119
%PathDebugCorridorFunnel.get_next_path_position()
156120
%PathDebugEdgeCentered.get_next_path_position()
121+
%PathDebugNoPostProcessing.get_next_path_position()

2d/navigation_mesh_chunks/navmesh_chhunks_demo_2d.tscn

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ debug_path_custom_color = Color(1, 1, 0, 1)
4343
debug_path_custom_point_size = 10.0
4444
debug_path_custom_line_width = 4.0
4545

46+
[node name="PathDebugNoPostProcessing" type="NavigationAgent2D" parent="DebugPaths"]
47+
unique_name_in_owner = true
48+
path_postprocessing = 2
49+
debug_enabled = true
50+
debug_use_custom = true
51+
debug_path_custom_color = Color(1, 0, 0, 1)
52+
debug_path_custom_point_size = 10.0
53+
debug_path_custom_line_width = 4.0
54+
4655
[node name="ChunksContainer" type="Node2D" parent="."]
4756
unique_name_in_owner = true
4857

@@ -97,3 +106,19 @@ layout_mode = 2
97106
text = "Path edge-centered"
98107
horizontal_alignment = 1
99108
vertical_alignment = 1
109+
110+
[node name="HBoxContainer3" type="HBoxContainer" parent="CanvasLayer/PanelContainer/MarginContainer/VBoxContainer"]
111+
layout_mode = 2
112+
theme_override_constants/separation = 10
113+
114+
[node name="ColorRect" type="ColorRect" parent="CanvasLayer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3"]
115+
custom_minimum_size = Vector2(128, 8)
116+
layout_mode = 2
117+
size_flags_vertical = 4
118+
color = Color(1, 0, 0, 1)
119+
120+
[node name="Label" type="Label" parent="CanvasLayer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3"]
121+
layout_mode = 2
122+
text = "Path no post-processing"
123+
horizontal_alignment = 1
124+
vertical_alignment = 1

3d/navigation_mesh_chunks/navmesh_chhunks_demo_3d.gd

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func _ready() -> void:
3636
static func create_region_chunks(chunks_root_node: Node, p_source_geometry: NavigationMeshSourceGeometryData3D, p_chunk_size: float, p_agent_radius: float) -> void:
3737
# We need to know how many chunks are required for the input geometry.
3838
# So first get an axis aligned bounding box that covers all vertices.
39-
var input_geometry_bounds: AABB = calculate_source_geometry_bounds(p_source_geometry)
39+
var input_geometry_bounds: AABB = p_source_geometry.get_bounds()
4040

4141
# Rasterize bounding box into chunk grid to know range of required chunks.
4242
var start_chunk: Vector3 = floor(
@@ -96,37 +96,6 @@ static func create_region_chunks(chunks_root_node: Node, p_source_geometry: Navi
9696
chunk_id_to_region[chunk_id] = chunk_region
9797

9898

99-
static func calculate_source_geometry_bounds(p_source_geometry: NavigationMeshSourceGeometryData3D) -> AABB:
100-
if p_source_geometry.has_method("get_bounds"):
101-
# Godot 4.3 Patch added get_bounds() function that does the same but faster.
102-
return p_source_geometry.call("get_bounds")
103-
104-
var bounds: AABB = AABB()
105-
var first_vertex: bool = true
106-
107-
var vertices: PackedFloat32Array = p_source_geometry.get_vertices()
108-
var vertices_count: int = vertices.size() / 3
109-
for i in vertices_count:
110-
var vertex: Vector3 = Vector3(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2])
111-
if first_vertex:
112-
first_vertex = false
113-
bounds.position = vertex
114-
else:
115-
bounds = bounds.expand(vertex)
116-
117-
for projected_obstruction: Dictionary in p_source_geometry.get_projected_obstructions():
118-
var projected_obstruction_vertices: PackedFloat32Array = projected_obstruction["vertices"]
119-
for i in projected_obstruction_vertices.size() / 3:
120-
var vertex: Vector3 = Vector3(projected_obstruction.vertices[i * 3], projected_obstruction.vertices[i * 3 + 1], projected_obstruction.vertices[i * 3 + 2]);
121-
if first_vertex:
122-
first_vertex = false
123-
bounds.position = vertex
124-
else:
125-
bounds = bounds.expand(vertex)
126-
127-
return bounds
128-
129-
13099
func _process(_delta: float) -> void:
131100
var mouse_cursor_position: Vector2 = get_viewport().get_mouse_position()
132101

@@ -152,6 +121,8 @@ func _process(_delta: float) -> void:
152121

153122
%PathDebugCorridorFunnel.target_position = closest_point_on_navmesh
154123
%PathDebugEdgeCentered.target_position = closest_point_on_navmesh
124+
%PathDebugNoPostProcessing.target_position = closest_point_on_navmesh
155125

156126
%PathDebugCorridorFunnel.get_next_path_position()
157127
%PathDebugEdgeCentered.get_next_path_position()
128+
%PathDebugNoPostProcessing.get_next_path_position()

3d/navigation_mesh_chunks/navmesh_chhunks_demo_3d.tscn

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ debug_use_custom = true
9393
debug_path_custom_color = Color(1, 1, 0, 1)
9494
debug_path_custom_point_size = 10.0
9595

96+
[node name="PathDebugNoPostProcessing" type="NavigationAgent3D" parent="DebugPaths"]
97+
unique_name_in_owner = true
98+
path_postprocessing = 2
99+
debug_enabled = true
100+
debug_use_custom = true
101+
debug_path_custom_color = Color(1, 0, 0, 1)
102+
debug_path_custom_point_size = 10.0
103+
96104
[node name="DebugMousePos" type="Node3D" parent="DebugPaths"]
97105
unique_name_in_owner = true
98106

@@ -150,3 +158,19 @@ layout_mode = 2
150158
text = "Path edge-centered"
151159
horizontal_alignment = 1
152160
vertical_alignment = 1
161+
162+
[node name="HBoxContainer3" type="HBoxContainer" parent="CanvasLayer/PanelContainer/MarginContainer/VBoxContainer"]
163+
layout_mode = 2
164+
theme_override_constants/separation = 10
165+
166+
[node name="ColorRect" type="ColorRect" parent="CanvasLayer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3"]
167+
custom_minimum_size = Vector2(128, 8)
168+
layout_mode = 2
169+
size_flags_vertical = 4
170+
color = Color(1, 0, 0, 1)
171+
172+
[node name="Label" type="Label" parent="CanvasLayer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3"]
173+
layout_mode = 2
174+
text = "Path no post-processing"
175+
horizontal_alignment = 1
176+
vertical_alignment = 1

0 commit comments

Comments
 (0)