threedog 0.7.0 → 0.8.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 (544) hide show
  1. package/CHANGELOG.md +196 -1
  2. package/README.md +6 -9
  3. package/core/{Animator.js → assets/Animator.js} +28 -18
  4. package/core/{Assets.js → assets/Assets.js} +98 -54
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +237 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +7 -6
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +6 -12
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +26 -23
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +10 -10
  18. package/core/{Random.js → base/Random.js} +5 -4
  19. package/core/{easing.js → base/easing.js} +1 -1
  20. package/core/{errorCodes.js → base/errorCodes.js} +98 -110
  21. package/core/{errorHints.js → base/errorHints.js} +5 -9
  22. package/core/{errors.js → base/errors.js} +6 -6
  23. package/core/{events.generated.js → base/events.generated.js} +1 -0
  24. package/core/{math.js → base/math.js} +15 -4
  25. package/core/{params.js → base/params.js} +3 -4
  26. package/core/base/util.js +32 -0
  27. package/core/{validate.js → base/validate.js} +28 -7
  28. package/core/{Engine.js → engine/Engine.js} +80 -77
  29. package/core/{Loading.js → engine/Loading.js} +4 -2
  30. package/core/{copies.js → engine/copies.js} +4 -4
  31. package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
  32. package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
  33. package/core/{loop.js → engine/loop.js} +68 -47
  34. package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
  35. package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
  36. package/core/{modules.js → engine/modules.js} +14 -11
  37. package/core/{page.js → engine/page.js} +36 -23
  38. package/core/{plugins.js → engine/plugins.js} +6 -9
  39. package/core/{services.js → engine/services.js} +47 -40
  40. package/core/{startup.js → engine/startup.js} +26 -24
  41. package/core/{Input.js → input/Input.js} +30 -22
  42. package/core/{inputContext.js → input/inputContext.js} +14 -5
  43. package/core/{inputPad.js → input/inputPad.js} +1 -1
  44. package/core/{inputPointer.js → input/inputPointer.js} +8 -2
  45. package/core/{inputTouch.js → input/inputTouch.js} +1 -1
  46. package/core/{Budget.js → inspect/Budget.js} +21 -20
  47. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
  48. package/core/{Describe.js → inspect/Describe.js} +26 -22
  49. package/core/{Inspect.js → inspect/Inspect.js} +9 -7
  50. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  51. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  52. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  53. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  54. package/core/{UrlState.js → inspect/UrlState.js} +52 -20
  55. package/core/{catalog.js → inspect/catalog.js} +3 -3
  56. package/core/{checks.js → inspect/checks.js} +7 -5
  57. package/core/{debugView.js → inspect/debugView.js} +4 -4
  58. package/core/{describeRender.js → inspect/describeRender.js} +21 -20
  59. package/core/{describeText.js → inspect/describeText.js} +11 -6
  60. package/core/inspect/geometryWatch.js +38 -0
  61. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  62. package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
  63. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  64. package/core/{Ops.js → ops/Ops.js} +16 -11
  65. package/core/{control.js → ops/control.js} +13 -12
  66. package/core/ops/holds.js +139 -0
  67. package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
  68. package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
  69. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  70. package/core/{opsRun.js → ops/opsRun.js} +7 -4
  71. package/core/{owned.js → ops/owned.js} +14 -17
  72. package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
  73. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  74. package/core/{stacks.js → ops/stacks.js} +12 -14
  75. package/core/{wrap.js → ops/wrap.js} +8 -6
  76. package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
  77. package/core/{Saves.js → saves/Saves.js} +58 -36
  78. package/core/{saveApply.js → saves/saveApply.js} +13 -9
  79. package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
  80. package/core/{saveValues.js → saves/saveValues.js} +20 -3
  81. package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
  82. package/core/{session.js → saves/session.js} +31 -17
  83. package/core/{Rays.js → scene/Rays.js} +23 -25
  84. package/core/{Views.js → scene/Views.js} +14 -6
  85. package/core/{adaptive.js → scene/adaptive.js} +15 -8
  86. package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
  87. package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
  88. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  89. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  90. package/core/{grid.js → scene/grid.js} +4 -4
  91. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  92. package/core/{ground.js → scene/ground.js} +9 -9
  93. package/core/{movement.js → scene/movement.js} +3 -3
  94. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  95. package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
  96. package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
  97. package/core/scene/stepPoses.js +55 -0
  98. package/core/{targeting.js → scene/targeting.js} +4 -5
  99. package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
  100. package/core/{thingOps.js → scene/thingOps.js} +4 -3
  101. package/core/{things.js → scene/things.js} +18 -5
  102. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  103. package/core/{view.js → scene/view.js} +17 -16
  104. package/core/{Batching.js → stream/Batching.js} +85 -27
  105. package/core/{Stream.js → stream/Stream.js} +60 -30
  106. package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
  107. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  108. package/core/{scatter.js → stream/scatter.js} +2 -2
  109. package/core/{streamSources.js → stream/streamSources.js} +12 -7
  110. package/core/{Commits.js → threads/Commits.js} +6 -5
  111. package/core/{Jobs.js → threads/Jobs.js} +12 -10
  112. package/core/{Threads.js → threads/Threads.js} +16 -16
  113. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  114. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  115. package/core/{Clock.js → time/Clock.js} +17 -10
  116. package/core/{dayTime.js → time/dayTime.js} +5 -1
  117. package/core/{skip.js → time/skip.js} +18 -17
  118. package/core/{time.js → time/time.js} +18 -12
  119. package/core/{uiClock.js → time/uiClock.js} +4 -4
  120. package/docs/AI.md +22 -19
  121. package/docs/API.md +24 -23
  122. package/docs/CODEMAP.md +76 -183
  123. package/docs/COMMANDS.md +66 -58
  124. package/docs/CONVENTIONS.md +54 -14
  125. package/docs/MIGRATING-0.8.md +169 -0
  126. package/docs/THREE.md +78 -29
  127. package/docs/api/assets.md +12 -13
  128. package/docs/api/audio.md +6 -5
  129. package/docs/api/budget.md +4 -4
  130. package/docs/api/calendar.md +10 -11
  131. package/docs/api/cameraRig.md +29 -29
  132. package/docs/api/characters.md +23 -18
  133. package/docs/api/clock.md +1 -1
  134. package/docs/api/collision.md +12 -9
  135. package/docs/api/content.md +6 -6
  136. package/docs/api/dialogue.md +3 -3
  137. package/docs/api/engine.md +45 -43
  138. package/docs/api/events.md +3 -2
  139. package/docs/api/flow.md +1 -1
  140. package/docs/api/grids.md +1 -1
  141. package/docs/api/ground.md +4 -5
  142. package/docs/api/hud.md +2 -2
  143. package/docs/api/i18n.md +6 -6
  144. package/docs/api/input.md +7 -7
  145. package/docs/api/interactions.md +4 -4
  146. package/docs/api/inventory.md +9 -9
  147. package/docs/api/jobs.md +5 -5
  148. package/docs/api/level.md +7 -7
  149. package/docs/api/lightPool.md +1 -6
  150. package/docs/api/music.md +3 -3
  151. package/docs/api/nav.md +10 -10
  152. package/docs/api/openWorld.md +1 -1
  153. package/docs/api/particles.md +2 -2
  154. package/docs/api/photo.md +4 -2
  155. package/docs/api/pickups.md +2 -2
  156. package/docs/api/post.md +20 -3
  157. package/docs/api/quests.md +3 -3
  158. package/docs/api/rays.md +5 -7
  159. package/docs/api/rigid.md +27 -18
  160. package/docs/api/saves.md +8 -7
  161. package/docs/api/settings.md +9 -8
  162. package/docs/api/sky.md +8 -7
  163. package/docs/api/stream.md +7 -7
  164. package/docs/api/swarm.md +34 -0
  165. package/docs/api/terrain.md +7 -8
  166. package/docs/api/terrainDraw.md +1 -1
  167. package/docs/api/timeline.md +2 -2
  168. package/docs/api/tools.md +25 -22
  169. package/docs/api/vars.md +1 -1
  170. package/docs/api/vegetation.md +4 -3
  171. package/docs/api/vegetationDraw.md +1 -1
  172. package/docs/api/water.md +1 -1
  173. package/docs/api/weather.md +9 -9
  174. package/docs/api/weatherDraw.md +3 -3
  175. package/docs/api/world.md +5 -5
  176. package/docs/recipes/01-new-game.md +25 -40
  177. package/docs/recipes/02-npc.md +19 -20
  178. package/docs/recipes/03-items-pickups.md +27 -43
  179. package/docs/recipes/04-quests.md +3 -4
  180. package/docs/recipes/05-props-bake.md +29 -39
  181. package/docs/recipes/06-clock-events.md +27 -18
  182. package/docs/recipes/07-flow-scenes-pause.md +12 -17
  183. package/docs/recipes/08-weather-sky.md +88 -34
  184. package/docs/recipes/09-materials-lights-models.md +22 -36
  185. package/docs/recipes/10-blender-level.md +6 -7
  186. package/docs/recipes/11-vehicles.md +30 -22
  187. package/docs/recipes/12-navmesh.md +9 -8
  188. package/docs/recipes/13-animation.md +39 -17
  189. package/docs/recipes/14-custom-module.md +14 -13
  190. package/docs/recipes/15-perf.md +49 -26
  191. package/docs/recipes/16-dev-bridge.md +32 -52
  192. package/docs/recipes/18-world.md +36 -23
  193. package/docs/recipes/19-shooting-picking.md +4 -2
  194. package/docs/recipes/20-content-actions-save.md +30 -35
  195. package/docs/recipes/21-camera.md +33 -5
  196. package/docs/recipes/22-shop-gold.md +0 -4
  197. package/docs/recipes/23-ops.md +10 -10
  198. package/docs/recipes/26-ui-parts.md +22 -12
  199. package/docs/recipes/27-net.md +0 -2
  200. package/docs/recipes/28-terrain.md +117 -21
  201. package/docs/recipes/29-grid.md +2 -2
  202. package/docs/recipes/30-templates.md +55 -19
  203. package/docs/recipes/31-audio.md +5 -5
  204. package/docs/recipes/32-action-game.md +15 -6
  205. package/docs/recipes/33-stream-sources.md +2 -2
  206. package/docs/recipes/34-environment-lighting.md +67 -19
  207. package/docs/recipes/35-picture-from-reference.md +10 -17
  208. package/docs/recipes/36-ground-plants.md +105 -0
  209. package/docs/recipes/40-scene.md +7 -11
  210. package/docs/recipes/43-shader-patches-surfaces.md +20 -41
  211. package/docs/recipes/44-water-weather-hooks.md +48 -43
  212. package/docs/recipes/45-cascaded-shadows.md +39 -17
  213. package/docs/recipes/46-blender-art-route.md +7 -8
  214. package/docs/recipes/49-game-module-contract.md +5 -5
  215. package/docs/recipes/50-own-renderer.md +2 -2
  216. package/docs/recipes/52-around-the-picture.md +54 -98
  217. package/docs/recipes/53-ground-up-close.md +61 -24
  218. package/docs/recipes/55-mods-time-wrap.md +12 -16
  219. package/docs/recipes/56-webgpu-tsl.md +16 -14
  220. package/docs/recipes/57-control.md +9 -2
  221. package/docs/recipes/58-input.md +2 -2
  222. package/docs/recipes/59-depth-post-effects.md +1 -1
  223. package/docs/recipes/60-judge-the-picture.md +29 -24
  224. package/docs/recipes/62-picture-code.md +49 -17
  225. package/docs/recipes/63-third-person-start.md +17 -4
  226. package/docs/recipes/64-particles.md +1 -1
  227. package/docs/recipes/65-swarm.md +140 -0
  228. package/examples/action/.threedog/content-index.json +1 -1
  229. package/examples/action/GAMEMAP.md +2 -2
  230. package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
  231. package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
  232. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  233. package/examples/{sheepisland → perf-island}/main.js +8 -8
  234. package/examples/{sheepisland → perf-island}/models.js +1 -1
  235. package/examples/{sheepisland → perf-island}/params.js +1 -1
  236. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  237. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  238. package/examples/{sheepisland → perf-island}/views.js +1 -1
  239. package/examples/plain-picture/GAMEMAP.md +1 -0
  240. package/examples/rc2d/GAMEMAP.md +3 -2
  241. package/examples/rc2d/main.js +1 -3
  242. package/examples/styletest/.threedog/content-index.json +1 -1
  243. package/examples/styletest/GAMEMAP.md +3 -2
  244. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  245. package/examples/techniques/contact-shadows/main.js +1 -1
  246. package/examples/techniques/interior-light/main.js +1 -1
  247. package/examples/techniques/modular-building/README.md +7 -6
  248. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  249. package/examples/techniques/procedural-animation/README.md +1 -1
  250. package/examples/webgpu-tsl/GAMEMAP.md +1 -0
  251. package/examples/world/.threedog/content-index.json +1 -1
  252. package/examples/world/GAMEMAP.md +4 -3
  253. package/examples/world/picture/sky.js +1 -1
  254. package/index.d.ts +8 -7
  255. package/index.js +31 -31
  256. package/llms.txt +9 -13
  257. package/modules/ambience/Ambience.js +11 -8
  258. package/modules/calendar/Calendar.js +19 -19
  259. package/modules/calendar/index.js +13 -13
  260. package/modules/calendar/schedule.js +11 -6
  261. package/modules/calendar/seasons.js +7 -7
  262. package/modules/camera/FirstPersonCamera.js +2 -2
  263. package/modules/camera/FixedCamera.js +14 -15
  264. package/modules/camera/FollowCamera.js +4 -4
  265. package/modules/camera/RtsCamera.js +11 -11
  266. package/modules/camera/common.js +48 -24
  267. package/modules/camera/contract.js +1 -0
  268. package/modules/camera/projection.js +2 -2
  269. package/modules/characters/Character.js +33 -30
  270. package/modules/characters/NPC.js +27 -19
  271. package/modules/characters/assetModel.js +14 -10
  272. package/modules/characters/astar.js +7 -5
  273. package/modules/characters/behaviors.js +4 -5
  274. package/modules/characters/contract.js +2 -2
  275. package/modules/characters/index.js +168 -214
  276. package/modules/characters/moveHelpers.js +14 -3
  277. package/modules/characters/movers/common.js +16 -14
  278. package/modules/characters/movers/manual.js +1 -1
  279. package/modules/characters/movers/rapier.js +7 -6
  280. package/modules/characters/movers/simple.js +3 -3
  281. package/modules/characters/movers/support.js +8 -8
  282. package/modules/characters/npcAvoid.js +4 -4
  283. package/modules/characters/npcSim.js +23 -17
  284. package/modules/characters/npcView.js +6 -5
  285. package/modules/characters/pathAsync.js +12 -10
  286. package/modules/characters/pathWorker.js +1 -1
  287. package/modules/characters/player.js +108 -0
  288. package/modules/characters/playerStrings.js +2 -2
  289. package/modules/characters/proceduralRig.js +2 -2
  290. package/modules/characters/useModel.js +3 -3
  291. package/modules/characters/walkTo.js +11 -17
  292. package/modules/collision/Collision.js +26 -20
  293. package/modules/collision/contract.js +15 -0
  294. package/modules/content/explain.js +1 -2
  295. package/modules/content/fields.js +24 -3
  296. package/modules/content/ids.js +2 -2
  297. package/modules/content/index.js +61 -99
  298. package/modules/content/loader.js +14 -17
  299. package/modules/content/markers.js +25 -0
  300. package/modules/content/models.js +10 -7
  301. package/modules/content/packs.js +3 -3
  302. package/modules/content/parts.js +2 -2
  303. package/modules/content/places.js +35 -0
  304. package/modules/content/props.js +17 -14
  305. package/modules/content/rules.js +25 -21
  306. package/modules/content/stages.js +7 -7
  307. package/modules/content/templates.js +20 -20
  308. package/modules/content/words.js +34 -0
  309. package/modules/debug/DebugPanel.js +10 -43
  310. package/modules/flow/contract.js +1 -1
  311. package/modules/flow/index.js +11 -7
  312. package/modules/gameplay/Container.js +12 -11
  313. package/modules/gameplay/Containers.js +14 -5
  314. package/modules/gameplay/Dialogue.js +13 -11
  315. package/modules/gameplay/Interactions.js +37 -24
  316. package/modules/gameplay/Inventory.js +8 -9
  317. package/modules/gameplay/Quests.js +16 -9
  318. package/modules/gameplay/boxOps.js +1 -1
  319. package/modules/gameplay/dialogueBubbles.js +3 -4
  320. package/modules/gameplay/inventoryOps.js +0 -1
  321. package/modules/gameplay/pickups.js +22 -23
  322. package/modules/gameplay/questSave.js +3 -3
  323. package/modules/grid/Grid.js +1 -1
  324. package/modules/grid/Layer.js +4 -4
  325. package/modules/grid/index.js +7 -8
  326. package/modules/grid/preview.js +7 -7
  327. package/modules/grid/tiles.js +6 -6
  328. package/modules/hlod/index.js +37 -55
  329. package/modules/hud/index.js +17 -11
  330. package/modules/hud/parts.js +4 -4
  331. package/modules/level/contract.js +16 -0
  332. package/modules/level/heightfield.js +12 -10
  333. package/modules/level/index.js +47 -152
  334. package/modules/level/load.js +79 -0
  335. package/modules/level/meshes.js +65 -0
  336. package/modules/level/nodes.js +6 -7
  337. package/modules/lights/index.js +28 -181
  338. package/modules/lights/slots.js +93 -0
  339. package/modules/lights/sources.js +88 -0
  340. package/modules/music/Music.js +30 -26
  341. package/modules/music/rules.js +1 -1
  342. package/modules/nav/contract.js +14 -0
  343. package/modules/nav/index.js +11 -10
  344. package/modules/net/Client.js +7 -7
  345. package/modules/net/Host.js +7 -7
  346. package/modules/net/Net.js +1 -1
  347. package/modules/net/index.js +5 -4
  348. package/modules/net/sync.js +2 -2
  349. package/modules/net/transports.js +2 -2
  350. package/modules/particles/Particles.js +11 -8
  351. package/modules/particles/effect.js +7 -5
  352. package/modules/particles/shaders.js +2 -1
  353. package/modules/photo/Photo.js +15 -17
  354. package/modules/rigid/RigidBodies.js +66 -43
  355. package/modules/rigid/Vehicles.js +2 -3
  356. package/modules/rigid/ragdoll.js +287 -0
  357. package/modules/rigid/ragdollBones.js +159 -0
  358. package/modules/rigid/sync.js +6 -6
  359. package/modules/settings/Settings.js +108 -39
  360. package/modules/settings/apply.js +6 -6
  361. package/modules/settings/sections.js +16 -14
  362. package/modules/settings/view.js +3 -3
  363. package/modules/sky/Sky.js +29 -22
  364. package/modules/sky/clouds.js +7 -7
  365. package/modules/sky/dome.js +33 -20
  366. package/modules/sky/domeLayers.js +9 -9
  367. package/modules/sky/environment.js +6 -6
  368. package/modules/sky/frame.js +19 -10
  369. package/modules/sky/season.js +7 -1
  370. package/modules/sky/shader.js +24 -25
  371. package/modules/sky/skyModule.js +14 -27
  372. package/modules/sky/tint.js +1 -1
  373. package/modules/swarm/Swarm.js +346 -0
  374. package/modules/swarm/draw.js +68 -0
  375. package/modules/swarm/grid.js +63 -0
  376. package/modules/terrain/ChunkManager.js +70 -52
  377. package/modules/terrain/chunkQueries.js +7 -24
  378. package/modules/terrain/chunkWorker.js +1 -1
  379. package/modules/terrain/draw.js +14 -11
  380. package/modules/terrain/index.js +28 -34
  381. package/modules/terrain/terrainColorMap.js +6 -3
  382. package/modules/terrain/terrainDefaults.js +2 -1
  383. package/modules/terrain/terrainEdit.js +32 -27
  384. package/modules/terrain/terrainGen.js +17 -12
  385. package/modules/terrain/terrainIsland.js +2 -2
  386. package/modules/terrain/terrainMesh.js +7 -6
  387. package/modules/terrain/terrainShape.js +8 -10
  388. package/modules/terrain/terrainShapeMain.js +3 -3
  389. package/modules/timeline/Timeline.js +27 -19
  390. package/modules/timeline/Tween.js +6 -6
  391. package/modules/timeline/shots.js +5 -7
  392. package/modules/triggers/index.js +9 -9
  393. package/modules/vegetation/Vegetation.js +30 -23
  394. package/modules/vegetation/densityMap.js +4 -7
  395. package/modules/vegetation/draw.js +23 -18
  396. package/modules/vegetation/groundChunks.js +11 -31
  397. package/modules/vegetation/index.js +8 -6
  398. package/modules/vegetation/modelGeometry.js +3 -6
  399. package/modules/vegetation/nearFade.js +1 -1
  400. package/modules/water/Water.js +16 -16
  401. package/modules/water/surface.js +3 -3
  402. package/modules/weather/Weather.js +41 -30
  403. package/modules/weather/particles.js +8 -8
  404. package/modules/weather/weatherDraw.js +22 -18
  405. package/modules/world/World.js +8 -8
  406. package/modules/world/explain.js +1 -1
  407. package/modules/world/index.js +18 -12
  408. package/modules/world/persist.js +73 -25
  409. package/modules/world/pos.js +4 -4
  410. package/modules/world/records.js +28 -8
  411. package/modules/world/sim.js +4 -4
  412. package/modules/world/state.js +12 -5
  413. package/modules/world/thingSource.js +4 -2
  414. package/modules/world/views.js +11 -9
  415. package/package.json +42 -7
  416. package/presets.js +1 -3
  417. package/render/PostFX.js +39 -27
  418. package/render/backend.js +26 -32
  419. package/render/cascades.js +17 -12
  420. package/render/cascades.tsl.js +5 -8
  421. package/render/daylight.js +20 -3
  422. package/render/detail.js +8 -7
  423. package/render/effects.js +28 -25
  424. package/render/fuse.js +3 -3
  425. package/render/fx/cloudShadow.tsl.js +3 -3
  426. package/render/fx/detail.tsl.js +1 -1
  427. package/render/fx/index.js +5 -10
  428. package/render/fx/library.tsl.js +11 -0
  429. package/render/fx/lighting.tsl.js +2 -1
  430. package/render/fx/nodeErrors.tsl.js +2 -2
  431. package/render/fx/objectOrigin.tsl.js +1 -2
  432. package/render/fx/patchNodes.tsl.js +5 -15
  433. package/render/fx/postWebGPU.tsl.js +27 -23
  434. package/render/fx/sky.tsl.js +15 -17
  435. package/render/fx/uniforms.tsl.js +4 -4
  436. package/render/fx/wind.tsl.js +1 -1
  437. package/render/fxNumbers.js +3 -0
  438. package/render/layers.js +1 -1
  439. package/render/lighting.js +5 -3
  440. package/render/lightmap.js +20 -20
  441. package/render/lights.js +6 -6
  442. package/render/lit.js +24 -0
  443. package/render/materials.js +8 -7
  444. package/render/mergeCommon.js +22 -0
  445. package/render/modeling.js +2 -2
  446. package/render/occlusion.js +20 -4
  447. package/render/ownFrame.js +4 -4
  448. package/render/patches.js +13 -13
  449. package/render/postWebGL.js +12 -10
  450. package/render/probes.js +16 -19
  451. package/render/recordSweep.js +117 -0
  452. package/render/shaderErrors.js +10 -9
  453. package/render/shadowCache.tsl.js +107 -0
  454. package/render/shadowTypes.js +9 -0
  455. package/{core → render}/shadows.js +57 -11
  456. package/render/slots.js +7 -7
  457. package/render/terms.js +22 -24
  458. package/render/uniformDecl.js +1 -1
  459. package/types/core.d.ts +200 -153
  460. package/types/gameplay.d.ts +163 -91
  461. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  462. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  463. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  464. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
  465. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  466. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  467. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +12 -8
  468. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  469. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
  470. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
  471. package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
  472. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
  473. package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
  474. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  475. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
  476. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  477. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
  478. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  479. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  480. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  481. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  482. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  483. package/types/generated/modules/grid/Layer.d.ts +1 -1
  484. package/types/generated/modules/grid/index.d.ts +3 -3
  485. package/types/generated/modules/music/Music.d.ts +7 -5
  486. package/types/generated/modules/particles/Particles.d.ts +1 -1
  487. package/types/generated/modules/sky/Sky.d.ts +21 -10
  488. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  489. package/types/generated/modules/timeline/Timeline.d.ts +2 -1
  490. package/types/generated/modules/water/Water.d.ts +1 -0
  491. package/types/generated/modules/weather/Weather.d.ts +16 -12
  492. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  493. package/types/generated/modules/world/World.d.ts +5 -3
  494. package/types/generated/render/PostFX.d.ts +17 -11
  495. package/types/generated/render/materials.d.ts +1 -0
  496. package/types/generated/render/occlusion.d.ts +9 -0
  497. package/types/generated/render/patches.d.ts +1 -0
  498. package/types/generated/ui/Focus.d.ts +1 -0
  499. package/types/generated/ui/UI.d.ts +1 -0
  500. package/types/nav.d.ts +11 -11
  501. package/types/physics.d.ts +99 -70
  502. package/types/tsl.d.ts +37 -4
  503. package/types/world.d.ts +38 -71
  504. package/ui/Focus.js +10 -9
  505. package/ui/Parts.js +4 -3
  506. package/ui/UI.js +7 -7
  507. package/ui/defaults.js +3 -2
  508. package/ui/theme.js +5 -3
  509. package/core/assetEntry.js +0 -109
  510. package/core/holds.js +0 -134
  511. package/core/shadowTypes.js +0 -16
  512. package/core/util.js +0 -17
  513. package/docs/MIGRATING-0.3.md +0 -248
  514. package/docs/MIGRATING-0.4.md +0 -320
  515. package/docs/MIGRATING-0.5.md +0 -68
  516. package/docs/MIGRATING-0.6.md +0 -126
  517. package/docs/PERF.md +0 -245
  518. package/docs/recipes/36-sky-ground-plants.md +0 -158
  519. package/docs/recipes/37-terrain-hooks.md +0 -115
  520. package/docs/recipes/38-environment-hooks.md +0 -67
  521. package/docs/recipes/42-terrain-shape.md +0 -64
  522. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  523. package/docs/recipes/54-three-idioms.md +0 -88
  524. package/examples/plain-picture/FINDINGS.md +0 -53
  525. /package/core/{Vars.js → base/Vars.js} +0 -0
  526. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  527. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  528. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  529. /package/core/{actor.js → ops/actor.js} +0 -0
  530. /package/core/{opsFail.js → ops/opsFail.js} +0 -0
  531. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  532. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  533. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  534. /package/core/{tier.js → scene/tier.js} +0 -0
  535. /package/core/{cells.js → stream/cells.js} +0 -0
  536. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  537. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  538. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  539. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  540. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  541. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  542. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  543. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  544. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -12,32 +12,28 @@
12
12
  // Clouds: sky({ clouds: { color, shade, coverage: 1, scale: 0.35, speed: [x, z], kind, ... } }) (coverage follows weather; see clouds.js); your own function: engine.sky.clouds(spec)
13
13
  // three.js objects: dome (dome Mesh), sunDir (Vector3 toward the sun). Dome layers: domeLayers.js
14
14
  // Skybox: engine.sky.replace('sky.jpg') (equirectangular panorama) replaces the gradient sky; brightness follows time
15
- import { engineOwned } from '../../core/things.js';
15
+ import { engineOwned } from '../../core/scene/things.js';
16
16
  import * as THREE from 'three';
17
- import { readParams } from '../../core/params.js';
18
- import { NEUTRAL_KEYFRAMES, checkKeyframes, makeSkyUniforms, makeDome, loadSkybox } from './shader.js';
17
+ import { readParams } from '../../core/base/params.js';
18
+ import { NEUTRAL_KEYFRAMES, checkKeyframes, makeSkyUniforms, makeDome } from './shader.js';
19
19
  import { defineSkyPoints } from './tint.js';
20
20
  import { environmentMethods } from './environment.js';
21
- import { codedError } from '../../core/errorHints.js';
22
21
  import { updateSky, watchOwned, skyLight } from './frame.js';
23
22
  import { prepareDome, domeEntries } from './dome.js';
24
- import { parseClock } from '../../core/dayTime.js';
23
+ import { parseClock, sunHeightAt } from '../../core/time/dayTime.js';
25
24
  import { onRendererSwap } from '../../render/backend.js';
26
25
  // sky({ dim }) (SkyPictureOptions.dim in types/world.d.ts): each picture decision the sky makes for every game, on unless the game turns it off (engine.sky.dim is the live value)
27
26
  const DIM_PARAMS = {
28
27
  tint: { type: 'bool', default: true, desc: 'a sky.tint color (weather grey, a cave tint) dims with the sky\'s own light, so a grey rain tint stays dark at night' },
29
- stars: { type: 'bool', default: true, desc: 'stars fade with the weather\'s cloud cover (uCloud), not only behind drawn clouds' },
28
+ stars: { type: 'bool', default: true, desc: 'stars fade with the weather\'s cloud cover (uWeatherCloud), not only behind drawn clouds' },
30
29
  };
31
30
  /** @import { Object3D, Vector3 } from '../../types/common' */
32
- /** @import { SkyOptions } from '../../types/world' */
33
- /** @import { Handle } from '../../types/common' */
34
31
  /** engine.sky */
35
32
  export class Sky {
36
33
  /** @internal */
37
34
  constructor(engine, { time = 0.33, ...over } = {}) {
38
35
  /** @internal */ this.engine = engine;
39
36
  const st = over;
40
- if (st.environment) throw codedError('sky-option', 'sky({ environment }) is gone: call engine.sky.environment({ into: engine.scene }) for the sky as a map; an asset map is plain three.js (recipes/34)');
41
37
  /**
42
38
  * The time of day drawn while no calendar is installed (0-1; sky({ time: '17:30' }) or applyState({ time })); with engine.calendar the sky
43
39
  * draws the calendar's time and this is unused @type {number}
@@ -63,7 +59,11 @@ export class Sky {
63
59
  const scene = engine.scene;
64
60
 
65
61
  const domeParts = prepareDome(this, st); // backdrop, dome layers (dome.js)
66
- /** @internal */ this.uniforms = { ...makeSkyUniforms(st, engine.uniforms), ...domeParts.uniforms };
62
+ /**
63
+ * The dome's { value } objects, live on both renderers: the built-in ones (the same objects as engine.uniforms where the names match) and the uniforms
64
+ * given to engine.sky.clouds() and engine.sky.layer(), which join here once the call has run @type {Record<string, { value: any }>}
65
+ */
66
+ this.uniforms = { ...makeSkyUniforms(st, engine.uniforms), ...domeParts.uniforms };
67
67
  /** Dome mesh @type {Object3D} */
68
68
  this.dome = makeDome(this.uniforms, st, domeParts, engine);
69
69
  scene.add(engineOwned('sky', this.dome));
@@ -78,16 +78,13 @@ export class Sky {
78
78
  this._entries?.reapply();
79
79
  this._envSwap();
80
80
  });
81
- // Skybox (panorama): replaces the gradient sky when present
81
+ // Skybox (panorama) while engine.sky.replace gave one
82
82
  /** @internal */ this.skybox = null;
83
- if (st.skybox) loadSkybox(this, st.skybox);
84
83
 
85
- /** Sun direction (unit vector toward the sun) @type {Vector3} */
86
- this.sunDir = new THREE.Vector3();
87
84
  /**
88
85
  * Sun orbit: tilt = north-south tilt, sway = east-west swing, distance = light distance (meters) @type {{ tilt: number, sway: number, distance: number }}
89
86
  */
90
- this.orbit = { tilt: st.orbitTilt ?? 0.45, sway: st.orbitSway ?? 0.8, distance: 160 };
87
+ this.orbit = { tilt: 0.45, sway: 0.8, distance: 160 };
91
88
  // the engine's own box on its placeholder sun, the sky's one job there: what is written on that light stays (render/lights.js holds the defaults).
92
89
  // createEngine({ lights: false }): the sun is not in the scene, nothing to place
93
90
  const box = engine.lights.sun.parent ? engine.shadows.sunBox({ follow: 'focus', snap: 0.5, ahead: 0 }, () => this.orbit.distance) : null;
@@ -106,6 +103,7 @@ export class Sky {
106
103
  // brightest row of the sky's ambient light (ambient column x the hemi color's brightness, frame.js skyLight): the sky's light now / this is
107
104
  // the 0-1 scale the sky.tint color (weather grey) follows
108
105
  /** @internal */ this._lightPeak = Math.max(...this.kf.map(k => skyLight(k[1], k[2], k[4])));
106
+ /** @internal brightest row's ambient column: a skybox is at full brightness there (frame.js) */ this._ambientPeak = Math.max(...this.kf.map(k => k[4]));
109
107
  }
110
108
 
111
109
  /**
@@ -117,6 +115,14 @@ export class Sky {
117
115
  */
118
116
  keyframes(rows) { checkKeyframes(rows); this._setKeyframes(rows); }
119
117
 
118
+ /**
119
+ * Sun direction (unit vector toward the sun): the same vector as engine.uniforms.uSunDir. Computed each frame from the time and orbit until a game writes either,
120
+ * then the value is the game's (the sun at a compass direction of your choice); engine.autoView.manual('sunDir', false) gives it back.
121
+ * @type {Vector3}
122
+ */
123
+ get sunDir() { return this.uniforms.uSunDir.value; }
124
+ set sunDir(v) { this.uniforms.uSunDir.value.copy(v); }
125
+
120
126
  /**
121
127
  * Your own cloud function on the dome: glsl defines `vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)`,
122
128
  * tsl is its WebGPURenderer form (ctx) => vec4 node; each renderer needs its own form (modules/sky/clouds.js). null gives the built-in kind back.
@@ -138,12 +144,13 @@ export class Sky {
138
144
  layer(name, spec) { this._entries.layer(name, spec); }
139
145
 
140
146
  /**
141
- * Replace or hide the dome: a skybox asset name (equirectangular panorama), a THREE.Texture / CubeTexture, or your own THREE.Object3D sky; null gives the dome back.
147
+ * Replace or hide the dome: a skybox asset name (equirectangular panorama), a THREE.Texture / CubeTexture, or your own THREE.Object3D sky; null gives the dome back,
148
+ * false draws no sky (the scene shows its base background, the signals keep running).
142
149
  * The engine never writes your object: it hides the dome, adds your object to the scene only when it has no parent, puts a plain texture's panorama
143
150
  * mapping on a clone, and keeps feeding engine.uniforms (uSunDir, uWind ...).
144
151
  * @example engine.sky.replace(new SkyMesh());
145
152
  * @example engine.sky.replace(null);
146
- * @param {string | import('three').Texture | Object3D | null} sky
153
+ * @param {string | import('three').Texture | Object3D | null | false} sky
147
154
  * @returns {void}
148
155
  */
149
156
  replace(sky) { this._entries.replace(sky); }
@@ -155,10 +162,10 @@ export class Sky {
155
162
  get backdrop() { return this._backdrop?.color ?? null; }
156
163
  set backdrop(v) { this._entries.backdrop(v); }
157
164
 
158
- /** Time of day being drawn, 0-1: engine.calendar.timeOfDay, or fixedTime without a calendar. Read-only: the time itself is the calendar's */
165
+ /** Time of day being drawn, 0-1: engine.calendar.timeOfDay, or fixedTime without a calendar. Read-only: the time itself is the calendar's @experimental */
159
166
  get drawnTime() { return this.engine.calendar?.timeOfDay ?? this.fixedTime; }
160
- /** Sun elevation -1 (midnight) ... 0 (horizon) ... 1 (noon) of the drawn sun (the calendar's daylight is the gameplay value) */
161
- get sunHeight() { return Math.sin((this.drawnTime - 0.25) * Math.PI * 2); }
167
+ /** Sun elevation -1 (midnight) ... 0 (horizon) ... 1 (noon) of the drawn sun (the calendar's daylight is the gameplay value) @experimental */
168
+ get sunHeight() { return sunHeightAt(this.drawnTime); }
162
169
  /** Whether the drawn sun is above the horizon (picture functions: ({ sky }) => sky.isDay ? ...; gameplay reads engine.calendar.isDay) */
163
170
  get isDay() { return this.sunHeight > 0; }
164
171
  /** Daylight of the drawn sun 0-1 (0 at night, 1 at noon) */
@@ -173,7 +180,7 @@ export class Sky {
173
180
 
174
181
  /**
175
182
  * Render the sky into an environment map. Only after this call is anything built: a PMREM target, rebuilt when the sky changed and interval seconds passed
176
- * (default 1, 4 times longer on a low-tier device). With into, that object's .environment gets the map at each rebuild (a map you wrote there yourself stays); without it nothing
183
+ * (default 1, 4 on a low-tier device). With into, that object's .environment gets the map at each rebuild (a map you wrote there yourself stays); without it nothing
177
184
  * is written anywhere and you read handle.texture. handle.remove() takes the map off and frees it. One at a time. Intensity and rotation are three.js: scene.environmentIntensity.
178
185
  * @example const env = engine.sky.environment({ into: engine.scene });
179
186
  * @example env.remove();
@@ -182,5 +189,5 @@ export class Sky {
182
189
  */
183
190
  environment(options) { return environmentMethods._envStart.call(this, options); }
184
191
  }
185
- // Mixed in from shadow.js and environment.js; methods the class already defines are kept
192
+ // Mixed in from environment.js; methods the class already defines are kept
186
193
  for (const [k, f] of Object.entries(environmentMethods)) if (!Object.hasOwn(Sky.prototype, k)) Sky.prototype[k] = f;
@@ -7,15 +7,15 @@
7
7
  // time seconds (engine.uniforms.uTime); sunDir unit vector towards the sun (moon is opposite); night 0 day .. 1 night
8
8
  // lit / shade cloud colors (clouds.color / clouds.shade); cover = weather cloud amount * clouds.coverage, 0..1+
9
9
  // returns rgb = final cloud color, a = opacity 0..1 (the dome does mix(sky, rgb, a)); apply your own horizon fade
10
- // In scope for your code: threedogHash(vec2), threedogNoise(vec2), the built-in cloud uniforms (uCloudScale, uCloudSpeed,
11
- // uCloudHorizon, uCloudFade, uCloudSoft, uCloudOpacity, uCloudMul, uCloudWeights, uCloudRelief) and the patch's own uniforms.
10
+ // In scope for your code: threedogHash(vec2), threedogNoise(vec2), the built-in cloud uniforms (uSkyCloudScale, uSkyCloudSpeed,
11
+ // uCloudHorizon, uCloudFade, uCloudSoft, uCloudOpacity, uCloudMul, uCloudWeights, uCloudRelief) and the patch's own uniforms (later writes: engine.sky.uniforms.uK.value).
12
12
  // WebGPURenderer draws the hook's tsl form instead ({ glsl, tsl, uniforms }; render/fx/sky.tsl.js): tsl: (ctx) => vec4 node, ctx = { dir, time,
13
13
  // sunDir, night, lit, shade, cover (the same arguments as nodes), clouds (the built-in kind's vec4, the value so far), uniforms (the dome's
14
14
  // uniforms as nodes, the patch's own included), fx: { noise, hash }, tsl (three/tsl) }. Each renderer needs its own form; a missing one throws by name.
15
15
  import * as THREE from 'three';
16
- import { closest } from '../../core/validate.js';
16
+ import { closest, oneForm } from '../../core/base/validate.js';
17
17
  import { declareUniforms } from '../../render/uniformDecl.js';
18
- import { codedError } from '../../core/errorHints.js';
18
+ import { codedError } from '../../core/base/errorHints.js';
19
19
  import { SKY as K, glslFloat as f } from '../../render/fxNumbers.js';
20
20
 
21
21
  const KINDS = ['plane', 'cumulus'];
@@ -28,7 +28,7 @@ const DEFAULTS = {
28
28
 
29
29
  // Original picture: one plane projected onto the sky (cells shrink towards the horizon), 3 fixed noise layers.
30
30
  const PLANE = `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cov){
31
- vec2 cp = d.xz / (d.y + uCloudHorizon) * uCloudScale + uCloudSpeed * time;
31
+ vec2 cp = d.xz / (d.y + uCloudHorizon) * uSkyCloudScale + uSkyCloudSpeed * time;
32
32
  float cn = threedogNoise(cp) * uCloudWeights.x + threedogNoise(cp * uCloudMul.x + 7.0) * uCloudWeights.y + threedogNoise(cp * uCloudMul.y) * uCloudWeights.z;
33
33
  float cloud = smoothstep(1.0 - cov, 1.0 - cov + uCloudSoft, cn) * smoothstep(uCloudFade.x, uCloudFade.y, d.y);
34
34
  vec3 cc = mix(shade, lit, smoothstep(${f(K.planeTone[0])}, ${f(K.planeTone[1])}, cn)) * (${f(K.nightDim)} + ${f(1 - K.nightDim)} * (1.0 - night));
@@ -45,7 +45,7 @@ const CUMULUS = `float threedogCumulusDensity(vec2 p){
45
45
  return s / ${f(K.norm)};
46
46
  }
47
47
  vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cov){
48
- vec2 cp = d.xz / (d.y + uCloudHorizon) * uCloudScale + uCloudSpeed * time;
48
+ vec2 cp = d.xz / (d.y + uCloudHorizon) * uSkyCloudScale + uSkyCloudSpeed * time;
49
49
  vec2 toSun = normalize(sunDir.xz + vec2(0.0001, 0.0)) * ${f(K.toSun)};
50
50
  float n0 = threedogCumulusDensity(cp), n1 = threedogCumulusDensity(cp + toSun);
51
51
  float t = 1.0 - cov * ${f(K.cover)};
@@ -70,7 +70,7 @@ export function resolveClouds(c, hook, gpu = false) {
70
70
  let glsl = kind === 'cumulus' ? CUMULUS : PLANE;
71
71
  if (h?.tsl != null && typeof h.tsl !== 'function') throw codedError('sky-option', "engine.sky.clouds(): tsl must be (ctx) => vec4 node (WebGPURenderer); see modules/sky/clouds.js");
72
72
  // gpu: the node dome draws h.tsl (render/fx/sky.tsl.js checks it); the GLSL, when given too, is still checked here
73
- if (h && h.glsl == null && !gpu) throw codedError('sky-option', "engine.sky.clouds() has only a tsl form, which WebGLRenderer cannot draw: give glsl too ({ glsl, tsl, uniforms })");
73
+ if (h && h.glsl == null && !gpu) throw oneForm('sky-option', 'engine.sky.clouds()', false);
74
74
  if (h?.glsl != null) {
75
75
  if (typeof h.glsl !== 'string' || !/vec4\s+threedogClouds\s*\(/.test(h.glsl)) throw codedError('sky-option', "engine.sky.clouds(): glsl must define `vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)` returning (rgb color, alpha); see modules/sky/clouds.js");
76
76
  glsl = h.glsl;
@@ -1,29 +1,29 @@
1
1
  // The dome's game entries (helper of Sky.js): the backdrop, the cloud function, the dome layers, and handing the dome over to the game's own sky.
2
2
  // A hook change rebuilds the dome shader text and recompiles that one material (a hitch, so do it at a scene change, not every frame).
3
3
  // Each renderer draws its own form of a hook: glsl on WebGLRenderer, tsl ((ctx) => vec4 node, render/fx/sky.tsl.js) on WebGPURenderer; a missing one throws by name.
4
- import { engineOwned } from '../../core/things.js';
4
+ import { engineOwned } from '../../core/scene/things.js';
5
5
  import * as THREE from 'three';
6
6
  import { resolveClouds } from './clouds.js';
7
7
  import { resolveDomeLayers } from './domeLayers.js';
8
8
  import { domeFragment, loadSkybox, skyNodes } from './shader.js';
9
9
  import { DOME_FOG } from './fog.js';
10
- import { codedError } from '../../core/errorHints.js';
10
+ import { codedError } from '../../core/base/errorHints.js';
11
11
  import { isWebGPU } from '../../render/backend.js';
12
12
 
13
13
  const isColorLike = v => typeof v === 'number' || typeof v === 'string' || !!v?.isColor;
14
14
 
15
- /** The fog band's uniforms and the dome layers for a new Sky: the extra dome uniforms and GLSL ({ uniforms, decl, body }), and the layers for a node dome */
15
+ /** The fog band's uniforms and GLSL for a new Sky: the extra dome parts ({ uniforms, decl, body }); it starts with no layers, engine.sky.layer adds them */
16
16
  export function prepareDome(sky, st) {
17
17
  sky._backdrop = resolveBackdrop(st);
18
- const f = DOME_FOG, l = resolveDomeLayers(st.layers, { gpu: isWebGPU(sky.engine.renderer) });
18
+ const f = DOME_FOG;
19
19
  // the fog object belongs to the game and may be replaced: read its color at draw time (fog.js fogBand turns the band on)
20
- const uniforms = { ...l.uniforms, uFogBand: { value: 0 }, uFogColor: { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } } };
21
- return { uniforms, decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body, layers: l.layers };
20
+ const uniforms = { uFogBand: { value: 0 }, uFogColor: { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } } };
21
+ return { uniforms, decl: f.decl, body: f.body, layers: [] };
22
22
  }
23
23
 
24
24
  // backdrop: one flat color instead of the dome: no gradient, horizon, sun / moon disk, stars or clouds. The color goes straight to scene.background
25
25
  // (no tone mapping), so what is written is what shows, and uSkyHorizon reports it so a game's fog can fade far things into it.
26
- export function resolveBackdrop(st) {
26
+ function resolveBackdrop(st) {
27
27
  const v = st.backdrop;
28
28
  if (v == null) return null;
29
29
  if (!isColorLike(v)) throw codedError('sky-option', `sky backdrop must be a color (0xefebe4, '#efebe4'); got ${typeof v === 'function' ? 'a function' : JSON.stringify(v)}. A color that changes: engine.sky.backdrop.set(...) each frame`);
@@ -37,7 +37,9 @@ export function resolveBackdrop(st) {
37
37
  export function domeEntries(sky, st) {
38
38
  const e = sky.engine, scene = e.scene, U = sky.uniforms;
39
39
  let cloudsHook = null, added = null, addedHere = false;
40
- const layers = new Map((Array.isArray(st.layers) ? st.layers : []).map((l, i) => [l?.name ?? `layer${i}`, l]));
40
+ const layers = new Map();
41
+ // a skybox dims with the hour through scene.backgroundIntensity: it comes off with the skybox, or whatever shows next stays dimmed
42
+ const undim = () => { if (sky.skybox && scene.background === sky.skybox) scene.backgroundIntensity = 1; };
41
43
 
42
44
  // The dome shader from a clouds function and layers; throws (changing nothing) when a hook is not valid for its contract
43
45
  const rebuild = (hook, map) => {
@@ -50,10 +52,12 @@ export function domeEntries(sky, st) {
50
52
  const text = domeFragment(cl, { decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body });
51
53
  return { text, uniforms: { ...cl.uniforms, ...l.uniforms } };
52
54
  };
53
- const apply = r => {
55
+ // given: the uniforms of the hook being set. Its start values replace the old ones under those names (in place: a game's handle stays live);
56
+ // every other hook's uniforms keep what was written since
57
+ const apply = (r, given) => {
54
58
  // node dome: a new color node over the uniforms with the hook's own added (setHooks throws first on a bad hook, the dome unchanged)
55
59
  if (r.nodes) skyNodes(e).setHooks(sky.dome.material, { ...r.uniforms, ...U }, r.nodes.kind, e, r.nodes);
56
- for (const [k, u] of Object.entries(r.uniforms)) if (!(k in U)) U[k] = u;
60
+ for (const [k, u] of Object.entries(r.uniforms)) { if (!(k in U)) U[k] = u; else if (given && k in given) U[k].value = u.value; }
57
61
  if (r.nodes) return;
58
62
  if (sky.dome.material.fragmentShader === r.text) return;
59
63
  sky.dome.material.fragmentShader = r.text; sky.dome.material.needsUpdate = true;
@@ -62,30 +66,32 @@ export function domeEntries(sky, st) {
62
66
  return {
63
67
  /** the renderer swap (Sky.js) builds a fresh dome; the hooks set since then go back on it */
64
68
  reapply() { apply(rebuild(cloudsHook, layers)); },
65
- clouds(spec) { apply(rebuild(spec, layers)); cloudsHook = spec ?? null; },
69
+ clouds(spec) { apply(rebuild(spec, layers), spec?.uniforms); cloudsHook = spec ?? null; },
66
70
  layer(name, spec) {
67
- if (typeof name !== 'string' || !/^[\w-]+$/.test(name)) throw codedError('sky-option', `engine.sky.layer(name, spec): name is a word such as 'aurora'; got ${JSON.stringify(name)}`);
71
+ if (typeof name !== 'string' || !name) throw codedError('sky-option', `engine.sky.layer(name, spec): name is a non-empty string such as 'aurora'; got ${JSON.stringify(name)}`);
68
72
  const next = new Map(layers);
69
73
  if (spec == null) next.delete(name); else next.set(name, spec);
70
- apply(rebuild(cloudsHook, next)); // throws before anything changes when the layer's GLSL is not valid
74
+ apply(rebuild(cloudsHook, next), spec?.uniforms); // throws before anything changes when the layer's GLSL is not valid
71
75
  layers.clear(); for (const [k, v] of next) layers.set(k, v);
72
76
  },
73
77
  backdrop(v) {
74
- if (v == null) { sky._backdrop = null; sky.dome.visible = !sky.skybox && !added; scene.background = sky.skybox ?? null; sky._oBg.mark(); return; }
78
+ if (v == null) { sky._backdrop = null; sky.dome.visible = !sky.skybox && !added && !sky._noSky; scene.background = sky.skybox ?? (sky._noSky ? e.baseBackground : null); sky._oBg.mark(); return; }
75
79
  if (sky._backdrop && isColorLike(v)) { sky._backdrop.color.set(v); return; }
76
- sky._backdrop = resolveBackdrop({ backdrop: v, skybox: sky.skybox }); // the sky writes scene.background and hides the dome each frame (frame.js)
80
+ sky._backdrop = resolveBackdrop({ backdrop: v }); // the sky writes scene.background and hides the dome each frame (frame.js)
77
81
  },
78
82
  // The game's own sky (three/addons Sky, a ShaderMaterial dome, a skybox texture) is never written: the engine only hides its dome, adds the
79
83
  // object to the scene when it has no parent yet (and takes it out again on hand-back only then), and keeps feeding time / weather / season
80
- // through engine.uniforms (uSunDir, uDaylight, uTimeOfDay, uWind, uCloud ...) and the day / season / weather events. A plain Texture gets its
84
+ // through engine.uniforms (uSunDir, uDaylight, uTimeOfDay, uWind, uWeatherCloud ...) and the day / season / weather events. A plain Texture gets its
81
85
  // panorama mapping on a clone, so the game's texture object stays as it was.
82
86
  replace(impl) {
83
- if (impl === false) throw codedError('sky-option', 'engine.sky.replace(false): false is not a sky; give the dome back with engine.sky.replace(null)');
84
- if (impl != null && typeof impl !== 'string' && !impl.isTexture && !impl.isObject3D) throw codedError('sky-option', 'engine.sky.replace(sky): sky is a skybox asset name, a THREE.Texture or a THREE.Object3D; null gives the dome back');
87
+ if (impl !== false && impl != null && typeof impl !== 'string' && !impl.isTexture && !impl.isObject3D) throw codedError('sky-option', 'engine.sky.replace(sky): sky is a skybox asset name, a THREE.Texture or a THREE.Object3D; null gives the dome back, false draws no sky');
85
88
  if (added) { if (addedHere) scene.remove(added); added = null; addedHere = false; }
86
- sky._ownSky = null;
89
+ undim();
90
+ sky._ownSky = null; sky._noSky = impl === false; sky._panorama = null;
91
+ // false: no drawn sky. The signals keep running and the scene shows its base background (a game's palette color lives there)
92
+ if (impl === false) { sky.skybox = null; sky._backdrop = null; sky.dome.visible = false; scene.background = e.baseBackground; sky._oBg.manual(false); sky._oBg.mark(); return; }
87
93
  if (impl == null) { sky.skybox = null; scene.background = sky._backdrop?.color ?? null; sky.dome.visible = !sky._backdrop; sky._oBg.manual(false); sky._oBg.mark(); return; }
88
- sky.dome.visible = false;
94
+ sky.dome.visible = false; sky._backdrop = null; // a backdrop left on would be written over this sky every frame
89
95
  if (typeof impl === 'string') loadSkybox(sky, impl);
90
96
  else if (impl.isTexture) {
91
97
  const tex = impl.isCubeTexture || impl.mapping !== THREE.UVMapping ? impl : Object.assign(impl.clone(), { mapping: THREE.EquirectangularReflectionMapping });
@@ -96,5 +102,12 @@ export function domeEntries(sky, st) {
96
102
  }
97
103
  sky._oBg.mark();
98
104
  },
105
+ /** the module goes: the game's own sky added here and a background the sky wrote go with it; a background the game wrote stays */
106
+ dispose() {
107
+ sky._panorama = null;
108
+ if (added && addedHere) scene.remove(added);
109
+ undim();
110
+ if (scene.background && (scene.background === sky.skybox || scene.background === sky._backdrop?.color)) scene.background = e.baseBackground;
111
+ },
99
112
  };
100
113
  }
@@ -1,37 +1,37 @@
1
1
  // Extra sky layers drawn on the dome after the clouds and stars (rainbow, aurora, a painted band): engine.sky.layer(name, spec).
2
2
  // Default none, and then the dome shader text is exactly the plain one.
3
- // layers: [{ glsl, uniforms?, order?, blend? }]
3
+ // spec: { glsl, uniforms?, order?, blend? }
4
4
  // glsl defines `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)`: dir = unit view direction (whole sphere,
5
5
  // dir.y < 0 below the horizon), time = engine.uniforms.uTime seconds, sunDir toward the sun, night 0 day .. 1 night;
6
6
  // returns (rgb, amount). Each layer's function is renamed (threedogSkyLayer0, 1...), so layers never clash.
7
- // uniforms like clouds.uniforms (render/uniformDecl.js): { uK: 0.4, uTint: new THREE.Color(...), uMap: texture } -> engine.sky.uniforms.uK
7
+ // uniforms as in engine.sky.clouds({ uniforms }) (render/uniformDecl.js): { uK: 0.4, uTint: new THREE.Color(...), uMap: texture } -> engine.sky.uniforms.uK.value, live on both renderers
8
8
  // order draw order among layers (smaller first, default 0, ties keep list order)
9
9
  // blend 'mix' (default: col = mix(col, rgb, amount)) | 'add' (col += rgb * amount: glows such as an aurora)
10
10
  // tsl the WebGPURenderer form (render/fx/sky.tsl.js): (ctx) => vec4 node (rgb, amount), ctx = { dir, time, sunDir, night, color (the sky
11
11
  // so far, vec3), uniforms (the dome's uniforms as nodes, the layer's own included), fx: { noise, hash }, tsl (three/tsl) }. Each
12
12
  // renderer needs its own form; a layer without it throws by name there.
13
- // In scope: threedogHash(vec2), threedogNoise(vec2) and the dome's uniforms (uTop, uHorizon, uSunColor, uCloud...).
14
- import { readParams, keysSchema, isOptions } from '../../core/params.js';
13
+ // In scope: threedogHash(vec2), threedogNoise(vec2) and the dome's uniforms (uTop, uHorizon, uSunColor, uWeatherCloud...).
14
+ import { readParams, keysSchema } from '../../core/base/params.js';
15
+ import { isOptions } from '../../core/base/util.js';
16
+ import { oneForm } from '../../core/base/validate.js';
15
17
  import { declareUniforms } from '../../render/uniformDecl.js';
16
- import { codedError } from '../../core/errorHints.js';
18
+ import { codedError } from '../../core/base/errorHints.js';
17
19
 
18
20
  const KEYS = ['glsl', 'tsl', 'uniforms', 'order', 'blend', 'name']; // name: the layer's name for engine.sky.layer(name, ...)
19
21
 
20
22
  /**
21
- * Check the layer list and return { uniforms, decl, body } for the GLSL dome (empty strings without layers) and `layers` ({ tsl, blend, where }
23
+ * Check the layer list (engine.sky.layer's entries) and return { uniforms, decl, body } for the GLSL dome (empty strings without layers) and `layers` ({ tsl, blend, where }
22
24
  * in draw order) for the node dome.
23
25
  * @param {any[]} list @param {{ gpu?: boolean, names?: string[] }} [o] gpu: the dome is a node material (tsl drawn, glsl optional);
24
26
  * names: the layer names per entry, so an error says engine.sky.layer('<name>') instead of the index
25
27
  */
26
28
  export function resolveDomeLayers(list, { gpu = false, names } = {}) {
27
- if (list == null) return { uniforms: {}, decl: '', body: '', layers: [] };
28
- if (!Array.isArray(list)) throw codedError('sky-option', 'dome layers must be an array of { glsl, uniforms?, order?, blend? }; see modules/sky/domeLayers.js');
29
29
  const uniforms = {}, decl = [], body = [], layers = [];
30
30
  list.map((l, i) => ({ l, i })).sort((a, b) => (a.l?.order ?? 0) - (b.l?.order ?? 0) || a.i - b.i).forEach(({ l, i }, n) => {
31
31
  const where = names?.[i] != null ? `engine.sky.layer('${names[i]}')` : `dome layer ${i}`;
32
32
  if (isOptions(l)) readParams(where, keysSchema(KEYS), l);
33
33
  if (l?.tsl != null && typeof l.tsl !== 'function') throw codedError('sky-option', `${where}.tsl must be (ctx) => vec4 node (WebGPURenderer); see modules/sky/domeLayers.js`);
34
- if (l?.glsl == null && l?.tsl != null && !gpu) throw codedError('sky-option', `${where} has only a tsl form, which WebGLRenderer cannot draw: give glsl too ({ glsl, tsl })`);
34
+ if (l?.glsl == null && l?.tsl != null && !gpu) throw oneForm('sky-option', where, false);
35
35
  // gpu: the glsl may be left out (render/fx/sky.tsl.js names a layer that has no tsl); when given it is checked all the same
36
36
  if ((l?.glsl != null || !gpu) && (typeof l?.glsl !== 'string' || !/vec4\s+threedogSkyLayer\s*\(/.test(l.glsl)))
37
37
  throw codedError('sky-option', `${where}.glsl must be GLSL that defines \`vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)\` returning (rgb, amount 0..1)`);
@@ -10,27 +10,27 @@
10
10
  // - Adding or removing scene.environment changes the program key of every Lambert material: one recompile at the switch, none after.
11
11
  // - The hemisphere light adds on top of it.
12
12
  import * as THREE from 'three';
13
- import { codedError } from '../../core/errorHints.js';
13
+ import { codedError } from '../../core/base/errorHints.js';
14
14
  import { isWebGPU, webgpuPart } from '../../render/backend.js';
15
15
 
16
16
  const DEFAULT_INTERVAL = 1; // seconds between rebuilds (only when the sky actually changed)
17
- const LOW_TIER_SLOWER = 4; // a low-tier device rebuilds this many times less often: the cube cannot be made smaller (256 px is PMREMGenerator's floor)
17
+ const LOW_TIER_SLOWER = 4; // by default a low-tier device rebuilds this many times less often (an interval the game gives stands): the cube cannot be made smaller (256 px is PMREMGenerator's floor)
18
18
 
19
19
  // Numbers that decide how the procedural sky looks right now: when they stay put the environment is not rebuilt
20
20
  function skyKey(u) {
21
21
  const f = x => Math.round(x * 400);
22
- return [...u.uTop.value.toArray(), ...u.uHorizon.value.toArray(), ...u.uSunDir.value.toArray(), ...u.uSunColor.value.toArray(), u.uNight.value, u.uCloud.value].map(f).join(',');
22
+ return [...u.uTop.value.toArray(), ...u.uHorizon.value.toArray(), ...u.uSunDir.value.toArray(), ...u.uSunColor.value.toArray(), u.uNight.value, u.uWeatherCloud.value].map(f).join(',');
23
23
  }
24
24
 
25
25
  export const environmentMethods = {
26
26
  // engine.sky.environment(): the first build waits for the first frame's colors, later calls build at once
27
- _envStart({ into = null, interval = DEFAULT_INTERVAL, ...rest } = {}) {
27
+ _envStart({ into = null, interval = this.engine.tier === 'low' ? DEFAULT_INTERVAL * LOW_TIER_SLOWER : DEFAULT_INTERVAL, ...rest } = {}) {
28
28
  const bad = Object.keys(rest)[0];
29
29
  if (bad) throw codedError('sky-option', `engine.sky.environment({ ${bad} }): the options are into and interval. Intensity and rotation are plain three.js: scene.environmentIntensity, scene.environmentRotation`);
30
30
  if (into !== null && typeof into !== 'object') throw codedError('sky-option', 'engine.sky.environment({ into }): into is the object whose .environment is written, usually engine.scene');
31
31
  if (typeof interval !== 'number' || !(interval >= 0)) throw codedError('sky-option', `engine.sky.environment({ interval }): interval is seconds, 0 or more; got ${JSON.stringify(interval)}`);
32
- if (this._env) throw codedError('sky-option', 'engine.sky.environment(): already on; call remove() on its handle first');
33
- const env = this._env = { into, interval: this.engine.tier === 'low' ? interval * LOW_TIER_SLOWER : interval, key: null, since: 0, builds: 0, target: null, deferred: !this._envFramed };
32
+ this._envOff(); // a second call replaces the first (a new interval, hot reload, another scene); the old handle's remove() then does nothing
33
+ const env = this._env = { into, interval, key: null, since: 0, builds: 0, target: null, deferred: !this._envFramed };
34
34
  if (!env.deferred) this._envBuild();
35
35
  // a lost context takes the map's pixels with it, and the key cannot see that: with the sky standing still (a fixed hour) the map would stay black
36
36
  env.restored = this.engine.events.on('page:contextrestored', () => { env.key = null; env.deferred = true; });
@@ -1,10 +1,13 @@
1
1
  // Sky per-frame work (helper of Sky.js): signals (uSunDir, uSunColor, uSkyTop, uSkyHorizon, season, cover) and the dome. Lights, fog,
2
2
  // exposure and the environment are the game's (its picture/ folder reads the signals): nothing here writes them, because a value with two writers
3
- // is what made a game's picture depend on code it never saw (plan 2026-11-04 rule 1). The shadow box around the focus is engine.shadows.box (core/shadows.js).
4
- import { defineOwned } from '../../core/owned.js';
3
+ // is what made a game's picture depend on code it never saw (plan 2026-11-04 rule 1). The shadow box around the focus is engine.shadows.box (render/shadows.js).
4
+ import { defineOwned } from '../../core/ops/owned.js';
5
5
  import { applySeason } from './season.js';
6
6
  import { applyCover, skyTint } from './tint.js';
7
7
  import { fogBand } from './fog.js';
8
+ import { signalWatch } from '../../render/daylight.js';
9
+ import { sunAngle } from '../../core/time/dayTime.js';
10
+ import { LUMA } from '../../render/fxNumbers.js';
8
11
 
9
12
  /**
10
13
  * Brightness of the sky's ambient light for one sky color pair: ambient intensity x the luminance of the hemi color (top / horizon halfway,
@@ -12,27 +15,32 @@ import { fogBand } from './fog.js';
12
15
  * @param {import('three').Color} top @param {import('three').Color} horizon @param {number} ambient
13
16
  */
14
17
  export const skyLight = (top, horizon, ambient) => ambient * (lum(top) + lum(horizon)) / 2;
15
- const lum = c => 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b;
18
+ const lum = c => LUMA[0] * c.r + LUMA[1] * c.g + LUMA[2] * c.b;
16
19
 
17
- // 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
+ // The copyable takeover calls each owned property's warning quotes (core/ops/owned.js): the engine yields to a direct write, these say it explicitly
18
21
  const L = {
19
22
  background: { manual: 'engine.sky.dome.visible = false', back: 'engine.sky.replace(null)' },
23
+ sunDir: { manual: "engine.autoView.manual('sunDir')", back: "engine.autoView.manual('sunDir', false)" },
20
24
  };
21
25
 
22
26
  /**
23
- * Register what the sky still moves on its own: the background (backdrop / skybox). It yields to a direct write. (The shadow box is engine.shadows.box, core/shadows.js)
27
+ * Register what the sky still moves on its own: the background (backdrop / skybox). It yields to a direct write. (The shadow box is engine.shadows.box, render/shadows.js)
24
28
  */
25
29
  export function watchOwned(sky) {
26
30
  const e = sky.engine, scene = e.scene;
31
+ sky._signals = signalWatch(e, { uSkyTop: 'engine.sky.top = color', uSkyHorizon: 'engine.sky.horizon = color' });
27
32
  const own = (id, part, key, read, levels, objects) => defineOwned(e, { id, part, key, read, levels, objects });
28
33
  const list = [];
29
34
  // 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
30
35
  // takes it, and the dome hides (onChange) so the game's background shows; handing it back shows the dome again
31
36
  list.push(sky._oBg = own('background', 'sky', 'background', () => [scene.background, scene.backgroundIntensity], L.background, [scene]));
32
- sky._oBg._onChange = o => { if (!sky._backdrop && !sky.skybox && !sky._ownSky) sky.dome.visible = o.on; }; // a replaced sky keeps the dome hidden
37
+ sky._oBg._onChange = o => { if (!sky._backdrop && !sky.skybox && !sky._ownSky && !sky._noSky) sky.dome.visible = o.on; }; // a replaced sky keeps the dome hidden
33
38
  // the reference is the scene as the engine made it, not what is there now: picture code runs before start() (and may run before sky()), and a write
34
39
  // with no reference to differ from would leave the dome drawn over the game's background for good
35
40
  sky._oBg.mark([e.baseBackground, 1]);
41
+ // the sun: part 'view', so engine.autoView.manual('sunDir') is the one takeover entry. The shadow and the game's lights follow this value, so a sun at a chosen
42
+ // direction has to survive the frame. sunDir and uSunDir are one vector (Sky.js), so a write to either name is seen here
43
+ list.push(sky._oSun = defineOwned(e, { id: 'sky.sunDir', part: 'view', key: 'sunDir', read: () => sky.sunDir.toArray(), levels: L.sunDir, objects: [sky] }));
36
44
  return list;
37
45
  }
38
46
 
@@ -66,16 +74,17 @@ export function updateSky(sky) {
66
74
  const bd = sky._backdrop; // engine.sky.backdrop (dome.js): a flat background in place of the dome
67
75
  if (bd && sky._oBg.on) { sky.dome.visible = false; scene.background = bd.color; }
68
76
  // the drawn sky colors for game shaders (render/effects.js uSkyTop / uSkyHorizon): the horizon a game's fog can copy
77
+ sky._signals.check();
69
78
  sky.engine.uniforms.uSkyTop.value.copy(u.uTop.value); sky.engine.uniforms.uSkyHorizon.value.copy(bd ? bd.color : u.uHorizon.value);
79
+ sky._signals.mark();
70
80
  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
71
81
  u.uSunColor.value.copy(a[3]).lerp(b[3], f); // the keyframes' sun color: the dome's sun disk, and a signal for the game's own sun (shader.js shares the object)
72
82
 
73
- const ang = (t - 0.25) * Math.PI * 2, elev = Math.sin(ang);
74
- sky.sunDir.set(Math.cos(ang) * sky.orbit.sway, elev, sky.orbit.tilt).normalize();
75
- u.uSunDir.value.copy(sky.sunDir);
83
+ const ang = sunAngle(t), elev = Math.sin(ang);
84
+ if (sky._oSun.on) sky.sunDir.set(Math.cos(ang) * sky.orbit.sway, elev, sky.orbit.tilt).normalize();
76
85
  // uDaylight / uTimeOfDay are not written here: render/daylight.js writes them from the 'daylight' / 'timeOfDay' measures (one writer each)
77
86
  u.uNight.value = Math.min(1, Math.max(0, -elev * 4));
78
87
  // a skybox is the dome's stand-in, so it dims with the keyframes' ambient column like the dome dims with its colors
79
- if (sky.skybox && sky._oBg.on) sky.engine.scene.backgroundIntensity = Math.max(0.05, hemiI / 1.2);
88
+ if (sky.skybox && sky._oBg.on) sky.engine.scene.backgroundIntensity = Math.max(0.05, sky._ambientPeak > 0 ? hemiI / sky._ambientPeak : 1);
80
89
  for (const o of sky._owned) o.mark();
81
90
  }
@@ -6,7 +6,13 @@ import * as THREE from 'three';
6
6
  const c1 = new THREE.Color(), c2 = new THREE.Color();
7
7
  export function applySeason(sky, uniforms) {
8
8
  // no seasons in this game's calendar (or no calendar: sky alone is a fixed time): the season colors never apply, the tint stays neutral
9
- const S = sky.seasonTints, cal = sky.engine.calendar; if (!S || !cal?.seasons.length) return;
9
+ const S = sky.seasonTints, cal = sky.engine.calendar;
10
+ if (!S || !cal?.seasons.length) {
11
+ // nothing is written while no tint was ever drawn (a game may write these uniforms itself); a tint just taken away goes back to neutral
12
+ if (sky._seasoned) { sky._seasoned = false; uniforms.uFoliageTint.value.setRGB(1, 1, 1); uniforms.uGroundTint.value.setRGB(1, 1, 1); uniforms.uFoliageMix.value = uniforms.uGroundMix.value = 0; }
13
+ return;
14
+ }
15
+ sky._seasoned = true;
10
16
  const cur = S[cal.season] || {}, next = S[cal.seasons[(cal.seasonIndex + 1) % cal.seasons.length]] || {};
11
17
  const k = Math.max(0, (cal.seasonProgress - 0.8) / 0.2);
12
18
  // mode 'multiply' (default): the color multiplies the surface. mode 'mix': the surface moves `strength` of the way to the color (orange on green
@@ -2,10 +2,9 @@
2
2
  import * as THREE from 'three';
3
3
  import { NOISE_GLSL } from '../../render/effects.js';
4
4
  import { resolveClouds, cloudUniforms, CLOUD_UNIFORM_DECL } from './clouds.js';
5
- import { codedError } from '../../core/errorHints.js';
5
+ import { codedError } from '../../core/base/errorHints.js';
6
6
  import { SKY as K, glslFloat as f } from '../../render/fxNumbers.js';
7
7
  import { isWebGPU, webgpuPart } from '../../render/backend.js';
8
- import { resolveDomeLayers } from './domeLayers.js';
9
8
 
10
9
  // Keyframes: [time 0-1, zenith color, horizon color (= fog color), sun color, ambient intensity]
11
10
  // Neutral fallback with no keyframes: pure gray (no hue), only brightness changes with time. Night holds from 19:12 to 04:48 (rows 0.2 / 0.8):
@@ -33,8 +32,8 @@ export function checkKeyframes(kf) {
33
32
 
34
33
  /**
35
34
  * Dome uniforms from the sky({ ... }) start values. The picture numbers are engine.uniforms' own objects, so a write to .value moves the dome on both renderers
36
- * and a game's shader reads the same object; the dome's clouds keep their shader names uCloudScale / uCloudSpeed, which in engine.uniforms are the
37
- * cloud shadows', so those two are engine.uniforms.uSkyCloudScale / uSkyCloudSpeed.
35
+ * and a game's shader reads the same object; the dome's own clouds are uSkyCloudScale / uSkyCloudSpeed in both places;
36
+ * uCloudShadowScale / uCloudShadowSpeed are the shadows on the ground.
38
37
  */
39
38
  export function makeSkyUniforms(st, E) {
40
39
  const cl = resolveClouds(st.clouds); // throws on a bad kind / glsl / custom uniform before anything is built
@@ -44,25 +43,24 @@ export function makeSkyUniforms(st, E) {
44
43
  uCloudOpacity: num('uCloudOpacity', built.uCloudOpacity.value), uCloudSoft: num('uCloudSoft', built.uCloudSoft.value),
45
44
  uTop: { value: new THREE.Color() }, uHorizon: { value: new THREE.Color() },
46
45
  uSunDir: E.uSunDir, uSunColor: E.uSunColor, uNight: { value: 0 },
47
- uSunSize: num('uSunSize', st.sunSize ?? 900), uSunGlow: num('uSunGlow', st.sunGlow ?? 0.18), uSunPower: num('uSunPower', st.sunBrightness ?? 6), uMoonPower: num('uMoonPower', st.moonBrightness ?? 3),
48
- uMoonSize: num('uMoonSize', st.moonSize ?? 1400), uMoonColor: put('uMoonColor', st.moonColor ?? 0xdcdcdc),
49
- uTime: E.uTime, uCloud: E.uCloud, uCloudCover: num('uCloudCover', st.clouds?.coverage ?? (st.clouds ? 1 : 0)),
50
- uCloudScale: num('uSkyCloudScale', st.clouds?.scale ?? 0.35), uCloudSpeed: put('uSkyCloudSpeed', ...(st.clouds?.speed ?? [0.004, 0.002])),
46
+ uSunSize: num('uSunSize', st.sunSize ?? 900), uSunGlow: num('uSunGlow', st.sunGlow ?? 0.18), uSunBrightness: num('uSunBrightness', st.sunBrightness ?? 6), uMoonBrightness: num('uMoonBrightness', st.moonBrightness ?? 3),
47
+ uMoonSize: num('uMoonSize', 1400), uMoonColor: put('uMoonColor', st.moonColor ?? 0xdcdcdc),
48
+ uTime: E.uTime, uWeatherCloud: E.uWeatherCloud, uCloudCover: num('uCloudCover', st.clouds?.coverage ?? (st.clouds ? 1 : 0)),
49
+ uSkyCloudScale: num('uSkyCloudScale', st.clouds?.scale ?? 0.35), uSkyCloudSpeed: put('uSkyCloudSpeed', ...(st.clouds?.speed ?? [0.004, 0.002])),
51
50
  uCloudColor: put('uCloudColor', st.clouds?.color ?? 0xf4f4f4), uCloudShade: put('uCloudShade', st.clouds?.shade ?? 0xaaaaaa),
52
- uStars: num('uStars', st.starDensity ?? 0.0025), uStarCloudDim: { value: st.dim?.stars === false ? 0 : 1 }, uStarScale: num('uStarScale', st.starScale ?? 260), uCurve: num('uCurve', st.gradientCurve ?? 0.55),
51
+ uStars: num('uStars', st.starDensity ?? 0.0025), uStarCloudDim: { value: st.dim?.stars === false ? 0 : 1 }, uStarScale: num('uStarScale', 260), uSkyCurve: num('uSkyCurve', 0.55),
53
52
  };
54
53
  }
55
54
 
56
55
  /**
57
56
  * The sky dome: a back-faced sphere that follows the camera and is scaled to 0.9 of its far plane (drawn first, no depth).
58
- * extra = { decl, body, layers? }: GLSL added by fog.js (fog-colored horizon band) and domeLayers.js (dome layers); empty keeps the plain shader text
59
- * engine: on a WebGPURenderer the dome is render/fx/sky.tsl.js's node material over the same uniforms (needs threedog/tsl), drawing the layers'
60
- * tsl forms (extra.layers from prepareDome, else st.layers resolved here)
57
+ * extra = { decl, body, layers }: GLSL added by fog.js (fog-colored horizon band) and domeLayers.js (dome layers)
58
+ * engine: on a WebGPURenderer the dome is render/fx/sky.tsl.js's node material over the same uniforms (needs threedog/tsl), drawing the layers' tsl forms
61
59
  */
62
- export function makeDome(uniforms, st, extra = { decl: '', body: '' }, engine = null) {
60
+ export function makeDome(uniforms, st, extra, engine) {
63
61
  const cl = resolveClouds(st.clouds);
64
62
  const nodes = skyNodes(engine);
65
- const dome = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), nodes ? nodes.domeMaterial(uniforms, st, cl.kind, engine, { layers: extra.layers ?? resolveDomeLayers(st.layers, { gpu: true }).layers })
63
+ const dome = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), nodes ? nodes.domeMaterial(uniforms, st, cl.kind, engine, { layers: extra.layers })
66
64
  : new THREE.ShaderMaterial({ vertexShader: vert, fragmentShader: domeFragment(cl, extra), uniforms, side: THREE.BackSide, depthWrite: false, depthTest: false }));
67
65
  dome.frustumCulled = false; dome.renderOrder = -1000; dome.userData.budgetTag = 'sky';
68
66
  dome.onBeforeRender = (r, sc, cam) => {
@@ -83,16 +81,17 @@ export function skyNodes(engine) {
83
81
  /** Panorama skybox (engine.sky.replace(name)): hides the gradient dome once the texture is wanted, becomes the scene background when loaded */
84
82
  export function loadSkybox(sky, name) {
85
83
  const e = sky.engine;
86
- sky.dome.visible = false;
87
- e.assets.useTexture(name, t => { t.mapping = THREE.EquirectangularReflectionMapping; e.scene.background = t; sky.skybox = t; sky._oBg?.mark(); },
84
+ sky.dome.visible = false; sky._panorama = name;
85
+ // the load can end after another replace(): only the panorama still asked for is shown
86
+ e.assets.useTexture(name, t => { if (sky._panorama !== name) return; t.mapping = THREE.EquirectangularReflectionMapping; e.scene.background = t; sky.skybox = t; sky._oBg?.mark(); },
88
87
  { where: 'sky skybox', instead: 'no panorama shows (the gradient dome stays hidden)' });
89
88
  }
90
89
 
91
90
  const vert = `varying vec3 vDir;
92
91
  void main(){ vDir = normalize(position); vec4 p = projectionMatrix * modelViewMatrix * vec4(position,1.0); gl_Position = p.xyww; }`;
93
92
  export const domeFragment = (cl, x) => `uniform vec3 uTop; uniform vec3 uHorizon; uniform vec3 uSunDir; uniform vec3 uSunColor; uniform float uNight;
94
- uniform float uSunSize; uniform float uSunGlow; uniform float uSunPower; uniform float uMoonPower; uniform float uMoonSize; uniform vec3 uMoonColor; uniform float uStars; uniform float uStarCloudDim; uniform float uStarScale; uniform float uCurve;
95
- uniform float uTime; uniform float uCloud; uniform float uCloudCover; uniform float uCloudScale; uniform vec2 uCloudSpeed; uniform vec3 uCloudColor; uniform vec3 uCloudShade;
93
+ uniform float uSunSize; uniform float uSunGlow; uniform float uSunBrightness; uniform float uMoonBrightness; uniform float uMoonSize; uniform vec3 uMoonColor; uniform float uStars; uniform float uStarCloudDim; uniform float uStarScale; uniform float uSkyCurve;
94
+ uniform float uTime; uniform float uWeatherCloud; uniform float uCloudCover; uniform float uSkyCloudScale; uniform vec2 uSkyCloudSpeed; uniform vec3 uCloudColor; uniform vec3 uCloudShade;
96
95
  ${CLOUD_UNIFORM_DECL}
97
96
  ${cl.decl}${x.decl ? '\n' + x.decl : ''}
98
97
  varying vec3 vDir;
@@ -102,22 +101,22 @@ ${cl.glsl}
102
101
  void main(){
103
102
  vec3 d = normalize(vDir);
104
103
  float y = max(d.y, 0.0);
105
- vec3 col = d.y < 0.0 ? uHorizon : mix(uHorizon, uTop, pow(y, uCurve));
104
+ vec3 col = d.y < 0.0 ? uHorizon : mix(uHorizon, uTop, pow(y, uSkyCurve));
106
105
  float sd = max(dot(d, uSunDir), 0.0);
107
- col += uSunColor * (pow(sd, uSunSize) * uSunPower + pow(sd, ${f(K.glowPower)}) * uSunGlow) * step(0.0, uSunDir.y + ${f(K.sunCut)});
106
+ col += uSunColor * (pow(sd, uSunSize) * uSunBrightness + pow(sd, ${f(K.glowPower)}) * uSunGlow) * step(0.0, uSunDir.y + ${f(K.sunCut)});
108
107
  float md = max(dot(d, -uSunDir), 0.0);
109
- col += uMoonColor * pow(md, uMoonSize) * uMoonPower * uNight;
108
+ col += uMoonColor * pow(md, uMoonSize) * uMoonBrightness * uNight;
110
109
  vec3 g = floor(d * uStarScale);
111
110
  // Clouds: threedogClouds() is the game's (or a built-in kind's) cloud function, see clouds.js; coverage follows weather
112
- float cov = uCloud * uCloudCover, clA = 0.0;
111
+ float cov = uWeatherCloud * uCloudCover, clA = 0.0;
113
112
  if (d.y > 0.0 && cov > 0.01) {
114
113
  vec4 cl = threedogClouds(d, uTime, uSunDir, uNight, uCloudColor, uCloudShade, cov);
115
114
  col = mix(col, cl.rgb, cl.a); clA = cl.a;
116
115
  }
117
- // Stars sit behind the clouds (hidden where a cloud is drawn) and dim with the weather's cloud cover (uCloud): a rainy / overcast night has
116
+ // Stars sit behind the clouds (hidden where a cloud is drawn) and dim with the weather's cloud cover (uWeatherCloud): a rainy / overcast night has
118
117
  // no clear sky between the drawn clouds either, and a picture with sparse cloud art must not show a starry sky in a storm. Relative to the
119
- // weather value, no extra constant: uCloud 0 = every star, 1 = none. engine.sky.dim.stars false (uStarCloudDim 0) keeps them through the cover
120
- col += vec3(step(1.0 - uStars, h3(g)) * uNight * smoothstep(0.0, ${f(K.starFade)}, d.y) * (1.0 - clA) * (1.0 - clamp(uCloud, 0.0, 1.0) * uStarCloudDim));${x.body}
118
+ // weather value, no extra constant: uWeatherCloud 0 = every star, 1 = none. engine.sky.dim.stars false (uStarCloudDim 0) keeps them through the cover
119
+ col += vec3(step(1.0 - uStars, h3(g)) * uNight * smoothstep(0.0, ${f(K.starFade)}, d.y) * (1.0 - clA) * (1.0 - clamp(uWeatherCloud, 0.0, 1.0) * uStarCloudDim));${x.body}
121
120
  gl_FragColor = vec4(col, 1.0);
122
121
  #include <tonemapping_fragment>
123
122
  #include <colorspace_fragment>