TerrainView draws the island as 16 x 16 chunks of 64 m, each at one of four detail levels (2, 4, 8 and 16 m spacing) chosen by distance to the camera. TerrainChunkBuilder builds chunk geometry on WorkerThreadPool threads; the main thread only uploads finished meshes, within a 2 ms per-frame budget, nearest chunks first. - Seams: every chunk hangs skirts deeper than twice the most any level strays from the full-resolution edge, so neighbours at any two levels meet without a crack. Normals come from the full-resolution heightfield at every level, and back faces light like the ground above them. - Splat material: a procedural shader blends sand, marsh, grass and rock with weights from the island's bands, averaged over 4 m so borders blend. Steep ground turns to rock and summits weather pale. - Collision stays SimGround's heightfield, with no renderer involved. - Capture scenarios terrain, terrain_lod (tinted by level) and terrain_cracks (magenta sky). tools/crack_check.gd counts sky pixels seen through the ground; make terrain-capture requires cracks in a skirtless control and none in the real terrain. Tests: chunk vertices sit on the heightfield; skirts cover every pairing of levels on sampled shared edges; detail falls with distance; flying across the island at 30 m/s for 2,037 frames streams 661 chunk rebuilds with the worst main-thread frame at 0.8 to 1.4 ms (headless, CPU only); 24 players over 900 ticks on two generated islands never sink into the ground, and a player sprints up towards a summit unharmed. make terrain-capture: control 437 crack pixels, terrain 0. Closes #10 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
1.9 KiB
GDScript
53 lines
1.9 KiB
GDScript
## Counts crack pixels in a terrain_cracks capture. terrain_scene.gd draws the sky as a
|
|
## flat magenta that appears nowhere in the terrain. Magenta connected to the top of the
|
|
## frame is open sky above the world's edge; any other magenta is sky seen through a gap
|
|
## in the terrain. Prints the counts and exits 1 if there are any cracks.
|
|
##
|
|
## tools/godot.sh --script res://tools/crack_check.gd -- --image=/abs/path/cracks.png
|
|
extends SceneTree
|
|
|
|
|
|
func _init() -> void:
|
|
var path: String = ""
|
|
for arg: String in OS.get_cmdline_user_args():
|
|
if arg.begins_with("--image="):
|
|
path = arg.trim_prefix("--image=")
|
|
var image: Image = Image.load_from_file(path)
|
|
if image == null or image.is_empty():
|
|
printerr("crack_check: can't read '%s'" % path)
|
|
quit(2)
|
|
return
|
|
var width: int = image.get_width()
|
|
var height: int = image.get_height()
|
|
var magenta: PackedByteArray = PackedByteArray()
|
|
magenta.resize(width * height)
|
|
var total: int = 0
|
|
for y: int in height:
|
|
for x: int in width:
|
|
var pixel: Color = image.get_pixel(x, y)
|
|
if pixel.r > 0.8 and pixel.b > 0.8 and pixel.g < 0.25:
|
|
magenta[y * width + x] = 1
|
|
total += 1
|
|
# Flood the open sky from the top row; what's left is seen through cracks.
|
|
var queue: PackedInt32Array = PackedInt32Array()
|
|
for x: int in width:
|
|
if magenta[x] == 1:
|
|
magenta[x] = 2
|
|
queue.append(x)
|
|
var head: int = 0
|
|
while head < queue.size():
|
|
var at: int = queue[head]
|
|
head += 1
|
|
var x: int = at % width
|
|
var y: int = at / width
|
|
for next: Vector2i in [Vector2i(x + 1, y), Vector2i(x - 1, y), Vector2i(x, y + 1), Vector2i(x, y - 1)]:
|
|
if next.x < 0 or next.y < 0 or next.x >= width or next.y >= height:
|
|
continue
|
|
var index: int = next.y * width + next.x
|
|
if magenta[index] == 1:
|
|
magenta[index] = 2
|
|
queue.append(index)
|
|
var cracks: int = total - queue.size()
|
|
print("crack_check: %d crack pixels (%d magenta, %d of it open sky)" % [cracks, total, queue.size()])
|
|
quit(1 if cracks > 0 else 0)
|