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
@@ -2,15 +2,17 @@
2
2
  // (c.plants[name]: matrices, colors, stable ids), tree collision circles (c.colliders), felled-tree records (saved) and instanceAt.
3
3
  // Data only: this file makes no mesh and touches no material. Draw parts subscribe with view({ species, change, ring, show, drop })
4
4
  // (vegetation/draw.js is the engine's own, slot 'vegetation-draw'); the models and materials given to define() are read there.
5
- import { isModelName, vegetationModel } from '../../core/namedModel.js';
6
- import { warnMissing } from '../../core/validate.js';
7
- import { readParams, keysSchema } from '../../core/params.js';
8
- import { reportError } from '../../core/errors.js';
9
- import { xzOf } from '../../core/math.js';
5
+ import { Vector3 } from 'three';
6
+ import { vegetationModel } from '../../core/assets/namedModel.js';
7
+ import { isModelName } from '../../core/base/util.js';
8
+ import { DEV, warnMissing, warnOnce } from '../../core/base/validate.js';
9
+ import { readParams, keysSchema } from '../../core/base/params.js';
10
+ import { reportError } from '../../core/base/errors.js';
11
+ import { xzOf } from '../../core/base/math.js';
10
12
  import { GroundChunks } from './groundChunks.js';
11
13
  import { fadeBand } from './nearFade.js';
12
14
  import { makeDensity, thin } from './densityMap.js';
13
- import { codedError } from '../../core/errorHints.js';
15
+ import { coded, codedError } from '../../core/base/errorHints.js';
14
16
  // parameters read by vegetation.define(); keys inside rule (sent to the worker thread)
15
17
  const ADD_KEYS = ['geometry', 'model', 'lodGeometry', 'rule', 'positions', 'densityMap', 'wind', 'nearOnly', 'maxRing', 'lodRing', 'castShadow', 'shadowRing', 'receiveShadow', 'material', 'effects', 'doubleSided', 'fade'];
16
18
  const RULE_KEYS = ['perChunk', 'chance', 'minHeight', 'maxHeight', 'maxSlope', 'cluster', 'scale', 'stretch', 'sink', 'tintJitter', 'tints', 'biomes', 'collider', 'avoidFlat', 'salt'];
@@ -25,37 +27,38 @@ function checkPositions(label, list, rule) {
25
27
  if (!Array.isArray(p) || p.length < 2 || p.length > 4 || !p.every(Number.isFinite)) throw codedError('vegetation-option', `${label}: positions[${i}] = ${JSON.stringify(p)}; each entry is [x, z], [x, z, scale] or [x, z, scale, yaw] (finite numbers)`);
26
28
  });
27
29
  const clash = SCATTER_ONLY.filter(k => rule && k in rule);
28
- if (clash.length) throw codedError('vegetation-option', `${label}: rule.${clash.join(' / rule.')} only filters random placement and does not apply to positions (every listed spot is planted). Drop it, or add a second species for the scattered ones`);
30
+ if (DEV && clash.length) warnOnce(coded('vegetation-option', `${label}: rule.${clash.join(' / rule.')} only filters random placement and does not apply to positions (every listed spot is planted). Drop it, or add a second species for the scattered ones`));
29
31
  }
30
32
 
31
33
  // Single-instance removal/restore (chop a tree, mine a rock): records are owned by vegetation and saved with the save (save key 'vegetation', entry
32
34
  // 'veg:<name>:<cx>,<cz>:<id>'), and reapplied when a chunk reloads.
33
35
  // The id is this tree's stable number (independent of quality and vegetation density), not its index in the instance array.
34
36
  // const hit = engine.vegetation.instanceAt(position, { radius: 2, species: '松树' }); // → { species, cx, cz, id, position } or null
35
- // engine.vegetation.removeInstance(hit.species, hit.cx, hit.cz, hit.id, { regrowSeconds: 300 }); // grows back after 300 game seconds
37
+ // engine.vegetation.removeInstance(hit.species, hit.cx, hit.cz, hit.id, { regrowSeconds: 300 }); // grows back after 300 calendar seconds
36
38
  // engine.vegetation.restoreInstance(...) // restore immediately
37
39
  // Hiding: the slot goes into c.hidden[name] (the draw part draws it as a zero matrix, count unchanged) and out of the chunk's collision circles.
38
- // Regrowth: the record stores the expiry time (engine.clock game seconds), checked once per second; the clock is saved, so the countdown continues after
40
+ // Regrowth: the record stores the expiry time (engine.calendar seconds), checked once per second; the clock is saved, so the countdown continues after
39
41
  // reload.
40
42
  const KEY_RE = /^veg:(.*):(-?\d+),(-?\d+):(\d+)$/;
41
43
  const hashName = s => { let h = 7; for (const ch of s) h = (Math.imul(h, 31) + ch.codePointAt(0)) | 0; return h & 0x7fffffff; };
42
44
  // stable id -> instance slot of one placement result (built once per result, kept off the record so it never travels)
43
45
  const SLOTS = new WeakMap();
44
46
  function slotOf(r, id) {
45
- if (!r.ids) return id < r.n ? id : undefined;
46
47
  let m = SLOTS.get(r);
47
48
  if (!m) { m = new Map(); SLOTS.set(r, m); for (let i = 0; i < r.ids.length; i++) m.set(r.ids[i], i); }
48
49
  return m.get(id);
49
50
  }
50
51
 
52
+ const REMOVE_KEYS = ['regrowSeconds'];
53
+
51
54
  export class Vegetation {
52
55
  constructor(engine, opts = {}) {
53
56
  this.engine = engine; this.species = new Map();
54
57
  // where it grows: on terrain chunks when the terrain module is installed (placed in its workers), else on vegetation's own chunks over
55
58
  // whatever provides the ground (a level, a code-built ground, flat). Both hosts keep chunks of one shape, so everything below is shared
56
59
  if (engine.terrain && Object.keys(opts).length) throw codedError('vegetation-option', `vegetation({ ${Object.keys(opts).join(', ')} }): with terrain() installed vegetation grows on the terrain chunks, and density / view distance are terrain options (terrain({ density, viewChunks })). The vegetation() options are for ground without terrain (a level, a code-built ground)`);
57
- /** @internal the chunk table vegetation lives in: engine.terrain, or its own GroundChunks */
58
60
  /** @internal the draw parts drawing the plants (view()) */ this.views = new Set();
61
+ /** @internal the chunk table vegetation lives in: engine.terrain, or its own GroundChunks */
59
62
  this.host = engine.terrain ?? new GroundChunks(engine, this, opts);
60
63
  // on terrain: this is the terrain's planter (it calls mount / unmount / drop / ring; terrain never reads engine.vegetation); a chunk's
61
64
  // visibility comes from the terrain data part, so a game that replaces the terrain drawing keeps its trees
@@ -63,11 +66,11 @@ export class Vegetation {
63
66
  this._planter = engine.terrain.setPlanter(this);
64
67
  this._view = engine.terrain.view({ show: (c, v) => this._emit('show', c, v) });
65
68
  }
66
- this._removed = new Map(); // 'name:cx,cz' -> Map(id -> regrow time (clock game seconds), null = permanent)
69
+ this._removed = new Map(); // 'name:cx,cz' -> Map(id -> regrow time (calendar seconds), null = permanent)
67
70
  this._acc = 0;
68
71
  this._pending = []; // density images still loading (densityMap.url); the module's init waits for them
69
- this._initDone = false; // set when init took _pending: an image of a species added later is not awaited, so its error is caught where it is added
70
- // dev asset hot swap (core/assetHot.js): a species made from a swapped model is added again with the new geometry / materials. Why here and
72
+ this._initDone = false; // set when init has waited for _pending: an image of a species added later is not awaited, so its error is caught where it is added
73
+ // dev asset hot swap (core/assets/assetHot.js): a species made from a swapped model is added again with the new geometry / materials. Why here and
71
74
  // not in the generic scene walk: a species' materials are patched copies (wind, season) and its geometry may be merged from a model
72
75
  engine.assets.onSwap?.(s => this._swapped(s));
73
76
  engine.saves.register('vegetation', {
@@ -141,7 +144,7 @@ export class Vegetation {
141
144
  // reaches the placer (terrain worker or ground chunks), and a list of numbers travels as plain data
142
145
  rule: { salt: hashName(name), ...(o.rule || {}), ...(o.positions != null ? { positions: o.positions } : {}) },
143
146
  density, // densityMap sampler (main thread only: a function may read game state), applied in mount()
144
- nearOnly: !!o.nearOnly, maxRing, lodRing: o.lodRing ?? 1, fade: o.effects === false ? null : fadeBand(o.fade, !!o.nearOnly, maxRing, this.host.CHUNK),
147
+ nearOnly: !!o.nearOnly, maxRing, lodRing: o.lodRing ?? 1, fade: o.effects === false ? null : fadeBand(o.fade, !!o.nearOnly, maxRing, this.host.chunkSize),
145
148
  castShadow: o.castShadow ?? !o.nearOnly, shadowRing: o.shadowRing ?? 1, receiveShadow: o.receiveShadow ?? true,
146
149
  };
147
150
  sp.source = o; // what it was made from: the draw part reads geometry / model / material / wind from it, a hot swap adds it again (_swapped)
@@ -187,8 +190,11 @@ export class Vegetation {
187
190
  }
188
191
  return out;
189
192
  }
190
- /** @internal module init: density images of species added before start */
191
- async whenLoaded() { const p = this._pending; this._pending = []; this._initDone = true; await Promise.all(p); }
193
+ /** @internal module init: density images and named models of species added before start; a named model's define() may add an image of its own, so until none is left */
194
+ async whenLoaded() {
195
+ try { while (this._pending.length) { const p = this._pending; this._pending = []; await Promise.all(p); } }
196
+ finally { this._initDone = true; }
197
+ }
192
198
  /**
193
199
  * Place every chunk again: after changing the ground behind the same provider (a ground function reading game state), or what a densityMap
194
200
  * function reads. A new setGround or level is followed automatically
@@ -198,7 +204,7 @@ export class Vegetation {
198
204
  list() { return [...this.species.values()]; }
199
205
  /**
200
206
  * Change at runtime how far a vegetation kind casts shadows: within `ring` chunk rings of the player (0 = only the chunk you stand in, 1 = the default,
201
- * larger = further and dearer). Takes effect at once; the add() option shadowRing is only the starting value. An unknown name warns with the known ones
207
+ * larger = further and dearer). Takes effect at once; the define() option shadowRing is only the starting value. An unknown name warns with the known ones
202
208
  * @example engine.vegetation.setShadowRing('tree', 0); // graphics setting "shadows: low": trees shadow only the nearest chunk
203
209
  * @param {string} name species name given to vegetation.define
204
210
  * @param {number} ring chunk rings, 0 or more
@@ -283,8 +289,9 @@ export class Vegetation {
283
289
  /** @internal save-key format */
284
290
  key(species, cx, cz, id) { return `veg:${species}:${cx},${cz}:${id}`; }
285
291
  isRemoved(species, cx, cz, id) { return !!this._removed.get(`${species}:${cx},${cz}`)?.has(id); }
286
- /** Remove one instance (regrowSeconds: game seconds until it grows back, 0/omitted = permanent). The record is saved with the save */
287
- removeInstance(species, cx, cz, id, { regrowSeconds = 0 } = {}) {
292
+ /** Remove one instance (regrowSeconds: calendar seconds until it grows back, 0/omitted = permanent). The record is saved with the save */
293
+ removeInstance(species, cx, cz, id, opts) {
294
+ const { regrowSeconds = 0 } = readParams('vegetation.removeInstance()', keysSchema(REMOVE_KEYS), opts);
288
295
  const ck = `${species}:${cx},${cz}`;
289
296
  if (!this._removed.has(ck)) this._removed.set(ck, new Map());
290
297
  this._removed.get(ck).set(id, regrowSeconds > 0 ? this.engine.clock.now + regrowSeconds : null);
@@ -318,7 +325,7 @@ export class Vegetation {
318
325
  instanceAt(position, opts = {}) {
319
326
  readParams('vegetation.instanceAt()', keysSchema(['radius', 'species']), opts);
320
327
  const [x, z] = xzOf(position), { radius = 2, species = null } = typeof opts === 'object' && opts ? opts : {};
321
- const T = this.host, CH = T.CHUNK;
328
+ const T = this.host, CH = T.chunkSize;
322
329
  let best = null, bestD = radius * radius;
323
330
  for (let cz = Math.floor((z - radius) / CH); cz <= Math.floor((z + radius) / CH); cz++)
324
331
  for (let cx = Math.floor((x - radius) / CH); cx <= Math.floor((x + radius) / CH); cx++) {
@@ -330,7 +337,7 @@ export class Vegetation {
330
337
  for (let i = 0; i < r.n; i++) {
331
338
  if (hid?.has(i)) continue;
332
339
  const dx = ox + a[i * 16 + 12] - x, dz = oz + a[i * 16 + 14] - z, d = dx * dx + dz * dz;
333
- if (d < bestD) { bestD = d; best = { species: name, cx, cz, id: r.ids ? r.ids[i] : i, position: new this.engine.THREE.Vector3(ox + a[i * 16 + 12], a[i * 16 + 13], oz + a[i * 16 + 14]) }; }
340
+ if (d < bestD) { bestD = d; best = { species: name, cx, cz, id: r.ids[i], position: new Vector3(ox + a[i * 16 + 12], a[i * 16 + 13], oz + a[i * 16 + 14]) }; }
334
341
  }
335
342
  }
336
343
  }
@@ -341,7 +348,7 @@ export class Vegetation {
341
348
  mount(c, name, r) {
342
349
  const sp = this.species.get(name);
343
350
  // densityMap thins here, before the colliders are taken, so a dropped plant blocks nothing; survivors keep their stable ids
344
- if (sp?.density) r = thin(r, c.cx * this.host.CHUNK, c.cz * this.host.CHUNK, sp.density.at, sp.rule.salt);
351
+ if (sp?.density) r = thin(r, c.cx * this.host.chunkSize, c.cz * this.host.chunkSize, sp.density.at, sp.rule.salt);
345
352
  c.plants ||= {}; c.colliders ||= {}; c.collidersAll ||= {};
346
353
  // none left (terrain dug, densityMap thinned all): drop the record, so the draw part tears its mesh down too and collision matches what is drawn
347
354
  if (r.n === 0) delete c.plants[name]; else c.plants[name] = r;
@@ -6,9 +6,9 @@
6
6
  // a zoning grid the game edits), which cannot travel to the terrain worker; and thinning the already placed instances keeps every survivor's
7
7
  // stable id, so felled-tree records and saves stay valid whether the map is on, off or changed. Each instance keeps or drops by its own hash
8
8
  // against the density there, so raising the density only adds plants, it never moves the ones already standing.
9
- import { readParams, keysSchema } from '../../core/params.js';
10
- import { grayAt, loadGray } from '../../core/grayMap.js';
11
- import { codedError } from '../../core/errorHints.js';
9
+ import { readParams, keysSchema } from '../../core/base/params.js';
10
+ import { grayWorld, loadGray } from '../../core/scene/grayMap.js';
11
+ import { codedError } from '../../core/base/errorHints.js';
12
12
 
13
13
  const MAP_KEYS = ['url', 'data', 'width', 'height', 'size', 'center', 'outside'];
14
14
 
@@ -26,10 +26,7 @@ export function makeDensity(spec, label) {
26
26
  const M = { ...spec, data: spec.data ?? null };
27
27
  const at = (x, z) => {
28
28
  if (!M.data) return 0; // image not loaded yet: nothing grows, the chunks are placed again once it is
29
- const [sx, sz] = M.size, [cx0, cz0] = M.center || [0, 0];
30
- const u = (x - cx0) / sx + 0.5, v = (z - cz0) / sz + 0.5;
31
- if (u < 0 || u > 1 || v < 0 || v > 1) return M.outside ?? 0;
32
- return grayAt(M, u, v);
29
+ return grayWorld(M, x, z) ?? M.outside ?? 0;
33
30
  };
34
31
  const pending = M.data ? null : loadGray(spec.url).then(g => { Object.assign(M, g); }, err => { throw codedError('vegetation-option', `${label}: densityMap url ${spec.url} did not load (${err?.message ?? err})`); });
35
32
  return { at, pending };
@@ -7,14 +7,16 @@
7
7
  // (engine.use(myPlants, { replaces: 'vegetation-draw' })) and keep everything that plays. A replacement draw part does what this file does:
8
8
  // install(e, ctx) { ctx.track(e.vegetation.view({ species(sp) {...}, change(c, name) {...c.plants[name]...}, ring(c, ring) {...}, show(c, v) {...}, drop(c) {...} })); }
9
9
  // This file never changes placement data; it only reads it.
10
- import { engineOwned } from '../../core/things.js';
10
+ import { engineOwned } from '../../core/scene/things.js';
11
+ import { needMaterial, oneForm } from '../../core/base/validate.js';
11
12
  import * as THREE from 'three';
12
13
  import { fromModel } from './modelGeometry.js';
13
14
  import { applyEffects, windCustom } from '../../render/materials.js';
14
15
  import { neutralMaterial } from '../../render/neutral.js';
15
16
  import { patchMaterial, unpatchMaterial } from '../../render/patches.js';
16
17
  import { EFFECTS, hashText } from '../../render/effects.js';
17
- import { codedError } from '../../core/errorHints.js';
18
+ import { codedError } from '../../core/base/errorHints.js';
19
+ import { isWebGPU } from '../../render/backend.js';
18
20
  import { nearFadePatch } from './nearFade.js';
19
21
 
20
22
  const COLOR = 'vegetationColor'; // the patch name of vegetation.color() on every species' material
@@ -41,14 +43,11 @@ export class VegetationDraw {
41
43
  /** @internal engine.vegetation.material: every species with no material or model of its own draws it, as given; null gives the neutral default back */
42
44
  get material() { return this._game ?? this._base; }
43
45
  set material(m) {
44
- if (m != null && !m.isMaterial) throw codedError('vegetation-option', `vegetation.material is a three.js material (or null for the neutral default); got ${m}`);
45
- const was = this._game;
46
+ if (m != null) needMaterial('vegetation-option', 'vegetation.material', m, ' (null gives the neutral default back)');
46
47
  this._game = m || null;
47
48
  for (const sp of this.v.list()) {
48
49
  const old = this.kinds.get(sp.name);
49
- if (!old?.shared) continue;
50
- this.species(sp);
51
- if (old.material !== was) old.material.dispose(); // a neutral copy of ours; the game's stays the game's
50
+ if (old?.shared) this.species(sp);
52
51
  }
53
52
  for (const rec of this.meshes.values()) for (const n in rec.ims) { const k = this.kinds.get(n); if (k) rec.ims[n].material = k.material; }
54
53
  }
@@ -78,9 +77,8 @@ export class VegetationDraw {
78
77
 
79
78
  /** Each renderer draws its own form; the one this engine's renderer needs, when missing, is named (else the code would do nothing silently) */
80
79
  _needForm(entry, s) {
81
- const gpu = !!this.engine.renderer?.isWebGPURenderer;
82
- if (!gpu && s.glsl == null) throw codedError('vegetation-option', `vegetation.${entry}() has only a tsl form, which WebGLRenderer cannot draw: give glsl too ({ glsl, tsl })`);
83
- if (gpu && s.tsl == null) throw codedError('vegetation-option', `vegetation.${entry}() has only a glsl form, which WebGPURenderer cannot draw: give tsl too ({ glsl, tsl })`);
80
+ const gpu = isWebGPU(this.engine.renderer);
81
+ if (gpu ? s.tsl == null : s.glsl == null) throw oneForm('vegetation-option', `vegetation.${entry}()`, !!gpu);
84
82
  }
85
83
  _windPatch(amplitude) { return EFFECTS.wind(amplitude, this._sway ? windCustom(this._sway) : undefined); }
86
84
  /** engine.vegetation.patches: what a game's shared material needs to behave like the engine's (the near fade is per species: define({ material }) gets it) */
@@ -108,13 +106,16 @@ export class VegetationDraw {
108
106
  const own = [nf?.patch, this._color].filter(Boolean);
109
107
  const fx = m => o.effects === false ? m : applyEffects(m, { wind, season: 'foliage', engine: e, patches: own.length ? own : undefined });
110
108
  const mdl = o.model && fromModel(o.model, label);
111
- let lod = o.lodGeometry?.isObject3D ? fromModel(o.lodGeometry, label + '.lodGeometry').geometry : o.lodGeometry || null;
109
+ const lodMdl = o.lodGeometry?.isObject3D ? fromModel(o.lodGeometry, label + '.lodGeometry') : null;
110
+ let lod = lodMdl ? lodMdl.geometry : o.lodGeometry || null;
112
111
  if (mdl && lod && !lod.groups.length) { lod = lod.clone(); lod.addGroup(0, Infinity, 0); } // a material array draws nothing without groups
113
112
  const shared = !mdl && !o.material, game = shared ? this._game : null;
114
- this.kinds.set(sp.name, {
115
- geometry: mdl ? mdl.geometry : o.geometry, lodGeometry: lod, fadeUniforms: game ? null : nf?.uniforms ?? null, shared,
116
- material: game ?? (mdl ? mdl.materials.map(fx) : fx(o.material ?? this._neutral(o))),
117
- });
113
+ const material = game ?? (mdl ? mdl.materials.map(fx) : fx(o.material ?? this._neutral(o)));
114
+ // what was built here and is ours to free (the game's geometry and materials stay the game's); a mesh still drawing the old ones uploads them again
115
+ const made = [...(lodMdl?.materials ?? []), ...(lod && lod !== o.lodGeometry ? [lod] : []), ...(mdl ? [mdl.geometry, ...material] : shared && !game ? [material] : [])];
116
+ const old = this.kinds.get(sp.name);
117
+ this.kinds.set(sp.name, { geometry: mdl ? mdl.geometry : o.geometry, lodGeometry: lod, fadeUniforms: game ? null : nf?.uniforms ?? null, shared, material, made });
118
+ for (const d of old?.made ?? []) d.dispose();
118
119
  }
119
120
  _neutral(o) {
120
121
  const m = neutralMaterial('vegetation', { vertexColors: true, side: o.doubleSided ? THREE.DoubleSide : THREE.FrontSide });
@@ -153,7 +154,7 @@ export class VegetationDraw {
153
154
  /** @internal view hook: the chunk's ring changed (or shadows were switched): draw distance, low-poly swap and shadows of every species there */
154
155
  ring(c, ring) {
155
156
  const rec = this.meshes.get(c); if (!rec) return;
156
- for (const n in rec.ims) { const sp = this.v.get(n), k = this.kinds.get(n); if (sp && k && !sp.nearOnly) this._level(rec.ims[n], sp, k, ring); }
157
+ for (const n in rec.ims) { const sp = this.v.get(n), k = this.kinds.get(n); if (sp && k) this._level(rec.ims[n], sp, k, ring); }
157
158
  }
158
159
  /** @internal view hook: in view or not (ring 1 is always in view, farther chunks by the camera frustum) */
159
160
  show(c, visible) { const rec = this.meshes.get(c); if (rec) rec.group.visible = visible; }
@@ -177,7 +178,7 @@ export class VegetationDraw {
177
178
  im.castShadow = !!this.engine.renderer?.shadowMap?.enabled && sp.castShadow && ring <= sp.shadowRing;
178
179
  }
179
180
  _chunk(c) {
180
- const CH = this.v.host.CHUNK, g = new THREE.Group();
181
+ const CH = this.v.host.chunkSize, g = new THREE.Group();
181
182
  g.userData.budgetTag = 'vegetation';
182
183
  g.position.set(c.cx * CH, 0, c.cz * CH); g.matrixAutoUpdate = false; g.updateMatrix();
183
184
  g.visible = c.inView !== false;
@@ -187,5 +188,9 @@ export class VegetationDraw {
187
188
  return rec;
188
189
  }
189
190
 
190
- dispose() { this._view.remove(); this.kinds.clear(); }
191
+ dispose() {
192
+ this._view.remove();
193
+ for (const k of this.kinds.values()) for (const d of k.made) d.dispose();
194
+ this.kinds.clear(); this._base.dispose();
195
+ }
191
196
  }
@@ -1,6 +1,6 @@
1
1
  // Vegetation on any ground (no terrain module): a level model, a code-built ground, the flat default. Chunks of the same shape as the terrain's
2
2
  // ({ cx, cz, state, plants, colliders, ring, inView, ... }), streamed around every engine.stream source, placed by the same rule code
3
- // (core/scatter.js) over engine.surface / slope / groundType -- whoever provides the ground. Data only: the vegetation drawing draws c.plants.
3
+ // (core/stream/scatter.js) over engine.surface / slope / groundType -- whoever provides the ground. Data only: the vegetation drawing draws c.plants.
4
4
  //
5
5
  // Why the main thread and not a worker: a ground provider is arbitrary main-thread code (a level heightfield, a game's closure), not
6
6
  // serializable data like a terrain generator. Placement is cheap (a few height lookups per attempt) and runs under a per-frame budget.
@@ -8,15 +8,15 @@
8
8
  // changes whether the player bumps into a tree, the same contract as terrain chunks.
9
9
  // The ground changing (setGround, a level loaded or switched: ground.staticVersion) rebuilds every chunk.
10
10
  import * as THREE from 'three';
11
- import { makePlacer, makeNoise } from '../../core/scatter.js';
12
- import { xzOf } from '../../core/math.js';
13
- import { ChunkStream } from '../../core/chunkStream.js';
11
+ import { makePlacer, makeNoise } from '../../core/stream/scatter.js';
12
+ import { ChunkStream, bookCollision, collidersNear, ringsReady } from '../../core/stream/chunkStream.js';
14
13
 
15
- const COLLIDER_LAG = 30; // fixed steps before a chunk's tree collision counts, times (1 + ring); ring 1 counts at once while loading
14
+ export const GROUND_DEFAULTS = { chunkSize: 32, viewChunks: 3, density: 1, seed: 1 }; // shown by engine.catalog too
16
15
 
17
16
  export class GroundChunks {
18
17
  /** opts: chunkSize (m), viewChunks (rings drawn), density, area { min: [x, z], max: [x, z] } or null (a level's walkable bounds when a level provides the ground, else unbounded), seed */
19
- constructor(engine, veg, { chunkSize = 32, viewChunks = 3, density = 1, area = null, seed = 1 } = {}) {
18
+ constructor(engine, veg, opts = {}) {
19
+ const { chunkSize, viewChunks, density, seed, area = null } = { ...GROUND_DEFAULTS, ...opts };
20
20
  this.engine = engine; this.veg = veg;
21
21
  this.chunkSize = chunkSize; this.viewChunks = viewChunks; this.density = density; this.area = area; this.seed = seed;
22
22
  this.chunks = new Map();
@@ -24,7 +24,7 @@ export class GroundChunks {
24
24
  this.gen = 0;
25
25
  this.stats = { loaded: 0, visible: 0, instances: 0, queued: 0 };
26
26
  this._want = []; this._ground = null; this._groundVer = undefined;
27
- // which chunks the sources need, ring, culling: the same helper as the terrain chunks (core/chunkStream.js), so both rings mean the same
27
+ // which chunks the sources need, ring, culling: the same helper as the terrain chunks (core/stream/chunkStream.js), so both rings mean the same
28
28
  this._stream = new ChunkStream(this, { show: (c, v) => this.veg._emit('show', c, v), level: (c, ring) => this._setLevel(c, ring),
29
29
  count: (c, ring) => { let n = 0; for (const k in c.plants) { const sp = this.veg.get(k); if (sp && ring <= sp.maxRing) n += c.plants[k].n; } return n; },
30
30
  inArea: (cx, cz) => this._inArea(cx, cz) });
@@ -33,7 +33,6 @@ export class GroundChunks {
33
33
  surface: (x, z) => e.surface(x, z), slope: (x, z) => e.slope(x, z), typeAt: (x, z) => e.groundType(x, z) });
34
34
  }
35
35
 
36
- get CHUNK() { return this.chunkSize; }
37
36
  /**
38
37
  * @internal vegetation plumbing: a species was added or defined again. Only its plants are placed again on the loaded chunks; the other
39
38
  * species and their collision stay (dropping every chunk left the whole map without trees and tree collision until rebuilt)
@@ -96,11 +95,9 @@ export class GroundChunks {
96
95
  _queue(cx, cz, key) {
97
96
  const c = { cx, cz, key, state: 'queued', plants: {}, colliders: {}, collidersAll: {}, inView: true, level: -1, sphere: null, solid: false, gen: this.gen };
98
97
  this.chunks.set(key, c);
99
- c.ticket = this.engine.commits.request({
100
- lag: !this.engine.ready && this._ring(c) <= 1 ? 0 : COLLIDER_LAG * (1 + this._ring(c)),
98
+ bookCollision(this, c, this._ring(c), {
101
99
  apply: () => { c.solid = true; },
102
100
  fallback: () => { if (c.state !== 'ready') this._build(c); return true; }, // due before the budget got to it: place it now, same result
103
- valid: () => this.chunks.get(c.key) === c && c.gen === this.gen,
104
101
  });
105
102
  return c;
106
103
  }
@@ -145,27 +142,10 @@ export class GroundChunks {
145
142
  dispose() { this.rebuild(); }
146
143
 
147
144
  /** @internal Collision circles of solid chunks near (x, z): fn(x, z, r). Joined into engine.ground.forEachCollider (collision, path planning) */
148
- forEachCollider(x, z, range, fn) {
149
- const CH = this.chunkSize;
150
- for (let cz = Math.floor((z - range) / CH); cz <= Math.floor((z + range) / CH); cz++)
151
- for (let cx = Math.floor((x - range) / CH); cx <= Math.floor((x + range) / CH); cx++) {
152
- const c = this.chunks.get(cx + ',' + cz);
153
- if (!c?.solid) continue;
154
- for (const n in c.colliders) {
155
- const k = c.colliders[n];
156
- for (let i = 0; i < k.length; i += 3) { const dx = k[i] - x, dz = k[i + 1] - z, rr = range + k[i + 2]; if (dx * dx + dz * dz < rr * rr) fn(k[i], k[i + 1], k[i + 2]); }
157
- }
158
- }
159
- }
145
+ forEachCollider(x, z, range, fn) { collidersNear(this.chunks, this.chunkSize, x, z, range, fn); }
160
146
 
161
147
  /** Whether chunks within `rings` (default 1) of a position are placed (loading screen / stream ready check) */
162
- isReadyAround(position, { rings = 1 } = {}) {
163
- const [x, z] = xzOf(position), CH = this.chunkSize, pcx = Math.floor(x / CH), pcz = Math.floor(z / CH);
164
- for (let dz = -rings; dz <= rings; dz++) for (let dx = -rings; dx <= rings; dx++) {
165
- if (!this._inArea(pcx + dx, pcz + dz)) continue;
166
- const c = this.chunks.get((pcx + dx) + ',' + (pcz + dz));
167
- if (!c || c.state !== 'ready') return false;
168
- }
169
- return true;
148
+ readyAt(position, { rings = 1 } = {}) {
149
+ return ringsReady(this.chunks, this.chunkSize, position, rings, (c, cx, cz) => !this._inArea(cx, cz) || c?.state === 'ready');
170
150
  }
171
151
  }
@@ -2,20 +2,21 @@
2
2
  // felled trees; Vegetation.js) and 'vegetationDraw' (instanced meshes, wind, fade, LOD; draw.js, slot 'vegetation-draw').
3
3
  // Why two: collision, paths and felling read only the data, so engine.use(myPlants, { replaces: 'vegetation-draw' }) swaps every pixel
4
4
  // of the plants and keeps all of play.
5
- import { readParams, keysSchema } from '../../core/params.js';
5
+ import { readParams, keysSchema } from '../../core/base/params.js';
6
6
  import { Vegetation } from './Vegetation.js';
7
7
  import { VegetationDraw } from './draw.js';
8
- import { codedError } from '../../core/errorHints.js';
8
+ import { GROUND_DEFAULTS } from './groundChunks.js';
9
+ import { codedError } from '../../core/base/errorHints.js';
9
10
 
10
11
  const OPTS = ['chunkSize', 'viewChunks', 'density', 'area', 'seed'];
11
- const VEG_PARAMS = keysSchema(OPTS, { chunkSize: 32, viewChunks: 3, density: 1, seed: 1 }); // defaults of the own-chunks mode (without terrain)
12
+ const VEG_PARAMS = keysSchema(OPTS, GROUND_DEFAULTS); // defaults of the own-chunks mode (without terrain)
12
13
  /**
13
14
  * Vegetation module. Provides engine.vegetation.define(name, {...}) once installed.
14
15
  * With terrain() installed first it grows on the terrain chunks and takes no options (density and view distance are terrain options).
15
16
  * Without terrain it grows on its own chunks over whatever provides the ground: a level model (engine.level), a code-built ground
16
17
  * (engine.setGround), or the flat default. Rules read engine.surface / slope / groundType, so a level's named surfaces are picked with
17
18
  * rule.biomes (a level's ground type is the mesh's groundType property or its material name).
18
- * Where a species grows is one add() call with up to three parts: rule (random scatter), positions (the game's own spots, instead of the
19
+ * Where a species grows is one define() call with up to three parts: rule (random scatter), positions (the game's own spots, instead of the
19
20
  * scatter) and densityMap (thins either by a function or a gray image). A game that wants full control still builds its own InstancedMesh.
20
21
  * @param {{ chunkSize?: number, viewChunks?: number, density?: number, area?: { min: number[], max: number[] }, seed?: number }} [opts]
21
22
  * only without terrain: chunkSize meters (default 32), viewChunks rings drawn around each stream source (default 3), density multiplier (default 1),
@@ -31,13 +32,14 @@ export function vegetation(opts = {}) {
31
32
  readParams('vegetation', VEG_PARAMS, opts);
32
33
  let v = null, own = null, cols = null, ready = null, drawPart = null;
33
34
  const data = { name: 'vegetation', type: 'world', provides: ['vegetation'], label: 'Vegetation', params: VEG_PARAMS, options: opts, stage: 'ground', after: ['terrain', 'level'], optional: ['terrain', 'level'],
34
- install(e) {
35
+ install(e, ctx) {
35
36
  e.i18n.add({ 'zh-CN': { 'module.vegetation': '植被' }, en: { 'module.vegetation': 'vegetation' } });
36
37
  v = new Vegetation(e, opts);
38
+ ctx.track(e.events.on('settings:shadows', () => v.host.refreshLevels())); // whichever chunks it grows on: each level pass rereads the shadow switch
37
39
  if (v.host !== e.terrain) {
38
40
  own = v.host;
39
41
  cols = e.addGroundColliders((x, z, range, fn) => own.forEachCollider(x, z, range, fn)); // collision and path planning see the trees
40
- ready = e.stream.readyCheck('vegetation', s => own.isReadyAround(s));
42
+ ready = e.stream.addReadyCheck('vegetation', s => own.readyAt(s));
41
43
  }
42
44
  return v;
43
45
  },
@@ -1,6 +1,6 @@
1
- import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
1
+ import { mergeCommon } from '../../render/mergeCommon.js';
2
2
  import { copyPatches } from '../../render/patches.js';
3
- import { codedError } from '../../core/errorHints.js';
3
+ import { codedError } from '../../core/base/errorHints.js';
4
4
 
5
5
  // Multi-material model (bark trunk + alpha-cut leaf cards) -> one geometry with a group per mesh + a material array, so a species stays
6
6
  // one InstancedMesh: instance matrices, felling and LOD swaps work unchanged for every part. Only attributes all meshes share are kept.
@@ -15,8 +15,5 @@ export function fromModel(root, label) {
15
15
  mats.push(copyPatches(n.material, n.material.clone())); // the clone keeps the model material's own shader patches
16
16
  });
17
17
  if (!geos.length) throw codedError('vegetation-option', `${label}: model has no meshes`);
18
- const names = Object.keys(geos[0].attributes).filter(k => geos.every(g => g.attributes[k]));
19
- const indexed = geos.every(g => g.index);
20
- const ready = geos.map(g => { const h = indexed ? g : g.toNonIndexed(); for (const k in h.attributes) if (!names.includes(k)) h.deleteAttribute(k); return h; });
21
- return { geometry: mergeGeometries(ready, true), materials: mats };
18
+ return { geometry: mergeCommon(geos, true), materials: mats };
22
19
  }
@@ -4,7 +4,7 @@
4
4
  // no extra draw call or shader program per frame (the patch is part of the material's one program), the sway of the wind patch is scaled with it, and the
5
5
  // shadow pass shrinks the same way. The band ends where the ring can first end, so a clump is already gone when its chunk drops out.
6
6
  import * as THREE from 'three';
7
- import { codedError } from '../../core/errorHints.js';
7
+ import { codedError } from '../../core/base/errorHints.js';
8
8
 
9
9
  const PARS = 'uniform vec2 uNearFade; uniform vec3 uNearFadeCenter;';
10
10
  const VERTEX = `
@@ -16,15 +16,15 @@ import * as THREE from 'three';
16
16
  import { neutralMaterial } from '../../render/neutral.js';
17
17
  import { placeholderTexture } from '../../render/effects.js';
18
18
  import { patchMaterial, unpatchMaterial } from '../../render/patches.js';
19
- import { readParams, keysSchema } from '../../core/params.js';
19
+ import { readParams, keysSchema } from '../../core/base/params.js';
20
20
  import { waterShader, wavesPatch, surfacePatch } from './surface.js';
21
- import { codedError } from '../../core/errorHints.js';
21
+ import { codedError } from '../../core/base/errorHints.js';
22
22
  import { glslFloat, FRESNEL_POWER } from '../../render/fxNumbers.js';
23
- import { DEV } from '../../core/validate.js';
23
+ import { needMaterial } from '../../core/base/validate.js';
24
24
 
25
25
  const GREY = new THREE.Color(0xcccccc);
26
26
  /** @import { ModuleDef } from '../../types/core' */
27
- /** @import { Object3D, Material, Vector3, Texture } from '../../types/common' */
27
+ /** @import { Material, Vector3, Texture } from '../../types/common' */
28
28
  /** @import { WaterBody, WaterOptions, WaterShaderOptions } from '../../types/world' */
29
29
  // Options accepted by water(): the structural choices only
30
30
  const WATER_OPTIONS = ['sea', 'level', 'flat', 'size', 'segments'];
@@ -32,13 +32,6 @@ const WATER_PARAMS = keysSchema(WATER_OPTIONS);
32
32
  const SHADER_PARAMS = keysSchema(['wave', 'surface', 'depthColor', 'foam', 'uniforms']);
33
33
  const NORMAL_PARAMS = { scale: { type: 'number', min: 0, optional: true, desc: 'normal map strength' }, repeat: { type: 'number', min: 0, optional: true, desc: 'tiles per meter' },
34
34
  speed: { type: 'position', optional: true, desc: 'scroll [x, z] per second' } };
35
- // keys that were picture values: each names where the same thing is written now
36
- const NORMAL = 'engine.water.normalMap(name, { scale, repeat, speed })', PHONG = 'a highlight belongs to your own material: engine.water.material = new THREE.MeshPhongMaterial({ shininess, specular })';
37
- const SHADER = k => `engine.water.shader({ ${k} })`, TUNE = u => `engine.water.uniforms.${u}.value`;
38
- const MOVED = { color: 'engine.water.material.color.set(...)', opacity: 'engine.water.material.opacity', material: 'engine.water.material = yourMaterial',
39
- waveHeight: TUNE('uWave'), waveScale: TUNE('uWaveScale'), waveSpeed: TUNE('uWaveSpeed'), fresnel: TUNE('uFresnel'),
40
- depthColor: SHADER('depthColor'), foam: SHADER('foam'), uniforms: SHADER('uniforms'), glsl: "engine.water.shader({ wave, surface })",
41
- normalMap: NORMAL, normalScale: NORMAL, normalRepeat: NORMAL, normalSpeed: NORMAL, shininess: PHONG, specular: PHONG };
42
35
 
43
36
  /** engine.water */
44
37
  export class Water {
@@ -83,13 +76,21 @@ export class Water {
83
76
  /**
84
77
  * Global water mesh (null when absent)
85
78
  * @type {THREE.Mesh | null}
79
+ * @experimental
86
80
  */
87
81
  this.sea = null;
88
82
  /** @internal */ this._seaChecked = st.sea === false; // global water is built on the first frame: terrain (water level) is installed by then, so no dependence on install order
89
83
  for (const b of engine.waterBodies) this._addBody(b);
90
84
  track(engine.events.on('water:add', b => this._addBody(b)));
91
- // material is shared by all bodies, so not engine.remove (which would dispose it); its ray registration goes too
92
- track(engine.events.on('water:remove', b => { const m = this.bodies.get(b); if (m) { engine.detach(m); engine.rays.forget(m); this._uv.delete(m); m.geometry.dispose(); this.bodies.delete(b); } }));
85
+ track(engine.events.on('water:remove', b => { const m = this.bodies.get(b); if (m) { this._drop(m); this.bodies.delete(b); } }));
86
+ }
87
+
88
+ /** One water mesh out of the scene. The material is shared by all water, so not engine.remove (which would dispose it); the ray registration goes too @internal */
89
+ _drop(m) { const e = this.engine; e.detach(m); e.rays.forget(m); this._uv.delete(m); m.geometry.dispose(); }
90
+ /** The module goes: its meshes and what it made leave with it; a game's material stays the game's @internal */
91
+ dispose() {
92
+ for (const m of [this.sea, ...this.bodies.values()]) if (m) this._drop(m);
93
+ this.sea = null; this.bodies.clear(); this._own.dispose(); this.normalTexture?.dispose();
93
94
  }
94
95
 
95
96
  /**
@@ -99,7 +100,7 @@ export class Water {
99
100
  */
100
101
  get material() { return this._material; }
101
102
  set material(m) {
102
- if (!m?.isMaterial) throw codedError('water-option', `engine.water.material takes a three.js Material, got ${m}; e.g. engine.water.material = applyEffects(new THREE.MeshPhongMaterial({ color: 0x3070a0 }), { patches: engine.water.patches })`);
103
+ needMaterial('water-option', 'engine.water.material', m, '; e.g. engine.water.material = applyEffects(new THREE.MeshPhongMaterial({ color: 0x3070a0 }), { patches: engine.water.patches })');
103
104
  const was = this._material;
104
105
  if (m === was) return;
105
106
  this._show(m);
@@ -232,10 +233,9 @@ export class Water {
232
233
  * @returns {ModuleDef<Water>}
233
234
  */
234
235
  export function water(opts = {}) {
235
- if (DEV) for (const k in MOVED) if (k in opts) throw codedError('water-option', `water({ ${k} }) is not an option: after engine.use(water()) use ${MOVED[k]} (recipes/44)`);
236
236
  readParams('water', WATER_PARAMS, opts);
237
237
  let w = null;
238
- return { name: 'water', type: 'picture', label: 'Water', params: WATER_PARAMS, options: opts, stage: 'environment', after: ['sky'], optional: ['sky'], install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.water': '水面' }, en: { 'module.water': 'water' } }); w = new Water(e, opts, ctx.track); return w; }, frame(dt, e) { w.update(e.focus, dt); },
238
+ return { name: 'water', type: 'picture', label: 'Water', params: WATER_PARAMS, options: opts, stage: 'environment', after: ['sky'], optional: ['sky'], install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.water': '水面' }, en: { 'module.water': 'water' } }); w = new Water(e, opts, ctx.track); return w; }, frame(dt, e) { w.update(e.focus, dt); }, dispose() { w.dispose(); },
239
239
  // "is there water where I think": the global sea (its level and plane size; null = none, e.g. no water level) and each separate body
240
240
  describe() {
241
241
  const r = v => Math.round(v * 10) / 10, s = w.sea;
@@ -8,11 +8,11 @@
8
8
  // base = material color and opacity; wave = threedogWaterWave at this point; facing = 1 looking straight down, 0 at grazing angles;
9
9
  // returns the color and opacity lighting starts from
10
10
  import * as THREE from 'three';
11
- import { closest } from '../../core/validate.js';
12
- import { readParams, keysSchema } from '../../core/params.js';
11
+ import { closest } from '../../core/base/validate.js';
12
+ import { readParams, keysSchema } from '../../core/base/params.js';
13
13
  import { declareUniforms } from '../../render/uniformDecl.js';
14
14
  import { hashText } from '../../render/effects.js';
15
- import { codedError } from '../../core/errorHints.js';
15
+ import { codedError } from '../../core/base/errorHints.js';
16
16
  import { glslFloat as gf, WAVE as W, WAVE_MAX, DEPTH, FOAM } from '../../render/fxNumbers.js';
17
17
 
18
18
  const DEPTH_KEYS = ['shallow', 'deep', 'by', 'curve'];