threedog 0.0.0-stage → 0.2.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 (506) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -2
  4. package/core/Animator.js +268 -0
  5. package/core/Assets.js +256 -0
  6. package/core/Audio.js +267 -0
  7. package/core/Baked.js +72 -0
  8. package/core/Batching.js +247 -0
  9. package/core/Budget.js +221 -0
  10. package/core/Clock.js +94 -0
  11. package/core/Commits.js +77 -0
  12. package/core/DebugOverrides.js +143 -0
  13. package/core/Describe.js +145 -0
  14. package/core/Engine.js +184 -0
  15. package/core/Events.js +153 -0
  16. package/core/I18n.js +94 -0
  17. package/core/Input.js +245 -0
  18. package/core/Inspect.js +77 -0
  19. package/core/InspectScene.js +191 -0
  20. package/core/Jobs.js +146 -0
  21. package/core/Loading.js +149 -0
  22. package/core/MaterialInfo.js +32 -0
  23. package/core/Ops.js +256 -0
  24. package/core/Random.js +52 -0
  25. package/core/Rays.js +160 -0
  26. package/core/SaveStore.js +85 -0
  27. package/core/Saves.js +254 -0
  28. package/core/Stream.js +279 -0
  29. package/core/Threads.js +158 -0
  30. package/core/UrlState.js +94 -0
  31. package/core/Vars.js +35 -0
  32. package/core/Views.js +49 -0
  33. package/core/actor.js +23 -0
  34. package/core/assetEntry.js +89 -0
  35. package/core/assetLoad.js +190 -0
  36. package/core/assetManifest.js +35 -0
  37. package/core/assetReport.js +83 -0
  38. package/core/audioRules.js +121 -0
  39. package/core/audioVoice.js +225 -0
  40. package/core/batchGroups.js +116 -0
  41. package/core/canvasBox.js +63 -0
  42. package/core/catalog.js +169 -0
  43. package/core/checks.js +67 -0
  44. package/core/claims.js +51 -0
  45. package/core/dayTime.js +15 -0
  46. package/core/debugView.js +76 -0
  47. package/core/describeRender.js +45 -0
  48. package/core/describeText.js +143 -0
  49. package/core/easing.js +34 -0
  50. package/core/errorCodes.js +205 -0
  51. package/core/errorHints.js +208 -0
  52. package/core/errors.js +40 -0
  53. package/core/events.generated.js +84 -0
  54. package/core/ground.js +102 -0
  55. package/core/holds.js +106 -0
  56. package/core/inputContext.js +69 -0
  57. package/core/inputDefaults.js +22 -0
  58. package/core/inputPad.js +35 -0
  59. package/core/inputPointer.js +48 -0
  60. package/core/inputTouch.js +48 -0
  61. package/core/lifecycle.js +69 -0
  62. package/core/lightWatch.js +56 -0
  63. package/core/look/coreParts.js +112 -0
  64. package/core/look/layers.js +136 -0
  65. package/core/look/part.js +173 -0
  66. package/core/look/report.js +79 -0
  67. package/core/look/write.js +86 -0
  68. package/core/loop.js +200 -0
  69. package/core/math.js +33 -0
  70. package/core/modules.js +196 -0
  71. package/core/movement.js +19 -0
  72. package/core/mulberry32.js +14 -0
  73. package/core/opsAtomic.js +31 -0
  74. package/core/opsCheck.js +97 -0
  75. package/core/opsFail.js +20 -0
  76. package/core/opsGuard.js +26 -0
  77. package/core/opsHistory.js +27 -0
  78. package/core/opsRun.js +77 -0
  79. package/core/page.js +78 -0
  80. package/core/params.js +132 -0
  81. package/core/pureWorker.js +5 -0
  82. package/core/renamed.js +21 -0
  83. package/core/saveApply.js +128 -0
  84. package/core/saveFiles.js +139 -0
  85. package/core/saveIds.js +53 -0
  86. package/core/saveVersions.js +97 -0
  87. package/core/scatter.js +92 -0
  88. package/core/sceneMethods.js +100 -0
  89. package/core/screenToGround.js +39 -0
  90. package/core/services.js +73 -0
  91. package/core/session.js +171 -0
  92. package/core/shadowTypes.js +15 -0
  93. package/core/skip.js +104 -0
  94. package/core/startup.js +135 -0
  95. package/core/streamCells.js +24 -0
  96. package/core/streamSources.js +73 -0
  97. package/core/styleParts.js +96 -0
  98. package/core/targeting.js +64 -0
  99. package/core/thingExplain.js +68 -0
  100. package/core/thingOps.js +168 -0
  101. package/core/things.js +212 -0
  102. package/core/threadPure.js +120 -0
  103. package/core/threadServe.js +25 -0
  104. package/core/tier.js +11 -0
  105. package/core/util.js +11 -0
  106. package/core/validate.js +204 -0
  107. package/docs/AI.md +123 -0
  108. package/docs/API.md +83 -0
  109. package/docs/CODEMAP.md +347 -0
  110. package/docs/COMMANDS.md +108 -0
  111. package/docs/CONVENTIONS.md +145 -0
  112. package/docs/PERF.md +217 -0
  113. package/docs/THREE.md +86 -0
  114. package/docs/api/ambience.md +15 -0
  115. package/docs/api/assets.md +62 -0
  116. package/docs/api/audio.md +53 -0
  117. package/docs/api/budget.md +40 -0
  118. package/docs/api/cameraRig.md +120 -0
  119. package/docs/api/characters.md +144 -0
  120. package/docs/api/clock.md +7 -0
  121. package/docs/api/collision.md +39 -0
  122. package/docs/api/content.md +64 -0
  123. package/docs/api/dialogue.md +39 -0
  124. package/docs/api/engine.md +199 -0
  125. package/docs/api/entities.md +61 -0
  126. package/docs/api/events.md +95 -0
  127. package/docs/api/flow.md +27 -0
  128. package/docs/api/grids.md +11 -0
  129. package/docs/api/ground.md +16 -0
  130. package/docs/api/hlod.md +34 -0
  131. package/docs/api/hud.md +31 -0
  132. package/docs/api/i18n.md +10 -0
  133. package/docs/api/input.md +24 -0
  134. package/docs/api/interactions.md +31 -0
  135. package/docs/api/inventory.md +66 -0
  136. package/docs/api/jobs.md +10 -0
  137. package/docs/api/level.md +41 -0
  138. package/docs/api/lightPool.md +56 -0
  139. package/docs/api/music.md +34 -0
  140. package/docs/api/nav.md +26 -0
  141. package/docs/api/net.md +14 -0
  142. package/docs/api/openWorld.md +24 -0
  143. package/docs/api/particles.md +41 -0
  144. package/docs/api/photo.md +15 -0
  145. package/docs/api/post.md +10 -0
  146. package/docs/api/quests.md +36 -0
  147. package/docs/api/rays.md +26 -0
  148. package/docs/api/rigid.md +84 -0
  149. package/docs/api/saves.md +32 -0
  150. package/docs/api/settings.md +36 -0
  151. package/docs/api/sky.md +58 -0
  152. package/docs/api/stream.md +31 -0
  153. package/docs/api/style.md +134 -0
  154. package/docs/api/terrain.md +34 -0
  155. package/docs/api/timeline.md +39 -0
  156. package/docs/api/tools.md +57 -0
  157. package/docs/api/triggers.md +56 -0
  158. package/docs/api/vars.md +9 -0
  159. package/docs/api/vegetation.md +52 -0
  160. package/docs/api/water.md +48 -0
  161. package/docs/api/weather.md +29 -0
  162. package/docs/api/world.md +30 -0
  163. package/docs/recipes/01-new-game.md +148 -0
  164. package/docs/recipes/02-npc.md +167 -0
  165. package/docs/recipes/03-items-pickups.md +158 -0
  166. package/docs/recipes/04-quests.md +83 -0
  167. package/docs/recipes/05-props-bake.md +159 -0
  168. package/docs/recipes/06-clock-events.md +117 -0
  169. package/docs/recipes/07-flow-scenes-pause.md +132 -0
  170. package/docs/recipes/08-weather-sky.md +74 -0
  171. package/docs/recipes/09-style-pack.md +234 -0
  172. package/docs/recipes/10-blender-level.md +67 -0
  173. package/docs/recipes/11-vehicles.md +55 -0
  174. package/docs/recipes/12-navmesh.md +79 -0
  175. package/docs/recipes/13-animation.md +149 -0
  176. package/docs/recipes/14-custom-module.md +91 -0
  177. package/docs/recipes/15-perf.md +78 -0
  178. package/docs/recipes/16-dev-bridge.md +180 -0
  179. package/docs/recipes/18-world.md +185 -0
  180. package/docs/recipes/19-shooting-picking.md +76 -0
  181. package/docs/recipes/20-content-actions-save.md +176 -0
  182. package/docs/recipes/21-camera.md +153 -0
  183. package/docs/recipes/22-shop-gold.md +107 -0
  184. package/docs/recipes/23-ops.md +175 -0
  185. package/docs/recipes/26-ui-parts.md +138 -0
  186. package/docs/recipes/27-net.md +96 -0
  187. package/docs/recipes/28-terrain.md +80 -0
  188. package/docs/recipes/29-grid.md +87 -0
  189. package/docs/recipes/30-templates.md +131 -0
  190. package/docs/recipes/31-audio.md +126 -0
  191. package/docs/recipes/32-action-game.md +33 -0
  192. package/docs/recipes/33-stream-sources.md +37 -0
  193. package/docs/recipes/34-environment-lighting.md +36 -0
  194. package/docs/recipes/35-style-from-reference.md +89 -0
  195. package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
  196. package/docs/recipes/37-terrain-look-hooks.md +97 -0
  197. package/docs/recipes/38-environment-look-hooks.md +83 -0
  198. package/docs/recipes/40-scene.md +108 -0
  199. package/docs/recipes/41-thing-registry.md +93 -0
  200. package/docs/recipes/42-terrain-shape.md +64 -0
  201. package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
  202. package/docs/recipes/44-water-weather-look-hooks.md +135 -0
  203. package/docs/recipes/45-cascaded-shadows.md +51 -0
  204. package/docs/recipes/46-blender-art-route.md +114 -0
  205. package/docs/recipes/47-island-snow-backdrop.md +44 -0
  206. package/docs/recipes/48-make-material.md +70 -0
  207. package/docs/recipes/49-game-module-contract.md +71 -0
  208. package/docs/recipes/50-own-renderer.md +12 -0
  209. package/docs/recipes/51-capability-catalog.md +63 -0
  210. package/docs/recipes/52-look.md +108 -0
  211. package/examples/action/DESIGN.md +3 -0
  212. package/examples/action/GAMEMAP.md +127 -0
  213. package/examples/action/content/actions.js +8 -0
  214. package/examples/action/content/audio.js +9 -0
  215. package/examples/action/content/index.js +10 -0
  216. package/examples/action/content/items.js +4 -0
  217. package/examples/action/content/places.js +4 -0
  218. package/examples/action/content/props.js +11 -0
  219. package/examples/action/content/templates.js +10 -0
  220. package/examples/action/content/views.js +6 -0
  221. package/examples/action/look.js +5 -0
  222. package/examples/action/main.js +137 -0
  223. package/examples/action/models.js +25 -0
  224. package/examples/sheepisland/GAMEMAP.md +107 -0
  225. package/examples/sheepisland/content/index.js +6 -0
  226. package/examples/sheepisland/content/props.js +19 -0
  227. package/examples/sheepisland/content/templates.js +5 -0
  228. package/examples/sheepisland/content/vegetation.js +8 -0
  229. package/examples/sheepisland/main.js +71 -0
  230. package/examples/sheepisland/params.js +25 -0
  231. package/examples/sheepisland/style/index.js +79 -0
  232. package/examples/sheepisland/style/models.js +59 -0
  233. package/examples/sheepisland/views.js +9 -0
  234. package/examples/styletest/GAMEMAP.md +135 -0
  235. package/examples/styletest/content/index.js +9 -0
  236. package/examples/styletest/content/items.js +8 -0
  237. package/examples/styletest/content/npcs.js +8 -0
  238. package/examples/styletest/content/places.js +5 -0
  239. package/examples/styletest/content/props.js +16 -0
  240. package/examples/styletest/content/templates.js +9 -0
  241. package/examples/styletest/content/vegetation.js +31 -0
  242. package/examples/styletest/look.js +11 -0
  243. package/examples/styletest/main.js +95 -0
  244. package/examples/styletest/models.js +87 -0
  245. package/examples/styletest/overrides.js +33 -0
  246. package/examples/styletest/panel.js +135 -0
  247. package/examples/styletest/params.js +32 -0
  248. package/examples/styletest/views.js +31 -0
  249. package/examples/world/DESIGN.md +5 -0
  250. package/examples/world/GAMEMAP.md +171 -0
  251. package/examples/world/content/actions.js +8 -0
  252. package/examples/world/content/audio.js +25 -0
  253. package/examples/world/content/bodies.js +12 -0
  254. package/examples/world/content/containers.js +4 -0
  255. package/examples/world/content/dialogues.js +33 -0
  256. package/examples/world/content/index.js +17 -0
  257. package/examples/world/content/items.js +10 -0
  258. package/examples/world/content/npcs.js +14 -0
  259. package/examples/world/content/pickups.js +11 -0
  260. package/examples/world/content/places.js +6 -0
  261. package/examples/world/content/props.js +12 -0
  262. package/examples/world/content/quests.js +15 -0
  263. package/examples/world/content/rules.js +23 -0
  264. package/examples/world/content/templates.js +5 -0
  265. package/examples/world/content/vegetation.js +32 -0
  266. package/examples/world/main.js +168 -0
  267. package/examples/world/models.js +28 -0
  268. package/index.d.ts +306 -0
  269. package/index.js +122 -0
  270. package/llms.txt +61 -0
  271. package/modules/ambience/Ambience.js +186 -0
  272. package/modules/camera/FirstPersonCamera.js +131 -0
  273. package/modules/camera/FixedCamera.js +162 -0
  274. package/modules/camera/FollowCamera.js +91 -0
  275. package/modules/camera/RtsCamera.js +132 -0
  276. package/modules/camera/common.js +182 -0
  277. package/modules/camera/index.js +11 -0
  278. package/modules/camera/projection.js +34 -0
  279. package/modules/characters/Character.js +235 -0
  280. package/modules/characters/NPC.js +242 -0
  281. package/modules/characters/assetModel.js +42 -0
  282. package/modules/characters/astar.js +66 -0
  283. package/modules/characters/behaviors.js +72 -0
  284. package/modules/characters/footsteps.js +13 -0
  285. package/modules/characters/index.js +215 -0
  286. package/modules/characters/moveHelpers.js +29 -0
  287. package/modules/characters/movers/common.js +62 -0
  288. package/modules/characters/movers/rapier.js +74 -0
  289. package/modules/characters/movers/simple.js +43 -0
  290. package/modules/characters/npcAvoid.js +129 -0
  291. package/modules/characters/npcSim.js +150 -0
  292. package/modules/characters/npcView.js +42 -0
  293. package/modules/characters/pathAsync.js +113 -0
  294. package/modules/characters/pathJob.js +62 -0
  295. package/modules/characters/pathWorker.js +7 -0
  296. package/modules/characters/playerStrings.js +12 -0
  297. package/modules/characters/proceduralRig.js +58 -0
  298. package/modules/characters/useModel.js +22 -0
  299. package/modules/characters/walkTo.js +58 -0
  300. package/modules/collision/Collision.js +274 -0
  301. package/modules/collision/grid.js +63 -0
  302. package/modules/content/explain.js +13 -0
  303. package/modules/content/ids.js +95 -0
  304. package/modules/content/index.js +154 -0
  305. package/modules/content/loader.js +190 -0
  306. package/modules/content/models.js +69 -0
  307. package/modules/content/packs.js +69 -0
  308. package/modules/content/props.js +89 -0
  309. package/modules/content/rules.js +134 -0
  310. package/modules/content/templates.js +189 -0
  311. package/modules/debug/DebugPanel.js +174 -0
  312. package/modules/entities/Entities.js +243 -0
  313. package/modules/entities/build.js +25 -0
  314. package/modules/entities/index.js +4 -0
  315. package/modules/flow/index.js +101 -0
  316. package/modules/gameplay/Container.js +227 -0
  317. package/modules/gameplay/Containers.js +89 -0
  318. package/modules/gameplay/Dialogue.js +219 -0
  319. package/modules/gameplay/Interactions.js +253 -0
  320. package/modules/gameplay/Inventory.js +224 -0
  321. package/modules/gameplay/Quests.js +205 -0
  322. package/modules/gameplay/boxOps.js +60 -0
  323. package/modules/gameplay/dialogueBox.js +48 -0
  324. package/modules/gameplay/interactionPrompt.js +28 -0
  325. package/modules/gameplay/inventoryOps.js +137 -0
  326. package/modules/gameplay/pickups.js +115 -0
  327. package/modules/gameplay/questLog.js +54 -0
  328. package/modules/gameplay/questSave.js +71 -0
  329. package/modules/grid/Grid.js +184 -0
  330. package/modules/grid/Layer.js +142 -0
  331. package/modules/grid/index.js +236 -0
  332. package/modules/grid/ops.js +73 -0
  333. package/modules/grid/preview.js +85 -0
  334. package/modules/grid/tiles.js +79 -0
  335. package/modules/hlod/index.js +167 -0
  336. package/modules/hud/index.js +167 -0
  337. package/modules/hud/parts.js +80 -0
  338. package/modules/level/geometry.js +46 -0
  339. package/modules/level/heightfield.js +160 -0
  340. package/modules/level/index.js +233 -0
  341. package/modules/level/nodes.js +84 -0
  342. package/modules/lights/index.js +227 -0
  343. package/modules/music/Music.js +294 -0
  344. package/modules/music/index.js +2 -0
  345. package/modules/music/rules.js +28 -0
  346. package/modules/nav/index.js +156 -0
  347. package/modules/nav/navPath.js +17 -0
  348. package/modules/net/Client.js +137 -0
  349. package/modules/net/Host.js +117 -0
  350. package/modules/net/Net.js +49 -0
  351. package/modules/net/index.js +77 -0
  352. package/modules/net/sync.js +114 -0
  353. package/modules/net/transports.js +118 -0
  354. package/modules/particles/Particles.js +179 -0
  355. package/modules/particles/effect.js +112 -0
  356. package/modules/particles/shaders.js +28 -0
  357. package/modules/photo/Photo.js +146 -0
  358. package/modules/rigid/RigidBodies.js +265 -0
  359. package/modules/rigid/Vehicles.js +97 -0
  360. package/modules/rigid/sync.js +158 -0
  361. package/modules/settings/Settings.js +297 -0
  362. package/modules/settings/apply.js +21 -0
  363. package/modules/settings/index.js +3 -0
  364. package/modules/settings/sections.js +156 -0
  365. package/modules/settings/strings.js +53 -0
  366. package/modules/settings/view.js +65 -0
  367. package/modules/sky/Sky.js +259 -0
  368. package/modules/sky/calendar.js +80 -0
  369. package/modules/sky/cascades.js +125 -0
  370. package/modules/sky/clouds.js +79 -0
  371. package/modules/sky/domeLayers.js +33 -0
  372. package/modules/sky/environment.js +141 -0
  373. package/modules/sky/fog.js +139 -0
  374. package/modules/sky/frame.js +77 -0
  375. package/modules/sky/layers.js +69 -0
  376. package/modules/sky/look.js +51 -0
  377. package/modules/sky/lookFog.js +80 -0
  378. package/modules/sky/lookShadow.js +50 -0
  379. package/modules/sky/lookSky.js +108 -0
  380. package/modules/sky/schedule.js +80 -0
  381. package/modules/sky/shader.js +96 -0
  382. package/modules/sky/shadow.js +74 -0
  383. package/modules/sky/skyModule.js +60 -0
  384. package/modules/terrain/ChunkManager.js +260 -0
  385. package/modules/terrain/chunkJob.js +19 -0
  386. package/modules/terrain/chunkLevels.js +40 -0
  387. package/modules/terrain/chunkQueries.js +42 -0
  388. package/modules/terrain/chunkWorker.js +5 -0
  389. package/modules/terrain/index.js +118 -0
  390. package/modules/terrain/lookGround.js +61 -0
  391. package/modules/terrain/mountTerrain.js +32 -0
  392. package/modules/terrain/terrainColorMap.js +41 -0
  393. package/modules/terrain/terrainDefaults.js +39 -0
  394. package/modules/terrain/terrainEdit.js +139 -0
  395. package/modules/terrain/terrainGen.js +155 -0
  396. package/modules/terrain/terrainIsland.js +131 -0
  397. package/modules/terrain/terrainMesh.js +92 -0
  398. package/modules/terrain/terrainShape.js +108 -0
  399. package/modules/terrain/terrainShapeMain.js +41 -0
  400. package/modules/terrain/terrainTexture.js +44 -0
  401. package/modules/timeline/Timeline.js +253 -0
  402. package/modules/timeline/Tween.js +114 -0
  403. package/modules/timeline/letterbox.js +24 -0
  404. package/modules/timeline/shots.js +90 -0
  405. package/modules/triggers/index.js +268 -0
  406. package/modules/vegetation/Vegetation.js +256 -0
  407. package/modules/vegetation/groundChunks.js +177 -0
  408. package/modules/vegetation/index.js +43 -0
  409. package/modules/vegetation/lookWind.js +37 -0
  410. package/modules/vegetation/modelGeometry.js +21 -0
  411. package/modules/water/Water.js +160 -0
  412. package/modules/water/look.js +80 -0
  413. package/modules/water/surface.js +88 -0
  414. package/modules/weather/Weather.js +242 -0
  415. package/modules/weather/look.js +75 -0
  416. package/modules/weather/particles.js +92 -0
  417. package/modules/weather/shaders.js +49 -0
  418. package/modules/weather/strings.js +15 -0
  419. package/modules/world/World.js +231 -0
  420. package/modules/world/cells.js +42 -0
  421. package/modules/world/explain.js +11 -0
  422. package/modules/world/index.js +71 -0
  423. package/modules/world/persist.js +107 -0
  424. package/modules/world/pos.js +20 -0
  425. package/modules/world/records.js +89 -0
  426. package/modules/world/sim.js +175 -0
  427. package/modules/world/simFar.js +82 -0
  428. package/modules/world/state.js +115 -0
  429. package/modules/world/thingSource.js +44 -0
  430. package/modules/world/views.js +182 -0
  431. package/package.json +66 -4
  432. package/presets.js +96 -0
  433. package/render/PostFX.js +240 -0
  434. package/render/detail.js +105 -0
  435. package/render/effects.js +144 -0
  436. package/render/engineUniforms.js +23 -0
  437. package/render/fuse.js +84 -0
  438. package/render/lighting.js +100 -0
  439. package/render/lights.js +18 -0
  440. package/render/lookSurface.js +161 -0
  441. package/render/materials.js +220 -0
  442. package/render/patches.js +252 -0
  443. package/render/postLook.js +86 -0
  444. package/render/surface.js +69 -0
  445. package/render/uniformDecl.js +29 -0
  446. package/types/common.d.ts +34 -0
  447. package/types/core.d.ts +1965 -0
  448. package/types/gameplay.d.ts +1822 -0
  449. package/types/generated/core/Audio.d.ts +200 -0
  450. package/types/generated/core/Batching.d.ts +47 -0
  451. package/types/generated/core/Budget.d.ts +90 -0
  452. package/types/generated/core/Commits.d.ts +31 -0
  453. package/types/generated/core/DebugOverrides.d.ts +52 -0
  454. package/types/generated/core/Events.d.ts +89 -0
  455. package/types/generated/core/I18n.d.ts +30 -0
  456. package/types/generated/core/Input.d.ts +118 -0
  457. package/types/generated/core/Jobs.d.ts +41 -0
  458. package/types/generated/core/Ops.d.ts +203 -0
  459. package/types/generated/core/Random.d.ts +49 -0
  460. package/types/generated/core/Rays.d.ts +49 -0
  461. package/types/generated/core/Saves.d.ts +162 -0
  462. package/types/generated/core/Stream.d.ts +93 -0
  463. package/types/generated/core/Threads.d.ts +82 -0
  464. package/types/generated/core/Views.d.ts +33 -0
  465. package/types/generated/core/audioVoice.d.ts +47 -0
  466. package/types/generated/core/page.d.ts +18 -0
  467. package/types/generated/core/session.d.ts +48 -0
  468. package/types/generated/modules/ambience/Ambience.d.ts +48 -0
  469. package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
  470. package/types/generated/modules/flow/index.d.ts +10 -0
  471. package/types/generated/modules/grid/Grid.d.ts +151 -0
  472. package/types/generated/modules/grid/Layer.d.ts +65 -0
  473. package/types/generated/modules/grid/index.d.ts +86 -0
  474. package/types/generated/modules/hlod/index.d.ts +11 -0
  475. package/types/generated/modules/hud/index.d.ts +10 -0
  476. package/types/generated/modules/lights/index.d.ts +13 -0
  477. package/types/generated/modules/music/Music.d.ts +111 -0
  478. package/types/generated/modules/net/Net.d.ts +34 -0
  479. package/types/generated/modules/net/index.d.ts +53 -0
  480. package/types/generated/modules/net/transports.d.ts +58 -0
  481. package/types/generated/modules/particles/Particles.d.ts +69 -0
  482. package/types/generated/modules/sky/Sky.d.ts +145 -0
  483. package/types/generated/modules/sky/skyModule.d.ts +10 -0
  484. package/types/generated/modules/timeline/Timeline.d.ts +51 -0
  485. package/types/generated/modules/water/Water.d.ts +29 -0
  486. package/types/generated/modules/weather/Weather.d.ts +62 -0
  487. package/types/generated/modules/world/World.d.ts +242 -0
  488. package/types/generated/modules/world/index.d.ts +15 -0
  489. package/types/generated/render/PostFX.d.ts +125 -0
  490. package/types/generated/render/materials.d.ts +100 -0
  491. package/types/generated/render/patches.d.ts +41 -0
  492. package/types/generated/ui/Focus.d.ts +11 -0
  493. package/types/generated/ui/LoadingScreen.d.ts +2 -0
  494. package/types/generated/ui/UI.d.ts +57 -0
  495. package/types/nav.d.ts +52 -0
  496. package/types/physics.d.ts +592 -0
  497. package/types/style.d.ts +638 -0
  498. package/types/worker.d.ts +11 -0
  499. package/types/world.d.ts +772 -0
  500. package/ui/Focus.js +51 -0
  501. package/ui/LoadingScreen.js +42 -0
  502. package/ui/Parts.js +199 -0
  503. package/ui/UI.js +167 -0
  504. package/ui/defaults.js +85 -0
  505. package/ui/theme.js +124 -0
  506. package/ui/touchPart.js +49 -0
@@ -0,0 +1,177 @@
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
+ // ({ cx, cz, state, group, veg, colliders, ... }), streamed around every engine.stream source, placed by the same rule code (core/scatter.js)
3
+ // over engine.surface / slope / groundType -- whoever provides the ground. One InstancedMesh per species per chunk, LOD and shadows by ring.
4
+ //
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
+ // serializable data like a terrain generator. Placement is cheap (a few height lookups per attempt) and runs under a per-frame budget.
7
+ // Collision circles take effect at the tick engine.commits sets (lag by ring, built on the spot if still pending): machine speed never
8
+ // changes whether the player bumps into a tree, the same contract as terrain chunks.
9
+ // The ground changing (setGround, a level loaded or switched: ground.staticVersion) rebuilds every chunk.
10
+ import * as THREE from 'three';
11
+ import { makePlacer, makeNoise } from '../../core/scatter.js';
12
+ import { xzOf } from '../../core/math.js';
13
+ import { chunkRing } from '../../core/streamSources.js';
14
+
15
+ const COLLIDER_LAG = 30; // fixed steps before a chunk's tree collision counts, times (1 + ring); ring 1 counts at once while loading
16
+
17
+ export class GroundChunks {
18
+ /** 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 } = {}) {
20
+ this.engine = engine; this.veg = veg;
21
+ this.chunkSize = chunkSize; this.viewChunks = viewChunks; this.density = density; this.area = area; this.seed = seed;
22
+ this.chunks = new Map();
23
+ this.applyBudgetMs = 3; // max ms per frame spent placing and uploading chunks once playing (loading builds ring 1 at once)
24
+ this.gen = 0;
25
+ this.stats = { loaded: 0, visible: 0, instances: 0, queued: 0 };
26
+ this._want = []; this._centers = []; this._key = ''; this._ground = null; this._groundVer = undefined;
27
+ this._frustum = new THREE.Frustum(); this._m = new THREE.Matrix4();
28
+ const e = engine, { fbm } = makeNoise(seed);
29
+ this._place = makePlacer({ chunk: chunkSize, seed, fbm,
30
+ surface: (x, z) => e.surface(x, z), slope: (x, z) => e.slope(x, z), typeAt: (x, z) => e.groundType(x, z) });
31
+ }
32
+
33
+ get CHUNK() { return this.chunkSize; }
34
+ /** @internal vegetation plumbing: a species was added; chunks rebuild with it */
35
+ registerSpecies() { this.rebuild(); }
36
+ /** @internal vegetation / settings plumbing */
37
+ refreshLevels() { for (const c of this.chunks.values()) c.level = -1; }
38
+ /** Rings of chunks drawn around each stream source (the settings page's view distance); the next update loads / releases chunks to match */
39
+ setViewChunks(n) { this.viewChunks = n; this.refreshLevels(); }
40
+ /** Vegetation density multiplier (rebuilds all chunks) */
41
+ setDensity(d) { this.density = d; this.rebuild(); }
42
+ /** Drop every chunk; they are placed again around the stream sources (call it after changing the ground behind the same provider) */
43
+ rebuild() {
44
+ for (const c of this.chunks.values()) { c.ticket?.remove(); this._dispose(c); }
45
+ this.chunks.clear(); this._want = []; this._key = ''; this.gen++;
46
+ }
47
+
48
+ _inArea(cx, cz) {
49
+ // no area given: a level that provides the ground bounds it (its walkable meshes), so plants never grow past the model's edge onto the
50
+ // flat fallback ground around it; with no level (setGround / flat default) the ground is unbounded and so is the vegetation
51
+ const b = this.area ? null : this.engine.level?.heightfield?.bounds;
52
+ const a = this.area ?? (b && !b.isEmpty() ? { min: [b.min.x, b.min.z], max: [b.max.x, b.max.z] } : null);
53
+ if (!a) return true;
54
+ const CH = this.chunkSize;
55
+ return (cx + 1) * CH > a.min[0] && cx * CH < a.max[0] && (cz + 1) * CH > a.min[1] && cz * CH < a.max[1];
56
+ }
57
+ _ring(c) { return chunkRing(c.cx, c.cz, this._centers, this.viewChunks); }
58
+
59
+ /** @internal module frame hook: follow the ground, queue / release chunks around the sources, build within budget, LOD and culling */
60
+ update(sources, camera) {
61
+ const e = this.engine, G = e.ground, ver = G.staticVersion?.();
62
+ if (G !== this._ground || ver !== this._groundVer) { this._ground = G; this._groundVer = ver; this.rebuild(); }
63
+ const CH = this.chunkSize, V = this.viewChunks;
64
+ this._centers = sources.map(s => ({ cx: Math.floor(s.x / CH), cz: Math.floor(s.z / CH), simple: s.detail === 'simple',
65
+ R: s.radius == null ? V : Math.min(V, Math.max(1, Math.ceil(s.radius / CH))) }));
66
+ const key = this._centers.map(c => `${c.cx},${c.cz},${c.R},${c.simple}`).join('|') + '/' + V;
67
+ if (key !== this._key) { // only when a source changed chunk: no lists rebuilt on a quiet frame
68
+ this._key = key;
69
+ const d2 = c => { let m = Infinity; for (const s of this._centers) m = Math.min(m, (c.cx - s.cx) ** 2 + (c.cz - s.cz) ** 2); return m; };
70
+ for (const s of this._centers) for (let dz = -s.R; dz <= s.R; dz++) for (let dx = -s.R; dx <= s.R; dx++) {
71
+ const cx = s.cx + dx, cz = s.cz + dz, k = cx + ',' + cz;
72
+ if (dx * dx + dz * dz <= s.R * s.R + s.R && !this.chunks.has(k) && this._inArea(cx, cz)) this._want.push(this._queue(cx, cz, k));
73
+ }
74
+ this._want.sort((a, b) => d2(a) - d2(b));
75
+ const kept = c => this._centers.some(s => (c.cx - s.cx) ** 2 + (c.cz - s.cz) ** 2 <= (s.R + 1) * (s.R + 1) + s.R + 1);
76
+ for (const [k, c] of this.chunks) if (!kept(c)) { c.ticket?.remove(); this._dispose(c); this.chunks.delete(k); }
77
+ this._want = this._want.filter(c => this.chunks.get(c.key) === c);
78
+ }
79
+ const t0 = performance.now(), loading = !e.ready; // measure: placement budget
80
+ while (this._want.length) {
81
+ const c = this._want[0];
82
+ if (c.state !== 'queued' || this.chunks.get(c.key) !== c) { this._want.shift(); continue; }
83
+ if (performance.now() - t0 >= this.applyBudgetMs && !(loading && this._ring(c) <= 1)) break; // measure
84
+ this._want.shift(); this._build(c);
85
+ }
86
+ this.stats.queued = this._want.length;
87
+ camera.updateMatrixWorld();
88
+ this._m.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
89
+ this._frustum.setFromProjectionMatrix(this._m);
90
+ let visible = 0, instances = 0;
91
+ for (const c of this.chunks.values()) {
92
+ if (c.state !== 'ready') continue;
93
+ const ring = this._ring(c);
94
+ this._setLevel(c, ring);
95
+ const v = ring <= 1 || this._frustum.intersectsSphere(c.sphere);
96
+ c.group.visible = v;
97
+ if (v) { visible++; for (const n in c.veg) if (c.veg[n].visible) instances += c.veg[n].count; }
98
+ }
99
+ Object.assign(this.stats, { loaded: this.chunks.size, visible, instances });
100
+ }
101
+
102
+ _queue(cx, cz, key) {
103
+ const c = { cx, cz, key, state: 'queued', group: null, veg: {}, colliders: {}, collidersAll: {}, level: -1, sphere: null, solid: false, gen: this.gen };
104
+ this.chunks.set(key, c);
105
+ c.ticket = this.engine.commits.request({
106
+ lag: !this.engine.ready && this._ring(c) <= 1 ? 0 : COLLIDER_LAG * (1 + this._ring(c)),
107
+ apply: () => { c.solid = true; },
108
+ fallback: () => { if (c.state !== 'ready') this._build(c); return true; }, // due before the budget got to it: place it now, same result
109
+ valid: () => this.chunks.get(c.key) === c && c.gen === this.gen,
110
+ });
111
+ return c;
112
+ }
113
+
114
+ // place every species that this ring shows (near-only ones only within their ring) and upload them
115
+ _build(c) {
116
+ const CH = this.chunkSize, g = c.group = new THREE.Group();
117
+ g.userData.budgetTag = 'vegetation';
118
+ g.position.set(c.cx * CH, 0, c.cz * CH); g.matrixAutoUpdate = false; g.updateMatrix();
119
+ c.state = 'ready'; c.lo = Infinity; c.hi = -Infinity;
120
+ const ring = this._ring(c);
121
+ for (const sp of this.veg.list()) if (!sp.nearOnly || ring <= sp.maxRing) this._grow(c, sp);
122
+ if (c.lo > c.hi) { c.lo = c.hi = this.engine.surface(c.cx * CH + CH / 2, c.cz * CH + CH / 2); }
123
+ c.sphere = new THREE.Sphere(new THREE.Vector3(c.cx * CH + CH / 2, (c.lo + c.hi) / 2 + 3, c.cz * CH + CH / 2), Math.hypot(CH / 2, CH / 2, (c.hi - c.lo) / 2 + 8));
124
+ this.engine.scene.add(g); g.updateMatrixWorld(true);
125
+ }
126
+ _grow(c, sp) {
127
+ const r = this._place(c.cx, c.cz, sp.rule, this.density);
128
+ for (let i = 0; i < r.n; i++) { const y = r.m[i * 16 + 13]; if (y < c.lo) c.lo = y; if (y > c.hi) c.hi = y; }
129
+ this.veg.mount(c, sp.name, r);
130
+ }
131
+
132
+ _setLevel(c, ring) {
133
+ if (c.level === ring) return;
134
+ c.level = ring;
135
+ for (const sp of this.veg.list()) {
136
+ const im = c.veg[sp.name];
137
+ if (sp.nearOnly) {
138
+ if (ring <= sp.maxRing && !im) this._grow(c, sp);
139
+ else if (ring > sp.maxRing + 1 && im) this.veg.unmount(c, sp.name);
140
+ continue;
141
+ }
142
+ if (im) this.veg.levelOf(im, sp, ring);
143
+ }
144
+ }
145
+
146
+ _dispose(c) {
147
+ if (c.state !== 'ready') return;
148
+ this.engine.scene.remove(c.group);
149
+ for (const n in c.veg) c.veg[n].dispose();
150
+ }
151
+ dispose() { this.rebuild(); }
152
+
153
+ /** @internal Collision circles of solid chunks near (x, z): fn(x, z, r). Joined into engine.ground.forEachCollider (collision, path planning) */
154
+ forEachCollider(x, z, range, fn) {
155
+ const CH = this.chunkSize;
156
+ for (let cz = Math.floor((z - range) / CH); cz <= Math.floor((z + range) / CH); cz++)
157
+ for (let cx = Math.floor((x - range) / CH); cx <= Math.floor((x + range) / CH); cx++) {
158
+ const c = this.chunks.get(cx + ',' + cz);
159
+ if (!c?.solid) continue;
160
+ for (const n in c.colliders) {
161
+ const k = c.colliders[n];
162
+ 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]); }
163
+ }
164
+ }
165
+ }
166
+
167
+ /** Whether chunks within `rings` (default 1) of a position are placed (loading screen / stream ready check) */
168
+ isReadyAround(position, { rings = 1 } = {}) {
169
+ const [x, z] = xzOf(position), CH = this.chunkSize, pcx = Math.floor(x / CH), pcz = Math.floor(z / CH);
170
+ for (let dz = -rings; dz <= rings; dz++) for (let dx = -rings; dx <= rings; dx++) {
171
+ if (!this._inArea(pcx + dx, pcz + dz)) continue;
172
+ const c = this.chunks.get((pcx + dx) + ',' + (pcz + dz));
173
+ if (!c || c.state !== 'ready') return false;
174
+ }
175
+ return true;
176
+ }
177
+ }
@@ -0,0 +1,43 @@
1
+ // Vegetation module factory: engine.use(vegetation(...)). The class and its chunk plumbing are in Vegetation.js.
2
+ import { readParams, keysSchema } from '../../core/params.js';
3
+ import { Vegetation } from './Vegetation.js';
4
+ import { defineWindLook } from './lookWind.js';
5
+
6
+ const OPTS = ['chunkSize', 'viewChunks', 'density', 'area', 'seed'];
7
+ const VEG_PARAMS = keysSchema(OPTS, { chunkSize: 32, viewChunks: 3, density: 1, seed: 1 }); // defaults of the own-chunks mode (without terrain)
8
+ /**
9
+ * Vegetation module. Provides engine.vegetation.add(name, {...}) once installed.
10
+ * With terrain() installed first it grows on the terrain chunks and takes no options (density and view distance are terrain options).
11
+ * Without terrain it grows on its own chunks over whatever provides the ground: a level model (engine.level), a code-built ground
12
+ * (engine.setGround), or the flat default. Rules read engine.surface / slope / groundType, so a level's named surfaces are picked with
13
+ * rule.biomes (a level's ground type is the mesh's groundType property or its material name).
14
+ * @param {{ chunkSize?: number, viewChunks?: number, density?: number, area?: { min: number[], max: number[] }, seed?: number }} [opts]
15
+ * only without terrain: chunkSize meters (default 32), viewChunks rings drawn around each stream source (default 3), density multiplier (default 1),
16
+ * area { min: [x, z], max: [x, z] } where it may grow (default: a level's walkable bounds when a level provides the ground, else anywhere), seed placement seed
17
+ * (default 1)
18
+ * @example
19
+ * engine.use(level({ url: '/levels/town.glb' }), vegetation({ area: { min: [-80, -80], max: [80, 80] } }));
20
+ * engine.vegetation.add('grass', { geometry, nearOnly: true, rule: { perChunk: 400, biomes: { lawn: 1 } } }); // only on 'lawn' surfaces
21
+ */
22
+ export function vegetation(opts = {}) {
23
+ readParams('vegetation', VEG_PARAMS, opts);
24
+ let v = null, own = null, cols = null, ready = null;
25
+ return { name: 'vegetation', label: 'Vegetation', params: VEG_PARAMS, options: opts, stage: 'world', after: ['terrain', 'level'], optional: ['terrain', 'level'],
26
+ install(e) {
27
+ defineWindLook(e); // look.wind
28
+ v = new Vegetation(e, opts);
29
+ if (v.host !== e.terrain) {
30
+ own = v.host;
31
+ cols = e.addGroundColliders((x, z, range, fn) => own.forEachCollider(x, z, range, fn)); // collision and path planning see the trees
32
+ ready = e.stream.readyCheck('vegetation', s => own.isReadyAround(s));
33
+ }
34
+ return v;
35
+ },
36
+ // terrain installed after vegetation would leave two chunk tables: say where to put it
37
+ critical: true, // a wrong install order is a setup error, not something to play on with
38
+ init(e) { if (own && e.terrain) throw new Error('vegetation() was installed before terrain(): put terrain() first, vegetation then grows on its chunks'); },
39
+ frame(dt, e) { own?.update(e.stream.sources(), e.camera); },
40
+ fixed(dt) { v.tick(dt); }, skip(dt, e, done) { if (done) v.tick(1); },
41
+ describe(e, ctx) { if (own) ctx.out.perf.vegetation = { loaded: own.stats.loaded, visible: own.stats.visible, queued: own.stats.queued }; },
42
+ dispose() { own?.dispose(); cols?.remove(); ready?.remove(); } };
43
+ }
@@ -0,0 +1,37 @@
1
+ // look.wind: how plants sway. Registered by the vegetation module (it is the one that adds wind patches to its species' materials).
2
+ // set({ frequency, amplitude }) uniforms: live on every wind patch (trees already planted too)
3
+ // patch('sway', glsl) a threedogWind function (style.wind.glsl is the style layer); read when a species is ADDED, so patch before vegetation.add
4
+ // No replace: the sway patch already is the whole motion; weather's gusts (uWind) still scale it.
5
+ import { defineLookPart } from '../../core/look/part.js';
6
+ import { codedError } from '../../core/errorHints.js';
7
+ import { windCustom } from '../../render/materials.js';
8
+
9
+ const asObj = v => (typeof v === 'string' ? { glsl: v } : v);
10
+ /** The custom sway { glsl, uniforms } to give a new wind patch, or null for the built-in sway */
11
+ export function swayOf(e) { const v = e.look?.wind?.value('hook:sway'); return v ? asObj(v) : null; }
12
+
13
+ /** @param {any} e */
14
+ export function defineWindLook(e) {
15
+ if (e.look?.wind) return;
16
+ const u = e.uniforms, w = e.style.wind ?? {};
17
+ const part = defineLookPart(e, {
18
+ id: 'wind', group: 'motion', module: 'vegetation', object: () => u, docs: ['recipes/52-look.md'],
19
+ params: {
20
+ frequency: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'sway speed multiplier (style.wind.frequency)' },
21
+ amplitude: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: "multiplies every species' wind amplitude; 0 = plants stand still" },
22
+ },
23
+ style: () => ({ frequency: w.frequency, ...(w.glsl ? { 'hook:sway': { glsl: w.glsl, uniforms: w.uniforms } } : {}) }),
24
+ read: () => ({ frequency: u.uWindFreq.value, amplitude: u.uWindAmp.value }),
25
+ apply(v, changed) {
26
+ if (changed.has('frequency')) u.uWindFreq.value = v.frequency;
27
+ if (changed.has('amplitude')) u.uWindAmp.value = v.amplitude;
28
+ },
29
+ hooks: { sway: { signature: 'void threedogWind(inout vec3 transformed, vec3 ip, vec3 position)', scope: ['vertex'], example: 'engine.look.wind.patch("sway", glsl) // or { glsl, uniforms }' } },
30
+ noReplace: 'the sway patch already is the whole motion; patch("sway", glsl) rewrites it, set({ amplitude: 0 }) stops it',
31
+ });
32
+ const patch = part.patch.bind(part);
33
+ part.patch = (name, glsl, o) => { // a wrong sway function throws here, not later inside vegetation.add
34
+ if (glsl != null) { try { windCustom(asObj(glsl)); } catch (err) { throw codedError('look-param', `look.wind.patch('${name}'): ${err.message}`); } }
35
+ return patch(name, glsl, o);
36
+ };
37
+ }
@@ -0,0 +1,21 @@
1
+ import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
2
+ import { copyPatches } from '../../render/patches.js';
3
+
4
+ // Multi-material model (bark trunk + alpha-cut leaf cards) -> one geometry with a group per mesh + a material array, so a species stays
5
+ // one InstancedMesh: instance matrices, felling and LOD swaps work unchanged for every part. Only attributes all meshes share are kept.
6
+ /** @internal */
7
+ export function fromModel(root, label) {
8
+ root.updateMatrixWorld(true);
9
+ const inv = root.matrixWorld.clone().invert(), geos = [], mats = [];
10
+ root.traverse(n => {
11
+ if (!n.isMesh) return;
12
+ if (Array.isArray(n.material)) throw new Error(`${label}: model mesh '${n.name}' has several materials; split it into one mesh per material`);
13
+ geos.push(n.geometry.clone().applyMatrix4(n.matrixWorld.clone().premultiply(inv)));
14
+ mats.push(copyPatches(n.material, n.material.clone())); // the clone keeps the model material's own shader patches
15
+ });
16
+ if (!geos.length) throw new Error(`${label}: model has no meshes`);
17
+ const names = Object.keys(geos[0].attributes).filter(k => geos.every(g => g.attributes[k]));
18
+ const indexed = geos.every(g => g.index);
19
+ 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; });
20
+ return { geometry: mergeGeometries(ready, true), materials: mats };
21
+ }
@@ -0,0 +1,160 @@
1
+ // Water module: draws the global water plane (sea, big lakes; snaps to a grid following the focus so it doesn't "swim") and independent water bodies (mountain lakes, ponds, each with its own level).
2
+ // Look comes from the style pack's style.water: color, opacity, waves, surface quality (material factory 'water'), normal map, grazing-angle reflection.
3
+ //
4
+ // engine.use(water()); // global water only (level taken from the terrain water level)
5
+ // engine.use(water({ sea: false })); // no global water
6
+ // engine.use(water({ level: 4, size: 1200 })); // level and size are world state: here, never in the style
7
+ // const lake = engine.addWaterBody({ position: [120, 0, -40], radius: 25, level: 18 }); // add a mountain lake (can be added any time); lake.remove()
8
+ //
9
+ // three.js objects: engine.water.sea (global water Mesh, may be null), material (shared by all water), bodies (Map: water body → its Mesh)
10
+ // Style pack: water = { color, opacity, flat, waveHeight, waveScale, waveSpeed, normalMap: '/textures/water-n.jpg', normalScale, normalRepeat,
11
+ // normalSpeed: [x, z], fresnel: 0.6, segments, depthColor, foam, glsl: { wave, surface }, uniforms,
12
+ // material?: (engine, { uniforms, waves, surface, normalMap }) => Material } (look hooks: recipes/44-water-weather-look-hooks.md)
13
+ import * as THREE from 'three';
14
+ import { makeMaterial } from '../../render/materials.js';
15
+ import { placeholderTexture } from '../../render/effects.js';
16
+ import { patchMaterial } from '../../render/patches.js';
17
+ import { warnOnce } from '../../core/validate.js';
18
+ import { readParams, keysSchema } from '../../core/params.js';
19
+ import { waterLook, wavesPatch, surfacePatch } from './surface.js';
20
+ import { defineWaterLook } from './look.js';
21
+ /** @import { ModuleDef } from '../../types/core' */
22
+ /** @import { Object3D, Material, Vector3 } from '../../types/common' */
23
+ /** @import { WaterBody, WaterOptions } from '../../types/world' */
24
+ // Options accepted by water(): sea / level + any appearance item that overrides the style pack's style.water
25
+ const WATER_OPTIONS = ['sea', 'level', 'color', 'opacity', 'flat', 'waveHeight', 'waveScale', 'waveSpeed', 'fresnel', 'size', 'segments', 'normalMap',
26
+ 'normalScale', 'normalRepeat', 'normalSpeed', 'shininess', 'specular', 'material', 'depthColor', 'foam', 'glsl', 'uniforms'];
27
+ const WATER_PARAMS = keysSchema(WATER_OPTIONS);
28
+
29
+ /** engine.water */
30
+ export class Water {
31
+ /** @internal */
32
+ constructor(engine, opts = {}) {
33
+ /** @internal */ this.engine = engine;
34
+ /** @internal */ this.opts = opts;
35
+ /** @internal */ this.st = { color: 0x888888, opacity: 0.85, flat: true, waveHeight: 1, waveScale: 1, waveSpeed: 1, fresnel: 0.5,
36
+ size: 900, segments: 150, normalScale: 0.4, normalRepeat: 0.05, normalSpeed: [0.01, 0.006], ...(engine.style.water || {}), ...opts };
37
+ const st = this.st;
38
+ /** @internal */ this.cell = st.size / st.segments;
39
+ /** @internal */ this.normalMap = null;
40
+ if (st.normalMap) {
41
+ // normal map: a flat-normal placeholder until the asset loads, then it takes the asset's image source (shared, not copied;
42
+ // goes through asset management, so it can be preloaded and released)
43
+ const n = this.normalMap = placeholderTexture('normal'); n.wrapS = n.wrapT = THREE.RepeatWrapping;
44
+ engine.assets.texture(st.normalMap, { color: false }).then(t => { n.source = t.source; n.needsUpdate = true; }).catch(err => warnOnce(err.message));
45
+ }
46
+ /**
47
+ * Water material (shared by all water)
48
+ * @type {Material}
49
+ */
50
+ this.material = this._material();
51
+ /**
52
+ * Water body → mesh
53
+ * @type {Map<WaterBody, THREE.Mesh>}
54
+ */
55
+ this.bodies = new Map();
56
+
57
+ /**
58
+ * Global water mesh (null when absent)
59
+ * @type {THREE.Mesh | null}
60
+ */
61
+ this.sea = null;
62
+ /** @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
63
+ for (const b of engine.waterBodies) this._addBody(b);
64
+ defineWaterLook(this); // look.water: the style's values are its style layer, water({...}) options its 'game' layer
65
+ engine.events.on('water:add', b => this._addBody(b));
66
+ // material is shared by all bodies, so not engine.remove (which would dispose it); its ray registration goes too
67
+ engine.events.on('water:remove', b => { const m = this.bodies.get(b); if (m) { engine.detach(m); engine.rays.forget(m); m.geometry.dispose(); this.bodies.delete(b); } });
68
+ }
69
+
70
+ /** @internal */
71
+ _material() {
72
+ const st = this.st, e = this.engine;
73
+ const look = waterLook(st), surface = surfacePatch(e, look), waves = wavesPatch(e, st, look, !!surface);
74
+ // A whole custom surface (toon foam bands, pixel ripples): the engine still builds the meshes and keeps the shared uniforms and the
75
+ // normal-map scroll running; the built-in look (role 'water', waves, fresnel) is skipped. waves (and surface, when depthColor / foam /
76
+ // glsl.surface ask for one; it needs waves before it) are offered for applyEffects({ patches })
77
+ if (st.material) {
78
+ this._u = waves.uniforms;
79
+ const own = st.material(e, { uniforms: waves.uniforms, waves, surface, normalMap: this.normalMap });
80
+ if (!own?.isMaterial) throw new Error('style.water.material must return a three.js Material, e.g. material: (engine, { uniforms }) => new THREE.ShaderMaterial({ uniforms, vertexShader, fragmentShader })');
81
+ return own;
82
+ }
83
+ const m = makeMaterial('water', { color: st.color, transparent: st.opacity < 1, opacity: st.opacity, flatShading: st.flat, shininess: st.shininess ?? 90, specular: st.specular ?? 0xaaaaaa, roughness: 0.15, metalness: 0 }, e);
84
+ if (this.normalMap && 'normalMap' in m) {
85
+ const lit = /** @type {THREE.MeshPhongMaterial | THREE.MeshStandardMaterial} */ (m); // only lit materials have normalMap; the `in` test guarantees it
86
+ lit.normalMap = this.normalMap; lit.normalScale = new THREE.Vector2(st.normalScale, st.normalScale);
87
+ }
88
+ const grey = new THREE.Color(0xcccccc);
89
+ const patches = surface ? [waves, surface] : [waves];
90
+ const uFresnel = { value: st.fresnel };
91
+ this._u = { ...waves.uniforms, uFresnel }; // the live uniforms look.water.set writes
92
+ // grazing-angle reflection: the flatter the view, the closer to the fog (horizon) color; the getter follows whatever fog exists at draw time.
93
+ // Basic material has no normal/view variables, so it gets no reflection
94
+ if (!('isMeshBasicMaterial' in m)) patches.push({ name: 'fresnel',
95
+ uniforms: { uFresnel, uFresnelColor: { get value() { return e.scene.fog?.color ?? grey; } } },
96
+ glsl: { fragment: { pars: 'uniform float uFresnel; uniform vec3 uFresnelColor;', opaque_fragment: { before: `
97
+ float threedogFres = pow(1.0 - abs(dot(normalize(vViewPosition), normal)), 3.0) * uFresnel;
98
+ outgoingLight = mix(outgoingLight, uFresnelColor, clamp(threedogFres, 0.0, 1.0));` } } } });
99
+ return patchMaterial(m, patches, { strict: false });
100
+ }
101
+ /** Build the shared material again (look.water changed something structural) and hand it to every water mesh @internal */
102
+ _rebuild() {
103
+ const old = this.material;
104
+ this.material = this._material();
105
+ for (const m of [this.sea, ...this.bodies.values()]) if (m) m.material = this.material;
106
+ old.dispose();
107
+ }
108
+ /** @internal */
109
+ _prep(mesh, size) {
110
+ mesh.receiveShadow = true; mesh.renderOrder = 1;
111
+ if (this.normalMap) { const uv = mesh.geometry.attributes.uv; for (let i = 0; i < uv.count; i++) uv.setXY(i, uv.getX(i) * size * this.st.normalRepeat, uv.getY(i) * size * this.st.normalRepeat); }
112
+ }
113
+ /** @internal */
114
+ _addBody(b) {
115
+ const seg = Math.max(4, Math.round((b.radius ? b.radius * 2 : Math.max(b.hw, b.hd) * 2) / this.cell));
116
+ const geo = b.radius ? new THREE.CircleGeometry(b.radius, Math.max(16, seg * 2)).rotateX(-Math.PI / 2) : new THREE.PlaneGeometry(b.hw * 2, b.hd * 2, seg, seg).rotateX(-Math.PI / 2);
117
+ const m = new THREE.Mesh(geo, this.material);
118
+ m.position.set(b.x, b.level - 0.1, b.z);
119
+ this._prep(m, b.radius ? b.radius * 2 : Math.max(b.hw, b.hd) * 2);
120
+ this.engine.add(m, { owner: 'engine:water' });
121
+ this.bodies.set(b, m);
122
+ }
123
+ /** @internal */
124
+ _makeSea() {
125
+ this._seaChecked = true;
126
+ const st = this.st, level = st.level ?? (Number.isFinite(this.engine.waterLevel) ? this.engine.waterLevel : null);
127
+ if (level == null) return;
128
+ this.sea = new THREE.Mesh(new THREE.PlaneGeometry(st.size, st.size, st.segments, st.segments).rotateX(-Math.PI / 2), this.material);
129
+ this.sea.position.y = level - 0.2;
130
+ this._prep(this.sea, st.size);
131
+ this.engine.add(this.sea, { owner: 'engine:water' });
132
+ }
133
+ /**
134
+ * Per-frame update: global water snaps to the focus grid, normal map scrolls (called by the module itself each frame)
135
+ * @param {Vector3} focus
136
+ * @param {number} dt
137
+ * @returns {void}
138
+ * @internal
139
+ */
140
+ update(focus, dt) {
141
+ if (!this._seaChecked) this._makeSea();
142
+ if (this.sea) {
143
+ const c = this.cell * 4;
144
+ this.sea.position.x = Math.round(focus.x / c) * c;
145
+ this.sea.position.z = Math.round(focus.z / c) * c;
146
+ }
147
+ if (this.normalMap) { this.normalMap.offset.x += this.st.normalSpeed[0] * dt; this.normalMap.offset.y += this.st.normalSpeed[1] * dt; }
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Water → engine.water. Global level defaults to the terrain water level; independent bodies use engine.addWaterBody()
153
+ * @param {WaterOptions} [opts]
154
+ * @returns {ModuleDef<Water>}
155
+ */
156
+ export function water(opts = {}) {
157
+ readParams('water', WATER_PARAMS, opts);
158
+ let w = null;
159
+ return { name: 'water', label: 'Water', params: WATER_PARAMS, options: opts, stage: 'environment', after: ['sky'], install(e) { w = new Water(e, opts); return w; }, frame(dt, e) { w.update(e.focus, dt); } };
160
+ }
@@ -0,0 +1,80 @@
1
+ // look.water: the water's look as a look part (recipes/52-look.md).
2
+ // set({ color, opacity, waveHeight, waveScale, waveSpeed, fresnel }) live: uniforms and material fields, no recompile
3
+ // set({ depthColor, foam }) structural: the shared material is rebuilt once (one recompile)
4
+ // patch('wave' | 'surface', glsl) the GLSL hooks of style.water.glsl (recipes/44)
5
+ // replace((engine, { uniforms, waves, surface, normalMap }) => Material) the whole surface (style.water.material)
6
+ // The style layer is style.water; the options of water({...}) are the game's own layer ('game'). Why a rebuild and not a patch of the old
7
+ // material: depthColor / foam / hooks decide which GLSL exists, and the shader is part of the material program.
8
+ import { defineLookPart, REPLACE } from '../../core/look/part.js';
9
+ import { waterLook } from './surface.js';
10
+
11
+ const WHY = 'the water module draws a plain gray, mostly opaque sea when the style gives none';
12
+ const OFF = "engine.use(water({ sea: false })) for no global water, or look.water.set({ opacity: 0 }) to hide the surface";
13
+ const KEYS = ['color', 'opacity', 'waveHeight', 'waveScale', 'waveSpeed', 'fresnel', 'depthColor', 'foam'];
14
+ const UN = { waveHeight: 'uWave', waveScale: 'uWaveScale', waveSpeed: 'uWaveSpeed', fresnel: 'uFresnel' }; // the uniforms behind the live keys
15
+ const STRUCT = ['depthColor', 'foam'];
16
+ const validate = (w, k) => v => { try { waterLook({ ...w.st, [k]: v }); return null; } catch (err) { return err.message; } };
17
+
18
+ /** @param {any} w the Water module */
19
+ export function defineWaterLook(w) {
20
+ const e = w.engine, st = w.st, g = st.glsl ?? {};
21
+ const pick = o => Object.fromEntries(KEYS.filter(k => o[k] !== undefined).map(k => [k, o[k]]));
22
+ const built = { sig: '', material: undefined };
23
+ const sig = () => JSON.stringify([st.depthColor ?? null, st.foam ?? null, st.glsl ?? null]);
24
+ built.sig = sig(); built.material = st.material;
25
+ const live = (k, v) => {
26
+ const m = w.material, u = w._u;
27
+ if (k === 'color' && !st.material && m.color) m.color.set(v);
28
+ else if (k === 'opacity' && !st.material) { const t = v < 1; m.opacity = v; if (m.transparent !== t) { m.transparent = t; m.needsUpdate = true; } }
29
+ else if (u?.[UN[k]]) u[UN[k]].value = v;
30
+ };
31
+ const rebuild = () => {
32
+ const now = sig();
33
+ if (now === built.sig && st.material === built.material) return; // the same structure again (e.g. the game layer repeating the style): nothing to do
34
+ built.sig = now; built.material = st.material;
35
+ w._rebuild();
36
+ };
37
+ const p = defineLookPart(e, {
38
+ id: 'water', group: 'surface', module: 'water', object: () => ({ material: w.material, sea: w.sea }), docs: ['recipes/52-look.md'], applyAtStart: false,
39
+ params: {
40
+ color: { type: 'any', default: 0x888888, cost: 'uniform', why: WHY, off: OFF, desc: 'base color (any THREE.Color input)' },
41
+ opacity: { type: 'number', default: 0.85, min: 0, max: 1, cost: 'uniform', why: WHY, off: OFF },
42
+ waveHeight: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'multiplies the wave function (0 = flat)' },
43
+ waveScale: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'world position scale fed to the wave function' },
44
+ waveSpeed: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'time scale fed to the wave function' },
45
+ fresnel: { type: 'number', default: 0.5, min: 0, max: 1, cost: 'uniform', why: 'grazing angles blend toward the fog (horizon) color', off: 'look.water.set({ fresnel: 0 })' },
46
+ depthColor: { type: 'any', default: null, neutral: true, cost: 'recompile', desc: '{ shallow, deep, by: "view" | "wave", curve } or null; rebuilds the water material once', check: validate(w, 'depthColor') },
47
+ foam: { type: 'any', default: null, neutral: true, cost: 'recompile', desc: 'true | { color, start, end, opacity } or null; rebuilds the water material once', check: validate(w, 'foam') },
48
+ },
49
+ style: () => ({ ...pick(e.style.water ?? {}), ...(g.wave ? { 'hook:wave': g.wave } : {}), ...(g.surface ? { 'hook:surface': g.surface } : {}),
50
+ ...(e.style.water?.material ? { [REPLACE]: e.style.water.material } : {}) }),
51
+ read: () => ({ opacity: !st.material && w.material.opacity !== undefined ? w.material.opacity : undefined }),
52
+ apply(v, changed) {
53
+ for (const k of changed) { st[k] = v[k]; live(k, v[k]); }
54
+ if (STRUCT.some(k => changed.has(k))) rebuild();
55
+ },
56
+ hooks: {
57
+ wave: { signature: 'float threedogWaterWave(vec3 p, float t)', scope: ['uTime'], example: 'float threedogWaterWave(vec3 p, float t) { return sin(p.x + t) * 0.2; }' },
58
+ surface: { signature: 'vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time)', scope: ['uTime'],
59
+ example: 'vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) { return vec4(base.rgb * (0.8 + wave), base.a); }' },
60
+ },
61
+ applyHook(name, glsl) {
62
+ const was = st.glsl;
63
+ st.glsl = { ...was, [name]: glsl ?? undefined };
64
+ try { waterLook(st); rebuild(); } catch (err) { st.glsl = was; throw err; }
65
+ },
66
+ replace: { accepts: '(engine, { uniforms, waves, surface, normalMap }) => THREE.Material', loses: ['built-in role "water" material, fresnel, color and opacity (your material owns them)', 'depthColor / foam unless your material uses surface'] },
67
+ // checked before any layer is written: the replace slot is a function, a GLSL hook builds (waterLook compiles it on a copy of the state)
68
+ validate: (k, v) => k === REPLACE ? (typeof v === 'function' ? null : 'is (engine, { uniforms, waves, surface, normalMap }) => THREE.Material')
69
+ : k.startsWith('hook:') ? validate(w, 'glsl')({ ...w.st.glsl, [k.slice(5)]: v }) : null,
70
+ applyReplace(impl) {
71
+ st.material = impl ?? undefined; rebuild();
72
+ },
73
+ });
74
+ // water({...}) options are the game's layer
75
+ const o = w.opts ?? {}, mine = pick(o);
76
+ if (Object.keys(mine).length) p.set(mine);
77
+ if (o.glsl) for (const k of ['wave', 'surface']) if (o.glsl[k]) p.patch(k, o.glsl[k]);
78
+ if (o.material) p.replace(o.material);
79
+ return p;
80
+ }
@@ -0,0 +1,88 @@
1
+ // Water look hooks (recipes/44): the wave function, depth color, crest foam and a replaceable surface function.
2
+ // The defaults draw exactly the old water (tests/specs/appearance-water.mjs): with no depthColor / foam / glsl.surface the surface patch
3
+ // is not added at all, so a plain style pays nothing.
4
+ //
5
+ // style.water.glsl.wave float threedogWaterWave(vec3 p, float t) p = world position * waveScale, t = time * waveSpeed; returns the
6
+ // height before waveHeight (default peaks near ±0.29 = waveMax)
7
+ // style.water.glsl.surface vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time)
8
+ // base = material color and opacity; wave = threedogWaterWave at this point; facing = 1 looking straight down,
9
+ // 0 at grazing angles; returns the color and opacity lighting starts from
10
+ import * as THREE from 'three';
11
+ import { checkOptions, closest } from '../../core/validate.js';
12
+ import { declareUniforms } from '../../render/uniformDecl.js';
13
+ import { hashText } from '../../render/effects.js';
14
+
15
+ const GLSL_KEYS = ['wave', 'surface', 'waveMax'];
16
+ const DEPTH_KEYS = ['shallow', 'deep', 'by', 'curve'];
17
+ const FOAM_KEYS = ['color', 'start', 'end', 'opacity'];
18
+ const BY = ['view', 'wave'];
19
+
20
+ // The built-in wave sum as a function, so a style can replace the motion alone and keep the rest of the water
21
+ const WAVE = `float threedogWaterWave(vec3 p, float t) {
22
+ return sin(p.x * 0.21 + t * 1.1) * 0.12 + cos(p.z * 0.17 + t * 0.9) * 0.12 + sin((p.x + p.z) * 0.37 + t * 1.7) * 0.05; }`;
23
+
24
+ /**
25
+ * Check and normalize the look keys of style.water (throws on wrong values with the fix; unknown keys warn with the near name)
26
+ * @internal
27
+ */
28
+ export function waterLook(st) {
29
+ const g = st.glsl || {};
30
+ if (st.glsl !== undefined) {
31
+ if (typeof st.glsl !== 'object') throw new Error('style.water.glsl must be { wave?, surface?, waveMax? } (GLSL strings); see recipes/44-water-weather-look-hooks.md');
32
+ checkOptions('style.water.glsl', g, GLSL_KEYS);
33
+ if (g.wave != null && !/\bfloat\s+threedogWaterWave\s*\(/.test(g.wave)) throw new Error('style.water.glsl.wave must define `float threedogWaterWave(vec3 p, float t)` returning the wave height (p = world position * waveScale, t = time * waveSpeed)');
34
+ if (g.surface != null && !/\bvec4\s+threedogWaterSurface\s*\(/.test(g.surface)) throw new Error('style.water.glsl.surface must define `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time)` returning (rgb, opacity)');
35
+ }
36
+ const d = st.depthColor, f = st.foam === true ? {} : st.foam;
37
+ if (d) {
38
+ checkOptions('style.water.depthColor', d, DEPTH_KEYS);
39
+ const by = d.by ?? 'view';
40
+ if (!BY.includes(by)) throw new Error(`style.water.depthColor.by '${by}' must be 'view' (fresnel: shallow looking down, deep at grazing angles) or 'wave' (shallow on crests)` + (closest(by, BY) ? ` (did you mean '${closest(by, BY)}'?)` : ''));
41
+ }
42
+ if (f) checkOptions('style.water.foam', f, FOAM_KEYS);
43
+ return { wave: g.wave ?? WAVE, surface: g.surface, waveMax: g.waveMax ?? 0.29, depth: d || null, foam: f || null, custom: declareUniforms('style.water.uniforms', st.uniforms) };
44
+ }
45
+
46
+ /** The 'waves' patch: moves the vertices by threedogWaterWave; with a surface it also hands the height and world position to the fragment @internal */
47
+ export function wavesPatch(e, st, look, surface) {
48
+ const vary = surface ? 'varying float vThreedogWave; varying vec3 vThreedogWaterPos;' : '';
49
+ return { name: 'waves', cacheKey: hashText(look.wave + look.custom.decl + vary),
50
+ uniforms: { uTime: e.uniforms.uTime, uWave: { value: st.waveHeight }, uWaveScale: { value: st.waveScale }, uWaveSpeed: { value: st.waveSpeed }, ...look.custom.uniforms },
51
+ glsl: { vertex: { pars: `uniform float uTime; uniform float uWave; uniform float uWaveScale; uniform float uWaveSpeed;\n${look.custom.decl}\n${vary}\n${look.wave}`, begin_vertex: `
52
+ vec3 wp = (modelMatrix * vec4(position, 1.0)).xyz * uWaveScale; float tw = uTime * uWaveSpeed;
53
+ float threedogWave = threedogWaterWave(wp, tw);
54
+ transformed.y += threedogWave * uWave;` + (surface ? `
55
+ vThreedogWave = threedogWave; vThreedogWaterPos = (modelMatrix * vec4(transformed, 1.0)).xyz;` : '') } } };
56
+ }
57
+
58
+ /** The built-in surface function from depthColor / foam (numbers are uniforms; only which parts exist is in the code) */
59
+ function builtSurface(look) {
60
+ const { depth, foam } = look, body = [];
61
+ if (depth) body.push((depth.by ?? 'view') === 'view'
62
+ ? 'c = mix(uWaterShallow, uWaterDeep, pow(1.0 - facing, uWaterCurve));'
63
+ : 'c = mix(uWaterDeep, uWaterShallow, pow(clamp(0.5 + 0.5 * wave / THREEDOG_WAVE_MAX, 0.0, 1.0), uWaterCurve));');
64
+ if (foam) body.push('float fo = smoothstep(uFoamStart, uFoamEnd, wave / THREEDOG_WAVE_MAX) * uFoamOpacity;\n c = mix(c, uFoamColor, fo); a = mix(a, 1.0, fo);');
65
+ return `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) {
66
+ vec3 c = base.rgb; float a = base.a;
67
+ ${body.join('\n ')}
68
+ return vec4(c, a); }`;
69
+ }
70
+
71
+ /** The 'waterSurface' patch, or null when the style asks for none (then the old shader is untouched) @internal */
72
+ export function surfacePatch(e, look) {
73
+ if (!look.depth && !look.foam && !look.surface) return null;
74
+ const d = look.depth || {}, f = look.foam || {};
75
+ const fn = look.surface ?? builtSurface(look);
76
+ const uniforms = { uTime: e.uniforms.uTime, ...look.custom.uniforms,
77
+ uWaterShallow: { value: new THREE.Color(d.shallow ?? 0x4fb8c8) }, uWaterDeep: { value: new THREE.Color(d.deep ?? 0x0e3a5c) }, uWaterCurve: { value: d.curve ?? 1 },
78
+ uFoamColor: { value: new THREE.Color(f.color ?? 0xffffff) }, uFoamStart: { value: f.start ?? 0.55 }, uFoamEnd: { value: f.end ?? 0.85 }, uFoamOpacity: { value: f.opacity ?? 1 } };
79
+ const pars = `#define THREEDOG_WAVE_MAX ${(+look.waveMax).toFixed(4)}
80
+ uniform float uTime; uniform vec3 uWaterShallow; uniform vec3 uWaterDeep; uniform float uWaterCurve;
81
+ uniform vec3 uFoamColor; uniform float uFoamStart; uniform float uFoamEnd; uniform float uFoamOpacity;
82
+ ${look.custom.decl}
83
+ varying float vThreedogWave; varying vec3 vThreedogWaterPos;
84
+ ${fn}`;
85
+ // after color_fragment: lighting has not started, so lit materials shade the new color (and Basic, which has no normal, works too)
86
+ return { name: 'waterSurface', cacheKey: hashText(pars), needs: { patches: ['waves'] }, uniforms, glsl: { fragment: { pars, color_fragment: `
87
+ diffuseColor = threedogWaterSurface(diffuseColor, vThreedogWave, abs(normalize(cameraPosition - vThreedogWaterPos).y), vThreedogWaterPos, uTime);` } } };
88
+ }