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
package/core/look/part.js DELETED
@@ -1,253 +0,0 @@
1
- // engine.look.<part>: what a game calls. Every part has the same small set (docs/plans/2026-11-03-look-api.md):
2
- // set(params, { owner }) change values (shallow merge into that owner's layer; null drops a key so the layer below shows again)
3
- // patch(hook, code, { owner }) swap one named hook the part declares (GLSL / TSL; null gives the default back). Only that meaning
4
- // add(thing, ...) put one more named thing in next to the engine's (look.post.add, look.materials.add); remove() takes it out
5
- // replace(thing, { owner }) swap the one three.js thing the part draws (a texture, a sky object, a Material, an effect list); null gives it
6
- // back. A whole module (behaviour, saves) is engine.use(mine(), { replaces: '<slot>' }) instead
7
- // manual(keys?) the engine stops writing values it writes on its own; the three.js object is yours
8
- // value(key) the one read: the value in effect (who set it: describe().look); object: the three.js object(s) behind it
9
- // A verb a part does not have throws with the part's pointer and the verbs it has. Everything else (raw writes, extending keys, drivers, the
10
- // per-frame tick) is for module code and lives on part.author, so engine.look.fog. autocompletes to the game verbs only.
11
- // Why one helper and not per-part code: layering, owner records, validation, catalog and describe were written differently in every module
12
- // (sky.modify had owners, engine.look.tone.set had none, describeRender guessed the source by comparing against start values). A part author writes only
13
- // apply / applyHook / applyReplace; everything a reader (describe, catalog, debug.override) needs comes from the same records.
14
- // Every key is a shared point 'look.<part>.<key>' (points.js, core/sharedPoint.js): engine default < style < game < effect (weather, sunset:
15
- // mul / add) < system < settings (restrict only, above system) < debug. Two owners setting one key on one layer is a dev error naming both, with the fix.
16
- // Hooks and the replace slot are keys too ('hook:<name>', '@replace'), so they get the same layering and records for free.
17
- import { closest } from '../validate.js';
18
- import { codedError } from '../errorHints.js';
19
- import { REPLACE, HOOK, addParams, allKeys, sourceOf, flush, quietRefresh, retractKeys, batch, driveKeys, tick, pointOf, ownerValues, dropOwner } from './points.js';
20
- import { LAYERS } from '../sharedPoint.js';
21
- import { setOn, setStyle, writeLayer, takeVerb, example } from './write.js';
22
- import { manualVerb, ownedOf } from '../owned.js';
23
- import { defineState } from './state.js';
24
-
25
- export { REPLACE };
26
-
27
- /** A patch(name, value) hook value as an object: a bare GLSL string becomes { glsl }, a { glsl, uniforms, ... } spec passes through */
28
- export const hookSpec = v => (typeof v === 'string' ? { glsl: v } : v);
29
- export { disposeLooksOf } from './points.js';
30
- const SPEC_FIELDS = ['id', 'group', 'module', 'object', 'params', 'style', 'read', 'apply', 'applyAtStart', 'hooks', 'applyHook', 'noPatch',
31
- 'replace', 'applyReplace', 'noReplace', 'noAdd', 'docs', 'normalize', 'validate', 'verbs', 'appliesTo', 'extraSignatures', 'info'];
32
- const SIG = { set: "set(params, { owner, layer? })", patch: 'patch(hook, code, { owner })', replace: 'replace(thing, { owner })', manual: 'manual(keys?, on = true)' };
33
-
34
- class LookPart {
35
- /** @param {any} e @param {any} spec see defineLookPart */
36
- constructor(e, spec) {
37
- this._e = e; this._spec = spec;
38
- this._params = {}; this._meta = {};
39
- /** key -> its shared point; _fns: function values on number keys (tick evaluates them); _dirty / _hold: batch(points.js) */
40
- this._points = new Map(); this._fns = new Map(); this._dirty = new Set(); this._hold = 0;
41
- this._style = new Map();
42
- this._resolved = new Map();
43
- addParams(this, spec.params);
44
- this._rev = 0; // goes up whenever refresh changed a resolved key, so a per-frame reader rebuilds its view only after a change
45
- this._driven = new Map(); // key -> who writes it every frame from the style (sky keyframes drive the sun)
46
- this._started = false; // true once defineLookPart wrote the style layer: apply runs only after that
47
- /** module code's half (PartAuthor below); not enumerable, so a logged part shows the game's view */
48
- this.author = /** @type {PartAuthor} */ (/** @type {unknown} */ (null));
49
- Object.defineProperty(this, 'author', { value: new PartAuthor(this), enumerable: false });
50
- }
51
- /** Catalog / override id: 'look.<part>' */
52
- get id() { return `look.${this._spec.id}`; }
53
- /** The three.js object(s) behind this part (renderer, lights ...); changing them directly works but is tagged 'three' in describe().look */
54
- get object() { return this._spec.object?.(); }
55
-
56
- /**
57
- * The error for a verb this part does not have. Every part says it the same way: why not, the part's own pointer (noPatch / noAdd / noReplace)
58
- * or a set() example, then the verbs it does have with their call shapes (the same list as engine.catalog('look.<part>').signatures), so the
59
- * next call is always on screen and no part's message can drift from what the part offers.
60
- * @param {string} verb @param {string} why @param {string} [hint]
61
- */
62
- _lacks(verb, why, hint) {
63
- const has = Object.values(this.author.signatures).map(sig => `${this.id}.${sig}`).join(', ');
64
- const next = (hint ?? `Change it with ${this.id}.set(${example(this)})`).replace(/\.\s*$/, ''); // a hint may end in a period: not two
65
- return codedError('look-verb', `${this.id}.${verb}(): ${why}. ${next}. Verbs it has: ${has}`);
66
- }
67
-
68
- /**
69
- * Change parameters for one owner. Nested objects flatten to the part's dotted keys ({ sun: { intensity: 3 } } -> 'sun.intensity').
70
- * @param {Record<string, any>} params null drops a key from this owner's layer
71
- * @param {{ owner?: string, layer?: 'style' | 'game' | 'effect' | 'system' | 'settings' | 'debug' }} [o] layer: game by default; an effect
72
- * module writes 'effect', 'system' takes the key over above every effect (the settings layer only restricts: set false)
73
- * @returns {{ remove(): void }} removes what this call wrote
74
- */
75
- set(params, { owner = 'game', layer = 'game' } = {}) {
76
- // 'engine' is outside the JSDoc type, but an untyped caller can pass it
77
- if (!(layer in LAYERS) || /** @type {string} */ (layer) === 'engine') throw codedError('shared-layer', `${this.id}.set(params, { layer }): layer is one of ${Object.keys(LAYERS).slice(1).join(' < ')}, got ${JSON.stringify(layer)}`);
78
- return this._setOn(layer, owner, params);
79
- }
80
- /**
81
- * Swap one named hook the part declares (only that: adding a thing is add()). Names and signatures: engine.catalog('look.<part>').hooks
82
- * @param {string} name @param {any} code a GLSL string (or the part's hook spec { glsl, tsl, uniforms }); null gives the default back
83
- * @param {{ owner?: string }} [o]
84
- */
85
- patch(name, code, o) {
86
- const hooks = this._spec.hooks;
87
- if (!hooks) throw this._lacks('patch', 'this part has no named hook to swap', this._spec.noPatch);
88
- if (!(name in hooks)) {
89
- const c = closest(name, Object.keys(hooks)); throw codedError('look-verb', `${this.id}.patch('${name}'): unknown hook${c ? ` (did you mean '${c}'?)` : ''}; hooks: ${Object.keys(hooks).join(', ')}`);
90
- }
91
- return this._write('game', o?.owner ?? 'game', { [HOOK + name]: code });
92
- }
93
- /**
94
- * Put one more named thing in next to the engine's (look.post.add: an effect; look.materials.add: a shader patch for some roles); the part's
95
- * call shape: engine.catalog('look.<part>').signatures.add. A part with nothing to add throws with its pointer
96
- * @param {...any} args @returns {{ remove(): void }}
97
- */
98
- add(...args) {
99
- if (this._spec.verbs?.add?.take) return this._take('add', args);
100
- throw this._lacks('add', 'this part has nothing to add', this._spec.noAdd);
101
- }
102
- /**
103
- * Swap the one three.js thing this part draws (what it accepts and what is lost: engine.catalog('look.<part>').replace); null gives it back
104
- * @param {any} impl @param {{ owner?: string, [option: string]: any }} [o] owner, plus the part's own options (catalog replace.options)
105
- */
106
- replace(impl, o) {
107
- if (!this._spec.replace) throw this._lacks('replace', 'this part has no thing to swap', this._spec.noReplace);
108
- if (this._spec.verbs?.replace?.take) return this._take('replace', [...arguments]);
109
- // options besides owner are the part's own (look.ground: { effects: false }); a key the part does not take throws instead of doing nothing
110
- const extra = Object.keys(o ?? {}).filter(k => k !== 'owner'), takes = this._spec.replace.options ?? [];
111
- const bad = extra.find(k => !takes.includes(k));
112
- if (bad) throw codedError('look-param', `${this.id}.replace(impl, { ${bad} }): ${takes.length ? `options are owner, ${takes.join(', ')}` : 'the only option is owner'}`);
113
- if (extra.length) this._spec.replace.withOptions(impl, o);
114
- return this._write('game', o?.owner ?? 'game', { [REPLACE]: impl });
115
- }
116
- /**
117
- * Take properties the engine writes on its own (every frame or on a timer) for the game, or hand them back. Taken, the engine stops writing them
118
- * and the three.js object is yours (engine.lights.sun.intensity = 3 sticks); manual(keys, false) or the returned remove() gives them back.
119
- * Keys match by dotted prefix ('sun' takes sun.intensity and sun.color); none = every one of this part. Which keys: describe().owned.
120
- * A direct write without manual() does the same (the engine yields and warns once), manual() just says it on purpose.
121
- * @example engine.look.lights.manual('sun'); engine.lights.sun.intensity = 3; engine.look.lights.manual('sun', false); engine.look.fog.manual();
122
- * @param {string | string[]} [keys] @param {boolean} [on] @returns {{ remove(): void }}
123
- */
124
- manual(keys, on) { return manualVerb(this._e, this._spec.id, keys, on); }
125
- /** The value in effect for a key (after all layers): the one read. Who set it and how: engine.describe().look.<part> */
126
- value(key) { return this._resolved.get(key); }
127
-
128
- // ---- internal (layering: points.js, write.js); module code goes through part.author ------------------------------------------------------
129
-
130
- /** @internal drop every layer owner wrote (every layer above style), for tests and tools that did not keep the handle; returns how many */
131
- _clear(owner) { let n = 0; for (const l of Object.keys(LAYERS)) if (l !== 'engine' && l !== 'style' && this._drop(l, owner)) n++; return n; }
132
- /** @internal set() and engine.debug.override share this (write.js: normalize, flatten, check, write) */
133
- _setOn(layer, owner, params) { return setOn(this, layer, owner, params); }
134
- /** @internal Replace the style layer (start, or a style swap); game and debug layers stay */
135
- _setStyle(values) { setStyle(this, values); }
136
- _write(layer, owner, values) { return writeLayer(this, layer, owner, values); }
137
- _drop(layer, owner) { return dropOwner(this, layer, owner); }
138
- /** @internal recompute (force: every key to apply again); _keys / _source: report.js */
139
- _refresh(force = false) { flush(this, force); }
140
- _keys() { return allKeys(this); }
141
- _source(key) { return sourceOf(this, key); }
142
- /** @internal Resolved params as a plain object */
143
- _values() { const o = {}; for (const k in this._params) o[k] = this._resolved.get(k); return o; }
144
- /** A verb with its own call shape (spec.verbs[verb].take) */
145
- _take(verb, args) { return takeVerb(this, verb, args); }
146
- }
147
-
148
- /**
149
- * part.author: what module code that defines or drives a part calls (render/postLook.js, terrain, weather, the sky's keyframes ...); a game never
150
- * needs it. Kept off the part so a game's autocomplete shows only set / patch / add / replace / manual / value; public (not `_`) so no module
151
- * reaches into a part's fields.
152
- */
153
- class PartAuthor {
154
- /** @param {LookPart} p */
155
- constructor(p) { this._p = p; }
156
- /** Each verb's call shape (spec.verbs overrides a default); the catalog lists it and verb errors quote it */
157
- get signatures() {
158
- const p = this._p, s = p._spec, out = /** @type {Record<string, string>} */ ({ set: SIG.set });
159
- if (s.hooks) out.patch = SIG.patch;
160
- if (s.verbs?.add) out.add = s.verbs.add.signature;
161
- if (s.replace) out.replace = s.verbs?.replace?.signature ?? SIG.replace;
162
- if (ownedOf(p._e, s.id).length) out.manual = SIG.manual;
163
- return Object.assign(out, s.extraSignatures); // a part's own verb (look.post.add, look.materials.glow), listed so the catalog shows it
164
- }
165
- /** Write raw keys (params, 'hook:<name>', '@replace', a part's own slot keys) for an owner on the game layer, no normalize; null drops a key */
166
- write(owner, values, { layer = 'game' } = {}) { return this._p._write(layer, owner, values); }
167
- /** What one owner holds for a key (undefined when it holds nothing): look.weather.replace adds to the object its owner put in the replace slot */
168
- ownerValue(owner, key, { layer = 'game' } = {}) { return ownerValues(this._p, layer, owner)[key]; }
169
- /** Add declared keys to a started part (same spec fields as params; a known key is left alone). Values recompute without calling apply */
170
- extend(params) { addParams(this._p, params, { skipKnown: true }); quietRefresh(this._p); }
171
- /** Remove every key starting with prefix (e.g. 'bloom.'), with the values any layer holds for them */
172
- retract(prefix) { retractKeys(this._p, prefix); }
173
- /** Replace the style layer (post: a replaced effect chain brings its own defaults) */
174
- restyle(values) { this._p._setStyle(values); }
175
- /** Is key a declared param of this part */
176
- has(key) { return key in this._p._params; }
177
- /** [key, value] pairs in effect whose key starts with prefix ('hook:' lists the patches set) */
178
- resolved(prefix = '') { return [...this._p._resolved].filter(([k]) => k.startsWith(prefix)); }
179
- /** Resolved params as a plain object */
180
- values() { return this._p._values(); }
181
- /** Only what the game (or a layer above it) set for a key, else undefined: render/lookSurface.js reads a game's material choice through it */
182
- top(key) {
183
- const p = this._p, s = p._points.get(key);
184
- let best = null;
185
- for (const en of s?._map(undefined)?.values() ?? []) if (en.op === 'set' && LAYERS[en.layer] >= LAYERS.game && (!best || LAYERS[en.layer] >= LAYERS[best.layer])) best = en;
186
- return best ? p._fns.get(`${key}\0${best.owner}`)?.fn ?? best.value : undefined;
187
- }
188
- /** The shared point behind key (engine.stacks.get('look.<part>.<key>')): take() on it adds an effect entry */
189
- point(key) { if (!(key in this._p._params)) throw this._p._lacks('point', `no key ${key}`); return pointOf(this._p, key); }
190
- /**
191
- * Declare keys a style-driven system writes every frame (the sky drives sun and hemisphere from style.sky.keyframes). While driven, the
192
- * driver's value (feed) is the style layer of those keys; a game set, the weather's mul and the settings still apply on top, and the part's
193
- * apply leaves the three.js object to the driver, which writes value(key). drive(keys, null) hands them back to the layers.
194
- * @param {string[]} keys @param {string | null} by the driver's name, e.g. 'sky' (a module name: disposing that module releases them)
195
- */
196
- drive(keys, by) { driveKeys(this._p, keys, by); }
197
- /** Who drives key every frame ('sky'), or null */
198
- driven(key) { return this._p._driven.get(key) ?? null; }
199
- /** The driver's value for a driven key this frame (the keyframes' sun intensity); the layers above still apply */
200
- feed(key, value) { const p = this._p, by = p._driven.get(key); if (by) pointOf(p, key).take({ owner: by, layer: 'style', set: value }); }
201
- /** Once per frame with the frame context: function values on number keys are evaluated (a function on a color key is the module's to read) */
202
- tick(ctx) { tick(this._p, ctx); }
203
- /** Run fn with the recompute held, so several writes apply once */
204
- batch(fn) { return batch(this._p, fn); }
205
- /** Unregister the part (its module is disposed, or its install failed): engine.look.<id> goes away and nothing drives its keys any more.
206
- * remove(), not dispose(): the part owns no GPU resource (the cancel convention for everything that only unregisters) */
207
- remove() {
208
- const p = this._p, look = p._e.look;
209
- if (look?.[p._spec.id] === p) delete look[p._spec.id];
210
- // its points stay registered (a part registered again reuses them) but hold nothing: every entry, the weather's too, goes with the part
211
- for (const s of p._points.values()) { s.onChange = null; s.clear(); }
212
- p._driven.clear(); p._fns.clear(); p._started = false;
213
- }
214
- }
215
-
216
- /**
217
- * Register a look part: engine.look.<id> gets set / patch / add / replace / manual / value (the verbs the spec supports; the others throw and
218
- * say which verb to use; module code reaches the rest through part.author), engine.catalog('look.<id>') lists its params, hooks, replace
219
- * contract and verb signatures, describe().look shows every key's value and who set it, and engine.debug.override(owner, 'look.<id>', values)
220
- * writes its debug layer. Every param needs a default; a default that changes the picture needs why (what it is for) and off (how to turn it
221
- * off), or neutral: true (checked by `npm run check`, rule R35). Its module's failed install drops it again (disposeLooksOf).
222
- * @param {any} engine @param {{ id: string, group?: string, module?: string, object?: () => any, params?: Record<string, any>, style?: () => object,
223
- * read?: () => object, apply?: (values: object, changed: Set<string>) => void, applyAtStart?: boolean,
224
- * hooks?: Record<string, { signature?: string, scope?: string[], example?: string }>, applyHook?: (name: string, glsl: any) => void, noPatch?: string,
225
- * replace?: { accepts: string, loses?: string[], options?: string[], withOptions?: (impl: any, o: object) => void }, applyReplace?: (impl: any) => void, noReplace?: string, docs?: string[],
226
- * normalize?: (params: Record<string, any>) => Record<string, any>, validate?: (key: string, value: any) => string | null | undefined, noAdd?: string,
227
- * verbs?: Partial<Record<'add' | 'replace', { signature: string, take: (bad: (msg: string) => never, ...args: any[]) => [Record<string, any>, string?, string?] }>>,
228
- * appliesTo?: string, info?: () => Record<string, object>, extraSignatures?: Record<string, string> }} spec validate: why a value is wrong (checked
229
- * before anything is written); normalize: rewrites a set() / debug.override value before the key check (a part's shorthand, or a pointed error
230
- * for a removed key); verbs: a verb with its own call shape (materials.add(name, patch, { roles }), materials.replace(role, impl));
231
- * extraSignatures: the call shapes of the part's own verbs (look.post.add, look.materials.glow); appliesTo: what a change reaches when not
232
- * everything ('new materials'); info: read-only rows describe().look adds beside the params (look.env's source: which map, does it follow the time)
233
- * @returns {LookPart}
234
- * @example
235
- * defineLookPart(engine, { id: 'glow', group: 'screen', module: 'myGlow', object: () => glowPass,
236
- * params: { strength: { type: 'number', default: 0, min: 0, neutral: true, desc: 'bloom strength' } },
237
- * apply(v, changed) { glowPass.strength = v.strength; } });
238
- * engine.look.glow.set({ strength: 0.6 }, { owner: 'night' });
239
- */
240
- export function defineLookPart(engine, spec) {
241
- for (const k of Object.keys(spec ?? {})) if (!SPEC_FIELDS.includes(k)) { const c = closest(k, SPEC_FIELDS); throw codedError('look-param', `defineLookPart: unknown spec field ${k}${c ? ` (did you mean ${c}?)` : ''}; fields: ${SPEC_FIELDS.join(', ')}`); }
242
- if (!/^[a-z][\w]*$/i.test(spec?.id ?? '')) throw codedError('look-param', `defineLookPart: id is the part name, e.g. 'fog' (engine.look.fog, catalog id 'look.fog'); got ${JSON.stringify(spec?.id)}`);
243
- const look = engine.look ??= {};
244
- defineState(look, engine); // engine.look.state(patch): the game's half of the frame context function values read (state.js)
245
- if (look[spec.id] && look[spec.id]._spec.module !== spec.module) throw codedError('look-param', `defineLookPart('${spec.id}'): engine.look.${spec.id} is already registered (by ${look[spec.id]._spec.module ?? 'core'})`);
246
- const part = new LookPart(engine, spec);
247
- part._setStyle(spec.style?.());
248
- part._started = true;
249
- // applyAtStart false: the module writes the three.js object itself at start, but value(key) must already answer (fogFarOf reads it)
250
- if (spec.applyAtStart !== false) part._refresh(true); else quietRefresh(part);
251
- look[spec.id] = part;
252
- return part;
253
- }
@@ -1,255 +0,0 @@
1
- // A LookPart's keys on shared points: every look.<part>.<key> is one engine.stacks point (core/sharedPoint.js), so look values follow the
2
- // same layers, owners, conflict errors and describe().shared rows as every other shared value. This file is the glue between a part and its points:
3
- // which point a key is, writing a value for an owner on a layer, and the recompute that hands changed keys to the part's apply.
4
- // Why points and not the part's own layer maps (the old layers.js): two layer systems decided differently (a game's look.lights.set covered the
5
- // weather's multiplier, sky/frame.js), and a reader had to learn both. One table means "game sets 3, weather x0.6 on top" holds for every look value.
6
- // Layers a part uses: the param default is the point's base (engine), a style pack writes owner 'style' on the style layer, a style-driven system
7
- // (the sky's keyframes) writes on the style layer under its own name while it drives a key, games write the game layer (or one they name),
8
- // effects (weather, sunset) write mul / add on effect, the settings menu restricts on settings, engine.debug.override writes debug.
9
- import { markOwned, ownedOf } from '../owned.js';
10
- import { parseSpec } from '../params.js';
11
- import { coded, codedError } from '../errorHints.js';
12
- import { DEV, warnOnce } from '../validate.js';
13
- import { live } from './state.js';
14
-
15
- // fn: the key also takes ({ time, weather, season, day, state, sky }) => value (number keys: evaluated each frame by tick(ctx), state.js)
16
- // device: why the engine default differs on this device (a costly post effect off on a low-tier device or headless page); describe().look shows it
17
- const LOOK_FIELDS = ['why', 'off', 'cost', 'neutral', 'check', 'fn', 'device'];
18
- export const REPLACE = '@replace';
19
- export const HOOK = 'hook:';
20
-
21
- /** Parse param specs into part._params / part._meta and give each its point (constructor and extend share it) */
22
- export function addParams(part, params, { skipKnown = false } = {}) {
23
- for (const [k, raw] of Object.entries(params ?? {})) {
24
- if (skipKnown && k in part._params) continue;
25
- const meta = {}, rest = { ...raw };
26
- for (const f of LOOK_FIELDS) if (f in rest) { meta[f] = rest[f]; delete rest[f]; }
27
- if (!('default' in rest)) throw codedError('look-param', `defineLookPart('${part._spec.id}'): param ${k} has no default. Every look param declares the value the engine uses when nobody sets it (and why / off when that value changes the picture)`);
28
- part._params[k] = parseSpec(part.id, k, rest, msg => codedError('look-param', msg));
29
- part._meta[k] = meta;
30
- pointOf(part, k);
31
- }
32
- }
33
-
34
- /** The shared point behind key ('look.fog.far'), made on first use. number params: kind number (effects multiply them); anything else
35
- * (colors, switches, hooks, the replace slot): kind value, set only. A part registered again reuses its points with the new default. */
36
- export function pointOf(part, key) {
37
- let s = part._points.get(key);
38
- if (s) return s;
39
- const S = part._e.stacks, id = part._spec.id, name = `look.${id}.${key}`, spec = part._params[key];
40
- const num = spec?.type === 'number' && typeof spec.default === 'number';
41
- if (S.has(name)) { s = S.get(name); s.clear(); s.base = spec ? spec.default : null; }
42
- else s = S.define(name, { kind: num ? 'number' : 'value', base: spec ? spec.default : null, min: num ? spec.min ?? -Infinity : -Infinity, max: num ? spec.max ?? Infinity : Infinity, save: false });
43
- // the conflict error's third fix: take it over on purpose. A key the engine writes on its own has manual(); any other is a set on system
44
- Object.defineProperty(s, 'manual', { configurable: true, get: () => (ownedOf(part._e, id, key).length
45
- ? `engine.look.${id}.manual('${key}')` : `engine.look.${id}.set({ '${key}': ... }, { owner, layer: 'system' })`) });
46
- s.onChange = () => { part._dirty.add(key); if (!part._hold) flush(part); };
47
- part._points.set(key, s);
48
- return s;
49
- }
50
-
51
- /** One owner's entry on a point (or undefined): the old value a failed write puts back */
52
- const entryOf = (s, owner) => s._map(undefined)?.get(owner);
53
-
54
- /** Every key that has a point: params, plus hooks / replace / slot keys someone wrote */
55
- export const allKeys = part => [...part._points.keys()];
56
-
57
- /** The value in effect for key: the point's layered result; a hook or slot key nobody wrote is undefined (not the null base) */
58
- function valueOf(part, k) {
59
- const s = part._points.get(k);
60
- if (!s) return undefined;
61
- const v = s.value();
62
- return k in part._params || (v != null && s.size()) ? v : undefined;
63
- }
64
-
65
- /** Hold the recompute until fn is done: a set of five keys, or the sky's frame, applies once (a point change only marks its key dirty) */
66
- export function batch(part, fn) {
67
- part._hold++;
68
- try { return fn(); } finally { if (!--part._hold && part._dirty.size) flush(part); }
69
- }
70
-
71
- /**
72
- * Recompute the dirty keys (force: every key) and hand the changed ones to the part's apply / applyHook / applyReplace.
73
- */
74
- export function flush(part, force = false) {
75
- const keys = force ? allKeys(part) : [...part._dirty], changed = [];
76
- part._dirty.clear();
77
- for (const k of keys) {
78
- const v = valueOf(part, k);
79
- if (force || part._resolved.get(k) !== v || !part._resolved.has(k)) changed.push(k);
80
- v === undefined ? part._resolved.delete(k) : part._resolved.set(k, v);
81
- }
82
- if (!changed.length) return;
83
- part._rev++;
84
- if (!part._started) return;
85
- const s = part._spec, params = changed.filter(k => k in part._params);
86
- if (changed.includes(REPLACE)) s.applyReplace?.(part._resolved.get(REPLACE) ?? null);
87
- for (const k of changed) if (k.startsWith(HOOK)) s.applyHook?.(k.slice(HOOK.length), part._resolved.get(k) ?? null);
88
- if (params.length) s.apply?.(part._values(), new Set(params));
89
- // the engine wrote these on the game's request: re-read the owned properties so the next frame does not take it for an outside write (owned.js)
90
- markOwned(part._e, s.id);
91
- }
92
-
93
- /**
94
- * Evaluate a number key's function value: the number, or undefined when it threw or gave something that is not a finite number. Then the point
95
- * keeps its last good value, the record counts the failure (describe().look shows fnErrors / fnError on the key) and dev warns once per key and
96
- * owner. Why not silent: `({ state }) => state.boss.dist * 3` before the boss exists left the fog still with no word, and the AI blamed the layers.
97
- */
98
- function evalFn(part, rec, ctx) {
99
- let n, bad;
100
- try { n = live(rec.fn, ctx); if (!Number.isFinite(n)) bad = `returned ${typeof n === 'number' ? String(n) : n === undefined ? 'undefined' : JSON.stringify(n) ?? String(n)}`; }
101
- catch (err) { bad = `threw "${err?.message ?? err}"`; }
102
- if (bad === undefined) return n;
103
- rec.errors = (rec.errors ?? 0) + 1; rec.lastError = bad;
104
- if (DEV) warnOnce(coded('look-fn', `${part.id}.${rec.key}: the function value set by '${rec.owner}' (layer ${rec.layer}) ${bad}, not a finite number; ` +
105
- 'the key keeps its last good value (describe().look counts it in fnErrors)'), `look-fn\0${part.id}\0${rec.key}\0${rec.owner}`);
106
- return undefined;
107
- }
108
-
109
- /** Put one value for owner on layer. A function on a number key is kept and re-evaluated by tick(ctx); value keys keep the function itself
110
- * (their module evaluates it while applying) */
111
- function put(part, s, k, layer, owner, v) {
112
- const fk = `${k}\0${owner}`;
113
- if (typeof v === 'function' && s.kind === 'number') {
114
- const rec = { key: k, owner, layer, fn: v };
115
- part._fns.set(fk, rec);
116
- // no frame context before the sky's first frame: the first tick evaluates it
117
- const n = part._e._lookCtx ? evalFn(part, rec, part._e._lookCtx) : undefined;
118
- if (n !== undefined) s.take({ owner, layer, set: n });
119
- return;
120
- }
121
- part._fns.delete(fk);
122
- s.take({ owner, layer, set: v });
123
- }
124
-
125
- /** Drop owner's value for key (and a kept function) */
126
- function drop(part, k, owner) { part._fns.delete(`${k}\0${owner}`); part._points.get(k)?.release(owner); }
127
-
128
- /**
129
- * Write owner's keys on layer; null drops a key. All or nothing: if a conflict or the part's apply throws, every key goes back to the entry
130
- * it had and the picture is re-applied (review H1). The handle drops only what this call wrote and still holds (a later write wins).
131
- */
132
- export function writeKeys(part, layer, owner, values) {
133
- const undo = [];
134
- try {
135
- batch(part, () => {
136
- for (const [k, v] of Object.entries(values)) {
137
- const s = pointOf(part, k), old = entryOf(s, owner), oldFn = part._fns.get(`${k}\0${owner}`);
138
- undo.push(() => { drop(part, k, owner); if (oldFn) part._fns.set(`${k}\0${owner}`, oldFn); if (old) s.take({ owner, layer: old.layer, set: old.value }); });
139
- v === null ? drop(part, k, owner) : put(part, s, k, layer, owner, v);
140
- }
141
- });
142
- } catch (err) {
143
- part._hold++;
144
- try { for (const u of undo.reverse()) u(); } finally { part._hold--; part._dirty.clear(); }
145
- try { flush(part, true); } catch { /* the rethrow below is the error that broke it; this one is its echo on the old values */ }
146
- throw err;
147
- }
148
- const wrote = Object.entries(values).filter(([, v]) => v !== null);
149
- // remove() answers whether it dropped anything: false once the owner wrote the key again (a stale handle) or on a second call
150
- return { remove: () => batch(part, () => {
151
- let any = false;
152
- for (const [k, v] of wrote) {
153
- const fn = part._fns.get(`${k}\0${owner}`), e = entryOf(part._points.get(k) ?? { _map() {} }, owner);
154
- if (fn ? fn.fn === v : e && e.value === v && e.layer === layer) { drop(part, k, owner); any = true; }
155
- }
156
- return any;
157
- }) };
158
- }
159
-
160
- /** Every entry owner holds on layer, as { key: value } (DebugOverrides lists and clears the debug layer through it) */
161
- export function ownerValues(part, layer, owner) {
162
- const out = {};
163
- for (const [k, s] of part._points) { const e = entryOf(s, owner); if (e?.layer === layer) out[k] = part._fns.get(`${k}\0${owner}`)?.fn ?? e.value; }
164
- return out;
165
- }
166
-
167
- /** The owners with an entry on layer */
168
- export function ownersOn(part, layer) {
169
- const out = new Set();
170
- for (const s of part._points.values()) for (const e of s._map(undefined)?.values() ?? []) if (e.layer === layer) out.add(e.owner);
171
- return [...out];
172
- }
173
-
174
- /** Drop everything owner wrote on layer; true when it held something */
175
- export function dropOwner(part, layer, owner) {
176
- const keys = Object.keys(ownerValues(part, layer, owner));
177
- if (keys.length) batch(part, () => { for (const k of keys) drop(part, k, owner); });
178
- return keys.length > 0;
179
- }
180
-
181
- /** Replace the style layer (start, or a style swap): owner 'style' on the style layer; a key a driver drives keeps the driver's value */
182
- export function writeStyle(part, given) {
183
- batch(part, () => {
184
- for (const k of part._style.keys()) if (!(k in given)) drop(part, k, 'style');
185
- part._style = new Map(Object.entries(given));
186
- for (const [k, v] of part._style) if (!part._driven.has(k)) put(part, pointOf(part, k), k, 'style', 'style', v);
187
- });
188
- }
189
-
190
- /**
191
- * Drive keys every frame from a style-driven system (the sky's keyframes): while driven, the driver's value sits on the style layer under its
192
- * name and the style's own value steps aside; game / effect / settings / debug entries still apply on top. by null hands them back.
193
- */
194
- export function driveKeys(part, keys, by) {
195
- batch(part, () => {
196
- for (const k of keys) {
197
- const was = part._driven.get(k);
198
- if (by) { part._driven.set(k, by); drop(part, k, 'style'); continue; }
199
- part._driven.delete(k);
200
- if (was) drop(part, k, was);
201
- if (part._style.has(k)) put(part, pointOf(part, k), k, 'style', 'style', part._style.get(k));
202
- }
203
- });
204
- }
205
-
206
- /** Re-evaluate every function value on a number key with this frame's context (the sky calls it once per frame) */
207
- export function tick(part, ctx) {
208
- if (!part._fns.size) return;
209
- batch(part, () => {
210
- for (const rec of part._fns.values()) {
211
- const n = evalFn(part, rec, ctx);
212
- if (n !== undefined) part._points.get(rec.key)?.take({ owner: rec.owner, layer: rec.layer, set: n });
213
- }
214
- });
215
- }
216
-
217
- /** Where a key's value comes from, from its point's describe row: { value, owner, layer, at, under } (report.js, look.lights env) */
218
- export function sourceOf(part, key) {
219
- const s = part._points.get(key);
220
- if (!s) return null;
221
- const r = s.row();
222
- if (r.writer === 'default' && !(key in part._params)) return null;
223
- const top = r.writer === 'default' ? { owner: 'engine', layer: 'engine', at: null } : { owner: r.writer, layer: r.layer ?? 'engine', at: r.at ?? null };
224
- return { ...top, value: valueOf(part, key), driver: part._driven.get(key) ?? null, how: r.how,
225
- under: r.also.filter(h => h.hidden).map(h => ({ owner: h.owner, layer: h.layer, at: h.at ?? null, value: h.value })) };
226
- }
227
-
228
- /** Remove every key starting with prefix, with every entry on it (LookPart.retract) */
229
- export function retractKeys(part, prefix) {
230
- part._hold++;
231
- try {
232
- for (const [k, s] of [...part._points]) if (k.startsWith(prefix)) {
233
- s.onChange = null; s.clear();
234
- for (const fk of [...part._fns.keys()]) if (fk.startsWith(k + '\0')) part._fns.delete(fk);
235
- part._points.delete(k); part._style.delete(k); part._driven.delete(k); part._resolved.delete(k);
236
- delete part._params[k]; delete part._meta[k];
237
- }
238
- } finally { part._hold--; part._dirty.clear(); }
239
- }
240
-
241
- /** A module went away (dispose, or engine.use rolled it back): drop the parts it registered and release the keys it drives (review M9) */
242
- export function disposeLooksOf(e, name) {
243
- if (!name) return;
244
- for (const p of Object.values(e.look ?? {})) {
245
- if (p._spec.module === name) { p.author.remove(); continue; }
246
- const mine = [...p._driven].filter(([, by]) => by === name).map(([k]) => k);
247
- if (mine.length) p.author.drive(mine, null);
248
- }
249
- }
250
-
251
- /** Recompute without calling apply: a key added later describes the object its owner just made, its default must not be pushed onto it */
252
- export function quietRefresh(part) {
253
- const was = part._started; part._started = false;
254
- try { flush(part, true); } finally { part._started = was; }
255
- }
@@ -1,96 +0,0 @@
1
- // describe().look, catalog('look.*').
2
- // Both read the same layer records (part.js), so "who set this"
3
- // in describe and "what can I set" in the catalog cannot disagree. Values set straight on the three.js object (renderer.toneMappingExposure = 2)
4
- // show up as writer: 'three': the part's read() returns the live value and it no longer matches what the layers say.
5
- // One field answers "who set it": `writer`, the same name describe().owned and describe().render use, so a tool reads one key everywhere.
6
- // It is the look layer that set the value ('style', 'game', 'game:cave', 'debug:probe'), unless something else writes the property now: then that
7
- // writer wins ('three' for a direct three.js write, 'manual:game' / 'three (engine yielded)' from describe().owned), because that is what is on screen.
8
- import { schemaInfo } from '../params.js';
9
- import { rv } from '../math.js';
10
- import { ownedOf } from '../owned.js';
11
- import { stylePackOf } from '../styleParts.js';
12
-
13
- const shown = v => (typeof v === 'number' ? rv(v) : typeof v === 'function' ? '<function>' : Array.isArray(v) && v.length > 4 ? `<array of ${v.length}>` : v?.isObject3D || v?.isTexture || v?.isMaterial ? `<${v.type}>` : v);
14
- /**
15
- * Same value for the 'three' check: numbers within a small tolerance, arrays / Colors / vectors element by element. Why: the live read
16
- * (a Color, a Vector2) is a different object from the layer value ([0.012, 0.006], '#fff'), and !== tagged it 'three' (review L5)
17
- */
18
- function same(a, b) {
19
- if (a === b) return true;
20
- if (typeof a === 'number' && typeof b === 'number') return Math.abs(a - b) <= 1e-6 * Math.max(1, Math.abs(a), Math.abs(b));
21
- const arr = v => (Array.isArray(v) ? v : v?.isColor ? [v.r, v.g, v.b] : typeof v?.toArray === 'function' ? v.toArray() : null);
22
- const x = arr(a), y = arr(b);
23
- if (x && y) return x.length === y.length && x.every((v, i) => same(v, y[i]));
24
- const c = a?.isColor ? a : b?.isColor ? b : null, other = c === a ? b : a;
25
- // 'horizon' and the like are not colors: three would warn
26
- if (c && (typeof other === 'number' || /^(#|rgb|hsl)/i.test(other ?? ''))) return c.clone().set(other).equals(c);
27
- return false;
28
- }
29
- /** A layer as a writer name: 'game' | 'style' | 'engine' | 'settings' (owner named like its layer) | '<layer>:<owner>' (owner as given to set / debug.override) */
30
- const tag = (s) => s.owner === s.layer || s.layer === 'style' || s.layer === 'engine' ? s.layer : `${s.layer}:${s.owner}`;
31
-
32
- /** One part's keys: { key: { value, writer, at?, under? } }; under lists the layers this value covers (top first) */
33
- function partInfo(p) {
34
- const live = p._spec.read?.() ?? {}, out = {}, owned = ownedOf(p._e, p._spec.id);
35
- for (const k of p._keys()) {
36
- const s = p._source(k);
37
- if (!s) continue;
38
- const o = { value: shown(s.value), writer: tag(s) };
39
- // a driver (the sky) writes it every frame from the layered value: the live value is what is on screen, whoever is on top (a debug override
40
- // shows on the next frame; while paused the live value is the last one drawn)
41
- if (s.driver) Object.assign(o, { value: shown(live[k]), driver: s.driver });
42
- else if (k in live && live[k] !== undefined && !same(live[k], s.value)) Object.assign(o, { value: shown(live[k]), writer: 'three' });
43
- if (s.at) o.at = s.at;
44
- // several packs merged into the style: name the one this value came from (styleParts.js records the source per path while merging)
45
- if (s.layer === 'style' && !s.driver && o.writer === 'style') { const pack = stylePackOf(p._e.style, k, s.value); if (pack) o.pack = pack; }
46
- if (s.layer === 'engine' && o.writer === 'engine' && p._meta[k]?.device) o.why = p._meta[k].device; // the engine chose this for the device (layers.js LOOK_FIELDS)
47
- if (s.under.length && s.layer !== 'engine') o.under = s.under.map(tag);
48
- // who writes it now (core/owned.js) when the engine yielded it: the owned row's name wins over the plain 'three' guess (yielded / manual:<who>)
49
- const w = owned.find(x => !x.on && (x.key === k || k.startsWith(x.key + '.')));
50
- if (w) o.writer = w.info().writer;
51
- // a function value that threw or gave a non-number (points.js evalFn): how many evaluations failed, and the last reason; the value is the last good one
52
- for (const f of p._fns.values()) if (f.key === k && f.errors) { o.fnErrors = (o.fnErrors ?? 0) + f.errors; o.fnError = `${f.owner}: ${f.lastError}`; }
53
- out[k] = o;
54
- }
55
- return Object.assign(out, p._spec.info?.()); // read-only rows that are not params (look.env source), same { value, writer } shape
56
- }
57
-
58
- /** describe().look: { <part>: { key: { value, writer } }, text } (undefined when no part is registered) @param {any} e */
59
- export function describeLook(e) {
60
- const parts = Object.values(e.look ?? {});
61
- if (!parts.length) return undefined;
62
- const out = {}, lines = [];
63
- for (const p of parts) {
64
- const info = out[p._spec.id] = partInfo(p);
65
- lines.push(`${p._spec.id}${p._spec.appliesTo ? ` (applies to ${p._spec.appliesTo})` : ''}:${Object.entries(info).map(([k, v]) => `${k}=${typeof v.value === 'object' && v.value ? JSON.stringify(v.value) : v.value} (${v.writer})`).join(' ')}`);
66
- }
67
- return { ...out, text: lines.join('\n') };
68
- }
69
-
70
- /** One part as catalog data: params (schema + why / off / cost + value in use and its source), hooks, replace contract, verbs */
71
- function lookEntry(e, p) {
72
- const s = p._spec, schema = schemaInfo(p._params), info = partInfo(p);
73
- for (const k in schema) {
74
- const m = p._meta[k];
75
- for (const f of ['why', 'off', 'cost']) if (m[f] !== undefined) schema[k][f] = m[f];
76
- if (m.neutral) schema[k].neutral = true;
77
- if (info[k]) Object.assign(schema[k], { value: info[k].value, writer: info[k].writer });
78
- }
79
- return { id: p.id, kind: 'look', group: s.group ?? null, module: s.module ?? 'core', verbs: verbsOf(p), signatures: p.author.signatures, params: schema,
80
- ...(s.appliesTo ? { appliesTo: s.appliesTo } : {}),
81
- hooks: s.hooks ?? null, replace: s.replace ?? null, ...(s.docs ? { docs: s.docs } : {}), problems: [] };
82
- }
83
- // the verbs a part has: the keys of its signatures, so the catalog's verb list and its call shapes come from one place
84
- const verbsOf = p => Object.keys(p.author.signatures);
85
-
86
- /** Short list rows for engine.catalog() (same row shape as modules: ops / saves stay empty) @param {any} e */
87
- export function lookSummaries(e) {
88
- return Object.values(e.look ?? {}).map(p => ({ id: p.id, kind: 'look', group: p._spec.group ?? null, module: p._spec.module ?? 'core', verbs: verbsOf(p), ops: [], saves: [] }));
89
- }
90
-
91
- /** engine.catalog('look') -> every part expanded; 'look.<part>' -> that part; else null @param {any} e @param {string} id */
92
- export function lookCatalog(e, id) {
93
- if (id === 'look') return Object.values(e.look ?? {}).map(p => lookEntry(e, p));
94
- const p = e.look?.[id.slice(5)];
95
- return p ? lookEntry(e, p) : null;
96
- }