// things: every section of ptr.pet as real rural-station architecture you can walk up to, open, and read. owner: cook import * as THREE from 'three'; import { scene, cam, state, G, COMMON, V, stopZ, stops, onFrame, onPhase } from './world.js'; import { mat, tex } from './look.js'; import { phys } from './phys.js'; import * as dollsMod from './dolls.js'; import { bag, JP } from './kit.js'; import { torii } from './megas.js'; import { GUESTS, BUTTONS, TRANSFERS, PROJECTS, GACHA, ENTRIES, TAGS, BIO, IDENT_DOC, WHISPERS, api, onLive, postWish, postMail, siteHref, } from './data.js'; import { net } from './net.js'; import { blip } from './radio.js'; const FM = 'cookmono', DM = 'cookdoll', U = .0015; const R = V(.89, 0, -.456); const open = (u) => { if (u) window.open(u, '_blank', 'noopener'); }; const pin = (x, y, z) => phys.point(V(x, y, z), { pinned: true }); const getDoll = () => dollsMod.doll || dollsMod.dolls?.[0] || null; const firePulse = (amt = 1) => { if (dollsMod.pulseDoll) dollsMod.pulseDoll(amt, true); else { const d = getDoll(); if (d) { d.pulse = amt; d.flap = 1; } } }; const fireShy = () => { const d = getDoll(); if (d) d.shy = 1; }; function wrap(t, n) { const out = []; String(t).split('\n').forEach((par) => { let l = ''; par.split(' ').forEach((w) => { if (l && (l + ' ' + w).length > n) { out.push(l); l = w; } else l = l ? l + ' ' + w : w; }); out.push(l); }); return out; } function canvasTex(c) { const t = new THREE.CanvasTexture(c); t.magFilter = t.minFilter = THREE.NearestFilter; t.generateMipmaps = false; return t; } function paper(lines, o = {}) { const px = o.px || 30, pad = o.pad ?? 14, lh = 1.28, c = document.createElement('canvas'), x = c.getContext('2d'); const fSpec = `${o.bold ? 'bold ' : ''}${px}px ${FM}, ${JP}`; x.font = fSpec; const txt = (l) => (Array.isArray(l) ? l[0] : l); c.width = Math.ceil(Math.max(o.minW || 0, ...lines.map((l) => x.measureText(txt(l)).width)) + pad * 2); c.height = Math.ceil(lines.length * px * lh + pad * 2); x.fillStyle = '#fff'; x.fillRect(0, 0, c.width, c.height); if (o.border) { x.strokeStyle = '#000'; x.lineWidth = 4; x.strokeRect(3, 3, c.width - 6, c.height - 6); } x.font = fSpec; x.textBaseline = 'top'; lines.forEach((l, i) => { x.fillStyle = Array.isArray(l) ? l[1] : '#000'; x.fillText(txt(l), o.center ? (c.width - x.measureText(txt(l)).width) / 2 : pad, pad + i * px * lh + px * .08); }); if (o.hole) { x.fillStyle = '#000'; x.beginPath(); x.arc(c.width / 2, 10, 5, 0, 7); x.fill(); } return { c, map: canvasTex(c), w: c.width * U * (o.k || 1), h: c.height * U * (o.k || 1) }; } function hang(lines, from, o = {}, h = {}) { const p = paper(lines, o); const s = phys.grabbable(phys.slip(p.w, p.h, { map: p.map, legible: o.legible ?? .90, hangFrom: from, rows: o.rows ?? 2, drop: o.drop, read: o.read, noTear: o.noTear }), h); s._paper = p; return s; } const box = (w, h, d, kind = 'metal') => new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat(kind)); let seed = 5; const rnd = () => (seed = (seed * 16807) % 2147483647) / 2147483647; /* ---- STOP 0 (`carrier` · home & links): Wooden Station Signboard + Enamel Transfer Sign + Post-Mounted Red Mailbox ---- */ export let mailbox = null; function carrier(z) { const st = stops[0]; // 1. Classic Japanese rural wooden station name-signboard (`駅名標`) with bio plate underneath { const c = document.createElement('canvas'); c.width = 520; c.height = 380; const x = c.getContext('2d'); x.fillStyle = '#000'; x.fillRect(0, 0, 520, 380); x.fillStyle = '#fff'; x.fillRect(6, 6, 508, 368); x.fillStyle = '#000'; x.textBaseline = 'top'; x.textAlign = 'center'; x.font = `28px ${DM}`; x.fillText('▖▖▖▖▘▌▌▌▖▘▘', 260, 16); x.font = `bold 96px ${FM}`; x.fillText('dawn', 260, 40); x.fillStyle = '#0f0'; x.fillRect(6, 154, 508, 18); x.fillStyle = '#f00'; x.fillRect(244, 148, 32, 30); x.fillStyle = '#000'; x.font = `bold 24px ${FM}`; x.textAlign = 'left'; x.fillText('< ptr.pet', 22, 182); x.textAlign = 'right'; x.fillText('90008 >', 498, 182); x.textAlign = 'center'; x.font = `20px ${FM}`; x.fillText('it/she · angel · robot · puppy · doll', 260, 214); x.fillRect(22, 246, 476, 2); x.textAlign = 'left'; x.font = `20px ${FM}`; BIO.forEach((ln, i) => x.fillText(ln, 24, 256 + i * 28)); const map = canvasTex(c); const g = new THREE.Group(); g.position.set(.54, 0, z + .82); g.lookAt(st.camAt.x, 0, st.camAt.z); const b = bag(); b.box('ink', .065, 2.24, .065, -.64, 1.12, 0); b.box('ink', .065, 2.24, .065, .64, 1.12, 0); b.box('ink', 1.48, .06, .14, 0, 2.24, 0); b.box('metal', 1.38, .98, .04, 0, 1.66, 0); b.build(g, { ink: mat('ink', { hatch: .25 }), metal: mat('metal', { hatch: .1 }) }); const face = new THREE.Mesh(new THREE.PlaneGeometry(1.32, .94), mat('paper', { map, legible: .92, side: THREE.FrontSide })); face.position.set(0, 1.66, .025); g.add(face); scene.add(g); const card = phys.grabbable(phys.slip(.70, .51, { map, legible: .96, rows: 2, pocket: true, noTear: true }), { onTap: () => { const u = siteHref('about'); if (api.live) location.href = u; else open(u); }, }); const pt = pin(.54, 1.66, z + .82); phys.grabbable({ kind: 'sign', mesh: face, points: [pt], outline: [face], pickPoints: false }, { onTap: () => phys.openCard(card, pt.p), }); } const TRANSFER_ICONS = { BS: { vb: [0, 0, 24, 24], rule: 'nonzero', d: "M12 10.8c-1.087-2.114-4.046-6.053-6.798-7.995C2.566.944 1.561 1.266.902 1.565.139 1.908 0 3.08 0 3.768c0 .69.378 5.65.624 6.479.815 2.736 3.713 3.66 6.383 3.364.136-.02.275-.039.415-.056-.138.022-.276.04-.415.056-3.912.58-7.387 2.005-2.83 7.078 5.013 5.19 6.87-1.113 7.823-4.308.953 3.195 2.05 9.271 7.733 4.308 4.267-4.308 1.172-6.498-2.74-7.078a8.741 8.741 0 0 1-.415-.056c.14.017.279.036.415.056 2.67.297 5.568-.628 6.383-3.364.246-.828.624-5.79.624-6.478 0-.69-.139-1.861-.902-2.206-.659-.298-1.664-.62-4.3 1.24C16.046 4.748 13.087 8.687 12 10.8Z" }, TG: { vb: [0, 0, 32, 32], rule: 'evenodd', d: "M15.0788 2.28032C17.1268 0.00211406 20.6953 -0.671906 23.4196 0.727584C25.4977 1.72302 26.9835 3.8 27.3444 6.0645C29.3219 6.85907 30.9877 8.48006 31.6413 10.5372C32.0782 11.8105 32.0922 13.2131 31.8092 14.5206C31.3035 16.5612 29.8673 18.2986 28.0084 19.2481C28.0129 19.6112 29.2035 22.2301 29.0045 24.2061C28.9609 26.6763 27.3985 29.0172 25.2321 30.1543C23.9679 30.8944 22.4694 30.8808 21.0963 30.8663C20.0561 30.8577 19.2621 30.5546 18.401 30.0274C17.1663 29.3758 16.2235 28.281 15.5495 27.0743C14.4787 28.4068 13.0472 29.2151 11.445 29.6719C10.7627 29.8706 9.56729 30.0724 7.58658 29.3526C4.73221 28.3907 2.65311 25.4114 2.88931 22.376C2.84608 21.1179 3.30358 19.8829 3.95181 18.8213C2.2223 17.8903 0.81231 16.3268 0.272122 14.4102C-0.0560871 13.3608 -0.042258 12.2301 0.0787624 11.1514C0.512215 8.6045 2.41664 6.38944 4.8688 5.59282C5.84756 3.3558 7.98326 1.68746 10.403 1.3477C12.0097 1.1233 13.6731 1.46128 15.0788 2.28032ZM17.779 9.11821C16.3306 10.5997 15.0034 10.5502 13.7213 9.37602C13.4332 9.1121 12.8825 10.9869 10.9528 9.92485C9.84421 10.8565 8.98497 11.7535 8.22329 13.044C7.48328 14.4349 6.70817 15.6702 6.64126 17.1807C6.60915 18.0637 7.29704 18.9888 8.22915 18.917C9.16076 19.0005 9.79525 18.0813 10.5006 17.6993L10.5856 18.6377C10.6828 19.5863 10.8279 20.5568 11.1393 21.459C11.616 23.0157 13.2948 24.0049 14.8834 23.7784C14.9926 23.7698 15.1628 23.7557 15.1725 23.7549C16.9248 23.5592 18.0743 22.0265 18.9665 20.6465C19.3881 20.018 19.7099 19.3145 20.0299 18.6456L20.1833 18.8028C20.5377 19.1984 20.8792 19.7672 21.4538 19.917C22.1452 20.133 22.9561 19.9581 23.3795 19.3282C24.1897 17.8124 23.7908 15.9829 23.319 14.4122C23.0284 13.51 22.6469 12.5839 21.9215 11.9444C22.0761 10.8499 21.4296 9.73796 20.5104 9.16508C19.727 9.79163 18.5348 9.78843 17.779 9.11821ZM16.2057 13.667C16.6784 13.0198 17.8313 13.2694 17.8825 14.0997C17.8486 14.935 17.4658 15.7669 17.5114 16.6329C17.4122 17.3559 17.5832 18.1682 17.2643 18.8291C17.0027 19.1947 16.4701 19.3014 16.0827 19.1065C15.2305 18.5826 15.6402 17.4451 15.6061 16.6192C15.6909 15.6226 15.759 14.575 16.2057 13.667ZM12.443 13.7022C13.1652 13.1972 14.1479 14.0622 13.8063 14.8565C13.4421 15.8602 13.6814 16.9569 13.6891 17.9747C13.5512 18.5751 12.9104 18.8937 12.36 18.6299C11.5577 18.1929 11.812 17.0943 11.6862 16.3301C11.7906 15.4453 11.7044 14.3227 12.443 13.7022Z" }, GH: { vb: [0, 0, 24, 24], rule: 'nonzero', d: "M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" }, IT: { vb: [0, 0, 24, 24], rule: 'nonzero', d: "M3.13 1.338C2.08 1.96.02 4.328 0 4.95v1.03c0 1.303 1.22 2.45 2.325 2.45 1.33 0 2.436-1.102 2.436-2.41 0 1.308 1.07 2.41 2.4 2.41 1.328 0 2.362-1.102 2.362-2.41 0 1.308 1.137 2.41 2.466 2.41h.024c1.33 0 2.466-1.102 2.466-2.41 0 1.308 1.034 2.41 2.363 2.41 1.33 0 2.4-1.102 2.4-2.41 0 1.308 1.106 2.41 2.435 2.41C22.78 8.43 24 7.282 24 5.98V4.95c-.02-.62-2.082-2.99-3.13-3.612-3.253-.114-5.508-.134-8.87-.133-3.362 0-7.945.053-8.87.133zm6.376 6.477a2.74 2.74 0 0 1-.468.602c-.5.49-1.19.795-1.947.795a2.786 2.786 0 0 1-1.95-.795c-.182-.178-.32-.37-.446-.59-.127.222-.303.412-.486.59a2.788 2.788 0 0 1-1.95.795c-.092 0-.187-.025-.264-.052-.107 1.113-.152 2.176-.168 2.95v.005l-.006 1.167c.02 2.334-.23 7.564 1.03 8.85 1.952.454 5.545.662 9.15.663 3.605 0 7.198-.21 9.15-.664 1.26-1.284 1.01-6.514 1.03-8.848l-.006-1.167v-.004c-.016-.775-.06-1.838-.168-2.95-.077.026-.172.052-.263.052a2.788 2.788 0 0 1-1.95-.795c-.184-.178-.36-.368-.486-.59-.127.22-.265.412-.447.59a2.786 2.786 0 0 1-1.95.794c-.76 0-1.446-.303-1.948-.793a2.74 2.74 0 0 1-.468-.602 2.738 2.738 0 0 1-.463.602 2.787 2.787 0 0 1-1.95.794h-.16a2.787 2.787 0 0 1-1.95-.793 2.738 2.738 0 0 1-.464-.602zm-2.004 2.59v.002c.795.002 1.5 0 2.373.953.687-.072 1.406-.108 2.125-.107.72 0 1.438.035 2.125.107.873-.953 1.578-.95 2.372-.953.376 0 1.876 0 2.92 2.934l1.123 4.028c.832 2.995-.266 3.068-1.636 3.07-2.03-.075-3.156-1.55-3.156-3.025-1.124.184-2.436.276-3.748.277-1.312 0-2.624-.093-3.748-.277 0 1.475-1.125 2.95-3.156 3.026-1.37-.004-2.468-.077-1.636-3.072l1.122-4.027c1.045-2.934 2.545-2.934 2.92-2.934zM12 12.714c-.002.002-2.14 1.964-2.523 2.662l1.4-.056v1.22c0 .056.56.033 1.123.007.562.026 1.124.05 1.124-.008v-1.22l1.4.055C14.138 14.677 12 12.713 12 12.713z" }, BT: { vb: [89.6, 18.4, 10.6, 10.6], rule: 'nonzero', d: "M99.1323,22.4912 L99.1323,21.6942 L97.1413,18.5082 L96.4543,18.5082 L95.3673,21.1152 L94.2993,18.8702 L93.7013,18.8692 L91.8913,23.1422 L91.8913,19.0872 L90.6603,19.0872 L90.6603,19.4462 L89.7193,19.4462 L89.7193,20.6952 L90.6603,20.6952 L90.6603,24.3012 C90.6603,24.6212 90.9203,24.8802 91.2403,24.8802 L91.8553,24.8802 L91.8553,28.8552 L93.1113,28.8552 L93.1113,27.0552 C93.1113,26.0582 93.9743,25.2492 95.0413,25.2432 L95.0533,25.2432 L95.0543,25.2432 L95.0553,25.2432 C96.8013,25.2442 98.2153,26.5642 98.2153,28.1922 L98.2153,28.8552 L99.1323,28.8552 L99.1323,25.2892 L100.0733,25.2892 L100.0733,23.3182 L99.1323,22.4912 Z" }, MK: { vb: [0, 0, 24, 24], rule: 'nonzero', d: "M8.91076 16.8915c-1.03957.0038-1.93213-.6294-2.35267-1.366-.22516-.3217-.66989-.4364-.6761 0v2.0148c0 .8094-.29152 1.5097-.87581 2.1002-.56755.573-1.25977.8595-2.0779.8595-.80014 0-1.49298-.2865-2.07727-.8601C.28408 19.05 0 18.3497 0 17.5403V6.45968c0-.62378.17553-1.18863.52599-1.69455.36657-.52284.83426-.88582 1.4018-1.08769a2.84574 2.84574 0 0 1 1.00049-.17742c.90125 0 1.65239.35421 2.25281 1.06262l2.99713 3.51572c.06699.05016.263.43696.73192.43696.47016 0 .6916-.3868.75796-.43758l2.9717-3.5151c.6178-.70841 1.377-1.06262 2.2782-1.06262.3337 0 .6675.05893 1.0012.17742.5669.20187 1.0259.56422 1.377 1.08769.3665.50592.5501 1.07077.5501 1.69455V17.5403c0 .8094-.2915 1.5097-.8758 2.1002-.5675.573-1.2604.8595-2.0779.8595-.8008 0-1.493-.2865-2.0779-.8601-.5669-.5899-.8504-1.2902-.8504-2.0996v-2.0148c-.0496-.5499-.5303-.2032-.7009 0-.4503.8431-1.31369 1.3616-2.35264 1.366ZM21.447 8.60998c-.7009 0-1.3015-.24449-1.8019-.73348-.4838-.50571-.7257-1.11277-.7257-1.82118s.2419-1.30711.7257-1.79611c.5004-.50571 1.101-.75856 1.8019-.75856.7009 0 1.3017.25285 1.8025.75856.5003.489.7505 1.0877.7505 1.79611 0 .70841-.2502 1.31547-.7505 1.82118-.5008.48899-1.1016.73348-1.8025.73348Zm.0248.50655c.7009 0 1.2935.25285 1.7777.75856.5003.50571.7505 1.11301.7505 1.82181v6.2484c0 .7084-.2502 1.3155-.7505 1.8212-.4838.489-1.0764.7335-1.7777.7335-.7005 0-1.3011-.2445-1.8019-.7335-.5003-.5057-.7505-1.1128-.7505-1.8212v-6.2484c0-.7084.2502-1.3157.7505-1.82181.5004-.50571 1.101-.75856 1.8019-.75856Z" }, EM: { vb: [0, 0, 24, 24], rule: 'evenodd', d: "M2 4.5h20v15H2v-15zm2.2 2.2v1.4L12 13.2l7.8-5.1V6.7L12 11.8 4.2 6.7z" }, }; function drawTransferBadge(x, code, color, bx, by, sz) { x.fillStyle = color; x.beginPath(); if (x.roundRect) x.roundRect(bx, by, sz, sz, Math.round(sz * .16)); else x.rect(bx, by, sz, sz); x.fill(); const ic = TRANSFER_ICONS[code]; if (!ic) return; const pad = sz * .16, inner = sz - pad * 2, [vx, vy, vw, vh] = ic.vb; const sc = Math.min(inner / vw, inner / vh); x.save(); x.translate(bx + (sz - vw * sc) * .5 - vx * sc, by + (sz - vh * sc) * .5 - vy * sc); x.scale(sc, sc); x.fillStyle = '#fff'; x.fill(new Path2D(ic.d), ic.rule); x.restore(); } const FSANS = `ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, ${FM}`; function drawBoldText(x, str, px, py, col) { x.fillStyle = col; x.fillText(str, px, py); } // 2. Enamel Transit Transfer Sign (`乗換案内` — social & profile lines) { const CW = 760, CH = 640; const c = document.createElement('canvas'); c.width = CW; c.height = CH; const x = c.getContext('2d'); x.fillStyle = '#fff'; x.fillRect(0, 0, CW, CH); x.strokeStyle = '#000'; x.lineWidth = 6; x.strokeRect(4, 4, CW - 8, CH - 8); x.fillStyle = '#000'; x.fillRect(0, 0, CW, 78); x.textBaseline = 'top'; x.font = `900 40px ${JP}`; drawBoldText(x, '乗換案内', 22, 18, '#fff'); x.font = `800 32px ${FSANS}`; drawBoldText(x, 'transfer lines', 204, 23, '#fff'); TRANSFERS.forEach((tr, i) => { const y = 90 + i * 77; if (i) { x.fillStyle = '#000'; x.fillRect(22, y - 6, CW - 44, 2); } drawTransferBadge(x, tr.code, tr.color, 22, y + 4, 60); x.textAlign = 'left'; x.font = `800 33px ${FSANS}`; drawBoldText(x, tr.line, 100, y + 17, '#000'); x.textAlign = 'right'; x.font = `800 30px ${FSANS}`; drawBoldText(x, '->', CW - 20, y + 18, '#f00'); x.font = `700 29px ${FSANS}`; drawBoldText(x, tr.handle, CW - 66, y + 19, '#000'); x.textAlign = 'left'; }); const map = canvasTex(c); const FW = 1.44, FH = 1.21, cy = 1.54; const g = new THREE.Group(); g.position.set(-2.04, 0, z + 1.12); g.lookAt(st.camAt.x, 0, st.camAt.z); const postL = new THREE.Mesh(new THREE.BoxGeometry(.055, 2.16, .055), mat('ink', { hatch: .25 })); postL.position.set(-.64, 1.08, -.02); const postR = postL.clone(); postR.position.x = .64; const plate = new THREE.Mesh(new THREE.BoxGeometry(FW + .08, FH + .08, .034), mat('metal', { hatch: .12 })); plate.position.set(0, cy, 0); const face = new THREE.Mesh(new THREE.PlaneGeometry(FW, FH), mat('paper', { map, legible: .95, side: THREE.FrontSide })); face.position.set(0, cy, .02); g.add(postL, postR, plate, face); scene.add(g); TRANSFERS.forEach((tr, i) => { const rowY = cy + (.5 - (124 + i * 77) / CH) * FH; const hitM = new THREE.Mesh(new THREE.BoxGeometry(FW - .02, FH * (72 / CH), .06), new THREE.MeshBasicMaterial({ colorWrite: false, depthWrite: false })); hitM.position.set(0, rowY, .02); g.add(hitM); const tc = document.createElement('canvas'); tc.width = 520; tc.height = 310; const tx = tc.getContext('2d'); tx.fillStyle = '#fff'; tx.fillRect(0, 0, 520, 310); tx.strokeStyle = '#000'; tx.lineWidth = 6; tx.strokeRect(4, 4, 512, 302); drawTransferBadge(tx, tr.code, tr.color, 22, 22, 68); tx.textBaseline = 'top'; tx.textAlign = 'left'; tx.font = `800 34px ${FSANS}`; drawBoldText(tx, tr.line, 106, 24, '#f00'); tx.font = `700 25px ${FSANS}`; drawBoldText(tx, tr.handle, 106, 67, '#000'); tx.fillStyle = '#000'; tx.fillRect(22, 108, 476, 2); const dispUrl = tr.code === 'TG' ? 'tangled.org/@ptr.pet' : tr.url.replace(/^https?:\/\//, '').replace(/^mailto:/, ''); tx.font = `700 25px ${FSANS}`; drawBoldText(tx, dispUrl.slice(0, 34), 22, 134, '#000'); tx.textAlign = 'right'; tx.font = `700 23px ${FSANS}`; drawBoldText(tx, 'open ->', 496, 258, '#f00'); const tMap = canvasTex(tc); const card = phys.grabbable(phys.slip(.62, .37, { map: tMap, legible: .96, rows: 2, pocket: true, noTear: true }), { onTap: () => open(tr.url), }); g.updateMatrixWorld(true); const wp = g.localToWorld(V(0, rowY, .03)); const pt = pin(wp.x, wp.y, wp.z); phys.grabbable({ kind: 'transfer', mesh: hitM, points: [pt], outline: [plate, face], pickPoints: false }, { onTap: () => { blip(520 + i * 55, .08); phys.openCard(card, pt.p); }, }); }); } // 3. Sturdy Post-Mounted Japanese Red Postbox (`郵便ポスト`) with `dear dawn,` letter! { const px = 2.14, pz = z + 1.18; const g = new THREE.Group(); g.position.set(px, 0, pz); g.lookAt(st.camAt.x, 0, st.camAt.z); const b = bag(); b.box('ink', .08, 1.08, .08, 0, .54, 0); b.box('blood', .38, .46, .30, 0, 1.28, 0); b.box('blood', .43, .06, .35, 0, 1.53, 0); b.box('ink', .24, .035, .02, 0, 1.39, .155); b.build(g, { ink: mat('ink', { hatch: .25 }), blood: mat('blood') }); const flag = box(.025, .18, .09, 'metal'); flag.position.set(.21, 1.34, 0); flag.geometry.translate(0, .09, 0); g.add(flag); scene.add(g); g.updateMatrixWorld(true); const slotL = pin(...g.localToWorld(V(-.14, 1.35, .18)).toArray()); const slotR = pin(...g.localToWorld(V(.14, 1.35, .18)).toArray()); mailbox = { flag, up: 0, point: slotL }; makeBlank('mail', [slotL, slotR]); } } /* ---- STOP 1 (`halo` · friends, games & 3d models): 88x31 Vending Machine + Stacked Gachapon Machines ---- */ const badgeGeo = new THREE.PlaneGeometry(.31, .109); function halo(z) { const st = stops[1], fxz = V(st.face.x, 0, st.face.z).normalize(); const at = V(-.86, 0, z + .96); const g = new THREE.Group(); g.position.copy(at); g.lookAt(st.camAt.x, 0, st.camAt.z); g.rotateZ(.015); scene.add(g); const b = bag(); b.box('body', 1.3, 1.86, .58, 0, .93, 0); b.box('glass', 1.14, 1.08, .02, 0, 1.02, .295); b.box('ink', .82, .16, .02, 0, .28, .295); b.box('ink', .16, .26, .02, .5, .28, .295); b.build(g, { body: mat('metal', { hatch: .1 }), ink: mat('ink'), glass: mat('flat', { colors: ['#0b0b12', '#000000', '#f4f3dc'], fog: 0 }) }); const pool = new THREE.Mesh(new THREE.PlaneGeometry(1.7, 2.4).rotateX(-Math.PI / 2).translate(0, .03, 1.5), mat('flat', { colors: ['#f4f3dc', '#f4f3dc', '#c6f03a'], hatch: .5, fog: .2 })); pool.renderOrder = -1; g.add(pool); onPhase((pc) => { pool.visible = pc === 2; }); const sg = paper(['cool buttons :>', ['88x31', '#f00']], { px: 28, center: true, pad: 8, bold: true }); const sk = Math.min(1.02 / sg.w, .23 / sg.h); const sm = new THREE.Mesh(new THREE.PlaneGeometry(sg.w * sk, sg.h * sk), mat('paper', { map: sg.map, legible: .92 })); sm.position.set(0, 1.71, .30); g.add(sm); g.updateMatrixWorld(true); const out = V(0, 0, 1).applyQuaternion(g.quaternion); const droppers = []; BUTTONS.forEach((bt, i) => { const m = new THREE.Mesh(badgeGeo, mat('paper', { map: tex(`btn/${bt.id}.png`), color: true, legible: .82 })); m.position.set(-.36 + (i % 3) * .36, 1.48 - Math.floor(i / 3) * .148, .31); g.add(m); const drop = (fromNet = false, grab = false) => { if (!m.visible) return null; m.visible = false; if (!fromNet) net.sendToy('can', { i }); const c = new THREE.Mesh(badgeGeo, m.material); const spawnAt = grab ? g.localToWorld(m.position.clone().add(V(0, 0, .08))) : g.localToWorld(V(-.25 + rnd() * .5, .38, .45)); const bd = phys.grabbable(phys.body(c, { at: spawnAt, radius: .05, billboard: true, mass: .5 }), { onTap: () => { if (bt.url) open(bt.url); else firePulse(1); }, }); if (!grab) bd.point.prev.addScaledVector(out, -.012 - rnd() * .02); return bd; }; droppers[i] = drop; phys.grabbable({ kind: 'can', mesh: m, points: [phys.point(g.localToWorld(m.position.clone()), { pinned: true })] }, { onTap: () => { if (bt.url) open(bt.url); else firePulse(1); }, onGrab: () => { const bd = drop(false, true); if (bd) phys.retarget(bd); }, }); if (i === 5 || i === 12) drop(true); }); net.on('toy', (d) => { if (d.k === 'can' && droppers[d.i]) droppers[d.i](true); }); // Gachapon Capsule Stand (`ガチャ` — games, 3D avatars & art!) right beside the vending machine! { const gg = new THREE.Group(); gg.position.copy(at).addScaledVector(st.right, 1.18).addScaledVector(fxz, -.18); gg.lookAt(st.camAt.x, 0, st.camAt.z); scene.add(gg); const gb = bag(); gb.box('ink', .92, .16, .48, 0, .08, 0); gb.box('metal', .88, .52, .44, 0, .42, 0); for (let k = 0; k < 3; k++) { const gx = (k - 1) * .29; gb.box('blood', .26, .34, .38, gx, .85, 0); gb.box('bone', .25, .36, .36, gx, 1.20, 0); gb.box('blood', .27, .06, .39, gx, 1.41, 0); gb.box('ink', .11, .08, .03, gx, .76, .20); for (let ci = 0; ci < 5; ci++) { gb.add(ci % 2 ? 'blood' : 'accent', new THREE.SphereGeometry(.042, 8, 6), gx + ((ci % 3) - 1) * .055, 1.09 + Math.floor(ci / 3) * .085, .08); } } gb.build(gg, { ink: mat('ink', { hatch: .2 }), metal: mat('metal', { hatch: .12 }), blood: mat('blood'), bone: mat('bone'), accent: mat('flat', { colors: ['#2a14d6', '#000000', '#c6f03a'] }), }); const hdr = paper(['ガチャ · stuff it made', ['click a capsule', '#f00']], { px: 24, center: true, pad: 8, bold: true }); const hm = new THREE.Mesh(new THREE.PlaneGeometry(.84, .20), mat('paper', { map: hdr.map, legible: .92 })); hm.position.set(0, 1.56, .04); gg.add(hm); gg.updateMatrixWorld(true); GACHA.forEach((item, k) => { const gx = (k - 1) * .29; const dial = new THREE.Mesh(new THREE.CylinderGeometry(.055, .055, .04, 12).rotateX(Math.PI / 2), mat('bone')); dial.position.set(gx, .88, .21); const bar = new THREE.Mesh(new THREE.BoxGeometry(.09, .02, .025), mat('ink')); bar.position.z = .022; dial.add(bar); gg.add(dial); const tagP = paper([[item.label, '#f00']], { px: 19, center: true, pad: 5, bold: true }); const tagM = new THREE.Mesh(new THREE.PlaneGeometry(.24, .09), mat('paper', { map: tagP.map, legible: .95 })); tagM.position.set(gx, 1.32, .19); gg.add(tagM); const hitM = new THREE.Mesh(new THREE.BoxGeometry(.27, .76, .44), new THREE.MeshBasicMaterial({ colorWrite: false, depthWrite: false })); hitM.position.set(gx, 1.05, .05); gg.add(hitM); const cardP = paper([ [item.label, '#f00'], item.sub, '', ...item.lines, '', ['open ->', '#f00'], ], { px: 24, pad: 16, border: true, bold: true }); const card = phys.grabbable(phys.slip(.58, .42, { map: cardP.map, legible: .96, rows: 2, pocket: true, noTear: true }), { onTap: () => open(item.url), }); const wp = gg.localToWorld(V(gx, .92, .22)); const pt = pin(wp.x, wp.y, wp.z); let spinLeft = 0; onFrame((dt) => { if (spinLeft > 0) { const step = Math.min(spinLeft, dt * 11); dial.rotation.z -= step; spinLeft -= step; } }); phys.grabbable({ kind: 'gacha', mesh: hitM, points: [pt], outline: [dial, tagM], pickPoints: false }, { onTap: () => { spinLeft = Math.PI * 2; blip(680 + k * 90, .12); firePulse(.8); phys.openCard(card, pt.p); }, }); }); } } /* ---- STOP 2 (`ident` · about 90008): Laminated Identification Document Board + Interactive Bone Specimen Tags ---- */ const tags = []; function ident(z) { const st = stops[2]; // 1. Clean Laminated Identification Document Kiosk (`IDENTIFICATION // 90008`) { const doc = paper(IDENT_DOC, { px: 22, pad: 16, border: true, bold: true }); const g = new THREE.Group(); g.position.set(1.58, 0, z + .52); g.lookAt(st.camAt.x, 0, st.camAt.z); const legL = new THREE.Mesh(new THREE.BoxGeometry(.045, 1.92, .045), mat('ink', { hatch: .25 })); legL.position.set(-.46, .96, -.02); const legR = legL.clone(); legR.position.x = .46; const plate = new THREE.Mesh(new THREE.BoxGeometry(1.10, .86, .032), mat('metal', { hatch: .12 })); plate.position.set(0, 1.44, 0); const face = new THREE.Mesh(new THREE.PlaneGeometry(1.04, .80), mat('paper', { map: doc.map, legible: .92, side: THREE.FrontSide })); face.position.set(0, 1.44, .02); g.add(legL, legR, plate, face); scene.add(g); const card = phys.grabbable(phys.slip(.70, .54, { map: doc.map, legible: .96, rows: 2, pocket: true, noTear: true }), { onTap: () => { const u = siteHref('about'); if (api.live) location.href = u; else open(u); }, }); const pt = pin(1.58, 1.44, z + .52); phys.grabbable({ kind: 'identdoc', mesh: face, points: [pt], outline: [plate, face], pickPoints: false }, { onTap: () => phys.openCard(card, pt.p), }); } // 2. Bone-tied anatomical specimen tags on Dawn's doll (2-pin flat hangers, zero spin/fold/inversion) const d = getDoll(); if (d && d.bones && d.attach) { d.pivot.updateMatrixWorld(true); const slotY = [1.92, 1.38, .84, 1.84, 1.30, .76]; const slotSide = [-1, -1, -1, 1, 1, 1]; TAGS.forEach(([bn, side0, _dy, lines], idx) => { const bone = d.bones[bn]; if (!bone) return; const side = slotSide[idx] ?? side0; const targetY = slotY[idx] ?? 1.2; const pCard = paper(lines, { px: 20, hole: true, pad: 9, k: 1.9, border: true }); const halfSpan = pCard.w * .50; const at = d.attach(phys.point(V()), bn); const calcAnchor = (out, spanSign) => { out.copy(d.pivot.position); out.addScaledVector(st.right, side * .78 + spanSign * halfSpan); out.y = d.pivot.position.y + targetY; out.z += .14; return out; }; const aMid = phys.point(V(), { pinTo: (out) => calcAnchor(out, 0) }); const aL = phys.point(V(), { pinTo: (out) => calcAnchor(out, -1) }); const aR = phys.point(V(), { pinTo: (out) => calcAnchor(out, 1) }); for (const q of [at, aMid, aL, aR]) { q.pinTo(q.p); q.prev.copy(q.p); } const rp = phys.rope(at, aMid, 1, { kind: 'string', pick: false }); const sl = phys.grabbable(phys.slip(pCard.w, pCard.h, { map: pCard.map, legible: .92, hangFrom: [aL, aR], rows: 2, rest: .025, read: true, noTear: true, }), { onDrag: (_o, pos) => { tg.pos = pos; }, onRelease: () => { tg.pos = null; }, }); const tg = { bone, rest: bone.position.clone(), pull: V(), want: V(), pos: null, a: aMid, aL, aR, rp, slip: sl, right: st.right, wasVis: true }; tags.push(tg); }); } } function resetTagSlip(t) { t.a.pinTo(t.a.p); t.a.prev.copy(t.a.p); t.aL.pinTo(t.aL.p); t.aL.prev.copy(t.aL.p); t.aR.pinTo(t.aR.p); t.aR.prev.copy(t.aR.p); const s = t.slip; s.points.forEach((q, i) => { const r = i >> 1, cc = i & 1; q.p.copy(t.a.p).addScaledVector(t.right, (cc - .5) * s.sw); q.p.y -= .025 + (r / s.rows) * s.sh; q.prev.copy(q.p); }); } const tv = V(), tw = V(); onFrame((dt) => { const d = getDoll(); const showTags = d ? (d.atIdent !== undefined ? !!d.atIdent : (state.here === 2 && !state.ride)) : false; for (const t of tags) { if (t.wasVis !== showTags) { t.wasVis = showTags; t.slip.mesh.visible = showTags; if (t.rp?.line) t.rp.line.visible = showTags; if (!showTags && phys.reading === t.slip) phys.reading = null; if (showTags) resetTagSlip(t); } if (!showTags) continue; const held = phys.held === t.slip && t.pos; if (held) t.want.copy(t.pos).sub(t.a.p).multiplyScalar(.7).clampLength(0, .52); else t.want.set(0, 0, 0); t.pull.lerp(t.want, 1 - Math.exp(-dt * (held ? 12 : 4))); const par = t.bone.parent; par.updateWorldMatrix(true, false); par.getWorldPosition(tv).add(t.pull); par.worldToLocal(tv); t.bone.position.copy(t.rest).add(tv); } }); /* ---- STOP 3 (`wire` · posts, blog entries & projects): Pamphlet Rack + Japan Polaroids + 8 Numbered Coin Lockers ---- */ function wireStop(z) { const st = stops[3]; // 1. Station Pamphlet Rack (`記事 / entries — take one` + 3 real dithered japan-trip24 Polaroid prints!) { const g = new THREE.Group(); g.position.set(2.04, 0, z + .62); g.lookAt(st.camAt.x, 0, st.camAt.z); scene.add(g); const b = bag(); b.box('ink', .78, .08, .42, 0, .04, 0); b.box('ink', .05, 1.62, .05, -.34, .81, -.08); b.box('ink', .05, 1.62, .05, .34, .81, -.08); b.box('metal', .76, 1.18, .04, 0, 1.08, -.06); b.box('ink', .76, .12, .22, 0, .68, .05); b.box('ink', .76, .10, .20, 0, 1.04, .05); b.build(g, { ink: mat('ink', { hatch: .22 }), metal: mat('metal', { hatch: .12 }) }); const hdr = paper(['記事 · entries', ['click to read', '#f00']], { px: 23, center: true, pad: 8, bold: true }); const hm = new THREE.Mesh(new THREE.PlaneGeometry(.70, .18), mat('paper', { map: hdr.map, legible: .94 })); hm.position.set(0, 1.54, -.03); g.add(hm); g.updateMatrixWorld(true); // 3 real Japan trip Polaroid prints pinned across the top of the rack! ['j/jp1.webp', 'j/jp2.webp', 'j/jp3.webp'].forEach((src, i) => { const pc = document.createElement('canvas'); pc.width = 200; pc.height = 180; const px = pc.getContext('2d'), pMap = canvasTex(pc); const drawPol = (im) => { px.fillStyle = '#fff'; px.fillRect(0, 0, 200, 180); px.strokeStyle = '#000'; px.lineWidth = 4; px.strokeRect(2, 2, 196, 176); if (im) px.drawImage(im, 10, 10, 180, 132); else { px.fillStyle = '#000'; px.fillRect(10, 10, 180, 132); } px.fillStyle = '#f00'; px.font = `bold 15px ${FM}`; px.textAlign = 'center'; px.textBaseline = 'top'; px.fillText(`09/24 #0${i + 1}`, 100, 149); pMap.needsUpdate = true; }; drawPol(null); const im = new Image(); im.onload = () => drawPol(im); im.src = src; const pm = new THREE.Mesh(new THREE.PlaneGeometry(.21, .19), mat('paper', { map: pMap, color: true, legible: .82 })); pm.position.set((i - 1) * .23, 1.29, -.025); pm.rotation.z = (i - 1) * -.045; g.add(pm); }); // Pull-out pamphlets for each entry in `ENTRIES` ENTRIES.slice(0, 2).forEach((en, i) => { const px0 = (i === 0 ? -.17 : .17), py0 = .84; const cover = paper([[en.date, '#f00'], en.title], { px: 19, center: true, pad: 8, border: true, bold: true }); const cm = new THREE.Mesh(new THREE.PlaneGeometry(.29, .24), mat('paper', { map: cover.map, legible: .94 })); cm.position.set(px0, py0, .08); cm.rotation.x = -.14; g.add(cm); const full = paper([ [en.date, '#f00'], en.title, '', ...wrap(en.excerpt, 24), '', ['open entry ->', '#f00'], ], { px: 24, pad: 16, border: true, bold: true }); const card = phys.grabbable(phys.slip(.62, .44, { map: full.map, legible: .96, rows: 2, pocket: true, noTear: true }), { onTap: () => { const u = siteHref(`entries/${en.slug}/`); if (api.live) location.href = u; else open(u); }, }); const wp = g.localToWorld(V(px0, py0, .10)); const pt = pin(wp.x, wp.y, wp.z); phys.grabbable({ kind: 'pamphlet', mesh: cm, points: [pt], outline: [cm], pickPoints: false }, { onTap: () => { blip(610 + i * 80, .09); phys.openCard(card, pt.p); }, }); }); } // 2. Bank of 8 Numbered Japanese Station Coin Lockers (`コインロッカー 01..08` — `stuff.md` projects!) { const lg = new THREE.Group(); lg.position.set(.82, 0, z - .18); lg.lookAt(st.camAt.x, 0, st.camAt.z); scene.add(lg); const W = 1.64, H = 1.78, D = .52; const lb = bag(); lb.box('ink', W + .06, .10, D + .04, 0, .05, 0); lb.box('metal', W, H, D, 0, .10 + H / 2, 0); lb.box('ink', W + .04, .14, D + .06, 0, .10 + H + .07, 0); lb.build(lg, { ink: mat('ink', { hatch: .22 }), metal: mat('metal', { hatch: .10 }) }); const topSign = paper(['stuff it did', ['click a locker', '#f00']], { px: 23, center: true, pad: 7, bold: true }); const tm = new THREE.Mesh(new THREE.PlaneGeometry(1.52, .20), mat('paper', { map: topSign.map, legible: .94 })); tm.position.set(0, .10 + H + .07, D / 2 + .035); lg.add(tm); lg.updateMatrixWorld(true); // 4 columns x 2 rows = 8 lockers! const cols = 4, dw = .37, dh = .76; PROJECTS.forEach((pr, idx) => { const col = idx % cols, row = Math.floor(idx / cols); const cx = (col - 1.5) * .395, cy = row === 0 ? 1.42 : .60; const hinge = new THREE.Group(); hinge.position.set(cx - dw / 2, cy, D / 2 + .008); lg.add(hinge); const dc = document.createElement('canvas'); dc.width = 192; dc.height = 384; const dx = dc.getContext('2d'); dx.fillStyle = '#fff'; dx.fillRect(0, 0, 192, 384); dx.strokeStyle = '#000'; dx.lineWidth = 6; dx.strokeRect(3, 3, 186, 378); dx.fillStyle = '#000'; dx.fillRect(14, 14, 72, 44); dx.fillStyle = '#fff'; dx.font = `bold 28px ${FM}`; dx.textAlign = 'center'; dx.textBaseline = 'top'; dx.fillText(pr.num, 50, 22); dx.fillStyle = '#f00'; dx.fillRect(150, 170, 18, 44); for (let v = 0; v < 3; v++) { dx.fillStyle = '#000'; dx.fillRect(36, 78 + v * 14, 120, 5); } dx.fillStyle = '#000'; dx.textAlign = 'center'; dx.font = `bold 23px ${FM}`; dx.fillText(pr.name, 96, 238); dx.fillStyle = '#f00'; dx.font = `18px ${FM}`; dx.fillText(pr.tag, 96, 272); if (!pr.active) { dx.save(); dx.translate(96, 332); dx.rotate(-.12); dx.fillStyle = '#000'; dx.fillRect(-78, -16, 156, 32); dx.fillStyle = '#fff'; dx.font = `bold 17px ${FM}`; dx.fillText('past', 0, -9); dx.restore(); } const dMap = canvasTex(dc); const doorM = new THREE.Mesh(new THREE.PlaneGeometry(dw, dh), mat('paper', { map: dMap, legible: .92, side: THREE.DoubleSide })); doorM.position.set(dw / 2, 0, .006); hinge.add(doorM); const cardP = paper([ [`${pr.num} · ${pr.name}`, '#f00'], `${pr.tag}${pr.active ? '' : ' · past'}`, '', ...pr.desc, '', ['open repo ->', '#f00'], ], { px: 24, pad: 16, border: true, bold: true }); let wantOpen = 0, curOpen = 0; const card = phys.grabbable(phys.slip(.62, .44, { map: cardP.map, legible: .96, rows: 2, pocket: true, noTear: true }), { onTap: () => open(pr.url), onClose: () => { wantOpen = 0; }, }); onFrame((dt) => { if (Math.abs(wantOpen - curOpen) > 1e-3) { curOpen += (wantOpen - curOpen) * (1 - Math.exp(-dt * 10)); hinge.rotation.y = -curOpen * 1.15; } }); const wp = lg.localToWorld(V(cx, cy, D / 2 + .04)); const pt = pin(wp.x, wp.y, wp.z); phys.grabbable({ kind: 'locker', mesh: doorM, points: [pt], outline: [doorM], pickPoints: false }, { onTap: () => { wantOpen = 1; blip(420 + idx * 45, .09); firePulse(.6); phys.openCard(card, pt.p); }, }); }); } } /* ---- STOP 4 (`pray` · guestbook): Dense Wooden Shrine Ema Rack (`絵馬掛け`) + Writing Stand ---- */ let prayZ = 0, planted = 0, haloMat = null; const haloGeo = new THREE.TorusGeometry(.13, .016, 4, 10).rotateX(Math.PI / 2), halos = []; onFrame((dt, t) => { halos.forEach((h, i) => { h.rotation.y = t * .8 + i; h.position.y = (h.userData.y0 ?? (h.userData.y0 = h.position.y)) + Math.sin(t * 1.5 + i) * .02; }); }); function emaCanvas(g) { const c = document.createElement('canvas'); c.width = 280; c.height = 210; const x = c.getContext('2d'); x.fillStyle = '#fff'; x.beginPath(); x.moveTo(140, 6); x.lineTo(272, 48); x.lineTo(272, 204); x.lineTo(8, 204); x.lineTo(8, 48); x.closePath(); x.fill(); x.strokeStyle = '#000'; x.lineWidth = 6; x.stroke(); x.fillStyle = '#f00'; x.beginPath(); x.arc(140, 26, 7, 0, 7); x.fill(); x.font = `bold 20px ${FM}`; x.fillStyle = '#000'; x.textBaseline = 'top'; const body = wrap(g.x, 19).slice(0, g.reply ? 3 : 4); body.forEach((ln, i) => x.fillText(ln, 20, 52 + i * 26)); if (g.reply) { x.fillStyle = '#f00'; x.font = `bold 18px ${FM}`; x.fillText('↳ ' + (g.reply.length > 22 ? g.reply.slice(0, 21) + '…' : g.reply), 20, 138); } x.fillStyle = '#f00'; x.font = `16px ${FM}`; x.textAlign = 'right'; x.fillText(g.t, 258, 178); return { c, map: canvasTex(c) }; } const emaHooks = []; function pray(z) { prayZ = z; const st = stops[4]; for (const [gx, gz, ry, w] of [[1.1, z - 1.6, .3, 2.6], [-.9, z - 4.6, .1, 2.0]]) { const g = torii(w, w * .95); g.position.set(gx, 0, gz); g.rotation.y = ry; scene.add(g); if (w === 2.0) { const h = new THREE.Mesh(haloGeo, haloMat ||= mat('metal')); h.scale.setScalar(2.2); h.position.set(gx, w * .95 + .25, gz); scene.add(h); halos.push(h); } } // Roofed wooden ema rack const rg = new THREE.Group(); rg.position.set(.38, 0, z + 1.18); rg.lookAt(st.camAt.x, 0, st.camAt.z); scene.add(rg); const rb = bag(); rb.box('ink', .07, 2.12, .07, -1.08, 1.06, 0); rb.box('ink', .07, 2.12, .07, 1.08, 1.06, 0); rb.box('blood', 2.42, .09, .38, 0, 2.14, 0); rb.box('ink', 2.48, .05, .44, 0, 2.20, 0); rb.box('ink', 2.16, .045, .045, 0, 1.68, .03); rb.box('ink', 2.16, .045, .045, 0, 1.16, .03); rb.build(rg, { ink: mat('ink', { hatch: .24 }), blood: mat('blood') }); const rSign = paper(['祈り · guestbook', ['click a plaque to read', '#f00']], { px: 21, center: true, pad: 6, bold: true }); const rSm = new THREE.Mesh(new THREE.PlaneGeometry(1.36, .18), mat('paper', { map: rSign.map, legible: .94 })); rSm.position.set(0, 1.94, .04); rg.add(rSm); rg.updateMatrixWorld(true); for (const ry of [1.66, 1.14]) { for (let c = 0; c < 6; c++) { const rx = (c - 2.5) * .36; const wpL = rg.localToWorld(V(rx - .11, ry, .05)); const wpR = rg.localToWorld(V(rx + .11, ry, .05)); emaHooks.push([pin(wpL.x, wpL.y, wpL.z), pin(wpR.x, wpR.y, wpR.z)]); } } const local = api.live ? [] : JSON.parse(localStorage.getItem('arfs') || '[]').reverse(); const all = [...local, ...GUESTS].slice(0, emaHooks.length); const slips = []; all.forEach((g, i) => { const em = emaCanvas(g); const s = phys.grabbable(phys.slip(.31, .24, { map: em.map, legible: .92, facing: V(0, 0, 1), hangFrom: emaHooks[i], rows: 2, rest: .03, noTear: true }), {}); s._ema = em; slips.push(s); planted = i + 1; }); onLive(() => { const src = [...(api.live ? [] : JSON.parse(localStorage.getItem('arfs') || '[]').reverse()), ...GUESTS].slice(0, slips.length); slips.forEach((s, i) => { if (!src[i]) return; const next = emaCanvas(src[i]); const ctx2 = s._ema.c.getContext('2d'); ctx2.clearRect(0, 0, s._ema.c.width, s._ema.c.height); ctx2.drawImage(next.c, 0, 0); s._ema.map.needsUpdate = true; }); }); // Wooden writing stand { const wg = new THREE.Group(); wg.position.set(1.98, 0, z + .45); wg.lookAt(st.camAt.x, 0, st.camAt.z); scene.add(wg); const wb = bag(); wb.box('ink', .05, 1.06, .05, -.24, .53, -.14); wb.box('ink', .05, 1.06, .05, .24, .53, -.14); wb.box('ink', .05, .96, .05, -.24, .48, .14); wb.box('ink', .05, .96, .05, .24, .48, .14); wb.box('metal', .62, .05, .42, 0, 1.04, 0, .22, 0, 0); wb.box('ink', .04, .48, .04, 0, 1.28, -.16); wb.build(wg, { ink: mat('ink', { hatch: .25 }), metal: mat('metal', { hatch: .12 }) }); const lbl = paper([['guestbook', '#f00'], 'click to post'], { px: 20, center: true, pad: 6, bold: true }); const lm = new THREE.Mesh(new THREE.PlaneGeometry(.46, .16), mat('paper', { map: lbl.map, legible: .95 })); lm.position.set(0, 1.48, -.13); wg.add(lm); wg.updateMatrixWorld(true); const deskL = pin(...wg.localToWorld(V(-.14, 1.24, .06)).toArray()); const deskR = pin(...wg.localToWorld(V(.14, 1.24, .06)).toArray()); makeBlank('wish', [deskL, deskR]); } net.on('wish', (text) => { if (!text || text === lastPlantedWish) return; const hook = emaHooks[planted % emaHooks.length]; planted++; const em = emaCanvas({ t: 'just now', x: text }); phys.grabbable(phys.slip(.31, .24, { map: em.map, legible: .92, facing: V(0, 0, 1), hangFrom: hook, rows: 2, rest: .03, noTear: true }), {}); firePulse(1); }); } let lastPlantedWish = ''; /* ---- Blank writable slips (mail at Stop 0 + guestbook wish at Stop 4) ---- */ export const blanks = []; function makeBlank(kind, from) { const c = document.createElement('canvas'); c.width = 352; c.height = 256; const b = { kind, c, map: canvasTex(c), text: '', at: from, busy: false, note: null }; b.draw = (text, cursor) => { const x = c.getContext('2d'); x.fillStyle = '#fff'; x.fillRect(0, 0, 352, 256); x.strokeStyle = '#000'; x.lineWidth = 4; x.strokeRect(3, 3, 346, 250); x.font = `bold 28px ${FM}`; x.textBaseline = 'top'; const maxRows = b.note ? 4 : 5; const L = wrap(text, 19).slice(-(kind === 'mail' ? maxRows - 1 : maxRows)); if (kind === 'mail') L.unshift(['notify this one (click)', '#f00']); else if (!text && !cursor) L.unshift(['say meow! (click)', '#f00']); L.forEach((l, i) => { x.fillStyle = Array.isArray(l) ? l[1] : '#000'; x.fillText(Array.isArray(l) ? l[0] : l, 16, 16 + i * 38); }); if (cursor) { const last = L[L.length - 1], lw = typeof last === 'string' ? x.measureText(last).width : 0; const row = typeof last === 'string' ? L.length - 1 : L.length; x.fillStyle = '#f00'; x.fillRect(16 + lw + 2, 16 + row * 38, 14, 28); } if (b.note) { x.fillStyle = '#000'; x.fillRect(16, 206, 320, 2); x.font = `bold 22px ${FM}`; x.fillStyle = b.note.color || '#f00'; x.fillText(b.note.text, 16, 214); } b.map.needsUpdate = true; }; b.draw('', false); b.slip = phys.grabbable(phys.slip(.48, .35, { map: b.map, legible: .92, facing: V(0, 0, 1), hangFrom: from, rows: 3, rest: .04, noTear: true }), {}); blanks.push(b); return b; } onFrame(() => { const now = performance.now(); for (const b of blanks) { if (!b.note) continue; if (b.note.retryUntil && now < b.note.retryUntil) { const next = `ratelimited, wait ${Math.max(1, Math.ceil((b.note.retryUntil - now) / 1000))}s`; if (b.note.text !== next) { b.note.text = next; b.draw(b.text, false); } } else if (now >= b.note.until) { b.note = null; b.draw(b.text, false); } } }); export async function commit(b, text) { if (b.busy) return false; b.busy = true; b.note = { text: 'sending...', color: '#0f0', until: Infinity }; b.draw(text, false); const r = await (b.kind === 'mail' ? postMail(text) : postWish(text)); b.busy = false; if (!r.ok) { const dur = Math.max(4500, (r.retryAfter || 0) * 1000); b.note = { text: r.msg, color: '#f00', until: performance.now() + dur, retryUntil: r.retryAfter ? performance.now() + r.retryAfter * 1000 : 0 }; b.draw(b.text, false); fireShy(); return false; } if (b.kind === 'mail') { b.text = ''; b.note = { text: 'sent!', color: '#0f0', until: performance.now() + 2400 }; b.draw('', false); if (phys.reading === b.slip) setTimeout(() => { if (phys.reading === b.slip && !b.text) phys.unread(); }, 900); if (mailbox) mailbox.up = 1; firePulse(1); return true; } lastPlantedWish = text; const g = { t: 'just now', x: text, local: !!r.local }; if (r.local) { const mine = JSON.parse(localStorage.getItem('arfs') || '[]'); mine.push(g); localStorage.setItem('arfs', JSON.stringify(mine.slice(-12))); } b.text = ''; b.note = { text: 'posted!', color: '#0f0', until: performance.now() + 2000 }; b.draw('', false); if (phys.reading === b.slip) phys.unread(); const hook = emaHooks[planted % emaHooks.length]; planted++; const em = emaCanvas(g); phys.grabbable(phys.slip(.31, .24, { map: em.map, legible: .92, facing: V(0, 0, 1), hangFrom: hook, rows: 2, rest: .03, noTear: true }), {}); firePulse(1); return true; } function sky() { const c = document.createElement('canvas'); c.width = 1024; c.height = 96; const x = c.getContext('2d'), map = canvasTex(c); const geo = new THREE.PlaneGeometry(150, 14); const m = new THREE.Mesh(geo, new THREE.ShaderMaterial({ uniforms: { ...G, map: { value: map } }, depthTest: false, depthWrite: false, side: THREE.DoubleSide, vertexShader: `varying vec2 vUv; void main(){ vUv=uv; gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.); }`, fragmentShader: COMMON + `uniform sampler2D map; varying vec2 vUv; void main(){ if(texture2D(map,vUv).r<.5) discard; gl_FragColor=vec4(ph(vec3(.04,.04,.07),vec3(0.),vec3(.96,.95,.86)),1.); }`, })); const gh = new THREE.Mesh(geo, new THREE.ShaderMaterial({ uniforms: { ...G, map: { value: map } }, depthTest: true, depthWrite: false, depthFunc: THREE.GreaterDepth, side: THREE.DoubleSide, vertexShader: `varying vec2 vUv; void main(){ vUv=uv; vec4 clip=projectionMatrix*modelViewMatrix*vec4(position,1.); clip.z=clip.w*.99996; gl_Position=clip; }`, fragmentShader: COMMON + `uniform sampler2D map; varying vec2 vUv; void main(){ if(texture2D(map,vUv).r<.5 || bayer(gl_FragCoord.xy)<.48) discard; gl_FragColor=vec4(ph(vec3(.04,.04,.07),vec3(.96,.95,.86),vec3(.96,.95,.86)),1.); }`, })); m.frustumCulled = gh.frustumCulled = false; m.renderOrder = -3; gh.renderOrder = 20; m.visible = gh.visible = false; m.add(gh); scene.add(m); let i = -1, t0 = 0, n = -1; onFrame((dt, t) => { if (state.still !== m.visible) { m.visible = gh.visible = state.still; if (state.still) { i = (i + 1) % WHISPERS.length; t0 = t; n = -1; } } if (!m.visible) return; const s = WHISPERS[i], k = Math.min(s.length, Math.floor((t - t0) * 7)); if (k !== n) { n = k; x.clearRect(0, 0, 1024, 96); x.fillStyle = '#fff'; x.font = '52px "Hiragino Mincho ProN","Yu Mincho","Noto Serif JP",serif'; x.textAlign = 'center'; x.textBaseline = 'middle'; x.fillText(s.slice(0, k).split('').join(' '), 512, 50); map.needsUpdate = true; } if ((t - t0) * 7 > s.length + 30) { i = (i + 1) % WHISPERS.length; t0 = t; } cam.getWorldDirection(tv); m.position.copy(cam.position).addScaledVector(tv, 320); m.position.y += 118; tw.setFromMatrixColumn(cam.matrixWorld, 0); m.position.addScaledVector(tw, state.portrait ? -20 : -135); m.quaternion.copy(cam.quaternion); m.rotateZ(.07); }); } onFrame((dt) => { if (mailbox) { mailbox.up = Math.max(0, mailbox.up - dt * .25); mailbox.flag.rotation.x = -Math.min(1, mailbox.up * 3) * 1.5 + 1.5; } }); export async function init() { const fonts = [new FontFace(FM, 'url(f/kosugimaru.woff2)'), new FontFace(DM, 'url(f/dollmonoopt.woff2)')]; await Promise.all(fonts.map((f) => f.load().then((l) => document.fonts.add(l)).catch(() => {}))); if (window.duet) window.duet.cook = { tags, blanks }; carrier(stopZ(0)); halo(stopZ(1)); ident(stopZ(2)); wireStop(stopZ(3)); pray(stopZ(4)); sky(); }