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
@@ -7,7 +7,7 @@ shows in `describe()` and the dev bridge, and can be driven by ops, without spec
7
7
  1. **State.** Prefer world records (`engine.world.add({ kind, ... })`, recipe 18): saved, streamed and far-simulated for you. State that is not a
8
8
  record (a counter, a machine's queue) goes in `engine.saves.register(key, { save, load, version?, migrate? })`. Raise `version` by 1 whenever the
9
9
  saved shape changes and add `migrate: { oldVersion: d => newData }`. Never keep game state only in a closure or module variable.
10
- 2. **Time, normal play.** Store *when* something happened in game seconds (`engine.clock.now`), and derive the state from `now - startedAt`. Never use
10
+ 2. **Time, normal play.** Store *when* something happened in calendar seconds (`engine.clock.now`), and derive the state from `now - startedAt`. Never use
11
11
  `Date.now`, `performance.now` or `setTimeout` for game time: they ignore pause, time channels, `step` and saves. If you must accumulate, do it in
12
12
  the module `fixed(dt, e)` hook (dt is real seconds; a speed several systems change goes through `engine.mod`, recipe 06).
13
13
  3. **Time, skipped** (`engine.skip`, the op `time.skip`, recipe 06 section 2). `fixed` hooks, physics and near simulation do **not** run during a skip.
@@ -15,7 +15,7 @@ shows in `describe()` and the dev bridge, and can be driven by ops, without spec
15
15
  segment, `done` on the last; do heavy work once when `done`), or put the logic in a world record `far(rec, dt)`, which gets one catch-up call.
16
16
  4. **Observable.** Module hook `describe(e, ctx)` puts its return value in `describe().<module name>` (plain JSON; the bridge `describe <name>` and
17
17
  `describeText()` show it). A game without a module uses `engine.describe.add(name, fn)`. The name must be new (it throws on a clash).
18
- Every engine module has one (check rule R44 fails a module without it): keep it compact, the state an AI checks to verify the module worked.
18
+ Keep it compact: the state an AI checks to verify the module worked.
19
19
  5. **Actions are ops.** `engine.ops.define('noun.verb', { args, can, run, offers, reasons, desc })`. `can` is read-only and returns `true` or a reason
20
20
  string (a key of `reasons`); `run` changes state; `offers(e, ctx)` lists the arg sets possible right now (shown by the bridge `ops` command and
21
21
  `describe`). Call with `engine.ops.run(name, args)` -> `{ ok, value }` or `{ ok: false, code, facts, nextActions }` (read `r.code`). Never mutate state from UI code directly.
@@ -23,14 +23,14 @@ shows in `describe()` and the dev bridge, and can be driven by ops, without spec
23
23
  ## Declaring stage and dependencies
24
24
  `stage` only picks where the hooks run (first to last): `control, ground, environment, gameplay, effects, late (default), audio`; `before / after`
25
25
  (module names) only order modules inside one stage; a contradiction with the stage order throws. `requires: ['world']` names a capability that must already be provided (throws
26
- otherwise, naming both fixes: the engine's `world()` first, or your own module with `provides: ['world']`). `type` says what the module may own
27
- (recipe 14: `'rules'` for game logic like this one; a `'picture'` module may not define ops). `optional: { sky: 'what is lost without it' }` is a soft dependency (use `engine.sky?.`). Core never imports
26
+ otherwise, naming both fixes: the engine's `world()` first, or your own module with `provides: ['world']`). `type` says what the module owns
27
+ (recipe 14): none means `'rules'`, game logic like this one, and a module doing what its type does not usually own (a `'picture'` module defining an op) gets a dev warning, never a refusal. `optional: { sky: 'what is lost without it' }` is a soft dependency (use `engine.sky?.`). Core never imports
28
28
  modules. The module `name` must not clash with an existing engine property.
29
29
 
30
30
  ## One copyable module: something that finishes after a delay (a smelter, a turret recharge, a crop)
31
31
  ```js
32
32
  export const machines = () => {
33
- const started = new Map(); // id -> startedAt (game seconds)
33
+ const started = new Map(); // id -> startedAt (calendar seconds)
34
34
  return {
35
35
  name: 'machines', type: 'rules', stage: 'gameplay', requires: ['inventory'],
36
36
  install(e) {
@@ -7,6 +7,6 @@ const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
7
7
  const engine = createEngine({ renderer }); // canvas defaults to renderer.domElement
8
8
  ```
9
9
 
10
- - The engine configures only a renderer it created itself. With yours it sets nothing: pixel ratio (unless `pixelRatio` is given), size, tone mapping, exposure and shadow map stay as you left them, so set them yourself on the renderer. MSAA follows your renderer's `antialias` too (unless `createEngine({ antialias })` or `style.antialias` says otherwise; a value that differs from the renderer's runs the post chain's MSAA targets every frame).
10
+ - The engine configures only a renderer it created itself. With yours it sets nothing: pixel ratio (unless `pixelRatio` is given), size, tone mapping, exposure and shadow map stay as you left them, so set them yourself on the renderer. MSAA follows your renderer's `antialias` too (unless `createEngine({ antialias })` says otherwise; a value that differs from the renderer's runs the post chain's MSAA targets every frame).
11
11
  - **WebGLRenderer or three's WebGPURenderer.** On WebGPURenderer, materials, patches and post effects take their node / TSL forms (recipe 56). Everything else (scene, modules, input, saves, ops) does not depend on the renderer.
12
- - Changing the renderer, lights or post effects is yours to do at any time; the engine never warns. `engine.describe().render` (CLI: `describe render`) lists the current values and tags each `engine` / `style` / `game`, so an AI can see who set a picture.
12
+ - Changing the renderer, lights or post effects is yours to do at any time; the engine never warns. `engine.describe().render` (CLI: `describe render`) lists the current values; `describe().picture.writers` says which line wrote each on the dev server.
@@ -1,6 +1,6 @@
1
1
  # 52 Around the picture: reading it back, the post chain, who writes what
2
2
 
3
- **In this recipe**: Atmosphere · Surfaces · Water, weather · Post effect chain · Who writes it · Lower-level forms that stay
3
+ **In this recipe**: Atmosphere · Surfaces · Post effect chain · Who writes it
4
4
 
5
5
  The picture is plain three.js in a `picture/` folder that reads `engine.uniforms` ([recipe 62](62-picture-code.md)). This page covers what sits around that code: reading the picture back,
6
6
  trying a value out, and the engine pieces it talks to.
@@ -15,31 +15,16 @@ engine.catalog('post'); // a capability's entries and wh
15
15
  Which knob changes what on screen, and how to judge it for your picture: [recipe 60](60-judge-the-picture.md). Where picture code sits among the other ways to customize: `../CONVENTIONS.md` "Customization ladder".
16
16
 
17
17
  - The picture is not saved: after a load, your `picture/` code draws it again from your own state.
18
- - How bright a lit color comes out (three.js light units, with `renderer.toneMapping = THREE.AgXToneMapping`, exposure 1): a diffuse surface facing up receives
19
- `sun.intensity × sin(sun elevation) + hemi.intensity` (the hemisphere's sky color, since it faces up), and three divides by π, so a total of
20
- **about 3 (≈ π) shows mid-tone albedos (sRGB 0.35-0.65) at roughly their own value**: sun 2 high overhead + hemisphere 1, or a low sun 4 at 20° +
21
- hemisphere 1.6. Measured on three's AgX curve: total 2.5 for sRGB 0.35, 2.6 for 0.5, 3.4 for 0.65, 5.5 for 0.8 (AgX darkens light colors and
22
- pales saturated ones, so a pale or vivid palette needs more, or exposure). Walls and faces away from the sun get only their `N·L` share, and
23
- the environment (`scene.environment`) adds on top for Standard / Physical materials.
18
+ - How bright a lit color comes out (three.js light units, exposure 1): a diffuse surface facing up receives `sun.intensity × sin(sun elevation) + hemi.intensity` (the hemisphere's sky color,
19
+ since it faces up), and three divides by π, so a total near π shows mid-tone albedos at roughly their own value under `AgXToneMapping`. AgX darkens light colors and pales saturated ones,
20
+ so a pale or vivid palette needs more, or exposure. Walls and faces away from the sun get only their `N·L` share, and the environment (`scene.environment`) adds on top for Standard / Physical materials.
24
21
 
25
22
  ## Atmosphere: fog, sky
26
23
 
27
- - Fog: `engine.scene.fog` is the game's, [recipe 38](38-environment-hooks.md#fog-plain-threejs-signals-your-own-math).
28
- - The sky: plain values and calls on `engine.sky`, [recipe 08](08-weather-sky.md).
29
- - <a id="tsl-forms"></a>**tsl forms** (`renderer: 'webgpu'`): the GLSL hooks `engine.sky.clouds` and `engine.sky.layer` take `{ glsl, tsl }`; each renderer draws its own form and a missing one throws by name (`[webgpu-needs-tsl]` on WebGPU). `tsl: (ctx) => vec4 node`, ctx = the GLSL function's arguments as nodes plus the value so far (`ctx.clouds` the built-in kind, `ctx.color` the sky under a layer, `ctx.fog` what the fog kind alone draws), `ctx.uniforms` (the dome's, yours included), `ctx.fx.noise` / `hash` and `ctx.tsl` (three/tsl):
30
- `engine.sky.layer('glow', { glsl, tsl: ({ dir, tsl }) => tsl.vec4(1, 0.6, 0.3, tsl.smoothstep(0.3, 0.8, dir.y).mul(0.4)), blend: 'add' })`.
31
- - Shadows are `engine.shadows` and three.js, recipe 45.
32
- - Whether a picture reads as lit is mostly key against fill. The key (the sun or one main light) is the light that casts the shadow; the fill is
33
- everything else (sky and ground light, the environment). Shadowed surfaces see only the fill while lit ones see both, so the balance sets how
34
- deep the shadows look: less fill is harder and more dramatic, more fill softer and more readable, and there is no right ratio, only the one
35
- the game wants. A warm key over a cool fill (or the reverse) separates lit from shaded sides without more contrast. The shot's `light:`
36
- fact measures the ratio; judge the result on a shot with a known-colored object in shadow. To compare afterwards, the `sun-and-key-light`
37
- technique (`threedog examples pull sun-and-key-light`) shows three routes side by side.
38
- - Shadow detail is texels per meter: one shadow-map texel covers `2 x extent / mapSize` meters (for example the default `extent` 70 on a
39
- 2048 map is about 6.8 cm, twice that on the 1024 map of low tier and headless shots). A box much bigger than what the camera sees blurs
40
- the shadows of small things; a box smaller than it cuts shadows off. `engine.shadows.box(light, { extent })` sizes it; a depth bias scales with the
41
- texel, so re-check `bias` / `normalBias` after changing either.
42
- - Fog kinds and the fog hook in detail, the placeholder lights: [recipe 38](38-environment-hooks.md).
24
+ Fog and the placeholder lights: [recipe 34](34-environment-lighting.md). The sky: plain values and calls on `engine.sky`, [recipe 08](08-weather-sky.md). Shadows: `engine.shadows` and three.js, recipe 45. Water and weather: recipe 44.
25
+
26
+ <a id="tsl-forms"></a>**tsl forms** (`renderer: 'webgpu'`): the GLSL hooks `engine.sky.clouds` and `engine.sky.layer` take `{ glsl, tsl }`; each renderer draws its own form and a missing one throws by name (`[webgpu-needs-tsl]` on WebGPU). `tsl: (ctx) => vec4 node`, ctx = the GLSL function's arguments as nodes plus the value so far (`ctx.clouds` the built-in kind, `ctx.color` the sky under a layer, `ctx.fog` what the fog kind alone draws), `ctx.uniforms` (the dome's, yours included), `ctx.fx` (the `threedog/tsl` functions, `ctx.fx.noise` and `hash` among them) and `ctx.tsl` (three/tsl):
27
+ `engine.sky.layer('glow', { glsl, tsl: ({ dir, tsl }) => tsl.vec4(1, 0.6, 0.3, tsl.smoothstep(0.3, 0.8, dir.y).mul(0.4)), blend: 'add' })`.
43
28
 
44
29
  ## Surfaces: ground, plants, cloud shadow, season
45
30
 
@@ -48,38 +33,30 @@ engine.terrain.material = myGroundMaterial;
48
33
  engine.uniforms.uWindFreq.value = 1.5; engine.uniforms.uWindAmp.value = 0.5; // signals: live on every plant, planted ones too
49
34
  engine.vegetation.define('grass', { geometry, wind: { amplitude: 0.05, glsl, tsl } }); // your own sway: threedogWind(...) / tsl: (ctx) => moved position (recipe 36)
50
35
  engine.vegetation.color({ glsl: 'diffuseColor.rgb *= 0.8;', tsl: c => c.color.mul(0.8) }); // code in the color slot, live on planted species
51
- engine.terms.cloudShadow({ glsl: 'reflectedLight.directDiffuse *= myShade(vThreedogWorld);', tsl: c => ({ directDiffuse: c.directDiffuse.mul(myShadeNode) }) });
52
- engine.terms.cloudShadow(false); // no engine cloud shadow anywhere: draw your own
53
- engine.terms.season(kind => ({ glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, vec3(1.0), uCover.y);', tsl: c => myTint(c, kind) })); // your own season / snow tint
36
+ engine.shaderTerms.cloudShadow({ glsl: 'reflectedLight.directDiffuse *= myShade(vThreedogWorld);', tsl: c => ({ directDiffuse: c.directDiffuse.mul(myShadeNode) }) });
37
+ engine.shaderTerms.cloudShadow(false); // no engine cloud shadow anywhere: draw your own
38
+ engine.shaderTerms.season(kind => ({ glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, vec3(1.0), uGroundCover.y);', tsl: c => myTint(c, kind) })); // your own season / snow tint
54
39
  ```
55
40
 
56
- - Wind is signals: `engine.uniforms.uWind` (weather), `uWindFreq`, `uWindAmp`. A three.js material of yours sways with `applyEffects(mat, { wind: 0.03 })`; your own shader calls `threedogWind(position, origin, amplitude)` (`#include <threedog_wind>`) or `wind(position, origin, amplitude)` (`threedog/tsl`). `uWindFreq` is the start value of `uWindFreq`.
57
- - The plants: `engine.vegetation.color(glsl | { glsl, tsl, uniforms })` puts code in the `color` slot of every species' material, changed live. The whole plant picture is replaced as a module: `engine.use(myPlants, { replaces: 'vegetation-draw' })`.
58
- - `engine.terms.cloudShadow(spec)` and `engine.terms.season(spec)` put your own patch (`{ glsl, tsl, uniforms?, pars?, slot? }`, slot `lighting` / `color` by default) in place of the engine's on every material that carries the term, including ones built before the call; `false` removes the term; the handle's `remove()` gives the engine's back. The signals stay bound: `uCloud*` and `threedogCloudShadow(worldPos)`; `uFoliageTint` / `uGroundTint` / `uFoliageMix` / `uGroundMix`, `uCover` (cover amount alone, x foliage, y ground) and `threedogSeason(color, kind)` (TSL: `season(color, kind)`). `season` also takes `kind => spec` (kind `'foliage'` | `'ground'`). Each renderer draws its own form, and a missing one throws by name.
59
- - Cloud shadow values are signals: `engine.uniforms.uCloudShadow` (darkest, 0 = none), `uCloudScale`, `uCloudSpeed`. The term sits on engine materials and on what you pass to `applyEffects(mat)`; your own shader calls `threedogCloudShadow(worldPos)` (GLSL) or `cloudShadow(positionWorld)` (`threedog/tsl`). The engine adds it to no other material.
60
-
61
- ## Water, weather
62
-
63
- - Water is plain three.js on the module (`engine.water.material`, `engine.water.uniforms`, `engine.water.shader`): recipe 44.
64
- - Weather: `weather({ rain, snow })` gives the particles, `engine.weather.define(field, spec)` a game's own (recipe 44).
41
+ - Wind is signals: `engine.uniforms.uWind` (weather), `uWindFreq`, `uWindAmp`. A three.js material of yours sways with `applyEffects(mat, { wind: 0.03 })`; your own shader calls `threedogWind(position, origin, amplitude)` (`#include <threedog_wind>`) or `wind(position, origin, amplitude)` (`threedog/tsl`).
42
+ - The whole plant picture is replaced as a module: `engine.use(myPlants, { replaces: 'vegetation-draw' })`.
43
+ - `engine.shaderTerms.cloudShadow(spec)` and `engine.shaderTerms.season(spec)` put your own patch (`{ glsl, tsl, uniforms?, pars?, slot? }`, slot `lighting` / `color` by default) in place of the engine's on every material that carries the term, including ones built before the call; `false` removes the term; the handle's `remove()` gives the engine's back. The signals stay bound: `uWeatherCloud, uCloudShadow*` and `threedogCloudShadow(worldPos)`; `uFoliageTint` / `uGroundTint` / `uFoliageMix` / `uGroundMix`, `uGroundCover` (cover amount alone, x foliage, y ground) and `threedogSeason(color, kind)` (TSL: `season(color, kind)`). `season` also takes `kind => spec` (kind `'foliage'` | `'ground'`). Each renderer draws its own form, and a missing one throws by name.
44
+ - Cloud shadow values are signals: `engine.uniforms.uCloudShadow` (darkest, 0 = none), `uCloudShadowScale`, `uCloudShadowSpeed`. The term sits on engine materials and on what you pass to `applyEffects(mat)`; your own shader calls `threedogCloudShadow(worldPos)` (GLSL) or `cloudShadow(positionWorld)` (`threedog/tsl`). The engine adds it to no other material.
65
45
 
66
46
  ## Post effect chain
67
47
 
68
48
  Post-processing is an ordered list of named effects, and **`engine.post.add(x, { name, slot, order })` is the one way an effect gets
69
49
  in**: game code and the game's `plugins/` folder (a file that exports the Pass or effect) go through it, so every
70
50
  effect has a name, a handle and a row in `describe().slots` and `describe().render.post`. It returns `{ name, enabled, set(params), remove() }`, and
71
- `engine.post.get(name)` returns the same handle. A wrong shape throws with nothing added. `x` is a plain three.js Pass (WebGL),
72
- a TSL node function `(input, ctx) => node` (WebGPU), or an effect `{ name, create, node, fuse, slot, order, params, needsDepth, needsBuffers, backend, skipOnLowTier, facts }` (both renderers: give
73
- `create` and `node`, or a `fuse`; the last five are optional: `needsBuffers` lists extra scene outputs on WebGPU, `backend: 'webgpu'` marks an effect the WebGL2 backend cannot run, `skipOnLowTier` holds it when `engine.tier` is 'low', `facts` adds a line to `describe().render.post`; all explained on `PostEffect` in `api/post.md`). Each runs in a slot, then by `order` (low first):
74
- `scene` (replaces the scene render, one at a time, e.g. pixelation) -> `hdr` (linear color: outline, AO, bloom) -> tone mapping -> `ldr` (sRGB: LUT,
75
- palette, grain, vignette) -> `final` (FXAA / SMAA). An effect is `{ name, slot, order, params, create(ctx) => pass, update?(pass, params) }`; under
76
- WebGL the pass is any three.js postprocessing Pass, built the first time it is on (on WebGPU an effect gives `node` instead: recipe 56). To read the chain: `engine.post.object()` (the
77
- EffectComposer, null until post first runs) and `engine.post.targets()` (its render targets); both stay the engine's (it rebuilds passes,
78
- resizes, disposes), so change the chain through `engine.post`; to take the built chain over yourself, `engine.post.own()` (the engine stops rebuilding it, `own(false)` gives it back). A plain Pass is placed by its kind: one that renders `engine.scene` itself
79
- (`RenderPixelatedPass`, `SSAARenderPass`, `TAARenderPass`) goes in `scene` and replaces the engine's scene render (the scene is drawn once; a
80
- second one throws), FXAA / SMAA / TAA in `final`, any other in `hdr` after the effects already there; a RenderPass of `engine.scene` and an OutputPass are
81
- skipped (the engine has them). Without `{ name }` it is listed by class or shader name (`CopyShader#1`); its `remove()` does not dispose it.
82
- A game that renders the canvas itself (its own composer) takes the frame: the engine stops drawing and warns once `[own-frame]`.
51
+ `engine.post.get(name)` returns the same handle. A wrong shape throws with nothing added.
52
+
53
+ `x` is a plain three.js Pass (WebGL), a TSL node function `(input, ctx) => node` (WebGPU), or an effect `{ name, create, node, fuse, slot, order, params, update, needsDepth, needsBuffers, backend, skipOnLowTier, facts }`: both renderers when it gives `create` and `node`, or a `fuse`. `create(ctx) => pass` returns any three.js postprocessing Pass, built the first time the effect is on, and `update?(pass, params)` applies new params (on WebGPU `node`: recipe 56). The optional ones: `needsBuffers` lists extra scene outputs on WebGPU, `backend: 'webgpu'` marks an effect the WebGL2 backend cannot run, `skipOnLowTier` holds it when `engine.tier` is 'low', `facts` adds a line to `describe().render.post`.
54
+
55
+ Each runs in a slot, then by `order` (low first): `scene` (replaces the scene render, one at a time, e.g. pixelation) -> `hdr` (linear color: outline, AO, bloom) -> `tone` (replaces the tone-mapping output, one at a time; it must output display color) -> `ldr` (sRGB: LUT, palette, grain, vignette) -> `final` (FXAA / SMAA).
56
+
57
+ A plain Pass is placed by its kind: one that renders `engine.scene` itself (`RenderPixelatedPass`, `SSAARenderPass`, `TAARenderPass`) goes in `scene` and replaces the engine's scene render (the scene is drawn once; a second one throws), FXAA / SMAA / TAA in `final`, any other in `hdr` after the effects already there (`ldr` when you added it after an OutputPass); a RenderPass of `engine.scene` and an OutputPass are skipped (the engine has them). Without `{ name }` it is listed by class or shader name (`CopyShader#1`); its `remove()` does not dispose it.
58
+
59
+ To read the chain: `engine.post.object()` and `engine.post.targets()`; both stay the engine's (it rebuilds passes, resizes, disposes), so change the chain through `engine.post`; to take the built chain over, `engine.post.own()` (`own(false)` gives it back). A game that renders the canvas itself (its own composer) takes the frame: the engine stops drawing and warns once `[own-frame]`.
83
60
  ```js
84
61
  import { bloom, outline, vignette, lut } from '@threedog/post-effects'; // shared effects come from the add-on
85
62
  import { LUTPass } from 'three/addons/postprocessing/LUTPass.js';
@@ -91,42 +68,25 @@ engine.post.add({ name: 'myLut', slot: 'ldr', params: { lut: myLut }, create: ({
91
68
  // a plugin file brings the same effect with no main.js line: plugins/10-bloom.js
92
69
  export default bloom({ strength: 0.2 });
93
70
  ```
94
- - The engine ships no effects. `@threedog/post-effects` (import only what you use) has `bloom`, `ao`, `outline`, `dof` (all `hdr`; outline and dof
95
- read depth) and `lut` (contrast / saturation / warm-cool / optional 3D LUT, or `paletteLut(colors)` for a fixed palette; it reads display colors after the tone curve), `grain`, `vignette`, `chromatic` (`ldr`). An added effect is on
96
- (`enabled: false` adds it off, for `handle.enabled = true` later). The heavy ones (`bloom`, `ao`, `dof`, outline `normal`/`both`) are the game's
97
- call on weak devices: read `engine.tier` before adding them (`threedog shot` renders the desktop tier, `--tier low` checks the low one). To take one
98
- of a pack's effects out: `engine.plugins.off('<pack>/<file>')` or `engine.post.get('ao').enabled = false`; to add one on top: a game plugin file or `engine.post.add`.
99
- - Where to import from:
100
-
101
- | You want | Import |
102
- |---|---|
103
- | Materials and lighting written as TSL | `threedog/tsl` |
104
- | Post effects that run on both routes (bloom, ao, outline, dof, lut, grain) | `@threedog/post-effects` |
105
- | Post effects that exist only on WebGPU (`voxelGI`, `temporalAA`, `sunShafts`, `lightVolumes`) | `@threedog/post-effects/tsl` |
106
- | The three.js layers the engine keeps (`RESERVED_LAYERS`) | `threedog/layers` |
107
-
71
+ - `bloom({ strength, radius, threshold })`, defaults 0.35, 0.5, 0.85: `strength` is how much glow is added, `radius` how far it spreads (0 to 1), `threshold` the brightness a pixel needs before it
72
+ glows at all. It reads linear color before the tone curve, so a surface brighter than 1 glows hard however small it is: if the frame washes out, raise `threshold` or lower that surface's brightness
73
+ before lowering `strength`. On the WebGPU route three's own `BloomNode` is also open to you through `engine.post.add({ node })`.
74
+ - The engine ships no effects. `@threedog/post-effects` (import only what you use) has `bloom`, `ao`, `outline`, `dof` (all `hdr`; outline and dof read depth) and `lut` (contrast / saturation / warm-cool / optional 3D LUT, or
75
+ `paletteLut(colors)` for a fixed palette), `grain`, `vignette`, `chromatic` (`ldr`), each on both routes. `voxelGI`, `temporalAA`, `sunShafts`, `lightVolumes` exist only on WebGPU: `@threedog/post-effects/tsl`. Materials and lighting as TSL: `threedog/tsl`; the three.js layers the engine keeps (`RESERVED_LAYERS`): `threedog/layers`.
76
+ An added effect is on (`enabled: false` adds it off, for `handle.enabled = true` later). The heavy ones (`bloom`, `ao`, `dof`, outline `normal`/`both`) are the game's call on weak devices (`threedog shot` renders the desktop tier, `--tier low` checks the low one).
108
77
  - Depth: an effect that reads scene depth (`needsDepth: true`, e.g. `outline`) must run before any pass that swaps buffers (a `ShaderPass`, a
109
78
  scene-slot pixelation pass, the tone-mapping output). A chain that breaks this throws when the effect is added or enabled, naming both effects;
110
79
  give the depth reader a lower `order`. `dof` keeps the scene depth (`pass.keepsDepth = true`), so `dof` and `outline` can both be on while `dof`
111
80
  has the lower `order` (default: dof 5, outline 10). The other order throws.
112
- - Order of glow and a step-style grade (posterize, palette snap, toon-style color banding, a few-level LUT). Glow (bloom) is a smooth falloff: the
113
- brightest pixels spread a fading halo. A grade that snaps every pixel to a few levels, run **after** the glow, cuts that falloff into flat plateaus:
114
- each plateau is a hard-edged disc, and the middle ones are a flat mid-tone that reads as a grey stain around a light, not as light. It shows in any
115
- art style that mixes glow with banded color (a pixel-art lantern, a flat-shaded neon sign, a cel-shaded campfire, a palette-locked sun), and it
116
- gets worse the fewer levels the grade has. By default `bloom` is an `hdr` effect and a grade is an `ldr` one, so the default order is the bad one.
117
- Ways out, pick by the picture you want: (1) grade first, glow after: give the grade `slot: 'hdr'` and an `order` lower than bloom's, so the glow is
118
- computed from the banded picture and stays smooth (the halo may then use colors outside the palette: fine for soft light, wrong for a strict
119
- palette); (2) keep the grade last and make the glow itself stepped on purpose, one or two clean rings with a threshold, so the discs are a decision
120
- and not a side effect; (3) drop the glow for that picture and paint the light (emissive sprites, a lighter ring in the art). Judge it with a
121
- `threedog shot` close on one bright light against a dark ground: the falloff should read as a gradient (1) or as deliberate rings (2); a grey flat
122
- disc with no gradient and no ring is the trap. Checked on a one-dimensional model of the two orders (a bright source, a blur, a four-level snap): glow
123
- then snap gave plateaus, snap then glow gave a smooth falloff. Not yet checked in a rendered scene with the real passes.
124
- - Pause or unload: `handle.enabled = false` pauses an effect where it is (its place and params stay); `engine.plugins.off('<file>')`
125
- unloads the plugin (the effect leaves the chain; `on` plugs it again). Either way the effect comes back in the same place: inside a slot,
126
- `order` decides, and equal orders keep the order the names were first added in (a plugin's effects are placed in plugin-list order, even
127
- one that starts off), so off / on never reorders the chain.
128
- - On / off is `engine.post.get('bloom').enabled = false` for every effect, whoever added it (there is no `createEngine({ post })`: the engine ships no
129
- effect to switch on, add one with `engine.post.add(bloom())`). The switch is the shared point `post.<name>.enabled`: `enabled` writes its game layer, a hold of your own goes through `engine.mod('post.bloom.enabled', { owner, set, layer })`, and reading `enabled` gives what runs now. MSAA is `engine.post.setAntialias(on)` and works with every effect on. The settings menu shows `bloom` / `ao` toggles only when effects with those names exist; a toggle the player turns off sits on the settings layer of that point, above the game and any hold (`describe().render.post` reads `writer: 'settings'`), and the menu writes nothing for a value it only re-applies unchanged.
81
+ - Order of glow and a step-style grade (posterize, palette snap, a few-level LUT). Glow is a smooth falloff; a grade that snaps every pixel to a few levels, run **after** it, cuts that falloff into flat
82
+ plateaus, and the middle ones read as a grey stain around a light, not as light. It shows in any style that mixes glow with banded color and gets worse the fewer levels the grade has, and the default
83
+ order is the bad one (`bloom` is `hdr`, a grade `ldr`). Ways out, by the picture you want: (1) grade first, glow after: give the grade `slot: 'hdr'` and an `order` lower than bloom's (the halo may then
84
+ use colors outside the palette: fine for soft light, wrong for a strict palette); (2) keep the grade last and make the glow stepped on purpose, one or two clean rings; (3) drop the glow and paint the light
85
+ (emissive sprites, a lighter ring in the art). Judge it with a `threedog shot` close on one bright light against a dark ground: a gradient (1) or deliberate rings (2) are fine; a grey flat disc is the trap.
86
+ This was reasoned on a one-dimensional model of the two orders, not yet checked with the real passes.
87
+ - On / off: `engine.post.get('bloom').enabled = false` for every effect, whoever added it, pauses it where it is (place and params stay); `engine.plugins.off('<file>')` unloads a plugin (the effect leaves the chain; `on` plugs it again; a pack's file: `'<pack>/<file>'`). Either way
88
+ it comes back in the same place: inside a slot `order` decides, and equal orders keep the order the names were first added in. There is no `createEngine({ post })`. The switch is the shared point `post.<name>.enabled`: `enabled` writes its game layer, a hold of your own goes through `engine.mod('post.bloom.enabled', { owner, set, layer })`, and reading `enabled` gives what runs now.
89
+ The settings menu shows `bloom` / `ao` toggles only when effects with those names exist; a toggle the player turns off sits on the settings layer of that point, above the game and any hold (`describe().render.post` reads `writer: 'settings'`). MSAA is `engine.post.setAntialias(on)` and works with every effect on.
130
90
  - `fuse`: a light color effect can skip its own fullscreen pass by carrying a GLSL snippet instead of `create()`:
131
91
  `fuse: { uniforms: { uMyAmount: 'float' }, values: p => ({ uMyAmount: p.amount }), glsl: 'color.rgb *= 1.0 - uMyAmount * length(vUv - 0.5);' }`.
132
92
  Fused effects that are on and next to each other in one slot (never `scene`) compile into one shader and draw in one pass, in `order`. The
@@ -135,39 +95,38 @@ export default bloom({ strength: 0.2 });
135
95
  `engine.post.add({ name, fuse: { glsl }, slot: 'ldr' })` adds just a snippet.
136
96
  - Outline: `outline({ mode: 'depth' | 'normal' | 'both' })`: `depth` (default, silhouettes), `normal` (creases; draws the scene once more with
137
97
  normals, so it costs more), `both`. `fadeWithDistance: false` keeps lines at any distance; `wobble: 1.5` jitters lines by up to 1.5 px at 8 steps a
138
- second. To exempt objects: `outline({ offLayer: OUTLINE_OFF_LAYER })` and `mesh.layers.enable(OUTLINE_OFF_LAYER)` (one extra render of just
139
- those objects; nothing when `offLayer` is `null`).
140
- - Ambient occlusion (darker creases and contact corners): `ao({ radius, intensity })` wraps three's `GTAOPass`; `radius` is in world units
141
- (default 0.25), `intensity` 0..1 (default 1), both change in place: `engine.post.get('ao').set({ radius: 0.6 })`. Order 20 runs it before bloom and the tone mapping. It follows resize,
142
- render scale and MSAA like every effect. It draws the scene once more with normals: points and lines are skipped, and a vertex-moving shader
143
- patch (wind) is not applied there, so swaying leaves get the AO of their rest pose. Cost on a laptop GPU (AMD 780M, 1280x720, MSAA, a street
144
- scene): about +6 ms a frame (4.4 -> 10.7 ms). Other GTAOPass settings (`samples`, `thickness`, `output`):
145
- `engine.post.object().passes.find(p => p.gtaoMaterial)`.
98
+ second. To exempt objects: `outline({ offLayer: OUTLINE_OFF_LAYER })` and `mesh.layers.enable(OUTLINE_OFF_LAYER)` (one extra render of just those objects; nothing when `offLayer` is `null`).
99
+ - Ambient occlusion (darker creases and contact corners): `ao({ radius, intensity })` wraps three's `GTAOPass`; `radius` is in world units, `intensity` 0..1, both change in place: `engine.post.get('ao').set({ radius: 0.6 })`.
100
+ Order 20 runs it before bloom and the tone mapping. It draws the scene once more with normals: points and lines are skipped, and a vertex-moving shader patch (wind) is not applied there, so swaying leaves get the AO of their rest pose.
101
+ Other GTAOPass settings (`samples`, `thickness`, `output`): `engine.post.object().passes.find(p => p.gtaoMaterial)`.
102
+
103
+ ### dof: blur the background (focus blur, bokeh, miniature, tilt shift, cinematic)
104
+ `dof` from `@threedog/post-effects` blurs what is away from the focus distance: `engine.post.add(dof({ focus: 8, range: 3, maxBlur: 5 }))`, then `engine.post.get('dof').set({ focus: distanceToTarget })` each frame for a follow focus. A small `range` and a large `maxBlur` read as a miniature; a long `range` as a soft cinematic backdrop. It is not a shadow setting (`engine.shadows` blur is edge softness).
146
105
 
147
106
  ## Who writes it: the ownership table
148
107
 
149
108
  Some three.js values the engine writes **on its own**, every frame or on a timer: the camera module places the camera, a sky keeps the shadow box around the focus. Lights, fog, exposure and the environment are not among them: the game's `picture/` code is their one writer (recipe 62).
150
- Each of them is registered once (`core/owned.js`), and every one behaves the same way:
109
+ Each of them is registered once (`core/ops/owned.js`), and every one behaves the same way:
151
110
 
152
111
  - **Engine** (default): the engine writes it. Adjust it while the engine keeps driving: the `set` call in the table.
153
- - **Taken** (`manual`): `engine.view.manual('far' | 'fov' | 'pixelRatio')` stops the engine writing it; the three.js value is yours.
112
+ - **Taken** (`manual`): `engine.autoView.manual('far' | 'fov' | 'pixelRatio')` stops the engine writing it; the three.js value is yours.
154
113
  `manual(key, false)` (or the handle's `remove()`) gives it back. No module option starts a value taken over.
155
114
  - **Written directly** without `manual`: the engine notices, **stops writing it and keeps your value**, and warns once with the `manual` call and the
156
115
  hand-back call. This happens in release builds too (only the warning is dev-only), so a game behaves the same with and without checks.
157
116
  - A `timeline.tween` on an object is a temporary takeover of that object only: no warning, no hand-over (other objects stay checked).
158
117
 
159
- `engine.describe().owned` lists every registered value and who writes it now, as `writer` (`engine`, `manual:game`,
160
- `three (engine yielded)`). A test (`tests/specs/owned.mjs`) runs the three
161
- behaviors for every registered value and fails when one is registered without a row here.
118
+ `engine.describe().owned` lists every registered value and who writes it now, as `writer` (`engine`, `manual:game`, `three (engine yielded)`).
162
119
 
163
120
  | id | part | written when | take it | adjust while the engine drives |
164
121
  |---|---|---|---|---|
165
122
  | `shadow.follow` | shadow | the box on the engine sun: under a sky every frame (center = `sun.target`); without one the placeholder sun follows `engine.focus` | `engine.shadows.box(engine.lights.sun, { follow: false })` | `engine.shadows.box(engine.lights.sun, { extent })` |
166
123
  | `toneMapping` | tone | never: `renderer.toneMapping` stays three.js's default until your code writes it | `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping`; an own curve as a post stage: `engine.post.add({ name, slot: 'tone', create })` (or `node` on WebGPU; replaces OutputPass / renderOutput; outputs display color) | - |
167
124
  | `background` | sky | sky: a backdrop color or skybox every frame; with the dome the dome hides when you take it | `scene.background = x` (the dome hides); whole sky: `engine.sky.replace(texture \| object3D)` | `engine.sky.backdrop = '#335577'` |
168
- | `view.far` | view | terrain view range (`setViewChunks`) | `engine.view.manual('far')` | - |
169
- | `view.fov` | view | the settings menu fov slider, camera modules (first person / rts fov, fixed shots, back to the install fov on a switch) | `engine.view.manual('fov')` | - |
170
- | `view.pixelRatio` | view | adaptive resolution, about once a second while slow | `engine.view.manual('pixelRatio')` | `engine.setPixelRatio(1.5)` |
125
+ | `view.aspect` | view | every resize | `engine.autoView.manual('aspect')` | - |
126
+ | `sky.sunDir` | view | `sky()` each frame, from the time and `engine.sky.orbit` (the same vector as `uSunDir`) | `engine.autoView.manual('sunDir')` | - |
127
+ | `view.far` | view | terrain view range (`setViewChunks`) | `engine.autoView.manual('far')` | - |
128
+ | `view.fov` | view | the settings menu fov slider, camera modules (first person / rts fov, fixed shots, back to the install fov on a switch) | `engine.autoView.manual('fov')` | - |
129
+ | `view.pixelRatio` | view | adaptive resolution, about once a second while slow | `engine.autoView.manual('pixelRatio')` | `engine.setPixelRatio(1.5)` |
171
130
  | `camera` (position, rotation) | view | the camera module, every frame | `const cam = engine.takeCamera('me')` (`cam.remove()` gives it back) | - |
172
131
  | `post.chain` | post | whenever the effect list changes (add / remove / on / off, MSAA): the engine rebuilds the composer passes (WebGL) or `pipeline.outputNode` (WebGPU) | `engine.post.own()`: the built chain stays as you left it in `engine.post.object()`; `own(false)` rebuilds it from the list. A write to `object()` without `own()` does not yield: the next chain change replaces it | `engine.post.get('bloom').set({ strength: 0.6 })` |
173
132
  | `shadow.csm` (not a property: a list) | shadow | while cascades are on: the `csm` patch goes on every built-in lit material, yours too (else N times as bright) | - (`handle.remove()`); your ShaderMaterial is left alone until `engine.shadows.include(mat)` | - |
@@ -176,6 +135,3 @@ Not in this table, because the engine writes them once rather than keeps writing
176
135
  and says so once in the dev console and in `describe().perf.batching`; turn it off per object with `userData.batch = false`, see
177
136
  [05-props-bake.md](05-props-bake.md) §2b) and `castShadow` on generator props (set when the model is made: a generator's own flags are kept, the
178
137
  manifest entry can set them; change it on the object afterwards).
179
-
180
- ## Lower-level forms that stay
181
-
@@ -1,24 +1,69 @@
1
- # The ground up close: options and diagnosis
1
+ # The ground up close: options, crisp color borders, normals, diagnosis
2
2
 
3
3
  Not a standard recipe. Several pictures are right for different games, and none is the default. **Decide from the reference images first**: is the
4
4
  ground flat color shapes, a painted surface, a photographic texture, or a few lit polygons? Then pick a row. If the ground already looks wrong,
5
5
  jump to the symptoms.
6
6
 
7
7
  ## Approaches (pick by the picture you want)
8
- | Picture | How | Typical values |
9
- |---|---|---|
10
- | Flat color blocks, no detail (minimal, flat illustration; on purpose) | `shading: 'flat'` or `'smooth'`, `colors` / `biomeColors`, no `detail`; a few `variation.patches` with `levels` | `resolution: 16`; `patches: { size: 90, levels: 3, strength: 0.15 }` |
11
- | Color map + detail layer + near grass (soft variation, crisp borders) | `terrain({ shading: 'texture', colorResolution, detail })`, grass with `vegetation.define(name, { nearOnly: true })` | `colorResolution: 128`; `detail: { noise: 'dabs', scale: 0.5, strength: 0.25, normal: 0.03 }` |
12
- | Tiling or triplanar textures (your own painted, photographed or generated images) | your own material with `map` and `texture.repeat` through `terrain({ material })`, or `detail: { texture: 'name' }` (`projection: 'triplanar'` on slopes and rocks) | `repeat: 8`; `detail: { texture, scale: 0.5, strength: 0.6 }` |
13
- | Vertex color + toon lighting | vertex colors from `colors` and `variation.jitter`, `terrain({ material })` with a `MeshToonMaterial`, `gradientMap: rampTexture(...)`; detail optional | `jitter: { size: 2, min: 0.9, range: 0.15 }`; `rampTexture([0.4, 0.75, 1])` |
14
- | Your own shader or plain three.js | `terrain({ material })`, or recipe 40 section 8 (what you give up) | any |
8
+ | Picture | How |
9
+ |---|---|
10
+ | Flat color blocks, no detail (minimal, flat illustration; on purpose) | `shading: 'flat'` or `'smooth'`, `colors` / `biomeColors`, no `detail`; a few `variation.patches` with `levels` |
11
+ | Color map + detail layer + near grass (soft variation, crisp borders) | `terrain({ shading: 'texture', colorResolution, detail })`, grass with `vegetation.define(name, { nearOnly: true })` |
12
+ | Tiling or triplanar textures (your own painted, photographed or generated images) | your own material with `map` and `texture.repeat` through `terrain({ material })`, or `detail: { texture: 'name' }` (`projection: 'triplanar'` on slopes and rocks) |
13
+ | Vertex color + toon lighting | vertex colors from `colors` and `variation.jitter`, `terrain({ material })` with a `MeshToonMaterial`, `gradientMap: rampTexture(...)`; detail optional |
14
+ | Your own shader or plain three.js | `terrain({ material })`, or recipe 40 section 8 (what you give up) |
15
15
 
16
16
  Detail noises (recipe 43): `grain` fine speckle, `paper` fibres, `stroke` directional streaks (stretched on purpose), `dabs` soft oval dabs with
17
- no direction. `fade` (on by default) removes the detail where its pattern is smaller than a pixel. At run time: `engine.terrain.recolor({ detail })`. On any
17
+ no direction. `fade` (on by default) removes the detail where its pattern is smaller than a pixel. On any
18
18
  other material: `applyEffects(mat, { detail })`, with your own function as `detail: { glsl }` (recipe 43).
19
19
 
20
- Where each key is defined: `variation` (blend, jitter, patches) recipe 36; `shading`, `colorResolution`, `normals`, `normalFn`, heights from a
21
- grid recipe 37; `detail` keys recipe 43; run-time changes `engine.terrain.recolor` recipe 36; terrain basics recipe 28.
20
+ `variation`, `recolor` and your own material are in recipe 36; terrain basics, the triangle cut and heights from a grid in recipe 28.
21
+
22
+ ## Crisp borders: `shading: 'texture'`
23
+ With `shading: 'smooth'` or `'flat'` a color is computed at a grid point (or triangle center) and blended across the triangle. At the default
24
+ `resolution: 16` on a 64 m chunk that is one color sample per 4 m, so any border between two ground types can only run along triangle edges.
25
+ Raising `resolution` fixes it at the price of triangles (and collision, and edit granularity). `shading: 'texture'` cuts the link: color is
26
+ computed per pixel into a per-chunk image, the mesh stays as coarse as you like.
27
+
28
+ ```js
29
+ engine.use(terrain({
30
+ shading: 'texture', colorResolution: 192, resolution: 16,
31
+ height: (x, z) => 0,
32
+ // the border is a curve; the ground type is evaluated per pixel
33
+ groundType: (x, z) => z > 32 + 14 * Math.sin(x * 0.09) ? 'grass' : 'sand',
34
+ colors: { grass: 0x5a8a3a, sand: 0xd8c690 }, biomeColors: { grass: ['grass'], sand: ['sand'] },
35
+ }));
36
+ ```
37
+ With a preset the same switch gives crisp banks without more triangles: `terrain({ ...terrainPreset(), shading: 'texture' })`.
38
+
39
+ - A worker computes a `(colorResolution + 2)^2` RGBA image per chunk with the same rules as the vertex colors (`groundType`, `biomeColors`, `steep`, `variation`, painted cells).
40
+ The `+ 2` is a 1 pixel border computed from world coordinates, so neighboring chunks hold identical values at the seam and no seam shows.
41
+ - Vertex colors are plain white in this mode. The material samples the image by world xz, so `uv`
42
+ stays free for your own textures. The map goes on before the vertex colors, so every patch after it sees the mapped color: a `mode: 'mix'` season tint (recipe 36) tints the textured top like the side walls.
43
+ - Each chunk gets its own clone of the terrain material (same patches, one compiled
44
+ program), so a property you write on the material object after chunks exist does not reach loaded chunks. Assign a material instead (`engine.terrain.material = m`, which remounts every chunk), or pass it through `terrain({ material })`.
45
+ - Painted cells (`terrain.edit(..., { paint })`) keep their whole-cell color; the image of every chunk touched by an edit is re-uploaded in place.
46
+ - Independent of `resolution`: `resolution` still sets mesh, collision and edit granularity, `colorResolution` only the color detail
47
+ (64 m chunk: 128 = 0.5 m per pixel, 256 = 0.25 m). `recolor` cannot change `colorResolution`.
48
+
49
+ Cost: the worker time per chunk is mostly your `groundType` called once per pixel, several times that of smooth at 128; 64 costs a quarter, 256 four times that.
50
+ Memory is `(colorResolution + 2)^2 x 4` bytes per chunk plus mipmaps (about 90 KB at 128, 23 KB at 64). The first frames pay one shader compile and the uploads, not a cost per frame.
51
+ On a low tier (`engine.tier === 'low'`) the default drops to 64 unless you set `colorResolution`. To skip the
52
+ color map there, choose the shading yourself: `shading: engine.tier === 'low' ? 'smooth' : 'texture'`.
53
+
54
+ `variation` shapes *what* color a point gets; `shading` decides *where* it is evaluated. In vertex modes every variation is limited to cell size; in
55
+ texture mode it is sampled per pixel, so `patches: { size: 20, levels: 4 }` gives hard-edged color blocks, and a `jitter.size` below the pixel size
56
+ (0.5 m at `colorResolution: 128`) comes out as one grain per pixel, coarser than asked.
57
+
58
+ ## Lighting normals: `normals` and `normalFn`
59
+ - `shading: 'smooth'` lights with one normal per grid point, `'flat'` one per triangle. In texture mode choose: `normals: 'smooth'` (default) or
60
+ `'flat'` (faceted light, fine color: a low-poly shape with crisp borders).
61
+ - `normalFn(i, j, h, cell) => [nx, ny, nz]` replaces the smooth normal at grid point `(i, j)`; `h(i, j)` reads a grid-point height, `cell` is the
62
+ spacing in meters. Pure like `height` / `groundType`. The engine normalizes the result. Default: central difference of the four neighbors.
63
+ ```js
64
+ terrain({ normalFn: (i, j, h, cell) => [(h(i - 1, j) - h(i + 1, j)) / cell, 4, (h(i, j - 1) - h(i, j + 1)) / cell] }) // gentler lighting on slopes
65
+ ```
66
+ `normals` and `normalFn` change light only, never height or collision. `engine.terrain.recolor({ normals: 'flat' })` changes it at run time (rebuilds the chunks).
22
67
 
23
68
  ## Symptom, causes, options
24
69
  **Brushed metal at grazing angles.** Cause: `stroke` stretches one axis (`stretch` 6) and `world` projection looks straight down, so a flat
@@ -29,30 +74,22 @@ ground seen at a low angle shows the stretch as long streaks. Options: `noise: '
29
74
  its cell lines (`terrain({ heightmap })` always reads its image bilinearly; `sampleGrid` defaults to `interp: 'linear'`); a coarse mesh
30
75
  `resolution` (16 per 64 m chunk = one height every 4 m); `shading: 'flat'`, which lights each triangle on its own so every facet shows.
31
76
  Options, any of them: more height samples (a larger image or table), or the data smoothed before the terrain reads it; `sampleGrid(...,
32
- { interp: 'cubic' })` for smooth heights everywhere outside the terrain module (placement, gameplay; recipe 37 section 7; a terrain `height`
33
- function runs in a worker and cannot capture a sampler); a finer `resolution` (more triangles, collision and edit cells); `shading: 'smooth'`,
77
+ { interp: 'cubic' })` for smooth heights everywhere outside the terrain module (placement, gameplay; recipe 28 section 9); a finer `resolution` (more triangles, collision and edit cells); `shading: 'smooth'`,
34
78
  or `normals: 'smooth'` with `shading: 'texture'`; `diagonal: 'adaptive'` against zigzag ridges; or noise in the `height` function (`n.fbm`; ridges from
35
79
  folding it) instead of a sparse table. Terraces can also be the picture you want: `interp: 'nearest'`, or a stepped `height`.
36
80
 
37
81
  **Blurry up close.** Cause: the color map is `colorResolution + 2` pixels per 64 m chunk side; 128 is 0.5 m per pixel, which is soft when the
38
- camera is within a few meters. It does not depend on the mesh `resolution`. On a `low` tier the default is 64 (twice as coarse) unless you set
39
- it. Options: `colorResolution: 256` (0.25 m; four times the image memory and worker time); a detail layer on top (it is computed per screen
82
+ camera is within a few meters. It does not depend on the mesh `resolution`. Options: `colorResolution: 256` (four times the image memory and worker time); a detail layer on top (it is computed per screen
40
83
  pixel, so it stays sharp); near grass over the ground; or accept soft color and let a texture carry the fine part.
41
84
 
42
85
  **One flat green.** Cause: not resolution. Color comes from `colors` / `biomeColors` per ground type (`groundType`), `variation.blend`
43
86
  (wavelength and `strength` of the two-color noise) and `steep`. One color with no `biomeColors` and a flat blend is one green. Options: two
44
- colors in `biomeColors` for the type; `blend.strength` 1.5; `variation.patches` with a `tint`; more ground types.
87
+ colors in `biomeColors` for the type; a higher `blend.strength`; `variation.patches` with a `tint`; more ground types.
45
88
 
46
- **Dark blotches.** Cause: usually cloud shadows (`engine.uniforms.uCloudShadow.value` above 0), not texture; they drift with `uCloudSpeed`, and bigger clouds mean
47
- bigger blotches. Test by setting `uCloudShadow` to 0; if they vanish, lower it or change `uCloudScale`. Blotches that
89
+ **Dark blotches.** Cause: usually cloud shadows (`engine.uniforms.uCloudShadow.value` above 0), not texture; they drift with `uCloudShadowSpeed`, and bigger clouds mean
90
+ bigger blotches. Test by setting `uCloudShadow` to 0; if they vanish, lower it or change `uCloudShadowScale`. Blotches that
48
91
  never move are `variation.patches` or a strong `detail`.
49
92
 
50
93
  **Shimmer far away.** Cause: a pattern smaller than a pixel aliases. `detail.fade` (default) fades it out; `fade: false` keeps it. In your own
51
94
  `glsl`, read `threedogDetailFootprint` (one pixel in pattern units; 1 = one cell per pixel) and fade yourself. A `variation.jitter.size` below a
52
95
  pixel shimmers the same way; use a few meters, or `shading: 'texture'` (mipmapped).
53
-
54
- **Near-only vegetation fades out by distance.** Any `nearOnly` species (grass, flowers, pebbles, twigs, snow tufts, debris ...) is placed per chunk ring
55
- (`maxRing`), whose edge would be a visible line. By default instances shrink toward their base over a band that ends at `maxRing x chunk size` from the
56
- player (start at 65% of it), so nothing pops per chunk. Tune with `fade: { start: 20, end: 45 }` (metres), or `fade: false` for a hard edge
57
- (e.g. a species hidden in fog anyway). It is part of the species' own material (no extra draw call or program), keeps wind sway and shadows in step, and is skipped
58
- when `effects: false`. A larger `maxRing`, fog, or a ground color near the species' base color still help for stylized looks with strong silhouettes.
@@ -34,7 +34,7 @@ engine.mod('time.player', { owner: 'haste', mul: 1.2, for: 5 });
34
34
  const menu = engine.freeze('pause-menu'); /* ... */ menu.remove(); // pause menu: the picture, UI and ambient uTime (wind, water, clouds) keep running; { ambient: true } stops those too
35
35
  engine.input.gate('jump', { owner: 'stun', for: 1.5 }); // no jumping while stunned
36
36
  engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) => // a weight rule on top of the engine's inventory
37
- carried() + weightOf(id) * n > 30 ? false : next(id, n, o), { owner: 'weight' });
37
+ carried() + weightOf(id) * n > 30 ? { ok: false, code: 'tooHeavy' } : next(id, n, o), { owner: 'weight' });
38
38
  ```
39
39
 
40
40
  ## The rules in full: `engine.mod(point, { owner, set | add | mul | clamp, layer?, for?, id? })`
@@ -44,8 +44,8 @@ engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) =>
44
44
  | `engine` | the engine's own defaults and drivers |
45
45
  | `game` (default) | game code, game modules |
46
46
  | `effect` | temporary effects: weather, sunset fade, bullet time, haste |
47
- | `settings` | the player's settings menu: only `clamp` / `mul` (a value point: `set: false`), so it can turn things down or off, never on |
48
47
  | `system` | cutscenes, menus, photo tools (also "lock this number": a `set` here hides every layer below) |
48
+ | `settings` | the player's settings menu: only `clamp` / `mul` (a value point: `set: false`), so it can turn things down or off, never on. Above `system`, so the restriction holds in a cutscene too |
49
49
  | `debug` | debug overrides and panels |
50
50
 
51
51
  - Inside a layer: `set`, then every `add`, then every `mul`, then every `clamp` (`{ min, max }`); the result is clamped to the point's own min / max.
@@ -67,13 +67,13 @@ engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) =>
67
67
  `shadows.enabled`, `post.<name>.enabled`, `sky.tint`, `sky.flash` and `ground.cover` are shared points like the rest: the game sets a base value, effects multiply on top, the player's settings cap it.
68
68
  `sky.tint`, `ground.cover` (blend by amount) and `sky.flash` (adds) are written with `engine.mod`.
69
69
  ```js
70
- const hold = engine.mod('shadows.enabled', { owner: 'cutscene', layer: 'system', set: false }); // decides over the game and the menu
70
+ const hold = engine.mod('shadows.enabled', { owner: 'cutscene', layer: 'system', set: false }); // decides over the game
71
71
  engine.describe().shared['shadows.enabled']; // who decided and who is hidden
72
72
  hold.remove(); // the handle ends yours
73
73
  ```
74
- - The exact number whatever else is stacked: set on `{ layer: 'system' }`, or write the three.js value.
75
- - The settings menu only restricts (`shadows` off is `shadows.enabled` set false on the settings layer); a game's `enabled: true` does not
76
- switch them back on, and a cutscene's `false` is not undone by the menu.
74
+ - The exact number whatever else is stacked: set on `{ layer: 'system' }` (the player's settings can still lower it), or write the three.js value.
75
+ - The settings menu only restricts (`shadows` off is `shadows.enabled` set false on the settings layer), so neither a game's nor a cutscene's `enabled: true`
76
+ switches them back on, and a cutscene's `false` is not undone by the menu.
77
77
  - A direct three.js write (`engine.lights.hemi.intensity = 0.2`) still works, and describe tags it `three`.
78
78
 
79
79
  ## Time channels
@@ -86,10 +86,8 @@ hold.remove();
86
86
  - One time source: `engine.time.tick` is the only counter; `engine.time.now('real' | 'ambient' | 'calendar' | channel)` are read-only views of it
87
87
  (recipe 06 "The time table"). Passing time is `engine.skip({ seconds })`: every view moves as if stepped, timers fire in order, far NPCs and
88
88
  the calendar catch up. Writing `engine.clock.now` throws (it is a view).
89
- - Timers: `engine.clock.after(s, fnOrEvent, data, { channel })` / `clock.every(s, fn, { channel })` on any view (default `'calendar'`; `'real'`
89
+ - Timers: `engine.clock.after(s, fnOrEvent, { data, channel })` / `clock.every(s, fn, { channel })` on any view (default `'calendar'`; `'real'`
90
90
  ignores bullet time; `'enemies'` slows with it). One queue: `remove()` takes effect at once, even later in the same step.
91
- - `character.velocity` / `character.vy` are not stacks: a write is an impulse the mover integrates from (no owner, nothing to hand back). Lasting
92
- knockback is `character.push(vx, vz, seconds)`; full takeover is `character.mover = 'manual'`.
93
91
 
94
92
  ## Fixed-step order: `onFixed(fn, { phase })`
95
93
 
@@ -102,7 +100,7 @@ checks that need this step's player position). The order never depends on which
102
100
  - Several wrappers compose: the last one wrapped runs first. `handle.remove()` takes one out; the method is restored when the last goes.
103
101
  - Every caller of that method goes through it (the game, the module's own ops, other modules). It wraps one method: a rule for every way items
104
102
  enter the bag wraps `add` and `transfer`.
105
- - Only public methods (the module's `contract.js` `api` list); `_private` names throw. `describe().wraps` lists `{ 'inventory.add': [owners] }`.
103
+ - Meant for public methods (the module's `contract.js` `api` list); a `_private` name warns once in dev and still works. `describe().wraps` lists `{ 'inventory.add': [owners] }`.
106
104
 
107
105
  ## Replacing a module
108
106
 
@@ -110,15 +108,13 @@ Two modules that each want to be "the" one (a sky, a tone-mapping stage, an inve
110
108
  Other modules `requires: ['inventory']` and work with whichever holds it. `engine.use(myInventory(), { replaces: 'inventory' })` unloads the
111
109
  holder (its tracked handles, its `ctx.mod` entries, its `dispose`) before the new install, and puts it back if that fails.
112
110
 
113
- Each replaceable module has a contract (`modules/gameplay/inventory.contract.js`, `interactions.contract.js`, `dialogue.contract.js`, `quests.contract.js`, `modules/flow/contract.js`,
114
- `modules/characters/contract.js`, `modules/calendar/contract.js`, `modules/camera/contract.js`; object contract `modules/characters/vehicle.contract.js`): the api, fields, ops, events
111
+ Most replaceable modules have a contract (`modules/gameplay/*.contract.js`, `modules/*/contract.js`; object contract `modules/characters/vehicle.contract.js`; the rest and what cannot be replaced: CONVENTIONS.md "What can be replaced"): the api, fields, ops, events
115
112
  and save keys other code relies on, and nothing more (the engine's callers use only that surface). `runContract(contract, () => myInventory(), { check })`
116
- from `@threedog/tools/contract` checks a replacement (in a game installed from npm too); `tests/contract/fakeInventory.js` in the engine's
117
- repository (not shipped) is a whole replacement in ~40 lines; `fakeDialogue.js`, `fakeQuests.js`, `fakeCamera.js` and `fakeVehicle.js`
118
- are the same for their contracts, and the engine's NPCs, timeline, content loader, hud and characters run on them (test `tests/specs/ui-nav.mjs`).
113
+ from `@threedog/tools/contract` checks a replacement (in a game installed from npm too); `tests/contract/` in the engine's repository (not shipped) holds small
114
+ whole replacements such as `fakeInventory.js`.
119
115
  A camera module's `prepare` hook: `runContract(contract, () => myCamera(), { check, prepare: e => { e.camera = ... } })` adds what it needs to the
120
116
  small engine. A vehicle is checked as an object: `runContract(vehicleContract, () => myBoat, { check })`.
121
117
 
122
118
  ## Who holds what
123
119
 
124
- `describe().holds`: pause / freeze / camera / debugView, `input` (pushed contexts with owners), `gates`. Every other shared value and slot: `describe().shared`.
120
+ Holders: `describe().holds` (recipe 16, Notes). Every other shared value and slot: `describe().shared`.