diff --git a/app/diorama/models.ts b/app/diorama/models.ts index aeb423e..a381f4d 100644 --- a/app/diorama/models.ts +++ b/app/diorama/models.ts @@ -219,6 +219,13 @@ function wallDisc(face: 'x' | 'y', at: number, along: number, zc: number, r: num return { pts, color, twoSided: true, flat: true, depth } } +/** Faces that must draw over a wall: sorted from `depth` on, in their own front-to-back order. */ +function over(faces: Face[], depth: number): Face[] { + const own = faces.map((f) => f.pts.reduce((n, [x, y, z]) => n + x + y + z, 0) / f.pts.length) + const low = Math.min(...own) + return faces.map((f, i) => ({ ...f, depth: depth + own[i]! - low })) +} + /** A beam lying on the ground between two points, or raised to z: a fence rail, a timber. */ function beam([ax, ay]: V2, [bx, by]: V2, z: number, t: number, h: number, color: string): Face[] { const len = Math.hypot(bx - ax, by - ay) || 1 @@ -291,6 +298,21 @@ function ram(x: number, y: number, k: number, quarters = 0): Face[] { return shift(turn(faces, quarters), x, y) } +/** A siege engine in the making, facing +x: the frame on its wheels, two posts up. */ +function frame(x: number, y: number, k: number): Face[] { + return shift( + [ + ...[-1, 1].flatMap((fx) => [-1, 1].map((fy) => [fx, fy])).flatMap(([fx, fy]) => wheel(fx! * 1.25 * k, fy! * 0.95 * k, 0.6 * k, 'y')), + ...box(0, 0, 3.3 * k, 1.5 * k, 0.65 * k, 0.3 * k, C.plank, C.plank), + ...post(-1.45 * k, -0.6 * k, 2.2 * k, 0.12 * k), + ...post(1.45 * k, -0.6 * k, 2.2 * k, 0.12 * k), + ...box(0, -0.6 * k, 3.1 * k, 0.12 * k, 2.1 * k, 0.12 * k, C.wood), + ], + x, + y, + ) +} + /** A catapult facing +x before `quarters` turns: a wheeled frame, two uprights with a crossbar, the arm with its bucket raised. */ function catapult(x: number, y: number, k: number, quarters = 0): Face[] { const faces: Face[] = [ @@ -354,13 +376,13 @@ function tent(x: number, y: number, w: number, d: number, h: number, along: 'x' const y1 = y + d / 2 const flap: V3[] = along === 'x' - ? [[x1 + 0.1, y - d * 0.2, 0], [x1 + 0.1, y + d * 0.2, 0], [x1 + 0.1, y, h * 0.62]] - : [[x - w * 0.2, y1 + 0.1, 0], [x + w * 0.2, y1 + 0.1, 0], [x, y1 + 0.1, h * 0.62]] + ? [[x1 + 0.1, y - d * 0.27, 0], [x1 + 0.1, y + d * 0.27, 0], [x1 + 0.1, y, h * 0.7]] + : [[x - w * 0.27, y1 + 0.1, 0], [x + w * 0.27, y1 + 0.1, 0], [x, y1 + 0.1, h * 0.7]] const depth = (along === 'x' ? x1 + y : x + y1) + h / 3 + 0.2 return [ ...gable(x - w / 2, y - d / 2, x1, y1, 0, h, along, color, scale(color, 0.9)), { pts: flap, color: door ? DOOR : C.dark, twoSided: true, flat: true, depth }, - ...(along === 'x' ? post(x1, y, h * 1.12, w * 0.02) : post(x, y1, h * 1.12, d * 0.02)), + ...shift(along === 'x' ? post(x1, y, h * 0.2, w * 0.02) : post(x, y1, h * 0.2, d * 0.02), 0, 0, h * 0.94), ] } @@ -772,9 +794,9 @@ const models: Record Model> = { faces: [ ...tent(-s * 0.3, -s * 0.4, s * 0.95, s * 0.7, s * 0.62, 'x', C.canvas, true), ...tent(-s * 0.6, s * 0.42, s * 0.75, s * 0.55, s * 0.5, 'x', C.canvasDark), - ...weaponRack(s * 0.5, s * 0.55, s, 'x'), - ...dummy(s * 0.75, -s * 0.05, s), - ...fire(s * 0.15, s * 0.2, s), + ...weaponRack(s * 0.4, s * 0.65, s, 'x'), + ...dummy(s * 0.8, -s * 0.2, s), + ...fire(s * 0.4, s * 0.15, s), ...banner(-s * 0.95, -s * 0.85, s * 1.15, s * 0.45), ], height: s * 1.15, @@ -856,12 +878,11 @@ const models: Record Model> = { const y0 = ey + 0.1 const z0 = h * 0.88 faces.push( - ...slab( + ...over(slab( [[x - 0.26 * k, y0, z0 - 0.75 * k], [x + 0.26 * k, y0, z0 - 0.75 * k], [x + 0.2 * k, y0 + 1.25 * k, z0 - 1.2 * k], [x - 0.2 * k, y0 + 1.25 * k, z0 - 1.2 * k]], [[x - 0.26 * k, y0, z0], [x + 0.26 * k, y0, z0], [x + 0.2 * k, y0 + 1.25 * k, z0 - 0.75 * k], [x - 0.2 * k, y0 + 1.25 * k, z0 - 0.75 * k]], coats[(i + 1) % 3]!, - ).map((f) => ({ ...f, depth: yDepth + 0.3 + k })), - ...pyramid(rect(x, y0 + 0.15 * k, 0.4 * k, 0.2 * k), z0, 0.35 * k, scale(coats[(i + 1) % 3]!, 0.6)).map((f) => ({ ...f, depth: yDepth + 0.4 + k })), + ), yDepth + 0.3), ) } } @@ -882,32 +903,32 @@ const models: Record Model> = { return { faces, height: s * 1.0 } }, - // Where siege engines are made: an open shed with wheels against its back wall and a - // frame on the floor, timbers outside; then a ram under the roof; then a stone hall - // with a catapult in front. + // Where siege engines are made: wheels stand in a row by the door, timbers lie ready. + // An open shed with a wheeled frame in the making first, then a ram ready in front, + // then a stone hall with a ram and a catapult. workshop(s, t) { const shed = (x0: number, y0: number, x1: number, y1: number, h: number, roof: string): Face[] => { - const back = scale(C.plank, 0.9) + const inside = scale(C.plank, 0.55) return [ plane(rect((x0 + x1) / 2, (y0 + y1) / 2, x1 - x0, y1 - y0).map(([x, y]): V3 => [x, y, 0.5]), C.soil), - plane([[x0, y0, 0], [x1, y0, 0], [x1, y0, h], [x0, y0, h]], back), - plane([[x0, y0, 0], [x0, y1, 0], [x0, y1, h], [x0, y0, h]], scale(back, 0.9)), - ...[x0, (x0 + x1) / 2, x1].flatMap((x) => [...post(x, y1, h, s * 0.04), ...post(x, y0, h, s * 0.04)]), - ...post(x1, (y0 + y1) / 2, h, s * 0.04), - ...gable(x0 - s * 0.06, y0 - s * 0.06, x1 + s * 0.06, y1 + s * 0.06, h, s * 0.32, 'x', roof, C.wood), + plane([[x0, y0, 0], [x1, y0, 0], [x1, y0, h], [x0, y0, h]], inside), + plane([[x0, y0, 0], [x0, y1, 0], [x0, y1, h], [x0, y0, h]], scale(inside, 0.9)), + ...[x0, (x0 + x1) / 2, x1].flatMap((x) => [...post(x, y1, h, s * 0.045), ...post(x, y0, h, s * 0.045)]), + ...post(x1, (y0 + y1) / 2, h, s * 0.045), + ...gable(x0 - s * 0.06, y0 - s * 0.06, x1 + s * 0.06, y1 + s * 0.06, h, s * 0.3, 'x', roof, C.wood), ] } - const leaning = (x: number, y: number) => [...wheel(x, y, s * 0.15, 'y'), ...wheel(x + s * 0.26, y, s * 0.15, 'y')] + /** Finished wheels standing in a row along y, faces to the viewer. */ + const wheels = (x: number, y: number, n: number) => Array.from({ length: n }, (_, i) => wheel(x, y + i * s * 0.34, s * 0.17, 'x')).flat() if (t === 1) { return { faces: [ - ...shed(-s * 0.8, -s * 0.8, s * 0.5, s * 0.1, s * 0.55, C.thatch), - ...leaning(-s * 0.55, -s * 0.66), - ...box(-s * 0.1, -s * 0.3, s * 0.5, s * 0.22, s * 0.1, s * 0.06, C.wood, C.plank), - ...wheel(-s * 0.25, -s * 0.15, s * 0.12, 'y'), - ...timbers(-s * 0.2, s * 0.6, s), - ...wheel(s * 0.75, s * 0.25, s * 0.15, 'x'), - ...box(s * 0.8, -s * 0.4, s * 0.4, s * 0.2, 0, s * 0.2, C.wood, C.plank), + ...shed(-s * 0.9, -s * 0.9, s * 0.2, -s * 0.15, s * 0.62, C.thatch), + ...wheel(-s * 0.55, -s * 0.78, s * 0.2, 'y'), + ...wheel(-s * 0.15, -s * 0.78, s * 0.2, 'y'), + ...frame(s * 0.05, s * 0.35, s * 0.15), + ...wheels(s * 0.75, -s * 0.6, 2), + ...timbers(-s * 0.5, s * 0.6, s), ], height: s * 0.95, } @@ -915,28 +936,25 @@ const models: Record Model> = { if (t === 2) { return { faces: [ - ...house(-s * 0.95, -s * 0.85, s * 0.5, s * 0.5, s * 0.5, s * 0.25, C.stone, C.slate), - ...box(-s * 0.95, -s * 0.85, s * 0.12, s * 0.12, s * 0.6, s * 0.4, C.stoneDark), - ...shed(-s * 0.65, -s * 0.85, s * 0.75, s * 0.05, s * 0.62, C.shingle), - ...leaning(-s * 0.45, -s * 0.72), - ...leaning(s * 0.15, -s * 0.72), - ...ram(s * 0.05, -s * 0.35, s * 0.11), - ...timbers(-s * 0.3, s * 0.6, s, 3), - ...wheel(s * 0.75, s * 0.45, s * 0.15, 'x'), - ...wheel(s * 0.75, s * 0.2, s * 0.15, 'x'), + ...shed(-s * 0.95, -s * 0.95, s * 0.35, -s * 0.15, s * 0.68, C.shingle), + ...wheel(-s * 0.65, -s * 0.83, s * 0.2, 'y'), + ...wheel(-s * 0.25, -s * 0.83, s * 0.2, 'y'), + ...frame(-s * 0.3, -s * 0.45, s * 0.13), + ...ram(s * 0.05, s * 0.4, s * 0.16), + ...wheels(s * 0.8, -s * 0.75, 3), + ...timbers(-s * 0.65, s * 0.55, s, 3), ], height: s * 1.05, } } return { faces: [ - ...house(-s * 0.35, -s * 0.6, s * 1.3, s * 0.75, s * 0.65, s * 0.4, C.stone, C.slate), + ...house(-s * 0.3, -s * 0.62, s * 1.35, s * 0.72, s * 0.62, s * 0.42, C.stone, C.slate), ...box(-s * 0.85, -s * 0.85, s * 0.14, s * 0.14, s * 0.75, s * 0.5, C.stoneDark), - ...ram(-s * 0.45, s * 0.3, s * 0.11), - ...catapult(s * 0.55, s * 0.15, s * 0.12), - ...timbers(s * 0.05, s * 0.85, s, 3), - ...wheel(s * 0.75, -s * 0.55, s * 0.15, 'x'), - ...wheel(s * 0.75, -s * 0.3, s * 0.15, 'x'), + ...ram(-s * 0.45, s * 0.42, s * 0.15), + ...catapult(s * 0.62, s * 0.25, s * 0.15), + ...wheels(s * 0.85, -s * 0.85, 2), + ...timbers(-s * 0.1, s * 0.92, s, 2), ], height: s * 1.2, }