Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(world): make the campus a real daylit place with walk-in rooms, photographic surfaces, real props and door arrivals
nirholasf91c34c80f33
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 17f22a580..9cd197ff6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -37,6 +37,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr- **Live widgets and an assistant on the desktop, and the desktop is back at /**: The homepage is the web desktop again, and the Field moves to /?view=field. The desktop gains eleven live widgets: the $THREE price with a 24 hour chart, weather where you are, clock, calendar, the newest agents, Pulse wallet moves, coins launched through three.ws, platform stats, headlines from the news desk, your device's battery, network and storage, and sticky notes. Pin them to the desktop in small, medium or large, drag them on a snap grid, or keep them on the widgets board beside a news column. The new assistant pane answers questions about three.ws, opens the right app from its reply, and lets you switch to any public agent and talk to it instead. Nothing is sample data: a source that is down says so and offers a retry. (`/docs/desktop-widgets`) `[feature, desktop]`- **Menu bar panel for the desktop app**: Click the three.ws icon in your menu bar or tray and a small panel shows your agent alive in 3D, its Solana wallet balance, a start and stop button, anything waiting on your approval, unread alerts and a box to ask the agent something. Approvals still open the native confirmation window, so what you approve is exactly what you were shown. (`/desktop`) `[feature]`- **Real agents live on the campus: a greeter meets you at the gate and every agent you walk up to talks back**: The campus is now populated by the ten most talked-to public agents on three.ws, each wearing its own avatar from its public record (five on a phone). The most popular one stands beside the gate path, turns to you as you walk in, waves and says hello through its own brain. Every agent idles, wanders a step, faces you when you come near and carries a name tag; walk up (or tap the tag) and press E to open a conversation that streams the agent's real reply, shows it as a speech bubble and can read it aloud. The panel opens the agent's profile as a window and hands you the one-tag embed that puts that exact agent, body and brain, on any web page. GET /api/agents/public now returns avatar_model_url for public and unlisted avatars. (`/?world=1`) `[feature, desktop]`+- **The campus is now a real place: daylight, walk-in buildings, photographic surfaces and real props**: The 3D campus in front of the desktop is rebuilt to feel like walking through a real place rather than a dark game level. A physical sky and sun with soft shadows that follow you, hills on the horizon, a walled gate with lamps and a welcome sign, a lawn, concrete paths and a paved plaza. Every building is a room you walk into through its door: the brick office with a gabled roof, windows and a furnished desk; the marble-columned exchange with a ticker outside and over the dais inside; the forge with a glowing furnace; the gallery under a skylight, hanging the real avatars of the agents on the campus; a hillside mine with a timbered portal, rails and a cart; the launchpad with its rocket, gantry and crew cabin; a pergola plaza with a fountain; and a timber market hall with striped stalls. Walls, floors and roofs use CC0 photographic materials from Poly Haven, and trees, hedges, lamps, benches, bins, crates and barrels are real glTF models streamed from the three.ws object library, nearest first. Walls and furniture are solid for you and the agents, the camera never cuts through a wall, teleporting puts you at a building's door facing in, and quality adapts to the device (a software renderer always gets the lightest tier). (`/?world=1`) `[feature, desktop]`- **The desktop behaves like a real computer**: Drag a selection box across the desktop, move icons on a snap grid, right-click for view options, and open every app from desktop icons or All Apps. Settings now covers your profile, theme, accent colour, wallpaper (including your own photo), icon size and taskbar, and the whole session (windows, icon layout, preferences) is saved in your browser, with export, import and reset. (`/docs/desktop`) `[feature, desktop]`- **The desktop now looks and works like a real operating system**: The desktop shell is rebuilt to feel like a computer, not a web page. A floating island taskbar with Start, Widgets and Assistant buttons. A new Start menu with your avatar, the time, an A to Z list of every app and page, pinned apps, recent files, quick folder links and a power button, plus search across apps, pages and your files. A system tray with live network, volume and battery readouts that opens quick settings (dark mode, night light, do not disturb, energy saver, sounds, full screen, brightness and volume). A notification centre over a month calendar, with toasts that open the app that sent them. A lock screen (Ctrl+Alt+L), a power menu with restart, shut down and sign out, a Run box (Ctrl+Alt+R) and an About page with your real device specs. The desktop is now your Desktop folder: create folders and text files from the right-click menu, rename with F2, delete to the Recycle Bin, drop files from your computer onto it, and set any picture as the wallpaper. New Bubbles wallpaper in dark and light, glossy app icons, and Ctrl+Alt shortcuts for every system surface. (`/?view=desktop`) `[feature, desktop]`- **The homepage is now the Field: one live map of every agent, launch and wallet move**: The front page no longer opens a web desktop. It opens the Field, a zoomable map of the whole platform built from live data. Every public agent is a star in the core, newest at the centre, and turns into its avatar as you zoom in; around it sit ten districts (Create, Forge, Gallery, Launchpad, Trenches, Pulse, Marketplace, Chat, Agent Studio, Console). From afar each shows one live readout; zoom in and it opens into a card with real content: the newest avatars, coins agents launched, the $THREE price, market cap, holders and contract address, the latest agent wallet moves, the skills agents carry most. New wallet moves from Pulse fly across the map as comets and land in their district. Search finds any place, agent or page; opening one loads the real page in place, with its own shareable /?go= link, and Back or Esc returns you to the map. It works with mouse, touch, pinch and keyboard, in light and dark, and lays itself out for phones. The windowed desktop is still at /?view=desktop and the 3D campus at /?world=1. (`/`) `[feature]`diff --git a/STRUCTURE.md b/STRUCTURE.mdindex 1cbd43bda..f46fb26f9 100644--- a/STRUCTURE.md+++ b/STRUCTURE.md@@ -26,7 +26,7 @@ bottom.| Event Market live feed | [api/event-markets/stream.js](api/event-markets/stream.js), [api/_lib/event-markets/hub.js](api/_lib/event-markets/hub.js), [feed.js](api/_lib/event-markets/feed.js), [moves.js](api/_lib/event-markets/moves.js), [live-stats.js](api/_lib/event-markets/live-stats.js), [api/cron/event-markets-feed.js](api/cron/event-markets-feed.js), [src/event-markets/live-feed.js](src/event-markets/live-feed.js), [ticker.js](src/event-markets/ticker.js), [data/event-markets-feed.json](data/event-markets-feed.json) | Live (migration 20261012200000 applied) | SSE odds, picks, moves and lifecycle with Last-Event-ID resume, odds-move detector, home ticker, in-place odds on the market page with polling fallback, pulse and trending additions. Docs: [docs/event-markets.md](docs/event-markets.md#live-feed). Tests: [tests/event-markets-live-feed.test.js](tests/event-markets-live-feed.test.js), [tests/event-markets-live-stats.test.js](tests/event-markets-live-stats.test.js). Bench: [scripts/event-markets-fanout-bench.mjs](scripts/event-markets-fanout-bench.mjs) || App pages (hub plus Android, Seeker, iOS, Desktop, Web) | Pages [pages/apps.html](pages/apps.html) `→ /apps` and `pages/apps-{web,android,seeker,ios,desktop}.html` `→ /apps/*`, code [src/apps.js](src/apps.js), [src/apps.css](src/apps.css) | Built and verified locally | One page per platform with its real install path and status; the desktop page reads the live release feed. Docs: [docs/apps.md](docs/apps.md) || The Field (a live, zoomable map of every agent and surface) | Page [pages/desktop.html](pages/desktop.html) `→ /?view=field`, code [src/field/](src/field) ([README](src/field/README.md)): pure layout and camera [logic.js](src/field/logic.js), feeds [data.js](src/field/data.js), map [field.js](src/field/field.js), entry and view switch [entry.js](src/field/entry.js) | Built and verified locally | Public agents drawn as stars in a golden-angle core around ten live districts; semantic zoom from one readout per district to full cards (avatars, launches, $THREE quote and CA, Pulse wallet moves, top skills, most-talked-to agents); Pulse events fly in as comets; search over places, agents and every nav page; any page opens in place at a shareable `/?go=` URL. The homepage `/` is the web desktop; the campus is at `/?world=1`. Docs: [docs/field.md](docs/field.md) |-| Web desktop (homepage as an OS, with a 3D campus in front of it) | Page [pages/desktop.html](pages/desktop.html) `→ /`, code [src/desktop/](src/desktop) ([README](src/desktop/README.md)): boot and lock screen [boot.js](src/desktop/boot.js) + [boot-logic.js](src/desktop/boot-logic.js), campus [src/desktop/world/](src/desktop/world), gem ledger [api/world/gems.js](api/world/gems.js) over [api/_lib/world-gems.js](api/_lib/world-gems.js) (migration `20261015000000_world_gems.sql`); previous homepage [pages/home.html](pages/home.html) `→ /classic` | Built and verified locally | Boots with a live log of real checks (GPU, site catalog, account, fonts, avatar, $THREE feed, gem ledger), locks with a greeting and live chips, then the visitor walks in as their avatar: a campus with the home office (sit at the desk to open the desktop on the monitor, pick up the phone for Pocket, put on the headset for WebXR), the three.ws Exchange with a live ticker (Trenches), the Launchpad, the Forge, the Gallery, Agent Plaza, the Marketplace and a gem mine with server-rolled, rate-limited digs. Real registered agents stand on the campus in their own bodies ([world/cast.js](src/desktop/world/cast.js), [agents.js](src/desktop/world/agents.js), [talk.js](src/desktop/world/talk.js)): a greeter meets you at the gate, and walking up to any of them opens a conversation through its own `/api/chat` brain, with the one-tag `<agent-3d>` embed to put it on your own site. Taskbar, Start, widgets and snappable windows framing real three.ws pages in the CTRL Mica theme; icons on a snap grid, All Apps, Settings (profile, Arrival, accent, wallpaper, icon size), session in localStorage plus IndexedDB. Framed pages hide the site nav via `public/nav.js` (`tws-os:` frame name). Docs: [docs/desktop.md](docs/desktop.md). Tests: [tests/desktop-boot.test.js](tests/desktop-boot.test.js), [tests/world-places.test.js](tests/world-places.test.js), [tests/world-ticker.test.js](tests/world-ticker.test.js), [tests/desktop-layout.test.js](tests/desktop-layout.test.js), [tests/desktop-page.test.js](tests/desktop-page.test.js); browser drives [scripts/desktop-world-smoke.mjs](scripts/desktop-world-smoke.mjs), [scripts/desktop-interact.mjs](scripts/desktop-interact.mjs) |+| Web desktop (homepage as an OS, with a 3D campus in front of it) | Page [pages/desktop.html](pages/desktop.html) `→ /`, code [src/desktop/](src/desktop) ([README](src/desktop/README.md)): boot and lock screen [boot.js](src/desktop/boot.js) + [boot-logic.js](src/desktop/boot-logic.js), campus [src/desktop/world/](src/desktop/world) (rooms [rooms.js](src/desktop/world/rooms.js), props [props.js](src/desktop/world/props.js), surfaces [surfaces.js](src/desktop/world/surfaces.js), textures [public/campus/](public/campus) built by [scripts/build-campus-textures.mjs](scripts/build-campus-textures.mjs), solids [src/shared/solids.js](src/shared/solids.js)), gem ledger [api/world/gems.js](api/world/gems.js) over [api/_lib/world-gems.js](api/_lib/world-gems.js) (migration `20261015000000_world_gems.sql`); previous homepage [pages/home.html](pages/home.html) `→ /classic` | Built and verified locally | Boots with a live log of real checks (GPU, site catalog, account, fonts, avatar, $THREE feed, gem ledger), locks with a greeting and live chips, then the visitor walks in as their avatar: a daylit campus of real walk-in buildings (physical sky and sun with soft shadows, CC0 Poly Haven surfaces, props streamed from the object library, walls and furniture as solids) with the home office (sit at the desk to open the desktop on the monitor, pick up the phone for Pocket, put on the headset for WebXR), the three.ws Exchange with a live ticker (Trenches), the Launchpad, the Forge, the Gallery, Agent Plaza, the Marketplace and a gem mine with server-rolled, rate-limited digs. Real registered agents stand on the campus in their own bodies ([world/cast.js](src/desktop/world/cast.js), [agents.js](src/desktop/world/agents.js), [talk.js](src/desktop/world/talk.js)): a greeter meets you at the gate, and walking up to any of them opens a conversation through its own `/api/chat` brain, with the one-tag `<agent-3d>` embed to put it on your own site. Taskbar, Start, widgets and snappable windows framing real three.ws pages in the CTRL Mica theme; icons on a snap grid, All Apps, Settings (profile, Arrival, accent, wallpaper, icon size), session in localStorage plus IndexedDB. Framed pages hide the site nav via `public/nav.js` (`tws-os:` frame name). Docs: [docs/desktop.md](docs/desktop.md). Tests: [tests/desktop-boot.test.js](tests/desktop-boot.test.js), [tests/world-places.test.js](tests/world-places.test.js), [tests/world-rooms.test.js](tests/world-rooms.test.js), [tests/world-props.test.js](tests/world-props.test.js), [tests/solids.test.js](tests/solids.test.js), [tests/world-ticker.test.js](tests/world-ticker.test.js), [tests/desktop-layout.test.js](tests/desktop-layout.test.js), [tests/desktop-page.test.js](tests/desktop-page.test.js); browser drives [scripts/desktop-world-smoke.mjs](scripts/desktop-world-smoke.mjs), [scripts/desktop-interact.mjs](scripts/desktop-interact.mjs) || Desktop widgets and assistant | Code [src/desktop/widgets/](src/desktop/widgets) ([README](src/desktop/widgets/README.md)): pure grid, catalog and formatting [logic.js](src/desktop/widgets/logic.js), shared feeds [data.js](src/desktop/widgets/data.js), renderers [render.js](src/desktop/widgets/render.js), desktop layer, gallery and board [index.js](src/desktop/widgets/index.js); assistant [src/desktop/assistant/](src/desktop/assistant) ([README](src/desktop/assistant/README.md)) | Built and verified locally | Eleven live widgets ($THREE, Weather, Clock, Calendar, New agents, Pulse, Launches, Platform, Headlines, System, Sticky note) in three sizes, pinned to a snap grid on the desktop (drag, edit mode, Add widget gallery with live previews) or on the widgets board with a greeting and a news column; feeds shared and paused while hidden, offline states with retry. The assistant streams `/api/chat`, opens desktop apps from `[[open:id]]` tags, and switches to any public agent's persona. Docs: [docs/desktop-widgets.md](docs/desktop-widgets.md). Tests: [tests/desktop-widgets.test.js](tests/desktop-widgets.test.js), [tests/desktop-assistant.test.js](tests/desktop-assistant.test.js) || Trenches Pulse (Solana + Robinhood Chain intelligence) | Service [services/pulse/](services/pulse) (vendored nirholas/pulse: firehose, scorer, API, Telegram newsletter), proxy [api/trenches.js](api/trenches.js) `→ /api/trenches`, page [pages/trenches.html](pages/trenches.html) + [src/trenches.js](src/trenches.js) `→ /trenches` | Built and verified locally; service deploy pending owner approval | Real pump.fun firehose over Solana WebSocket: launches, graduations, hottest tokens, runners, scored wallets. Offline upstream is a designed 503 state, never fabricated data. Docs: [docs/trenches.md](docs/trenches.md). Tests: [tests/trenches-api.test.js](tests/trenches-api.test.js) || Browse by goal (every feature grouped into twelve goals, search, pins, what-next strip) | [pages/everything.html](pages/everything.html), [src/everything.js](src/everything.js), [src/everything.css](src/everything.css), taxonomy [scripts/lib/feature-jobs.mjs](scripts/lib/feature-jobs.mjs), [public/next-steps.js](public/next-steps.js) | Live | `/everything` reads `public/features.json`, which `scripts/build-page-index.mjs` builds from `data/pages.json` plus the goal taxonomy, so a new page appears with no extra step. Also drives the goal labels in the ⌘K palette and the nav entry. Docs: [docs/everything.md](docs/everything.md). Tests: [tests/feature-jobs.test.js](tests/feature-jobs.test.js), [tests/next-steps.test.js](tests/next-steps.test.js) |diff --git a/data/changelog.json b/data/changelog.jsonindex d1de6c8c0..ffc2b8602 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,16 @@{"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security, desktop (desktop entries become the desktop app's release notes). `link` is optional and must be a live three.ws path.","entries": [+ {+ "date": "2026-10-11",+ "title": "The campus is now a real place: daylight, walk-in buildings, photographic surfaces and real props",+ "link": "/?world=1",+ "summary": "The 3D campus in front of the desktop is rebuilt to feel like walking through a real place rather than a dark game level. A physical sky and sun with soft shadows that follow you, hills on the horizon, a walled gate with lamps and a welcome sign, a lawn, concrete paths and a paved plaza. Every building is a room you walk into through its door: the brick office with a gabled roof, windows and a furnished desk; the marble-columned exchange with a ticker outside and over the dais inside; the forge with a glowing furnace; the gallery under a skylight, hanging the real avatars of the agents on the campus; a hillside mine with a timbered portal, rails and a cart; the launchpad with its rocket, gantry and crew cabin; a pergola plaza with a fountain; and a timber market hall with striped stalls. Walls, floors and roofs use CC0 photographic materials from Poly Haven, and trees, hedges, lamps, benches, bins, crates and barrels are real glTF models streamed from the three.ws object library, nearest first. Walls and furniture are solid for you and the agents, the camera never cuts through a wall, teleporting puts you at a building's door facing in, and quality adapts to the device (a software renderer always gets the lightest tier).",+ "tags": [+ "feature",+ "desktop"+ ]+ },{"date": "2026-10-11","title": "The desktop now looks and works like a real operating system",diff --git a/docs/desktop.md b/docs/desktop.mdindex 07f515028..37cc579d0 100644--- a/docs/desktop.md+++ b/docs/desktop.md@@ -64,6 +64,50 @@ World button brings you back to that place's doorstep, not the gate. Youravatar is the same default body and clip library the rest of the site uses(`/avatars/default.glb`, `/animations/manifest.json`).+### The grounds++The campus is a real place in daylight, not a dark floor with props on it.+The sky is a physical sky model lit by one sun (soft shadows that follow you),+the horizon is a ring of hills in haze, and a walled gate with lamps and a+welcome sign opens onto a concrete path that crosses a lawn to a paved plaza+round the office; paths lead from the plaza to every other door. Every+building is a room you walk into through an open door: the office (brick,+gabled roof, windows on three sides, a real desk with monitor, keyboard,+mouse, phone and headset), the exchange (marble columns, a porch, a ticker+board outside and a second one over the dais inside), the forge (brick, a+furnace that glows and flickers, an anvil and a workbench), the gallery+(skylight, seven framed pictures that hang the real avatars of the agents on+the campus) and the mine (a hillside cave with timbered portal, rails and a+cart around the five veins). The launchpad is a concrete pad with the rocket,+its gantry and a crew cabin; the plaza is a pergola with a fountain; the+market is a timber hall with striped stalls. The chase camera never clips+through a wall: it pulls in along the line to your avatar when a wall or the+hillside gets between you (`keepCameraInRoom` in `world/index.js`).++Surfaces are photographic. `public/campus/textures` holds colour, normal and+ARM (ambient occlusion, roughness, metal) maps for grass, paving, brick,+concrete, wood floor, roof tiles and rock, all CC0 from Poly Haven, downscaled+by `node scripts/build-campus-textures.mjs` and listed in+`public/campus/manifest.json` (which the world reads at runtime). Trees,+hedges, benches, lamps, bins, planters, crates, barrels and the rest are real+glTF models streamed from the three.ws object library (CC0 Poly Haven GLBs on+the R2 CDN); `world/props.js` is the placement list, with a byte budget per+tier (58 MB on desktop, 16 MB on a phone) and models loaded nearest-first from+your spawn so the gate is dressed before the far side of the campus.++Walls, columns, the desk, the furnace, the stalls and every prop are solids+your avatar and the agents slide around (`src/shared/solids.js`, unit tested+in `tests/solids.test.js`). The rooms, their doors, windows and roofs are pure+data in `world/rooms.js` (`tests/world-rooms.test.js` proves every door is+walkable, every arrival point stands outside the building at its door with+open air behind the camera, and no window sits on a wall the door is in).++Quality follows the device. `detectQualityTier` picks high (2048 px soft+shadows, normal maps, 8x anisotropy), medium or mobile (no shadows, no normal+maps), and a software rasteriser (SwiftShader, llvmpipe, Microsoft Basic+Render) always gets mobile so a headless browser or a VM stays responsive.+`?quality=high|medium|mobile` on the URL overrides the choice for testing.+### The agentsThe campus is populated by real registered agents, not extras. On entry thediff --git a/public/campus/README.md b/public/campus/README.mdnew file mode 100644index 000000000..6a0402a8b--- /dev/null+++ b/public/campus/README.md@@ -0,0 +1,17 @@+# Campus textures++PBR texture sets for the three.ws campus (`src/desktop/world/campus.js`): the+grass, paving, paths, walls, floors, rock and roofs the visitor walks on and+past. Every set is CC0 from [Poly Haven](https://polyhaven.com), resized to+1k and recompressed; `manifest.json` records the role, the real-world size of+one tile, the byte size and the source page of each set.++Rebuild (downloads the 1k JPGs, resizes with sharp, rewrites the manifest):++```+node scripts/build-campus-textures.mjs+```++The 3D props placed around the campus (desks, chairs, lamps, trees) stream at+runtime from the three.ws object library on R2, listed in+`src/desktop/world/props.js`; nothing from that library is checked in here.diff --git a/public/campus/manifest.json b/public/campus/manifest.jsonnew file mode 100644index 000000000..b265a1e81--- /dev/null+++ b/public/campus/manifest.json@@ -0,0 +1,96 @@+{+ "license": "CC0",+ "source": "https://polyhaven.com",+ "sets": {+ "leafy_grass": {+ "role": "ground",+ "metresPerTile": 3,+ "bytes": 356842,+ "diff": "/campus/textures/leafy_grass_diff.jpg",+ "nor": "/campus/textures/leafy_grass_nor.jpg",+ "arm": "/campus/textures/leafy_grass_arm.jpg",+ "page": "https://polyhaven.com/a/leafy_grass"+ },+ "patterned_paving": {+ "role": "plaza",+ "metresPerTile": 3,+ "bytes": 180868,+ "diff": "/campus/textures/patterned_paving_diff.jpg",+ "nor": "/campus/textures/patterned_paving_nor.jpg",+ "arm": "/campus/textures/patterned_paving_arm.jpg",+ "page": "https://polyhaven.com/a/patterned_paving"+ },+ "concrete_pavement_03": {+ "role": "path",+ "metresPerTile": 2.5,+ "bytes": 139748,+ "diff": "/campus/textures/concrete_pavement_03_diff.jpg",+ "nor": "/campus/textures/concrete_pavement_03_nor.jpg",+ "arm": "/campus/textures/concrete_pavement_03_arm.jpg",+ "page": "https://polyhaven.com/a/concrete_pavement_03"+ },+ "plastered_wall_04": {+ "role": "wall",+ "metresPerTile": 3,+ "bytes": 11125,+ "diff": "/campus/textures/plastered_wall_04_diff.jpg",+ "nor": "/campus/textures/plastered_wall_04_nor.jpg",+ "arm": "/campus/textures/plastered_wall_04_arm.jpg",+ "page": "https://polyhaven.com/a/plastered_wall_04"+ },+ "brick_wall_10": {+ "role": "brick",+ "metresPerTile": 2.5,+ "bytes": 203392,+ "diff": "/campus/textures/brick_wall_10_diff.jpg",+ "nor": "/campus/textures/brick_wall_10_nor.jpg",+ "arm": "/campus/textures/brick_wall_10_arm.jpg",+ "page": "https://polyhaven.com/a/brick_wall_10"+ },+ "wood_floor": {+ "role": "floor-wood",+ "metresPerTile": 2.5,+ "bytes": 115069,+ "diff": "/campus/textures/wood_floor_diff.jpg",+ "nor": "/campus/textures/wood_floor_nor.jpg",+ "arm": "/campus/textures/wood_floor_arm.jpg",+ "page": "https://polyhaven.com/a/wood_floor"+ },+ "marble_01": {+ "role": "floor-marble",+ "metresPerTile": 3,+ "bytes": 44508,+ "diff": "/campus/textures/marble_01_diff.jpg",+ "nor": "/campus/textures/marble_01_nor.jpg",+ "arm": "/campus/textures/marble_01_arm.jpg",+ "page": "https://polyhaven.com/a/marble_01"+ },+ "concrete_floor_01": {+ "role": "floor-concrete",+ "metresPerTile": 3,+ "bytes": 181536,+ "diff": "/campus/textures/concrete_floor_01_diff.jpg",+ "nor": "/campus/textures/concrete_floor_01_nor.jpg",+ "arm": "/campus/textures/concrete_floor_01_arm.jpg",+ "page": "https://polyhaven.com/a/concrete_floor_01"+ },+ "rock_wall_03": {+ "role": "rock",+ "metresPerTile": 4,+ "bytes": 242674,+ "diff": "/campus/textures/rock_wall_03_diff.jpg",+ "nor": "/campus/textures/rock_wall_03_nor.jpg",+ "arm": "/campus/textures/rock_wall_03_arm.jpg",+ "page": "https://polyhaven.com/a/rock_wall_03"+ },+ "grey_roof_01": {+ "role": "roof",+ "metresPerTile": 2.5,+ "bytes": 199067,+ "diff": "/campus/textures/grey_roof_01_diff.jpg",+ "nor": "/campus/textures/grey_roof_01_nor.jpg",+ "arm": "/campus/textures/grey_roof_01_arm.jpg",+ "page": "https://polyhaven.com/a/grey_roof_01"+ }+ }+}diff --git a/public/campus/textures/brick_wall_10_arm.jpg b/public/campus/textures/brick_wall_10_arm.jpgnew file mode 100644index 000000000..79588cd63Binary files /dev/null and b/public/campus/textures/brick_wall_10_arm.jpg differdiff --git a/public/campus/textures/brick_wall_10_diff.jpg b/public/campus/textures/brick_wall_10_diff.jpgnew file mode 100644index 000000000..9ab7de649Binary files /dev/null and b/public/campus/textures/brick_wall_10_diff.jpg differdiff --git a/public/campus/textures/brick_wall_10_nor.jpg b/public/campus/textures/brick_wall_10_nor.jpgnew file mode 100644index 000000000..75bc4a168Binary files /dev/null and b/public/campus/textures/brick_wall_10_nor.jpg differdiff --git a/public/campus/textures/concrete_floor_01_arm.jpg b/public/campus/textures/concrete_floor_01_arm.jpgnew file mode 100644index 000000000..9aea58630Binary files /dev/null and b/public/campus/textures/concrete_floor_01_arm.jpg differdiff --git a/public/campus/textures/concrete_floor_01_diff.jpg b/public/campus/textures/concrete_floor_01_diff.jpgnew file mode 100644index 000000000..a3c28613aBinary files /dev/null and b/public/campus/textures/concrete_floor_01_diff.jpg differdiff --git a/public/campus/textures/concrete_floor_01_nor.jpg b/public/campus/textures/concrete_floor_01_nor.jpgnew file mode 100644index 000000000..194ba5a7aBinary files /dev/null and b/public/campus/textures/concrete_floor_01_nor.jpg differdiff --git a/public/campus/textures/concrete_pavement_03_arm.jpg b/public/campus/textures/concrete_pavement_03_arm.jpgnew file mode 100644index 000000000..62b2a5606Binary files /dev/null and b/public/campus/textures/concrete_pavement_03_arm.jpg differdiff --git a/public/campus/textures/concrete_pavement_03_diff.jpg b/public/campus/textures/concrete_pavement_03_diff.jpgnew file mode 100644index 000000000..74c18501fBinary files /dev/null and b/public/campus/textures/concrete_pavement_03_diff.jpg differdiff --git a/public/campus/textures/concrete_pavement_03_nor.jpg b/public/campus/textures/concrete_pavement_03_nor.jpgnew file mode 100644index 000000000..46042b06cBinary files /dev/null and b/public/campus/textures/concrete_pavement_03_nor.jpg differdiff --git a/public/campus/textures/grey_roof_01_arm.jpg b/public/campus/textures/grey_roof_01_arm.jpgnew file mode 100644index 000000000..72d5898b4Binary files /dev/null and b/public/campus/textures/grey_roof_01_arm.jpg differdiff --git a/public/campus/textures/grey_roof_01_diff.jpg b/public/campus/textures/grey_roof_01_diff.jpgnew file mode 100644index 000000000..d4b4823fdBinary files /dev/null and b/public/campus/textures/grey_roof_01_diff.jpg differdiff --git a/public/campus/textures/grey_roof_01_nor.jpg b/public/campus/textures/grey_roof_01_nor.jpgnew file mode 100644index 000000000..717a52042Binary files /dev/null and b/public/campus/textures/grey_roof_01_nor.jpg differdiff --git a/public/campus/textures/leafy_grass_arm.jpg b/public/campus/textures/leafy_grass_arm.jpgnew file mode 100644index 000000000..f1311fa2eBinary files /dev/null and b/public/campus/textures/leafy_grass_arm.jpg differdiff --git a/public/campus/textures/leafy_grass_diff.jpg b/public/campus/textures/leafy_grass_diff.jpgnew file mode 100644index 000000000..64c950abcBinary files /dev/null and b/public/campus/textures/leafy_grass_diff.jpg differdiff --git a/public/campus/textures/leafy_grass_nor.jpg b/public/campus/textures/leafy_grass_nor.jpgnew file mode 100644index 000000000..13d823bfeBinary files /dev/null and b/public/campus/textures/leafy_grass_nor.jpg differdiff --git a/public/campus/textures/marble_01_arm.jpg b/public/campus/textures/marble_01_arm.jpgnew file mode 100644index 000000000..8502fadb6Binary files /dev/null and b/public/campus/textures/marble_01_arm.jpg differdiff --git a/public/campus/textures/marble_01_diff.jpg b/public/campus/textures/marble_01_diff.jpgnew file mode 100644index 000000000..3bda63bdaBinary files /dev/null and b/public/campus/textures/marble_01_diff.jpg differdiff --git a/public/campus/textures/marble_01_nor.jpg b/public/campus/textures/marble_01_nor.jpgnew file mode 100644index 000000000..86419ea4cBinary files /dev/null and b/public/campus/textures/marble_01_nor.jpg differdiff --git a/public/campus/textures/patterned_paving_arm.jpg b/public/campus/textures/patterned_paving_arm.jpgnew file mode 100644index 000000000..132994382Binary files /dev/null and b/public/campus/textures/patterned_paving_arm.jpg differdiff --git a/public/campus/textures/patterned_paving_diff.jpg b/public/campus/textures/patterned_paving_diff.jpgnew file mode 100644index 000000000..220e316cbBinary files /dev/null and b/public/campus/textures/patterned_paving_diff.jpg differdiff --git a/public/campus/textures/patterned_paving_nor.jpg b/public/campus/textures/patterned_paving_nor.jpgnew file mode 100644index 000000000..3754e66bfBinary files /dev/null and b/public/campus/textures/patterned_paving_nor.jpg differdiff --git a/public/campus/textures/plastered_wall_04_arm.jpg b/public/campus/textures/plastered_wall_04_arm.jpgnew file mode 100644index 000000000..aa96d6077Binary files /dev/null and b/public/campus/textures/plastered_wall_04_arm.jpg differdiff --git a/public/campus/textures/plastered_wall_04_diff.jpg b/public/campus/textures/plastered_wall_04_diff.jpgnew file mode 100644index 000000000..626bc946eBinary files /dev/null and b/public/campus/textures/plastered_wall_04_diff.jpg differdiff --git a/public/campus/textures/plastered_wall_04_nor.jpg b/public/campus/textures/plastered_wall_04_nor.jpgnew file mode 100644index 000000000..41eba4c84Binary files /dev/null and b/public/campus/textures/plastered_wall_04_nor.jpg differdiff --git a/public/campus/textures/rock_wall_03_arm.jpg b/public/campus/textures/rock_wall_03_arm.jpgnew file mode 100644index 000000000..effea7c89Binary files /dev/null and b/public/campus/textures/rock_wall_03_arm.jpg differdiff --git a/public/campus/textures/rock_wall_03_diff.jpg b/public/campus/textures/rock_wall_03_diff.jpgnew file mode 100644index 000000000..2b0ec3ac4Binary files /dev/null and b/public/campus/textures/rock_wall_03_diff.jpg differdiff --git a/public/campus/textures/rock_wall_03_nor.jpg b/public/campus/textures/rock_wall_03_nor.jpgnew file mode 100644index 000000000..27d9824a3Binary files /dev/null and b/public/campus/textures/rock_wall_03_nor.jpg differdiff --git a/public/campus/textures/wood_floor_arm.jpg b/public/campus/textures/wood_floor_arm.jpgnew file mode 100644index 000000000..23cb9c076Binary files /dev/null and b/public/campus/textures/wood_floor_arm.jpg differdiff --git a/public/campus/textures/wood_floor_diff.jpg b/public/campus/textures/wood_floor_diff.jpgnew file mode 100644index 000000000..28e5a1c66Binary files /dev/null and b/public/campus/textures/wood_floor_diff.jpg differdiff --git a/public/campus/textures/wood_floor_nor.jpg b/public/campus/textures/wood_floor_nor.jpgnew file mode 100644index 000000000..905839cbeBinary files /dev/null and b/public/campus/textures/wood_floor_nor.jpg differdiff --git a/public/changelog-recent.json b/public/changelog-recent.jsonindex 97eabc898..afbe364d5 100644--- a/public/changelog-recent.json+++ b/public/changelog-recent.json@@ -1,11 +1,11 @@{- "generated_at": "2026-10-11T07:59:53.860Z",+ "generated_at": "2026-10-11T09:50:28.630Z","generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json","site": {"name": "three.ws","url": "https://three.ws"},- "total": 3998,+ "total": 3999,"complete": false,"full_feed": "/changelog.json","entries": [@@ -292,6 +292,17 @@"desktop"]},+ {+ "date": "2026-10-11",+ "type": "update",+ "title": "The campus is now a real place: daylight, walk-in buildings, photographic surfaces and real props",+ "summary": "The 3D campus in front of the desktop is rebuilt to feel like walking through a real place rather than a dark game level. A physical sky and sun with soft shadows that follow you, hills on the horizon, a walled gate with lamps and a welcome sign, a lawn, concrete paths and a paved plaza. Every building is a room you walk into through its door: the brick office with a gabled roof, windows and a furnished desk; the marble-columned exchange with a ticker outside and over the dais inside; the forge with a glowing furnace; the gallery under a skylight, hanging the real avatars of the agents on the campus; a hillside mine with a timbered portal, rails and a cart; the launchpad with its rocket, gantry and crew cabin; a pergola plaza with a fountain; and a timber market hall with striped stalls. Walls, floors and roofs use CC0 photographic materials from Poly Haven, and trees, hedges, lamps, benches, bins, crates and barrels are real glTF models streamed from the three.ws object library, nearest first. Walls and furniture are solid for you and the agents, the camera never cuts through a wall, teleporting puts you at a building's door facing in, and quality adapts to the device (a software renderer always gets the lightest tier).",+ "link": "/?world=1",+ "tags": [+ "feature",+ "desktop"+ ]+ },{"date": "2026-10-11","type": "update",@@ -1535,16 +1546,6 @@"tags": ["fix"]- },- {- "date": "2026-10-09",- "type": "update",- "title": "Ready-made recipes for Grok Bot and other always-on agents",- "summary": "The 3D Studio and Grok connectors now offer guided prompts written for an agent that runs on a schedule with nobody watching: a daily 3D brief that turns the top trending topic into a model and a poster image, a themed asset pack that uses the free catalog first and generates only the gaps, a rigged avatar from a photo, a quick tour, and a read-only status report on your agents. Each one names the exact tools, never stops to ask a question, and reuses a retry key so a repeated run collects the original model instead of generating twice. A new list_my_agents tool lets a signed-in connector see which agents your account holds.",- "link": "/grok",- "tags": [- "feature"- ]}]}diff --git a/public/changelog.json b/public/changelog.jsonindex 6977d6135..cb405ef1e 100644--- a/public/changelog.json+++ b/public/changelog.json@@ -1,5 +1,5 @@{- "generated_at": "2026-10-11T07:59:53.836Z",+ "generated_at": "2026-10-11T09:50:28.599Z","generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json","site": {"name": "three.ws",@@ -289,6 +289,17 @@"desktop"]},+ {+ "date": "2026-10-11",+ "type": "update",+ "title": "The campus is now a real place: daylight, walk-in buildings, photographic surfaces and real props",+ "summary": "The 3D campus in front of the desktop is rebuilt to feel like walking through a real place rather than a dark game level. A physical sky and sun with soft shadows that follow you, hills on the horizon, a walled gate with lamps and a welcome sign, a lawn, concrete paths and a paved plaza. Every building is a room you walk into through its door: the brick office with a gabled roof, windows and a furnished desk; the marble-columned exchange with a ticker outside and over the dais inside; the forge with a glowing furnace; the gallery under a skylight, hanging the real avatars of the agents on the campus; a hillside mine with a timbered portal, rails and a cart; the launchpad with its rocket, gantry and crew cabin; a pergola plaza with a fountain; and a timber market hall with striped stalls. Walls, floors and roofs use CC0 photographic materials from Poly Haven, and trees, hedges, lamps, benches, bins, crates and barrels are real glTF models streamed from the three.ws object library, nearest first. Walls and furniture are solid for you and the agents, the camera never cuts through a wall, teleporting puts you at a building's door facing in, and quality adapts to the device (a software renderer always gets the lightest tier).",+ "link": "/?world=1",+ "tags": [+ "feature",+ "desktop"+ ]+ },{"date": "2026-10-11","type": "update",diff --git a/public/changelog.xml b/public/changelog.xmlindex b33abe19a..1f2e8b4f3 100644--- a/public/changelog.xml+++ b/public/changelog.xml@@ -230,6 +230,14 @@<category>feature</category><description>The campus is now populated by the ten most talked-to public agents on three.ws, each wearing its own avatar from its public record (five on a phone). The most popular one stands beside the gate path, turns to you as you walk in, waves and says hello through its own brain. Every agent idles, wanders a step, faces you when you come near and carries a name tag; walk up (or tap the tag) and press E to open a conversation that streams the agent's real reply, shows it as a speech bubble and can read it aloud. The panel opens the agent's profile as a window and hands you the one-tag embed that puts that exact agent, body and brain, on any web page. GET /api/agents/public now returns avatar_model_url for public and unlisted avatars.</description></item>+ <item>+ <title>The campus is now a real place: daylight, walk-in buildings, photographic surfaces and real props</title>+ <link>https://three.ws/?world=1</link>+ <guid isPermaLink="false">2026-10-11:The campus is now a real place: daylight, walk-in buildings, photographic surfaces and real props</guid>+ <pubDate>Sun, 11 Oct 2026 12:00:00 GMT</pubDate>+ <category>feature</category>+ <description>The 3D campus in front of the desktop is rebuilt to feel like walking through a real place rather than a dark game level. A physical sky and sun with soft shadows that follow you, hills on the horizon, a walled gate with lamps and a welcome sign, a lawn, concrete paths and a paved plaza. Every building is a room you walk into through its door: the brick office with a gabled roof, windows and a furnished desk; the marble-columned exchange with a ticker outside and over the dais inside; the forge with a glowing furnace; the gallery under a skylight, hanging the real avatars of the agents on the campus; a hillside mine with a timbered portal, rails and a cart; the launchpad with its rocket, gantry and crew cabin; a pergola plaza with a fountain; and a timber market hall with striped stalls. Walls, floors and roofs use CC0 photographic materials from Poly Haven, and trees, hedges, lamps, benches, bins, crates and barrels are real glTF models streamed from the three.ws object library, nearest first. Walls and furniture are solid for you and the agents, the camera never cuts through a wall, teleporting puts you at a building's door facing in, and quality adapts to the device (a software renderer always gets the lightest tier).</description>+ </item><item><title>The desktop behaves like a real computer</title><link>https://three.ws/docs/desktop</link>diff --git a/public/features.json b/public/features.jsonindex e20092298..4de089452 100644--- a/public/features.json+++ b/public/features.json@@ -1,5 +1,5 @@{- "generated_at": "2026-10-11T07:59:53.821Z",+ "generated_at": "2026-10-11T09:50:28.566Z","generated_by": "scripts/build-page-index.mjs from data/pages.json","site": {"name": "three.ws",diff --git a/scripts/build-campus-textures.mjs b/scripts/build-campus-textures.mjsnew file mode 100644index 000000000..55f02f2be--- /dev/null+++ b/scripts/build-campus-textures.mjs@@ -0,0 +1,74 @@+#!/usr/bin/env node+/**+ * Build the campus surface textures: the ground, paving, walls, floors, roof+ * and rock the homepage world (src/desktop/world/campus.js) is made of.+ *+ * Every set comes from Poly Haven (CC0, public domain, no attribution needed)+ * and is downscaled here so the committed files stay small: the colour map at+ * 1024 or 768 px, the normal and ARM (ambient occlusion / roughness / metal)+ * maps at 512 px, all JPEG. The ledger of what was built, and from where, is+ * written to public/campus/manifest.json and read by the world at runtime.+ *+ * Reproducible: `node scripts/build-campus-textures.mjs` rebuilds everything;+ * `--only=<name>` rebuilds one set.+ */+import { mkdirSync, writeFileSync, statSync } from 'node:fs';+import { join, dirname, resolve } from 'node:path';+import { fileURLToPath } from 'node:url';++const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');+const OUT = join(ROOT, 'public', 'campus');+const TEX = join(OUT, 'textures');+const DL = 'https://dl.polyhaven.org/file/ph-assets/Textures/jpg/1k';+const UA = { 'User-Agent': 'three.ws-campus-textures/1.0' };++/** The sets the campus uses, what each is for, and how large the colour map may be. */+export const SETS = [+ { name: 'leafy_grass', role: 'ground', diffuse: 1024, metresPerTile: 3 },+ { name: 'patterned_paving', role: 'plaza', diffuse: 1024, metresPerTile: 3 },+ { name: 'concrete_pavement_03', role: 'path', diffuse: 1024, metresPerTile: 2.5 },+ { name: 'plastered_wall_04', role: 'wall', diffuse: 768, metresPerTile: 3 },+ { name: 'brick_wall_10', role: 'brick', diffuse: 1024, metresPerTile: 2.5 },+ { name: 'wood_floor', role: 'floor-wood', diffuse: 1024, metresPerTile: 2.5 },+ { name: 'marble_01', role: 'floor-marble', diffuse: 768, metresPerTile: 3 },+ { name: 'concrete_floor_01', role: 'floor-concrete', diffuse: 768, metresPerTile: 3 },+ { name: 'rock_wall_03', role: 'rock', diffuse: 1024, metresPerTile: 4 },+ { name: 'grey_roof_01', role: 'roof', diffuse: 768, metresPerTile: 2.5 },+];++const MAPS = [+ { key: 'diff', suffix: 'diff', size: (s) => s.diffuse, quality: 78 },+ { key: 'nor', suffix: 'nor_gl', size: () => 512, quality: 82 },+ { key: 'arm', suffix: 'arm', size: () => 512, quality: 80 },+];++async function fetchBuf(url) {+ const r = await fetch(url, { headers: UA });+ if (!r.ok) throw new Error(`${r.status} ${url}`);+ return Buffer.from(await r.arrayBuffer());+}++const only = process.argv.find((a) => a.startsWith('--only='))?.slice(7);+const { default: sharp } = await import('sharp');+mkdirSync(TEX, { recursive: true });++const manifest = { license: 'CC0', source: 'https://polyhaven.com', sets: {} };+for (const set of SETS) {+ if (only && set.name !== only) continue;+ const files = {};+ let bytes = 0;+ for (const map of MAPS) {+ const src = await fetchBuf(`${DL}/${set.name}/${set.name}_${map.suffix}_1k.jpg`);+ const file = `${set.name}_${map.key}.jpg`;+ const out = join(TEX, file);+ await sharp(src).resize(map.size(set), map.size(set), { fit: 'fill' }).jpeg({ quality: map.quality, mozjpeg: true }).toFile(out);+ const size = statSync(out).size;+ bytes += size;+ files[map.key] = `/campus/textures/${file}`;+ }+ manifest.sets[set.name] = { role: set.role, metresPerTile: set.metresPerTile, bytes, ...files, page: `https://polyhaven.com/a/${set.name}` };+ process.stdout.write(`${set.name.padEnd(22)} ${(bytes / 1024).toFixed(0).padStart(5)} KB\n`);+}+writeFileSync(join(OUT, 'manifest.json'), `${JSON.stringify(manifest, null, '\t')}\n`);+const total = Object.values(manifest.sets).reduce((n, s) => n + s.bytes, 0);+console.log(`total ${(total / 1024 / 1024).toFixed(2)} MB → ${OUT}`);diff --git a/scripts/desktop-world-smoke.mjs b/scripts/desktop-world-smoke.mjsindex 5956df2a2..c41f9803a 100644--- a/scripts/desktop-world-smoke.mjs+++ b/scripts/desktop-world-smoke.mjs@@ -15,7 +15,8 @@ page.on('console', (m) => m.type() === 'error' && !/Failed to load resource/.tespage.on('pageerror', (e) => problems.push(`pageerror: ${e.message}`));page.on('requestfailed', (r) => !/ERR_ABORTED/.test(r.failure()?.errorText || '') && problems.push(`failed: ${r.url()}`));page.on('response', (r) => r.status() >= 500 && problems.push(`http ${r.status()}: ${r.url()}`));-const shot = (n) => shots && page.screenshot({ path: `${shots}/${n}.png` });+// 120 s: right after entry the props and textures are still uploading, and a SwiftShader frame can take seconds.+const shot = (n) => shots && page.screenshot({ path: `${shots}/${n}.png`, timeout: 120_000 });const text = (sel) => page.locator(sel).first().textContent().then((t) => (t || '').trim());// `?world=1` asks for the campus arrival whichever entry answers at `/`.@@ -68,11 +69,13 @@ if (tags.length) {await page.waitForTimeout(500);}-// Run to the desk (22 m at run speed) and watch the prompt arm.-await page.mouse.click(720, 450);+// Run in through the door to the desk and watch the prompt arm. Keys go to the world once no+// field has focus; a click would be a tap, and a tap on the nearest agent opens its talk panel.+await page.evaluate(() => document.activeElement?.blur());await page.keyboard.down('Shift');await page.keyboard.down('w');-await page.waitForFunction(() => /sit down/i.test(document.querySelector('.wd-prompt')?.textContent || ''), null, { timeout: 15_000 }).catch(() => {});+// 90 s: near the monitor the live desktop cast drops a SwiftShader loop to ~1 fps, and the frame clamp makes the run slow-motion.+await page.waitForFunction(() => /sit down/i.test(document.querySelector('.wd-prompt')?.textContent || ''), null, { timeout: 90_000 }).catch(() => {});await page.keyboard.up('w');await page.keyboard.up('Shift');await page.waitForTimeout(400);@@ -111,19 +114,20 @@ console.log('returned near:', await text('.wd-where'));await page.click('.wd-place:has-text("workstation")').catch(() => {});await page.waitForTimeout(600);await page.keyboard.down('w');-await page.waitForFunction(() => /sit down/i.test(document.querySelector('.wd-prompt')?.textContent || ''), null, { timeout: 6000 }).catch(() => {});+await page.waitForFunction(() => /sit down/i.test(document.querySelector('.wd-prompt')?.textContent || ''), null, { timeout: 90_000 }).catch(() => {});console.log('prompt back at desk:', await text('.wd-prompt'));-// Slide round the desk's keep-out disc to the phone side.-await page.keyboard.down('d');-await page.waitForFunction(() => /phone/i.test(document.querySelector('.wd-prompt')?.textContent || ''), null, { timeout: 6000 }).catch(() => {});-await page.keyboard.up('d');+// Slide left round the desk's keep-out disc to the phone side (you face the desk from the door; the headset is on your right).+await page.keyboard.down('a');+await page.waitForFunction(() => /phone/i.test(document.querySelector('.wd-prompt')?.textContent || ''), null, { timeout: 60_000 }).catch(() => {});+await page.keyboard.up('a');await page.keyboard.up('w');console.log('prompt near phone:', await text('.wd-prompt'));if (/phone/i.test(await text('.wd-prompt'))) {await page.keyboard.press('e');- await page.waitForSelector('.wd-phone.is-open, .wd-phone:not([hidden])', { timeout: 8000 });- await page.waitForTimeout(2500);- console.log('phone iframe:', await page.locator('.wd-phone iframe').getAttribute('src'));+ await page.waitForSelector('.wd-phone:not([hidden])', { timeout: 8000 });+ // The pocket boots its own scene inside the iframe; under SwiftShader that stalls the page for ~25 s, so give it a minute.+ await page.waitForFunction(() => document.querySelector('.wd-phone iframe')?.contentDocument?.readyState === 'complete', null, { timeout: 60_000 });+ console.log('phone iframe:', await page.evaluate(() => document.querySelector('.wd-phone iframe')?.src));await shot('7-phone');await page.keyboard.press('Escape');await page.waitForTimeout(500);diff --git a/src/desktop/README.md b/src/desktop/README.mdindex c38f59305..af3a74278 100644--- a/src/desktop/README.md+++ b/src/desktop/README.md@@ -18,7 +18,11 @@ The web desktop served at `/` (page: `pages/desktop.html`). See| `icons.js` | Stroke glyphs || `theme.css`, `desktop.css`, `styles.css` | CTRL tokens; shell and window styles; Snap layouts, Snap assist, peek and the Fluent, Aqua and Classic skins || `world/index.js` | The campus controller: mounts the 3D world over the desktop, input, proximity prompts, sit-down and walk-in transitions, the phone, the VR headset, mining, the frame loop |-| `world/campus.js` | The scene: ground, office desk, exchange, launchpad, mine, forge, gallery, plaza, market, lighting |+| `world/campus.js` | The scene: sky, sun and shadows, the grounds (lawn, gate, paths, plaza, hills), every building as a walk-in room with photographic surfaces, the furnished office, the exchange, the launchpad, the cave mine, the forge, the gallery, the plaza, the market, quality tiers |+| `world/rooms.js` | Pure room data: footprint, walls, doors, windows, roofs, columns, door and arrival points, wall solids (unit tested) |+| `world/props.js` | Pure prop placement: trees, hedges, lamps, benches, bins, crates and the rest from the three.ws object library, per-tier byte budget, prop solids (unit tested) |+| `world/prop-loader.js` | Streams the placed GLBs nearest-first from the spawn, shares geometry between instances, hands each prop its hit id |+| `world/surfaces.js` | PBR surface materials (colour, normal, ARM) from `public/campus/manifest.json`, tiled in metres || `world/places.js` | Pure campus map: places, keep-outs, veins, desk objects, trigger radii, stand points (unit tested) || `world/cast.js` | Pure rules for the agents on the campus: who qualifies (real name, public GLB), where they stand, prompt distances, the SSE parser, the embed snippet and the grounding prompt (unit tested) || `world/agents.js` | Spawns the cast from `/api/agents/public?avatar=1`, each in its own body: wander, notice and face the visitor, the greeter's wave and hello, name tags and speech bubbles, the streaming `/api/chat` client |diff --git a/src/desktop/world/agents.js b/src/desktop/world/agents.jsindex 51f63cf7c..240350d6c 100644--- a/src/desktop/world/agents.js+++ b/src/desktop/world/agents.js@@ -11,6 +11,7 @@import { Box3, Group, Vector3 } from 'three';import { buildAvatar, CLIP_IDLE, CLIP_WALK, getAllEmoteDefs, loadManifest, newAnim, releaseAvatar } from '../../game/avatar-rig.js';import { log } from '../../shared/log.js';+import { insideSolids } from '../../shared/solids.js';import { CAST_MAX, GREET_RANGE, arrivalMessage, castSpots, groundingPrompt, parseSse, pickCast, pickGreeter } from './cast.js';import { PLACES, placeById } from './places.js';@@ -170,8 +171,7 @@ export function createAgents({ scene, tagsEl, solids, isTouch, reducedMotion, vi// ---- behaviour ----function blocked(x, z) {- for (const s of solids) if (Math.hypot(x - s.group.position.x, z - s.group.position.z) < s.keepout + 0.6) return true;- return false;+ return insideSolids(x, z, solids, 0.6);}function pickStroll(m) {for (let i = 0; i < 6; i++) {@@ -365,6 +365,10 @@ export function createAgents({ scene, tagsEl, solids, isTouch, reducedMotion, vifunction byId(id) {return members.find((m) => m.member.id === id) || null;}+ /** Public avatar portraits of the agents on campus, for the gallery walls. */+ function thumbs() {+ return members.filter((m) => m.ready && m.member.thumb).map((m) => ({ id: m.member.id, name: m.member.name, url: m.member.thumb }));+ }function hold(id, on) {const m = byId(id);if (m) m.held = on;@@ -385,6 +389,7 @@ export function createAgents({ scene, tagsEl, solids, isTouch, reducedMotion, viload,update,positions,+ thumbs,byId,hold,say: (id, text) => say(byId(id), text),diff --git a/src/desktop/world/campus.js b/src/desktop/world/campus.jsindex ef2b33744..33fd756b3 100644--- a/src/desktop/world/campus.js+++ b/src/desktop/world/campus.js@@ -1,19 +1,24 @@-// The campus: the 3D place the visitor walks through before (and around) the-// desktop. Low-poly, emissive, one hemisphere light and one directional light,-// so it holds 60fps on integrated GPUs. Every building here maps to a real-// surface in places.js; the exchange board, the monitor and the mine show live-// data supplied by the controller (index.js).+// The campus: the real place the visitor walks through before (and around)+// the desktop. Daylight under a physical sky, grass and paving underfoot,+// buildings with walls, doors and windows you walk through, furniture and+// lamps scanned from the real world (props.js), and live data on the exchange+// board, the monitor and the mine supplied by the controller (index.js).+// Room specs live in rooms.js, surfaces in surfaces.js; this file turns them+// into meshes and keeps the contract index.js relies on.import {BoxGeometry,+ CanvasTexture,CircleGeometry,Color,ConeGeometry,CylinderGeometry,DirectionalLight,+ DoubleSide,Fog,Group,HemisphereLight,+ MathUtils,Mesh,MeshBasicMaterial,MeshStandardMaterial,@@ -23,142 +28,329 @@ import {PointLight,Raycaster,RingGeometry,+ SRGBColorSpace,Scene,+ Shape,+ ShapeGeometry,+ SphereGeometry,+ TextureLoader,TorusGeometry,Vector2,Vector3,- CanvasTexture,- SRGBColorSpace,- DoubleSide,- ACESFilmicToneMapping,} from 'three';+import { Sky } from 'three/examples/jsm/objects/Sky.js';import { createRenderer } from '../../webgl-support.js';-import { makeLabelSprite, makeSkyDome, makeStars } from '../../docs-world/world.js';-import { CAMPUS_RADIUS, DESK_OBJECTS, PLACES, VEINS, facingOf as facing, placeById } from './places.js';+import { applyCinematicDefaults, detectQualityTier, loadEnvironment } from '../../shared/cinematic-render.js';+import { disposeGltfLoader } from '../../loaders/gltf.js';+import { boxSolid } from '../../shared/solids.js';+import { log } from '../../shared/log.js';+import { CAMPUS_RADIUS, DESK_OBJECTS, PLACES, SPAWN, VEINS, placeById } from './places.js';+import { ROOMS, WALL, allRoomSolids, columnsOf, doorPoints, roomFrame, wallsOf } from './rooms.js';+import { placeProps, propSolids } from './props.js';+import { createPropLoader } from './prop-loader.js';+import { createSurfaces, tileBox, tilePlane } from './surfaces.js';import { GEMS } from '../../../api/_lib/world-gems.js';-const BG = 0x050505;+const HORIZON = 0xd3dfea;const VIOLET = 0xc4b5fd;+const SUN_ELEVATION = 38;+const SUN_AZIMUTH = 150;+const GATE_Z = 38;+const QUALITY_PARAM = 'quality';const hueColor = (hue, l = 0.62) => new Color().setHSL(hue / 360, 0.6, l);const hex = (c) => `#${c.getHexString()}`;-const std = (o) => new MeshStandardMaterial({ roughness: 0.78, metalness: 0.12, ...o });const glow = (color, intensity = 1) => new MeshBasicMaterial({ color: new Color(color).multiplyScalar(intensity), toneMapped: false });+const PI = Math.PI;++/* ------------------------------------------------------------- materials */-function groundTexture() {- const size = 2048;+function sharedMaterials() {+ return {+ wood: std({ color: 0x7a5636, roughness: 0.7 }),+ darkWood: std({ color: 0x3e2a1c, roughness: 0.65 }),+ paint: std({ color: 0x3a3a3f, roughness: 0.5, metalness: 0.3 }),+ steel: std({ color: 0x8e9299, roughness: 0.35, metalness: 0.85 }),+ darkSteel: std({ color: 0x2d2f35, roughness: 0.45, metalness: 0.7 }),+ stone: std({ color: 0xd9d4c8, roughness: 0.8 }),+ white: std({ color: 0xf2f1ec, roughness: 0.6 }),+ glass: new MeshStandardMaterial({ color: 0xcfe4ff, roughness: 0.05, metalness: 0.1, transparent: true, opacity: 0.32, side: DoubleSide, depthWrite: false }),+ canvasStripe: null,+ };+}++/** A physical sign board: painted panel, white lettering, violet rule. */+function signTexture(title, sub, accent = '#c4b5fd') {const canvas = document.createElement('canvas');- canvas.width = size;- canvas.height = size;+ canvas.width = 1024;+ canvas.height = 320;const g = canvas.getContext('2d');- const c = size / 2;- const px = (m) => (m / CAMPUS_RADIUS) * c; // metres to pixels-- const base = g.createRadialGradient(c, c, 0, c, c, c);- base.addColorStop(0, '#0d0d12');- base.addColorStop(0.6, '#08080b');- base.addColorStop(1, '#050505');- g.fillStyle = base;- g.fillRect(0, 0, size, size);-- // Hairline grid, the classic site's background motif.- g.strokeStyle = 'rgba(255,255,255,0.045)';- g.lineWidth = 1.5;- for (let m = -CAMPUS_RADIUS; m <= CAMPUS_RADIUS; m += 2) {- g.beginPath();- g.moveTo(c + px(m), 0);- g.lineTo(c + px(m), size);- g.stroke();- g.beginPath();- g.moveTo(0, c + px(m));- g.lineTo(size, c + px(m));- g.stroke();- }-- // Paths from the gate (spawn) to the office and from the office to every place.- const office = placeById('office');- const path = (ax, az, bx, bz, w, a) => {- g.strokeStyle = `rgba(196,181,253,${a})`;- g.lineWidth = px(w);- g.lineCap = 'round';- g.beginPath();- g.moveTo(c + px(ax), c + px(az));- g.lineTo(c + px(bx), c + px(bz));- g.stroke();- };- path(0, CAMPUS_RADIUS - 4, office.x, office.z + 4, 3.2, 0.16);- for (const p of PLACES) {- if (p.id === 'office') continue;- path(office.x, office.z, p.x, p.z, 2.2, 0.1);+ g.fillStyle = '#1b1b20';+ g.fillRect(0, 0, 1024, 320);+ g.fillStyle = accent;+ g.fillRect(64, 236, 896, 6);+ g.fillStyle = '#f5f5f7';+ g.textAlign = 'center';+ g.textBaseline = 'middle';+ g.font = '600 118px system-ui, -apple-system, "Segoe UI", sans-serif';+ g.fillText(title, 512, sub ? 120 : 160, 920);+ if (sub) {+ g.fillStyle = 'rgba(245,245,247,0.78)';+ g.font = '400 52px system-ui, -apple-system, "Segoe UI", sans-serif';+ g.fillText(sub, 512, 196, 920);}- // Plaza ring around the office.- g.strokeStyle = 'rgba(196,181,253,0.14)';- g.lineWidth = px(0.5);- g.beginPath();- g.arc(c + px(office.x), c + px(office.z), px(7), 0, Math.PI * 2);- g.stroke();-const tex = new CanvasTexture(canvas);tex.colorSpace = SRGBColorSpace;tex.anisotropy = 8;return tex;}-function lamp(x, z, hue = 262) {+function signBoard(title, sub, accent, w = 3.2) {+ const tex = signTexture(title, sub, accent);+ const board = new Mesh(new PlaneGeometry(w, w * 0.3125), new MeshStandardMaterial({ map: tex, emissive: 0xffffff, emissiveMap: tex, emissiveIntensity: 0.3, roughness: 0.55 }));+ const back = new Mesh(new BoxGeometry(w + 0.08, w * 0.3125 + 0.08, 0.05), std({ color: 0x141418, roughness: 0.6 }));+ back.position.z = -0.03;const g = new Group();- const post = new Mesh(new CylinderGeometry(0.05, 0.07, 3.2, 8), std({ color: 0x1a1a1f, metalness: 0.5 }));- post.position.y = 1.6;- const head = new Mesh(new BoxGeometry(0.5, 0.12, 0.5), glow(hueColor(hue, 0.7), 1.4));- head.position.y = 3.2;- g.add(post, head);- g.position.set(x, 0, z);+ g.add(back, board);return g;}-/* ---------------------------------------------------------------- office */+/** A sign on a post, for the places without a wall to hang one on. */+function signPost(title, sub, accent, mats) {+ const g = new Group();+ const post = new Mesh(new CylinderGeometry(0.04, 0.05, 2.6, 10), mats.paint);+ post.position.y = 1.3;+ const board = signBoard(title, sub, accent, 2.2);+ board.position.y = 2.3;+ g.add(post, board);+ return g;+}++/** Four strips of painted timber around an opening. */+function frameAround(w, h, depth, mat, t = 0.08) {+ const g = new Group();+ const side = new BoxGeometry(t, h + t * 2, depth);+ const top = new BoxGeometry(w + t * 2, t, depth);+ const l = new Mesh(side, mat);+ l.position.x = -w / 2 - t / 2;+ const r = new Mesh(side, mat);+ r.position.x = w / 2 + t / 2;+ const u = new Mesh(top, mat);+ u.position.y = h / 2 + t / 2;+ const d = new Mesh(top, mat);+ d.position.y = -h / 2 - t / 2;+ g.add(l, r, u, d);+ return g;+}++/* ---------------------------------------------------------- the shells */++const WALL_FRAMES = {+ front: (r) => ({ x: 0, z: r.d / 2, yaw: 0, inward: -1 }),+ back: (r) => ({ x: 0, z: -r.d / 2, yaw: 0, inward: 1 }),+ left: (r) => ({ x: -r.w / 2, z: 0, yaw: PI / 2, inward: 1 }),+ right: (r) => ({ x: r.w / 2, z: 0, yaw: PI / 2, inward: -1 }),+};++/**+ * Walls, floor, ceiling and roof of one room in its local frame. Returns the+ * group plus the meshes the camera must not pass through.+ */+function buildShell(room, surfaces, mats, { shadows }) {+ const g = new Group();+ const occluders = [];+ const wallMat = surfaces.material(room.wall);+ const wallTile = surfaces.metresPerTile(room.wall);+ const addShadow = (m, cast = true) => {+ m.castShadow = cast && shadows;+ m.receiveShadow = true;+ return m;+ };++ for (const wall of wallsOf(room)) {+ const frame = WALL_FRAMES[wall.side](room);+ const wg = new Group();+ wg.position.set(frame.x, 0, frame.z);+ wg.rotation.y = frame.yaw;+ for (const p of wall.pieces) {+ const hgt = p.y1 - p.y0;+ const geom = tileBox(new BoxGeometry(p.len, hgt, WALL), p.len, hgt, WALL, wallTile);+ const m = addShadow(new Mesh(geom, wallMat));+ m.position.set(wall.side === 'left' || wall.side === 'right' ? p.z : p.x, p.y0 + hgt / 2, 0);+ wg.add(m);+ occluders.push(m);+ }+ for (const o of wall.openings) {+ if (o.kind === 'window') {+ const pane = new Mesh(new PlaneGeometry(o.w, o.y1 - o.y0), mats.glass);+ pane.position.set(o.at, (o.y0 + o.y1) / 2, 0);+ const fr = frameAround(o.w, o.y1 - o.y0, WALL + 0.06, mats.paint);+ fr.position.copy(pane.position);+ const sill = new Mesh(new BoxGeometry(o.w + 0.3, 0.06, WALL + 0.2), mats.stone);+ sill.position.set(o.at, o.y0 - 0.03, 0);+ wg.add(pane, fr, sill);+ } else {+ const fr = frameAround(o.w, o.y1, WALL + 0.06, mats.darkWood, 0.1);+ fr.position.set(o.at, o.y1 / 2, 0);+ wg.add(fr);+ if (room.kind !== 'cave') {+ // The door stands open, swung inward on the left jamb.+ const pivot = new Group();+ pivot.position.set(o.at - o.w / 2, 0, 0);+ const leaf = addShadow(new Mesh(new BoxGeometry(o.w * 0.96, o.y1 * 0.985, 0.05), mats.darkWood));+ leaf.position.set((o.w * 0.96) / 2, (o.y1 * 0.985) / 2, 0);+ const handle = new Mesh(new CylinderGeometry(0.012, 0.012, 0.12, 8), mats.steel);+ handle.rotation.z = PI / 2;+ handle.position.set(o.w * 0.96 - 0.1, 1.0, -0.04);+ pivot.add(leaf, handle);+ pivot.rotation.y = -frame.inward * 1.72;+ wg.add(pivot);+ }+ const threshold = new Mesh(new BoxGeometry(o.w + 0.2, 0.02, WALL + 0.3), mats.stone);+ threshold.position.set(o.at, 0.03, 0);+ wg.add(threshold);+ }+ }+ g.add(wg);+ }++ // Floor and ceiling.+ const floorRole = room.floor === 'rock' ? 'rock' : `floor-${room.floor}`;+ const floor = new Mesh(tilePlane(new PlaneGeometry(room.w, room.d), room.w, room.d, surfaces.metresPerTile(floorRole)), surfaces.material(floorRole));+ floor.rotation.x = -PI / 2;+ floor.position.y = 0.025;+ floor.receiveShadow = true;+ g.add(floor);+ const ceilRole = room.kind === 'cave' ? 'rock' : 'wall';+ const ceiling = new Mesh(tilePlane(new PlaneGeometry(room.w, room.d), room.w, room.d, surfaces.metresPerTile(ceilRole)), surfaces.material(ceilRole));+ ceiling.rotation.x = PI / 2;+ ceiling.position.y = room.h - 0.02;+ g.add(ceiling);+ occluders.push(ceiling);++ // Roof.+ if (room.kind === 'room') {+ const roof = room.roof === 'flat' || room.skylight ? flatRoof(room, surfaces, mats, addShadow) : gableRoof(room, surfaces, mats, addShadow);+ g.add(roof);+ roof.traverse((m) => m.isMesh && occluders.push(m));+ }+ return { group: g, occluders };+}-function buildOffice(place, screenMaterial) {+export function gableRoof(room, surfaces, mats, addShadow) {const g = new Group();+ const pitch = MathUtils.degToRad(26);+ const over = 0.45;+ const half = room.d / 2 + over;+ const run = half / Math.cos(pitch);+ const rise = half * Math.tan(pitch);+ const roofMat = surfaces.material('roof');+ for (const s of [-1, 1]) {+ const slab = addShadow(new Mesh(tileBox(new BoxGeometry(room.w + over * 2, 0.16, run), room.w + over * 2, 0.16, run, surfaces.metresPerTile('roof')), roofMat));+ slab.position.set(0, room.h + rise / 2 + 0.06, (s * half) / 2);+ // +pitch for the +z slab and -pitch for the -z slab: each drops from the ridge to its own eave.+ slab.rotation.x = s * pitch;+ g.add(slab);+ }+ const ridge = new Mesh(new BoxGeometry(room.w + over * 2 + 0.1, 0.12, 0.3), mats.darkSteel);+ ridge.position.set(0, room.h + rise + 0.1, 0);+ g.add(ridge);+ // Gable ends close the triangle under each slope.+ const shape = new Shape();+ shape.moveTo(-room.d / 2, 0);+ shape.lineTo(room.d / 2, 0);+ shape.lineTo(0, rise);+ shape.closePath();+ for (const s of [-1, 1]) {+ const end = new Mesh(new ShapeGeometry(shape), new MeshStandardMaterial({ color: surfaces.material(room.wall).color, roughness: 0.85, side: DoubleSide }));+ end.rotation.y = PI / 2;+ end.position.set(s * (room.w / 2 - WALL / 2 - 0.01), room.h, 0);+ end.receiveShadow = true;+ g.add(end);+ }+ // Eaves boards.+ for (const s of [-1, 1]) {+ const fascia = new Mesh(new BoxGeometry(room.w + over * 2, 0.18, 0.05), mats.white);+ fascia.position.set(0, room.h - 0.02, s * (room.d / 2 + over));+ g.add(fascia);+ }+ return g;+}++function flatRoof(room, surfaces, mats, addShadow) {+ const g = new Group();+ const over = 0.3;+ const W = room.w + over * 2;+ const D = room.d + over * 2;+ const roofMat = surfaces.material('roof');+ const tile = surfaces.metresPerTile('roof');+ const y = room.h + 0.12;+ if (room.skylight) {+ const hole = 2.6;+ const side = (W - hole) / 2;+ const parts = [+ [-(hole / 2 + side / 2), 0, side, D],+ [hole / 2 + side / 2, 0, side, D],+ [0, -(hole / 2 + (D - hole) / 4), hole, (D - hole) / 2],+ [0, hole / 2 + (D - hole) / 4, hole, (D - hole) / 2],+ ];+ for (const [x, z, w, d] of parts) {+ const m = addShadow(new Mesh(tileBox(new BoxGeometry(w, 0.24, d), w, 0.24, d, tile), roofMat));+ m.position.set(x, y, z);+ g.add(m);+ }+ const pane = new Mesh(new PlaneGeometry(hole, hole), mats.glass);+ pane.rotation.x = -PI / 2;+ pane.position.y = y + 0.1;+ const fr = frameAround(hole, hole, 0.1, mats.paint, 0.1);+ fr.rotation.x = -PI / 2;+ fr.position.y = y + 0.1;+ g.add(pane, fr);+ } else {+ const m = addShadow(new Mesh(tileBox(new BoxGeometry(W, 0.24, D), W, 0.24, D, tile), roofMat));+ m.position.y = y;+ g.add(m);+ }+ // Parapet.+ const lip = new Mesh(new BoxGeometry(W + 0.1, 0.2, 0.1), mats.stone);+ lip.position.set(0, y + 0.2, D / 2);+ const lip2 = lip.clone();+ lip2.position.z = -D / 2;+ const lip3 = new Mesh(new BoxGeometry(0.1, 0.2, D), mats.stone);+ lip3.position.set(W / 2, y + 0.2, 0);+ const lip4 = lip3.clone();+ lip4.position.x = -W / 2;+ g.add(lip, lip2, lip3, lip4);+ return g;+}++/** Hang a sign over the front door, on the outside face of the front wall. */+function doorSign(room, place, title = place.title, sub = place.sub) {+ const h = Math.min(0.8, room.h - room.door.h - 0.25);+ const sign = signBoard(title, sub, hex(hueColor(place.hue, 0.7)), h / 0.3125);+ sign.position.set(room.door.at, room.door.h + 0.15 + h / 2, room.d / 2 + WALL / 2 + 0.04);+ return sign;+}++/* ---------------------------------------------------------------- office */++function buildOffice(room, place, screenMaterial, surfaces, mats, opts) {+ const shell = buildShell(room, surfaces, mats, opts);+ const g = shell.group;const col = hueColor(place.hue);+ const TOP = 0.79; // the real desk's top (props.js: metal_office_desk)- // Floor slab and a back wall carrying the wordmark: the "room" is open so- // the camera can orbit freely.- const slab = new Mesh(new BoxGeometry(9, 0.18, 7), std({ color: 0x0f0f14, roughness: 0.6 }));- slab.position.y = 0.09;- g.add(slab);- const rim = new Mesh(new RingGeometry(5.3, 5.42, 64), glow(col, 0.6));- rim.rotation.x = -Math.PI / 2;- rim.position.y = 0.02;- g.add(rim);-- const wall = new Mesh(new BoxGeometry(9, 4.2, 0.25), std({ color: 0x0a0a0d }));- wall.position.set(0, 2.1, -3.4);- g.add(wall);- const brand = makeLabelSprite('three.ws', 'The 3D agent layer of the internet', hex(col), 1.1);- brand.position.set(0, 3.2, -3.1);+ const brand = signBoard('three.ws', 'The 3D agent layer of the internet', hex(col), 3.6);+ brand.position.set(0, 2.25, -room.d / 2 + WALL / 2 + 0.04);g.add(brand);- // A thin violet strip at the wall foot reads as the site's hairline motif.- const strip = new Mesh(new BoxGeometry(9, 0.04, 0.02), glow(col, 1.2));- strip.position.set(0, 0.2, -3.26);- g.add(strip);-- // Desk.- const top = new Mesh(new BoxGeometry(2.6, 0.06, 1.1), std({ color: 0x15151a, roughness: 0.4, metalness: 0.3 }));- top.position.set(0, 0.76, -0.5);- g.add(top);- for (const sx of [-1.15, 1.15]) {- const leg = new Mesh(new BoxGeometry(0.08, 0.74, 0.9), std({ color: 0x111115 }));- leg.position.set(sx, 0.37, -0.5);- g.add(leg);- }// Monitor: stand, bezel and the live screen plane.const mon = DESK_OBJECTS.find((o) => o.id === 'monitor');- const stand = new Mesh(new CylinderGeometry(0.035, 0.05, 0.22, 10), std({ color: 0x1c1c22, metalness: 0.5 }));- stand.position.set(mon.dx, 0.9, mon.dz);- const foot = new Mesh(new CylinderGeometry(0.22, 0.24, 0.02, 20), std({ color: 0x1c1c22, metalness: 0.5 }));- foot.position.set(mon.dx, 0.8, mon.dz);+ const stand = new Mesh(new CylinderGeometry(0.035, 0.05, 0.3, 10), mats.darkSteel);+ stand.position.set(mon.dx, TOP + 0.15, mon.dz);+ const foot = new Mesh(new CylinderGeometry(0.22, 0.24, 0.02, 20), mats.darkSteel);+ foot.position.set(mon.dx, TOP + 0.01, mon.dz);const bezel = new Mesh(new BoxGeometry(1.44, 0.84, 0.04), std({ color: 0x0b0b0e, roughness: 0.3, metalness: 0.4 }));bezel.position.set(mon.dx, 1.42, mon.dz);const screen = new Mesh(new PlaneGeometry(1.36, 0.765), screenMaterial);@@ -166,60 +358,59 @@ function buildOffice(place, screenMaterial) {screen.userData.hit = { type: 'object', id: 'monitor' };bezel.userData.hit = screen.userData.hit;g.add(stand, foot, bezel, screen);- const screenLight = new PointLight(0x9d8cff, 0.9, 4, 2);+ const screenLight = new PointLight(0x9d8cff, 0.6, 3, 2);screenLight.position.set(mon.dx, 1.5, mon.dz + 0.6);g.add(screenLight);- // Keyboard.- const kb = new Mesh(new BoxGeometry(0.62, 0.025, 0.2), std({ color: 0x18181d, roughness: 0.5 }));- kb.position.set(0, 0.8, -0.1);- g.add(kb);+ // Keyboard and mouse.+ const kb = new Mesh(new BoxGeometry(0.44, 0.02, 0.15), std({ color: 0x1c1c21, roughness: 0.5 }));+ kb.position.set(0, TOP + 0.01, -0.12);+ const mouse = new Mesh(new SphereGeometry(0.035, 12, 8), std({ color: 0x1c1c21, roughness: 0.4 }));+ mouse.scale.set(1, 0.6, 1.5);+ mouse.position.set(0.34, TOP + 0.02, -0.12);+ g.add(kb, mouse);// Phone: a slab with a lit screen.const ph = DESK_OBJECTS.find((o) => o.id === 'phone');const phoneBody = new Mesh(new BoxGeometry(0.075, 0.012, 0.155), std({ color: 0x0c0c0f, roughness: 0.3, metalness: 0.6 }));- phoneBody.position.set(ph.dx, 0.8, ph.dz);+ phoneBody.position.set(ph.dx, TOP + 0.006, ph.dz);phoneBody.rotation.y = -0.35;phoneBody.userData.hit = { type: 'object', id: 'phone' };const phoneScreen = new Mesh(new PlaneGeometry(0.066, 0.142), glow(0x8b5cf6, 0.9));- phoneScreen.rotation.x = -Math.PI / 2;+ phoneScreen.rotation.x = -PI / 2;phoneScreen.rotation.z = -0.35;- phoneScreen.position.set(ph.dx, 0.807, ph.dz);+ phoneScreen.position.set(ph.dx, TOP + 0.013, ph.dz);phoneScreen.userData.hit = phoneBody.userData.hit;g.add(phoneBody, phoneScreen);- // Headset: a visor ring with a strap.+ // Headset: a visor with a strap.const hs = DESK_OBJECTS.find((o) => o.id === 'headset');const visor = new Mesh(new BoxGeometry(0.22, 0.1, 0.11), std({ color: 0xe8e8ee, roughness: 0.35 }));- visor.position.set(hs.dx, 0.85, hs.dz);+ visor.position.set(hs.dx, TOP + 0.06, hs.dz);visor.rotation.y = 0.4;visor.userData.hit = { type: 'object', id: 'headset' };const strap = new Mesh(new TorusGeometry(0.11, 0.012, 8, 24), std({ color: 0x2a2a30 }));- strap.position.set(hs.dx - 0.02, 0.85, hs.dz - 0.07);+ strap.position.set(hs.dx - 0.02, TOP + 0.06, hs.dz - 0.07);strap.rotation.set(0, 0.4, 0);strap.userData.hit = visor.userData.hit;const lens = new Mesh(new PlaneGeometry(0.18, 0.06), glow(0x60a5fa, 0.8));- lens.position.set(hs.dx + 0.04, 0.85, hs.dz + 0.057);+ lens.position.set(hs.dx + 0.04, TOP + 0.06, hs.dz + 0.057);lens.rotation.y = 0.4;lens.userData.hit = visor.userData.hit;g.add(visor, strap, lens);- // Chair, facing the desk.- const seat = new Mesh(new BoxGeometry(0.56, 0.08, 0.56), std({ color: 0x1a1a20, roughness: 0.6 }));- seat.position.set(0, 0.48, 0.55);- const back = new Mesh(new BoxGeometry(0.56, 0.7, 0.08), std({ color: 0x1a1a20, roughness: 0.6 }));- back.position.set(0, 0.87, 0.83);- const post = new Mesh(new CylinderGeometry(0.03, 0.03, 0.44, 8), std({ color: 0x2b2b33, metalness: 0.6 }));- post.position.set(0, 0.22, 0.55);- const base = new Mesh(new CylinderGeometry(0.3, 0.3, 0.03, 12), std({ color: 0x2b2b33, metalness: 0.6 }));- base.position.set(0, 0.015, 0.55);- g.add(seat, back, post, base);-- g.position.set(place.x, 0, place.z);+ // Warm room light.+ const lamp = new PointLight(0xffe4c4, 0.9, 9, 2);+ lamp.position.set(0, room.h - 0.5, 0.8);+ g.add(lamp);++ const fr = roomFrame(room);+ g.position.set(fr.x, 0, fr.z);+ g.rotation.y = fr.yaw;return {group: g,+ occluders: shell.occluders,screen,- // Where the camera goes when the visitor sits down, in world space.sitFrom: new Vector3(place.x, 1.55, place.z + 1.9),sitTo: new Vector3(place.x + mon.dx, 1.42, place.z + mon.dz + 0.42),screenCentre: new Vector3(place.x + mon.dx, 1.42, place.z + mon.dz),@@ -228,171 +419,272 @@ function buildOffice(place, screenMaterial) {/* -------------------------------------------------------------- exchange */-function buildExchange(place, tickerMaterial) {- const g = new Group();- const col = hueColor(place.hue);- const stone = std({ color: 0x1b1b21, roughness: 0.9 });+function buildExchange(room, place, tickerMaterial, surfaces, mats, opts) {+ const shell = buildShell({ ...room, roof: 'flat' }, surfaces, mats, opts);+ const g = shell.group;+ const occluders = shell.occluders;+ const hit = { type: 'place', id: place.id };+ g.add(doorSign(room, place));- // Steps.- for (let i = 0; i < 3; i++) {- const s = new Mesh(new BoxGeometry(14 - i * 0.6, 0.22, 2.2 - i * 0.5), stone);- s.position.set(0, 0.11 + i * 0.22, 4.6 - i * 0.3);- g.add(s);- }- // Podium and hall.- const podium = new Mesh(new BoxGeometry(14, 0.7, 8), stone);- podium.position.set(0, 0.35, 0);- g.add(podium);- const hall = new Mesh(new BoxGeometry(12.4, 6, 6), std({ color: 0x0d0d11 }));- hall.position.set(0, 3.7, -0.8);- hall.userData.hit = { type: 'place', id: place.id };- g.add(hall);- // Six columns.- for (let i = 0; i < 6; i++) {- const x = -5.5 + i * 2.2;- const c = new Mesh(new CylinderGeometry(0.42, 0.46, 6.2, 14), std({ color: 0x26262e, roughness: 0.7 }));- c.position.set(x, 3.8, 2.6);- c.userData.hit = hall.userData.hit;- g.add(c);- const cap = new Mesh(new BoxGeometry(1.1, 0.3, 1.1), stone);- cap.position.set(x, 6.95, 2.6);- g.add(cap);- }- // Entablature and pediment.- const beam = new Mesh(new BoxGeometry(14, 0.9, 1.6), stone);- beam.position.set(0, 7.5, 2.6);- g.add(beam);- const ped = new Mesh(new ConeGeometry(7.6, 2.4, 4), stone);- ped.rotation.y = Math.PI / 4;- ped.scale.z = 0.22;- ped.position.set(0, 9.1, 2.6);+ // Portico: columns, entablature, pediment and the ticker across the front.+ const stone = surfaces.material('floor-marble');+ for (const [x, z] of columnsOf(room)) {+ const c = new Mesh(new CylinderGeometry(0.36, 0.4, room.h, 18), stone);+ c.position.set(x, room.h / 2, z);+ c.castShadow = opts.shadows;+ c.receiveShadow = true;+ const cap = new Mesh(new BoxGeometry(1, 0.22, 1), mats.stone);+ cap.position.set(x, room.h - 0.11, z);+ const base = new Mesh(new BoxGeometry(1, 0.16, 1), mats.stone);+ base.position.set(x, 0.08, z);+ g.add(c, cap, base);+ occluders.push(c);+ }+ const porchDepth = 3;+ const porch = new Mesh(tileBox(new BoxGeometry(room.w + 0.6, 1.3, porchDepth), room.w + 0.6, 1.3, porchDepth, 3), mats.stone);+ porch.position.set(0, room.h + 0.65, room.d / 2 + porchDepth / 2);+ porch.castShadow = opts.shadows;+ g.add(porch);+ occluders.push(porch);+ const ped = new Mesh(new ConeGeometry(room.w / 2 + 0.5, 2.2, 4), mats.stone);+ ped.rotation.y = PI / 4;+ ped.scale.z = 0.24;+ ped.position.set(0, room.h + 1.3 + 1.1, room.d / 2 + porchDepth / 2);+ ped.castShadow = opts.shadows;g.add(ped);- // The board: a live ticker across the front of the entablature, and a- // taller board above the hall for the second line of sight.+ const patio = new Mesh(tilePlane(new PlaneGeometry(room.w + 0.6, porchDepth + 0.6), room.w + 0.6, porchDepth + 0.6, 3), stone);+ patio.rotation.x = -PI / 2;+ patio.position.set(0, 0.028, room.d / 2 + porchDepth / 2);+ patio.receiveShadow = true;+ g.add(patio);+const board = new Mesh(new PlaneGeometry(13.4, 1.25), tickerMaterial);- board.position.set(0, 7.5, 3.42);+ board.position.set(0, room.h + 0.65, room.d / 2 + porchDepth + 0.01);g.add(board);const board2 = new Mesh(new PlaneGeometry(11, 1.0), tickerMaterial);- board2.position.set(0, 6.0, 2.22);+ board2.position.set(0, room.h - 0.9, -room.d / 2 + WALL / 2 + 0.03);g.add(board2);- // Door glow.- const door = new Mesh(new PlaneGeometry(2.4, 4.2), glow(col, 0.55));- door.position.set(0, 2.8, 2.22);- door.userData.hit = hall.userData.hit;- g.add(door);- const sign = makeLabelSprite(place.title, place.sub, hex(col), 1.25);- sign.position.set(0, 11.6, 2.4);- g.add(sign);- g.position.set(place.x, 0, place.z);- g.rotation.y = facing(place);- return g;+ // Trading floor: a raised dais and a brass rail where the quotes get shouted.+ const dais = new Mesh(new CylinderGeometry(1.6, 1.7, 0.18, 32), stone);+ dais.position.set(0, 0.09, -2.4);+ g.add(dais);+ const rail = new Mesh(new TorusGeometry(1.7, 0.03, 8, 48), std({ color: 0xc9a24a, roughness: 0.3, metalness: 0.9 }));+ rail.rotation.x = PI / 2;+ rail.position.set(0, 1.0, -2.4);+ g.add(rail);+ for (let i = 0; i < 6; i++) {+ const a = (i / 6) * PI * 2;+ const post = new Mesh(new CylinderGeometry(0.025, 0.025, 1, 8), std({ color: 0xc9a24a, roughness: 0.3, metalness: 0.9 }));+ post.position.set(Math.cos(a) * 1.7, 0.5, -2.4 + Math.sin(a) * 1.7);+ g.add(post);+ }++ for (const x of [-3.4, 3.4]) {+ const light = new PointLight(0xffe9d0, 0.9, 12, 2);+ light.position.set(x, room.h - 1.2, 0);+ g.add(light);+ }++ g.traverse((o) => { if (o.isMesh && o.material !== tickerMaterial && !o.userData.hit) o.userData.hit = hit; });+ const fr = roomFrame(room);+ g.position.set(fr.x, 0, fr.z);+ g.rotation.y = fr.yaw;+ return { group: g, occluders, localSolids: [{ x: 0, z: -2.4, keepout: 2.1 }] };}/* ------------------------------------------------------------- launchpad */-function buildLaunchpad(place) {+function buildLaunchpad(room, place, surfaces, mats, opts) {const g = new Group();const col = hueColor(place.hue);- const pad = new Mesh(new CylinderGeometry(5.2, 5.4, 0.5, 32), std({ color: 0x15151a }));- pad.position.y = 0.25;- pad.userData.hit = { type: 'place', id: place.id };+ const hit = { type: 'place', id: place.id };+ const pad = new Mesh(tilePlane(new CircleGeometry(room.r, 48), room.r * 2, room.r * 2, surfaces.metresPerTile('floor-concrete')), surfaces.material('floor-concrete'));+ pad.rotation.x = -PI / 2;+ pad.position.y = 0.022;+ pad.receiveShadow = true;g.add(pad);- const ring = new Mesh(new RingGeometry(4.3, 4.6, 48), glow(col, 0.8));- ring.rotation.x = -Math.PI / 2;- ring.position.y = 0.51;+ const ring = new Mesh(new RingGeometry(4.2, 4.5, 64), std({ color: 0xf3c13a, roughness: 0.8 }));+ ring.rotation.x = -PI / 2;+ ring.position.y = 0.03;g.add(ring);- // Rocket.+ const cross = new Mesh(new PlaneGeometry(0.3, 3), std({ color: 0xf3c13a, roughness: 0.8 }));+ cross.rotation.x = -PI / 2;+ cross.position.set(1.2, 0.03, 0);+ const cross2 = cross.clone();+ cross2.rotation.z = PI / 2;+ g.add(cross, cross2);++ // Rocket on its stand.const rocket = new Group();- const body = new Mesh(new CylinderGeometry(0.9, 1.0, 6, 20), std({ color: 0xe9e9f0, roughness: 0.35, metalness: 0.25 }));+ const hull = std({ color: 0xf4f4f6, roughness: 0.32, metalness: 0.3 });+ const trim = std({ color: 0xe8552b, roughness: 0.4, metalness: 0.2 });+ const body = new Mesh(new CylinderGeometry(0.9, 1.0, 6, 28), hull);body.position.y = 3.5;- const nose = new Mesh(new ConeGeometry(0.9, 2.2, 20), std({ color: hueColor(place.hue, 0.55), roughness: 0.4 }));+ const band = new Mesh(new CylinderGeometry(0.905, 0.905, 0.5, 28), trim);+ band.position.y = 5.6;+ const band2 = new Mesh(new CylinderGeometry(0.98, 1.0, 0.4, 28), mats.darkSteel);+ band2.position.y = 0.7;+ const nose = new Mesh(new ConeGeometry(0.9, 2.2, 28), trim);nose.position.y = 7.6;- rocket.add(body, nose);+ rocket.add(body, band, band2, nose);for (let i = 0; i < 3; i++) {- const fin = new Mesh(new BoxGeometry(0.12, 1.8, 1.4), std({ color: hueColor(place.hue, 0.55) }));- const a = (i / 3) * Math.PI * 2;- fin.position.set(Math.cos(a) * 1.25, 1.2, Math.sin(a) * 1.25);+ const fin = new Mesh(new BoxGeometry(0.1, 1.8, 1.3), trim);+ const a = (i / 3) * PI * 2;+ fin.position.set(Math.cos(a) * 1.3, 1.3, Math.sin(a) * 1.3);fin.rotation.y = -a;rocket.add(fin);}- const porthole = new Mesh(new CylinderGeometry(0.3, 0.3, 0.05, 16), glow(0x60a5fa, 1));- porthole.rotation.x = Math.PI / 2;- porthole.position.set(0, 5.2, 0.98);+ const porthole = new Mesh(new CylinderGeometry(0.3, 0.3, 0.05, 20), std({ color: 0x9cc8ff, roughness: 0.1, metalness: 0.3 }));+ porthole.rotation.x = PI / 2;+ porthole.position.set(0, 5.0, 0.98);rocket.add(porthole);- const flame = new Mesh(new ConeGeometry(0.75, 1.8, 16, 1, true), glow(hueColor(place.hue, 0.7), 1.6));- flame.rotation.x = Math.PI;- flame.position.y = -0.4;+ for (let i = 0; i < 4; i++) {+ const a = (i / 4) * PI * 2 + PI / 4;+ const nozzle = new Mesh(new CylinderGeometry(0.22, 0.3, 0.5, 14, 1, true), new MeshStandardMaterial({ color: 0x55575c, roughness: 0.5, metalness: 0.8, side: DoubleSide }));+ nozzle.position.set(Math.cos(a) * 0.45, 0.25, Math.sin(a) * 0.45);+ rocket.add(nozzle);+ }+ const flame = new Mesh(new ConeGeometry(0.5, 1.2, 16, 1, true), glow(hueColor(place.hue, 0.7), 1.4));+ flame.rotation.x = PI;+ flame.position.y = -0.3;flame.material.transparent = true;- flame.material.opacity = 0.85;+ flame.material.opacity = 0.55;flame.material.side = DoubleSide;rocket.add(flame);- rocket.traverse((o) => (o.userData.hit = pad.userData.hit));- rocket.position.y = 0.5;+ rocket.traverse((o) => { o.userData.hit = hit; if (o.isMesh) o.castShadow = opts.shadows; });+ rocket.position.set(1.2, 0.55, 0);g.add(rocket);- // Gantry.- const gantry = new Mesh(new BoxGeometry(0.3, 7.5, 0.3), std({ color: 0x2a2a30, metalness: 0.5 }));- gantry.position.set(2.2, 4.25, 0);- g.add(gantry);- for (const y of [3, 5, 7]) {- const arm = new Mesh(new BoxGeometry(1.4, 0.12, 0.12), std({ color: 0x2a2a30, metalness: 0.5 }));- arm.position.set(1.5, y, 0);- g.add(arm);- }- const sign = makeLabelSprite(place.title, place.sub, hex(col), 1.1);- sign.position.set(0, 10.6, 0);+ const cradle = new Mesh(new CylinderGeometry(1.5, 1.7, 0.55, 8), mats.darkSteel);+ cradle.position.set(1.2, 0.27, 0);+ g.add(cradle);++ // Gantry tower.+ const tower = new Group();+ for (const [x, z] of [[-0.3, -0.3], [0.3, -0.3], [-0.3, 0.3], [0.3, 0.3]]) {+ const leg = new Mesh(new BoxGeometry(0.1, 8.5, 0.1), mats.steel);+ leg.position.set(x, 4.25, z);+ tower.add(leg);+ }+ for (const y of [2, 4, 6, 8]) {+ const ringBeam = new Mesh(new BoxGeometry(0.7, 0.08, 0.7), mats.steel);+ ringBeam.position.y = y;+ tower.add(ringBeam);+ const arm = new Mesh(new BoxGeometry(1.5, 0.1, 0.1), mats.steel);+ arm.position.set(-1.0, y + 0.2, 0);+ tower.add(arm);+ }+ tower.position.set(3.6, 0, 0);+ tower.traverse((o) => { o.userData.hit = hit; if (o.isMesh) o.castShadow = opts.shadows; });+ g.add(tower);+ const sign = signPost(place.title, place.sub, hex(col), mats);+ sign.position.set(-3.2, 0, 5.6);g.add(sign);- g.position.set(place.x, 0, place.z);- return { group: g, rocket, flame };+ const fr = roomFrame(room);+ g.position.set(fr.x, 0, fr.z);+ g.rotation.y = fr.yaw;+ return { group: g, rocket, flame, occluders: [body] };}/* ------------------------------------------------------------------ mine */-function buildMine(place) {- const g = new Group();- const col = hueColor(place.hue);- const rock = std({ color: 0x14141a, roughness: 1 });-- // Cave: two shoulders, a lintel, a dark back wall and a dim interior floor.- const left = new Mesh(new BoxGeometry(3.2, 6.5, 4), rock);- left.position.set(-5.2, 3.25, -3);- const right = left.clone();- right.position.x = 5.2;- const lintel = new Mesh(new BoxGeometry(13.6, 2.2, 4), rock);- lintel.position.set(0, 6.4, -3);- const back = new Mesh(new BoxGeometry(13.6, 7.5, 1), rock);- back.position.set(0, 3.75, -7);- const floor = new Mesh(new CircleGeometry(7.2, 40), std({ color: 0x0a0a0d, roughness: 1 }));- floor.rotation.x = -Math.PI / 2;- floor.position.y = 0.01;- g.add(left, right, lintel, back, floor);- // Rails and a cart.- for (const dx of [-0.35, 0.35]) {- const rail = new Mesh(new BoxGeometry(0.06, 0.05, 12), std({ color: 0x3a3a44, metalness: 0.7 }));- rail.position.set(dx, 0.04, 1);+function buildMine(room, place, surfaces, mats, opts) {+ const shell = buildShell(room, surfaces, mats, opts);+ const g = shell.group;+ const occluders = shell.occluders;+ const rock = surfaces.material('rock');++ // The hill the cave is cut into.+ const hill = new Mesh(tilePlane(new SphereGeometry(1, 40, 24), 2 * PI * 13, PI * 6.5, surfaces.metresPerTile('rock')), rock);+ hill.scale.set(13.5, 6.8, 11);+ hill.position.set(0, 0, -4);+ hill.castShadow = opts.shadows;+ hill.receiveShadow = true;+ g.add(hill);+ occluders.push(hill);+ // Grass creeps over the top of the hill.+ const cap = new Mesh(tilePlane(new SphereGeometry(1, 32, 16, 0, PI * 2, 0, PI / 2.6), 60, 12, 3), surfaces.material('ground'));+ cap.scale.set(13.0, 6.9, 10.6);+ cap.position.set(0, 0.05, -4);+ g.add(cap);++ // Portal timbers.+ for (const x of [-1.85, 1.85]) {+ const post = new Mesh(new BoxGeometry(0.3, room.door.h, 0.35), mats.darkWood);+ post.position.set(x, room.door.h / 2, room.d / 2);+ post.castShadow = opts.shadows;+ g.add(post);+ }+ const lintel = new Mesh(new BoxGeometry(4.2, 0.32, 0.4), mats.darkWood);+ lintel.position.set(0, room.door.h + 0.16, room.d / 2);+ g.add(lintel);+ const sign = signBoard(place.title, place.sub, hex(hueColor(place.hue, 0.7)), 2.4);+ sign.position.set(0, room.door.h + 0.85, room.d / 2 + 0.25);+ g.add(sign);++ // Rails from the daylight to the face, a cart, timber props along the walls.+ const railLen = room.d / 2 + 3 + 4;+ for (const dx of [-0.38, 0.38]) {+ const rail = new Mesh(new BoxGeometry(0.06, 0.06, railLen), mats.darkSteel);+ rail.position.set(dx, 0.06, (room.d / 2 + 3 - 4) / 2);g.add(rail);}- const cart = new Mesh(new BoxGeometry(0.9, 0.5, 1.2), std({ color: 0x24242b, metalness: 0.4 }));- cart.position.set(0, 0.45, 4.6);+ for (let z = -4; z < room.d / 2 + 3; z += 0.7) {+ const sleeper = new Mesh(new BoxGeometry(1.1, 0.06, 0.18), mats.darkWood);+ sleeper.position.set(0, 0.03, z);+ g.add(sleeper);+ }+ const cart = new Group();+ const tub = new Mesh(new BoxGeometry(0.95, 0.55, 1.25), std({ color: 0x4a4a52, metalness: 0.6, roughness: 0.5 }));+ tub.position.y = 0.5;+ cart.add(tub);+ for (const [x, z] of [[-0.45, -0.4], [0.45, -0.4], [-0.45, 0.4], [0.45, 0.4]]) {+ const wheel = new Mesh(new CylinderGeometry(0.16, 0.16, 0.08, 14), mats.darkSteel);+ wheel.rotation.z = PI / 2;+ wheel.position.set(x, 0.16, z);+ cart.add(wheel);+ }+ const ore = new Mesh(new SphereGeometry(0.45, 10, 8), rock);+ ore.scale.set(1, 0.5, 1.2);+ ore.position.y = 0.8;+ cart.add(ore);+ cart.position.set(0, 0, 3.6);+ cart.traverse((o) => { if (o.isMesh) o.castShadow = opts.shadows; });g.add(cart);+ for (const x of [-room.w / 2 + 0.6, room.w / 2 - 0.6]) {+ for (const z of [-3.5, 0, 3.5]) {+ const prop = new Mesh(new BoxGeometry(0.22, room.h - 0.1, 0.22), mats.darkWood);+ prop.position.set(x, (room.h - 0.1) / 2, z);+ g.add(prop);+ }+ }+ for (const x of [-room.w / 2 + 0.6, room.w / 2 - 0.6]) {+ const beam = new Mesh(new BoxGeometry(0.22, 0.22, room.d - 1), mats.darkWood);+ beam.position.set(x, room.h - 0.2, 0);+ g.add(beam);+ }- // Veins: clusters of octahedra, one per gem colour, lit from inside.+ // Veins: clusters of crystal, one per gem colour, lit from inside.const veins = [];const palette = GEMS.map((gm) => gm.hex);VEINS.forEach((v, i) => {const cluster = new Group();const colour = palette[(i + 1) % palette.length];- const mat = new MeshStandardMaterial({ color: colour, emissive: colour, emissiveIntensity: 0.55, roughness: 0.2, metalness: 0.1, transparent: true, opacity: 0.92 });+ const mat = new MeshStandardMaterial({ color: colour, emissive: colour, emissiveIntensity: 0.55, roughness: 0.15, metalness: 0.1, transparent: true, opacity: 0.92 });for (let k = 0; k < 5; k++) {const s = 0.22 + Math.random() * 0.32;const crystal = new Mesh(new OctahedronGeometry(s, 0), mat);crystal.scale.y = 1.8 + Math.random();- const a = (k / 5) * Math.PI * 2 + i;+ const a = (k / 5) * PI * 2 + i;crystal.position.set(Math.cos(a) * 0.35, s * 1.1, Math.sin(a) * 0.35);crystal.rotation.set(Math.random() * 0.5 - 0.25, a, Math.random() * 0.5 - 0.25);crystal.userData.hit = { type: 'vein', id: v.id };cluster.add(crystal);}+ const rubble = new Mesh(new SphereGeometry(0.75, 10, 7), rock);+ rubble.scale.set(1.2, 0.35, 1.2);+ rubble.position.y = -0.05;+ cluster.add(rubble);const light = new PointLight(colour, 0.6, 3.5, 2);light.position.y = 0.6;cluster.add(light);@@ -400,123 +692,335 @@ function buildMine(place) {g.add(cluster);veins.push({ id: v.id, group: cluster, material: mat, light, x: place.x + v.dx, z: place.z + v.dz, phase: i * 1.3 });});- const sign = makeLabelSprite(place.title, place.sub, hex(col), 1.1);- sign.position.set(0, 9, -1);- g.add(sign);- g.position.set(place.x, 0, place.z);- return { group: g, veins };++ const fr = roomFrame(room);+ g.position.set(fr.x, 0, fr.z);+ g.rotation.y = fr.yaw;+ return { group: g, veins, occluders };}-/* ------------------------------------------------------- small pavilions */+/* ----------------------------------------------------------------- forge */-function buildForge(place) {- const g = new Group();- const col = hueColor(place.hue);- const base = new Mesh(new CylinderGeometry(3.6, 3.8, 0.4, 24), std({ color: 0x15151a }));- base.position.y = 0.2;- base.userData.hit = { type: 'place', id: place.id };- const anvil = new Mesh(new BoxGeometry(2.4, 1.3, 1.1), std({ color: 0x23232a, metalness: 0.7, roughness: 0.35 }));- anvil.position.y = 1.05;- anvil.userData.hit = base.userData.hit;- const hot = new Mesh(new BoxGeometry(2.4, 0.08, 1.1), glow(col, 1.6));- hot.position.y = 1.74;- const chimney = new Mesh(new CylinderGeometry(0.5, 0.7, 5.5, 12), std({ color: 0x1b1b21 }));- chimney.position.set(-1.6, 3.1, -1.2);- const ember = new Mesh(new CylinderGeometry(0.48, 0.48, 0.1, 12), glow(col, 1.2));- ember.position.set(-1.6, 5.9, -1.2);- g.add(base, anvil, hot, chimney, ember);- const sign = makeLabelSprite(place.title, place.sub, hex(col));- sign.position.set(0, 7.4, 0);- g.add(sign);- g.position.set(place.x, 0, place.z);- g.rotation.y = facing(place);- return { group: g, pulse: [hot.material, ember.material] };+function buildForge(room, place, surfaces, mats, opts) {+ const shell = buildShell(room, surfaces, mats, opts);+ const g = shell.group;+ const hit = { type: 'place', id: place.id };+ g.add(doorSign(room, place));+ const brick = surfaces.material('brick');++ // Furnace, its mouth and the chimney through the roof.+ const furnace = new Mesh(tileBox(new BoxGeometry(1.6, 2.2, 1.2), 1.6, 2.2, 1.2, 1.5), brick);+ furnace.position.set(1.9, 1.1, -2.2);+ furnace.castShadow = opts.shadows;+ const mouth = new Mesh(new PlaneGeometry(0.7, 0.5), glow(0xff7a2a, 1.8));+ mouth.position.set(1.9, 0.85, -1.59);+ const fire = new PointLight(0xff8a3c, 1.4, 6, 2);+ fire.position.set(1.9, 0.9, -1.2);+ const chimney = new Mesh(tileBox(new BoxGeometry(0.6, 3.4, 0.6), 0.6, 3.4, 0.6, 1.5), brick);+ chimney.position.set(1.9, room.h + 0.9, -2.2);+ chimney.castShadow = opts.shadows;+ g.add(furnace, mouth, fire, chimney);++ // Workbench with an anvil and a quench bucket.+ const bench = new Mesh(new BoxGeometry(2.0, 0.08, 0.7), mats.wood);+ bench.position.set(-0.5, 0.86, -2.35);+ for (const x of [-1.4, 0.4]) for (const z of [-2.65, -2.05]) {+ const leg = new Mesh(new BoxGeometry(0.08, 0.84, 0.08), mats.wood);+ leg.position.set(x, 0.42, z);+ g.add(leg);+ }+ const anvil = new Mesh(new BoxGeometry(0.55, 0.22, 0.2), mats.darkSteel);+ anvil.position.set(-0.9, 1.01, -2.35);+ const horn = new Mesh(new ConeGeometry(0.08, 0.3, 10), mats.darkSteel);+ horn.rotation.z = PI / 2;+ horn.position.set(-0.5, 1.03, -2.35);+ const bucket = new Mesh(new CylinderGeometry(0.2, 0.17, 0.4, 14, 1, true), new MeshStandardMaterial({ color: 0x555a62, metalness: 0.7, roughness: 0.5, side: DoubleSide }));+ bucket.position.set(0.6, 0.2, -1.6);+ g.add(bench, anvil, horn, bucket);+ g.traverse((o) => { if (o.isMesh && !o.userData.hit) o.userData.hit = hit; });++ const fr = roomFrame(room);+ g.position.set(fr.x, 0, fr.z);+ g.rotation.y = fr.yaw;+ return { group: g, occluders: shell.occluders, pulse: [mouth.material], localSolids: [{ box: [1.9, -2.2, 1.6, 1.2] }, { box: [-0.5, -2.35, 2.0, 0.7] }] };}-function buildGallery(place) {- const g = new Group();- const col = hueColor(place.hue);- const base = new Mesh(new CylinderGeometry(3.6, 3.8, 0.4, 24), std({ color: 0x15151a }));- base.position.y = 0.2;- base.userData.hit = { type: 'place', id: place.id };- g.add(base);- const frames = [];- for (let i = 0; i < 4; i++) {- const a = (i / 4) * Math.PI * 2;- const ped = new Mesh(new BoxGeometry(0.5, 1.1, 0.5), std({ color: 0x1b1b21 }));- ped.position.set(Math.cos(a) * 2.2, 0.95, Math.sin(a) * 2.2);- const frame = new Mesh(new BoxGeometry(1.2, 1.6, 0.08), std({ color: 0x0b0b0e, metalness: 0.4 }));- frame.position.set(Math.cos(a) * 2.2, 2.5, Math.sin(a) * 2.2);- frame.rotation.y = -a + Math.PI / 2;- const art = new Mesh(new PlaneGeometry(1.0, 1.4), glow(hueColor(place.hue + i * 40, 0.6), 0.7));- art.position.set(0, 0, 0.05);- frame.add(art);- frame.userData.hit = base.userData.hit;- art.userData.hit = base.userData.hit;- g.add(ped, frame);- frames.push(frame);- }- const sign = makeLabelSprite(place.title, place.sub, hex(col));- sign.position.set(0, 5.6, 0);- g.add(sign);- g.position.set(place.x, 0, place.z);- g.rotation.y = facing(place);- return { group: g, frames };+/* --------------------------------------------------------------- gallery */++function buildGallery(room, place, surfaces, mats, opts) {+ const shell = buildShell(room, surfaces, mats, opts);+ const g = shell.group;+ const hit = { type: 'place', id: place.id };+ g.add(doorSign(room, place));+ const inset = WALL / 2 + 0.035;+ const spots = [+ { x: -2.1, z: -room.d / 2 + inset, yaw: 0 },+ { x: 0, z: -room.d / 2 + inset, yaw: 0 },+ { x: 2.1, z: -room.d / 2 + inset, yaw: 0 },+ { x: -room.w / 2 + inset, z: -1.6, yaw: PI / 2 },+ { x: -room.w / 2 + inset, z: 0.8, yaw: PI / 2 },+ { x: room.w / 2 - inset, z: -1.6, yaw: -PI / 2 },+ { x: room.w / 2 - inset, z: 0.8, yaw: -PI / 2 },+ ];+ const frames = spots.map((s) => {+ const holder = new Group();+ holder.position.set(s.x, 1.65, s.z);+ holder.rotation.y = s.yaw;+ const frame = new Mesh(new BoxGeometry(1.08, 1.08, 0.06), mats.darkWood);+ const art = new Mesh(new PlaneGeometry(0.92, 0.92), new MeshStandardMaterial({ color: 0xe9e6df, roughness: 0.7 }));+ art.position.z = 0.035;+ const plate = new Mesh(new PlaneGeometry(0.6, 0.12), new MeshStandardMaterial({ color: 0xd9d4c8, roughness: 0.5 }));+ plate.position.set(0, -0.7, 0.01);+ const spot = new PointLight(0xfff2dc, 0.35, 3, 2);+ spot.position.set(0, 1.1, 0.8);+ holder.add(frame, art, plate, spot);+ g.add(holder);+ return { art, plate };+ });+ g.traverse((o) => { if (o.isMesh && !o.userData.hit) o.userData.hit = hit; });+ const fr = roomFrame(room);+ g.position.set(fr.x, 0, fr.z);+ g.rotation.y = fr.yaw;+ return { group: g, occluders: shell.occluders, frames };}-function buildPlaza(place) {+/* ----------------------------------------------------------- agent plaza */++function buildPlaza(room, place, surfaces, mats, opts) {const g = new Group();const col = hueColor(place.hue);- const base = new Mesh(new CylinderGeometry(3.6, 3.8, 0.4, 24), std({ color: 0x15151a }));- base.position.y = 0.2;- base.userData.hit = { type: 'place', id: place.id };- g.add(base);- // The plaza is a stage, not a diorama: the real agents (agents.js) stand- // around it, so nothing abstract is built here to stand in for them.- const beacon = new Mesh(new CylinderGeometry(0.1, 0.1, 4.5, 8), glow(col, 1.2));- beacon.position.y = 2.6;- g.add(beacon);- const sign = makeLabelSprite(place.title, place.sub, hex(col));- sign.position.set(0, 6.2, 0);+ const hit = { type: 'place', id: place.id };+ const paving = new Mesh(tilePlane(new CircleGeometry(room.r, 56), room.r * 2, room.r * 2, surfaces.metresPerTile('plaza')), surfaces.material('plaza'));+ paving.rotation.x = -PI / 2;+ paving.position.y = 0.022;+ paving.receiveShadow = true;+ g.add(paving);+ // Pergola.+ const r = room.pergola / 2;+ for (const [x, z] of [[-r, -r], [r, -r], [-r, r], [r, r]]) {+ const post = new Mesh(new BoxGeometry(0.22, 2.8, 0.22), mats.wood);+ post.position.set(x, 1.4, z);+ post.castShadow = opts.shadows;+ g.add(post);+ }+ for (const z of [-r, r]) {+ const beam = new Mesh(new BoxGeometry(room.pergola + 0.8, 0.16, 0.16), mats.wood);+ beam.position.set(0, 2.85, z);+ beam.castShadow = opts.shadows;+ g.add(beam);+ }+ for (let i = 0; i < 9; i++) {+ const slat = new Mesh(new BoxGeometry(0.08, 0.14, room.pergola + 0.8), mats.wood);+ slat.position.set(-r + (i / 8) * room.pergola, 3.0, 0);+ slat.castShadow = opts.shadows;+ g.add(slat);+ }+ // A small fountain in the middle: the plaza's centrepiece.+ const basin = new Mesh(new CylinderGeometry(1.0, 1.1, 0.45, 32, 1, true), new MeshStandardMaterial({ color: 0xd9d4c8, roughness: 0.8, side: DoubleSide }));+ basin.position.y = 0.225;+ const water = new Mesh(new CircleGeometry(0.98, 32), new MeshStandardMaterial({ color: 0x6fa3d8, roughness: 0.05, metalness: 0.2, transparent: true, opacity: 0.85 }));+ water.rotation.x = -PI / 2;+ water.position.y = 0.38;+ const column = new Mesh(new CylinderGeometry(0.12, 0.16, 0.9, 12), mats.stone);+ column.position.y = 0.6;+ const bowl = new Mesh(new CylinderGeometry(0.4, 0.1, 0.2, 20, 1, true), new MeshStandardMaterial({ color: 0xd9d4c8, roughness: 0.8, side: DoubleSide }));+ bowl.position.y = 1.1;+ g.add(basin, water, column, bowl);+ const sign = signPost(place.title, place.sub, hex(col), mats);+ sign.position.set(2.4, 0, room.r - 0.6);g.add(sign);- g.position.set(place.x, 0, place.z);- g.rotation.y = facing(place);- return { group: g };+ g.traverse((o) => { if (o.isMesh && !o.userData.hit) o.userData.hit = hit; });+ const fr = roomFrame(room);+ g.position.set(fr.x, 0, fr.z);+ g.rotation.y = fr.yaw;+ return { group: g, occluders: [], localSolids: [{ x: 0, z: 0, keepout: 1.4 }] };+}++/* ---------------------------------------------------------------- market */++function stripeTexture(a, b) {+ const canvas = document.createElement('canvas');+ canvas.width = 256;+ canvas.height = 64;+ const g = canvas.getContext('2d');+ for (let i = 0; i < 8; i++) {+ g.fillStyle = i % 2 ? a : b;+ g.fillRect(i * 32, 0, 32, 64);+ }+ const tex = new CanvasTexture(canvas);+ tex.colorSpace = SRGBColorSpace;+ return tex;}-function buildMarket(place) {+function buildMarket(room, place, surfaces, mats, opts) {const g = new Group();const col = hueColor(place.hue);- const base = new Mesh(new CylinderGeometry(3.6, 3.8, 0.4, 24), std({ color: 0x15151a }));- base.position.y = 0.2;- base.userData.hit = { type: 'place', id: place.id };- g.add(base);- for (let i = 0; i < 3; i++) {- const a = (i / 3) * Math.PI * 2 + 0.5;- const stall = new Group();- const counter = new Mesh(new BoxGeometry(2, 0.9, 0.8), std({ color: 0x1b1b21 }));- counter.position.y = 0.85;- const canopy = new Mesh(new BoxGeometry(2.3, 0.08, 1.4), std({ color: hueColor(place.hue + i * 25, 0.5) }));- canopy.position.set(0, 2.5, 0.1);- const light = new Mesh(new BoxGeometry(1.9, 0.05, 0.05), glow(col, 1.2));- light.position.set(0, 2.44, 0.6);- for (const sx of [-1.05, 1.05]) {- const post = new Mesh(new CylinderGeometry(0.04, 0.04, 2.5, 8), std({ color: 0x2a2a30 }));- post.position.set(sx, 1.25, 0.6);- stall.add(post);+ const hit = { type: 'place', id: place.id };+ const floor = new Mesh(tilePlane(new PlaneGeometry(room.w + 1, room.d + 1), room.w + 1, room.d + 1, surfaces.metresPerTile('plaza')), surfaces.material('plaza'));+ floor.rotation.x = -PI / 2;+ floor.position.y = 0.022;+ floor.receiveShadow = true;+ g.add(floor);+ for (const [x, z] of room.posts) {+ const post = new Mesh(new CylinderGeometry(0.13, 0.15, room.h, 12), mats.wood);+ post.position.set(x, room.h / 2, z);+ post.castShadow = opts.shadows;+ g.add(post);+ }+ for (const z of [-3.2, 3.2]) {+ const beam = new Mesh(new BoxGeometry(room.w + 0.6, 0.18, 0.18), mats.wood);+ beam.position.set(0, room.h, z);+ g.add(beam);+ }+ const roof = gableRoof({ ...room, wall: 'wall' }, surfaces, mats, (m) => { m.castShadow = opts.shadows; m.receiveShadow = true; return m; });+ g.add(roof);+ const occluders = [];+ roof.traverse((m) => m.isMesh && occluders.push(m));++ // Stalls: timber counters under striped canvas.+ const stripes = [stripeTexture('#c93b3b', '#f4f1ea'), stripeTexture('#2d6cb5', '#f4f1ea')];+ const stalls = [{ x: 1.6, z: -2.0, yaw: 0 }, { x: 3.9, z: 0.2, yaw: -PI / 2 }];+ stalls.forEach((s, i) => {+ const st = new Group();+ const counter = new Mesh(new BoxGeometry(2.0, 0.95, 0.8), mats.wood);+ counter.position.y = 0.475;+ counter.castShadow = opts.shadows;+ const top = new Mesh(new BoxGeometry(2.1, 0.05, 0.9), mats.darkWood);+ top.position.y = 0.975;+ const canopy = new Mesh(new PlaneGeometry(2.4, 1.3), new MeshStandardMaterial({ map: stripes[i], roughness: 0.9, side: DoubleSide }));+ canopy.rotation.x = -PI / 2 + 0.35;+ canopy.position.set(0, 2.25, 0.25);+ for (const x of [-1.1, 1.1]) {+ const post = new Mesh(new CylinderGeometry(0.03, 0.03, 2.2, 8), mats.paint);+ post.position.set(x, 1.1, 0.75);+ st.add(post);}- stall.add(counter, canopy, light);- stall.position.set(Math.cos(a) * 2.1, 0.4, Math.sin(a) * 2.1);- stall.rotation.y = -a - Math.PI / 2;- stall.traverse((o) => (o.userData.hit = base.userData.hit));- g.add(stall);- }- const sign = makeLabelSprite(place.title, place.sub, hex(col));- sign.position.set(0, 5.6, 0);+ for (let k = 0; k < 3; k++) {+ const crate = new Mesh(new BoxGeometry(0.4, 0.22, 0.3), mats.wood);+ crate.position.set(-0.7 + k * 0.7, 1.11, 0.05);+ const fruit = new Mesh(new SphereGeometry(0.17, 10, 8), std({ color: [0xe25822, 0x6fbf3b, 0xf2c14e][k], roughness: 0.6 }));+ fruit.scale.y = 0.5;+ fruit.position.set(-0.7 + k * 0.7, 1.27, 0.05);+ st.add(crate, fruit);+ }+ st.add(counter, top, canopy);+ st.position.set(s.x, 0, s.z);+ st.rotation.y = s.yaw;+ g.add(st);+ });+ const sign = signPost(place.title, place.sub, hex(col), mats);+ sign.position.set(-4.8, 0, 3.0);g.add(sign);- g.position.set(place.x, 0, place.z);- g.rotation.y = facing(place);- return { group: g };+ for (const x of [-2.2, 2.2]) {+ const light = new PointLight(0xffe9d0, 0.5, 8, 2);+ light.position.set(x, room.h - 0.6, 0);+ g.add(light);+ }+ g.traverse((o) => { if (o.isMesh && !o.userData.hit) o.userData.hit = hit; });+ const fr = roomFrame(room);+ g.position.set(fr.x, 0, fr.z);+ g.rotation.y = fr.yaw;+ return { group: g, occluders, localSolids: stalls.map((s) => ({ box: [s.x, s.z, 2.1, 0.9], yaw: s.yaw })) };+}++/* ---------------------------------------------------------- the grounds */++/** A path stops at a building's door, or at the edge of an open-air place. */+function pathEnd(place) {+ const room = ROOMS.find((r) => r.place === place.id);+ if (room?.door) return doorPoints(room, 0.3).outside;+ const office = placeById('office');+ const a = Math.atan2(place.x - office.x, place.z - office.z);+ const edge = room?.r ? room.r - 0.4 : room?.w ? Math.min(room.w, room.d) / 2 - 0.3 : 1;+ return { x: place.x - Math.sin(a) * edge, z: place.z - Math.cos(a) * edge };+}++function buildGrounds(surfaces, mats, { shadows }) {+ const g = new Group();+ const occluders = [];+ const ground = new Mesh(tilePlane(new CircleGeometry(210, 96), 420, 420, surfaces.metresPerTile('ground')), surfaces.material('ground'));+ ground.rotation.x = -PI / 2;+ ground.receiveShadow = true;+ ground.raycast = () => {};+ g.add(ground);++ // The plaza round the office and the paths out to every place.+ const office = placeById('office');+ const plaza = new Mesh(tilePlane(new CylinderGeometry(11, 11, 0.03, 64), 22, 22, surfaces.metresPerTile('plaza')), surfaces.material('plaza'));+ plaza.position.set(office.x, 0.015, office.z);+ plaza.receiveShadow = true;+ g.add(plaza);+ const kerb = new Mesh(new RingGeometry(11, 11.3, 64), mats.stone);+ kerb.rotation.x = -PI / 2;+ kerb.position.set(office.x, 0.018, office.z);+ g.add(kerb);+ const path = (ax, az, bx, bz, w) => {+ const dx = bx - ax;+ const dz = bz - az;+ const len = Math.hypot(dx, dz);+ const m = new Mesh(tileBox(new BoxGeometry(w, 0.03, len), w, 0.03, len, surfaces.metresPerTile('path')), surfaces.material('path'));+ m.position.set((ax + bx) / 2, 0.02, (az + bz) / 2);+ m.rotation.y = Math.atan2(dx, dz);+ m.receiveShadow = true;+ g.add(m);+ };+ path(0, CAMPUS_RADIUS - 2, 0, office.z + 3.5, 3.2);+ for (const p of PLACES) {+ if (p.id === 'office') continue;+ const a = Math.atan2(p.x - office.x, p.z - office.z);+ const end = pathEnd(p);+ path(office.x + Math.sin(a) * 10.5, office.z + Math.cos(a) * 10.5, end.x, end.z, 3);+ }++ // The gate: brick piers and the welcome board.+ for (const sx of [-3.2, 3.2]) {+ const pier = new Mesh(tileBox(new BoxGeometry(0.7, 2.8, 0.7), 0.7, 2.8, 0.7, surfaces.metresPerTile('brick')), surfaces.material('brick'));+ pier.position.set(sx, 1.4, GATE_Z);+ pier.castShadow = shadows;+ pier.receiveShadow = true;+ const cap = new Mesh(new BoxGeometry(0.9, 0.12, 0.9), mats.stone);+ cap.position.set(sx, 2.86, GATE_Z);+ const lampHead = new Mesh(new SphereGeometry(0.16, 12, 8), glow(0xfff1d6, 1.2));+ lampHead.position.set(sx, 3.1, GATE_Z);+ g.add(pier, cap, lampHead);+ occluders.push(pier);+ }+ const beam = new Mesh(new BoxGeometry(7.2, 0.14, 0.14), mats.darkSteel);+ beam.position.set(0, 3.9, GATE_Z);+ g.add(beam);+ const welcome = signBoard('Welcome to three.ws', 'The 3D agent layer of the internet', '#c4b5fd', 4.6);+ welcome.position.set(0, 3.1, GATE_Z);+ welcome.rotation.y = PI;+ g.add(welcome);+ const welcomeBack = signBoard('three.ws', 'Walk in. Meet the agents.', '#c4b5fd', 4.6);+ welcomeBack.position.set(0, 3.1, GATE_Z + 0.06);+ g.add(welcomeBack);+ // A low wall either side of the gate, in line with the hedge.+ for (const sx of [-1, 1]) {+ const wall = new Mesh(tileBox(new BoxGeometry(12, 1.1, 0.4), 12, 1.1, 0.4, surfaces.metresPerTile('brick')), surfaces.material('brick'));+ wall.position.set(sx * 9.6, 0.55, GATE_Z);+ wall.rotation.y = sx * 0.22;+ wall.castShadow = shadows;+ wall.receiveShadow = true;+ g.add(wall);+ occluders.push(wall);+ }++ // Far hills on the horizon, softened by the haze.+ let seed = 7;+ const rnd = () => { seed = (seed * 9301 + 49297) % 233280; return seed / 233280; };+ const hillMat = std({ color: 0x6f8c5a, roughness: 1 });+ for (let i = 0; i < 18; i++) {+ const a = (i / 18) * PI * 2 + rnd() * 0.2;+ const r = 150 + rnd() * 40;+ const hill = new Mesh(new SphereGeometry(1, 18, 10), hillMat);+ hill.scale.set(45 + rnd() * 40, 12 + rnd() * 16, 30 + rnd() * 20);+ hill.position.set(Math.sin(a) * r, -2, Math.cos(a) * r);+ hill.rotation.y = rnd() * PI;+ hill.raycast = () => {};+ g.add(hill);+ }+ return { group: g, occluders };}/**@@ -528,80 +1032,125 @@ export function createCampus(canvas, { screenMaterial, tickerMaterial, reducedMo{ canvas, antialias: true, alpha: false, powerPreference: 'high-performance' },{ fallback: canvas.parentElement },);- renderer.setPixelRatio(Math.min(2, devicePixelRatio || 1));+ // `?quality=high|medium|mobile` overrides the detected tier (support, QA, slow laptops).+ const asked = new URLSearchParams(location.search).get(QUALITY_PARAM);+ const tierName = asked === 'high' || asked === 'medium' || asked === 'mobile' ? asked : detectQualityTier({ gl: renderer.getContext() });+ const tier = applyCinematicDefaults(renderer, { tier: tierName, exposure: 0.92 });renderer.setSize(innerWidth, innerHeight, false);- renderer.toneMapping = ACESFilmicToneMapping;- renderer.toneMappingExposure = 1.05;+ const shadows = !!tier.shadows;+ const opts = { shadows };const scene = new Scene();- scene.background = new Color(BG);- scene.fog = new Fog(BG, 42, 120);- const camera = new PerspectiveCamera(58, innerWidth / innerHeight, 0.1, 400);-- scene.add(new HemisphereLight(0xa39bd0, 0x14121c, 1.25));- const sun = new DirectionalLight(0xdcd6ff, 1.1);- sun.position.set(18, 30, 12);- scene.add(sun);- scene.add(makeSkyDome(), makeStars(560));-- // Ground.- const groundTex = groundTexture();- const ground = new Mesh(new CircleGeometry(CAMPUS_RADIUS + 14, 96), new MeshStandardMaterial({ map: groundTex, roughness: 0.95, metalness: 0 }));- ground.rotation.x = -Math.PI / 2;- ground.receiveShadow = false;- scene.add(ground);- // Edge glow where the walkable disc ends.- const edge = new Mesh(new RingGeometry(CAMPUS_RADIUS - 0.1, CAMPUS_RADIUS + 0.25, 128), glow(VIOLET, 0.5));- edge.rotation.x = -Math.PI / 2;- edge.position.y = 0.015;- scene.add(edge);-- // Lamps along the gate path and around the plaza.- for (const z of [26, 20, 14]) scene.add(lamp(-2.2, z), lamp(2.2, z));- for (let i = 0; i < 8; i++) {- const a = (i / 8) * Math.PI * 2;- scene.add(lamp(Math.cos(a) * 9, 8 + Math.sin(a) * 9));- }+ scene.background = new Color(HORIZON);+ scene.fog = new Fog(HORIZON, 70, 190);+ const camera = new PerspectiveCamera(58, innerWidth / innerHeight, 0.1, 420);- // Gate pylons at the spawn.- for (const sx of [-3.2, 3.2]) {- const pylon = new Mesh(new BoxGeometry(0.5, 5.5, 0.5), std({ color: 0x0f0f14 }));- pylon.position.set(sx, 2.75, 33);- const tip = new Mesh(new BoxGeometry(0.5, 0.1, 0.5), glow(VIOLET, 1.2));- tip.position.set(sx, 5.55, 33);- scene.add(pylon, tip);+ // Daylight: a physical sky, the sun, the sky's bounce, and the outdoor HDRI for reflections.+ const sky = new Sky();+ sky.scale.setScalar(400);+ sky.raycast = () => {};+ const su = sky.material.uniforms;+ su.turbidity.value = 2.6;+ su.rayleigh.value = 1.1;+ su.mieCoefficient.value = 0.004;+ su.mieDirectionalG.value = 0.8;+ const sunDir = new Vector3().setFromSphericalCoords(1, MathUtils.degToRad(90 - SUN_ELEVATION), MathUtils.degToRad(SUN_AZIMUTH));+ su.sunPosition.value.copy(sunDir);+ scene.add(sky);+ const sun = new DirectionalLight(0xfff0dc, 2.8);+ sun.position.copy(sunDir).multiplyScalar(70);+ sun.castShadow = shadows;+ if (shadows) {+ const size = tierName === 'high' ? 2048 : 1024;+ sun.shadow.mapSize.set(size, size);+ sun.shadow.camera.left = sun.shadow.camera.bottom = -28;+ sun.shadow.camera.right = sun.shadow.camera.top = 28;+ sun.shadow.camera.near = 5;+ sun.shadow.camera.far = 160;+ sun.shadow.bias = -0.0004;+ sun.shadow.normalBias = 0.04;+ sun.shadow.radius = 3;+ sun.shadow.blurSamples = 8;}- const gateSign = makeLabelSprite('Welcome to three.ws', 'The 3D agent layer of the internet', '#c4b5fd', 1.1);- gateSign.position.set(0, 6.4, 33);- scene.add(gateSign);+ scene.add(sun, sun.target);+ scene.add(new HemisphereLight(0xcfe0ff, 0x5f6e45, 0.65));+ scene.environmentIntensity = 0.55;+ loadEnvironment(renderer, scene, 'outdoor', { tier: tierName }).catch((err) => log.warn('world/campus', 'environment', err?.message || err));++ const surfaces = createSurfaces({ normals: tierName !== 'mobile', anisotropy: tierName === 'high' ? 8 : 4 });+ surfaces.ready.catch((err) => log.warn('world/campus', 'surfaces', err?.message || err));+ const mats = sharedMaterials();++ const grounds = buildGrounds(surfaces, mats, opts);+ scene.add(grounds.group);// Buildings.- const office = buildOffice(placeById('office'), screenMaterial);- const exchange = buildExchange(placeById('exchange'), tickerMaterial);- const launchpad = buildLaunchpad(placeById('launchpad'));- const mine = buildMine(placeById('mine'));- const forge = buildForge(placeById('forge'));- const gallery = buildGallery(placeById('gallery'));- const plaza = buildPlaza(placeById('agents'));- const market = buildMarket(placeById('market'));- scene.add(office.group, exchange, launchpad.group, mine.group, forge.group, gallery.group, plaza.group, market.group);-- // Keep-out volumes for the player (same shape player.update expects).- const solids = PLACES.filter((p) => p.keepout > 0).map((p) => ({ group: { position: new Vector3(p.x, 0, p.z) }, keepout: p.keepout }));- // The desk itself: a small disc so the avatar never walks through the table.+ const room = (id) => ROOMS.find((r) => r.id === id);+ const office = buildOffice(room('office'), placeById('office'), screenMaterial, surfaces, mats, opts);+ const exchange = buildExchange(room('exchange'), placeById('exchange'), tickerMaterial, surfaces, mats, opts);+ const launchpad = buildLaunchpad(room('pad'), placeById('launchpad'), surfaces, mats, opts);+ const cabin = buildShell(room('cabin'), surfaces, mats, opts);+ cabin.group.add(doorSign(room('cabin'), placeById('launchpad'), 'Mission control', 'Launch desk'));+ const cabinLight = new PointLight(0xffe4c4, 0.6, 5, 2);+ cabinLight.position.set(0, room('cabin').h - 0.4, 0);+ cabin.group.add(cabinLight);+ cabin.group.traverse((o) => { if (o.isMesh) o.userData.hit = { type: 'place', id: 'launchpad' }; });+ {+ const fr = roomFrame(room('cabin'));+ cabin.group.position.set(fr.x, 0, fr.z);+ cabin.group.rotation.y = fr.yaw;+ }+ const mine = buildMine(room('mine'), placeById('mine'), surfaces, mats, opts);+ const forge = buildForge(room('forge'), placeById('forge'), surfaces, mats, opts);+ const gallery = buildGallery(room('gallery'), placeById('gallery'), surfaces, mats, opts);+ const plaza = buildPlaza(room('plaza'), placeById('agents'), surfaces, mats, opts);+ const market = buildMarket(room('market'), placeById('market'), surfaces, mats, opts);+ const buildings = [office, exchange, launchpad, cabin, mine, forge, gallery, plaza, market];+ for (const b of buildings) scene.add(b.group);+ const occluders = buildings.flatMap((b) => b.occluders).concat(grounds.occluders);++ // Solids: every wall (through its door), the furniture, the rocket and the+ // posts, the desk and the veins. Places themselves are walk-in now, so+ // their keep-out radii drive prompts and stand points, not collision.+ const solids = allRoomSolids();const o = placeById('office');solids.push({ group: { position: new Vector3(o.x, 0, o.z - 0.5) }, keepout: 1.35 });- // Mine shoulders.- const m = placeById('mine');- solids.push({ group: { position: new Vector3(m.x - 5.2, 0, m.z - 3) }, keepout: 2.6 }, { group: { position: new Vector3(m.x + 5.2, 0, m.z - 3) }, keepout: 2.6 });for (const v of mine.veins) solids.push({ group: { position: new Vector3(v.x, 0, v.z) }, keepout: 0.75 });+ const localSolid = (b, roomId) => {+ const fr = roomFrame(room(roomId));+ const sin = Math.sin(fr.yaw);+ const cos = Math.cos(fr.yaw);+ for (const s of b.localSolids || []) {+ if (s.box) {+ const [lx, lz, w, d] = s.box;+ solids.push(boxSolid(fr.x + lx * cos + lz * sin, fr.z - lx * sin + lz * cos, fr.yaw + (s.yaw || 0), w, d));+ } else solids.push({ group: { position: new Vector3(fr.x + s.x * cos + s.z * sin, 0, fr.z - s.x * sin + s.z * cos) }, keepout: s.keepout });+ }+ };+ localSolid(exchange, 'exchange');+ localSolid(forge, 'forge');+ localSolid(plaza, 'plaza');+ localSolid(market, 'market');+ const propTier = tierName === 'mobile' ? 'mobile' : 'desktop';+ const placements = placeProps(propTier);+ solids.push(...propSolids(placements));+ // Agents keep to the grounds: their stroll solids add each building's footprint.+ const strollSolids = solids.concat(ROOMS.filter((r) => r.w).map((r) => {+ const fr = roomFrame(r);+ return { group: { position: new Vector3(fr.x, 0, fr.z) }, keepout: Math.hypot(r.w, r.d) / 2 + 1 };+ }));++ // Props stream in from the object library once the first frame is up.+ const propHit = (p) => (p.place && p.place !== 'office' && p.place !== 'mine' ? { type: 'place', id: p.place } : null);+ const props = createPropLoader(renderer, scene, placements, { shadows, from: SPAWN, reducedMotion, hitFor: propHit });+ let propsStarted = false;- // Highlight: the nearest interactable gets a soft ring under it (an agent's- // ring follows the agent, so the caller passes its current x/z).+ // Highlight: the nearest interactable gets a soft ring under it.const halo = new Mesh(new RingGeometry(0.9, 1.1, 40), new MeshBasicMaterial({ color: VIOLET, transparent: true, opacity: 0.7, toneMapped: false }));- halo.rotation.x = -Math.PI / 2;- halo.position.y = 0.03;+ halo.rotation.x = -PI / 2;+ halo.position.y = 0.035;halo.visible = false;+ halo.raycast = () => {};scene.add(halo);function highlight(target) {if (!target) {@@ -623,10 +1172,13 @@ export function createCampus(canvas, { screenMaterial, tickerMaterial, reducedMoz = v.z;r = 0.9;} else if (target.type === 'place') {+ // The ring sits in the doorway (or in the middle of an open-air place), not round the whole building.const p = placeById(target.id);- x = p.x;- z = p.z;- r = p.keepout + 0.6;+ const rm = ROOMS.find((rr) => rr.place === p.id);+ const door = rm?.door ? doorPoints(rm, 0.9).outside : null;+ x = door ? door.x : p.x;+ z = door ? door.z : p.z;+ r = door ? 1.1 : 1.6;} else if (target.type === 'agent') {r = 0.75;}@@ -651,18 +1203,53 @@ export function createCampus(canvas, { screenMaterial, tickerMaterial, reducedMoreturn null;}+ // The gallery hangs real agents' portraits.+ const artLoader = new TextureLoader();+ artLoader.setCrossOrigin('anonymous');+ function hangArt(list) {+ gallery.frames.forEach((f, i) => {+ const item = list[i];+ if (!item?.url) return;+ artLoader.load(item.url, (tex) => {+ tex.colorSpace = SRGBColorSpace;+ tex.anisotropy = 4;+ f.art.material.map?.dispose();+ f.art.material.map = tex;+ f.art.material.color.set(0xffffff);+ f.art.material.needsUpdate = true;+ }, undefined, () => {});+ const plateTex = signTexture(item.name, '', '#c4b5fd');+ f.plate.material.map?.dispose();+ f.plate.material.map = plateTex;+ f.plate.material.color.set(0xffffff);+ f.plate.material.needsUpdate = true;+ });+ }+let t = 0;- function tick(dt) {+ const shadowAnchor = new Vector3();+ function tick(dt, playerPos) {+ if (!propsStarted) {+ propsStarted = true;+ props.start().then(() => log.info('world/campus', `${props.loaded} of ${props.models} prop models in, ${props.failed} failed`));+ }+ props.tick(dt);+ if (playerPos && shadows) {+ // The shadow frustum follows the visitor, snapped to whole metres so edges do not swim.+ shadowAnchor.set(Math.round(playerPos.x), 0, Math.round(playerPos.z));+ sun.target.position.copy(shadowAnchor);+ sun.position.copy(shadowAnchor).addScaledVector(sunDir, 70);+ }if (reducedMotion) return;t += dt;- launchpad.rocket.position.y = 0.5 + Math.sin(t * 0.8) * 0.06;+ launchpad.rocket.position.y = 0.55 + Math.sin(t * 0.8) * 0.03;launchpad.flame.scale.set(1 + Math.sin(t * 17) * 0.12, 1 + Math.sin(t * 13) * 0.2, 1 + Math.cos(t * 15) * 0.12);for (const v of mine.veins) {const k = 0.45 + Math.sin(t * 1.6 + v.phase) * 0.2;v.material.emissiveIntensity = k;v.light.intensity = 0.4 + k;}- for (const f of gallery.frames) f.rotation.y += dt * 0.25;+ for (const m of forge.pulse) m.color.setScalar(1.5 + Math.sin(t * 6) * 0.35).multiply(new Color(0xff7a2a));halo.material.opacity = 0.55 + Math.sin(t * 4) * 0.2;}@@ -676,16 +1263,20 @@ export function createCampus(canvas, { screenMaterial, tickerMaterial, reducedMofunction dispose() {renderer.setAnimationLoop(null);+ props.dispose();scene.traverse((obj) => {obj.geometry?.dispose?.();- const mats = Array.isArray(obj.material) ? obj.material : obj.material ? [obj.material] : [];- for (const mat of mats) {+ const ms = Array.isArray(obj.material) ? obj.material : obj.material ? [obj.material] : [];+ for (const mat of ms) {if (mat === screenMaterial || mat === tickerMaterial) continue;mat.map?.dispose?.();+ mat.emissiveMap?.dispose?.();mat.dispose?.();}});- groundTex.dispose();+ surfaces.dispose();+ scene.environment?.dispose?.();+ disposeGltfLoader(renderer);renderer.dispose();}@@ -694,10 +1285,14 @@ export function createCampus(canvas, { screenMaterial, tickerMaterial, reducedMoscene,camera,solids,+ strollSolids,+ occluders,+ tier: tierName,veinPositions: mine.veins.map((v) => ({ id: v.id, x: v.x, z: v.z })),desk: office,highlight,pick,+ hangArt,tick,resize,dispose,diff --git a/src/desktop/world/index.js b/src/desktop/world/index.jsindex ab6c9d60b..a580b9d34 100644--- a/src/desktop/world/index.js+++ b/src/desktop/world/index.js@@ -5,7 +5,7 @@// visitor starts here or on the desktop; the taskbar's World button brings// them back.-import { MeshBasicMaterial, Vector3 } from 'three';+import { MeshBasicMaterial, Raycaster, Vector3 } from 'three';import { createPlayer } from '../../docs-world/player.js';import { createControls } from '../../docs-world/controls.js';import { createCameraModeController, CAMERA_MODE_LABELS } from '../../game/camera-modes.js';@@ -20,7 +20,8 @@ import { enterVR, vrSupported } from './xr.js';import { createAgents } from './agents.js';import { APPROACH_DISTANCE } from './cast.js';import { createTalkPanel } from './talk.js';-import { CAMPUS_RADIUS, PLACES, SPAWN, nearestInteractable, placeById, standPointFor } from './places.js';+import { CAMPUS_RADIUS, PLACES, SPAWN, nearestInteractable, placeById } from './places.js';+import { arrivalPointFor } from './rooms.js';import './world.css';const TICKER_REFRESH_MS = 60_000;@@ -118,7 +119,7 @@ export function createWorld({ shell, apps, reducedMotion = false, onDesktop }) {const agents = createAgents({scene,tagsEl: $('.wd-tags'),- solids: campus.solids,+ solids: campus.strollSolids,isTouch,reducedMotion,visitorName: () => shell.displayName(),@@ -126,6 +127,7 @@ export function createWorld({ shell, apps, reducedMotion = false, onDesktop }) {});let castErrorShown = false;agents.onState(({ state, error }) => {+ if (state === 'ready') campus.hangArt(agents.thumbs());if (state === 'error' && !castErrorShown) {castErrorShown = true;toast(`The agents could not come out: ${error}. The campus is still open.`, '#f87171');@@ -172,6 +174,23 @@ export function createWorld({ shell, apps, reducedMotion = false, onDesktop }) {syncCamera();camBtn.addEventListener('click', () => cameraCtl.cycle(camera));+ // Walls, roofs and the hill never come between the camera and the avatar:+ // when one does, the camera moves up to it, so rooms stay readable inside.+ const occluderRay = new Raycaster();+ const eye = new Vector3();+ const toCamera = new Vector3();+ function keepCameraInRoom() {+ eye.set(player.position.x, player.position.y + 1.4, player.position.z);+ toCamera.subVectors(camera.position, eye);+ const dist = toCamera.length();+ if (dist < 0.5) return;+ occluderRay.set(eye, toCamera.divideScalar(dist));+ occluderRay.far = dist;+ const hit = occluderRay.intersectObjects(campus.occluders, false)[0];+ if (!hit) return;+ camera.position.copy(eye).addScaledVector(toCamera, Math.max(0.4, hit.distance - 0.35));+ }+let busy = false; // a transition is running: ignore interactionslet nearest = null;let digHeld = false;@@ -259,9 +278,9 @@ export function createWorld({ shell, apps, reducedMotion = false, onDesktop }) {b.addEventListener('click', () => goTo(p));nav.append(b);}- /** Put the player just outside a place, facing it. */+ /** Put the player at a place's door (or on its approach), facing in. */function goTo(p) {- const s = standPointFor(p);+ const s = arrivalPointFor(p);player.root.position.set(s.x, 0, s.z);player.root.rotation.y = s.yaw;controls.orbit.yaw = s.yaw;@@ -335,7 +354,7 @@ export function createWorld({ shell, apps, reducedMotion = false, onDesktop }) {talk.close();controls.enabled = false;await fadeTo(true, `Entering ${place.title}`);- const s = standPointFor(place);+ const s = arrivalPointFor(place);player.root.position.set(s.x, 0, s.z);player.root.rotation.y = s.yaw;leaveTo({ app: place.app, place: place.id });@@ -476,7 +495,7 @@ export function createWorld({ shell, apps, reducedMotion = false, onDesktop }) {const yaw = xr ? Math.atan2(-camera.matrixWorld.elements[8], -camera.matrixWorld.elements[10]) + Math.PI : controls.orbit.yaw;player.update(dt, move, yaw, controls.run, campus.solids);if (!sitting) agents.update(dt, player.position, camera);- campus.tick(dt);+ campus.tick(dt, player.position);ticker.tick(dt);if (Math.hypot(player.position.x, player.position.z - 8) < 14) {screen.draw({ wall: shell.prefs.wall, name: shell.displayName(), prompt: nearest?.id === 'monitor' ? 'Press E to sit down' : '', clock24: shell.prefs.clock24, accent: shell.prefs.accent });@@ -498,6 +517,7 @@ export function createWorld({ shell, apps, reducedMotion = false, onDesktop }) {} else {cameraCtl.tick(dt);cameraCtl.apply(camera, player.position, player.height, controls.orbit, 0.35);+ if (!cameraCtl.isFirstPerson()) keepCameraInRoom();}renderer.render(scene, camera);}diff --git a/src/desktop/world/prop-loader.js b/src/desktop/world/prop-loader.jsnew file mode 100644index 000000000..8b3b4eca9--- /dev/null+++ b/src/desktop/world/prop-loader.js@@ -0,0 +1,130 @@+// Streams the campus props (props.js) in from the object library: one+// download per model, a clone per placement, nearest to the visitor first, a+// few at a time, each one growing in where it stands. Everything it creates+// it can dispose.++import { Box3, Group, Vector3 } from 'three';+import { gltfLoader } from '../../loaders/gltf.js';+import { log } from '../../shared/log.js';++const CONCURRENCY = 3;+const GROW_SECONDS = 0.35;++/**+ * @param {import('three').WebGLRenderer} renderer+ * @param {import('three').Scene} scene+ * @param {Array<object>} placements from props.js placeProps()+ * @param {{ shadows: boolean, from: {x:number, z:number}, reducedMotion?: boolean, hitFor?: (placement) => object|null }} o+ */+export function createPropLoader(renderer, scene, placements, { shadows, from, reducedMotion = false, hitFor }) {+ const loader = gltfLoader(renderer);+ const byModel = new Map();+ for (const p of placements) {+ if (!byModel.has(p.model)) byModel.set(p.model, []);+ byModel.get(p.model).push(p);+ }+ const order = [...byModel.entries()].map(([model, list]) => ({ model, list, d: Math.min(...list.map((p) => Math.hypot(p.x - from.x, p.z - from.z))) })).sort((a, b) => a.d - b.d);+ const templates = [];+ const growing = [];+ const placed = [];+ let disposed = false;+ let loaded = 0;+ let failed = 0;+ const box = new Box3();+ const size = new Vector3();+ const centre = new Vector3();++ async function loadOne({ model, list }) {+ let gltf;+ try {+ gltf = await loader.loadAsync(list[0].url);+ } catch (err) {+ failed++;+ log.warn('world/props', `${model} did not load`, err?.message || err);+ return;+ }+ if (disposed) {+ disposeObject(gltf.scene);+ return;+ }+ const template = gltf.scene;+ template.traverse((o) => {+ if (!o.isMesh) return;+ o.castShadow = shadows;+ o.receiveShadow = true;+ if (o.material?.map) o.material.map.anisotropy = 4;+ });+ templates.push(template);+ box.setFromObject(template);+ box.getSize(size);+ box.getCenter(centre);+ for (const p of list) {+ const holder = new Group();+ holder.position.set(p.x, p.y, p.z);+ holder.rotation.y = p.yaw;+ const inner = template.clone();+ inner.scale.setScalar(p.scale);+ if (p.anchor === 'floor') inner.position.set(-centre.x * p.scale, -box.min.y * p.scale, -centre.z * p.scale);+ holder.add(inner);+ const hit = hitFor?.(p);+ if (hit) holder.traverse((o) => { o.userData.hit = hit; });+ holder.userData.prop = p.model;+ scene.add(holder);+ placed.push(holder);+ if (reducedMotion) continue;+ holder.scale.setScalar(0.001);+ growing.push({ holder, t: 0 });+ }+ loaded++;+ }++ let started = false;+ async function start() {+ if (started) return;+ started = true;+ const queue = order.slice();+ const workers = Array.from({ length: CONCURRENCY }, async () => {+ while (queue.length && !disposed) await loadOne(queue.shift());+ });+ await Promise.all(workers);+ }++ function tick(dt) {+ for (let i = growing.length - 1; i >= 0; i--) {+ const g = growing[i];+ g.t = Math.min(1, g.t + dt / GROW_SECONDS);+ const e = 1 - (1 - g.t) * (1 - g.t);+ g.holder.scale.setScalar(Math.max(0.001, e));+ if (g.t >= 1) growing.splice(i, 1);+ }+ }++ function dispose() {+ disposed = true;+ for (const h of placed) scene.remove(h);+ for (const t of templates) disposeObject(t);+ placed.length = 0;+ templates.length = 0;+ growing.length = 0;+ }++ return {+ start,+ tick,+ dispose,+ get models() { return order.length; },+ get loaded() { return loaded; },+ get failed() { return failed; },+ };+}++function disposeObject(root) {+ root.traverse((o) => {+ o.geometry?.dispose?.();+ const mats = Array.isArray(o.material) ? o.material : o.material ? [o.material] : [];+ for (const m of mats) {+ for (const k of ['map', 'normalMap', 'roughnessMap', 'metalnessMap', 'aoMap', 'emissiveMap', 'alphaMap']) m[k]?.dispose?.();+ m.dispose?.();+ }+ });+}diff --git a/src/desktop/world/props.js b/src/desktop/world/props.jsnew file mode 100644index 000000000..36bf7b079--- /dev/null+++ b/src/desktop/world/props.js@@ -0,0 +1,256 @@+// Real objects for the campus: the furniture, lamps, plants and tools that+// make a room a room. Every model is a CC0 scan from the platform's own+// object library (the same CDN src/objects-library.js serves), measured once+// so this file can place them without loading anything. Pure data and+// placement maths; campus.js does the loading.+//+// Positions are room-local (see rooms.js: +z is the front/door side, +x the+// right hand side seen from the front) unless `world: true`. `anchor: 'floor'`+// drops the model's bounding box onto y; 'origin' keeps the file's own origin+// (ceiling lamps hang from theirs, the rock set is modelled part-buried).++import { CAMPUS_RADIUS, placeById } from './places.js';+import { roomById, roomToWorld } from './rooms.js';++export const LIBRARY_BASE = 'https://pub-2534e921bf9c4314addcd4d8a6e98b7b.r2.dev/objects/polyhaven/glb';+export const LIBRARY_LICENSE = 'CC0';++/** Payload budgets in bytes: a desktop on a decent line, and a phone. */+export const PROP_BUDGET = { desktop: 58 * 1048576, mobile: 16 * 1048576 };++/** Measured bounding boxes (metres) and compressed sizes of every model used. */+export const MODELS = {+ street_lamp_01: { bytes: 2471216, w: 0.7, h: 3.87, d: 0.39 },+ painted_wooden_bench: { bytes: 1988580, w: 1.16, h: 0.89, d: 0.5 },+ outdoor_table_chair_set_01: { bytes: 1239772, w: 0.74, h: 0.86, d: 1.72 },+ planter_box_01: { bytes: 2338392, w: 0.91, h: 0.42, d: 0.41 },+ shrub_02: { bytes: 1962912, w: 6.05, h: 1.7, d: 2.29 },+ grass_medium_02: { bytes: 797444, w: 1.31, h: 0.41, d: 0.43 },+ fern_02: { bytes: 1143468, w: 1.97, h: 0.43, d: 1.72 },+ quiver_tree_02: { bytes: 4546840, w: 0.87, h: 1.47, d: 0.88 },+ rock_moss_set_01: { bytes: 1932784, w: 8, h: 1.77, d: 6.95 },+ metal_office_desk: { bytes: 1600260, w: 2.0, h: 0.79, d: 0.95 },+ modern_arm_chair_01: { bytes: 2696080, w: 0.82, h: 1.02, d: 0.99 },+ classic_laptop: { bytes: 2180780, w: 0.65, h: 0.54, d: 0.49 },+ potted_plant_02: { bytes: 2632148, w: 0.7, h: 0.84, d: 0.66 },+ steel_frame_shelves_01: { bytes: 1596392, w: 10.97, h: 21.41, d: 5.02 },+ wall_clock: { bytes: 1560784, w: 0.32, h: 0.32, d: 0.06 },+ hanging_picture_frame_01: { bytes: 483412, w: 0.59, h: 0.84, d: 0.04 },+ hanging_picture_frame_02: { bytes: 693508, w: 0.75, h: 0.5, d: 0.04 },+ fancy_picture_frame_01: { bytes: 739640, w: 0.6, h: 0.46, d: 0.05 },+ modern_ceiling_lamp_01: { bytes: 433412, w: 0.4, h: 0.95, d: 0.4 },+ sofa_03: { bytes: 818108, w: 2.73, h: 1.12, d: 0.93 },+ sofa_02: { bytes: 425576, w: 1.81, h: 0.71, d: 0.82 },+ modern_coffee_table_01: { bytes: 1330320, w: 0.6, h: 0.39, d: 1.2 },+ side_table_01: { bytes: 504336, w: 0.55, h: 0.55, d: 0.45 },+ drawer_cabinet: { bytes: 1140032, w: 1.14, h: 1.88, d: 0.49 },+ dining_chair_02: { bytes: 920128, w: 0.43, h: 0.97, d: 0.58 },+ hanging_industrial_lamp: { bytes: 3241308, w: 0.55, h: 1.36, d: 0.55 },+ old_drill_press: { bytes: 2350984, w: 0.53, h: 1.05, d: 0.61 },+ wooden_crate_01: { bytes: 2274660, w: 0.83, h: 0.35, d: 0.41 },+ wooden_stool_01: { bytes: 960764, w: 0.43, h: 0.44, d: 0.43 },+ steel_frame_shelves_02: { bytes: 539296, w: 0.59, h: 2.14, d: 0.5 },+ CoffeeCart_01: { bytes: 1832980, w: 2.17, h: 1.72, d: 1.07 },+ standing_chalkboard_01: { bytes: 2615284, w: 0.92, h: 1.51, d: 0.76 },+ SchoolDesk_01: { bytes: 420696, w: 0.71, h: 0.88, d: 0.55 },+};++export function propUrl(model) {+ return `${LIBRARY_BASE}/${model}.glb`;+}++const PI = Math.PI;+const half = PI / 2;++/**+ * Where everything stands. `room` places in that room's frame; `place` in the+ * place's own frame (its front toward the campus centre); `world` in world+ * space. `solid` adds collision: a radius, or {w, d} for a box of that size.+ * `mobile: true` keeps the prop on phones.+ */+export const PROPS = [+ // Office: a real desk the built-in monitor and phone sit on, somewhere to sit and a shelf of things.+ { model: 'metal_office_desk', room: 'office', x: 0, z: -0.5, yaw: 0, mobile: true },+ { model: 'modern_arm_chair_01', room: 'office', x: 0, z: 0.6, yaw: PI, mobile: true },+ { model: 'steel_frame_shelves_01', room: 'office', x: -3.2, z: -3.05, yaw: 0, scale: 0.1, solid: { w: 1.1, d: 0.5 } },+ { model: 'drawer_cabinet', room: 'office', x: 3.2, z: -3.05, yaw: 0, solid: { w: 1.14, d: 0.5 } },+ { model: 'wall_clock', room: 'office', x: 2.2, z: -3.3, y: 2.2, yaw: 0, anchor: 'origin' },+ { model: 'hanging_picture_frame_01', room: 'office', x: -4.33, z: -1.4, y: 1.7, yaw: half, anchor: 'origin', mobile: true },+ { model: 'sofa_03', room: 'office', x: -3.85, z: 1.0, yaw: half, solid: { w: 1, d: 2.8 }, mobile: true },+ { model: 'modern_coffee_table_01', room: 'office', x: -2.9, z: 1.0, yaw: 0, solid: 0.5, mobile: true },+ { model: 'classic_laptop', room: 'office', x: -2.9, z: 1.0, y: 0.39, yaw: -half },+ { model: 'potted_plant_02', room: 'office', x: 3.7, z: 2.6, yaw: 0, solid: 0.4 },+ { model: 'modern_ceiling_lamp_01', room: 'office', x: 0, z: 0.8, y: 1.8, anchor: 'origin', mobile: true },++ // Exchange: four trading desks, lamps over the floor, clocks for three markets.+ { model: 'metal_office_desk', room: 'exchange', x: -3.4, z: -1.6, yaw: 0, solid: { w: 2, d: 1 }, mobile: true },+ { model: 'metal_office_desk', room: 'exchange', x: 3.4, z: -1.6, yaw: 0, solid: { w: 2, d: 1 }, mobile: true },+ { model: 'metal_office_desk', room: 'exchange', x: -3.4, z: 1.6, yaw: PI, solid: { w: 2, d: 1 } },+ { model: 'metal_office_desk', room: 'exchange', x: 3.4, z: 1.6, yaw: PI, solid: { w: 2, d: 1 } },+ { model: 'dining_chair_02', room: 'exchange', x: -3.4, z: -0.75, yaw: PI, mobile: true },+ { model: 'dining_chair_02', room: 'exchange', x: 3.4, z: -0.75, yaw: PI, mobile: true },+ { model: 'dining_chair_02', room: 'exchange', x: -3.4, z: 0.75, yaw: 0 },+ { model: 'dining_chair_02', room: 'exchange', x: 3.4, z: 0.75, yaw: 0 },+ { model: 'classic_laptop', room: 'exchange', x: -3.4, z: -1.6, y: 0.79, yaw: 0 },+ { model: 'classic_laptop', room: 'exchange', x: 3.4, z: -1.6, y: 0.79, yaw: 0 },+ { model: 'classic_laptop', room: 'exchange', x: -3.4, z: 1.6, y: 0.79, yaw: PI },+ { model: 'classic_laptop', room: 'exchange', x: 3.4, z: 1.6, y: 0.79, yaw: PI },+ { model: 'hanging_industrial_lamp', room: 'exchange', x: -3.4, z: 0, y: 5.2, anchor: 'origin' },+ { model: 'hanging_industrial_lamp', room: 'exchange', x: 0, z: 0, y: 5.2, anchor: 'origin' },+ { model: 'hanging_industrial_lamp', room: 'exchange', x: 3.4, z: 0, y: 5.2, anchor: 'origin' },+ { model: 'wall_clock', room: 'exchange', x: -2.4, z: -4.3, y: 3.6, yaw: 0, anchor: 'origin' },+ { model: 'wall_clock', room: 'exchange', x: 0, z: -4.3, y: 3.6, yaw: 0, anchor: 'origin' },+ { model: 'wall_clock', room: 'exchange', x: 2.4, z: -4.3, y: 3.6, yaw: 0, anchor: 'origin' },+ { model: 'potted_plant_02', room: 'exchange', x: -5.6, z: 3.6, yaw: 0, solid: 0.4 },+ { model: 'potted_plant_02', room: 'exchange', x: 5.6, z: 3.6, yaw: 0, solid: 0.4 },++ // Launch pad: the control cabin's desk, and crates of parts by the pad.+ { model: 'SchoolDesk_01', room: 'cabin', x: 0, z: -0.7, yaw: 0, mobile: true },+ { model: 'classic_laptop', room: 'cabin', x: 0, z: -0.7, y: 0.74, yaw: 0 },+ { model: 'dining_chair_02', room: 'cabin', x: 0, z: 0.1, yaw: PI },+ { model: 'wooden_crate_01', place: 'launchpad', x: 3.2, z: 3.2, yaw: 0.4, solid: 0.5 },+ { model: 'wooden_crate_01', place: 'launchpad', x: 3.6, z: 2.5, yaw: -0.3 },+ { model: 'street_lamp_01', place: 'launchpad', x: -5.8, z: 5.6, yaw: 0, solid: 0.3, mobile: true },+ { model: 'street_lamp_01', place: 'launchpad', x: 5.8, z: 5.6, yaw: 0, solid: 0.3, mobile: true },++ // Mine: crates by the portal, a lamp over the face, mossy rock at the hill's foot.+ { model: 'wooden_crate_01', room: 'mine', x: -5.6, z: 3.2, yaw: 0.2, solid: 0.5 },+ { model: 'wooden_crate_01', room: 'mine', x: -4.9, z: 3.5, yaw: -0.4 },+ { model: 'hanging_industrial_lamp', room: 'mine', x: 0, z: -2, y: 4.5, anchor: 'origin' },+ { model: 'hanging_industrial_lamp', room: 'mine', x: -4, z: 1, y: 4.5, anchor: 'origin' },+ { model: 'hanging_industrial_lamp', room: 'mine', x: 4, z: 1, y: 4.5, anchor: 'origin' },+ { model: 'rock_moss_set_01', place: 'mine', x: -11.5, z: 5, yaw: 0.6, anchor: 'origin' },+ { model: 'rock_moss_set_01', place: 'mine', x: 11.5, z: 5, yaw: -2.4, anchor: 'origin' },++ // Forge: the drill press, shelves of parts, a stool and a lamp over the bench.+ { model: 'old_drill_press', room: 'forge', x: -2.4, z: -2.2, yaw: 0, solid: 0.45 },+ { model: 'steel_frame_shelves_02', room: 'forge', x: 2.8, z: -0.4, yaw: -half, solid: { w: 0.6, d: 2.2 } },+ { model: 'wooden_crate_01', room: 'forge', x: 2.5, z: 1.8, yaw: 0.3, solid: 0.5 },+ { model: 'wooden_stool_01', room: 'forge', x: -0.6, z: -1.3, yaw: 0.5 },+ { model: 'hanging_industrial_lamp', room: 'forge', x: 0, z: -1, y: 3.4, anchor: 'origin' },++ // Gallery: frames go up through campus.hangArt; a bench to sit and look.+ { model: 'sofa_02', room: 'gallery', x: 0, z: 0.3, yaw: PI, solid: { w: 1.9, d: 0.9 }, mobile: true },+ { model: 'potted_plant_02', room: 'gallery', x: -2.6, z: 2.5, yaw: 0, solid: 0.4 },+ { model: 'potted_plant_02', room: 'gallery', x: 2.6, z: 2.5, yaw: 0, solid: 0.4 },++ // Market: a coffee cart, the chalkboard menu, crates of stock and bistro tables outside.+ { model: 'CoffeeCart_01', room: 'market', x: -2.6, z: -1.8, yaw: 0, solid: { w: 2.2, d: 1.1 } },+ { model: 'standing_chalkboard_01', room: 'market', x: -0.9, z: -1.6, yaw: 0.3, solid: 0.5 },+ { model: 'wooden_crate_01', room: 'market', x: 3.6, z: 2.6, yaw: 0.2, solid: 0.5 },+ { model: 'wooden_crate_01', room: 'market', x: 4.1, z: 2.0, yaw: -0.5 },+ { model: 'outdoor_table_chair_set_01', room: 'market', x: 1.4, z: 1.4, yaw: 0, solid: 0.9 },+ { model: 'outdoor_table_chair_set_01', room: 'market', x: -2.4, z: 1.2, yaw: 0, solid: 0.9 },+ { model: 'planter_box_01', place: 'market', x: -4.2, z: 5.2, yaw: 0, solid: 0.5 },+ { model: 'planter_box_01', place: 'market', x: 4.2, z: 5.2, yaw: 0, solid: 0.5 },++ // Agent plaza: benches round the pergola, planters, lamps and a tree.+ { model: 'painted_wooden_bench', room: 'plaza', x: -3.6, z: 0, yaw: half, solid: { w: 0.5, d: 1.2 }, mobile: true },+ { model: 'painted_wooden_bench', room: 'plaza', x: 3.6, z: 0, yaw: -half, solid: { w: 0.5, d: 1.2 }, mobile: true },+ { model: 'painted_wooden_bench', room: 'plaza', x: 0, z: -3.6, yaw: 0, solid: { w: 1.2, d: 0.5 } },+ { model: 'planter_box_01', room: 'plaza', x: -3.6, z: -3.6, yaw: 0.8, solid: 0.5 },+ { model: 'planter_box_01', room: 'plaza', x: 3.6, z: -3.6, yaw: -0.8, solid: 0.5 },+ { model: 'street_lamp_01', room: 'plaza', x: -5.6, z: 3.4, yaw: 0, solid: 0.3, mobile: true },+ { model: 'street_lamp_01', room: 'plaza', x: 5.6, z: 3.4, yaw: 0, solid: 0.3, mobile: true },+ { model: 'quiver_tree_02', room: 'plaza', x: 0, z: -7.6, yaw: 0, scale: 3, solid: 0.6 },++ // Around the campus: lamps along the way in, benches by the paths, greenery.+ { model: 'street_lamp_01', world: true, x: -3.2, z: 24, yaw: 0, solid: 0.3, mobile: true },+ { model: 'street_lamp_01', world: true, x: 3.2, z: 18, yaw: 0, solid: 0.3, mobile: true },+ { model: 'street_lamp_01', world: true, x: -7.6, z: 0.4, yaw: 0, solid: 0.3, mobile: true },+ { model: 'street_lamp_01', world: true, x: 7.6, z: 0.4, yaw: 0, solid: 0.3, mobile: true },+ { model: 'street_lamp_01', world: true, x: -9, z: -16, yaw: 0, solid: 0.3 },+ { model: 'street_lamp_01', world: true, x: 9, z: -16, yaw: 0, solid: 0.3 },+ { model: 'painted_wooden_bench', world: true, x: -6.2, z: 20, yaw: 1.2, solid: { w: 1.2, d: 0.5 }, mobile: true },+ { model: 'painted_wooden_bench', world: true, x: 6.4, z: 13, yaw: -1.9, solid: { w: 1.2, d: 0.5 }, mobile: true },+ { model: 'painted_wooden_bench', world: true, x: -8.2, z: -12.6, yaw: 0.6, solid: { w: 1.2, d: 0.5 } },+ { model: 'painted_wooden_bench', world: true, x: 8.2, z: -12.6, yaw: -0.6, solid: { w: 1.2, d: 0.5 } },+ { model: 'quiver_tree_02', world: true, x: -13, z: 6, yaw: 0.3, scale: 3, solid: 0.6 },+ { model: 'quiver_tree_02', world: true, x: 13, z: 6, yaw: 2.1, scale: 3, solid: 0.6 },+ { model: 'quiver_tree_02', world: true, x: -12, z: -14, yaw: 1.1, scale: 3.4, solid: 0.6 },+ { model: 'quiver_tree_02', world: true, x: 12, z: -14, yaw: -0.7, scale: 3.2, solid: 0.6 },+ { model: 'quiver_tree_02', world: true, x: -16, z: 28, yaw: 0, scale: 3.6, solid: 0.6 },+ { model: 'quiver_tree_02', world: true, x: 16, z: 28, yaw: 0, scale: 3.3, solid: 0.6 },+ { model: 'fern_02', world: true, x: -9, z: 9, yaw: 0.5 },+ { model: 'fern_02', world: true, x: 9.2, z: 9.4, yaw: 2.2 },+ { model: 'fern_02', world: true, x: -14, z: -15.6, yaw: 1.3 },+ { model: 'grass_medium_02', world: true, x: -5.4, z: 14, yaw: 0.2 },+ { model: 'grass_medium_02', world: true, x: 5.8, z: 22, yaw: 1.4 },+ { model: 'grass_medium_02', world: true, x: -11, z: -3, yaw: 2.6 },+ { model: 'grass_medium_02', world: true, x: 11.4, z: -2.2, yaw: 0.9 },+ { model: 'grass_medium_02', world: true, x: -30, z: 4, yaw: 1.9 },+ { model: 'grass_medium_02', world: true, x: 30, z: 3, yaw: 0.4 },+ { model: 'rock_moss_set_01', world: true, x: -30, z: 30, yaw: 0.8, anchor: 'origin' },+ { model: 'rock_moss_set_01', world: true, x: 30, z: 30, yaw: -1.9, anchor: 'origin' },+ { model: 'planter_box_01', world: true, x: -2.2, z: 12.4, yaw: 0, solid: 0.5 },+ { model: 'planter_box_01', world: true, x: 2.2, z: 12.4, yaw: 0, solid: 0.5 },+];++/** How many hedge bushes ring the campus and the radius they stand on. */+export const HEDGE = { model: 'shrub_02', radius: CAMPUS_RADIUS + 2.5, count: 44, gapAt: Math.PI / 2, gapWidth: 0.34 };++/** The hedge ring resolved to world placements, leaving the gate open behind the spawn. */+export function hedgePlacements() {+ const out = [];+ for (let i = 0; i < HEDGE.count; i++) {+ const a = (i / HEDGE.count) * Math.PI * 2;+ // The gate is on +z (atan2(x, z) = 0): leave it open.+ let gap = Math.abs(Math.atan2(Math.sin(a), Math.cos(a)));+ if (gap < HEDGE.gapWidth) continue;+ out.push({ model: HEDGE.model, url: propUrl(HEDGE.model), bytes: MODELS[HEDGE.model].bytes, x: Math.sin(a) * HEDGE.radius, z: Math.cos(a) * HEDGE.radius, yaw: a + Math.PI / 2, y: 0, anchor: 'floor', scale: 1, mobile: true, solid: null, world: true });+ }+ return out;+}++/**+ * Resolve every prop for a quality tier into world placements:+ * {model, url, x, y, z, yaw, scale, anchor, solid, mobile, place}.+ * @param {'desktop'|'mobile'} tier+ */+export function placeProps(tier = 'desktop') {+ const list = PROPS.filter((p) => tier !== 'mobile' || p.mobile).map(resolveProp);+ return list.concat(tier === 'mobile' ? hedgePlacements().filter((_, i) => i % 2 === 0) : hedgePlacements());+}++export function resolveProp(p) {+ const def = MODELS[p.model];+ if (!def) throw new Error(`unknown prop model ${p.model}`);+ let x = p.x;+ let z = p.z;+ let yaw = p.yaw || 0;+ let place = null;+ if (p.room) {+ const room = roomById(p.room);+ const w = roomToWorld(room, p.x, p.z);+ x = w.x;+ z = w.z;+ yaw = w.yaw + (p.yaw || 0);+ place = room.place;+ } else if (p.place) {+ place = placeById(p.place).id;+ const w = roomToWorld({ place }, p.x, p.z);+ x = w.x;+ z = w.z;+ yaw = w.yaw + (p.yaw || 0);+ }+ return { model: p.model, url: propUrl(p.model), x, y: p.y || 0, z, yaw, scale: p.scale || 1, anchor: p.anchor || 'floor', solid: p.solid ?? null, mobile: !!p.mobile, bytes: def.bytes, place };+}++/** Bytes a tier downloads: each model once, however many times it is placed. */+export function payloadBytes(tier = 'desktop') {+ const seen = new Set(placeProps(tier).map((p) => p.model));+ let total = 0;+ for (const m of seen) total += MODELS[m].bytes;+ return total;+}++/** Collision for the placed props (world space), for the player and the agents. */+export function propSolids(placements) {+ const out = [];+ for (const p of placements) {+ if (!p.solid) continue;+ if (typeof p.solid === 'number') out.push({ group: { position: { x: p.x, y: 0, z: p.z } }, keepout: p.solid * p.scale });+ else out.push({ obb: { x: p.x, z: p.z, yaw: p.yaw, hw: (p.solid.w * p.scale) / 2 + 0.3, hd: (p.solid.d * p.scale) / 2 + 0.3 } });+ }+ return out;+}diff --git a/src/desktop/world/rooms.js b/src/desktop/world/rooms.jsnew file mode 100644index 000000000..36d370bca--- /dev/null+++ b/src/desktop/world/rooms.js@@ -0,0 +1,227 @@+// The buildings: real rooms with walls, floors, doorways and windows the+// avatar walks into. Pure data and geometry rules (no Three.js) so tests can+// prove every door is walkable, every wall is solid, and nothing a visitor+// has to reach is sealed off. campus.js turns these specs into meshes and+// src/shared/solids.js turns the wall spans into collision.+//+// Room-local frame: the centre is the place's own position, +z is the front+// (the side with the door, turned toward the campus centre), +x is the right+// hand side seen from the front. `at` on an opening is measured along the run+// of its wall: x for the front and back walls, z for the sides.++import { boxSolid } from '../../shared/solids.js';+import { facingOf, placeById, standPointFor } from './places.js';++/** Wall thickness, in metres, shared by the meshes and the colliders. */+export const WALL = 0.3;+/** Window sill and head heights shared by every room. */+export const SILL = 0.95;+export const HEAD = 2.3;++/**+ * Every building on the campus.+ * `kind`: room (four walls, roof), hall (a roof on posts, open sides),+ * plaza (paving and a pergola), pad (the launch pad), cave (the mine: rock+ * walls, no roof, a hill over it).+ */+export const ROOMS = [+ {+ id: 'office', place: 'office', kind: 'room', w: 9, d: 7, h: 3, wall: 'plaster', floor: 'wood',+ door: { at: 0, w: 1.8, h: 2.2 },+ windows: { front: [{ at: -2.9, w: 1.8 }, { at: 2.9, w: 1.8 }], back: [{ at: -1.9, w: 2.2 }], left: [{ at: 1.3, w: 1.8 }], right: [{ at: 1.3, w: 1.8 }] },+ },+ {+ id: 'exchange', place: 'exchange', kind: 'room', w: 13, d: 9, h: 5.2, wall: 'plaster', floor: 'marble', columns: 6,+ door: { at: 0, w: 2.6, h: 3.4 },+ windows: { left: [{ at: -1.2, w: 2 }, { at: 1.8, w: 2 }], right: [{ at: -1.2, w: 2 }, { at: 1.8, w: 2 }] },+ sill: 1.3, head: 3.8,+ },+ { id: 'pad', place: 'launchpad', kind: 'pad', r: 5.2 },+ {+ id: 'cabin', place: 'launchpad', kind: 'room', w: 3.4, d: 2.8, h: 2.7, wall: 'plaster', floor: 'concrete', at: { x: -3.6, z: 2.4 }, turn: Math.PI / 2,+ door: { at: 0.4, w: 1.1, h: 2.1 },+ windows: { front: [{ at: -0.9, w: 1 }], back: [{ at: 0, w: 1.6 }] },+ },+ {+ id: 'mine', place: 'mine', kind: 'cave', w: 16, d: 13.5, h: 4.5, wall: 'rock', floor: 'rock',+ door: { at: 0, w: 3.2, h: 3.2 },+ windows: {},+ },+ {+ id: 'forge', place: 'forge', kind: 'room', w: 6.6, d: 5.8, h: 3.4, wall: 'brick', floor: 'concrete',+ door: { at: -1.3, w: 1.6, h: 2.3 },+ windows: { front: [{ at: 1.6, w: 1.6 }], right: [{ at: 0.2, w: 1.6 }] },+ },+ {+ id: 'gallery', place: 'gallery', kind: 'room', w: 6.6, d: 6.6, h: 3.6, wall: 'plaster', floor: 'marble', skylight: true,+ door: { at: 0, w: 1.8, h: 2.5 },+ windows: {},+ },+ { id: 'plaza', place: 'agents', kind: 'plaza', r: 6.5, pergola: 4.4 },+ { id: 'market', place: 'market', kind: 'hall', w: 9, d: 7, h: 3.4, floor: 'paving', posts: [[-4.2, -3.2], [0, -3.2], [4.2, -3.2], [-4.2, 3.2], [0, 3.2], [4.2, 3.2]] },+];++export function roomById(id) {+ return ROOMS.find((r) => r.id === id) || null;+}++/** The yaw a place's buildings turn by: the front faces the campus centre; the office faces the gate. */+export function rotationOf(place) {+ return place.id === 'office' ? 0 : facingOf(place);+}++/** World position and yaw of a room's centre. */+export function roomFrame(room) {+ const place = placeById(room.place);+ const base = rotationOf(place);+ const { x, z } = toWorld(place, room.at?.x || 0, room.at?.z || 0, base);+ return { x, z, yaw: base + (room.turn || 0) };+}++/** Rotate a local offset by `yaw` (Three.js Y rotation) and add the place. */+export function toWorld(place, lx, lz, yaw = rotationOf(place)) {+ const sin = Math.sin(yaw);+ const cos = Math.cos(yaw);+ return { x: place.x + lx * cos + lz * sin, z: place.z - lx * sin + lz * cos };+}++/** A room-local point to world space, including the room's own turn. */+export function roomToWorld(room, lx, lz) {+ const f = roomFrame(room);+ const sin = Math.sin(f.yaw);+ const cos = Math.cos(f.yaw);+ return { x: f.x + lx * cos + lz * sin, z: f.z - lx * sin + lz * cos, yaw: f.yaw };+}++const SIDES = {+ front: (r) => ({ cx: 0, cz: r.d / 2, len: r.w, yaw: 0 }),+ back: (r) => ({ cx: 0, cz: -r.d / 2, len: r.w, yaw: 0 }),+ left: (r) => ({ cx: -r.w / 2, cz: 0, len: r.d, yaw: Math.PI / 2 }),+ right: (r) => ({ cx: r.w / 2, cz: 0, len: r.d, yaw: Math.PI / 2 }),+};++/** Every opening in one wall of a room, as {at, w, y0, y1}. */+export function openingsOf(room, side) {+ const list = [];+ if (room.door && (room.door.side || 'front') === side) list.push({ at: room.door.at, w: room.door.w, y0: 0, y1: room.door.h, kind: 'door' });+ for (const win of room.windows?.[side] || []) list.push({ at: win.at, w: win.w, y0: room.sill ?? SILL, y1: room.head ?? HEAD, kind: 'window' });+ return list.sort((a, b) => a.at - b.at);+}++/**+ * Split one wall into solid pieces around its openings: full-height pieces+ * between openings, a sill piece under each window and a lintel piece over+ * every opening. Each piece is {at, len, y0, y1} along the wall's run.+ */+export function wallPieces(len, h, openings) {+ const pieces = [];+ let cursor = -len / 2;+ for (const o of openings) {+ const a = o.at - o.w / 2;+ const b = o.at + o.w / 2;+ if (a > cursor + 0.01) pieces.push({ at: (cursor + a) / 2, len: a - cursor, y0: 0, y1: h });+ if (o.y0 > 0) pieces.push({ at: o.at, len: o.w, y0: 0, y1: o.y0 });+ if (o.y1 < h) pieces.push({ at: o.at, len: o.w, y0: o.y1, y1: h });+ cursor = b;+ }+ if (cursor < len / 2 - 0.01) pieces.push({ at: (cursor + len / 2) / 2, len: len / 2 - cursor, y0: 0, y1: h });+ return pieces;+}++/**+ * The four walls of a room as pieces in room-local space:+ * {side, x, z, yaw, len, y0, y1, openings}. Halls, plazas and pads have none.+ */+export function wallsOf(room) {+ if (!['room', 'cave'].includes(room.kind)) return [];+ const out = [];+ for (const [side, geom] of Object.entries(SIDES)) {+ const { cx, cz, len, yaw } = geom(room);+ const openings = openingsOf(room, side);+ const pieces = wallPieces(len, room.h, openings).map((p) => ({+ side,+ yaw,+ len: p.len,+ y0: p.y0,+ y1: p.y1,+ x: side === 'left' || side === 'right' ? cx : p.at,+ z: side === 'left' || side === 'right' ? p.at : cz,+ }));+ out.push({ side, cx, cz, len, yaw, openings, pieces });+ }+ return out;+}++/**+ * Collision for a building, in world space. Walls are solid along their+ * whole run except through the door; a hall's posts and the pad's rocket are+ * cylinders; the cave adds the hill that wraps round it.+ */+export function roomSolids(room) {+ const f = roomFrame(room);+ const solids = [];+ const world = (lx, lz) => roomToWorld(room, lx, lz);+ for (const wall of wallsOf(room)) {+ const spans = wallPieces(wall.len, room.h, wall.openings.filter((o) => o.y0 === 0)).filter((p) => p.y0 === 0 && p.y1 === room.h);+ for (const s of spans) {+ const lx = wall.side === 'left' || wall.side === 'right' ? wall.cx : s.at;+ const lz = wall.side === 'left' || wall.side === 'right' ? s.at : wall.cz;+ const p = world(lx, lz);+ solids.push(boxSolid(p.x, p.z, f.yaw + wall.yaw, s.len, WALL));+ }+ }+ if (room.kind === 'hall') for (const [lx, lz] of room.posts) solids.push(disc(world(lx, lz), 0.5));+ for (const [lx, lz] of columnsOf(room)) solids.push(disc(world(lx, lz), 0.45));+ if (room.kind === 'plaza') {+ const r = room.pergola / 2;+ for (const [lx, lz] of [[-r, -r], [r, -r], [-r, r], [r, r]]) solids.push(disc(world(lx, lz), 0.45));+ }+ if (room.kind === 'pad') solids.push(disc(world(1.2, 0), 1.6), disc(world(3.6, 0), 0.5));+ if (room.kind === 'cave') {+ // The hill: shoulders either side of the portal and the mass behind the cave.+ solids.push(disc(world(-12, -5), 4), disc(world(12, -5), 4), disc(world(0, -14), 6.5));+ }+ return solids;+}++/** Local positions of a classical facade's columns: evenly spaced, never in front of the door. */+export const COLUMN_X = [-5.4, -3.6, -1.8, 1.8, 3.6, 5.4];+export function columnsOf(room) {+ if (!room.columns) return [];+ return COLUMN_X.slice(0, room.columns).map((x) => [x, room.d / 2 + 1.5]);+}++function disc(p, keepout) {+ return { group: { position: { x: p.x, y: 0, z: p.z } }, keepout };+}++/** The world point just outside and just inside a room's door, for tests and arrivals. */+export function doorPoints(room, reach = 1) {+ if (!room.door) return null;+ const f = roomFrame(room);+ const side = room.door.side || 'front';+ const g = SIDES[side](room);+ const onRun = (t, off) => (side === 'front' || side === 'back' ? { lx: t, lz: g.cz + off } : { lx: g.cx + off, lz: t });+ const sign = side === 'front' || side === 'right' ? 1 : -1;+ const out = onRun(room.door.at, sign * reach);+ const inn = onRun(room.door.at, -sign * reach);+ return { outside: roomToWorld(room, out.lx, out.lz), inside: roomToWorld(room, inn.lx, inn.lz), yaw: f.yaw };+}++/**+ * Where a visitor lands when they teleport to a place or come back from it:+ * just outside the building's door, facing in, so the follow camera has open+ * air behind it. Open-air places keep the stand point on the approach path.+ * @returns {{ x:number, z:number, yaw:number }}+ */+export function arrivalPointFor(place, reach = 2.2) {+ const room = ROOMS.find((r) => r.place === place.id);+ if (!room?.door) return standPointFor(place);+ const d = doorPoints(room, reach);+ return { x: d.outside.x, z: d.outside.z, yaw: roomFrame(room).yaw + Math.PI };+}++/** Every building's collision, in one list. */+export function allRoomSolids() {+ return ROOMS.flatMap(roomSolids);+}diff --git a/src/desktop/world/surfaces.js b/src/desktop/world/surfaces.jsnew file mode 100644index 000000000..d4597da88--- /dev/null+++ b/src/desktop/world/surfaces.js@@ -0,0 +1,112 @@+// Real materials for the campus: scanned PBR surfaces (grass, paving,+// plaster, brick, wood, marble, concrete, rock, roof tiles) from Poly Haven,+// CC0, resized into public/campus by scripts/build-campus-textures.mjs.+// One material per surface role is shared by every mesh that wears it; the+// geometry's UVs are scaled to the surface's real metres-per-tile instead of+// cloning textures, so a 9 m wall and a 2 m counter tile the same plaster at+// the same size. Every material exists at once with a flat base colour and+// takes its maps as the images arrive, so the first frame is never bare.++import { Color, MeshStandardMaterial, RepeatWrapping, SRGBColorSpace, TextureLoader } from 'three';++export const MANIFEST_URL = '/campus/manifest.json';++/** Base colours (and material tuning) per role, shown until the scans load and under them. */+const ROLES = {+ ground: { color: 0x5f7a3e, roughness: 1 },+ plaza: { color: 0x9a948c, roughness: 0.9 },+ path: { color: 0xa09c96, roughness: 0.95 },+ wall: { color: 0xd9d4cb, roughness: 0.85 },+ brick: { color: 0x9a6a55, roughness: 0.9 },+ 'floor-wood': { color: 0x8c6a4a, roughness: 0.6 },+ 'floor-marble': { color: 0xd8d6d0, roughness: 0.3 },+ 'floor-concrete': { color: 0x8e8d8a, roughness: 0.8 },+ rock: { color: 0x6c655c, roughness: 1 },+ // Roof tiles photograph dark and sit at a grazing angle to the sun: lift them so they read as slate, not a hole.+ roof: { color: 0x5a5b60, roughness: 0.85, tint: 2.2 },+};++/** Fallback metres-per-tile when the manifest has not arrived yet. */+const TILE = { ground: 3, plaza: 3, path: 2.5, wall: 3, brick: 2.5, 'floor-wood': 2.5, 'floor-marble': 3, 'floor-concrete': 3, rock: 4, roof: 2.5 };++/**+ * @param {{ normals?: boolean, anisotropy?: number }} [o] `normals: false` skips normal maps (phones)+ */+export function createSurfaces({ normals = true, anisotropy = 8 } = {}) {+ const loader = new TextureLoader();+ const materials = {};+ const textures = [];+ for (const [role, tune] of Object.entries(ROLES)) materials[role] = new MeshStandardMaterial({ color: tune.color, roughness: tune.roughness, metalness: 0 });+ let disposed = false;++ function texture(url, srgb) {+ const tex = loader.load(url);+ tex.wrapS = tex.wrapT = RepeatWrapping;+ tex.anisotropy = anisotropy;+ tex.channel = 0;+ if (srgb) tex.colorSpace = SRGBColorSpace;+ textures.push(tex);+ return tex;+ }++ const ready = fetch(MANIFEST_URL)+ .then((r) => (r.ok ? r.json() : Promise.reject(new Error(`campus manifest ${r.status}`))))+ .then((manifest) => {+ if (disposed) return manifest;+ for (const set of Object.values(manifest.sets || {})) {+ const mat = materials[set.role];+ if (!mat) continue;+ TILE[set.role] = set.metresPerTile || TILE[set.role];+ mat.map = texture(set.diff, true);+ const arm = texture(set.arm, false);+ mat.aoMap = arm;+ mat.roughnessMap = arm;+ mat.metalnessMap = arm;+ mat.aoMapIntensity = 0.9;+ mat.roughness = 1;+ mat.metalness = 1;+ if (normals) mat.normalMap = texture(set.nor, false);+ mat.color = new Color().setScalar(ROLES[set.role].tint ?? 1);+ mat.needsUpdate = true;+ }+ return manifest;+ });++ return {+ /** The shared material for a role. */+ material: (role) => materials[role] || materials.wall,+ /** Metres one tile of a role covers; UV scaling uses it. */+ metresPerTile: (role) => TILE[role] || 3,+ /** Resolves once the manifest is read (maps keep streaming in after). Errors surface to the caller. */+ ready,+ dispose() {+ disposed = true;+ for (const t of textures) t.dispose();+ for (const m of Object.values(materials)) m.dispose();+ },+ };+}++/**+ * Scale a BoxGeometry's UVs so each face tiles every `m` metres. Faces are+ * emitted +x, -x, +y, -y, +z, -z with four vertices each.+ */+export function tileBox(geom, w, h, d, m) {+ const uv = geom.attributes.uv;+ const dims = [[d, h], [d, h], [w, d], [w, d], [w, h], [w, h]];+ for (let i = 0; i < uv.count; i++) {+ const face = Math.min(5, Math.floor(i / 4));+ const [fw, fh] = dims[face];+ uv.setXY(i, uv.getX(i) * (fw / m), uv.getY(i) * (fh / m));+ }+ uv.needsUpdate = true;+ return geom;+}++/** Scale a plane or circle's UVs so it tiles every `m` metres (`w`, `h` are its full extents). */+export function tilePlane(geom, w, h, m) {+ const uv = geom.attributes.uv;+ for (let i = 0; i < uv.count; i++) uv.setXY(i, uv.getX(i) * (w / m), uv.getY(i) * (h / m));+ uv.needsUpdate = true;+ return geom;+}diff --git a/src/docs-world/player.js b/src/docs-world/player.jsindex 8907aa29b..c409ff941 100644--- a/src/docs-world/player.js+++ b/src/docs-world/player.js@@ -18,6 +18,7 @@ import {import { AnimationManager } from '../animation-manager.js';import { gltfLoader } from '../loaders/gltf.js';import { log } from '../shared/log.js';+import { resolveSolids } from '../shared/solids.js';import { WORLD_RADIUS, RING_RADIUS } from './world.js';// The same default body /walk, /walk-embed and the embed preview use. It must@@ -168,7 +169,7 @@ export function createPlayer(* @param {{x:number, z:number}} move input vector in camera space, |v| <= 1* @param {number} camYaw camera yaw so input is screen-relative* @param {boolean} run- * @param {Array<{group: import('three').Group, keepout?: number}>} pavilions keep-out volumes+ * @param {Array<{group: import('three').Group, keepout?: number} | {obb: {x:number, z:number, yaw:number, hw:number, hd:number}}>} pavilions solids (see src/shared/solids.js)*/function update(dt, move, camYaw, run, pavilions) {running = run;@@ -200,21 +201,11 @@ export function createPlayer(root.position.z *= bound / dist;}- // Keep-out: push out radially so portals and props stay walk-aroundable.- // A volume may carry its own `keepout` radius; the world default applies otherwise.- if (pavilions) {- for (const p of pavilions) {- const dx = root.position.x - p.group.position.x;- const dz = root.position.z - p.group.position.z;- const d = Math.hypot(dx, dz);- const r = p.keepout ?? keepout;- if (d > 0.001 && d < r) {- const push = r / d;- root.position.x = p.group.position.x + dx * push;- root.position.z = p.group.position.z + dz * push;- }- }- }+ // Keep-out: cylinders (portals, props) push out radially, oriented boxes+ // (walls, counters) push out through their nearest face, so rooms are+ // solid and doorways are walkable. A cylinder may carry its own+ // `keepout` radius; the world default applies otherwise.+ resolveSolids(root.position, pavilions, { keepout });// Face travel direction.const speed = Math.hypot(velocity.x, velocity.z);diff --git a/src/shared/cinematic-render.js b/src/shared/cinematic-render.jsindex 16e5d2237..36b496b07 100644--- a/src/shared/cinematic-render.js+++ b/src/shared/cinematic-render.js@@ -76,11 +76,28 @@ export function detectQualityTier(env = {}) {const lowMem = (nav.deviceMemory ?? 8) < 4;const lowCores = (nav.hardwareConcurrency ?? 8) < 4;const coarse = !!(win.matchMedia && win.matchMedia('(any-pointer: coarse)').matches);+ if (env.gl && isSoftwareRenderer(env.gl)) return 'mobile';if (isMobile && (lowMem || lowCores)) return 'mobile';if (coarse || lowMem || lowCores) return 'medium';return 'high';}+/**+ * True when WebGL is being rasterised on the CPU (SwiftShader, llvmpipe,+ * Mesa software paths): shadows and normal maps cost seconds a frame there,+ * so such a session gets the lightest tier whatever the host's specs say.+ * @param {WebGLRenderingContext|WebGL2RenderingContext} gl+ */+export function isSoftwareRenderer(gl) {+ try {+ const dbg = gl.getExtension('WEBGL_debug_renderer_info');+ const name = String(dbg ? gl.getParameter(dbg.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER));+ return /SwiftShader|llvmpipe|softpipe|Software|Microsoft Basic Render/i.test(name);+ } catch {+ return false;+ }+}+/*** Apply ACES tone mapping + correct color management + soft shadow type to* a renderer. Call once, right after construction.diff --git a/src/shared/solids.js b/src/shared/solids.jsnew file mode 100644index 000000000..a96901474--- /dev/null+++ b/src/shared/solids.js@@ -0,0 +1,75 @@+// Walkable-world collision: the one resolver every world's player and every+// NPC share. A solid is either a cylinder keep-out (`{ group: { position },+// keepout }`, the shape the docs plaza and the campus always used) or an+// oriented box (`{ obb: { x, z, yaw, hw, hd } }`): a wall, a counter, a sofa.+// Boxes carry their own padding in `hw`/`hd`, so a point body is enough.+// Pure math, no Three.js, so tests pin the behaviour.++/**+ * Push `pos` (mutated in place; any `{x, z}`) out of every solid it is inside.+ * @param {{x:number, z:number}} pos+ * @param {Array<object>} solids+ * @param {{ keepout?: number }} [o] default radius for cylinders that carry none+ */+export function resolveSolids(pos, solids, { keepout = 0 } = {}) {+ if (!solids) return pos;+ for (const s of solids) {+ if (s.obb) pushOutOfBox(pos, s.obb);+ else pushOutOfDisc(pos, s.group.position, s.keepout ?? keepout);+ }+ return pos;+}++function pushOutOfDisc(pos, c, r) {+ const dx = pos.x - c.x;+ const dz = pos.z - c.z;+ const d = Math.hypot(dx, dz);+ if (d > 0.001 && d < r) {+ const push = r / d;+ pos.x = c.x + dx * push;+ pos.z = c.z + dz * push;+ }+}++function pushOutOfBox(pos, b) {+ const sin = Math.sin(b.yaw);+ const cos = Math.cos(b.yaw);+ const dx = pos.x - b.x;+ const dz = pos.z - b.z;+ // Into the box's frame (inverse of a Y rotation by yaw).+ const lx = dx * cos - dz * sin;+ const lz = dx * sin + dz * cos;+ if (Math.abs(lx) >= b.hw || Math.abs(lz) >= b.hd) return;+ // Leave along the axis that needs the least travel.+ const px = b.hw - Math.abs(lx);+ const pz = b.hd - Math.abs(lz);+ let nx = lx;+ let nz = lz;+ if (px < pz) nx = Math.sign(lx || 1) * b.hw;+ else nz = Math.sign(lz || 1) * b.hd;+ pos.x = b.x + nx * cos + nz * sin;+ pos.z = b.z - nx * sin + nz * cos;+}++/** True when (x, z) is inside any solid, grown by `margin`. */+export function insideSolids(x, z, solids, margin = 0) {+ for (const s of solids || []) {+ if (s.obb) {+ const b = s.obb;+ const sin = Math.sin(b.yaw);+ const cos = Math.cos(b.yaw);+ const dx = x - b.x;+ const dz = z - b.z;+ if (Math.abs(dx * cos - dz * sin) < b.hw + margin && Math.abs(dx * sin + dz * cos) < b.hd + margin) return true;+ } else if (Math.hypot(x - s.group.position.x, z - s.group.position.z) < (s.keepout ?? 0) + margin) return true;+ }+ return false;+}++/**+ * An oriented box solid from a centre, a yaw and full extents, padded so a+ * body of radius `pad` never clips its faces.+ */+export function boxSolid(x, z, yaw, w, d, pad = 0.35) {+ return { obb: { x, z, yaw, hw: w / 2 + pad, hd: d / 2 + pad } };+}diff --git a/tests/hdri-mobile-tier.test.js b/tests/hdri-mobile-tier.test.jsindex 14fc139df..e9b1f6884 100644--- a/tests/hdri-mobile-tier.test.js+++ b/tests/hdri-mobile-tier.test.js@@ -25,7 +25,7 @@ import {MOBILE_HEIGHT,MEAN_TOLERANCE,} from '../scripts/build-hdri-mobile.mjs';-import { HDRI_PRESETS, HDRI_PRESETS_MOBILE, QUALITY_TIERS } from '../src/shared/cinematic-render.js';+import { HDRI_PRESETS, HDRI_PRESETS_MOBILE, QUALITY_TIERS, detectQualityTier, isSoftwareRenderer } from '../src/shared/cinematic-render.js';const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');const HDRI_DIR = join(ROOT, 'public/hdri');@@ -72,3 +72,18 @@ describe('mobile HDRI variants', () => {expect(QUALITY_TIERS.mobile.hdri).toBe(false);});});++describe('software rasterisers get the lightest tier', () => {+ const gl = (name) => ({ getExtension: () => ({ UNMASKED_RENDERER_WEBGL: 1 }), getParameter: () => name });+ it('detects SwiftShader and llvmpipe', () => {+ expect(isSoftwareRenderer(gl('Google SwiftShader'))).toBe(true);+ expect(isSoftwareRenderer(gl('Mesa llvmpipe (LLVM 15.0.7, 256 bits)'))).toBe(true);+ expect(isSoftwareRenderer(gl('ANGLE (NVIDIA, NVIDIA GeForce RTX 3080 Direct3D11 vs_5_0 ps_5_0)'))).toBe(false);+ });+ it('forces the mobile tier on a software context even on a fast host', () => {+ const navigator = { userAgent: 'Mozilla/5.0 (X11; Linux x86_64)', deviceMemory: 32, hardwareConcurrency: 16 };+ const window = { matchMedia: () => ({ matches: false }) };+ expect(detectQualityTier({ navigator, window })).toBe('high');+ expect(detectQualityTier({ navigator, window, gl: gl('Google SwiftShader') })).toBe('mobile');+ });+});diff --git a/tests/solids.test.js b/tests/solids.test.jsnew file mode 100644index 000000000..b8a2d4da6--- /dev/null+++ b/tests/solids.test.js@@ -0,0 +1,54 @@+import { describe, it, expect } from 'vitest';+import { resolveSolids, insideSolids, boxSolid } from '../src/shared/solids.js';++const disc = (x, z, keepout) => ({ group: { position: { x, z } }, keepout });++describe('shared solids', () => {+ it('pushes a body radially out of a cylinder keep-out and leaves it alone outside', () => {+ const p = resolveSolids({ x: 0.5, z: 0 }, [disc(0, 0, 2)]);+ expect(p.x).toBeCloseTo(2);+ expect(p.z).toBeCloseTo(0);+ const q = resolveSolids({ x: 3, z: 0 }, [disc(0, 0, 2)]);+ expect(q).toEqual({ x: 3, z: 0 });+ });++ it('uses the caller default radius for cylinders that carry none', () => {+ const p = resolveSolids({ x: 1, z: 0 }, [{ group: { position: { x: 0, z: 0 } } }], { keepout: 2.4 });+ expect(p.x).toBeCloseTo(2.4);+ });++ it('pushes a body out of an axis-aligned wall along the nearest face', () => {+ // A 6 m wall, 0.3 m thick, padded 0.35: the body is inside and nearer the +z face.+ const wall = boxSolid(0, 0, 0, 6, 0.3);+ const p = resolveSolids({ x: 1, z: 0.2 }, [wall]);+ expect(p.x).toBeCloseTo(1);+ expect(p.z).toBeCloseTo(0.5);+ const q = resolveSolids({ x: 1, z: -0.1 }, [wall]);+ expect(q.z).toBeCloseTo(-0.5);+ });++ it('leaves the ends of a wall open so a doorway beside it is walkable', () => {+ const wall = boxSolid(0, 0, 0, 6, 0.3);+ expect(resolveSolids({ x: 3.5, z: 0 }, [wall])).toEqual({ x: 3.5, z: 0 });+ expect(insideSolids(3.5, 0, [wall])).toBe(false);+ expect(insideSolids(2.9, 0, [wall])).toBe(true);+ });++ it('resolves a rotated wall in its own frame', () => {+ // The same wall turned 90 degrees now runs along z.+ const wall = boxSolid(0, 0, Math.PI / 2, 6, 0.3);+ const p = resolveSolids({ x: 0.2, z: 1 }, [wall]);+ expect(p.z).toBeCloseTo(1);+ expect(Math.abs(p.x)).toBeCloseTo(0.5);+ expect(insideSolids(0, 2.9, [wall])).toBe(true);+ expect(insideSolids(0, 3.5, [wall])).toBe(false);+ });++ it('never leaves a body inside after one pass over a mixed list', () => {+ const solids = [disc(4, 4, 1), boxSolid(0, 0, 0.7, 3, 1)];+ for (const [x, z] of [[4.2, 4.1], [0.1, 0.1], [1, 0.3]]) {+ const p = resolveSolids({ x, z }, solids);+ expect(insideSolids(p.x, p.z, solids)).toBe(false);+ }+ });+});diff --git a/tests/world-props.test.js b/tests/world-props.test.jsnew file mode 100644index 000000000..7240bedfa--- /dev/null+++ b/tests/world-props.test.js@@ -0,0 +1,92 @@+import { describe, it, expect } from 'vitest';+import { PROPS, MODELS, PROP_BUDGET, LIBRARY_BASE, placeProps, payloadBytes, propSolids, propUrl, hedgePlacements, HEDGE } from '../src/desktop/world/props.js';+import { allRoomSolids, roomById, doorPoints } from '../src/desktop/world/rooms.js';+import { insideSolids } from '../src/shared/solids.js';+import { CAMPUS_RADIUS, SPAWN, VEINS, DESK_OBJECTS, placeById } from '../src/desktop/world/places.js';++describe('campus props', () => {+ it('only places models that were measured, and names a real library file for each', () => {+ for (const p of PROPS) expect(MODELS[p.model], p.model).toBeDefined();+ expect(propUrl('sofa_02')).toBe(`${LIBRARY_BASE}/sofa_02.glb`);+ for (const m of Object.values(MODELS)) {+ expect(m.bytes).toBeGreaterThan(0);+ expect(m.w).toBeGreaterThan(0);+ expect(m.h).toBeGreaterThan(0);+ }+ });++ it('stays inside the payload budget on desktop and on phones, and phones get a subset', () => {+ expect(payloadBytes('desktop')).toBeLessThanOrEqual(PROP_BUDGET.desktop);+ expect(payloadBytes('mobile')).toBeLessThanOrEqual(PROP_BUDGET.mobile);+ const desktop = new Set(placeProps('desktop').map((p) => p.model));+ for (const p of placeProps('mobile')) expect(desktop.has(p.model)).toBe(true);+ expect(placeProps('mobile').length).toBeLessThan(placeProps('desktop').length);+ });++ it('places everything on the campus and nothing on the walk from the gate to the desk', () => {+ for (const p of placeProps('desktop')) {+ expect(Math.hypot(p.x, p.z), p.model).toBeLessThan(CAMPUS_RADIUS + 6);+ const onCorridor = Math.abs(p.x) < 1.6 && p.z > 9.5 && p.z < SPAWN.z + 1;+ expect(onCorridor, `${p.model} at ${p.x.toFixed(1)},${p.z.toFixed(1)} blocks the walk in`).toBe(false);+ }+ });++ it('never stands a solid prop in a doorway, on a vein, or on the desk objects', () => {+ const solids = propSolids(placeProps('desktop'));+ for (const room of [roomById('office'), roomById('exchange'), roomById('forge'), roomById('gallery'), roomById('mine'), roomById('cabin')]) {+ const { outside, inside } = doorPoints(room, 0.8);+ expect(insideSolids(outside.x, outside.z, solids, 0.35), `${room.id} door, outside`).toBe(false);+ expect(insideSolids(inside.x, inside.z, solids, 0.35), `${room.id} door, inside`).toBe(false);+ }+ const mine = placeById('mine');+ for (const v of VEINS) expect(insideSolids(mine.x + v.dx, mine.z + v.dz, solids, 0.6), v.id).toBe(false);+ const office = placeById('office');+ // The player must reach the phone and headset: a solid prop may not sit on their reach points.+ for (const d of DESK_OBJECTS) expect(insideSolids(office.x + d.dx, office.z + d.dz + 1.2, solids, 0.3), d.id).toBe(false);+ });++ it('keeps room props inside their rooms, clear of the walls', () => {+ const walls = allRoomSolids();+ for (const p of PROPS) {+ if (!p.room) continue;+ const room = roomById(p.room);+ if (!room.w) continue;+ const w = MODELS[p.model];+ expect(Math.abs(p.x), `${p.model} in ${p.room}`).toBeLessThanOrEqual(room.w / 2 + 0.01);+ expect(Math.abs(p.z), `${p.model} in ${p.room}`).toBeLessThanOrEqual(room.d / 2 + 0.01);+ if (p.anchor === 'origin' && p.y) expect(p.y).toBeLessThanOrEqual(room.h);+ expect(w.h * (p.scale || 1)).toBeLessThanOrEqual(room.h + 0.01);+ }+ expect(walls.length).toBeGreaterThan(20);+ });++ it('rings the campus with hedge and leaves the gate behind the spawn open', () => {+ const hedge = hedgePlacements();+ expect(hedge.length).toBeGreaterThan(HEDGE.count * 0.8);+ expect(hedge.length).toBeLessThan(HEDGE.count);+ for (const h of hedge) {+ expect(Math.hypot(h.x, h.z)).toBeCloseTo(HEDGE.radius);+ const nearGate = Math.abs(h.x) < 8 && h.z > 0;+ expect(nearGate, `hedge at ${h.x.toFixed(1)},${h.z.toFixed(1)} blocks the gate`).toBe(false);+ }+ });++ it('resolves room-local positions through the room rotation', () => {+ const desk = placeProps('desktop').find((p) => p.model === 'metal_office_desk');+ const office = placeById('office');+ expect(desk.x).toBeCloseTo(office.x);+ expect(desk.z).toBeCloseTo(office.z - 0.5);+ const cart = placeProps('desktop').find((p) => p.model === 'CoffeeCart_01');+ const market = placeById('market');+ expect(Math.hypot(cart.x - market.x, cart.z - market.z)).toBeCloseTo(Math.hypot(2.6, 1.8));+ });+});++it('every placement, hedge included, resolves to a library URL and a byte size', () => {+ for (const tier of ['desktop', 'mobile']) {+ for (const p of placeProps(tier)) {+ expect(p.url, `${p.model} url`).toMatch(/^https:\/\/.+\.glb$/);+ expect(p.bytes, `${p.model} bytes`).toBeGreaterThan(0);+ }+ }+});diff --git a/tests/world-rooms.test.js b/tests/world-rooms.test.jsnew file mode 100644index 000000000..a5fff0f2a--- /dev/null+++ b/tests/world-rooms.test.js@@ -0,0 +1,181 @@+import { describe, it, expect } from 'vitest';+import { ROOMS, roomById, roomFrame, roomToWorld, wallsOf, wallPieces, roomSolids, allRoomSolids, doorPoints, columnsOf, arrivalPointFor, WALL } from '../src/desktop/world/rooms.js';+import { insideSolids, resolveSolids } from '../src/shared/solids.js';+import { PLACES, SPAWN, CAMPUS_RADIUS, VEINS, DESK_OBJECTS, PLACE_TRIGGER, placeById, standPointFor } from '../src/desktop/world/places.js';++describe('campus rooms', () => {+ it('every room belongs to a real place and every place with a window has a door to walk through', () => {+ for (const room of ROOMS) {+ expect(placeById(room.place), room.id).not.toBeNull();+ if (room.kind === 'room' || room.kind === 'cave') {+ expect(room.door.w, `${room.id} door`).toBeGreaterThanOrEqual(1.1);+ expect(room.door.h, `${room.id} door height`).toBeGreaterThanOrEqual(2.1);+ expect(room.door.h).toBeLessThan(room.h);+ }+ }+ expect(new Set(ROOMS.map((r) => r.id)).size).toBe(ROOMS.length);+ });++ it('splits a wall into pieces that leave the door open and keep the lintel and sills', () => {+ const pieces = wallPieces(9, 3, [{ at: 0, w: 1.5, y0: 0, y1: 2.2 }, { at: 2.9, w: 1.8, y0: 0.95, y1: 2.3 }]);+ const full = pieces.filter((p) => p.y0 === 0 && p.y1 === 3);+ const covered = full.reduce((n, p) => n + p.len, 0);+ expect(covered).toBeCloseTo(9 - 1.5 - 1.8);+ expect(pieces.some((p) => p.at === 0 && p.y0 === 2.2 && p.y1 === 3)).toBe(true);+ expect(pieces.some((p) => p.at === 2.9 && p.y0 === 0 && p.y1 === 0.95)).toBe(true);+ expect(pieces.some((p) => p.at === 2.9 && p.y0 === 2.3 && p.y1 === 3)).toBe(true);+ expect(pieces.every((p) => p.len > 0)).toBe(true);+ });++ it('builds four walls for every closed room and none for halls, plazas and pads', () => {+ for (const room of ROOMS) {+ const walls = wallsOf(room);+ if (room.kind === 'room' || room.kind === 'cave') {+ expect(walls.map((w) => w.side).sort()).toEqual(['back', 'front', 'left', 'right']);+ for (const w of walls) expect(w.pieces.length).toBeGreaterThan(0);+ } else expect(walls).toEqual([]);+ }+ });++ it('is walkable through every door and solid through every wall', () => {+ for (const room of ROOMS) {+ if (!room.door) continue;+ const solids = roomSolids(room);+ const { outside, inside } = doorPoints(room, 0.9);+ expect(insideSolids(outside.x, outside.z, solids, 0.3), `${room.id} outside the door`).toBe(false);+ expect(insideSolids(inside.x, inside.z, solids, 0.3), `${room.id} inside the door`).toBe(false);+ // A body walking straight through the doorway is never pushed.+ for (let t = 0; t <= 1; t += 0.1) {+ const p = { x: outside.x + (inside.x - outside.x) * t, z: outside.z + (inside.z - outside.z) * t };+ const q = resolveSolids({ ...p }, solids, { keepout: 0.3 });+ expect(Math.hypot(q.x - p.x, q.z - p.z), `${room.id} doorway at ${t.toFixed(1)}`).toBeLessThan(1e-6);+ }+ // The middle of the back wall is solid.+ const back = roomToWorld(room, 0.3, -room.d / 2);+ expect(insideSolids(back.x, back.z, solids, 0.2), `${room.id} back wall`).toBe(true);+ }+ });++ it('keeps the office door in line with the gate so the walk from spawn to the desk is a straight run', () => {+ const office = roomById('office');+ const { outside, inside } = doorPoints(office, 1);+ expect(outside.x).toBeCloseTo(0);+ expect(inside.x).toBeCloseTo(0);+ expect(outside.z).toBeGreaterThan(inside.z);+ expect(SPAWN.x).toBe(0);+ // Nothing solid on the line x = 0 between the spawn and the desk.+ const solids = allRoomSolids();+ const desk = placeById('office');+ for (let z = SPAWN.z; z > desk.z + 1.2; z -= 0.25) expect(insideSolids(0, z, solids, 0.45), `corridor at z=${z}`).toBe(false);+ });++ it('leaves the desk objects and every mine vein inside their rooms, clear of the walls', () => {+ const office = roomById('office');+ const o = placeById('office');+ for (const d of DESK_OBJECTS) {+ const w = roomToWorld(office, d.dx, d.dz);+ expect(w.x).toBeCloseTo(o.x + d.dx);+ expect(w.z).toBeCloseTo(o.z + d.dz);+ }+ const mine = roomById('mine');+ const m = placeById('mine');+ const solids = roomSolids(mine);+ for (const v of VEINS) {+ expect(insideSolids(m.x + v.dx, m.z + v.dz, solids, 0.9), v.id).toBe(false);+ expect(Math.abs(v.dx)).toBeLessThan(mine.w / 2 - 1);+ expect(Math.abs(v.dz)).toBeLessThan(mine.d / 2 - 0.5);+ }+ });++ it('turns every building so its door faces the campus centre and its stand point is outside', () => {+ for (const room of ROOMS) {+ if (!room.door || room.id === 'office' || room.id === 'cabin') continue;+ const place = placeById(room.place);+ const { outside, inside } = doorPoints(room, 1);+ const dOut = Math.hypot(outside.x, outside.z);+ const dIn = Math.hypot(inside.x, inside.z);+ expect(dOut, `${room.id} door faces in`).toBeLessThan(dIn);+ const stand = standPointFor(place);+ expect(insideSolids(stand.x, stand.z, roomSolids(room), 0.5), `${room.id} stand point`).toBe(false);+ if (place.keepout) expect(Math.hypot(stand.x - place.x, stand.z - place.z)).toBeGreaterThan(Math.max(room.w || 0, room.d || 0, (room.r || 0) * 2) / 2);+ }+ });++ it('keeps every wall and column inside the campus and never in another building', () => {+ for (const room of ROOMS) {+ const f = roomFrame(room);+ const reach = Math.hypot((room.w || room.r * 2) / 2, (room.d || room.r * 2) / 2);+ expect(Math.hypot(f.x, f.z) + reach, room.id).toBeLessThan(CAMPUS_RADIUS + 2);+ for (const [x, z] of columnsOf(room)) {+ const w = roomToWorld(room, x, z);+ expect(Math.hypot(w.x, w.z)).toBeLessThan(CAMPUS_RADIUS);+ }+ }+ const centres = ROOMS.filter((r) => r.kind === 'room' || r.kind === 'cave').map((r) => ({ id: r.id, ...roomFrame(r), r: Math.hypot(r.w, r.d) / 2 }));+ for (const a of centres) for (const b of centres) {+ if (a.id === b.id) continue;+ if (a.id === 'cabin' || b.id === 'cabin') continue;+ expect(Math.hypot(a.x - b.x, a.z - b.z), `${a.id} vs ${b.id}`).toBeGreaterThan(a.r + b.r - 2);+ }+ });++ it('keeps the facade columns clear of the exchange doorway', () => {+ const ex = roomById('exchange');+ for (const [x] of columnsOf(ex)) expect(Math.abs(x)).toBeGreaterThan(ex.door.w / 2 + 0.3);+ expect(columnsOf(ex)).toHaveLength(ex.columns);+ });++ it('uses one wall thickness for meshes and colliders', () => {+ expect(WALL).toBeGreaterThan(0.2);+ expect(WALL).toBeLessThan(0.5);+ expect(PLACES.length).toBeGreaterThan(0);+ });+});++describe('arrival points', () => {+ const solids = allRoomSolids();+ it('land every visitor outside the building, at its door, with open air behind the follow camera', () => {+ for (const place of PLACES) {+ const a = arrivalPointFor(place);+ const room = ROOMS.find((r) => r.place === place.id);+ expect(insideSolids(a.x, a.z, solids, 0.45), `${place.id} arrival stands clear`).toBe(false);+ if (room?.door) {+ const f = roomFrame(room);+ // Facing in: one step forward lands in the doorway, not out on the lawn.+ const step = { x: a.x + Math.sin(a.yaw) * 2.2, z: a.z + Math.cos(a.yaw) * 2.2 };+ const door = doorPoints(room, 0);+ expect(Math.hypot(step.x - door.outside.x, step.z - door.outside.z), `${place.id} faces its door`).toBeLessThan(0.05);+ expect(Math.abs(((a.yaw - f.yaw - Math.PI) % (Math.PI * 2)))).toBeLessThan(1e-9);+ }+ // The chase camera starts six metres behind: that spot must be clear of walls and the hill.+ const cam = { x: a.x - Math.sin(a.yaw) * 6, z: a.z - Math.cos(a.yaw) * 6 };+ expect(insideSolids(cam.x, cam.z, solids, 0.3), `${place.id} camera start is in open air`).toBe(false);+ // And the prompt to enter must already be armed where they land.+ if (place.kind !== 'office' && place.kind !== 'mine') {+ expect(Math.hypot(a.x - place.x, a.z - place.z)).toBeLessThan(PLACE_TRIGGER + place.keepout);+ }+ }+ });+});++describe('gable roofs', () => {+ it('slope down from the ridge to the eaves on both sides, never up into a V', async () => {+ const { gableRoof } = await import('../src/desktop/world/campus.js');+ const { MeshStandardMaterial, Vector3 } = await import('three');+ const surfaces = { material: () => new MeshStandardMaterial(), metresPerTile: () => 2.5 };+ const mats = { darkSteel: new MeshStandardMaterial(), white: new MeshStandardMaterial() };+ const room = roomById('office');+ const roof = gableRoof(room, surfaces, mats, (m) => m);+ roof.updateMatrixWorld(true);+ const slabs = roof.children.filter((m) => m.geometry?.type === 'BoxGeometry' && m.geometry.parameters.height === 0.16);+ expect(slabs).toHaveLength(2);+ for (const slab of slabs) {+ const run = slab.geometry.parameters.depth;+ const inner = slab.localToWorld(new Vector3(0, 0, slab.position.z > 0 ? -run / 2 : run / 2));+ const outer = slab.localToWorld(new Vector3(0, 0, slab.position.z > 0 ? run / 2 : -run / 2));+ expect(Math.abs(inner.z), 'inner end sits on the ridge line').toBeLessThan(0.05);+ expect(inner.y, 'ridge end is the high end').toBeGreaterThan(outer.y + 1);+ expect(outer.y, 'eave end sits just above the wall top').toBeLessThan(room.h + 0.3);+ }+ });+});