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
@@ -6,6 +6,7 @@
6
6
  // Where state lives (nothing is stored twice):
7
7
  // placed things -> world records with a `grid` field (saved by world); occupancy is an index rebuilt from them (world:add / change / remove / load)
8
8
  // per-cell layers -> Layer maps, saved here under the save key 'grids' (version 2) as a per-cell diff against the authored cells (Layer.js)
9
+ // Picture: grids({ ok, bad, previewOpacity, previewHeight, tiles, tileLift }) for the plain values, pv.material and layer.material for the three.js materials.
9
10
  // The index is the "don't go around it" check: in dev a record's grid field is frozen (editing it in place throws), writes outside ops
10
11
  // trigger the ops guard, and a record whose footprint overlaps another one is reported with the fix.
11
12
  import { Grid, MAIN, occKey } from './Grid.js';
@@ -41,9 +42,19 @@ const freeze = p => { Object.freeze(p.cell); Object.freeze(p.size); return Objec
41
42
  * @experimental
42
43
  */
43
44
  export class Grids {
44
- /** @internal */
45
- constructor(e) {
45
+ /**
46
+ * @internal
47
+ * @param {any} e
48
+ * @param {GridsOptions} o
49
+ */
50
+ constructor(e, o) {
46
51
  /** @internal */ this.engine = e;
52
+ /** Preview color where it can be placed, read when a preview is made @type {any} */ this.ok = o.ok;
53
+ /** Preview color where it cannot be placed, read when a preview is made @type {any} */ this.bad = o.bad;
54
+ /** Opacity of the preview box, read when a preview is made */ this.previewOpacity = o.previewOpacity;
55
+ /** Height of the preview box (meters), read when a preview is made */ this.previewHeight = o.previewHeight;
56
+ /** Tile colors by layer name, { layer: { field: color } } (first truthy field of a cell wins), read when a layer is made @type {Record<string, Record<string, any>>} */ this.tiles = o.tiles;
57
+ /** Height of tiles above the ground (meters), read when a layer is made */ this.tileLift = o.tileLift;
47
58
  /** @internal */ this._grids = new Map();
48
59
  /** @internal */ this._defs = new Map();
49
60
  /** @internal id -> { g, keys } */ this._byId = new Map();
@@ -131,16 +142,16 @@ export class Grids {
131
142
  }
132
143
  /**
133
144
  * Show where an item would go: the target cell under the pointer ('pointer', default), in front of the player ('front') or from your
134
- * function, turned by the input action rotate (default name 'rotate'; the game binds it, e.g. presets.bindings.gridRotate; the engine binds no key itself), light when can() passes, dark otherwise (neutral tool colors; style.grid.ok / bad override them).
135
- * look: false = no visual; (engine) => ({ update(view), hide(), dispose() }) = your own. place() runs grid.place with what is shown
145
+ * function, turned by the input action rotate (default name 'rotate'; the game binds it, e.g. presets.bindings.gridRotate; the engine binds no key itself), light when can() passes, dark otherwise (neutral tool colors; grids({ ok, bad }) override them).
146
+ * draw: false = no visual; (engine) => ({ update(view), hide(), dispose() }) = your own; pv.material is the default box's three.js material. place() runs grid.place with what is shown
136
147
  * @example engine.input.bind({ place: ['Mouse0'], ...presets.bindings.gridRotate }); // the game's own bindings
137
148
  * const pv = engine.grids.preview({ grid: 'field', item: 'tower' });
138
149
  * engine.onFrame(() => { if (engine.input.pressed('place')) { const r = pv.place(); if (!r.ok) toast(engine, engine.t('grid.' + r.code)); } });
139
- * @param {{ grid: string, item: string, from?: 'pointer' | 'front' | ((e: any) => any), rotate?: string | false, rotation?: number, look?: false | ((e: any) => any) }} opts
150
+ * @param {{ grid: string, item: string, from?: 'pointer' | 'front' | ((e: any) => any), rotate?: string | false, rotation?: number, draw?: false | ((e: any) => any) }} opts
140
151
  * @returns {{ cell: [number, number] | null, rotation: number, ok: boolean, code: string | null, rotate(n?: number): void, place(fields?: object): { ok: boolean, value?: any, code?: string }, remove(): void }}
141
152
  */
142
153
  preview(opts) {
143
- readParams('grids.preview()', keysSchema(['grid', 'item', 'from', 'rotate', 'rotation', 'look']), opts);
154
+ readParams('grids.preview()', keysSchema(['grid', 'item', 'from', 'rotate', 'rotation', 'draw']), opts);
144
155
  return makePreview(this.engine, this, opts);
145
156
  }
146
157
 
@@ -148,11 +159,11 @@ export class Grids {
148
159
  _layerAdded(l) {
149
160
  const d = this._loaded?.[l.grid.name]?.[l.name];
150
161
  if (d) l.fromJSON(d);
151
- const t = layerTiles(this.engine, l);
162
+ const t = layerTiles(this.engine, l, this);
152
163
  if (t) this._tiles.set(l, t);
153
164
  }
154
165
  /** @internal a layer's options changed after content created it: rebuild its tiles */
155
- _retile(l) { this._tiles.get(l)?.dispose(); this._tiles.delete(l); const t = layerTiles(this.engine, l); if (t) this._tiles.set(l, t); }
166
+ _retile(l) { this._tiles.get(l)?.dispose(); this._tiles.delete(l); const t = layerTiles(this.engine, l, this); if (t) this._tiles.set(l, t); }
156
167
  /** @internal */
157
168
  _index(rec) {
158
169
  const p = rec.grid, g = this._grids.get(p.id);
@@ -223,19 +234,37 @@ export class Grids {
223
234
  }
224
235
  }
225
236
 
237
+ // tool colors, not art: neutral defaults that still tell the two apart (light = can place, dark = cannot)
238
+ const GRID_PARAMS = {
239
+ ok: { type: 'any', default: 0xe0e0e0, desc: 'preview color where it can be placed' },
240
+ bad: { type: 'any', default: 0x3a3a3a, desc: 'preview color where it cannot be placed' },
241
+ previewOpacity: { type: 'number', default: 0.45, min: 0, max: 1, desc: 'opacity of the preview box' },
242
+ previewHeight: { type: 'number', default: 0.08, min: 0, desc: 'height of the preview box (meters)' },
243
+ tiles: { type: 'any', default: {}, desc: 'tile colors by layer name: { layer: { field: color } }, first truthy field of a cell wins; a layer named here draws tiles' },
244
+ tileLift: { type: 'number', default: 0.03, desc: 'height of tiles above the ground (meters)' },
245
+ };
246
+ /**
247
+ * Options of grids()
248
+ * @typedef {{ ok?: any, bad?: any, previewOpacity?: number, previewHeight?: number, tiles?: Record<string, Record<string, any>>, tileLift?: number }} GridsOptions
249
+ */
250
+
226
251
  /**
227
252
  * Grid placement module: installed as engine.grids. Needs world(). Adds the ops grid.place / grid.remove / grid.move and the save key 'grids' (layers).
253
+ * Options: ok, bad, previewOpacity, previewHeight (the preview box), tiles, tileLift (layer tiles). The materials are pv.material and layer.material.
228
254
  * @example engine.use(world(), grids())
255
+ * @example engine.use(world(), grids({ ok: 0x66dd88, bad: 0xdd5544, tiles: { soil: { watered: 0x5b3d2a, tilled: 0x8a6243 } } }))
256
+ * @param {GridsOptions} [opts]
229
257
  * @returns {import('../../types/core').ModuleDef<Grids>}
230
258
  * @experimental
231
259
  */
232
- export function grids() {
260
+ export function grids(opts = {}) {
261
+ const o = readParams('grids', GRID_PARAMS, opts);
233
262
  let G = null, offOps = null;
234
263
  const subs = [];
235
264
  return {
236
- name: 'grids', type: 'world', label: 'Grid placement', stage: 'gameplay', requires: ['world'],
265
+ name: 'grids', type: 'world', label: 'Grid placement', stage: 'gameplay', requires: ['world'], params: GRID_PARAMS, options: o,
237
266
  install(e) {
238
- G = new Grids(e);
267
+ G = new Grids(e, o);
239
268
  e.i18n.add(TEXT); // grid.<code> player text for every built-in failure code, and the rotate action's label
240
269
  e.saves.register('grids', { atomic: true, version: 2, migrate: GRIDS_MIGRATE, save: () => G.toJSON(), load: d => G.fromJSON(d) });
241
270
  offOps = defineGridOps(e, G);
@@ -1,34 +1,37 @@
1
1
  // Placement preview (engine.grids.preview): picks the target cell every frame (under the pointer, in front of the player, or from
2
2
  // your function), keeps a rotation turned by an input action, asks can(), and shows a see-through footprint
3
- // (style.grid.ok / bad colors). It never changes gameplay state: place() runs the grid.place op with what it shows.
4
- // The look is a replaceable part: look: false (no visual, the handle still answers), or (engine) => ({ update(view), hide(), dispose() }).
3
+ // (grids({ ok, bad }) colors). It never changes gameplay state: place() runs the grid.place op with what it shows.
4
+ // The picture is a replaceable part: draw: false (no visual, the handle still answers), or (engine) => ({ update(view), hide(), dispose() }); pv.material is the default box's.
5
5
  import * as THREE from 'three';
6
- import { makeMaterial } from '../../render/materials.js';
6
+ import { neutralMaterial } from '../../render/neutral.js';
7
7
  import { screenToGround } from '../../core/screenToGround.js';
8
8
  import { warnOnce } from '../../core/validate.js';
9
9
  import { failure } from '../../core/opsFail.js';
10
+ import { codedError } from '../../core/errorHints.js';
10
11
 
11
- // tool colors, not art: neutral defaults that still tell the two apart (light = can place, dark = cannot); a style may override them
12
- const OK = 0xe0e0e0, BAD = 0x3a3a3a;
13
12
  const NO_KEY = 'grids.preview(): the action "{a}" has no keys, so the preview cannot be turned by input. Bind it (engine.input.bind("{a}", ["KeyR"]) or presets.bindings.gridRotate), or pass rotate: false and call pv.rotate() from your own control';
14
13
 
15
- /** Default look: a flat translucent box over the footprint @internal */
16
- function boxLook(e) {
17
- const st = e.style.grid ?? {}, opacity = st.previewOpacity ?? 0.45;
18
- const mat = makeMaterial('decal', { transparent: true, opacity, depthWrite: false }, e);
19
- const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), mat);
14
+ /** Default picture: a flat translucent box over the footprint @internal */
15
+ function boxPart(e, st) {
16
+ const own = neutralMaterial('decal', { transparent: true, opacity: st.previewOpacity, depthWrite: false });
17
+ const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), own);
20
18
  mesh.name = 'grid:preview'; mesh.visible = false; mesh.renderOrder = 2;
21
19
  e.add(mesh, { owner: 'engine:grid' });
22
- const ok = new THREE.Color(st.ok ?? OK), bad = new THREE.Color(st.bad ?? BAD), h = st.previewHeight ?? 0.08;
20
+ const ok = new THREE.Color(st.ok), bad = new THREE.Color(st.bad), h = st.previewHeight;
23
21
  return {
22
+ get material() { return mesh.material; },
23
+ set material(m) {
24
+ if (!m?.isMaterial) throw codedError('grids-misuse', `pv.material takes a three.js material, got ${m}`);
25
+ mesh.material = m;
26
+ },
24
27
  update(v) {
25
28
  mesh.visible = true;
26
29
  mesh.scale.set(v.size[0] - 0.04, h, v.size[1] - 0.04);
27
30
  mesh.position.set(v.center.x, v.center.y + h / 2, v.center.z);
28
- mat.color.copy(v.ok ? ok : bad);
31
+ /** @type {any} */ (mesh.material).color?.copy(v.ok ? ok : bad); // telling can from cannot is the preview's job, on any material that has a color
29
32
  },
30
33
  hide() { mesh.visible = false; },
31
- dispose() { e.remove(mesh); mesh.geometry.dispose(); mat.dispose(); },
34
+ dispose() { e.remove(mesh); mesh.geometry.dispose(); own.dispose(); }, // a material the game set stays the game's
32
35
  };
33
36
  }
34
37
 
@@ -46,17 +49,23 @@ function target(e, from, g) {
46
49
 
47
50
  /** Create a preview handle @internal */
48
51
  export function makePreview(e, grids, opts) {
49
- const { grid, item, from = 'pointer', rotate = 'rotate', look } = opts;
52
+ const { grid, item, from = 'pointer', rotate = 'rotate', draw } = opts;
50
53
  const g = grids._must(grid), rule = grids._rule(item);
51
54
  // declared by the preview, owned by the grid module and taken away with the preview (or the module), so nothing outlives it; the game binds
52
55
  // the key (presets.bindings.gridRotate) like every module action
53
56
  const decl = rotate ? e.input.action(rotate, { label: 'grid.rotate', owner: 'grids', optional: true }) : null;
54
57
  if (rotate && !e.input.keysOf(rotate).length) warnOnce(NO_KEY.replaceAll('{a}', rotate));
55
- const part = look === false ? null : typeof look === 'function' ? look(e) : boxLook(e);
58
+ const part = draw === false ? null : typeof draw === 'function' ? draw(e) : boxPart(e, grids);
56
59
  const h = {
57
60
  /** target cell or null (nothing under the pointer) */ cell: null,
58
61
  rotation: opts.rotation ?? 0,
59
62
  /** why it cannot be placed: 'noTarget' or the grid.can() code; null when ok */ ok: false, code: 'noTarget',
63
+ /** The default box's three.js material (null with draw: false or your own part). Set it to swap the picture, used as given; its color still shows ok / bad */
64
+ get material() { return part?.material ?? null; },
65
+ set material(m) {
66
+ if (!part || !('material' in part)) throw codedError('grids-misuse', "pv.material: this preview has draw: false or your own part, so it draws no default box");
67
+ part.material = m;
68
+ },
60
69
  /** Turn by quarter turns (the rotate action does this too) */
61
70
  rotate(n = 1) { h.rotation = (((h.rotation + n) % 4) + 4) % 4; },
62
71
  /** Run grid.place with the shown cell and rotation; returns the op result */
@@ -2,39 +2,35 @@
2
2
  // whose four corners sit on engine.surface + lift, so tiles hug a ramp or terrain and work on any ground provider
3
3
  // (procedural terrain, a Blender level, a flat greenhouse floor). One merged mesh = one draw call; it is rebuilt only when
4
4
  // the layer version or the ground (level:loaded) changes.
5
- // Look: layer option tiles.look(data, cell) -> color | null, else tiles.colors = { field: color } (call site, same shape as the style table), else the style table style.grid.tiles[layer] = { field: color }
6
- // (first truthy field in the table's order wins), else neutral gray. tiles: false = off; a function = your own part.
5
+ // Picture: layer option tiles.color(data, cell) -> color | null, else tiles.colors = { field: color }, else the module's table grids({ tiles: { layer: { field: color } } })
6
+ // (first truthy field in the table's order wins), else neutral gray. tiles: false = off; a function = your own part. layer.material is the three.js material they draw with.
7
7
  import * as THREE from 'three';
8
- import { makeMaterial } from '../../render/materials.js';
8
+ import { neutralMaterial } from '../../render/neutral.js';
9
9
  import { surfaceOr } from '../../core/ground.js';
10
+ import { readParams, keysSchema } from '../../core/params.js';
10
11
 
11
12
  const GAP = 0.03; // fraction of a cell left between tiles: keeps tiles visibly separate (crisp edges)
12
13
  const FALLBACK = 0x9a9a9a;
13
14
 
14
- /** Look function from a { field: color } table: the first truthy field in the table's order wins (same table shape as style.grid.tiles[layer]; the call-site option tiles.colors wins over the style) @internal */
15
- function tableLook(table) {
15
+ /** Color function from a { field: color } table: the first truthy field in the table's order wins (the layer's tiles.colors wins over the module's grids({ tiles })) @internal */
16
+ function tableColor(table) {
16
17
  if (!table) return null;
17
18
  const order = Object.entries(table);
18
19
  return d => { for (const [f, c] of order) if (d[f]) return c; return null; };
19
20
  }
20
21
 
21
- /** Look function from the style table (null if the style has none for this layer) @internal */
22
- function styleLook(e, name) {
23
- return tableLook(e.style.grid?.tiles?.[name]);
24
- }
25
-
26
22
  /** Build the tile view of a layer, or null when off. Returns { frame(), dispose() } @internal */
27
- export function layerTiles(e, layer) {
23
+ export function layerTiles(e, layer, st) {
28
24
  const t = layer.opts.tiles, name = layer.name;
29
25
  if (t === false) return null;
30
26
  if (typeof t === 'function') return customTiles(e, layer, t(e, layer));
31
- const look = (t && typeof t === 'object' && (t.look || tableLook(t.colors))) || styleLook(e, name) || (t ? () => FALLBACK : null);
32
- if (!look) return null; // no style table and not asked for: a pure data layer
33
- const lift = (t && typeof t === 'object' && t.lift) ?? e.style.grid?.tileLift ?? 0.03;
34
- const mat = makeMaterial('decal', { vertexColors: true }, e);
27
+ if (t && typeof t === 'object') readParams(`layer('${name}') tiles`, keysSchema(['color', 'colors', 'lift']), t);
28
+ const color = (t && typeof t === 'object' && (t.color || tableColor(t.colors))) || tableColor(st.tiles[name]) || (t ? () => FALLBACK : null);
29
+ if (!color) return null; // no table and not asked for: a pure data layer
30
+ const lift = t?.lift ?? st.tileLift;
35
31
  // drawn over the ground it lies on: depth offset instead of a big lift keeps it glued to slopes
36
- mat.polygonOffset = true; mat.polygonOffsetFactor = -2; mat.polygonOffsetUnits = -2;
37
- const geo = new THREE.BufferGeometry(), mesh = new THREE.Mesh(geo, mat);
32
+ const own = neutralMaterial('decal', { vertexColors: true, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2 });
33
+ const geo = new THREE.BufferGeometry(), mesh = new THREE.Mesh(geo, own);
38
34
  mesh.name = `grid:${layer.grid.name}.${name}`; mesh.receiveShadow = true; mesh.frustumCulled = false;
39
35
  e.add(mesh, { owner: 'engine:grid' });
40
36
  let ver = -1, ground = 0, built = -1;
@@ -44,7 +40,7 @@ export function layerTiles(e, layer) {
44
40
  const cells = layer.query(), pos = [], clr = [], idx = [];
45
41
  let last = 0; // height of the previous corner: a corner beyond the island borrows it instead of -Infinity
46
42
  for (const { cell, data } of cells) {
47
- const c = look(data, cell);
43
+ const c = color(data, cell);
48
44
  if (c == null) continue;
49
45
  col.set(c);
50
46
  // from the grid's mapping (its cell centers), so a replaced mapping draws where its cells are
@@ -65,7 +61,7 @@ export function layerTiles(e, layer) {
65
61
  mesh.visible = g.zone == null || e.world?.zone == null || e.world.zone === g.zone;
66
62
  if (layer._ver !== ver || ground !== built) { ver = layer._ver; built = ground; rebuild(); }
67
63
  },
68
- dispose() { off.remove(); e.remove(mesh); geo.dispose(); mat.dispose(); },
64
+ dispose() { off.remove(); e.remove(mesh); geo.dispose(); own.dispose(); }, // a material the game set stays the game's
69
65
  };
70
66
  }
71
67
 
@@ -149,6 +149,7 @@ export function hlod(opts = {}) {
149
149
  group.add(p); c.proxy.push(p);
150
150
  }
151
151
  delete c.sources;
152
+ c.watch = e.occlusion.watch([...c.proxy, ...c.originals]);
152
153
  api.cells.push(c);
153
154
  yield;
154
155
  }
@@ -158,7 +159,7 @@ export function hlod(opts = {}) {
158
159
  /** Unregister: restore originals, release proxies */
159
160
  remove() {
160
161
  h.removed = true; handles.delete(h);
161
- for (const c of list) { setFar(c, false); for (const p of c.proxy) p.geometry.dispose(); for (const m of c.originals) { delete m.userData.hlod; shade.get(m)?.release(); } }
162
+ for (const c of list) { c.watch?.remove(); setFar(c, false); for (const p of c.proxy) p.geometry.dispose(); for (const m of c.originals) { delete m.userData.hlod; shade.get(m)?.release(); } }
162
163
  api.cells = api.cells.filter(c => !list.includes(c));
163
164
  for (const l of lods.values()) shade.get(l.node)?.release();
164
165
  e.detach(group); // proxies share the originals' materials and are never ray-registered: geometries were disposed above
@@ -183,7 +184,7 @@ export function hlod(opts = {}) {
183
184
 
184
185
  const addLevel = root => { levelHandle?.remove(); levelHandle = root ? api.add(root) : null; };
185
186
  return {
186
- name: 'hlod', type: 'look', params: HLOD_PARAMS, options: opts, label: 'HLOD', optional: ['terrain', 'level'],
187
+ name: 'hlod', type: 'picture', params: HLOD_PARAMS, options: opts, label: 'HLOD', optional: ['terrain', 'level'],
187
188
  install(engine, ctx) {
188
189
  e = engine;
189
190
  e.i18n.add({ 'zh-CN': { 'module.hlod': '远景合并' }, en: { 'module.hlod': 'distant merge' } });
@@ -153,6 +153,19 @@ export function hud(opts = {}) {
153
153
  * 'left' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right', the screen corner / edge its column sits at
154
154
  */
155
155
  counter(id, o) { item('counter', id, o); },
156
+ /**
157
+ * Add n (default 1; negative takes away) to a number counter and return the new value. A counter not declared yet starts at 0 with its id as the label, so
158
+ * declare it with counter() for a player-facing label and max
159
+ * @example engine.hud.counter('shells', { label: 'Shells', value: 0, max: 4 }); engine.hud.add('shells');
160
+ */
161
+ add(id, n = 1) {
162
+ const it = items.get(id), v = it?.o.value ?? 0;
163
+ if (typeof v !== 'number') throw codedError('hud-option', `hud.add('${id}'): this counter shows text (${JSON.stringify(v)}), not a number`, TypeError);
164
+ item('counter', id, it ? { value: v + n } : { label: id, value: n });
165
+ return v + n;
166
+ },
167
+ /** Current value of a counter or bar (a number or text); undefined when there is none. This is also where an interaction's `counter` total is read */
168
+ value(id) { return items.get(id)?.o.value; },
156
169
  /** Progress bar (calling again with the same id = update): { value, max = 1, label, anchor } (anchor as for counter) */
157
170
  bar(id, o) { item('bar', id, o); },
158
171
  /** Remove a counter or bar */
@@ -1,8 +1,8 @@
1
1
  // Default HUD UI parts (hud.marker, hud.counter, hud.bar). hud/index.js keeps the logic (targets, projection, edge arrows, quest sync)
2
2
  // and hands each part plain data; a game replaces any of them with engine.ui.set('hud.counter', ...) or turns it off with false.
3
- // Look: CSS classes .threedog-hud .threedog-hud-stats .threedog-hud-marker .threedog-hud-arrow .threedog-hud-counter .threedog-hud-bar;
4
- // colors --threedog-hud-bg/fg/accent (style.ui.hudBg...); layout is plain CSS, so style.ui.css moves the stats column, sizes, fonts.
5
- // Inner HTML: style.ui.templates.hudMarker / hudCounter / hudBar (data, { esc, t }) => HTML.
3
+ // Picture: CSS classes .threedog-hud .threedog-hud-stats .threedog-hud-marker .threedog-hud-arrow .threedog-hud-counter .threedog-hud-bar;
4
+ // colors follow ui.theme bg / fg / accent unless ui.theme hudBg / hudFg / hudAccent say otherwise; layout is plain CSS, so ui.css moves the stats column, sizes, fonts.
5
+ // Inner HTML: ui.templates.hudMarker / hudCounter / hudBar (data, { esc, t }) => HTML.
6
6
  import { esc, placeAt } from '../../ui/UI.js';
7
7
  /** @import { Engine, UIPart } from '../../types/core' */
8
8
 
@@ -15,10 +15,10 @@ export const CSS = `
15
15
  .threedog-hud-top-left,.threedog-hud-top,.threedog-hud-top-right{top:var(--hy)}
16
16
  .threedog-hud-bottom-left,.threedog-hud-bottom,.threedog-hud-bottom-right{bottom:calc(12px + env(safe-area-inset-bottom,0px))}
17
17
  .threedog-hud-left,.threedog-hud-right{top:50%;transform:translateY(-50%)}
18
- .threedog-hud-counter,.threedog-hud-bar{background:var(--threedog-hud-bg);border-radius:8px;padding:4px 10px;min-width:120px}
18
+ .threedog-hud-counter,.threedog-hud-bar{background:var(--threedog-hud-bg);border-radius:var(--threedog-radius-small);padding:4px 10px;min-width:120px}
19
19
  .threedog-hud-bar-track{height:6px;border-radius:3px;background:var(--threedog-line);overflow:hidden;margin-top:3px}
20
20
  .threedog-hud-bar-fill{height:100%;width:calc(var(--threedog-hud-fill,0) * 100%);background:var(--threedog-hud-accent)}
21
- .threedog-hud-marker{position:absolute;left:0;top:0;transform:translate(-50%,-100%);display:flex;flex-direction:column;align-items:center;white-space:nowrap;text-shadow:0 1px 2px rgba(0,0,0,.6)}
21
+ .threedog-hud-marker{position:absolute;left:0;top:0;transform:translate(-50%,-100%);display:flex;flex-direction:column;align-items:center;white-space:nowrap;text-shadow:var(--threedog-shadow-small)}
22
22
  .threedog-hud-marker::after{content:'';width:10px;height:10px;margin-top:2px;border-radius:50%;background:var(--threedog-hud-accent)}
23
23
  .threedog-hud-marker.threedog-hud-arrow{transform:translate(-50%,-50%)}
24
24
  .threedog-hud-marker.threedog-hud-arrow::after{width:0;height:0;border-radius:0;border:7px solid transparent;border-left:12px solid var(--threedog-hud-accent);order:-1;transform:rotate(var(--threedog-hud-angle,0rad))}
@@ -33,7 +33,7 @@ export const CSS = `
33
33
  */
34
34
  export function defineHudParts(e, root) {
35
35
  const tools = { esc, t: (k, p) => e.t(k, p) };
36
- const tpl = name => e.style.ui?.templates?.[name];
36
+ const tpl = name => e.ui.templates[name];
37
37
 
38
38
  // One marker: update({ x, y, arrow, angle, label, icon, distance }) moves and redraws it; hide() hides it
39
39
  e.ui.define('hud.marker', () => {
@@ -46,10 +46,12 @@ export function defineHudParts(e, root) {
46
46
  el.hidden = false;
47
47
  el.classList.toggle('threedog-hud-arrow', d.arrow);
48
48
  if (d.arrow) el.style.setProperty('--threedog-hud-angle', d.angle.toFixed(3) + 'rad');
49
- placeAt(el, d.x, d.y);
50
49
  const t = tpl('hudMarker');
51
50
  const h = t ? t(d, tools) : `${d.icon || d.label ? `<span class="threedog-hud-label">${esc(d.icon)} ${esc(d.label)}</span>` : ''}${d.distance ? `<span class="threedog-hud-dist">${esc(d.distance)}</span>` : ''}`;
52
51
  if (h !== html) { html = h; el.innerHTML = h; } // rebuild only when the text changed (called every frame)
52
+ // An edge arrow is centered on its spot, so a long label would run off the screen: keep the whole marker inside
53
+ const half = d.arrow ? el.offsetWidth / 2 : 0, w = el.parentNode?.clientWidth ?? 0;
54
+ placeAt(el, half && w ? Math.min(Math.max(d.x, half), w - half) : d.x, d.y);
53
55
  },
54
56
  hide() { el.hidden = true; },
55
57
  dispose() { el.remove(); },
@@ -56,7 +56,7 @@
56
56
  // scenes built in code (scene) cannot be saved, loading does not switch level -- to support cross-level loading, register the builder in the assets manifest
57
57
  // and use level({ url: name }).
58
58
  // Event: level:loaded { root, markers, spawn }
59
- // Look: the level module draws nothing itself, the scene looks entirely like your model, so it does not read the style.
59
+ // Picture: the level module draws nothing itself, the scene looks entirely like your model, so it does not read the style.
60
60
  import * as THREE from 'three';
61
61
  import { buildHeightfield } from './heightfield.js';
62
62
  import { toast } from '../../ui/UI.js';
@@ -99,7 +99,6 @@ export function level(opts = {}) {
99
99
 
100
100
  const api = {
101
101
  root: null, markers: {}, spawn: new THREE.Vector3(), heightfield: null,
102
- get object() { return api.root; }, // same as root (consistent with player.object, ent.object)
103
102
  get ready() { return done; },
104
103
  /** Register things belonging to the current level ({ remove() } handles); auto-removed on level switch / unload; returns the same handle */
105
104
  track(h) { if (h) removers.push(h); return h; },
@@ -204,8 +203,10 @@ export function level(opts = {}) {
204
203
  const sp = markers.spawn || Object.values(markers).find(m => /^spawn_/i.test(m.name));
205
204
  api.spawn = sp ? sp.position.clone() : new THREE.Vector3(0, hf.height(0, 0), 0);
206
205
  pendingColliders = colliders === false ? cols.filter(m => COL_RE.test(m.name) || chainValue(m, root, 'collider')) : cols;
207
- // rays: all meshes; collision meshes and non-walkable meshes also occlude the camera
208
- removers.push(e.rays.addStatic(root), e.rays.addStatic([...cols, ...meshes.filter(m => !walkSet.has(m))], { occluder: true }));
206
+ // rays: all meshes; collision meshes and shown non-walkable meshes also occlude the camera, unless a node says userData.occluder = false (a glass roof, a thin railing).
207
+ // col_ meshes are hidden by design and still block; any other hidden mesh is not on screen, so the arm has nothing to avoid
208
+ const blocks = m => chainValue(m, root, 'occluder') !== false, shownHere = m => !chainHas(m, root, p => !p.visible);
209
+ removers.push(e.rays.addStatic(root), e.rays.addStatic([...cols.filter(blocks), ...meshes.filter(m => !walkSet.has(m) && shownHere(m) && blocks(m))], { occluder: true }));
209
210
  trimeshCache = null; version++;
210
211
  addColliders();
211
212
  }
@@ -14,7 +14,7 @@
14
14
  // Shadows: none by default; lightPool({ shadows: k }) makes k of the point lights cast, used by sources added with castShadow: true.
15
15
  // An idle shadow light (no source, or faded to 0) stops re-rendering its cube shadow map (shadow.autoUpdate = false): six shadow passes a frame for a dark light.
16
16
  // When every point light casts (shadows >= point) there are no plain ones, so sources without castShadow also take the shadow lights (they cast then) instead of never lighting.
17
- // Day / night: a source added with `dusk` (street lamps, shop lights) is scaled by the same daylight curve as look.materials.glow (render/lookGlow.js,
17
+ // Day / night: a source added with `dusk` (street lamps, shop lights) is scaled by the daylight curve of engine.uniforms.uNight (render/daylight.js,
18
18
  // shared code, not a copy), so its real light, its stand-in and the game's window glow switch on together. Off by default: a torch in a cave, a
19
19
  // muzzle flash or a lamp the game wants lit at noon keeps its intensity. Its scaled intensity is what the choice scores, so lamps that are off by
20
20
  // day give their lights to sources that are lit.
@@ -24,7 +24,7 @@ import { warnOnce } from '../../core/validate.js';
24
24
  import { readParams, keysSchema } from '../../core/params.js';
25
25
  import { vec3 } from '../../core/math.js';
26
26
  import { codedError, coded } from '../../core/errorHints.js';
27
- import { DUSK, daylightOf, nightOf } from '../../render/lookGlow.js';
27
+ import { DUSK, daylightOf, nightOf } from '../../render/daylight.js';
28
28
  /** @import { ModuleDef } from '../../types/core' */
29
29
  /** @import { LightPool, LightPoolOptions } from '../../types/world' */
30
30
 
@@ -64,11 +64,11 @@ const LIGHT_POOL_PARAMS = keysSchema(OPT_KEYS);
64
64
  export function lightPool(opts = {}) {
65
65
  readParams('lightPool', LIGHT_POOL_PARAMS, opts);
66
66
  const { point = 8, spot = 0, shadows = 0, every = 0.1, fade = 0.3 } = opts;
67
- let e = null, timer = Infinity, time = 0, seq = 0, daylight = null;
67
+ let e = null, timer = Infinity, time = 0, seq = 0, daylight = null, cut = false, offCut = null;
68
68
  const sources = [], groups = [], tmp = new THREE.Vector3(), at = new THREE.Vector3();
69
69
 
70
70
  const worldPos = (src, out) => src.follow ? out.setFromMatrixPosition(src.follow.matrixWorld) : out.copy(src.pos);
71
- // 1 for a source that ignores the time of day, else glow's night factor (0 by day, 1 at night) for its dusk
71
+ // 1 for a source that ignores the time of day, else the night factor (0 by day, 1 at night) for its dusk
72
72
  const nightK = src => src.dusk === null ? 1 : nightOf(daylight, src.dusk);
73
73
  const litOf = src => src.intensity * nightK(src);
74
74
  const setGlow = (src, k) => {
@@ -147,7 +147,7 @@ export function lightPool(opts = {}) {
147
147
  for (const k of ['intensity', 'distance', 'decay', 'priority', 'angle', 'penumbra', 'flicker', 'target', 'name']) if (k in o) src[k] = o[k];
148
148
  if ('dusk' in o) {
149
149
  const d = o.dusk === true ? DUSK : o.dusk === false || o.dusk == null ? null : o.dusk;
150
- if (d !== null && !(typeof d === 'number' && d >= 0 && d <= 1)) throw codedError('look-param', STRINGS.dusk.replace('{d}', String(DUSK)) + JSON.stringify(o.dusk), TypeError);
150
+ if (d !== null && !(typeof d === 'number' && d >= 0 && d <= 1)) throw codedError('lightpool-dusk', STRINGS.dusk.replace('{d}', String(DUSK)) + JSON.stringify(o.dusk), TypeError);
151
151
  src.dusk = d;
152
152
  }
153
153
  if ('glow' in o) { if (src.glow) setGlow(src, 1); src.glow = glowOf(o.glow); setGlow(src, src.slot ? 1 - src.slot.w : 1); }
@@ -224,7 +224,7 @@ export function lightPool(opts = {}) {
224
224
  }
225
225
 
226
226
  return {
227
- name: 'lightPool', type: 'look', params: LIGHT_POOL_PARAMS, options: opts, label: 'Light pool', stage: 'late',
227
+ name: 'lightPool', type: 'picture', params: LIGHT_POOL_PARAMS, options: opts, label: 'Light pool', stage: 'late',
228
228
  install(engine) { engine.i18n.add({ 'zh-CN': { 'module.lightPool': '光源池' }, en: { 'module.lightPool': 'light pool' } });
229
229
  e = engine;
230
230
  const k = Math.max(0, Math.min(shadows, point));
@@ -233,16 +233,20 @@ export function lightPool(opts = {}) {
233
233
  makeGroup('point', false, point - k);
234
234
  makeGroup('spot', false, spot);
235
235
  if (e.ready) warnOnce(STRINGS.late);
236
+ offCut = e.events.on('camera:shot', () => { cut = true; });
236
237
  return api;
237
238
  },
238
239
  frame(dt) {
239
240
  time += dt; // presentation seconds for flicker: keeps running while gameplay is frozen, like the picture
240
241
  daylight = daylightOf(e);
241
- if (daylight === null && sources.some(s => s.dusk !== null)) warnOnce(coded('look-param', STRINGS.noDay));
242
+ if (daylight === null && sources.some(s => s.dusk !== null)) warnOnce(coded('lightpool-dusk', STRINGS.noDay));
243
+ // a camera cut (a view, a fixed shot): no fade, the picture is new anyway. Twice: the first pass frees the slots of sources left behind, the
244
+ // second hands them over. Without it `shot --view` drew the lamps of the old spot, 1/30 s after the cut and 0.3 s before any fade would end
245
+ if (cut) { cut = false; timer = 0; for (let i = 0; i < 2; i++) { assign(); update(fade); } return; }
242
246
  if ((timer += dt) >= every) { timer = 0; assign(); }
243
247
  update(dt);
244
248
  },
245
- dispose() { for (const L of api.lights) { L.removeFromParent(); L.target?.removeFromParent(); L.dispose(); } },
249
+ dispose() { offCut?.remove(); for (const L of api.lights) { L.removeFromParent(); L.target?.removeFromParent(); L.dispose(); } },
246
250
  describe() {
247
251
  const u = api.usage();
248
252
  return { lights: api.lights.length, lit: u.lit, sources: u.sources, shadows: Math.max(0, Math.min(shadows, point)) };
@@ -297,7 +297,7 @@ export function music(opts = {}) {
297
297
  readParams('music', MUSIC_PARAMS, opts);
298
298
  let m = null;
299
299
  return {
300
- name: 'music', type: 'look', params: MUSIC_PARAMS, options: opts, label: 'Music', optional: ['dialogue'], stage: 'audio',
300
+ name: 'music', type: 'picture', params: MUSIC_PARAMS, options: opts, label: 'Music', optional: ['dialogue'], stage: 'audio',
301
301
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.music': '音乐' }, en: { 'module.music': 'music' } });
302
302
  m = new Music(e, opts, ctx.track);
303
303
  ctx.track(e.events.on('session:end', () => m.stop({ fade: 0 }))); // a playthrough ends: its music stops at once
@@ -31,29 +31,40 @@
31
31
  // fog true affected by fog
32
32
  // maxPixels 512 largest on-screen size of one particle (pixels), so smoke drifting past the camera does not fill the screen
33
33
  //
34
- // Style: style.particles[name] = {...same params...} sits under the define() params (what define sets wins).
35
- // so a game can write only engine.particles.define('leaves', { max: 200 }) and leave color and texture to the style.
36
- // style.particles.default = {...} is the fallback for all effects.
37
- // The style can also define effects directly: a name in style.particles that the game never define()d is defined from the style on the first emit/attach.
34
+ // Pictures: particles({ effects: { name: {...same params...} }, default: {...} }). effects[name] sits under the define() params (what define sets wins),
35
+ // so a game can write only engine.particles.define('leaves', { max: 200 }) and keep color and texture with the rest of its picture. default is the fallback for all effects.
36
+ // A name in effects that the game never define()d is defined on the first emit/attach.
37
+ // Material: each effect's material is a plain three.js material, swapped with fx.material = myMaterial and drawn as given; fx.uniforms are the engine's { value } objects.
38
38
  import * as THREE from 'three';
39
39
  import { vec3 } from '../../core/math.js';
40
40
  import { Effect, NEUTRAL, KEYS } from './effect.js';
41
41
  import { warnMissing } from '../../core/validate.js';
42
- import { readParams, keysSchema } from '../../core/params.js';
42
+ import { readParams, keysSchema, isOptions } from '../../core/params.js';
43
+ import { codedError } from '../../core/errorHints.js';
43
44
  // one schema per public entry (unknown keys throw in dev with did-you-mean). Effect param values come in many shapes (number or [min, max], color), so only key names are checked
44
45
  const FX_PARAMS = keysSchema(KEYS);
46
+ const PARTICLES_PARAMS = {
47
+ effects: { type: 'object', optional: true, desc: 'effect params by name: under what define() gives, and defined on the first emit / attach when define() never ran' },
48
+ default: { type: 'object', optional: true, desc: 'params every effect starts from' },
49
+ };
45
50
  const EMIT_PARAMS = { count: { type: 'number', default: 10, min: 0, desc: 'particles in this burst' }, overrides: 'any?' }; // overrides: null is allowed (no override)
46
51
  const ATTACH_PARAMS = { rate: { type: 'number', optional: true, min: 0, desc: 'particles per second (default: the effect rate)' }, offset: 'any?', overrides: 'any?' };
47
52
  const _vs = new THREE.Vector2(); // canvas CSS size (particle point scale follows the canvas height, not the window)
48
53
  /** @import { ModuleDef } from '../../types/core' */
49
54
  /** @import { Object3D, PositionLike } from '../../types/common' */
50
- /** @import { ParticleEffect, ParticleEmitter, ParticleOptions } from '../../types/gameplay' */
55
+ /** @import { ParticleEffect, ParticleEmitter, ParticleOptions, ParticlesOptions } from '../../types/gameplay' */
51
56
 
52
57
  /** engine.particles */
53
58
  export class Particles {
54
- /** @internal */
55
- constructor(engine) {
59
+ /**
60
+ * @internal
61
+ * @param {any} engine
62
+ * @param {ParticlesOptions} [opts]
63
+ */
64
+ constructor(engine, { effects = {}, default: fallback = {} } = {}) {
56
65
  /** @internal */ this.engine = engine;
66
+ /** @internal what particles({ effects }) gave */ this._given = effects;
67
+ /** @internal what particles({ default }) gave */ this._fallback = fallback;
57
68
  /** Defined effects @type {Map<string, ParticleEffect>} */
58
69
  this.effects = new Map();
59
70
  /** @internal */ this.emitters = new Set();
@@ -63,12 +74,12 @@ export class Particles {
63
74
  /** @internal */ this._e = new THREE.Vector3();
64
75
  }
65
76
 
66
- /** @internal */
67
- _styleFor(name) { const s = this.engine.style.particles || {}; return { ...(s.default || {}), ...(s[name] || {}) }; }
68
-
69
77
  /**
70
- * Define an effect (same name replaces it, and emitters attached to it move to the new definition); params sit on top of the style
71
- * pack preset. Returns the effect object: .points is its THREE.Points (a Sprite on WebGPURenderer), .material is the shader material
78
+ * Define an effect (same name replaces it, and emitters attached to it move to the new definition); params sit on top of particles({ effects,
79
+ * default }). Returns the effect object: .points is its THREE.Points (a Sprite on WebGPURenderer); .material is its plain three.js material (set
80
+ * your own and it is drawn as given, null gives the engine's back); .uniforms are the engine material's { value } objects (uMap, uHasMap, uScale,
81
+ * uMaxPx), which a ShaderMaterial of yours can share. A material of yours lasts until the effect is defined again
82
+ * @example engine.particles.define('sparks', { blending: 'additive' }).material = myMaterial;
72
83
  * @param {string} name
73
84
  * @param {ParticleOptions} [opts]
74
85
  * @returns {ParticleEffect}
@@ -76,7 +87,7 @@ export class Particles {
76
87
  define(name, opts = {}) {
77
88
  readParams(`particles.define('${name}')`, FX_PARAMS, opts);
78
89
  const old = this.effects.get(name);
79
- const o = { ...NEUTRAL, ...this._styleFor(name), ...opts };
90
+ const o = { ...NEUTRAL, ...this._fallback, ...this._given[name], ...opts };
80
91
  const fx = new Effect(this, name, o);
81
92
  this.effects.set(name, fx);
82
93
  // emitters attached to the old effect keep running on the new one (redefining tunes an effect, it does not stop it)
@@ -92,8 +103,8 @@ export class Particles {
92
103
  /** @internal */
93
104
  _get(name) {
94
105
  let fx = this.effects.get(name);
95
- if (!fx && this.engine.style.particles?.[name]) fx = this.define(name);
96
- if (!fx) warnMissing('particle', name, [...this.effects.keys(), ...Object.keys(this.engine.style.particles || {}).filter(k => k !== 'default' && !this.effects.has(k))]);
106
+ if (!fx && this._given[name]) fx = this.define(name);
107
+ if (!fx) warnMissing('particle', name, [...new Set([...this.effects.keys(), ...Object.keys(this._given)])]);
97
108
  return fx;
98
109
  }
99
110
 
@@ -167,17 +178,27 @@ export class Particles {
167
178
  h.object.getWorldQuaternion(this._q);
168
179
  h.fx.spawn(p, n, o, o.worldSpace === false ? this._q : null);
169
180
  }
170
- for (const fx of this.effects.values()) { fx.material.uniforms.uScale.value = scale; fx.update(dt); }
181
+ for (const fx of this.effects.values()) { fx.uniforms.uScale.value = scale; fx.update(dt); }
171
182
  }
172
183
  }
173
184
 
174
185
  /**
175
- * Particles -> engine.particles
186
+ * Particles -> engine.particles. effects: params by name, under what define() gives; a name define() never saw is defined on its first emit / attach.
187
+ * default: params every effect starts from
188
+ * @param {ParticlesOptions} [opts]
176
189
  * @returns {ModuleDef<Particles>}
190
+ * @example engine.use(particles({ default: { color: 0xc8b89a }, effects: { dust: { max: 300, size: [0.3, 0.8] } } }));
177
191
  */
178
- export function particles() {
192
+ export function particles(opts = {}) {
193
+ readParams('particles', PARTICLES_PARAMS, opts);
194
+ // checked here, not on the first emit: a typo in a style table should fail at startup, not in the middle of play
195
+ for (const [name, spec] of Object.entries(opts.effects ?? {})) {
196
+ if (!isOptions(spec)) throw codedError('module-params', `particles({ effects: { ${name} } }): an effect is an object of params, e.g. { max: 200, color: 0xcccccc }; got ${JSON.stringify(spec)}`);
197
+ readParams(`particles({ effects: { ${name} } })`, FX_PARAMS, spec);
198
+ }
199
+ if (opts.default) readParams('particles({ default })', FX_PARAMS, opts.default);
179
200
  let p = null;
180
- return { name: 'particles', type: 'look', provides: ['particles'], label: 'Particles', stage: 'effects', install(e) { e.i18n.add({ 'zh-CN': { 'module.particles': '粒子' }, en: { 'module.particles': 'particles' } }); p = new Particles(e); return p; }, frame(dt) { p.update(dt); },
201
+ return { name: 'particles', type: 'picture', provides: ['particles'], label: 'Particles', params: PARTICLES_PARAMS, options: opts, stage: 'effects', install(e) { e.i18n.add({ 'zh-CN': { 'module.particles': '粒子' }, en: { 'module.particles': 'particles' } }); p = new Particles(e, opts); return p; }, frame(dt) { p.update(dt); },
181
202
  counts() { return { alive: p.count(), emitters: p.emitters.size }; }, // engine.counts().particles
182
203
  // "did the dust burst fire": live particles in total and per effect that has any (idle effects left out to stay short). Kept under `alive`
183
204
  // because the numbers change every frame (an emitter's smoke): state comparisons (the session spec) skip that key as presentation, not game state