Skip to content

A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D

Give town buildings distinct entrances and working yards (#18)

Sandro Maglioneb93443689c91
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index 71f6879..01fe8d9 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -206,6 +206,25 @@ That is how the README's screenshots of grown towns were made.
### Reviewing the new town models
+[`/model-review.html?collection=town`](http://localhost:5232/model-review.html?collection=town)
+shows all 23 building kinds plus the market hall and church upgrades. The final
+nine refinements are grouped at `?collection=rural`. `src/asset-lab/rural.ts`
+owns timber entrances, nursery and farm fittings, chapel porches, granary louvres
+and the supported fire-watch access route. The same geometry is used in the game,
+catalogue, model sheets and GLB exports.
+
+[`/model-review.html?collection=trades`](http://localhost:5232/model-review.html?collection=trades)
+groups the mill, warehouse, fishery, bakery, weaver and watch house revisions.
+`src/asset-lab/trades.ts` owns their equipment, loading doors, open yards and the
+bakery smoke origin. The mill keeps its animated sails. Cargo sits on the ground
+or loading apron, and the four new yard layouts turn towards connected roads.
+
+[`/model-review.html?collection=workshops`](http://localhost:5232/model-review.html?collection=workshops)
+groups the revised mine, smithy, sawmill and town hall. The three workshops have
+open yards and road-facing layouts. `src/asset-lab/workshops.ts` owns their
+geometry, construction frames and smoke origins. The live renderer and catalogue
+use the same models; simulation footprints and building costs are unchanged.
+
Open [`/model-review.html`](http://localhost:5232/model-review.html) for
the models added for PR #3. Collections cover buildings, parks,
home tiers and neighbourhoods, winter, hazards, people/cargo, building
diff --git a/scripts/check-town-models.ts b/scripts/check-town-models.ts
index f8973f8..e38b175 100644
--- a/scripts/check-town-models.ts
+++ b/scripts/check-town-models.ts
@@ -14,7 +14,7 @@ page.on("console", e => { if (e.type() === "error") errors.push(e.text()) })
page.on("response", r => { if (r.status() >= 400) errors.push(`${r.status()} ${r.url()}`) })
const output = "output/inkline-3d/town-review"
await mkdir(output, { recursive: true })
-const groups = ["Review fixes", "Buildings", "Parks", "Homes & neighbourhoods", "Winter", "Ruins", "People & cargo", "Building condition", "Upgrades & worked faces"]
+const groups = ["All buildings", "Final refinements", "Trade buildings", "Workshop batch", "Review fixes", "Buildings", "Parks", "Homes & neighbourhoods", "Winter", "Ruins", "People & cargo", "Building condition", "Upgrades & worked faces"]
const captureSheet = async () => {
const previous = await page.locator("#sheet-link").getAttribute("href")
await page.getByRole("button", { name: "Save model sheet", exact: true }).click()
@@ -42,6 +42,10 @@ try {
await page.screenshot({ path: `${output}/${collection}-page.png` })
await page.getByRole("button", { name: "See the back", exact: true }).click()
assert.equal(await page.locator("output").textContent(), "180°")
+ if (["town", "rural", "workshops", "trades"].includes(collection)) {
+ const rear = await captureSheet()
+ await writeFile(`${output}/${collection}-rear.png`, Buffer.from(rear.split(",")[1]!, "base64"))
+ }
await page.getByRole("button", { name: "Reset view", exact: true }).click()
await page.getByLabel("View elevation").selectOption("50")
const rear = await captureSheet()
@@ -50,6 +54,20 @@ try {
console.log(`ok ${collection}: ${await page.locator(".model-view").count()} models, rotation, elevation, PNG export`)
}
await page.setViewportSize({ width: 390, height: 844 })
+ for (const [group, count, name] of [["All buildings", 25, "town"], ["Final refinements", 9, "rural"]] as const) {
+ await page.getByRole("button", { name: group, exact: true }).click()
+ assert.equal(await page.locator(".model-view").count(), count)
+ assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, `${group}: phone preview must fit`)
+ await page.screenshot({ path: `${output}/${name}-phone.png` })
+ }
+ await page.getByRole("button", { name: "Trade buildings", exact: true }).click()
+ assert.equal(await page.locator(".model-view").count(), 6)
+ assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "Trade building phone preview must fit the viewport")
+ await page.screenshot({ path: `${output}/trades-phone.png` })
+ await page.getByRole("button", { name: "Workshop batch", exact: true }).click()
+ assert.equal(await page.locator(".model-view").count(), 4)
+ assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "Workshop phone preview must fit the viewport")
+ await page.screenshot({ path: `${output}/workshops-phone.png` })
await page.getByRole("button", { name: "Parks", exact: true }).click()
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "Phone preview must fit the viewport")
await page.screenshot({ path: `${output}/phone.png` })
diff --git a/src/asset-lab/buildings.ts b/src/asset-lab/buildings.ts
index b24768c..8d87469 100644
--- a/src/asset-lab/buildings.ts
+++ b/src/asset-lab/buildings.ts
@@ -2,6 +2,9 @@ import { kinds, type KindId } from "../content.ts"
import { U } from "../iso.ts"
import { Drawing, palette, pale, square, sides, type Vertex, type Side } from "./primitives.ts"
import { finishTownBuilding, townBuildingNotes, institutionDoor, makeQuarry } from "./services.ts"
+import { isWorkshop, makeWorkshop, workshopSmokeOrigin, townHallEntrance } from "./workshops.ts"
+import { isTradeYard, makeTradeYard, tradeSmokeOrigin, tradeEntrance, millHoist } from "./trades.ts"
+import { chapelPorch, hayBands, isRuralDoor, lumberRack, nursery, ruralEntrance, ruralNotes, sheepTrough } from "./rural.ts"
const dresses: Record<KindId, { accent: number; roof?: number; glass?: number }> = {
townhall: { accent: 0x8a58a8, glass: 0xf3dca6 },
@@ -38,6 +41,8 @@ export interface BuildingOptions {
motion?: boolean
}
export function makeBuilding(id: KindId, options: BuildingOptions = {}) {
+ if (isWorkshop(id)) return makeWorkshop(id, options)
+ if (isTradeYard(id)) return makeTradeYard(id, options)
if (id === "quarry") return makeQuarry(options)
const fit = options.fit ?? 1
const kind = kinds[id],
@@ -49,12 +54,12 @@ export function makeBuilding(id: KindId, options: BuildingOptions = {}) {
const d = new Drawing(
id,
kind.title,
- townBuildingNotes[id] ?? (id === "mill"
- ? "Upright lattice sails, a tapered roof and coopered flour barrels in the mill yard."
+ ruralNotes[id] ?? townBuildingNotes[id] ?? (id === "mill"
+ ? "Upright lattice sails and a tapered roof, with braced grain-loading doors, a sack hoist and coopered flour barrels."
: id === "market"
? "Striped canopy, coloured goods crates and roof flag, all built as geometry."
: id === "townhall"
- ? "Two storeys, clock faces, violet trim, three skylights and a red flag. Original dimensions throughout."
+ ? "Civic timber double doors beneath stone porches, with broad steps, clocks, violet trim, three skylights and a red flag."
: "Original footprint, palette and yard details, with complete walls and roof geometry.")
)
d.asset.category = "buildings"
@@ -74,6 +79,7 @@ export function makeBuilding(id: KindId, options: BuildingOptions = {}) {
if (kind.roof === "flat" && fit > 0.4)
for (let floor = 0; floor < kind.stories; floor++)
for (const s of positions) {
+ if (id === "granary" && floor === 1) continue
if (id === "chapel") {
const z = floor * 32 + 9,
w = 1 / 16,
@@ -83,7 +89,13 @@ export function makeBuilding(id: KindId, options: BuildingOptions = {}) {
} else d.window(side, a, s, floor * 32 + 12, 8, glass, true)
}
if (door && fit > 0.15) {
- if (id === "chapel" || id === "hospital") institutionDoor(d,side,a,id,fit)
+ if (id === "townhall") townHallEntrance(d, side, a, fit, options.open ?? 0)
+ else if (id === "mill" || id === "watchhouse") tradeEntrance(d, id, side, a, fit, options.open ?? 0)
+ else if (isRuralDoor(id)) ruralEntrance(d, id, side, a, fit, options.open ?? 0)
+ else if (id === "chapel" || id === "hospital") {
+ institutionDoor(d,side,a,id,fit)
+ if (id === "chapel") chapelPorch(d, side, a, fit)
+ }
else d.door(side, a, Math.max(2, Math.round(Math.min(16, H - 8) * fit)), 5 * U, 6 * U, 2.5 * U, accent, true, options.open ?? 0)
}
if (kind.roof === "gable" && !door && fit > 0.4) d.window(side, a, 0, 6)
@@ -114,6 +126,7 @@ export function makeBuilding(id: KindId, options: BuildingOptions = {}) {
for (let row = 0; row < kind.bays; row++)
for (let col = 0; col < kind.bays; col++) {
if (
+ id === "chapel" ||
(kind.topper === "flag" && row === 0 && col === kind.bays - 1) ||
(["chimney", "cupola", "crates"].includes(kind.topper) && row === 0 && col === 0)
)
@@ -189,6 +202,32 @@ export function makeBuilding(id: KindId, options: BuildingOptions = {}) {
return d.asset
}
+/** Shared by catalogue geometry and working-building emitters. Open yards have no flue. */
+export function buildingSmokeOrigin(id: KindId, doors?: BuildingOptions["doors"]): Vertex | null {
+ if (isWorkshop(id)) return workshopSmokeOrigin(id, doors)
+ if (isTradeYard(id)) return tradeSmokeOrigin(id, doors)
+ const kind = kinds[id]
+ if (kind.topper !== "chimney") return null
+ const a = kind.half * U, pitch = 2 * a / kind.bays
+ return [-a + pitch * 0.5, -a + pitch * 0.5, (kind.roof === "gable" ? 20 : kind.stories * 32) + 24.3]
+}
+
+/** Presentation dimensions stay separate from simulation footprints and content costs. */
+export function buildingDimensions(id: KindId) {
+ if (isTradeYard(id)) return {
+ half: (id === "warehouse" ? 21 : 13.5) * U,
+ height: id === "fishery" ? 20 : id === "bakery" ? 28 : id === "weaver" ? 30 : 32,
+ top: id === "warehouse" ? 45 : id === "fishery" ? 30 : id === "bakery" ? 48.3 : 38
+ }
+ const kind = kinds[id], height = kind.roof === "gable" ? 20 : kind.stories * 32
+ const topper = kind.topper === "chimney" || kind.topper === "flag" ? 24 : kind.topper === "cupola" ? 25 : kind.topper === "sails" ? 16 : 0
+ return {
+ half: isWorkshop(id) ? 13.5 * U : kind.half * U,
+ height,
+ top: id === "firewatch" ? 55 : id === "sawmill" ? 36.7 : id === "mine" || id === "smithy" ? 56 : height + topper
+ }
+}
+
function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number, fit = 1) {
const kind = kinds[id],
c = (a + p) / 2,
@@ -223,10 +262,6 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,
],
1.5
)
- } else if (kind.topper === "crates" && fit > 0.5) {
- d.crate(u, v, H, 0xd27a34, 3 * U, 12)
- d.crate(u + 7 * U, v, H, 0x2f8c87, 3 * U, 12)
- d.crate(u + 3 * U, v, H + 12, 0x8a58a8, 3 * U, 12)
}
const post = (x: number, y: number, h: number) =>
d.line(
@@ -238,19 +273,12 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,
)
const bush = (x: number, y: number, r: number, shade = 0xc6d4b2, light = 0xe4ecd6) =>
d.ellipsoid(x, y, r, r / 45.2548, r / 45.2548, r * 0.866, shade, 1, light)
- const pyramid = (x: number, y: number, half: number, z: number, rise: number, color: number) => {
- const base = square(x, y, half, z)
- for (let i = 0; i < 4; i++) d.face([base[i]!, base[(i + 1) % 4]!, [x, y, z + rise]], pale(color, i >= 2 ? 0.7 : 0.52))
- }
if (fit <= 0.75) return
finishTownBuilding(d, id, a, p, H)
+ if (id === "mill") millHoist(d, a)
switch (id) {
- case "warehouse":
- d.crate(c, c - 1.3 * U, 0, 0x2f8c87, 1.1 * U, 6)
- d.crate(c, c + 1.3 * U, 0, 0xd27a34, 1.1 * U, 6)
- d.barrel(c, -a - 2 * U, 1.5 * U)
- break
case "lumberjack": {
+ lumberRack(d, a, p)
for (const [du, z] of [
[-1.6, 0],
[0, 0],
@@ -258,7 +286,7 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,
[-0.8, 2.6],
[0.8, 2.6]
])
- d.log("v", c + du! * U, a + 0.5 * U, p - 0.5 * U, z!, 1.6, 0xb08a5e, 0xe9d2a8)
+ d.log("v", c + du! * U, a + 0.5 * U, p - 0.5 * U, z! + 1.5, 1.6, 0xb08a5e, 0xe9d2a8)
const y = -a - 1.5 * U
d.cylinder(c, y, 1.3 * U, 0, 3, 0xb08a5e, 0xe9d2a8, 1.5)
d.line(
@@ -273,14 +301,7 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,
break
}
case "forester":
- for (const [x, y, s] of [
- [c, c, 0.8],
- [c, -a - 2 * U, 0.6],
- [-a - 2 * U, c, 0.55]
- ]) {
- d.cylinder(x!, y!, 1.2 * U, 0, 3, 0xd5a86c, 0x7d6140, 1.5)
- d.fir(x!, y!, 3, s!, 2)
- }
+ nursery(d, a, p)
break
case "quarry": {
for (const [x, y, z] of [
@@ -306,66 +327,6 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,
d.box(c, y, U, U, 4, 4, 0xeeefea, 0xdcded7, 0xc9ccc4)
break
}
- case "mine": {
- for (const du of [-1, 1])
- d.line(
- [
- [c + du * U, a + 0.5 * U, 0],
- [c + du * U, p - 0.2 * U, 0]
- ],
- 1,
- palette.ink,
- 0.6
- )
- d.box(c, c, 1.6 * U, 2 * U, 2, 5, 0x6c7488, 0xd5dae4, 0xbcc3d1)
- for (const [du, dv] of [
- [-0.8, -0.5],
- [0.7, 0.5],
- [0, 0]
- ])
- d.ellipsoid(c + du! * U, c + dv! * U, 7.5, 0.035, 0.035, 1.5, 0x5a6479, 0.75)
- for (const dv of [-1.2, 1.2]) d.cylinder(c + 1.6 * U, c + dv * U, 0.026, 0, 3, palette.ink, palette.ink, 0.75)
- pyramid(c - U, -a - 2 * U, 2 * U, 0, 6, 0x5a6479)
- break
- }
- case "fishery": {
- d.cylinder(c, c, 1.5 * U, 0, 7, 0xc79a5b, 0x9fc9c4, 1.5)
- const y0 = -a - 4 * U,
- y1 = -a + 3 * U
- post(c, y0, 11)
- post(c, y1, 11)
- d.line([
- [c, y0, 11],
- [c, y1, 11]
- ])
- for (let i = 1; i <= 3; i++) {
- const y = y0 + ((y1 - y0) * i) / 4
- d.line([
- [c, y, 11],
- [c, y, 9]
- ])
- d.ellipsoid(c, y, 6, 0.028, 0.045, 3, 0x2f8c87, 1)
- d.face(
- [
- [c, y - 0.04, 4],
- [c, y + 0.04, 4],
- [c, y, 3]
- ],
- 0x2f8c87,
- 1
- )
- }
- break
- }
- case "sawmill":
- for (let i = 0; i < 3; i++) d.box(c, -a + 1.5 * U, 1.1 * U, 3 * U, i * 2.5, 2.5, 0xf0c59a, 0xe2a873, 0xd2945c, 1)
- d.log("u", c, -a - 3 * U, -a + 4 * U, 0, 2, 0xb08a5e, 0xe9d2a8)
- break
- case "smithy":
- d.cylinder(c, c, U, 0, 3, 0xb08a5e, 0xe9d2a8, 1.5)
- d.box(c, c, 0.6 * U, 1.4 * U, 3, 3, 0x6d7671, 0x5a625e, 0x4b524e)
- pyramid(c, -a - 1.5 * U, 1.2 * U, 0, 5, 0x3d4943)
- break
case "farm":
d.cylinder(c + U, -a - 3 * U, 3.5 * U, 0, 28, 0xeeeae0, pale(0xc4523f, 0.6), 1.5)
{
@@ -386,18 +347,11 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,
[c - 1.2 * U, 0],
[c + 1.2 * U, 0],
[c, 5.3]
- ])
+ ]) {
d.log("u", y!, a + 2 * U, a + 7 * U, z!, 3, 0xe9cf7c, 0xf3e3a8)
+ hayBands(d, y!, a + 2 * U, a + 7 * U, z!, 3)
+ }
break
- case "bakery": {
- d.barrel(c, -a - U, U, 0, 8, 0xf1e9d5)
- d.barrel(c, -a + 2 * U, U, 0, 7)
- post(c, c, 12)
- const p = (x: number, z: number): Vertex => [c + x / 64, c - x / 64, z]
- d.face([p(-4, 11), p(4, 11), p(4, 17), p(-4, 17)], 0xfaf3e3, 1)
- d.ellipsoid(c + 0.015, c + 0.015, 14, 0.05, 0.05, 1.3, 0xc4523f, 0.75)
- break
- }
case "sheep": {
const s = a + U,
e = p - U
@@ -408,14 +362,20 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,
[e, e]
])
post(x!, y!, 6)
- for (const z of [2.5, 5.5])
+ for (const z of [2.5, 5.5]) {
d.line([
[s, s, z],
- [s, e, z],
- [e, e, z],
[e, s, z],
+ [e, e, z],
+ [s, e, z],
+ [s, 21 * U, z]
+ ])
+ d.line([
+ [s, 17 * U, z],
[s, s, z]
])
+ }
+ for (const y of [17 * U, 21 * U]) post(s, y, 6)
for (const [x, y, facing] of [
[s + 3 * U, s + 4 * U, 1],
[s + 6 * U, s + 2.5 * U, -1],
@@ -434,32 +394,7 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,
d.ellipsoid(x! + facing! * 0.1, y!, 5.5, 0.032, 0.032, 1.4, palette.ink, 0)
}
d.cylinder(c, -a - 3 * U, 2 * U, 0, 5, 0xe9cf7c, 0xf3e3a8, 1.5)
- break
- }
- case "weaver": {
- const y0 = -a - 2.5 * U,
- y1 = -a + 5 * U
- post(c, y0, 11)
- post(c, y1, 11)
- d.line([
- [c, y0, 11],
- [c, y1, 11]
- ])
- for (const [i, color] of [0x8a58a8, 0xd6ae2e, 0x3d6db5].entries()) {
- const s = y0 + ((y1 - y0) / 3) * i + 0.4 * U,
- e = y0 + ((y1 - y0) / 3) * (i + 1) - 0.4 * U
- d.face(
- [
- [c, s, 10.5],
- [c, e, 10.5],
- [c, e, 4 + (i % 2)],
- [c, s, 4 + (i % 2)]
- ],
- color
- )
- }
- d.barrel(c, c, U, 0, 7, 0xeceee8)
- d.face([[c-U,c,7.04],[c+U,c,7.04],[c+U,c+U,6],[c-U,c+U,6]],0xb7a4ca,0.75)
+ sheepTrough(d, a)
break
}
case "chapel":
diff --git a/src/asset-lab/main.ts b/src/asset-lab/main.ts
index 49f3e70..de697e4 100644
--- a/src/asset-lab/main.ts
+++ b/src/asset-lab/main.ts
@@ -32,9 +32,9 @@ root.innerHTML = `
<header><a href="/model-review.html">Model review ↗</a><span>COMPLETE ASSET CATALOGUE</span><a href="/effects-lab.html">Animated house effects ↗</a></header>
<div class="intro"><div><h1>The same ink.<br>A different angle.</h1><p>Original game drawings and complete 3D assets, side by side.</p></div><span class="tag">Procedural · Orthographic · Rotatable</span></div>
<div class="filters"><label>Collection <select id="category"></select></label><label>Find <input id="search" type="search" placeholder="Name or material"></label><a href="/service-upgrades.html">Compare service tiers ↗</a><a href="/map-lab.html">See everything on the map ↗</a></div><nav class="assets" aria-label="Choose an asset"></nav>
- <section class="comparison" aria-label="Compare the original drawing with the 3D model">
- <div class="view"><div class="view-label"><span>01 / CURRENT GAME</span><span>Fixed isometric drawing</span></div><canvas id="reference" aria-label="Original 2D asset"></canvas><span class="view-foot">Original art.ts drawing</span></div>
- <div class="view"><div class="view-label"><span>02 / 3D STUDY</span><span id="angle-label">Original angle</span></div><div id="viewer" role="img" aria-label="Rotatable 3D asset. Drag horizontally to rotate."></div><span class="view-foot">Drag to rotate · wheel to zoom</span></div>
+ <section class="comparison" aria-label="Compare the original 2D drawing with the current 3D model">
+ <div class="view"><div class="view-label"><span>01 / ORIGINAL 2D ART</span><span>Fixed isometric drawing</span></div><canvas id="reference" aria-label="Original 2D asset"></canvas><span class="view-foot">Original art.ts drawing</span></div>
+ <div class="view"><div class="view-label"><span>02 / CURRENT 3D MODEL</span><span id="angle-label">Original angle</span></div><div id="viewer" role="img" aria-label="Rotatable 3D asset. Drag horizontally to rotate."></div><span class="view-foot">Drag to rotate · wheel to zoom</span></div>
</section>
<section class="controls" aria-label="Camera controls"><button id="reset">Match original view</button><label>Rotation <input id="rotation" type="range" min="-180" max="180" value="0" step="1"><output id="rotation-value">0°</output></label><label>Elevation <input id="elevation" type="range" min="10" max="65" value="30" step="1"><output id="elevation-value">30°</output></label><button id="rear">See the back</button></section>
<section class="caption"><div><h2 id="asset-title"></h2><p id="asset-note"></p></div><div class="downloads"><button id="download-glb">Download GLB</button><button id="download-source">Download geometry</button><button id="download-png">Save comparison</button></div></section>
@@ -235,9 +235,8 @@ function render() {
const ref = references.get(selected.id)!
const model = models.get(selected.id)!
const effectBounds=selected.smokeEffect||selected.fountains?.length?new THREE.Box3().setFromObject(model.group):null
- const upgraded = selected.reference?.type === "building" && selected.reference.tier === 2
- const bounds = upgraded ? new THREE.Box3().setFromObject(model.group).getBoundingSphere(new THREE.Sphere()) : null
- const vertical = Math.max(40, ref.height * 1.45, ((ref.width * height) / width) * 1.3, effectBounds?effectBounds.getSize(new THREE.Vector3()).y*1.45:0, bounds ? bounds.radius * 2.4 * Math.max(1, height / width) : 0) / zoom
+ const bounds = selected.reference?.type === "building" ? new THREE.Box3().setFromObject(model.group).getBoundingSphere(new THREE.Sphere()) : null
+ const vertical = Math.max(40, ref.height * 1.45, ((ref.width * height) / width) * 1.3, effectBounds?effectBounds.getSize(new THREE.Vector3()).y*1.45:0, bounds ? bounds.radius * 2.6 * Math.max(1, height / width) : 0) / zoom
renderer.setSize(width, height, false)
camera.left = (-vertical * width) / height / 2
camera.right = -camera.left
diff --git a/src/asset-lab/rural.ts b/src/asset-lab/rural.ts
new file mode 100644
index 0000000..7d48af3
--- /dev/null
+++ b/src/asset-lab/rural.ts
@@ -0,0 +1,141 @@
+import { type KindId } from "../content.ts"
+import { U } from "../iso.ts"
+import { Drawing, palette, pale, type Side, type Vertex } from "./primitives.ts"
+import { beam, block, iron, post, stone, wood } from "./workshops.ts"
+
+export const ruralIds = ["firewatch", "lumberjack", "forester", "farm", "sheep", "smokehouse", "builder", "chapel", "granary"] as const
+export const ruralDoorIds = ["lumberjack", "forester", "farm", "sheep", "smokehouse", "builder", "granary"] as const
+type RuralDoorId = typeof ruralDoorIds[number]
+export const isRuralDoor = (id: KindId): id is RuralDoorId => ruralDoorIds.some(kind => kind === id)
+export const ruralNotes: Partial<Record<KindId, string>> = {
+ firewatch: "A bell lookout with a supported landing and roof stair connecting its ground ladder to the deck; water buckets remain below.",
+ lumberjack: "A timber hut with braced doors, a supported log rack and an axe on its chopping block.",
+ forester: "A green-roofed nursery with a boarded timber door, framed seedling bed and one potted fir.",
+ farm: "A red-roofed barn with braced timber doors, a silo and bound round hay bales.",
+ sheep: "A barn beside a sheep pen, with a side gate and an open water trough.",
+ smokehouse: "A timber curing-room door, soot-dark flue, hanging fish, split firewood and a curing barrel.",
+ builder: "Braced workshop doors beside timber racks, a trestle bench, mallet, ladder and dressed stone.",
+ chapel: "Pointed timber entrances beneath small stone porches, with blue lancet windows, a quiet pale roof and the original cupola.",
+ granary: "A raised loading threshold, boarded grain doors, framed upper-store louvres, timber braces and the sack hoist."
+}
+
+function wallBlock(d: Drawing, side: Side, a: number, along: number, out: number, half: number, depth: number, z: number, h: number, colors: readonly [number, number, number] = stone) {
+ const [u, v] = d.wall(side, a, along, 0, out)
+ const turn = side === "right" || side === "backRight"
+ block(d, u, v, turn ? depth : half, turn ? half : depth, z, h, colors)
+}
+
+/** Timber leaves open at their hinges; all planks and braces follow the leaf. */
+export function ruralEntrance(d: Drawing, id: RuralDoorId, side: Side, a: number, fit: number, open: number) {
+ const half = (id === "farm" || id === "sheep" ? 4.5 : id === "granary" ? 4 : id === "forester" ? 2.5 : 3.2) * U
+ const bottom = id === "granary" ? 3 : 0.5, height = id === "granary" ? 24 : 18
+ const p = (s: number, z: number, out = 0.02) => d.wall(side, a, s, z * fit, out)
+ d.face([p(-half, bottom), p(half, bottom), p(half, bottom + height), p(-half, bottom + height)], 0x68726c, 0.7)
+ const single = id === "forester", angle = Math.max(0, Math.min(1, open)) * Math.PI / 9
+ for (const sign of single ? [-1] : [-1, 1]) {
+ const width = single ? half * 2 : half
+ const leaf = (t: number, z: number, extra = 0): Vertex => p(sign * (half - t * width * Math.cos(angle)), z, 0.04 + t * width * Math.sin(angle) + extra)
+ d.face([leaf(0, bottom), leaf(1, bottom), leaf(1, bottom + height), leaf(0, bottom + height)], wood[1], 0.8)
+ for (let i = 1; i < 4; i++) d.line([leaf(i / 4, bottom, 0.005), leaf(i / 4, bottom + height, 0.005)], 0.45, 0x987a54)
+ for (const z of [bottom + 2, bottom + height - 2]) beam(d, leaf(0, z, 0.01), leaf(1, z, 0.01), 0.8)
+ if (id !== "forester") beam(d, leaf(0.06, bottom + 2, 0.015), leaf(0.94, bottom + height - 2, 0.015), 0.9)
+ d.line([leaf(0.88, bottom + 7, 0.03), leaf(0.88, bottom + 10, 0.03)], 0.9, iron[2])
+ for (const z of [bottom + 4, bottom + height - 4]) d.line([leaf(0, z, 0.025), leaf(0.22, z, 0.025)], 0.9, iron[1])
+ }
+ for (const sign of [-1, 1]) beam(d, p(sign * (half + 0.6 * U), bottom, 0.4 * U), p(sign * (half + 0.6 * U), bottom + height + 1, 0.4 * U), 1.25)
+ beam(d, p(-half - 1.1 * U, bottom + height + 1, 0.4 * U), p(half + 1.1 * U, bottom + height + 1, 0.4 * U), 1.4)
+ if (id === "granary") {
+ wallBlock(d, side, a, 0, 2 * U, 5.4 * U, 2 * U, 0, fit)
+ wallBlock(d, side, a, 0, 1.4 * U, 5 * U, 1.4 * U, fit, fit)
+ wallBlock(d, side, a, 0, 0.8 * U, 4.6 * U, 0.8 * U, 2 * fit, fit)
+ }
+}
+
+export function chapelPorch(d: Drawing, side: Side, a: number, fit: number) {
+ const p = (s: number, z: number, out: number) => d.wall(side, a, s, z * fit, out)
+ wallBlock(d, side, a, 0, 1.3 * U, 5.4 * U, 1.3 * U, 0, 1.1 * fit)
+ wallBlock(d, side, a, 0, 0.8 * U, 4.8 * U, 0.8 * U, 1.1 * fit, 1.1 * fit)
+ for (const sign of [-1, 1]) beam(d, p(sign * 4.7 * U, 1.1, 2 * U), p(sign * 4.7 * U, 24.5, 2 * U), 1.1, stone)
+ for (const sign of [-1, 1]) {
+ d.face([p(sign * 5.4 * U, 24, 0.02), p(sign * 5.4 * U, 24, 2.8 * U), p(0, 29, 2.8 * U), p(0, 29, 0.02)], sign < 0 ? palette.roof : palette.left, 0.8)
+ beam(d, p(sign * 5.4 * U, 24, 2.8 * U), p(0, 29, 2.8 * U), 0.8, stone)
+ }
+ d.face([p(-5.4 * U, 24, 2.8 * U), p(5.4 * U, 24, 2.8 * U), p(0, 29, 2.8 * U)], pale(0x3d6db5, 0.88), 0.8)
+ d.face([p(-5.4 * U, 24, 0.02), p(5.4 * U, 24, 0.02), p(5.4 * U, 24, 2.8 * U), p(-5.4 * U, 24, 2.8 * U)], palette.right, 0)
+}
+
+export function granaryVents(d: Drawing, side: Side, a: number) {
+ const p = (s: number, z: number, out = 0.025) => d.wall(side, a, s, z, out)
+ for (const center of [-5 * U, 5 * U]) {
+ d.face([p(center - 2.2 * U, 44), p(center + 2.2 * U, 44), p(center + 2.2 * U, 56), p(center - 2.2 * U, 56)], 0x6f796d, 0.7)
+ for (const x of [-2.4 * U, 2.4 * U]) beam(d, p(center + x, 43.5, 0.04), p(center + x, 56.5, 0.04), 0.75)
+ for (const z of [44, 56]) beam(d, p(center - 2.4 * U, z, 0.04), p(center + 2.4 * U, z, 0.04), 0.75)
+ for (const z of [46, 48.5, 51, 53.5]) beam(d, p(center - 2.1 * U, z, 0.055), p(center + 2.1 * U, z, 0.055), 1.1)
+ }
+}
+
+export function lumberRack(d: Drawing, a: number, p: number) {
+ const c = (a + p) / 2
+ for (const v of [a + 0.8 * U, p - 0.8 * U]) block(d, c, v, 2.3 * U, 0.35 * U, 0, 1.5)
+ for (const u of [c - 2.3 * U, c + 2.1 * U]) {
+ for (const v of [a + 0.6 * U, p - 0.6 * U]) block(d, u, v, 0.3 * U, 0.3 * U, 0, 8.5)
+ beam(d, [u, a + 0.6 * U, 7], [u, p - 0.6 * U, 7], 0.8)
+ }
+}
+
+export function nursery(d: Drawing, a: number, p: number) {
+ const c = (a + p) / 2, u = -5 * U, v = c, width = 3.6 * U, depth = 1.8 * U
+ block(d, u, v, width, depth, 0, 1.5, [0x9d977e, 0x9d977e, 0x9d977e], 0)
+ for (const x of [-width, width]) block(d, u + x, v, 0.3 * U, depth, 0, 2.4)
+ for (const y of [-depth, depth]) block(d, u, v + y, width, 0.3 * U, 0, 2.4)
+ for (const x of [-2, 0, 2]) for (const y of [-0.8, 0.8]) d.fir(u + x * U, v + y * U, 1.5, 0.25, 1)
+ d.cylinder(c, c, 1.4 * U, 0, 3, 0xd5a86c, 0x7d6140, 0.8)
+ d.fir(c, c, 3, 0.7, 2)
+}
+
+export function hayBands(d: Drawing, across: number, from: number, to: number, z: number, radius: number) {
+ for (const u of [from + (to - from) * 0.27, from + (to - from) * 0.73]) {
+ const ring = Array.from({ length: 25 }, (_, i): Vertex => {
+ const t = i * Math.PI * 2 / 24
+ return [u, across + Math.cos(t) * (radius + 0.04) / Math.sqrt(5) * U, z + radius + Math.sin(t) * (radius + 0.04)]
+ })
+ d.line(ring, 1.1, 0xa6925d)
+ }
+}
+
+export function sheepTrough(d: Drawing, a: number) {
+ const u = a - U, v = 19 * U
+ block(d, u, v, 1.2 * U, 2.5 * U, 0, 0.8)
+ for (const x of [-1.2 * U, 1.2 * U]) block(d, u + x, v, 0.25 * U, 2.5 * U, 0.8, 2.8)
+ for (const y of [-2.5 * U, 2.5 * U]) block(d, u, v + y, 1.2 * U, 0.25 * U, 0.8, 2.8)
+ d.face([[u - U, v - 2.2 * U, 2.5], [u + U, v - 2.2 * U, 2.5], [u + U, v + 2.2 * U, 2.5], [u - U, v + 2.2 * U, 2.5]], 0xc3d6cf, 0)
+}
+
+/** The outside ladder reaches a landing; seven supported treads clear the roof and meet the deck. */
+export function firewatchAccess(d: Drawing, a: number, p: number, H: number) {
+ const base = H + 7, top = base + 1.5, v = -4.5 * U
+ block(d, 11.25 * U, v, 1.25 * U, 1.6 * U, base, 1.5)
+ for (const y of [-6 * U, -3 * U]) {
+ post(d, 12 * U, y, base)
+ beam(d, [a, y, 17], [12 * U, y, base], 1.2)
+ }
+ const foot = p - U, head = 12.5 * U
+ for (const y of [-1.1, 1.1]) beam(d, [foot, v + y * U, 0], [head, v + y * U, top], 1.1)
+ for (let z = 2.5; z < top; z += 2.5) {
+ const u = foot + (head - foot) * z / top
+ beam(d, [u, v - 1.1 * U, z], [u, v + 1.1 * U, z], 0.7)
+ }
+ const point = (t: number, side: number, height: number): Vertex => [(11 - 7 * t) * U, (-4.5 + 2.7 * t + side * 1.2) * U, top + 6 * t + height]
+ for (const side of [-1, 1]) {
+ beam(d, point(0, side, -0.5), point(1, side, -0.5), 1.2)
+ beam(d, point(0, side, 5), point(1, side, 5), 0.8)
+ for (const t of [0, 0.5, 1]) beam(d, point(t, side, 0), point(t, side, 5), 0.8)
+ beam(d, [10 * U, v + side * 1.6 * U, top + 5], [12.5 * U, v + side * 1.6 * U, top + 5], 0.8)
+ for (const u of [10 * U, 12.5 * U]) beam(d, [u, v + side * 1.6 * U, top], [u, v + side * 1.6 * U, top + 5], 0.8)
+ }
+ for (let i = 0; i < 7; i++) {
+ const t = (i + 0.5) / 7
+ block(d, (11 - 7 * t) * U, (-4.5 + 2.7 * t) * U, 0.55 * U, 1.2 * U, top + 6 * (i + 1) / 7 - 0.55, 0.55)
+ }
+ for (const u of [-3 * U, 3 * U]) for (const y of [-3 * U, 3 * U]) beam(d, [u, y, H], [u, y, H + 13], 1.4)
+}
diff --git a/src/asset-lab/services.ts b/src/asset-lab/services.ts
index 1ad55ef..9486e90 100644
--- a/src/asset-lab/services.ts
+++ b/src/asset-lab/services.ts
@@ -4,6 +4,7 @@ import { Drawing, palette, pale, sides, square, type Vertex, type Side } from ".
import { bench, flowerBed } from "./town-props.ts"
import type { BuildingOptions } from "./buildings.ts"
import { rockOutcrop } from "./land.ts"
+import { firewatchAccess, granaryVents } from "./rural.ts"
export function institutionDoor(d: Drawing, side: Side, a: number, kind: "chapel" | "hospital", fit: number) {
const p = (s: number, z: number, out = 0.015) => d.wall(side,a,s,z*fit,out)
@@ -58,7 +59,7 @@ export const townBuildingNotes: Partial<Record<KindId, string>> = {
firewatch: "A timber lookout and alarm bell above the red roof; ladder, buckets and a water butt below.",
healer: "An apothecary with a mortar sign, herb beds, medicine jars and a waiting bench.",
hospital: "Pale green ward windows, a roof lantern, medical emblems and a waiting bench.",
- watchhouse: "Blue shield, barred windows, a lantern and a street noticeboard.",
+ watchhouse: "A guarded timber entrance with bracing and viewing grilles, beneath a blue shield; barred windows, a lantern and a street noticeboard remain.",
builder: "Open timber racks, trestle workbench, mallet, ladder and dressed stone."
}
@@ -77,7 +78,7 @@ export function finishTownBuilding(d: Drawing, id: KindId, a: number, p: number,
const at = (s: number, z: number) => d.wall(side, a, s, z, 0.015)
for (const x of [-a + U, a - U]) d.line([at(x, 0), at(x, H)], 1.5, 0x9f8b69)
d.line([at(-a + U, 28), at(0, 40), at(a - U, 28)], 1, 0x9f8b69)
- for (const z of [47, 50, 53]) d.line([at(-2 * U, z), at(2 * U, z)], 1, 0xa99575)
+ granaryVents(d, side, a)
}
post(c, -a * 0.4, 43)
d.line([[c, -a * 0.4, 43], [c, a * 0.5, 43], [c, a * 0.5, 33]], 1.5, 0x8a6a45)
@@ -106,7 +107,7 @@ export function finishTownBuilding(d: Drawing, id: KindId, a: number, p: number,
d.cylinder(0, 0, 1.5 * U, z + 5, 1, 0xc2ac70, 0xe4d29a, 1, 12)
d.ellipsoid(0, 0, z + 7, U, U, 2, 0xd3bd84, 1, undefined, 12)
d.line([[0, 0, z + 9], [0, 0, z + 14]], 1)
- ladder(p-U,a+0.003,-a/2,H+7)
+ firewatchAccess(d, a, p, H)
d.barrel(c, c, 2 * U, 0, 9, 0xc9dde6)
for (const y of [-2, 1]) d.cylinder(-a - 2 * U, c + y * U, U, 0, 4, 0xbda07a, 0xa9c5d0, 1, 12)
} else if (id === "healer" || id === "hospital") {
@@ -158,8 +159,7 @@ export function finishTownBuilding(d: Drawing, id: KindId, a: number, p: number,
d.box(-a / 2, c, 3 * U, 2 * U, 6, 1, 0xe9d2a8, 0xd0b58c, 0xb08a5e, 1)
d.line([[-a / 2, c, 7], [-a / 2 + U, c, 11]], 1.5, 0x8a6a45)
d.box(-a / 2 + U, c, U, 0.7 * U, 10, 2, 0x9ca79a, 0xbfc8ba, 0x8f9a8c, 0.75)
- // Both rails clear the six-unit awning; the rear rack and ground blocks
- // leave this stretch of wall and the ladder's feet unobstructed.
+ // The ladder stays beside the timber entry, clear of the rack and ground blocks.
ladder(p-U,a+0.003,a-2*U,18)
for (const x of [-1, 1]) d.box(c + x * U, c - U, U, U, 0, 3, 0xe4e6df, 0xd6d9cf, 0xc2c9bd, 1)
}
diff --git a/src/asset-lab/trades.ts b/src/asset-lab/trades.ts
new file mode 100644
index 0000000..d18c594
--- /dev/null
+++ b/src/asset-lab/trades.ts
@@ -0,0 +1,235 @@
+import { buildStages } from "../art.ts"
+import { kinds, type KindId } from "../content.ts"
+import { U } from "../iso.ts"
+import { Drawing, palette, pale, type Side, type Vertex } from "./primitives.ts"
+import type { BuildingOptions } from "./buildings.ts"
+import { beam, block, iron, orient, post, roof, stone, wheel, wood, workshopPoint } from "./workshops.ts"
+
+export const tradeYardIds = ["warehouse", "fishery", "bakery", "weaver"] as const
+export type TradeYardId = typeof tradeYardIds[number]
+export const isTradeYard = (id: KindId): id is TradeYardId => tradeYardIds.some(kind => kind === id)
+export const tradeNotes = {
+ warehouse: "Braced loading doors open onto a raised cargo apron, with ground-level crates, steps and a timber hoist.",
+ fishery: "A teal-roofed fishing hut with a framed net, fish-sorting bench and water barrel, all on dry ground.",
+ bakery: "A masonry barrel oven opens into a sheltered bread counter, with flour barrels and a projecting loaf sign.",
+ weaver: "An open weaving bay with a treadle loom, tensioned warp, violet cloth and a rack of thread spools."
+}
+
+type Wall = (along: number, height: number, out?: number) => Vertex
+
+/** Paired timber leaves slide clear of the opening, with bracing attached to each leaf. */
+function loadingDoors(d: Drawing, p: Wall, half: number, bottom: number, height: number, open: number, grille = false) {
+ d.face([p(-half, bottom), p(half, bottom), p(half, bottom + height), p(-half, bottom + height)], 0x68726c, 0)
+ for (const sign of [-1, 1]) {
+ const shift = sign * Math.max(0, Math.min(1, open)) * half * 0.65
+ const left = (sign < 0 ? -half : 0) + shift, right = left + half
+ const at = (s: number, z: number) => p(s, z, 0.035)
+ d.face([at(left, bottom), at(right, bottom), at(right, bottom + height), at(left, bottom + height)], wood[1], 0.9)
+ for (const z of [bottom + 2, bottom + height - 2]) beam(d, at(left, z), at(right, z), 0.8)
+ beam(d, at(left + 0.3 * U, bottom + 2), at(right - 0.3 * U, bottom + height - 2), 0.8)
+ for (const x of [1, 2]) d.line([at(left + half * x / 3, bottom), at(left + half * x / 3, bottom + height)], 0.45, 0x987a54)
+ const handle = sign < 0 ? right - 0.5 * U : left + 0.5 * U
+ d.line([p(handle, bottom + 8, 0.05), p(handle, bottom + 11, 0.05)], 1, iron[2])
+ if (grille) {
+ const center = (left + right) / 2, z = bottom + height - 7
+ d.face([p(center - U, z, 0.055), p(center + U, z, 0.055), p(center + U, z + 4, 0.055), p(center - U, z + 4, 0.055)], 0x4f5a53, 0.7)
+ for (const x of [-0.6, 0, 0.6]) d.line([p(center + x * U, z, 0.06), p(center + x * U, z + 4, 0.06)], 0.65, iron[0])
+ }
+ }
+}
+
+export function tradeEntrance(d: Drawing, id: "mill" | "watchhouse", side: Side, a: number, fit: number, open: number) {
+ const p: Wall = (s, z, out = 0.02) => d.wall(side, a, s, z * fit, out)
+ const half = (id === "mill" ? 3.5 : 3) * U, height = id === "mill" ? 26 : 22
+ loadingDoors(d, p, half, 1, height, open * (id === "mill" ? 1 : 0.25), id === "watchhouse")
+ for (const sign of [-1, 1]) beam(d, p(sign * (half + 0.6 * U), 0, 0.5 * U), p(sign * (half + 0.6 * U), height + 2, 0.5 * U), 1.6, id === "mill" ? wood : stone)
+ beam(d, p(-half - 1.3 * U, height + 2, 0.5 * U), p(half + 1.3 * U, height + 2, 0.5 * U), 1.8, id === "mill" ? wood : stone)
+ beam(d, p(-half - U, 0.5, 0.6 * U), p(half + U, 0.5, 0.6 * U), 1.2, stone)
+}
+
+export function millHoist(d: Drawing, a: number) {
+ const u = -4.5 * U, front = 13 * U
+ beam(d, [u, a, 36], [u, front, 36], 1.8)
+ beam(d, [u, a, 27], [u, front, 35], 1.2)
+ wheel(d, u, front - 1.25 * U, 34.5, 1.75)
+ d.line([[u, front, 34.5], [u, front, 12]], 0.6, 0x8a6a45)
+ d.sack(u, front, 5)
+ d.line([[u - U, front, 11], [u, front, 12], [u + U, front, 11]], 0.65, 0x8a6a45)
+ d.sack(-11 * U, 7 * U)
+}
+
+export function tradeSmokeOrigin(id: TradeYardId, doors?: BuildingOptions["doors"]): Vertex | null {
+ return id === "bakery" ? workshopPoint([-8 * U, -2 * U, 48.3], doors) : null
+}
+
+export function makeTradeYard(id: TradeYardId, options: BuildingOptions = {}) {
+ const d = new Drawing(id, kinds[id].title, tradeNotes[id]), fit = Math.max(0, Math.min(1, options.fit ?? 1))
+ d.asset.category = "buildings"; d.asset.reference = { type: "building", kind: id }; d.asset.footprint = kinds[id].size
+ if (options.plate !== false) d.plate(kinds[id].size)
+ const half = (id === "warehouse" ? 21 : 13.5) * U
+ block(d, 0, 0, half, half, 0, 1, stone, 0)
+ if (id === "warehouse") warehouse(d, fit, options.open ?? 0)
+ else if (id === "fishery") fishery(d, fit)
+ else if (id === "bakery") bakery(d, fit, options.open ?? 0)
+ else weaver(d, fit)
+ const asset = orient(d.asset, options.doors), origin = tradeSmokeOrigin(id, options.doors)
+ if (origin && options.motion !== false && fit > 0.75) asset.smokeEffect = { origin }
+ return asset
+}
+
+function warehouse(d: Drawing, fit: number, open: number) {
+ block(d, 0, -19 * U, 19 * U, 0.65 * U, 1, 31, stone)
+ for (const u of [-19 * U, 19 * U]) block(d, u, -7 * U, 0.65 * U, 12 * U, 1, 31, stone)
+ for (const u of [-13 * U, 13 * U]) block(d, u, 5 * U, 6 * U, 0.65 * U, 1, 31, stone)
+ block(d, 0, 5 * U, 6 * U, 0.65 * U, 28, 4, stone)
+ if (fit > 0) roof(d, 20.5 * U, 13.5 * U, -7 * U, 32, 9 * fit, 0x8a58a8)
+ if (fit <= 0.4) return
+ const p: Wall = (s, z, out = 0.02) => [s, 5.7 * U + out, z]
+ loadingDoors(d, p, 6 * U, 4, 24, open)
+ for (const u of [-6.7 * U, 6.7 * U]) beam(d, [u, 5.9 * U, 3], [u, 5.9 * U, 29], 1.7)
+ beam(d, [-11 * U, 5.9 * U, 29], [11 * U, 5.9 * U, 29], 1.4, iron)
+ block(d, 0, 10.5 * U, 18 * U, 5 * U, 1, 3, stone)
+ block(d, 0, 17 * U, 5 * U, 1.5 * U, 1, 1.5, stone)
+ // A clear central approach, with cargo kept on the loading platform beside it.
+ if (fit <= 0.75) return
+ d.crate(11 * U, 9 * U, 4, 0x8a58a8, 2.5 * U, 8)
+ d.crate(15 * U, 12 * U, 4, 0xd27a34, 1.5 * U, 6)
+ d.barrel(-10 * U, 9 * U, 1.8 * U, 4, 8)
+ d.crate(-10 * U, -9 * U, 1, 0x2f8c87, 2 * U, 7)
+ post(d, -15 * U, 9 * U, 44)
+ beam(d, [-15 * U, 9 * U, 43], [-15 * U, 17 * U, 43], 1.8)
+ beam(d, [-15 * U, 9 * U, 30], [-15 * U, 15 * U, 42], 1.5)
+ wheel(d, -15 * U, 15 * U, 41.5, 1.4)
+ d.line([[-15 * U, 16 * U, 41.5], [-15 * U, 16 * U, 13]], 0.75, 0x8a6a45)
+ d.crate(-15 * U, 16 * U, 5, 0x2f8c87, 1.7 * U, 6)
+ d.line([[-16.7 * U, 16 * U, 11], [-15 * U, 16 * U, 13], [-13.3 * U, 16 * U, 11]], 0.75, 0x8a6a45)
+}
+
+function bench(d: Drawing, u: number, v: number, a: number, b: number, z = 7) {
+ for (const x of [-a + 0.5 * U, a - 0.5 * U]) for (const y of [-b + 0.5 * U, b - 0.5 * U]) block(d, u + x, v + y, 0.35 * U, 0.35 * U, 1, z - 1)
+ block(d, u, v, a, b, z, 1)
+}
+
+function fishery(d: Drawing, fit: number) {
+ block(d, -5 * U, -6 * U, 7 * U, 6 * U, 1, 19, stone)
+ if (fit > 0) roof(d, 8 * U, 7 * U, -6 * U, 20, 10 * fit, 0x2f8c87, -5 * U)
+ if (fit <= 0.4) return
+ loadingDoors(d, (s, z, out = 0.02) => [s - 5 * U, out, z], 2.5 * U, 1, 16, 0)
+ d.face([[2.03 * U, -10 * U, 8], [2.03 * U, -5 * U, 8], [2.03 * U, -5 * U, 14], [2.03 * U, -10 * U, 14]], palette.glass, 0.8)
+ for (const v of [-11 * U, U]) post(d, 10 * U, v, 21)
+ beam(d, [10 * U, -11 * U, 20], [10 * U, U, 20], 1.5)
+ beam(d, [10 * U, -11 * U, 3], [10 * U, U, 3], 1.1)
+ // The mesh is tied to its frame at every edge, and reads from both sides.
+ for (let i = 0; i <= 8; i++) {
+ const v = (-11 + 12 * i / 8) * U
+ d.line([[10 * U, v, 3], [10 * U, v, 20]], 0.45, 0x6e9b91, 0.85)
+ }
+ for (let i = 0; i <= 6; i++) d.line([[10 * U, -11 * U, 3 + 17 * i / 6], [10 * U, U, 3 + 17 * i / 6]], 0.45, 0x6e9b91, 0.85)
+ if (fit <= 0.75) return
+ bench(d, -5 * U, 8 * U, 5 * U, 2.6 * U)
+ for (const u of [-8, -5, -2]) {
+ d.ellipsoid(u * U, 8 * U, 8.6, 0.7 * U, 1.8 * U, 0.65, 0x97b7ad, 0.55, 0xc8d8cb, 12)
+ d.face([[(u - 0.8) * U, 10.5 * U, 8.2], [(u + 0.8) * U, 10.5 * U, 8.2], [u * U, 9.5 * U, 8.7]], 0x789c93, 0.6)
+ }
+ d.barrel(9 * U, 9 * U, 2 * U, 1, 7, 0xa8c7c1)
+ d.crate(5 * U, -6 * U, 1, 0x2f8c87, 1.5 * U, 5)
+}
+
+function oven(d: Drawing, u: number, v: number, warm: boolean) {
+ block(d, u, v, 4.5 * U, 4 * U, 1, 5, stone)
+ const p = (t: number, inside: boolean, back: boolean): Vertex => [u + Math.cos(t) * (inside ? 3 : 4.3) * U, v + (back ? -3 : 4) * U, 12 + Math.sin(t) * (inside ? 4.8 : 6.5)]
+ for (let i = 0; i < 12; i++) {
+ const t = i * Math.PI / 12, n = (i + 1) * Math.PI / 12
+ d.face([p(t, false, false), p(n, false, false), p(n, true, false), p(t, true, false)], 0xe3d1b5, 0.65)
+ d.face([p(t, false, false), p(n, false, false), p(n, false, true), p(t, false, true)], pale(0xc9b48a, 0.6), 0.35)
+ d.face([p(t, true, false), p(n, true, false), p(n, true, true), p(t, true, true)], 0x8d8576, 0.3)
+ }
+ for (const x of [-3.65 * U, 3.65 * U]) block(d, u + x, v + 0.5 * U, 0.65 * U, 3.5 * U, 6, 6, stone)
+ const back: Vertex[] = [[u - 4.3 * U, v - 3 * U, 6], [u + 4.3 * U, v - 3 * U, 6], ...Array.from({ length: 13 }, (_, i) => p(i * Math.PI / 12, false, true))]
+ d.face(back, palette.right, 0.8)
+ d.face([[u - 3 * U, v - 2.95 * U, 6], [u + 3 * U, v - 2.95 * U, 6], ...Array.from({ length: 13 }, (_, i): Vertex => { const q = p(i * Math.PI / 12, true, true); return [q[0], q[1] + 0.05 * U, q[2]] })], 0x51554c, 0)
+ block(d, u, v + 0.5 * U, 3 * U, 3.5 * U, 6, 0.2, [warm ? 0xd6aa67 : 0x947c5c, 0x947c5c, 0x947c5c], 0)
+}
+
+function bakery(d: Drawing, fit: number, open: number) {
+ block(d, 0, -7 * U, 12 * U, 6 * U, 1, 27, stone)
+ if (fit > 0) roof(d, 13 * U, 7 * U, -7 * U, 28, 9 * fit, 0xc4523f)
+ if (fit <= 0.4) return
+ loadingDoors(d, (s, z, out = 0.02) => [s + 7 * U, -U + out, z], 2.5 * U, 1, 19, open * 0.5)
+ oven(d, -6 * U, 2 * U, open > 0.25)
+ const flueTop = 18 + 30 * fit
+ block(d, -8 * U, -2 * U, 1.6 * U, 1.6 * U, 18, 30 * fit, stone)
+ block(d, -8 * U, -2 * U, 2 * U, 2 * U, flueTop - 2, 2, stone)
+ d.face([[-9.2 * U, -3.2 * U, flueTop + 0.02], [-6.8 * U, -3.2 * U, flueTop + 0.02], [-6.8 * U, -0.8 * U, flueTop + 0.02], [-9.2 * U, -0.8 * U, flueTop + 0.02]], 0x68726c, 0)
+ if (fit <= 0.75) return
+ bench(d, 6 * U, 8 * U, 5.2 * U, 2.3 * U)
+ for (const u of [1 * U, 11 * U]) post(d, u, 10.8 * U, 18)
+ const top: Vertex[] = [[0, -0.8 * U, 22], [12 * U, -0.8 * U, 22], [12 * U, 11 * U, 18], [0, 11 * U, 18]]
+ d.face(top, pale(0xc4523f, 0.68), 0.8)
+ beam(d, [0, 11 * U, 18], [12 * U, 11 * U, 18], 1)
+ for (const u of [3, 6, 9]) for (const v of [7, 9]) {
+ d.ellipsoid(u * U, v * U, 8.8, U, 0.65 * U, 0.9, 0xd0a369, 0.45, 0xebce96, 12)
+ d.line([[(u - 0.3) * U, (v - 0.4) * U, 9.4], [(u + 0.3) * U, (v + 0.4) * U, 9.4]], 0.4, 0xa5804f)
+ }
+ d.barrel(-11 * U, 10 * U, U, 1, 7, 0xf1e9d5)
+ d.barrel(-8 * U, 11 * U, U, 1, 6)
+ beam(d, [9 * U, -U, 26], [9 * U, 3 * U, 26], 0.9, iron)
+ d.line([[9 * U, 2.5 * U, 26], [9 * U, 2.5 * U, 24]], 0.55)
+ d.ellipsoid(9 * U, 2.5 * U, 23, 2 * U, 0.55 * U, 1.3, 0xc5985f, 0.65, 0xebce96, 16)
+ for (const u of [8, 9, 10]) d.line([[u * U, 2.95 * U, 23], [(u + 0.3) * U, 2.95 * U, 24]], 0.45, 0x9c7546)
+}
+
+function weaver(d: Drawing, fit: number) {
+ block(d, 0, -12 * U, 12 * U, 0.65 * U, 1, 29, stone)
+ block(d, -12 * U, -6 * U, 0.65 * U, 6 * U, 1, 29, stone)
+ block(d, 6 * U, -9 * U, 6 * U, 3 * U, 1, 29, stone)
+ for (const u of [-12 * U, 12 * U]) post(d, u, U, 30)
+ beam(d, [-12 * U, U, 30], [12 * U, U, 30], 1.6)
+ if (fit > 0) roof(d, 13.5 * U, 7.5 * U, -6 * U, 30, 8 * fit, 0x8a58a8)
+ if (fit <= 0.4) return
+ loadingDoors(d, (s, z, out = 0.02) => [s + 6 * U, -6 * U + out, z], 2.5 * U, 1, 18, 0)
+ for (const u of [-4 * U, 4 * U]) {
+ post(d, u, 4 * U, 22)
+ post(d, u, -U, 19)
+ beam(d, [u, -U, 19], [u, 7 * U, 8], 1.1)
+ beam(d, [u, 4 * U, 2], [u, 8 * U, 2], 1.2)
+ }
+ for (const [v, z] of [[-1, 19], [4, 22], [7, 8]]) beam(d, [-4 * U, v! * U, z!], [4 * U, v! * U, z!], 1.5)
+ if (fit <= 0.75) return
+ d.face([[-3 * U, 2 * U, 14.875], [3 * U, 2 * U, 14.875], [3 * U, 7 * U, 8], [-3 * U, 7 * U, 8]], 0xb7a4ca, 0.7)
+ for (let i = 0; i <= 12; i++) {
+ const u = (-3 + i / 2) * U
+ d.line([[u, -U, 19], [u, 2 * U, 14.875]], 0.45, 0xd7ccb4)
+ d.line([[u, 2 * U, 14.9], [u, 7 * U, 8.03]], 0.3, 0xe4d9eb)
+ }
+ // Beater, heddle rail and treadles all connect to the loom frame.
+ for (const u of [-3.5 * U, 3.5 * U]) beam(d, [u, 4 * U, 10], [u, 4 * U, 21], 0.8)
+ for (const z of [10, 21]) beam(d, [-3.5 * U, 4 * U, z], [3.5 * U, 4 * U, z], 0.8)
+ beam(d, [-4 * U, 2 * U, 16], [4 * U, 2 * U, 16], 0.9)
+ for (const u of [-U, U]) beam(d, [u, -U, 4], [u, 7 * U, 1.5], 1.1)
+ d.cylinder(-8 * U, 8 * U, 1.6 * U, 1, 5, wood[2], wood[0], 0.7, 12)
+ bench(d, 9 * U, 7 * U, 2.7 * U, 3 * U)
+ for (const [v, color] of [[5, 0x8a58a8], [7, 0xc9ad5d], [9, 0x7097b5]] as const) {
+ d.cylinder(9 * U, v * U, U, 8, 0.7, wood[2], wood[0], 0.6, 12)
+ d.cylinder(9 * U, v * U, 0.65 * U, 8.7, 2.2, pale(color, 0.2), pale(color, 0.5), 0.4, 12)
+ d.cylinder(9 * U, v * U, U, 10.9, 0.5, wood[2], wood[0], 0.6, 12)
+ }
+}
+
+/** Early construction keeps the work apron open instead of filling the plot with a cube. */
+export function tradeConstruction(id: TradeYardId, build: number, share: number | null, doors: BuildingOptions["doors"]) {
+ const d = new Drawing(id, `${kinds[id].title} · construction`, "Store walls and an open work apron."), stage = buildStages(build)
+ const half = (id === "warehouse" ? 21 : 13.5) * U, height = id === "fishery" ? 20 : id === "bakery" ? 28 : id === "weaver" ? 30 : 32
+ d.asset.footprint = kinds[id].size
+ if (share !== null) for (let i = 0; i < Math.ceil(share * 3); i++) d.crate(half - 2 * U - i * 3 * U, half - 2 * U, 0, 0x8f9891)
+ if (stage.walls > 0) {
+ block(d, 0, 0, half, half, 0, Math.max(0.1, stage.walls), stone, 0)
+ const rear = id === "warehouse" ? -19 * U : -12 * U
+ block(d, 0, rear, half - U, 0.6 * U, 1, Math.max(0.1, height * stage.walls), stone)
+ }
+ if (stage.frame > 0) {
+ const rear = id === "warehouse" ? -19 * U : -12 * U, front = id === "warehouse" ? 5 * U : 0
+ for (const u of [-half + U, half - U]) for (const v of [rear, front]) post(d, u, v, Math.max(2.1, height * stage.frame))
+ }
+ return orient(d.asset, doors)
+}
diff --git a/src/asset-lab/workshops.ts b/src/asset-lab/workshops.ts
new file mode 100644
index 0000000..62ba8a2
--- /dev/null
+++ b/src/asset-lab/workshops.ts
@@ -0,0 +1,307 @@
+import { buildStages } from "../art.ts"
+import { kinds, type KindId } from "../content.ts"
+import { U } from "../iso.ts"
+import { rockOutcrop } from "./land.ts"
+import { Drawing, palette, pale, type InkAsset, type Side, type Vertex } from "./primitives.ts"
+import type { BuildingOptions } from "./buildings.ts"
+
+export const workshopIds = ["mine", "smithy", "sawmill"] as const
+export type WorkshopId = typeof workshopIds[number]
+export const isWorkshop = (id: KindId): id is WorkshopId => workshopIds.some(kind => kind === id)
+export const wood = [0xe9d2a8, 0xd0b58c, 0xb08a5e] as const
+export const stone = [0xeeefea, 0xdcded7, 0xc9ccc4] as const
+export const iron = [0xa4ada6, 0x79847d, 0x5a645e] as const
+const floorScale = 32 * Math.SQRT2, heightScale = 1 / Math.cos(Math.PI / 6)
+
+/** Local +v is the open working face. Orient it towards a connected road. */
+export function workshopPoint(point: Vertex, doors?: BuildingOptions["doors"]): Vertex {
+ const side = (["left", "right", "backLeft", "backRight"] as const).find(side => doors?.[side]) ?? "left"
+ const [u, v, z] = point
+ switch (side) {
+ case "right": return [v, -u, z]
+ case "backLeft": return [-u, -v, z]
+ case "backRight": return [-v, u, z]
+ default: return point
+ }
+}
+
+export function workshopSmokeOrigin(id: WorkshopId, doors?: BuildingOptions["doors"]): Vertex | null {
+ return id === "smithy" ? workshopPoint([-6 * U, 2 * U, 56.3], doors) : null
+}
+
+export function orient(asset: InkAsset, doors?: BuildingOptions["doors"]) {
+ for (const face of asset.faces) face.points = face.points.map(p => workshopPoint(p, doors))
+ for (const stroke of asset.strokes) stroke.points = stroke.points.map(p => workshopPoint(p, doors))
+ return asset
+}
+
+export function block(d: Drawing, u: number, v: number, a: number, b: number, z: number, h: number, colors: readonly [number, number, number] = wood, width = 0.8) {
+ d.box(u, v, a, b, z, h, ...colors, width)
+}
+
+/** Square-section structural member. Width is in rendered world units. */
+export function beam(d: Drawing, from: Vertex, to: Vertex, width = 1.5, colors: readonly [number, number, number] = wood) {
+ const a = [from[0] * floorScale, from[1] * floorScale, from[2] * heightScale],
+ b = [to[0] * floorScale, to[1] * floorScale, to[2] * heightScale]
+ const delta = b.map((n, i) => n - a[i]!), length = Math.hypot(...delta)
+ if (length < 0.001) return
+ const direction = delta.map(n => n / length)
+ const cross = (x: number[], y: number[]) => [x[1]! * y[2]! - x[2]! * y[1]!, x[2]! * y[0]! - x[0]! * y[2]!, x[0]! * y[1]! - x[1]! * y[0]!]
+ const normal = cross(direction, Math.abs(direction[2]!) > 0.9 ? [1, 0, 0] : [0, 0, 1]), norm = Math.hypot(...normal)
+ const x = normal.map(n => n / norm * width / 2), y = cross(direction, x)
+ const ring = (center: number[]) => [[-1, -1], [1, -1], [1, 1], [-1, 1]].map(([sx, sy]): Vertex => {
+ const p = center.map((n, i) => n + sx! * x[i]! + sy! * y[i]!)
+ return [p[0]! / floorScale, p[1]! / floorScale, p[2]! / heightScale]
+ })
+ const lower = ring(a), upper = ring(b)
+ for (let i = 0; i < 4; i++) d.face([lower[i]!, lower[(i + 1) % 4]!, upper[(i + 1) % 4]!, upper[i]!], colors[i % 3]!, 0.65)
+ d.face([...lower].reverse(), colors[2], 0.65)
+ d.face(upper, colors[0], 0.65)
+}
+
+export function post(d: Drawing, u: number, v: number, height: number, bottom = 2) {
+ block(d, u, v, 0.8 * U, 0.8 * U, 0, bottom, stone)
+ if (height > bottom) block(d, u, v, 0.55 * U, 0.55 * U, bottom, height - bottom)
+}
+
+export function roof(d: Drawing, a: number, b: number, v: number, z: number, rise: number, color: number, offsetU = 0) {
+ const startFace = d.asset.faces.length, startStroke = d.asset.strokes.length
+ d.face([[-a, v - b, z], [-a, v + b, z], [0, v + b, z + rise], [0, v - b, z + rise]], pale(color, 0.74), 1)
+ d.face([[a, v - b, z], [a, v + b, z], [0, v + b, z + rise], [0, v - b, z + rise]], pale(color, 0.58), 1)
+ for (const sign of [-1, 1]) d.face([[-a, v + sign * b, z], [a, v + sign * b, z], [0, v + sign * b, z + rise]], palette.roof, 1)
+ d.face([[-a, v - b, z], [a, v - b, z], [a, v + b, z], [-a, v + b, z]], palette.left, 0)
+ if (offsetU) {
+ const shift = ([u, v, z]: Vertex): Vertex => [u + offsetU, v, z]
+ for (const f of d.asset.faces.slice(startFace)) f.points = f.points.map(shift)
+ for (const s of d.asset.strokes.slice(startStroke)) s.points = s.points.map(shift)
+ }
+}
+
+/** Wheel with a horizontal axle, with real thickness and an open centre. */
+export function wheel(d: Drawing, u: number, v: number, z: number, radius: number, spokes = true) {
+ const n = 20, point = (i: number, r: number, x: number): Vertex => {
+ const t = i / n * Math.PI * 2
+ return [u + x, v + Math.cos(t) * r / floorScale, z + Math.sin(t) * r / heightScale]
+ }
+ for (let i = 0; i < n; i++) {
+ const j = (i + 1) % n
+ for (const x of [-0.2 * U, 0.2 * U]) d.face([point(i, radius, x), point(j, radius, x), point(j, radius * 0.77, x), point(i, radius * 0.77, x)], iron[1], 0)
+ d.face([point(i, radius, -0.2 * U), point(j, radius, -0.2 * U), point(j, radius, 0.2 * U), point(i, radius, 0.2 * U)], iron[2], 0)
+ }
+ const rim = Array.from({ length: n + 1 }, (_, i) => point(i, radius, 0.2 * U))
+ d.line(rim, 0.7)
+ if (spokes) for (let i = 0; i < 4; i++) beam(d, [u, v, z], point(i * n / 4, radius * 0.9, 0), 0.9, iron)
+ block(d, u, v, 0.35 * U, 0.35 * U, z - 0.6, 1.2, iron, 0.6)
+}
+
+export function makeWorkshop(id: WorkshopId, options: BuildingOptions = {}) {
+ const notes = {
+ mine: "Timber headframe and recessed adit, with rails, ore cart and an open sorting yard. The 2×2 plot stays unchanged.",
+ smithy: "An open-sided forge shed: stone hearth, tapered smoke hood, horned anvil and tool bench. The 2×2 plot stays unchanged.",
+ sawmill: "An open saw yard with a roofed frame saw, flywheel, log supports and separate plank stacks. The 2×2 plot stays unchanged."
+ }
+ const d = new Drawing(id, kinds[id].title, notes[id]), fit = Math.max(0, Math.min(1, options.fit ?? 1))
+ d.asset.category = "buildings"
+ d.asset.reference = { type: "building", kind: id }
+ d.asset.footprint = kinds[id].size
+ if (options.plate !== false) d.plate(kinds[id].size)
+ block(d, 0, 0, 13.5 * U, 13.5 * U, 0, 1, stone, 0)
+ if (id === "mine") mine(d, fit)
+ else if (id === "smithy") smithy(d, fit, options.open ?? 0)
+ else sawmill(d, fit)
+ const asset = orient(d.asset, options.doors)
+ const origin = workshopSmokeOrigin(id, options.doors)
+ if (origin && options.motion !== false && fit > 0.75) asset.smokeEffect = { origin }
+ return asset
+}
+
+function mine(d: Drawing, fit: number) {
+ // The adit is a real recess between two rock cheeks, not a dark door painted on a box.
+ rockOutcrop(d, -9 * U, -6 * U, 4.5 * U, 27, true, 1)
+ rockOutcrop(d, 9 * U, -6 * U, 4.5 * U, 31, true, 3)
+ block(d, 0, -11 * U, 5 * U, U, 1, 27, stone)
+ d.face([[-4 * U, -10 * U, 1.02], [4 * U, -10 * U, 1.02], [4 * U, -10 * U, 24], [-4 * U, -10 * U, 24]], 0x57615d, 0)
+ for (const u of [-4.5 * U, 4.5 * U]) {
+ block(d, u, -5 * U, 0.7 * U, 6 * U, 1, 24, stone)
+ post(d, u, U, 25)
+ }
+ block(d, 0, -5 * U, 5.2 * U, 6 * U, 25, 3, stone)
+ block(d, 0, 1.1 * U, 5.6 * U, U, 25, 3)
+ // Four load-bearing posts, cross-bracing, pulley and a rope down to the shaft.
+ for (const u of [-6 * U, 6 * U]) for (const v of [-10 * U, -3 * U]) post(d, u, v, 49)
+ for (const v of [-10 * U, -3 * U]) {
+ beam(d, [-6 * U, v, 49], [6 * U, v, 49], 2.3)
+ beam(d, [-6 * U, v, 29], [6 * U, v, 45], 1.4)
+ }
+ for (const u of [-6 * U, 6 * U]) {
+ beam(d, [u, -10 * U, 49], [u, -3 * U, 49], 1.8)
+ beam(d, [u, -10 * U, 31], [u, -3 * U, 46], 1.4)
+ }
+ if (fit > 0) roof(d, 7.5 * U, 4.8 * U, -6.5 * U, 50, 6 * fit, 0x5a6479)
+ if (fit <= 0.4) return
+ beam(d, [-6 * U, -6.5 * U, 45], [6 * U, -6.5 * U, 45], 1.2, iron)
+ wheel(d, 0, -6.5 * U, 45, 2.7)
+ d.line([[0, -5.5 * U, 45], [0, -5.5 * U, 3]], 0.65, 0x68726c)
+ block(d, 0, -5.5 * U, 1.2 * U, 1.2 * U, 1, 3, iron)
+ for (const v of [-8, -5, -2, 1, 4, 7, 10, 13]) block(d, 0, v * U, 3.5 * U, 0.5 * U, 1, 0.8, wood, 0.6)
+ for (const u of [-2 * U, 2 * U]) beam(d, [u, -9 * U, 2], [u, 14 * U, 2], 0.85, iron)
+ if (fit <= 0.75) return
+ const cv = 7.5 * U
+ for (const u of [-2.9 * U, 2.9 * U]) for (const v of [cv - 2 * U, cv + 2 * U]) wheel(d, u, v, 3, 1.8, false)
+ block(d, 0, cv, 3.1 * U, 3 * U, 4, 1, iron)
+ // Four separate sides leave the ore cart visibly open at the top.
+ for (const u of [-3.1 * U, 3.1 * U]) block(d, u, cv, 0.3 * U, 3.1 * U, 5, 5, iron)
+ for (const v of [cv - 3 * U, cv + 3 * U]) block(d, 0, v, 3.1 * U, 0.3 * U, 5, 5, iron)
+ for (const [u, v] of [[-1, 0], [1, 1], [0, -1.5]]) d.ellipsoid(u! * U, cv + v! * U, 8.5, 1.5 * U, 1.5 * U, 2, 0x737a8c, 0.7, 0xa9aebb, 8)
+ block(d, 10 * U, 8 * U, 2.5 * U, 3.5 * U, 1, 2, wood)
+ for (const u of [8 * U, 12 * U]) block(d, u, 8 * U, 0.4 * U, 3.5 * U, 3, 5)
+ for (const v of [4.5 * U, 11.5 * U]) block(d, 10 * U, v, 2.5 * U, 0.4 * U, 3, 5)
+ d.ellipsoid(10 * U, 8 * U, 5.5, 1.7 * U, 2.7 * U, 2.5, 0x737a8c, 0.7, 0xa9aebb, 8)
+ // Pickaxe on a timber-supported rack beside the sorting bin.
+ post(d, -11 * U, 8 * U, 10)
+ beam(d, [-11 * U, 8 * U, 5], [-8 * U, 8 * U, 13], 1.1)
+ beam(d, [-10 * U, 8 * U, 12], [-6 * U, 8 * U, 13], 1.3, iron)
+}
+
+function smithy(d: Drawing, fit: number, open: number) {
+ block(d, -5.5 * U, -12 * U, 6.5 * U, 0.7 * U, 1, 31, stone)
+ block(d, -12 * U, -5.5 * U, 0.7 * U, 6.5 * U, 1, 31, stone)
+ for (const u of [-12 * U, U]) post(d, u, U, 32)
+ post(d, U, -12 * U, 32)
+ beam(d, [-12 * U, U, 31], [U, U, 31], 2)
+ beam(d, [-12 * U, U, 23], [-8 * U, U, 31], 1.7)
+ beam(d, [U, U, 23], [-3 * U, U, 31], 1.7)
+ if (fit > 0) roof(d, 8 * U, 8 * U, -5.5 * U, 32, 9 * fit, 0xb04a39, -5.5 * U)
+ const u = -6 * U, v = 2 * U
+ block(d, u, v, 4 * U, 4 * U, 1, 7, stone)
+ block(d, u, v - 3.2 * U, 4 * U, 0.8 * U, 8, 16, stone)
+ for (const x of [u - 3.3 * U, u + 3.3 * U]) block(d, x, v, 0.7 * U, 3 * U, 8, 16, stone)
+ d.face([[u - 2.6 * U, v - 2.3 * U, 8], [u + 2.6 * U, v - 2.3 * U, 8], [u + 2.6 * U, v - 2.3 * U, 20], [u - 2.6 * U, v - 2.3 * U, 20]], 0x4b524e, 0)
+ if (fit > 0.15) {
+ const base = [[-4, -4], [4, -4], [4, 4], [-4, 4]], top = [[-2, -2], [2, -2], [2, 2], [-2, 2]]
+ for (let i = 0; i < 4; i++) {
+ const j = (i + 1) % 4
+ const p = (xy: number[], z: number): Vertex => [u + xy[0]! * U, v + xy[1]! * U, z]
+ d.face([p(base[i]!, 24), p(base[j]!, 24), p(top[j]!, 33), p(top[i]!, 33)], i % 2 ? 0x9da69b : 0xc4cbc0, 0.8)
+ }
+ block(d, u, v, 2 * U, 2 * U, 33, 23 * fit, stone)
+ block(d, u, v, 2.4 * U, 2.4 * U, 33 + 23 * fit - 2, 2, stone)
+ d.face([[u - 1.5 * U, v - 1.5 * U, 33 + 23 * fit + 0.02], [u + 1.5 * U, v - 1.5 * U, 33 + 23 * fit + 0.02], [u + 1.5 * U, v + 1.5 * U, 33 + 23 * fit + 0.02], [u - 1.5 * U, v + 1.5 * U, 33 + 23 * fit + 0.02]], 0x68726c, 0)
+ }
+ if (fit <= 0.75) return
+ block(d, u, v, 2.4 * U, 2.8 * U, 8, 0.4, [open > 0.25 ? 0xd8aa5e : 0x8a7860, 0x8a7860, 0x6d7469], 0)
+ // A wide horn and narrow waist keep the anvil legible from the street.
+ d.cylinder(5 * U, 5 * U, 2.3 * U, 1, 5, wood[2], wood[0], 0.8, 12)
+ block(d, 5 * U, 5 * U, 2.2 * U, 1.4 * U, 6, 1, iron)
+ block(d, 5 * U, 5 * U, U, 0.8 * U, 7, 2.5, iron)
+ const plan = [[-2.5, -1.2], [1.7, -1.2], [4.5, 0], [1.7, 1.2], [-2.5, 1.2]]
+ const ring = (z: number) => plan.map(([x, y]): Vertex => [(5 + x!) * U, (5 + y!) * U, z])
+ const bottom = ring(9.5), upper = ring(11.3)
+ for (let i = 0; i < plan.length; i++) d.face([bottom[i]!, bottom[(i + 1) % plan.length]!, upper[(i + 1) % plan.length]!, upper[i]!], iron[1], 0.7)
+ d.face(upper, iron[0], 0.8)
+ workbench(d, -6 * U, 9 * U)
+ beam(d, [-7 * U, 9 * U, 7], [-4 * U, 9 * U, 7], 1.1)
+ block(d, -4 * U, 9 * U, 0.7 * U, 1.3 * U, 6.6, 1.8, iron)
+ d.barrel(10 * U, -7 * U, 1.5 * U, 1, 6, 0x68726c)
+}
+
+function workbench(d: Drawing, u: number, v: number) {
+ for (const x of [-2.5 * U, 2.5 * U]) for (const y of [-U, U]) block(d, u + x, v + y, 0.35 * U, 0.35 * U, 1, 5)
+ block(d, u, v, 3.2 * U, 1.7 * U, 6, 1)
+}
+
+function sawmill(d: Drawing, fit: number) {
+ block(d, 0, -12 * U, 12 * U, 0.6 * U, 1, 35, stone)
+ for (const u of [-12 * U, 12 * U]) {
+ post(d, u, -12 * U, 36)
+ post(d, u, 4 * U, 32)
+ beam(d, [u, -12 * U, 36], [u, 4 * U, 32], 1.8)
+ beam(d, [u, 4 * U, 24], [u, -U, 33.25], 1.5)
+ }
+ beam(d, [-12 * U, 4 * U, 32], [12 * U, 4 * U, 32], 2)
+ if (fit > 0) {
+ const top: Vertex[] = [[-13.5 * U, -13 * U, 36.7], [13.5 * U, -13 * U, 36.7], [13.5 * U, 5 * U, 32.3], [-13.5 * U, 5 * U, 32.3]]
+ const bottom = top.map(([u, v, z]): Vertex => [u, v, z - 0.8])
+ d.face(top, pale(0x8a6a45, 0.76), 1)
+ d.face([...bottom].reverse(), pale(0x8a6a45, 0.65), 0)
+ for (let i = 0; i < 4; i++) d.face([bottom[i]!, bottom[(i + 1) % 4]!, top[(i + 1) % 4]!, top[i]!], pale(0x8a6a45, 0.58), 0.6)
+ block(d, 0, 4.8 * U, 13.5 * U, 0.35 * U, 31, 1.3, [pale(0xd27a34, 0.4), pale(0xd27a34, 0.4), pale(0xd27a34, 0.25)])
+ }
+ // The cutting frame stands in the open bay. Logs run through its centre.
+ for (const u of [-4 * U, 4 * U]) {
+ post(d, u, 3 * U, 25)
+ beam(d, [u, 3 * U, 4], [u, -2 * U, 1], 1.5)
+ }
+ block(d, 0, 3 * U, 5 * U, 0.6 * U, 23, 2)
+ block(d, 0, 3 * U, 5 * U, 0.7 * U, 7, 1.5)
+ if (fit <= 0.4) return
+ for (const v of [-6 * U, 10 * U]) {
+ for (const u of [-2.2 * U, 2.2 * U]) post(d, u, v, 6)
+ block(d, 0, v, 3 * U, 0.8 * U, 6, 1.2)
+ }
+ d.log("v", 0, -9 * U, 13 * U, 7, 2.8, 0xb08a5e, 0xe9d2a8)
+ // The blade lands in its upper and lower guide beams; it cuts into the supported log.
+ block(d, 0, 3 * U, 0.35 * U, 0.18 * U, 8.5, 14.5, iron, 0.6)
+ for (let z = 10; z < 23; z += 2) d.face([[-0.35 * U, 3.2 * U, z], [0.6 * U, 3.2 * U, z + 0.6], [-0.35 * U, 3.2 * U, z + 1.2]], iron[1], 0)
+ beam(d, [4 * U, 3 * U, 10], [7 * U, 3 * U, 10], 1.5, iron)
+ wheel(d, 7 * U, 3 * U, 10, 5.5)
+ if (fit <= 0.75) return
+ for (const [u, z] of [[8, 1], [11, 1], [9.5, 5]]) d.log("v", u! * U, 6 * U, 13 * U, z!, 2, wood[2], wood[0])
+ for (let i = 0; i < 4; i++) block(d, -8 * U, 8.5 * U, 2.5 * U, 5 * U, 1 + i * 1.8, 1.4, [0xf0c59a, 0xe2a873, 0xd2945c], 0.7)
+ workbench(d, -7 * U, -7 * U)
+ beam(d, [-8 * U, -7 * U, 7], [-5 * U, -7 * U, 7], 0.9, iron)
+}
+
+/** The open yard is assembled as posts and a rear wall, rather than a temporary solid cube. */
+export function workshopConstruction(id: WorkshopId, build: number, share: number | null, doors: BuildingOptions["doors"]) {
+ const d = new Drawing(id, `${kinds[id].title} · construction`, "Open workshop frame and supplied materials.")
+ d.asset.footprint = 2
+ const stage = buildStages(build)
+ if (share !== null) {
+ const half = 14 * U
+ for (const u of [-half, half]) for (const v of [-half, half]) d.line([[u, v, 0], [u, v, 6]], 1)
+ for (let i = 0; i < Math.ceil(share * 3); i++) d.crate((9 - i * 3) * U, 10 * U, 0, 0x8f9891)
+ }
+ if (stage.walls > 0) block(d, 0, 0, 13.5 * U, 13.5 * U, 0, Math.max(0.1, stage.walls), stone, 0)
+ if (stage.frame > 0) {
+ const height = (id === "mine" ? 49 : 32) * stage.frame
+ const us = id === "mine" ? [-6 * U, 6 * U] : [-12 * U, id === "smithy" ? U : 12 * U]
+ const vs = id === "mine" ? [-10 * U, -3 * U] : [-12 * U, id === "sawmill" ? 4 * U : U]
+ for (const u of us) for (const v of vs) {
+ beam(d, [u, v, 0], [u, v, height], 1.4)
+ }
+ beam(d, [us[0]!, vs[0]!, height], [us[1]!, vs[0]!, height], 1.4)
+ }
+ if (stage.walls > 0) {
+ const height = Math.max(0.1, 32 * stage.walls)
+ block(d, id === "smithy" ? -5.5 * U : 0, -12 * U, (id === "smithy" ? 6.5 : 12) * U, 0.6 * U, 1, height, stone)
+ if (id === "smithy") block(d, -12 * U, -5.5 * U, 0.6 * U, 6.5 * U, 1, height, stone)
+ }
+ return orient(d.asset, doors)
+}
+
+/** A civic entry uses a framed timber double door and a supported pediment, not a shop awning. */
+export function townHallEntrance(d: Drawing, side: Side, a: number, fit: number, open: number) {
+ const wall = (s: number, z: number, out = 0.01) => d.wall(side, a, s, z * fit, out)
+ const box = (s: number, out: number, half: number, depth: number, z: number, h: number, colors: readonly [number, number, number] = stone) => {
+ const [u, v] = d.wall(side, a, s, 0, out)
+ block(d, u, v, side === "right" || side === "backRight" ? depth : half, side === "right" || side === "backRight" ? half : depth, z * fit, h * fit, colors)
+ }
+ box(0, 1.4 * U, 5.4 * U, 1.4 * U, 0, 1.2)
+ box(0, 0.9 * U, 4.8 * U, 0.9 * U, 1.2, 1.2)
+ d.face([wall(-3.2 * U, 2.4), wall(3.2 * U, 2.4), wall(3.2 * U, 22), wall(-3.2 * U, 22)], 0x68726c, 0.8)
+ const angle = Math.max(0, Math.min(1, open)) * Math.PI / 9
+ for (const sign of [-1, 1]) {
+ const leaf = (inner: boolean, z: number) => wall(sign * (3 * U - (inner ? 3 * U * Math.cos(angle) : 0)), z, 0.025 + (inner ? 3 * U * Math.sin(angle) : 0))
+ d.face([leaf(false, 2.4), leaf(true, 2.4), leaf(true, 21.5), leaf(false, 21.5)], 0xbda683, 0.8)
+ const handle = sign * (3 * U - 2.4 * U * Math.cos(angle))
+ d.line([wall(handle, 10, 0.04 + 2.4 * U * Math.sin(angle)), wall(handle, 12, 0.04 + 2.4 * U * Math.sin(angle))], 0.8, 0x7d6140)
+ box(sign * 4.2 * U, 0.7 * U, 0.7 * U, 0.7 * U, 2.4, 20)
+ box(sign * 4.2 * U, 0.7 * U, U, 0.9 * U, 21.4, 1.8)
+ }
+ box(0, 0.7 * U, 5.3 * U, 0.9 * U, 23.2, 1.8)
+ const back = [wall(-5.3 * U, 25, 0.01), wall(5.3 * U, 25, 0.01), wall(0, 29, 0.01)],
+ front = [wall(-5.3 * U, 25, 1.6 * U), wall(5.3 * U, 25, 1.6 * U), wall(0, 29, 1.6 * U)]
+ d.face(front, palette.roof, 0.8)
+ for (let i = 0; i < 3; i++) d.face([back[i]!, back[(i + 1) % 3]!, front[(i + 1) % 3]!, front[i]!], palette.left, 0.8)
+}
diff --git a/src/model-review/main.ts b/src/model-review/main.ts
index 824c4a2..ab15f06 100644
--- a/src/model-review/main.ts
+++ b/src/model-review/main.ts
@@ -1,9 +1,15 @@
import * as THREE from "three"
import { assetById } from "../asset-lab/assets.ts"
import { buildAsset, exportAsset } from "../asset-lab/renderer.ts"
+import { kindIds } from "../content.ts"
+import { ruralIds } from "../asset-lab/rural.ts"
import "./style.css"
const families = {
+ town: { title: "All buildings", ids: [...kindIds, "market-hall", "church"] },
+ rural: { title: "Final refinements", ids: ruralIds },
+ trades: { title: "Trade buildings", ids: ["mill", "warehouse", "fishery", "bakery", "weaver", "watchhouse"] },
+ workshops: { title: "Workshop batch", ids: ["mine", "smithy", "sawmill", "townhall"] },
fixes: { title: "Review fixes", ids: ["mill","bakery","weaver","warehouse","mine","farm","chapel","hospital","smokehouse","builder","townhouse","quarry","stone-full","stone-quarried","ore-full","ore-quarried","stone-full-2x1","stone-full-2x2","stone-full-3x3","ore-full-2x1","ore-full-2x2","ore-full-3x3","problem-marker","smoke","firewatch"] },
buildings: { title: "Buildings", ids: ["granary", "smokehouse", "firewatch", "healer", "hospital", "watchhouse", "builder"] },
ornaments: { title: "Parks", ids: ["park-sample", "park-lamp", "park-fountain", "park-statue", "paved-street"] },
@@ -15,8 +21,14 @@ const families = {
upgrades: { title: "Upgrades & worked faces", ids: ["market", "market-hall", "chapel", "church", "stone-full", "stone-quarried", "stone-worked", "ore-full", "ore-quarried", "ore-worked"] }
} as const
type Family = keyof typeof families
+const introductions: Partial<Record<Family, { heading: string; eyebrow: string; description: string; aside: string }>> = {
+ town: { heading: "The whole town.<br>The same ink.", eyebrow: "The complete building collection", description: "Every building kind, plus the market hall and church. Compare their silhouettes, turn the collection, and open any building for a closer look.", aside: `${kindIds.length} building kinds<br>2 upgraded buildings<br><span>Work yards, homes for trades,<br>stores and town services.</span>` },
+ rural: { heading: "Small things.<br>A better town.", eyebrow: "The final building pass", description: "Timber entrances, nursery beds, farm details, a quieter chapel and a connected fire-watch lookout. Inspect all nine refinements together.", aside: "9 refined buildings<br>Original plots<br><span>Connected structures,<br>clear entrances and useful yards.</span>" },
+ workshops: { heading: "Room to work.<br>The same ink.", eyebrow: "The first building batch", description: "Open work yards around real tools, and a civic entrance for the town hall. Turn the models to inspect their working space.", aside: "4 revised buildings<br>3 open work yards<br><span>Original plots, pale surfaces,<br>fine ink and purposeful tools.</span>" },
+ trades: { heading: "Built for the job.<br>The same ink.", eyebrow: "The second building batch", description: "Loading aprons, a fishing net, an open oven and a working loom. Inspect the equipment and entrances from every side.", aside: "6 revised buildings<br>Original plots<br><span>Timber loading doors, open bays,<br>and equipment for each trade.</span>" }
+}
const root = document.querySelector<HTMLElement>("#review")!
-root.innerHTML = `<header><a href="/">Inkline Town</a><span>PR 03 / MODEL REVIEW</span><a href="/map-lab.html">Town map ↗</a></header>
+root.innerHTML = `<header><a href="/">Inkline Town</a><span>TOWN MODEL REVIEW</span><a href="/map-lab.html">Town map ↗</a></header>
<section class="intro"><div><p class="eyebrow">A town with a little more life</p><h1>New places.<br>The same ink.</h1><p>Inspect the models together, turn them around, then open any one for a closer look.</p></div><aside>7 buildings<br>3 park furnishings<br>3 home tiers<br><span>Plus people, hazards, paving,<br>snow and signs of wear.</span></aside></section>
<nav aria-label="Model collections"></nav><section class="camera"><label>Turn the models <input aria-label="Model rotation" type="range" min="-180" max="180" value="0"><output>0°</output></label><button id="rear">See the back</button><button id="reset">Reset view</button><button id="sheet">Save model sheet</button><a id="sheet-link" hidden download>Download sheet ↗</a><label>View <select aria-label="View elevation"><option value="30">Street angle</option><option value="50">From above</option><option value="15">Near the ground</option></select></label></section>
<section class="grid" aria-label="3D models"></section><footer><a href="/park-lab.html">Built park & running water ↗</a> · <a href="/effects-lab.html">Animated house effects ↗</a> · Drag a model to turn the collection · <a href="/asset-lab.html">Full asset catalogue ↗</a> · <a href="/">Play this town ↗</a></footer>`
@@ -28,6 +40,14 @@ renderer.domElement.className = "models"; document.body.append(renderer.domEleme
let family: Family = "buildings", yaw = 0, pitch = 30, renders = 0
let sheetUrl = ""
let models: Array<{ scene: THREE.Scene; camera: THREE.OrthographicCamera; built: ReturnType<typeof buildAsset>; view: HTMLElement; center: THREE.Vector3; size: THREE.Vector3 }> = []
+// Include both the tower height and the ground plane projected into the view.
+// Taking only the larger dimension clips the mill's foreground at street angle.
+function viewHeight(size: THREE.Vector3, heading: number, angle: number, aspect: number) {
+ const width = Math.abs(Math.cos(heading)) * size.x + Math.abs(Math.sin(heading)) * size.z
+ const depth = Math.abs(Math.sin(heading)) * size.x + Math.abs(Math.cos(heading)) * size.z
+ const height = Math.abs(Math.cos(angle)) * size.y + Math.abs(Math.sin(angle)) * depth
+ return Math.max(height, width / aspect, 18) * 1.12
+}
function render() {
renderer.setSize(innerWidth, innerHeight, false)
renderer.setScissorTest(false); renderer.clear(); renderer.setScissorTest(true)
@@ -35,8 +55,7 @@ function render() {
const r = model.view.getBoundingClientRect()
if (r.bottom <= 0 || r.top >= innerHeight) continue
const heading = (45 + yaw) * Math.PI / 180, angle = pitch * Math.PI / 180,
- extent = Math.max(model.size.y, Math.hypot(model.size.x, model.size.z) * 0.75, 18) * 1.3,
- vertical = Math.max(extent, Math.hypot(model.size.x, model.size.z) * r.height / r.width * 1.4), camera = model.camera
+ vertical = viewHeight(model.size, heading, angle, r.width / r.height), camera = model.camera
camera.top = vertical / 2; camera.bottom = -camera.top; camera.left = -vertical * r.width / r.height / 2; camera.right = -camera.left
camera.position.copy(model.center).add(new THREE.Vector3(Math.sin(heading) * Math.cos(angle), Math.sin(angle), Math.cos(heading) * Math.cos(angle)).multiplyScalar(1000))
camera.lookAt(model.center); camera.updateProjectionMatrix(); camera.updateMatrixWorld()
@@ -52,6 +71,11 @@ function select(next: Family) {
if (sheetUrl) URL.revokeObjectURL(sheetUrl)
sheetUrl = ""; root.querySelector<HTMLAnchorElement>("#sheet-link")!.hidden = true
family = next; models.forEach(m => m.built.dispose()); models = []; grid.replaceChildren()
+ const intro = introductions[family] ?? { heading: "New places.<br>The same ink.", eyebrow: "A town with a little more life", description: "Inspect the models together, turn them around, then open any one for a closer look.", aside: "7 buildings<br>3 park furnishings<br>3 home tiers<br><span>Plus people, hazards, paving,<br>snow and signs of wear.</span>" }
+ root.querySelector(".intro h1")!.innerHTML = intro.heading
+ root.querySelector(".eyebrow")!.textContent = intro.eyebrow
+ root.querySelector(".intro > div > p:last-child")!.textContent = intro.description
+ root.querySelector(".intro aside")!.innerHTML = intro.aside
for (const [i, id] of families[family].ids.entries()) {
const asset = assetById.get(id)!
if (!asset) throw new Error(`Missing review model: ${id}`)
@@ -82,11 +106,11 @@ root.querySelector<HTMLButtonElement>("#sheet")!.onclick = () => {
canvas.width = columns * width; canvas.height = 100 + Math.ceil(models.length / columns) * height
ctx.fillStyle = "#f0f2ec"; ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.fillStyle = "#3d4943"; ctx.font = "30px Georgia"; ctx.fillText(`Inkline Town / ${families[family].title}`, 30, 48)
- ctx.font = "13px monospace"; ctx.fillText(`PR 03 · ${Math.round(yaw)}° rotation · ${pitch}° elevation`, 30, 76)
+ ctx.font = "13px monospace"; ctx.fillText(`Inkline Town · ${Math.round(yaw)}° rotation · ${pitch}° elevation`, 30, 76)
renderer.setSize(width, 270, false); renderer.setScissorTest(false)
models.forEach((model, i) => {
const camera = model.camera, heading = (45 + yaw) * Math.PI / 180, angle = pitch * Math.PI / 180,
- vertical = Math.max(model.size.y, Math.hypot(model.size.x, model.size.z) * 0.75, 18) * 1.3
+ vertical = viewHeight(model.size, heading, angle, width / 270)
camera.top = vertical / 2; camera.bottom = -camera.top; camera.left = -vertical * width / 270 / 2; camera.right = -camera.left
camera.position.copy(model.center).add(new THREE.Vector3(Math.sin(heading) * Math.cos(angle), Math.sin(angle), Math.cos(heading) * Math.cos(angle)).multiplyScalar(1000))
camera.lookAt(model.center); camera.updateProjectionMatrix(); camera.updateMatrixWorld(); model.built.updateContours(camera)
diff --git a/src/render3d/models.ts b/src/render3d/models.ts
index f0e0c71..c16232e 100644
--- a/src/render3d/models.ts
+++ b/src/render3d/models.ts
@@ -1,5 +1,5 @@
import { buildStages, homeVariant } from "../art.ts"
-import { makeBuilding, type BuildingOptions } from "../asset-lab/buildings.ts"
+import { makeBuilding, buildingDimensions, type BuildingOptions } from "../asset-lab/buildings.ts"
import { house } from "../asset-lab/homes.ts"
import { Drawing, palette, square, type InkAsset, type Vertex, type Side } from "../asset-lab/primitives.ts"
import { hash } from "../asset-lab/land.ts"
@@ -9,6 +9,8 @@ import { key, cellOf, DIRS } from "../grid.ts"
import type { Preview } from "../ui.ts"
import { withAppearance, type Appearance } from "../asset-lab/appearance.ts"
import { setts } from "../asset-lab/town-props.ts"
+import { isWorkshop, workshopConstruction } from "../asset-lab/workshops.ts"
+import { isTradeYard, tradeConstruction } from "../asset-lab/trades.ts"
import { serviceBuilding, upgradeHeights, type ServiceKind } from "../asset-lab/service-upgrades.ts"
export type DoorSet = Record<Side, boolean>
@@ -65,17 +67,21 @@ export function constructionAsset(size: number, half: number, height: number, bu
}
/** The height a building of a kind is drawn to its eaves, upgraded or not (see `upgradeHeights`). */
export const buildingHeight = (id: KindId, upgraded = false) =>
- upgraded && isUpgradable(id) ? upgradeHeights[id].eave : kinds[id].roof === "gable" ? 20 : kinds[id].stories * 32
+ upgraded && isUpgradable(id) ? upgradeHeights[id].eave : buildingDimensions(id).height
const isUpgradable = (id: KindId): id is ServiceKind => id === "market" || id === "chapel"
export function buildingAsset(id: KindId, build: number, share: number | null, doors: DoorSet, open: number, appearance: Appearance = {}, upgraded = false) {
const kind = kinds[id],
stage = buildStages(build)
- if (build < 0.78) return constructionAsset(kind.size, kind.half, kind.roof === "gable" ? 20 : kind.stories * 32, build, share)
+ if (build < 0.78) return isWorkshop(id)
+ ? workshopConstruction(id, build, share, doors)
+ : isTradeYard(id) ? tradeConstruction(id, build, share, doors)
+ : constructionAsset(kind.size, kind.half, kind.roof === "gable" ? 20 : kind.stories * 32, build, share)
// An upgraded building is only ever a standing one: the upgrade is paid and done at once.
if (upgraded && isUpgradable(id)) return withAppearance(serviceBuilding(id, 2, { plate: false, doors }), kind.half * U, buildingHeight(id, true), appearance)
const asset = makeBuilding(id, { doors, open, fit: stage.fit, plate: false, motion: false } satisfies BuildingOptions)
- return build >= 1 ? withAppearance(asset, kind.half * U, kind.roof === "gable" ? 20 : kind.stories * 32, appearance) : asset
+ const dimensions = buildingDimensions(id)
+ return build >= 1 ? withAppearance(asset, dimensions.half, dimensions.height, appearance) : asset
}
export function homeAsset(tier: Tier, n: number, build: number, share: number | null, doors: DoorSet, appearance: Appearance = {}) {
if (build < 0.78) return constructionAsset(1, home.half + (tier >= 2 ? 1 : 0), home.tiers[tier].height, build, share)
diff --git a/src/render3d/views.ts b/src/render3d/views.ts
index 80678f3..1f5d810 100644
--- a/src/render3d/views.ts
+++ b/src/render3d/views.ts
@@ -15,7 +15,7 @@ import { kinds, home, GROWN, ROCK_AMOUNT, type KindId } from "../content.ts"
import { U, type Point } from "../iso.ts"
import { vertex3 } from "../asset-lab/renderer.ts"
import { Drawing, type Vertex } from "../asset-lab/primitives.ts"
-import { makeSails, makeFlag } from "../asset-lab/buildings.ts"
+import { makeSails, makeFlag, buildingSmokeOrigin, buildingDimensions } from "../asset-lab/buildings.ts"
import { makeMarker } from "../asset-lab/construction.ts"
import { makeRuin } from "../asset-lab/town-props.ts"
import { StructureEffects } from "./structure-effects.ts"
@@ -92,6 +92,7 @@ export class BuildingView extends WorldView {
private marker: ModelHandle
private motion: ModelHandle
private smoke: SmokePlume | null = null
+ private effectLayout = ""
private wave = 0
private opening = 0
private beat = -1
@@ -131,19 +132,24 @@ export class BuildingView extends WorldView {
)
this.plate.use(`plate/${kind.size}/${build}`, () => plateAsset(kind.size, build))
this.body.root.scale.set(1 + this.pulse * 0.04, 1 - this.pulse * 0.06, 1 + this.pulse * 0.04)
- const H = buildingHeight(this.kindId, upgraded)
+ const dimensions = buildingDimensions(this.kindId), H = buildingHeight(this.kindId, upgraded)
const top = upgraded
? upgradeHeights[this.kindId as "market" | "chapel"].top
- : H + (kind.topper === "chimney" ? 24 : kind.topper === "cupola" ? 25 : kind.topper === "flag" ? 24 : kind.topper === "sails" ? 16 : 0)
+ : dimensions.top
this.marker.root.position.set(0, (top + 8) / Math.cos(Math.PI / 6), 0)
const signed = !!look.burning || (look.alert !== null && look.alert !== undefined)
this.marker.root.visible = look.problem && look.build >= 1 && !signed
const state = structureState(look,this.stage.frost)
this.body.effects = build >= 1 ? state : surfaceState()
- this.body.effectBounds.set(kind.half * U * 32 * Math.SQRT2,H/Math.cos(Math.PI/6),this.entity%97/97,1)
- if(this.effects&&this.effects.group.userData.upgraded!==upgraded){this.effects.dispose();this.effects=null}
+ this.body.effectBounds.set((upgraded ? kind.half * U : dimensions.half) * 32 * Math.SQRT2,H/Math.cos(Math.PI/6),this.entity%97/97,1)
+ const effectLayout = `${upgraded ? 2 : 1}/${doorKey(doors)}`
+ if (this.effects && this.effectLayout !== effectLayout) {
+ this.effects.dispose()
+ this.effects = null
+ }
if(!this.effects&&build>=1&&(state.burning||state.fireRisk)){
- this.effects = new StructureEffects(buildingAsset(this.kindId,1,null,upgraded?doors:noDoors,0,{},upgraded),H)
+ this.effects = new StructureEffects(buildingAsset(this.kindId,1,null,doors,0,{},upgraded),H)
+ this.effectLayout = effectLayout
this.effects.group.userData.upgraded=upgraded
this.group.add(this.effects.group)
}
@@ -165,13 +171,13 @@ export class BuildingView extends WorldView {
this.motion.root.position.copy(vertex3([kind.half * U + 3 * U, 0, H - 6]))
this.motion.root.rotation.x = this.wave
}
- const smoking=look.working&&kind.topper==="chimney"&&look.build>=1&&!look.burning
+ const origin = buildingSmokeOrigin(this.kindId, doors)
+ const smoking=look.working&&origin!==null&&look.build>=1&&!look.burning
if(smoking&&!this.smoke){
this.smoke=new SmokePlume()
- const a=kind.half*U,pitch=2*a/kind.bays
- this.smoke.group.position.copy(vertex3([-a+pitch*0.5,-a+pitch*0.5,H+24.3]))
this.group.add(this.smoke.group)
}
+ if (smoking) this.smoke!.group.position.copy(vertex3(origin!))
this.smoke?.update(performance.now()/1000,Number(smoking))
this.viewTint = look.tint ?? null
this.emphasis(emphasis)
diff --git a/test/render3d.test.ts b/test/render3d.test.ts
index a37f1a6..0963e8c 100644
--- a/test/render3d.test.ts
+++ b/test/render3d.test.ts
@@ -3,7 +3,8 @@ import { test } from "node:test"
import * as THREE from "three"
import { kindIds } from "../src/content.ts"
import { Drawing, type InkAsset } from "../src/asset-lab/primitives.ts"
-import { buildingAsset, homeAsset, noDoors, treeVariant } from "../src/render3d/models.ts"
+import { buildingAsset, buildingHeight, homeAsset, noDoors, treeVariant } from "../src/render3d/models.ts"
+import { upgradeHeights } from "../src/asset-lab/service-upgrades.ts"
import { ModelHandle, ModelPool } from "../src/render3d/pool.ts"
import { assetById } from "../src/asset-lab/assets.ts"
import { surfaceState, hazardStrength } from "../src/render3d/surface-state.ts"
@@ -30,6 +31,23 @@ test("live construction and fitting are valid for every building and all three h
}
})
+test("live service upgrades retain their taller models and material bounds beside the revised base buildings", () => {
+ for (const id of ["market", "chapel"] as const) for (const side of Object.keys(noDoors)) {
+ const doors = { ...noDoors, [side]: true }
+ const base = buildingAsset(id, 1, null, doors, 1)
+ const upgraded = buildingAsset(id, 1, null, doors, 1, { winter: true }, true)
+ valid(upgraded)
+ assert.equal(upgraded.reference?.type === "building" && upgraded.reference.tier, 2)
+ const top = (asset: InkAsset) => Math.max(...asset.faces.flatMap(face => face.points.map(p => p[2])))
+ assert.ok(top(upgraded) > top(base), `${id}/${side}: live upgrade lost its silhouette`)
+ assert.equal(buildingHeight(id, true), upgradeHeights[id].eave)
+ assert.equal(upgraded.effects?.height, upgradeHeights[id].eave)
+ assert.equal(upgraded.effects?.state.snow, 1)
+ }
+ for (const [id, height] of [["bakery", 28], ["weaver", 30], ["fishery", 20]] as const)
+ assert.equal(buildingHeight(id), height, `${id}: public height must follow the revised model`)
+})
+
test("shared geometry retains independent colours, transforms and entity picking", () => {
const pool = new ModelPool(), root = new THREE.Group()
let built = 0
diff --git a/test/rural.test.ts b/test/rural.test.ts
new file mode 100644
index 0000000..7bed0c0
--- /dev/null
+++ b/test/rural.test.ts
@@ -0,0 +1,46 @@
+import assert from "node:assert/strict"
+import { test } from "node:test"
+import * as THREE from "three"
+import { makeBuilding, buildingDimensions } from "../src/asset-lab/buildings.ts"
+import { ruralDoorIds } from "../src/asset-lab/rural.ts"
+import { sides, type InkAsset } from "../src/asset-lab/primitives.ts"
+import { vertex3 } from "../src/asset-lab/renderer.ts"
+import { noDoors } from "../src/render3d/models.ts"
+import { kinds } from "../src/content.ts"
+import { U } from "../src/iso.ts"
+
+test("rural timber doors stay within their plots when opened on any road face", () => {
+ for (const id of ruralDoorIds) for (const side of sides) for (const open of [0, 0.5, 1]) {
+ const asset = makeBuilding(id, { doors: { ...noDoors, [side]: true }, open })
+ const half = (kinds[id].size * 8 - 1) * U
+ for (const p of [...asset.faces, ...asset.strokes].flatMap(part => part.points))
+ assert.ok(Math.abs(p[0]) <= half + 0.0001 && Math.abs(p[1]) <= half + 0.0001, `${id}/${side}/${open}: leaves original plot`)
+ }
+})
+
+function verticalHits(asset: InkAsset, u: number, v: number, from: number, to: number) {
+ const start = vertex3([u * U, v * U, from]), end = vertex3([u * U, v * U, to])
+ const ray = new THREE.Ray(start, end.clone().sub(start).normalize())
+ return asset.faces.flatMap(face => face.points.slice(1, -1).flatMap((_, i) => {
+ const hit = ray.intersectTriangle(vertex3(face.points[0]!), vertex3(face.points[i + 1]!), vertex3(face.points[i + 2]!), false, new THREE.Vector3())
+ return hit && hit.distanceTo(start) <= end.distanceTo(start) ? [hit] : []
+ }))
+}
+
+test("the fire-watch ladder landing and every roof tread connect to the lookout without roof obstruction", () => {
+ const asset = makeBuilding("firewatch")
+ const stations = [
+ [12.3, -4.5, 28.5],
+ ...Array.from({ length: 7 }, (_, i) => {
+ const t = (i + 0.5) / 7
+ return [11 - 7 * t, -4.5 + 2.7 * t, 28.5 + 6 * (i + 1) / 7]
+ }),
+ [3.9, -1.8, 34.5]
+ ]
+ for (const [u, v, z] of stations) {
+ assert.ok(verticalHits(asset, u!, v!, z! + 0.1, z! - 0.65).length > 0, `Unsupported route at ${u}/${v}/${z}`)
+ assert.equal(verticalHits(asset, u!, v!, z! + 0.1, z! + 4).length, 0, `Roof obstructs route at ${u}/${v}/${z}`)
+ }
+ const highest = Math.max(...asset.faces.flatMap(face => face.points.map(p => p[2])))
+ assert.ok(buildingDimensions("firewatch").top >= highest, "Problem marker must sit above the lookout roof")
+})
diff --git a/test/trades.test.ts b/test/trades.test.ts
new file mode 100644
index 0000000..1b380ea
--- /dev/null
+++ b/test/trades.test.ts
@@ -0,0 +1,46 @@
+import assert from "node:assert/strict"
+import { test } from "node:test"
+import * as THREE from "three"
+import { makeBuilding, buildingSmokeOrigin } from "../src/asset-lab/buildings.ts"
+import { tradeYardIds } from "../src/asset-lab/trades.ts"
+import { workshopPoint } from "../src/asset-lab/workshops.ts"
+import { type InkAsset, sides } from "../src/asset-lab/primitives.ts"
+import { buildingAsset, noDoors } from "../src/render3d/models.ts"
+import { vertex3 } from "../src/asset-lab/renderer.ts"
+import { kinds } from "../src/content.ts"
+import { U } from "../src/iso.ts"
+
+function hits(asset: InkAsset, start: THREE.Vector3, end: THREE.Vector3) {
+ const ray = new THREE.Ray(start, end.clone().sub(start).normalize())
+ return asset.faces.flatMap(face => face.points.slice(1, -1).flatMap((_, i) => {
+ const hit = ray.intersectTriangle(vertex3(face.points[0]!), vertex3(face.points[i + 1]!), vertex3(face.points[i + 2]!), false, new THREE.Vector3())
+ return hit && hit.distanceTo(start) <= end.distanceTo(start) ? [hit] : []
+ }))
+}
+
+test("trade yards keep open approaches and remain inside their plots through construction and work", () => {
+ for (const id of tradeYardIds) for (const side of sides) for (const build of [0.3, 0.6, 0.85, 1]) {
+ const doors = { ...noDoors, [side]: true }, asset = buildingAsset(id, build, 0.5, doors, 1)
+ const half = (kinds[id].size * 8 - 1) * U
+ for (const p of [...asset.faces, ...asset.strokes].flatMap(part => part.points))
+ assert.ok(Math.abs(p[0]) <= half && Math.abs(p[1]) <= half, `${id}/${side}/${build}: outside original plot`)
+ const v = (id === "warehouse" ? 20 : 12) * U
+ assert.equal(hits(asset, vertex3(workshopPoint([0, v, 14], doors)), vertex3(workshopPoint([0, v, 20], doors))).length, 0, `${id}: approach must remain open`)
+ }
+})
+
+test("the bakery oven is recessed masonry, with smoke attached to its actual flue", () => {
+ for (const side of sides) {
+ const doors = { ...noDoors, [side]: true }, asset = makeBuilding("bakery", { doors })
+ const at = (v: number) => vertex3(workshopPoint([-6 * U, v * U, 10], doors))
+ assert.equal(hits(asset, at(12), at(0)).length, 0, `${side}: the oven mouth must be open`)
+ assert.ok(hits(asset, at(12), at(-2)).length > 0, `${side}: the oven needs a back`)
+ const origin = buildingSmokeOrigin("bakery", doors)!
+ assert.deepEqual(asset.smokeEffect?.origin, origin)
+ const mouth = asset.faces.find(face => face.points.every(p => Math.abs(p[2] - 48.02) < 0.0001))!
+ assert.ok(mouth)
+ const center = mouth.points.reduce((sum, p) => [sum[0]! + p[0], sum[1]! + p[1]], [0, 0]).map(n => n / mouth.points.length)
+ assert.ok(Math.abs(center[0]! - origin[0]) < 0.0001 && Math.abs(center[1]! - origin[1]) < 0.0001)
+ assert.equal(buildingAsset("bakery", 1, null, doors, 1).smokeEffect, undefined)
+ }
+})
diff --git a/test/workshops.test.ts b/test/workshops.test.ts
new file mode 100644
index 0000000..eda00c9
--- /dev/null
+++ b/test/workshops.test.ts
@@ -0,0 +1,40 @@
+import assert from "node:assert/strict"
+import { test } from "node:test"
+import * as THREE from "three"
+import { makeBuilding, buildingSmokeOrigin, buildingDimensions } from "../src/asset-lab/buildings.ts"
+import { workshopIds, workshopPoint } from "../src/asset-lab/workshops.ts"
+import { vertex3 } from "../src/asset-lab/renderer.ts"
+import { buildingAsset, noDoors } from "../src/render3d/models.ts"
+import { sides } from "../src/asset-lab/primitives.ts"
+import { U } from "../src/iso.ts"
+
+test("open workshop forecourts retain air above the work floor on every road heading", () => {
+ for (const id of workshopIds) for (const side of sides) {
+ const doors = { ...noDoors, [side]: true }, asset = makeBuilding(id, { doors })
+ const start = vertex3(workshopPoint([0, 12 * U, 14], doors))
+ const end = vertex3(workshopPoint([0, 12 * U, 20], doors))
+ const ray = new THREE.Ray(start, end.clone().sub(start).normalize())
+ for (const face of asset.faces) for (let i = 1; i < face.points.length - 1; i++) {
+ const hit = ray.intersectTriangle(vertex3(face.points[0]!), vertex3(face.points[i]!), vertex3(face.points[i + 1]!), false, new THREE.Vector3())
+ assert.ok(!hit || hit.distanceTo(start) > end.distanceTo(start), `${id}/${side}: forecourt must stay open`)
+ }
+ for (const p of [...asset.faces, ...asset.strokes].flatMap(part => part.points))
+ assert.ok(Math.abs(p[0]) <= 15 * U && Math.abs(p[1]) <= 15 * U, `${id}/${side}: outside original plot`)
+ }
+})
+
+test("the working smithy emitter follows its flue and the other open yards do not smoke", () => {
+ for (const side of sides) {
+ const doors = { ...noDoors, [side]: true }, asset = makeBuilding("smithy", { doors })
+ const origin = buildingSmokeOrigin("smithy", doors)!
+ assert.deepEqual(asset.smokeEffect?.origin, origin)
+ const mouth = asset.faces.find(face => face.color === 0x68726c && face.points.every(p => Math.abs(p[2] - 56.02) < 0.0001))!
+ assert.ok(mouth, `flue mouth missing for ${side}`)
+ const center = mouth.points.reduce((sum, p) => [sum[0]! + p[0], sum[1]! + p[1], sum[2]! + p[2]], [0, 0, 0]).map(n => n / mouth.points.length)
+ assert.ok(Math.abs(center[0]! - origin[0]) < 0.0001 && Math.abs(center[1]! - origin[1]) < 0.0001)
+ assert.ok(origin[2] > center[2]! && origin[2] - center[2]! < 0.5)
+ assert.equal(buildingAsset("smithy", 1, null, doors, 1).smokeEffect, undefined, "live view owns the working smoke, without a duplicate catalogue plume")
+ }
+ for (const id of ["mine", "sawmill"] as const) assert.equal(buildingSmokeOrigin(id), null)
+ assert.equal(buildingDimensions("sawmill").top, 36.7)
+})