create-threenative 0.2.17 → 0.2.18

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 (310) hide show
  1. package/agent-docs/kit-mcp.md +1 -1
  2. package/agent-docs/kit-router.md +1 -1
  3. package/agent-docs/references/assertion-reference.md +54 -110
  4. package/agent-docs/references/capability-reference.md +580 -22
  5. package/agent-docs/references/conventions.md +28 -0
  6. package/agent-docs/references/performance-basics.md +8 -4
  7. package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
  8. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +7 -4
  9. package/agent-files/.claude/hooks/discovery-gate.mjs +2 -2
  10. package/dist/index.d.ts +97 -6
  11. package/dist/index.js +769 -277
  12. package/dist/threenative.js +96 -17
  13. package/dist/web-engine-ccd-ik-solver.js +127 -0
  14. package/dist/web-engine-gltf-loader.js +52 -14
  15. package/dist/web-engine-post-effects.js +5 -10
  16. package/dist/web-engine-runtime.js +3648 -546
  17. package/package.json +8 -7
  18. package/template-assets/clearwater/README.md +1 -1
  19. package/template-assets/patches/manifest.json +18 -0
  20. package/template-assets/terrain/alpine/assets.json +12 -0
  21. package/template-assets/terrain/alpine/bake.mjs +6 -0
  22. package/template-assets/terrain/alpine/credits.json +164 -0
  23. package/template-assets/terrain/alpine/heightmap.r16 +0 -0
  24. package/template-assets/terrain/alpine/recipe.json +119 -0
  25. package/template-assets/terrain/alpine/surface.json +53 -0
  26. package/template-assets/terrain/coastal/assets.json +11 -0
  27. package/template-assets/terrain/coastal/bake.mjs +6 -0
  28. package/template-assets/terrain/coastal/credits.json +117 -0
  29. package/template-assets/terrain/coastal/heightmap.r16 +0 -0
  30. package/template-assets/terrain/coastal/recipe.json +113 -0
  31. package/template-assets/terrain/coastal/surface.json +41 -0
  32. package/template-assets/terrain/desert/assets.json +12 -0
  33. package/template-assets/terrain/desert/bake.mjs +6 -0
  34. package/template-assets/terrain/desert/credits.json +164 -0
  35. package/template-assets/terrain/desert/heightmap.r16 +0 -0
  36. package/template-assets/terrain/desert/recipe.json +108 -0
  37. package/template-assets/terrain/desert/surface.json +54 -0
  38. package/template-assets/terrain/forest/assets.json +65 -0
  39. package/template-assets/terrain/forest/bake.mjs +8 -0
  40. package/template-assets/terrain/forest/credits.json +225 -0
  41. package/template-assets/terrain/forest/heightmap.r16 +0 -0
  42. package/template-assets/terrain/forest/recipe.json +350 -0
  43. package/template-assets/terrain/forest/surface.json +79 -0
  44. package/template-assets/terrain/tundra/assets.json +12 -0
  45. package/template-assets/terrain/tundra/bake.mjs +6 -0
  46. package/template-assets/terrain/tundra/credits.json +164 -0
  47. package/template-assets/terrain/tundra/heightmap.r16 +0 -0
  48. package/template-assets/terrain/tundra/recipe.json +277 -0
  49. package/template-assets/terrain/tundra/surface.json +54 -0
  50. package/templates/action-rpg/AGENTS.md +8 -4
  51. package/templates/action-rpg/CLAUDE.md +8 -4
  52. package/templates/action-rpg/package.json +7 -7
  53. package/templates/action-rpg/src/game.ts +1 -1
  54. package/templates/action-rpg/src/render/atmosphere.ts +6 -0
  55. package/templates/action-rpg/src/render/backlightControls.ts +10 -0
  56. package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
  57. package/templates/action-rpg/src/render/clouds.ts +13 -0
  58. package/templates/action-rpg/src/render/materialLighting.ts +5 -5
  59. package/templates/action-rpg/src/render/quality.ts +7 -32
  60. package/templates/action-rpg/src/scenes/Play.ts +4 -1
  61. package/templates/action-rpg/src/style.css +4 -0
  62. package/templates/action-rpg/vite.config.ts +2 -0
  63. package/templates/adventure/AGENTS.md +7 -2
  64. package/templates/adventure/CLAUDE.md +7 -2
  65. package/templates/adventure/kit.json +5 -1
  66. package/templates/adventure/package.json +7 -7
  67. package/templates/adventure/src/game.ts +1 -1
  68. package/templates/adventure/src/style.css +4 -0
  69. package/templates/adventure/tsconfig.json +1 -1
  70. package/templates/adventure/vite.config.ts +2 -0
  71. package/templates/collectathon/AGENTS.md +7 -2
  72. package/templates/collectathon/CLAUDE.md +7 -2
  73. package/templates/collectathon/package.json +7 -7
  74. package/templates/collectathon/src/game.ts +1 -1
  75. package/templates/collectathon/src/level/Course.ts +55 -9
  76. package/templates/collectathon/src/level/terrain.ts +27 -6
  77. package/templates/collectathon/src/main.ts +1 -0
  78. package/templates/collectathon/src/render/foliage.ts +359 -98
  79. package/templates/collectathon/src/render/sky.ts +76 -12
  80. package/templates/collectathon/src/render/water.ts +32 -10
  81. package/templates/collectathon/src/scenes/Play.ts +18 -5
  82. package/templates/collectathon/src/style.css +4 -0
  83. package/templates/collectathon/tsconfig.json +1 -1
  84. package/templates/collectathon/vite.config.ts +2 -0
  85. package/templates/kart/AGENTS.md +7 -2
  86. package/templates/kart/CLAUDE.md +7 -2
  87. package/templates/kart/package.json +6 -6
  88. package/templates/kart/src/game.ts +1 -1
  89. package/templates/kart/src/main.ts +1 -0
  90. package/templates/kart/src/style.css +4 -0
  91. package/templates/kart/tsconfig.json +1 -1
  92. package/templates/kart/vite.config.ts +2 -0
  93. package/templates/minimal/AGENTS.md +8 -3
  94. package/templates/minimal/CLAUDE.md +8 -3
  95. package/templates/minimal/package.json +6 -6
  96. package/templates/minimal/playtests/stands-still.playtest.json +30 -0
  97. package/templates/minimal/src/game.ts +1 -1
  98. package/templates/minimal/src/render/atmosphere.ts +6 -0
  99. package/templates/minimal/src/render/backlightControls.ts +10 -0
  100. package/templates/minimal/src/render/backlightMaterial.ts +4 -4
  101. package/templates/minimal/src/render/camera.ts +13 -2
  102. package/templates/minimal/src/render/clouds.ts +13 -0
  103. package/templates/minimal/src/render/lighting.ts +4 -2
  104. package/templates/minimal/src/render/materialLighting.ts +5 -5
  105. package/templates/minimal/src/render/materials.ts +10 -0
  106. package/templates/minimal/src/render/quality.ts +7 -32
  107. package/templates/minimal/src/scenes/Play.ts +4 -1
  108. package/templates/minimal/vite.config.ts +7 -1
  109. package/templates/platformer/AGENTS.md +9 -4
  110. package/templates/platformer/CLAUDE.md +9 -4
  111. package/templates/platformer/index.html +1 -1
  112. package/templates/platformer/main.html +12 -0
  113. package/templates/platformer/package.json +7 -7
  114. package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
  115. package/templates/platformer/playtests/gamepad.playtest.json +30 -0
  116. package/templates/platformer/src/entities/Fox.ts +21 -6
  117. package/templates/platformer/src/game.ts +1 -1
  118. package/templates/platformer/src/main.ts +1 -0
  119. package/templates/platformer/src/render/backlightControls.ts +10 -0
  120. package/templates/platformer/src/render/backlightMaterial.ts +4 -4
  121. package/templates/platformer/src/render/materialLighting.ts +5 -5
  122. package/templates/platformer/src/render/quality.ts +7 -32
  123. package/templates/platformer/src/scenes/Play.ts +2 -1
  124. package/templates/platformer/src/style.css +4 -0
  125. package/templates/platformer/src/worker-page.ts +29 -0
  126. package/templates/platformer/src/worker.ts +5 -0
  127. package/templates/platformer/tsconfig.json +1 -1
  128. package/templates/platformer/vite.config.ts +4 -0
  129. package/templates/puzzle/AGENTS.md +7 -2
  130. package/templates/puzzle/CLAUDE.md +7 -2
  131. package/templates/puzzle/package.json +7 -7
  132. package/templates/puzzle/src/game.ts +1 -1
  133. package/templates/puzzle/src/render/backlightControls.ts +10 -0
  134. package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
  135. package/templates/puzzle/src/render/materialLighting.ts +5 -5
  136. package/templates/puzzle/src/render/quality.ts +7 -32
  137. package/templates/puzzle/src/scenes/Play.ts +1 -1
  138. package/templates/puzzle/src/style.css +4 -0
  139. package/templates/puzzle/tsconfig.json +1 -1
  140. package/templates/puzzle/vite.config.ts +2 -0
  141. package/templates/racing/AGENTS.md +7 -2
  142. package/templates/racing/CLAUDE.md +7 -2
  143. package/templates/racing/package.json +7 -7
  144. package/templates/racing/src/game.ts +1 -1
  145. package/templates/racing/src/render/atmosphere.ts +6 -0
  146. package/templates/racing/src/render/backlightControls.ts +10 -0
  147. package/templates/racing/src/render/backlightMaterial.ts +4 -4
  148. package/templates/racing/src/render/clouds.ts +13 -0
  149. package/templates/racing/src/render/materialLighting.ts +5 -5
  150. package/templates/racing/src/render/quality.ts +7 -32
  151. package/templates/racing/src/scenes/Race.ts +4 -1
  152. package/templates/racing/src/style.css +4 -0
  153. package/templates/racing/tsconfig.json +1 -1
  154. package/templates/racing/vite.config.ts +2 -0
  155. package/templates/rain/AGENTS.md +6 -2
  156. package/templates/rain/CLAUDE.md +6 -2
  157. package/templates/rain/package.json +6 -6
  158. package/templates/rain/src/game.ts +1 -1
  159. package/templates/rain/vite.config.ts +6 -0
  160. package/templates/rts/AGENTS.md +6 -2
  161. package/templates/rts/CLAUDE.md +6 -2
  162. package/templates/rts/package.json +6 -6
  163. package/templates/rts/src/game.ts +1 -1
  164. package/templates/rts/src/render/backlightControls.ts +10 -0
  165. package/templates/rts/src/render/backlightMaterial.ts +4 -4
  166. package/templates/rts/src/render/materialLighting.ts +5 -5
  167. package/templates/rts/src/render/quality.ts +7 -31
  168. package/templates/rts/src/scenes/Play.ts +1 -1
  169. package/templates/rts/src/style.css +4 -0
  170. package/templates/rts/vite.config.ts +2 -0
  171. package/templates/runner/AGENTS.md +7 -2
  172. package/templates/runner/CLAUDE.md +7 -2
  173. package/templates/runner/package.json +7 -7
  174. package/templates/runner/src/game.ts +1 -1
  175. package/templates/runner/src/render/atmosphere.ts +6 -0
  176. package/templates/runner/src/render/backlightControls.ts +10 -0
  177. package/templates/runner/src/render/backlightMaterial.ts +4 -4
  178. package/templates/runner/src/render/clouds.ts +13 -0
  179. package/templates/runner/src/render/materialLighting.ts +5 -5
  180. package/templates/runner/src/render/quality.ts +7 -32
  181. package/templates/runner/src/scenes/Run.ts +4 -1
  182. package/templates/runner/src/style.css +4 -0
  183. package/templates/runner/tsconfig.json +1 -1
  184. package/templates/runner/vite.config.ts +2 -0
  185. package/templates/sailing/AGENTS.md +7 -2
  186. package/templates/sailing/CLAUDE.md +7 -2
  187. package/templates/sailing/package.json +7 -7
  188. package/templates/sailing/src/game.ts +1 -1
  189. package/templates/sailing/src/render/backlightControls.ts +10 -0
  190. package/templates/sailing/src/render/backlightMaterial.ts +4 -4
  191. package/templates/sailing/src/render/environmentSetup.ts +1 -1
  192. package/templates/sailing/src/render/materialLighting.ts +5 -5
  193. package/templates/sailing/src/render/quality.ts +7 -32
  194. package/templates/sailing/src/style.css +5 -0
  195. package/templates/sailing/vite.config.ts +6 -0
  196. package/templates/shooter/AGENTS.md +6 -2
  197. package/templates/shooter/CLAUDE.md +6 -2
  198. package/templates/shooter/package.json +7 -7
  199. package/templates/shooter/src/game.ts +3 -2
  200. package/templates/shooter/src/render/atmosphere.ts +6 -0
  201. package/templates/shooter/src/render/backlightControls.ts +10 -0
  202. package/templates/shooter/src/render/backlightMaterial.ts +4 -4
  203. package/templates/shooter/src/render/clouds.ts +13 -0
  204. package/templates/shooter/src/render/materialLighting.ts +5 -5
  205. package/templates/shooter/src/render/quality.ts +7 -32
  206. package/templates/shooter/src/scenes/Play.ts +4 -1
  207. package/templates/shooter/src/style.css +4 -0
  208. package/templates/shooter/vite.config.ts +2 -0
  209. package/templates/snow/AGENTS.md +7 -2
  210. package/templates/snow/CLAUDE.md +7 -2
  211. package/templates/snow/package.json +7 -7
  212. package/templates/snow/src/game.ts +1 -1
  213. package/templates/snow/src/render/backlightControls.ts +10 -0
  214. package/templates/snow/src/render/backlightMaterial.ts +4 -4
  215. package/templates/snow/src/render/materialLighting.ts +5 -5
  216. package/templates/snow/src/render/quality.ts +7 -32
  217. package/templates/snow/src/style.css +5 -0
  218. package/templates/snow/vite.config.ts +6 -0
  219. package/templates/starter/AGENTS.md +8 -3
  220. package/templates/starter/CLAUDE.md +8 -3
  221. package/templates/starter/package.json +7 -7
  222. package/templates/starter/src/entities/Crate.ts +5 -2
  223. package/templates/starter/src/game.ts +4 -3
  224. package/templates/starter/src/render/adaptiveQuality.ts +17 -0
  225. package/templates/starter/src/render/atmosphere.ts +6 -0
  226. package/templates/starter/src/render/backlightControls.ts +10 -0
  227. package/templates/starter/src/render/backlightMaterial.ts +4 -4
  228. package/templates/starter/src/render/clouds.ts +13 -0
  229. package/templates/starter/src/render/contactShadow.ts +1 -1
  230. package/templates/starter/src/render/materialLighting.ts +5 -5
  231. package/templates/starter/src/render/postprocessing.ts +11 -10
  232. package/templates/starter/src/render/quality.ts +14 -1
  233. package/templates/starter/src/scenes/Play.ts +12 -3
  234. package/templates/starter/src/state.ts +2 -0
  235. package/templates/starter/src/style.css +4 -0
  236. package/templates/starter/src/ui/Menu.tsx +5 -1
  237. package/templates/starter/vite.config.ts +2 -0
  238. package/templates/tower-defense/AGENTS.md +7 -2
  239. package/templates/tower-defense/CLAUDE.md +7 -2
  240. package/templates/tower-defense/package.json +7 -7
  241. package/templates/tower-defense/src/game.ts +1 -1
  242. package/templates/tower-defense/src/render/backlightControls.ts +10 -0
  243. package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
  244. package/templates/tower-defense/src/render/materialLighting.ts +5 -5
  245. package/templates/tower-defense/src/render/quality.ts +7 -32
  246. package/templates/tower-defense/src/scenes/Battle.ts +1 -1
  247. package/templates/tower-defense/src/style.css +4 -0
  248. package/templates/tower-defense/tsconfig.json +1 -1
  249. package/templates/tower-defense/vite.config.ts +2 -0
  250. package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
  251. package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
  252. package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
  253. package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
  254. package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
  255. package/templates/minimal/src/render/environmentContribution.ts +0 -188
  256. package/templates/minimal/src/render/environmentRadiance.ts +0 -36
  257. package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
  258. package/templates/minimal/src/render/environmentSampling.ts +0 -193
  259. package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
  260. package/templates/platformer/src/render/environmentContribution.ts +0 -188
  261. package/templates/platformer/src/render/environmentRadiance.ts +0 -36
  262. package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
  263. package/templates/platformer/src/render/environmentSampling.ts +0 -193
  264. package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
  265. package/templates/puzzle/src/render/environmentContribution.ts +0 -188
  266. package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
  267. package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
  268. package/templates/puzzle/src/render/environmentSampling.ts +0 -193
  269. package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
  270. package/templates/racing/src/render/environmentContribution.ts +0 -188
  271. package/templates/racing/src/render/environmentRadiance.ts +0 -36
  272. package/templates/racing/src/render/environmentSampleCache.ts +0 -43
  273. package/templates/racing/src/render/environmentSampling.ts +0 -193
  274. package/templates/racing/src/render/environmentSnapshot.ts +0 -53
  275. package/templates/rts/src/render/environmentContribution.ts +0 -188
  276. package/templates/rts/src/render/environmentRadiance.ts +0 -36
  277. package/templates/rts/src/render/environmentSampleCache.ts +0 -43
  278. package/templates/rts/src/render/environmentSampling.ts +0 -193
  279. package/templates/rts/src/render/environmentSnapshot.ts +0 -53
  280. package/templates/runner/src/render/environmentContribution.ts +0 -188
  281. package/templates/runner/src/render/environmentRadiance.ts +0 -36
  282. package/templates/runner/src/render/environmentSampleCache.ts +0 -43
  283. package/templates/runner/src/render/environmentSampling.ts +0 -193
  284. package/templates/runner/src/render/environmentSnapshot.ts +0 -53
  285. package/templates/sailing/src/render/environmentContribution.ts +0 -188
  286. package/templates/sailing/src/render/environmentRadiance.ts +0 -36
  287. package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
  288. package/templates/sailing/src/render/environmentSampling.ts +0 -193
  289. package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
  290. package/templates/shooter/src/render/environmentContribution.ts +0 -188
  291. package/templates/shooter/src/render/environmentRadiance.ts +0 -36
  292. package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
  293. package/templates/shooter/src/render/environmentSampling.ts +0 -193
  294. package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
  295. package/templates/snow/src/render/environmentContribution.ts +0 -188
  296. package/templates/snow/src/render/environmentRadiance.ts +0 -36
  297. package/templates/snow/src/render/environmentSampleCache.ts +0 -43
  298. package/templates/snow/src/render/environmentSampling.ts +0 -193
  299. package/templates/snow/src/render/environmentSnapshot.ts +0 -53
  300. package/templates/starter/src/render/environmentContribution.ts +0 -188
  301. package/templates/starter/src/render/environmentRadiance.ts +0 -36
  302. package/templates/starter/src/render/environmentSampleCache.ts +0 -43
  303. package/templates/starter/src/render/environmentSampling.ts +0 -193
  304. package/templates/starter/src/render/environmentSnapshot.ts +0 -53
  305. package/templates/starter/src/render/rendererGate.ts +0 -36
  306. package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
  307. package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
  308. package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
  309. package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
  310. package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
@@ -13,6 +13,7 @@ import { compileAssets, parsePng, parseAudioConfig } from '@threenative/assets';
13
13
  import { read, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_SRGB_BLOCK, KHR_SUPERCOMPRESSION_NONE, KHR_DF_MODEL_ASTC, KHR_DF_TRANSFER_SRGB, KHR_DF_TRANSFER_LINEAR } from 'ktx-parse';
14
14
  import { brotliCompressSync, constants as constants$1, gzipSync } from 'zlib';
15
15
  import { platform, homedir } from 'os';
16
+ import { fixAuthoringLayer, authoringLayerStatus } from './index.js';
16
17
 
17
18
  createRequire(import.meta.url);
18
19
  var BUILD_REPORT_SUFFIX = ".build-report.json";
@@ -184,6 +185,13 @@ function positiveInteger(value, fallback, code, label) {
184
185
  }
185
186
  return value;
186
187
  }
188
+ function priorityValue(value) {
189
+ if (value === void 0) return "game";
190
+ if (value !== "game" && value !== "normal") {
191
+ fail("TN_CONFIG_PRIORITY_INVALID", 'display.priority must be "game" or "normal".');
192
+ }
193
+ return value;
194
+ }
187
195
  function maxFpsValue(value) {
188
196
  if (value === void 0) return 60;
189
197
  if (!Number.isSafeInteger(value) || value < 0 || value > 1e3) {
@@ -285,6 +293,10 @@ function resolveEsbuild(cwd) {
285
293
  }
286
294
  }
287
295
  }
296
+ var configLoadSequence = 0;
297
+ function configTempName(cwd, pid, now, sequence) {
298
+ return path5.join(cwd, `.threenative.config.${pid}.${now}.${sequence}.mjs`);
299
+ }
288
300
  async function importConfig(cwd) {
289
301
  const sourcePath = path5.join(cwd, CONFIG_FILE);
290
302
  try {
@@ -347,7 +359,8 @@ async function importConfig(cwd) {
347
359
  error instanceof Error ? error.message : String(error)
348
360
  );
349
361
  }
350
- const compiledPath = path5.join(cwd, `.threenative.config.${process.pid}.${Date.now()}.mjs`);
362
+ configLoadSequence += 1;
363
+ const compiledPath = configTempName(cwd, process.pid, Date.now(), configLoadSequence);
351
364
  try {
352
365
  await writeFile(compiledPath, code, "utf8");
353
366
  } catch (error) {
@@ -622,7 +635,13 @@ async function validateIconVariants(raw, cwd) {
622
635
  }
623
636
  function validateDisplay(raw) {
624
637
  const display = assertRecord(raw, "display");
625
- assertKeys(display, "display", ["orientation", "fullscreen", "keepScreenOn", "maxFps"]);
638
+ assertKeys(display, "display", [
639
+ "orientation",
640
+ "fullscreen",
641
+ "keepScreenOn",
642
+ "priority",
643
+ "maxFps"
644
+ ]);
626
645
  const orientation = display.orientation === void 0 ? "landscape" : display.orientation;
627
646
  if (typeof orientation !== "string" || !ORIENTATIONS.includes(orientation)) {
628
647
  fail(
@@ -644,6 +663,7 @@ function validateDisplay(raw) {
644
663
  "TN_CONFIG_KEEP_SCREEN_ON_INVALID",
645
664
  "display.keepScreenOn"
646
665
  ),
666
+ priority: priorityValue(display.priority),
647
667
  maxFps: maxFpsValue(display.maxFps)
648
668
  };
649
669
  }
@@ -1713,8 +1733,8 @@ function describeNativeCssFindings(findings) {
1713
1733
  (f) => ` ${f.file}:${f.line}:${f.column}${f.authored === void 0 ? "" : ` authored ${f.authored}`} ${f.what} \u2014 ${f.why}`
1714
1734
  ).join("\n");
1715
1735
  }
1716
- function webRuntimeDecoders(config) {
1717
- return config.engine === "threejs" ? { ktx2: true, meshopt: true } : { ktx2: false, meshopt: false };
1736
+ function webRuntimeDecoders(_config) {
1737
+ return { ktx2: true, meshopt: true };
1718
1738
  }
1719
1739
 
1720
1740
  // src/build.ts
@@ -2371,7 +2391,7 @@ async function buildWeb(cwd, viteArgs = [], profile) {
2371
2391
  config: config.assets,
2372
2392
  cwd,
2373
2393
  platform: "web",
2374
- runtimeDecoders: webRuntimeDecoders(config),
2394
+ runtimeDecoders: webRuntimeDecoders(),
2375
2395
  ...config.engine !== "threejs" && { runtimeIdentity: "web:native-engine" }
2376
2396
  });
2377
2397
  const assets = assetRoot(cwd, config);
@@ -2686,6 +2706,8 @@ async function buildEngineDesktop(cwd, config, entry) {
2686
2706
  String(config.window.height),
2687
2707
  "--title",
2688
2708
  config.window.title,
2709
+ "--priority",
2710
+ config.display.priority,
2689
2711
  "--output",
2690
2712
  output
2691
2713
  ]);
@@ -3245,11 +3267,11 @@ var MCP_SERVERS = Object.freeze({
3245
3267
  })
3246
3268
  });
3247
3269
  var MCP_PACKAGES = Object.freeze({
3248
- assets: Object.freeze({ name: "threenative-asset-mcp", version: "0.15.0" }),
3249
- terrain: Object.freeze({ name: "@threenative/terrain", version: "0.1.8" }),
3270
+ assets: Object.freeze({ name: "threenative-asset-mcp", version: "0.16.0" }),
3271
+ terrain: Object.freeze({ name: "@threenative/terrain", version: "0.1.9" }),
3250
3272
  sculpt: Object.freeze({ name: "threenative-sculpt-mcp", version: "0.2.2" }),
3251
- engine: Object.freeze({ name: "threenative-engine-mcp", version: "0.2.12" }),
3252
- animation: Object.freeze({ name: "threenative-animation-mcp", version: "0.1.9" }),
3273
+ engine: Object.freeze({ name: "threenative-engine-mcp", version: "0.2.13" }),
3274
+ animation: Object.freeze({ name: "threenative-animation-mcp", version: "0.1.10" }),
3253
3275
  // `args` fixes the launch for every host. The Chrome flags are `WEBGPU_BROWSER_ARGS` from
3254
3276
  // `@threenative/playtest`, so a DevTools trace profiles the same adapter a playtest does and not
3255
3277
  // SwiftShader. An isolated profile keeps the user's own Chrome profile out, and the two opt-outs
@@ -3362,7 +3384,12 @@ var MCP_HOSTS = Object.freeze([
3362
3384
  Object.freeze({ id: "zed", label: "Zed", file: ".zed/settings.json", format: "zed" })
3363
3385
  ]);
3364
3386
 
3387
+ // ../core/src/version.ts
3388
+ var CORE_VERSION = "0.3.13";
3389
+
3365
3390
  // src/mcp-servers.ts
3391
+ var CORE_PACKAGE_NAME = "@threenative/core";
3392
+ var CORE_PACKAGE_VERSION = CORE_VERSION;
3366
3393
  function serverEntryPath(server) {
3367
3394
  const entry = server.args[0];
3368
3395
  if (entry === void 0) {
@@ -3408,8 +3435,6 @@ function requiredAndroidSdkFromRoot(root) {
3408
3435
  return DEFAULT_ANDROID_COMPILE_SDK;
3409
3436
  }
3410
3437
  }
3411
- var CORE_PACKAGE_NAME = "@threenative/core";
3412
- var CORE_PACKAGE_VERSION = "0.3.12";
3413
3438
  var CORE_RESOLVED_SERVERS = /* @__PURE__ */ new Set([
3414
3439
  "threenative-engine",
3415
3440
  "threenative-animation"
@@ -3735,7 +3760,7 @@ function probeMcpServer(projectRoot, spec) {
3735
3760
  method: "initialize",
3736
3761
  params: {
3737
3762
  capabilities: {},
3738
- clientInfo: { name: "threenative-doctor", version: "0.3.12" },
3763
+ clientInfo: { name: "threenative-doctor", version: CORE_PACKAGE_VERSION },
3739
3764
  protocolVersion: "2025-06-18"
3740
3765
  }
3741
3766
  });
@@ -4744,6 +4769,7 @@ function diagnoseProject(snapshot, options = {}) {
4744
4769
  },
4745
4770
  sceneShapeCheck(snapshot),
4746
4771
  ...capabilitySearchChecks(snapshot),
4772
+ ...snapshot.authoringLayer === void 0 ? [] : [authoringLayerCheck(snapshot.authoringLayer)],
4747
4773
  editorActivationCheck(snapshot),
4748
4774
  ...blender === void 0 ? [] : [blender]
4749
4775
  ];
@@ -4753,6 +4779,22 @@ function diagnoseProject(snapshot, options = {}) {
4753
4779
  });
4754
4780
  return { checks: scoped, pass: scoped.every(({ status }) => status !== "fail") };
4755
4781
  }
4782
+ var AUTHORING_LAYER_FIX = "After 'pnpm up --latest create-threenative', run 'pnpm exec threenative doctor --fix'; add --force to overwrite files this game edited.";
4783
+ function authoringLayerCheck(layer) {
4784
+ const name = "authoring layer";
4785
+ if (layer.problem !== void 0)
4786
+ return { detail: layer.problem, fix: AUTHORING_LAYER_FIX, name, status: "warn" };
4787
+ const where = `installed create-threenative ${layer.installed} (${layer.kit} kit)`;
4788
+ if (layer.stamped === layer.installed && layer.stale.length === 0)
4789
+ return { detail: `stamp matches ${where}`, name, status: "ok" };
4790
+ const count = `${layer.stale.length} stale file${layer.stale.length === 1 ? "" : "s"}`;
4791
+ return {
4792
+ detail: `stamp ${layer.stamped ?? "absent"}, ${where}: ${count}`,
4793
+ fix: AUTHORING_LAYER_FIX,
4794
+ name,
4795
+ status: "warn"
4796
+ };
4797
+ }
4756
4798
  async function collectFiles(root, relative = "", depth = 0) {
4757
4799
  if (depth > 3) return [];
4758
4800
  const absolute = path5.join(root, relative);
@@ -4808,6 +4850,13 @@ async function readProject(root) {
4808
4850
  const runtimeVersion = installedVersions.get(RUNTIME_PACKAGE);
4809
4851
  const runtimeManifestUrl = runtimeRoot === void 0 || runtimeVersion === void 0 ? void 0 : await runtimeReleaseManifestUrl(runtimeRoot, runtimeVersion);
4810
4852
  const playtestRunnerPath = resolveBinaryFrom(projectRoot, PLAYTEST_BINARY);
4853
+ const authoringLayer = await authoringLayerStatus(projectRoot).catch(
4854
+ (error) => ({
4855
+ installed: "unknown",
4856
+ problem: error instanceof Error ? error.message : String(error),
4857
+ stale: []
4858
+ })
4859
+ );
4811
4860
  const mcpServerHealth = /* @__PURE__ */ new Map();
4812
4861
  if (SHAPE_VERIFIABLE_HOSTS.some(({ file }) => files.has(file))) {
4813
4862
  for (const spec of MCP_SERVER_SPECS) {
@@ -4819,6 +4868,7 @@ async function readProject(root) {
4819
4868
  }
4820
4869
  }
4821
4870
  return {
4871
+ authoringLayer,
4822
4872
  config,
4823
4873
  files,
4824
4874
  installedVersions,
@@ -4876,7 +4926,7 @@ async function readTypeScriptConfig(root) {
4876
4926
  function formatDoctorReport(report) {
4877
4927
  const symbols = { fail: "\u2717", ok: "\u2713", warn: "!" };
4878
4928
  const isBaseline = (name) => ["package.json", "dependencies", "versions"].includes(name);
4879
- const isCraft = (name) => name.startsWith("capability search");
4929
+ const isCraft = (name) => name.startsWith("capability search") || name === "authoring layer";
4880
4930
  const isTest = (name) => name === "playtest" || name === "playtests";
4881
4931
  const groups = [
4882
4932
  ["Baseline", isBaseline],
@@ -4900,8 +4950,6 @@ function formatDoctorReport(report) {
4900
4950
  return `${lines.join("\n")}
4901
4951
  `;
4902
4952
  }
4903
-
4904
- // src/threenative.ts
4905
4953
  var DOCTOR_TARGETS = ["web", "desktop", "android", "ios"];
4906
4954
  var DOCTOR_MODES = ["debug", "release"];
4907
4955
  function cliHelp(command) {
@@ -4909,7 +4957,7 @@ function cliHelp(command) {
4909
4957
  if (command === "doctor") {
4910
4958
  return `${[
4911
4959
  "Usage: threenative doctor [--target web|desktop|android|ios] [--mode debug|release]",
4912
- " [--text] [--capture <path>]",
4960
+ " [--text] [--capture <path>] [--fix [--force]]",
4913
4961
  "",
4914
4962
  "Checks this project against what the build and the native host assume about it:",
4915
4963
  "installed and version-matched @threenative packages, a portable entry that",
@@ -4926,6 +4974,11 @@ function cliHelp(command) {
4926
4974
  " need once PRD-212 ships it, so a green report here is a forecast, not a release.",
4927
4975
  "Prints JSON by default; --text prints the same report for a person.",
4928
4976
  "--capture forwards a browser census JSON or native TN_PIPELINE_EVENT log to the playtest doctor.",
4977
+ "--fix rewrites this game's authoring layer (AGENTS.md, CLAUDE.md, skills, hooks, MCP configs)",
4978
+ " from the installed create-threenative, then checks again. To update an existing game:",
4979
+ " 'pnpm up --latest create-threenative @threenative/*', then 'pnpm exec threenative doctor --fix'.",
4980
+ " A file this game edited is kept and listed, and the run exits 1 (TN_AUTHORING_LAYER_EDITED);",
4981
+ " --force overwrites it. Git is the undo. .threenative/agent-files.json records what was written.",
4929
4982
  "Exits 0 when nothing failed, 1 when a check failed."
4930
4983
  ].join("\n")}
4931
4984
  `;
@@ -4950,6 +5003,8 @@ ${cliHelp()}`);
4950
5003
  }
4951
5004
  async function runDoctorCommand(argv, cwd = process.cwd()) {
4952
5005
  let capturePath;
5006
+ let fix = false;
5007
+ let force = false;
4953
5008
  let mode;
4954
5009
  let target;
4955
5010
  const valueFor = (flag, value) => {
@@ -4960,6 +5015,11 @@ async function runDoctorCommand(argv, cwd = process.cwd()) {
4960
5015
  for (let index = 0; index < argv.length; index += 1) {
4961
5016
  const flag = argv[index];
4962
5017
  if (flag === "--text") continue;
5018
+ if (flag === "--fix" || flag === "--force") {
5019
+ if (flag === "--fix") fix = true;
5020
+ else force = true;
5021
+ continue;
5022
+ }
4963
5023
  if (flag === "--capture") {
4964
5024
  capturePath = valueFor(flag, argv[index + 1]);
4965
5025
  index += 1;
@@ -4985,12 +5045,31 @@ async function runDoctorCommand(argv, cwd = process.cwd()) {
4985
5045
  }
4986
5046
  if (mode !== void 0 && target === void 0)
4987
5047
  throw new Error("doctor: '--mode' requires '--target'.");
5048
+ if (force && !fix) throw new Error("doctor: '--force' requires '--fix'.");
5049
+ let kept = 0;
5050
+ if (fix) {
5051
+ const result = await fixAuthoringLayer(cwd, { force });
5052
+ const lines = [
5053
+ ...result.written.map((file) => `wrote ${file}`),
5054
+ ...result.deleted.map((file) => `deleted ${file}`),
5055
+ ...result.kept.map((file) => `kept ${file}`)
5056
+ ];
5057
+ kept = result.kept.length;
5058
+ if (kept > 0)
5059
+ lines.push(
5060
+ `TN_AUTHORING_LAYER_EDITED: kept ${kept} file${kept === 1 ? "" : "s"} this game edited; rerun with --force to overwrite (git is the undo).`
5061
+ );
5062
+ process.stderr.write(
5063
+ lines.length === 0 ? "authoring layer already current\n" : `${lines.join("\n")}
5064
+ `
5065
+ );
5066
+ }
4988
5067
  const report = diagnoseProject(await readProject(cwd), { capturePath, mode, target });
4989
5068
  process.stdout.write(
4990
5069
  argv.includes("--text") ? formatDoctorReport(report) : `${JSON.stringify(report, null, 2)}
4991
5070
  `
4992
5071
  );
4993
- return report.pass ? 0 : 1;
5072
+ return report.pass && kept === 0 ? 0 : 1;
4994
5073
  }
4995
5074
  async function main(argv = process.argv.slice(2)) {
4996
5075
  if (argv.includes("--help") || argv.includes("-h")) {
@@ -0,0 +1,127 @@
1
+ import { Quaternion, Vector3 } from 'three';
2
+
3
+ // ../three-native/src/addons/ccd-ik-solver.ts
4
+ var modulo = (n, m) => (n % m + m) % m;
5
+ var CCDIKSolver = class {
6
+ constructor(mesh, iks = []) {
7
+ this.mesh = mesh;
8
+ this.iks = iks;
9
+ this.#initialQuaternions = iks.map((ik) => ik.links.map(() => new Quaternion()));
10
+ this.#valid();
11
+ }
12
+ mesh;
13
+ iks;
14
+ #quaternion = new Quaternion();
15
+ #targetPos = new Vector3();
16
+ #targetVec = new Vector3();
17
+ #effectorPos = new Vector3();
18
+ #effectorVec = new Vector3();
19
+ #linkPos = new Vector3();
20
+ #invLinkQ = new Quaternion();
21
+ #linkScale = new Vector3();
22
+ #axis = new Vector3();
23
+ #vector = new Vector3();
24
+ #center = new Vector3();
25
+ #workingQuaternion = new Quaternion();
26
+ #initialQuaternions;
27
+ update(globalBlendFactor = 1) {
28
+ for (const ik of this.iks) this.updateOne(ik, globalBlendFactor);
29
+ return this;
30
+ }
31
+ updateOne(ik, overrideBlend = 1) {
32
+ const chainBlend = ik.blendFactor ?? overrideBlend;
33
+ const bones = this.mesh.skeleton.bones;
34
+ const initialQuaternions = this.#initialQuaternions[this.iks.indexOf(ik)] ?? [];
35
+ const effector = bones[ik.effector];
36
+ const target = bones[ik.target];
37
+ this.#targetPos.setFromMatrixPosition(target.matrixWorld);
38
+ const links = ik.links;
39
+ if (chainBlend < 1)
40
+ for (const [j, link] of links.entries())
41
+ initialQuaternions[j]?.copy(bones[link.index].quaternion);
42
+ for (let i = 0; i < (ik.iteration ?? 1); i++) if (!this.#iterate(ik, bones, effector)) break;
43
+ if (chainBlend < 1) this.#blend(links, bones, initialQuaternions, chainBlend);
44
+ return this;
45
+ }
46
+ createHelper() {
47
+ throw new Error(
48
+ "TN_NATIVE_UNSUPPORTED_CCDIKHELPER: CCDIKSolver.createHelper needs three's CCDIKHelper, which the engine does not bind; draw the chain from skeleton.bones instead."
49
+ );
50
+ }
51
+ // One pass over the chain; false when no link turned, which ends the solve.
52
+ #iterate(ik, bones, effector) {
53
+ let rotated = false;
54
+ for (const entry of ik.links) {
55
+ if (entry.enabled === false) break;
56
+ if (this.#rotateLink(ik, entry, bones[entry.index], effector)) rotated = true;
57
+ }
58
+ return rotated;
59
+ }
60
+ // A chain blend under 1 slerps each link from its pose before the solve toward the solved pose.
61
+ #blend(links, bones, initial, chainBlend) {
62
+ for (const [j, entry] of links.entries()) {
63
+ const link = bones[entry.index];
64
+ this.#workingQuaternion.copy(initial[j]).slerp(link.quaternion, chainBlend);
65
+ link.quaternion.copy(this.#workingQuaternion);
66
+ link.updateMatrixWorld(true);
67
+ }
68
+ }
69
+ // One CCD step on one link: rotate it so the effector points at the target. False when the angle
70
+ // is too small to turn, which three skips to prevent bone vibration.
71
+ #rotateLink(ik, entry, link, effector) {
72
+ link.matrixWorld.decompose(this.#linkPos, this.#invLinkQ, this.#linkScale);
73
+ this.#invLinkQ.invert();
74
+ this.#effectorPos.setFromMatrixPosition(effector.matrixWorld);
75
+ this.#effectorVec.subVectors(this.#effectorPos, this.#linkPos).applyQuaternion(this.#invLinkQ).normalize();
76
+ this.#targetVec.subVectors(this.#targetPos, this.#linkPos).applyQuaternion(this.#invLinkQ).normalize();
77
+ let angle = Math.acos(Math.min(1, Math.max(-1, this.#targetVec.dot(this.#effectorVec))));
78
+ if (angle < 1e-5) return false;
79
+ if (ik.minAngle !== void 0 && angle < ik.minAngle) angle = ik.minAngle;
80
+ if (ik.maxAngle !== void 0 && angle > ik.maxAngle) angle = ik.maxAngle;
81
+ this.#axis.crossVectors(this.#effectorVec, this.#targetVec).normalize();
82
+ this.#quaternion.setFromAxisAngle(this.#axis, angle);
83
+ link.quaternion.multiply(this.#quaternion);
84
+ this.#limit(entry, link);
85
+ link.updateMatrixWorld(true);
86
+ return true;
87
+ }
88
+ // three's link limits: a hinge axis, then Euler angle bounds.
89
+ #limit(entry, link) {
90
+ const { limitation, rotationMin, rotationMax } = entry;
91
+ if (limitation !== void 0) {
92
+ const q = link.quaternion;
93
+ const c = Math.min(q.w, 1);
94
+ const dot = q.x * limitation.x + q.y * limitation.y + q.z * limitation.z;
95
+ const c2 = (dot < 0 ? -1 : 1) * Math.sqrt(1 - c * c);
96
+ q.set(limitation.x * c2, limitation.y * c2, limitation.z * c2, c);
97
+ }
98
+ if (rotationMin !== void 0 || rotationMax !== void 0) {
99
+ const v = this.#vector.setFromEuler(link.rotation);
100
+ if (rotationMin !== void 0 && rotationMax !== void 0) {
101
+ const c = this.#center.addVectors(rotationMin, rotationMax).multiplyScalar(0.5);
102
+ v.x = c.x + modulo(v.x - c.x + Math.PI, 2 * Math.PI) - Math.PI;
103
+ v.y = c.y + modulo(v.y - c.y + Math.PI, 2 * Math.PI) - Math.PI;
104
+ v.z = c.z + modulo(v.z - c.z + Math.PI, 2 * Math.PI) - Math.PI;
105
+ }
106
+ if (rotationMin !== void 0) v.max(rotationMin);
107
+ if (rotationMax !== void 0) v.min(rotationMax);
108
+ link.rotation.setFromVector3(v);
109
+ }
110
+ }
111
+ #valid() {
112
+ const bones = this.mesh.skeleton.bones;
113
+ for (const ik of this.iks) {
114
+ let child = bones[ik.effector];
115
+ for (const entry of ik.links) {
116
+ const parent = bones[entry.index];
117
+ if (child.parent !== parent)
118
+ console.warn(
119
+ `THREE.CCDIKSolver: bone ${child.name} is not the child of bone ${parent.name}`
120
+ );
121
+ child = parent;
122
+ }
123
+ }
124
+ }
125
+ };
126
+
127
+ export { CCDIKSolver };
@@ -33,7 +33,27 @@ function refuse(what) {
33
33
  }
34
34
  var HOSTED_PLUGIN = "TN_discrete_lod";
35
35
  var ELEMENTS = { 5121: Uint8Array, 5123: Uint16Array, 5125: Uint32Array };
36
- function readIndices(json, bin, index) {
36
+ async function viewBytes(view, bin, decoder, index) {
37
+ const meshopt = view.extensions?.EXT_meshopt_compression ?? view.extensions?.KHR_meshopt_compression;
38
+ if (meshopt === void 0) return bin.subarray(view.byteOffset ?? 0);
39
+ const { byteLength = 0, byteOffset = 0, byteStride = 0, count = 0, mode = "" } = meshopt;
40
+ if (decoder === void 0 || (meshopt.buffer ?? 0) !== 0 || byteOffset + byteLength > bin.byteLength)
41
+ throw new Error(
42
+ `TN_WASM_GLTF_LOD_ACCESSOR: accessor ${String(index)} is meshopt-compressed ${decoder === void 0 ? "and no meshopt decoder was set" : "outside the binary chunk"}`
43
+ );
44
+ await decoder.ready;
45
+ const decoded = new Uint8Array(count * byteStride);
46
+ decoder.decodeGltfBuffer(
47
+ decoded,
48
+ count,
49
+ byteStride,
50
+ bin.subarray(byteOffset, byteOffset + byteLength),
51
+ mode,
52
+ meshopt.filter
53
+ );
54
+ return decoded;
55
+ }
56
+ async function readIndices(json, bin, index, decoder) {
37
57
  const accessor = json.accessors?.[index];
38
58
  const view = json.bufferViews?.[accessor?.bufferView ?? -1];
39
59
  const Element = ELEMENTS[accessor?.componentType];
@@ -43,13 +63,14 @@ function readIndices(json, bin, index) {
43
63
  );
44
64
  if (bin === void 0)
45
65
  throw new Error("TN_WASM_GLTF_LOD_ACCESSOR: only a GLB's binary chunk is read for a LOD chain");
46
- const start = (view.byteOffset ?? 0) + (accessor.byteOffset ?? 0);
66
+ const bytes = await viewBytes(view, bin, decoder, index);
67
+ const start = accessor.byteOffset ?? 0;
47
68
  const end = start + accessor.count * Element.BYTES_PER_ELEMENT;
48
- if (!Number.isInteger(start) || end > bin.byteLength)
69
+ if (!Number.isInteger(start) || end > bytes.byteLength)
49
70
  throw new Error(
50
71
  `TN_WASM_GLTF_LOD_ACCESSOR: accessor ${String(index)} reads past the binary chunk`
51
72
  );
52
- return { array: new Element(bin.slice(start, end).buffer) };
73
+ return { array: new Element(bytes.slice(start, end).buffer) };
53
74
  }
54
75
  function associate(json, scene, into) {
55
76
  const expected = [];
@@ -75,13 +96,13 @@ function associate(json, scene, into) {
75
96
  );
76
97
  for (const [i, mesh] of meshes.entries()) into.set(mesh, expected[i]);
77
98
  }
78
- function hostPlugins(factories, data) {
99
+ function hostPlugins(factories, data, decoder) {
79
100
  if (factories.length === 0) return void 0;
80
101
  const { bin, json } = readGltf(data);
81
102
  const parser = {
82
103
  associations: /* @__PURE__ */ new Map(),
83
104
  getDependency: async (type, index) => {
84
- if (type === "accessor") return readIndices(json, bin, index);
105
+ if (type === "accessor") return readIndices(json, bin, index, decoder);
85
106
  throw new Error(
86
107
  `TN_WASM_GLTF_DEPENDENCY_UNSUPPORTED: the engine glTF loader returns no '${type}'`
87
108
  );
@@ -112,9 +133,15 @@ function imageBytes(url) {
112
133
  }
113
134
  var GLTFLoader = class {
114
135
  path = "";
136
+ /**
137
+ * Serves one image file's bytes in place of a plain fetch: core hands the resident levels of a
138
+ * KTX2 here (PRD-860). `undefined` from it means "fetch it as usual".
139
+ */
140
+ imageSource = void 0;
115
141
  /** A plugin defect (a chain the file declares and cannot deliver) rejects the load; core's plugin logs it on stock three. */
116
142
  failClosed = true;
117
143
  #factories = [];
144
+ #meshopt;
118
145
  setPath(path) {
119
146
  this.path = path;
120
147
  return this;
@@ -128,11 +155,17 @@ var GLTFLoader = class {
128
155
  setRequestHeader() {
129
156
  return this;
130
157
  }
131
- setKTX2Loader() {
132
- return refuse("KTX2");
158
+ /** The engine's loader transcodes KHR_texture_basisu itself (PRD-861), so the JS loader goes unused. */
159
+ setKTX2Loader(_loader) {
160
+ return this;
133
161
  }
134
- setMeshoptDecoder() {
135
- return refuse("MESHOPT");
162
+ /**
163
+ * The engine's loader decodes EXT/KHR_meshopt_compression itself (PRD-861); the JS decoder reads
164
+ * only a hosted LOD chain's compressed index views.
165
+ */
166
+ setMeshoptDecoder(decoder) {
167
+ this.#meshopt = decoder;
168
+ return this;
136
169
  }
137
170
  setDRACOLoader() {
138
171
  return refuse("DRACO");
@@ -150,11 +183,11 @@ var GLTFLoader = class {
150
183
  if (load === void 0)
151
184
  throw new Error("TN_WASM_GLTF_UNAVAILABLE: this web engine has no glTF loader");
152
185
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : new Uint8Array(data);
153
- const hosted = hostPlugins(this.#factories, data);
154
- const model = load(bytes, files);
186
+ const hosted = hostPlugins(this.#factories, data, this.#meshopt);
187
+ const model = await load(bytes, files);
155
188
  result = {
156
189
  scene: model.scene,
157
- scenes: [model.scene],
190
+ scenes: [...model.scenes],
158
191
  animations: [...model.animations],
159
192
  cameras: [],
160
193
  asset: { version: "2.0" },
@@ -179,7 +212,12 @@ var GLTFLoader = class {
179
212
  }
180
213
  Promise.all(
181
214
  // The engine loader asks for the uri with its percent escapes decoded.
182
- uris.map(async (uri) => [decodeURIComponent(uri), await imageBytes(path + uri)])
215
+ uris.map(
216
+ async (uri) => [
217
+ decodeURIComponent(uri),
218
+ await this.imageSource?.(path + uri) ?? await imageBytes(path + uri)
219
+ ]
220
+ )
183
221
  ).then(
184
222
  (files) => settle(new Map(files)),
185
223
  (error) => {
@@ -535,6 +535,7 @@ function defineScreenSpaceGi(tsl) {
535
535
  const probeJitter = uniform(1);
536
536
  const probeDebug = uniform(0);
537
537
  const occlusion = (gather) => {
538
+ if (options.fallback !== void 0) return vec4(1, 1, 1, 1);
538
539
  const ao2 = pow(clamp(float(1).sub(gather.a), float(0), float(1)), aoIntensity);
539
540
  return vec4(ao2, ao2, ao2, 1);
540
541
  };
@@ -586,7 +587,6 @@ function defineScreenSpaceGi(tsl) {
586
587
  If(centreDepth.lessThan(1).and(centreNormal.dot(centreNormal).greaterThan(0.25)), () => {
587
588
  const position = viewPosition(coordinate, centreDepth);
588
589
  const normal = normalize(centreNormal);
589
- const fallback = options.fallback?.(position, normal) ?? vec3(0, 0, 0);
590
590
  const helper = normal.y.abs().lessThan(0.99).select(vec3(0, 1, 0), vec3(1, 0, 0));
591
591
  const tangent = normalize(helper.cross(normal));
592
592
  const bitangent = normal.cross(tangent);
@@ -613,6 +613,7 @@ function defineScreenSpaceGi(tsl) {
613
613
  const trace = march(origin, direction, position.z);
614
614
  If(trace.hitDistance.greaterThanEqual(0), () => {
615
615
  const hit = shade(trace.hitCoordinate, trace.hitDistance, direction);
616
+ const fallback = options.fallback?.(position, direction, normal) ?? vec3(0, 0, 0);
616
617
  gathered.assign(gathered.add(hit.radiance.sub(fallback).mul(hit.weight)));
617
618
  hits.assign(hits.add(hit.weight));
618
619
  });
@@ -712,7 +713,8 @@ function defineScreenProbes(tsl, input) {
712
713
  const trace = march(origin, direction, position.z);
713
714
  If(trace.hitDistance.greaterThanEqual(0), () => {
714
715
  const hit = shade(trace.hitCoordinate, trace.hitDistance, direction);
715
- result.assign(vec4(hit.radiance.mul(hit.weight), hit.weight));
716
+ const believed = options.fallback?.(position, direction, normal) ?? vec3(0, 0, 0);
717
+ result.assign(vec4(hit.radiance.sub(believed).mul(hit.weight), hit.weight));
716
718
  });
717
719
  });
718
720
  return result;
@@ -739,15 +741,8 @@ function defineScreenProbes(tsl, input) {
739
741
  sum.assign(sum.add(found.mul(weight)));
740
742
  weights.assign(weights.add(weight));
741
743
  });
742
- const probeUv = tile.add(0.5).div(tiles).min(vec2(1, 1));
743
- const depth = depthNode.sample(probeUv).r;
744
- const rawNormal = normalNode.sample(probeUv).xyz;
745
- const believed = valid(depth, rawNormal).select(
746
- options.fallback?.(viewPosition(probeUv, depth), normal) ?? vec3(0, 0, 0),
747
- vec3(0, 0, 0)
748
- );
749
744
  const total = max(weights, float(1e-4));
750
- return vec4(sum.rgb.sub(believed.mul(sum.a)).div(total), sum.a.div(total));
745
+ return vec4(sum.rgb.div(total), sum.a.div(total));
751
746
  })();
752
747
  const filtered = rtt(filterGraph, tilesX * IRRADIANCE_SIDE, tilesY * IRRADIANCE_SIDE, {
753
748
  type: HALF_FLOAT_TYPE,