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
package/types/world.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  // World modules: terrain, vegetation, sky, weather, water.
2
- import type { Object3D, Vector3, Color, Material, BufferGeometry, ColorLike, Handle, PositionLike } from './common';
2
+ import type { Object3D, Vector3, Color, Material, BufferGeometry, ColorLike, Handle, PositionLike, Loose } from './common';
3
+ import type { Mesh, InstancedMesh } from 'three';
3
4
  import type { Engine, ModuleDef } from './core';
4
- import type { StyleSky, StyleShadow, StyleFog } from './style';
5
+ import type { ShaderPatch } from './generated/render/patches';
5
6
 
6
7
  // ======================================================================
7
8
  // Terrain terrain()
@@ -53,7 +54,7 @@ export interface TerrainShape {
53
54
  mask: ((x: number, z: number, n: TerrainNoise) => number) | string
54
55
  | { url?: string; data?: ArrayLike<number>; width?: number; height?: number; size: number[]; center?: number[]; threshold?: number };
55
56
  /**
56
- * The rim's look. noise: meters of fbm added to the mask (a ragged outline), size: its wavelength in meters (default 16; keep it above a cell,
57
+ * The rim's picture. noise: meters of fbm added to the mask (a ragged outline), size: its wavelength in meters (default 16; keep it above a cell,
57
58
  * the cut cannot be finer than `resolution`); jitter: meters of per-grid-point random offset (a jagged rim); round: meters the top bends down
58
59
  * towards the rim (0 = a hard cliff edge)
59
60
  */
@@ -85,7 +86,7 @@ export interface TerrainConfig {
85
86
  waterLevel: number;
86
87
  /** Flattened plots */
87
88
  flatten: FlattenZone[];
88
- /** Ground type → palette color names (two are blended by noise); usually from style.terrain.biomeColors */
89
+ /** Ground type → palette color names (two are blended by noise); a type left out is neutral gray */
89
90
  biomeColors: Record<string, string[]>;
90
91
  /** Steep-slope color rule */
91
92
  steep: SteepRule[];
@@ -110,12 +111,12 @@ export interface TerrainConfig {
110
111
  /**
111
112
  * How the ground gets its color: 'smooth' (default) blended per grid point | 'flat' one color and normal per triangle (low poly) |
112
113
  * 'texture' per-chunk color map sampled per pixel, so color borders (a river bank) are not confined to triangle edges and the mesh can stay coarse.
113
- * See recipes/37-terrain-look-hooks.md. A style may set it (style.terrain.config.shading).
114
+ * See recipes/37-terrain-draw-hooks.md.
114
115
  */
115
116
  shading: 'flat' | 'smooth' | 'texture';
116
- /** Texture shading: color map pixels per chunk edge (default 128, 64 on low-tier devices; independent of `resolution`). A style may set it */
117
+ /** Texture shading: color map pixels per chunk edge (default 128, 64 on low-tier devices; independent of `resolution`) */
117
118
  colorResolution: number;
118
- /** Texture shading only: lighting normals 'smooth' (default) | 'flat'. A style may set it */
119
+ /** Texture shading only: lighting normals 'smooth' (default) | 'flat' */
119
120
  normals: 'smooth' | 'flat' | null;
120
121
  /**
121
122
  * Replace the smooth normal at grid point (i, j): (i, j, h, cell) => [nx, ny, nz] (any length; the engine normalizes). h(i, j) is a grid-point
@@ -125,12 +126,12 @@ export interface TerrainConfig {
125
126
  normalFn: ((i: number, j: number, h: (i: number, j: number) => number, cell: number) => number[]) | string | null;
126
127
  /**
127
128
  * How each cell is cut into two triangles: 'fixed' (default, the same diagonal everywhere) | 'adaptive' (along the diagonal with the smaller
128
- * height difference, fewer zigzag ridges on slopes) | 'alternate' (flips every other cell). It is shape: engine.surface follows it. World setting, not style
129
+ * height difference, fewer zigzag ridges on slopes) | 'alternate' (flips every other cell). It is shape: engine.surface follows it
129
130
  */
130
131
  diagonal: 'fixed' | 'adaptive' | 'alternate';
131
132
  /** Chunk bounding sphere margin in meters (default { up: 3, radius: 8 }): center raised by `up`, radius grown by `radius`. Raise it when a shader moves vertices far */
132
133
  boundsPad: { up?: number; radius?: number };
133
- /** World outline (default null = ground everywhere): an island, a floating rock, a coastline that ends. World setting, not style */
134
+ /** World outline (default null = ground everywhere): an island, a floating rock, a coastline that ends */
134
135
  shape: TerrainShape | null;
135
136
  /** Palette: color name → color */
136
137
  colors: Record<string, ColorLike>;
@@ -142,10 +143,39 @@ export interface TerrainOptions extends Partial<TerrainConfig> {
142
143
  viewChunks?: number;
143
144
  /** Vegetation density multiplier, default 1 */
144
145
  density?: number;
145
- /** true: the fog distance (engine.fogFar) follows the view distance so the far chunk edge fades out; default false keeps the game's fog (openWorld() sets true) */
146
+ /** true: the signal engine.uniforms.uViewDistance follows the view distance, so a game's fog can read it and fade the far chunk edge out (openWorld() sets true) */
146
147
  viewFog?: boolean;
147
- /** Ground material (default style.terrain.material, else the 'terrain' role with vertex colors); chunks have uv = world xz / chunk size. Cloud shadows and season tint are added */
148
+ /** Ground material (default neutral gray with vertex colors); chunks have position, normal, color and uv = world xz / chunk size. Cloud shadows, season tint and detail are added */
148
149
  material?: Material | ((engine: Engine) => Material);
150
+ /** With material: false = draw it exactly as given, no cloud shadow / season / detail patch */
151
+ effects?: boolean;
152
+ /** Detail layer over the ground: a noise, a texture asset name or your own glsl; defaults scale 0.25, strength 0.35, top-down world projection, multiply. Change it with engine.terrain.recolor({ detail }) */
153
+ detail?: MaterialDetail | null;
154
+ /** Ground color noise, baked into the chunks */
155
+ variation?: TerrainVariation;
156
+ }
157
+
158
+ /** The color noise on the ground, baked into the chunks */
159
+ export interface TerrainVariation {
160
+ /** The two-color noise: size = wavelength in meters */
161
+ blend?: { size?: number; strength?: number };
162
+ /** Per-cell brightness grain */
163
+ jitter?: { size?: number; min?: number; range?: number };
164
+ /** Large color blocks, off unless given */
165
+ patches?: { size?: number; strength?: number; levels?: number; tint?: ColorLike };
166
+ }
167
+
168
+ /** engine.terrain.recolor({...}): what terrain({...}) baked in. Each value is given whole; null takes it out */
169
+ export interface TerrainRecolor {
170
+ colors?: Record<string, ColorLike> | null;
171
+ biomeColors?: Record<string, string[]> | null;
172
+ steep?: SteepRule[] | null;
173
+ variation?: TerrainVariation | null;
174
+ /** null goes back to what terrain({...}) was given */
175
+ shading?: 'flat' | 'smooth' | 'texture' | null;
176
+ normals?: 'smooth' | 'flat' | null;
177
+ /** The detail layer on the engine's material; no chunk is rebuilt, a game's own material is left alone */
178
+ detail?: MaterialDetail | null;
149
179
  }
150
180
 
151
181
  /** Pure-computation terrain returned by createTerrain() (draws nothing, only computes heights; usable before the engine exists, e.g. for previews) */
@@ -175,11 +205,66 @@ export interface TerrainGen {
175
205
  place(cx: number, cz: number, rule: VegetationRule, density?: number): any;
176
206
  }
177
207
 
178
- /** engine.terrain: chunk manager */
208
+ /** A loaded chunk record (data only; the draw parts keep their meshes): c.data = generated arrays, c.plants = what grows there */
209
+ export interface TerrainChunk {
210
+ cx: number; cz: number; key: string;
211
+ state: 'queued' | 'pending' | 'ready' | 'failed';
212
+ /** generated arrays: pos / nor / col (3 per vertex), uv (2 per vertex), tex (color map of shading 'texture') */
213
+ data: { pos: Float32Array; nor: Float32Array; col: Float32Array; uv: Float32Array; tex?: any; top?: number } | null;
214
+ /** species name -> placement (see VegetationPlants) */
215
+ plants: Record<string, VegetationPlants>;
216
+ /** species name -> felled instance slots (null = none) */
217
+ hidden?: Record<string, Set<number> | null> | null;
218
+ /** LOD ring from the nearest stream source; inView: in the camera view */
219
+ ring?: number; inView: boolean;
220
+ }
221
+ /** One species' placement in one chunk: n plants, m = 16 floats per plant (chunk-local matrix), c = 3 colors per plant, ids = stable ids */
222
+ export interface VegetationPlants { n: number; m: Float32Array; c: Float32Array; ids?: Uint32Array; k?: Float32Array }
223
+
224
+ /** engine.terrainDraw: draws the terrain chunks (slot 'terrain-draw'; engine.use(mine, { replaces: 'terrain-draw' }) swaps it) */
225
+ export interface TerrainDraw {
226
+ /** The ground material every chunk draws with; setting swaps it on every loaded chunk as given (same as engine.terrain.material). Nothing is regenerated, collision is untouched */
227
+ material: Material;
228
+ /** Same as engine.terrain.patches */
229
+ readonly patches: ShaderPatch[];
230
+ /** Same as engine.terrain.uniforms */
231
+ readonly uniforms: Record<string, { value: any }>;
232
+ /** Same as engine.terrain.recolor */
233
+ recolor(o?: TerrainRecolor): void;
234
+ /** chunk record -> { group, mesh, colorTex, colorMat } */
235
+ meshes: Map<TerrainChunk, { group: Object3D; mesh: Mesh; colorTex: any; colorMat: any }>;
236
+ }
237
+
238
+ /** engine.vegetationDraw: draws the plants (slot 'vegetation-draw'; engine.use(mine, { replaces: 'vegetation-draw' }) swaps it) */
239
+ export interface VegetationDraw {
240
+ /** The InstancedMesh drawing one species in one chunk, null when none */
241
+ mesh(c: TerrainChunk, name: string): InstancedMesh | null;
242
+ /** How one species is drawn: its geometry, low-poly geometry, patched material(s), near-fade uniforms; shared = it draws engine.vegetation.material; null for an unknown name */
243
+ kind(name: string): { geometry: BufferGeometry; lodGeometry: BufferGeometry | null; material: Material | Material[]; fadeUniforms: any; shared: boolean } | null;
244
+ /** chunk record -> { group, ims: { species name: InstancedMesh } } */
245
+ meshes: Map<TerrainChunk, { group: Object3D; ims: Record<string, InstancedMesh> }>;
246
+ }
247
+
248
+ /** engine.terrain: the terrain data part (chunks, heights, edits, collision); engine.terrainDraw draws it */
179
249
  export interface Terrain {
180
- engine: Engine;
181
250
  /** Pure-computation terrain (height, landform) */
182
251
  T: TerrainGen;
252
+ /**
253
+ * The plain three.js material every chunk draws with (null under a draw part that replaced 'terrain-draw'). The neutral one takes direct writes; setting one swaps it on every
254
+ * loaded chunk and draws it as given. Nothing is regenerated, collision is untouched. Chunks carry position, normal, color and uv (world xz / chunk size)
255
+ * @example engine.terrain.material = applyEffects(new THREE.MeshStandardMaterial({ vertexColors: true }), { patches: engine.terrain.patches });
256
+ */
257
+ material: Material | null;
258
+ /** The engine's ground patches (world, clouds, season, detail), so a game material keeps them: applyEffects(mat, { patches: engine.terrain.patches }) */
259
+ readonly patches: ShaderPatch[];
260
+ /** The detail layer's { value } uniforms, written directly and live: uDetailStrength, uDetailScale, uDetailTint... ({} without a detail layer) */
261
+ readonly uniforms: Record<string, { value: any }>;
262
+ /**
263
+ * Change at run time what terrain({...}) baked in. colors, biomeColors, steep, variation, shading, normals rebuild every chunk (edits stay); detail only patches the engine's material.
264
+ * Throws under a draw part that replaced 'terrain-draw'
265
+ * @example engine.terrain.recolor({ colors: { grass: 0x6a8a3a }, biomeColors: { meadow: ['grass'] } });
266
+ */
267
+ recolor(o?: TerrainRecolor): void;
183
268
  /** Chunk edge length (meters) */
184
269
  readonly CHUNK: number;
185
270
  /**
@@ -189,19 +274,28 @@ export interface Terrain {
189
274
  */
190
275
  readonly voidY: number;
191
276
  /** Loaded chunks: 'cx,cz' → chunk */
192
- chunks: Map<string, any>;
277
+ chunks: Map<string, TerrainChunk>;
193
278
  /** View distance (in chunks) */
194
279
  viewChunks: number;
195
280
  /** Vegetation density multiplier */
196
281
  density: number;
197
282
  /** Time budget (milliseconds) for uploading chunks per frame */
198
283
  applyBudgetMs: number;
199
- /** Statistics (for the debug panel) */
200
- stats: { builtThisFrame: number; applyMs: number; queued: number; visible?: number; loaded?: number; instances?: number };
201
- /** Change the view distance (in chunks); fog and camera far plane adjust too */
284
+ /** Statistics (for the debug panel); failed = chunks that failed every try (terrain:chunkFailed) */
285
+ stats: { builtThisFrame: number; applyMs: number; queued: number; failed: number; visible?: number; loaded?: number; instances?: number };
286
+ /** Change the view distance (in chunks); camera far plane and, with viewFog, uViewDistance adjust too */
202
287
  setViewChunks(n: number): void;
203
- /** Change the vegetation density (rebuilds all chunks) */
288
+ /** Change the vegetation density: plants are placed again on the loaded chunks; the ground and its collision stay */
204
289
  setDensity(d: number): void;
290
+ /**
291
+ * Draw these chunks: the hooks a draw part that replaces 'terrain-draw' uses. add(c): generated (c.data holds pos / nor / col / uv / tex arrays,
292
+ * c.cx / c.cz the chunk); change(c): an edit rewrote c.data (same vertex count); remove(c): released; show(c, visible): in view or not.
293
+ * Chunks already loaded are added at once. Returns { remove() } (ctx.track it).
294
+ * @example ctx.track(engine.terrain.view({ add(c) { draw(c) }, remove(c) { undraw(c) } }))
295
+ */
296
+ view(hooks: { add?: (c: TerrainChunk) => void; change?: (c: TerrainChunk) => void; remove?: (c: TerrainChunk) => void; show?: (c: TerrainChunk, visible: boolean) => void }): { remove(): void };
297
+ /** Send chunks that failed every try (terrain:chunkFailed) again, e.g. after fixing what their rule reads. Returns how many were queued */
298
+ retry(): number;
205
299
  /** Rebuild all chunks */
206
300
  rebuild(): void;
207
301
  /** Grid spacing (meters) = chunkSize / resolution: edits snap to it, paint colors whole cells of this size */
@@ -223,7 +317,7 @@ export interface Terrain {
223
317
  // Vegetation vegetation()
224
318
  // ======================================================================
225
319
 
226
- /** Vegetation placement rule (must be JSON-able, no functions) */
320
+ /** Vegetation placement rule (must be JSON-able, no functions: it is sent to the terrain workers) */
227
321
  export interface VegetationRule {
228
322
  /** Placement attempts per chunk, default 100 */
229
323
  perChunk?: number;
@@ -258,18 +352,36 @@ export interface VegetationRule {
258
352
  /** Random seed offset (default computed from the name) */
259
353
  salt?: number;
260
354
  }
261
- /** Parameters of engine.vegetation.add(name, {...}) */
355
+ /** Parameters of engine.vegetation.define(name, {...}) */
262
356
  export interface VegetationOptions {
263
357
  /** High-detail model (this or model is required) */
264
358
  geometry?: BufferGeometry;
265
- /** Multi-material model (one material per mesh, e.g. bark trunk + leaf cards); still one InstancedMesh per species. Its materials are cloned */
266
- model?: Object3D;
267
- /** Low-detail model, switched to beyond lodRing rings; with model an Object3D with the same mesh order, or a geometry drawn with the first material */
268
- lodGeometry?: BufferGeometry | Object3D;
269
- /** Placement rule */
359
+ /**
360
+ * A model name from an asset pack ('pine', or ['flower', color] for a generator with params), resolved as content resolves it (file or generator,
361
+ * cache, bake; add then returns a Promise of the species), or a multi-material Object3D (one material per mesh, e.g. bark trunk + leaf cards);
362
+ * still one InstancedMesh per species. Its materials are cloned
363
+ */
364
+ model?: Object3D | string | [string, ...any[]];
365
+ /** Low-detail model, switched to beyond lodRing rings: a model name, or with model an Object3D with the same mesh order, or a geometry drawn with the first material */
366
+ lodGeometry?: BufferGeometry | Object3D | string | [string, ...any[]];
367
+ /** Placement rule (random scatter per chunk) */
270
368
  rule?: VegetationRule;
271
- /** Wind sway amplitude, 0 = still */
272
- wind?: number;
369
+ /**
370
+ * The game's own spots instead of the random scatter: [x, z], [x, z, scale] or [x, z, scale, yaw] in world metres / size multiplier / radians. Each is
371
+ * planted at the ground height; rule.scale / stretch / sink / tints / tintJitter / collider still apply (scale and yaw only where the entry leaves them
372
+ * out), the scatter filters (perChunk, chance, cluster, min/maxHeight, maxSlope, biomes, avoidFlat) are refused, and the density setting does not
373
+ * thin them. The stable id (instanceAt, removeInstance, saves) is the index in this list. Plain data, so it also works from content files
374
+ */
375
+ positions?: number[][];
376
+ /**
377
+ * How much of this species survives at each spot, 0 (none) .. 1 (all that the rule or positions placed): a function (x, z) => 0..1 (may read game
378
+ * state; call vegetation.rebuild() after what it reads changes), or a gray image laid over the world with the keys of terrain({ heightmap }) — url,
379
+ * or data (0..1, row 0 at the -z edge) + width + height; size [width m, length m]; center [x, z] (default [0, 0]); outside (value beyond the image,
380
+ * default 0). An image url is waited for by start(). Survivors keep their stable ids, so raising the density only adds plants
381
+ */
382
+ densityMap?: ((x: number, z: number) => number) | { url?: string; data?: ArrayLike<number>; width?: number; height?: number; size: number[]; center?: number[]; outside?: number };
383
+ /** Wind sway amplitude, 0 = still; or this species' own sway: { amplitude, glsl, tsl, uniforms }, which vegetation.sway() leaves alone (recipes/36) */
384
+ wind?: number | { amplitude: number; glsl?: string; tsl?: (ctx: any) => any; uniforms?: Record<string, any> };
273
385
  /** Only generated near the player (grass, flowers) */
274
386
  nearOnly?: boolean;
275
387
  /** No longer drawn beyond this many rings */
@@ -288,17 +400,17 @@ export interface VegetationOptions {
288
400
  shadowRing?: number;
289
401
  /** Receive shadows, default true */
290
402
  receiveShadow?: boolean;
291
- /** Custom material, any three.js material (default: the style pack's 'vegetation' role); wind, cloud shadows and season tint are added to it */
403
+ /** Custom material, any three.js material (default: the style's 'vegetation' role); wind, cloud shadows and season tint are added to it */
292
404
  material?: Material;
293
405
  /** false: leave a custom material untouched (no wind / clouds / season added) */
294
406
  effects?: boolean;
295
407
  /** Double-sided rendering */
296
408
  doubleSided?: boolean;
297
409
  }
298
- /** A registered kind of vegetation */
410
+ /** A defined species (data; how it is drawn: engine.vegetationDraw.kind(name)). source = the options define() was given */
299
411
  export interface Species {
300
- name: string; geometry: BufferGeometry; lodGeometry: BufferGeometry | null; rule: VegetationRule;
301
- nearOnly: boolean; maxRing: number; fade: { start: number; end: number } | null; lodRing: number; castShadow: boolean; shadowRing: number; receiveShadow: boolean; material: Material | Material[];
412
+ name: string; rule: VegetationRule; source: VegetationOptions;
413
+ nearOnly: boolean; maxRing: number; fade: { start: number; end: number } | null; lodRing: number; castShadow: boolean; shadowRing: number; receiveShadow: boolean;
302
414
  }
303
415
  /** A found plant: species name, chunk cx/cz, stable id, world coordinates position */
304
416
  export interface VegetationHit { species: string; cx: number; cz: number; id: number; position: Vector3 }
@@ -318,8 +430,30 @@ export interface VegetationModuleOptions {
318
430
  seed?: number;
319
431
  }
320
432
 
321
- /** engine.vegetation */
433
+ /** engine.vegetation: the vegetation data part (species, placement, tree collision, felling); engine.vegetationDraw draws it */
322
434
  export interface Vegetation {
435
+ /**
436
+ * The shared default material: species with no material or model of their own draw it, as given, planted ones too; null gives the neutral default
437
+ * back. Until set, reading gives the neutral source of each species' own copy (only .color written there reaches them all). Throws when a game
438
+ * module drew the plants instead (replaces: 'vegetation-draw'). Per species: define(name, { material })
439
+ */
440
+ material: Material | null;
441
+ /** The engine's plant patches (season tint, sway with one amplitude, vegetation.color() code) for applyEffects(myMaterial, { patches }) */
442
+ readonly patches: any[];
443
+ /**
444
+ * Replace the sway shape of every species whose wind is a number, planted ones too; a species with its own wind object keeps it. null gives the built-in sway back. GLSL defines
445
+ * void threedogWind(inout vec3 transformed, vec3 ip, vec3 position); tsl: (ctx) => the moved object-space position
446
+ */
447
+ sway(spec: string | { glsl?: string; tsl?: (ctx: any) => any; uniforms?: Record<string, any> } | null): void;
448
+ /** Code in the 'color' slot of every species' material, planted ones too (diffuseColor is yours); tsl: (ctx) => vec4 from ctx.color; null takes it off */
449
+ color(spec: string | { glsl?: string; tsl?: (ctx: any) => any; uniforms?: Record<string, any>; pars?: string } | null): void;
450
+ /**
451
+ * Draw the plants: the hooks a draw part that replaces 'vegetation-draw' uses. species(sp): defined or defined again (sp.source = the define()
452
+ * options); change(c, name): c.plants[name] placed, replaced or gone, or c.hidden[name] (felled slots) changed; ring(c, ring): LOD ring;
453
+ * show(c, visible); drop(c): released. What is already there is replayed at once. Returns { remove() } (ctx.track it).
454
+ * @example ctx.track(engine.vegetation.view({ change(c, name) { draw(c, c.plants[name]) }, drop(c) { undraw(c) } }))
455
+ */
456
+ view(hooks: { species?: (sp: Species) => void; change?: (c: TerrainChunk, name: string) => void; ring?: (c: TerrainChunk, ring: number) => void; show?: (c: TerrainChunk, visible: boolean) => void; drop?: (c: TerrainChunk) => void }): { remove(): void };
323
457
  /**
324
458
  * Place every chunk again: after changing the ground behind the same provider (a ground function reading game state). A new setGround or level is
325
459
  * followed automatically
@@ -327,12 +461,12 @@ export interface Vegetation {
327
461
  rebuild(): void;
328
462
  /**
329
463
  * Change at runtime how far a vegetation kind casts shadows: within `ring` chunk rings of the player (0 = only the chunk you stand in, 1 = the default,
330
- * larger = further and dearer). Takes effect at once; the add() option shadowRing is only the starting value. An unknown name warns with the known ones
464
+ * larger = further and dearer). Takes effect at once; the define() option shadowRing is only the starting value. An unknown name warns with the known ones
331
465
  * @example engine.vegetation.setShadowRing('tree', 0); // graphics setting "shadows: low": trees shadow only the nearest chunk
332
466
  */
333
467
  setShadowRing(name: string, ring: number): void;
334
- /** Register a kind of vegetation */
335
- add(name: string, opts: VegetationOptions): Species;
468
+ /** Define a kind of vegetation (a model name in model / lodGeometry: resolves first, so the result is a Promise of the species) */
469
+ define(name: string, opts: VegetationOptions): Species | Promise<Species>;
336
470
  get(name: string): Species | undefined;
337
471
  list(): Species[];
338
472
  isRemoved(species: string, cx: number, cz: number, id: number): boolean;
@@ -354,100 +488,229 @@ export interface Vegetation {
354
488
  /** What engine.sky.environment reports */
355
489
  export interface SkyEnvironmentInfo { source: string, intensity: number, rotation: number, interval: number, builds: number }
356
490
 
357
- export interface SkyOptions extends Omit<StyleSky, 'fog'> {
491
+ /** Parameters of sky({...}). The sky computes signals and draws the dome; lights and fog are the game's (sky({ sun | hemisphere | fog }) throw naming what to write). Picture values are start values here:
492
+ * after install the numbers are engine.uniforms (write .value), the rest engine.sky fields and calls (keyframes, clouds, layer, replace, backdrop, top, horizon, orbit, dim) */
493
+ export interface SkyOptions extends Pick<SkyPictureOptions, 'clouds' | 'backdrop' | 'keyframes' | 'sunSize' | 'sunGlow' | 'sunBrightness' | 'moonSize' | 'moonColor' | 'moonBrightness' | 'starDensity' | 'starScale' | 'gradientCurve' | 'orbitTilt' | 'orbitSway' | 'dim'> {
494
+ /**
495
+ * The fixed time of day drawn while no calendar() is installed: 'HH:MM' or 0–1 (0.5 noon), default 0.33 (a sunset arena: sky({ time: '18:30' })).
496
+ * With calendar() the sky draws engine.calendar.timeOfDay and this option throws (start the day with calendar({ time }))
497
+ */
498
+ time?: string | number;
499
+ }
500
+
501
+ /** Sky keyframe: [time 0–1, zenith color, horizon color, sun disk color, sun intensity, ambient intensity] */
502
+ export type SkyKeyframe = (number | ColorLike)[];
503
+
504
+ /**
505
+ * engine.sky.seasonTints: what each season tints the plants and ground, blended by the calendar's season. mode 'multiply' (default) multiplies
506
+ * the color onto the surface (pick tints near white: orange times green is muddy); 'mix' moves the surface `strength` (0-1, default 0.5) of the
507
+ * way to the color. Season names are the other keys, so none can be called mode or strength
508
+ * @example engine.sky.seasonTints = { autumn: { foliage: 0xffb070 }, winter: { foliage: 0xdfe4e8, ground: 0xeef0f2 } }
509
+ */
510
+ export interface SeasonTints {
511
+ mode?: Loose<'multiply' | 'mix'>;
512
+ strength?: number;
513
+ [season: string]: any;
514
+ }
515
+
516
+ export interface SkyPictureOptions {
517
+ /**
518
+ * Rows [time, zenith, horizon, sunColor, ambient]. time: share of the day (0 = 00:00, 0.5 = noon), sorted, first row 0,
519
+ * last 1 (midnight again: same values as 0). They color the dome and the signals uSkyTop / uSkyHorizon, and light nothing: sunColor is the sun disk and the signal uSunColor,
520
+ * ambient dims a skybox and the weather's sky tint (recipe 08).
521
+ * @example [[0, 0x0b1030, 0x1c2440, 0x8090c0, 0.25], [0.5, 0x5a8fd0, 0xbcd4ea, 0xfff4e0, 1.1], [1, 0x0b1030, 0x1c2440, 0x8090c0, 0.25]]
522
+ */
523
+ keyframes?: SkyKeyframe[];
524
+ /**
525
+ * A flat background color in place of the dome (no gradient, horizon line, sun / moon disk, stars or clouds), or ({ time, weather, season, state, sky }) => color per
526
+ * frame. Drawn as written (no tone mapping); a fog asked for in the default horizon color takes it (a
527
+ * fog.color of your own still wins). Leave out for the dome. Not with skybox. recipes/47
528
+ * @example backdrop: ({ sky }) => sky.isDay ? 0xefebe4 : 0x2c3346
529
+ */
530
+ backdrop?: ColorLike;
531
+ /** Sharpness exponent of the sun disk, default 900 (about 2 deg); larger = smaller. Not a size in degrees: 10 is ~20 deg, under ~3 the "disk" washes most of the sky toward the sun color */
532
+ sunSize?: number;
533
+ /** Sun glow, default 0.18 */
534
+ sunGlow?: number;
535
+ /** Sun brightness, default 6 */
536
+ sunBrightness?: number;
537
+ /** Larger means a smaller moon */
538
+ moonSize?: number;
539
+ moonColor?: ColorLike;
540
+ moonBrightness?: number;
541
+ /** North-south tilt of the sun path */
542
+ orbitTilt?: number;
543
+ /** East-west swing of the sun path */
544
+ orbitSway?: number;
545
+ /** Share of the sky grid cells (0-1) that hold a star at night, default 0.0025 (0 = no stars). A probability, not a brightness: near 1 every cell is lit and the upper sky turns into a white sheet. The cell size is starScale */
546
+ starDensity?: number;
547
+ /** Star grid resolution (cells per unit of view direction), default 260: larger means smaller and more numerous stars */
548
+ starScale?: number;
549
+ /**
550
+ * What the sky dims for every game unless the style says no (each default true; false turns that one off, the rest stay). The one place these
551
+ * picture decisions are switched:
552
+ * - tint: a sky.tint color (weather grey, a cave tint) dims with the sky's own light, so a grey rain tint stays dark at night. false: the tint
553
+ * keeps its full color at any hour (a fantasy sky that stays bright at night)
554
+ * - stars: stars fade with the weather's cloud cover, not only behind drawn clouds. false: stars shine through an overcast / rainy sky
555
+ * @example sky({ dim: { stars: false } }) // live: engine.sky.dim.tint = false
556
+ */
557
+ dim?: { tint?: boolean; stars?: boolean };
558
+ /**
559
+ * Gradient curve from horizon to zenith, default 0.55 (color = mix(horizon, zenith, elevation^curve), mixed in linear light, then tone mapped
560
+ * and exposed like the scene). The keyframe zenith shows only high up: a level camera (55 deg fov) sees the lowest ~25 deg, where a warm
561
+ * horizon and a deep-blue zenith mix to a gray-lavender (desert R4: e8d4a8 / 1858c8 read as #9b99bd at the frame's top). Lower curve = more
562
+ * zenith color near the horizon; or bring the horizon color closer to the zenith hue. toneMapping 'aces' also turns a saturated blue toward
563
+ * violet ('agx' / 'neutral' keep the hue closer). Check with threedog shot
564
+ */
565
+ gradientCurve?: number;
566
+ /** Clouds in the sky (cloud cover follows the weather); see SkyCloudOptions */
567
+ clouds?: SkyCloudOptions;
568
+ /** Panorama (equirectangular) replacing the gradient sky, asset name or path (at run time engine.sky.replace(name)) */
569
+ skybox?: string;
570
+ /** Extra dome layers drawn after the clouds and stars (rainbow, aurora), default none; see SkyLayerOptions */
571
+ layers?: SkyLayerOptions[];
572
+ }
573
+
574
+ /**
575
+ * One extra sky layer (modules/sky/domeLayers.js)
576
+ * @example layers: [{ blend: 'add', uniforms: { uAurora: [0.2, 1, 0.6] }, glsl: `vec4 threedogSkyLayer(vec3 d, float time, vec3 sunDir, float night){
577
+ * float band = smoothstep(0.25, 0.45, d.y) * (1.0 - smoothstep(0.55, 0.8, d.y)) * threedogNoise(vec2(d.x * 4.0 + time * 0.05, d.z * 2.0));
578
+ * return vec4(uAurora, band * night); }` }]
579
+ */
580
+ export interface SkyLayerOptions {
581
+ /** The layer's name, the key for engine.sky.layer(name, spec); default layer0, layer1 ... by position */
582
+ name?: string;
583
+ /** Defines `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)` returning (rgb, amount 0..1); renamed per layer, so layers never clash. WebGLRenderer draws it */
584
+ glsl?: string;
585
+ /** WebGPURenderer form: (ctx) => vec4 node (rgb, amount); ctx = { dir, time, sunDir, night, color (sky so far), uniforms, fx: { noise, hash }, tsl } (recipe 52 'tsl forms') */
586
+ tsl?: (ctx: any) => any;
587
+ /** Custom uniforms (numbers, THREE.Color, [x, y(, z, w)], THREE.Texture), live in engine.sky.dome.material.uniforms */
588
+ uniforms?: Record<string, any>;
589
+ /** Draw order among the layers, smaller first (default 0) */
590
+ order?: number;
591
+ /** 'mix' (default: mix(sky, rgb, amount)) | 'add' (sky + rgb * amount, for glows) */
592
+ blend?: Loose<'mix' | 'add'>;
593
+ }
594
+
595
+
596
+ /**
597
+ * Sky cloud layer. The defaults are the original picture ('plane': one plane projected onto the sky, 3 noise layers), so a style
598
+ * that sets nothing here draws what it always drew. Values below marked (plane) are the defaults of kind 'plane'.
599
+ * @example clouds: { kind: 'cumulus', coverage: 1, scale: 0.5, color: 0xfff6ea, shade: 0x8fa0b8 } // full-sky billowy clouds with sun-side light
600
+ * Your own cloud function is not a style key: engine.sky.clouds({ glsl, tsl, uniforms }) (modules/sky/clouds.js has the signature).
601
+ */
602
+ export interface SkyCloudOptions {
603
+ color?: ColorLike; shade?: ColorLike;
604
+ /** 0-1+, multiplies the weather cloud amount (default 1) */
605
+ coverage?: number;
606
+ /** Cloud cell size: larger = smaller clouds (plane 0.35) */
607
+ scale?: number;
608
+ /** Drift per second [x, z] (plane [0.004, 0.002]) */
609
+ speed?: number[];
610
+ /**
611
+ * 'plane' (default): cheap, 3 noise samples, cells shrink and crowd towards the horizon.
612
+ * 'cumulus': 8 noise samples per cloudy pixel, flatter projection (clouds fill the whole sky), sun-side light and shaded undersides.
613
+ * Both are one 2D pass, no ray marching.
614
+ */
615
+ kind?: Loose<'plane' | 'cumulus'>;
616
+ /** Added to dir.y in the plane projection: smaller = stronger crowding at the horizon (plane 0.08, cumulus 0.5) */
617
+ horizon?: number;
618
+ /** Horizon fade [from, to] in dir.y: clouds are invisible below `from` and full above `to` (plane [0, 0.18], cumulus [0, 0.12]) */
619
+ fade?: number[];
620
+ /** Cloud opacity 0-1 (plane 0.9, cumulus 0.95) */
621
+ opacity?: number;
622
+ /** Width of the cloud edge in noise units: larger = softer edge (plane 0.3, cumulus 0.35) */
623
+ softness?: number;
624
+ /** 'plane' only: the 3 noise layers. scales = frequency multipliers of layers 2 and 3 (default [2.7, 6.1]), weights = their mix (default [0.6, 0.3, 0.1]) */
625
+ noise?: { scales?: number[]; weights?: number[] };
626
+ /** 'cumulus' only: contrast of the sun-side light (default 5) */
627
+ relief?: number;
628
+ }
629
+
630
+
631
+
632
+ /**
633
+ * The `detail` surface patch. Source: texture (asset name) or noise ('grain' | 'paper' | 'stroke' | 'dabs', default grain) or glsl (your own sampler
634
+ * function). Effects: color (strength, mode), normal (relief height in meters), roughness (amount). Every number is a uniform, so many materials
635
+ * with different values share one shader program. Channels (color / normal / roughness) are fixed when the material is made.
636
+ */
637
+ export interface MaterialDetail {
638
+ /** Read as data, not color: 50% gray (128) is neutral. An asset name is loaded without sRGB decoding; a THREE.Texture you pass should use NoColorSpace */
639
+ texture?: string | import('three').Texture;
640
+ noise?: Loose<'grain' | 'paper' | 'stroke' | 'dabs'>;
641
+ /** Replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns vec4(color rgb, height 0-1); p is scaled, turned, stretched */
642
+ glsl?: string;
643
+ /** Uniforms for glsl: numbers, colors, [x, y(, z, w)] arrays or textures */
644
+ uniforms?: Record<string, any>;
358
645
  /**
359
- * Who owns scene.fog: true (default; the sky creates it and writes color and distance every frame) | 'manual' (created once, then never written:
360
- * the game sets its color / near / far or its own object) | false (scene.fog = null, never touched). An object is style.sky.fog settings (kind,
361
- * color, density...) and means true. A sky() option, not a style key. Custom kinds / glsl share the page's shader chunks: a second engine needs
362
- * the same setting or it throws. See recipes/38
363
- * @example sky({ fog: 'manual' }) // the game manages scene.fog itself
646
+ * 'world' (default, looks straight down) | 'triplanar' (three axis planes blended by the surface normal; for walls and rocks) |
647
+ * 'screen' (on the screen pixels: the same grain size near and far, for illustrated / printed looks; scale is pixels per cell)
364
648
  */
365
- fog?: boolean | 'manual' | StyleFog;
366
- /** Time of day at start: fraction of a day 0–1 (0.5 noon), default 0.33 (afterwards read / write engine.sky.timeOfDay) */
367
- time?: number;
368
- /** Game seconds per day, default Infinity: the time of day never moves until the game sets a length (presets.calendar.cycle has 360) (one sky hour = dayLength / hoursPerDay game seconds; with timeScale 1 game seconds are fixed-step seconds); Infinity = the time of day never moves */
649
+ projection?: Loose<'world' | 'triplanar' | 'screen'>;
650
+ /** Repeats per meter, default 0.25; with projection 'screen' pixels per pattern cell, default 2 */
651
+ scale?: number;
652
+ /** Color effect 0-1, default 0.35 (0 turns the color part off) */
653
+ strength?: number;
654
+ /** How the color is applied: 'multiply' (default) | 'add' (lighter and darker) | 'mix' (towards the sample color) */
655
+ mode?: Loose<'multiply' | 'add' | 'mix'>;
656
+ /** Colors the sample (default white) */
657
+ tint?: ColorLike;
658
+ /** Default true: the effect fades out where the pattern is smaller than about a pixel (far away, grazing angles), so it does not shimmer. `false` keeps it. In `glsl`, `threedogDetailFootprint` is one pixel in pattern units */
659
+ fade?: boolean;
660
+ /** Degrees; turns the pattern (strokes run along it) */
661
+ direction?: number;
662
+ /** Stretches the pattern along direction (default 1, strokes 6) */
663
+ stretch?: number;
664
+ /** Noise layers 1-4, default 2 */
665
+ octaves?: number;
666
+ /** Relief height in meters (bumps the normal); needs a lit material */
667
+ normal?: number;
668
+ /** How much the sample moves roughness (standard / physical only) */
669
+ roughness?: number;
670
+ }
671
+
672
+ // ======================================================================
673
+ // Calendar calendar()
674
+ // ======================================================================
675
+
676
+ export interface CalendarOptions {
677
+ /** Time of day at start: 'HH:MM' or fraction of a day 0–1 (0.5 noon), default 0.33 (afterwards read / write engine.calendar.timeOfDay) */
678
+ time?: string | number;
679
+ /** Game seconds per day, default Infinity: the time of day never moves until the game sets a length (presets.calendar.cycle has 360) (one hour = dayLength / hoursPerDay game seconds; with clock.rate 1 calendar seconds are real seconds) */
369
680
  dayLength?: number;
370
- /** Hours per day of the displayed clock and of clock notation ('18:30'), default 24. Gameplay timing, so a sky() option and not a style key */
681
+ /** Hours per day of the displayed clock and of clock notation ('18:30'), default 24 */
371
682
  hoursPerDay?: number;
372
683
  /** Which day to start from, default 1 */
373
684
  day?: number;
374
685
  /** Days of each season given by name only, default 7 */
375
686
  daysPerSeason?: number;
376
687
  /**
377
- * The calendar's seasons, default none ([]): names (each daysPerSeason days) or { name, days } for seasons of their own length, e.g. ['spring',
378
- * 'summer', 'autumn', 'winter']
688
+ * Seasons, default none ([]): names (each daysPerSeason days) or { name, days } for seasons of their own length, e.g. ['spring',
689
+ * 'summer', 'autumn', 'winter'], [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], or ['q1', 'q2', 'q3', 'q4'] for a business year
379
690
  */
380
691
  seasons?: (string | { name: string, days: number })[];
381
- /**
382
- * Whether the sky drives engine.lights.sun: true (default; color, intensity, direction and shadow box from the keyframes) | 'manual' (still aimed
383
- * along the time of day with the shadow box; color and intensity are the game's) | false (hidden, never touched: light the world with your own
384
- * three.js lights). How the game lights its world, so a sky() option, not a style key. See recipes/38
385
- * @example sky({ sun: false, hemisphere: false }) // a dungeon lit by the game's own lights
386
- */
387
- sun?: boolean | 'manual';
388
- /** Same for engine.lights.hemi (ambient): true (default) | 'manual' (colors and intensity are the game's) | false (hidden) */
389
- hemisphere?: boolean | 'manual';
390
692
  }
391
- /** Parameters of sky.at() / daily() */
392
- export interface SkyAtOptions {
693
+ /** Parameters of calendar.at() / daily() */
694
+ export interface CalendarAtOptions {
393
695
  /** Only fire on these days: a list of days, or (day) => whether to fire */
394
696
  days?: number[] | ((day: number) => boolean);
395
697
  /** When one advance crosses several trigger points: 'all' fire them all | 'once' fire once (default) | 'skip' do not make up */
396
698
  catchUp?: 'all' | 'once' | 'skip';
397
699
  }
398
- /** Callback of sky.between: on is called when entering the period, off when leaving it */
399
- export interface SkyBetweenOptions {
700
+ /** Callback of calendar.between: on is called when entering the period, off when leaving it */
701
+ export interface CalendarBetweenOptions {
400
702
  /** Entering the period (or found inside it when aligned) */
401
703
  on?: () => void;
402
704
  /** Leaving the period (or found outside it when aligned) */
403
705
  off?: () => void;
404
706
  }
405
- /** Sky modifiers: weather and other modules write them every frame, the sky layers them on its own result */
406
- /** Sky modifiers (sky.modifiers is the combined result of all layers, read-only) */
407
- export interface SkyModifiers {
408
- /** Sunlight multiplier (layers multiply) */
409
- readonly sun: number;
410
- /** Ambient light multiplier (layers multiply) */
411
- readonly ambient: number;
412
- /** Fog distance multiplier (layers multiply, smaller = denser fog) */
413
- readonly fog: number;
414
- /** Sky tint (layers blend weighted by tint amount) */
415
- readonly tint: Color;
416
- /** Zenith tint amount 0–1 */
417
- readonly tintAmount: number;
418
- /** Horizon tint amount 0–1 */
419
- readonly horizonTintAmount: number;
420
- /** Lightning brightness (layers take the max) */
421
- readonly flash: number;
422
- }
423
-
424
- /** One layer of sky.modify: write only what to change, omitted items have no effect */
425
- export interface SkyLayer {
426
- /** Sunlight multiplier, default 1 */
427
- sun?: number;
428
- /** Ambient light multiplier, default 1 */
429
- ambient?: number;
430
- /** Fog distance multiplier, default 1 (smaller = denser fog) */
431
- fog?: number;
432
- /** Sky tint (color number or Color) */
433
- tint?: Color | number;
434
- /** Zenith tint amount 0–1, default 0 */
435
- tintAmount?: number;
436
- /** Horizon tint amount 0–1, default 0 */
437
- horizonTintAmount?: number;
438
- /** Lightning brightness, default 0 */
439
- flash?: number;
440
- /** Cover color laid over the foliage season tint (snow, ash, frost); null removes it. Rides the season patch, see recipes/47 */
441
- foliageCover?: Color | number | null;
442
- /** Cover color laid over the ground season tint */
443
- groundCover?: Color | number | null;
444
- /** How far toward the cover colors, 0–1, default 0 (style.weather.snow.cover drives the weather layer's from the snow amount) */
445
- coverAmount?: number;
446
- }
447
707
 
448
708
  // Sky (engine.sky) is generated from the JSDoc in modules/sky/Sky.js (npm run map); only the types are re-exported here
449
709
  import type { Sky } from './generated/modules/sky/Sky';
450
710
  export type { Sky };
711
+ // Calendar (engine.calendar) is generated from the JSDoc in modules/calendar/Calendar.js
712
+ import type { Calendar } from './generated/modules/calendar/Calendar';
713
+ export type { Calendar };
451
714
 
452
715
  // ======================================================================
453
716
  // Weather weather()
@@ -471,6 +734,8 @@ export interface WeatherPreset {
471
734
  grey: number;
472
735
  /** Thunder: above 0.5 it thunders */
473
736
  lightning: number;
737
+ /** A field of the game's own (heat: 1): it blends like the rest and reads back from engine.weather.current */
738
+ [field: string]: number;
474
739
  }
475
740
  /** A weather name from the game's table (weather() alone has only 'clear'; presets.weather.temperate brings seven) */
476
741
  export type WeatherName = string;
@@ -482,6 +747,20 @@ export interface WeatherOptions {
482
747
  auto?: boolean;
483
748
  /** Rain / snow particle count, default 6000 */
484
749
  particles?: number;
750
+ /** Rain particles (default streaks: color 0xc8c8c8, opacity 0.55, length 0.7 m, speed 22 m/s, slant 1); a texture or a sprite shape draws drops */
751
+ rain?: WeatherParticles;
752
+ /** Snow particles (default round sprites: color 0xffffff, opacity 0.9, size 20, maxSize 5 px, speed 1.6 m/s, sway 1.5 m), plus the cover it leaves */
753
+ snow?: WeatherParticles & { cover?: SnowCover };
754
+ /**
755
+ * Strike picture: flash (1 at the strike, fading in a third of a second) -> sky flash amount; default flickers. Return 0 and draw your own bolt on the
756
+ * weather:lightning event for a whole replacement
757
+ * @example lightning: f => f * f * 0.8
758
+ */
759
+ lightning?: (flash: number, engine: Engine) => number;
760
+ /** Multiplies the sky flash of every strike, default 1 */
761
+ lightningBrightness?: number;
762
+ /** Color the sky turns as a weather type raises grey, default 0x8c8c8c */
763
+ overcastColor?: ColorLike;
485
764
  /** The game's weather table, the whole list (default only a calm 'clear'; seven temperate ones in presets.weather.temperate.types, extend them with { ...presets.weather.temperate.types, dust: {...} }). Left-out fields are calm; extra numeric fields of the game's own blend too and show in weather.current */
486
765
  types?: Record<string, Partial<WeatherPreset> & Record<string, number>>;
487
766
  /** Candidates for automatic changes (repeat an entry for higher probability) */
@@ -492,11 +771,82 @@ export interface WeatherOptions {
492
771
  transition?: number;
493
772
  /** Rain / snow coverage (meters) */
494
773
  area?: number;
774
+ /** Seconds to the first bolt once a type with lightning > 0.5 holds, default 5 */
775
+ lightningFirst?: number;
776
+ /** Seconds between later bolts [shortest, longest], default [6, 20] */
777
+ lightningInterval?: number[];
778
+ }
779
+
780
+ /**
781
+ * Snow cover (weather({ snow: { cover } })): the season tint of foliage / ground (vegetation, terrain, materials with season) moves toward these colors
782
+ * as the weather's snow amount rises, `strength` of the way at full snow, and melts back as it falls. Leave it out and snow only draws particles.
783
+ * The same cover for anything else (ash, frost): engine.mod('ground.cover', { owner: 'ash', value: { ground: 0x555555, amount: 0.6 } }). recipes/47
784
+ * @example cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 }
785
+ */
786
+ export interface SnowCover {
787
+ /** Snow color on foliage (leave out: foliage keeps its season color) */
788
+ foliage?: ColorLike;
789
+ /** Snow color on the ground (leave out: ground keeps its season color) */
790
+ ground?: ColorLike;
791
+ /** How far toward the color at full snow, 0-1, default 0.8 */
792
+ strength?: number;
793
+ }
794
+
795
+ /** Falling weather particles: weather({ rain, snow }) and engine.weather.define(field, spec). See recipes/44-water-weather-hooks.md */
796
+ export interface WeatherParticles {
797
+ /** 'line' streaks slant with the wind; 'round' | 'soft' | 'square' sprites drift (sway) */
798
+ shape?: Loose<'line' | 'round' | 'soft' | 'square'>;
799
+ /** Sprite image (asset name), replaces the shape */
800
+ texture?: string | null;
801
+ color?: ColorLike;
802
+ opacity?: number;
803
+ /** Sprite size (pixels at 3 m) and its pixel cap */
804
+ size?: number;
805
+ maxSize?: number;
806
+ /** Streak length (meters, lines) */
807
+ length?: number;
808
+ /** Fall speed (m/s) */
809
+ speed?: number;
810
+ /** Streak lean per unit of wind (lines) */
811
+ slant?: number;
812
+ /** Sprite drift (meters) */
813
+ sway?: number;
814
+ /** Particle count (default weather({ particles }); halved on low-tier devices) */
815
+ count?: number;
816
+ /** Weather amount 0..1 -> share of particles drawn (rain default a => min(1, a * 1.2), snow () => 1; opacity follows the amount too) */
817
+ density?: (amount: number) => number;
818
+ /**
819
+ * Whole shader text (copy modules/weather/shaders.js). In scope: uCam uSize uFallOff uOpacity uColor, lines uWindDir uLen (attribute aEnd),
820
+ * sprites uPx uMaxPx uSway uSwayAmp uMap uUseMap, and your uniforms (declared for you)
821
+ */
822
+ glsl?: { vertex?: string; fragment?: string };
823
+ /** Uniforms for your glsl: numbers, colors, [x, y(, z, w)] arrays, textures; live in engine.weather.particles[field].uniforms */
824
+ uniforms?: Record<string, any>;
825
+ /** A system of your own instead (engine.weather.define only): the engine adds object, shows it while the amount is above 0.02, calls update */
826
+ create?: (engine: Engine, ctx: { area: number; count: number }) => {
827
+ object: Object3D; update?: (amount: number, ctx: { camera: any; time: number; wind: number }) => void };
828
+ }
829
+
830
+ /** One entry of engine.weather.particles */
831
+ export interface WeatherParticleSystem {
832
+ field: string;
833
+ /** The three.js object drawn (LineSegments, Points; a Sprite on WebGPURenderer; yours with create) */
834
+ object: Object3D;
835
+ /** The plain three.js material; set yours and it is drawn as given (share uniforms to keep the fall), null gives the engine's back */
836
+ material: Material | null;
837
+ /** { value } objects: uColor uLen uPx uMaxPx uSwayAmp are yours to write; uCam uOpacity uFallOff uSway uWindDir are written each frame. null with create */
838
+ uniforms: Record<string, { value: any }> | null;
839
+ /** The keys it was built from; opacity, speed, slant, density are read each frame, so a plain write is live. Undefined with create */
840
+ spec?: WeatherParticles;
841
+ [key: string]: any;
495
842
  }
496
843
 
497
844
  // Weather (engine.weather) is generated from the JSDoc in modules/weather/Weather.js (npm run map); only the types are re-exported here
498
845
  import type { Weather } from './generated/modules/weather/Weather';
499
846
  export type { Weather };
847
+ // the drawing half of weather() (engine.weatherDraw): particles, flash, picture effects; generated from modules/weather/weatherDraw.js
848
+ import type { WeatherDraw } from './generated/modules/weather/weatherDraw';
849
+ export type { WeatherDraw };
500
850
 
501
851
  // ======================================================================
502
852
  // Water water()
@@ -533,27 +883,30 @@ export interface WaterOptions {
533
883
  sea?: boolean;
534
884
  /** Global water level (meters); if omitted, the terrain's water level is used */
535
885
  level?: number;
536
- color?: ColorLike;
537
- opacity?: number;
886
+ /** Flat shading (low poly), default true */
538
887
  flat?: boolean;
539
- waveHeight?: number;
540
- waveScale?: number;
541
- waveSpeed?: number;
542
- fresnel?: number;
888
+ /** Edge length of the global water plane (meters), default 900 */
543
889
  size?: number;
890
+ /** Mesh subdivision of the global water, default 150 */
544
891
  segments?: number;
545
- normalMap?: string;
546
- normalScale?: number;
547
- normalRepeat?: number;
548
- normalSpeed?: number[];
549
- shininess?: number;
550
- specular?: ColorLike;
551
- /** Replace the whole surface material, same as style.water.material */
552
- material?: import('./style').StyleWater['material'];
553
- depthColor?: import('./style').StyleWater['depthColor'];
554
- foam?: import('./style').StyleWater['foam'];
555
- glsl?: import('./style').StyleWater['glsl'];
556
- uniforms?: import('./style').StyleWater['uniforms'];
892
+ // Picture values are not options: water({ color }) throws naming where each is written on engine.water (recipes/44)
893
+ }
894
+
895
+ /** engine.water.shader(): which GLSL the water has */
896
+ export interface WaterShaderOptions {
897
+ /** Your wave function: GLSL defining `float threedogWaterWave(vec3 p, float t)`; waveMax is its peak (foam and depthColor 'wave' divide by it, default 0.29); null = built-in */
898
+ wave?: string | { glsl: string; waveMax?: number } | null;
899
+ /** Your surface function: GLSL defining `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time)`; null = none */
900
+ surface?: string | null;
901
+ /**
902
+ * Water color from the view angle (by 'view', default: shallow looking down, deep at grazing angles) or the wave height (by 'wave': shallow on
903
+ * crests); replaces the material color. curve shapes the blend (default 1). A color left out is a neutral gray
904
+ */
905
+ depthColor?: { shallow?: ColorLike; deep?: ColorLike; by?: 'view' | 'wave'; curve?: number } | null;
906
+ /** Crest foam from the wave height (start / end: fraction of waveMax where foam begins / is full, default 0.55 / 0.85); true = defaults. Shore foam needs depth: recipes/44 */
907
+ foam?: { color?: ColorLike; start?: number; end?: number; opacity?: number } | true | null;
908
+ /** Uniforms for your GLSL, in both stages: numbers, colors, [x, y(, z, w)] arrays or textures; live in engine.water.uniforms */
909
+ uniforms?: Record<string, any>;
557
910
  }
558
911
 
559
912
  // Water (engine.water) is generated from the JSDoc in modules/water/Water.js (npm run map); only the types are re-exported here
@@ -649,7 +1002,7 @@ export interface LightSourceOptions {
649
1002
  type?: 'point' | 'spot';
650
1003
  /** Light color, default white */
651
1004
  color?: ColorLike;
652
- /** three.js intensity at full strength, default 1; 0 = off (it gives its light away) */
1005
+ /** three.js intensity, default 1; 0 = off (gives its light away). With decay 2 a surface d m away gets intensity / d^2: pick it for the distance to what it lights (one that pools on a street 4 m below blows a wall 1 m away to white). Example values are no targets: threedog shot / snap name a light that glares. */
653
1006
  intensity?: number;
654
1007
  /** three.js light distance (range, meters), default 10; also the scale of the distance score */
655
1008
  distance?: number;
@@ -672,6 +1025,11 @@ export interface LightSourceOptions {
672
1025
  * from its value at add() down to 0 as the real light fades in. Give each source its own material
673
1026
  */
674
1027
  glow?: Material | Object3D | null;
1028
+ /**
1029
+ * Follow the time of day on the curve of engine.uniforms.uNight: true = its default dusk, a number = the daylight (0..1; 0 = on only while daylight is 0) below which
1030
+ * the source fades in. Off by day (its light goes to lit sources, its stand-in dims too). Default false: lit at any hour. Needs calendar() or sky()
1031
+ */
1032
+ dusk?: boolean | number;
675
1033
  }
676
1034
  /** What lightPool.add().set(patch) can change (type and castShadow are fixed when added) */
677
1035
  export interface LightSourcePatch {
@@ -688,6 +1046,7 @@ export interface LightSourcePatch {
688
1046
  target?: PositionLike | null;
689
1047
  flicker?: ((time: number, index: number) => number) | null;
690
1048
  glow?: Material | Object3D | null;
1049
+ dusk?: boolean | number;
691
1050
  }
692
1051
  /** Handle returned by lightPool.add() */
693
1052
  export interface LightSource {
@@ -748,6 +1107,14 @@ export interface BudgetLimits {
748
1107
  chunkApplyMs?: number;
749
1108
  /** Rigid body count */
750
1109
  rigidBodies?: number;
1110
+ /** Lit point + spot lights, a game's own and pooled ones (default limit 8) */
1111
+ lights?: number;
1112
+ /** Lit point + spot lights that cast shadows */
1113
+ shadowLights?: number;
1114
+ /** Shadow maps drawn each frame, sun and cascades included, a point light counts six */
1115
+ shadowMaps?: number;
1116
+ /** The largest side of a shadow map, in pixels */
1117
+ shadowMapSize?: number;
751
1118
  /** Per-frame cost of applying background results, by stage (engine.budget.cost): worker transit (approximate), creating three.js objects, colliders, GPU upload (approximate), stream build() */
752
1119
  applyTransitMs?: number;
753
1120
  applyBuildMs?: number;