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
+2
View File
@@ -41,6 +41,8 @@ continuity.
| `make hud-captures` | Renders the HUD over a staged moment of play (three bots out, carried items, a wound) at 1280x720, in build mode, and at 3840x2160 (`captures/hud_*.png`, about 5 min). Needs Docker. Look at them. | | `make hud-captures` | Renders the HUD over a staged moment of play (three bots out, carried items, a wound) at 1280x720, in build mode, and at 3840x2160 (`captures/hud_*.png`, about 5 min). Needs Docker. Look at them. |
| `make menu-captures` | Renders every menu screen: main, practice, join (with a made-up server list), settings (controls and mouse tabs), pause and results over a match (`captures/menu_*.png`, about 5 min). Needs Docker. Look at them. | | `make menu-captures` | Renders every menu screen: main, practice, join (with a made-up server list), settings (controls and mouse tabs), pause and results over a match (`captures/menu_*.png`, about 5 min). Needs Docker. Look at them. |
| `make chart-captures` | Renders the chart and minimap of seed 2 with the first tide forecast, and again once it has risen (`captures/chart_*.png`, about 2 min). Needs Docker. Look at them. | | `make chart-captures` | Renders the chart and minimap of seed 2 with the first tide forecast, and again once it has risen (`captures/chart_*.png`, about 2 min). Needs Docker. Look at them. |
| `make poi-captures` | Renders each kind of point of interest (`captures/poi_*.png`, about 3 min). Needs Docker. Look at them. |
| `make build-captures` | Renders the fort and the wall test card: a row per material, a column per state (half built, intact, worn, battered), and a battered ramp (`captures/build_*.png`), and the barge and sea chests (`captures/vessels.png`), about 2 min. Needs Docker. Look at them. |
| `make style-captures` | Renders a hamlet and a dock with and without the woodcut print pass (`captures/style_*.png`). Needs Docker. | | `make style-captures` | Renders a hamlet and a dock with and without the woodcut print pass (`captures/style_*.png`). Needs Docker. |
| `make soak` | The 24-client network soak (N8): a real server and 24 headless `SoakPlayer` clients in three processes, each behind a `UdpRelay` adding 60 ms, +/-20 ms jitter and 2% loss each way, for two whole matches in real time (about 30 min, under `nice`). Fails on a world-hash mismatch, errors, unreadable packets, a client that didn't play every match, memory growth between matches, or a p99 tick over budget. `SOAK_MATCHES`, `SOAK_CLIENTS`, `SOAK_PROCS`, `SOAK_LATENCY`, `SOAK_JITTER`, `SOAK_LOSS` scale it. Results in `build/soak/report.txt`. | | `make soak` | The 24-client network soak (N8): a real server and 24 headless `SoakPlayer` clients in three processes, each behind a `UdpRelay` adding 60 ms, +/-20 ms jitter and 2% loss each way, for two whole matches in real time (about 30 min, under `nice`). Fails on a world-hash mismatch, errors, unreadable packets, a client that didn't play every match, memory growth between matches, or a p99 tick over budget. `SOAK_MATCHES`, `SOAK_CLIENTS`, `SOAK_PROCS`, `SOAK_LATENCY`, `SOAK_JITTER`, `SOAK_LOSS` scale it. Results in `build/soak/report.txt`. |
| `make soak-selfcheck` | About a minute: tampers with one client's world and checks the soak's comparison catches it and only it. | | `make soak-selfcheck` | About a minute: tampers with one client's world and checks the soak's comparison catches it and only it. |
+8 -1
View File
@@ -1,7 +1,7 @@
# Tidewall build entry points. Everything runs headless with the repo-local engine. # Tidewall build entry points. Everything runs headless with the repo-local engine.
GODOT := tools/godot.sh GODOT := tools/godot.sh
.PHONY: art figure figure-captures sea-captures models item-captures audio audio-check check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine bot-matches match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz soak soak-selfcheck server-package-check .PHONY: build-captures poi-captures art figure figure-captures sea-captures models item-captures audio audio-check check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine bot-matches match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz soak soak-selfcheck server-package-check
## A8: regenerates every sound in assets/audio/ from tools/audio/ (about 6 s). ## A8: regenerates every sound in assets/audio/ from tools/audio/ (about 6 s).
audio: import audio: import
@@ -118,6 +118,13 @@ menu-captures: import
chart-captures: import chart-captures: import
@for scene in chart_first chart_later; do tools/capture.sh $$scene captures/$$scene.png; done @for scene in chart_first chart_later; do tools/capture.sh $$scene captures/$$scene.png; done
## A5: every kind of point of interest, and the fort and wall state test card. Needs Docker.
poi-captures: import
@for scene in poi_hamlet poi_dock poi_lighthouse poi_quarry poi_salt_works poi_shrine; do tools/capture.sh $$scene captures/$$scene.png; done
build-captures: import
@for scene in build_fort build_fort_side build_states vessels; do tools/capture.sh $$scene captures/$$scene.png; done
## A1: the woodcut print pass on and off, side by side scenes (captures/style_*.png). Needs Docker. ## A1: the woodcut print pass on and off, side by side scenes (captures/style_*.png). Needs Docker.
style-captures: import style-captures: import
@for scene in style_hamlet style_hamlet_plain style_dock style_dock_plain; do tools/capture.sh $$scene captures/$$scene.png; done @for scene in style_hamlet style_hamlet_plain style_dock style_dock_plain; do tools/capture.sh $$scene captures/$$scene.png; done
+6 -1
View File
@@ -2,7 +2,12 @@
Every file under `assets/` is made by a script in this repository. Nothing here is Every file under `assets/` is made by a script in this repository. Nothing here is
sampled, recorded, downloaded or taken from a third party. Colours, shaders and sampled, recorded, downloaded or taken from a third party. Colours, shaders and
meshes built in code are recorded by being in the repository and aren't listed here. meshes built in code are recorded by being in the repository and aren't listed here:
that covers the points of interest (`src/client/poi/poi_mesher.gd`), build pieces
(`src/client/building/piece_mesher.gd`), the barge and sea chests
(`src/client/entities/vessel_models.gd`), props (`src/client/props/prop_view.gd`) and
the terrain and sea shaders. `test/client/test_world_art.gd` fails on any primitive
stand-in mesh or placeholder resource under `src/` or `assets/`.
## Audio (`assets/audio/`, A8) ## Audio (`assets/audio/`, A8)
+28
View File
@@ -42,6 +42,8 @@ or `src/app`, and on any palette colour this table doesn't list. Values are sRGB
| `CRATE_WOOD` | 0.68, 0.55, 0.38 | Unpainted crate wood | | `CRATE_WOOD` | 0.68, 0.55, 0.38 | Unpainted crate wood |
| `BARK` | 0.40, 0.30, 0.22 | Pine bark | | `BARK` | 0.40, 0.30, 0.22 | Pine bark |
| `HOLD_SHADOW` | 0.22, 0.20, 0.18 | Inside an emptied chest or hold | | `HOLD_SHADOW` | 0.22, 0.20, 0.18 | Inside an emptied chest or hold |
| `WINDOW_PANE` | 0.13, 0.16, 0.17 | Window glass from outside |
| `OPENED_DULL` | 0.45, 0.43, 0.42 | Tint over an opened sea chest |
| `CANVAS` | 0.84, 0.80, 0.68 | Rope and sailcloth | | `CANVAS` | 0.84, 0.80, 0.68 | Rope and sailcloth |
| `TANNED_SAIL` | 0.62, 0.44, 0.28 | Bark-tanned sails | | `TANNED_SAIL` | 0.62, 0.44, 0.28 | Bark-tanned sails |
| `STONE` | 0.56, 0.54, 0.49 | Field stone in walls and quays | | `STONE` | 0.56, 0.54, 0.49 | Field stone in walls and quays |
@@ -136,6 +138,32 @@ No shiny plastic, no rim lights, no bloom beyond lamps.
- **Silhouettes first.** Every object reads by outline alone; the ink pass depends on - **Silhouettes first.** Every object reads by outline alone; the ink pass depends on
it. it.
## World art (A5)
Everything in the world is built in code from `Palette` colours; there are no texture
files. The rule is that what is drawn is what blocks: dressing stays inside each
collision box, give or take a few centimetres of lap or trim.
- **Points of interest** (`PoiMesher`): tarred walls are lapped weatherboards, every
other board standing proud; plank is boards (vertical on walls, across decks); stone
is courses in a running bond with the odd lichened block; roofs are rows of ochre
tiles over a dark fascia with a ridge cap; paint carries a salt-white border line;
salt pans are crusted; huts have a shuttered window in each side wall; the light
chamber glows in a tarred frame.
- **Build pieces** (`PieceMesher`) show their state. Building, the strips go up one
after another in quarter steps with nothing behind them. Worn (a third of health
gone), a third of the strips are split short and darkened. Battered (two thirds
gone), a third are knocked out so the dark backing shows, and the rest are split
and charred. `make build-captures` renders the test card (`captures/build_states.png`).
- **The barge and sea chests** (`VesselModels`): a lofted tarred hull with an ochre
rubbing strake under a gored canvas envelope, striped tanned and banded ochre; sea
chests painted sea-green with tarred bands, a salt-white border and a gilt hasp.
- **Terrain** (`terrain.gdshader`): sand with shingle, marsh, grass in tussocks and
wind-dried patches, rock with lichen blotches, pale summits. Fine detail fades out
past about 150 m so it doesn't shimmer.
- **Props** (`PropView`): low-poly pines, scrub, boulders, wrecks and crates, per
vertex coloured and tinted per instance.
## Characters ## Characters
- **Proportions:** about 6.5 heads tall, broad shoulders, heavy boots and coats, hands - **Proportions:** about 6.5 heads tall, broad shoulders, heavy boots and coats, hands
+90 -10
View File
@@ -1,10 +1,24 @@
## Builds meshes for structure pieces from their collision boxes, so what players see is ## Builds meshes for structure pieces from their collision boxes, so what players see is
## what blocks them. Faces are split into planks, stone courses or iron panels, each ## what blocks them. Faces are split into planks, stone courses or iron panels, each
## with its own slight tint, in the weathered palette from docs/STYLE.md. This is ## with its own slight tint, in the weathered palette from docs/STYLE.md.
## a blockout look; the v0.6 art pass replaces it. ##
## A piece shows its state. While it is building, its strips go up one after another
## with nothing behind them, like a frame being filled in. Once damaged it shows wear:
## at WORN a third of the strips are split short and darkened; at BATTERED a third of them are
## gone, so the dark backing shows through, and the rest are cracked and charred.
class_name PieceMesher class_name PieceMesher
extends RefCounted extends RefCounted
## Wear stages, from the share of its health a piece has lost.
const INTACT: int = 0
const WORN: int = 1
const BATTERED: int = 2
## Damage shares (of max health) at which WORN and BATTERED start.
const WORN_AT: float = 0.34
const BATTERED_AT: float = 0.67
## Building shows in this many steps.
const BUILD_STEPS: int = 4
## Base colour per material code, in sRGB. ## Base colour per material code, in sRGB.
const COLOURS: Array[Color] = [Palette.DRIFTWOOD, Palette.DRESSED_STONE, Palette.SALVAGE_IRON] const COLOURS: Array[Color] = [Palette.DRIFTWOOD, Palette.DRESSED_STONE, Palette.SALVAGE_IRON]
## Size of a plank, course or panel, in metres, per material code. ## Size of a plank, course or panel, in metres, per material code.
@@ -14,27 +28,63 @@ const SEAM: float = 0.03
const SEAM_DARKEN: float = 0.45 const SEAM_DARKEN: float = 0.45
## A mesh for a piece of `material` made of `boxes`, with strips tinted from `salt`. ## The wear stage of a piece that has taken `damage` of `max_health`.
static func build(boxes: Array[AABB], material: int, salt: int) -> ArrayMesh: static func wear_of(damage: int, max_health: int) -> int:
var share: float = float(damage) / float(maxi(max_health, 1))
if share >= BATTERED_AT:
return BATTERED
if share >= WORN_AT:
return WORN
return INTACT
## How far a piece's building shows, rounded up to a BUILD_STEPS step: 1.0 when built.
static func built_of(build_ticks_left: int, build_ticks: int) -> float:
if build_ticks <= 0 or build_ticks_left <= 0:
return 1.0
var done: float = 1.0 - float(build_ticks_left) / float(build_ticks)
return maxf(ceilf(done * BUILD_STEPS), 1.0) / BUILD_STEPS
## The state `build()` should show for `piece`: [wear, built].
static func state_of(piece: StructureSet.Piece) -> Array:
return [wear_of(StructureSet.damage_taken(piece), piece.max_health), built_of(piece.build_ticks_left, piece.build_ticks)]
## A mesh for a piece of `material` made of `boxes`, with strips tinted from `salt`,
## showing `wear` and `built` (see the class notes).
static func build(boxes: Array[AABB], material: int, salt: int, wear: int = INTACT, built: float = 1.0) -> ArrayMesh:
var tool: SurfaceTool = SurfaceTool.new() var tool: SurfaceTool = SurfaceTool.new()
tool.begin(Mesh.PRIMITIVE_TRIANGLES) tool.begin(Mesh.PRIMITIVE_TRIANGLES)
var base: Color = COLOURS[clampi(material, 0, COLOURS.size() - 1)] var base: Color = COLOURS[clampi(material, 0, COLOURS.size() - 1)]
var strip: float = STRIP[clampi(material, 0, STRIP.size() - 1)] var strip: float = STRIP[clampi(material, 0, STRIP.size() - 1)]
var index: int = 0 var index: int = 0
for box: AABB in boxes: for box: AABB in boxes:
# Seam colour behind the strips. if built >= 1.0:
_box(tool, box.grow(-SEAM * 0.5), base.darkened(SEAM_DARKEN)) # Seam colour behind the strips, darker the more battered.
_box(tool, box.grow(-SEAM * 0.5), base.darkened(SEAM_DARKEN + 0.15 * wear))
# Wood runs vertically; stone and iron in horizontal bands. # Wood runs vertically; stone and iron in horizontal bands.
var axis: int = 1 if material != Materials.DRIFTWOOD else (0 if box.size.x >= box.size.z else 2) var axis: int = 1 if material != Materials.DRIFTWOOD else (0 if box.size.x >= box.size.z else 2)
if box.size[axis] < strip * 1.5 and axis != 1: if box.size[axis] < strip * 1.5 and axis != 1:
axis = 2 if axis == 0 else 0 axis = 2 if axis == 0 else 0
var count: int = maxi(1, roundi(box.size[axis] / strip)) var count: int = maxi(1, roundi(box.size[axis] / strip))
var step: float = box.size[axis] / count var step: float = box.size[axis] / count
for part: int in count: var shown: int = clampi(ceili(count * built - 0.001), 1, count)
for part: int in shown:
var piece: AABB = box var piece: AABB = box
piece.position[axis] = box.position[axis] + part * step + SEAM * 0.5 piece.position[axis] = box.position[axis] + part * step + SEAM * 0.5
piece.size[axis] = step - SEAM piece.size[axis] = step - SEAM
_box(tool, piece, _tint(base, salt * 131 + index * 17 + part)) var key: int = salt * 131 + index * 17 + part
var colour: Color = _tint(base, key)
if wear != INTACT:
var h: int = hash(key * 40503 + 7)
# A third knocked out, and always at least one where there are three or more.
if wear == BATTERED and (h % 3 == 0 or (count >= 3 and part == posmod(salt + index, count))):
continue # Knocked out.
if h % (2 if wear == BATTERED else 3) == 1:
piece = _split(piece, axis, 0.25 + 0.15 * wear, h)
colour = colour.darkened(0.3 + 0.1 * wear)
_box(tool, piece, colour)
index += 1 index += 1
tool.generate_normals() tool.generate_normals()
var mesh: ArrayMesh = tool.commit() var mesh: ArrayMesh = tool.commit()
@@ -47,10 +97,24 @@ static func build(boxes: Array[AABB], material: int, salt: int) -> ArrayMesh:
return mesh return mesh
## `strip` with `share` of its length broken off one end (which end from `h`). Its
## length runs along the larger of its two axes other than `axis`.
static func _split(strip: AABB, axis: int, share: float, h: int) -> AABB:
var along: int = -1
for candidate: int in [0, 1, 2]:
if candidate != axis and (along < 0 or strip.size[candidate] > strip.size[along]):
along = candidate
var cut: float = strip.size[along] * share
strip.size[along] -= cut
if (h >> 4) % 2 == 0:
strip.position[along] += cut
return strip
## A ramp drawn as a sloped plank deck on a solid wedge, rather than its stair-step ## A ramp drawn as a sloped plank deck on a solid wedge, rather than its stair-step
## collision boxes. The slope runs from the cell's low edge at `base` to its far edge ## collision boxes. The slope runs from the cell's low edge at `base` to its far edge
## one cell up, so the deck passes through the nose of every step. ## one cell up, so the deck passes through the nose of every step.
static func build_ramp(slot: Vector4i, facing: int, material: int, salt: int) -> ArrayMesh: static func build_ramp(slot: Vector4i, facing: int, material: int, salt: int, wear: int = INTACT, built: float = 1.0) -> ArrayMesh:
var g: float = Tuning.GRID_CELL_METRES var g: float = Tuning.GRID_CELL_METRES
var base: Color = COLOURS[clampi(material, 0, COLOURS.size() - 1)] var base: Color = COLOURS[clampi(material, 0, COLOURS.size() - 1)]
var origin: Vector3 = Vector3(slot.x * g, slot.y * Tuning.BUILD_LEVEL_METRES, slot.z * g) var origin: Vector3 = Vector3(slot.x * g, slot.y * Tuning.BUILD_LEVEL_METRES, slot.z * g)
@@ -59,10 +123,16 @@ static func build_ramp(slot: Vector4i, facing: int, material: int, salt: int) ->
tool.begin(Mesh.PRIMITIVE_TRIANGLES) tool.begin(Mesh.PRIMITIVE_TRIANGLES)
tool.set_smooth_group(-1) tool.set_smooth_group(-1)
var planks: int = 8 var planks: int = 8
for plank: int in planks: for plank: int in clampi(ceili(planks * built - 0.001), 1, planks):
var u0: float = (plank + 0.04) / planks var u0: float = (plank + 0.04) / planks
var u1: float = (plank + 0.96) / planks var u1: float = (plank + 0.96) / planks
var colour: Color = _tint(base, salt * 131 + plank) var colour: Color = _tint(base, salt * 131 + plank)
if wear != INTACT:
var h: int = hash((salt * 131 + plank) * 40503 + 7)
if wear == BATTERED and h % 3 == 0 and plank > 0 and plank < planks - 1:
continue # Knocked out; the wedge shows through.
if h % (2 if wear == BATTERED else 4) == 1:
colour = colour.darkened(0.25 + 0.1 * wear)
var corners: Array[Vector3] = [] var corners: Array[Vector3] = []
for corner: Vector2 in [Vector2(u0, 0.0), Vector2(u1, 0.0), Vector2(u1, 1.0), Vector2(u0, 1.0)]: for corner: Vector2 in [Vector2(u0, 0.0), Vector2(u1, 0.0), Vector2(u1, 1.0), Vector2(u0, 1.0)]:
corners.append(origin + _ramp_point(direction, corner.x, corner.y, g) + Vector3(0.0, 0.02, 0.0)) corners.append(origin + _ramp_point(direction, corner.x, corner.y, g) + Vector3(0.0, 0.02, 0.0))
@@ -123,6 +193,16 @@ static func box_mesh(boxes: Array[AABB], colour: Color) -> ArrayMesh:
return tool.commit() return tool.commit()
## Adds a flat-faced box in `colour`. Shared with PoiMesher.
static func add_box(tool: SurfaceTool, box: AABB, colour: Color) -> void:
_box(tool, box, colour)
## `base` shifted slightly in brightness and warmth by a hash of `key`.
static func tint(base: Color, key: int) -> Color:
return _tint(base, key)
static func _tint(base: Color, key: int) -> Color: static func _tint(base: Color, key: int) -> Color:
var h: int = hash(key * 2654435761) var h: int = hash(key * 2654435761)
var shift: float = (float(h & 0xff) / 255.0 - 0.5) * 0.14 var shift: float = (float(h & 0xff) / 255.0 - 0.5) * 0.14
+23 -7
View File
@@ -1,5 +1,6 @@
## Draws every built piece. `sync()` adds a mesh for each piece the simulation has that ## Draws every built piece. `sync()` adds a mesh for each piece the simulation has that
## isn't drawn yet and drops meshes for pieces that are gone. Collision never comes from ## isn't drawn yet, rebuilds it when its building step or wear stage changes (see
## PieceMesher), and drops meshes for pieces that are gone. Collision never comes from
## here; the simulation's SimGround holds the pieces' boxes. ## here; the simulation's SimGround holds the pieces' boxes.
class_name StructureView class_name StructureView
extends Node3D extends Node3D
@@ -7,6 +8,10 @@ extends Node3D
var _structures: StructureSet var _structures: StructureSet
## Piece ID -> MeshInstance3D. ## Piece ID -> MeshInstance3D.
var _drawn: Dictionary = {} var _drawn: Dictionary = {}
## Piece ID -> the [wear, built] state its mesh shows.
var _shown: Dictionary = {}
## Meshes built since setup, for tests.
var meshes_built: int = 0
func setup(structures: StructureSet) -> void: func setup(structures: StructureSet) -> void:
@@ -21,17 +26,28 @@ func sync() -> void:
if _structures.find(piece_id) == null: if _structures.find(piece_id) == null:
_drawn[piece_id].queue_free() _drawn[piece_id].queue_free()
_drawn.erase(piece_id) _drawn.erase(piece_id)
_shown.erase(piece_id)
for piece: StructureSet.Piece in _structures.pieces.values(): for piece: StructureSet.Piece in _structures.pieces.values():
if _drawn.has(piece.id): var state: Array = PieceMesher.state_of(piece)
if _drawn.has(piece.id) and _shown[piece.id] == state:
continue continue
var instance: MeshInstance3D = MeshInstance3D.new() var instance: MeshInstance3D = _drawn.get(piece.id)
if instance == null:
instance = MeshInstance3D.new()
instance.name = "piece_%d" % piece.id instance.name = "piece_%d" % piece.id
if piece.kind == StructureSet.RAMP:
instance.mesh = PieceMesher.build_ramp(piece.slot, piece.facing, piece.material, piece.id)
else:
instance.mesh = PieceMesher.build(piece.boxes, piece.material, piece.id)
add_child(instance) add_child(instance)
_drawn[piece.id] = instance _drawn[piece.id] = instance
if piece.kind == StructureSet.RAMP:
instance.mesh = PieceMesher.build_ramp(piece.slot, piece.facing, piece.material, piece.id, state[0], state[1])
else:
instance.mesh = PieceMesher.build(piece.boxes, piece.material, piece.id, state[0], state[1])
_shown[piece.id] = state
meshes_built += 1
## The [wear, built] state piece `piece_id` is drawn in, or [] if it isn't drawn.
func shown_state(piece_id: int) -> Array:
return _shown.get(piece_id, [])
func drawn_count() -> int: func drawn_count() -> int:
+18 -63
View File
@@ -6,8 +6,8 @@
## simulation replicates about them, with shots, swings and building played from FX ## simulation replicates about them, with shots, swings and building played from FX
## records through hear(). Held and lying items are the models of A4 (ItemModels): a ## records through hear(). Held and lying items are the models of A4 (ItemModels): a
## held one sits with its grip in the figure's right hand and points where its player ## held one sits with its grip in the figure's right hand and points where its player
## looks. The barge and chests are still stand-in shapes. Nothing here is ever used ## looks. The barge and the sea chests are VesselModels, generated in code. Nothing
## for collision. ## here is ever used for collision.
class_name EntityView class_name EntityView
extends Node3D extends Node3D
@@ -17,12 +17,10 @@ const OILSKINS: Array[Color] = [
Palette.OILSKIN_SLATE, Palette.OILSKIN_NAVY, Palette.TANNED_SAIL, Palette.OILSKIN_SLATE, Palette.OILSKIN_NAVY, Palette.TANNED_SAIL,
] ]
const SKIN: Color = Palette.SKIN const SKIN: Color = Palette.SKIN
const CANVAS: Color = Palette.CANVAS ## Chest instance colours, multiplied into the chest model's own: an opened chest
const TAR: Color = Palette.TAR ## shows darker, its paint dulled.
const PLANK: Color = Palette.PLANK const CHEST_SHUT: Color = Color.WHITE
const CHEST_SHUT: Color = Palette.SEA_PAINT const CHEST_OPEN: Color = Palette.OPENED_DULL
const CHEST_OPEN: Color = Palette.HOLD_SHADOW
const ITEM: Color = Palette.GILT
## How far apart passengers stand on the barge's deck, in metres. The simulation ## How far apart passengers stand on the barge's deck, in metres. The simulation
## carries them all at one point; this only spreads them out to be seen. ## carries them all at one point; this only spreads them out to be seen.
const DECK_SPACING: float = 1.3 const DECK_SPACING: float = 1.3
@@ -56,7 +54,7 @@ func setup(sim: Simulation) -> void:
_pickups = Node3D.new() _pickups = Node3D.new()
_pickups.name = "Pickups" _pickups.name = "Pickups"
add_child(_pickups) add_child(_pickups)
_chests = _box_field("Chests", Vector3(0.9, 0.55, 0.6), false) _chests = _chest_field()
add_child(_chests) add_child(_chests)
sync() sync()
@@ -145,7 +143,7 @@ func sync() -> void:
var chests: MultiMesh = _chests.multimesh var chests: MultiMesh = _chests.multimesh
chests.instance_count = _sim.loot.chest_positions.size() chests.instance_count = _sim.loot.chest_positions.size()
for index: int in _sim.loot.chest_positions.size(): for index: int in _sim.loot.chest_positions.size():
chests.set_instance_transform(index, Transform3D(Basis.IDENTITY, _sim.loot.chest_positions[index] + Vector3(0.0, 0.28, 0.0))) chests.set_instance_transform(index, Transform3D(Basis.IDENTITY, _sim.loot.chest_positions[index]))
chests.set_instance_color(index, CHEST_OPEN if _sim.loot.chest_opened[index] != 0 else CHEST_SHUT) chests.set_instance_color(index, CHEST_OPEN if _sim.loot.chest_opened[index] != 0 else CHEST_SHUT)
@@ -231,10 +229,9 @@ func _item_field(key: String) -> MultiMeshInstance3D:
multimesh.transform_format = MultiMesh.TRANSFORM_3D multimesh.transform_format = MultiMesh.TRANSFORM_3D
var mesh: ArrayMesh = ItemModels.model(key.get_slice("@", 0), key.get_slice("@", 1).to_int()) var mesh: ArrayMesh = ItemModels.model(key.get_slice("@", 0), key.get_slice("@", 1).to_int())
if mesh == null: if mesh == null:
var stand_in: BoxMesh = BoxMesh.new() # Every catalogue item has a model (test_item_models); this is a bug.
stand_in.size = Vector3(0.25, 0.25, 0.25) push_error("EntityView: no model for item %s" % key)
multimesh.mesh = stand_in mesh = ArrayMesh.new()
else:
multimesh.mesh = mesh multimesh.mesh = mesh
var field: MultiMeshInstance3D = MultiMeshInstance3D.new() var field: MultiMeshInstance3D = MultiMeshInstance3D.new()
field.name = key.replace("@", "_") field.name = key.replace("@", "_")
@@ -250,64 +247,22 @@ func _build_figure(entity_id: int) -> FigureRig:
return figure return figure
## A flat-bottomed hull hung under a canvas envelope. Its deck is at the origin, where ## The barge (VesselModels): a hull hung under a canvas envelope. Its deck is at the
## the simulation carries the passengers. ## origin, where the simulation carries the passengers.
func _build_barge() -> Node3D: func _build_barge() -> Node3D:
var barge: Node3D = Node3D.new() var barge: MeshInstance3D = MeshInstance3D.new()
barge.name = "Barge" barge.name = "Barge"
var deck: BoxMesh = BoxMesh.new() barge.mesh = VesselModels.barge()
deck.size = Vector3(7.5, 0.3, 11.0)
barge.add_child(_part(deck, PLANK, Vector3(0.0, -0.15, 0.0)))
var hull: BoxMesh = BoxMesh.new()
hull.size = Vector3(6.4, 1.3, 9.6)
barge.add_child(_part(hull, TAR, Vector3(0.0, -0.95, 0.0)))
for side: float in [-1.0, 1.0]:
var rail: BoxMesh = BoxMesh.new()
rail.size = Vector3(0.15, 0.7, 11.0)
barge.add_child(_part(rail, TAR, Vector3(side * 3.68, 0.35, 0.0)))
for end: float in [-1.0, 1.0]:
var rope: CylinderMesh = CylinderMesh.new()
rope.top_radius = 0.05
rope.bottom_radius = 0.05
rope.height = 7.0
barge.add_child(_part(rope, PLANK.darkened(0.3), Vector3(side * 3.4, 3.5, end * 4.6)))
var envelope: SphereMesh = SphereMesh.new()
envelope.radius = 1.0
envelope.height = 2.0
var bag: MeshInstance3D = _part(envelope, CANVAS, Vector3(0.0, 10.5, 0.0))
bag.scale = Vector3(5.2, 3.8, 9.0)
barge.add_child(bag)
return barge return barge
func _part(mesh: PrimitiveMesh, colour: Color, at: Vector3) -> MeshInstance3D: func _chest_field() -> MultiMeshInstance3D:
var material: StandardMaterial3D = StandardMaterial3D.new()
material.albedo_color = colour
material.roughness = 0.85
mesh.material = material
var instance: MeshInstance3D = MeshInstance3D.new()
instance.mesh = mesh
instance.position = at
return instance
func _box_field(node_name: String, size: Vector3, glow: bool) -> MultiMeshInstance3D:
var material: StandardMaterial3D = StandardMaterial3D.new()
material.vertex_color_use_as_albedo = true
material.roughness = 0.7
if glow:
material.emission_enabled = true
material.emission = ITEM
material.emission_energy_multiplier = 0.5
var mesh: BoxMesh = BoxMesh.new()
mesh.size = size
mesh.material = material
var multimesh: MultiMesh = MultiMesh.new() var multimesh: MultiMesh = MultiMesh.new()
multimesh.transform_format = MultiMesh.TRANSFORM_3D multimesh.transform_format = MultiMesh.TRANSFORM_3D
multimesh.use_colors = true multimesh.use_colors = true
multimesh.mesh = mesh multimesh.mesh = VesselModels.chest()
var instance: MultiMeshInstance3D = MultiMeshInstance3D.new() var instance: MultiMeshInstance3D = MultiMeshInstance3D.new()
instance.name = node_name instance.name = "Chests"
instance.multimesh = multimesh instance.multimesh = multimesh
instance.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF instance.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
return instance return instance
+176
View File
@@ -0,0 +1,176 @@
## Generated meshes for the drop barge and the sea chests, built in code from Palette
## colours (no imported art):
##
## - the barge: a tarred, lofted hull with a sheer and pointed ends, a planked deck,
## rails, mooring lines, and a gored canvas envelope with tanned stripes and an ochre
## band, in the folk-art manner of docs/STYLE.md. Its deck top is at the origin, where
## the simulation carries the passengers; it points along +z;
## - a sea chest: a painted box with a lid, tarred iron bands, a salt-white border and a
## gilt hasp, its base at the origin.
class_name VesselModels
extends RefCounted
## Hull half-length, half-breadth at the deck, and depth amidships, in metres.
const HULL_HALF_LENGTH: float = 5.5
const HULL_HALF_BREADTH: float = 3.4
const HULL_DEPTH: float = 1.6
## Envelope centre height above the deck and its semi-axes (x, y, z), in metres.
const ENVELOPE_HEIGHT: float = 10.5
const ENVELOPE_AXES: Vector3 = Vector3(5.2, 3.8, 9.0)
const ENVELOPE_RINGS: int = 14
const ENVELOPE_SIDES: int = 20
## Chest size (x, y, z), in metres; its lid is the top LID share of its height.
const CHEST_SIZE: Vector3 = Vector3(0.9, 0.55, 0.6)
const LID: float = 0.3
static func barge() -> ArrayMesh:
var tool: SurfaceTool = SurfaceTool.new()
tool.begin(Mesh.PRIMITIVE_TRIANGLES)
tool.set_smooth_group(-1)
var rings: Array[PackedVector3Array] = _hull(tool)
# Deck planks run fore and aft, each cut to where the hull is wide enough for it.
var index: int = 0
var x: float = -HULL_HALF_BREADTH + 0.2
while x < HULL_HALF_BREADTH - 0.2:
var width: float = minf(0.32, HULL_HALF_BREADTH - 0.2 - x)
var outer: float = maxf(absf(x), absf(x + width)) + 0.15
var reach: float = HULL_HALF_LENGTH * pow(maxf(1.0 - pow(outer / HULL_HALF_BREADTH, 2.0), 0.0), 0.25) - 0.1
if reach > 0.3:
var plank: AABB = AABB(Vector3(x + 0.015, -0.12, -reach), Vector3(width - 0.03, 0.12, 2.0 * reach))
PieceMesher.add_box(tool, plank, PieceMesher.tint(Palette.PLANK, 9001 + index))
x += 0.32
index += 1
# Rails follow the sheer on stanchions at every station.
var rail: Vector3 = Vector3(0.0, 0.65, 0.0)
for side: int in [0, 4]:
var inward: Vector3 = Vector3(0.12 if side == 0 else -0.12, 0.0, 0.0)
for station: int in rings.size():
var at: Vector3 = rings[station][side] + inward
_line(tool, at, at + rail, 0.1, Palette.TAR)
if station + 1 < rings.size():
_line(tool, at + rail, rings[station + 1][side] + inward + rail, 0.1, Palette.TAR)
for side: float in [-1.0, 1.0]:
# Mooring lines from the rail to the envelope's belly.
for end: float in [-1.0, 1.0]:
var foot: Vector3 = Vector3(side * (HULL_HALF_BREADTH - 0.35), 0.6, end * 3.6)
var hx: float = 0.55
var hz: float = 0.5
var under: float = ENVELOPE_AXES.y * sqrt(1.0 - hx * hx - hz * hz)
var head: Vector3 = Vector3(side * ENVELOPE_AXES.x * hx, ENVELOPE_HEIGHT - under + 0.15, end * ENVELOPE_AXES.z * hz)
_line(tool, foot, head, 0.05, Palette.PLANK.darkened(0.3))
_envelope(tool)
tool.generate_normals()
var mesh: ArrayMesh = tool.commit()
mesh.surface_set_material(0, _material(0.85))
return mesh
static func chest() -> ArrayMesh:
var tool: SurfaceTool = SurfaceTool.new()
tool.begin(Mesh.PRIMITIVE_TRIANGLES)
tool.set_smooth_group(-1)
var s: Vector3 = CHEST_SIZE
var lid_y: float = s.y * (1.0 - LID)
var body: AABB = AABB(Vector3(-s.x * 0.5, 0.0, -s.z * 0.5), Vector3(s.x, lid_y, s.z))
PieceMesher.add_box(tool, body, Palette.SEA_PAINT)
var lid: AABB = AABB(Vector3(-s.x * 0.5 - 0.02, lid_y, -s.z * 0.5 - 0.02), Vector3(s.x + 0.04, s.y - lid_y, s.z + 0.04))
PieceMesher.add_box(tool, lid, Palette.SEA_PAINT.darkened(0.12))
# Salt-white border round the body, just under the lid.
PieceMesher.add_box(tool, AABB(Vector3(-s.x * 0.5 - 0.01, lid_y - 0.08, -s.z * 0.5 - 0.01), Vector3(s.x + 0.02, 0.035, s.z + 0.02)), Palette.SALT)
# Iron bands over the lid and down the sides, and the gilt hasp at the front.
for x: float in [-s.x * 0.3, s.x * 0.3]:
PieceMesher.add_box(tool, AABB(Vector3(x - 0.04, 0.0, -s.z * 0.5 - 0.03), Vector3(0.08, s.y + 0.01, s.z + 0.06)), Palette.TAR)
PieceMesher.add_box(tool, AABB(Vector3(-0.06, lid_y - 0.14, s.z * 0.5), Vector3(0.12, 0.18, 0.04)), Palette.GILT)
tool.generate_normals()
var mesh: ArrayMesh = tool.commit()
mesh.surface_set_material(0, _material(0.7))
return mesh
## The hull as rings of five points (rail, bilge, keel, bilge, rail) along z. Returns
## the rings, for the rails.
static func _hull(tool: SurfaceTool) -> Array[PackedVector3Array]:
var stations: int = 12
var rings: Array[PackedVector3Array] = []
for station: int in stations + 1:
var t: float = float(station) / stations * 2.0 - 1.0
var z: float = t * HULL_HALF_LENGTH
var breadth: float = HULL_HALF_BREADTH * sqrt(maxf(1.0 - pow(absf(t), 4.0), 0.015))
var keel: float = -HULL_DEPTH * (1.0 - 0.55 * pow(absf(t), 3.0))
var sheer: float = 0.25 * t * t
var ring: PackedVector3Array = PackedVector3Array([
Vector3(-breadth, sheer, z), Vector3(-breadth * 0.8, keel * 0.6, z), Vector3(0.0, keel, z),
Vector3(breadth * 0.8, keel * 0.6, z), Vector3(breadth, sheer, z),
])
rings.append(ring)
for station: int in stations:
for side: int in 4:
var colour: Color = Palette.TAR if side == 1 or side == 2 else Palette.TAR_WEATHERED
# A painted strake under the rail, every other station a shade lighter.
if side == 0 or side == 3:
colour = PieceMesher.tint(colour, station * 7 + side)
_quad(tool, rings[station][side], rings[station][side + 1], rings[station + 1][side + 1], rings[station + 1][side], colour)
# Rubbing strake: an ochre band along the top of the hull.
for station: int in stations:
for side: int in [0, 4]:
var a: Vector3 = rings[station][side]
var b: Vector3 = rings[station + 1][side]
var out: float = 0.04 * signf(a.x) if absf(a.x) > 0.01 else 0.0
var drop: Vector3 = Vector3(0.0, -0.22, 0.0)
_quad(tool, a + Vector3(out, 0.0, 0.0), b + Vector3(out, 0.0, 0.0), b + drop + Vector3(out, 0.0, 0.0), a + drop + Vector3(out, 0.0, 0.0), Palette.OCHRE_RED)
return rings
## The envelope: an ellipsoid of gores along z, alternately canvas and tanned, with an
## ochre band round its middle.
static func _envelope(tool: SurfaceTool) -> void:
var centre: Vector3 = Vector3(0.0, ENVELOPE_HEIGHT, 0.0)
var rings: Array[PackedVector3Array] = []
for ring: int in ENVELOPE_RINGS + 1:
var phi: float = PI * float(ring) / ENVELOPE_RINGS
var z: float = -cos(phi) * ENVELOPE_AXES.z
var r: float = sin(phi)
var points: PackedVector3Array = PackedVector3Array()
for side: int in ENVELOPE_SIDES + 1:
var theta: float = TAU * float(side) / ENVELOPE_SIDES
points.append(centre + Vector3(cos(theta) * r * ENVELOPE_AXES.x, sin(theta) * r * ENVELOPE_AXES.y, z))
rings.append(points)
var middle: int = ENVELOPE_RINGS / 2
tool.set_smooth_group(1)
for ring: int in ENVELOPE_RINGS:
for side: int in ENVELOPE_SIDES:
var colour: Color = Palette.CANVAS if (side / 2) % 2 == 0 else Palette.TANNED_SAIL.lightened(0.15)
if ring == middle or ring == middle - 1:
colour = Palette.OCHRE_RED
_quad(tool, rings[ring][side], rings[ring][side + 1], rings[ring + 1][side + 1], rings[ring + 1][side], colour)
tool.set_smooth_group(-1)
## A square line `width` thick from `a` to `b`.
static func _line(tool: SurfaceTool, a: Vector3, b: Vector3, width: float, colour: Color) -> void:
var along: Vector3 = (b - a).normalized()
var side: Vector3 = along.cross(Vector3.FORWARD if absf(along.z) < 0.9 else Vector3.RIGHT).normalized() * width * 0.5
var up: Vector3 = along.cross(side).normalized() * width * 0.5
var corners: Array[Vector3] = [side + up, -side + up, -side - up, side - up]
for index: int in 4:
var c0: Vector3 = corners[index]
var c1: Vector3 = corners[(index + 1) % 4]
_quad(tool, a + c0, a + c1, b + c1, b + c0, colour)
## A quad. The material draws both sides, so the order of its corners doesn't matter.
static func _quad(tool: SurfaceTool, a: Vector3, b: Vector3, c: Vector3, d: Vector3, colour: Color) -> void:
tool.set_color(colour)
for point: Vector3 in [a, b, c, a, c, d]:
tool.add_vertex(point)
static func _material(roughness: float) -> StandardMaterial3D:
var material: StandardMaterial3D = StandardMaterial3D.new()
material.vertex_color_use_as_albedo = true
material.vertex_color_is_srgb = true
material.roughness = roughness
material.cull_mode = BaseMaterial3D.CULL_DISABLED
return material
+1
View File
@@ -0,0 +1 @@
uid://b6u71jxsh531
+302
View File
@@ -0,0 +1,302 @@
## Builds the meshes for one point of interest from its render parts. Each part is a box
## with a look; the mesher dresses it by shape and look so a hut reads as lapped tarred
## boards on coursed stone under a tiled roof, not as coloured boxes:
##
## - tarred wood: lapped horizontal weatherboards, alternate boards standing proud;
## - plank: boards across the long side of a deck, vertical on walls;
## - stone: courses of blocks in a running bond, some with lichen;
## - roof: rows of tiles over a darker fascia, with a ridge cap;
## - paint: the colour with a salt-white border line, the folk-art trim;
## - salt: a pale pan crusted with lumps;
## - window: a painted frame and cross bars over a dark pane;
## - lamp: the lit glass, on its own glowing surface, in a tarred frame.
##
## Everything is vertex-coloured from Palette and tinted per board or block from a hash
## of its position, so the same island always looks the same. What is drawn stays
## within a few centimetres of a part's box (lapped boards and trim stand just proud),
## so what players see is what blocks them.
class_name PoiMesher
extends RefCounted
## Boards on tarred-wood walls, and on plank walls and decks, in metres.
const WEATHERBOARD: float = 0.26
const BOARD: float = 0.3
## How far alternate weatherboards stand out of the wall, in metres.
const LAP: float = 0.018
## Stone course height and block length, in metres.
const COURSE: float = 0.42
const BLOCK: float = 0.85
## Roof tile row depth and tile length, in metres.
const TILE_ROW: float = 0.45
const TILE: float = 0.9
const SEAM: float = 0.025
## A part thinner than this on a horizontal axis is a wall or a post; lower than this
## is a slab (a floor, deck, roof or pan).
const THIN: float = 0.45
const LOW: float = 0.45
## Surface indices in the mesh `build()` returns.
const SURFACE_SOLID: int = 0
const SURFACE_LAMP: int = 1
## The mesh for `parts` ({"box": AABB, "look": String}, in world space), with the
## vertex-coloured parts in surface 0 and any lamp glass in surface 1.
static func build(parts: Array[Dictionary]) -> ArrayMesh:
var tool: SurfaceTool = SurfaceTool.new()
tool.begin(Mesh.PRIMITIVE_TRIANGLES)
tool.set_smooth_group(-1)
var lamps: Array[AABB] = []
for part: Dictionary in parts:
var box: AABB = part["box"]
match String(part["look"]):
Poi.LOOK_TARRED_WOOD:
_tarred_wood(tool, box)
Poi.LOOK_PLANK:
_plank(tool, box)
Poi.LOOK_STONE:
_stone(tool, box)
Poi.LOOK_ROOF:
_roof(tool, box)
Poi.LOOK_PAINT:
_paint(tool, box)
Poi.LOOK_SALT:
_salt(tool, box)
Poi.LOOK_WINDOW:
_window(tool, box)
Poi.LOOK_LAMP:
lamps.append(box)
_lamp_frame(tool, box)
_:
PieceMesher.add_box(tool, box, Palette.PLANK)
tool.generate_normals()
var mesh: ArrayMesh = tool.commit()
var surface: StandardMaterial3D = StandardMaterial3D.new()
surface.vertex_color_use_as_albedo = true
surface.vertex_color_is_srgb = true
surface.roughness = 0.9
mesh.surface_set_material(SURFACE_SOLID, surface)
if not lamps.is_empty():
var glass: SurfaceTool = SurfaceTool.new()
glass.begin(Mesh.PRIMITIVE_TRIANGLES)
glass.set_smooth_group(-1)
for box: AABB in lamps:
PieceMesher.add_box(glass, box.grow(-0.04), Palette.LAMP)
glass.generate_normals()
glass.commit(mesh)
var lit: StandardMaterial3D = StandardMaterial3D.new()
lit.albedo_color = Palette.LAMP
lit.roughness = 0.3
lit.emission_enabled = true
lit.emission = Palette.LAMP
lit.emission_energy_multiplier = 1.6
mesh.surface_set_material(SURFACE_LAMP, lit)
return mesh
## The longer and the shorter horizontal axis of `box` (0 for x, 2 for z).
static func long_axis(box: AABB) -> int:
return 0 if box.size.x >= box.size.z else 2
static func short_axis(box: AABB) -> int:
return 2 if box.size.x >= box.size.z else 0
static func is_wall(box: AABB) -> bool:
return box.size.y > 1.0 and box.size[short_axis(box)] <= THIN and box.size[long_axis(box)] > THIN
static func is_slab(box: AABB) -> bool:
return box.size.y <= LOW and box.size[short_axis(box)] > THIN
## A stable key for tints from a box's position.
static func _key(box: AABB, extra: int = 0) -> int:
return roundi(box.position.x * 7.0) * 73856093 ^ roundi(box.position.y * 7.0) * 19349663 ^ roundi(box.position.z * 7.0) * 83492791 ^ extra
## Cuts `box` along `axis` into strips about `width` wide, separated by seams.
static func strips(box: AABB, axis: int, width: float) -> Array[AABB]:
var strips: Array[AABB] = []
var count: int = maxi(1, roundi(box.size[axis] / width))
var step: float = box.size[axis] / count
var seam: float = minf(SEAM, step * 0.2)
for index: int in count:
var strip: AABB = box
strip.position[axis] = box.position[axis] + index * step + seam * 0.5
strip.size[axis] = step - seam
strips.append(strip)
return strips
static func _tarred_wood(tool: SurfaceTool, box: AABB) -> void:
if box.size.x <= THIN and box.size.z <= THIN:
# A pile or post: one tarred timber.
PieceMesher.add_box(tool, box, PieceMesher.tint(Palette.TAR, _key(box)))
return
PieceMesher.add_box(tool, box.grow(-SEAM), Palette.TAR.darkened(0.4))
var thin: int = short_axis(box)
var index: int = 0
for board: AABB in strips(box, 1, WEATHERBOARD):
if index % 2 == 1 and box.size[thin] <= THIN:
board.position[thin] -= LAP
board.size[thin] += 2.0 * LAP
PieceMesher.add_box(tool, board, PieceMesher.tint(Palette.TAR, _key(box, index)))
index += 1
static func _plank(tool: SurfaceTool, box: AABB) -> void:
if box.size.x <= THIN and box.size.z <= THIN:
# A post: one tinted timber with a darker foot.
var foot: AABB = box
foot.size.y = minf(0.5, box.size.y * 0.3)
PieceMesher.add_box(tool, foot, Palette.TAR_WEATHERED)
var rest: AABB = box
rest.position.y += foot.size.y
rest.size.y -= foot.size.y
PieceMesher.add_box(tool, rest, PieceMesher.tint(Palette.PLANK, _key(box)))
return
_boards(tool, box, Palette.PLANK, BOARD)
## Boards: vertical on a wall, across the long side of anything else.
static func _boards(tool: SurfaceTool, box: AABB, base: Color, width: float) -> void:
PieceMesher.add_box(tool, box.grow(-SEAM), base.darkened(0.45))
var index: int = 0
for board: AABB in strips(box, long_axis(box), width):
PieceMesher.add_box(tool, board, PieceMesher.tint(base, _key(box, index)))
index += 1
static func _stone(tool: SurfaceTool, box: AABB) -> void:
PieceMesher.add_box(tool, box.grow(-SEAM), Palette.STONE.darkened(0.5))
var along: int = long_axis(box)
var course: int = 0
for row: AABB in strips(box, 1, COURSE):
# Running bond: every other course starts half a block along.
var length: float = box.size[along]
var count: int = maxi(1, roundi(length / BLOCK))
var step: float = length / count
var offset: float = step * 0.5 if course % 2 == 1 and count > 1 else 0.0
var cuts: PackedFloat32Array = PackedFloat32Array([0.0])
for index: int in count + 1:
var at: float = offset + index * step
if at > 0.05 and at < length - 0.05:
cuts.append(at)
cuts.append(length)
for index: int in cuts.size() - 1:
var block: AABB = row
block.position[along] = box.position[along] + cuts[index] + SEAM * 0.5
block.size[along] = cuts[index + 1] - cuts[index] - SEAM
var key: int = _key(box, course * 97 + index)
var colour: Color = PieceMesher.tint(Palette.STONE, key)
if (key >> 11) % 7 == 0:
colour = colour.lerp(Palette.LICHEN, 0.45)
PieceMesher.add_box(tool, block, colour)
course += 1
static func _roof(tool: SurfaceTool, box: AABB) -> void:
if not is_slab(box):
PieceMesher.add_box(tool, box, PieceMesher.tint(Palette.OCHRE_RED, _key(box)))
return
# The fascia: the slab, darker, a little inside the tiles.
var fascia: AABB = box.grow(-0.04)
fascia.size.y = box.size.y * 0.7
PieceMesher.add_box(tool, fascia, Palette.OCHRE_RED.darkened(0.45))
var along: int = long_axis(box)
var across: int = short_axis(box)
var row_index: int = 0
var rows: Array[AABB] = strips(box, across, TILE_ROW)
var middle: int = rows.size() / 2
for row: AABB in rows:
if row_index == middle and rows.size() >= 3:
# The ridge cap: one long darker tile along the middle, flush with the top.
var ridge: AABB = row
ridge.position.y = box.position.y + box.size.y * 0.5
ridge.size.y = box.size.y * 0.5
PieceMesher.add_box(tool, ridge, Palette.OCHRE_RED.darkened(0.3))
row_index += 1
continue
# Tiles sit in the upper part of the slab, alternate rows a touch higher.
row.position.y = box.position.y + box.size.y * 0.55
row.size.y = box.size.y * (0.45 if row_index % 2 == 0 else 0.4)
if row_index % 2 == 1:
row.position.y += box.size.y * 0.05
var tile_index: int = 0
for tile: AABB in strips(row, along, TILE):
PieceMesher.add_box(tool, tile, PieceMesher.tint(Palette.OCHRE_RED, _key(box, row_index * 131 + tile_index)))
tile_index += 1
row_index += 1
static func _paint(tool: SurfaceTool, box: AABB) -> void:
PieceMesher.add_box(tool, box, PieceMesher.tint(Palette.SEA_PAINT, _key(box)))
if box.size.y < 0.6 or box.size[long_axis(box)] < 1.0:
return
# A salt-white line just inside the top and bottom edges, standing out of every side.
for at: float in [box.position.y + 0.1, box.end.y - 0.16]:
var line: AABB = box.grow(0.012)
line.position.y = at
line.size.y = 0.06
PieceMesher.add_box(tool, line, Palette.SALT)
static func _salt(tool: SurfaceTool, box: AABB) -> void:
PieceMesher.add_box(tool, box, Palette.SALT.darkened(0.08))
if not is_slab(box):
return
# Crust: low heaps raked across the pan, kept inside its box.
var count: int = clampi(roundi(box.size.x * box.size.z / 2.5), 1, 24)
for index: int in count:
var h: int = hash(_key(box, index * 7919))
var u: float = float(h & 0xffff) / 65535.0
var v: float = float((h >> 16) & 0x7fff) / 32767.0
var size: Vector3 = Vector3(0.5 + 0.6 * u, 0.06 + 0.05 * v, 0.4 + 0.5 * v)
size.x = minf(size.x, box.size.x * 0.8)
size.z = minf(size.z, box.size.z * 0.8)
var at: Vector3 = Vector3(
box.position.x + (box.size.x - size.x) * u,
box.end.y - size.y,
box.position.z + (box.size.z - size.z) * v)
PieceMesher.add_box(tool, AABB(at, size), Palette.SALT.lightened(0.05 * u))
static func _window(tool: SurfaceTool, box: AABB) -> void:
var thin: int = 0 if box.size.x <= box.size.z else 2
var wide: int = 2 if thin == 0 else 0
PieceMesher.add_box(tool, box, Palette.SEA_PAINT)
var pane: AABB = box
pane.position[thin] -= 0.01
pane.size[thin] += 0.02
pane.position[wide] += 0.09
pane.size[wide] -= 0.18
pane.position.y += 0.09
pane.size.y -= 0.18
PieceMesher.add_box(tool, pane, Palette.WINDOW_PANE)
var bar_out: AABB = box
bar_out.position[thin] -= 0.02
bar_out.size[thin] += 0.04
var upright: AABB = bar_out
upright.position[wide] = box.get_center()[wide] - 0.03
upright.size[wide] = 0.06
PieceMesher.add_box(tool, upright, Palette.SEA_PAINT)
var rail: AABB = bar_out
rail.position.y = box.get_center().y - 0.03
rail.size.y = 0.06
PieceMesher.add_box(tool, rail, Palette.SEA_PAINT)
## The tarred frame of a light chamber: corner posts, middle bars and a sill.
static func _lamp_frame(tool: SurfaceTool, box: AABB) -> void:
var bar: float = 0.14
for x: float in [box.position.x, box.get_center().x - bar * 0.5, box.end.x - bar]:
for z: float in [box.position.z, box.get_center().z - bar * 0.5, box.end.z - bar]:
if x != box.position.x and x != box.end.x - bar and z != box.position.z and z != box.end.z - bar:
continue # Not the middle of the chamber.
PieceMesher.add_box(tool, AABB(Vector3(x, box.position.y, z), Vector3(bar, box.size.y, bar)), Palette.TAR)
var sill: AABB = box
sill.size.y = 0.2
PieceMesher.add_box(tool, sill, Palette.TAR)
+1
View File
@@ -0,0 +1 @@
uid://c35b5ggtxp7uw
+8 -47
View File
@@ -1,54 +1,15 @@
## Draws an island's points of interest from their parts: one MultiMesh of boxes per ## Draws an island's points of interest. PoiMesher dresses each one's parts in boards,
## look, so the whole set costs a handful of draw calls. Colours follow the weathered ## stone courses, tiles and trim from the weathered palette in docs/STYLE.md; each point
## seafaring palette in docs/STYLE.md: tarred wood, grey planks, stone, faded red ## of interest is one mesh, so the whole set costs a few dozen draw calls.
## roofs, salt-faded paint and white salt. No textures; the art pass replaces these.
class_name PoiView class_name PoiView
extends Node3D extends Node3D
const LOOKS: Dictionary = {
Poi.LOOK_TARRED_WOOD: {"colour": Palette.TAR, "roughness": 0.7},
Poi.LOOK_PLANK: {"colour": Palette.PLANK, "roughness": 0.9},
Poi.LOOK_STONE: {"colour": Palette.STONE, "roughness": 0.95},
Poi.LOOK_ROOF: {"colour": Palette.OCHRE_RED, "roughness": 0.85},
Poi.LOOK_PAINT: {"colour": Palette.SEA_PAINT, "roughness": 0.8},
Poi.LOOK_SALT: {"colour": Palette.SALT, "roughness": 0.6},
Poi.LOOK_LAMP: {"colour": Palette.LAMP, "roughness": 0.3, "glow": 1.6},
}
func setup(placed: PoiSet) -> void: func setup(placed: PoiSet) -> void:
var by_look: Dictionary = {} var index: int = 0
for poi: Poi in placed.pois: for poi: Poi in placed.pois:
for part: Dictionary in poi.parts: var instance: MeshInstance3D = MeshInstance3D.new()
var look: String = part["look"] instance.name = "%s_%d" % [poi.kind, index]
if not by_look.has(look): instance.mesh = PoiMesher.build(poi.parts)
by_look[look] = []
(by_look[look] as Array).append(part["box"])
for look: String in by_look:
var boxes: Array = by_look[look]
var mesh: BoxMesh = BoxMesh.new()
mesh.size = Vector3.ONE
mesh.material = _material(look)
var multimesh: MultiMesh = MultiMesh.new()
multimesh.transform_format = MultiMesh.TRANSFORM_3D
multimesh.mesh = mesh
multimesh.instance_count = boxes.size()
for index: int in boxes.size():
var box: AABB = boxes[index]
multimesh.set_instance_transform(index, Transform3D(Basis.from_scale(box.size), box.get_center()))
var instance: MultiMeshInstance3D = MultiMeshInstance3D.new()
instance.name = look
instance.multimesh = multimesh
add_child(instance) add_child(instance)
index += 1
func _material(look: String) -> StandardMaterial3D:
var spec: Dictionary = LOOKS.get(look, LOOKS[Poi.LOOK_PLANK])
var material: StandardMaterial3D = StandardMaterial3D.new()
material.albedo_color = spec["colour"]
material.roughness = spec["roughness"]
if spec.has("glow"):
material.emission_enabled = true
material.emission = spec["colour"]
material.emission_energy_multiplier = spec["glow"]
return material
+4
View File
@@ -59,6 +59,10 @@ const OILSKIN_NAVY: Color = Color(0.30, 0.36, 0.48)
const GILT: Color = Color(0.93, 0.80, 0.42) const GILT: Color = Color(0.93, 0.80, 0.42)
## Lamp glass, lit. ## Lamp glass, lit.
const LAMP: Color = Color(0.98, 0.86, 0.55) const LAMP: Color = Color(0.98, 0.86, 0.55)
## Window glass seen from outside, by day.
const WINDOW_PANE: Color = Color(0.13, 0.16, 0.17)
## Multiplied into a chest once it has been opened, dulling its paint.
const OPENED_DULL: Color = Color(0.45, 0.43, 0.42)
## Weathered skin. ## Weathered skin.
const SKIN: Color = Color(0.74, 0.58, 0.46) const SKIN: Color = Color(0.74, 0.58, 0.46)
+13
View File
@@ -52,13 +52,26 @@ void fragment() {
float broad = fbm(p * 0.035); float broad = fbm(p * 0.035);
float fine = fbm(p * 0.6); float fine = fbm(p * 0.6);
float clumps = fbm(p * 0.16 + vec2(17.0, 3.0));
float grain = value_noise(p * 3.1);
// Detail fades with distance so it doesn't shimmer far off.
float near = 1.0 - smoothstep(40.0, 160.0, length(world_position - CAMERA_POSITION_WORLD));
float ripple = 0.5 + 0.5 * sin(dot(p, vec2(0.55, 0.32)) + broad * 9.0); float ripple = 0.5 + 0.5 * sin(dot(p, vec2(0.55, 0.32)) + broad * 9.0);
vec3 sand = sand_colour * (0.9 + 0.12 * fine) * (0.97 + 0.04 * ripple); vec3 sand = sand_colour * (0.9 + 0.12 * fine) * (0.97 + 0.04 * ripple);
// Shingle: dark pebbles scattered on the sand.
sand = mix(sand, rock_colour * 0.75, near * 0.6 * step(0.86, grain) * step(0.45, clumps));
vec3 marsh = mix(marsh_colour * 0.75, marsh_colour * 1.1, smoothstep(0.35, 0.65, broad + 0.2 * fine)); vec3 marsh = mix(marsh_colour * 0.75, marsh_colour * 1.1, smoothstep(0.35, 0.65, broad + 0.2 * fine));
vec3 grass = grass_colour * (0.78 + 0.35 * broad) * (0.9 + 0.15 * fine); vec3 grass = grass_colour * (0.78 + 0.35 * broad) * (0.9 + 0.15 * fine);
grass = mix(grass, grass * vec3(1.15, 1.05, 0.7), smoothstep(0.55, 0.75, broad)); grass = mix(grass, grass * vec3(1.15, 1.05, 0.7), smoothstep(0.55, 0.75, broad));
// Tussocks: darker clumps of rough grass, and paler wind-dried patches between them.
grass *= mix(1.0, 0.8, smoothstep(0.5, 0.68, clumps));
grass = mix(grass, grass * vec3(1.12, 1.08, 0.82), 0.6 * smoothstep(0.3, 0.18, clumps));
grass *= 1.0 - near * 0.12 * smoothstep(0.55, 0.9, grain);
float strata = 0.5 + 0.5 * sin(world_position.y * 2.1 + broad * 5.0); float strata = 0.5 + 0.5 * sin(world_position.y * 2.1 + broad * 5.0);
vec3 rock = rock_colour * (0.82 + 0.22 * fine + 0.1 * strata); vec3 rock = rock_colour * (0.82 + 0.22 * fine + 0.1 * strata);
// Lichen crusts in blotches.
rock = mix(rock, vec3(0.62, 0.61, 0.45) * (0.9 + 0.2 * fine), 0.45 * smoothstep(0.6, 0.72, clumps));
vec3 summit = summit_colour * (0.88 + 0.14 * fine); vec3 summit = summit_colour * (0.88 + 0.14 * fine);
rock = mix(rock, summit, 0.8 * smoothstep(summit_height - 2.0, summit_height + 6.0, world_position.y + 3.0 * broad)); rock = mix(rock, summit, 0.8 * smoothstep(summit_height - 2.0, summit_height + 6.0, world_position.y + 3.0 * broad));
+19
View File
@@ -15,6 +15,7 @@ const LOOK_ROOF: String = "roof"
const LOOK_PAINT: String = "paint" const LOOK_PAINT: String = "paint"
const LOOK_SALT: String = "salt" const LOOK_SALT: String = "salt"
const LOOK_LAMP: String = "lamp" const LOOK_LAMP: String = "lamp"
const LOOK_WINDOW: String = "window"
const WALL: float = 0.3 const WALL: float = 0.3
const DOOR_WIDTH: float = 1.4 const DOOR_WIDTH: float = 1.4
@@ -154,6 +155,11 @@ func hut(centre: Vector3, width: float, depth: float, height: float, wall_look:
box(Vector3(x0 + side_width - 0.12, floor_y, z0 + depth), Vector3(0.12, DOOR_HEIGHT, 0.06), LOOK_PAINT, false) box(Vector3(x0 + side_width - 0.12, floor_y, z0 + depth), Vector3(0.12, DOOR_HEIGHT, 0.06), LOOK_PAINT, false)
box(Vector3(x0 + side_width + DOOR_WIDTH, floor_y, z0 + depth), Vector3(0.12, DOOR_HEIGHT, 0.06), LOOK_PAINT, false) box(Vector3(x0 + side_width + DOOR_WIDTH, floor_y, z0 + depth), Vector3(0.12, DOOR_HEIGHT, 0.06), LOOK_PAINT, false)
if wall_look != LOOK_STONE:
# A shuttered window in each side wall. Decoration only: the wall stays whole.
for outside: float in [x0 - 0.03, x0 + width - 0.03]:
window(Vector3(outside, floor_y + 1.05, centre.z - 0.45), Vector3(0.06, 0.9, 0.9))
var door: Vector3 = Vector3(centre.x, floor_y, z0 + depth) var door: Vector3 = Vector3(centre.x, floor_y, z0 + depth)
var foot: Vector3 = steps_down(door, Vector3(0.0, 0.0, 1.0), DOOR_WIDTH + 0.4, LOOK_STONE) var foot: Vector3 = steps_down(door, Vector3(0.0, 0.0, 1.0), DOOR_WIDTH + 0.4, LOOK_STONE)
var inside: Vector3 = Vector3(centre.x, floor_y, z0 + depth - 1.2) var inside: Vector3 = Vector3(centre.x, floor_y, z0 + depth - 1.2)
@@ -162,6 +168,19 @@ func hut(centre: Vector3, width: float, depth: float, height: float, wall_look:
add_route([foot + Vector3(0.0, 0.0, 1.5), foot, door, inside, marker]) add_route([foot + Vector3(0.0, 0.0, 1.5), foot, door, inside, marker])
## A window on a wall's outside face, with a painted shutter either side. Not solid.
## `size` is thin along x or z, the axis the window faces.
func window(local_min: Vector3, size: Vector3) -> void:
box(local_min, size, LOOK_WINDOW, false)
var shutter: float = 0.42
if size.x <= size.z:
for z: float in [local_min.z - shutter - 0.04, local_min.z + size.z + 0.04]:
box(Vector3(local_min.x - 0.01, local_min.y - 0.05, z), Vector3(size.x + 0.02, size.y + 0.1, shutter), LOOK_PAINT, false)
else:
for x: float in [local_min.x - shutter - 0.04, local_min.x + size.x + 0.04]:
box(Vector3(x, local_min.y - 0.05, local_min.z - 0.01), Vector3(shutter, size.y + 0.1, size.z + 0.02), LOOK_PAINT, false)
func add_loot(local: Vector3) -> void: func add_loot(local: Vector3) -> void:
loot.append(to_world(local)) loot.append(to_world(local))
+51
View File
@@ -1,10 +1,14 @@
## Capture scenario for building (B2): a small fort of every piece kind in all three ## 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. ## 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 extends Node3D
@export var island_seed: int = 2 @export var island_seed: int = 2
## Camera offset from the fort's corner: x east, y up, z south. ## 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 view: Vector3 = Vector3(-11.0, 8.5, -12.0)
@export var states: bool = false
func _ready() -> void: func _ready() -> void:
@@ -24,6 +28,9 @@ func _ready() -> void:
feet.y = sim.ground.terrain_height(feet.x, feet.z) feet.y = sim.ground.terrain_height(feet.x, feet.z)
var level: int = roundi(feet.y / Tuning.BUILD_LEVEL_METRES) var level: int = roundi(feet.y / Tuning.BUILD_LEVEL_METRES)
var up: int = roundi(g / 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] = [] var placed: Array[String] = []
# A two-cell room: floor, walls in three materials, a roof, a ramp up its side and a # 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. # 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]) var result: Building.Result = Building.place(sim, builder, at, entry[3])
placed.append("%s %s" % [StructureSet.KINDS[at.kind], Building.Result.keys()[result]]) placed.append("%s %s" % [StructureSet.KINDS[at.kind], Building.Result.keys()[result]])
print("build_scene: site %s level %d: %s" % [site, level, ", ".join(placed)]) print("build_scene: site %s level %d: %s" % [site, level, ", ".join(placed)])
_finish_building(sim)
_environment() _environment()
var structures: StructureView = StructureView.new() var structures: StructureView = StructureView.new()
@@ -92,6 +100,49 @@ func _ready() -> void:
add_child(water) 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: 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)) var command: PlayerCommand = PlayerCommand.from_input(0, Vector2.ZERO, deg_to_rad(yaw_degrees), deg_to_rad(pitch_degrees))
player.yaw = command.yaw 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