castle-web-cli 0.4.237 → 0.4.238

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/dist/bundle.d.ts +24 -0
  2. package/dist/bundle.js +447 -4
  3. package/dist/bundleLatin1.d.ts +6 -0
  4. package/dist/bundleLatin1.js +333 -0
  5. package/dist/castle-host/host.d.ts +10 -1
  6. package/dist/castle-host/host.js +78 -9
  7. package/dist/castleJson.d.ts +2 -0
  8. package/dist/castleJson.js +1 -0
  9. package/dist/deckExports.d.ts +35 -0
  10. package/dist/deckExports.js +365 -0
  11. package/dist/importCheckHook.d.ts +1 -0
  12. package/dist/importCheckHook.js +1 -1
  13. package/dist/index.js +5 -0
  14. package/dist/init.js +2 -1
  15. package/dist/save-deck.js +4 -0
  16. package/kits/base/castle.json +1 -1
  17. package/kits/base/sdk/README.md +47 -0
  18. package/kits/base/sdk/castle.d.ts +3 -1
  19. package/kits/base/sdk/castle.js +1 -0
  20. package/kits/base/sdk/commands.d.ts +25 -1
  21. package/kits/base/sdk/commands.js +29 -1
  22. package/kits/base/sdk/hub.d.ts +17 -0
  23. package/kits/base/sdk/hub.js +33 -9
  24. package/kits/base/sdk/localCache.d.ts +27 -0
  25. package/kits/base/sdk/localCache.js +115 -0
  26. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  27. package/kits/base/sdk/localCacheStore.js +358 -0
  28. package/kits/base/sdk/transport.d.ts +1 -0
  29. package/kits/base/sdk/transport.js +4 -5
  30. package/kits/hub-game/CLAUDE.md +22 -2
  31. package/kits/hub-game/castle.json +4 -1
  32. package/kits/hub-game/code/client/act.js +66 -91
  33. package/kits/hub-game/code/client/actCore.js +134 -0
  34. package/kits/hub-game/code/client/car.js +35 -0
  35. package/kits/hub-game/code/client/chrome.js +207 -381
  36. package/kits/hub-game/code/client/crowdNames.js +2 -2
  37. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  38. package/kits/hub-game/code/client/hats.js +2 -0
  39. package/kits/hub-game/code/client/hookLayer.js +99 -48
  40. package/kits/hub-game/code/client/hostGo.js +77 -0
  41. package/kits/hub-game/code/client/hubControls.js +125 -0
  42. package/kits/hub-game/code/client/hubEntry.js +187 -0
  43. package/kits/hub-game/code/client/hudSurface.js +148 -0
  44. package/kits/hub-game/code/client/hudTree.js +96 -0
  45. package/kits/hub-game/code/client/idle.js +59 -13
  46. package/kits/hub-game/code/client/invites.js +13 -4
  47. package/kits/hub-game/code/client/menuIcons.js +8 -0
  48. package/kits/hub-game/code/client/noTrips.js +38 -0
  49. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  50. package/kits/hub-game/code/client/rehello.js +3 -1
  51. package/kits/hub-game/code/client/riders.js +26 -0
  52. package/kits/hub-game/code/client/role.js +79 -0
  53. package/kits/hub-game/code/client/safeLayout.js +32 -3
  54. package/kits/hub-game/code/client/sound.js +10 -3
  55. package/kits/hub-game/code/client/soundscape.js +2 -2
  56. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  57. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  58. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  59. package/kits/hub-game/code/client/state.js +19 -0
  60. package/kits/hub-game/code/client/stuck.js +2 -1
  61. package/kits/hub-game/code/client/talkSurface.js +178 -0
  62. package/kits/hub-game/code/client/talkTree.js +238 -0
  63. package/kits/hub-game/code/client/tiers.js +8 -5
  64. package/kits/hub-game/code/client/uiDom.js +600 -0
  65. package/kits/hub-game/code/client/uiTree.js +359 -0
  66. package/kits/hub-game/code/client/vehicle.js +154 -0
  67. package/kits/hub-game/code/client/wear.js +27 -5
  68. package/kits/hub-game/code/client/worldLabels.js +3 -2
  69. package/kits/hub-game/code/client/yours.js +10 -3
  70. package/kits/hub-game/code/server/actors.js +4 -3
  71. package/kits/hub-game/code/server/analytics.js +56 -6
  72. package/kits/hub-game/code/server/decor.js +56 -16
  73. package/kits/hub-game/code/server/hub.js +258 -46
  74. package/kits/hub-game/code/server/idle.js +118 -5
  75. package/kits/hub-game/code/server/manifest.js +46 -4
  76. package/kits/hub-game/code/server/npcs.js +4 -2
  77. package/kits/hub-game/code/server/players.js +3 -0
  78. package/kits/hub-game/code/server/role.js +142 -0
  79. package/kits/hub-game/code/server/standing.js +6 -4
  80. package/kits/hub-game/code/server/vehicle.js +126 -0
  81. package/kits/hub-game/code/shared/car.js +52 -0
  82. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  83. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  84. package/kits/hub-game/code/shared/expression.js +9 -0
  85. package/kits/hub-game/code/systems/hub.js +272 -84
  86. package/kits/hub-game/docs/analytics.md +11 -2
  87. package/kits/hub-game/docs/contract.md +352 -14
  88. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  89. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  90. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  91. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  92. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  93. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  94. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  95. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  96. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  97. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  98. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  99. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  100. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  101. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  102. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  103. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  104. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  105. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  106. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  107. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  108. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  109. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  110. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  111. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  112. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  113. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  114. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  115. package/kits/hub-game/package-lock.json +1 -1
  116. package/kits/hub-game/package.json +1 -1
  117. package/kits/hub-game/scripts/check.mjs +7 -4
  118. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  119. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  120. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  121. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  122. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  123. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  124. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  125. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  126. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  127. package/kits/hub-game/scripts/test-analytics.mjs +99 -5
  128. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  129. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  130. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  131. package/kits/hub-game/scripts/test-car.mjs +43 -0
  132. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  133. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  134. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  135. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  136. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  137. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  138. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  139. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  140. package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
  141. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  142. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  143. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  144. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  145. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  146. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  147. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  148. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  149. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  150. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  151. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  152. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  153. package/kits/hub-game/scripts/test-resync.mjs +183 -0
  154. package/kits/hub-game/scripts/test-role-client.mjs +421 -0
  155. package/kits/hub-game/scripts/test-role.mjs +350 -0
  156. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  157. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  158. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  159. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  160. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  161. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  162. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  163. package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
  164. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  165. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  166. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  167. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  168. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  169. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  170. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
  171. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  172. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  173. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  174. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  175. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
  176. package/kits/multiplayer-3d/castle.json +4 -4
  177. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  178. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  179. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  180. package/kits/multiplayer-3d/package-lock.json +1 -1
  181. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  182. package/kits/physics-3d/CLAUDE.md +1 -1
  183. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  184. package/kits/physics-3d/castle.json +2 -2
  185. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  186. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  187. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  188. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  189. package/kits/physics-3d/engine3d/world3d.js +6 -3
  190. package/kits/physics-3d/package.json +1 -1
  191. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  192. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  193. package/kits/physics-3d/systems/physics3d.js +5 -2
  194. package/kits/real-time/castle.json +2 -2
  195. package/kits/real-time/code/client/messages.js +5 -0
  196. package/kits/real-time/code/server/session.js +28 -1
  197. package/kits/real-time/package-lock.json +1 -1
  198. package/package.json +5 -4
  199. package/vendor/three/LICENSE +21 -0
  200. package/vendor/three/build/three.core.js +58773 -0
  201. package/vendor/three/build/three.module.js +18251 -0
  202. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  203. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  204. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  205. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  206. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  207. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  208. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  209. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  210. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  211. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  212. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  213. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  214. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  215. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  216. package/vendor/three/package.json +134 -0
@@ -0,0 +1,39 @@
1
+ // Merges exported decks into one HubSceneManifest root, the folder a native host loads:
2
+ // node merge-root.mjs <root> <deck>/.castle/exports/hubScene [...]
3
+ // Each source is an export.mjs output folder (shared/ + <hubId>/manifest.json). Shared files are
4
+ // content-addressed, so the same name is the same bytes and is linked (copied across filesystems)
5
+ // once. A hub folder in <root> is replaced by the source's. Every merged manifest is validated
6
+ // against <root>; exits 1 on any fault.
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import { validateManifest } from './validate-manifest.mjs';
10
+
11
+ const [rootArg, ...sources] = process.argv.slice(2);
12
+ if (!rootArg || !sources.length) {
13
+ console.error('usage: node merge-root.mjs <root> <exportDir> [...]');
14
+ process.exit(2);
15
+ }
16
+ const root = path.resolve(rootArg);
17
+ fs.mkdirSync(path.join(root, 'shared'), { recursive: true });
18
+ const linkOrCopy = (from, to) => {
19
+ if (fs.existsSync(to)) return;
20
+ try { fs.linkSync(from, to); } catch { fs.copyFileSync(from, to); }
21
+ };
22
+ const report = [];
23
+ for (const src of sources.map((s) => path.resolve(s))) {
24
+ for (const name of fs.readdirSync(path.join(src, 'shared'))) linkOrCopy(path.join(src, 'shared', name), path.join(root, 'shared', name));
25
+ for (const hub of fs.readdirSync(src)) {
26
+ const manifestFile = path.join(src, hub, 'manifest.json');
27
+ if (hub === 'shared' || !fs.existsSync(manifestFile)) continue;
28
+ const dest = path.join(root, hub);
29
+ fs.rmSync(dest, { recursive: true, force: true });
30
+ fs.cpSync(path.join(src, hub), dest, { recursive: true });
31
+ const m = JSON.parse(fs.readFileSync(path.join(dest, 'manifest.json'), 'utf8'));
32
+ const faults = validateManifest(m, dest);
33
+ report.push({ hubId: m.hubId, title: m.title, assets: Object.keys(m.assets).length, faults });
34
+ }
35
+ }
36
+ const files = fs.readdirSync(path.join(root, 'shared'));
37
+ const bytes = files.reduce((n, f) => n + fs.statSync(path.join(root, 'shared', f)).size, 0);
38
+ console.log(JSON.stringify({ root, hubs: report, sharedFiles: files.length, sharedBytes: bytes }));
39
+ process.exit(report.some((r) => r.faults.length) ? 1 : 0);
@@ -0,0 +1,227 @@
1
+ // A hub deck's three.js world built in Node from its folder on disk, with the kit's own engine
2
+ // (physics-3d world3d.syncActors): the same nodes and models the page builds, without a browser or
3
+ // a GPU. Sets globalThis.__hub and globalThis.__expLib the way collectHubData (hubdata.mjs) expects.
4
+ //
5
+ // The kits are written for their bundler: extensionless imports, `@imports/<alias>/` paths, and
6
+ // two workspace packages (castle-web-sdk, castle-web-fonts) the world build calls none of. A loader
7
+ // hook (export.mjs, installed before this file loads) resolves the first two and stands in for the
8
+ // packages. Kit code only ever comes from the CLI's own shipped kits folder; a deck's imports/ is
9
+ // read as data and never imported.
10
+ import crypto from 'node:crypto';
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+ import { pathToFileURL } from 'node:url';
14
+
15
+ /**
16
+ * Imports the engine from `kitsDir` (the CLI's shipped kits), through the loader export.mjs
17
+ * installed before importing this file.
18
+ */
19
+ export async function loadEngine({ kitsDir }) {
20
+ const THREE = await import('three');
21
+ const { GLTFExporter } = await import('three/examples/jsm/exporters/GLTFExporter.js');
22
+ const { mergeGeometries } = await import('three/examples/jsm/utils/BufferGeometryUtils.js');
23
+ const kit = (name, rel) => import(pathToFileURL(path.join(kitsDir, name, rel)).href);
24
+ const world3d = await kit('physics-3d', 'engine3d/world3d.js');
25
+ const { parseBlueprintText, mergeComponents } = await kit('physics-2d', 'engine/blueprintCore.js');
26
+ const { resolveDeckFile } = await import('castle-web-sdk');
27
+ const sky = await kit('physics-3d', 'engine3d/sky.js');
28
+ const skyKey = await kit('physics-2d', 'engine/skyKey.js');
29
+ const defaultEnvironment = await kit('hub-game', 'code/client/defaultEnvironment.js');
30
+ // The Low picture's distances (SCENERY_NEAR_M, NPC_NEAR_M), from the kit itself.
31
+ const tiers = await kit('hub-game', 'code/client/tiers.js');
32
+ // The pad cue list and the spawn ring's mesh, as the hub client makes them.
33
+ const padCues = await kit('hub-game', 'code/client/padCues.js');
34
+ const padRings = await kit('hub-game', 'code/client/padRings.js');
35
+ return { THREE, GLTFExporter, mergeGeometries, tiers, padCues, padRings, world3d, sky, skyKey, parseBlueprintText, mergeComponents, resolveDeckFile, defaultEnvironment };
36
+ }
37
+
38
+ // The data files the world reads, by the deck path the engine asks for: the deck's own file
39
+ // (imports/ included, pinned or not: it is only ever read, never imported), else, for an
40
+ // imports/castle.<kit>/ path the deck has no copy of, the shipped kit's. Every read and every miss
41
+ // is recorded with the bytes' SHA-256, which export.mjs keys its cache on.
42
+ const DATA_FILE = /\.(scene|pxmodel|pxart|sprite|drawing)$/;
43
+ export function deckFiles(deckDir, kitsDir) {
44
+ const reads = new Map();
45
+ const absent = new Set();
46
+ const cache = new Map();
47
+ const locate = (key) => {
48
+ if (key.split('/').includes('..') || key.startsWith('/')) return null;
49
+ const own = path.join(deckDir, key);
50
+ const m = /^imports\/castle\.([a-z0-9-]+)\/(.*)$/.exec(key);
51
+ if (!m || fs.existsSync(own)) return own;
52
+ absent.add(own);
53
+ return path.join(kitsDir, m[1], m[2]);
54
+ };
55
+ const read = (key) => {
56
+ if (typeof key !== 'string' || !DATA_FILE.test(key)) return undefined;
57
+ if (cache.has(key)) return cache.get(key);
58
+ const abs = locate(key);
59
+ let text;
60
+ try { text = abs ? fs.readFileSync(abs) : undefined; } catch { text = undefined; }
61
+ reads.set(key, { file: abs, sha256: text === undefined ? null : crypto.createHash('sha256').update(text).digest('hex') });
62
+ const value = text === undefined ? undefined : text.toString('utf8');
63
+ cache.set(key, value);
64
+ return value;
65
+ };
66
+ const files = new Proxy({}, {
67
+ get: (t, k) => read(k),
68
+ has: (t, k) => read(k) !== undefined,
69
+ // Nothing the world build calls lists the files; a blueprint helper that does sees none.
70
+ ownKeys: () => [],
71
+ getOwnPropertyDescriptor: (t, k) => { const v = read(k); return v === undefined ? undefined : { value: v, enumerable: true, configurable: true, writable: false }; },
72
+ });
73
+ return { files, reads, absent };
74
+ }
75
+
76
+ // GLTFExporter's binary path and collectHubData read Blobs through FileReader, which Node lacks.
77
+ if (!globalThis.FileReader) {
78
+ globalThis.FileReader = class {
79
+ readAsArrayBuffer(blob) { blob.arrayBuffer().then((b) => { this.result = b; this.onloadend?.(); this.onload?.(); }); }
80
+ readAsDataURL(blob) {
81
+ blob.arrayBuffer().then((b) => {
82
+ this.result = `data:${blob.type || 'application/octet-stream'};base64,${Buffer.from(b).toString('base64')}`;
83
+ this.onloadend?.(); this.onload?.();
84
+ });
85
+ }
86
+ };
87
+ }
88
+
89
+ // The physics-3d behaviors' defaultProps (behaviors/*.jsx, which Node cannot import), applied as
90
+ // SceneRuntime.load applies them; collectHubData gives every other component its own fallbacks.
91
+ const DEFAULTS = {
92
+ Transform: { x: 0, y: 0, z: 0, rotationX: 0, rotationY: 0, rotationZ: 0 },
93
+ Shape: { kind: 'box', width: 1, height: 1, depth: 1, radius: 0.5, color: '#c7cfdd', art: '', artRepeat: null, tint: '', roughness: 0.7,
94
+ metalness: 0, clearcoat: 0, emissive: '#000000', emissiveIntensity: 1, solid: false },
95
+ Model: { file: '', scale: 1, yOffset: 0 },
96
+ Body: { type: 'fixed', friction: 0.6, restitution: 0, gravityScale: 0, lockRotations: false },
97
+ };
98
+
99
+ /**
100
+ * Builds the deck scene `scenePath` from `files` (deckFiles) and installs it as globalThis.__hub.
101
+ * `avatarBlueprint` (a deck path) is built too, far from the scene at its capsule's half height, as
102
+ * actor `avatarId`: collectHubData exports it as the avatar and leaves it out of everything else.
103
+ * Returns { world, runtime, actors, notes }.
104
+ */
105
+ export function buildDeckWorld(engine, { files, scenePath, avatarBlueprint = null, avatarId = '__hub_avatar' }) {
106
+ const { THREE, GLTFExporter, mergeGeometries, world3d, parseBlueprintText, mergeComponents, resolveDeckFile } = engine;
107
+ const notes = [];
108
+ const text = files[scenePath];
109
+ if (text === undefined) throw new Error(`no scene ${scenePath}`);
110
+ const data = JSON.parse(text);
111
+
112
+ // blueprint.js getBlueprintTemplate (which Node cannot import: it globs files at build time): the
113
+ // ref resolves against the scene that wrote it, and the template's own file refs against the
114
+ // blueprint's deck, rewritten only when the resolved path is a file the deck has.
115
+ const blueprintTemplate = (ref, fromPath) => {
116
+ const key = resolveDeckFile(ref, fromPath);
117
+ const template = parseBlueprintText(files[key]);
118
+ if (!template) notes.push(`blueprint ${key} not found`);
119
+ const resolveIn = (props) => {
120
+ for (const [k, value] of Object.entries(props ?? {})) {
121
+ if (typeof value === 'string' && value) {
122
+ const resolved = resolveDeckFile(value, key);
123
+ if (resolved !== value && files[resolved] !== undefined) props[k] = resolved;
124
+ } else if (value && typeof value === 'object' && !Array.isArray(value)) resolveIn(value);
125
+ }
126
+ };
127
+ for (const props of Object.values(template?.components ?? {})) resolveIn(props);
128
+ return template;
129
+ };
130
+ const materialize = (a, fromPath) => {
131
+ const own = structuredClone(a.components ?? {});
132
+ const template = a.blueprint ? blueprintTemplate(a.blueprint, fromPath) : null;
133
+ const components = template ? mergeComponents(template.components, own) : own;
134
+ for (const [name, defaults] of Object.entries(DEFAULTS)) if (components[name]) components[name] = { ...defaults, ...components[name] };
135
+ return { ...a, runtime: {}, components };
136
+ };
137
+ const actors = (data.actors ?? []).map((a) => materialize(a, scenePath));
138
+ if (avatarBlueprint) {
139
+ const body = materialize({ id: avatarId, blueprint: avatarBlueprint, components: {} }, '');
140
+ const half = (body.components.Shape?.height ?? 1.4) / 2;
141
+ // Far from the scene, so the floor under it is the bare origin plane (y 0).
142
+ body.components.Transform = { ...DEFAULTS.Transform, x: 1e4, y: half, z: 1e4 };
143
+ if (body.components.Model) actors.push(body);
144
+ else notes.push(`avatar ${avatarBlueprint} has no Model`);
145
+ }
146
+
147
+ const scene = new THREE.Scene();
148
+ const ground = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), new THREE.MeshStandardMaterial({ color: 0x22222b }));
149
+ ground.rotation.x = -Math.PI / 2;
150
+ ground.position.y = -0.01;
151
+ ground.name = 'engine.ground';
152
+ const grid = new THREE.GridHelper(60, 60, 0x505050, 0x505050);
153
+ grid.visible = false;
154
+ scene.add(ground, grid);
155
+ addLights(THREE, scene);
156
+ const camera = new THREE.PerspectiveCamera(70, 16 / 9, 0.1, 1000);
157
+ const clear = new THREE.Color(0x000000);
158
+ // The renderer surface collectHubData and the hub's default environment read, at the engine's defaults.
159
+ const renderer = {
160
+ dispose() {},
161
+ properties: { get: () => null },
162
+ getClearColor: (c) => c.copy(clear),
163
+ setClearColor: (c) => { clear.set(c); },
164
+ getClearAlpha: () => 1,
165
+ toneMapping: THREE.NoToneMapping,
166
+ toneMappingExposure: 1,
167
+ outputColorSpace: THREE.SRGBColorSpace,
168
+ getPixelRatio: () => 1,
169
+ domElement: null,
170
+ };
171
+ const world = {
172
+ scene, camera, renderer, nodes: new Map(), parked: new Map(), models: new Map(), skipping: { on: false },
173
+ modelSigs: new Map(), sigEpoch: 0, syncCount: 0, syncDepth: 0, generation: 0, snapshots: new WeakMap(),
174
+ nearShadows: null, sky: null, orbitLens: null, shadowFade: null, bakesLookLater: false, lookBake: null,
175
+ instances: new Map(), instanceModels: false, ground, grid,
176
+ };
177
+ const runtime = { scenePath, data, files, actors, getActors() { return [...this.actors]; } };
178
+ world3d.syncGround(world, data.ground, {});
179
+ world3d.syncActors(world, runtime, {}, 0);
180
+ scene.updateMatrixWorld(true);
181
+
182
+ // The camera where the kit's follow camera starts: behind the player, looking at it.
183
+ const player = actors.find((a) => a.components.Player && a.id !== avatarId);
184
+ const pt = player?.components.Transform ?? { x: 0, y: 1, z: 0, rotationY: 0 };
185
+ const dist = player?.components.Player?.camDistance ?? 6;
186
+ const height = player?.components.Player?.camHeight ?? 4.5;
187
+ const yaw = ((pt.rotationY ?? 0) * Math.PI) / 180;
188
+ camera.position.set(pt.x - Math.sin(yaw) * dist, (pt.y ?? 0) + height, pt.z - Math.cos(yaw) * dist);
189
+ camera.lookAt(pt.x, pt.y ?? 0, pt.z);
190
+ camera.updateMatrixWorld(true);
191
+
192
+ const hubScene = { actors: new Map(actors.map((a) => [a.id, a])), data, three: world, actorWith: (name) => actors.find((a) => a.components[name] && a.id !== avatarId) ?? null };
193
+
194
+ // The sky dome, as the kit's sky.js makes it on the first frame of a scene with an engine.sky key.
195
+ // SceneRuntime reads the key with physics-2d skyKey.js readSkyKey; sky.js draws from runtime.sky.
196
+ if (data.engine?.sky && engine.sky?.renderWithSky && engine.skyKey?.readSkyKey) {
197
+ try {
198
+ runtime.sky = engine.skyKey.readSkyKey(data, (message) => notes.push(`sky key: ${message}`));
199
+ if (runtime.sky) engine.sky.renderWithSky(world, runtime, () => {}, 0);
200
+ } catch (e) { notes.push(`sky: ${e?.message ?? e}`); }
201
+ if (!world.sky?.mesh) notes.push('sky: the kit made no dome in Node');
202
+ }
203
+ // The hub kit's fallback picture (clear colour and linear fog) for a scene that authors none.
204
+ if (engine.defaultEnvironment?.makeDefaultEnvironment) {
205
+ try {
206
+ // A frame with no local player adopts the scene and draws no fall fade.
207
+ engine.defaultEnvironment.makeDefaultEnvironment().frame(hubScene, null);
208
+ } catch (e) { notes.push(`default environment: ${e?.message ?? e}`); }
209
+ }
210
+
211
+ globalThis.__expLib = { THREE, GLTFExporter, mergeGeometries };
212
+ globalThis.__THREE__ = THREE.REVISION;
213
+ globalThis.__hub = { scene: hubScene, state: null, tier: null };
214
+ return { world, runtime, actors, notes };
215
+ }
216
+
217
+ // world3d addLights, which makeWorld3D runs with its renderer.
218
+ function addLights(THREE, scene) {
219
+ scene.add(new THREE.HemisphereLight(0xc8d0d8, 0x3a3530, 0.62 * Math.PI));
220
+ scene.add(new THREE.AmbientLight(0xffffff, 0.24));
221
+ const sun = new THREE.DirectionalLight(0xffffff, 1.15);
222
+ sun.position.set(6, 18, -6);
223
+ sun.castShadow = true;
224
+ sun.shadow.mapSize.set(2048, 2048);
225
+ Object.assign(sun.shadow.camera, { near: 0.5, far: 50, top: 85, bottom: -35, left: -75, right: 75 });
226
+ scene.add(sun, sun.target);
227
+ }