threedog 0.5.0 → 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 (511) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/README.md +21 -13
  3. package/core/Assets.js +23 -12
  4. package/core/Audio.js +1 -1
  5. package/core/Baked.js +14 -23
  6. package/core/Budget.js +2 -2
  7. package/core/DebugOverrides.js +33 -18
  8. package/core/Describe.js +10 -11
  9. package/core/Engine.js +50 -46
  10. package/core/I18n.js +2 -2
  11. package/core/Input.js +11 -5
  12. package/core/Inspect.js +6 -3
  13. package/core/InspectMaterials.js +2 -3
  14. package/core/InspectPerf.js +11 -4
  15. package/core/MaterialInfo.js +7 -5
  16. package/core/Rays.js +7 -2
  17. package/core/Stream.js +2 -3
  18. package/core/UrlState.js +49 -9
  19. package/core/Views.js +1 -0
  20. package/core/adaptive.js +2 -2
  21. package/core/assetEntry.js +5 -2
  22. package/core/assetLoad.js +13 -15
  23. package/core/assetManifest.js +6 -3
  24. package/core/assetReport.js +4 -4
  25. package/core/batchGroups.js +9 -1
  26. package/core/catalog.js +16 -3
  27. package/core/chunkStream.js +1 -1
  28. package/core/copies.js +1 -1
  29. package/core/debugView.js +4 -4
  30. package/core/describeRender.js +104 -28
  31. package/core/describeText.js +6 -6
  32. package/core/errorCodes.js +72 -45
  33. package/core/errorHints.js +4 -1
  34. package/core/errors.js +4 -4
  35. package/core/events.generated.js +1 -0
  36. package/core/gameLights.js +9 -2
  37. package/core/lifecycle.js +2 -4
  38. package/core/lightWatch.js +5 -3
  39. package/core/loop.js +18 -11
  40. package/core/math.js +7 -0
  41. package/core/moduleSlots.js +32 -7
  42. package/core/moduleTypes.js +20 -7
  43. package/core/modules.js +7 -7
  44. package/core/namedModel.js +8 -4
  45. package/core/owned.js +33 -30
  46. package/core/page.js +43 -10
  47. package/core/pictureSlots.js +33 -0
  48. package/core/pictureWriters.js +343 -0
  49. package/core/plugins.js +64 -96
  50. package/core/sceneDelta.js +12 -4
  51. package/core/sceneMethods.js +2 -9
  52. package/core/services.js +1 -1
  53. package/core/shadowTypes.js +1 -1
  54. package/core/shadows.js +405 -0
  55. package/core/sharedPoint.js +5 -19
  56. package/core/stackFrames.js +16 -5
  57. package/core/stacks.js +6 -6
  58. package/core/startup.js +9 -11
  59. package/core/thingExplain.js +1 -1
  60. package/core/things.js +1 -1
  61. package/core/tier.js +1 -1
  62. package/core/util.js +1 -1
  63. package/core/validate.js +1 -1
  64. package/core/view.js +43 -0
  65. package/docs/AI.md +62 -58
  66. package/docs/API.md +15 -15
  67. package/docs/CODEMAP.md +36 -54
  68. package/docs/COMMANDS.md +28 -25
  69. package/docs/CONVENTIONS.md +36 -30
  70. package/docs/MIGRATING-0.4.md +93 -1
  71. package/docs/MIGRATING-0.6.md +126 -0
  72. package/docs/MIGRATING-0.7.md +39 -0
  73. package/docs/THREE.md +24 -22
  74. package/docs/api/assets.md +5 -3
  75. package/docs/api/audio.md +2 -2
  76. package/docs/api/budget.md +4 -0
  77. package/docs/api/characters.md +3 -1
  78. package/docs/api/collision.md +2 -2
  79. package/docs/api/engine.md +47 -20
  80. package/docs/api/events.md +2 -1
  81. package/docs/api/grids.md +8 -1
  82. package/docs/api/ground.md +1 -1
  83. package/docs/api/hud.md +3 -0
  84. package/docs/api/input.md +3 -2
  85. package/docs/api/interactions.md +3 -1
  86. package/docs/api/inventory.md +1 -2
  87. package/docs/api/level.md +0 -1
  88. package/docs/api/lightPool.md +1 -1
  89. package/docs/api/occlusion.md +5 -0
  90. package/docs/api/particles.md +6 -3
  91. package/docs/api/pickups.md +6 -0
  92. package/docs/api/post.md +5 -3
  93. package/docs/api/sky.md +12 -10
  94. package/docs/api/terrain.md +12 -6
  95. package/docs/api/terrainDraw.md +12 -0
  96. package/docs/api/tools.md +8 -7
  97. package/docs/api/triggers.md +2 -0
  98. package/docs/api/vegetation.md +7 -2
  99. package/docs/api/vegetationDraw.md +10 -0
  100. package/docs/api/water.md +6 -2
  101. package/docs/api/weather.md +5 -0
  102. package/docs/api/weatherDraw.md +10 -0
  103. package/docs/api/world.md +1 -1
  104. package/docs/recipes/01-new-game.md +19 -23
  105. package/docs/recipes/03-items-pickups.md +25 -4
  106. package/docs/recipes/05-props-bake.md +53 -37
  107. package/docs/recipes/06-clock-events.md +3 -3
  108. package/docs/recipes/07-flow-scenes-pause.md +12 -3
  109. package/docs/recipes/08-weather-sky.md +45 -57
  110. package/docs/recipes/09-materials-lights-models.md +185 -0
  111. package/docs/recipes/10-blender-level.md +2 -2
  112. package/docs/recipes/11-vehicles.md +3 -3
  113. package/docs/recipes/13-animation.md +13 -7
  114. package/docs/recipes/14-custom-module.md +7 -5
  115. package/docs/recipes/15-perf.md +3 -3
  116. package/docs/recipes/16-dev-bridge.md +22 -12
  117. package/docs/recipes/18-world.md +10 -8
  118. package/docs/recipes/19-shooting-picking.md +7 -5
  119. package/docs/recipes/20-content-actions-save.md +6 -2
  120. package/docs/recipes/21-camera.md +8 -3
  121. package/docs/recipes/23-ops.md +1 -1
  122. package/docs/recipes/26-ui-parts.md +35 -11
  123. package/docs/recipes/28-terrain.md +12 -12
  124. package/docs/recipes/29-grid.md +14 -5
  125. package/docs/recipes/30-templates.md +8 -3
  126. package/docs/recipes/31-audio.md +4 -4
  127. package/docs/recipes/32-action-game.md +18 -4
  128. package/docs/recipes/34-environment-lighting.md +102 -38
  129. package/docs/recipes/35-picture-from-reference.md +147 -0
  130. package/docs/recipes/36-sky-ground-plants.md +158 -0
  131. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
  132. package/docs/recipes/38-environment-hooks.md +67 -0
  133. package/docs/recipes/40-scene.md +106 -27
  134. package/docs/recipes/42-terrain-shape.md +1 -1
  135. package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
  136. package/docs/recipes/44-water-weather-hooks.md +191 -0
  137. package/docs/recipes/45-cascaded-shadows.md +121 -23
  138. package/docs/recipes/46-blender-art-route.md +17 -20
  139. package/docs/recipes/47-island-snow-backdrop.md +10 -12
  140. package/docs/recipes/49-game-module-contract.md +1 -1
  141. package/docs/recipes/50-own-renderer.md +3 -3
  142. package/docs/recipes/52-around-the-picture.md +181 -0
  143. package/docs/recipes/53-ground-up-close.md +12 -12
  144. package/docs/recipes/54-three-idioms.md +18 -18
  145. package/docs/recipes/55-mods-time-wrap.md +17 -5
  146. package/docs/recipes/56-webgpu-tsl.md +66 -23
  147. package/docs/recipes/57-control.md +39 -0
  148. package/docs/recipes/58-input.md +3 -0
  149. package/docs/recipes/59-depth-post-effects.md +5 -5
  150. package/docs/recipes/60-judge-the-picture.md +39 -24
  151. package/docs/recipes/61-deploy.md +27 -0
  152. package/docs/recipes/62-picture-code.md +244 -0
  153. package/docs/recipes/63-third-person-start.md +77 -0
  154. package/docs/recipes/64-particles.md +35 -0
  155. package/examples/action/.threedog/content-index.json +1 -1
  156. package/examples/action/GAMEMAP.md +7 -5
  157. package/examples/action/main.js +5 -4
  158. package/examples/action/models.js +12 -14
  159. package/examples/action/picture/index.js +13 -0
  160. package/examples/action/picture/lights.js +35 -0
  161. package/examples/action/picture/materials.js +8 -0
  162. package/examples/action/picture/palette.js +33 -0
  163. package/examples/plain-picture/.threedog/content-index.json +1 -0
  164. package/examples/plain-picture/FINDINGS.md +53 -0
  165. package/examples/plain-picture/GAMEMAP.md +90 -0
  166. package/examples/plain-picture/main.js +48 -0
  167. package/examples/plain-picture/picture/index.js +21 -0
  168. package/examples/plain-picture/picture/lights.js +54 -0
  169. package/examples/plain-picture/picture/materials.js +24 -0
  170. package/examples/plain-picture/picture/palette.js +16 -0
  171. package/examples/plain-picture/picture/sky.js +37 -0
  172. package/examples/pullable.json +31 -9
  173. package/examples/rc2d/GAMEMAP.md +8 -3
  174. package/examples/rc2d/README.md +11 -6
  175. package/examples/rc2d/main.js +25 -33
  176. package/examples/rc2d/picture/index.js +18 -0
  177. package/examples/rc2d/picture/lights.js +11 -0
  178. package/examples/rc2d/picture/materials.js +18 -0
  179. package/examples/rc2d/picture/palette.js +15 -0
  180. package/examples/rc2d/picture/post.js +11 -0
  181. package/examples/rc2d/rc2d.js +18 -28
  182. package/examples/sheepisland/.threedog/content-index.json +1 -1
  183. package/examples/sheepisland/GAMEMAP.md +13 -10
  184. package/examples/sheepisland/assets.js +2 -2
  185. package/examples/sheepisland/content/templates.js +1 -1
  186. package/examples/sheepisland/content/vegetation.js +3 -1
  187. package/examples/sheepisland/main.js +15 -9
  188. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  189. package/examples/sheepisland/picture/index.js +20 -0
  190. package/examples/sheepisland/picture/lights.js +34 -0
  191. package/examples/sheepisland/picture/materials.js +61 -0
  192. package/examples/sheepisland/picture/palette.js +60 -0
  193. package/examples/sheepisland/picture/sky.js +20 -0
  194. package/examples/sheepisland/views.js +1 -1
  195. package/examples/styletest/.threedog/content-index.json +1 -1
  196. package/examples/styletest/GAMEMAP.md +15 -11
  197. package/examples/styletest/main.js +20 -30
  198. package/examples/styletest/models.js +29 -29
  199. package/examples/styletest/params.js +1 -4
  200. package/examples/styletest/picture/env.js +38 -0
  201. package/examples/styletest/picture/index.js +16 -0
  202. package/examples/styletest/picture/lights.js +9 -0
  203. package/examples/styletest/picture/materials.js +28 -0
  204. package/examples/styletest/picture/palette.js +22 -0
  205. package/examples/techniques/contact-shadows/README.md +22 -23
  206. package/examples/techniques/contact-shadows/contactShadows.js +32 -16
  207. package/examples/techniques/contact-shadows/main.js +20 -18
  208. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  209. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  210. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  211. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  212. package/examples/techniques/day-night-grade/README.md +13 -16
  213. package/examples/techniques/day-night-grade/main.js +15 -25
  214. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  215. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  216. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  217. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  218. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  219. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  220. package/examples/techniques/interior-light/README.md +16 -13
  221. package/examples/techniques/interior-light/interiorLight.js +19 -17
  222. package/examples/techniques/interior-light/main.js +30 -67
  223. package/examples/techniques/interior-light/picture/index.js +24 -0
  224. package/examples/techniques/interior-light/picture/lights.js +52 -0
  225. package/examples/techniques/interior-light/picture/materials.js +13 -0
  226. package/examples/techniques/interior-light/picture/palette.js +32 -0
  227. package/examples/techniques/interior-light/picture/sky.js +40 -0
  228. package/examples/techniques/modular-building/README.md +4 -3
  229. package/examples/techniques/modular-building/kit.js +2 -2
  230. package/examples/techniques/modular-building/main.js +9 -17
  231. package/examples/techniques/modular-building/picture/index.js +17 -0
  232. package/examples/techniques/modular-building/picture/lights.js +26 -0
  233. package/examples/techniques/modular-building/picture/materials.js +13 -0
  234. package/examples/techniques/modular-building/picture/palette.js +23 -0
  235. package/examples/techniques/night-lights/README.md +15 -14
  236. package/examples/techniques/night-lights/main.js +20 -43
  237. package/examples/techniques/night-lights/nightLights.js +25 -21
  238. package/examples/techniques/night-lights/picture/index.js +18 -0
  239. package/examples/techniques/night-lights/picture/lights.js +44 -0
  240. package/examples/techniques/night-lights/picture/materials.js +15 -0
  241. package/examples/techniques/night-lights/picture/palette.js +34 -0
  242. package/examples/techniques/night-lights/picture/post.js +9 -0
  243. package/examples/techniques/night-lights/picture/sky.js +36 -0
  244. package/examples/techniques/outlines-and-rim/README.md +2 -2
  245. package/examples/techniques/outlines-and-rim/main.js +15 -38
  246. package/examples/techniques/outlines-and-rim/outlines.js +3 -3
  247. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  248. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  249. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  250. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  251. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  252. package/examples/techniques/procedural-animation/README.md +5 -3
  253. package/examples/techniques/procedural-animation/main.js +9 -7
  254. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  255. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  256. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  257. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  258. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  259. package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
  260. package/examples/techniques/procedural-surface/README.md +2 -0
  261. package/examples/techniques/procedural-surface/main.js +17 -55
  262. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  263. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  264. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  265. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  266. package/examples/techniques/stylized-shading/README.md +13 -14
  267. package/examples/techniques/stylized-shading/main.js +11 -42
  268. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  269. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  270. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  271. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  272. package/examples/techniques/stylized-shading/shading.js +2 -2
  273. package/examples/techniques/sun-and-key-light/README.md +20 -22
  274. package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
  275. package/examples/techniques/sun-and-key-light/main.js +19 -63
  276. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  277. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  278. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  279. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  280. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  281. package/examples/techniques/three-looks/README.md +21 -0
  282. package/examples/techniques/three-looks/main.js +58 -0
  283. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  284. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  285. package/examples/techniques/three-looks/picture/comic.js +27 -0
  286. package/examples/techniques/three-looks/picture/index.js +14 -0
  287. package/examples/techniques/three-looks/picture/sun.js +23 -0
  288. package/examples/techniques/wet-road/README.md +7 -4
  289. package/examples/techniques/wet-road/main.js +18 -38
  290. package/examples/techniques/wet-road/picture/index.js +17 -0
  291. package/examples/techniques/wet-road/picture/lights.js +57 -0
  292. package/examples/techniques/wet-road/picture/materials.js +16 -0
  293. package/examples/techniques/wet-road/picture/palette.js +24 -0
  294. package/examples/techniques/wet-road/picture/sky.js +46 -0
  295. package/examples/webgpu-tsl/GAMEMAP.md +9 -4
  296. package/examples/webgpu-tsl/README.md +13 -10
  297. package/examples/webgpu-tsl/main.js +30 -7
  298. package/examples/webgpu-tsl/picture/index.js +18 -0
  299. package/examples/webgpu-tsl/picture/lights.js +25 -0
  300. package/examples/webgpu-tsl/picture/materials.js +36 -0
  301. package/examples/webgpu-tsl/picture/palette.js +23 -0
  302. package/examples/webgpu-tsl/picture/post.js +16 -0
  303. package/examples/webgpu-tsl/picture/sky.js +30 -0
  304. package/examples/world/.threedog/content-index.json +1 -1
  305. package/examples/world/GAMEMAP.md +15 -12
  306. package/examples/world/art/humanoid.js +9 -13
  307. package/examples/world/art/index.js +2 -2
  308. package/examples/world/art/models.js +3 -4
  309. package/examples/world/art/shapes.js +2 -2
  310. package/examples/world/assets.js +2 -2
  311. package/examples/world/content/audio.js +1 -1
  312. package/examples/world/content/items.js +1 -1
  313. package/examples/world/content/props.js +1 -1
  314. package/examples/world/content/templates.js +1 -1
  315. package/examples/world/content/vegetation.js +1 -1
  316. package/examples/world/main.js +10 -10
  317. package/examples/world/models.js +17 -7
  318. package/examples/world/picture/index.js +20 -0
  319. package/examples/world/picture/lights.js +41 -0
  320. package/examples/world/picture/materials.js +34 -0
  321. package/examples/world/picture/palette.js +74 -0
  322. package/examples/world/picture/post.js +9 -0
  323. package/examples/world/picture/sky.js +39 -0
  324. package/index.d.ts +7 -16
  325. package/index.js +7 -7
  326. package/llms.txt +15 -13
  327. package/modules/ambience/Ambience.js +1 -1
  328. package/modules/calendar/Calendar.js +1 -1
  329. package/modules/calendar/index.js +1 -0
  330. package/modules/camera/FirstPersonCamera.js +1 -1
  331. package/modules/camera/FixedCamera.js +2 -2
  332. package/modules/camera/RtsCamera.js +1 -1
  333. package/modules/camera/common.js +7 -5
  334. package/modules/characters/Character.js +15 -10
  335. package/modules/characters/NPC.js +5 -5
  336. package/modules/characters/assetModel.js +5 -4
  337. package/modules/characters/index.js +28 -3
  338. package/modules/characters/movers/common.js +6 -1
  339. package/modules/characters/movers/manual.js +3 -0
  340. package/modules/characters/movers/support.js +25 -11
  341. package/modules/characters/npcSim.js +5 -1
  342. package/modules/characters/proceduralRig.js +18 -4
  343. package/modules/characters/useModel.js +2 -2
  344. package/modules/collision/Collision.js +4 -2
  345. package/modules/content/index.js +8 -0
  346. package/modules/content/models.js +56 -11
  347. package/modules/content/props.js +5 -3
  348. package/modules/content/rules.js +12 -4
  349. package/modules/content/templates.js +5 -3
  350. package/modules/gameplay/Interactions.js +91 -16
  351. package/modules/gameplay/Inventory.js +3 -3
  352. package/modules/gameplay/dialogueBox.js +1 -1
  353. package/modules/gameplay/dialogueBubbles.js +1 -1
  354. package/modules/gameplay/interactionPrompt.js +1 -1
  355. package/modules/gameplay/interactions.contract.js +1 -1
  356. package/modules/gameplay/inventoryOps.js +2 -2
  357. package/modules/gameplay/pickups.js +62 -24
  358. package/modules/gameplay/questLog.js +2 -2
  359. package/modules/grid/Layer.js +13 -0
  360. package/modules/grid/index.js +40 -11
  361. package/modules/grid/preview.js +24 -15
  362. package/modules/grid/tiles.js +15 -19
  363. package/modules/hlod/index.js +3 -2
  364. package/modules/hud/index.js +13 -0
  365. package/modules/hud/parts.js +9 -7
  366. package/modules/level/index.js +5 -4
  367. package/modules/lights/index.js +12 -8
  368. package/modules/music/Music.js +1 -1
  369. package/modules/particles/Particles.js +41 -20
  370. package/modules/particles/effect.js +21 -6
  371. package/modules/photo/Photo.js +11 -10
  372. package/modules/settings/Settings.js +7 -7
  373. package/modules/settings/apply.js +5 -5
  374. package/modules/settings/sections.js +2 -2
  375. package/modules/settings/strings.js +1 -1
  376. package/modules/sky/Sky.js +104 -89
  377. package/modules/sky/clouds.js +16 -17
  378. package/modules/sky/dome.js +100 -0
  379. package/modules/sky/domeLayers.js +5 -5
  380. package/modules/sky/environment.js +45 -169
  381. package/modules/sky/fog.js +5 -180
  382. package/modules/sky/frame.js +26 -90
  383. package/modules/sky/season.js +3 -3
  384. package/modules/sky/shader.js +35 -29
  385. package/modules/sky/skyModule.js +25 -22
  386. package/modules/sky/tint.js +9 -11
  387. package/modules/terrain/ChunkManager.js +29 -12
  388. package/modules/terrain/draw.js +154 -0
  389. package/modules/terrain/index.js +44 -66
  390. package/modules/terrain/terrainDefaults.js +2 -2
  391. package/modules/terrain/terrainEdit.js +1 -1
  392. package/modules/terrain/terrainGen.js +2 -2
  393. package/modules/triggers/index.js +10 -6
  394. package/modules/vegetation/Vegetation.js +58 -17
  395. package/modules/vegetation/draw.js +191 -0
  396. package/modules/vegetation/groundChunks.js +1 -1
  397. package/modules/vegetation/index.js +10 -10
  398. package/modules/water/Water.js +135 -88
  399. package/modules/water/surface.js +53 -53
  400. package/modules/weather/Weather.js +52 -17
  401. package/modules/weather/particles.js +13 -5
  402. package/modules/weather/shaders.js +1 -1
  403. package/modules/weather/weatherDraw.js +141 -0
  404. package/modules/world/World.js +2 -2
  405. package/modules/world/views.js +1 -1
  406. package/package.json +3 -2
  407. package/presets.js +2 -2
  408. package/render/PostFX.js +199 -41
  409. package/render/backend.js +52 -6
  410. package/render/cascades.js +195 -0
  411. package/render/cascades.tsl.js +96 -0
  412. package/render/daylight.js +39 -0
  413. package/render/detail.js +5 -5
  414. package/render/effects.js +41 -26
  415. package/render/fx/cel.tsl.js +42 -0
  416. package/render/fx/index.js +7 -5
  417. package/render/fx/patchNodes.tsl.js +1 -1
  418. package/render/fx/postWebGPU.tsl.js +30 -7
  419. package/render/fx/sky.tsl.js +19 -92
  420. package/render/fx/water.tsl.js +1 -1
  421. package/render/layers.js +14 -0
  422. package/render/lighting.js +6 -5
  423. package/render/lightmap.js +142 -0
  424. package/render/lights.js +23 -201
  425. package/render/materials.js +44 -160
  426. package/render/neutral.js +23 -0
  427. package/render/occlusion.js +184 -0
  428. package/render/ownFrame.js +1 -1
  429. package/render/patches.js +34 -29
  430. package/render/postWebGL.js +11 -3
  431. package/render/probes.js +179 -122
  432. package/render/slots.js +4 -4
  433. package/render/terms.js +53 -101
  434. package/render/uniformDecl.js +1 -1
  435. package/types/core.d.ts +333 -296
  436. package/types/gameplay.d.ts +65 -26
  437. package/types/generated/core/Audio.d.ts +1 -1
  438. package/types/generated/core/DebugOverrides.d.ts +14 -6
  439. package/types/generated/core/Input.d.ts +9 -2
  440. package/types/generated/core/page.d.ts +9 -2
  441. package/types/generated/modules/grid/Layer.d.ts +8 -0
  442. package/types/generated/modules/grid/index.d.ts +29 -5
  443. package/types/generated/modules/particles/Particles.d.ts +13 -6
  444. package/types/generated/modules/sky/Sky.d.ts +85 -18
  445. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  446. package/types/generated/modules/water/Water.d.ts +50 -3
  447. package/types/generated/modules/weather/Weather.d.ts +33 -3
  448. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  449. package/types/generated/modules/world/World.d.ts +2 -2
  450. package/types/generated/render/PostFX.d.ts +53 -10
  451. package/types/generated/render/lighting.d.ts +29 -0
  452. package/types/generated/render/materials.d.ts +19 -44
  453. package/types/generated/render/occlusion.d.ts +13 -0
  454. package/types/physics.d.ts +5 -3
  455. package/types/tsl.d.ts +8 -0
  456. package/types/world.d.ts +376 -57
  457. package/ui/Focus.js +12 -2
  458. package/ui/LoadingScreen.js +2 -2
  459. package/ui/Parts.js +8 -4
  460. package/ui/UI.js +10 -10
  461. package/ui/cursor.js +1 -1
  462. package/ui/theme.js +33 -27
  463. package/ui/touchPart.js +1 -1
  464. package/core/look/coreParts.js +0 -219
  465. package/core/look/part.js +0 -253
  466. package/core/look/points.js +0 -255
  467. package/core/look/report.js +0 -96
  468. package/core/look/shadowPart.js +0 -63
  469. package/core/look/state.js +0 -45
  470. package/core/look/write.js +0 -70
  471. package/core/styleParts.js +0 -114
  472. package/docs/api/style.md +0 -136
  473. package/docs/api/terrainLook.md +0 -10
  474. package/docs/api/vegetationLook.md +0 -10
  475. package/docs/api/weatherLook.md +0 -10
  476. package/docs/recipes/09-style.md +0 -218
  477. package/docs/recipes/35-style-from-reference.md +0 -153
  478. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  479. package/docs/recipes/38-environment-look-hooks.md +0 -99
  480. package/docs/recipes/41-thing-registry.md +0 -97
  481. package/docs/recipes/44-water-weather-look-hooks.md +0 -144
  482. package/docs/recipes/48-make-material.md +0 -75
  483. package/docs/recipes/52-look.md +0 -282
  484. package/examples/action/look.js +0 -5
  485. package/examples/sheepisland/style/index.js +0 -79
  486. package/examples/styletest/look.js +0 -11
  487. package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
  488. package/examples/webgpu-tsl/tslScene.js +0 -75
  489. package/examples/world/style/index.js +0 -61
  490. package/examples/world/style/plugins/10-bloom.js +0 -5
  491. package/modules/sky/cascades.js +0 -186
  492. package/modules/sky/cascades.tsl.js +0 -82
  493. package/modules/sky/look.js +0 -54
  494. package/modules/sky/lookFog.js +0 -76
  495. package/modules/sky/lookShadow.js +0 -62
  496. package/modules/sky/lookSky.js +0 -169
  497. package/modules/sky/shadow.js +0 -98
  498. package/modules/terrain/look.js +0 -83
  499. package/modules/terrain/lookGround.js +0 -66
  500. package/modules/vegetation/look.js +0 -119
  501. package/modules/vegetation/lookWind.js +0 -98
  502. package/modules/water/look.js +0 -91
  503. package/modules/water/surfaceDefaults.js +0 -3
  504. package/modules/weather/look.js +0 -74
  505. package/modules/weather/weatherLook.js +0 -135
  506. package/render/lookGlow.js +0 -139
  507. package/render/lookSurface.js +0 -224
  508. package/render/postLook.js +0 -164
  509. package/render/surface.js +0 -105
  510. package/types/generated/modules/weather/weatherLook.d.ts +0 -12
  511. package/types/style.d.ts +0 -671
@@ -1,98 +0,0 @@
1
- // look.wind: how plants sway. Registered by the vegetation look module (it is the one that adds wind patches to its species' materials).
2
- // set({ frequency, amplitude }) uniforms: live on every wind patch (trees already planted too)
3
- // patch('sway', glsl | { glsl, tsl, uniforms }) a threedogWind function (tsl: the WebGPURenderer form, (ctx) => moved position);
4
- // read when a species is ADDED, so patch before vegetation.define.
5
- // The only way in: style.wind.glsl / .uniforms throw (one shader injection entry per look value)
6
- // No replace: the sway patch already is the whole motion; weather's gusts (uWind) still scale it.
7
- // Also look.vegetation (defineVegetationLook below): the color hook on every species' material.
8
- import { defineLookPart, hookSpec } from '../../core/look/part.js';
9
- import { codedError } from '../../core/errorHints.js';
10
- import { windCustom } from '../../render/materials.js';
11
- import { patchMaterial, unpatchMaterial } from '../../render/patches.js';
12
- import { hashText } from '../../render/effects.js';
13
-
14
- /** The custom sway { glsl, uniforms } to give a new wind patch, or null for the built-in sway */
15
- export function swayOf(e) { const v = e.look?.wind?.value('hook:sway'); return v ? hookSpec(v) : null; }
16
-
17
- /** @param {any} e */
18
- export function defineWindLook(e) {
19
- if (e.look?.wind) return;
20
- const u = e.uniforms, w = e.style.wind ?? {};
21
- for (const k of ['glsl', 'uniforms']) if (w[k] != null) throw codedError('look-param', `style.wind.${k} is not an option; your own sway goes through the look hook: engine.look.wind.patch('sway', { glsl, uniforms }) before vegetation.define`);
22
- const part = defineLookPart(e, {
23
- id: 'wind', group: 'motion', module: 'vegetationLook', object: () => u, docs: ['recipes/52-look.md'],
24
- params: {
25
- frequency: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'sway speed multiplier (style.wind.frequency)' },
26
- amplitude: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: "multiplies every species' wind amplitude; 0 = plants stand still" },
27
- },
28
- style: () => ({ frequency: w.frequency }),
29
- read: () => ({ frequency: u.uWindFreq.value, amplitude: u.uWindAmp.value }),
30
- apply(v, changed) {
31
- if (changed.has('frequency')) u.uWindFreq.value = v.frequency;
32
- if (changed.has('amplitude')) u.uWindAmp.value = v.amplitude;
33
- },
34
- hooks: { sway: { signature: 'void threedogWind(inout vec3 transformed, vec3 ip, vec3 position); tsl: (ctx) => vec3 moved object-space position', scope: ['vertex'], example: 'engine.look.wind.patch("sway", glsl) // or { glsl, tsl, uniforms }' } },
35
- noReplace: 'the sway patch already is the whole motion; patch("sway", glsl) rewrites it, set({ amplitude: 0 }) stops it',
36
- });
37
- const patch = part.patch.bind(part);
38
- part.patch = (name, glsl, o) => { // a wrong sway function throws here, not later inside vegetation.define
39
- if (glsl != null) {
40
- try { windCustom(hookSpec(glsl)); } catch (err) { throw codedError('look-param', `look.wind.patch('${name}'): ${err.message}`); }
41
- const miss = missingForm(e, hookSpec(glsl));
42
- if (miss) throw codedError('look-param', `look.wind.patch('${name}'): ${miss}`);
43
- }
44
- return patch(name, glsl, o);
45
- };
46
- }
47
-
48
- /** Each renderer draws its own form; the one this engine's renderer needs, when missing, is named (else the hook would do nothing silently) */
49
- function missingForm(e, s) {
50
- const gpu = !!e.renderer?.isWebGPURenderer;
51
- if (!gpu && s.glsl == null) return 'has only a tsl form, which WebGLRenderer cannot draw: give glsl too ({ glsl, tsl })';
52
- if (gpu && s.tsl == null) return 'has only a glsl form, which WebGPURenderer cannot draw: give tsl too ({ glsl, tsl })';
53
- return null;
54
- }
55
-
56
- const COLOR = 'vegetationColor'; // the patch name of look.vegetation's color hook on every species' material
57
- /** The game's look.vegetation color patch, or null @param {any} e */
58
- export function colorPatchOf(e) {
59
- const v = e.look?.vegetation?.value('hook:color');
60
- if (!v) return null;
61
- const s = hookSpec(v);
62
- let p = PATCHES.get(s); // one patch object per hook value: every species' material shares its program
63
- if (!p) PATCHES.set(s, p = { name: COLOR, slot: 'color', cacheKey: hashText(JSON.stringify([s.glsl ?? '', s.pars ?? ''])),
64
- ...(s.uniforms && { uniforms: s.uniforms }), ...(s.glsl != null && { glsl: s.glsl, ...(s.pars && { pars: s.pars }) }), ...(s.tsl && { tsl: s.tsl }) });
65
- return p;
66
- }
67
- const PATCHES = new WeakMap();
68
-
69
- /**
70
- * look.vegetation: change part of how plants are drawn without replacing the vegetation look (that is engine.use(myPlants, { replaces: 'vegetation-look' })).
71
- * patch('color', glsl | { glsl, tsl, uniforms, pars }) code in the 'color' slot of every species' material (render/slots.js): diffuseColor
72
- * (vertex / instance colors and the season tint applied) is yours to change; tsl:
73
- * (ctx) => vec4 from ctx.color. Live: species already planted change at once.
74
- * The sway shape is look.wind.patch('sway', { glsl, tsl }): one hook per thing, not two names for it.
75
- * @param {any} e @param {any} look the VegetationLook (its species materials)
76
- */
77
- export function defineVegetationLook(e, look) {
78
- if (e.look?.vegetation) return;
79
- defineLookPart(e, {
80
- id: 'vegetation', group: 'surface', module: 'vegetationLook', object: () => look.kinds, docs: ['recipes/52-look.md'], params: {},
81
- hooks: { color: { signature: "'color' slot code on diffuseColor (vec4); tsl: (ctx) => vec4 from ctx.color", scope: ['diffuseColor', 'vThreedogWorld (needs world)', 'engine uniforms you list'],
82
- example: "engine.look.vegetation.patch('color', { glsl: 'diffuseColor.rgb *= vec3(1.1, 0.9, 0.7);', tsl: c => c.color.mul(c.tsl.vec4(1.1, 0.9, 0.7, 1)) })" } },
83
- validate: (k, v) => {
84
- if (k !== 'hook:color' || v == null) return null;
85
- const s = hookSpec(v);
86
- if (typeof s !== 'object' || (s.glsl != null && typeof s.glsl !== 'string') || (s.tsl != null && typeof s.tsl !== 'function')) return 'is GLSL code, or { glsl, tsl: (ctx) => vec4, uniforms }';
87
- return missingForm(e, s);
88
- },
89
- applyHook() { // every species' material gets the new code (or loses it): the shared patch keeps one program for all of them
90
- const p = colorPatchOf(e);
91
- for (const k of look.kinds.values()) for (const m of [k.material].flat()) {
92
- if (!m) continue;
93
- if (p) patchMaterial(m, [p]); else unpatchMaterial(m, COLOR);
94
- }
95
- },
96
- noReplace: "the whole plant look is a module: engine.use(myPlants, { replaces: 'vegetation-look' }) keeps collision, felling and saves",
97
- });
98
- }
@@ -1,91 +0,0 @@
1
- // look.water: the water's look as a look part (recipes/52-look.md).
2
- // set({ color, opacity, waveHeight, waveScale, waveSpeed, fresnel, live: uniforms and material fields, no recompile
3
- // normalScale, normalRepeat, normalSpeed, shininess, specular }) (normalRepeat rewrites the meshes' UVs once)
4
- // set({ depthColor, foam, normalMap }) structural: the shared material is rebuilt once (one recompile)
5
- // patch('wave' | 'surface', glsl) the GLSL hooks (recipes/44), the only way GLSL reaches the water
6
- // replace((engine, { uniforms, waves, surface, normalMap }) => Material) the whole surface (style.water.material)
7
- // The style layer is style.water; water({...}) takes no look values (they throw there, naming set). Why a rebuild and not a patch of the old
8
- // material: depthColor / foam / hooks decide which GLSL exists, and the shader is part of the material program.
9
- import { defineLookPart, REPLACE } from '../../core/look/part.js';
10
- import { waterLook } from './surface.js';
11
-
12
- const WHY = 'the water module draws a plain gray, mostly opaque sea when the style gives none';
13
- const OFF = "engine.use(water({ sea: false })) for no global water, or look.water.set({ opacity: 0 }) to hide the surface";
14
- const KEYS = ['color', 'opacity', 'waveHeight', 'waveScale', 'waveSpeed', 'fresnel', 'depthColor', 'foam', 'normalMap', 'normalScale', 'normalRepeat',
15
- 'normalSpeed', 'shininess', 'specular'];
16
- /** The look keys water({...}) no longer takes (Water.js throws naming look.water.set) */
17
- export const LOOK_KEYS = KEYS;
18
- const UN = { waveHeight: 'uWave', waveScale: 'uWaveScale', waveSpeed: 'uWaveSpeed', fresnel: 'uFresnel' }; // the uniforms behind the live keys
19
- const STRUCT = ['depthColor', 'foam', 'normalMap'];
20
- const validate = (w, k) => v => { try { waterLook({ ...w.st, [k]: v }); return null; } catch (err) { return err.message; } };
21
-
22
- /** @param {any} w the Water module */
23
- export function defineWaterLook(w) {
24
- const e = w.engine, st = w.st;
25
- const pick = o => Object.fromEntries(KEYS.filter(k => o[k] !== undefined).map(k => [k, o[k]]));
26
- const built = { sig: '', material: undefined };
27
- const sig = () => JSON.stringify([st.depthColor ?? null, st.foam ?? null, st._hooks ?? null, st.normalMap ?? null]);
28
- built.sig = sig(); built.material = st.material;
29
- const live = (k, v) => {
30
- const m = w.material, u = w._u;
31
- if (k === 'color' && !st.material && m.color) m.color.set(v);
32
- else if (k === 'opacity' && !st.material) { const t = v < 1; m.opacity = v; if (m.transparent !== t) { m.transparent = t; m.needsUpdate = true; } }
33
- else if (k === 'shininess' && 'shininess' in m) m.shininess = v;
34
- else if (k === 'specular' && m.specular?.isColor) m.specular.set(v);
35
- else if (k === 'normalScale' && m.normalScale) m.normalScale.set(v, v);
36
- else if (k === 'normalRepeat') w._retile();
37
- else if (u?.[UN[k]]) u[UN[k]].value = v;
38
- };
39
- const rebuild = () => {
40
- const now = sig();
41
- if (now === built.sig && st.material === built.material) return; // the same structure again (e.g. the game layer repeating the style): nothing to do
42
- if (JSON.parse(built.sig)[3] !== (st.normalMap ?? null)) w._setNormalMap(st.normalMap);
43
- built.sig = now; built.material = st.material;
44
- w._rebuild();
45
- };
46
- const p = defineLookPart(e, {
47
- id: 'water', group: 'surface', module: 'water', object: () => ({ material: w.material, sea: w.sea }), docs: ['recipes/52-look.md'], applyAtStart: false,
48
- params: {
49
- color: { type: 'any', default: 0x888888, cost: 'uniform', why: WHY, off: OFF, desc: 'base color (any THREE.Color input)' },
50
- opacity: { type: 'number', default: 0.85, min: 0, max: 1, cost: 'uniform', why: WHY, off: OFF },
51
- waveHeight: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'multiplies the wave function (0 = flat)' },
52
- waveScale: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'world position scale fed to the wave function' },
53
- waveSpeed: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'time scale fed to the wave function' },
54
- fresnel: { type: 'number', default: 0.5, min: 0, max: 1, cost: 'uniform', why: 'grazing angles blend toward the fog (horizon) color', off: 'look.water.set({ fresnel: 0 })' },
55
- depthColor: { type: 'any', default: null, neutral: true, cost: 'recompile', desc: '{ shallow, deep, by: "view" | "wave", curve } or null; rebuilds the water material once', check: validate(w, 'depthColor') },
56
- foam: { type: 'any', default: null, neutral: true, cost: 'recompile', desc: 'true | { color, start, end, opacity } or null; rebuilds the water material once', check: validate(w, 'foam') },
57
- normalMap: { type: 'any', default: null, neutral: true, cost: 'recompile', desc: 'normal map asset name or path (null = none); rebuilds the water material once',
58
- check: v => (v == null || typeof v === 'string' ? null : `is an asset name or path (or null); got ${typeof v}`) },
59
- normalScale: { type: 'number', default: 0.4, min: 0, neutral: true, cost: 'uniform', desc: 'normal map strength (only with a normalMap)' },
60
- normalRepeat: { type: 'number', default: 0.05, min: 0, neutral: true, cost: 'uniform', desc: 'normal map tiles per meter (only with a normalMap; rewrites the mesh UVs once)' },
61
- normalSpeed: { type: 'array', default: [0.01, 0.006], neutral: true, cost: 'uniform', desc: 'normal map scroll [x, z] per second (only with a normalMap)' },
62
- shininess: { type: 'number', default: 90, min: 0, cost: 'uniform', why: 'a lit water surface needs a highlight to read as water', off: 'look.water.set({ shininess: 0 })', desc: 'Phong highlight size (lit Phong water only)' },
63
- specular: { type: 'any', default: 0xaaaaaa, cost: 'uniform', why: 'a lit water surface needs a highlight to read as water', off: 'look.water.set({ specular: 0x000000 })', desc: 'Phong highlight color (lit Phong water only)' },
64
- },
65
- style: () => ({ ...pick(e.style.water ?? {}),
66
- ...(e.style.water?.material ? { [REPLACE]: e.style.water.material } : {}) }),
67
- read: () => ({ opacity: !st.material && w.material.opacity !== undefined ? w.material.opacity : undefined }),
68
- apply(v, changed) {
69
- for (const k of changed) { st[k] = v[k]; live(k, v[k]); }
70
- if (STRUCT.some(k => changed.has(k))) rebuild();
71
- },
72
- hooks: {
73
- wave: { signature: 'float threedogWaterWave(vec3 p, float t)', scope: ['uTime'], example: 'float threedogWaterWave(vec3 p, float t) { return sin(p.x + t) * 0.2; }' },
74
- surface: { signature: 'vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time)', scope: ['uTime'],
75
- example: 'vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) { return vec4(base.rgb * (0.8 + wave), base.a); }' },
76
- },
77
- applyHook(name, glsl) {
78
- const was = st._hooks; // internal hook state (surface.js waterLook reads it), never a style / option key
79
- st._hooks = { ...was, [name]: glsl ?? undefined };
80
- try { waterLook(st); rebuild(); } catch (err) { st._hooks = was; throw err; }
81
- },
82
- replace: { accepts: '(engine, { uniforms, waves, surface, normalMap }) => THREE.Material', loses: ['built-in role "water" material, fresnel, color and opacity (your material owns them)', 'depthColor / foam unless your material uses surface'] },
83
- // checked before any layer is written: the replace slot is a function, a GLSL hook builds (waterLook compiles it on a copy of the state)
84
- validate: (k, v) => k === REPLACE ? (typeof v === 'function' ? null : 'is (engine, { uniforms, waves, surface, normalMap }) => THREE.Material')
85
- : k.startsWith('hook:') ? validate(w, '_hooks')({ ...w.st._hooks, [k.slice(5)]: v }) : null,
86
- applyReplace(impl) {
87
- st.material = impl ?? undefined; rebuild();
88
- },
89
- });
90
- return p;
91
- }
@@ -1,3 +0,0 @@
1
- // The water surface defaults moved to render/fxNumbers.js (render/ must not import a module file). Re-exported so modules/water's imports
2
- // keep working until that folder imports render/fxNumbers.js itself; then delete this file.
3
- export { WAVE, WAVE_MAX, FRESNEL_POWER, DEPTH, FOAM } from '../../render/fxNumbers.js';
@@ -1,74 +0,0 @@
1
- // look.weather: rain / snow particles, lightning flash and the overcast color as a look part (recipes/52-look.md).
2
- // set({ 'rain.color', 'rain.speed', 'snow.size', 'lightning.brightness', overcastColor ... }) rebuilds that field's particle system once (a few ms)
3
- // patch('rain.vertex' | 'rain.fragment' | 'snow.vertex' | 'snow.fragment', glsl) the WHOLE shader text, not a function (see shaders.js)
4
- // replace({ rain: spec, ash: spec }) spec = the keys of style.weather.rain or { create(engine, { area, count }) => { object, update } }; null gives back
5
- // Why the shader stays whole (decision #9): the rain / snow shaders move vertices and size points; a function hook would hide most of that.
6
- import { defineLookPart, REPLACE } from '../../core/look/part.js';
7
- import { warnOnce } from '../../core/validate.js';
8
- import { RAIN, SNOW, dropSystem } from './particles.js';
9
-
10
- const WHY = { rain: 'built-in rain: streaks drawn while a weather type has rain > 0', snow: 'built-in snow: flakes drawn while a weather type has snow > 0' };
11
- const OFF = { rain: "leave 'rain' out of the weather table (no particles are built), or look.weather.set({ 'rain.opacity': 0 })", snow: "leave 'snow' out of the weather table, or look.weather.set({ 'snow.opacity': 0 })" };
12
- const KEYS = { rain: ['color', 'opacity', 'length', 'speed', 'slant'], snow: ['color', 'opacity', 'size', 'speed', 'sway'] };
13
- const BASE = { rain: RAIN, snow: SNOW };
14
- const FIELDS = ['rain', 'snow'], STAGES = ['vertex', 'fragment'];
15
-
16
- /** { 'rain.color': { type, default, why, off } ... } built from the particle defaults, so the numbers live in one place (particles.js) */
17
- const rows = () => Object.fromEntries(FIELDS.flatMap(f => KEYS[f].map(k => [`${f}.${k}`,
18
- { type: k === 'color' ? 'any' : 'number', default: BASE[f][k], ...(k === 'color' ? {} : { min: 0 }), cost: 'gpu', why: WHY[f], off: OFF[f] }])));
19
-
20
- /** @param {any} w the Weather module */
21
- export function defineWeatherLook(w) {
22
- const e = w.engine, st = e.style.weather ?? {}, { cover, ...snowStyle } = st.snow ?? {};
23
- const styleSpec = f => (f === 'snow' ? snowStyle : st[f] ?? {});
24
- let applied = {}; // fields a replace() holds now: field -> spec
25
- const rebuild = f => {
26
- if (applied[f]) return; // replace() owns this field
27
- if (!w.systems.has(f)) { warnOnce(`look.weather: this game's weather table has no ${f}, so there are no ${f} particles to change; add a type with ${f}: 1 to weather({ types })`); return; }
28
- const v = p.author.values(), s = styleSpec(f), g = { ...s.glsl };
29
- for (const h of STAGES) { const x = p.value(`hook:${f}.${h}`); if (x) g[h] = x; }
30
- w._build(f, { ...s, ...Object.fromEntries(KEYS[f].map(k => [k, v[`${f}.${k}`]])), ...(Object.keys(g).length ? { glsl: g } : {}) }, BASE[f]);
31
- };
32
- const p = defineLookPart(e, {
33
- id: 'weather', group: 'dynamic', module: 'weather', object: () => w.systems, docs: ['recipes/52-look.md'], applyAtStart: false,
34
- params: {
35
- ...rows(),
36
- 'lightning.brightness': { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'how bright the sky flashes at a strike' },
37
- overcastColor: { type: 'any', default: 0x8c8c8c, cost: 'uniform', why: 'sky and fog turn this gray as a weather type raises grey', off: 'weather types with grey: 0 never use it' },
38
- },
39
- style: () => ({
40
- ...Object.fromEntries(FIELDS.flatMap(f => KEYS[f].filter(k => styleSpec(f)[k] !== undefined).map(k => [`${f}.${k}`, styleSpec(f)[k]]))),
41
- ...Object.fromEntries(FIELDS.flatMap(f => STAGES.filter(h => styleSpec(f).glsl?.[h]).map(h => [`hook:${f}.${h}`, styleSpec(f).glsl[h]]))),
42
- 'lightning.brightness': st.lightningBrightness, overcastColor: st.overcastColor,
43
- }),
44
- read: () => ({}),
45
- apply(v, changed) {
46
- if (changed.has('lightning.brightness')) w.flashStrength = v['lightning.brightness'];
47
- if (changed.has('overcastColor')) w.grey.set(v.overcastColor);
48
- for (const f of FIELDS) if ([...changed].some(k => k.startsWith(f + '.'))) rebuild(f);
49
- },
50
- hooks: Object.fromEntries(FIELDS.flatMap(f => STAGES.map(h => [`${f}.${h}`, { signature: 'whole GLSL shader text (copy it from modules/weather/shaders.js)', scope: ['uCam', 'uSize', 'uFallOff', 'uOpacity', 'uColor'] }]))),
51
- applyHook(name) { rebuild(name.split('.')[0]); },
52
- replace: { accepts: '{ <field>: spec } with spec = the keys of style.weather.rain, or { create(engine, { area, count }) => { object, update?(amount, ctx) } }; null gives the fields back',
53
- loses: ['the style rain / snow look of every field named in the object (look.weather.set values for it are ignored while it holds)'] },
54
- // a wrong replace value stops here, before any layer is written (the throw used to come from applyReplace, after the write)
55
- validate: (k, v) => {
56
- if (k !== REPLACE) return null;
57
- if (v != null && (typeof v !== 'object' || Array.isArray(v))) return "is { <field>: spec }, e.g. replace({ ash: { shape: 'soft', color: 0x555555 } }); see recipes/44-water-weather-look-hooks.md";
58
- const fields = [...new Set(Object.values(w.types).flatMap(t => Object.keys(t)))], bad = Object.keys(v ?? {}).find(f => !fields.includes(f));
59
- return bad ? `no weather type has a field '${bad}'; add it to a type in weather({ types }) (e.g. ashfall: { ${bad}: 1 }), or use one of ${fields.join(', ')}` : null;
60
- },
61
- applyReplace(impl) {
62
- const next = impl ?? {}, old = applied;
63
- applied = next;
64
- for (const f of new Set([...Object.keys(old), ...Object.keys(next)])) {
65
- if (next[f] && next[f] === old[f]) continue; // unchanged: keep the system (and any handle the game holds)
66
- if (next[f]) w._build(f, next[f], BASE[f]);
67
- else if (BASE[f]) rebuild(f);
68
- else { const s = w.systems.get(f); if (s) { dropSystem(e, s); w.systems.delete(f); } }
69
- }
70
- },
71
- });
72
- return p;
73
- }
74
-
@@ -1,135 +0,0 @@
1
- // The look half of weather() (type 'look', engine.weatherLook): what the current weather looks and sounds like. It only reads engine.weather
2
- // (the state half, Weather.js) and never changes it, so a game can replace this half (engine.use(myRain(), { replaces: 'weatherLook' })) and keep the
3
- // weather table, its save and its events.
4
- // effects on the look values (effect layer): sun / hemi intensity, fog far, sky tint, lightning flash, snow cover
5
- // rain / snow particles that follow the camera (look.weather, look.js), cloud shadows and wind uniforms, thunder, audio rule conditions
6
- import * as THREE from 'three';
7
- import { builtInSounds } from '../../core/assetManifest.js';
8
- import { readParams, keysSchema, isOptions } from '../../core/params.js';
9
- import { codedError } from '../../core/errorHints.js';
10
- import { onRendererSwap } from '../../render/backend.js';
11
- import { makeSystem, updateSystem, dropSystem, RAIN, SNOW } from './particles.js';
12
- import { defineWeatherLook } from './look.js';
13
-
14
- const LOOK_PARAMS = keysSchema(['particles', 'area']); // the look options of weather(): the rest are the state's
15
- const STYLE_KEYS = ['area', 'overcastColor', 'lightningBrightness', 'lightning', 'rain', 'snow', 'types'];
16
-
17
- /** engine.weatherLook: particles and look effects of the current weather */
18
- export class WeatherLook {
19
- /**
20
- * @internal
21
- * @param {any} engine
22
- * @param {{ particles?: number, area?: number }} [opts]
23
- */
24
- constructor(engine, { particles = 6000, area = undefined } = {}) {
25
- /** @internal */ this.engine = engine;
26
- /** @internal the state half: read only */ this.state = engine.weather;
27
- const st = engine.style.weather || {};
28
- readParams('style.weather', keysSchema(STYLE_KEYS), st);
29
- /** @internal */ this.flashStrength = st.lightningBrightness ?? 1;
30
- // lightning look: flash (1 at the strike, fading over a third of a second) -> how bright the sky flashes; default flickers
31
- if (st.lightning !== undefined && typeof st.lightning !== 'function') throw codedError('weather-option', 'style.weather.lightning must be a function (flash 0..1, engine) => sky flash amount, e.g. lightning: f => f * 0.6; return 0 and draw your own bolt on the weather:lightning event');
32
- /** @internal */ this.lightningLook = st.lightning ?? (f => f * (Math.random() > 0.3 ? 1 : 0.4)); // presentation: flash flickers
33
- /** Sky flash now, 1 at a strike (the weather:lightning event) fading to 0 @type {number} */
34
- this.flash = 0;
35
- /** @internal */ this.grey = new THREE.Color(st.overcastColor ?? 0x8c8c8c);
36
- // the weather's entries on the look points: taken once through ctx.mod (owned by this module, gone with it) and rewritten every frame with
37
- // handle.change (core/sharedPoint.js), so a frame adds no entry and no cleanup handle. ctx is set by the module's install
38
- /** @internal */ this._ctx = null; /** @internal */ this._h = {};
39
- /** @internal */ this._tint = { color: this.grey, amount: 0, horizon: 0 };
40
- /** Default particle count per system (halved on low-tier devices) @type {number} */
41
- this.particles = engine.tier === 'low' ? Math.round(particles / 2) : particles;
42
- /** @internal */ this.area = area ?? st.area ?? 40;
43
- /** Particle systems drawn now: field -> { field, object, uniforms } (rain / snow when the table has them, plus fields look.weather.replace adds) @type {Map<string, any>} */
44
- this.systems = new Map();
45
- // zero cost when unused: a table where nothing ever rains or snows builds no particle meshes
46
- const { cover, ...snowLook } = st.snow || {};
47
- for (const [k, base] of /** @type {[string, any][]} */ ([['rain', RAIN], ['snow', SNOW]])) if (Object.values(this.types).some(v => v[k] > 0)) this._build(k, k === 'snow' ? snowLook : st[k] || {}, base);
48
- // snow cover: foliage / ground season tint moves toward the snow colors as current.snow rises (look.ground.cover)
49
- if (cover !== undefined) {
50
- if (isOptions(cover)) readParams('style.weather.snow.cover', keysSchema(['foliage', 'ground', 'strength']), cover);
51
- if (cover.foliage == null && cover.ground == null) throw codedError('weather-option', "style.weather.snow.cover needs a color for foliage and / or ground, e.g. cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 }");
52
- /** @internal */ this._cover = { strength: cover.strength ?? 0.8 };
53
- /** @internal */ this._coverMod = { foliage: cover.foliage ?? null, ground: cover.ground ?? null, amount: 0 };
54
- }
55
- defineWeatherLook(this); // look.weather: the style's rain / snow / lightning values are its style layer
56
- }
57
-
58
- /** @internal the weather table (state half), read by look.js */
59
- get types() { return this.state.types; }
60
-
61
- /** @internal */
62
- _build(field, spec, base) {
63
- const old = this.systems.get(field);
64
- if (old) dropSystem(this.engine, old);
65
- const sys = makeSystem(this.engine, field, spec, { area: this.area, count: this.particles, base });
66
- sys.made = { spec, base }; // what built it: the renderer swap builds it again from the same values (look / replace included)
67
- this.systems.set(field, sys);
68
- return sys;
69
- }
70
-
71
- /**
72
- * @internal fallback 'webgl': systems built before start() carry WebGPURenderer node materials; rebuild them for the renderer in use.
73
- * A replace() create(engine) object is the game's own and stays (the scene check names it if WebGL cannot draw it).
74
- */
75
- _rendererSwapped() {
76
- for (const [f, sys] of [...this.systems]) if (!sys.own) this._build(f, sys.made.spec, sys.made.base);
77
- }
78
-
79
- /**
80
- * Write the current weather into the 'weather' entries on the look values and move rain / snow with the camera (the module calls this every frame)
81
- * @param {any} camera
82
- * @param {number} [dt] real seconds since the last frame (the flash fades with it)
83
- * @returns {void}
84
- * @internal
85
- */
86
- apply(camera, dt = 0) {
87
- const c = this.state.current, e = this.engine, T = this._tint;
88
- const U = e.uniforms, t = e.time.now('real');
89
- this.flash = Math.max(0, this.flash - dt * 3);
90
- U.uCloud.value = c.cloud;
91
- U.uWind.value = c.wind;
92
- // effects on the look values a game sets: the game's sun 3 in rain shows 3 x c.sun (the effect layer, core/sharedPoint.js)
93
- this._put('look.lights.sun.intensity', 'mul', c.sun);
94
- this._put('look.lights.hemi.intensity', 'mul', 0.75 + 0.25 * c.sun);
95
- if (e.stacks.has('look.fog.far')) this._put('look.fog.far', 'mul', c.fog);
96
- T.amount = c.grey; T.horizon = c.grey * 0.8; this._put('look.sky.tint', 'value', T);
97
- this._put('look.sky.flash', 'add', this.flash > 0 ? this.lightningLook(this.flash, e) * this.flashStrength : 0);
98
- if (this._cover) { this._coverMod.amount = (c.snow ?? 0) * this._cover.strength; this._put('look.ground.cover', 'value', this._coverMod); } // requires sky: the look points exist
99
- for (const sys of this.systems.values()) updateSystem(sys, c[sys.field] ?? 0, camera, t, c.wind);
100
- }
101
- /** @internal one look contribution: taken on first use (a point may appear later, look.fog.far with fog), then changed in place */
102
- _put(point, op, v) {
103
- // change() is false when the entry is gone (a point cleared on a new session): take it again, as the old per-frame take did anyway
104
- if (this._h[point]?.change(v)) return;
105
- const o = op === 'value' ? { value: v } : { [op]: v, layer: 'effect' }; // tint / cover are data points (value), the rest effect-layer numbers
106
- this._h[point] = this._ctx ? this._ctx.mod(point, o) : this.engine.mod(point, { ...o, owner: 'weatherLook' });
107
- }
108
- }
109
-
110
- /**
111
- * @internal the look half of weather(opts) (weather() returns both; install them together)
112
- * @param {{ particles?: number, area?: number }} opts
113
- */
114
- export function weatherLookModule(opts) {
115
- readParams('weather (look half)', LOOK_PARAMS, opts);
116
- let L = null;
117
- return {
118
- name: 'weatherLook', type: 'look', provides: ['weatherLook'], label: 'Weather look', params: LOOK_PARAMS, options: opts, requires: ['weather', 'sky'], stage: 'environment', before: ['sky'], after: ['weather'],
119
- install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.weatherLook': '天气外观' }, en: { 'module.weatherLook': 'weather look' } });
120
- L = new WeatherLook(e, opts);
121
- L._ctx = ctx; // the weather's entries on the look points go with this module (ctx.mod): removing it gives the game's values back unscaled
122
- ctx.track(onRendererSwap(e, () => L._rendererSwapped()));
123
- const w = e.weather;
124
- ctx.track(e.audio.condition('weather', v => [].concat(v).includes(w.name))); // audio rule condition { weather: 'rain' | ['rain', 'storm'] }
125
- for (const k of ['rain', 'snow', 'wind']) ctx.track(e.audio.measure(k, () => w.current[k])); // data rules: { rain: { lt: 0.2 } }, volume add: { rain: 0.22 }
126
- builtInSounds(e.assets, { thunder: (audio, p, out) => { const dur = p.duration ?? 3.5, delay = 0.4 + Math.random() * 1.5; // presentation: thunder delay
127
- audio.noiseBurst({ type: 'lowpass', freq: p.freq ?? 140, vol: p.volume ?? 0.9, dur, rate: 0.4 * p.pitch, delay, out }); return delay + dur; } },
128
- { bus: 'ambience' }); // sound asset 'thunder', silent until audio.sounds names it
129
- ctx.track(e.events.on('weather:lightning', () => { L.flash = 1; e.audio.sfx('thunder'); }));
130
- return L;
131
- },
132
- frame(dt, e) { L.apply(e.camera, dt); },
133
- describe: () => ({ rainVisible: !!L.systems.get('rain')?.object.visible, snowVisible: !!L.systems.get('snow')?.object.visible, flash: Math.round(L.flash * 100) / 100 }),
134
- };
135
- }
@@ -1,139 +0,0 @@
1
- // Night glow: emissive following daylight.
2
- // look.materials.glow(match, { night, day, dusk }) for lit windows, neon signs, lamp bulbs, glowing mushrooms, screens.
3
- // Why the engine does it: the game knows WHICH materials glow and how bright; it cannot easily know WHEN a matching material exists. Templates and
4
- // streamed models are built near the player long after startup, so games walked the whole scene on a timer to find them. Here one rule names
5
- // the materials once; only objects that entered the scene since the last frame are looked at (core/sceneDelta.js, shared with the cascades
6
- // and fog), and each frame only the matched materials get one number written, and only when it changed.
7
- // Why a verb on look.materials: a rule is a look value with an owner like the others, so describe().look.materials lists it ('glow:<name>'),
8
- // remove() hands it back (the material gets its own emissiveIntensity again) and the picture's colors stay the game's (emissive is never touched).
9
- import { sceneVisitor } from '../core/sceneDelta.js';
10
- import { warnOnce } from '../core/validate.js';
11
- import { coded } from '../core/errorHints.js';
12
-
13
- const KEY = 'glow:';
14
- // default dusk: lights fade in as daylight drops below 0.3 (calendar daylight: about 16:50 -> fully lit at 18:00). It is only a starting value:
15
- // each rule may pass its own `dusk` (signs on earlier than windows, a cave mushroom that only glows in the dark)
16
- // exported with daylightOf / nightOf: lightPool sources with `dusk` (modules/lights) fade on the same curve, so a lamp's real light and its
17
- // window glow switch on together instead of two curves drifting apart
18
- export const DUSK = 0.3;
19
- const SIG = 'glow(match, { night, day = 0, dusk = 0.3, owner })';
20
-
21
- /** What a match finds: a role / material name string, one Material, or (material) => boolean */
22
- function matcher(match) {
23
- if (typeof match === 'string' && match) return { label: match, test: m => m.name === match || m.userData?.purpose === match };
24
- if (match?.isMaterial) return { label: match.name || `material#${match.id}`, test: m => m === match };
25
- if (typeof match === 'function') return { label: match.name || 'filter', test: match };
26
- return null;
27
- }
28
-
29
- /** Daylight 0..1 from the 'daylight' measure (engine.audio.measure): the calendar registers it (gameplay day / night), the sky only when no
30
- * calendar did (the drawn sun). Read through the measure, not e.calendar / e.sky, so render/ names no module and a game's own clock module counts
31
- * the same by registering the measure. null when nothing tells day from night */
32
- export const daylightOf = e => { const d = e.audio?.measures.get('daylight')?.(e); return typeof d === 'number' ? d : null; };
33
- /**
34
- * 0 by day, 1 at night for one rule's dusk (daylight below which it fades in); null daylight -> 0 (the day value is kept). dusk 0 has no fade:
35
- * on only while daylight is 0 (a cave mushroom that glows only in full dark); the d / dusk curve would divide by zero there
36
- */
37
- export function nightOf(d, dusk) {
38
- if (d === null) return 0;
39
- if (dusk === 0) return d > 0 ? 0 : 1;
40
- const t = Math.min(1, Math.max(0, d / dusk));
41
- return 1 - t * t * (3 - 2 * t); // smoothstep: no visible kink when the fade starts or ends
42
- }
43
- const valueOf = (r, d) => r.day + (r.night - r.day) * nightOf(d, r.dusk);
44
-
45
- /**
46
- * Add the glow verb to the materials look part.
47
- * @param {any} e @param {any} part engine.look.materials
48
- */
49
- export function addGlowVerb(e, part) {
50
- const tests = new Map(); // 'glow:<name>' -> test; the layer value itself stays plain data so describe prints it
51
- const base = new WeakMap(); // material -> its own emissiveIntensity before a rule touched it (restored when no rule matches it any more)
52
- // found: material in the scene -> the rule it matched and how many scene objects use it (given back when the count drops to 0);
53
- // held: object -> the matched materials it counted, so its leave takes back exactly what its enter added
54
- let found = new Map(), held = new WeakMap(), view = null, frame = null, seq = 0, testsRev = 0;
55
- // the rules, rebuilt only when the materials part changed (part._rev), not every frame; sig = which keys and tests, so a night / day
56
- // change rewrites numbers without looking at the scene again
57
- let rev = -1, sig = '', list = [], byKey = new Map();
58
-
59
- const restore = m => { if (base.has(m)) { m.emissiveIntensity = base.get(m); base.delete(m); } };
60
- const enter = o => {
61
- if (!o.isMesh || !o.material) return;
62
- let mine = null;
63
- for (const m of Array.isArray(o.material) ? o.material : [o.material]) {
64
- const r = list.find(x => x.test?.(m));
65
- if (!r) continue;
66
- if (!('emissiveIntensity' in m)) { warnOnce(coded('look-param', `look.materials.glow('${r.key.slice(KEY.length)}'): material '${m.name || m.type}' has no emissive (a ${m.type}); give it an emissive material (MeshStandardMaterial / Lambert / Phong / Toon)`)); continue; }
67
- if (m.emissive?.getHex?.() === 0) warnOnce(coded('look-param', `look.materials.glow('${r.key.slice(KEY.length)}'): material '${m.name || m.type}' has a black emissive, so it cannot glow; set its color: material.emissive.set('#ffcc66')`));
68
- if (!base.has(m)) base.set(m, m.emissiveIntensity);
69
- const f = found.get(m);
70
- if (f) f.n++; else found.set(m, { key: r.key, n: 1 });
71
- (mine ??= []).push(m);
72
- }
73
- if (mine) held.set(o, mine);
74
- };
75
- const leave = o => {
76
- const mine = held.get(o);
77
- if (!mine) return;
78
- held.delete(o);
79
- for (const m of mine) { const f = found.get(m); if (f && --f.n <= 0) { found.delete(m); restore(m); } } // out of the scene: its own value back
80
- };
81
-
82
- function update() {
83
- if (part._rev !== rev) {
84
- rev = part._rev;
85
- // every rule in effect now (layers decide which owner's value wins, as for any look key)
86
- list = part.author.resolved(KEY).filter(([, v]) => v).map(([k, v]) => ({ key: k, test: tests.get(k), night: v.night, day: v.day, dusk: v.dusk ?? DUSK }));
87
- byKey = new Map(list.map(r => [r.key, r]));
88
- const s = list.map(r => r.key).join('|') + '#' + testsRev;
89
- if (s !== sig) {
90
- // which materials match changed: show this visitor the whole scene again, then give back what no rule matches now
91
- sig = s;
92
- const old = found;
93
- found = new Map(); held = new WeakMap();
94
- if (list.length) { if (view) view.rescan(); else view = sceneVisitor(e.scene, { enter, leave }); view.sync(); }
95
- for (const m of old.keys()) if (!found.has(m)) restore(m);
96
- }
97
- }
98
- if (!list.length) { view?.remove(); view = null; frame?.remove(); frame = null; return; }
99
- view.sync(); // only what entered the scene since the last frame (core/sceneDelta.js)
100
- const d = daylightOf(e);
101
- if (d === null) { warnOnce(coded('look-param', 'look.materials.glow(): nothing tells day from night, so the day value is kept. Install calendar() (or sky())')); }
102
- for (const [m, f] of found) {
103
- const v = valueOf(byKey.get(f.key), d);
104
- if (m.emissiveIntensity !== v) m.emissiveIntensity = v;
105
- }
106
- }
107
-
108
- /** @param {any} match @param {{ night?: number, day?: number, dusk?: number, owner?: string, [k: string]: any }} [o] */
109
- part.glow = (match, o = {}) => {
110
- const t = matcher(match);
111
- if (!t) throw part._lacks('glow', `match is a material role or material name ('window'), a Material, or (material) => boolean; got ${typeof match}`, `Call it as look.materials.${SIG}`);
112
- const { night, day = 0, dusk = DUSK, owner, ...rest } = o;
113
- const extra = Object.keys(rest)[0];
114
- if (extra) throw part._lacks('glow', `unknown option ${extra} (options: night, day, dusk, owner)`, `Call it as look.materials.${SIG}`);
115
- if (typeof dusk !== 'number' || !(dusk >= 0 && dusk <= 1)) throw part._lacks('glow', `dusk is the daylight (0..1; 0 = only while daylight is 0) below which the glow fades in; got ${JSON.stringify(dusk)}`, `Call it as look.materials.${SIG}`);
116
- if (typeof night !== 'number' || typeof day !== 'number') throw part._lacks('glow', `night and day are emissiveIntensity numbers, e.g. { night: 2, day: 0 } (an example value: a near-white emissive color clips to white well below it, a saturated one reads as light; judge with threedog shot, docs/recipes/52-look.md "Night glow"); got ${JSON.stringify({ night, day })}`, `Call it as look.materials.${SIG}`);
117
- // a string names its rule (a second glow('window') replaces the first); a Material / filter gets its own key so two never overwrite each other
118
- const key = KEY + t.label + (typeof match === 'string' ? '' : `#${++seq}`);
119
- tests.set(key, t.test); testsRev++;
120
- const handle = part.author.write(owner ?? key, { [key]: { night, day, dusk, match: t.label } });
121
- frame ??= e.onFrame(update);
122
- update(); // at once: a test or screenshot right after the call sees the value
123
- // the handle undoes this write only (a second rule under the same owner stays). A Material / filter key is this call's alone, so its test goes too
124
- // (a string key may still be another owner's rule)
125
- return { remove() { handle.remove(); if (typeof match !== 'string') { tests.delete(key); testsRev++; } update(); } };
126
- };
127
- return {
128
- /** describe().look.materials rows: per rule, how many materials it found and the intensity written now */
129
- info() {
130
- const out = {}, d = daylightOf(e);
131
- for (const r of list) {
132
- let n = 0;
133
- for (const f of found.values()) if (f.key === r.key) n++;
134
- out[`${r.key}.found`] = { value: `${n} material(s), emissiveIntensity ${Math.round(valueOf(r, d) * 100) / 100} now`, writer: 'engine' };
135
- }
136
- return out;
137
- },
138
- };
139
- }