threedog 0.2.1 → 0.7.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 (725) hide show
  1. package/CHANGELOG.md +371 -1
  2. package/README.md +21 -12
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +92 -26
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +30 -15
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +40 -19
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +75 -25
  11. package/core/Describe.js +105 -45
  12. package/core/Engine.js +203 -75
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +175 -80
  16. package/core/Inspect.js +8 -5
  17. package/core/InspectMaterials.js +84 -0
  18. package/core/InspectPerf.js +68 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/MaterialInfo.js +7 -5
  22. package/core/Ops.js +50 -9
  23. package/core/Random.js +9 -2
  24. package/core/Rays.js +12 -7
  25. package/core/SaveStore.js +41 -9
  26. package/core/Saves.js +71 -15
  27. package/core/Stream.js +13 -10
  28. package/core/Threads.js +26 -7
  29. package/core/UrlState.js +69 -13
  30. package/core/Views.js +10 -6
  31. package/core/actor.js +1 -1
  32. package/core/adaptive.js +93 -0
  33. package/core/assetEntry.js +27 -7
  34. package/core/assetHot.js +176 -0
  35. package/core/assetLoad.js +44 -19
  36. package/core/assetManifest.js +53 -11
  37. package/core/assetReport.js +5 -5
  38. package/core/audioRules.js +13 -11
  39. package/core/audioVoice.js +69 -42
  40. package/core/batchGroups.js +9 -1
  41. package/core/canvasBox.js +1 -2
  42. package/core/catalog.js +21 -5
  43. package/core/cells.js +62 -0
  44. package/core/checks.js +10 -8
  45. package/core/chunkStream.js +87 -0
  46. package/core/control.js +149 -0
  47. package/core/copies.js +32 -0
  48. package/core/dayTime.js +12 -6
  49. package/core/debugView.js +85 -18
  50. package/core/describeRender.js +117 -21
  51. package/core/describeText.js +41 -21
  52. package/core/engineCamera.js +32 -0
  53. package/core/errorCodes.js +478 -32
  54. package/core/errorHints.js +41 -142
  55. package/core/errors.js +31 -8
  56. package/core/events.generated.js +13 -7
  57. package/core/gameLights.js +69 -0
  58. package/core/grayMap.js +20 -0
  59. package/core/grid.js +14 -13
  60. package/core/gridLoad.js +2 -1
  61. package/core/ground.js +6 -4
  62. package/core/headlessLoad.js +55 -0
  63. package/core/holds.js +78 -50
  64. package/core/inputContext.js +11 -7
  65. package/core/inputDefaults.js +24 -21
  66. package/core/inputPad.js +1 -1
  67. package/core/inputPointer.js +1 -1
  68. package/core/inputTouch.js +2 -2
  69. package/core/lifecycle.js +46 -12
  70. package/core/lightWatch.js +9 -5
  71. package/core/loop.js +109 -43
  72. package/core/math.js +18 -3
  73. package/core/moduleSlots.js +100 -0
  74. package/core/moduleTypes.js +86 -0
  75. package/core/modules.js +147 -29
  76. package/core/movement.js +2 -2
  77. package/core/namedModel.js +74 -0
  78. package/core/opsCheck.js +3 -3
  79. package/core/opsFail.js +15 -6
  80. package/core/opsGuard.js +4 -4
  81. package/core/opsRun.js +4 -3
  82. package/core/owned.js +171 -0
  83. package/core/page.js +44 -10
  84. package/core/params.js +30 -8
  85. package/core/pictureSlots.js +33 -0
  86. package/core/pictureWriters.js +343 -0
  87. package/core/plugins.js +245 -0
  88. package/core/saveApply.js +99 -17
  89. package/core/saveFiles.js +8 -6
  90. package/core/saveValues.js +46 -0
  91. package/core/saveVersions.js +20 -3
  92. package/core/scatter.js +48 -19
  93. package/core/sceneDelta.js +211 -0
  94. package/core/sceneMethods.js +31 -33
  95. package/core/screenToGround.js +1 -1
  96. package/core/services.js +27 -11
  97. package/core/session.js +28 -25
  98. package/core/shaderCost.js +78 -0
  99. package/core/shadowTypes.js +3 -2
  100. package/core/shadows.js +405 -0
  101. package/core/sharedPoint.js +303 -0
  102. package/core/skip.js +36 -28
  103. package/core/stackFrames.js +45 -0
  104. package/core/stacks.js +166 -0
  105. package/core/startup.js +153 -13
  106. package/core/streamSources.js +0 -11
  107. package/core/targeting.js +1 -1
  108. package/core/textureBytes.js +20 -0
  109. package/core/thingExplain.js +3 -3
  110. package/core/thingOps.js +29 -6
  111. package/core/things.js +22 -12
  112. package/core/threadPure.js +7 -3
  113. package/core/threePatches.js +47 -0
  114. package/core/tier.js +21 -10
  115. package/core/time.js +236 -0
  116. package/core/uiClock.js +25 -0
  117. package/core/util.js +8 -2
  118. package/core/validate.js +66 -87
  119. package/core/view.js +43 -0
  120. package/core/wrap.js +106 -0
  121. package/docs/AI.md +95 -104
  122. package/docs/API.md +35 -31
  123. package/docs/CODEMAP.md +231 -176
  124. package/docs/COMMANDS.md +63 -39
  125. package/docs/CONVENTIONS.md +99 -31
  126. package/docs/MIGRATING-0.3.md +248 -0
  127. package/docs/MIGRATING-0.4.md +320 -0
  128. package/docs/MIGRATING-0.5.md +68 -0
  129. package/docs/MIGRATING-0.6.md +126 -0
  130. package/docs/MIGRATING-0.7.md +39 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +82 -28
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +15 -11
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/budget.md +4 -0
  137. package/docs/api/calendar.md +41 -0
  138. package/docs/api/cameraRig.md +16 -5
  139. package/docs/api/characters.md +41 -24
  140. package/docs/api/clock.md +6 -5
  141. package/docs/api/collision.md +10 -7
  142. package/docs/api/content.md +6 -4
  143. package/docs/api/dialogue.md +9 -9
  144. package/docs/api/engine.md +95 -65
  145. package/docs/api/events.md +20 -14
  146. package/docs/api/grids.md +10 -3
  147. package/docs/api/ground.md +1 -1
  148. package/docs/api/hud.md +5 -2
  149. package/docs/api/i18n.md +1 -1
  150. package/docs/api/input.md +13 -7
  151. package/docs/api/interactions.md +10 -6
  152. package/docs/api/inventory.md +17 -17
  153. package/docs/api/level.md +0 -2
  154. package/docs/api/lightPool.md +3 -1
  155. package/docs/api/music.md +1 -1
  156. package/docs/api/nav.md +3 -0
  157. package/docs/api/occlusion.md +5 -0
  158. package/docs/api/openWorld.md +2 -1
  159. package/docs/api/particles.md +6 -3
  160. package/docs/api/photo.md +0 -2
  161. package/docs/api/pickups.md +21 -0
  162. package/docs/api/post.md +8 -5
  163. package/docs/api/quests.md +2 -3
  164. package/docs/api/rigid.md +16 -14
  165. package/docs/api/saves.md +6 -4
  166. package/docs/api/settings.md +2 -3
  167. package/docs/api/sky.md +18 -49
  168. package/docs/api/stream.md +1 -1
  169. package/docs/api/terrain.md +16 -7
  170. package/docs/api/terrainDraw.md +12 -0
  171. package/docs/api/timeline.md +3 -4
  172. package/docs/api/tools.md +32 -15
  173. package/docs/api/triggers.md +7 -10
  174. package/docs/api/vegetation.md +17 -9
  175. package/docs/api/vegetationDraw.md +10 -0
  176. package/docs/api/water.md +9 -21
  177. package/docs/api/weather.md +10 -15
  178. package/docs/api/weatherDraw.md +10 -0
  179. package/docs/api/world.md +3 -2
  180. package/docs/recipes/01-new-game.md +52 -42
  181. package/docs/recipes/02-npc.md +24 -7
  182. package/docs/recipes/03-items-pickups.md +57 -22
  183. package/docs/recipes/04-quests.md +12 -5
  184. package/docs/recipes/05-props-bake.md +174 -22
  185. package/docs/recipes/06-clock-events.md +100 -52
  186. package/docs/recipes/07-flow-scenes-pause.md +50 -10
  187. package/docs/recipes/08-weather-sky.md +134 -37
  188. package/docs/recipes/09-materials-lights-models.md +185 -0
  189. package/docs/recipes/10-blender-level.md +16 -4
  190. package/docs/recipes/11-vehicles.md +67 -10
  191. package/docs/recipes/13-animation.md +23 -9
  192. package/docs/recipes/14-custom-module.md +63 -29
  193. package/docs/recipes/15-perf.md +31 -10
  194. package/docs/recipes/16-dev-bridge.md +74 -40
  195. package/docs/recipes/18-world.md +26 -14
  196. package/docs/recipes/19-shooting-picking.md +12 -10
  197. package/docs/recipes/20-content-actions-save.md +60 -18
  198. package/docs/recipes/21-camera.md +55 -17
  199. package/docs/recipes/22-shop-gold.md +3 -3
  200. package/docs/recipes/23-ops.md +17 -11
  201. package/docs/recipes/26-ui-parts.md +86 -13
  202. package/docs/recipes/27-net.md +11 -5
  203. package/docs/recipes/28-terrain.md +36 -3
  204. package/docs/recipes/29-grid.md +46 -19
  205. package/docs/recipes/30-templates.md +72 -15
  206. package/docs/recipes/31-audio.md +20 -12
  207. package/docs/recipes/32-action-game.md +51 -4
  208. package/docs/recipes/34-environment-lighting.md +108 -21
  209. package/docs/recipes/35-picture-from-reference.md +147 -0
  210. package/docs/recipes/36-sky-ground-plants.md +158 -0
  211. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
  212. package/docs/recipes/38-environment-hooks.md +67 -0
  213. package/docs/recipes/40-scene.md +114 -32
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surfaces.md +206 -0
  216. package/docs/recipes/44-water-weather-hooks.md +191 -0
  217. package/docs/recipes/45-cascaded-shadows.md +130 -23
  218. package/docs/recipes/46-blender-art-route.md +17 -20
  219. package/docs/recipes/47-island-snow-backdrop.md +13 -15
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +4 -4
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-around-the-picture.md +181 -0
  224. package/docs/recipes/53-ground-up-close.md +12 -12
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +124 -0
  227. package/docs/recipes/56-webgpu-tsl.md +303 -0
  228. package/docs/recipes/57-control.md +104 -0
  229. package/docs/recipes/58-input.md +60 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +70 -0
  232. package/docs/recipes/61-deploy.md +27 -0
  233. package/docs/recipes/62-picture-code.md +244 -0
  234. package/docs/recipes/63-third-person-start.md +77 -0
  235. package/docs/recipes/64-particles.md +35 -0
  236. package/examples/action/.threedog/content-index.json +1 -0
  237. package/examples/action/GAMEMAP.md +20 -14
  238. package/examples/action/assets.js +8 -0
  239. package/examples/action/content/actions.js +1 -1
  240. package/examples/action/content/audio.js +5 -5
  241. package/examples/action/main.js +12 -15
  242. package/examples/action/models.js +23 -24
  243. package/examples/action/picture/index.js +13 -0
  244. package/examples/action/picture/lights.js +35 -0
  245. package/examples/action/picture/materials.js +8 -0
  246. package/examples/action/picture/palette.js +33 -0
  247. package/examples/plain-picture/.threedog/content-index.json +1 -0
  248. package/examples/plain-picture/FINDINGS.md +53 -0
  249. package/examples/plain-picture/GAMEMAP.md +90 -0
  250. package/examples/plain-picture/main.js +48 -0
  251. package/examples/plain-picture/picture/index.js +21 -0
  252. package/examples/plain-picture/picture/lights.js +54 -0
  253. package/examples/plain-picture/picture/materials.js +24 -0
  254. package/examples/plain-picture/picture/palette.js +16 -0
  255. package/examples/plain-picture/picture/sky.js +37 -0
  256. package/examples/pullable.json +133 -0
  257. package/examples/rc2d/.threedog/content-index.json +1 -0
  258. package/examples/rc2d/GAMEMAP.md +88 -0
  259. package/examples/rc2d/README.md +57 -0
  260. package/examples/rc2d/main.js +55 -0
  261. package/examples/rc2d/picture/index.js +18 -0
  262. package/examples/rc2d/picture/lights.js +11 -0
  263. package/examples/rc2d/picture/materials.js +18 -0
  264. package/examples/rc2d/picture/palette.js +15 -0
  265. package/examples/rc2d/picture/post.js +11 -0
  266. package/examples/rc2d/rc2d.js +187 -0
  267. package/examples/rc2d/shaders.js +144 -0
  268. package/examples/sheepisland/.threedog/content-index.json +1 -0
  269. package/examples/sheepisland/GAMEMAP.md +22 -17
  270. package/examples/sheepisland/assets.js +5 -0
  271. package/examples/sheepisland/content/templates.js +1 -1
  272. package/examples/sheepisland/content/vegetation.js +3 -1
  273. package/examples/sheepisland/main.js +29 -18
  274. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  275. package/examples/sheepisland/picture/index.js +20 -0
  276. package/examples/sheepisland/picture/lights.js +34 -0
  277. package/examples/sheepisland/picture/materials.js +61 -0
  278. package/examples/sheepisland/picture/palette.js +60 -0
  279. package/examples/sheepisland/picture/sky.js +20 -0
  280. package/examples/sheepisland/views.js +1 -1
  281. package/examples/styletest/.threedog/content-index.json +1 -0
  282. package/examples/styletest/GAMEMAP.md +25 -22
  283. package/examples/styletest/assets.js +6 -0
  284. package/examples/styletest/content/templates.js +1 -1
  285. package/examples/styletest/content/vegetation.js +1 -1
  286. package/examples/styletest/main.js +25 -34
  287. package/examples/styletest/models.js +30 -30
  288. package/examples/styletest/params.js +2 -5
  289. package/examples/styletest/picture/env.js +38 -0
  290. package/examples/styletest/picture/index.js +16 -0
  291. package/examples/styletest/picture/lights.js +9 -0
  292. package/examples/styletest/picture/materials.js +28 -0
  293. package/examples/styletest/picture/palette.js +22 -0
  294. package/examples/techniques/contact-shadows/README.md +91 -0
  295. package/examples/techniques/contact-shadows/contactShadows.js +67 -0
  296. package/examples/techniques/contact-shadows/main.js +55 -0
  297. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  298. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  299. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  300. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  301. package/examples/techniques/day-night-grade/README.md +83 -0
  302. package/examples/techniques/day-night-grade/main.js +41 -0
  303. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  304. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  305. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  306. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  307. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  308. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  309. package/examples/techniques/interior-light/README.md +106 -0
  310. package/examples/techniques/interior-light/interiorLight.js +47 -0
  311. package/examples/techniques/interior-light/main.js +87 -0
  312. package/examples/techniques/interior-light/picture/index.js +24 -0
  313. package/examples/techniques/interior-light/picture/lights.js +52 -0
  314. package/examples/techniques/interior-light/picture/materials.js +13 -0
  315. package/examples/techniques/interior-light/picture/palette.js +32 -0
  316. package/examples/techniques/interior-light/picture/sky.js +40 -0
  317. package/examples/techniques/modular-building/README.md +126 -0
  318. package/examples/techniques/modular-building/kit.js +426 -0
  319. package/examples/techniques/modular-building/main.js +39 -0
  320. package/examples/techniques/modular-building/picture/index.js +17 -0
  321. package/examples/techniques/modular-building/picture/lights.js +26 -0
  322. package/examples/techniques/modular-building/picture/materials.js +13 -0
  323. package/examples/techniques/modular-building/picture/palette.js +23 -0
  324. package/examples/techniques/night-lights/README.md +95 -0
  325. package/examples/techniques/night-lights/main.js +47 -0
  326. package/examples/techniques/night-lights/nightLights.js +95 -0
  327. package/examples/techniques/night-lights/picture/index.js +18 -0
  328. package/examples/techniques/night-lights/picture/lights.js +44 -0
  329. package/examples/techniques/night-lights/picture/materials.js +15 -0
  330. package/examples/techniques/night-lights/picture/palette.js +34 -0
  331. package/examples/techniques/night-lights/picture/post.js +9 -0
  332. package/examples/techniques/night-lights/picture/sky.js +36 -0
  333. package/examples/techniques/outlines-and-rim/README.md +59 -0
  334. package/examples/techniques/outlines-and-rim/main.js +61 -0
  335. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  336. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  337. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  338. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  339. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  340. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  341. package/examples/techniques/procedural-animation/README.md +79 -0
  342. package/examples/techniques/procedural-animation/creature.js +44 -0
  343. package/examples/techniques/procedural-animation/main.js +47 -0
  344. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  345. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  346. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  347. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  348. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  349. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  350. package/examples/techniques/procedural-surface/README.md +69 -0
  351. package/examples/techniques/procedural-surface/main.js +65 -0
  352. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  353. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  354. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  355. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  356. package/examples/techniques/procedural-surface/surface.js +120 -0
  357. package/examples/techniques/stylized-shading/README.md +74 -0
  358. package/examples/techniques/stylized-shading/main.js +62 -0
  359. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  360. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  361. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  362. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  363. package/examples/techniques/stylized-shading/shading.js +131 -0
  364. package/examples/techniques/sun-and-key-light/README.md +133 -0
  365. package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
  366. package/examples/techniques/sun-and-key-light/main.js +51 -0
  367. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  368. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  369. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  370. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  371. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  372. package/examples/techniques/three-looks/README.md +21 -0
  373. package/examples/techniques/three-looks/main.js +58 -0
  374. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  375. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  376. package/examples/techniques/three-looks/picture/comic.js +27 -0
  377. package/examples/techniques/three-looks/picture/index.js +14 -0
  378. package/examples/techniques/three-looks/picture/sun.js +23 -0
  379. package/examples/techniques/wet-road/README.md +102 -0
  380. package/examples/techniques/wet-road/main.js +48 -0
  381. package/examples/techniques/wet-road/picture/index.js +17 -0
  382. package/examples/techniques/wet-road/picture/lights.js +57 -0
  383. package/examples/techniques/wet-road/picture/materials.js +16 -0
  384. package/examples/techniques/wet-road/picture/palette.js +24 -0
  385. package/examples/techniques/wet-road/picture/sky.js +46 -0
  386. package/examples/techniques/wet-road/wetRoad.js +209 -0
  387. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  388. package/examples/webgpu-tsl/GAMEMAP.md +89 -0
  389. package/examples/webgpu-tsl/README.md +45 -0
  390. package/examples/webgpu-tsl/main.js +44 -0
  391. package/examples/webgpu-tsl/picture/index.js +18 -0
  392. package/examples/webgpu-tsl/picture/lights.js +25 -0
  393. package/examples/webgpu-tsl/picture/materials.js +36 -0
  394. package/examples/webgpu-tsl/picture/palette.js +23 -0
  395. package/examples/webgpu-tsl/picture/post.js +16 -0
  396. package/examples/webgpu-tsl/picture/sky.js +30 -0
  397. package/examples/world/.threedog/content-index.json +1 -0
  398. package/examples/world/GAMEMAP.md +31 -21
  399. package/examples/world/art/humanoid.js +38 -0
  400. package/examples/world/art/index.js +11 -0
  401. package/examples/world/art/models.js +57 -0
  402. package/examples/world/art/shapes.js +9 -0
  403. package/examples/world/assets.js +6 -0
  404. package/examples/world/content/audio.js +5 -5
  405. package/examples/world/content/items.js +1 -1
  406. package/examples/world/content/npcs.js +1 -1
  407. package/examples/world/content/props.js +1 -1
  408. package/examples/world/content/rules.js +1 -1
  409. package/examples/world/content/templates.js +1 -1
  410. package/examples/world/content/vegetation.js +1 -1
  411. package/examples/world/main.js +22 -18
  412. package/examples/world/models.js +17 -7
  413. package/examples/world/picture/index.js +20 -0
  414. package/examples/world/picture/lights.js +41 -0
  415. package/examples/world/picture/materials.js +34 -0
  416. package/examples/world/picture/palette.js +74 -0
  417. package/examples/world/picture/post.js +9 -0
  418. package/examples/world/picture/sky.js +39 -0
  419. package/index.d.ts +44 -54
  420. package/index.js +29 -25
  421. package/llms.txt +24 -15
  422. package/modules/ambience/Ambience.js +34 -23
  423. package/modules/calendar/Calendar.js +163 -0
  424. package/modules/calendar/contract.js +21 -0
  425. package/modules/calendar/index.js +82 -0
  426. package/modules/{sky → calendar}/schedule.js +17 -16
  427. package/modules/calendar/seasons.js +55 -0
  428. package/modules/camera/FirstPersonCamera.js +6 -15
  429. package/modules/camera/FixedCamera.js +33 -15
  430. package/modules/camera/FollowCamera.js +90 -16
  431. package/modules/camera/RtsCamera.js +18 -17
  432. package/modules/camera/common.js +73 -20
  433. package/modules/camera/contract.js +17 -0
  434. package/modules/camera/projection.js +11 -24
  435. package/modules/characters/Character.js +188 -48
  436. package/modules/characters/NPC.js +92 -41
  437. package/modules/characters/assetModel.js +8 -16
  438. package/modules/characters/behaviors.js +2 -1
  439. package/modules/characters/contract.js +13 -0
  440. package/modules/characters/footsteps.js +1 -1
  441. package/modules/characters/index.js +112 -49
  442. package/modules/characters/moveHelpers.js +4 -5
  443. package/modules/characters/movers/common.js +102 -19
  444. package/modules/characters/movers/manual.js +23 -0
  445. package/modules/characters/movers/rapier.js +19 -16
  446. package/modules/characters/movers/simple.js +14 -11
  447. package/modules/characters/movers/support.js +186 -0
  448. package/modules/characters/npcAvoid.js +47 -42
  449. package/modules/characters/npcSim.js +17 -9
  450. package/modules/characters/npcView.js +44 -16
  451. package/modules/characters/pathAsync.js +7 -3
  452. package/modules/characters/playerStrings.js +4 -3
  453. package/modules/characters/proceduralRig.js +19 -4
  454. package/modules/characters/useModel.js +2 -2
  455. package/modules/characters/vehicle.contract.js +21 -0
  456. package/modules/characters/walkTo.js +21 -7
  457. package/modules/collision/Collision.js +69 -27
  458. package/modules/collision/grid.js +8 -6
  459. package/modules/content/explain.js +2 -2
  460. package/modules/content/fields.js +102 -0
  461. package/modules/content/ids.js +8 -6
  462. package/modules/content/index.js +104 -27
  463. package/modules/content/loader.js +45 -33
  464. package/modules/content/models.js +58 -42
  465. package/modules/content/packs.js +6 -5
  466. package/modules/content/parts.js +41 -0
  467. package/modules/content/props.js +20 -11
  468. package/modules/content/rules.js +66 -0
  469. package/modules/content/stages.js +80 -0
  470. package/modules/content/templates.js +123 -30
  471. package/modules/debug/DebugPanel.js +24 -17
  472. package/modules/flow/contract.js +16 -0
  473. package/modules/flow/index.js +21 -15
  474. package/modules/gameplay/Container.js +41 -32
  475. package/modules/gameplay/Containers.js +30 -15
  476. package/modules/gameplay/Dialogue.js +113 -55
  477. package/modules/gameplay/Interactions.js +273 -72
  478. package/modules/gameplay/Inventory.js +72 -76
  479. package/modules/gameplay/Quests.js +75 -39
  480. package/modules/gameplay/boxOps.js +3 -3
  481. package/modules/gameplay/dialogue.contract.js +21 -0
  482. package/modules/gameplay/dialogueBox.js +4 -2
  483. package/modules/gameplay/dialogueBubbles.js +116 -0
  484. package/modules/gameplay/interactionPrompt.js +4 -1
  485. package/modules/gameplay/interactions.contract.js +16 -0
  486. package/modules/gameplay/inventory.contract.js +23 -0
  487. package/modules/gameplay/inventoryOps.js +19 -17
  488. package/modules/gameplay/pickups.js +306 -85
  489. package/modules/gameplay/questLog.js +6 -6
  490. package/modules/gameplay/quests.contract.js +17 -0
  491. package/modules/grid/Grid.js +92 -50
  492. package/modules/grid/Layer.js +27 -13
  493. package/modules/grid/index.js +96 -43
  494. package/modules/grid/ops.js +20 -18
  495. package/modules/grid/preview.js +37 -29
  496. package/modules/grid/strings.js +12 -0
  497. package/modules/grid/tiles.js +19 -22
  498. package/modules/hlod/index.js +52 -19
  499. package/modules/hud/index.js +48 -20
  500. package/modules/hud/parts.js +28 -13
  501. package/modules/level/heightfield.js +3 -1
  502. package/modules/level/index.js +49 -23
  503. package/modules/level/nodes.js +4 -3
  504. package/modules/lights/index.js +47 -19
  505. package/modules/music/Music.js +38 -21
  506. package/modules/music/rules.js +1 -1
  507. package/modules/nav/index.js +48 -42
  508. package/modules/net/Client.js +13 -6
  509. package/modules/net/Host.js +19 -5
  510. package/modules/net/Net.js +2 -1
  511. package/modules/net/index.js +13 -8
  512. package/modules/net/sync.js +9 -8
  513. package/modules/net/transports.js +77 -27
  514. package/modules/particles/Particles.js +58 -28
  515. package/modules/particles/contract.js +17 -0
  516. package/modules/particles/effect.js +54 -11
  517. package/modules/photo/Photo.js +56 -38
  518. package/modules/rigid/RigidBodies.js +194 -32
  519. package/modules/rigid/Vehicles.js +18 -15
  520. package/modules/rigid/sync.js +62 -17
  521. package/modules/settings/Settings.js +60 -55
  522. package/modules/settings/apply.js +38 -3
  523. package/modules/settings/sections.js +5 -3
  524. package/modules/settings/strings.js +3 -2
  525. package/modules/settings/view.js +5 -3
  526. package/modules/sky/Sky.js +132 -205
  527. package/modules/sky/clouds.js +37 -23
  528. package/modules/sky/dome.js +100 -0
  529. package/modules/sky/domeLayers.js +30 -15
  530. package/modules/sky/environment.js +45 -99
  531. package/modules/sky/fog.js +9 -139
  532. package/modules/sky/frame.js +60 -56
  533. package/modules/sky/season.js +21 -0
  534. package/modules/sky/shader.js +63 -35
  535. package/modules/sky/skyModule.js +52 -37
  536. package/modules/sky/tint.js +59 -0
  537. package/modules/terrain/ChunkManager.js +194 -110
  538. package/modules/terrain/chunkJob.js +1 -1
  539. package/modules/terrain/chunkQueries.js +6 -4
  540. package/modules/terrain/draw.js +154 -0
  541. package/modules/terrain/index.js +87 -54
  542. package/modules/terrain/terrainDefaults.js +2 -2
  543. package/modules/terrain/terrainEdit.js +18 -20
  544. package/modules/terrain/terrainGen.js +6 -4
  545. package/modules/terrain/terrainIsland.js +5 -4
  546. package/modules/terrain/terrainShape.js +12 -12
  547. package/modules/terrain/terrainShapeMain.js +8 -7
  548. package/modules/terrain/terrainTexture.js +21 -19
  549. package/modules/timeline/Timeline.js +95 -43
  550. package/modules/timeline/Tween.js +18 -10
  551. package/modules/timeline/letterbox.js +2 -2
  552. package/modules/timeline/shots.js +5 -1
  553. package/modules/triggers/index.js +111 -76
  554. package/modules/vegetation/Vegetation.js +229 -112
  555. package/modules/vegetation/densityMap.js +62 -0
  556. package/modules/vegetation/draw.js +191 -0
  557. package/modules/vegetation/groundChunks.js +52 -58
  558. package/modules/vegetation/index.js +32 -11
  559. package/modules/vegetation/modelGeometry.js +3 -2
  560. package/modules/vegetation/nearFade.js +8 -2
  561. package/modules/water/Water.js +157 -72
  562. package/modules/water/surface.js +86 -47
  563. package/modules/weather/Weather.js +96 -103
  564. package/modules/weather/particles.js +37 -14
  565. package/modules/weather/shaders.js +1 -1
  566. package/modules/weather/strings.js +2 -2
  567. package/modules/weather/weatherDraw.js +141 -0
  568. package/modules/world/World.js +26 -9
  569. package/modules/world/explain.js +1 -1
  570. package/modules/world/index.js +18 -4
  571. package/modules/world/persist.js +62 -2
  572. package/modules/world/pos.js +3 -2
  573. package/modules/world/records.js +8 -6
  574. package/modules/world/sim.js +60 -20
  575. package/modules/world/simFar.js +4 -3
  576. package/modules/world/state.js +3 -2
  577. package/modules/world/thingSource.js +1 -1
  578. package/modules/world/views.js +8 -6
  579. package/package.json +8 -3
  580. package/presets.js +43 -29
  581. package/render/PostFX.js +318 -135
  582. package/render/backend.js +486 -0
  583. package/render/cascades.js +195 -0
  584. package/render/cascades.tsl.js +96 -0
  585. package/render/daylight.js +39 -0
  586. package/render/detail.js +122 -41
  587. package/render/effects.js +155 -48
  588. package/render/engineUniforms.js +10 -1
  589. package/render/fuse.js +5 -4
  590. package/render/fx/cel.tsl.js +42 -0
  591. package/render/fx/cloudShadow.tsl.js +16 -0
  592. package/render/fx/detail.tsl.js +66 -0
  593. package/render/fx/index.js +28 -0
  594. package/render/fx/lighting.tsl.js +28 -0
  595. package/render/fx/nodeErrors.tsl.js +68 -0
  596. package/render/fx/noise.tsl.js +12 -0
  597. package/render/fx/objectOrigin.tsl.js +42 -0
  598. package/render/fx/particles.tsl.js +139 -0
  599. package/render/fx/patchNodes.tsl.js +403 -0
  600. package/render/fx/postWebGPU.tsl.js +181 -0
  601. package/render/fx/season.tsl.js +13 -0
  602. package/render/fx/sky.tsl.js +187 -0
  603. package/render/fx/uniforms.tsl.js +67 -0
  604. package/render/fx/water.tsl.js +53 -0
  605. package/render/fx/wind.tsl.js +22 -0
  606. package/render/fxNumbers.js +36 -0
  607. package/render/hotGlsl.js +24 -0
  608. package/render/layers.js +14 -0
  609. package/render/lighting.js +71 -18
  610. package/render/lightmap.js +142 -0
  611. package/render/lights.js +47 -6
  612. package/render/materials.js +55 -152
  613. package/render/modeling.js +73 -0
  614. package/render/neutral.js +23 -0
  615. package/render/occlusion.js +184 -0
  616. package/render/ownFrame.js +76 -0
  617. package/render/patches.js +317 -35
  618. package/render/postWebGL.js +205 -0
  619. package/render/probes.js +288 -0
  620. package/render/shaderErrors.js +154 -0
  621. package/render/slots.js +165 -0
  622. package/render/terms.js +163 -0
  623. package/render/uniformDecl.js +4 -3
  624. package/types/common.d.ts +2 -2
  625. package/types/core.d.ts +757 -346
  626. package/types/gameplay.d.ts +539 -330
  627. package/types/generated/core/Audio.d.ts +26 -42
  628. package/types/generated/core/Batching.d.ts +6 -2
  629. package/types/generated/core/Budget.d.ts +2 -8
  630. package/types/generated/core/DebugOverrides.d.ts +58 -9
  631. package/types/generated/core/I18n.d.ts +2 -2
  632. package/types/generated/core/Input.d.ts +110 -32
  633. package/types/generated/core/Ops.d.ts +31 -0
  634. package/types/generated/core/Random.d.ts +2 -2
  635. package/types/generated/core/Saves.d.ts +10 -2
  636. package/types/generated/core/Stream.d.ts +1 -1
  637. package/types/generated/core/Threads.d.ts +4 -1
  638. package/types/generated/core/Views.d.ts +0 -1
  639. package/types/generated/core/audioVoice.d.ts +17 -9
  640. package/types/generated/core/control.d.ts +55 -0
  641. package/types/generated/core/page.d.ts +9 -2
  642. package/types/generated/core/session.d.ts +2 -1
  643. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  644. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  645. package/types/generated/modules/calendar/index.d.ts +10 -0
  646. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  647. package/types/generated/modules/grid/Grid.d.ts +61 -25
  648. package/types/generated/modules/grid/Layer.d.ts +13 -5
  649. package/types/generated/modules/grid/index.d.ts +56 -20
  650. package/types/generated/modules/music/Music.d.ts +5 -3
  651. package/types/generated/modules/net/index.d.ts +3 -3
  652. package/types/generated/modules/net/transports.d.ts +12 -3
  653. package/types/generated/modules/particles/Particles.d.ts +13 -6
  654. package/types/generated/modules/sky/Sky.d.ts +85 -110
  655. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  656. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  657. package/types/generated/modules/water/Water.d.ts +50 -3
  658. package/types/generated/modules/weather/Weather.d.ts +44 -15
  659. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  660. package/types/generated/modules/world/World.d.ts +20 -5
  661. package/types/generated/render/PostFX.d.ts +109 -29
  662. package/types/generated/render/lighting.d.ts +29 -0
  663. package/types/generated/render/materials.d.ts +31 -50
  664. package/types/generated/render/modeling.d.ts +30 -0
  665. package/types/generated/render/occlusion.d.ts +13 -0
  666. package/types/generated/render/patches.d.ts +16 -2
  667. package/types/generated/ui/UI.d.ts +6 -3
  668. package/types/nav.d.ts +6 -0
  669. package/types/physics.d.ts +140 -45
  670. package/types/tsl.d.ts +94 -0
  671. package/types/world.d.ts +489 -122
  672. package/ui/Focus.js +35 -14
  673. package/ui/LoadingScreen.js +3 -3
  674. package/ui/Parts.js +35 -15
  675. package/ui/UI.js +27 -17
  676. package/ui/cursor.js +115 -0
  677. package/ui/defaults.js +15 -11
  678. package/ui/theme.js +36 -27
  679. package/ui/touchPart.js +2 -2
  680. package/core/claims.js +0 -51
  681. package/core/look/coreParts.js +0 -112
  682. package/core/look/layers.js +0 -136
  683. package/core/look/part.js +0 -173
  684. package/core/look/report.js +0 -79
  685. package/core/look/write.js +0 -86
  686. package/core/renamed.js +0 -22
  687. package/core/styleParts.js +0 -98
  688. package/docs/api/entities.md +0 -61
  689. package/docs/api/style.md +0 -134
  690. package/docs/recipes/09-style-pack.md +0 -169
  691. package/docs/recipes/35-style-from-reference.md +0 -84
  692. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  693. package/docs/recipes/38-environment-look-hooks.md +0 -88
  694. package/docs/recipes/41-thing-registry.md +0 -93
  695. package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
  696. package/docs/recipes/44-water-weather-look-hooks.md +0 -135
  697. package/docs/recipes/48-make-material.md +0 -70
  698. package/docs/recipes/52-look.md +0 -146
  699. package/examples/action/look.js +0 -5
  700. package/examples/sheepisland/style/index.js +0 -79
  701. package/examples/styletest/look.js +0 -11
  702. package/examples/styletest/overrides.js +0 -33
  703. package/examples/styletest/panel.js +0 -135
  704. package/modules/entities/Entities.js +0 -243
  705. package/modules/entities/build.js +0 -25
  706. package/modules/entities/index.js +0 -4
  707. package/modules/sky/calendar.js +0 -80
  708. package/modules/sky/cascades.js +0 -125
  709. package/modules/sky/layers.js +0 -69
  710. package/modules/sky/look.js +0 -51
  711. package/modules/sky/lookFog.js +0 -80
  712. package/modules/sky/lookShadow.js +0 -50
  713. package/modules/sky/lookSky.js +0 -108
  714. package/modules/sky/shadow.js +0 -74
  715. package/modules/terrain/chunkLevels.js +0 -40
  716. package/modules/terrain/lookGround.js +0 -61
  717. package/modules/terrain/mountTerrain.js +0 -32
  718. package/modules/vegetation/lookWind.js +0 -37
  719. package/modules/water/look.js +0 -80
  720. package/modules/weather/look.js +0 -75
  721. package/modules/world/cells.js +0 -42
  722. package/render/lookSurface.js +0 -161
  723. package/render/postLook.js +0 -86
  724. package/render/surface.js +0 -69
  725. package/types/style.d.ts +0 -643
@@ -1,5 +1,7 @@
1
1
  # Scene transitions and pause (flow)
2
2
 
3
+ **In this recipe**: 1. Pause, title, ending · 1b. Start and continue · 2. Changing scene · 2b. Input contexts · 3. Verify · 4. Sessions · 5. Window and device
4
+
3
5
  Needs the module `flow()` (not in openWorld; add it yourself: `engine.use(openWorld({ camera: 'follow', ...}), flow())`).
4
6
  - **Flow states**: title, playing (built-in `playing`), paused (built-in `paused`: freezes gameplay + locks input), ending, ... Only one is active at a time.
5
7
  - **Scene transition** `transition(fn)`: lock input -> fade to black -> fade music out -> (with `{ autosave: 'auto' }` save slot 'auto'; off by
@@ -19,7 +21,7 @@ engine.flow.define('title', {
19
21
  engine.flow.define('ending', { freeze: true, lockInput: true, enter: () => toast(engine, 'The end') });
20
22
  startBtn.onclick = () => engine.flow.go('playing');
21
23
 
22
- engine.input.define('pause', ['KeyO'], 'Pause'); // read by action name; Esc is the back key (see below); presets.keys / presets.interactions bind P, I, J, E (see the key table in GAMEMAP)
24
+ engine.input.action('pause', { label: 'Pause', keys: ['KeyO'] }); // read by action name; Esc is the back key (see below); presets.bindings.* hold ready key maps (P, I, J, E; see the key table in GAMEMAP)
23
25
  engine.onFrame(() => {
24
26
  if (engine.input.pressedRaw('pause')) engine.flow.go(engine.flow.state === 'paused' ? 'playing' : 'paused'); // paused pushes an opaque input context, so use pressedRaw
25
27
  });
@@ -46,6 +48,39 @@ A game's own windows made with `makeWindow` are pushed automatically (`onCancel`
46
48
  import { uiFocus } from 'threedog';
47
49
  const h = uiFocus(engine).push('myMap', { cancel: () => closeMap() }); // call h.remove() when closing; h.fresh = opened this very frame
48
50
  ```
51
+ An entry with a `nav` (every window, the settings menu, dialogue choices) lets go of a locked mouse when it opens. For anything else, `engine.page.releaseLock()` frees the mouse
52
+ (recipe 21); neither counts as the player's Esc, so the pause menu stays shut.
53
+
54
+ ## 1b. Title -> start -> continue, and opening straight into a moment (screenshots, tests)
55
+ `flow({ start: 'title' })` enters the title during `engine.start()` (on `engine:ready`), so when `await engine.start()` returns the title is
56
+ already showing. The title's buttons go through `engine.session` (section 4): a fresh run or the saved one, then flow moves to `'playing'` by itself.
57
+ To open straight into play, pick the start state up front instead of leaving the title afterwards; time and weather come from the engine's
58
+ own URL keys (`?time=22:20&weather=storm`, applied after `engine:ready`, weather at once, then `wait` seconds are advanced), so only the game's
59
+ own state needs a key of its own.
60
+ ```js
61
+ const q = new URLSearchParams(location.search), moment = q.get('moment'); // the game's own key: which lamps are lit, the score ...
62
+ engine.use(openWorld({ camera: 'follow' }), flow({ start: moment ? 'playing' : 'title' }));
63
+ engine.flow.define('title', { freeze: true, lockInput: true,
64
+ enter: () => showTitle({ canContinue: engine.saves.list().some(s => s.slot === 'auto') }), exit: () => hideTitle() });
65
+ newBtn.onclick = () => engine.session.newGame(); // -> session:start -> 'playing'
66
+ continueBtn.onclick = () => engine.session.load('auto'); // the same, from the save
67
+ await engine.start();
68
+ if (moment) setUpMoment(moment); // the game's own data only; in code, time / weather are engine.calendar.timeOfDay = 0.93, weather.set('storm', { seconds: 0 })
69
+ ```
70
+ The engine's ready-made title (`createEngine({ ui: { title } })`, recipe 26 §5) opens in `start()` the same way: leave `title` out for a moment
71
+ (`ui: { ...(moment ? {} : { title: { title: 'My Game', items: ['continue', 'start'] } }) }`).
72
+ Shoot it with `npm run shot -- "/?moment=night" --time 22:20 --weather storm`; a game test opens the same URL.
73
+ To start at a named place, write no code: `?at=pier` (dev and tools, like the other URL keys; `npm run shot -- --at pier`, `applyState({ at: 'pier' })`) leaves the
74
+ start screen as `?play` does, stands the player at that place of `content/places.js` (or a level marker) after the game's `session:start` code ran, and puts the
75
+ game's camera there at once. An unknown name stops with the list of places. A camera of your own: listen to `state:placed` ({ x, z }).
76
+
77
+ To get past the title without a key of your own, use the engine's `?play` URL key (`npm run shot -- --play`, `applyState({ play: true })`): after
78
+ `engine:ready` it does what the title's Start does (`engine.session.newGame()`, then the title part closes), so `flow({ start: 'title' })` moves to
79
+ `'playing'` and the game's `session:start` setup runs; with no title up it does nothing. `?fresh` (`applyState({ fresh: true })`) first deletes this
80
+ page's saves, so the title offers no Continue; on a running page it also ends the run. Two things that make a moment
81
+ drawing half-done in a picture: a headless page advances only on `engine.step` (the shot steps one frame after the game's code, so a
82
+ `weather.set(name, { seconds: 0.1 })` made after `start()` shows a third of the change: use `seconds: 0`), and an `onFrame` copy of a sky
83
+ color is one frame old (share `engine.uniforms.uSkyHorizon` instead, recipe 08).
49
84
 
50
85
  ## 2. Changing scene / teleporting
51
86
  ```js
@@ -75,26 +110,28 @@ are moved over on first launch). `save()` / `remove()` / `load()` return a Promi
75
110
  Backup: `engine.saves.exportFile('slot1')` downloads a .json (including all binary attachments such as photos; `{ files: false }` gives only the world
76
111
  save), and `await engine.saves.importFile(file)` restores it into a save slot (without a file, a file picker opens); the "Saves" page of the settings
77
112
  menu has matching buttons.
78
- For just a fade-to-black, without locking input or saving: `await fadeScreen(engine, 1, 0.5); ...; await fadeScreen(engine, 0, 0.5);` (import from `threedog`).
113
+ For just a fade-to-black, without locking input or saving: `await fadeScreen(engine, 1, { seconds: 0.5 }); ...; await fadeScreen(engine, 0, { seconds: 0.5 });` (import from `threedog`).
79
114
  Fades inside a cutscene use the timeline steps `{ fade: 0.5 }`, `{ fade: 0.5, to: 0 }`.
80
115
 
81
116
  ## 2b. Input contexts (menus, vehicles, build mode)
117
+ Who declares an action and who binds its keys: recipe 58.
82
118
  Actions are grouped into **contexts**, a stack like Unity's Action Maps. `input.push(name)` returns a handle; `h.remove()` pops it. The top context
83
119
  shadows lower actions bound to the same key; an opaque context (the default) blocks everything below it, `{ pass: true }` lets unrelated actions
84
- through. Dialogue, windows, full-screen UI parts, cutscenes, paused and transitions each push an opaque one: that is what "locks input" means
85
- (`input.enabled` is false while one is on the stack).
120
+ through. Dialogue, windows, full-screen UI parts, cutscenes (while the player is one of their `actors`), paused and transitions each push an
121
+ opaque one: that is what "locks input" means (`input.enabled` is false while one is on the stack). Who moves a character is separate: a
122
+ cutscene takes its actors' control ([57-control](57-control.md)).
86
123
  ```js
87
- engine.input.define('exit', 'KeyF', 'Get out', { context: 'vehicle' }); // 'interact' has E; give the vehicle its own keys
88
- engine.input.define('inspect', 'KeyF', 'Inspect'); // gameplay action on the same key
124
+ engine.input.action('exit', { label: 'Get out', keys: ['KeyF'], context: 'vehicle' }); // 'interact' has E; give the vehicle its own keys
125
+ engine.input.action('inspect', { label: 'Inspect', keys: ['KeyF'] }); // gameplay action on the same key
89
126
  const h = engine.input.push('vehicle', { pass: true }); // now F means exit, inspect is shadowed, WASD still works
90
127
  h.remove(); // back on foot
91
- engine.input.define('menuConfirm', 'Space', 'OK', { context: 'menu' }); // readable only while a window / menu is open
128
+ engine.input.action('menuConfirm', { label: 'OK', keys: ['Space'], context: 'menu' }); // readable only while a window / menu is open
92
129
  ```
93
130
  - A switch applies at the start of the next fixed step (the input snapshot), so the press that boarded cannot also get out in the same step. Actions
94
131
  the switch blocks lose their held state, and a key cleared this way stays dead until released: closing a menu never leaves a key "still held" and
95
132
  keyboard auto-repeat does not bring it back.
96
133
  - Losing focus (`blur`, tab hidden) releases every held key.
97
- - `describe().ui.inputContexts` lists the stack; the event `input:context { stack }` fires on every change. `characters()` pushes `'vehicle'` while
134
+ - `describe().holds.input` lists the stack with owners (`input.push(name, { owner })`; `input.gate(action, owner)` closes one action, listed in `holds.gates`); the event `input:context { stack }` fires on every change. `characters()` pushes `'vehicle'` while
98
135
  the player drives (its `brake` action lives there).
99
136
  - Test: `engine.input.push('menu'); engine.step(1 / 60);` then `input.pressed('attack')` is false.
100
137
 
@@ -117,6 +154,8 @@ engine.session.track(engine.events.once('npc:talk', onTalk)); // anything the
117
154
  Ending a playthrough skips a running cutscene, removes tracked handles, drops clock timers added after start(), drops background results not yet
118
155
  applied (commits), stops the music, applies the start state and snaps the camera to the player. flow goes back to its start state, then to
119
156
  `'playing'`. Events: `session:end`, `session:start { kind: 'new' | 'load', slot? }` (play an intro per new game there, not on `engine:ready`).
157
+ - When a save part's `load()` throws, newGame / `session.load` resolve `false` and the old playthrough goes on: its data is rolled back, its
158
+ tracked handles and timers stay, flow returns to the state it left, and `session:failed { kind, slot? }` fires instead of `session:start`.
120
159
  - `saves.load(slot)` is a quick load onto the running playthrough (keeps what the game added); `session.load(slot)` ends the playthrough first and
121
160
  refuses an unreadable save without touching the game. Deleting a save is `saves.remove(slot)`.
122
161
  - Listeners and hooks registered at boot stay (they are the game); register play-time ones with `session.track`.
@@ -124,9 +163,10 @@ applied (commits), stops the music, applies the start state and snaps the camera
124
163
  ## 5. Window and device (engine.page)
125
164
  One place listens to window focus, tab visibility, mouse lock and the WebGL context; modules never add their own listeners.
126
165
  - Window in the background / tab hidden: gameplay waits (no fixed steps; rendering and UI go on). `createEngine({ pauseOnBlur: false })` or
127
- `engine.page.pauseOnBlur = false` keeps playing. Coming back resumes with no catch-up burst; a long frame turns into at most 0.1 s of fixed steps.
166
+ `engine.page.pauseOnBlur = false` keeps playing. Coming back resumes with no catch-up burst; a long frame turns into at most 0.1 s of fixed steps,
167
+ and fewer when the steps are heavy (at most about 33 ms of catch-up work per frame; the rest is dropped as a brief slow-down). `engine.step()` never drops time.
128
168
  - `engine.events.on('page:blur', () => engine.flow?.go('paused'))` also opens the pause menu. Other events: `page:focus`,
129
- `page:pointerlock { locked }` (cameras lock again on the next click), `page:contextlost` / `page:contextrestored` (gameplay waits and the player
169
+ `page:pointerlock { locked, byEngine }` (cameras lock again on the next click; a lock the player ended counts as Esc, because the browser keeps that key), `page:contextlost` / `page:contextrestored` (gameplay waits and the player
130
170
  sees a message; three.js restores the context).
131
171
  - `engine.step()` still advances while away (tests, dev bridge). Held keys are released by Input.
132
172
  - Tests: `npm test -- "Session:" "Window:"`.
@@ -1,11 +1,77 @@
1
1
  # Add weather or change the sky
2
2
 
3
- Modules: `sky()` (day/night, sun and moon, fog, calendar), `weather()` (needs sky; the game's weather types, smooth transitions, rain and snow,
4
- lightning). All look data lives in the style pack; the engine has only a neutral fallback.
3
+ **In this recipe**: 1. Switching weather · 2. The game's own weather table · 3. Sky colors, sun, stars (and the sky color for your own shader) · 4. Time and brightness (how a game's value and the weather multiply) · 5. Verify · 6. Day and night in game logic · 7. Wet roads
4
+
5
+ Modules: `sky()` (draws the dome from `engine.calendar`, sun and moon, and computes the signals; it writes no light, fog or exposure, those are your `picture/` code, recipe 62; the time itself is `calendar()`, recipe 06), `weather()` (needs sky; the game's weather types, smooth transitions, rain and snow,
6
+ lightning; their picture is `weather({ rain, snow, lightning })`, recipe 44). The engine has only a neutral fallback.
7
+
8
+ ```js
9
+ engine.use(sky({ keyframes: ROWS, sunSize: 600, clouds: { coverage: 0.6 }, dim: { stars: false } })); // start values
10
+ engine.uniforms.uSunPower.value = 4; // sun, moon, star and dome cloud numbers: engine.uniforms, the dome's own objects, on both renderers
11
+ engine.uniforms.uCloudCover.value = 0.8; // also uSunSize uSunGlow uMoonSize uMoonPower uMoonColor uStars uStarScale uCurve uSkyCloudScale uSkyCloudSpeed uCloudOpacity uCloudSoft uCloudColor uCloudShade
12
+ engine.sky.top = boss ? '#400' : null; // plain fields, read each frame: top, horizon (color over the keyframes, null = keyframes), orbit.tilt / sway, dim.tint / stars
13
+ engine.sky.backdrop = 0x335577; // one flat color in place of the dome; null gives the dome back
14
+ engine.sky.keyframes(NIGHT_ROWS); // the day's rows, live
15
+ engine.sky.clouds({ glsl, tsl }); // your cloud function; null = the built-in kind
16
+ engine.sky.layer('aurora', { glsl, tsl, blend: 'add' }); // a named dome layer; null removes it
17
+ const mySky = new THREE.Mesh(skyGeometry, skyMaterial); // or a skybox name, a Texture
18
+ engine.sky.replace(mySky); // skybox name | Texture | CubeTexture | Object3D, never written; null gives the dome back
19
+ mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
20
+ ```
21
+
22
+ WebGPU (recipe 56): same dome as a node material. Hooks take `{ glsl, tsl: (ctx) => vec4 }` ([52](52-around-the-picture.md#tsl-forms)); GLSL alone throws `[webgpu-needs-tsl]`. Own sky: three's `SkyMesh` via `engine.sky.replace`.
23
+
24
+ The sky follows one contract: **inputs** time, weather, season,
25
+ **outputs** the dome and the background, plus the shared `engine.uniforms`
26
+ (`uSunDir`, `uSunColor`, `uDaylight`, `uTimeOfDay`, `uSkyTop`, `uSkyHorizon`, `uWind`, `uCloud`, `uRain`, `uSnow`, `uWeatherLight`, `uWeatherFog` (the weather state writes the last six every frame), season tints) and events (`day:start`, `season:change`, `weather:change`) that wind,
27
+ rain and vegetation read. The keyframes are only the default implementation: `engine.sky.replace` swaps the whole dome and everything else keeps running (the whole sky module is
28
+ `engine.use(mySky(), { replaces: 'sky' })`).
29
+
30
+ ### Your own sky object: what `engine.sky.replace(obj)` does with it
31
+ The engine hides its dome, adds `obj` to the scene root when it has no parent yet (and removes it again on `replace(null)` only then), and from
32
+ then on **never moves, scales or writes it**: it does not follow the camera, is not scaled to the far plane and is not exempted from culling.
33
+ (The built-in dome does all three itself: an `onBeforeRender` copies the camera position and scales it to `0.9 × camera.far`.) So a dome of
34
+ your own must, on its own:
35
+
36
+ - **contain the camera and stay inside the far plane**: either a fixed sphere big enough for everywhere the camera goes (radius < `camera.far`,
37
+ which the engine pulls in to the view range unless you take it: `engine.view.manual('far')`), or one that follows the camera; or skip
38
+ depth altogether as below, so the radius no longer matters;
39
+ - **compute the view direction per pixel from world space**: pass `worldPosition - cameraPosition` (linear, safe to interpolate) as the
40
+ varying and do every non-linear step (normalize, `atan`, projecting onto a cloud plane, noise) in the fragment shader. A direction taken from
41
+ the vertex's local `position`, or a non-linear value computed per vertex, is wrong once the dome is off-centre or its triangles are big:
42
+ that is where arcs bend and seams show at the corners of the sphere's faces;
43
+ - draw behind everything: `gl_Position = clip.xyww` (depth 1), `depthWrite: false`, `frustumCulled = false`, `renderOrder` well below the scene,
44
+ `side: THREE.BackSide`, `fog: false`.
45
+
46
+ ```js
47
+ const sky = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), new THREE.ShaderMaterial({
48
+ side: THREE.BackSide, depthWrite: false, depthTest: false, fog: false,
49
+ uniforms: { uTop: { value: new THREE.Color('#3b6fb6') }, uLow: { value: new THREE.Color('#cfe3f2') } },
50
+ vertexShader: /* glsl */`
51
+ varying vec3 vDir;
52
+ void main() {
53
+ vec4 w = modelMatrix * vec4(position, 1.0);
54
+ vDir = w.xyz - cameraPosition; // linear: interpolates correctly; normalize in the fragment shader
55
+ gl_Position = (projectionMatrix * viewMatrix * w).xyww; // depth 1: never clipped by far, never in front of anything
56
+ }`,
57
+ fragmentShader: /* glsl */`
58
+ uniform vec3 uTop, uLow; varying vec3 vDir;
59
+ void main() {
60
+ vec3 d = normalize(vDir);
61
+ gl_FragColor = vec4(mix(uLow, uTop, smoothstep(0.0, 0.6, d.y)), 1.0);
62
+ #include <colorspace_fragment>
63
+ }`,
64
+ }));
65
+ sky.frustumCulled = false; sky.renderOrder = -1000;
66
+ sky.onBeforeRender = (r, s, cam) => { sky.position.copy(cam.position); sky.updateMatrixWorld(); }; // centred on the camera: any radius works
67
+ engine.sky.replace(sky);
68
+ ```
69
+ Time of day still reaches it through `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay` ...): put them in its `uniforms` to follow the day.
5
70
 
6
71
  ## 1. Switching weather / automatic weather (main.js)
7
72
  ```js
8
- engine.weather.set('rain', 20); // transition to rain over 20 seconds (a type of the game's table, see 2)
73
+ engine.weather.set('rain', { seconds: 20 }); // transition to rain over 20 seconds (a type of the game's table, see 2)
74
+ engine.weather.set('storm', { seconds: 0 }); // at once: the full storm before the next step (a screenshot or test right after the call)
9
75
  engine.weather.setAuto(true); // change weather at random (openWorld({ camera: 'follow', autoWeather: true }) also works)
10
76
  engine.events.on('weather:lightning', () => { /* thunder */ });
11
77
  ```
@@ -14,61 +80,92 @@ engine.events.on('weather:lightning', () => { /* thunder */ });
14
80
  `weather({ types })` is the whole list of the game's weather; without it there is only a calm `clear` (the engine assumes no climate). Seven temperate
15
81
  ones (clear cloudy overcast rain storm snow fog) are an opt-in preset: `weather(presets.weather.temperate)`; extend with
16
82
  `types: { ...presets.weather.temperate.types, dust: {...} }`.
17
- Left-out fields are calm (no cloud, rain, snow, grey, lightning; sun, fog, wind 1). The style pack's `style.weather.types` only retunes types the game has.
83
+ The preset supplies types and an `autoPool`; the weather changes by itself only with `auto: true` (or `engine.weather.setAuto(true)`). To pin one
84
+ for a picture: `engine.weather.set('clear')`, or a shot's `--weather clear` (it also turns `auto` off); a shot prints the weather under the picture.
85
+ Left-out fields are calm (no cloud, rain, snow, grey, lightning; sun, fog, wind 1). There is no patch option for one field
86
+ of a preset type: spread that one type, `const T = presets.weather.temperate.types; weather({ types: { ...T, rain: { ...T.rain, fog: 0.5 } } })`.
18
87
  ```js
19
88
  import { createEngine, presets, sky, weather } from 'threedog';
20
89
  engine.use(sky(), weather({
21
90
  types: { clear: { cloud: 0.1 }, dust: { cloud: 0.5, sun: 0.6, fog: 0.35, wind: 2.2, grey: 0.4, heat: 1 } }, // heat: a field of the game's own, blends too
22
91
  autoPool: ['clear', 'clear', 'dust'], // candidates for automatic weather (repeats = higher probability; default: each type once)
23
92
  }));
24
- engine.weather.set('dust', 15); engine.weather.current.heat; // 0..1 during the change
93
+ engine.weather.set('dust', { seconds: 15 }); engine.weather.current.heat; // 0..1 during the change
25
94
  ```
26
95
  Fields: `cloud` cloud cover 0-1, `sun` sunlight multiplier, `fog` fog distance multiplier (smaller = denser fog), `wind` wind strength, `rain`/`snow`
27
96
  0-1, `grey` how gray the sky turns, `lightning` lightning. A table where nothing rains or snows builds no particles.
28
97
  With openWorld the weather module is already installed; pass its options through the preset: `openWorld({ camera: 'follow', weather: { types, autoPool } })`.
29
98
 
30
- ## 3. Changing sky colors, sun, stars (style pack)
31
- `sky.keyframes` in the style pack (your pack's `index.js`):
32
- `[time 0-1, zenith color, horizon color (= fog color), sunlight color, sunlight intensity, ambient intensity]`, interpolated by time;
33
- also `sunSize sunGlow moonSize starDensity clouds skybox shadow` (see the comments in the style types, `types/style.d.ts`, for what they mean; `hoursPerDay` is timing, so it is a
34
- `sky()` option, not a style key). The look of rain and snow is in `style.weather.rain / snow` (shape, density, shaders, the game's own particles: recipe 44).
99
+ ## 3. Changing sky colors, sun, stars
100
+ `sky({ keyframes })`:
101
+ `[time 0-1, zenith color, horizon color, sun color, ambient intensity]`, interpolated by time; the rows
102
+ run from time 0 to time 1 (both midnight: the first row at 0, the last at 1 with the same values), else the sky throws. What each column drives
103
+ (and which light carries the moonlight) is on `keyframes` in `SkyPictureOptions`, `types/world.d.ts`;
104
+ also `sunSize sunGlow moonSize starDensity clouds` (defaults and ranges there too; `hoursPerDay` is timing, so it is a
105
+ `calendar()` option, not a sky key). `sky()` takes `time` and the dome's start values: all of these are `sky({ ... })` start values; at run time use the entries at the top of this page. `sky({ sun | hemisphere | fog })`
106
+ throw naming what to write in your `picture/` code.
107
+ **Day and night brightness** is your `picture/` code: the sky lights nothing. Read `uDaylight` and write your own lights (recipe 62), and check with `shot --time 12:00` and
108
+ `--time 22:00`. The keyframes only color the dome; the ambient column also dims a skybox and the weather's sky tint. `engine.sky.environment({ into: engine.scene })` builds an environment map
109
+ from the dome (outdoor reflections show the sky, not a studio; it darkens by itself), recipe 34.
110
+ The look of rain and snow is `weather({ rain, snow })` (shape, density, shaders; the game's own particles with `engine.weather.define`: recipe 44).
111
+
112
+ ### Sky color for my shader (horizon color, zenith color)
113
+ A shader of your own that should meet the sky (a sea fading to the horizon, distant cards, a reflection) reads the colors the sky draws this frame:
114
+ `engine.uniforms.uSkyHorizon` and `engine.uniforms.uSkyTop` (`THREE.Color`, linear). They hold the keyframes, `engine.sky.top` / `horizon`,
115
+ the weather's grey tint and lightning; with a backdrop the horizon is the backdrop color. A fog of yours that should melt into the sky copies
116
+ it in `engine.onRender`: `scene.fog.color.copy(engine.uniforms.uSkyHorizon.value)`. Share the object, do not copy it in `onFrame`: `onFrame` runs before the sky updates, so a copy is one
117
+ frame old (after a time jump, the first picture shows the old hour's color).
118
+ ```js
119
+ const sea = new THREE.ShaderMaterial({ uniforms: { uHorizon: engine.uniforms.uSkyHorizon, uTop: engine.uniforms.uSkyTop, uSunDir: engine.uniforms.uSunDir },
120
+ fragmentShader: '... gl_FragColor = vec4(mix(base, uHorizon, fresnel), 1.0); #include <tonemapping_fragment> #include <colorspace_fragment>' /* ... */ });
121
+ engine.uniforms.uSkyHorizon.value.getHexString(); // read it in JS too (game logic, a HUD swatch)
122
+ ```
123
+ `engine.sky.horizon` is the override a game set (`null` = the keyframes), not the drawn color.
35
124
 
36
125
  ## 4. Time and brightness (game code)
37
126
  ```js
38
- engine.sky.timeOfDay = parseClock('19:30'); // jump to a time (0-1)
39
- engine.clock.timeScale = 0; // sky and game seconds stop together (2 = double speed); game seconds per day: sky({ dayLength: 600 }); the three kinds of time are in recipe 06
40
- engine.look.fog.set({ far: 300 }); // base fog distance (meters); weather scales it. engine.setFogFar(300) sets the same base value directly
127
+ await engine.skip({ to: '19:30' }); // jump forward to a time: timers, calendar.at / daily, day:start fire on the way (needs a calendar dayLength; recipe 06)
128
+ engine.mod('clock.rate', { owner: 'game', set: 0 }); // the calendar and calendar seconds stop together, so the sky stops moving (set: 2 = double speed; remove() undoes it); game seconds per day: calendar({ dayLength: 600 }); the three kinds of time are in recipe 06
129
+ engine.scene.fog = new THREE.Fog(0x99aabb, 90, 300); // fog is plain three.js; engine.uniforms.uViewDistance (terrain({ viewFog: true }) writes it) and uWeatherFog are signals your picture/ code reads
41
130
  ```
42
- Fixed dusk: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day) and do not pass `sky: presets.calendar.cycle` (the template does; the cycle
43
- is what moves the clock). `engine.sky.isDay` is `sunHeight > 0` with `sunHeight = sin((timeOfDay - 0.25) * 2π)`: true strictly between timeOfDay 0.25 and 0.75 (06:00 to 18:00 on the default 24-hour face; with `hoursPerDay: H` the same fractions, 0.25H to 0.75H), false at exactly 06:00 and 18:00, so 18:30 already reads as "night" in `describe().time.isDay`. `daylight` = `max(0, sunHeight)`. Keyframes only change colors, not this flip.
44
- The calendar is the game's: `sky()` alone keeps one time of day (dungeon, arena, space); a day-night cycle is `sky({ dayLength: 360 })` or
45
- `sky(presets.calendar.cycle)` (`presets.calendar.fourSeasons` includes it); `hoursPerDay` changes the clock face. An audio rule's `time` condition
46
- takes `'day'`, `'night'` or a range `['18:00', '06:00']`; anything else warns once.
47
- Seasons are off by default (`engine.sky.season` is `null`, no `season:change`); name them to turn them on:
131
+ **The sky draws the calendar's time; it does not own it.** Day, time of day and seasons are the `calendar()` module (recipe 06 "The time table");
132
+ the sky reads `engine.calendar.timeOfDay` each frame to place the sun and blend the keyframes, and `engine.calendar.season` for the season tint.
133
+ Without a calendar, `sky({ time: '18:30' })` draws that one fixed time (an arena, a museum diorama, a space station window); with a calendar,
134
+ `sky({ time })` throws (start the day with `calendar({ time })`). A game that draws its own sky (a skybox shader, a 2D painted backdrop) keeps the
135
+ calendar and reads it the same way; a game indoors keeps the calendar and installs no sky.
136
+ Fixed dusk in an open world: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day; goes to the calendar) and do not pass
137
+ `calendar: presets.calendar.cycle` (the template does; the cycle is what moves the clock). `engine.sky.isDay` is `sunHeight > 0` with `sunHeight = sin((timeOfDay - 0.25) * 2π)`: true strictly between timeOfDay 0.25 and 0.75 (06:00 to 18:00 on the default 24-hour face; with `hoursPerDay: H` the same fractions, 0.25H to 0.75H), false at exactly 06:00 and 18:00, so 18:30 already reads as "night" in `describe().time.isDay`. `daylight` = `max(0, sunHeight)`. Keyframes only change colors, not this flip.
138
+ `engine.calendar.isDay` / `daylight` are the same formula from the clock (they work with no sky); the sky's are what it draws (its fixed time without a calendar).
139
+ A day-night cycle is `calendar({ dayLength: 360 })` or `calendar(presets.calendar.cycle)` (`presets.calendar.fourSeasons` includes it);
140
+ `hoursPerDay` changes the clock face. An audio rule's `time` condition (from the calendar) takes `'day'`, `'night'` or a range `['18:00', '06:00']`;
141
+ anything else warns once.
142
+ Seasons are off by default (`engine.calendar.season` is `null`, no `season:change`); name them to turn them on:
48
143
  ```js
49
- sky({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28, dayLength: 360 }); // days advance only with a dayLength; or the preset: openWorld({ camera: 'follow', sky: presets.calendar.fourSeasons })
50
- sky({ seasons: [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], dayLength: 360 }); // seasons of their own length
144
+ calendar({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28, dayLength: 360 }); // days advance only with a dayLength; or the preset: openWorld({ camera: 'follow', calendar: presets.calendar.fourSeasons })
145
+ calendar({ seasons: [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], dayLength: 360 }); // seasons of their own length
51
146
  ```
52
- **Don't modify directly** `sky.sun.intensity / color`, `sky.hemi`, `scene.fog`: the sky recomputes them every frame and overwrites your change (the
53
- console warns about it during development). Use `engine.look.lights` / `look.fog` (recipe 52), or take them over yourself (recipe 38).
54
- To darken or tint everything (a cave, a horror segment), write a modifier layer of your own; it stacks with the weather's 'weather' layer without
55
- overwriting it (multiplier layers vs `look.lights` overrides: [recipe 52](52-look.md#skymodify-vs-looklights)):
147
+ The lights and the fog are your own three.js objects, so nothing overwrites them. To darken or tint everything (a cave, a horror segment), your `picture/` code reads one signal of yours and multiplies
148
+ it in with the weather's (`uWeatherLight`, `uWeatherFog`); the sky color has its own shared points, which stack with the weather's without overwriting it ([recipe 55](55-mods-time-wrap.md#picture-points-follow-the-same-rule)):
56
149
  ```js
57
- engine.sky.modify('cave', { sun: 0.3, ambient: 0.4, fog: 0.5 }); // enter the cave: layers multiply
58
- engine.sky.modify('cave', { tint: 0x402030, tintAmount: 0.5 }); // changes only the given fields (this layer's sun/ambient stay)
59
- engine.sky.modify('cave', null); // leave the cave: remove this layer
150
+ const cave = engine.mod('sky.tint', { owner: 'cave', value: { color: 0x402030, amount: 0.5 } }); // amount = zenith, horizon: = horizon
151
+ cave.remove(); // leave the cave
60
152
  ```
61
- `sun / ambient / fog` multiply across layers, `tint` is blended weighted by `tintAmount` (zenith) / `horizonTintAmount` (horizon), and `flash` takes
62
- the maximum.
63
- Write once and it stays in effect; no need to write every frame. For a gradual change, write a new value every frame. `engine.sky.modifiers` is the
64
- combined result and is read-only (changing it directly triggers a warning during development).
153
+ These are ordinary shared points (recipe 55): `sky.flash` adds, `sky.tint` / `ground.cover` entries blend weighted by their amount, `{ for: 3 }` ends one by itself.
65
154
 
66
155
  ## 5. Verify
67
156
  - Text: `npm run shot -- / --time 19:30 --weather dust --wait 2 --describe-only`, then look for "Time: 19:30..." and "Weather: dust (rain 0, snow 0, fog 0.35)".
68
- `describe().weather` has `name progress rain snow fog wind cloud`; `describe().time` has `clock day season isDay dayLength timeScale`.
69
- - Take a screenshot only after the look changed: `npm run shot -- / --time 19:30 --weather dust`.
157
+ `describe().weather` has `name progress rain snow fog wind cloud`; `describe().time` has `clock day season isDay dayLength rate`.
158
+ - Take a screenshot only after the picture changed: `npm run shot -- / --time 19:30 --weather dust`.
70
159
 
71
160
  ## 6. Day and night in game logic
72
- Day and night come only from the sky: test `engine.sky.isDay`, and fade with `engine.sky.daylight` (0-1). Don't decide it from the clock time
73
- yourself, so a game with different day lengths or seasons stays right. Lights and shop doors that follow the time of day use `engine.sky.between(...)`
74
- (its page: `api/sky.md`).
161
+ Gameplay reads day and night from the calendar: test `engine.calendar.isDay`, and fade with `engine.calendar.daylight` (0-1); they work with or
162
+ without a sky. Don't decide it from the clock text yourself, so a game with different day lengths or hours stays right. Lights and shop doors that
163
+ follow the time of day use `engine.calendar.between(...)` (its page: `api/calendar.md`).
164
+
165
+ ## 7. Wet roads and puddles after rain
166
+ The engine gives the rain, not the wet look: `engine.weather.current.rain` (0-1) is the signal; what gets wet, how fast it dries and where
167
+ puddles collect are the game's decisions. Water fills the pores of a rough surface, so wet reads as darker and glossier together (lower `color`
168
+ and `roughness`); darker alone reads as dirt or shadow. Gloss only shows when there is something bright to reflect: the sky by day, at night
169
+ the lamps and windows as long streaks. A puddle needs a soft-rimmed mask; a hard cut-off makes opaque discs that read as holes. Judge it on a
170
+ shot at noon and at night, in rain and after. To compare with your own result afterwards, the technique example `wet-road`
171
+ (`threedog examples pull wet-road`) shows one way, with a dry-out delay in game time.
@@ -0,0 +1,185 @@
1
+ # Materials, lights and models: the game's own picture
2
+
3
+ **In this recipe**: 0. Where the picture lives · 1. Materials are plain three.js · 1a. The engine's big pieces · 1b. Lights and stalls · 1c. The UI's picture ·
4
+ 2. Using your own models instead of procedural ones · 2a. Reusing art · 2b. Wind, cloud shadows and season tint on your own materials ·
5
+ 3. When the engine gets a new picture value · 4. Verify · 5. Sounds and music
6
+
7
+ ```js
8
+ // picture/materials.js: the game's materials are its own three.js objects
9
+ const wood = new THREE.MeshStandardMaterial({ color: 0x8a5a36, roughness: 0.8 });
10
+ const crate = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), wood);
11
+ engine.water.material.color.set(0x3070a0); // a big engine piece hands out its material the same way
12
+ ```
13
+
14
+ **The engine ships no art.** No default picture, character model, terrain drawing or terrain generator: until the game gives one, everything is a
15
+ plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
16
+ one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
17
+
18
+ ## 0. Where the picture lives
19
+ The picture is code of the game: a `picture/` folder of plain three.js, and recipe 62 is its home. Any art direction fits: realistic, toon, pixel, painterly,
20
+ flat, noir. Not part of the picture: model / texture / sound files and procedural models content names (an **asset pack**, `engine.assets.manifest`, recipe 05
21
+ "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20; `calendar({ hoursPerDay })`).
22
+
23
+ Swapping the picture must never change the map or the rules, so a thing that changes the world (water level, terrain seed, a size) is a module option, and a
24
+ thing that only changes pixels is a write on the module's three.js material. The terrain generator `terrainPreset` / `riverAt` / `BIOMES` / `terrainStrings` is a
25
+ separate package, `@threedog/terrain-noise`, because the shape of the world is gameplay. Post effects such as `bloom` / `ao` / `outline` come from
26
+ `@threedog/post-effects` and go in as `plugins/` files (recipe 40 §1, chain order: recipe 52).
27
+
28
+ ## 1. Materials are plain three.js
29
+ `new THREE.MeshStandardMaterial(...)`, `MeshToonMaterial`, `ShaderMaterial`, `onBeforeCompile`: all work as in any three.js project, and a plain material gets fog and
30
+ cascaded shadows by itself. Keep them in `picture/materials.js` by name, and let other code ask for `picture.materials.wall`, so a change of picture touches one folder.
31
+ ```js
32
+ // Solid prop with vertex colors (merged model)
33
+ const prop = new THREE.MeshLambertMaterial({ vertexColors: true });
34
+
35
+ // See-through, double-sided
36
+ const banner = new THREE.MeshLambertMaterial({ color: 0xd04a3a, transparent: true, opacity: 0.8, side: THREE.DoubleSide });
37
+
38
+ // Glowing lamp
39
+ const lamp = new THREE.MeshStandardMaterial({ color: 0x6b5a40, emissive: 0xffc070, emissiveIntensity: 1.2 });
40
+
41
+ // Toon with an explicit light ramp: three.js's gradientMap; rampTexture takes grays, dark to light, and how far the bands melt (0-1). three's toon reads only
42
+ // the red channel, so a colored ramp needs celLighting on the WebGPU route (recipe 56); on WebGL a colored shade is a lighting patch (recipe 43)
43
+ import { rampTexture } from 'threedog';
44
+ const skin = new THREE.MeshToonMaterial({ color: 0xe8a0a0, gradientMap: rampTexture([0.25, 0.6, 1], 0.2) });
45
+ ```
46
+ **Textures by asset name.** `engine.assets.texture(name)` returns a promise of a `THREE.Texture`; a data map (normal, roughness, ao) takes `{ color: false }`. The
47
+ `assets.useTexture` form fills a slot when the image arrives and warns once if it fails, so the material can be used at once. Tiling is three.js:
48
+ ```js
49
+ const rock = new THREE.MeshStandardMaterial({ roughness: 0.9 });
50
+ engine.assets.useTexture('rock.png', t => { t.wrapS = t.wrapT = THREE.RepeatWrapping; t.repeat.set(4, 4); rock.map = t; rock.needsUpdate = true; });
51
+ engine.assets.useTexture('rock_n.png', t => { rock.normalMap = t; rock.needsUpdate = true; }, { opts: { color: false } });
52
+ ```
53
+ Changing what compiles into the program (`vertexColors`, `flatShading`, `transparent`, adding a map) after the first render needs `material.needsUpdate = true`, as in
54
+ three.js. `material.clone()` does not carry engine patches (three's `Material.copy` skips `onBeforeCompile`): apply the effects to the clone again.
55
+ Grain, your own GLSL and the engine's shader functions on these materials: section 2b and recipe 43.
56
+
57
+ ## 1a. The engine's big pieces
58
+ Terrain, water, plants, rain and snow, pickups and grid layers keep their engineering in the engine and hand out their picture as plain three.js. The same four doors on each:
59
+
60
+ | Door | What it is | Example |
61
+ |---|---|---|
62
+ | `.material` | The three.js material it draws with; set it and it swaps on every mesh, drawn as given (nothing added behind your back) | `engine.terrain.material`, `engine.vegetation.material`, `engine.pickups.material`, `layer.material`, `engine.weather.particles.rain.material` |
63
+ | `.uniforms` | Plain `{ value }` objects for what the shader reads, written directly and live | `engine.water.uniforms.uWave.value = 1.5` |
64
+ | `.patches` | The engine's shader patches for that piece, so your own material keeps its behavior | `engine.water.material = applyEffects(new THREE.MeshPhongMaterial(), { patches: engine.water.patches })` |
65
+ | Module options and a plain method | Values baked when the module builds (terrain colors, normal map tiling) | `terrain({ colors })`, `engine.terrain.recolor({ colors })`, `engine.water.normalMap(name, { repeat })` |
66
+
67
+ Each piece's own recipe has its details: water and weather 44, terrain 37, plants 36, pickups 03, grids 29.
68
+
69
+ ## 1b. Lights and stalls
70
+ The placeholder lights and your own: recipe 38. This section is what a changing light setup costs.
71
+
72
+ three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
73
+ loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
74
+ a frame can freeze for hundreds of milliseconds. Keep the number of lights fixed: create them up front and fade with `intensity` (0 = off, no
75
+ recompile). In dev the console warns (code `light-recompile`) when programs were compiled in a frame where the lights changed.
76
+
77
+ For many torches, street lamps, campfires, muzzle flashes or neon signs use the light pool: a fixed number of real lights, created once at install,
78
+ moves to the sources that matter most (near the camera, bright, high `priority`) and fades with intensity, so the light setup never changes. Install
79
+ it before `engine.start()` so the startup compile covers its lights:
80
+ ```js
81
+ import { lightPool } from 'threedog';
82
+ engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
83
+ for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
84
+ color: 0xffa040, intensity: 4, distance: 8,
85
+ flicker: (time, i) => 0.85 + 0.15 * Math.sin(time * 13 + i),
86
+ glow: t.getObjectByName('halo'), // stand-in while it has no real light: its material's opacity / emissiveIntensity fades to 0 as the light fades in
87
+ });
88
+ const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, distance: 6 });
89
+ flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
90
+ ```
91
+ `engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
92
+ camera. Options and handle: `../api/lightPool.md`. Windows and signs that light up at night need no real light each: see below.
93
+
94
+ ### Night glow: emissive that follows daylight
95
+ Lit windows, neon signs, lamp bulbs, glowing mushrooms, screens. `engine.uniforms.uNight` is 0 by day and 1 at night, on the curve `dusk` lamps fade on
96
+ (the calendar's daylight, else the sky's sun), so a window and the lamp outside it switch on together. One write per material per frame; the color stays the
97
+ material's `emissive`:
98
+ ```js
99
+ // picture/glow.js
100
+ const windows = new THREE.MeshLambertMaterial({ color: 0x202020, emissive: 0xffcc66 });
101
+ const neon = new THREE.MeshStandardMaterial({ emissive: 0x33ccff });
102
+ engine.onFrame(() => {
103
+ const night = engine.uniforms.uNight.value, day = engine.uniforms.uDaylight.value;
104
+ windows.emissiveIntensity = 2 * night;
105
+ neon.emissiveIntensity = 0.4 + 2.6 * (1 - THREE.MathUtils.smoothstep(day, 0, 0.6)); // its own dusk: faintly lit by day, on while the sky is still bright
106
+ });
107
+ ```
108
+ Share one Material between the meshes that glow together. Models built later bring their own copies: collect them when the model is made
109
+ (`model.traverse(o => { if (o.material?.name === 'window') glowing.add(o.material); })`, a `Set` the frame loop walks), and take them out when it leaves. `uNight`
110
+ starts at daylight 0.3, roughly 17:00 to 18:00 and back in the morning: a starting value, not a rule. Judge it in shots at dusk.
111
+
112
+ **Headroom: why a glow turns into glare.** What reaches the tone curve is the emissive color times `emissiveIntensity`. A near-white color
113
+ (`#ffe6c0`) has no headroom: all three channels already sit near 1, so multiplied past 1 they clip to the same white under tone mapping, and
114
+ bloom spreads that white over what is around it (a lit sign becomes a white block with a smear). A saturated color at a lower intensity still
115
+ reads as light: its strongest channel carries the brightness, the others keep the hue, and bloom carries the halo. The numbers above are the
116
+ examples' current values, not targets. Judge the result with the picture check of `threedog shot` or `threedog snap` at night: it names each
117
+ glowing material and light that blows pixels out, with its current emissive and intensity and how much detail is lost under it, as a fact to
118
+ weigh against what the game wants (some games want a blinding sign).
119
+ For the light those windows throw on the street, add a few `lightPool` sources above; a pool source's `glow` stand-in is for one object near one light.
120
+
121
+ Top-down or side-view games whose light should spread over the floor and stop at walls (soft shadows, any number or shape of emissive
122
+ lights) can copy the optional 2D radiance cascades example instead: `examples/rc2d/` (README there: when it fits, cost, limits). It is not a module.
123
+
124
+ ## 1c. The UI's picture
125
+ `createEngine({ ui: { theme, css, fonts, templates } })`: `theme` sets the colors and the `font` of the default parts (they are CSS variables), `css` adds your own
126
+ rules, `fonts` lists font asset names to load at start (the files sit in an asset pack: recipe 05 §3b), `templates` replace a whole UI piece. Parts and their keys: recipe 26.
127
+
128
+ ## 2. Using your own models instead of procedural ones
129
+ Models are assets: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
130
+ name to swap one:
131
+ ```js
132
+ engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
133
+ engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
134
+ ```
135
+ Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
136
+ mesh, e.g. bark trunk + alpha-cut leaf cards:
137
+ `engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
138
+ the import workflow see `10-blender-level.md`.
139
+ `mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
140
+ A generator in `models` may also return an Object3D with its own materials; those are used as they are.
141
+
142
+ ### 2a. Reusing art from somewhere else: copy it in, do not depend on it
143
+ Art code you already have (generator modules such as `art/my-crate.js` from an earlier game, a folder of your own, files someone gave you, a package
144
+ you installed) is reused by **copying** it into this game. The copy is the game's own: edit it freely; nothing links back and nothing updates it.
145
+ ```sh
146
+ threedog art list ../earlier-game # modules, exported functions with their first JSDoc line, asset files (uses its art/ folder)
147
+ threedog art copy ../earlier-game crate lamp # by file or function name; none = every module
148
+ threedog art copy ../earlier-game crate --dry # what would be written, nothing written
149
+ ```
150
+ It copies the named modules, every local file they import and every texture / model file they name ('./wood.png', `new URL(...)`, '/models/x.glb'
151
+ from the source's `public/`), rewrites relative import paths to the new layout (outside-the-art-folder helpers land in `art/shared/`), keeps package
152
+ imports and lists them, and prints the `engine.assets.manifest` lines to register the generators. An existing file with different content stops the
153
+ whole copy (nothing written) unless `--force`. The engine ships no art library and names no source: which art to reuse is yours to choose.
154
+ GLB files from Blender are copied the same way and checked with recipe 46 section 3.
155
+
156
+ ## 2b. Wind, cloud shadows and season tint on your own materials
157
+ The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
158
+ ```js
159
+ import { applyEffects } from 'threedog';
160
+ const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
161
+ engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
162
+ ```
163
+ The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, and stacks with the built-in ones and with
164
+ the material's own `onBeforeCompile`:
165
+ `applyEffects(mat, { patches:
166
+ [{ name: 'snap', cacheKey: 64, uniforms, glsl: { vertex: { pars: '...', project_vertex: '...code after #include <project_vertex>' } } }] })`.
167
+ A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#include <threedog_wind_vertex>`, `<threedog_clouds_pars_fragment>` etc. (see
168
+ `render/effects.js`) with `engine.uniforms` as its uniforms.
169
+ What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`), the chunk names and the engine GLSL functions you can call in your own shader: recipe 43.
170
+
171
+ ## 3. When the engine gets a new picture value
172
+ For engine developers. Hard rule 1: a module shows neutral gray until the game writes something. It makes its material with `neutralMaterial(what, params)` from
173
+ `render/neutral.js` and hands it out through the doors of section 1a. A shader-side value is a `{ value }` in `.uniforms`; a value baked at build time is a module option, with
174
+ one plain method when it can change at run time. There is no table of picture values to add to. A value that changes the world (a level, a size, a seed) is a module option only.
175
+
176
+ ## 4. Verify
177
+ - `npm run check`: R14 reports "creates a material directly" in engine code (games and examples are plain three.js and not checked), R35 a reach into the old look
178
+ table, R39 a "non-gray fallback color".
179
+ - Take screenshots only when the picture changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
180
+ (images go to .threedog/shots/). Against a reference picture: `threedog picture compare` (recipe 60).
181
+ - It must still run with no picture code: start once with `createEngine({ canvas })` (gray placeholders, one console note per missing piece).
182
+
183
+ ## 5. Sounds and music (the game's, not the picture's)
184
+ Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`. The engine plays
185
+ nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and ducking: `recipes/31-audio.md`.
@@ -14,7 +14,7 @@
14
14
  Export glTF/GLB (tick "Custom Properties") into `art/models/` (create it if missing).
15
15
 
16
16
  ## 2. Compression
17
- `npm run assets` compresses to `public/models/<same name>.glb` (Meshopt geometry + WebP textures; `-- --ktx2` uses KTX2 textures). Object names and
17
+ `npm run assets` compresses to `public/optimized/<same name>.glb` (Meshopt geometry + KTX2 textures; needs the `ktx` command for textures) and points `assets.js` at the results (`/optimized/<name>.glb`). Object names and
18
18
  hierarchy are kept; faces are not reduced. Only changed files are processed; `-- --force` redoes everything.
19
19
 
20
20
  ## 3. Putting it in the game (main.js)
@@ -49,8 +49,8 @@ the flat default. Rules read `engine.surface / slope / groundType`, so pick the
49
49
  property, else its material name) with `rule.biomes`, and limit the scatter with `area`:
50
50
  ```js
51
51
  engine.use(level({ url: '/models/town.glb' }), vegetation({ area: { min: [-80, -80], max: [80, 80] }, viewChunks: 3 }), collision());
52
- engine.vegetation.add('grass', { geometry: grassGeo, nearOnly: true, rule: { perChunk: 500, biomes: { lawn: 1 } } });
53
- engine.vegetation.add('tree', { model: oak, rule: { perChunk: 6, biomes: { lawn: 0.6, park: 1 }, maxSlope: 0.4, collider: 0.4 } });
52
+ engine.vegetation.define('grass', { geometry: grassGeo, nearOnly: true, rule: { perChunk: 500, biomes: { lawn: 1 } } });
53
+ engine.vegetation.define('tree', { model: oak, rule: { perChunk: 6, biomes: { lawn: 0.6, park: 1 }, maxSlope: 0.4, collider: 0.4 } });
54
54
  ```
55
55
  Chunks stream around `engine.stream` sources and stay one InstancedMesh per species per chunk (LOD, shadows and felling work as on terrain:
56
56
  `instanceAt` / `removeInstance`, saved). Collision and path planning see the trees through `engine.ground.forEachCollider`; a new level or `setGround`
@@ -58,8 +58,20 @@ re-places them; after changing a ground function behind the same provider call `
58
58
  sets `minHeight / maxHeight`. Content `vegetation` works the same way. With `terrain()` installed, `vegetation()` takes no options (density and view
59
59
  distance are terrain options). Rapier (`rigid()`) bodies collide with them too (cylinders from `engine.ground.forEachCollider`, gone when felled).
60
60
 
61
+ Where a species grows is decided in the same `add()` call, with up to three parts (on a level, a code-built ground or terrain alike):
62
+ ```js
63
+ // rule: random scatter per chunk (above). positions: the game's own spots instead, [x, z] or [x, z, scale, yaw], planted at the ground height
64
+ engine.vegetation.define('hedge', { model: hedge, positions: hedgeSpots /* [[x, z], ...] from your level data */, rule: { collider: 0.5 } });
65
+ // densityMap: thins the rule's or the positions' result, 0..1 per spot -- a function of game data, or a gray image with the heightmap keys
66
+ engine.vegetation.define('weeds', { geometry: weedGeo, rule: { perChunk: 300 }, densityMap: (x, z) => farm.neglect(x, z) });
67
+ engine.vegetation.define('flowers', { geometry: flowerGeo, rule: { perChunk: 200 }, densityMap: { url: '/maps/flowers.png', size: [256, 256] } });
68
+ ```
69
+ With `positions`, the rule keeps only what shapes an instance (`scale`, `stretch`, `sink`, `tints`, `tintJitter`, `collider`); the scatter filters
70
+ are refused. The id of a listed plant is its index in the list. After what a density function reads changes, call `engine.vegetation.rebuild()`.
71
+ A game that wants every instance under its own code still builds a plain `THREE.InstancedMesh` and adds it to the scene.
72
+
61
73
  ## 5. Verify
62
- - `npm run assets` prints each file's size before and after compression; a browser 404 appears in `.threedog/errors.log` (asset load failure).
74
+ - `npm run assets` prints each file's size before and after compression (`-- --dry` only estimates); a browser 404 appears in `.threedog/errors.log` (asset load failure).
63
75
  - `describe()`: `ready` is true and `loading` is empty; the player's coordinates are at the spawn point; `nearby` contains trigger zones
64
76
  (`kind: 'trigger'`) and NPCs.
65
77
  Text version: `npm run shot -- /your-page.html --describe-only`.