feat(tools): declarative site terrain baker and calibration recipe
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
84e66d304a
commit
8ab1289d10
9 files changed
+461
No files matched your search
@@ -0,0 +1,71 @@
|
||||
extends SceneTree
|
||||
|
||||
const SonarMaterial = preload("res://game/domain/sonar/sonar_material.gd")
|
||||
const SiteTerrainBaker = preload("res://tools/site_terrain_baker.gd")
|
||||
const VehicleTestRecipe = preload("res://tools/sites/vehicle_test_terrain_recipe.gd")
|
||||
|
||||
const TEST_COUNT := 10
|
||||
|
||||
var _failures: Array[String] = []
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_test_plane_and_blob()
|
||||
_test_materials_and_determinism()
|
||||
|
||||
if _failures.is_empty():
|
||||
print("Site baker unit tests: %d passed, 0 failed." % TEST_COUNT)
|
||||
quit(0)
|
||||
else:
|
||||
for failure: String in _failures:
|
||||
push_error(failure)
|
||||
print("Site baker unit tests: %d failed." % _failures.size())
|
||||
quit(1)
|
||||
|
||||
|
||||
func _small_recipe() -> SiteTerrainBaker.Recipe:
|
||||
var recipe := SiteTerrainBaker.Recipe.new()
|
||||
recipe.columns = 21
|
||||
recipe.rows = 21
|
||||
recipe.cell_size_m = 2.0
|
||||
recipe.origin_x_m = -20.0
|
||||
recipe.origin_z_m = -20.0
|
||||
recipe.floor_elevation_m = -80.0
|
||||
recipe.rock_slope_degrees = 20.0
|
||||
return recipe
|
||||
|
||||
|
||||
func _test_plane_and_blob() -> void:
|
||||
var recipe := _small_recipe()
|
||||
recipe.primitives.append(SiteTerrainBaker.SlopedPlane.new(30.0, 0.0, 0.1, 0.0, 0.0))
|
||||
var data := SiteTerrainBaker.bake(recipe)
|
||||
_expect(data != null and data.validation_error().is_empty(), "plane recipe bakes valid data")
|
||||
_expect(is_equal_approx(data.elevations_m[data.index_of(10, 10)], -30.0), "plane depth at the reference point")
|
||||
_expect(is_equal_approx(data.elevations_m[data.index_of(10, 20)], -28.0), "plane slopes along +Z")
|
||||
_expect(data.materials[data.index_of(10, 10)] == SonarMaterial.Value.SAND, "gentle plane is sand")
|
||||
|
||||
recipe.primitives.append(SiteTerrainBaker.Blob.new(Vector2(0.0, 0.0), 4.0, 4.0, 10.0))
|
||||
data = SiteTerrainBaker.bake(recipe)
|
||||
_expect(is_equal_approx(data.elevations_m[data.index_of(10, 10)], -20.0), "blob adds its amplitude at the centre")
|
||||
_expect(data.materials[data.index_of(12, 10)] == SonarMaterial.Value.ROCK, "steep blob flank is rock")
|
||||
|
||||
|
||||
func _test_materials_and_determinism() -> void:
|
||||
var recipe := _small_recipe()
|
||||
recipe.primitives.append(SiteTerrainBaker.SlopedPlane.new(30.0, 0.0, 0.0, 0.0, 0.0))
|
||||
recipe.primitives.append(SiteTerrainBaker.Roughness.new(1933, 0.05, 0.5))
|
||||
recipe.material_patches.append(
|
||||
SiteTerrainBaker.MaterialPatch.new(Vector2(10.0, 10.0), 3.0, SonarMaterial.Value.ROCK)
|
||||
)
|
||||
var first := SiteTerrainBaker.bake(recipe)
|
||||
var second := SiteTerrainBaker.bake(recipe)
|
||||
_expect(first.elevations_m == second.elevations_m, "same recipe bakes identical elevations")
|
||||
_expect(first.materials == second.materials, "same recipe bakes identical materials")
|
||||
_expect(first.materials[first.index_of(15, 15)] == SonarMaterial.Value.ROCK, "material patch overrides the slope rule")
|
||||
var calibration := SiteTerrainBaker.bake(VehicleTestRecipe.recipe())
|
||||
_expect(calibration != null and calibration.validation_error().is_empty(), "calibration recipe bakes valid data")
|
||||
|
||||
|
||||
func _expect(condition: bool, label: String) -> void:
|
||||
if not condition:
|
||||
_failures.append(label)
|
||||
Reference in new issue
Block a user