feat(world): render steep tiles on a smooth bicubic surface, sampled in parallel
Tiles holding a slope over 35 degrees are meshed at two vertices per cell on a clamped Catmull-Rom surface that passes through every grid node, so cliffs and ledges lose the facets of the heightfield grid while the collision stays on the grid. The domain field exposes the smooth elevation and a separable, per-phase-weighted block sampler with linear edge extrapolation and a one-cell margin for continuous normals; the actor samples tiles on the worker thread pool and builds meshes afterwards. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
d7e50f8879
commit
122f3f5800
11 files changed
+314
-19
No files matched your search
@@ -7,7 +7,7 @@ const SitePlacement = preload("res://game/domain/sites/site_placement.gd")
|
||||
const SiteRoute = preload("res://game/domain/sites/site_route.gd")
|
||||
const DiveSiteDefinition = preload("res://game/domain/sites/dive_site_definition.gd")
|
||||
|
||||
const TEST_COUNT := 41
|
||||
const TEST_COUNT := 46
|
||||
|
||||
var _failures: Array[String] = []
|
||||
|
||||
@@ -97,6 +97,38 @@ func _test_height_field_sampling() -> void:
|
||||
_expect(field.material_at(-10.4, 100.0) == SonarMaterial.Value.ROCK, "material is the nearest cell")
|
||||
_expect(field.material_at(-6.0, 103.0) == SonarMaterial.Value.SAND, "material of an interior cell")
|
||||
_expect(field.normal_at_cell(1, 1).is_equal_approx(Vector3(0.0, 1.0, 1.0).normalized()), "normal leans against the downhill direction")
|
||||
_expect(is_equal_approx(field.smooth_elevation_at(-10.0, 100.0), field.elevation_at(-10.0, 100.0)), "smooth elevation passes through the grid nodes")
|
||||
var plane_data := SiteTerrainData.new()
|
||||
plane_data.columns = 7
|
||||
plane_data.rows = 6
|
||||
plane_data.cell_size_m = 2.0
|
||||
plane_data.origin_x_m = 0.0
|
||||
plane_data.origin_z_m = 0.0
|
||||
var plane_elevations := PackedFloat32Array()
|
||||
var plane_materials := PackedByteArray()
|
||||
for row in 6:
|
||||
for column in 7:
|
||||
plane_elevations.append(-20.0 + 0.5 * float(column) * 2.0 - 0.25 * float(row) * 2.0)
|
||||
plane_materials.append(SonarMaterial.Value.SAND)
|
||||
plane_data.elevations_m = plane_elevations
|
||||
plane_data.materials = plane_materials
|
||||
var plane := TerrainHeightField.from_data(plane_data)
|
||||
_expect(
|
||||
is_equal_approx(plane.smooth_elevation_at(5.0, 3.0), -20.0 + 2.5 - 0.75)
|
||||
and is_equal_approx(plane.smooth_elevation_at(0.5, 0.5), -20.0 + 0.25 - 0.125),
|
||||
"smooth elevation reproduces a plane between nodes, edges included"
|
||||
)
|
||||
var fine := field.cell_block_positions_subdivided(1, 2, 0, 3, 2)
|
||||
var fine_normals := field.cell_block_normals_subdivided(1, 2, 0, 3, 2)
|
||||
_expect(fine.size() == 3 * 7 and fine_normals.size() == 3 * 7, "a subdivided block has cells * 2 + 1 points per axis")
|
||||
var nodes_match := fine.size() == 21
|
||||
for row in 4:
|
||||
for column in range(1, 3):
|
||||
var index := (row * 2) * 3 + (column - 1) * 2
|
||||
if nodes_match and not fine[index].is_equal_approx(field.cell_world_position(column, row)):
|
||||
nodes_match = false
|
||||
_expect(nodes_match, "subdivided block points on the grid nodes equal the cell positions")
|
||||
_expect(fine_normals[0].is_normalized() and fine_normals[10].y > 0.0, "subdivided normals are unit length and point up")
|
||||
var block_positions := field.cell_block_positions(1, 2, 0, 3)
|
||||
var block_normals := field.cell_block_normals(1, 2, 0, 3)
|
||||
var block_matches := block_positions.size() == 8 and block_normals.size() == 8
|
||||
|
||||
Reference in new issue
Block a user