generated from krampus/template-godot4
Bounded grid generation layers check distance from plane before generation
All checks were successful
linting & formatting / build (push) Successful in 49s
All checks were successful
linting & formatting / build (push) Successful in 49s
This commit is contained in:
parent
94f97ad3ae
commit
9cb5de8e93
@ -134,6 +134,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 18900, 25000, 18900)
|
||||
simple_construct_threshold = 0.4
|
||||
construct_height_factor_x = SubResource("Curve_kox75")
|
||||
bounding_box = AABB(0, 0, 0, 5632, 400, 5632)
|
||||
debug = true
|
||||
noise_scale = Vector3(0.01, 0.01, 0.01)
|
||||
|
||||
[node name="MetroGridLayer2" parent="MetroQuadrant/UpperMetro" instance=ExtResource("4_fy7wq")]
|
||||
|
||||
@ -4,9 +4,10 @@ class_name BoundedGridLayer extends GridLayer
|
||||
## Bounding box for the grid on the local XZ plane.
|
||||
##
|
||||
## Note that only feature handles are checked to be within the bounding box.
|
||||
## The Y component of this AABB is not used.
|
||||
@export var bounding_box: AABB
|
||||
|
||||
@export var debug := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var grid := _plane_size()
|
||||
@ -19,28 +20,31 @@ func _ready() -> void:
|
||||
func _generate(lod: WorldGen.LOD) -> bool:
|
||||
var center := WorldGenManager.get_generation_point()
|
||||
var radius := WorldGenManager.get_lod_radius(lod)
|
||||
var rad_diff := Vector3(radius, 0, radius)
|
||||
|
||||
# Translate probe box limits to grid space
|
||||
var a := world_to_local(center - rad_diff).floor()
|
||||
var b := world_to_local(center + rad_diff).floor()
|
||||
var grid_low := Vector2(minf(a.x, b.x), minf(a.y, b.y))
|
||||
var grid_high := Vector2(maxf(a.x, b.x), maxf(a.y, b.y))
|
||||
var grid_max := _plane_size().floor()
|
||||
# Only generate if the bounding box is within generation radius.
|
||||
if absf((center * global_transform).y) + bounding_box.size.y < radius:
|
||||
var rad_diff := Vector3(radius, 0, radius)
|
||||
|
||||
# Constrain to bounding box
|
||||
var x_min := maxf(grid_low.x, 0)
|
||||
var x_max := minf(grid_high.x + 1, grid_max.x)
|
||||
var y_min := maxf(grid_low.y, 0)
|
||||
var y_max := minf(grid_high.y + 1, grid_max.y)
|
||||
# Translate probe box limits to grid space
|
||||
var a := world_to_local(center - rad_diff).floor()
|
||||
var b := world_to_local(center + rad_diff).floor()
|
||||
var grid_low := Vector2(minf(a.x, b.x), minf(a.y, b.y))
|
||||
var grid_high := Vector2(maxf(a.x, b.x), maxf(a.y, b.y))
|
||||
var grid_max := _plane_size().floor()
|
||||
|
||||
# Probe everything within radius
|
||||
for i in range(x_min, x_max):
|
||||
for j in range(y_min, y_max):
|
||||
var pt := Vector2(i, j)
|
||||
if pt in _generation_grid[lod]:
|
||||
if generate_grid(lod, pt):
|
||||
_generation_grid[lod].erase(pt)
|
||||
# Constrain to bounding box
|
||||
var x_min := maxf(grid_low.x, 0)
|
||||
var x_max := minf(grid_high.x + 1, grid_max.x)
|
||||
var y_min := maxf(grid_low.y, 0)
|
||||
var y_max := minf(grid_high.y + 1, grid_max.y)
|
||||
|
||||
# Probe everything within radius
|
||||
for i in range(x_min, x_max):
|
||||
for j in range(y_min, y_max):
|
||||
var pt := Vector2(i, j)
|
||||
if pt in _generation_grid[lod]:
|
||||
if generate_grid(lod, pt):
|
||||
_generation_grid[lod].erase(pt)
|
||||
|
||||
# Return false if there are still grid points to be generated
|
||||
return not _generation_grid[lod]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user