threedog 0.2.1 → 0.5.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 (593) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +71 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +183 -59
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +37 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +14 -13
  58. package/core/gridLoad.js +2 -1
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +100 -41
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +63 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +87 -100
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +220 -147
  126. package/docs/COMMANDS.md +56 -35
  127. package/docs/CONVENTIONS.md +90 -28
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +11 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +38 -23
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +63 -60
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +28 -26
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +29 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +11 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +48 -34
  180. package/docs/recipes/02-npc.md +24 -7
  181. package/docs/recipes/03-items-pickups.md +35 -21
  182. package/docs/recipes/04-quests.md +12 -5
  183. package/docs/recipes/05-props-bake.md +151 -15
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +40 -9
  186. package/docs/recipes/08-weather-sky.md +145 -36
  187. package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +14 -6
  191. package/docs/recipes/14-custom-module.md +61 -29
  192. package/docs/recipes/15-perf.md +30 -9
  193. package/docs/recipes/16-dev-bridge.md +61 -37
  194. package/docs/recipes/18-world.md +16 -6
  195. package/docs/recipes/19-shooting-picking.md +6 -6
  196. package/docs/recipes/20-content-actions-save.md +55 -17
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +3 -3
  199. package/docs/recipes/23-ops.md +16 -10
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +11 -5
  202. package/docs/recipes/28-terrain.md +34 -1
  203. package/docs/recipes/29-grid.md +34 -16
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +26 -3
  208. package/docs/recipes/35-style-from-reference.md +88 -19
  209. package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
  210. package/docs/recipes/37-terrain-look-hooks.md +3 -2
  211. package/docs/recipes/38-environment-look-hooks.md +37 -26
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
  216. package/docs/recipes/44-water-weather-look-hooks.md +26 -17
  217. package/docs/recipes/45-cascaded-shadows.md +16 -7
  218. package/docs/recipes/47-island-snow-backdrop.md +7 -7
  219. package/docs/recipes/48-make-material.md +11 -6
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +2 -2
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-look.md +197 -61
  224. package/docs/recipes/53-ground-up-close.md +1 -1
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +112 -0
  227. package/docs/recipes/56-webgpu-tsl.md +260 -0
  228. package/docs/recipes/57-control.md +65 -0
  229. package/docs/recipes/58-input.md +57 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +55 -0
  232. package/examples/action/.threedog/content-index.json +1 -0
  233. package/examples/action/GAMEMAP.md +17 -13
  234. package/examples/action/assets.js +8 -0
  235. package/examples/action/content/actions.js +1 -1
  236. package/examples/action/content/audio.js +5 -5
  237. package/examples/action/look.js +1 -1
  238. package/examples/action/main.js +10 -14
  239. package/examples/action/models.js +24 -23
  240. package/examples/pullable.json +111 -0
  241. package/examples/rc2d/.threedog/content-index.json +1 -0
  242. package/examples/rc2d/GAMEMAP.md +83 -0
  243. package/examples/rc2d/README.md +52 -0
  244. package/examples/rc2d/main.js +63 -0
  245. package/examples/rc2d/rc2d.js +197 -0
  246. package/examples/rc2d/shaders.js +144 -0
  247. package/examples/sheepisland/.threedog/content-index.json +1 -0
  248. package/examples/sheepisland/GAMEMAP.md +13 -11
  249. package/examples/sheepisland/assets.js +5 -0
  250. package/examples/sheepisland/main.js +17 -12
  251. package/examples/sheepisland/style/index.js +6 -6
  252. package/examples/styletest/.threedog/content-index.json +1 -0
  253. package/examples/styletest/GAMEMAP.md +15 -16
  254. package/examples/styletest/assets.js +6 -0
  255. package/examples/styletest/content/templates.js +1 -1
  256. package/examples/styletest/content/vegetation.js +1 -1
  257. package/examples/styletest/look.js +1 -1
  258. package/examples/styletest/main.js +17 -16
  259. package/examples/styletest/models.js +1 -1
  260. package/examples/styletest/params.js +3 -3
  261. package/examples/techniques/contact-shadows/README.md +92 -0
  262. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  263. package/examples/techniques/contact-shadows/main.js +53 -0
  264. package/examples/techniques/day-night-grade/README.md +86 -0
  265. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  266. package/examples/techniques/day-night-grade/main.js +51 -0
  267. package/examples/techniques/interior-light/README.md +103 -0
  268. package/examples/techniques/interior-light/interiorLight.js +45 -0
  269. package/examples/techniques/interior-light/main.js +124 -0
  270. package/examples/techniques/modular-building/README.md +125 -0
  271. package/examples/techniques/modular-building/kit.js +426 -0
  272. package/examples/techniques/modular-building/main.js +47 -0
  273. package/examples/techniques/night-lights/README.md +94 -0
  274. package/examples/techniques/night-lights/main.js +70 -0
  275. package/examples/techniques/night-lights/nightLights.js +91 -0
  276. package/examples/techniques/outlines-and-rim/README.md +59 -0
  277. package/examples/techniques/outlines-and-rim/main.js +84 -0
  278. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  279. package/examples/techniques/procedural-animation/README.md +77 -0
  280. package/examples/techniques/procedural-animation/creature.js +44 -0
  281. package/examples/techniques/procedural-animation/main.js +45 -0
  282. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  283. package/examples/techniques/procedural-surface/README.md +67 -0
  284. package/examples/techniques/procedural-surface/main.js +103 -0
  285. package/examples/techniques/procedural-surface/surface.js +120 -0
  286. package/examples/techniques/stylized-shading/README.md +75 -0
  287. package/examples/techniques/stylized-shading/main.js +93 -0
  288. package/examples/techniques/stylized-shading/shading.js +131 -0
  289. package/examples/techniques/sun-and-key-light/README.md +135 -0
  290. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  291. package/examples/techniques/sun-and-key-light/main.js +95 -0
  292. package/examples/techniques/wet-road/README.md +99 -0
  293. package/examples/techniques/wet-road/main.js +68 -0
  294. package/examples/techniques/wet-road/wetRoad.js +209 -0
  295. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  296. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  297. package/examples/webgpu-tsl/README.md +42 -0
  298. package/examples/webgpu-tsl/main.js +21 -0
  299. package/examples/webgpu-tsl/tslScene.js +75 -0
  300. package/examples/world/.threedog/content-index.json +1 -0
  301. package/examples/world/GAMEMAP.md +22 -15
  302. package/examples/world/art/humanoid.js +42 -0
  303. package/examples/world/art/index.js +11 -0
  304. package/examples/world/art/models.js +58 -0
  305. package/examples/world/art/shapes.js +9 -0
  306. package/examples/world/assets.js +6 -0
  307. package/examples/world/content/audio.js +5 -5
  308. package/examples/world/content/npcs.js +1 -1
  309. package/examples/world/content/props.js +1 -1
  310. package/examples/world/content/rules.js +1 -1
  311. package/examples/world/content/templates.js +1 -1
  312. package/examples/world/content/vegetation.js +1 -1
  313. package/examples/world/main.js +17 -13
  314. package/examples/world/style/index.js +61 -0
  315. package/examples/world/style/plugins/10-bloom.js +5 -0
  316. package/index.d.ts +44 -45
  317. package/index.js +26 -22
  318. package/llms.txt +11 -4
  319. package/modules/ambience/Ambience.js +34 -23
  320. package/modules/calendar/Calendar.js +163 -0
  321. package/modules/calendar/contract.js +21 -0
  322. package/modules/calendar/index.js +81 -0
  323. package/modules/{sky → calendar}/schedule.js +17 -16
  324. package/modules/calendar/seasons.js +55 -0
  325. package/modules/camera/FirstPersonCamera.js +6 -15
  326. package/modules/camera/FixedCamera.js +33 -15
  327. package/modules/camera/FollowCamera.js +90 -16
  328. package/modules/camera/RtsCamera.js +18 -17
  329. package/modules/camera/common.js +70 -19
  330. package/modules/camera/contract.js +17 -0
  331. package/modules/camera/projection.js +11 -24
  332. package/modules/characters/Character.js +177 -42
  333. package/modules/characters/NPC.js +87 -36
  334. package/modules/characters/assetModel.js +4 -13
  335. package/modules/characters/behaviors.js +2 -1
  336. package/modules/characters/contract.js +13 -0
  337. package/modules/characters/footsteps.js +1 -1
  338. package/modules/characters/index.js +87 -49
  339. package/modules/characters/moveHelpers.js +4 -5
  340. package/modules/characters/movers/common.js +97 -19
  341. package/modules/characters/movers/manual.js +20 -0
  342. package/modules/characters/movers/rapier.js +19 -16
  343. package/modules/characters/movers/simple.js +14 -11
  344. package/modules/characters/movers/support.js +172 -0
  345. package/modules/characters/npcAvoid.js +47 -42
  346. package/modules/characters/npcSim.js +12 -8
  347. package/modules/characters/npcView.js +44 -16
  348. package/modules/characters/pathAsync.js +7 -3
  349. package/modules/characters/playerStrings.js +4 -3
  350. package/modules/characters/proceduralRig.js +2 -1
  351. package/modules/characters/useModel.js +1 -1
  352. package/modules/characters/vehicle.contract.js +21 -0
  353. package/modules/characters/walkTo.js +21 -7
  354. package/modules/collision/Collision.js +65 -25
  355. package/modules/collision/grid.js +8 -6
  356. package/modules/content/explain.js +2 -2
  357. package/modules/content/fields.js +102 -0
  358. package/modules/content/ids.js +8 -6
  359. package/modules/content/index.js +96 -27
  360. package/modules/content/loader.js +45 -33
  361. package/modules/content/models.js +11 -40
  362. package/modules/content/packs.js +6 -5
  363. package/modules/content/parts.js +41 -0
  364. package/modules/content/props.js +16 -9
  365. package/modules/content/rules.js +58 -0
  366. package/modules/content/stages.js +80 -0
  367. package/modules/content/templates.js +121 -30
  368. package/modules/debug/DebugPanel.js +24 -17
  369. package/modules/flow/contract.js +16 -0
  370. package/modules/flow/index.js +21 -15
  371. package/modules/gameplay/Container.js +41 -32
  372. package/modules/gameplay/Containers.js +30 -15
  373. package/modules/gameplay/Dialogue.js +113 -55
  374. package/modules/gameplay/Interactions.js +193 -67
  375. package/modules/gameplay/Inventory.js +69 -73
  376. package/modules/gameplay/Quests.js +75 -39
  377. package/modules/gameplay/boxOps.js +3 -3
  378. package/modules/gameplay/dialogue.contract.js +21 -0
  379. package/modules/gameplay/dialogueBox.js +4 -2
  380. package/modules/gameplay/dialogueBubbles.js +116 -0
  381. package/modules/gameplay/interactionPrompt.js +4 -1
  382. package/modules/gameplay/interactions.contract.js +16 -0
  383. package/modules/gameplay/inventory.contract.js +23 -0
  384. package/modules/gameplay/inventoryOps.js +18 -16
  385. package/modules/gameplay/pickups.js +268 -85
  386. package/modules/gameplay/questLog.js +4 -4
  387. package/modules/gameplay/quests.contract.js +17 -0
  388. package/modules/grid/Grid.js +92 -50
  389. package/modules/grid/Layer.js +14 -13
  390. package/modules/grid/index.js +60 -36
  391. package/modules/grid/ops.js +20 -18
  392. package/modules/grid/preview.js +15 -16
  393. package/modules/grid/strings.js +12 -0
  394. package/modules/grid/tiles.js +6 -5
  395. package/modules/hlod/index.js +51 -19
  396. package/modules/hud/index.js +35 -20
  397. package/modules/hud/parts.js +20 -7
  398. package/modules/level/heightfield.js +3 -1
  399. package/modules/level/index.js +45 -20
  400. package/modules/level/nodes.js +4 -3
  401. package/modules/lights/index.js +42 -18
  402. package/modules/music/Music.js +38 -21
  403. package/modules/music/rules.js +1 -1
  404. package/modules/nav/index.js +48 -42
  405. package/modules/net/Client.js +13 -6
  406. package/modules/net/Host.js +19 -5
  407. package/modules/net/Net.js +2 -1
  408. package/modules/net/index.js +13 -8
  409. package/modules/net/sync.js +9 -8
  410. package/modules/net/transports.js +77 -27
  411. package/modules/particles/Particles.js +23 -14
  412. package/modules/particles/contract.js +17 -0
  413. package/modules/particles/effect.js +39 -11
  414. package/modules/photo/Photo.js +53 -36
  415. package/modules/rigid/RigidBodies.js +194 -32
  416. package/modules/rigid/Vehicles.js +18 -15
  417. package/modules/rigid/sync.js +62 -17
  418. package/modules/settings/Settings.js +57 -52
  419. package/modules/settings/apply.js +38 -3
  420. package/modules/settings/sections.js +5 -3
  421. package/modules/settings/strings.js +3 -2
  422. package/modules/settings/view.js +5 -3
  423. package/modules/sky/Sky.js +88 -176
  424. package/modules/sky/cascades.js +86 -25
  425. package/modules/sky/cascades.tsl.js +82 -0
  426. package/modules/sky/clouds.js +34 -19
  427. package/modules/sky/domeLayers.js +30 -15
  428. package/modules/sky/environment.js +83 -13
  429. package/modules/sky/fog.js +140 -95
  430. package/modules/sky/frame.js +112 -44
  431. package/modules/sky/look.js +22 -19
  432. package/modules/sky/lookFog.js +48 -52
  433. package/modules/sky/lookShadow.js +53 -41
  434. package/modules/sky/lookSky.js +82 -21
  435. package/modules/sky/season.js +21 -0
  436. package/modules/sky/shader.js +41 -19
  437. package/modules/sky/shadow.js +44 -20
  438. package/modules/sky/skyModule.js +45 -33
  439. package/modules/sky/tint.js +61 -0
  440. package/modules/terrain/ChunkManager.js +175 -108
  441. package/modules/terrain/chunkJob.js +1 -1
  442. package/modules/terrain/chunkQueries.js +6 -4
  443. package/modules/terrain/index.js +105 -50
  444. package/modules/terrain/look.js +83 -0
  445. package/modules/terrain/lookGround.js +21 -16
  446. package/modules/terrain/terrainDefaults.js +1 -1
  447. package/modules/terrain/terrainEdit.js +18 -20
  448. package/modules/terrain/terrainGen.js +5 -3
  449. package/modules/terrain/terrainIsland.js +5 -4
  450. package/modules/terrain/terrainShape.js +12 -12
  451. package/modules/terrain/terrainShapeMain.js +8 -7
  452. package/modules/terrain/terrainTexture.js +21 -19
  453. package/modules/timeline/Timeline.js +95 -43
  454. package/modules/timeline/Tween.js +18 -10
  455. package/modules/timeline/letterbox.js +2 -2
  456. package/modules/timeline/shots.js +5 -1
  457. package/modules/triggers/index.js +107 -76
  458. package/modules/vegetation/Vegetation.js +186 -110
  459. package/modules/vegetation/densityMap.js +62 -0
  460. package/modules/vegetation/groundChunks.js +52 -58
  461. package/modules/vegetation/index.js +32 -11
  462. package/modules/vegetation/look.js +119 -0
  463. package/modules/vegetation/lookWind.js +71 -10
  464. package/modules/vegetation/modelGeometry.js +3 -2
  465. package/modules/vegetation/nearFade.js +8 -2
  466. package/modules/water/Water.js +65 -27
  467. package/modules/water/look.js +29 -18
  468. package/modules/water/surface.js +64 -25
  469. package/modules/water/surfaceDefaults.js +3 -0
  470. package/modules/weather/Weather.js +62 -104
  471. package/modules/weather/look.js +1 -2
  472. package/modules/weather/particles.js +24 -9
  473. package/modules/weather/strings.js +2 -2
  474. package/modules/weather/weatherLook.js +135 -0
  475. package/modules/world/World.js +24 -7
  476. package/modules/world/explain.js +1 -1
  477. package/modules/world/index.js +18 -4
  478. package/modules/world/persist.js +62 -2
  479. package/modules/world/pos.js +3 -2
  480. package/modules/world/records.js +8 -6
  481. package/modules/world/sim.js +60 -20
  482. package/modules/world/simFar.js +4 -3
  483. package/modules/world/state.js +3 -2
  484. package/modules/world/thingSource.js +1 -1
  485. package/modules/world/views.js +7 -5
  486. package/package.json +7 -3
  487. package/presets.js +41 -27
  488. package/render/PostFX.js +145 -120
  489. package/render/backend.js +440 -0
  490. package/render/detail.js +120 -39
  491. package/render/effects.js +130 -38
  492. package/render/engineUniforms.js +10 -1
  493. package/render/fuse.js +5 -4
  494. package/render/fx/cloudShadow.tsl.js +16 -0
  495. package/render/fx/detail.tsl.js +66 -0
  496. package/render/fx/index.js +26 -0
  497. package/render/fx/lighting.tsl.js +28 -0
  498. package/render/fx/nodeErrors.tsl.js +68 -0
  499. package/render/fx/noise.tsl.js +12 -0
  500. package/render/fx/objectOrigin.tsl.js +42 -0
  501. package/render/fx/particles.tsl.js +139 -0
  502. package/render/fx/patchNodes.tsl.js +403 -0
  503. package/render/fx/postWebGPU.tsl.js +158 -0
  504. package/render/fx/season.tsl.js +13 -0
  505. package/render/fx/sky.tsl.js +260 -0
  506. package/render/fx/uniforms.tsl.js +67 -0
  507. package/render/fx/water.tsl.js +53 -0
  508. package/render/fx/wind.tsl.js +22 -0
  509. package/render/fxNumbers.js +36 -0
  510. package/render/hotGlsl.js +24 -0
  511. package/render/lighting.js +66 -14
  512. package/render/lights.js +223 -4
  513. package/render/lookGlow.js +139 -0
  514. package/render/lookSurface.js +99 -36
  515. package/render/materials.js +71 -52
  516. package/render/modeling.js +73 -0
  517. package/render/ownFrame.js +76 -0
  518. package/render/patches.js +311 -34
  519. package/render/postLook.js +124 -46
  520. package/render/postWebGL.js +197 -0
  521. package/render/probes.js +231 -0
  522. package/render/shaderErrors.js +154 -0
  523. package/render/slots.js +165 -0
  524. package/render/surface.js +53 -17
  525. package/render/terms.js +211 -0
  526. package/render/uniformDecl.js +3 -2
  527. package/types/common.d.ts +2 -2
  528. package/types/core.d.ts +614 -240
  529. package/types/gameplay.d.ts +482 -312
  530. package/types/generated/core/Audio.d.ts +26 -42
  531. package/types/generated/core/Batching.d.ts +6 -2
  532. package/types/generated/core/Budget.d.ts +2 -8
  533. package/types/generated/core/DebugOverrides.d.ts +44 -3
  534. package/types/generated/core/I18n.d.ts +2 -2
  535. package/types/generated/core/Input.d.ts +102 -31
  536. package/types/generated/core/Ops.d.ts +31 -0
  537. package/types/generated/core/Random.d.ts +2 -2
  538. package/types/generated/core/Saves.d.ts +10 -2
  539. package/types/generated/core/Stream.d.ts +1 -1
  540. package/types/generated/core/Threads.d.ts +4 -1
  541. package/types/generated/core/Views.d.ts +0 -1
  542. package/types/generated/core/audioVoice.d.ts +17 -9
  543. package/types/generated/core/control.d.ts +55 -0
  544. package/types/generated/core/session.d.ts +2 -1
  545. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  546. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  547. package/types/generated/modules/calendar/index.d.ts +10 -0
  548. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  549. package/types/generated/modules/grid/Grid.d.ts +61 -25
  550. package/types/generated/modules/grid/Layer.d.ts +5 -5
  551. package/types/generated/modules/grid/index.d.ts +29 -17
  552. package/types/generated/modules/music/Music.d.ts +5 -3
  553. package/types/generated/modules/net/index.d.ts +3 -3
  554. package/types/generated/modules/net/transports.d.ts +12 -3
  555. package/types/generated/modules/particles/Particles.d.ts +1 -1
  556. package/types/generated/modules/sky/Sky.d.ts +12 -104
  557. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  558. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  559. package/types/generated/modules/weather/Weather.d.ts +17 -18
  560. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  561. package/types/generated/modules/world/World.d.ts +18 -3
  562. package/types/generated/render/PostFX.d.ts +67 -30
  563. package/types/generated/render/materials.d.ts +26 -20
  564. package/types/generated/render/modeling.d.ts +30 -0
  565. package/types/generated/render/patches.d.ts +16 -2
  566. package/types/generated/ui/UI.d.ts +6 -3
  567. package/types/nav.d.ts +6 -0
  568. package/types/physics.d.ts +137 -44
  569. package/types/style.d.ts +109 -81
  570. package/types/tsl.d.ts +86 -0
  571. package/types/world.d.ts +158 -110
  572. package/ui/Focus.js +25 -14
  573. package/ui/LoadingScreen.js +1 -1
  574. package/ui/Parts.js +27 -11
  575. package/ui/UI.js +20 -10
  576. package/ui/cursor.js +115 -0
  577. package/ui/defaults.js +15 -11
  578. package/ui/theme.js +9 -6
  579. package/ui/touchPart.js +1 -1
  580. package/core/claims.js +0 -51
  581. package/core/look/layers.js +0 -136
  582. package/core/renamed.js +0 -22
  583. package/docs/api/entities.md +0 -61
  584. package/examples/styletest/overrides.js +0 -33
  585. package/examples/styletest/panel.js +0 -135
  586. package/modules/entities/Entities.js +0 -243
  587. package/modules/entities/build.js +0 -25
  588. package/modules/entities/index.js +0 -4
  589. package/modules/sky/calendar.js +0 -80
  590. package/modules/sky/layers.js +0 -69
  591. package/modules/terrain/chunkLevels.js +0 -40
  592. package/modules/terrain/mountTerrain.js +0 -32
  593. package/modules/world/cells.js +0 -42
@@ -1,27 +1,45 @@
1
1
  // Sky fog (helper of Sky.js): style.sky.fog / sky({ fog }) picks the fog model and color; the sky drives it every frame.
2
2
  // kind 'linear' (default, three.js Fog: near = 0.3 x far) | 'exp' | 'exp2' (three.js FogExp2) | 'height' (thick low, thin high)
3
- // color 'horizon' (default: the dome's horizon color, so distant ground melts into the sky) | a color | (sky) => color
4
- // density per meter for exp / exp2 / height (default: derived from engine.fogFar, so the fog reaches the same distance as linear)
3
+ // color 'horizon' (default: the dome's horizon color, so distant ground melts into the sky) | a color | ({ time, weather, season, state, sky }) => color
4
+ // color / near / far / density each also take such a function, evaluated every frame (core/look/state.js)
5
+ // density per meter for exp / exp2 / height (default: derived from look.fog far, so the fog reaches the same distance as linear)
5
6
  // height / falloff 'height' only: the fog's floor (world y) and how fast it thins above it (per meter)
6
- // glsl replace the fog math in every material: `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returns
7
- // (fog rgb, amount 0..1). In scope: fogColor, cameraPosition, fogNear / fogFar (linear) or fogDensity (the other kinds),
8
- // THREEDOG_FOG_HEIGHT / THREEDOG_FOG_FALLOFF. No custom uniforms: three copies fog uniforms into each material when it
9
- // compiles, so a live value would need every material patched; write constants in the GLSL instead.
10
- // How: 'linear' / 'exp2' without glsl are three's own fog, untouched (the default draws exactly what it always drew). 'exp', 'height'
11
- // and glsl replace three's fog_* shader chunks (ShaderChunk is shared by every material, including other packages' and the game's own),
12
- // once at install: three caches programs by material settings, not by source, so the chunks cannot change mid-play; density and color
13
- // stay live. The replacement keeps three's code for materials that compile under the other fog object. The chunks are shared by the
14
- // page, so two engines may use the same custom setting (reference counted) but a different one throws; the originals return when the
15
- // last engine using them is disposed.
16
- // sky({ fog: true | 'manual' | false }) (look.js) says who owns scene.fog: the sky (default), the game (the sky never writes it), or nobody (null).
7
+ // Your own fog math is the look hook, never a style key: engine.look.fog.patch('fog', glsl) with
8
+ // `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returning (fog rgb, amount 0..1). In scope: fogColor, cameraPosition, fogNear / fogFar
9
+ // (linear) or fogDensity (the other kinds), THREEDOG_FOG_HEIGHT / THREEDOG_FOG_FALLOFF. No custom uniforms: write constants in the GLSL.
10
+ // WebGPURenderer draws the hook's tsl form instead ({ glsl, tsl }; render/fx/sky.tsl.js): tsl: (ctx) => vec4 node (fog rgb, amount), ctx = { color,
11
+ // depth, worldPos (the same arguments as nodes), cameraPosition, density, near, far, height, falloff, fog (what the kind alone draws, the value
12
+ // so far), fx, tsl }. Each renderer needs its own form; a missing one throws by name.
13
+ // How: 'linear' / 'exp2' without a hook are three's own fog, untouched (the default draws exactly what it always drew). 'exp', 'height' and the
14
+ // hook are one named shader patch, 'fog', on the semantic slots fogPars / fog (render/slots.js), put on each material in this engine's scene
15
+ // (fogMaterials below). Why per material and not THREE.ShaderChunk.fog_*: the chunks are one object per page, so a rewrite reached every
16
+ // engine and every package, and two engines with different fog could not share a page (it used to throw). A patch lives on the material, its
17
+ // cacheKey follows the code, so two engines with different fog both draw right; changing the fog later recompiles the patched materials.
18
+ // Like the cascades' csm patch (cascades.js), this reaches the game's own built-in materials too: three's fog under a FogExp2 object would draw
19
+ // exp2 instead of the asked kind, a wrong picture, not a neutral one. describe().owned row 'fog.patch' lists the game materials it went on.
20
+ // A ShaderMaterial (fog: true) is the game's own code and keeps three's fog; so do Sprite materials (no world position varying there).
21
+ // Who writes scene.fog: sky({ fog: true | false }) (look.js) and look.fog.manual() / replace() (lookFog.js), one owned record (frame.js).
17
22
  import * as THREE from 'three';
18
- import { checkOptions, closest } from '../../core/validate.js';
23
+ import { closest } from '../../core/validate.js';
24
+ import { readParams, keysSchema } from '../../core/params.js';
25
+ import { live } from '../../core/look/state.js';
26
+ import { patchMaterial, unpatchMaterial, isEngineMade } from '../../render/patches.js';
27
+ import { hashText } from '../../render/effects.js';
28
+ import { sceneVisitor } from '../../core/sceneDelta.js';
29
+ import { codedError } from '../../core/errorHints.js';
30
+ import { fogFarOf } from '../../core/sceneMethods.js';
31
+ import { skyNodes } from './shader.js';
32
+
33
+ /** A start distance for the fog object: a function far is evaluated per frame (updateFog), so the object starts at the distance in effect */
34
+ export const startFar = (f, e) => (typeof f.far === 'number' ? f.far : fogFarOf(e));
19
35
 
20
36
  const KINDS = ['linear', 'exp', 'exp2', 'height'];
21
37
  export const FOG_KINDS = KINDS;
22
- const KEYS = ['kind', 'color', 'density', 'height', 'falloff', 'glsl', 'near', 'far', 'enabled']; // near / far / enabled: look.fog (lookFog.js)
23
- const NAMES = ['fog_pars_vertex', 'fog_vertex', 'fog_pars_fragment', 'fog_fragment'];
24
- const ORIGINAL = Object.fromEntries(NAMES.map(n => [n, THREE.ShaderChunk[n]]));
38
+ // Linear fog starts at this fraction of far when look.fog near is not set. One constant, shown in look.fog's catalog (lookFog.js why / off),
39
+ // so the start distance is a visible engine choice instead of a number buried in two places (review 2026-11-03)
40
+ export const FOG_NEAR = 0.3;
41
+ // no 'glsl': custom fog math is look.fog.patch('fog', glsl) only (one injection entry), so style.sky.fog.glsl throws as an unknown key
42
+ const KEYS = ['kind', 'color', 'density', 'height', 'falloff', 'near', 'far', 'enabled']; // near / far / enabled: look.fog (lookFog.js)
25
43
  // fog amount reached at the far distance with the derived density: exp(-3.9) = 2% (exp, height), exp(-1.98^2) = 2% (exp2)
26
44
  const REACH = { exp: 3.9, exp2: 1.98, height: 3.9 };
27
45
  const flt = v => Number.isInteger(v) ? v.toFixed(1) : String(v);
@@ -37,103 +55,130 @@ const FN = {
37
55
  return vec4(color, 1.0 - exp(-fogDensity * dist * k));
38
56
  }`,
39
57
  };
58
+ export const FOG_SIGNATURE = /vec4\s+threedogFog\s*\(/;
40
59
 
41
- /** Check style.sky.fog (+ sky({ fog }) on top) and return the resolved settings; throws with the fix on a bad kind or glsl */
42
- export function resolveFog(spec) {
60
+ /**
61
+ * Check style.sky.fog (+ sky({ fog }) on top) and return the resolved settings; throws with the fix on a bad kind.
62
+ * @param {object} spec the settings @param {string | { glsl?: string, tsl?: Function }} [hook] look.fog's 'hook:fog' value (lookFog.js validated it)
63
+ */
64
+ export function resolveFog(spec, hook) {
43
65
  const s = spec || {};
44
- checkOptions('style.sky.fog', s, KEYS);
66
+ if (s.glsl != null) throw codedError('sky-option', "style.sky.fog.glsl is not an option; your own fog math goes through the look hook: engine.look.fog.patch('fog', glsl) with `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)`");
67
+ readParams('style.sky.fog', keysSchema(KEYS), s);
45
68
  const kind = s.kind ?? 'linear';
46
- if (!KINDS.includes(kind)) throw new Error(`style.sky.fog.kind '${kind}' is not a fog kind; use ${KINDS.map(k => `'${k}'`).join(' | ')}` + (closest(kind, KINDS) ? ` (did you mean '${closest(kind, KINDS)}'?)` : ''));
47
- if (s.glsl != null && (typeof s.glsl !== 'string' || !/vec4\s+threedogFog\s*\(/.test(s.glsl)))
48
- throw new Error('style.sky.fog.glsl must be GLSL that defines `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returning (fog rgb, amount 0..1); see modules/sky/fog.js');
69
+ if (!KINDS.includes(kind)) throw codedError('sky-option', `style.sky.fog.kind '${kind}' is not a fog kind; use ${KINDS.map(k => `'${k}'`).join(' | ')}` + (closest(kind, KINDS) ? ` (did you mean '${closest(kind, KINDS)}'?)` : ''));
49
70
  const color = s.color ?? 'horizon';
71
+ // the hook: GLSL text, or { glsl?, tsl? } (lookFog.js checked the shape); kept whole so each renderer picks its own form
72
+ const h = hook == null ? null : typeof hook === 'string' ? { glsl: hook } : hook;
50
73
  return { kind, color: color === 'horizon' || typeof color === 'function' ? color : new THREE.Color(color), density: s.density ?? null,
51
- height: s.height ?? 0, falloff: s.falloff ?? 0.05, glsl: s.glsl ?? FN[kind] ?? null, near: s.near ?? null, far: s.far ?? null, enabled: s.enabled !== false };
74
+ height: s.height ?? 0, falloff: s.falloff ?? 0.05, glsl: h ? h.glsl ?? null : FN[kind] ?? null, hook: h, near: s.near ?? null, far: s.far ?? null, enabled: s.enabled !== false };
52
75
  }
53
76
 
54
77
  /** The fog object for the kind: density-based kinds use FogExp2 (its fogDensity uniform is live), linear uses Fog */
55
78
  export function makeFog(f, far) {
56
- return f.kind === 'linear' ? new THREE.Fog(0xcccccc, far * 0.3, far) : new THREE.FogExp2(0xcccccc, REACH[f.kind] / far);
79
+ return f.kind === 'linear' ? new THREE.Fog(0xcccccc, far * FOG_NEAR, far) : new THREE.FogExp2(0xcccccc, REACH[f.kind] / far);
57
80
  }
58
81
 
59
- // The chunks are one global per page, so only one custom fog setting can own them at a time. Engines with the same setting share
60
- // them (count); a different setting throws; the originals come back when the last owner is disposed. Plain linear / exp2 never claim.
61
- let held = null; // { key, count }
62
-
63
- /** Install the fog chunks for f (a plain linear / exp2 touches nothing); returns the function that releases them (restores at the last owner) */
64
- export function applyFogChunks(f) {
65
- const C = THREE.ShaderChunk;
66
- if (!f?.glsl) return () => {};
67
- // everything the chunks bake in: kind picks the branch, height / falloff are constants, glsl is the math
68
- const key = JSON.stringify([f.kind, f.height, f.falloff, f.glsl]);
69
- if (held && held.key !== key)
70
- throw new Error(`sky fog: another engine on this page already installed a different custom fog (kind '${held.kind}'); three.js shares the fog shader chunks across the page, so only one custom fog setting can exist at a time. `
71
- + `Use the same style.sky.fog (kind, height, falloff, glsl) in both engines, give only one engine a custom fog (the other keeps 'linear' / 'exp2'), or dispose the first engine before creating this one.`);
72
- if (held) { held.count++; return release(held); }
73
- held = { key, kind: f.kind, count: 1 };
74
- // the material compiles under FOG_EXP2 when the fog object is FogExp2, so that branch holds the replacement for density kinds;
75
- // a custom glsl for 'linear' takes the other branch
76
- const dense = f.kind !== 'linear', own = `vec4 threedogFogOut = threedogFog(fogColor, vFogDepth, vFogWorld);
77
- gl_FragColor.rgb = mix(gl_FragColor.rgb, threedogFogOut.rgb, clamp(threedogFogOut.a, 0.0, 1.0));`;
78
- const orig = ORIGINAL.fog_fragment.replace('#ifdef USE_FOG', '').replace(/#endif\s*$/, '');
79
- C.fog_pars_vertex = '#ifdef USE_FOG\n\tvarying float vFogDepth;\n\tvarying vec3 vFogWorld;\n#endif\n';
80
- // world position from the view-space one: the view matrix is a pure rotation + translation, so its transpose undoes the rotation
81
- // (cheaper than another matrix and right for instanced and skinned meshes too, which mvPosition already includes)
82
- C.fog_vertex = '#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n\tvFogWorld = ( vec4( mvPosition.xyz, 0.0 ) * viewMatrix ).xyz + cameraPosition;\n#endif\n';
83
- C.fog_pars_fragment = `#ifdef USE_FOG
84
- uniform vec3 fogColor;
85
- varying float vFogDepth;
86
- varying vec3 vFogWorld;
87
- const float THREEDOG_FOG_HEIGHT = ${flt(f.height)};
88
- const float THREEDOG_FOG_FALLOFF = ${flt(f.falloff)};
89
- #ifdef FOG_EXP2
90
- uniform float fogDensity;
91
- ${dense ? f.glsl : ''}
92
- #else
93
- uniform float fogNear;
94
- uniform float fogFar;
95
- ${dense ? '' : f.glsl}
96
- #endif
82
+ /**
83
+ * The 'fog' patch for resolved settings, or null when three's own fog draws it (plain linear / exp2).
84
+ * The material compiles under FOG_EXP2 when the fog object is FogExp2, so that branch holds the replacement for the density kinds; a hook on
85
+ * 'linear' takes the other branch. The other branch keeps three's own code, so a game that swaps in the other fog object still gets fog.
86
+ */
87
+ export function fogPatch(f) {
88
+ if (!f?.glsl) return null;
89
+ const dense = f.kind !== 'linear', mine = dense ? '#ifdef FOG_EXP2' : '#ifndef FOG_EXP2';
90
+ // three's fog_fragment body without its #ifdef USE_FOG wrapper (read now: nothing in the engine rewrites the chunk any more)
91
+ const orig = THREE.ShaderChunk.fog_fragment.replace('#ifdef USE_FOG', '').replace(/#endif\s*$/, '');
92
+ const pars = `#ifdef USE_FOG
93
+ const float THREEDOG_FOG_HEIGHT = ${flt(f.height)};
94
+ const float THREEDOG_FOG_FALLOFF = ${flt(f.falloff)};
95
+ ${mine}
96
+ ${f.glsl}
97
97
  #endif
98
- `;
99
- C.fog_fragment = `#ifdef USE_FOG
100
- #ifdef FOG_EXP2
101
- ${dense ? own : orig}
102
- #else
103
- ${dense ? orig : own}
104
- #endif
98
+ #endif`;
99
+ // vFogDepth is three's own varying (fog_vertex); the world position comes from the engine's 'world' patch (vThreedogWorld)
100
+ const body = `#ifdef USE_FOG
101
+ ${mine}
102
+ vec4 threedogFogOut = threedogFog(fogColor, vFogDepth, vThreedogWorld);
103
+ gl_FragColor.rgb = mix(gl_FragColor.rgb, threedogFogOut.rgb, clamp(threedogFogOut.a, 0.0, 1.0));
104
+ #else
105
+ ${orig}
105
106
  #endif
106
- `;
107
- return release(held);
107
+ #endif`;
108
+ return { name: 'fog', cacheKey: hashText(pars + body), needs: { patches: ['world'] }, glsl: { fogPars: pars, fog: body } };
108
109
  }
109
110
 
110
- // One release per owner; the originals return only when the count reaches 0
111
- function release(h) {
112
- let done = false;
113
- return () => {
114
- if (done) return; done = true;
115
- if (--h.count > 0) return;
116
- for (const n of NAMES) THREE.ShaderChunk[n] = ORIGINAL[n];
117
- if (held === h) held = null;
111
+ // Built-in material types whose shaders have the world varying's anchor and three's fog chunks (Sprite does not: it builds mvPosition by hand)
112
+ const FOGGED = new Set(['MeshBasicMaterial', 'MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMaterial', 'MeshPhysicalMaterial',
113
+ 'MeshToonMaterial', 'MeshMatcapMaterial', 'LineBasicMaterial', 'LineDashedMaterial', 'PointsMaterial']);
114
+
115
+ /**
116
+ * Point the fog patch at new settings: unchanged code does nothing, new code re-patches every material it went on (they recompile once),
117
+ * null takes it off them. The next fogMaterials walk reaches materials it has not seen.
118
+ * @param {any} sky @param {any} f resolved settings, or null (no fog: sky({ fog: false }), module disposed)
119
+ */
120
+ export function setFogPatch(sky, f) {
121
+ sky._fogSet = f; // the settings in force: a renderer swap (fallback 'webgl') applies them again on the other route
122
+ // WebGPURenderer: one scene fog node instead of the per-material patch (render/fx/sky.tsl.js fogSide: kinds, the FogExp2 rule, the hook error)
123
+ const n = skyNodes(sky.engine);
124
+ if (n) { (sky._fogNode ??= n.fogSide(sky.engine.scene)).set(f); return; }
125
+ if (f?.hook && f.glsl == null) throw codedError('sky-option', "look.fog.patch('fog') has only a tsl form, which WebGLRenderer cannot draw: give glsl too ({ glsl, tsl })");
126
+ const w = sky._fogWalk ??= { patch: null, mats: new Map(), view: null };
127
+ const p = f ? fogPatch(f) : null;
128
+ if ((p?.cacheKey ?? null) === (w.patch?.cacheKey ?? null)) return;
129
+ w.patch = p;
130
+ for (const m of w.mats.keys()) unpatchMaterial(m, 'fog');
131
+ w.mats.clear();
132
+ // new code: every material in the scene again (rescan); no patch: stop watching the scene
133
+ if (!p) { w.view?.remove(); w.view = null; return; }
134
+ const fit = m => {
135
+ if (!m || w.mats.get(m) === w.patch || !FOGGED.has(m.type) || m.fog === false) return;
136
+ patchMaterial(m, [w.patch], { strict: false }); w.mats.set(m, w.patch);
118
137
  };
138
+ if (w.view) w.view.rescan();
139
+ else w.view = sceneVisitor(sky.engine.scene, { enter(o) { const ms = o.material; if (Array.isArray(ms)) for (const m of ms) fit(m); else fit(ms); } });
140
+ }
141
+
142
+ /** Per frame (updateSky): put the fog patch on fogged materials of objects that entered the scene since the last frame (core/sceneDelta.js) */
143
+ export function fogMaterials(sky) {
144
+ sky._fogWalk?.view?.sync();
145
+ sky._fogNode?.sync(); // WebGPU: the scene fog node follows scene.fog's type (render/fx/sky.tsl.js)
119
146
  }
147
+
148
+ /** describe().owned row 'fog.patch': the game's own materials the fog patch went on (undefined while none) */
149
+ export function fogGameMaterials(sky) {
150
+ const g = [...(sky._fogWalk?.mats.keys() ?? [])].filter(m => !isEngineMade(m)).map(m => m.name || m.type);
151
+ return g.length ? { part: 'fog', key: 'patch', writer: 'engine', materials: g, why: "kind 'exp' / 'height' / look.fog hook: three's fog would draw another curve" } : undefined;
152
+ }
153
+
154
+ /** The far distance a disabled fog is pushed to (out of reach, no recompile); fogBand reads it back to know the fog is off */
155
+ const FOG_OFF_FAR = 1e9;
156
+
120
157
  /** Per frame: fog color and distance / density from the sky's horizon and the modifier layers (fog multiplies the distance) */
121
- export function updateFog(sky, horizon, M) {
158
+ export function updateFog(sky, horizon, ctx) {
122
159
  // only when the sky drives fog (sky({ fog: true })) and scene.fog is still a fog object: the game may have nulled or replaced it
123
160
  const fog = sky.engine.scene.fog, f = sky._fog;
124
- if (sky._drive.fog !== true || sky._fogHeld || !fog?.color) return; // _fogHeld: look.fog.replace(...) gave the fog to the game
125
- // look.fog: far / near set explicitly are the base distance (weather still scales it); enabled false pushes the fog out of reach without a recompile
126
- const far = f.enabled ? (f.far ?? sky.engine.fogFar) * M.fog : 1e9;
127
- if (f.color === 'horizon') fog.color.copy(horizon);
128
- else if (typeof f.color === 'function') fog.color.set(f.color(sky));
129
- else fog.color.copy(f.color);
130
- // near / far are written for every kind: engine.setFogFar and the dev guard read them
131
- fog.far = far; fog.near = f.enabled && f.near != null ? f.near * M.fog : far * 0.3;
132
- if (f.kind !== 'linear') fog.density = !f.enabled ? 0 : f.density != null ? f.density / M.fog : REACH[f.kind] / far;
161
+ if (!sky._oFog?.on || !fog?.color) return; // off after scene.fog = yours (the owned entry yielded) or look.fog.manual()
162
+ // look.fog far is a shared point: its value already holds the weather's multiplier (engine.mod('look.fog.far', { mul })); near / density set
163
+ // explicitly are kept as given; enabled false pushes the fog out of reach without a recompile
164
+ const far = f.enabled ? fogFarOf(sky.engine) : FOG_OFF_FAR, near = live(f.near, ctx), density = live(f.density, ctx);
165
+ // a function color may answer 'horizon' too (({ state }) => state.boss ? '#400' : 'horizon'), so the default stays one word away
166
+ const color = live(f.color, ctx);
167
+ if (color === 'horizon') fog.color.copy(horizon);
168
+ else fog.color.set(color);
169
+ // near / far are written for every kind: the dev guard reads them
170
+ fog.far = far; fog.near = f.enabled && near != null ? near : far * FOG_NEAR;
171
+ if (f.kind !== 'linear') fog.density = !f.enabled ? 0 : density != null ? density : REACH[f.kind] / far;
133
172
  }
134
173
 
135
- /** Dome addition when the fog color is not the horizon: the dome's lower band fades to the fog color so the horizon line does not show */
136
- export function domeFog(f) {
137
- if (f.color === 'horizon') return { decl: '', body: '' };
138
- return { decl: 'uniform vec3 uFogColor;', body: '\n col = mix(col, uFogColor, 1.0 - smoothstep(-0.02, 0.15, d.y));' };
139
- }
174
+ // The dome's fog band: its lower band fades to the fog color so the line where fogged ground meets the sky does not show.
175
+ // Always compiled in and switched by the uFogBand uniform (0 = off, mix(col, x, 0.0) is col exactly), so any fog color change at
176
+ // runtime -- 'horizon' <-> a fixed color <-> a function, look.fog.set, a game writing scene.fog.color under manual() -- needs no recompile.
177
+ export const DOME_FOG = { decl: 'uniform vec3 uFogColor; uniform float uFogBand;', body: '\n col = mix(col, uFogColor, uFogBand * (1.0 - smoothstep(-0.02, 0.15, d.y)));' };
178
+ /** Per frame, after updateFog: the band is on exactly when the fog's color is not the horizon the dome draws. One rule for every mode
179
+ * (sky-driven, manual, replaced fog), because it reads the fog object itself rather than the sky's settings; 'horizon' copies the color
180
+ * exactly, so the default stays bit-for-bit the plain dome. No fog object (fog: false) = nothing to hide = off; a fog that is there but draws
181
+ * nothing (look.fog enabled: false pushes far out of reach, or an exp2 density of 0) = also off, or the dome would show a band no ground has. */
182
+ // !(far >= off): a game's own FogExp2 has no far at all and still shows
183
+ const fogShows = fog => !(fog.far >= FOG_OFF_FAR) && !(fog.isFogExp2 && fog.density <= 0);
184
+ export const fogBand = (fog, horizon) => (fog?.color && fogShows(fog) && !fog.color.equals(horizon) ? 1 : 0);
@@ -1,76 +1,144 @@
1
1
  // Sky per-frame work (helper of Sky.js): dome colors, sun / moon light, ambient, fog and the shadow center from the time of day and
2
2
  // the modifier layers; plus the dev guard that warns when a game edits what this overwrites every frame.
3
- import { ownedProps } from '../../core/validate.js';
4
- import { applySeason } from './calendar.js';
5
- import { applyCover } from './layers.js';
6
- import { updateFog } from './fog.js';
3
+ import { defineOwned } from '../../core/owned.js';
4
+ import { applySeason } from './season.js';
5
+ import { applyCover, skyTint } from './tint.js';
6
+ import { updateFog, fogBand, fogMaterials } from './fog.js';
7
7
  import { cascadeFrame } from './cascades.js';
8
+ import { fillContext, live } from '../../core/look/state.js';
9
+ import { roomShare, ROOM_RADIANCE } from '../../render/lights.js';
8
10
 
9
- // Developer message: how to fix when a per-frame recomputed property (ownedProps) is edited directly
10
- const STRINGS = {
11
- sun: "use engine.sky.modify('layerName', { sun })",
12
- sunColor: "edit style pack sky.keyframes or use engine.sky.modify('layerName', { tint, tintAmount })",
13
- sunPos: 'sun position is driven by sky.timeOfDay',
14
- hemi: "use engine.sky.modify('layerName', { ambient })",
15
- fog: "use look.fog.set({ color, density, far }), engine.sky.modify('layerName', { fog }) or engine.setFogFar(); to own scene.fog, create the sky with sky({ fog: 'manual' }) (or false)",
16
- modifiers: "sky.modifiers is the composite of all layers; use engine.sky.modify('layerName', { sun, ambient, fog, ... })",
11
+ /**
12
+ * Brightness of the sky's ambient light for one sky color pair: ambient intensity x the luminance of the hemi color (top / horizon halfway,
13
+ * linear colors, so the mean of their luminances). One measure for the keyframe peak (Sky.js) and the frame (updateSky).
14
+ * @param {import('three').Color} top @param {import('three').Color} horizon @param {number} ambient
15
+ */
16
+ export const skyLight = (top, horizon, ambient) => ambient * (lum(top) + lum(horizon)) / 2;
17
+ const lum = c => 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b;
18
+
19
+ // The copyable takeover calls each owned property's warning quotes (core/owned.js): the engine yields to a direct write, these say it explicitly
20
+ const L = {
21
+ sun: { manual: "engine.look.lights.manual('sun')", set: "engine.look.lights.set({ sun: { intensity: 2 } })" },
22
+ sunColor: { manual: "engine.look.lights.manual('sun.color')", set: "engine.look.lights.set({ sun: { color: '#ffd9a0' } })" },
23
+ sunDir: { manual: "engine.look.lights.manual('sun.direction')" },
24
+ hemi: { manual: "engine.look.lights.manual('hemi')", set: "engine.look.lights.set({ hemi: { intensity: 0.8 } })" },
25
+ fog: { manual: 'engine.look.fog.manual()', set: "engine.look.fog.set({ color: '#cfd8e0', far: 300 })" },
26
+ exposure: { manual: "engine.look.tone.manual('exposure')", set: 'engine.look.tone.set({ exposure: 1.2 })' },
27
+ background: { manual: "engine.look.sky.manual('background')", replace: 'engine.look.sky.replace(null)' },
28
+ follow: { manual: "engine.look.shadow.manual('follow')", set: 'engine.look.shadow.set({ follow: false })' },
17
29
  };
18
30
 
19
- /** Watchers of the properties sky rewrites every frame (validate.js ownedProps) */
31
+ /**
32
+ * Register what the sky writes every frame (core/owned.js). Everything starts engine-written; the one way to take a value over is
33
+ * look.<part>.manual(key) (or a direct write, which the sky yields to). Lights in false mode are hidden and not registered.
34
+ */
20
35
  export function watchOwned(sky) {
21
- const scene = sky.engine.scene, fog = () => scene.fog;
22
- // only what the sky writes: a light in 'manual' or false mode (look.js) is the game's to edit
23
- const D = sky._drive;
24
- return [
25
- D.sun === true && ownedProps('sky.sun.intensity', () => sky.sun.intensity, STRINGS.sun),
26
- D.sun === true && ownedProps('sky.sun.color', () => sky.sun.color.toArray(), STRINGS.sunColor),
27
- D.sun !== false && ownedProps('sky.sun.position', () => sky.sun.position.toArray(), STRINGS.sunPos),
28
- D.hemi === true && ownedProps('sky.hemi', () => [sky.hemi.intensity, ...sky.hemi.color.toArray(), ...sky.hemi.groundColor.toArray()], STRINGS.hemi),
29
- // fog: the object itself, color, near/far ratio (engine.setFogFar keeps the ratio, so it is not a violation)
30
- D.fog === true && ownedProps('scene.fog', () => sky._fogHeld ? [null] : [fog(), ...(fog()?.color?.toArray() ?? []), fog()?.near / fog()?.far], STRINGS.fog),
31
- ownedProps('sky.modifiers', () => { const M = sky.modifiers; return [M.sun, M.ambient, M.fog, M.tintAmount, M.horizonTintAmount, M.flash, ...M.tint.toArray()]; }, STRINGS.modifiers),
32
- ].filter(Boolean);
36
+ const e = sky.engine, scene = e.scene, fog = () => scene.fog, D = sky._drive, sun = sky._sun, hemi = sky._hemi;
37
+ const own = (id, part, key, read, levels, objects) => defineOwned(e, { id, part, key, read, levels, objects });
38
+ const list = [];
39
+ if (D.sun !== false) {
40
+ sky._oSunI = own('sun.intensity', 'lights', 'sun.intensity', () => sun.intensity, L.sun, [sun]);
41
+ sky._oSunC = own('sun.color', 'lights', 'sun.color', () => sun.color.toArray(), L.sunColor, [sun, sun.color]);
42
+ // the direction is where the sun sits relative to its target; the shadow box still follows the focus when the game owns the direction (shadow.js)
43
+ sky._oSunDir = own('sun.direction', 'lights', 'sun.direction', () => { const p = sun.position, t = sun.target.position; return [p.x - t.x, p.y - t.y, p.z - t.z]; }, L.sunDir, [sun, sun.position]);
44
+ sky._oFollow = own('shadow.follow', 'shadow', 'follow', () => sun.target.position.toArray(), L.follow, [sun.target, sun.target.position]);
45
+ list.push(sky._oSunI, sky._oSunC, sky._oSunDir, sky._oFollow);
46
+ }
47
+ if (D.hemi !== false) list.push(sky._oHemi = own('hemi', 'lights', 'hemi', () => [hemi.intensity, ...hemi.color.toArray(), ...hemi.groundColor.toArray()], L.hemi, [hemi, hemi.color, hemi.groundColor]));
48
+ // fog: the object itself, color, near and far (the values, not their ratio: a game writing far 50 / near 15 is an outside write too; the engine
49
+ // only writes near / far inside updateFog, between check and mark, so its own writes never look like the game's).
50
+ // scene.fog = a fog of yours is a change of the object this entry reads, so it yields: "who writes scene.fog" has one record, not a second flag
51
+ if (D.fog !== false) list.push(sky._oFog = own('fog', 'fog', 'fog', () => [fog(), ...(fog()?.color?.toArray() ?? []), fog()?.near, fog()?.far, fog()?.density], L.fog,
52
+ [scene, ...(fog() ? [fog(), fog().color] : [])]));
53
+ list.push(sky._oExposure = own('exposure', 'tone', 'exposure', () => e.renderer.toneMappingExposure, L.exposure, [e.renderer]));
54
+ // background: the sky writes it with a backdrop / skybox; with the dome it draws over whatever scene.background holds, so a game that sets one
55
+ // takes it, and the dome hides (onChange) so the game's background shows; handing it back shows the dome again
56
+ list.push(sky._oBg = own('background', 'sky', 'background', () => [scene.background, scene.backgroundIntensity], L.background, [scene]));
57
+ sky._oBg._onChange = o => { if (!sky._backdrop && !sky.skybox && !sky._ownSky) sky.dome.visible = o.on; }; // a replaced sky keeps the dome hidden
58
+ return list;
33
59
  }
34
60
 
35
61
  /** Recompute dome, lights, fog and shadow placement for this frame */
36
62
  export function updateSky(sky, focus) {
37
63
  applySeason(sky, sky.engine.uniforms);
38
- const t = sky.timeOfDay, kf = sky.kf;
64
+ // the contract's inputs, once per frame: every function-valued look key below reads this one object (core/look/state.js)
65
+ const ctx = fillContext(sky.engine, sky, sky.engine.weather?.name, sky.engine.calendar), P = sky.engine.look.sky;
66
+ for (const p of Object.values(sky.engine.look)) p.author.tick(ctx); // function values on number keys (look.fog far, look.lights sun.intensity ...)
67
+ const t = sky.drawnTime, kf = sky.kf;
39
68
  let i = 0; while (i < kf.length - 2 && t > kf[i + 1][0]) i++;
40
69
  const a = kf[i], b = kf[i + 1], f = (t - a[0]) / (b[0] - a[0]);
41
70
  const u = sky.uniforms, scene = sky.engine.scene;
42
71
  u.uTop.value.copy(a[1]).lerp(b[1], f);
43
72
  u.uHorizon.value.copy(a[2]).lerp(b[2], f);
44
- for (const o of sky._owned) o.check();
45
- sky._combine();
73
+ // look.sky top / horizon: a color or a function over the keyframes (null = keyframes); fog 'horizon', hemi color and the dome all follow
74
+ const top = P.value('top'), hor = P.value('horizon');
75
+ if (top != null) u.uTop.value.set(live(top, ctx));
76
+ if (hor != null) u.uHorizon.value.set(live(hor, ctx));
77
+ for (const o of sky._owned) if (o !== sky._oExposure || sky.engine.exposureDriver) o.check(); // exposure is engine-written only with a driver
46
78
  applyCover(sky, sky.engine.uniforms); // after the season: snow / ash cover lies over the season tint
47
- const M = sky.modifiers;
48
- if (M.tintAmount) u.uTop.value.lerp(M.tint, M.tintAmount);
49
- if (M.horizonTintAmount) u.uHorizon.value.lerp(M.tint, M.horizonTintAmount);
50
- if (M.flash) { u.uTop.value.addScalar(M.flash * 0.4); u.uHorizon.value.addScalar(M.flash * 0.3); }
79
+ const M = skyTint(sky, sky._tintNow), flash = sky._points.flash.value(), hemiI = a[5] + (b[5] - a[5]) * f;
80
+ // the sky's light now, 0-1 of its brightest keyframe row, read before any tint. Why: a sky.tint color (weather grey, a cave tint) is the color
81
+ // under that brightest sky; lerping toward it as a fixed color turned a rainy night into a lit grey (#0d1628 -> #6b6b6d, R3). Dimmed by the
82
+ // sky's own light it stays dark at night and is unchanged at the brightest row
83
+ // sky. style.sky.dim.tint false keeps the tint at its full color at any hour (a style decision, not the engine's)
84
+ const light = !sky.dim.tint ? 1 : sky._lightPeak > 0 ? Math.min(1, skyLight(u.uTop.value, u.uHorizon.value, hemiI) / sky._lightPeak) : 1;
85
+ if (M.amount || M.horizon) {
86
+ const tint = sky._tintLit.copy(M.color).multiplyScalar(light);
87
+ if (M.amount) u.uTop.value.lerp(tint, M.amount);
88
+ if (M.horizon) u.uHorizon.value.lerp(tint, M.horizon);
89
+ }
90
+ if (flash) { u.uTop.value.addScalar(flash * 0.4); u.uHorizon.value.addScalar(flash * 0.3); }
51
91
  const bd = sky._backdrop; // style.sky.backdrop (look.js): a flat background in place of the dome, fog follows it
52
- if (bd) { if (bd.fn) bd.color.set(bd.fn(sky)); sky.dome.visible = false; scene.background = bd.color; }
53
- updateFog(sky, bd ? bd.color : u.uHorizon.value, M);
92
+ if (bd && sky._oBg.on) { if (bd.fn) bd.color.set(bd.fn(ctx)); sky.dome.visible = false; scene.background = bd.color; }
93
+ updateFog(sky, bd ? bd.color : u.uHorizon.value, ctx);
94
+ // the drawn sky colors for game shaders (render/effects.js uSkyTop / uSkyHorizon): the same horizon the fog's 'horizon' color copies
95
+ sky.engine.uniforms.uSkyTop.value.copy(u.uTop.value); sky.engine.uniforms.uSkyHorizon.value.copy(bd ? bd.color : u.uHorizon.value);
96
+ fogMaterials(sky); // the 'fog' patch onto materials added since the last scene change (nothing while three's own fog draws it)
97
+ u.uFogBand.value = fogBand(scene.fog, u.uHorizon.value); // compared to the dome's horizon (not the backdrop): the band is drawn on the dome
54
98
  u.uSunColor.value.copy(a[3]).lerp(b[3], f); // the dome's sun disk follows the keyframes whatever drives the light
55
- if (sky._drive.sun === true) sky.sun.color.copy(u.uSunColor.value);
56
- const sunI = a[4] + (b[4] - a[4]) * f, hemiI = a[5] + (b[5] - a[5]) * f;
99
+ const sunI = a[4] + (b[4] - a[4]) * f;
57
100
 
58
101
  const ang = (t - 0.25) * Math.PI * 2, elev = Math.sin(ang);
59
102
  sky.sunDir.set(Math.cos(ang) * sky.orbit.sway, elev, sky.orbit.tilt).normalize();
60
103
  u.uSunDir.value.copy(sky.sunDir);
104
+ // the contract's shared outputs: engine.uniforms is what a game's own sky / water / shader reads (a replaced dome keeps getting
105
+ // these); uSunDir is the dome's own object (shader.js), so the copy above already wrote it
106
+ const EU = sky.engine.uniforms;
107
+ EU.uDaylight.value = Math.max(0, elev); EU.uTimeOfDay.value = t;
61
108
  u.uNight.value = Math.min(1, Math.max(0, -elev * 4));
62
109
  const lightDir = elev >= 0 ? sky.sunDir : sky._lightDir.copy(sky.sunDir).negate().setZ(sky.orbit.tilt).normalize();
63
- if (sky._drive.sun === true) sky.sun.intensity = sunI * Math.min(1, Math.abs(elev) * 7) * M.sun; // fade out near the horizon so day/night switching does not pop
64
- if (sky._drive.hemi === true) {
65
- sky.hemi.intensity = hemiI * M.ambient + M.flash * 3;
66
- sky.hemi.color.copy(u.uTop.value).lerp(u.uHorizon.value, 0.5);
67
- sky.hemi.groundColor.copy(sky.groundTint).multiplyScalar(0.4 + 0.6 * Math.min(1, hemiI));
110
+ // the keyframes are the style layer of the light keys (look.lights.drive in Sky.js); the sunset fade is an effect on top, like the weather's
111
+ // multiplier. So a game's look.lights.set({ sun: { intensity: 3 } }) replaces the keyframes and still dims at dusk and in rain (core/look/points.js)
112
+ const Lk = sky.engine.look.lights, La = Lk.author, D = sky._drive;
113
+ La.batch(() => {
114
+ if (D.sun === true) {
115
+ La.feed('sun.intensity', sunI); La.feed('sun.color', u.uSunColor.value.getHex());
116
+ // fade out near the horizon so day/night switching does not pop
117
+ sky._horizon = La.point('sun.intensity').take({ owner: 'sky:horizon', layer: 'effect', mul: Math.min(1, Math.abs(elev) * 7) });
118
+ }
119
+ if (D.hemi === true) {
120
+ La.feed('hemi.intensity', hemiI);
121
+ La.feed('hemi.color', sky._tmpC.copy(u.uTop.value).lerp(u.uHorizon.value, 0.5).getHex());
122
+ La.feed('hemi.ground', sky._tmpC.copy(sky.groundTint).multiplyScalar(0.4 + 0.6 * Math.min(1, hemiI)).getHex());
123
+ }
124
+ });
125
+ if (sky._oSunI?.on) sky._sun.intensity = Lk.value('sun.intensity');
126
+ if (sky._oSunC?.on) sky._sun.color.set(live(Lk.value('sun.color'), ctx));
127
+ // one ambient budget (look.lights hemi.intensity: the style's ambient column x the weather's multiplier): the room map takes its share, the hemisphere light the rest
128
+ const amb = Lk.value('hemi.intensity'), share = roomShare(sky.engine);
129
+ if (sky._oHemi?.on) {
130
+ sky._hemi.intensity = amb * (1 - share) + flash * 3;
131
+ sky._hemi.color.set(live(Lk.value('hemi.color'), ctx));
132
+ sky._hemi.groundColor.set(live(Lk.value('hemi.ground'), ctx));
68
133
  }
69
- sky.engine.look.lights.applyTop(); // a game look.lights.set({ sun: { intensity } }) wins over the keyframes (look/part.js)
134
+ // the room environment is its share of the same budget, in the same units: ambient x the luminance of the sky color the hemi light takes
135
+ // (a neutral white map must not light a dark-blue night white: desert demo R4), turned into an environment intensity by what the map gives
136
+ // at 1 (ROOM_RADIANCE; three's hemisphere light divides by PI, the environment does not). look.lights env.share is the share
137
+ sky._envFollow(amb * skyLight(u.uTop.value, u.uHorizon.value, 1) / (Math.PI * ROOM_RADIANCE));
70
138
  const ex = sky.engine.exposureDriver;
71
- if (ex) sky.engine.renderer.toneMappingExposure = ex(sky); // style.exposure keyframes / function (engine.look.tone.set)
139
+ if (ex && sky._oExposure.on) sky.engine.renderer.toneMappingExposure = ex(ctx); // style.exposure keyframes / function (engine.look.tone.set)
72
140
 
73
- if (sky.skybox) sky.engine.scene.backgroundIntensity = Math.max(0.05, hemiI * M.ambient / 1.2);
141
+ if (sky.skybox && sky._oBg.on) sky.engine.scene.backgroundIntensity = Math.max(0.05, amb / 1.2);
74
142
  if (sky.csm) cascadeFrame(sky, lightDir); // cascades place their own lights from the camera (cascades.js)
75
143
  else if (sky._drive.sun !== false) sky._placeShadow(focus, lightDir);
76
144
  for (const o of sky._owned) o.mark();
@@ -1,27 +1,31 @@
1
1
  // Sky look setup (helper of Sky.js): which engine lights the sky drives, the fog model, extra dome layers.
2
2
  // Light modes, sky() options only (whether the engine's two lights exist is how the game lights its world, not a swappable look):
3
3
  // sky({ sun: true }) default: the sky drives engine.lights.sun (color, intensity, direction, shadow box) from the keyframes
4
- // sky({ sun: 'manual' }) the sky still aims it along the time of day and moves the shadow box; color and intensity are the game's
5
4
  // sky({ sun: false }) hidden (visible = false, no shadows) and never touched: light the world with your own three.js lights
6
- // sky({ hemisphere: true | 'manual' | false }) the same for engine.lights.hemi (ambient): 'manual' leaves its colors and intensity alone
7
- // sky({ fog: true | 'manual' | false }) scene.fog: true (default) the sky creates it and writes color and distance every frame |
8
- // 'manual' created once, then never written (the game sets color / near / far / its own object) |
9
- // false scene.fog = null and never touched. An object here is style.sky.fog settings (= true)
5
+ // sky({ hemisphere: true | false }) the same for engine.lights.hemi (ambient)
6
+ // sky({ fog: true | false }) scene.fog: true (default) the sky creates it and writes color and distance every frame | false scene.fog = null
7
+ // and never touched. An object here is style.sky.fog settings (= true)
8
+ // Keeping a light / the fog but writing it yourself is not a sky() option: one takeover entry per look value (2026-11-02), engine.look.lights.manual(
9
+ // 'sun' | 'hemi' | 'sun.intensity' ...) and engine.look.fog.manual() (core/owned.js). manual(key, false) hands it back, and a direct write without
10
+ // either takes it too (the sky yields and warns once). The removed 'manual' mode throws and names that call, so old code learns the one way.
10
11
  // Hidden lights are left in the scene (visible = false): three skips them, and toggling visible later recompiles like adding a light would.
11
12
  import * as THREE from 'three';
12
- import { resolveFog, domeFog } from './fog.js';
13
+ import { resolveFog, DOME_FOG } from './fog.js';
13
14
  import { resolveDomeLayers } from './domeLayers.js';
15
+ import { codedError } from '../../core/errorHints.js';
16
+ import { isWebGPU } from '../../render/backend.js';
14
17
 
15
- const MODES = [true, false, 'manual'];
18
+ const TAKE = { sun: "engine.look.lights.manual(['sun.intensity', 'sun.color'])", hemisphere: "engine.look.lights.manual('hemi')", fog: 'engine.look.fog.manual()' };
16
19
  const modeOf = (name, v = true) => {
17
- if (!MODES.includes(v)) throw new Error(`sky({ ${name} }) must be true (the sky drives it), 'manual' (the game sets its color and intensity) or false (hidden, light the world yourself); got ${JSON.stringify(v)}`);
20
+ if (v === 'manual') throw codedError('sky-option', `sky({ ${name}: 'manual' }) is not an option; keep the default and take it over after engine.use(sky()) with ${TAKE[name]} (manual(..., false) hands it back)`);
21
+ if (v !== true && v !== false) throw codedError('sky-option', `sky({ ${name} }) must be true (the sky drives it) or false (${name === 'fog' ? 'no fog' : 'hidden, light the world yourself'}); to write it yourself: ${TAKE[name]}; got ${JSON.stringify(v)}`);
18
22
  return v;
19
23
  };
20
24
 
21
- /** Resolve light modes, fog and dome layers for a new Sky; returns the extra dome uniforms and GLSL ({ uniforms, decl, body }) */
25
+ /** Resolve light modes, fog and dome layers for a new Sky; returns the extra dome uniforms and GLSL ({ uniforms, decl, body }), and the layers for a node dome */
22
26
  export function prepareLook(sky, st, over) {
23
- /** @internal which engine lights the sky writes each frame: true / 'manual' / false */
24
- // fog is also the look override (an object of style.sky.fog settings, which means true); a boolean or 'manual' picks the mode and keeps the style's settings
27
+ /** @internal which engine lights / fog the sky writes each frame: true / false */
28
+ // fog is also the look override (an object of style.sky.fog settings, which means true); a boolean picks the mode and keeps the style's settings
25
29
  const fogObj = over.fog != null && typeof over.fog === 'object';
26
30
  sky._drive = { sun: modeOf('sun', over.sun), hemi: modeOf('hemisphere', over.hemisphere), fog: fogObj ? true : modeOf('fog', over.fog) };
27
31
  const { sun, hemi } = sky.engine.lights;
@@ -31,21 +35,20 @@ export function prepareLook(sky, st, over) {
31
35
  sky._fogSpec = fogObj || over.fog == null ? st.fog : sky.engine.style.sky?.fog; // look.fog's style layer (lookFog.js)
32
36
  sky._fog = resolveFog(sky._fogSpec);
33
37
  sky._backdrop = resolveBackdrop(st);
34
- const f = domeFog(sky._fog), l = resolveDomeLayers(st.layers);
35
- const uniforms = { ...l.uniforms };
36
- // the fog object is created after the dome, and its color is rewritten each frame: read it at draw time
37
- if (f.decl) uniforms.uFogColor = { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } }; // no fog object (fog: false): fade to the horizon
38
- return { uniforms, decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body };
38
+ const f = DOME_FOG, l = resolveDomeLayers(st.layers, { gpu: isWebGPU(sky.engine.renderer) });
39
+ // the fog object is created after the dome and may be replaced by the game: read its color at draw time (fog.js fogBand turns the band on)
40
+ const uniforms = { ...l.uniforms, uFogBand: { value: 0 }, uFogColor: { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } } };
41
+ return { uniforms, decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body, layers: l.layers };
39
42
  }
40
43
 
41
- // style.sky.backdrop: one flat color (or (sky) => color each frame) instead of the dome -- no gradient, horizon, sun / moon disk,
44
+ // style.sky.backdrop: one flat color (or ({ time, weather, season, state, sky }) => color each frame, core/look/state.js) instead of the dome -- no gradient, horizon, sun / moon disk,
42
45
  // stars or clouds. The color goes straight to scene.background (no tone mapping), so what is written is what shows; the keyframes
43
46
  // still light the world, and fog in its default 'horizon' color follows the backdrop so far things fade into it.
44
47
  export function resolveBackdrop(st) {
45
48
  const v = st.backdrop;
46
49
  if (v == null) return null;
47
50
  const color = typeof v === 'number' || typeof v === 'string' || v.isColor;
48
- if (!color && typeof v !== 'function') throw new Error(`style.sky.backdrop must be a color (0xefebe4, '#efebe4') or (sky) => color; got ${JSON.stringify(v)}`);
49
- if (st.skybox) throw new Error('style.sky: backdrop and skybox both replace the dome; keep one (backdrop for a flat color, skybox for a panorama)');
51
+ if (!color && typeof v !== 'function') throw codedError('sky-option', `style.sky.backdrop must be a color (0xefebe4, '#efebe4') or ({ time, state }) => color; got ${JSON.stringify(v)}`);
52
+ if (st.skybox) throw codedError('sky-option', 'style.sky: backdrop and skybox both replace the dome; keep one (backdrop for a flat color, skybox for a panorama)');
50
53
  return { fn: color ? null : v, color: new THREE.Color(color ? v : 0x000000) };
51
54
  }