A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D
Refine town props, entrances, deposits, and chimney smoke
SandroMaglione8de46be33c35
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.mdindex dd91dc1..c8672d5 100644--- a/DEVELOPMENT.md+++ b/DEVELOPMENT.md@@ -175,6 +175,15 @@ condition. Drag any model or use the rotation slider to turn the collection.`pnpm check:models` checks every collection, camera controls, sheet exportsand phone layout, and saves PNGs to `output/inkline-3d/town-review/`.+The **Review fixes** collection groups the revised storage props, entrances,+hay stack, townhouse, quarry, stone deposits, markers and emitters. All building+and house geometry is checked against its plate bounds. Natural rock deposits+use six seeded silhouettes while retaining their simulation cell footprints.+`pnpm check:revisions` renders every catalogue entry, checks the exclamation+mark from both sides and verifies animated smoke through rendered pixels.+The chimney plume uses `render3d/smoke-effects.ts` in both the catalogue and+working buildings. Smoke's GLB stores emitter metadata; particles run at runtime.+Open [`/effects-lab.html`](http://localhost:5232/effects-lab.html) to inspecteight conditions on the same house geometry. Select any home tier, rotate,adjust effect strength or pause animation. Dirt, masonry, cracks, snow,diff --git a/asset-lab.html b/asset-lab.htmlindex 26f6485..e01f607 100644--- a/asset-lab.html+++ b/asset-lab.html@@ -3,6 +3,7 @@<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <link rel="icon" href="/favicon.svg" type="image/svg+xml" /><title>Inkline Town · 3D art study</title></head><body>diff --git a/package.json b/package.jsonindex 1a7a4df..f627426 100644--- a/package.json+++ b/package.json@@ -13,6 +13,7 @@"check:browser": "node scripts/check-browser.ts","check:models": "node scripts/check-town-models.ts","check:effects": "node scripts/check-house-effects.ts",+ "check:revisions": "node scripts/check-model-revisions.ts","test": "node --test \"test/*.test.ts\"","release": "pnpm --dir deploy release"},diff --git a/scripts/check-model-revisions.ts b/scripts/check-model-revisions.tsnew file mode 100644index 0000000..c5f7b29--- /dev/null+++ b/scripts/check-model-revisions.ts@@ -0,0 +1,37 @@+import assert from "node:assert/strict"+import { existsSync } from "node:fs"+import { mkdir, writeFile } from "node:fs/promises"+import { chromium } from "playwright"++const executablePath=process.env.BROWSER_EXECUTABLE_PATH??["/Applications/Brave Browser.app/Contents/MacOS/Brave Browser","/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"].find(existsSync)+const browser=await chromium.launch({headless:true,...(executablePath?{executablePath}:{})})+const page=await browser.newPage({viewport:{width:1440,height:1100},deviceScaleFactor:2}),errors:string[]=[],output="output/inkline-3d/model-revisions"+page.on("pageerror",e=>errors.push(e.message));page.on("console",m=>{if(m.type()==="error")errors.push(m.text())});page.on("response",r=>{if(r.status()>=400)errors.push(`${r.status()} ${r.url()}`)})+await mkdir(output,{recursive:true})+try{+ await page.goto(`${process.env.GAME_BASE_URL??"http://127.0.0.1:5232"}/asset-lab.html?asset=problem-marker`)+ await page.waitForFunction(()=>Boolean((window as any).inkLab))+ for(const yaw of [0,180]){+ await page.evaluate(y=>(window as any).inkLab.rotate(y),yaw)+ const image=await page.evaluate(()=>(window as any).inkLab.capture("model"))+ await writeFile(`${output}/marker-${yaw}.png`,Buffer.from(image.split(",")[1],"base64"))+ const glyph=await page.evaluate(async data=>{+ const image=new Image();image.src=data;await image.decode();const c=document.createElement("canvas");c.width=image.width;c.height=image.height;const ctx=c.getContext("2d")!;ctx.drawImage(image,0,0)+ const pixels=ctx.getImageData(0,0,c.width,c.height).data,red=(i:number)=>pixels[i]!>150&&pixels[i+1]!<130&&pixels[i+2]!<120&&pixels[i+3]!>100+ let l=c.width,r=0,t=c.height,b=0+ for(let y=0;y<c.height;y++)for(let x=0;x<c.width;x++)if(red((y*c.width+x)*4)){l=Math.min(l,x);r=Math.max(r,x);t=Math.min(t,y);b=Math.max(b,y)}+ let inside=0+ for(let y=Math.ceil(t+(b-t)*0.2);y<b-(b-t)*0.2;y++)for(let x=Math.ceil(l+(r-l)*0.2);x<r-(r-l)*0.2;x++)if(red((y*c.width+x)*4))inside+++ return inside+ },image)+ assert.ok(glyph>100,`The exclamation mark must remain visible at ${yaw}°, not just its red border`)+ }+ await page.evaluate(()=>(window as any).inkLab.select("smoke"))+ const first=await page.evaluate(()=>(window as any).inkLab.captureEffect(0)),next=await page.evaluate(()=>(window as any).inkLab.captureEffect(1))+ assert.notEqual(first,next,"Smoke must animate in the actual GPU rendering")+ await writeFile(`${output}/smoke.png`,Buffer.from(next.split(",")[1],"base64"))+ const count=await page.evaluate(()=>{const lab=(window as any).inkLab;for(const a of lab.assets){lab.select(a.id);assertGeometry(lab.stats().triangles,a.id)}function assertGeometry(n:number,id:string){if(n<=0)throw new Error(`${id}: empty render`)}return lab.assets.length})+ assert.equal(count,204)+ assert.deepEqual(errors,[])+ console.log(JSON.stringify({catalogueModels:count,markerViews:[0,180],animatedSmoke:true,browserErrors:errors}))+}finally{await browser.close()}diff --git a/scripts/check-town-models.ts b/scripts/check-town-models.tsindex f85205c..b72db59 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 = ["Buildings", "Gardens & squares", "Homes & neighbourhoods", "Winter", "Ruins", "People & cargo", "Building condition"]+const groups = ["Review fixes", "Buildings", "Gardens & squares", "Homes & neighbourhoods", "Winter", "Ruins", "People & cargo", "Building condition"]const captureSheet = async () => {const previous = await page.locator("#sheet-link").getAttribute("href")await page.getByRole("button", { name: "Save model sheet", exact: true }).click()diff --git a/scripts/ink-assets.ts b/scripts/ink-assets.tsindex fed8254..e279843 100644--- a/scripts/ink-assets.ts+++ b/scripts/ink-assets.ts@@ -30,6 +30,7 @@ for (const asset of inkAssets) {await writeFile(path.join(output, "models", `${asset.id}.json`), JSON.stringify(asset, null, 2))const imported = await loader.parseAsync(glb, "")if(asset.effects&&!imported.scene.getObjectByName(asset.id)?.userData.inklineSurfaceEffects)throw new Error(`${asset.id}: surface state metadata lost on export`)+ if(asset.smokeEffect&&!imported.scene.getObjectByName(asset.id)?.userData.inklineSmokeEffect)throw new Error(`${asset.id}: smoke emitter metadata lost on export`)let meshes = 0,vertices = 0imported.scene.traverse((object) => {@@ -52,6 +53,7 @@ for (const asset of inkAssets) {title: asset.title,category: asset.category,effects: asset.effects,+ smokeEffect: asset.smokeEffect,glb: `models/${asset.id}.glb`,geometry: `models/${asset.id}.json`,bytes: glb.byteLength,diff --git a/src/asset-lab/buildings.ts b/src/asset-lab/buildings.tsindex b7e6416..6a82391 100644--- a/src/asset-lab/buildings.ts+++ b/src/asset-lab/buildings.ts@@ -2,7 +2,7 @@ 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 { makeDecor } from "./town-props.ts"-import { finishTownBuilding, townBuildingNotes } from "./services.ts"+import { finishTownBuilding, townBuildingNotes, institutionDoor, makeQuarry } from "./services.ts"const dresses: Record<KindId, { accent: number; roof?: number; glass?: number }> = {townhall: { accent: 0x8a58a8, glass: 0xf3dca6 },@@ -45,6 +45,7 @@ export interface BuildingOptions {}export function makeBuilding(id: KindId, options: BuildingOptions = {}) {if (kinds[id].decor) return makeDecor(id)+ if (id === "quarry") return makeQuarry(options)const fit = options.fit ?? 1const kind = kinds[id],a = kind.half * U,@@ -56,7 +57,7 @@ export function makeBuilding(id: KindId, options: BuildingOptions = {}) {id,kind.title,townBuildingNotes[id] ?? (id === "mill"- ? "The lattice sails sit on a real upright plane. Flour sacks remain softly rounded."+ ? "Upright lattice sails, a tapered roof and coopered flour barrels in the mill yard.": id === "market"? "Striped canopy, coloured goods crates and roof flag, all built as geometry.": id === "townhall"@@ -88,22 +89,23 @@ export function makeBuilding(id: KindId, options: BuildingOptions = {}) {d.line([p(s - w - 0.5 / 16, z), p(s + w + 0.5 / 16, z)])} else d.window(side, a, s, floor * 32 + 12, 8, glass, true)}- if (door && fit > 0.15)- d.door(side, a, Math.max(2, Math.round(Math.min(16, H - 8) * fit)), 5 * U, 6 * U, 3 * U, accent, true, options.open ?? 0)+ if (door && fit > 0.15) {+ if (id === "chapel" || id === "hospital") institutionDoor(d,side,a,id,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)if (id === "townhall" && fit > 0.8) d.circle(side, a, 50, 5)}if (id === "mill") {if (fit > 0) d.pyramid(a, H, 16 * fit, pale(0x8a6a45, 0.7), pale(0x8a6a45, 0.52))if (options.motion !== false && fit > 0.6) drawSails(d, a, H, 1.2)- // Sacks are complete faceted solids, rather than a fixed screen drawing.const c = (a + p) / 2for (const [u, v] of [- [c - U, c + U],- [c + 1.5 * U, c - U],- [c + 0.5 * U, c + 2.5 * U]+ [c - 1.5 * U, c - 1.5 * U],+ [c + 1.2 * U, c - 1.5 * U],+ [c, c + 1.5 * U]])- d.sack(u!, v!)+ d.barrel(u!, v!, 1.1 * U, 0, 8, 0xf1e9d5)} else if (kind.roof === "gable") {const roof = dresses[id].roof ?? 0x8a6a45if(fit>0)d.gable(a, H, 14 * fit, "x", pale(roof, 0.7), pale(roof, 0.52), false)@@ -180,13 +182,13 @@ export function makeBuilding(id: KindId, options: BuildingOptions = {}) {[[u0, s, 12],[u0, e, 12],- [u1 + U, e, 9],- [u1 + U, s, 9]+ [u1, e, 9],+ [u1, s, 9]],i % 2 === 0 ? 0xc4523f : 0xf7f3ea)}- d.crate(-a - 2 * U, c, 0, 0x2f8c87)+ d.crate(-a - 1.7 * U, c, 0, 0x2f8c87)d.crate(-a + 1.5 * U, c, 0, 0xc4523f)d.crate(-a - 0.2 * U, c, 5, 0x8a58a8)}@@ -251,9 +253,9 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,finishTownBuilding(d, id, a, p, H)switch (id) {case "warehouse":- d.crate(c, c - 1.5 * U, 0, 0x2f8c87, 1.6 * U, 6)- d.crate(c, c + 1.5 * U, 0, 0xd27a34, 1.6 * U, 6)- d.cylinder(c, -a - 2 * U, 1.5 * U, 0, 8, 0xc79a5b, 0xe9c48a, 1.5)+ 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)breakcase "lumberjack": {for (const [du, z] of [@@ -330,7 +332,7 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,])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, -a - 2 * U, 3 * U, 0, 6, 0x5a6479)+ pyramid(c - U, -a - 2 * U, 2 * U, 0, 6, 0x5a6479)break}case "fishery": {@@ -369,7 +371,7 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,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 - 2 * U, 2.5 * U, 0, 5, 0x3d4943)+ pyramid(c, -a - 1.5 * U, 1.2 * U, 0, 5, 0x3d4943)breakcase "farm":d.cylinder(c + U, -a - 3 * U, 3.5 * U, 0, 28, 0xeeeae0, pale(0xc4523f, 0.6), 1.5)@@ -388,15 +390,15 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,d.line([...ring, ring[0]!], 1.5)}for (const [y, z] of [- [c - 2.5 * U, 0],- [c + 2.5 * U, 0],- [c, 5]+ [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)breakcase "bakery": {- d.sack(c, -a - U)- d.sack(c, -a + 2 * U)+ 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)@@ -463,11 +465,12 @@ function finishBuilding(d: Drawing, id: KindId, a: number, p: number, H: number,color)}- d.sack(c, c, 0, 0xeceee8)+ 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)break}case "chapel":- bush(c, c, 4.5)+ bush(c, c, 3.5)bush(c, -a - U, 4, 0xbccfa8, 0xdde8cf)bush(-a - U, c, 4, 0xccd5ae, 0xe8ecd2)breakdiff --git a/src/asset-lab/construction.ts b/src/asset-lab/construction.tsindex 055ef13..c007b86 100644--- a/src/asset-lab/construction.ts+++ b/src/asset-lab/construction.ts@@ -79,28 +79,23 @@ export function makeMarker() {d.asset.category = "construction"d.asset.reference = { type: "none" }d.asset.footprint = 1- const p = (x: number, z: number): Vertex => [x / 64, -x / 64, z]+ const p = (x: number, z: number, out = 0): Vertex => [x / 64+out, -x / 64+out, z]d.face([p(-7.5, 0), p(7.5, 0), p(7.5, 15), p(-7.5, 15)], 0xf6f7f3, 1, 0xc4523f)- d.face([p(-1, 6), p(1, 6), p(1, 12), p(-1, 12)], 0xc4523f, 0)- d.face([p(-1, 3), p(1, 3), p(1, 5), p(-1, 5)], 0xc4523f, 0)+ for(const out of [-0.008,0.008]){+ d.face([p(-1.2, 6,out), p(1.2, 6,out), p(1.2, 12,out), p(-1.2, 12,out)], 0xc4523f, 0)+ d.face([p(-1.2, 3,out), p(1.2, 3,out), p(1.2, 5,out), p(-1.2, 5,out)], 0xc4523f, 0)+ }return d.asset}export function makeSmoke() {- const d = new Drawing("smoke", "Chimney smoke", "The original fine smoke rings, on upright planes above the chimney.")+ const d = new Drawing("smoke", "Chimney smoke", "Animated soft smoke rises and disperses from a flue. The plume uses the same particle shader as the live game.")d.asset.category = "construction"d.asset.reference = { type: "none" }d.asset.footprint = 1- for (const t of [0.1, 0.4, 0.7]) {- const r = 4 + t * 7,- dx = Math.sin(t * 5) * 1.5,- h = t * 34- const ring = Array.from({ length: 25 }, (_, i): Vertex => [- (dx + Math.cos((i / 24) * Math.PI * 2) * r) / 64,- -(dx + Math.cos((i / 24) * Math.PI * 2) * r) / 64,- h + Math.sin((i / 24) * Math.PI * 2) * r- ])- d.line(ring, 1, palette.ink, (1 - t) * 0.55)- }+ d.box(0,0,2*U,2*U,0,12)+ d.box(0,0,2.4*U,2.4*U,10,2,0xb7c0af,0xa2ad99,0x8f9d85,1)+ d.face(square(0,0,1.5*U,12.03),0x687363,0)+ d.asset.smokeEffect={origin:[0,0,12.2]}return d.asset}export function makePlot(look: "hover" | "picked" | "blocked" | "reach") {diff --git a/src/asset-lab/homes.ts b/src/asset-lab/homes.tsindex 18a4b8e..60ef819 100644--- a/src/asset-lab/homes.ts+++ b/src/asset-lab/homes.ts@@ -14,7 +14,7 @@ export function house(id,tier === 1 ? "Settler cottage" : tier === 2 ? "Citizen home" : "Townhouse",tier === 3- ? "A burgher's townhouse with stone quoins, a cornice, iron balconies, a fanlight and a stepped entrance."+ ? "A modest three-storey townhouse with regular windows, a simple timber door and the town's familiar gabled roof.": "Original roof palette, footprint, chimney, windows and awnings. Rear walls completed for rotation.")const variant = homeVariant(variantN)@@ -28,7 +28,7 @@ export function house(for (const side of sides) {const door = options.doors ? !!options.doors[side] : side === "right"for (const z of tier === 3 ? [13, 25] : tier === 2 ? [13] : []) d.line([d.wall(side, a, -a, z), d.wall(side, a, a, z)], 1, palette.ink, 0.7)- if (door && fit > 0.15) d.door(side, a, Math.max(2, 9 * fit), 2 * U, 3 * U, 2 * U, variant.roof.shade)+ if (door && fit > 0.15) d.door(side, a, Math.max(2, (tier===3?11:9) * fit), 2 * U, 2.5 * U, 0.8 * U, variant.roof.shade)for (const floor of fit > 0.4 ? (tier === 3 ? [0, 12, 24] : tier === 2 ? [0, 12] : [0]) : []) {if (tier >= 2) {for (const along of [-3 * U, 3 * U]) if (!(door && floor === 0)) d.window(side, a, along, floor + 5)@@ -45,25 +45,5 @@ export function house(variant.roof.shade,fit > 0.8 && (variant.chimney || tier >= 2))- if (tier === 3 && fit > 0.75) {- for (const side of sides) {- const p = (s: number, z: number, out = 0.02) => d.wall(side, a, s, z, out)- for (const x of [-a + U, a - U]) for (let z = 1; z < H; z += 4)- d.face([p(x - 0.6 * U, z), p(x + 0.6 * U, z), p(x + 0.6 * U, z + 2), p(x - 0.6 * U, z + 2)], 0xe7e3d4, 0.75, 0xa7b1a1)- d.line([p(-a - U, H - 1), p(a + U, H - 1)], 2, 0xb8c4af)- for (const along of [-3 * U, 3 * U]) {- d.line([p(along - 1.5 * U, 17, 0.055), p(along + 1.5 * U, 17, 0.055)], 1)- for (const dx of [-1.5, 0, 1.5]) d.line([p(along + dx * U, 14, 0.055), p(along + dx * U, 17, 0.055)], 0.75)- }- if (options.doors ? options.doors[side] : side === "right") {- d.face([p(-2 * U, 10), p(2 * U, 10), p(U, 13), p(-U, 13)], 0xe2ebde, 1)- const [u, v] = p(0, 0, 0.035)- for (let i = 0; i < 3; i++) {- const h = 0.04 + i * 0.035- d.box(u, v, side === "left" || side === "backLeft" ? 2.5 * U : h, side === "right" || side === "backRight" ? 2.5 * U : h, 0, 1.5 - i * 0.4, 0xe5e6dd, 0xd3d9cc, 0xc3ccbd, 0.75)- }- }- }- }return d.asset}diff --git a/src/asset-lab/land.ts b/src/asset-lab/land.tsindex fff69c3..0b6db78 100644--- a/src/asset-lab/land.ts+++ b/src/asset-lab/land.ts@@ -134,67 +134,39 @@ export function makeTree(return d.asset}-export function makeRock(ore: boolean, full: boolean) {- const x = ore ? 5 : 0,- y = ore ? 3 : 0,- h = hash(x, y),- h2 = hash(x * 7 + 3, y * 5 + 11),- h3 = hash(y * 17 + 5, x * 3 + 29)- const colors = ore ? { top: 0xe8ebf0, left: 0xd5dae3, right: 0xbcc3d0 } : { top: 0xeeefe9, left: 0xdfe1da, right: 0xcbcfc7 }- const d = new Drawing(- `${ore ? "ore" : "stone"}-${full ? "full" : "quarried"}`,- `${ore ? "Ore" : "Stone"} · ${full ? "full" : "quarried"}`,- "Faceted boulders, pebbles and mineral flecks, in both resource states."- )- d.asset.category = "land"- d.asset.reference = { type: "rock", x, y, ore, amount: full ? 40 : 10 }- d.asset.footprint = 1- const s = (full ? 5 : 4) * U * (0.85 + h2 * 0.3),- tall = Math.round((full ? 10 : 7) * (0.8 + h3 * 0.4)),- u = (h - 0.5) * 4 * U,- v = (h3 - 0.5) * 3 * U- const boulder = (u: number, v: number, s: number, H: number, k: number, j: number) => {- const base = square(u, v, s),- top: Array<Vertex> = [- [u - s * j, v - s * j, H],- [u + s * k, v - s * j, H],- [u + s, v + s * k, H],- [u - s * j, v + s * k, H]- ]- for (let i = 0; i < 4; i++) d.face([base[i]!, base[(i + 1) % 4]!, top[(i + 1) % 4]!, top[i]!], i === 1 ? colors.right : colors.left)- d.face(top, colors.top)- d.face([...base].reverse(), colors.left, 0)+/** Layered angular rock, shared by natural deposits and the quarry face. */+export function rockOutcrop(d: Drawing, u: number, v: number, radius: number, height: number, ore: boolean, variant = 0) {+ const start=d.asset.faces.length,n=7, turn=variant*0.29+ const colors=ore?{top:0xe0e5ed,left:0xc6ceda,right:0xa9b5c7}:{top:0xeeefe8,left:0xdcded4,right:0xc1c7b9}+ const ring=(scale:number,z:number,layer:number)=>Array.from({length:n},(_,i):Vertex=>{+ const t=i*Math.PI*2/n+turn,rough=0.66+hash(i+variant*7,variant+3)*0.34+ const shift=layer===3?-radius*0.17:0+ return [u+Math.cos(t)*radius*scale*rough+shift,v+Math.sin(t)*radius*scale*rough,z===0?0:z*(0.7+hash(i+3,variant+2)*0.3)]+ })+ const rings=[ring(1,0,0),ring(0.95,height*0.32,1),ring(0.78,height*0.65,2),ring(0.51,height,3)]+ for(let j=0;j<3;j++)for(let i=0;i<n;i++){+ const a=rings[j]![i]!,b=rings[j]![(i+1)%n]!,c=rings[j+1]![(i+1)%n]!,e=rings[j+1]![i]!+ d.face([a,b,c,e],i<4?colors.right:colors.left,0)}- if (h2 > 0.35) boulder(u - s * 0.9, v - s * 1.1, s * 0.55, Math.round(tall * 0.6), 0.3 + h * 0.3, 0.5)- boulder(u, v, s, tall, 0.3 + h2 * 0.3, 0.5 + h3 * 0.2)- if (full && h3 > 0.5) boulder(u + s * 0.9, v + s * 1.2, s * 0.4, Math.round(tall * 0.45), 0.4, 0.6)- for (let i = 0; i < 3; i++)- d.ellipsoid(u + (hash(x + i, y * 3) - 0.5) * 14 * U, v + s + (hash(y + i, x * 5) * 3 + 1) * U, 0.4, 0.02, 0.02, 0.4, 0xaab1a6, 0)- if (ore) {- for (const [du, dv, z] of [- [-0.3, 1, 3],- [0.2, 1, 6],- [1, 0.1, 4],- [1, -0.5, 7]- ]) {- const U0 = u + du! * s,- V0 = v + dv! * s,- H = z! * (tall / 10),- w = 1 / 64- d.face(- [- [U0 - w, V0 + 0.003, H - 1],- [U0 + w, V0 + 0.003, H - 1],- [U0 + w, V0 + 0.003, H + 1],- [U0 - w, V0 + 0.003, H + 1]- ],- 0x4a5368,- 0- )- }- const base = square(u - s * 0.2, v + s * 0.1, 0.035, tall)- for (let i = 0; i < 4; i++) d.face([base[i]!, base[(i + 1) % 4]!, [u - s * 0.2, v + s * 0.1, tall + 4]], 0x8fa3c8, 1)+ const summit:Vertex=[u-radius*0.19,v+radius*0.09,height*0.99]+ for(let i=0;i<n;i++)d.face([rings[3]![i]!,rings[3]![(i+1)%n]!,summit],i%3===0?colors.left:colors.top,0)+ d.face([...rings[0]!].reverse(),colors.left,0)+ d.volume(start,0.8)+ for(const j of [1,2])for(const indices of [[0,1,2],[3,4,5]])d.line(indices.map(i=>rings[j]![i]!),0.65,ore?0x73849c:0x98a68c,0.65)+ for(const i of [0,2,5])d.line([rings[0]![i]!,rings[1]![i]!,rings[2]![(i+1)%n]!],0.75,ore?0x73849c:0x98a68c,0.6)+ if(ore)for(const i of [0,1,3,6]){+ const a=rings[1]![i]!,b=rings[2]![i]!+ d.line([[a[0]*0.997+u*0.003+0.003,a[1]+0.003,a[2]+1],[b[0]+0.003,b[1]+0.003,b[2]-1]],1.8,0x8199bb)}+}++export function makeRock(ore: boolean, full: boolean, variant = 0) {+ const d=new Drawing(`${ore?"ore":"stone"}-${full?"full":"quarried"}`,`${ore?"Ore":"Stone"} · ${full?"full":"quarried"}`,"A clustered deposit with layered rock faces, fractures and exposed mineral seams. Seeded silhouettes vary across the land.")+ d.asset.category="land";d.asset.reference={type:"rock",x:ore?5:0,y:ore?3:0,ore,amount:full?40:10};d.asset.footprint=1+ rockOutcrop(d,-2.9*U,-2.2*U,2.8*U,full?10:4,ore,variant+2)+ rockOutcrop(d,0.3*U,-0.1*U,(full?4.4:4)*U,full?12+(variant%3)*1.5:6,ore,variant)+ rockOutcrop(d,3.7*U,3.2*U,2.8*U,full?9:3,ore,variant+4)+ for(const [u,v]of [[-4,4],[-2,5.8],[5,-3.5]] as const)rockOutcrop(d,u*U,v*U,0.7*U,1.8,ore,variant+u)return d.asset}diff --git a/src/asset-lab/main.ts b/src/asset-lab/main.tsindex 64c6c00..5db5f0f 100644--- a/src/asset-lab/main.ts+++ b/src/asset-lab/main.ts@@ -189,6 +189,7 @@ for (const asset of inkAssets) {pixi.destroy(true)const models = new Map<string, ReturnType<typeof buildAsset>>()+let effectTimeOverride:number|null=nulllet selected = inkAssets[2]!,yaw = 0,pitch = 30,@@ -223,7 +224,9 @@ function render() {height = viewer.clientHeightif (!width || !height) returnconst ref = references.get(selected.id)!- const vertical = Math.max(40, ref.height * 1.45, ((ref.width * height) / width) * 1.3) / zoom+ const model = models.get(selected.id)!+ const effectBounds=selected.smokeEffect?new THREE.Box3().setFromObject(model.group):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) / zoomrenderer.setSize(width, height, false)camera.left = (-vertical * width) / height / 2camera.right = -camera.left@@ -231,7 +234,7 @@ function render() {camera.bottom = -camera.topconst heading = ((45 + yaw) * Math.PI) / 180,altitude = (pitch * Math.PI) / 180- const target = new THREE.Vector3(0, -(ref.y + ref.height / 2) / Math.cos(Math.PI / 6), 0)+ const target = effectBounds?effectBounds.getCenter(new THREE.Vector3()):new THREE.Vector3(0, -(ref.y + ref.height / 2) / Math.cos(Math.PI / 6), 0)camera.position.copy(target).add(@@ -244,7 +247,7 @@ function render() {camera.lookAt(target)camera.updateProjectionMatrix()camera.updateMatrixWorld()- const model = models.get(selected.id)!+ model.updateEffects(effectTimeOverride??performance.now()/1000)for (const { material, width: lineWidth } of model.lineMaterials) material.linewidth = lineWidthmodel.updateContours(camera)renderer.render(scene, camera)@@ -400,12 +403,17 @@ Object.assign(window, {return { meshes: model.children.length }},stats: () => ({ selected: selected.id, yaw, pitch, drawCount, triangles: renderer.info.render.triangles }),- capture+ capture,+ captureEffect: (time:number)=>{effectTimeOverride=time;render();const image=capture("model");effectTimeOverride=null;return image}}})select(new URLSearchParams(location.search).get("asset") ?? selected.id)+let effectFrame=0+const animateEffect=()=>{if(selected.smokeEffect)render();effectFrame=requestAnimationFrame(animateEffect)}+effectFrame=requestAnimationFrame(animateEffect)if (import.meta.hot)import.meta.hot.dispose(() => {+ cancelAnimationFrame(effectFrame)resize.disconnect()models.forEach((model) => model.dispose())renderer.dispose()diff --git a/src/asset-lab/primitives.ts b/src/asset-lab/primitives.tsindex 6d62a6f..f29b9b7 100644--- a/src/asset-lab/primitives.ts+++ b/src/asset-lab/primitives.ts@@ -33,6 +33,7 @@ export type AssetReference =| { type: "roads" | "water" }| { type: "none" }export interface InkAsset {+ smokeEffect?: { origin: Vertex }effects?: { half: number; height: number; state: SurfaceState }appearance?: "fine" | "poor" | "worn" | "winter"category?: AssetCategory@@ -266,6 +267,18 @@ export class Drawing {this.line([...upper, upper[0]!], width)if (h > 1) this.line([...bottom, bottom[0]!], width)}+ barrel(u: number, v: number, r = 1.2 * U, z = 0, height = 8, contents?: number) {+ const start = this.asset.faces.length, n = 12+ const ring = (h: number, radius: number) => Array.from({ length: n }, (_, i): Vertex => [u + Math.cos(i * Math.PI * 2 / n) * radius, v + Math.sin(i * Math.PI * 2 / n) * radius, z + h])+ const rings = [ring(0, r * 0.85), ring(height * 0.25, r), ring(height * 0.75, r), ring(height, r * 0.85)]+ for (let j = 0; j < 3; j++) for (let i = 0; i < n; i++) this.face([rings[j]![i]!, rings[j]![(i + 1) % n]!, rings[j + 1]![(i + 1) % n]!, rings[j + 1]![i]!], i % 3 === 0 ? 0xcbb18a : 0xd9bd95, 0)+ this.face([...rings[0]!].reverse(), 0xb59b75, 0)+ this.face(rings[3]!, contents ?? 0xe9d2a8, 0)+ this.volume(start, 1)+ for (const points of [rings[1]!, rings[2]!]) this.line([...points, points[0]!], 1.2, 0x7d877d)+ this.line([...rings[3]!, rings[3]![0]!], 1)+ if (contents === undefined) for (const x of [-0.35, 0.35]) this.line([[u + x * r, v - r * 0.75, z + height + 0.04], [u + x * r, v + r * 0.75, z + height + 0.04]], 0.5, 0xa98c66)+ }ellipsoid(u: number, v: number, z: number, ru: number, rv: number, rz: number, color: number, width = 1, light?: number, segments = 16) {const start = this.asset.faces.length,n = segments,@@ -324,16 +337,13 @@ export class Drawing {this.line([...small, small[0]!], 1, palette.ink, 0.45)}sack(u: number, v: number, z = 0, color = 0xf2ecdc) {- this.ellipsoid(u, v, z + 3.5, 3 / 45.2548, 3 / 45.2548, 3.15, color, 1)- this.line(- [- [u - 0.03, v + 0.055, z + 5.5],- [u + 0.03, v + 0.055, z + 5.5]- ],- 1,- palette.ink,- 0.6- )+ const start = this.asset.faces.length, n = 8+ const ring = (radius: number, h: number) => Array.from({length:n},(_,i):Vertex=>[u+Math.cos(i*Math.PI*2/n)*radius,v+Math.sin(i*Math.PI*2/n)*radius*0.8,z+h])+ const rings = [ring(0.045,0),ring(0.064,2),ring(0.05,6),ring(0.016,7),ring(0.028,8)]+ for(let j=0;j<4;j++)for(let i=0;i<n;i++)this.face([rings[j]![i]!,rings[j]![(i+1)%n]!,rings[j+1]![(i+1)%n]!,rings[j+1]![i]!],i%3===0?mix(color,0xb8aa8c,0.16):color,0)+ this.face([...rings[0]!].reverse(),color,0);this.face(rings[4]!,color,0);this.volume(start,1)+ this.line([...rings[3]!,rings[3]![0]!],1,0x9f8b69)+ this.line([[u-0.025,v+0.053,z+1],[u-0.015,v+0.04,z+5.5]],0.6,0xb7ab95)}fir(u: number, v: number, z = 0, size = 1, tiers = 2) {const step = (24 * size) / (tiers + 1)diff --git a/src/asset-lab/renderer.ts b/src/asset-lab/renderer.tsindex 6d2136d..8b7c247 100644--- a/src/asset-lab/renderer.ts+++ b/src/asset-lab/renderer.ts@@ -7,6 +7,7 @@ import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js"import { mergeGeometries, mergeVertices } from "three/addons/utils/BufferGeometryUtils.js"import { palette, type Face, type InkAsset, type Vertex } from "./primitives.ts"import { installSurfaceShader } from "../render3d/surface-shader.ts"+import { SmokePlume } from "../render3d/smoke-effects.ts"/** A 30° elevation and 45° heading reproduce the game's 64×32 projection.* The vertical conversion preserves pixel-authored building heights exactly. */@@ -299,7 +300,10 @@ export function buildAsset(asset: InkAsset, options: { batchFaces?: boolean; mesprevious.dispose()}}+ const plume=asset.smokeEffect&&options.surfaceEffects!==false?new SmokePlume():null+ if(plume){plume.group.position.copy(vertex3(asset.smokeEffect!.origin));group.add(plume.group);plume.update(0)}const dispose = () => {+ plume?.dispose()group.traverse((object) => {if (object instanceof THREE.Mesh) object.geometry.dispose()})@@ -309,7 +313,7 @@ export function buildAsset(asset: InkAsset, options: { batchFaces?: boolean; mesif (hull) (hull.material as THREE.Material).dispose()for (const object of group.children) if (object instanceof LineSegments2) object.geometry.dispose()}- return { group, lineMaterials, updateContours, updateEffects: time => { effectTime.value = time }, dispose }+ return { group, lineMaterials, updateContours, updateEffects: time => { effectTime.value = time;plume?.update(time) }, dispose }}/** GLB uses ordinary meshes for ink strokes so the outlines survive import.@@ -318,6 +322,7 @@ export async function exportAsset(asset: InkAsset) {const group = new THREE.Group()group.name = asset.idif(asset.effects)group.userData.inklineSurfaceEffects=asset.effects+ if(asset.smokeEffect)group.userData.inklineSmokeEffect=asset.smokeEffectfor (const face of asset.faces) group.add(faceMesh(face.points, face.color, face.opacity ?? 1))const contourFaces = asset.faces.filter((face) => face.contour)const hull = contourFaces.length ? silhouetteMesh(asset, contourFaces) : nulldiff --git a/src/asset-lab/services.ts b/src/asset-lab/services.tsindex 08c6042..e55f4d5 100644--- a/src/asset-lab/services.ts+++ b/src/asset-lab/services.ts@@ -1,7 +1,56 @@-import { type KindId } from "../content.ts"+import { kinds, type KindId } from "../content.ts"import { U } from "../iso.ts"-import { Drawing, palette, pale, sides, square, type Vertex } from "./primitives.ts"+import { Drawing, palette, pale, sides, square, type Vertex, type Side } from "./primitives.ts"import { bench, flowerBed } from "./town-props.ts"+import type { BuildingOptions } from "./buildings.ts"+import { rockOutcrop } from "./land.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)+ if (kind === "chapel") {+ d.face([p(-4*U,0),p(4*U,0),p(4*U,17),p(0,24),p(-4*U,17)],0xd8d8cc,1)+ d.face([p(-3*U,0,0.025),p(3*U,0,0.025),p(3*U,16,0.025),p(0,21,0.025),p(-3*U,16,0.025)],0x9c8060,1)+ for(const x of [-2,-1,0,1,2])d.line([p(x*U,1,0.03),p(x*U,16-Math.abs(x),0.03)],0.6,0x765f46)+ for(const sign of [-1,1])for(const z of [4,9,14])d.line([p(sign*3*U,z,0.03),p(sign*4*U,z,0.03)],0.6,0xa4ad9d)+ d.line([p(-3*U,7,0.032),p(3*U,7,0.032)],1,0x6d7469)+ d.line([p(-3*U,12,0.032),p(3*U,12,0.032)],1,0x6d7469)+ } else {+ d.face([p(-4*U,0),p(4*U,0),p(4*U,23),p(-4*U,23)],0xe3e6dd,1)+ d.face([p(-3*U,0,0.025),p(3*U,0,0.025),p(3*U,18,0.025),p(-3*U,18,0.025)],0x839a89,1)+ for(const x of [-1.6,1.6])d.face([p((x-0.8)*U,10,0.03),p((x+0.8)*U,10,0.03),p((x+0.8)*U,16,0.03),p((x-0.8)*U,16,0.03)],0xdbe9e7,0.75)+ d.face([p(-3*U,19,0.025),p(3*U,19,0.025),p(3*U,21.5,0.025),p(-3*U,21.5,0.025)],0xdbe9e7,0.75)+ d.line([p(0,0,0.03),p(0,18,0.03)],1,0x596c60)+ }+ for(const x of [-0.6,0.6])d.line([p(x*U,8,0.04),p(x*U,10,0.04)],1.2,0xceb887)+ d.line([p(-4*U,0.3,0.04),p(4*U,0.3,0.04)],1.5,0xb6bead)+}++export function makeQuarry(options: BuildingOptions = {}) {+ const fit = options.fit ?? 1, p = 15*U, H = 32+ const d = new Drawing("quarry", "Quarry", "A two-cell stonecutting yard with a stepped rock face, timber derrick, dressed blocks and a small workshop.")+ d.asset.category="buildings";d.asset.reference={type:"building",kind:"quarry"};d.asset.footprint=kinds.quarry.size+ if(options.plate!==false)d.plate(2)+ d.box(-9*U,-6*U,4*U,7*U,0,H)+ if(fit>0)d.box(-9*U,-6*U,4.3*U,7.3*U,H,1.5*fit,0xd1d7ca,0xb8c2b1,0xa6b49f,1)+ if(fit>0.4){+ d.face([[-11*U,1*U+0.005,0],[-7*U,1*U+0.005,0],[-7*U,1*U+0.005,17],[-11*U,1*U+0.005,17]],0x8f9891,1)+ d.line([[-9*U,1*U+0.01,1],[-9*U,1*U+0.01,16]],1)+ d.face([[-4.9*U,-8*U,12],[-4.9*U,-4*U,12],[-4.9*U,-4*U,20],[-4.9*U,-8*U,20]],0xdbe6ea,1)+ }+ if(fit>0.75){+ rockOutcrop(d,4*U,5*U,7.5*U,25,false,2)+ for(const [x,y,z]of [[-9,8,0],[-5,8,0],[-9,12,0],[-7,10,5]] as const)d.box(x*U,y*U,1.6*U,1.5*U,z,5,0xe9ebe2,0xd4d9ce,0xbec7b9,1)+ for(const x of [4,10])d.box(x*U,-10*U,0.45*U,0.5*U,0,43,0xd8bb91,0xc3a177,0xaa8b65,1)+ d.box(7*U,-10*U,4*U,0.5*U,41,2,0xd8bb91,0xc3a177,0xaa8b65,1)+ d.line([[4*U,-10*U,22],[10*U,-10*U,40]],1,0x8a6a45)+ d.line([[8*U,-10*U,42],[8*U,-10*U,25]],0.75)+ d.box(8*U,-10*U,1.4*U,1.2*U,20,5,0xe9ebe2,0xd4d9ce,0xbec7b9,1)+ d.line([[6.5*U,-10*U,25],[8*U,-10*U,28],[9.5*U,-10*U,25]],0.75)+ d.box(-2*U,12*U,3*U,U,0,3,0xe9d2a8,0xd0b58c,0xb08a5e,1)+ d.line([[-3*U,12*U,3],[-1*U,12*U,7]],1.5,0x8a6a45)+ }+ return d.asset+}export const townBuildingNotes: Partial<Record<KindId, string>> = {granary: "Raised grain store with timber braces, a sack hoist, ventilation shutters and grain bins.",@@ -16,9 +65,12 @@ export const townBuildingNotes: Partial<Record<KindId, string>> = {export function finishTownBuilding(d: Drawing, id: KindId, a: number, p: number, H: number) {const c = (a + p) / 2const post = (u: number, v: number, height: number, z = 0) => d.box(u, v, 0.35 * U, 0.35 * U, z, height, 0xe9d2a8, 0xd0b58c, 0xb08a5e, 0.75)- const ladder = (u: number, v: number, height: number) => {- for (const x of [-1.2, 1.2]) d.line([[u + x * U, v, 0], [u + x * U, v - 1.5 * U, height]], 1, 0x8a6a45)- for (let z = 3; z < height; z += 3) d.line([[u - 1.2 * U, v - (z / height) * 1.5 * U, z], [u + 1.2 * U, v - (z / height) * 1.5 * U, z]], 1, 0x8a6a45)+ const ladder = (foot: number, wall: number, v: number, height: number) => {+ for (const y of [-1.1, 1.1]) d.line([[foot,v+y*U,0],[wall,v+y*U,height]],1.2,0x8a6a45)+ for (let z = 3; z < height; z += 3) {+ const u=foot+(wall-foot)*z/height+ d.line([[u,v-1.1*U,z],[u,v+1.1*U,z]],1,0x8a6a45)+ }}if (id === "granary") {for (const side of sides) {@@ -44,8 +96,8 @@ export function finishTownBuilding(d: Drawing, id: KindId, a: number, p: number,d.face([[c, y - U, 5], [c, y + U, 5], [c, y, 3]], 0xb58b64, 0.75)for (const z of [7, 9]) d.line([[c + 0.03, y - 0.02, z], [c + 0.03, y + 0.02, z - 0.5]], 0.5, 0x8a6a45)}- d.cylinder(-a - 2 * U, c, 1.5 * U, 0, 7, 0xbda07a, 0xdbc3a0, 1)- for (let i = 0; i < 3; i++) d.log("u", c + i * U, -a - U, -a + 3 * U, 0, 1.3, 0xb08a5e, 0xe9d2a8)+ d.barrel(-a - 2 * U, c, 1.5 * U,0,7)+ for (const [y,z] of [[-0.55,0],[0.55,0],[0,2.2]]) d.log("u", c + y!*U, -a + U, -a + 5 * U, z!, 1.3, 0xb08a5e, 0xe9d2a8)} else if (id === "firewatch") {const half = 3 * U, z = H + 13for (const [u, v] of square(0, 0, half)) post(u, v, 15, z)@@ -54,8 +106,8 @@ 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(c, -a / 2, 31)- d.cylinder(c, c, 2 * U, 0, 9, 0xc79a5b, 0xc9dde6, 1)+ ladder(p-U,a+0.003,-a/2,H+7)+ 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") {for (const side of sides) {@@ -64,9 +116,13 @@ export function finishTownBuilding(d: Drawing, id: KindId, a: number, p: number,d.line([at(0, z + 1.5), at(0, z + 5.5)], 2, 0x719383)d.line([at(-U, z + 3.5), at(U, z + 3.5)], 2, 0x719383)}- flowerBed(d, c, -a / 2, 2.5, 0xb29ac2)+ flowerBed(d, c, -a / 2, 2, 0xb29ac2)flowerBed(d, -a / 2, c, 2.5, 0xe1cb85)- bench(d, c, c)+ const startFace=d.asset.faces.length,startStroke=d.asset.strokes.length+ bench(d, 0, 0)+ const place=([u,v,z]:Vertex):Vertex=>[c+v,a/2+u,z]+ for(const f of d.asset.faces.slice(startFace))f.points=f.points.map(place)+ for(const s of d.asset.strokes.slice(startStroke))s.points=s.points.map(place)if (id === "healer") {d.box(-a - 2 * U, c, 1.5 * U, 2.5 * U, 0, 6, 0xe9d2a8, 0xd0b58c, 0xb08a5e, 1)for (const y of [-1, 1]) {@@ -102,7 +158,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)- ladder(c, c, 18)+ ladder(p-U,a+0.003,a/2,18)for (const x of [-1, 1]) d.box(c + x * U, c - 2 * U, U, U, 0, 3, 0xe4e6df, 0xd6d9cf, 0xc2c9bd, 1)}}diff --git a/src/asset-lab/town-props.ts b/src/asset-lab/town-props.tsindex 7aeb81d..7f54c4a 100644--- a/src/asset-lab/town-props.ts+++ b/src/asset-lab/town-props.ts@@ -72,8 +72,8 @@ export function makeDecor(id: KindId) {d.face(square(0, 0, p, -0.15), id === "plaza" || id === "statue" || id === "fountain" ? stone : green)if (id === "garden") {d.box(0, 0, p, U, 0, 0.3, 0xeee9de, 0xe3ddcf, 0xd5d0c4, 0.75)- tree(d, -p / 2, -p / 2, 0.7)- tree(d, p / 2, p / 2, 0.8)+ tree(d, -2*U, -2*U, 0.6)+ tree(d, 2*U, 2*U, 0.6)flowerBed(d, p / 2, -p / 2, 2, 0xc78374)flowerBed(d, -p / 2, p / 2, 2, 0xd6ba69)} else if (id === "park") {@@ -100,8 +100,8 @@ export function makeDecor(id: KindId) {} else if (id === "plaza") {setts(d, 0, 0, p - 0.02, 0)figure(d, 0, 0, 6)- tree(d, -p * 0.75, -p * 0.75, 0.7)- tree(d, p * 0.75, p * 0.75, 0.7)+ tree(d, -p * 0.65, -p * 0.65, 0.65)+ tree(d, p * 0.65, p * 0.65, 0.65)bench(d, p * 0.6, -p * 0.7)bench(d, -p * 0.6, p * 0.7)}diff --git a/src/model-review/main.ts b/src/model-review/main.tsindex 14807f9..81b79c7 100644--- a/src/model-review/main.ts+++ b/src/model-review/main.ts@@ -4,6 +4,7 @@ import { buildAsset, exportAsset } from "../asset-lab/renderer.ts"import "./style.css"const families = {+ fixes: { title: "Review fixes", ids: ["mill","bakery","weaver","warehouse","mine","farm","chapel","hospital","smokehouse","builder","townhouse","quarry","stone-full","stone-quarried","ore-full","problem-marker","smoke","firewatch"] },buildings: { title: "Buildings", ids: ["granary", "smokehouse", "firewatch", "healer", "hospital", "watchhouse", "builder"] },ornaments: { title: "Gardens & squares", ids: ["garden", "park", "fountain", "statue", "plaza", "paved-street"] },homes: { title: "Homes & neighbourhoods", ids: ["cottage", "citizen", "townhouse", "cottage-fine", "citizen-fine", "townhouse-fine", "cottage-poor", "citizen-worn", "townhouse-worn"] },@@ -39,6 +40,7 @@ function render() {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)+ model.built.updateEffects(performance.now()/1000)renderer.setViewport(r.left, innerHeight - r.bottom, r.width, r.height)renderer.setScissor(Math.max(0, r.left), Math.max(0, innerHeight - r.bottom), Math.min(innerWidth, r.right) - Math.max(0, r.left), Math.min(innerHeight, r.bottom) - Math.max(0, r.top))renderer.render(model.scene, camera)@@ -87,6 +89,7 @@ root.querySelector<HTMLButtonElement>("#sheet")!.onclick = () => {camera.top = vertical / 2; camera.bottom = -camera.top; camera.left = -vertical * width / 270 / 2; camera.right = -camera.leftcamera.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)+ model.built.updateEffects(performance.now()/1000)renderer.setViewport(0, 0, width, 270); renderer.render(model.scene, camera)const x = (i % columns) * width, y = 100 + Math.floor(i / columns) * heightctx.drawImage(renderer.domElement, x, y, width, 270)@@ -111,5 +114,8 @@ const schedule = () => { cancelAnimationFrame(frame); frame = requestAnimationFraddEventListener("scroll", schedule, {passive: true}); addEventListener("resize", schedule)const query = new URLSearchParams(location.search).get("collection")select(query && query in families ? query as Family : "buildings")+let effectFrame=0+const animateEffects=()=>{if(families[family].ids.some(id=>assetById.get(id)?.smokeEffect))render();effectFrame=requestAnimationFrame(animateEffects)}+effectFrame=requestAnimationFrame(animateEffects)Object.assign(window, { townModelReview: { stats: () => ({ family, models: models.length, renders, yaw, pitch }) } })-if (import.meta.hot) import.meta.hot.dispose(() => { models.forEach(m => m.built.dispose()); renderer.dispose(); renderer.domElement.remove(); removeEventListener("scroll", schedule); removeEventListener("resize", schedule) })+if (import.meta.hot) import.meta.hot.dispose(() => { cancelAnimationFrame(effectFrame);models.forEach(m => m.built.dispose()); renderer.dispose(); renderer.domElement.remove(); removeEventListener("scroll", schedule); removeEventListener("resize", schedule) })diff --git a/src/render3d/smoke-effects.ts b/src/render3d/smoke-effects.tsnew file mode 100644index 0000000..47ebf62--- /dev/null+++ b/src/render3d/smoke-effects.ts@@ -0,0 +1,57 @@+import * as THREE from "three"++const vertex = `+attribute float puffSeed;+uniform float time;+varying vec2 tex;+varying float age;+varying float seed;+void main(){+ tex=uv;seed=puffSeed;age=fract(time/3.8+seed);+ vec4 center=modelViewMatrix*vec4(0,0,0,1);+ center.y+=age*29.0;+ center.x+=age*age*6.0+sin(age*5.0+seed*29.0)*age*2.0;+ float size=4.0+age*11.0;+ center.xy+=position.xy*vec2(size,size*1.18);+ gl_Position=projectionMatrix*center;+}`+const fragment = `+uniform float time;+uniform float power;+varying vec2 tex;+varying float age;+varying float seed;+float hash(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}+float noise(vec2 p){vec2 i=floor(p),f=fract(p);f=f*f*(3.0-2.0*f);return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),mix(hash(i+vec2(0,1)),hash(i+vec2(1,1)),f.x),f.y);}+void main(){+ vec2 p=(tex-0.5)*2.0;+ float cloud=noise(tex*3.0+seed*13.0+vec2(0,time*0.13))*0.65+noise(tex*7.0+seed*9.0)*0.35;+ float edge=1.0-smoothstep(0.35,1.0,length(p)+cloud*0.24);+ float alpha=edge*sin(age*3.14159)*0.19*power;+ if(alpha<0.008)discard;+ vec3 color=mix(vec3(0.40,0.45,0.39),vec3(0.68,0.70,0.63),age);+ gl_FragColor=vec4(pow(color,vec3(2.2)),alpha);+ #include <colorspace_fragment>+}`++/** A bounded cloud emitter, anchored at the actual flue opening. */+export class SmokePlume {+ readonly group = new THREE.Group()+ private mesh: THREE.InstancedMesh<THREE.PlaneGeometry,THREE.ShaderMaterial>+ constructor() {+ const count=10,geometry=new THREE.PlaneGeometry(1,1)+ geometry.setAttribute("puffSeed",new THREE.InstancedBufferAttribute(Float32Array.from({length:count},(_,i)=>i/count),1))+ geometry.boundingBox=new THREE.Box3(new THREE.Vector3(-14,0,-14),new THREE.Vector3(14,42,14))+ geometry.boundingSphere=new THREE.Sphere(new THREE.Vector3(0,21,0),30)+ const material=new THREE.ShaderMaterial({vertexShader:vertex,fragmentShader:fragment,uniforms:{time:{value:0},power:{value:1}},transparent:true,depthWrite:false,depthTest:true,side:THREE.DoubleSide})+ this.mesh=new THREE.InstancedMesh(geometry,material,count)+ for(let i=0;i<count;i++)this.mesh.setMatrixAt(i,new THREE.Matrix4())+ this.mesh.frustumCulled=false;this.mesh.renderOrder=4;this.group.add(this.mesh)+ }+ update(time: number, strength = 1) {+ this.group.visible=strength>0+ this.mesh.material.uniforms.time!.value=time+ this.mesh.material.uniforms.power!.value=strength+ }+ dispose(){this.group.removeFromParent();this.mesh.geometry.dispose();this.mesh.material.dispose();this.mesh.dispose()}+}diff --git a/src/render3d/structure-effects.ts b/src/render3d/structure-effects.tsindex 4bc9015..faf3fb9 100644--- a/src/render3d/structure-effects.ts+++ b/src/render3d/structure-effects.ts@@ -40,8 +40,9 @@ void main(){float core=(1.0-body)*pow(1.0-y,0.7);color=mix(vec3(0.87,0.33,0.12),vec3(1.0,0.83,0.38),smoothstep(0.0,0.8,core));}else if(mode<1.5){- float d=length((p-0.5)*2.0); float cloud=noise(p*5.0+vec2(seed*9.0,time*0.12));- alpha=(1.0-smoothstep(0.3,1.0,d+cloud*0.2))*sin(age*3.14159)*0.20*power;+ float d=length((p-0.5)*vec2(2.0,1.8));+ float cloud=noise(p*3.0+vec2(seed*9.0,time*0.12))*0.65+noise(p*7.0+seed*11.0)*0.35;+ alpha=(1.0-smoothstep(0.3,1.0,d+cloud*0.24))*sin(age*3.14159)*0.24*power;color=mix(vec3(0.35,0.39,0.33),vec3(0.64,0.66,0.58),age);}else{alpha=(1.0-smoothstep(0.05,0.5,length(p-0.5)))*sin(age*3.14159)*power;diff --git a/src/render3d/views.ts b/src/render3d/views.tsindex 0a9d12a..c05b0e2 100644--- a/src/render3d/views.ts+++ b/src/render3d/views.ts@@ -19,6 +19,7 @@ import { makeSails, makeFlag } 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"+import { SmokePlume } from "./smoke-effects.ts"import { surfaceState, type SurfaceState } from "./surface-state.ts"import { makePerson, serviceCostume, type ServiceRole } from "../asset-lab/people.ts"import { makeTree, makeRock, makeField, hash } from "../asset-lab/land.ts"@@ -87,9 +88,7 @@ export class BuildingView extends WorldView {private plate: ModelHandleprivate marker: ModelHandleprivate motion: ModelHandle- private smokes: Array<ModelHandle>- private rings: Array<number> = []- private puff = 0+ private smoke: SmokePlume | null = nullprivate wave = 0private opening = 0private beat = -1@@ -104,8 +103,7 @@ export class BuildingView extends WorldView {this.marker.use("problem-marker", makeMarker)this.marker.root.visible = falsethis.body.root.add(this.motion.root)- this.smokes = [this.model(false), this.model(false), this.model(false)]- for (const s of this.smokes) s.root.visible = false+}place(x: number, y: number) {const size = kinds[this.kindId].size@@ -163,45 +161,21 @@ 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}- this.puff -= dt- if (look.working && kind.topper === "chimney" && look.build >= 1 && this.puff <= 0) {- this.rings.push(0)- if (this.rings.length > 3) this.rings.shift()- this.puff = 0.7+ const smoking=look.working&&kind.topper==="chimney"&&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)}- this.rings = this.rings.map((age) => age + dt / 1.8).filter((age) => age < 1)- const a = kind.half * U,- pitch = (2 * a) / kind.bays,- u = -a + pitch * 0.5,- v = -a + pitch * 0.5- this.smokes.forEach((smoke, i) => {- const t = this.rings[i]- smoke.root.visible = t !== undefined- if (t === undefined) return- const r = Math.round(4 + t * 7)- smoke.use("smoke-ring/" + r, () => {- const d = new Drawing("smoke-ring", "Smoke", "")- d.line(- Array.from({ length: 25 }, (_, j): Vertex => [- (Math.cos((j / 24) * Math.PI * 2) * r) / 64,- (-Math.cos((j / 24) * Math.PI * 2) * r) / 64,- Math.sin((j / 24) * Math.PI * 2) * r- ]),- 1,- 0x3d4943,- 0.55- )- return d.asset- })- smoke.alpha = 1 - t- smoke.root.position.copy(vertex3([u + (Math.sin(t * 5) * 1.5) / 64, v - (Math.sin(t * 5) * 1.5) / 64, H + 24 + t * 34]))- })+ this.smoke?.update(performance.now()/1000,Number(smoking))this.emphasis(emphasis)}override orient() {this.marker.root.rotation.y = this.stage.heading - Math.PI / 4- for (const smoke of this.smokes) smoke.root.rotation.y = this.stage.heading - Math.PI / 4}+ override destroy() { this.smoke?.dispose();this.smoke=null;super.destroy() }+}export class HouseView extends WorldView {@@ -286,18 +260,20 @@ export class TreeView extends WorldView {}export class RockView extends WorldView {private body: ModelHandle+ private variant = 0constructor(stage: GameScene, entity: number) {super(stage, entity)this.body = this.model()}place(x: number, y: number) {+ this.variant = Math.floor(hash(x,y)*6)this.anchor.x = x + 0.5this.anchor.y = y + 0.5this.group.position.copy(vertex3([this.anchor.x, this.anchor.y, 0]))}update(ore: boolean, amount: number) {const full = amount > ROCK_AMOUNT / 2- this.body.use(`rock/${ore}/${full}`, () => makeRock(ore, full))+ this.body.use(`rock/${ore}/${full}/${this.variant}`, () => makeRock(ore, full, this.variant))}}export class FieldView extends WorldView {diff --git a/test/ink-assets.test.ts b/test/ink-assets.test.tsindex 4ea81c7..7cb68c9 100644--- a/test/ink-assets.test.ts+++ b/test/ink-assets.test.ts@@ -3,6 +3,8 @@ import { test } from "node:test"import { inkAssets, assetById } from "../src/asset-lab/assets.ts"import { kindIds, goodIds, kinds } from "../src/content.ts"import { testMap } from "../src/map-lab/map.ts"+import { U } from "../src/iso.ts"+import { makeRock } from "../src/asset-lab/land.ts"test("the portable catalogue covers all world object families", () => {assert.equal(assetById.size, inkAssets.length, "Asset IDs must be unique")@@ -49,3 +51,11 @@ test("the review map includes every catalogue model at least once", () => {assert.deepEqual([...represented].sort(), inkAssets.map((a) => a.id).sort())assert.equal(testMap.coverage, inkAssets.length)})++test("buildings, homes and resource deposits stay inside their plates", () => {+ const models = [...inkAssets.filter(a=>a.reference?.type==="building"||a.reference?.type==="house"),...Array.from({length:6},(_,i)=>[makeRock(false,true,i),makeRock(true,true,i)]).flat()]+ for(const a of models){+ const half=(a.footprint!*8-1)*U+ for(const p of [...a.faces.flatMap(f=>f.points),...a.strokes.flatMap(s=>s.points)])assert.ok(Math.abs(p[0])<=half+0.0001&&Math.abs(p[1])<=half+0.0001,`${a.id}: geometry outside the ${a.footprint}-cell plate`)+ }+})