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:
@@ -1,10 +1,24 @@
|
||||
## 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
|
||||
## with its own slight tint, in the weathered palette from docs/STYLE.md. This is
|
||||
## a blockout look; the v0.6 art pass replaces it.
|
||||
## with its own slight tint, in the weathered palette from docs/STYLE.md.
|
||||
##
|
||||
## 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
|
||||
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.
|
||||
const COLOURS: Array[Color] = [Palette.DRIFTWOOD, Palette.DRESSED_STONE, Palette.SALVAGE_IRON]
|
||||
## 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
|
||||
|
||||
|
||||
## A mesh for a piece of `material` made of `boxes`, with strips tinted from `salt`.
|
||||
static func build(boxes: Array[AABB], material: int, salt: int) -> ArrayMesh:
|
||||
## The wear stage of a piece that has taken `damage` of `max_health`.
|
||||
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()
|
||||
tool.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||
var base: Color = COLOURS[clampi(material, 0, COLOURS.size() - 1)]
|
||||
var strip: float = STRIP[clampi(material, 0, STRIP.size() - 1)]
|
||||
var index: int = 0
|
||||
for box: AABB in boxes:
|
||||
# Seam colour behind the strips.
|
||||
_box(tool, box.grow(-SEAM * 0.5), base.darkened(SEAM_DARKEN))
|
||||
if built >= 1.0:
|
||||
# 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.
|
||||
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:
|
||||
axis = 2 if axis == 0 else 0
|
||||
var count: int = maxi(1, roundi(box.size[axis] / strip))
|
||||
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
|
||||
piece.position[axis] = box.position[axis] + part * step + SEAM * 0.5
|
||||
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
|
||||
tool.generate_normals()
|
||||
var mesh: ArrayMesh = tool.commit()
|
||||
@@ -47,10 +97,24 @@ static func build(boxes: Array[AABB], material: int, salt: int) -> ArrayMesh:
|
||||
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
|
||||
## 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.
|
||||
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 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)
|
||||
@@ -59,10 +123,16 @@ static func build_ramp(slot: Vector4i, facing: int, material: int, salt: int) ->
|
||||
tool.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||
tool.set_smooth_group(-1)
|
||||
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 u1: float = (plank + 0.96) / planks
|
||||
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] = []
|
||||
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))
|
||||
@@ -123,6 +193,16 @@ static func box_mesh(boxes: Array[AABB], colour: Color) -> ArrayMesh:
|
||||
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:
|
||||
var h: int = hash(key * 2654435761)
|
||||
var shift: float = (float(h & 0xff) / 255.0 - 0.5) * 0.14
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
## 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.
|
||||
class_name StructureView
|
||||
extends Node3D
|
||||
@@ -7,6 +8,10 @@ extends Node3D
|
||||
var _structures: StructureSet
|
||||
## Piece ID -> MeshInstance3D.
|
||||
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:
|
||||
@@ -21,17 +26,28 @@ func sync() -> void:
|
||||
if _structures.find(piece_id) == null:
|
||||
_drawn[piece_id].queue_free()
|
||||
_drawn.erase(piece_id)
|
||||
_shown.erase(piece_id)
|
||||
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
|
||||
var instance: MeshInstance3D = MeshInstance3D.new()
|
||||
instance.name = "piece_%d" % piece.id
|
||||
var instance: MeshInstance3D = _drawn.get(piece.id)
|
||||
if instance == null:
|
||||
instance = MeshInstance3D.new()
|
||||
instance.name = "piece_%d" % piece.id
|
||||
add_child(instance)
|
||||
_drawn[piece.id] = instance
|
||||
if piece.kind == StructureSet.RAMP:
|
||||
instance.mesh = PieceMesher.build_ramp(piece.slot, piece.facing, piece.material, piece.id)
|
||||
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)
|
||||
add_child(instance)
|
||||
_drawn[piece.id] = instance
|
||||
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:
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
## 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
|
||||
## 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
|
||||
## for collision.
|
||||
## looks. The barge and the sea chests are VesselModels, generated in code. Nothing
|
||||
## here is ever used for collision.
|
||||
class_name EntityView
|
||||
extends Node3D
|
||||
|
||||
@@ -17,12 +17,10 @@ const OILSKINS: Array[Color] = [
|
||||
Palette.OILSKIN_SLATE, Palette.OILSKIN_NAVY, Palette.TANNED_SAIL,
|
||||
]
|
||||
const SKIN: Color = Palette.SKIN
|
||||
const CANVAS: Color = Palette.CANVAS
|
||||
const TAR: Color = Palette.TAR
|
||||
const PLANK: Color = Palette.PLANK
|
||||
const CHEST_SHUT: Color = Palette.SEA_PAINT
|
||||
const CHEST_OPEN: Color = Palette.HOLD_SHADOW
|
||||
const ITEM: Color = Palette.GILT
|
||||
## Chest instance colours, multiplied into the chest model's own: an opened chest
|
||||
## shows darker, its paint dulled.
|
||||
const CHEST_SHUT: Color = Color.WHITE
|
||||
const CHEST_OPEN: Color = Palette.OPENED_DULL
|
||||
## 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.
|
||||
const DECK_SPACING: float = 1.3
|
||||
@@ -56,7 +54,7 @@ func setup(sim: Simulation) -> void:
|
||||
_pickups = Node3D.new()
|
||||
_pickups.name = "Pickups"
|
||||
add_child(_pickups)
|
||||
_chests = _box_field("Chests", Vector3(0.9, 0.55, 0.6), false)
|
||||
_chests = _chest_field()
|
||||
add_child(_chests)
|
||||
sync()
|
||||
|
||||
@@ -145,7 +143,7 @@ func sync() -> void:
|
||||
var chests: MultiMesh = _chests.multimesh
|
||||
chests.instance_count = _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)
|
||||
|
||||
|
||||
@@ -231,11 +229,10 @@ func _item_field(key: String) -> MultiMeshInstance3D:
|
||||
multimesh.transform_format = MultiMesh.TRANSFORM_3D
|
||||
var mesh: ArrayMesh = ItemModels.model(key.get_slice("@", 0), key.get_slice("@", 1).to_int())
|
||||
if mesh == null:
|
||||
var stand_in: BoxMesh = BoxMesh.new()
|
||||
stand_in.size = Vector3(0.25, 0.25, 0.25)
|
||||
multimesh.mesh = stand_in
|
||||
else:
|
||||
multimesh.mesh = mesh
|
||||
# Every catalogue item has a model (test_item_models); this is a bug.
|
||||
push_error("EntityView: no model for item %s" % key)
|
||||
mesh = ArrayMesh.new()
|
||||
multimesh.mesh = mesh
|
||||
var field: MultiMeshInstance3D = MultiMeshInstance3D.new()
|
||||
field.name = key.replace("@", "_")
|
||||
field.multimesh = multimesh
|
||||
@@ -250,64 +247,22 @@ func _build_figure(entity_id: int) -> FigureRig:
|
||||
return figure
|
||||
|
||||
|
||||
## A flat-bottomed hull hung under a canvas envelope. Its deck is at the origin, where
|
||||
## the simulation carries the passengers.
|
||||
## The barge (VesselModels): a hull hung under a canvas envelope. Its deck is at the
|
||||
## origin, where the simulation carries the passengers.
|
||||
func _build_barge() -> Node3D:
|
||||
var barge: Node3D = Node3D.new()
|
||||
var barge: MeshInstance3D = MeshInstance3D.new()
|
||||
barge.name = "Barge"
|
||||
var deck: BoxMesh = BoxMesh.new()
|
||||
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)
|
||||
barge.mesh = VesselModels.barge()
|
||||
return barge
|
||||
|
||||
|
||||
func _part(mesh: PrimitiveMesh, colour: Color, at: Vector3) -> MeshInstance3D:
|
||||
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
|
||||
func _chest_field() -> MultiMeshInstance3D:
|
||||
var multimesh: MultiMesh = MultiMesh.new()
|
||||
multimesh.transform_format = MultiMesh.TRANSFORM_3D
|
||||
multimesh.use_colors = true
|
||||
multimesh.mesh = mesh
|
||||
multimesh.mesh = VesselModels.chest()
|
||||
var instance: MultiMeshInstance3D = MultiMeshInstance3D.new()
|
||||
instance.name = node_name
|
||||
instance.name = "Chests"
|
||||
instance.multimesh = multimesh
|
||||
instance.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
return instance
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
uid://b6u71jxsh531
|
||||
@@ -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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c35b5ggtxp7uw
|
||||
@@ -1,54 +1,15 @@
|
||||
## Draws an island's points of interest from their parts: one MultiMesh of boxes per
|
||||
## look, so the whole set costs a handful of draw calls. Colours follow the weathered
|
||||
## seafaring palette in docs/STYLE.md: tarred wood, grey planks, stone, faded red
|
||||
## roofs, salt-faded paint and white salt. No textures; the art pass replaces these.
|
||||
## Draws an island's points of interest. PoiMesher dresses each one's parts in boards,
|
||||
## stone courses, tiles and trim from the weathered palette in docs/STYLE.md; each point
|
||||
## of interest is one mesh, so the whole set costs a few dozen draw calls.
|
||||
class_name PoiView
|
||||
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:
|
||||
var by_look: Dictionary = {}
|
||||
var index: int = 0
|
||||
for poi: Poi in placed.pois:
|
||||
for part: Dictionary in poi.parts:
|
||||
var look: String = part["look"]
|
||||
if not by_look.has(look):
|
||||
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
|
||||
var instance: MeshInstance3D = MeshInstance3D.new()
|
||||
instance.name = "%s_%d" % [poi.kind, index]
|
||||
instance.mesh = PoiMesher.build(poi.parts)
|
||||
add_child(instance)
|
||||
|
||||
|
||||
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
|
||||
index += 1
|
||||
|
||||
@@ -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)
|
||||
## Lamp glass, lit.
|
||||
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.
|
||||
const SKIN: Color = Color(0.74, 0.58, 0.46)
|
||||
|
||||
|
||||
@@ -52,13 +52,26 @@ void fragment() {
|
||||
float broad = fbm(p * 0.035);
|
||||
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);
|
||||
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 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));
|
||||
// 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);
|
||||
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);
|
||||
rock = mix(rock, summit, 0.8 * smoothstep(summit_height - 2.0, summit_height + 6.0, world_position.y + 3.0 * broad));
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ const LOOK_ROOF: String = "roof"
|
||||
const LOOK_PAINT: String = "paint"
|
||||
const LOOK_SALT: String = "salt"
|
||||
const LOOK_LAMP: String = "lamp"
|
||||
const LOOK_WINDOW: String = "window"
|
||||
|
||||
const WALL: float = 0.3
|
||||
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 + 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 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)
|
||||
@@ -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])
|
||||
|
||||
|
||||
## 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:
|
||||
loot.append(to_world(local))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user