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,242 @@
1
+ // Weather: the game's table of weather types (weather({ types })); without one only a calm 'clear' (the engine assumes no climate).
2
+ // Seven temperate ones are an opt-in preset: weather(presets.weather.temperate), extend with types: { ...presets.weather.temperate.types, dust: {...} }.
3
+ // All fields blend smoothly on change.
4
+ // Affects: cloud shadows, sky color, sun intensity, fog distance, wind (plants sway), rain/snow particles, lightning, ambience.
5
+ // Particle and lightning looks: style.weather.rain / snow / lightning, engine.look.weather.replace (particles.js, recipes/44).
6
+ //
7
+ // engine.weather.set('rain', 20) // turn to rain over 20 seconds
8
+ // engine.weather.setAuto(true) // change weather at random (uses engine.random, so step/tests are reproducible and saved)
9
+ // Weather display names live in the string table as weather.<name> (describe and the debug panel use them); a game that adds a new weather adds its name with
10
+ // i18n.add.
11
+ import * as THREE from 'three';
12
+ import { checkOptions, warnMissing, warnOnce } from '../../core/validate.js';
13
+ import { readParams, keysSchema } from '../../core/params.js';
14
+ import { makeSystem, updateSystem, dropSystem, RAIN, SNOW } from './particles.js';
15
+ import { STRINGS, ERR } from './strings.js';
16
+ import { defineWeatherLook } from './look.js';
17
+ import { renamed } from '../../core/errorHints.js';
18
+ /** @import { ModuleDef } from '../../types/core' */
19
+ /** @import { WeatherName, WeatherPreset, WeatherOptions } from '../../types/world' */
20
+
21
+ // The table when the game gives none: one calm type, so engine.weather works without assuming rain, snow or storms exist
22
+ const ONLY_CLEAR = { clear: {} };
23
+ const STYLE_KEYS = ['area', 'overcastColor', 'lightningBrightness', 'lightning', 'rain', 'snow', 'types'];
24
+ const OPTIONS = ['start', 'auto', 'particles', 'types', 'autoPool', 'autoInterval', 'transition', 'area'];
25
+ const WEATHER_PARAMS = keysSchema(OPTIONS);
26
+ // Fields a type leaves out: calm (no cloud, rain, snow, grey or lightning; normal sun, fog and wind)
27
+ const CALM = { cloud: 0, sun: 1, fog: 1, wind: 1, rain: 0, snow: 0, grey: 0, lightning: 0 };
28
+ /** engine.weather */
29
+ export class Weather {
30
+ /**
31
+ * start: initial weather (default 'clear', or the table's first type); particles: rain/snow particle count; types: the game's weather table (default only a
32
+ * calm 'clear'; seven temperate ones in presets.weather.temperate)
33
+ * autoPool autoPool: candidates for automatic weather (repeat a name to make it likelier); autoInterval [min, max] seconds
34
+ * @internal
35
+ */
36
+ constructor(engine, { start, particles = 6000, types, autoPool, autoInterval = [90, 240], transition = 25, area } = {}) {
37
+ /** @internal */ this.engine = engine;
38
+ const st = engine.style.weather || {};
39
+ checkOptions('style.weather', st, STYLE_KEYS);
40
+ // The game's table is the whole list (a desert game has no snow, a space station no rain); without one only a calm 'clear'.
41
+ // The style pack only fills fields of types the table has (its look of 'storm'), it never adds a kind of weather to a game.
42
+ if (types !== undefined && (!types || typeof types !== 'object' || !Object.keys(types).length)) throw new Error(ERR.types.replace('{got}', JSON.stringify(types)));
43
+ const table = types ?? ONLY_CLEAR;
44
+ /**
45
+ * The weather types this game has: name -> numbers (the standard fields plus any of the game's own, all blended on change) @type {Record<string,
46
+ * WeatherPreset>}
47
+ */
48
+ this.types = {};
49
+ for (const k of Object.keys(table)) {
50
+ // calm, then the style's look, then the game's own numbers (a preset the game picked counts as the game's)
51
+ const v = { ...CALM, ...(st.types?.[k] || {}), ...table[k] };
52
+ for (const f in v) if (typeof v[f] !== 'number') throw new Error(ERR.field.replace('{k}', k).replace('{f}', f).replace('{got}', JSON.stringify(v[f])));
53
+ this.types[k] = v;
54
+ }
55
+ // a game field one type has ('heat' on 'heatwave') is 0 on the others, so a change always blends between two numbers
56
+ for (const v of Object.values(this.types)) for (const o of Object.values(this.types)) for (const f in o) v[f] ??= 0;
57
+ start ??= this.types.clear ? 'clear' : Object.keys(this.types)[0];
58
+ if (!this.types[start]) throw new Error(ERR.start.replace('{got}', start).replace('{list}', Object.keys(this.types).join(', ')));
59
+ /** Current (mid-transition) weather parameters @type {WeatherPreset} */
60
+ this.current = { ...this.types[start] };
61
+ /** @internal */ this.from = { ...this.current };
62
+ /** @internal */ this.to = { ...this.current };
63
+ /** @internal */ this.t = 1;
64
+ /** @internal */ this.dur = 1;
65
+ /** Current weather name @type {string} */
66
+ this.name = start;
67
+ /** Automatic weather on/off @type {boolean} */
68
+ this.auto = false;
69
+ /** @internal */ this.autoTimer = 0;
70
+ /** Candidates for automatic weather (repeat a name to make it likelier) @type {string[]} */
71
+ this.autoPool = [...(autoPool || Object.keys(this.types))];
72
+ for (const k of this.autoPool) if (!this.types[k]) throw new Error(ERR.pool.replace('{got}', k).replace('{list}', Object.keys(this.types).join(', ')));
73
+ /** Automatic weather interval [min, max] seconds @type {number[]} */
74
+ this.autoInterval = autoInterval;
75
+ /** Transition seconds for automatic weather @type {number} */
76
+ this.autoTransition = transition;
77
+ /** @internal */ this.flashStrength = st.lightningBrightness ?? 1;
78
+ // lightning look: flash (1 at the strike, fading over a third of a second) -> how bright the sky flashes; default flickers
79
+ if (st.lightning !== undefined && typeof st.lightning !== 'function') throw new Error('style.weather.lightning must be a function (flash 0..1, engine) => sky flash amount, e.g. lightning: f => f * 0.6; return 0 and draw your own bolt on the weather:lightning event');
80
+ /** @internal */ this.lightningLook = st.lightning ?? (f => f * (Math.random() > 0.3 ? 1 : 0.4)); // presentation: flash flickers
81
+ /** @internal */ this.flash = 0;
82
+ /** @internal */ this.nextBolt = 5;
83
+ /** @internal */ this.grey = new THREE.Color(st.overcastColor ?? 0x8c8c8c);
84
+ /** @internal */ this._layer = { sun: 1, ambient: 1, fog: 1, tint: this.grey, tintAmount: 0, horizonTintAmount: 0, flash: 0 }; // reused every frame
85
+ /** Default particle count per system (halved on low-tier devices) @type {number} */
86
+ this.particles = engine.tier === 'low' ? Math.round(particles / 2) : particles;
87
+ /** @internal */ this.area = area ?? st.area ?? 40;
88
+ /** Particle systems drawn now: field -> { field, object, uniforms } (rain / snow when the table has them, plus define()) @type {Map<string, any>} */
89
+ this.systems = new Map();
90
+ // zero cost when unused: a table where nothing ever rains or snows builds no particle meshes
91
+ const { cover, ...snowLook } = st.snow || {};
92
+ for (const [k, base] of [['rain', RAIN], ['snow', SNOW]]) if (Object.values(this.types).some(v => v[k] > 0)) this._build(k, k === 'snow' ? snowLook : st[k] || {}, base);
93
+ // snow cover: foliage / ground season tint moves toward the snow colors as current.snow rises (sky layer cover, layers.js applyCover)
94
+ if (cover !== undefined) {
95
+ checkOptions('style.weather.snow.cover', cover, ['foliage', 'ground', 'strength']);
96
+ if (cover.foliage == null && cover.ground == null) throw new Error("style.weather.snow.cover needs a color for foliage and / or ground, e.g. cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 }");
97
+ /** @internal */ this._cover = { strength: cover.strength ?? 0.8 };
98
+ Object.assign(this._layer, { foliageCover: cover.foliage ?? null, groundCover: cover.ground ?? null, coverAmount: 0 });
99
+ }
100
+ defineWeatherLook(this); // look.weather: the style's rain / snow / lightning values are its style layer
101
+ }
102
+
103
+ /**
104
+ * Renamed in 0.2: throws and names the new call, engine.look.weather.replace({ [field]: spec }) (recipes/44-water-weather-look-hooks.md)
105
+ * @param {string} _field
106
+ * @param {import('../../types/style').StyleWeatherParticles} [_spec]
107
+ * @returns {never}
108
+ */
109
+ define(_field, _spec) { return renamed('weatherDefine'); }
110
+
111
+ /** @internal */
112
+ _build(field, spec, base) {
113
+ const old = this.systems.get(field);
114
+ if (old) dropSystem(this.engine, old);
115
+ const sys = makeSystem(this.engine, field, spec, { area: this.area, count: this.particles, base });
116
+ this.systems.set(field, sys);
117
+ return sys;
118
+ }
119
+
120
+ /**
121
+ * Automatic weather on/off
122
+ * @param {boolean} on
123
+ * @returns {void}
124
+ */
125
+ setAuto(on) { this.auto = on; if (on) this.autoTimer = 0; }
126
+
127
+ /**
128
+ * Switch weather. seconds: transition seconds, default 15
129
+ * @param {WeatherName} name
130
+ * @param {number} [seconds]
131
+ * @returns {void}
132
+ */
133
+ set(name, seconds = 15) {
134
+ const p = this.types[name];
135
+ if (!p) { warnMissing('weather', name, Object.keys(this.types)); return; }
136
+ const from = this.name;
137
+ this.name = name; this.from = { ...this.current }; this.to = { ...p }; this.t = 0; this.dur = Math.max(0.01, seconds);
138
+ // once per change of name (the blend then runs over `seconds`); setting the same weather again is not a change
139
+ if (from !== name) this.engine.events.emit('weather:change', { from, to: name });
140
+ }
141
+ /**
142
+ * Display name of a weather (string table weather.<name>, falls back to the name itself); defaults to the current weather
143
+ * @param {string} [name]
144
+ * @returns {string}
145
+ */
146
+ label(name = this.name) { const k = 'weather.' + name; return this.engine.i18n.has(k) ? this.engine.t(k) : name; }
147
+
148
+ // fixed step: transitions, automatic weather, lightning (gameplay-relevant randomness all uses engine.random)
149
+ /**
150
+ * Advance weather transition, automatic weather and lightning (the module calls this itself every fixed step)
151
+ * @param {number} dt
152
+ * @param {boolean} [quiet] true during engine.skip: same state changes, no lightning event (nobody saw it)
153
+ * @returns {void}
154
+ * @internal
155
+ */
156
+ tick(dt, quiet = false) {
157
+ const rnd = this.engine.random;
158
+ if (this.t < 1) {
159
+ this.t = Math.min(1, this.t + dt / this.dur);
160
+ const k = this.t * this.t * (3 - 2 * this.t);
161
+ for (const key in this.to) this.current[key] = this.from[key] + (this.to[key] - this.from[key]) * k;
162
+ }
163
+ if (this.auto) {
164
+ this.autoTimer -= dt;
165
+ if (this.autoTimer <= 0) {
166
+ this.autoTimer = rnd.range(this.autoInterval[0], this.autoInterval[1]);
167
+ this.set(rnd.pick(this.autoPool), this.autoTransition);
168
+ }
169
+ }
170
+ if (this.current.lightning > 0.5) {
171
+ this.nextBolt -= dt;
172
+ if (this.nextBolt <= 0) { this.flash = 1; this.nextBolt = rnd.range(6, 20); if (!quiet) this.engine.events.emit('weather:lightning'); }
173
+ }
174
+ this.flash = Math.max(0, this.flash - dt * 3);
175
+ }
176
+
177
+ // per frame (before sky): weather effects go into the sky's 'weather' modifier layer, which sky composites with the others; rain/snow particles follow the
178
+ // camera
179
+ /**
180
+ * Write weather effects into the sky modifier layer and make rain/snow particles follow the camera (the module calls this itself every frame)
181
+ * @param {any} camera
182
+ * @returns {void}
183
+ * @internal
184
+ */
185
+ apply(camera) {
186
+ const c = this.current, L = this._layer;
187
+ const U = this.engine.uniforms, t = this.engine.elapsed;
188
+ U.uCloud.value = c.cloud;
189
+ U.uWind.value = c.wind;
190
+ L.sun = c.sun; L.ambient = 0.75 + 0.25 * c.sun; L.fog = c.fog;
191
+ L.tintAmount = c.grey; L.horizonTintAmount = c.grey * 0.8;
192
+ L.flash = this.flash > 0 ? this.lightningLook(this.flash, this.engine) * this.flashStrength : 0;
193
+ if (this._cover) L.coverAmount = (c.snow ?? 0) * this._cover.strength;
194
+ this.engine.sky.modify('weather', L); // weather depends on sky (requires), so it is always present
195
+ for (const sys of this.systems.values()) updateSystem(sys, c[sys.field] ?? 0, camera, t, c.wind);
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Weather → engine.weather (install sky first)
201
+ * @param {WeatherOptions} [opts]
202
+ * @returns {ModuleDef<Weather>}
203
+ */
204
+ export function weather(opts = {}) {
205
+ readParams('weather', WEATHER_PARAMS, opts);
206
+ let w = null;
207
+ return {
208
+ name: 'weather', label: 'Weather', params: WEATHER_PARAMS, options: opts, requires: ['sky'], stage: 'environment', before: ['sky'],
209
+ install(e) {
210
+ e.i18n.add(STRINGS);
211
+ w = new Weather(e, opts);
212
+ e.audio.condition('weather', v => [].concat(v).includes(w.name)); // audio rule condition { weather: 'rain' | ['rain', 'storm'] }
213
+ for (const k of ['rain', 'snow', 'wind']) e.audio.measure(k, () => w.current[k]); // data rules: { rain: { lt: 0.2 } }, volume add: { rain: 0.22 }
214
+ if (opts.auto) w.auto = true;
215
+ e.audio.register('thunder', (audio, p, out) => { const dur = p.duration ?? 3.5, delay = 0.4 + Math.random() * 1.5; // presentation: thunder delay
216
+ audio.noiseBurst({ type: 'lowpass', freq: p.freq ?? 140, vol: p.volume ?? 0.9, dur, rate: 0.4 * p.pitch, delay, out }); return delay + dur; },
217
+ { builtIn: true, bus: 'ambience' });
218
+ e.events.on('weather:lightning', () => e.audio.sfx('thunder'));
219
+ e.saves.register('weather', { save: () => ({ name: w.name, auto: w.auto, autoTimer: w.autoTimer, nextBolt: w.nextBolt }),
220
+ load: d => { if (!d) return; w.set(d.name, 0.01); w.auto = d.auto; w.autoTimer = d.autoTimer ?? 0; w.nextBolt = d.nextBolt ?? 5; } });
221
+ return w;
222
+ },
223
+ fixed(dt) { w.tick(dt); },
224
+ // engine.skip: fixed hooks do not run, so the skipped fixed steps are replayed here without events (a bolt nobody saw)
225
+ skip(dt) { // replay the fixed steps (same random draws, same order as stepping, so checkSkip matches); nothing pending = nothing to replay
226
+ if (w.t >= 1 && !w.auto && !(w.current.lightning > 0.5)) return;
227
+ for (let n = Math.round(dt * 60); n > 0; n--) w.tick(1 / 60, true); // 60 = the engine's fixed steps per second
228
+ },
229
+ frame(dt, e) { w.apply(e.camera); },
230
+ // scenario param weather: switch to this weather at once (no transition) and turn off automatic weather, so the scene is reproducible
231
+ applyState(e, { weather: name }) {
232
+ if (!name) return;
233
+ w.set(name, 0.01); w.auto = false;
234
+ if (w.name === name) { w.current = { ...w.to }; w.t = 1; }
235
+ },
236
+ describe() {
237
+ const c = w.current, r = v => Math.round(v * 100) / 100;
238
+ return { name: w.name, label: w.label(), progress: r(w.t), auto: w.auto, rain: r(c.rain), snow: r(c.snow), fog: r(c.fog), wind: r(c.wind),
239
+ cloud: r(c.cloud), lightning: r(c.lightning), rainVisible: !!w.systems.get('rain')?.object.visible, snowVisible: !!w.systems.get('snow')?.object.visible };
240
+ },
241
+ };
242
+ }
@@ -0,0 +1,75 @@
1
+ // look.weather: rain / snow particles, lightning flash and the overcast color as a look part (recipes/52-look.md).
2
+ // set({ 'rain.color', 'rain.speed', 'snow.size', 'lightning.brightness', overcastColor ... }) rebuilds that field's particle system once (a few ms)
3
+ // patch('rain.vertex' | 'rain.fragment' | 'snow.vertex' | 'snow.fragment', glsl) the WHOLE shader text, not a function (see shaders.js)
4
+ // replace({ rain: spec, ash: spec }) spec = the keys of style.weather.rain or { create(engine, { area, count }) => { object, update } }; null gives back
5
+ // The old engine.weather call with a field name was renamed in 0.2 (it throws): use replace({ [field]: spec }).
6
+ // Why the shader stays whole (decision #9): the rain / snow shaders move vertices and size points; a function hook would hide most of that.
7
+ import { defineLookPart, REPLACE } from '../../core/look/part.js';
8
+ import { warnOnce } from '../../core/validate.js';
9
+ import { RAIN, SNOW, dropSystem } from './particles.js';
10
+
11
+ const WHY = { rain: 'built-in rain: streaks drawn while a weather type has rain > 0', snow: 'built-in snow: flakes drawn while a weather type has snow > 0' };
12
+ const OFF = { rain: "leave 'rain' out of the weather table (no particles are built), or look.weather.set({ 'rain.opacity': 0 })", snow: "leave 'snow' out of the weather table, or look.weather.set({ 'snow.opacity': 0 })" };
13
+ const KEYS = { rain: ['color', 'opacity', 'length', 'speed', 'slant'], snow: ['color', 'opacity', 'size', 'speed', 'sway'] };
14
+ const BASE = { rain: RAIN, snow: SNOW };
15
+ const FIELDS = ['rain', 'snow'], STAGES = ['vertex', 'fragment'];
16
+
17
+ /** { 'rain.color': { type, default, why, off } ... } built from the particle defaults, so the numbers live in one place (particles.js) */
18
+ const rows = () => Object.fromEntries(FIELDS.flatMap(f => KEYS[f].map(k => [`${f}.${k}`,
19
+ { type: k === 'color' ? 'any' : 'number', default: BASE[f][k], ...(k === 'color' ? {} : { min: 0 }), cost: 'gpu', why: WHY[f], off: OFF[f] }])));
20
+
21
+ /** @param {any} w the Weather module */
22
+ export function defineWeatherLook(w) {
23
+ const e = w.engine, st = e.style.weather ?? {}, { cover, ...snowStyle } = st.snow ?? {};
24
+ const styleSpec = f => (f === 'snow' ? snowStyle : st[f] ?? {});
25
+ let applied = {}; // fields a replace() holds now: field -> spec
26
+ const rebuild = f => {
27
+ if (applied[f]) return; // replace() owns this field
28
+ if (!w.systems.has(f)) { warnOnce(`look.weather: this game's weather table has no ${f}, so there are no ${f} particles to change; add a type with ${f}: 1 to weather({ types })`); return; }
29
+ const v = p.values(), s = styleSpec(f), g = { ...s.glsl };
30
+ for (const h of STAGES) { const x = p.value(`hook:${f}.${h}`); if (x) g[h] = x; }
31
+ w._build(f, { ...s, ...Object.fromEntries(KEYS[f].map(k => [k, v[`${f}.${k}`]])), ...(Object.keys(g).length ? { glsl: g } : {}) }, BASE[f]);
32
+ };
33
+ const p = defineLookPart(e, {
34
+ id: 'weather', group: 'dynamic', module: 'weather', object: () => w.systems, docs: ['recipes/52-look.md'], applyAtStart: false,
35
+ params: {
36
+ ...rows(),
37
+ 'lightning.brightness': { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'how bright the sky flashes at a strike' },
38
+ overcastColor: { type: 'any', default: 0x8c8c8c, cost: 'uniform', why: 'sky and fog turn this gray as a weather type raises grey', off: 'weather types with grey: 0 never use it' },
39
+ },
40
+ style: () => ({
41
+ ...Object.fromEntries(FIELDS.flatMap(f => KEYS[f].filter(k => styleSpec(f)[k] !== undefined).map(k => [`${f}.${k}`, styleSpec(f)[k]]))),
42
+ ...Object.fromEntries(FIELDS.flatMap(f => STAGES.filter(h => styleSpec(f).glsl?.[h]).map(h => [`hook:${f}.${h}`, styleSpec(f).glsl[h]]))),
43
+ 'lightning.brightness': st.lightningBrightness, overcastColor: st.overcastColor,
44
+ }),
45
+ read: () => ({}),
46
+ apply(v, changed) {
47
+ if (changed.has('lightning.brightness')) w.flashStrength = v['lightning.brightness'];
48
+ if (changed.has('overcastColor')) w.grey.set(v.overcastColor);
49
+ for (const f of FIELDS) if ([...changed].some(k => k.startsWith(f + '.'))) rebuild(f);
50
+ },
51
+ hooks: Object.fromEntries(FIELDS.flatMap(f => STAGES.map(h => [`${f}.${h}`, { signature: 'whole GLSL shader text (copy it from modules/weather/shaders.js)', scope: ['uCam', 'uSize', 'uFallOff', 'uOpacity', 'uColor'] }]))),
52
+ applyHook(name) { rebuild(name.split('.')[0]); },
53
+ replace: { accepts: '{ <field>: spec } with spec = the keys of style.weather.rain, or { create(engine, { area, count }) => { object, update?(amount, ctx) } }; null gives the fields back',
54
+ loses: ['the style rain / snow look of every field named in the object (look.weather.set values for it are ignored while it holds)'] },
55
+ // a wrong replace value stops here, before any layer is written (the throw used to come from applyReplace, after the write)
56
+ validate: (k, v) => {
57
+ if (k !== REPLACE) return null;
58
+ if (v != null && (typeof v !== 'object' || Array.isArray(v))) return "is { <field>: spec }, e.g. replace({ ash: { shape: 'soft', color: 0x555555 } }); see recipes/44-water-weather-look-hooks.md";
59
+ const fields = [...new Set(Object.values(w.types).flatMap(t => Object.keys(t)))], bad = Object.keys(v ?? {}).find(f => !fields.includes(f));
60
+ return bad ? `no weather type has a field '${bad}'; add it to a type in weather({ types }) (e.g. ashfall: { ${bad}: 1 }), or use one of ${fields.join(', ')}` : null;
61
+ },
62
+ applyReplace(impl) {
63
+ const next = impl ?? {}, old = applied;
64
+ applied = next;
65
+ for (const f of new Set([...Object.keys(old), ...Object.keys(next)])) {
66
+ if (next[f] && next[f] === old[f]) continue; // unchanged: keep the system (and any handle the game holds)
67
+ if (next[f]) w._build(f, next[f], BASE[f]);
68
+ else if (BASE[f]) rebuild(f);
69
+ else { const s = w.systems.get(f); if (s) { dropSystem(e, s); w.systems.delete(f); } }
70
+ }
71
+ },
72
+ });
73
+ return p;
74
+ }
75
+
@@ -0,0 +1,92 @@
1
+ // Weather particle systems (recipes/44). Built-in rain and snow are two specs of one falling-particle system; a game draws a field of its
2
+ // own table (ash, petals, sparks) with engine.look.weather.replace({ field: spec }), and the same call replaces rain or snow. The amount each frame is
3
+ // weather.current[field], so the table's smooth blending drives particles too.
4
+ //
5
+ // spec (style.weather.rain / snow, or define): shape 'line' (streaks that slant with the wind) | 'round' | 'soft' | 'square' (point sprites
6
+ // that drift), texture (asset name, sprites only), color, opacity, size / maxSize (sprite size and pixel cap), length (line meters),
7
+ // speed (fall m/s), slant (line lean per unit of wind), sway (sprite drift meters), count, density (amount 0..1 -> share of particles drawn),
8
+ // glsl: { vertex, fragment } (whole shader text; copy from shaders.js), uniforms (for your glsl);
9
+ // or create(engine, { area, count }) => { object, update?(amount, ctx) } for a system of your own (the engine adds it, shows it while the
10
+ // amount is above 0.02 and calls update every frame with ctx = { camera, time, wind }).
11
+ import * as THREE from 'three';
12
+ import { checkOptions, closest, warnOnce } from '../../core/validate.js';
13
+ import { declareUniforms } from '../../render/uniformDecl.js';
14
+ import { lineVert, lineFrag, pointVert, pointFrag, SHAPES, shaderMat, scatter } from './shaders.js';
15
+
16
+ const SPEC_KEYS = ['shape', 'texture', 'color', 'opacity', 'size', 'maxSize', 'length', 'speed', 'slant', 'sway', 'count', 'density', 'glsl', 'uniforms', 'create'];
17
+ const SHAPE_LIST = ['line', ...Object.keys(SHAPES)];
18
+ // The built-in looks (a style's weather.rain / snow fills in over them); a defined field starts from DRIFT
19
+ export const RAIN = { shape: 'line', color: 0xc8c8c8, opacity: 0.55, length: 0.7, speed: 22, slant: 1, size: 14, maxSize: 8, sway: 1.5, density: a => Math.min(1, a * 1.2) };
20
+ export const SNOW = { shape: 'round', color: 0xffffff, opacity: 0.9, size: 20, maxSize: 5, speed: 1.6, sway: 1.5, density: () => 1 };
21
+ const DRIFT = { ...SNOW, opacity: 1 };
22
+
23
+ /**
24
+ * Build one particle system for a weather field and add it to the scene (hidden until its amount rises)
25
+ * @internal
26
+ * @param {any} engine
27
+ * @param {string} field
28
+ * @param {Record<string, any>} spec the given keys (checked here) over the defaults
29
+ * @param {{ area: number, count: number, base?: Record<string, any> }} ctx
30
+ */
31
+ export function makeSystem(engine, field, spec, { area, count, base = DRIFT }) {
32
+ const where = `weather particles '${field}'`;
33
+ checkOptions(where, spec, SPEC_KEYS);
34
+ const s = { ...base, ...spec, shape: spec.shape ?? (spec.texture ? 'round' : base.shape) };
35
+ const n = Math.max(1, Math.round(spec.count ? (engine.tier === 'low' ? spec.count / 2 : spec.count) : count));
36
+ if (s.create) {
37
+ const own = s.create(engine, { area, count: n });
38
+ if (!own?.object?.isObject3D) throw new Error(`${where}: create must return { object: THREE.Object3D, update?(amount, { camera, time, wind }) }`);
39
+ return finish(engine, field, { field, object: own.object, uniforms: null, update: own.update?.bind(own) ?? null, own: true });
40
+ }
41
+ if (!SHAPE_LIST.includes(s.shape)) throw new Error(`${where}: shape '${s.shape}' must be ${SHAPE_LIST.map(k => `'${k}'`).join(' | ')}` + (closest(s.shape, SHAPE_LIST) ? ` (did you mean '${closest(s.shape, SHAPE_LIST)}'?)` : ''));
42
+ if (typeof s.density !== 'function') throw new Error(`${where}: density must be a function amount (0..1) => share of particles drawn (0..1), e.g. density: a => a * a`);
43
+ const line = s.shape === 'line', custom = declareUniforms(`${where}.uniforms`, s.uniforms);
44
+ const u = { uCam: { value: new THREE.Vector3() }, uSize: { value: area }, uFallOff: { value: 0 }, uOpacity: { value: 0 }, uColor: { value: new THREE.Color(s.color) }, ...custom.uniforms };
45
+ const geo = new THREE.BufferGeometry(), p3 = scatter(n * 3, area);
46
+ if (line) {
47
+ // each streak is two vertices at the same point; aEnd marks the tail the shader pulls back along the fall
48
+ const rp = new Float32Array(n * 6), re = new Float32Array(n * 2);
49
+ for (let i = 0; i < n; i++) { rp.set(p3.subarray(i * 3, i * 3 + 3), i * 6); rp.set(p3.subarray(i * 3, i * 3 + 3), i * 6 + 3); re[i * 2 + 1] = 1; }
50
+ geo.setAttribute('position', new THREE.BufferAttribute(rp, 3)); geo.setAttribute('aEnd', new THREE.BufferAttribute(re, 1));
51
+ Object.assign(u, { uWindDir: { value: new THREE.Vector2(1, 0.3) }, uLen: { value: s.length } });
52
+ } else {
53
+ geo.setAttribute('position', new THREE.BufferAttribute(p3, 3));
54
+ Object.assign(u, { uPx: { value: s.size }, uMaxPx: { value: s.maxSize }, uSway: { value: 0 }, uSwayAmp: { value: s.sway }, uMap: { value: null }, uUseMap: { value: 0 } });
55
+ if (s.texture) engine.assets.texture(s.texture).then(t => { u.uMap.value = t; u.uUseMap.value = 1; }).catch(err => warnOnce(err.message));
56
+ }
57
+ const g = s.glsl || {};
58
+ if (s.glsl !== undefined) checkOptions(`${where}.glsl`, g, ['vertex', 'fragment']);
59
+ const vert = g.vertex ?? (line ? lineVert : pointVert), frag = g.fragment ?? (line ? lineFrag : pointFrag(s.shape));
60
+ const mat = shaderMat(custom.decl ? custom.decl + '\n' + vert : vert, custom.decl ? custom.decl + '\n' + frag : frag, u);
61
+ const object = line ? new THREE.LineSegments(geo, mat) : new THREE.Points(geo, mat);
62
+ return finish(engine, field, { field, object, uniforms: u, spec: s, count: n, line, update: null, own: false });
63
+ }
64
+
65
+ function finish(engine, field, sys) {
66
+ const o = sys.object;
67
+ o.frustumCulled = false; o.visible = false; o.userData.budgetTag = 'weather'; o.name ||= 'weather-' + field;
68
+ engine.scene.add(o);
69
+ return sys;
70
+ }
71
+
72
+ /**
73
+ * Per frame: amount = weather.current[field]; falling particles follow the camera, fall and drift with wrapped time (see shaders.js)
74
+ * @internal
75
+ */
76
+ export function updateSystem(sys, amount, camera, t, wind) {
77
+ sys.object.visible = amount > 0.02;
78
+ if (sys.own) { sys.update?.(amount, { camera, time: t, wind }); return; }
79
+ const u = sys.uniforms, s = sys.spec;
80
+ u.uFallOff.value = (t * s.speed) % u.uSize.value;
81
+ u.uCam.value.copy(camera.position);
82
+ u.uOpacity.value = amount * s.opacity;
83
+ sys.object.geometry.setDrawRange(0, Math.floor(sys.count * Math.min(1, Math.max(0, s.density(amount)))) * (sys.line ? 2 : 1));
84
+ if (sys.line) u.uWindDir.value.set(wind * s.slant, wind * s.slant * 0.3);
85
+ else u.uSway.value = t % (20 * Math.PI);
86
+ }
87
+
88
+ /** Remove a system's object and free its GPU data @internal */
89
+ export function dropSystem(engine, sys) {
90
+ engine.scene.remove(sys.object);
91
+ if (!sys.own) { sys.object.geometry.dispose(); sys.object.material.dispose(); }
92
+ }
@@ -0,0 +1,49 @@
1
+ // Weather particle shaders: lines (rain streaks; position loops downward in the shader, zero CPU cost) and point sprites (snow, textured
2
+ // drops, a game's own particles). Time arrives already wrapped on the CPU (uFallOff = fall distance mod area size, uSway = time mod 20π,
3
+ // the common period of the drift), so drops do not jitter from float32 precision in multi-hour sessions. Colors go through tone mapping
4
+ // and the output color space like three's own materials, so rain looks the same with and without post-processing.
5
+ // A style replaces either text with weather.<type>.glsl.vertex / fragment (recipes/44); copy these as the starting point.
6
+ import * as THREE from 'three';
7
+
8
+ export const lineVert = `uniform vec3 uCam; uniform float uSize; uniform float uFallOff; uniform vec2 uWindDir; uniform float uLen; attribute float aEnd;
9
+ varying float vA;
10
+ void main(){
11
+ vec3 p = position;
12
+ float fall = mod(p.y - uFallOff, uSize);
13
+ vec3 w = vec3(mod(p.x - uCam.x + uWindDir.x * fall * 0.3, uSize) - uSize*0.5, fall - uSize*0.35, mod(p.z - uCam.z + uWindDir.y * fall * 0.3, uSize) - uSize*0.5);
14
+ w += uCam;
15
+ w.y -= aEnd * uLen; w.x -= aEnd * uWindDir.x * 0.2; w.z -= aEnd * uWindDir.y * 0.2;
16
+ vA = 1.0 - aEnd * 0.8;
17
+ gl_Position = projectionMatrix * viewMatrix * vec4(w, 1.0);
18
+ }`;
19
+ export const lineFrag = `uniform float uOpacity; uniform vec3 uColor; varying float vA;
20
+ void main(){
21
+ gl_FragColor = vec4(uColor, uOpacity * vA);
22
+ #include <tonemapping_fragment>
23
+ #include <colorspace_fragment>
24
+ }`;
25
+ export const pointVert = `uniform vec3 uCam; uniform float uSize; uniform float uPx; uniform float uMaxPx; uniform float uFallOff; uniform float uSway; uniform float uSwayAmp;
26
+ void main(){
27
+ vec3 p = position;
28
+ float fall = mod(p.y - uFallOff, uSize);
29
+ vec3 w = vec3(mod(p.x - uCam.x + sin(uSway*0.7 + p.y)*uSwayAmp, uSize) - uSize*0.5, fall - uSize*0.35, mod(p.z - uCam.z + cos(uSway*0.5 + p.x)*uSwayAmp, uSize) - uSize*0.5) + uCam;
30
+ vec4 mv = viewMatrix * vec4(w, 1.0);
31
+ gl_PointSize = min(uPx * 3.0 / -mv.z, uMaxPx);
32
+ gl_Position = projectionMatrix * mv;
33
+ }`;
34
+ // sprite alpha by shape (d = offset from the sprite center, |d| <= 0.5); a texture, when there is one, replaces the shape
35
+ export const SHAPES = { round: 'step(dot(d,d), 0.25)', soft: '1.0 - smoothstep(0.0, 0.25, dot(d,d))', square: '1.0' };
36
+ export const pointFrag = (shape = 'round') => `uniform float uOpacity; uniform vec3 uColor; uniform sampler2D uMap; uniform float uUseMap;
37
+ void main(){
38
+ vec2 d = gl_PointCoord - 0.5;
39
+ vec4 c = uUseMap > 0.5 ? texture2D(uMap, gl_PointCoord) : vec4(1.0, 1.0, 1.0, ${SHAPES[shape]});
40
+ if (c.a < 0.05) discard;
41
+ gl_FragColor = vec4(uColor * c.rgb, uOpacity * c.a);
42
+ #include <tonemapping_fragment>
43
+ #include <colorspace_fragment>
44
+ }`;
45
+
46
+ /** Particle shader material (transparent, no depth write) */
47
+ export const shaderMat = (vertexShader, fragmentShader, uniforms) => new THREE.ShaderMaterial({ vertexShader, fragmentShader, uniforms, transparent: true, depthWrite: false });
48
+ /** Initial particle positions: presentation only, no effect on gameplay */
49
+ export const scatter = (n, size) => { const a = new Float32Array(n); for (let i = 0; i < n; i++) a[i] = Math.random() * size; return a; }; // presentation
@@ -0,0 +1,15 @@
1
+ // Weather display names (string table weather.<name>); a game that adds a weather adds its name with i18n.add.
2
+ export const STRINGS = {
3
+ 'zh-CN': { 'weather.clear': '晴', 'weather.cloudy': '多云', 'weather.overcast': '阴', 'weather.rain': '雨', 'weather.storm': '暴雨',
4
+ 'weather.snow': '雪', 'weather.fog': '雾', 'weather.auto': '自动变化' },
5
+ en: { 'weather.clear': 'Clear', 'weather.cloudy': 'Cloudy', 'weather.overcast': 'Overcast', 'weather.rain': 'Rain', 'weather.storm': 'Storm',
6
+ 'weather.snow': 'Snow', 'weather.fog': 'Fog', 'weather.auto': 'Auto' },
7
+ };
8
+
9
+ // Errors of weather() / the weather table
10
+ export const ERR = {
11
+ types: "weather({ types }): the game's weather table, name -> { cloud, sun, fog, wind, rain, snow, grey, lightning } (left-out fields are calm), at least one; got {got}. Seven temperate ones: weather(presets.weather.temperate) with presets from 'threedog'",
12
+ field: "weather type '{k}': field {f} must be a number (every field blends smoothly on change); got {got}",
13
+ start: "weather({ start }): '{got}' is not one of this game's weather types ({list})",
14
+ pool: "weather({ autoPool }): '{got}' is not one of this game's weather types ({list})",
15
+ };