// The skyline's signatures: the Ferry Building and its clock, the pier sheds with their numbers, // Coit Tower on Telegraph Hill, the pyramid, ChadAI's tower with its violet crown, the labs' // billboards, the Bay Bridge, and the barriers where the ride ends for now. import * as THREE from "three"; import { BRIDGE, CITY, CURB, FERRY, PIERS, QUAY, RIDE, heightAt, surfaceAt } from "../city.js"; import { BRIDGE_ORANGE, CHADAI, CLAMCODE, STEEL, WHITE_TRIM } from "../palette.js"; import { Builder, STYLE, buildingMaterial, standard, textTexture, vertexColored, windowAttributes } from "./kit.js"; const STONE = 0xe6dccb; const SHED = 0xd5d8c6; const SHED_TRIM = 0xf0ece0; const ROOF = 0x7d847c; const CONCRETE = 0xc9c2b6; function windowed(geometry, color, win, box, style = STYLE.plain) { windowAttributes(geometry, win, box, style); const mat = buildingMaterial(); mat.color.set(color); const m = new THREE.Mesh(geometry, mat); m.castShadow = true; m.receiveShadow = true; return m; } function boxGeo(x0, y0, z0, x1, y1, z1) { const g = new THREE.BoxGeometry(x1 - x0, y1 - y0, z1 - z0); g.translate((x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2); return g; } /** A gable roof along x (ridge along x) or along z, as triangles into a builder. */ function gable(b, x0, x1, z0, z1, y, rise, along, color) { if (along === "x") { const zm = (z0 + z1) / 2; b.quad([x0, y, z1], [x1, y, z1], [x1, y + rise, zm], [x0, y + rise, zm], color); b.quad([x1, y, z0], [x0, y, z0], [x0, y + rise, zm], [x1, y + rise, zm], color); b.tri([x0, y, z0], [x0, y, z1], [x0, y + rise, zm], color); b.tri([x1, y, z1], [x1, y, z0], [x1, y + rise, zm], color); } else { const xm = (x0 + x1) / 2; b.quad([x0, y, z0], [x0, y, z1], [xm, y + rise, z1], [xm, y + rise, z0], color); b.quad([x1, y, z1], [x1, y, z0], [xm, y + rise, z0], [xm, y + rise, z1], color); b.tri([x0, y, z1], [x1, y, z1], [xm, y + rise, z1], color); b.tri([x1, y, z0], [x0, y, z0], [xm, y + rise, z0], color); } } function signTexture(lines, o) { return textTexture(o.w ?? 1024, o.h ?? 256, (ctx, w, h) => { ctx.fillStyle = o.bg; ctx.fillRect(0, 0, w, h); if (o.border) { ctx.strokeStyle = o.border; ctx.lineWidth = h * 0.05; ctx.strokeRect(h * 0.04, h * 0.04, w - h * 0.08, h - h * 0.08); } ctx.fillStyle = o.fg; ctx.textAlign = "center"; ctx.textBaseline = "middle"; const [big, small] = lines; let size = h * (small ? 0.36 : 0.56); ctx.font = `800 ${size}px "Helvetica Neue", Helvetica, Arial, sans-serif`; while (ctx.measureText(big).width > w * 0.9) { size *= 0.92; ctx.font = `800 ${size}px "Helvetica Neue", Helvetica, Arial, sans-serif`; } ctx.fillText(big, w / 2, small ? h * 0.4 : h * 0.52); if (small) { ctx.globalAlpha = 0.92; ctx.font = `700 ${h * 0.2}px "Helvetica Neue", Helvetica, Arial, sans-serif`; ctx.fillText(small, w / 2, h * 0.76); } }); } /** A flat convex shape (fan-triangulated) turned so its normal points along (nx, 0, nz). */ function panel(b, pts, nx, nz, color) { for (let k = 1; k + 1 < pts.length; k++) { const a = pts[0]; const c = pts[k]; const d = pts[k + 1]; const ux = c[0] - a[0], uy = c[1] - a[1], uz = c[2] - a[2]; const vx = d[0] - a[0], vy = d[1] - a[1], vz = d[2] - a[2]; const cx = uy * vz - uz * vy; const cz = ux * vy - uy * vx; if (cx * nx + cz * nz >= 0) b.tri(a, c, d, color); else b.tri(a, d, c, color); } } /** An arched opening on a wall facing ±x at `x`: centered at z, `w` wide, from y0 up to the * springline ys, then a half circle. */ function archX(b, x, side, z, w, y0, ys, color) { const pts = [[x, y0, z - w / 2], [x, y0, z + w / 2], [x, ys, z + w / 2]]; for (let k = 1; k < 8; k++) { const a = (k / 8) * Math.PI; pts.push([x, ys + Math.sin(a) * (w / 2), z + Math.cos(a) * (w / 2)]); } pts.push([x, ys, z - w / 2]); panel(b, pts, side, 0, color); } function ferryBuilding(group) { const f = FERRY; const b = new Builder(); const DARK = 0x37342f; const PANE = 0x55606b; const y1 = QUAY + 6.8; const y2 = QUAY + 12.6; b.box(f.x0, QUAY - 1, f.z0, f.x1, y2, f.z1, STONE); b.box(f.x0 - 0.35, QUAY - 1, f.z0 - 0.35, f.x1 + 0.35, QUAY + 0.6, f.z1 + 0.35, 0xd6cbb6); b.box(f.x0 - 0.45, y1 - 0.35, f.z0 - 0.45, f.x1 + 0.45, y1 + 0.35, f.z1 + 0.45, WHITE_TRIM); b.box(f.x0 - 0.7, y2, f.z0 - 0.7, f.x1 + 0.7, y2 + 1.0, f.z1 + 0.7, WHITE_TRIM); // the arcade and the arched windows above it, on the street side and the bay side for (const side of [-1, 1]) { const x = side < 0 ? f.x0 - 0.03 : f.x1 + 0.03; for (let z = f.z0 + 4.5; z < f.z1 - 4; z += 6.2) { const zc = z + 3.1; if (Math.abs(zc - f.tower.z) < 9) continue; archX(b, x, side, zc, 3.7, QUAY + 0.6, QUAY + 4.3, DARK); archX(b, x + side * 0.01, side, zc, 2.3, QUAY + 7.7, QUAY + 10.3, PANE); const px = side < 0 ? f.x0 - 0.35 : f.x1; b.box(px, QUAY + 0.6, z - 0.45, px + 0.35, y2, z + 0.45, 0xefe7d8); } } // the grand entry under the tower archX(b, f.x0 - 0.04, -1, f.tower.z, 8, QUAY + 0.6, QUAY + 6, DARK); // the ends for (const [z, s] of [[f.z0 - 0.03, -1], [f.z1 + 0.03, 1]]) for (let x = f.x0 + 5; x < f.x1 - 3; x += 7) { const pts = [[x, QUAY + 0.6, z], [x + 3.4, QUAY + 0.6, z], [x + 3.4, QUAY + 4.6, z], [x + 1.7, QUAY + 6, z], [x, QUAY + 4.6, z]]; panel(b, pts, 0, s, DARK); } // the roof: a long gable with a skylight spine gable(b, f.x0 + 0.5, f.x1 - 0.5, f.z0 + 0.5, f.z1 - 0.5, y2 + 1.0, 4.2, "z", ROOF); b.box((f.x0 + f.x1) / 2 - 2.2, y2 + 4.2, f.z0 + 8, (f.x0 + f.x1) / 2 + 2.2, y2 + 6.2, f.z1 - 8, 0xa9b4b4, 0x8fa0a4); // The clock tower. const { x, z } = f.tower; const y0 = QUAY; const shaft = windowed(boxGeo(x - 7, y0, z - 7, x + 7, y0 + 46, z + 7), STONE, [7.5, 3.4, 0.32, 0.55], [y0, y0 + 46, 14, 0.71], STYLE.stone); group.add(shaft); b.box(x - 7.6, y0 + 44, z - 7.6, x + 7.6, y0 + 46.5, z + 7.6, WHITE_TRIM); b.box(x - 5.6, y0 + 46.5, z - 5.6, x + 5.6, y0 + 56, z + 5.6, STONE); for (const [dx, dz] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) { for (let k = -1; k <= 1; k++) { const cx = x + dx * 5.65 + (dz !== 0 ? k * 3.2 : 0); const cz = z + dz * 5.65 + (dx !== 0 ? k * 3.2 : 0); const w = 0.9; b.box(cx - (dx === 0 ? w : 0.08), y0 + 48, cz - (dz === 0 ? w : 0.08), cx + (dx === 0 ? w : 0.08), y0 + 53.5, cz + (dz === 0 ? w : 0.08), 0x3d3a36); } } b.box(x - 6.2, y0 + 56, z - 6.2, x + 6.2, y0 + 57.2, z + 6.2, WHITE_TRIM); b.box(x - 4.2, y0 + 57.2, z - 4.2, x + 4.2, y0 + 63, z + 4.2, STONE); b.box(x - 4.8, y0 + 63, z - 4.8, x + 4.8, y0 + 64, z + 4.8, WHITE_TRIM); const apex = [x, y0 + 72, z]; const c = [[x - 4.2, y0 + 64, z - 4.2], [x + 4.2, y0 + 64, z - 4.2], [x + 4.2, y0 + 64, z + 4.2], [x - 4.2, y0 + 64, z + 4.2]]; for (let k = 0; k < 4; k++) b.tri(c[(k + 1) % 4], c[k], apex, 0x9aa39a); b.box(x - 0.12, y0 + 72, z - 0.12, x + 0.12, y0 + 77, z + 0.12, 0xdddddd); const mesh = new THREE.Mesh(b.geometry(), vertexColored()); mesh.castShadow = true; mesh.receiveShadow = true; group.add(mesh); // Clock faces, reading 6:47: the sun is just up. const face = textTexture(256, 256, (ctx, w) => { ctx.fillStyle = "#f7f3e8"; ctx.beginPath(); ctx.arc(w / 2, w / 2, w * 0.48, 0, Math.PI * 2); ctx.fill(); ctx.strokeStyle = "#2c2a26"; ctx.lineWidth = 8; ctx.stroke(); for (let k = 0; k < 12; k++) { const a = (k / 12) * Math.PI * 2; ctx.fillStyle = "#2c2a26"; ctx.fillRect(w / 2 + Math.sin(a) * w * 0.4 - 4, w / 2 - Math.cos(a) * w * 0.4 - 4, 8, 8); } const hand = (a, len, width) => { ctx.lineWidth = width; ctx.lineCap = "round"; ctx.beginPath(); ctx.moveTo(w / 2, w / 2); ctx.lineTo(w / 2 + Math.sin(a) * len, w / 2 - Math.cos(a) * len); ctx.stroke(); }; hand(((6 + 47 / 60) / 12) * Math.PI * 2, w * 0.24, 12); hand((47 / 60) * Math.PI * 2, w * 0.36, 8); }); const faceMat = new THREE.MeshStandardMaterial({ map: face, transparent: true, roughness: 0.6, emissive: 0xffffff, emissiveMap: face, emissiveIntensity: 0.15 }); for (const [dx, dz, ry] of [[1, 0, Math.PI / 2], [-1, 0, -Math.PI / 2], [0, 1, 0], [0, -1, Math.PI]]) { const m = new THREE.Mesh(new THREE.CircleGeometry(3.3, 40), faceMat); m.position.set(x + dx * 7.05, y0 + 39, z + dz * 7.05); m.rotation.y = ry; group.add(m); } } function piers(group) { const b = new Builder(); const shedMat = buildingMaterial(); const sheds = []; for (const p of PIERS) { const y = QUAY + CURB; if (p.kind === "shed") { const s = p.shed; const g = boxGeo(s.x0, y - 0.2, s.z0, s.x1, y + 10.5, s.z1); windowAttributes(g, [5.2, 4.2, 0.72, 0.34], [y, y + 10.5, 6.5, 0.4]); sheds.push(g); gable(b, s.x0, s.x1, s.z0 - 0.3, s.z1 + 0.3, y + 10.5, 3.2, "x", ROOF); // the head house facing the Embarcadero, with its pediment and number const hx0 = s.x0 - 0.6; const hx1 = s.x0 + 7; const g2 = boxGeo(hx0, y - 0.2, s.z0 - 0.6, hx1, y + 15, s.z1 + 0.6); windowAttributes(g2, [5, 3.6, 0.5, 0.6], [y, y + 15, 7, 2.6]); sheds.push(g2); const zm = (s.z0 + s.z1) / 2; const half = (s.z1 - s.z0) / 2 + 0.6; b.tri([hx0, y + 15, zm + half], [hx0, y + 15, zm - half], [hx0, y + 19.5, zm], SHED_TRIM); b.tri([hx1, y + 15, zm - half], [hx1, y + 15, zm + half], [hx1, y + 19.5, zm], SHED_TRIM); b.quad([hx0, y + 15, zm - half], [hx1, y + 15, zm - half], [hx1, y + 19.5, zm], [hx0, y + 19.5, zm], ROOF); b.quad([hx1, y + 15, zm + half], [hx0, y + 15, zm + half], [hx0, y + 19.5, zm], [hx1, y + 19.5, zm], ROOF); b.box(hx0 - 0.3, y + 14.6, s.z0 - 0.9, hx1 + 0.3, y + 15.2, s.z1 + 0.9, SHED_TRIM); const sign = new THREE.Mesh(new THREE.PlaneGeometry(Math.min(16, (s.z1 - s.z0) * 0.7), 2.6), new THREE.MeshStandardMaterial({ map: signTexture([p.name.toUpperCase()], { bg: "#f2eee3", fg: "#3b3f3a", w: 1024, h: 168 }), roughness: 0.7 })); sign.position.set(hx0 - 0.05, y + 12.2, zm); sign.rotation.y = -Math.PI / 2; group.add(sign); } else if (p.kind === "fireboat") { const s = p.shed; b.box(s.x0, y, s.z0, s.x1, y + 7, s.z1, 0xece6da); gable(b, s.x0 - 0.5, s.x1 + 0.5, s.z0 - 0.5, s.z1 + 0.5, y + 7, 2.4, "x", 0xa7472f); b.box(s.x0 + 3, y + 7, s.z0 + 2, s.x0 + 6, y + 12, s.z0 + 5, 0xece6da); } else { // a public pier: railings and lamps for (const zr of [p.deck.z0 + 0.15, p.deck.z1 - 0.15]) { b.box(1, y + 1.0, zr - 0.06, p.len - 0.5, y + 1.12, zr + 0.06, 0x3f4a48); for (let x = 2; x < p.len; x += 3) b.box(x - 0.05, y, zr - 0.05, x + 0.05, y + 1.05, zr + 0.05, 0x3f4a48); } b.box(p.len - 0.3, y + 1.0, p.deck.z0, p.len - 0.18, y + 1.12, p.deck.z1, 0x3f4a48); for (let x = 12; x < p.len; x += 24) for (const zr of [p.deck.z0 + 0.5, p.deck.z1 - 0.5]) { b.box(x - 0.08, y, zr - 0.08, x + 0.08, y + 4.2, zr + 0.08, 0x37403d); b.box(x - 0.25, y + 4.2, zr - 0.25, x + 0.25, y + 4.7, zr + 0.25, 0xfff1cf); } } } shedMat.color.set(SHED); for (const g of sheds) { const m = new THREE.Mesh(g, shedMat); m.castShadow = true; m.receiveShadow = true; group.add(m); } const mesh = new THREE.Mesh(b.geometry(), vertexColored()); mesh.castShadow = true; mesh.receiveShadow = true; group.add(mesh); } function coitTower(group) { const { x, z, y } = CITY.coit; const pts = []; const n = 20; const g = new THREE.CylinderGeometry(4.7, 5.1, 58, n * 2, 1, false); const pos = g.attributes.position; for (let i = 0; i < pos.count; i++) { const a = Math.atan2(pos.getZ(i), pos.getX(i)); const k = Math.round((a / (Math.PI * 2)) * n * 2); const s = k % 2 === 0 ? 1 : 0.93; pos.setX(i, pos.getX(i) * s); pos.setZ(i, pos.getZ(i) * s); } g.computeVertexNormals(); g.translate(x, y + 29 + 6, z); const shaft = windowed(g, 0xf1ece0, [5.5, 1.9, 0.22, 0.3], [y + 6, y + 64, 2, 0.13]); group.add(shaft); const b = new Builder(); // the base reaches well down into the mound, which falls away from it down the hill b.box(x - 9, y - 6, z - 9, x + 9, y + 6, z + 9, 0xeae3d4); b.box(x - 9.6, y + 5.6, z - 9.6, x + 9.6, y + 6.4, z + 9.6, WHITE_TRIM); const crown = new THREE.CylinderGeometry(5.4, 5.1, 5, 24, 1, true); crown.translate(x, y + 6 + 58 + 2.5, z); const cm = new THREE.Mesh(crown, standard(0xf3eee3)); cm.castShadow = true; group.add(cm); for (let k = 0; k < 12; k++) { const a = (k / 12) * Math.PI * 2; const cx = x + Math.cos(a) * 5.45; const cz = z + Math.sin(a) * 5.45; b.box(cx - 0.55, y + 65, cz - 0.55, cx + 0.55, y + 68.2, cz + 0.55, 0x3a3936); } const top = new THREE.CylinderGeometry(4.4, 5.6, 1.2, 24); top.translate(x, y + 6 + 58 + 5.6, z); group.add(new THREE.Mesh(top, standard(0xf3eee3))); const mesh = new THREE.Mesh(b.geometry(), vertexColored()); mesh.castShadow = true; mesh.receiveShadow = true; group.add(mesh); } function pyramid(group) { const p = CITY.pyramid; const h = p.height * 0.83; const g = new THREE.ConeGeometry(p.base / Math.SQRT2, h, 4, 1, false); g.rotateY(Math.PI / 4); g.translate(p.x, p.y + h / 2, p.z); group.add(windowed(g.toNonIndexed(), 0xeeebe4, [3.7, 1.7, 0.42, 0.62], [p.y, p.y + h, 6, 2.31])); const spire = new THREE.ConeGeometry(2.2, p.height - h + 6, 4); spire.rotateY(Math.PI / 4); spire.translate(p.x, p.y + h - 3 + (p.height - h + 6) / 2, p.z); const sm = new THREE.Mesh(spire, standard(0xf2f0ea, { roughness: 0.5 })); sm.castShadow = true; group.add(sm); // a plinth under it, down to the lowest ground beneath: the block slopes, and the tower // stands level, so without it the downhill side would hang in the air const half = p.base / 2; let low = p.y; for (let k = 0; k <= 8; k++) for (const [u, v] of [[k / 4 - 1, -1], [k / 4 - 1, 1], [-1, k / 4 - 1], [1, k / 4 - 1]]) low = Math.min(low, heightAt(p.x + u * half, p.z + v * half) + CURB); if (low < p.y - 0.05) { const plinth = new THREE.Mesh(new THREE.BoxGeometry(p.base, p.y - low + 1, p.base), standard(0xd9d4ca, { roughness: 0.8 })); plinth.position.set(p.x, (p.y + low - 1) / 2 + 0.01, p.z); plinth.castShadow = plinth.receiveShadow = true; group.add(plinth); } // the wings, east and west for (const s of [-1, 1]) { const wg = new THREE.ConeGeometry(6.5, h * 0.72, 4, 1, false); wg.rotateY(Math.PI / 4); wg.scale(0.6, 1, 1); wg.translate(p.x + s * (p.base / 2 - 4), p.y + (h * 0.72) / 2, p.z); const m = new THREE.Mesh(wg, standard(0xe6e2da)); m.castShadow = true; group.add(m); } } function chadaiTower(group) { const t = CITY.chadai; const H = t.height; const rings = 26; const around = 28; const half = t.w / 2; const shape = (u) => { // half-width at height fraction u: a gentle taper, then a rounded top const taper = 1 - 0.22 * u; const top = u > 0.86 ? Math.sqrt(Math.max(0, 1 - ((u - 0.86) / 0.14) ** 2)) : 1; return half * taper * (0.25 + 0.75 * top); }; const pos = []; const ys = []; for (let r = 0; r <= rings; r++) ys.push(r / rings); const ring = (u) => { const s = shape(u); const out = []; for (let k = 0; k < around; k++) { const a = (k / around) * Math.PI * 2; const c = Math.cos(a); const sn = Math.sin(a); const e = 4; // superellipse: rounded square const rx = Math.sign(c) * Math.abs(c) ** (2 / e); const rz = Math.sign(sn) * Math.abs(sn) ** (2 / e); out.push([t.x + rx * s, t.y + u * H, t.z + rz * s]); } return out; }; const b = new Builder(); for (let r = 0; r < rings; r++) { const A = ring(ys[r]); const B = ring(ys[r + 1]); for (let k = 0; k < around; k++) { const k2 = (k + 1) % around; b.quad(A[k], A[k2], B[k2], B[k], 0xffffff); } } const capRing = ring(1); for (let k = 0; k < around; k++) b.tri(capRing[k], capRing[(k + 1) % around], [t.x, t.y + H + 2, t.z], 0xffffff); const geo = b.geometry(); geo.deleteAttribute("color"); group.add(windowed(geo, 0xc9d2db, [4.1, 1.45, 0.8, 0.78], [t.y, t.y + H * 0.83, 8, 2.57], STYLE.glass)); // The crown: a violet lattice lit from inside. const crown = new Builder(); const c0 = ring(0.83); const c1 = ring(0.97); for (let k = 0; k < around; k++) { const k2 = (k + 1) % around; const grow = (p) => [t.x + (p[0] - t.x) * 1.035, p[1], t.z + (p[2] - t.z) * 1.035]; crown.quad(grow(c0[k]), grow(c0[k2]), grow(c1[k2]), grow(c1[k]), CHADAI); } const glow = new THREE.Mesh(crown.geometry(), new THREE.MeshBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.55, side: THREE.DoubleSide, depthWrite: false, fog: true })); group.add(glow); // The name, on all four sides. const tex = textTexture(1024, 256, (ctx, w, h) => { ctx.clearRect(0, 0, w, h); ctx.fillStyle = "#ffffff"; ctx.textAlign = "center"; ctx.textBaseline = "middle"; ctx.font = `800 ${h * 0.62}px "Helvetica Neue", Helvetica, Arial, sans-serif`; ctx.fillText("ChadAI", w / 2, h * 0.54); }); const nameMat = new THREE.MeshBasicMaterial({ map: tex, transparent: true, color: 0xe9ddff, depthWrite: false, fog: true }); const yName = t.y + H * 0.76; const s = shape(0.76) + 0.6; for (const [dx, dz, ry] of [[1, 0, Math.PI / 2], [-1, 0, -Math.PI / 2], [0, 1, 0], [0, -1, Math.PI]]) { const m = new THREE.Mesh(new THREE.PlaneGeometry(s * 1.6, s * 0.4), nameMat); m.position.set(t.x + dx * s, yName, t.z + dz * s); m.rotation.y = ry; group.add(m); } } function billboards(group) { for (const bb of CITY.billboards) { const chad = bb.lab === "chadai"; const tex = signTexture(bb.lines, chad ? { bg: "#8b5cf6", fg: "#ffffff", w: 1024, h: 384 } : { bg: "#ff8a6b", fg: "#2a211e", w: 1024, h: 384 }); const mat = new THREE.MeshStandardMaterial({ map: tex, roughness: 0.6, emissive: 0xffffff, emissiveMap: tex, emissiveIntensity: 0.32 }); const panel = new THREE.Mesh(new THREE.PlaneGeometry(bb.w, bb.h), mat); const g = new THREE.Group(); g.position.set(bb.x, bb.y, bb.z); g.rotation.y = Math.PI - bb.facing; panel.position.set(0, 2.2 + bb.h / 2, 0.12); g.add(panel); const back = new THREE.Mesh(new THREE.BoxGeometry(bb.w + 0.5, bb.h + 0.5, 0.2), standard(0x3a3d42)); back.position.set(0, 2.2 + bb.h / 2, 0); back.castShadow = true; g.add(back); for (const sx of [-0.3, 0.3]) { const post = new THREE.Mesh(new THREE.BoxGeometry(0.35, 2.4, 0.35), standard(0x4a4d52)); post.position.set(sx * bb.w, 1.2, -0.3); g.add(post); } group.add(g); } // ClamCode's own building, far down in Mission Bay. const c = CITY.clamcode; const tex = signTexture(["ClamCode"], { bg: "rgba(0,0,0,0)", fg: "#ffd4c6", w: 1024, h: 256 }); const sign = new THREE.Mesh(new THREE.PlaneGeometry(40, 10), new THREE.MeshBasicMaterial({ map: tex, transparent: true, fog: true })); sign.position.set(c.x, c.y + 52, c.z - 30); sign.rotation.y = Math.PI; group.add(sign); } function bayBridge(group) { const B = BRIDGE; const steel = standard(STEEL, { roughness: 0.55, metalness: 0.35 }); const concrete = standard(CONCRETE); const b = new Builder(); const w = B.width / 2; const nx = -B.dz; // across the deck const nz = B.dx; const P = (s, off, y) => [B.ax + B.dx * s + nx * off, y, B.az + B.dz * s + nz * off]; // the deck: a double-deck truss as a hollow box, sampled along the line for (let s = B.start; s < B.island; s += 20) { const s2 = Math.min(B.island, s + 20); const y1 = B.deckY(s); const y2 = B.deckY(s2); const depth = 8; b.quad(P(s, -w, y1), P(s, w, y1), P(s2, w, y2), P(s2, -w, y2), 0x6f7378); b.quad(P(s, w, y1 - depth), P(s, -w, y1 - depth), P(s2, -w, y2 - depth), P(s2, w, y2 - depth), 0x4c5055); b.quad(P(s, -w, y1 - depth), P(s, -w, y1), P(s2, -w, y2), P(s2, -w, y2 - depth), STEEL); b.quad(P(s2, w, y2 - depth), P(s2, w, y2), P(s, w, y1), P(s, w, y1 - depth), STEEL); // the truss: diagonals zig-zagging along each face const sm = (s + s2) / 2; const ym = (y1 + y2) / 2; for (const side of [-w - 0.06, w + 0.06]) { const strut = (p, q) => { const pa = [p[0], p[1] + 0.6, p[2]]; const qa = [q[0], q[1] + 0.6, q[2]]; if (side > 0) b.quad(q, p, pa, qa, 0x7d858d); else b.quad(p, q, qa, pa, 0x7d858d); }; strut(P(s, side, y1 - depth + 0.4), P(sm, side, ym - 1.2)); strut(P(sm, side, ym - 1.2), P(s2, side, y2 - depth + 0.4)); } } // land approach: concrete bents, stepped off any street they would land in for (let s = -40; s > B.start; s -= 55) { let sp = s; for (let k = 0; k < 5; k++) { const [x, , z] = P(sp, 0, 0); const ground = x > 0 ? "water" : surfaceAt(x, z); if (ground !== "road" && ground !== "walk") break; sp -= 12; } const top = B.deckY(sp) - 8; for (const off of [-w + 2.5, w - 2.5]) { const [x, , z] = P(sp, off, 0); const base = x > 0 ? -1 : heightAt(x, z); b.box(x - 1.4, base, z - 1.4, x + 1.4, top, z + 1.4, CONCRETE); } const [x0, , z0] = P(sp, -w, 0); const [x1, , z1] = P(sp, w, 0); b.quad([x0, top - 2.2, z0], [x1, top - 2.2, z1], [x1, top, z1], [x0, top, z0], CONCRETE); b.quad([x1, top - 2.2, z1], [x0, top - 2.2, z0], [x0, top, z0], [x1, top, z1], CONCRETE); } // anchorages const anchor = (s, top, len, wid, color) => { const corners = [P(s - len / 2, -wid, 0), P(s + len / 2, -wid, 0), P(s + len / 2, wid, 0), P(s - len / 2, wid, 0)]; const lo = -2; for (let k = 0; k < 4; k++) { const a = corners[k]; const c = corners[(k + 1) % 4]; b.quad([a[0], lo, a[2]], [c[0], lo, c[2]], [c[0], top, c[2]], [a[0], top, a[2]], color); } b.quad([corners[0][0], top, corners[0][2]], [corners[3][0], top, corners[3][2]], [corners[2][0], top, corners[2][2]], [corners[1][0], top, corners[1][2]], color); }; anchor(0, 56, 36, 22, CONCRETE); anchor(B.center, 72, 60, 26, CONCRETE); // towers: two legs with X bracing const towerAt = (s, base, top) => { for (const off of [-w + 1, w - 1]) { const [x, , z] = P(s, off, 0); b.box(x - 2.2, base, z - 2.2, x + 2.2, top, z + 2.2, STEEL); } const levels = 6; for (let k = 0; k < levels; k++) { const ya = base + ((top - base) * k) / levels + 4; const yb = base + ((top - base) * (k + 1)) / levels; const L = P(s, -w + 1, 0); const R = P(s, w - 1, 0); const brace = (p, q, y1, y2) => { const t = 0.7; b.quad([p[0] - B.dx * t, y1, p[2] - B.dz * t], [q[0] - B.dx * t, y2, q[2] - B.dz * t], [q[0] - B.dx * t, y2 + 1.4, q[2] - B.dz * t], [p[0] - B.dx * t, y1 + 1.4, p[2] - B.dz * t], STEEL); b.quad([q[0] + B.dx * t, y2, q[2] + B.dz * t], [p[0] + B.dx * t, y1, p[2] + B.dz * t], [p[0] + B.dx * t, y1 + 1.4, p[2] + B.dz * t], [q[0] + B.dx * t, y2 + 1.4, q[2] + B.dz * t], STEEL); }; brace(L, R, ya, yb - 1.4); brace(R, L, ya, yb - 1.4); } const L = P(s, -w - 1.5, top); const R = P(s, w + 1.5, top); b.quad([L[0] - B.dx * 2.4, top, L[2] - B.dz * 2.4], [R[0] - B.dx * 2.4, top, R[2] - B.dz * 2.4], [R[0] - B.dx * 2.4, top + 3, R[2] - B.dz * 2.4], [L[0] - B.dx * 2.4, top + 3, L[2] - B.dz * 2.4], STEEL); b.quad([R[0] + B.dx * 2.4, top, R[2] + B.dz * 2.4], [L[0] + B.dx * 2.4, top, L[2] + B.dz * 2.4], [L[0] + B.dx * 2.4, top + 3, L[2] + B.dz * 2.4], [R[0] + B.dx * 2.4, top + 3, R[2] + B.dz * 2.4], STEEL); // pier in the water const [cx, , cz] = P(s, 0, 0); b.box(cx - 8, -2, cz - 8, cx + 8, 8, cz + 8, CONCRETE); }; for (const s of B.towers) towerAt(s, 8, B.towerTop); towerAt(B.center, 72, 150); const mesh = new THREE.Mesh(b.geometry(), vertexColored({ roughness: 0.6 })); mesh.castShadow = true; mesh.receiveShadow = true; group.add(mesh); void steel; void concrete; // Main cables and suspenders as lines: hair-thin at any distance, like the real thing. const supports = [ [0, 56], [B.towers[0], B.towerTop + 1], [B.towers[1], B.towerTop + 1], [B.center, 150], [B.towers[2], B.towerTop + 1], [B.towers[3], B.towerTop + 1], [B.island, 60], ]; const cablePts = []; const hangers = []; for (const off of [-w + 1, w - 1]) { for (let k = 0; k + 1 < supports.length; k++) { const [sa, ya] = supports[k]; const [sb, yb] = supports[k + 1]; const main = yb > 100 && ya > 100; const sag = main ? B.deckY((sa + sb) / 2) + 6 : Math.min(ya, yb) - 14; const steps = 40; let prev = null; for (let i = 0; i <= steps; i++) { const u = i / steps; const s = sa + (sb - sa) * u; const chord = ya + (yb - ya) * u; const mid = (ya + yb) / 2; const y = main ? chord - (mid - sag) * 4 * u * (1 - u) : chord - (mid - sag) * 4 * u * (1 - u) * 0.6; const p = P(s, off, y); if (prev) cablePts.push(...prev, ...p); prev = p; if (i % 2 === 0 && i > 0 && i < steps && y > B.deckY(s) + 1) { hangers.push(...p, ...P(s, off, B.deckY(s))); } } } } const cg = new THREE.BufferGeometry(); cg.setAttribute("position", new THREE.Float32BufferAttribute(cablePts, 3)); group.add(new THREE.LineSegments(cg, new THREE.LineBasicMaterial({ color: 0x8e979f }))); const hg = new THREE.BufferGeometry(); hg.setAttribute("position", new THREE.Float32BufferAttribute(hangers, 3)); group.add(new THREE.LineSegments(hg, new THREE.LineBasicMaterial({ color: 0x9ba3aa, transparent: true, opacity: 0.7 }))); } function barriers(group) { const b = new Builder(); const stripes = textTexture(512, 64, (ctx, w, h) => { for (let k = 0; k < 16; k++) { ctx.fillStyle = k % 2 ? "#f4f1ea" : "#c4442f"; ctx.beginPath(); ctx.moveTo(k * 40 - 20, h); ctx.lineTo(k * 40 + 20, 0); ctx.lineTo(k * 40 + 60, 0); ctx.lineTo(k * 40 + 20, h); ctx.fill(); } }); stripes.wrapS = THREE.RepeatWrapping; const boardMat = new THREE.MeshStandardMaterial({ map: stripes, roughness: 0.7 }); for (const br of CITY.barriers) { const len = Math.hypot(br.x1 - br.x0, br.z1 - br.z0); const along = br.x0 === br.x1 ? "z" : "x"; for (let s = 1.5; s < len - 1; s += 4.2) { const x = along === "x" ? br.x0 + s : br.x0; const z = along === "z" ? br.z0 + s : br.z0; const y = heightAt(x, z); const g = new THREE.Mesh(new THREE.PlaneGeometry(3.4, 0.42), boardMat); g.position.set(x, y + 1.0, z); g.rotation.y = along === "x" ? 0 : Math.PI / 2; group.add(g); const g2 = g.clone(); g2.rotation.y += Math.PI; group.add(g2); for (const d of [-1.5, 1.5]) { const px = along === "x" ? x + d : x; const pz = along === "z" ? z + d : z; b.box(px - 0.05, y, pz - 0.05, px + 0.05, y + 1.25, pz + 0.05, 0x3a3a3a); } // a cone in front const cx = along === "x" ? x + 0.8 : x - 1.2; const cz = along === "z" ? z + 0.8 : z - 1.2; const cone = [[cx - 0.22, y, cz - 0.22], [cx + 0.22, y, cz - 0.22], [cx + 0.22, y, cz + 0.22], [cx - 0.22, y, cz + 0.22]]; for (let k = 0; k < 4; k++) b.tri(cone[k], cone[(k + 1) % 4], [cx, y + 0.75, cz], BRIDGE_ORANGE); } } const mesh = new THREE.Mesh(b.geometry(), vertexColored()); group.add(mesh); } export function buildLandmarks(scene) { const group = new THREE.Group(); ferryBuilding(group); piers(group); coitTower(group); pyramid(group); chadaiTower(group); billboards(group); bayBridge(group); barriers(group); scene.add(group); void RIDE; void CLAMCODE; return group; }