A5: World art for points of interest, build pieces, vessels and terrain

- PoiMesher dresses every point of interest from its parts: lapped tarred
  weatherboards, plank boards, stone in a running bond with lichen, tiled
  roofs with a ridge cap, salt-white trim on paint, crusted salt pans, and a
  tarred frame round the lighthouse's glowing glass. One mesh per POI.
- Huts get a shuttered window in each side wall (non-solid parts, no rng).
- Build pieces show their state: building in quarter steps, worn (a third of
  health gone) and battered (two thirds gone, strips knocked out).
  StructureView rebuilds a piece's mesh only when its state changes.
- VesselModels builds the barge (lofted hull, curved rails, mooring lines,
  gored envelope) and the sea chests in code; the primitive stand-ins are gone.
- Terrain: tussocks, wind-dried patches, shingle on sand, lichen on rock.
- test_world_art (9) fails on any primitive stand-in mesh or placeholder
  resource under src/ or assets/, and covers POI bounds and determinism,
  windows, the lamp surface, wear and build stages, view rebuilds and the
  vessel models.
- make poi-captures and make build-captures (state card, vessels).

Closes #45

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 20:39:24 -05:00
co-authored by Claude Opus 5.5
parent fdd4c992c3
commit 923876ed1f
22 changed files with 976 additions and 131 deletions
+51
View File
@@ -1,10 +1,14 @@
## Capture scenario for building (B2): a small fort of every piece kind in all three
## materials on real island terrain, with one valid and one invalid placement ghost.
## With `states`, instead a test card of walls (A5): a row per material (driftwood at
## the bottom, then stone, then iron) and a column per state: half built, intact, worn
## and battered, left to right, plus a battered driftwood ramp on the left.
extends Node3D
@export var island_seed: int = 2
## Camera offset from the fort's corner: x east, y up, z south.
@export var view: Vector3 = Vector3(-11.0, 8.5, -12.0)
@export var states: bool = false
func _ready() -> void:
@@ -24,6 +28,9 @@ func _ready() -> void:
feet.y = sim.ground.terrain_height(feet.x, feet.z)
var level: int = roundi(feet.y / Tuning.BUILD_LEVEL_METRES)
var up: int = roundi(g / Tuning.BUILD_LEVEL_METRES)
if states:
_state_card(sim, site, level, up)
return
var placed: Array[String] = []
# A two-cell room: floor, walls in three materials, a roof, a ramp up its side and a
# breakwater on the seaward... well, the near side.
@@ -47,6 +54,7 @@ func _ready() -> void:
var result: Building.Result = Building.place(sim, builder, at, entry[3])
placed.append("%s %s" % [StructureSet.KINDS[at.kind], Building.Result.keys()[result]])
print("build_scene: site %s level %d: %s" % [site, level, ", ".join(placed)])
_finish_building(sim)
_environment()
var structures: StructureView = StructureView.new()
@@ -92,6 +100,49 @@ func _ready() -> void:
add_child(water)
## Steps every piece's building to the end, so the captures show finished pieces.
func _finish_building(sim: Simulation) -> void:
# A copy: set_progress drops finished pieces from the live list.
for piece_id: int in sim.structures.building().duplicate():
var piece: StructureSet.Piece = sim.structures.find(piece_id)
sim.structures.set_progress(piece_id, piece.build_ticks, StructureSet.damage_taken(piece))
func _state_card(sim: Simulation, site: Vector2i, level: int, up: int) -> void:
var g: float = Tuning.GRID_CELL_METRES
# Fraction built and share of max health lost, per column.
var columns: Array = [[0.5, 0.0], [1.0, 0.0], [1.0, 0.45], [1.0, 0.8]]
var shown: Array[String] = []
for material: int in 3:
for column: int in columns.size():
# Seen from the north (the sunlit side), so the columns run towards -x.
var slot: Vector4i = Vector4i(site.x + 3 - column, level + up * material, site.y, StructureSet.SLOT_WALL_Z)
var piece: StructureSet.Piece = sim.structures.add(StructureSet.WALL, material, slot, 0, 0, 0, sim.ground)
var spec: Array = columns[column]
sim.structures.set_progress(piece.id, roundi(piece.build_ticks * float(spec[0])), roundi(piece.max_health * float(spec[1])))
shown.append(str(PieceMesher.state_of(piece)))
var ramp: StructureSet.Piece = sim.structures.add(StructureSet.RAMP, Materials.DRIFTWOOD, Vector4i(site.x + 5, level, site.y - 1, StructureSet.SLOT_VOLUME), 0, 0, 0, sim.ground)
sim.structures.set_progress(ramp.id, ramp.build_ticks, roundi(ramp.max_health * 0.8))
print("build_scene: state card at %s level %d: %s" % [site, level, ", ".join(shown)])
_environment()
var structures: StructureView = StructureView.new()
structures.setup(sim.structures)
add_child(structures)
var camera: Camera3D = Camera3D.new()
camera.fov = 62.0
camera.far = 1500.0
var centre: Vector3 = Vector3((site.x + 2.6) * g, level * Tuning.BUILD_LEVEL_METRES + 1.5 * g, site.y * g)
camera.position = centre + view
add_child(camera)
camera.look_at(centre)
camera.make_current()
var terrain: TerrainView = TerrainView.new()
terrain.setup(sim.island)
terrain.focus = camera.position
add_child(terrain)
terrain.build_all_now()
func _face(player: SimEntity, yaw_degrees: float, pitch_degrees: float) -> void:
var command: PlayerCommand = PlayerCommand.from_input(0, Vector2.ZERO, deg_to_rad(yaw_degrees), deg_to_rad(pitch_degrees))
player.yaw = command.yaw
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/build_scene.gd" id="1"]
[node name="CaptureBuild" type="Node3D"]
script = ExtResource("1")
view = Vector3(3, 1, -19)
states = true
+6
View File
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/vessels_scene.gd" id="1"]
[node name="CaptureVessels" type="Node3D"]
script = ExtResource("1")
+35
View File
@@ -0,0 +1,35 @@
## Capture scenario for the generated barge and sea chests (A5): the barge from outside,
## in the air above the sea, with a row of chests on a plank stand, shut and opened.
extends Node3D
func _ready() -> void:
var world: WorldEnvironment = WorldEnvironment.new()
world.environment = Look.environment()
add_child(world)
add_child(Look.sun(200.0))
var barge: MeshInstance3D = MeshInstance3D.new()
barge.mesh = VesselModels.barge()
barge.position = Vector3(0.0, 0.0, 0.0)
barge.rotation.y = 0.5
add_child(barge)
var multimesh: MultiMesh = MultiMesh.new()
multimesh.transform_format = MultiMesh.TRANSFORM_3D
multimesh.use_colors = true
multimesh.mesh = VesselModels.chest()
multimesh.instance_count = 3
for index: int in 3:
var at: Vector3 = Vector3(-1.4 + index * 1.4, 0.0, 0.0)
multimesh.set_instance_transform(index, Transform3D(Basis.IDENTITY, at))
multimesh.set_instance_color(index, EntityView.CHEST_OPEN if index == 2 else EntityView.CHEST_SHUT)
var chests: MultiMeshInstance3D = MultiMeshInstance3D.new()
chests.multimesh = multimesh
chests.position = Vector3(9.0, 0.0, 6.0)
add_child(chests)
var camera: Camera3D = Camera3D.new()
camera.fov = 60.0
camera.position = Vector3(16.0, 6.0, 20.0)
add_child(camera)
camera.look_at(Vector3(2.0, 5.0, 0.0))
camera.make_current()
Look.add_print_pass(camera)
+1
View File
@@ -0,0 +1 @@
uid://4sttk8o6hosl
+173
View File
@@ -0,0 +1,173 @@
extends TestCase
## Issue A5: world art. Points of interest, build piece states, the barge and chests,
## and no placeholder meshes left in the game.
## Primitive meshes that would be stand-ins for real models. PlaneMesh (the sea's
## shader surface) and QuadMesh (screen passes and rain) are surfaces, not models.
const PLACEHOLDER_CLASSES: Array[String] = ["BoxMesh", "SphereMesh", "CylinderMesh", "CapsuleMesh", "PrismMesh", "TorusMesh", "TextMesh", "PlaceholderMesh", "PlaceholderMaterial", "PlaceholderTexture"]
const PLACEHOLDER_WORDS: Array[String] = ["stand-in shape", "placeholder mesh", "blockout", "art pass replaces"]
static var _island: Island
static var _pois: PoiSet
func _placed() -> PoiSet:
if _pois == null:
_island = Island.generate(2)
_pois = PoiSet.generate(_island)
return _pois
func test_no_placeholder_meshes_or_resources_remain() -> void:
var files: PackedStringArray = PackedStringArray()
_collect("res://src", files)
_collect("res://assets", files)
assert_true(files.size() > 100, "found the game's files (%d)" % files.size())
for path: String in files:
assert_false(path.get_file().to_lower().contains("placeholder"), "%s is named as a placeholder" % path)
if not (path.ends_with(".gd") or path.ends_with(".tscn") or path.ends_with(".tres") or path.ends_with(".gdshader")):
continue
var text: String = FileAccess.get_file_as_string(path)
for name: String in PLACEHOLDER_CLASSES:
assert_false(text.contains(name), "%s uses %s" % [path, name])
var lower: String = text.to_lower()
for word: String in PLACEHOLDER_WORDS:
assert_false(lower.contains(word), "%s says '%s'" % [path, word])
func test_every_poi_is_dressed_within_its_parts() -> void:
var placed: PoiSet = _placed()
var kinds: Dictionary = {}
var known: Array[String] = [Poi.LOOK_TARRED_WOOD, Poi.LOOK_PLANK, Poi.LOOK_STONE, Poi.LOOK_ROOF, Poi.LOOK_PAINT, Poi.LOOK_SALT, Poi.LOOK_LAMP, Poi.LOOK_WINDOW]
for poi: Poi in placed.pois:
kinds[poi.kind] = true
var bounds: AABB = poi.parts[0]["box"]
var parts: int = 0
for part: Dictionary in poi.parts:
assert_true(known.has(String(part["look"])), "%s: unknown look %s" % [poi.kind, part["look"]])
bounds = bounds.merge(part["box"])
parts += 1
var mesh: ArrayMesh = PoiMesher.build(poi.parts)
var vertices: int = mesh.surface_get_array_len(PoiMesher.SURFACE_SOLID)
# Dressed, not one box per part: boards, courses and tiles add many.
assert_true(vertices > parts * 36 * 2, "%s: %d vertices for %d parts" % [poi.kind, vertices, parts])
assert_true(bounds.grow(0.06).encloses(mesh.get_aabb()), "%s: mesh %s strays outside its parts %s" % [poi.kind, mesh.get_aabb(), bounds])
for kind: String in PoiSet.ORDER:
assert_true(kinds.has(kind), "seed 2 has a %s to check" % kind)
func test_poi_meshes_are_the_same_every_time() -> void:
var poi: Poi = _placed().pois[0]
var first: PackedVector3Array = PoiMesher.build(poi.parts).surface_get_arrays(0)[Mesh.ARRAY_VERTEX]
var second: PackedVector3Array = PoiMesher.build(poi.parts).surface_get_arrays(0)[Mesh.ARRAY_VERTEX]
var first_colours: PackedColorArray = PoiMesher.build(poi.parts).surface_get_arrays(0)[Mesh.ARRAY_COLOR]
var second_colours: PackedColorArray = PoiMesher.build(poi.parts).surface_get_arrays(0)[Mesh.ARRAY_COLOR]
assert_eq(first, second)
assert_eq(first_colours, second_colours)
func test_huts_have_windows_that_do_not_block() -> void:
var placed: PoiSet = _placed()
var windows: int = 0
for poi: Poi in placed.pois:
for part: Dictionary in poi.parts:
if part["look"] == Poi.LOOK_WINDOW:
windows += 1
assert_false(poi.solids.has(part["box"]), "%s: a window is solid" % poi.kind)
assert_true(windows >= 4, "the island's huts have windows (%d)" % windows)
func test_the_light_glows_on_its_own_surface() -> void:
for poi: Poi in _placed().pois:
if poi.kind != "lighthouse":
continue
var mesh: ArrayMesh = PoiMesher.build(poi.parts)
assert_eq(mesh.get_surface_count(), 2)
var lit: StandardMaterial3D = mesh.surface_get_material(PoiMesher.SURFACE_LAMP)
assert_true(lit.emission_enabled)
return
assert_true(false, "seed 2 has a lighthouse")
func test_wear_and_building_stages() -> void:
assert_eq(PieceMesher.wear_of(0, 300), PieceMesher.INTACT)
assert_eq(PieceMesher.wear_of(101, 300), PieceMesher.INTACT)
assert_eq(PieceMesher.wear_of(102, 300), PieceMesher.WORN)
assert_eq(PieceMesher.wear_of(201, 300), PieceMesher.BATTERED)
assert_eq(PieceMesher.wear_of(299, 300), PieceMesher.BATTERED)
assert_eq(PieceMesher.built_of(0, 60), 1.0)
assert_eq(PieceMesher.built_of(60, 60), 0.25, "just placed still shows its first step")
assert_eq(PieceMesher.built_of(30, 60), 0.5)
assert_eq(PieceMesher.built_of(1, 60), 1.0)
assert_eq(PieceMesher.built_of(5, 0), 1.0)
func test_piece_meshes_show_wear_and_building_inside_their_box() -> void:
var slot: Vector4i = Vector4i(0, 0, 0, StructureSet.SLOT_WALL_X)
var boxes: Array[AABB] = StructureSet.boxes_for(StructureSet.WALL, slot, 0)
for material: int in 3:
var counts: Dictionary = {}
for wear: int in [PieceMesher.INTACT, PieceMesher.WORN, PieceMesher.BATTERED]:
var mesh: ArrayMesh = PieceMesher.build(boxes, material, 7, wear)
assert_true(boxes[0].grow(0.001).encloses(mesh.get_aabb()), "material %d wear %d stays in the wall" % [material, wear])
counts[wear] = mesh.surface_get_array_len(0)
assert_true(counts[PieceMesher.BATTERED] < counts[PieceMesher.INTACT], "material %d: battered strips are knocked out" % material)
var intact_colours: PackedColorArray = PieceMesher.build(boxes, material, 7).surface_get_arrays(0)[Mesh.ARRAY_COLOR]
var worn_colours: PackedColorArray = PieceMesher.build(boxes, material, 7, PieceMesher.WORN).surface_get_arrays(0)[Mesh.ARRAY_COLOR]
assert_ne(intact_colours, worn_colours, "material %d: wear shows" % material)
var half: ArrayMesh = PieceMesher.build(boxes, material, 7, PieceMesher.INTACT, 0.5)
var whole: ArrayMesh = PieceMesher.build(boxes, material, 7)
assert_true(half.surface_get_array_len(0) < whole.surface_get_array_len(0), "material %d: half built shows less" % material)
assert_true(boxes[0].grow(0.001).encloses(half.get_aabb()))
var ramp: AABB = PieceMesher.build_ramp(Vector4i(0, 0, 0, StructureSet.SLOT_VOLUME), 0, 0, 3).get_aabb()
var ramp_half: AABB = PieceMesher.build_ramp(Vector4i(0, 0, 0, StructureSet.SLOT_VOLUME), 0, 0, 3, PieceMesher.BATTERED, 0.5).get_aabb()
assert_true(ramp.grow(0.001).encloses(ramp_half))
func test_structure_view_redraws_a_piece_when_its_state_changes() -> void:
var sim: Simulation = Simulation.new(3, SimGround.flat())
var piece: StructureSet.Piece = sim.structures.add(StructureSet.WALL, Materials.STONE, Vector4i(2, 0, 2, StructureSet.SLOT_WALL_X), 0, 0, 0, sim.ground)
var view: StructureView = StructureView.new()
view.setup(sim.structures)
assert_eq(view.meshes_built, 1)
assert_eq(view.shown_state(piece.id), [PieceMesher.INTACT, 0.25])
view.sync()
assert_eq(view.meshes_built, 1, "nothing changed, nothing rebuilt")
sim.structures.set_progress(piece.id, piece.build_ticks, 0)
view.sync()
assert_eq(view.meshes_built, 2)
assert_eq(view.shown_state(piece.id), [PieceMesher.INTACT, 1.0])
var events: Array[Dictionary] = []
sim.structures.damage(piece.id, roundi(piece.max_health * 0.5), "test", sim.ground, events)
view.sync()
assert_eq(view.shown_state(piece.id), [PieceMesher.WORN, 1.0])
sim.structures.damage(piece.id, roundi(piece.max_health * 0.3), "test", sim.ground, events)
view.sync()
assert_eq(view.shown_state(piece.id), [PieceMesher.BATTERED, 1.0])
assert_eq(view.meshes_built, 4)
assert_eq(view.drawn_count(), 1)
view.free()
func test_barge_and_chest_models() -> void:
var barge: AABB = VesselModels.barge().get_aabb()
assert_near(barge.position.y, -VesselModels.HULL_DEPTH, 0.05, "hull bottom")
assert_near(barge.end.y, VesselModels.ENVELOPE_HEIGHT + VesselModels.ENVELOPE_AXES.y, 0.05, "envelope top")
assert_near(barge.size.x, 2.0 * VesselModels.ENVELOPE_AXES.x, 0.05, "the envelope is the widest part")
assert_true(barge.size.z >= 2.0 * VesselModels.HULL_HALF_LENGTH, "hull length")
var chest: AABB = VesselModels.chest().get_aabb()
assert_near(chest.position.y, 0.0, 0.001, "chests stand on the ground")
assert_near(chest.size.y, VesselModels.CHEST_SIZE.y + 0.01, 0.02)
assert_true(chest.size.x < VesselModels.CHEST_SIZE.x + 0.1)
func _collect(dir_path: String, into: PackedStringArray) -> void:
var dir: DirAccess = DirAccess.open(dir_path)
if dir == null:
return
for name: String in dir.get_files():
into.append(dir_path.path_join(name))
for name: String in dir.get_directories():
if not name.begins_with("."):
_collect(dir_path.path_join(name), into)
+1
View File
@@ -0,0 +1 @@
uid://c3ipydy117bkm