threedog 0.0.0-stage → 0.2.0

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 (506) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -2
  4. package/core/Animator.js +268 -0
  5. package/core/Assets.js +256 -0
  6. package/core/Audio.js +267 -0
  7. package/core/Baked.js +72 -0
  8. package/core/Batching.js +247 -0
  9. package/core/Budget.js +221 -0
  10. package/core/Clock.js +94 -0
  11. package/core/Commits.js +77 -0
  12. package/core/DebugOverrides.js +143 -0
  13. package/core/Describe.js +145 -0
  14. package/core/Engine.js +184 -0
  15. package/core/Events.js +153 -0
  16. package/core/I18n.js +94 -0
  17. package/core/Input.js +245 -0
  18. package/core/Inspect.js +77 -0
  19. package/core/InspectScene.js +191 -0
  20. package/core/Jobs.js +146 -0
  21. package/core/Loading.js +149 -0
  22. package/core/MaterialInfo.js +32 -0
  23. package/core/Ops.js +256 -0
  24. package/core/Random.js +52 -0
  25. package/core/Rays.js +160 -0
  26. package/core/SaveStore.js +85 -0
  27. package/core/Saves.js +254 -0
  28. package/core/Stream.js +279 -0
  29. package/core/Threads.js +158 -0
  30. package/core/UrlState.js +94 -0
  31. package/core/Vars.js +35 -0
  32. package/core/Views.js +49 -0
  33. package/core/actor.js +23 -0
  34. package/core/assetEntry.js +89 -0
  35. package/core/assetLoad.js +190 -0
  36. package/core/assetManifest.js +35 -0
  37. package/core/assetReport.js +83 -0
  38. package/core/audioRules.js +121 -0
  39. package/core/audioVoice.js +225 -0
  40. package/core/batchGroups.js +116 -0
  41. package/core/canvasBox.js +63 -0
  42. package/core/catalog.js +169 -0
  43. package/core/checks.js +67 -0
  44. package/core/claims.js +51 -0
  45. package/core/dayTime.js +15 -0
  46. package/core/debugView.js +76 -0
  47. package/core/describeRender.js +45 -0
  48. package/core/describeText.js +143 -0
  49. package/core/easing.js +34 -0
  50. package/core/errorCodes.js +205 -0
  51. package/core/errorHints.js +208 -0
  52. package/core/errors.js +40 -0
  53. package/core/events.generated.js +84 -0
  54. package/core/ground.js +102 -0
  55. package/core/holds.js +106 -0
  56. package/core/inputContext.js +69 -0
  57. package/core/inputDefaults.js +22 -0
  58. package/core/inputPad.js +35 -0
  59. package/core/inputPointer.js +48 -0
  60. package/core/inputTouch.js +48 -0
  61. package/core/lifecycle.js +69 -0
  62. package/core/lightWatch.js +56 -0
  63. package/core/look/coreParts.js +112 -0
  64. package/core/look/layers.js +136 -0
  65. package/core/look/part.js +173 -0
  66. package/core/look/report.js +79 -0
  67. package/core/look/write.js +86 -0
  68. package/core/loop.js +200 -0
  69. package/core/math.js +33 -0
  70. package/core/modules.js +196 -0
  71. package/core/movement.js +19 -0
  72. package/core/mulberry32.js +14 -0
  73. package/core/opsAtomic.js +31 -0
  74. package/core/opsCheck.js +97 -0
  75. package/core/opsFail.js +20 -0
  76. package/core/opsGuard.js +26 -0
  77. package/core/opsHistory.js +27 -0
  78. package/core/opsRun.js +77 -0
  79. package/core/page.js +78 -0
  80. package/core/params.js +132 -0
  81. package/core/pureWorker.js +5 -0
  82. package/core/renamed.js +21 -0
  83. package/core/saveApply.js +128 -0
  84. package/core/saveFiles.js +139 -0
  85. package/core/saveIds.js +53 -0
  86. package/core/saveVersions.js +97 -0
  87. package/core/scatter.js +92 -0
  88. package/core/sceneMethods.js +100 -0
  89. package/core/screenToGround.js +39 -0
  90. package/core/services.js +73 -0
  91. package/core/session.js +171 -0
  92. package/core/shadowTypes.js +15 -0
  93. package/core/skip.js +104 -0
  94. package/core/startup.js +135 -0
  95. package/core/streamCells.js +24 -0
  96. package/core/streamSources.js +73 -0
  97. package/core/styleParts.js +96 -0
  98. package/core/targeting.js +64 -0
  99. package/core/thingExplain.js +68 -0
  100. package/core/thingOps.js +168 -0
  101. package/core/things.js +212 -0
  102. package/core/threadPure.js +120 -0
  103. package/core/threadServe.js +25 -0
  104. package/core/tier.js +11 -0
  105. package/core/util.js +11 -0
  106. package/core/validate.js +204 -0
  107. package/docs/AI.md +123 -0
  108. package/docs/API.md +83 -0
  109. package/docs/CODEMAP.md +347 -0
  110. package/docs/COMMANDS.md +108 -0
  111. package/docs/CONVENTIONS.md +145 -0
  112. package/docs/PERF.md +217 -0
  113. package/docs/THREE.md +86 -0
  114. package/docs/api/ambience.md +15 -0
  115. package/docs/api/assets.md +62 -0
  116. package/docs/api/audio.md +53 -0
  117. package/docs/api/budget.md +40 -0
  118. package/docs/api/cameraRig.md +120 -0
  119. package/docs/api/characters.md +144 -0
  120. package/docs/api/clock.md +7 -0
  121. package/docs/api/collision.md +39 -0
  122. package/docs/api/content.md +64 -0
  123. package/docs/api/dialogue.md +39 -0
  124. package/docs/api/engine.md +199 -0
  125. package/docs/api/entities.md +61 -0
  126. package/docs/api/events.md +95 -0
  127. package/docs/api/flow.md +27 -0
  128. package/docs/api/grids.md +11 -0
  129. package/docs/api/ground.md +16 -0
  130. package/docs/api/hlod.md +34 -0
  131. package/docs/api/hud.md +31 -0
  132. package/docs/api/i18n.md +10 -0
  133. package/docs/api/input.md +24 -0
  134. package/docs/api/interactions.md +31 -0
  135. package/docs/api/inventory.md +66 -0
  136. package/docs/api/jobs.md +10 -0
  137. package/docs/api/level.md +41 -0
  138. package/docs/api/lightPool.md +56 -0
  139. package/docs/api/music.md +34 -0
  140. package/docs/api/nav.md +26 -0
  141. package/docs/api/net.md +14 -0
  142. package/docs/api/openWorld.md +24 -0
  143. package/docs/api/particles.md +41 -0
  144. package/docs/api/photo.md +15 -0
  145. package/docs/api/post.md +10 -0
  146. package/docs/api/quests.md +36 -0
  147. package/docs/api/rays.md +26 -0
  148. package/docs/api/rigid.md +84 -0
  149. package/docs/api/saves.md +32 -0
  150. package/docs/api/settings.md +36 -0
  151. package/docs/api/sky.md +58 -0
  152. package/docs/api/stream.md +31 -0
  153. package/docs/api/style.md +134 -0
  154. package/docs/api/terrain.md +34 -0
  155. package/docs/api/timeline.md +39 -0
  156. package/docs/api/tools.md +57 -0
  157. package/docs/api/triggers.md +56 -0
  158. package/docs/api/vars.md +9 -0
  159. package/docs/api/vegetation.md +52 -0
  160. package/docs/api/water.md +48 -0
  161. package/docs/api/weather.md +29 -0
  162. package/docs/api/world.md +30 -0
  163. package/docs/recipes/01-new-game.md +148 -0
  164. package/docs/recipes/02-npc.md +167 -0
  165. package/docs/recipes/03-items-pickups.md +158 -0
  166. package/docs/recipes/04-quests.md +83 -0
  167. package/docs/recipes/05-props-bake.md +159 -0
  168. package/docs/recipes/06-clock-events.md +117 -0
  169. package/docs/recipes/07-flow-scenes-pause.md +132 -0
  170. package/docs/recipes/08-weather-sky.md +74 -0
  171. package/docs/recipes/09-style-pack.md +234 -0
  172. package/docs/recipes/10-blender-level.md +67 -0
  173. package/docs/recipes/11-vehicles.md +55 -0
  174. package/docs/recipes/12-navmesh.md +79 -0
  175. package/docs/recipes/13-animation.md +149 -0
  176. package/docs/recipes/14-custom-module.md +91 -0
  177. package/docs/recipes/15-perf.md +78 -0
  178. package/docs/recipes/16-dev-bridge.md +180 -0
  179. package/docs/recipes/18-world.md +185 -0
  180. package/docs/recipes/19-shooting-picking.md +76 -0
  181. package/docs/recipes/20-content-actions-save.md +176 -0
  182. package/docs/recipes/21-camera.md +153 -0
  183. package/docs/recipes/22-shop-gold.md +107 -0
  184. package/docs/recipes/23-ops.md +175 -0
  185. package/docs/recipes/26-ui-parts.md +138 -0
  186. package/docs/recipes/27-net.md +96 -0
  187. package/docs/recipes/28-terrain.md +80 -0
  188. package/docs/recipes/29-grid.md +87 -0
  189. package/docs/recipes/30-templates.md +131 -0
  190. package/docs/recipes/31-audio.md +126 -0
  191. package/docs/recipes/32-action-game.md +33 -0
  192. package/docs/recipes/33-stream-sources.md +37 -0
  193. package/docs/recipes/34-environment-lighting.md +36 -0
  194. package/docs/recipes/35-style-from-reference.md +89 -0
  195. package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
  196. package/docs/recipes/37-terrain-look-hooks.md +97 -0
  197. package/docs/recipes/38-environment-look-hooks.md +83 -0
  198. package/docs/recipes/40-scene.md +108 -0
  199. package/docs/recipes/41-thing-registry.md +93 -0
  200. package/docs/recipes/42-terrain-shape.md +64 -0
  201. package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
  202. package/docs/recipes/44-water-weather-look-hooks.md +135 -0
  203. package/docs/recipes/45-cascaded-shadows.md +51 -0
  204. package/docs/recipes/46-blender-art-route.md +114 -0
  205. package/docs/recipes/47-island-snow-backdrop.md +44 -0
  206. package/docs/recipes/48-make-material.md +70 -0
  207. package/docs/recipes/49-game-module-contract.md +71 -0
  208. package/docs/recipes/50-own-renderer.md +12 -0
  209. package/docs/recipes/51-capability-catalog.md +63 -0
  210. package/docs/recipes/52-look.md +108 -0
  211. package/examples/action/DESIGN.md +3 -0
  212. package/examples/action/GAMEMAP.md +127 -0
  213. package/examples/action/content/actions.js +8 -0
  214. package/examples/action/content/audio.js +9 -0
  215. package/examples/action/content/index.js +10 -0
  216. package/examples/action/content/items.js +4 -0
  217. package/examples/action/content/places.js +4 -0
  218. package/examples/action/content/props.js +11 -0
  219. package/examples/action/content/templates.js +10 -0
  220. package/examples/action/content/views.js +6 -0
  221. package/examples/action/look.js +5 -0
  222. package/examples/action/main.js +137 -0
  223. package/examples/action/models.js +25 -0
  224. package/examples/sheepisland/GAMEMAP.md +107 -0
  225. package/examples/sheepisland/content/index.js +6 -0
  226. package/examples/sheepisland/content/props.js +19 -0
  227. package/examples/sheepisland/content/templates.js +5 -0
  228. package/examples/sheepisland/content/vegetation.js +8 -0
  229. package/examples/sheepisland/main.js +71 -0
  230. package/examples/sheepisland/params.js +25 -0
  231. package/examples/sheepisland/style/index.js +79 -0
  232. package/examples/sheepisland/style/models.js +59 -0
  233. package/examples/sheepisland/views.js +9 -0
  234. package/examples/styletest/GAMEMAP.md +135 -0
  235. package/examples/styletest/content/index.js +9 -0
  236. package/examples/styletest/content/items.js +8 -0
  237. package/examples/styletest/content/npcs.js +8 -0
  238. package/examples/styletest/content/places.js +5 -0
  239. package/examples/styletest/content/props.js +16 -0
  240. package/examples/styletest/content/templates.js +9 -0
  241. package/examples/styletest/content/vegetation.js +31 -0
  242. package/examples/styletest/look.js +11 -0
  243. package/examples/styletest/main.js +95 -0
  244. package/examples/styletest/models.js +87 -0
  245. package/examples/styletest/overrides.js +33 -0
  246. package/examples/styletest/panel.js +135 -0
  247. package/examples/styletest/params.js +32 -0
  248. package/examples/styletest/views.js +31 -0
  249. package/examples/world/DESIGN.md +5 -0
  250. package/examples/world/GAMEMAP.md +171 -0
  251. package/examples/world/content/actions.js +8 -0
  252. package/examples/world/content/audio.js +25 -0
  253. package/examples/world/content/bodies.js +12 -0
  254. package/examples/world/content/containers.js +4 -0
  255. package/examples/world/content/dialogues.js +33 -0
  256. package/examples/world/content/index.js +17 -0
  257. package/examples/world/content/items.js +10 -0
  258. package/examples/world/content/npcs.js +14 -0
  259. package/examples/world/content/pickups.js +11 -0
  260. package/examples/world/content/places.js +6 -0
  261. package/examples/world/content/props.js +12 -0
  262. package/examples/world/content/quests.js +15 -0
  263. package/examples/world/content/rules.js +23 -0
  264. package/examples/world/content/templates.js +5 -0
  265. package/examples/world/content/vegetation.js +32 -0
  266. package/examples/world/main.js +168 -0
  267. package/examples/world/models.js +28 -0
  268. package/index.d.ts +306 -0
  269. package/index.js +122 -0
  270. package/llms.txt +61 -0
  271. package/modules/ambience/Ambience.js +186 -0
  272. package/modules/camera/FirstPersonCamera.js +131 -0
  273. package/modules/camera/FixedCamera.js +162 -0
  274. package/modules/camera/FollowCamera.js +91 -0
  275. package/modules/camera/RtsCamera.js +132 -0
  276. package/modules/camera/common.js +182 -0
  277. package/modules/camera/index.js +11 -0
  278. package/modules/camera/projection.js +34 -0
  279. package/modules/characters/Character.js +235 -0
  280. package/modules/characters/NPC.js +242 -0
  281. package/modules/characters/assetModel.js +42 -0
  282. package/modules/characters/astar.js +66 -0
  283. package/modules/characters/behaviors.js +72 -0
  284. package/modules/characters/footsteps.js +13 -0
  285. package/modules/characters/index.js +215 -0
  286. package/modules/characters/moveHelpers.js +29 -0
  287. package/modules/characters/movers/common.js +62 -0
  288. package/modules/characters/movers/rapier.js +74 -0
  289. package/modules/characters/movers/simple.js +43 -0
  290. package/modules/characters/npcAvoid.js +129 -0
  291. package/modules/characters/npcSim.js +150 -0
  292. package/modules/characters/npcView.js +42 -0
  293. package/modules/characters/pathAsync.js +113 -0
  294. package/modules/characters/pathJob.js +62 -0
  295. package/modules/characters/pathWorker.js +7 -0
  296. package/modules/characters/playerStrings.js +12 -0
  297. package/modules/characters/proceduralRig.js +58 -0
  298. package/modules/characters/useModel.js +22 -0
  299. package/modules/characters/walkTo.js +58 -0
  300. package/modules/collision/Collision.js +274 -0
  301. package/modules/collision/grid.js +63 -0
  302. package/modules/content/explain.js +13 -0
  303. package/modules/content/ids.js +95 -0
  304. package/modules/content/index.js +154 -0
  305. package/modules/content/loader.js +190 -0
  306. package/modules/content/models.js +69 -0
  307. package/modules/content/packs.js +69 -0
  308. package/modules/content/props.js +89 -0
  309. package/modules/content/rules.js +134 -0
  310. package/modules/content/templates.js +189 -0
  311. package/modules/debug/DebugPanel.js +174 -0
  312. package/modules/entities/Entities.js +243 -0
  313. package/modules/entities/build.js +25 -0
  314. package/modules/entities/index.js +4 -0
  315. package/modules/flow/index.js +101 -0
  316. package/modules/gameplay/Container.js +227 -0
  317. package/modules/gameplay/Containers.js +89 -0
  318. package/modules/gameplay/Dialogue.js +219 -0
  319. package/modules/gameplay/Interactions.js +253 -0
  320. package/modules/gameplay/Inventory.js +224 -0
  321. package/modules/gameplay/Quests.js +205 -0
  322. package/modules/gameplay/boxOps.js +60 -0
  323. package/modules/gameplay/dialogueBox.js +48 -0
  324. package/modules/gameplay/interactionPrompt.js +28 -0
  325. package/modules/gameplay/inventoryOps.js +137 -0
  326. package/modules/gameplay/pickups.js +115 -0
  327. package/modules/gameplay/questLog.js +54 -0
  328. package/modules/gameplay/questSave.js +71 -0
  329. package/modules/grid/Grid.js +184 -0
  330. package/modules/grid/Layer.js +142 -0
  331. package/modules/grid/index.js +236 -0
  332. package/modules/grid/ops.js +73 -0
  333. package/modules/grid/preview.js +85 -0
  334. package/modules/grid/tiles.js +79 -0
  335. package/modules/hlod/index.js +167 -0
  336. package/modules/hud/index.js +167 -0
  337. package/modules/hud/parts.js +80 -0
  338. package/modules/level/geometry.js +46 -0
  339. package/modules/level/heightfield.js +160 -0
  340. package/modules/level/index.js +233 -0
  341. package/modules/level/nodes.js +84 -0
  342. package/modules/lights/index.js +227 -0
  343. package/modules/music/Music.js +294 -0
  344. package/modules/music/index.js +2 -0
  345. package/modules/music/rules.js +28 -0
  346. package/modules/nav/index.js +156 -0
  347. package/modules/nav/navPath.js +17 -0
  348. package/modules/net/Client.js +137 -0
  349. package/modules/net/Host.js +117 -0
  350. package/modules/net/Net.js +49 -0
  351. package/modules/net/index.js +77 -0
  352. package/modules/net/sync.js +114 -0
  353. package/modules/net/transports.js +118 -0
  354. package/modules/particles/Particles.js +179 -0
  355. package/modules/particles/effect.js +112 -0
  356. package/modules/particles/shaders.js +28 -0
  357. package/modules/photo/Photo.js +146 -0
  358. package/modules/rigid/RigidBodies.js +265 -0
  359. package/modules/rigid/Vehicles.js +97 -0
  360. package/modules/rigid/sync.js +158 -0
  361. package/modules/settings/Settings.js +297 -0
  362. package/modules/settings/apply.js +21 -0
  363. package/modules/settings/index.js +3 -0
  364. package/modules/settings/sections.js +156 -0
  365. package/modules/settings/strings.js +53 -0
  366. package/modules/settings/view.js +65 -0
  367. package/modules/sky/Sky.js +259 -0
  368. package/modules/sky/calendar.js +80 -0
  369. package/modules/sky/cascades.js +125 -0
  370. package/modules/sky/clouds.js +79 -0
  371. package/modules/sky/domeLayers.js +33 -0
  372. package/modules/sky/environment.js +141 -0
  373. package/modules/sky/fog.js +139 -0
  374. package/modules/sky/frame.js +77 -0
  375. package/modules/sky/layers.js +69 -0
  376. package/modules/sky/look.js +51 -0
  377. package/modules/sky/lookFog.js +80 -0
  378. package/modules/sky/lookShadow.js +50 -0
  379. package/modules/sky/lookSky.js +108 -0
  380. package/modules/sky/schedule.js +80 -0
  381. package/modules/sky/shader.js +96 -0
  382. package/modules/sky/shadow.js +74 -0
  383. package/modules/sky/skyModule.js +60 -0
  384. package/modules/terrain/ChunkManager.js +260 -0
  385. package/modules/terrain/chunkJob.js +19 -0
  386. package/modules/terrain/chunkLevels.js +40 -0
  387. package/modules/terrain/chunkQueries.js +42 -0
  388. package/modules/terrain/chunkWorker.js +5 -0
  389. package/modules/terrain/index.js +118 -0
  390. package/modules/terrain/lookGround.js +61 -0
  391. package/modules/terrain/mountTerrain.js +32 -0
  392. package/modules/terrain/terrainColorMap.js +41 -0
  393. package/modules/terrain/terrainDefaults.js +39 -0
  394. package/modules/terrain/terrainEdit.js +139 -0
  395. package/modules/terrain/terrainGen.js +155 -0
  396. package/modules/terrain/terrainIsland.js +131 -0
  397. package/modules/terrain/terrainMesh.js +92 -0
  398. package/modules/terrain/terrainShape.js +108 -0
  399. package/modules/terrain/terrainShapeMain.js +41 -0
  400. package/modules/terrain/terrainTexture.js +44 -0
  401. package/modules/timeline/Timeline.js +253 -0
  402. package/modules/timeline/Tween.js +114 -0
  403. package/modules/timeline/letterbox.js +24 -0
  404. package/modules/timeline/shots.js +90 -0
  405. package/modules/triggers/index.js +268 -0
  406. package/modules/vegetation/Vegetation.js +256 -0
  407. package/modules/vegetation/groundChunks.js +177 -0
  408. package/modules/vegetation/index.js +43 -0
  409. package/modules/vegetation/lookWind.js +37 -0
  410. package/modules/vegetation/modelGeometry.js +21 -0
  411. package/modules/water/Water.js +160 -0
  412. package/modules/water/look.js +80 -0
  413. package/modules/water/surface.js +88 -0
  414. package/modules/weather/Weather.js +242 -0
  415. package/modules/weather/look.js +75 -0
  416. package/modules/weather/particles.js +92 -0
  417. package/modules/weather/shaders.js +49 -0
  418. package/modules/weather/strings.js +15 -0
  419. package/modules/world/World.js +231 -0
  420. package/modules/world/cells.js +42 -0
  421. package/modules/world/explain.js +11 -0
  422. package/modules/world/index.js +71 -0
  423. package/modules/world/persist.js +107 -0
  424. package/modules/world/pos.js +20 -0
  425. package/modules/world/records.js +89 -0
  426. package/modules/world/sim.js +175 -0
  427. package/modules/world/simFar.js +82 -0
  428. package/modules/world/state.js +115 -0
  429. package/modules/world/thingSource.js +44 -0
  430. package/modules/world/views.js +182 -0
  431. package/package.json +66 -4
  432. package/presets.js +96 -0
  433. package/render/PostFX.js +240 -0
  434. package/render/detail.js +105 -0
  435. package/render/effects.js +144 -0
  436. package/render/engineUniforms.js +23 -0
  437. package/render/fuse.js +84 -0
  438. package/render/lighting.js +100 -0
  439. package/render/lights.js +18 -0
  440. package/render/lookSurface.js +161 -0
  441. package/render/materials.js +220 -0
  442. package/render/patches.js +252 -0
  443. package/render/postLook.js +86 -0
  444. package/render/surface.js +69 -0
  445. package/render/uniformDecl.js +29 -0
  446. package/types/common.d.ts +34 -0
  447. package/types/core.d.ts +1965 -0
  448. package/types/gameplay.d.ts +1822 -0
  449. package/types/generated/core/Audio.d.ts +200 -0
  450. package/types/generated/core/Batching.d.ts +47 -0
  451. package/types/generated/core/Budget.d.ts +90 -0
  452. package/types/generated/core/Commits.d.ts +31 -0
  453. package/types/generated/core/DebugOverrides.d.ts +52 -0
  454. package/types/generated/core/Events.d.ts +89 -0
  455. package/types/generated/core/I18n.d.ts +30 -0
  456. package/types/generated/core/Input.d.ts +118 -0
  457. package/types/generated/core/Jobs.d.ts +41 -0
  458. package/types/generated/core/Ops.d.ts +203 -0
  459. package/types/generated/core/Random.d.ts +49 -0
  460. package/types/generated/core/Rays.d.ts +49 -0
  461. package/types/generated/core/Saves.d.ts +162 -0
  462. package/types/generated/core/Stream.d.ts +93 -0
  463. package/types/generated/core/Threads.d.ts +82 -0
  464. package/types/generated/core/Views.d.ts +33 -0
  465. package/types/generated/core/audioVoice.d.ts +47 -0
  466. package/types/generated/core/page.d.ts +18 -0
  467. package/types/generated/core/session.d.ts +48 -0
  468. package/types/generated/modules/ambience/Ambience.d.ts +48 -0
  469. package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
  470. package/types/generated/modules/flow/index.d.ts +10 -0
  471. package/types/generated/modules/grid/Grid.d.ts +151 -0
  472. package/types/generated/modules/grid/Layer.d.ts +65 -0
  473. package/types/generated/modules/grid/index.d.ts +86 -0
  474. package/types/generated/modules/hlod/index.d.ts +11 -0
  475. package/types/generated/modules/hud/index.d.ts +10 -0
  476. package/types/generated/modules/lights/index.d.ts +13 -0
  477. package/types/generated/modules/music/Music.d.ts +111 -0
  478. package/types/generated/modules/net/Net.d.ts +34 -0
  479. package/types/generated/modules/net/index.d.ts +53 -0
  480. package/types/generated/modules/net/transports.d.ts +58 -0
  481. package/types/generated/modules/particles/Particles.d.ts +69 -0
  482. package/types/generated/modules/sky/Sky.d.ts +145 -0
  483. package/types/generated/modules/sky/skyModule.d.ts +10 -0
  484. package/types/generated/modules/timeline/Timeline.d.ts +51 -0
  485. package/types/generated/modules/water/Water.d.ts +29 -0
  486. package/types/generated/modules/weather/Weather.d.ts +62 -0
  487. package/types/generated/modules/world/World.d.ts +242 -0
  488. package/types/generated/modules/world/index.d.ts +15 -0
  489. package/types/generated/render/PostFX.d.ts +125 -0
  490. package/types/generated/render/materials.d.ts +100 -0
  491. package/types/generated/render/patches.d.ts +41 -0
  492. package/types/generated/ui/Focus.d.ts +11 -0
  493. package/types/generated/ui/LoadingScreen.d.ts +2 -0
  494. package/types/generated/ui/UI.d.ts +57 -0
  495. package/types/nav.d.ts +52 -0
  496. package/types/physics.d.ts +592 -0
  497. package/types/style.d.ts +638 -0
  498. package/types/worker.d.ts +11 -0
  499. package/types/world.d.ts +772 -0
  500. package/ui/Focus.js +51 -0
  501. package/ui/LoadingScreen.js +42 -0
  502. package/ui/Parts.js +199 -0
  503. package/ui/UI.js +167 -0
  504. package/ui/defaults.js +85 -0
  505. package/ui/theme.js +124 -0
  506. package/ui/touchPart.js +49 -0
@@ -0,0 +1,89 @@
1
+ // The life of one engine.assets entry, split from Assets.js (which keeps the public API and the manifest):
2
+ // load: fetchEntry runs the load as a task in engine.loading and, for a registered non-critical file that fails, falls back (gray placeholder / silence / the entry's fallback)
3
+ // free: freeEntry gives the GPU memory back, deferred while model copies are still in the scene; shareModel marks what copies share so engine.remove does not dispose it
4
+ // Plain functions that take the Assets instance, so they stay out of the class's public surface.
5
+ import { warnOnce, fmt } from './validate.js';
6
+ import { codedError, coded } from './errorHints.js';
7
+ import { loadGltf, loadTexture, loadFont, generated, placeholder, LoadError } from './assetLoad.js';
8
+ import { failureText } from './Loading.js';
9
+
10
+ const STRINGS = {
11
+ failed: 'Asset failed to load: {what}',
12
+ fellBack: '; using {fallback} instead, the game continues (mark it critical: true if the game cannot start without it)',
13
+ missingRefs: 'Asset loaded with missing references: {what} (missing {list}); materials show without those files',
14
+ };
15
+
16
+ /** Mark a model template's geometry and materials as shared (copies share them; engine.remove must not dispose them) */
17
+ function shareModel(a, g) {
18
+ g.scene.traverse(o => { if (o.geometry) a.shared.add(o.geometry); for (const m of [].concat(o.material || [])) a.shared.add(m); });
19
+ return g;
20
+ }
21
+
22
+ /** Load an entry as a task in engine.loading; a registered, non-critical file that fails resolves to its fallback */
23
+ export function fetchEntry(a, e) {
24
+ if (e.promise) return e.promise;
25
+ const L = a.engine.loading, name = e.variantOf ?? e.name ?? e.url;
26
+ const t = L._begin(name, e.type, { critical: e.opts.critical === true, url: e.opts.build ? null : e.url, manifest: e.manifest ?? null });
27
+ if (e.type === 'model') {
28
+ const load = e.opts.build ? (t.phase('build'), generated(a, e.url, e.opts.build, e.opts.params, t)) : loadGltf(a, e.url, t);
29
+ e.promise = load.then(g => shareModel(a, g));
30
+ } else if (e.type === 'texture') e.promise = loadTexture(a, e, t);
31
+ else if (e.type === 'font') e.promise = loadFont(a, e, t);
32
+ else if (e.type === 'sound') {
33
+ t.phase('download');
34
+ e.promise = a.engine.audio.load(e.url).catch(err => { throw new LoadError(err.message, { url: e.url }); });
35
+ }
36
+ e.promise = e.promise.then(v => {
37
+ L._done(t);
38
+ const what = `${e.type} "${name}" <- ${e.url}`;
39
+ if (t.missing.length) warnOnce(coded('asset-missing-ref', fmt(STRINGS.missingRefs, { what, list: t.missing.join(', ') })));
40
+ return (e.value = v);
41
+ }, err => failedEntry(a, e, t, err));
42
+ return e.promise;
43
+ }
44
+
45
+ /** A load failed: a registered file entry degrades (warn + fallback); anything else is recorded and rethrown to the caller */
46
+ function failedEntry(a, e, t, err) {
47
+ e.promise = null;
48
+ const degrade = e.named && !e.opts.build && !e.opts.critical;
49
+ const fb = degrade ? (e.opts.fallback ?? (e.type === 'sound' ? 'silence' : e.type === 'font' ? 'the system font' : 'gray placeholder')) : null;
50
+ a.engine.loading._fail(t, err, fb);
51
+ const msg = fmt(STRINGS.failed, { what: failureText(t) });
52
+ if (!degrade) throw codedError('asset-load', msg);
53
+ warnOnce(coded('asset-load', msg + fmt(STRINGS.fellBack, { fallback: e.opts.fallback ? `"${fb}"` : fb })));
54
+ if (e.opts.fallback) return (e.promise = fetchEntry(a, a._resolve(e.opts.fallback, e.type))); // e.value stays null: the fallback entry owns the memory
55
+ e.value = e.type === 'model' ? shareModel(a, placeholder('model', a.engine)) : placeholder(e.type);
56
+ return (e.promise = Promise.resolve(e.value));
57
+ }
58
+
59
+ /** Free an entry's GPU memory; while model copies are still in use it waits (releasePending) and the last engine.remove frees it */
60
+ export function freeEntry(e) {
61
+ if (!e.value) return;
62
+ if (e.users > 0) { e.releasePending = true; return; }
63
+ if (e.type === 'texture') e.value.dispose();
64
+ if (e.type === 'font') document.fonts.delete(e.value); // a released font stops matching its family
65
+ if (e.value.isBufferGeometry) e.value.dispose(); // code-generated geometry
66
+ else if (e.type === 'model') {
67
+ (e.value.scene ?? e.value).traverse?.(o => {
68
+ if (!o.isMesh) return;
69
+ o.geometry.dispose();
70
+ [].concat(o.material).forEach(m => { for (const k in m) if (m[k]?.isTexture) m[k].dispose(); m.dispose(); });
71
+ });
72
+ }
73
+ e.value = null; e.promise = null; e.releasePending = e.pinned = false;
74
+ }
75
+
76
+ /** Load the entries preload() wants and report progress; returns { loaded, failed, ok } (Assets.preload documents it) */
77
+ export async function preloadEntries(a, onProgress, onlyMarked) {
78
+ // generators and fonts only when marked: a font pack may hold many faces, and only those style.ui.fonts names (or preload: true) are wanted
79
+ const list = [...a.entries.entries()].filter(([, e]) => e.opts.build || e.type === 'font' ? e.opts.preload : !onlyMarked || e.opts.preload);
80
+ let done = 0;
81
+ onProgress?.(list.length ? 0 : 1, '');
82
+ // critical failures are reported by start(); others not already warned about (generated models) are warned here
83
+ await Promise.all(list.map(([name, e]) => fetchEntry(a, e).catch(err => { if (!e.opts.critical) console.warn(err.message); }).finally(() => {
84
+ done++;
85
+ onProgress?.(done / list.length, name);
86
+ })));
87
+ const failed = list.filter(([name, e]) => a.engine.loading.get(name, e.type)?.phase === 'failed').map(([name]) => name);
88
+ return { loaded: list.length - failed.length, failed, ok: !failed.length };
89
+ }
@@ -0,0 +1,190 @@
1
+ // File loading for engine.assets, split into the phases engine.loading reports: download -> decode -> upload.
2
+ // Each step names the failing file and HTTP status, and a glTF records what it references but could not load
3
+ // (a texture / .bin that 404s), so "the model looks gray" is traceable to one path instead of a bare "failed".
4
+ import { coded } from './errorHints.js';
5
+ import * as THREE from 'three';
6
+ import { restoreBaked, toGLB, fromGLTF } from './Baked.js';
7
+ import { warnOnce } from './validate.js';
8
+ import { makeMaterial } from '../render/materials.js';
9
+
10
+ const BASE = import.meta.env?.BASE_URL ?? '/';
11
+ const DEV_SERVER = !!import.meta.env?.DEV; // only npm run dev serves the /__threedog/cache endpoint
12
+ const CACHE = '/__threedog/cache/';
13
+ const STALE = 'The generator code for "{name}" has changed, so it is built from code now; run npm run bake once it is final';
14
+ const NO_CACHE = '[cache] the dev server has no threedog model cache (a plain Vite server without the threedog plugin): code-generated models are built every time. Use the vite config of the game template (threedog gameConfig) to cache them';
15
+
16
+ // A dev / preview server answers a missing path with its index.html (status 200): treat an HTML answer for an asset as "not found"
17
+ const NOT_THERE = 'not found (404: the server sent an HTML page instead, so the file is not at this path)';
18
+ const isHtml = res => /text\/html/i.test(res.headers.get('content-type') || '');
19
+
20
+ /** Error with the failing URL and HTTP status (status 0 = network / CORS / not an HTTP failure) */
21
+ export class LoadError extends Error {
22
+ /** @param {string} message @param {{ url: string, status?: number }} info */
23
+ constructor(message, { url, status = 0 }) { super(message); this.url = url; this.status = status; }
24
+ }
25
+
26
+ /** Extensions a glTF file uses (reads only the JSON part, not the whole file) */
27
+ function gltfExtensions(buf) {
28
+ const dv = new DataView(buf);
29
+ let json;
30
+ if (buf.byteLength >= 20 && dv.getUint32(0, true) === 0x46546c67) json = new TextDecoder().decode(new Uint8Array(buf, 20, dv.getUint32(12, true)));
31
+ else json = new TextDecoder().decode(buf);
32
+ try { return JSON.parse(json).extensionsUsed || []; } catch { return []; }
33
+ }
34
+
35
+ /** Download as ArrayBuffer, reporting progress when the server sends a length; records size and version headers on the task */
36
+ async function download(url, task) {
37
+ task.phase('download', 0);
38
+ const res = await fetch(url);
39
+ if (!res.ok) throw new LoadError(`${res.status} ${res.statusText}`.trim(), { url, status: res.status });
40
+ if (isHtml(res)) throw new LoadError(NOT_THERE, { url, status: 404 });
41
+ const total = +(res.headers.get('content-length') || 0);
42
+ task.source.version = res.headers.get('etag') || res.headers.get('last-modified') || null;
43
+ let buf;
44
+ if (total && res.body) { // stream so a big model shows 0-100% instead of sitting at "downloading"
45
+ const reader = res.body.getReader(), parts = [];
46
+ let got = 0;
47
+ for (let r; !(r = await reader.read()).done;) { parts.push(r.value); got += r.value.length; task.progress = Math.min(1, got / total); }
48
+ const all = new Uint8Array(got);
49
+ let at = 0; for (const p of parts) { all.set(p, at); at += p.length; }
50
+ buf = all.buffer;
51
+ } else buf = await res.arrayBuffer();
52
+ task.source.bytes = buf.byteLength;
53
+ return buf;
54
+ }
55
+
56
+ /** Upload textures to the GPU now, so the first frame that shows them does not stall (the 'upload' phase) */
57
+ function upload(assets, textures, task) {
58
+ task.phase('upload');
59
+ for (const t of textures) assets.engine.renderer.initTexture(t);
60
+ }
61
+
62
+ /** Download a glTF, set up the Draco / KTX2 decoder it needs, parse it and upload its textures. Returns the gltf */
63
+ export async function loadGltf(assets, url, task) {
64
+ const buf = await download(url, task), used = gltfExtensions(buf);
65
+ task.phase('decode');
66
+ if (used.includes('KHR_draco_mesh_compression')) await decoder(assets, 'draco');
67
+ if (used.includes('KHR_texture_basisu')) await decoder(assets, 'ktx2');
68
+ // A per-file manager hears which referenced files (.bin, textures) failed; GLTFParser reads the manager when parse() starts,
69
+ // so swapping it around the synchronous start of parseAsync scopes it to this file even with several loads in flight
70
+ const mgr = new THREE.LoadingManager(), missing = task.missing;
71
+ mgr.onError = ref => { if (!missing.includes(ref)) missing.push(ref); };
72
+ const prev = assets.gltf.manager;
73
+ assets.gltf.manager = mgr;
74
+ const parsing = assets.gltf.parseAsync(buf, THREE.LoaderUtils.extractUrlBase(url));
75
+ assets.gltf.manager = prev;
76
+ let gltf;
77
+ try { gltf = restoreBaked(await parsing, assets.engine); } // baked file: restore materials etc.
78
+ catch (err) { throw new LoadError(String(err?.message ?? err) + (missing.length ? ` (missing: ${missing.join(', ')})` : ''), { url: missing[0] ?? url }); }
79
+ task.source.animations = gltf.animations.map(a => a.name);
80
+ const tex = new Set();
81
+ gltf.scene.traverse(o => { for (const m of [].concat(o.material || [])) for (const k in m) if (m[k]?.isTexture) tex.add(m[k]); });
82
+ upload(assets, tex, task);
83
+ return gltf;
84
+ }
85
+
86
+ /** Load a texture (.ktx2 through KTX2Loader, .hdr through HDRLoader), apply the entry's options and upload it */
87
+ export async function loadTexture(assets, e, task) {
88
+ task.phase('download');
89
+ const ktx = /\.ktx2(\?|$)|^data:image\/ktx2/i.test(e.url);
90
+ const hdr = /\.hdr(\?|$)/i.test(e.url); // Radiance HDR (environment lighting): float data in linear color
91
+ let t;
92
+ try {
93
+ if (ktx) t = await (await decoder(assets, 'ktx2')).loadAsync(e.url);
94
+ else if (hdr) t = await new (await import('three/addons/loaders/HDRLoader.js')).HDRLoader().loadAsync(e.url);
95
+ else t = await assets.tex.loadAsync(e.url);
96
+ }
97
+ catch (err) {
98
+ // an <img> error carries no status: ask the server once so the report says 404 vs a broken file
99
+ const status = await fetch(e.url, { method: 'HEAD' }).then(r => (!r.ok ? r.status : isHtml(r) ? 404 : 0), () => 0);
100
+ throw new LoadError(status === 404 ? NOT_THERE : status ? `HTTP ${status}` : String(err?.message ?? 'not a decodable image'), { url: e.url, status });
101
+ }
102
+ if (e.opts.color === false) t.colorSpace = THREE.NoColorSpace;
103
+ else if (!t.isCompressedTexture && !hdr) t.colorSpace = THREE.SRGBColorSpace; // KTX2 carries its own color space
104
+ t.anisotropy = assets.engine.renderer.capabilities.getMaxAnisotropy();
105
+ if (e.opts.pixelated) { t.magFilter = THREE.NearestFilter; t.minFilter = THREE.NearestMipmapNearestFilter; }
106
+ if (e.opts.repeat) { t.wrapS = t.wrapT = THREE.RepeatWrapping; t.repeat.set(e.opts.repeat[0], e.opts.repeat[1]); }
107
+ upload(assets, [t], task);
108
+ return t;
109
+ }
110
+
111
+ /** Import and create DRACOLoader / KTX2Loader on first use. Decoders default to the ones shipped with three (vite bundles them); if engine.decoders is set, download from there */
112
+ function decoder(assets, kind) {
113
+ return assets._loaders[kind] ||= (async () => {
114
+ const dir = assets.engine.decoders;
115
+ if (kind === 'draco') {
116
+ const { DRACOLoader } = await import('three/addons/loaders/DRACOLoader.js');
117
+ assets.draco = new DRACOLoader();
118
+ if (dir) assets.draco.setDecoderPath(dir + 'draco/');
119
+ assets.gltf.setDRACOLoader(assets.draco);
120
+ return assets.draco;
121
+ }
122
+ const { KTX2Loader } = await import('three/addons/loaders/KTX2Loader.js');
123
+ assets.ktx2 = new KTX2Loader().detectSupport(assets.engine.renderer);
124
+ if (dir) assets.ktx2.setTranscoderPath(dir + 'basis/');
125
+ assets.gltf.setKTX2Loader(assets.ktx2);
126
+ return assets.ktx2;
127
+ })();
128
+ }
129
+
130
+ /** FontFace descriptors an asset pack's fonts entry may carry (everything else on the entry is the asset's own: url, family, critical...) */
131
+ const FONT_DESCRIPTORS = ['weight', 'style', 'stretch', 'unicodeRange', 'display', 'featureSettings', 'variationSettings'];
132
+ /**
133
+ * Download a font file and add it to document.fonts as a FontFace (family = entry.family, else the asset name). Downloaded with fetch
134
+ * (not the FontFace url source) so a 404 reports its HTTP status like any other asset; the face is decoded before it is added, so a
135
+ * broken file fails here instead of silently falling back to the system font. Returns the FontFace
136
+ */
137
+ export async function loadFont(assets, e, task) {
138
+ const family = e.opts.family ?? e.name;
139
+ if (typeof family !== 'string' || /["'();\\<>]/.test(family))
140
+ throw new LoadError(`font family ${JSON.stringify(family)} must be a plain name without quotes, brackets, ';' or '\\', e.g. family: 'PixelFont'`, { url: e.url });
141
+ const buf = await download(e.url, task);
142
+ task.phase('decode');
143
+ const desc = Object.fromEntries(FONT_DESCRIPTORS.filter(k => e.opts[k] != null).map(k => [k, String(e.opts[k])]));
144
+ const face = new FontFace(family, buf, { display: 'swap', ...desc });
145
+ try { await face.load(); } catch (err) { throw new LoadError(`not a font the browser can read (${err.message})`, { url: e.url }); }
146
+ document.fonts.add(face);
147
+ return face;
148
+ }
149
+
150
+ /** Stand-ins for a degradable asset that failed: neutral gray (hard rule 1: the engine has no art of its own) */
151
+ export function placeholder(type, engine) {
152
+ if (type === 'texture') { const t = new THREE.DataTexture(new Uint8Array([128, 128, 128, 255]), 1, 1); t.needsUpdate = true; return t; }
153
+ if (type === 'model') {
154
+ const g = new THREE.Group();
155
+ g.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1).translate(0, 0.5, 0), makeMaterial('default', {}, engine)));
156
+ g.name = 'placeholder';
157
+ return { scene: g, animations: [] };
158
+ }
159
+ return null; // sound: silence; font: the next family in style.ui.font (the system font)
160
+ }
161
+
162
+ /** Code-generated model: baked file -> dev cache -> build now (see Assets.cached); returns { scene, animations, geometry? } */
163
+ export async function generated(assets, name, build, params, task) {
164
+ const wrap = v => v.isBufferGeometry
165
+ ? { geometry: v, scene: new THREE.Mesh(v, makeMaterial('default', { vertexColors: !!v.attributes.color }, assets.engine)), animations: [] }
166
+ : { scene: v, animations: v.animations ?? [] };
167
+ const same = JSON.stringify(params ?? null);
168
+ const ctx = { palette: assets.engine.style.palette, engine: assets.engine }; // a function() generator reads this.palette (style.palette)
169
+ const baked = (await bakedIndex(assets))[name];
170
+ const bakedOk = baked && JSON.stringify(baked.params ?? null) === same;
171
+ const file = async url => wrap(fromGLTF(await loadGltf(assets, url, task)));
172
+ if (!DEV_SERVER) return bakedOk ? file(BASE + 'models/baked/' + baked.file) : wrap(await build.call(ctx, params));
173
+ // In dev: ask the dev server for the current hash of this generator (with its file and imports)
174
+ // a plain Vite dev server without threedog's plugin answers with index.html: no cache then, build now (said once)
175
+ const info = await fetch(CACHE + 'key', { method: 'POST', body: JSON.stringify({ name, src: String(build), params: ctx.palette ? [params ?? null, ctx.palette] : params ?? null }) }).then(r => r.json()).catch(() => null);
176
+ if (!info) { warnOnce(coded('asset-cache', NO_CACHE)); return bakedOk ? file(BASE + 'models/baked/' + baked.file) : wrap(await build.call(ctx, params)); }
177
+ if (bakedOk) {
178
+ if (baked.source === 'file' || baked.key === info.key) return file(BASE + 'models/baked/' + baked.file);
179
+ warnOnce(coded('asset-cache', STALE.replace('{name}', name)));
180
+ }
181
+ if (info.hit) return file(CACHE + info.key + '.glb');
182
+ const t0 = performance.now(), v = await build.call(ctx, params); // measure:build time
183
+ if (performance.now() - t0 >= assets.cacheMinMs) // measure
184
+ toGLB(v, assets.engine).then(buf => fetch(CACHE + info.key + '.glb', { method: 'PUT', body: buf })).catch(err => warnOnce(coded('asset-cache', '[cache] could not store a built model in .threedog/cache (' + err.message + '); it is built again next time')));
185
+ return wrap(v);
186
+ }
187
+ /** Bake manifest public/models/baked/index.json (empty if missing) */
188
+ function bakedIndex(assets) {
189
+ return assets._baked ||= fetch(BASE + 'models/baked/index.json').then(r => (r.ok ? r.text() : '{}')).then(t => { try { return JSON.parse(t); } catch { return {}; } }, () => ({}));
190
+ }
@@ -0,0 +1,35 @@
1
+ // engine.assets.manifest(pack) (helper of Assets.js): registers the named models, textures, sounds and fonts of an asset pack. `a` is the Assets instance.
2
+ import { fmt, warnOnce, checkOptions } from './validate.js';
3
+ import { codedError } from './errorHints.js';
4
+
5
+ const STRINGS = {
6
+ clash: 'assets.manifest(): "{name}" is already registered as a {was} (manifest "{list}"), and now as a {type}; one name is one asset, ' +
7
+ 'so the second would replace the first. Rename one, e.g. {name}_{type}',
8
+ replaced: 'assets.manifest(): {type} "{name}" from manifest "{was}" is replaced by manifest "{list}" (the later one wins). If both packs mean their own asset, rename one; '
9
+ + 'if the override is intended (a mod replacing a model), ignore this',
10
+ };
11
+ /** Keys of a manifest / asset pack: anything else is a typo (checkOptions says "did you mean") */
12
+ const MANIFEST_KEYS = ['name', 'base', 'models', 'textures', 'sounds', 'fonts'];
13
+ /** Keys of one fonts entry: the file, the CSS family it registers (default: the asset name), FontFace descriptors, and the usual asset flags */
14
+ const FONT_KEYS = ['url', 'family', 'weight', 'style', 'stretch', 'unicodeRange', 'display', 'featureSettings', 'variationSettings', 'critical', 'preload'];
15
+
16
+ export function registerManifest(a, pack) {
17
+ checkOptions('assets.manifest()', pack, MANIFEST_KEYS);
18
+ const { models = {}, textures = {}, sounds = {}, fonts = {}, base = null } = pack, list = pack.name ?? 'manifest#' + (a._lists = (a._lists || 0) + 1);
19
+ const at = base == null ? null : new URL(String(base).replace(/\/?$/, '/'), location.href);
20
+ const resolve = u => at && typeof u === 'string' && !u.startsWith('/') && !/^[a-z][a-z\d+.-]*:/i.test(u) ? new URL(u, at).href : u;
21
+ const add = (type, map) => {
22
+ for (const [name, v] of Object.entries(map)) {
23
+ const o0 = typeof v === 'string' ? { url: v } : typeof v === 'function' ? { build: v } : v;
24
+ if (type === 'font') checkOptions(`assets.manifest() fonts.${name}`, o0, FONT_KEYS);
25
+ const o = o0.url && at ? { ...o0, url: resolve(o0.url) } : o0;
26
+ const old = a.entries.get(name);
27
+ if (old?.named && old.type !== type) throw codedError('asset-name-clash', fmt(STRINGS.clash, { name, was: old.type, list: old.manifest, type }));
28
+ // same type from another manifest: allowed (a mod overriding a model) but never silent, the two packs may just share a name by accident
29
+ if (old?.named && old.manifest !== list) warnOnce(fmt(STRINGS.replaced, { type, name, was: old.manifest, list }));
30
+ a.entries.set(name, { type, name, url: o.url ?? name, opts: o, promise: null, named: true, manifest: list });
31
+ }
32
+ };
33
+ add('model', models); add('texture', textures); add('sound', sounds); add('font', fonts);
34
+ return a;
35
+ }
@@ -0,0 +1,83 @@
1
+ // Import report of a loaded glTF (engine.assets.report): what the file declares vs what is in the scene now.
2
+ // Pure: reads a three.js scene plus the file's JSON (gltf.parser.json), never changes anything, so it also runs in node tests.
3
+ // "Lost" means: the file has it, the scene does not (a normal map a material no longer has, a clip that did not load, a material replaced by another).
4
+ // Color-space basis: three's color management manual. Color slots (map, emissiveMap) hold sRGB, data slots (normal, roughness, metalness, ao...) stay linear.
5
+ import * as THREE from 'three';
6
+
7
+ const COLOR_SLOTS = ['map', 'emissiveMap', 'specularColorMap', 'sheenColorMap'];
8
+ const DATA_SLOTS = ['normalMap', 'roughnessMap', 'metalnessMap', 'aoMap', 'bumpMap', 'alphaMap', 'displacementMap', 'specularMap', 'clearcoatMap', 'clearcoatNormalMap', 'clearcoatRoughnessMap', 'transmissionMap', 'thicknessMap', 'lightMap'];
9
+ const SRGB = THREE.SRGBColorSpace, LINEAR = THREE.NoColorSpace;
10
+ // three's PropertyBinding.sanitizeNodeName: the name the engine sees ("door.001" -> "door001")
11
+ const sanitize = n => String(n ?? '').replace(/\s/g, '_').replace(/[[\].:/]/g, '');
12
+
13
+ /** Color-space problems of one texture used in the given slots: [] when fine */
14
+ export function colorSpaceIssues(tex, slots) {
15
+ const out = [], cs = tex.colorSpace || LINEAR;
16
+ const color = slots.filter(s => COLOR_SLOTS.includes(s)), data = slots.filter(s => DATA_SLOTS.includes(s));
17
+ if (color.length && data.length) out.push(`used as both color (${color}) and data (${data}): one texture has one color space`);
18
+ else if (color.length && cs !== SRGB) out.push(`color texture (${slots}) is "${cs || 'none'}", should be srgb (it looks washed out or too dark); set texture.colorSpace = THREE.SRGBColorSpace, or fetch it with engine.assets.texture() (sRGB by default)`);
19
+ else if (data.length && cs === SRGB) out.push(`data texture (${slots}) is srgb, should be linear: the shader would decode it as color. Fetch it with { color: false }`);
20
+ return out;
21
+ }
22
+
23
+ /**
24
+ * @param {{ scene: any, animations?: any[], parser?: any }} gltf a GLTFLoader result (or an object with the same fields)
25
+ * @param {{ name?: string, url?: string, opts?: any }} [entry] asset entry (opts.animation.states is the clip mapping)
26
+ * @param {any} [root] a model copy to check instead of the template scene (what the game actually shows)
27
+ * @param {{ outputColorSpace?: string }} [renderer]
28
+ */
29
+ export function reportGltf(gltf, entry = {}, root = gltf.scene, renderer) {
30
+ const json = gltf.parser?.json ?? null, issues = [], flag = (severity, code, msg) => issues.push({ severity, code, msg });
31
+ const materials = new Set(), textures = new Map(), nodes = [], colliders = [], templates = [];
32
+ root.traverse(o => {
33
+ if (o !== root) nodes.push(o.name);
34
+ if (/^col_/i.test(o.name) || o.userData?.collider != null) colliders.push(o.name);
35
+ if (o.userData?.template != null || o.userData?.id != null) templates.push({ node: o.name, ...(o.userData.template != null && { template: String(o.userData.template) }), ...(o.userData.id != null && { id: o.userData.id }) });
36
+ for (const m of [].concat(o.material || [])) materials.add(m);
37
+ });
38
+ const mats = [...materials].map(m => {
39
+ const maps = {};
40
+ for (const k of [...COLOR_SLOTS, ...DATA_SLOTS]) if (m[k]?.isTexture) {
41
+ maps[k] = m[k].colorSpace || LINEAR;
42
+ const t = textures.get(m[k]) ?? textures.set(m[k], { name: m[k].name || '(unnamed)', slots: [] }).get(m[k]);
43
+ if (!t.slots.includes(k)) t.slots.push(k);
44
+ }
45
+ return { name: m.name || '(unnamed)', type: m.type, maps, flatShading: !!m.flatShading, vertexColors: !!m.vertexColors, madeByStyle: !!m.userData?.materialSource };
46
+ });
47
+ const texList = [...textures].map(([t, v]) => ({ ...v, colorSpace: t.colorSpace || LINEAR, problems: colorSpaceIssues(t, v.slots) }));
48
+ for (const t of texList) for (const p of t.problems) flag('warn', 'color-space', `texture ${t.name}: ${p}`);
49
+ if (renderer?.outputColorSpace && renderer.outputColorSpace !== SRGB) flag('warn', 'output-color-space', `renderer output color space is "${renderer.outputColorSpace}", not srgb: every color on screen is encoded wrongly. Leave renderer.outputColorSpace at its default`);
50
+ const clips = (gltf.animations || []).map(a => ({ name: a.name, seconds: +a.duration.toFixed(2), tracks: a.tracks.length }));
51
+ // Against the file: only possible when the loader kept the JSON (code-built models have none)
52
+ if (json) {
53
+ for (const fm of json.materials || []) {
54
+ const live = mats.find(m => m.name === (fm.name || '(unnamed)'));
55
+ if (!live) { if (fm.name) flag('warn', 'material-replaced', `file material "${fm.name}" is not in the scene: a path replaced it (the painted look is gone)`); continue; }
56
+ if (fm.normalTexture && !live.maps.normalMap) flag('warn', 'normal-map-lost', `material "${live.name}" has a normal map in the file but none in the scene`);
57
+ if (fm.pbrMetallicRoughness?.baseColorTexture && !live.maps.map) flag('warn', 'base-color-lost', `material "${live.name}" has a base color texture in the file but none in the scene`);
58
+ if (fm.pbrMetallicRoughness?.metallicRoughnessTexture && !live.maps.roughnessMap && !live.maps.metalnessMap) flag('warn', 'metal-rough-lost', `material "${live.name}" has a metallic-roughness texture in the file but none in the scene`);
59
+ if (live.flatShading) flag('warn', 'flat-shading', `material "${live.name}" is flat shaded; the file asks for smooth normals`);
60
+ if (live.madeByStyle) flag('warn', 'material-replaced', `material "${live.name}" was made by makeMaterial (style role), not read from the file`);
61
+ }
62
+ for (const a of json.animations || []) if (!clips.some(c => c.name === a.name)) flag('warn', 'clip-lost', `file clip "${a.name}" did not load`);
63
+ const names = new Set(nodes.map(sanitize)), gone = (json.nodes || []).map(n => sanitize(n.name)).filter(n => n && !names.has(n));
64
+ if (root === gltf.scene && gone.length) flag('warn', 'node-lost', `file nodes missing from the scene: ${gone.slice(0, 8).join(', ')}${gone.length > 8 ? ', ...' : ''}`);
65
+ }
66
+ const states = entry.opts?.animation?.states ?? {}, mapped = new Set(Object.values(states).map(s => s?.clip).filter(Boolean));
67
+ for (const [state, s] of Object.entries(states)) if (s?.clip && clips.length && !clips.some(c => c.name === s.clip)) flag('warn', 'clip-unmapped', `state "${state}" maps clip "${s.clip}", which the file does not have (clips: ${clips.map(c => c.name).join(', ') || 'none'})`);
68
+ if (mapped.size) for (const c of clips) if (!mapped.has(c.name)) flag('info', 'clip-unused', `clip "${c.name}" is in the file but no animation state uses it`);
69
+ return {
70
+ name: entry.name ?? null, url: entry.url ?? null, fromFile: !!json,
71
+ counts: { nodes: nodes.length, materials: mats.length, textures: texList.length, normalMaps: mats.filter(m => m.maps.normalMap).length, clips: clips.length, colliders: colliders.length, templates: templates.length },
72
+ materials: mats, textures: texList, clips, colliders, templates, issues,
73
+ };
74
+ }
75
+
76
+ /** Text for the console / describe: one block, issues last */
77
+ export function reportText(r) {
78
+ const c = r.counts, L = [`model ${r.name ?? r.url}${r.fromFile ? '' : ' (built in code: no file to compare with)'}: ${c.nodes} nodes · ${c.materials} materials · ${c.textures} textures (${c.normalMaps} normal maps) · ${c.clips} clips · ${c.colliders} col_ · ${c.templates} template/id nodes`];
79
+ for (const m of r.materials) L.push(` material ${m.name} (${m.type}${m.flatShading ? ', flat' : ''}${m.madeByStyle ? ', from style' : ''}) ${Object.entries(m.maps).map(([k, v]) => `${k}:${v}`).join(' ') || 'no textures'}`);
80
+ for (const c of r.clips) L.push(` clip ${c.name} ${c.seconds}s`);
81
+ for (const i of r.issues) L.push(` ${i.severity === 'warn' ? '!' : '·'} [${i.code}] ${i.msg}`);
82
+ return L.join('\n');
83
+ }
@@ -0,0 +1,121 @@
1
+ // The data side of audio rules: condition keys, measures (comparable numbers), data volumes, and the audio of content packs.
2
+ // Split out of Audio.js so the bus / playback side and the rule side each stay readable in one go.
3
+ //
4
+ // Why measures: a content pack is data, so `when: e => e.sky.daylight > 0.15` cannot live in it. A module registers the number once
5
+ // (sky: daylight; weather: rain, snow, wind; ambience: nearWater, altitude) and data compares it: `when: { daylight: { gt: 0.15 } }`,
6
+ // `volume: { base: 0.05, add: { wind: 0.08 }, max: 0.5 }`. Code may still pass functions (createEngine({ audio }), ambience.add).
7
+ import { codedError } from './errorHints.js';
8
+ import { DEV, fmt, missingText, warnOnce, checkOptions } from './validate.js';
9
+
10
+ const COMPARE = { gt: (x, v) => x > v, gte: (x, v) => x >= v, lt: (x, v) => x < v, lte: (x, v) => x <= v };
11
+ const VOLUME_KEYS = ['base', 'add', 'min', 'max'];
12
+ /** Keys of a content pack's audio table */
13
+ const PACK_KEYS = ['sounds', 'ambience', 'music', 'footsteps'];
14
+ /** Looks like a file, not an asset name (same test as content models, plus audio extensions) */
15
+ const PATH = /[/\\]|\.(mp3|ogg|wav|m4a|aac|flac|webm|opus)$/i;
16
+
17
+ const STRINGS = {
18
+ clash: "audio: '{name}' is both a condition key and a measure; one name is one thing. Rename one (measures are numbers compared with { gt, lt, gte, lte })",
19
+ compare: "audio rule when.{key}: a measure is compared with { gt, lt, gte, lte } (e.g. { {key}: { gt: 0.15 } }), got {got}",
20
+ noMeasure: 'audio volume add.{key}: no measure named {key}{known}. sky() adds daylight, weather() rain / snow / wind, ambience() nearWater / altitude; '
21
+ + 'or engine.audio.measure(name, e => number)',
22
+ fn: 'content {from}: audio.{what} holds a function, so the rule was dropped. Content is data: compare a measure ({ daylight: { gt: 0.15 } }), '
23
+ + 'write volume as { base, add: { rain: 0.22 }, min, max }, or register a value with engine.audio.measure(name, fn)',
24
+ path: "content {from}: audio.{what} names the file \"{src}\". Content names sounds only: register the file in an asset pack "
25
+ + "(engine.assets.manifest({ sounds: { {short}: '{src}' } })) and write '{short}'",
26
+ codeToo: "audio.{table}.{name} is defined both in createEngine({ audio }) and in content {from}. One name, one place: keep it in the content pack "
27
+ + '(data) or in code (when it needs a function), not both',
28
+ };
29
+ const hasFn = v => typeof v === 'function' || (v !== null && typeof v === 'object' && Object.values(v).some(hasFn));
30
+
31
+ /** Does a measure comparison hold? cmp = { gt: 0.15 } / { lt: 0.2, gte: 0 } (every key must hold) */
32
+ function compare(audio, key, cmp) {
33
+ const ok = cmp !== null && typeof cmp === 'object' && !Array.isArray(cmp) && Object.keys(cmp).length && Object.keys(cmp).every(k => k in COMPARE);
34
+ if (!ok) { warnOnce(fmt(STRINGS.compare, { key, got: JSON.stringify(cmp) })); return false; }
35
+ const x = audio.measures.get(key)(audio.engine);
36
+ return Object.entries(cmp).every(([k, v]) => COMPARE[k](x, v));
37
+ }
38
+
39
+ /** audio.matches body: an object needs every key to hold (condition keys first, then measures); a function gets (engine, ...extra) */
40
+ export function matchesWhen(audio, when, extra) {
41
+ if (when == null) return true;
42
+ if (typeof when === 'function') return !!when(audio.engine, ...extra);
43
+ for (const [k, v] of Object.entries(when)) {
44
+ const test = audio.conditions.get(k);
45
+ if (test) { if (!test(v, audio.engine)) return false; continue; }
46
+ if (audio.measures.has(k)) { if (!compare(audio, k, v)) return false; continue; }
47
+ warnOnce(missingText('condition', k, [...audio.conditions.keys(), ...audio.measures.keys()])
48
+ + '. time comes from sky(), weather from weather(), zone from triggers(), measures (daylight, rain, nearWater...) from their modules; or write when: e => ...');
49
+ return false;
50
+ }
51
+ return true;
52
+ }
53
+
54
+ /** audio.volumeOf body: a number, a function of the moment, or data { base, add: { measure: factor }, min, max }; missing = 1 */
55
+ export function volumeOf(audio, v, extra) {
56
+ if (v == null) return 1;
57
+ if (typeof v === 'number') return v;
58
+ if (typeof v === 'function') return v(audio.engine, ...extra);
59
+ checkOptions('audio rule volume', v, VOLUME_KEYS);
60
+ let x = v.base ?? 0;
61
+ for (const [k, f] of Object.entries(v.add || {})) {
62
+ const m = audio.measures.get(k);
63
+ if (!m) { warnOnce(fmt(STRINGS.noMeasure, { key: k, known: audio.measures.size ? ` (measures: ${[...audio.measures.keys()].join(', ')})` : '' })); continue; }
64
+ x += m(audio.engine) * f;
65
+ }
66
+ return Math.min(v.max ?? Infinity, Math.max(v.min ?? -Infinity, x));
67
+ }
68
+
69
+ /** audio.measure / audio.condition share one namespace (a rule key is looked up in both) */
70
+ export function checkRuleName(audio, name, isMeasure) {
71
+ if (isMeasure ? audio.conditions.has(name) : audio.measures.has(name)) throw codedError('audio-name-clash', fmt(STRINGS.clash, { name }));
72
+ }
73
+
74
+ /** Variants / src of a sounds entry, for the path check */
75
+ const srcsOf = v => typeof v === 'string' ? (v === 'synth' ? [] : [v]) : Array.isArray(v) ? v : v && typeof v === 'object' ? [v.src].flat().filter(Boolean) : [];
76
+ const trackSrcs = t => typeof t === 'string' ? [t] : t && typeof t === 'object' ? [t.url, ...(t.stems || []).map(s => s?.url)].filter(Boolean) : [];
77
+
78
+ /**
79
+ * Normalize one content pack's audio table (engine.audio.contentPack): data only. A rule holding a function is dropped with a dev warning;
80
+ * a file path warns (dev) and still plays; a sound / footstep name the game also defines in code is an error.
81
+ * Returns { sounds, footsteps, ambience, music: { tracks, rules } } with the dropped rules gone.
82
+ */
83
+ export function packAudio(audio, data, from) {
84
+ checkOptions(`content ${from} audio`, data, PACK_KEYS);
85
+ const music = data.music || {};
86
+ checkOptions(`content ${from} audio.music`, music, ['tracks', 'rules']);
87
+ const tables = { sounds: data.sounds, footsteps: data.footsteps, tracks: music.tracks };
88
+ for (const [table, map] of Object.entries(tables)) for (const name of Object.keys(map || {}))
89
+ if (audio._code[table].has(name)) throw codedError('audio-name-clash', fmt(STRINGS.codeToo, { table: table === 'tracks' ? 'music.tracks' : table, name, from }));
90
+ if (DEV) {
91
+ const path = (what, src) => { if (typeof src === 'string' && PATH.test(src)) warnOnce(fmt(STRINGS.path, { from, what, src, short: src.split(/[/\\]/).pop().replace(/\.\w+$/, '') })); };
92
+ for (const [n, v] of Object.entries(data.sounds || {})) for (const s of srcsOf(v)) path(`sounds.${n}`, s);
93
+ for (const [n, t] of Object.entries(music.tracks || {})) for (const s of trackSrcs(t)) path(`music.tracks.${n}`, s);
94
+ }
95
+ // a dropped rule never plays: content is data, and a function there is a mistake the static check (content-check) reports as an error
96
+ const dataOnly = (list, what) => (list || []).filter((r, i) => {
97
+ if (!hasFn(r)) return true;
98
+ warnOnce(fmt(STRINGS.fn, { from, what: `${what}[${i}]` })); return false;
99
+ });
100
+ const sounds = Object.fromEntries(Object.entries(data.sounds || {}).filter(([n, v]) => !hasFn(v) || (warnOnce(fmt(STRINGS.fn, { from, what: `sounds.${n}` })), false)));
101
+ return { sounds, footsteps: { ...data.footsteps }, ambience: dataOnly(data.ambience, 'ambience'), music: { tracks: { ...music.tracks }, rules: dataOnly(music.rules, 'music.rules') } };
102
+ }
103
+
104
+ /** Re-apply every active duck to the bus duck nodes, fading over fade seconds (Audio._applyDucks) */
105
+ export function applyDucks(a, fade) {
106
+ if (!a.ctx) return;
107
+ const t = a.ctx.currentTime;
108
+ for (const [bus, node] of Object.entries(a._duckNodes)) {
109
+ let v = 1; for (const d of a._ducks) v *= d.levels[bus] ?? 1;
110
+ const g = node.gain; g.cancelScheduledValues(t);
111
+ if (fade > 0) { g.setValueAtTime(g.value, t); g.linearRampToValueAtTime(v, t + fade); } else g.value = v;
112
+ }
113
+ }
114
+
115
+ /** What is playing: bus levels, duck multipliers, live voices per sound name (Audio.info) */
116
+ export function audioInfo(a) {
117
+ const ducks = {}, voices = {};
118
+ for (const [b, n] of Object.entries(a._duckNodes)) ducks[b] = +n.gain.value.toFixed(3);
119
+ for (const [name, list] of a._voices) { const n = list.filter(v => v.playing).length; if (n) voices[name] = n; }
120
+ return { running: a.running, state: a.state, levels: { ...a.levels }, ducks, voices };
121
+ }