threedog 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +411 -1
  2. package/README.md +8 -11
  3. package/core/{Animator.js → assets/Animator.js} +30 -18
  4. package/core/{Assets.js → assets/Assets.js} +131 -56
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +302 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +9 -7
  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} +7 -14
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +47 -25
  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} +15 -12
  18. package/core/{Random.js → base/Random.js} +7 -4
  19. package/core/{Vars.js → base/Vars.js} +14 -4
  20. package/core/{easing.js → base/easing.js} +1 -1
  21. package/core/{errorCodes.js → base/errorCodes.js} +151 -125
  22. package/core/{errorHints.js → base/errorHints.js} +17 -10
  23. package/core/{errors.js → base/errors.js} +12 -10
  24. package/core/{events.generated.js → base/events.generated.js} +11 -0
  25. package/core/base/follows.js +26 -0
  26. package/core/base/math.js +66 -0
  27. package/core/{params.js → base/params.js} +5 -6
  28. package/core/base/saveValues.js +81 -0
  29. package/core/base/sections.js +97 -0
  30. package/core/base/spelling.js +32 -0
  31. package/core/base/util.js +32 -0
  32. package/core/{validate.js → base/validate.js} +34 -34
  33. package/core/{Engine.js → engine/Engine.js} +137 -91
  34. package/core/{Loading.js → engine/Loading.js} +34 -5
  35. package/core/{copies.js → engine/copies.js} +4 -4
  36. package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
  37. package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
  38. package/core/{loop.js → engine/loop.js} +88 -49
  39. package/core/engine/moduleSlots.js +176 -0
  40. package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
  41. package/core/engine/modules.js +503 -0
  42. package/core/{page.js → engine/page.js} +59 -29
  43. package/core/{plugins.js → engine/plugins.js} +21 -12
  44. package/core/{services.js → engine/services.js} +50 -40
  45. package/core/{startup.js → engine/startup.js} +66 -54
  46. package/core/{Input.js → input/Input.js} +67 -39
  47. package/core/{inputContext.js → input/inputContext.js} +14 -5
  48. package/core/input/inputKeyboard.js +39 -0
  49. package/core/{inputPad.js → input/inputPad.js} +24 -3
  50. package/core/{inputPointer.js → input/inputPointer.js} +11 -3
  51. package/core/input/inputSeat.js +66 -0
  52. package/core/{inputTouch.js → input/inputTouch.js} +24 -7
  53. package/core/{Budget.js → inspect/Budget.js} +21 -20
  54. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
  55. package/core/{Describe.js → inspect/Describe.js} +34 -26
  56. package/core/{Inspect.js → inspect/Inspect.js} +39 -10
  57. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  58. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  59. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  60. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  61. package/core/{UrlState.js → inspect/UrlState.js} +60 -24
  62. package/core/{catalog.js → inspect/catalog.js} +15 -8
  63. package/core/{checks.js → inspect/checks.js} +7 -5
  64. package/core/{debugView.js → inspect/debugView.js} +4 -4
  65. package/core/{describeRender.js → inspect/describeRender.js} +24 -22
  66. package/core/{describeText.js → inspect/describeText.js} +17 -8
  67. package/core/inspect/geometryWatch.js +38 -0
  68. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  69. package/core/inspect/metadata.generated.js +4140 -0
  70. package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
  71. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  72. package/core/inspect/toolDoor.js +21 -0
  73. package/core/inspect/valueHistory.js +35 -0
  74. package/core/{Ops.js → ops/Ops.js} +44 -14
  75. package/core/{control.js → ops/control.js} +57 -31
  76. package/core/ops/holds.js +140 -0
  77. package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
  78. package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
  79. package/core/{opsFail.js → ops/opsFail.js} +5 -7
  80. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  81. package/core/{opsRun.js → ops/opsRun.js} +9 -6
  82. package/core/{owned.js → ops/owned.js} +33 -19
  83. package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
  84. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  85. package/core/{stacks.js → ops/stacks.js} +34 -15
  86. package/core/{wrap.js → ops/wrap.js} +8 -6
  87. package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
  88. package/core/{Saves.js → saves/Saves.js} +171 -54
  89. package/core/saves/saveApply.js +312 -0
  90. package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
  91. package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
  92. package/core/saves/session.js +231 -0
  93. package/core/saves/stateReplace.js +184 -0
  94. package/core/{Rays.js → scene/Rays.js} +44 -30
  95. package/core/{Views.js → scene/Views.js} +16 -8
  96. package/core/{adaptive.js → scene/adaptive.js} +19 -9
  97. package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
  98. package/core/scene/compositeGround.js +72 -0
  99. package/core/scene/floor.js +17 -0
  100. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  101. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  102. package/core/{grid.js → scene/grid.js} +6 -4
  103. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  104. package/core/scene/ground.contract.js +14 -0
  105. package/core/scene/ground.js +139 -0
  106. package/core/{movement.js → scene/movement.js} +3 -3
  107. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  108. package/core/scene/pixel.js +154 -0
  109. package/core/scene/pixelRatio.js +167 -0
  110. package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
  111. package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
  112. package/core/scene/stepPoses.js +60 -0
  113. package/core/{targeting.js → scene/targeting.js} +4 -5
  114. package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
  115. package/core/{thingOps.js → scene/thingOps.js} +25 -16
  116. package/core/{things.js → scene/things.js} +18 -5
  117. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  118. package/core/{tier.js → scene/tier.js} +10 -0
  119. package/core/scene/view.js +161 -0
  120. package/core/{Batching.js → stream/Batching.js} +85 -28
  121. package/core/{Stream.js → stream/Stream.js} +80 -38
  122. package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
  123. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  124. package/core/{scatter.js → stream/scatter.js} +7 -4
  125. package/core/{streamSources.js → stream/streamSources.js} +14 -8
  126. package/core/{Commits.js → threads/Commits.js} +17 -11
  127. package/core/{Jobs.js → threads/Jobs.js} +25 -13
  128. package/core/{Threads.js → threads/Threads.js} +21 -18
  129. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  130. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  131. package/core/{Clock.js → time/Clock.js} +20 -11
  132. package/core/{dayTime.js → time/dayTime.js} +5 -1
  133. package/core/{skip.js → time/skip.js} +28 -21
  134. package/core/{time.js → time/time.js} +32 -20
  135. package/core/{uiClock.js → time/uiClock.js} +4 -4
  136. package/docs/AI.md +92 -72
  137. package/docs/API.md +33 -28
  138. package/docs/CODEMAP.md +121 -200
  139. package/docs/COMMANDS.md +77 -70
  140. package/docs/CONVENTIONS.md +167 -24
  141. package/docs/MIGRATING-0.8.md +171 -0
  142. package/docs/MIGRATING-1.0.md +101 -0
  143. package/docs/THREE.md +140 -38
  144. package/docs/api/assets.md +12 -13
  145. package/docs/api/audio.md +6 -5
  146. package/docs/api/budget.md +4 -4
  147. package/docs/api/calendar.md +10 -11
  148. package/docs/api/cameraRig.md +32 -29
  149. package/docs/api/characters.md +35 -24
  150. package/docs/api/clock.md +1 -1
  151. package/docs/api/collider3d.md +9 -0
  152. package/docs/api/collision.md +12 -9
  153. package/docs/api/content.md +18 -17
  154. package/docs/api/dialogue.md +5 -4
  155. package/docs/api/engine.md +58 -54
  156. package/docs/api/events.md +17 -6
  157. package/docs/api/flow.md +1 -1
  158. package/docs/api/grids.md +1 -1
  159. package/docs/api/ground.md +6 -7
  160. package/docs/api/hud.md +2 -2
  161. package/docs/api/i18n.md +6 -6
  162. package/docs/api/input.md +9 -8
  163. package/docs/api/interactions.md +5 -5
  164. package/docs/api/inventory.md +10 -10
  165. package/docs/api/jobs.md +5 -5
  166. package/docs/api/level.md +10 -9
  167. package/docs/api/lightPool.md +1 -6
  168. package/docs/api/music.md +3 -3
  169. package/docs/api/nav.md +14 -12
  170. package/docs/api/openWorld.md +1 -1
  171. package/docs/api/particles.md +10 -7
  172. package/docs/api/photo.md +4 -2
  173. package/docs/api/pickups.md +3 -3
  174. package/docs/api/post.md +21 -5
  175. package/docs/api/quests.md +7 -5
  176. package/docs/api/rays.md +7 -7
  177. package/docs/api/rigid.md +29 -19
  178. package/docs/api/saves.md +13 -11
  179. package/docs/api/settings.md +9 -8
  180. package/docs/api/sky.md +8 -7
  181. package/docs/api/stream.md +8 -9
  182. package/docs/api/swarm.md +34 -0
  183. package/docs/api/terrain.md +6 -8
  184. package/docs/api/terrainDraw.md +2 -2
  185. package/docs/api/timeline.md +4 -4
  186. package/docs/api/tools.md +27 -22
  187. package/docs/api/triggers.md +2 -0
  188. package/docs/api/vars.md +1 -1
  189. package/docs/api/vegetation.md +4 -3
  190. package/docs/api/vegetationDraw.md +2 -2
  191. package/docs/api/water.md +7 -3
  192. package/docs/api/weather.md +27 -12
  193. package/docs/api/weatherDraw.md +4 -4
  194. package/docs/api/world.md +6 -6
  195. package/docs/recipes/01-new-game.md +28 -43
  196. package/docs/recipes/02-npc.md +21 -23
  197. package/docs/recipes/03-items-pickups.md +37 -53
  198. package/docs/recipes/04-quests.md +5 -4
  199. package/docs/recipes/05-props-bake.md +34 -44
  200. package/docs/recipes/06-clock-events.md +31 -22
  201. package/docs/recipes/07-flow-scenes-pause.md +30 -32
  202. package/docs/recipes/08-weather-sky.md +91 -37
  203. package/docs/recipes/09-materials-lights-models.md +25 -39
  204. package/docs/recipes/10-blender-level.md +22 -11
  205. package/docs/recipes/11-vehicles.md +44 -24
  206. package/docs/recipes/12-navmesh.md +60 -15
  207. package/docs/recipes/13-animation.md +70 -22
  208. package/docs/recipes/14-custom-module.md +33 -20
  209. package/docs/recipes/15-perf.md +51 -28
  210. package/docs/recipes/16-dev-bridge.md +39 -58
  211. package/docs/recipes/18-world.md +49 -28
  212. package/docs/recipes/19-shooting-picking.md +7 -4
  213. package/docs/recipes/20-content-actions-save.md +55 -40
  214. package/docs/recipes/21-camera.md +47 -25
  215. package/docs/recipes/22-shop-gold.md +21 -16
  216. package/docs/recipes/23-ops.md +28 -24
  217. package/docs/recipes/26-ui-parts.md +25 -14
  218. package/docs/recipes/27-net.md +3 -5
  219. package/docs/recipes/28-terrain.md +119 -23
  220. package/docs/recipes/29-grid.md +3 -3
  221. package/docs/recipes/30-templates.md +63 -30
  222. package/docs/recipes/31-audio.md +7 -7
  223. package/docs/recipes/32-action-game.md +21 -11
  224. package/docs/recipes/33-stream-sources.md +6 -3
  225. package/docs/recipes/34-environment-lighting.md +72 -25
  226. package/docs/recipes/35-picture-from-reference.md +20 -23
  227. package/docs/recipes/36-ground-plants.md +106 -0
  228. package/docs/recipes/40-scene.md +18 -21
  229. package/docs/recipes/43-shader-patches-surfaces.md +27 -48
  230. package/docs/recipes/44-water-weather-hooks.md +56 -50
  231. package/docs/recipes/45-cascaded-shadows.md +41 -20
  232. package/docs/recipes/46-blender-art-route.md +9 -10
  233. package/docs/recipes/49-game-module-contract.md +7 -6
  234. package/docs/recipes/50-own-renderer.md +3 -2
  235. package/docs/recipes/51-capability-catalog.md +14 -8
  236. package/docs/recipes/52-around-the-picture.md +56 -100
  237. package/docs/recipes/53-ground-up-close.md +61 -24
  238. package/docs/recipes/55-mods-time-wrap.md +17 -20
  239. package/docs/recipes/56-webgpu-tsl.md +28 -15
  240. package/docs/recipes/57-control.md +39 -12
  241. package/docs/recipes/58-input.md +15 -2
  242. package/docs/recipes/59-depth-post-effects.md +1 -1
  243. package/docs/recipes/60-judge-the-picture.md +30 -25
  244. package/docs/recipes/62-picture-code.md +129 -39
  245. package/docs/recipes/63-third-person-start.md +19 -5
  246. package/docs/recipes/64-particles.md +54 -5
  247. package/docs/recipes/65-swarm.md +140 -0
  248. package/docs/recipes/66-common-tasks.md +313 -0
  249. package/examples/action/.threedog/content-index.json +1 -1
  250. package/examples/action/GAMEMAP.md +5 -5
  251. package/examples/perf-island/.threedog/content-index.json +1 -0
  252. package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
  253. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  254. package/examples/{sheepisland → perf-island}/main.js +8 -8
  255. package/examples/{sheepisland → perf-island}/models.js +1 -1
  256. package/examples/{sheepisland → perf-island}/params.js +1 -1
  257. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  258. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  259. package/examples/{sheepisland → perf-island}/views.js +1 -1
  260. package/examples/plain-picture/GAMEMAP.md +4 -1
  261. package/examples/rc2d/GAMEMAP.md +4 -3
  262. package/examples/rc2d/main.js +1 -3
  263. package/examples/rc2d/rc2d.js +1 -1
  264. package/examples/styletest/.threedog/content-index.json +1 -1
  265. package/examples/styletest/GAMEMAP.md +6 -5
  266. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  267. package/examples/techniques/contact-shadows/main.js +1 -1
  268. package/examples/techniques/interior-light/main.js +1 -1
  269. package/examples/techniques/modular-building/README.md +7 -6
  270. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  271. package/examples/techniques/procedural-animation/README.md +1 -1
  272. package/examples/webgpu-tsl/GAMEMAP.md +2 -1
  273. package/examples/world/.threedog/content-index.json +1 -1
  274. package/examples/world/GAMEMAP.md +9 -7
  275. package/examples/world/main.js +3 -3
  276. package/examples/world/picture/sky.js +1 -1
  277. package/index.d.ts +16 -12
  278. package/index.js +53 -32
  279. package/llms.txt +11 -14
  280. package/modules/ambience/Ambience.js +16 -11
  281. package/modules/calendar/Calendar.js +19 -19
  282. package/modules/calendar/index.js +18 -16
  283. package/modules/calendar/schedule.js +11 -6
  284. package/modules/calendar/seasons.js +7 -7
  285. package/modules/camera/FirstPersonCamera.js +5 -5
  286. package/modules/camera/FixedCamera.js +43 -30
  287. package/modules/camera/FollowCamera.js +24 -15
  288. package/modules/camera/RtsCamera.js +12 -11
  289. package/modules/camera/common.js +72 -37
  290. package/modules/camera/contract.js +1 -0
  291. package/modules/camera/pixelSnap.js +62 -0
  292. package/modules/characters/Character.js +166 -70
  293. package/modules/characters/NPC.js +84 -44
  294. package/modules/characters/assetModel.js +16 -12
  295. package/modules/characters/astar.js +48 -27
  296. package/modules/characters/behaviors.js +4 -5
  297. package/modules/characters/character.contract.js +21 -0
  298. package/modules/characters/contract.js +17 -3
  299. package/modules/characters/index.js +240 -226
  300. package/modules/characters/moveHelpers.js +88 -12
  301. package/modules/characters/mover.contract.js +14 -0
  302. package/modules/characters/movers/common.js +22 -18
  303. package/modules/characters/movers/manual.js +1 -1
  304. package/modules/characters/movers/rapier.js +18 -10
  305. package/modules/characters/movers/simple.js +26 -13
  306. package/modules/characters/movers/support.js +24 -13
  307. package/modules/characters/npcAvoid.js +19 -16
  308. package/modules/characters/npcSim.js +88 -32
  309. package/modules/characters/npcView.js +19 -11
  310. package/modules/characters/pathAsync.js +81 -29
  311. package/modules/characters/pathJob.js +38 -21
  312. package/modules/characters/pathWorker.js +1 -1
  313. package/modules/characters/player.js +120 -0
  314. package/modules/characters/playerStrings.js +2 -2
  315. package/modules/characters/proceduralRig.js +2 -2
  316. package/modules/characters/seat.js +56 -0
  317. package/modules/characters/useModel.js +3 -3
  318. package/modules/characters/vehicle.contract.js +8 -5
  319. package/modules/characters/walkTo.js +40 -33
  320. package/modules/collision/Collision.js +69 -45
  321. package/modules/collision/contract.js +15 -0
  322. package/modules/collision/grid.js +6 -1
  323. package/modules/content/explain.js +2 -3
  324. package/modules/content/fields.js +24 -3
  325. package/modules/content/ids.js +5 -3
  326. package/modules/content/index.js +132 -114
  327. package/modules/content/loader.js +117 -140
  328. package/modules/content/markers.js +25 -0
  329. package/modules/content/models.js +54 -17
  330. package/modules/content/packs.js +5 -4
  331. package/modules/content/parts.js +2 -2
  332. package/modules/content/places.js +36 -0
  333. package/modules/content/props.js +22 -17
  334. package/modules/content/rules.js +47 -61
  335. package/modules/content/stages.js +7 -7
  336. package/modules/content/templates.js +80 -49
  337. package/modules/content/words.js +47 -0
  338. package/modules/debug/DebugPanel.js +14 -45
  339. package/modules/flow/contract.js +2 -1
  340. package/modules/flow/index.js +30 -16
  341. package/modules/gameplay/Container.js +17 -13
  342. package/modules/gameplay/Containers.js +23 -6
  343. package/modules/gameplay/Dialogue.js +93 -34
  344. package/modules/gameplay/Interactions.js +93 -51
  345. package/modules/gameplay/Inventory.js +64 -22
  346. package/modules/gameplay/Quests.js +146 -30
  347. package/modules/gameplay/boxOps.js +8 -1
  348. package/modules/gameplay/dialogueBubbles.js +16 -12
  349. package/modules/gameplay/inventoryOps.js +11 -8
  350. package/modules/gameplay/pickups.js +63 -37
  351. package/modules/gameplay/questLog.js +4 -2
  352. package/modules/gameplay/questSave.js +9 -4
  353. package/modules/gameplay/quests.contract.js +1 -1
  354. package/modules/grid/Grid.js +2 -2
  355. package/modules/grid/Layer.js +12 -8
  356. package/modules/grid/index.js +28 -23
  357. package/modules/grid/ops.js +43 -46
  358. package/modules/grid/preview.js +7 -7
  359. package/modules/grid/tiles.js +6 -6
  360. package/modules/hlod/index.js +42 -57
  361. package/modules/hud/index.js +22 -14
  362. package/modules/hud/parts.js +8 -8
  363. package/modules/level/contract.js +16 -0
  364. package/modules/level/heightfield.js +29 -31
  365. package/modules/level/index.js +113 -161
  366. package/modules/level/load.js +196 -0
  367. package/modules/level/meshes.js +65 -0
  368. package/modules/level/nodes.js +40 -23
  369. package/modules/lights/index.js +33 -183
  370. package/modules/lights/slots.js +93 -0
  371. package/modules/lights/sources.js +90 -0
  372. package/modules/music/Music.js +34 -28
  373. package/modules/music/rules.js +1 -1
  374. package/modules/nav/contract.js +16 -0
  375. package/modules/nav/index.js +180 -49
  376. package/modules/nav/navPath.js +45 -10
  377. package/modules/net/Client.js +7 -7
  378. package/modules/net/Host.js +7 -7
  379. package/modules/net/Net.js +1 -1
  380. package/modules/net/index.js +6 -5
  381. package/modules/net/sync.js +2 -2
  382. package/modules/net/transports.js +2 -2
  383. package/modules/particles/Particles.js +95 -29
  384. package/modules/particles/effect.js +86 -32
  385. package/modules/particles/shaders.js +19 -1
  386. package/modules/photo/Photo.js +23 -23
  387. package/modules/rigid/RigidBodies.js +255 -89
  388. package/modules/rigid/Vehicles.js +17 -8
  389. package/modules/rigid/collider3d.contract.js +26 -0
  390. package/modules/rigid/ragdoll.js +298 -0
  391. package/modules/rigid/ragdollBones.js +209 -0
  392. package/modules/rigid/refresh.js +10 -0
  393. package/modules/rigid/sync.js +51 -20
  394. package/modules/settings/Settings.js +177 -61
  395. package/modules/settings/apply.js +20 -13
  396. package/modules/settings/sections.js +19 -14
  397. package/modules/settings/strings.js +2 -2
  398. package/modules/settings/view.js +3 -3
  399. package/modules/sky/Sky.js +29 -22
  400. package/modules/sky/clouds.js +7 -7
  401. package/modules/sky/dome.js +33 -20
  402. package/modules/sky/domeLayers.js +9 -9
  403. package/modules/sky/environment.js +6 -6
  404. package/modules/sky/frame.js +19 -10
  405. package/modules/sky/season.js +7 -1
  406. package/modules/sky/shader.js +24 -25
  407. package/modules/sky/skyModule.js +17 -28
  408. package/modules/sky/tint.js +1 -1
  409. package/modules/swarm/Swarm.js +356 -0
  410. package/modules/swarm/draw.js +68 -0
  411. package/modules/swarm/grid.js +63 -0
  412. package/modules/terrain/ChunkManager.js +71 -59
  413. package/modules/terrain/chunkQueries.js +7 -24
  414. package/modules/terrain/chunkWorker.js +1 -1
  415. package/modules/terrain/draw.js +14 -11
  416. package/modules/terrain/index.js +42 -42
  417. package/modules/terrain/terrainColorMap.js +6 -3
  418. package/modules/terrain/terrainDefaults.js +2 -1
  419. package/modules/terrain/terrainEdit.js +45 -29
  420. package/modules/terrain/terrainGen.js +19 -12
  421. package/modules/terrain/terrainIsland.js +2 -2
  422. package/modules/terrain/terrainMesh.js +7 -6
  423. package/modules/terrain/terrainShape.js +8 -10
  424. package/modules/terrain/terrainShapeMain.js +3 -3
  425. package/modules/timeline/Timeline.js +83 -43
  426. package/modules/timeline/Tween.js +25 -19
  427. package/modules/timeline/shots.js +24 -17
  428. package/modules/triggers/index.js +95 -28
  429. package/modules/vegetation/Vegetation.js +34 -26
  430. package/modules/vegetation/densityMap.js +4 -7
  431. package/modules/vegetation/draw.js +39 -18
  432. package/modules/vegetation/groundChunks.js +21 -38
  433. package/modules/vegetation/index.js +37 -12
  434. package/modules/vegetation/modelGeometry.js +3 -6
  435. package/modules/vegetation/nearFade.js +1 -1
  436. package/modules/water/Water.js +20 -16
  437. package/modules/water/surface.js +3 -3
  438. package/modules/weather/Weather.js +52 -40
  439. package/modules/weather/particles.js +8 -8
  440. package/modules/weather/weatherDraw.js +28 -23
  441. package/modules/world/World.js +28 -15
  442. package/modules/world/explain.js +1 -1
  443. package/modules/world/index.js +30 -17
  444. package/modules/world/persist.js +90 -27
  445. package/modules/world/pos.js +5 -5
  446. package/modules/world/records.js +37 -11
  447. package/modules/world/sim.js +78 -27
  448. package/modules/world/simFar.js +2 -2
  449. package/modules/world/state.js +43 -11
  450. package/modules/world/thingSource.js +20 -5
  451. package/modules/world/views.js +27 -14
  452. package/package.json +48 -7
  453. package/presets.js +1 -3
  454. package/render/PostFX.js +83 -53
  455. package/render/backend.js +31 -33
  456. package/render/cascades.js +17 -12
  457. package/render/cascades.tsl.js +5 -8
  458. package/render/daylight.js +20 -3
  459. package/render/detail.js +8 -7
  460. package/render/effects.js +28 -25
  461. package/render/fuse.js +3 -3
  462. package/render/fx/cloudShadow.tsl.js +3 -3
  463. package/render/fx/detail.tsl.js +1 -1
  464. package/render/fx/index.js +5 -10
  465. package/render/fx/library.tsl.js +11 -0
  466. package/render/fx/lighting.tsl.js +2 -1
  467. package/render/fx/nodeErrors.tsl.js +2 -2
  468. package/render/fx/objectOrigin.tsl.js +1 -2
  469. package/render/fx/particles.tsl.js +8 -6
  470. package/render/fx/patchNodes.tsl.js +5 -15
  471. package/render/fx/postWebGPU.tsl.js +30 -26
  472. package/render/fx/sky.tsl.js +15 -17
  473. package/render/fx/uniforms.tsl.js +4 -4
  474. package/render/fx/wind.tsl.js +1 -1
  475. package/render/fxNumbers.js +3 -0
  476. package/render/layers.js +2 -2
  477. package/render/lighting.js +5 -3
  478. package/render/lightmap.js +41 -21
  479. package/render/lights.js +6 -6
  480. package/render/lit.js +24 -0
  481. package/render/materials.js +8 -7
  482. package/render/mergeCommon.js +22 -0
  483. package/render/modeling.js +2 -2
  484. package/render/occlusion.js +62 -15
  485. package/render/ownFrame.js +4 -4
  486. package/render/patches.js +15 -15
  487. package/render/postWebGL.js +15 -12
  488. package/render/probes.js +41 -19
  489. package/render/recordSweep.js +117 -0
  490. package/render/shaderErrors.js +10 -9
  491. package/render/shadowCache.tsl.js +107 -0
  492. package/render/shadowTypes.js +9 -0
  493. package/{core → render}/shadows.js +59 -13
  494. package/render/slots.js +7 -7
  495. package/render/terms.js +22 -24
  496. package/render/uniformDecl.js +1 -1
  497. package/types/core.d.ts +336 -202
  498. package/types/gameplay.d.ts +254 -130
  499. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  500. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  501. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  502. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
  503. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  504. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  505. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
  506. package/types/generated/core/input/inputSeat.d.ts +26 -0
  507. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  508. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
  509. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
  510. package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
  511. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
  512. package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
  513. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  514. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
  515. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  516. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
  517. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  518. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  519. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  520. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  521. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  522. package/types/generated/modules/grid/Grid.d.ts +1 -0
  523. package/types/generated/modules/grid/Layer.d.ts +1 -1
  524. package/types/generated/modules/grid/index.d.ts +3 -3
  525. package/types/generated/modules/music/Music.d.ts +7 -5
  526. package/types/generated/modules/particles/Particles.d.ts +5 -4
  527. package/types/generated/modules/sky/Sky.d.ts +21 -10
  528. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  529. package/types/generated/modules/timeline/Timeline.d.ts +7 -5
  530. package/types/generated/modules/water/Water.d.ts +1 -0
  531. package/types/generated/modules/weather/Weather.d.ts +14 -16
  532. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  533. package/types/generated/modules/world/World.d.ts +11 -7
  534. package/types/generated/render/PostFX.d.ts +21 -23
  535. package/types/generated/render/materials.d.ts +1 -0
  536. package/types/generated/render/occlusion.d.ts +9 -0
  537. package/types/generated/render/patches.d.ts +1 -0
  538. package/types/generated/ui/Focus.d.ts +1 -0
  539. package/types/generated/ui/UI.d.ts +1 -0
  540. package/types/nav.d.ts +47 -15
  541. package/types/physics.d.ts +150 -73
  542. package/types/pixel.d.ts +75 -0
  543. package/types/tsl.d.ts +37 -4
  544. package/types/world.d.ts +48 -75
  545. package/ui/Focus.js +10 -9
  546. package/ui/Parts.js +13 -5
  547. package/ui/UI.js +7 -7
  548. package/ui/defaults.js +3 -2
  549. package/ui/theme.js +7 -5
  550. package/core/assetEntry.js +0 -109
  551. package/core/engineCamera.js +0 -32
  552. package/core/ground.js +0 -104
  553. package/core/holds.js +0 -134
  554. package/core/math.js +0 -48
  555. package/core/moduleSlots.js +0 -100
  556. package/core/modules.js +0 -314
  557. package/core/saveApply.js +0 -210
  558. package/core/saveValues.js +0 -46
  559. package/core/session.js +0 -174
  560. package/core/shadowTypes.js +0 -16
  561. package/core/util.js +0 -17
  562. package/core/view.js +0 -43
  563. package/docs/MIGRATING-0.3.md +0 -248
  564. package/docs/MIGRATING-0.4.md +0 -320
  565. package/docs/MIGRATING-0.5.md +0 -68
  566. package/docs/MIGRATING-0.6.md +0 -126
  567. package/docs/PERF.md +0 -245
  568. package/docs/recipes/36-sky-ground-plants.md +0 -158
  569. package/docs/recipes/37-terrain-hooks.md +0 -115
  570. package/docs/recipes/38-environment-hooks.md +0 -67
  571. package/docs/recipes/42-terrain-shape.md +0 -64
  572. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  573. package/docs/recipes/54-three-idioms.md +0 -88
  574. package/examples/plain-picture/FINDINGS.md +0 -53
  575. package/examples/sheepisland/.threedog/content-index.json +0 -1
  576. package/modules/camera/projection.js +0 -21
  577. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  578. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  579. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  580. /package/core/{actor.js → ops/actor.js} +0 -0
  581. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  582. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  583. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  584. /package/core/{cells.js → stream/cells.js} +0 -0
  585. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  586. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  587. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  588. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  589. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  590. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  591. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  592. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  593. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -1,47 +1,45 @@
1
1
  # Add weather or change the sky
2
2
 
3
- **In this recipe**: 1. Switching weather · 2. The game's own weather table · 3. Sky colors, sun, stars (and the sky color for your own shader) · 4. Time and brightness (how a game's value and the weather multiply) · 5. Verify · 6. Day and night in game logic · 7. Wet roads
3
+ **In this recipe**: 1. Switching weather · 2. The game's own weather table · 3. Sky colors, sun, stars (and the sky color for your own shader) · 4. Time and brightness · 5. Verify · 6. Day and night in game logic · 7. Wet roads · 8. Clouds · 9. Extra sky layers · 10. Flat backdrop
4
4
 
5
- Modules: `sky()` (draws the dome from `engine.calendar`, sun and moon, and computes the signals; it writes no light, fog or exposure, those are your `picture/` code, recipe 62; the time itself is `calendar()`, recipe 06), `weather()` (needs sky; the game's weather types, smooth transitions, rain and snow,
5
+ Modules: `sky()` (draws the dome from `engine.calendar`, sun and moon, and computes the signals; it writes no light, fog or exposure, those are your `picture/` code, recipe 62; the time itself is `calendar()`, recipe 06), `weather()` (the game's weather types, smooth transitions, rain and snow,
6
6
  lightning; their picture is `weather({ rain, snow, lightning })`, recipe 44). The engine has only a neutral fallback.
7
7
 
8
- ```js
8
+ ```js fragment
9
9
  engine.use(sky({ keyframes: ROWS, sunSize: 600, clouds: { coverage: 0.6 }, dim: { stars: false } })); // start values
10
- engine.uniforms.uSunPower.value = 4; // sun, moon, star and dome cloud numbers: engine.uniforms, the dome's own objects, on both renderers
11
- engine.uniforms.uCloudCover.value = 0.8; // also uSunSize uSunGlow uMoonSize uMoonPower uMoonColor uStars uStarScale uCurve uSkyCloudScale uSkyCloudSpeed uCloudOpacity uCloudSoft uCloudColor uCloudShade
10
+ engine.uniforms.uSunBrightness.value = 4; // sun, moon, star and dome cloud numbers: engine.uniforms, the dome's own objects, on both renderers
11
+ engine.uniforms.uCloudCover.value = 0.8; // also uSunSize uSunGlow uMoonSize uMoonBrightness uMoonColor uStars uStarScale uSkyCurve uSkyCloudScale uSkyCloudSpeed uCloudOpacity uCloudSoft uCloudColor uCloudShade
12
12
  engine.sky.top = boss ? '#400' : null; // plain fields, read each frame: top, horizon (color over the keyframes, null = keyframes), orbit.tilt / sway, dim.tint / stars
13
13
  engine.sky.backdrop = 0x335577; // one flat color in place of the dome; null gives the dome back
14
14
  engine.sky.keyframes(NIGHT_ROWS); // the day's rows, live
15
15
  engine.sky.clouds({ glsl, tsl }); // your cloud function; null = the built-in kind
16
16
  engine.sky.layer('aurora', { glsl, tsl, blend: 'add' }); // a named dome layer; null removes it
17
17
  const mySky = new THREE.Mesh(skyGeometry, skyMaterial); // or a skybox name, a Texture
18
- engine.sky.replace(mySky); // skybox name | Texture | CubeTexture | Object3D, never written; null gives the dome back
18
+ engine.sky.replace(mySky); // skybox name | Texture | CubeTexture | Object3D, never written; null gives the dome back, false draws no sky
19
19
  mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
20
20
  ```
21
21
 
22
- WebGPU (recipe 56): same dome as a node material. Hooks take `{ glsl, tsl: (ctx) => vec4 }` ([52](52-around-the-picture.md#tsl-forms)); GLSL alone throws `[webgpu-needs-tsl]`. Own sky: three's `SkyMesh` via `engine.sky.replace`.
22
+ WebGPU (recipe 56): same dome as a node material. Hooks take `{ glsl, tsl: (ctx) => vec4 }` ([52](52-around-the-picture.md#tsl-forms)); GLSL alone throws `[webgpu-needs-tsl]`. Own sky: three's `SkyMesh` via `engine.sky.replace`, or a dome of your own with a node material (the `ShaderMaterial` below is the WebGL form): a `MeshBasicNodeMaterial` with `side: THREE.BackSide`, `fog: false`, `depthWrite: false`, `depthTest: false`, and a `colorNode` built on the view direction (world position minus camera position, normalized), on a sphere that follows the camera.
23
23
 
24
24
  The sky follows one contract: **inputs** time, weather, season,
25
25
  **outputs** the dome and the background, plus the shared `engine.uniforms`
26
- (`uSunDir`, `uSunColor`, `uDaylight`, `uTimeOfDay`, `uSkyTop`, `uSkyHorizon`, `uWind`, `uCloud`, `uRain`, `uSnow`, `uWeatherLight`, `uWeatherFog` (the weather state writes the last six every frame), season tints) and events (`day:start`, `season:change`, `weather:change`) that wind,
26
+ (`uSunDir`, `uSunColor`, `uDaylight`, `uTimeOfDay`, `uSkyTop`, `uSkyHorizon`, `uWind`, `uWeatherCloud`, `uRain`, `uSnow`, `uWeatherLight`, `uWeatherFog` (the weather state writes the last six every frame), season tints) and events (`day:start`, `season:change`, `weather:change`) that wind,
27
27
  rain and vegetation read. The keyframes are only the default implementation: `engine.sky.replace` swaps the whole dome and everything else keeps running (the whole sky module is
28
28
  `engine.use(mySky(), { replaces: 'sky' })`).
29
29
 
30
30
  ### Your own sky object: what `engine.sky.replace(obj)` does with it
31
31
  The engine hides its dome, adds `obj` to the scene root when it has no parent yet (and removes it again on `replace(null)` only then), and from
32
32
  then on **never moves, scales or writes it**: it does not follow the camera, is not scaled to the far plane and is not exempted from culling.
33
- (The built-in dome does all three itself: an `onBeforeRender` copies the camera position and scales it to `0.9 × camera.far`.) So a dome of
34
- your own must, on its own:
33
+ (The built-in dome does all three itself.) So a dome of your own must, on its own:
35
34
 
36
35
  - **contain the camera and stay inside the far plane**: either a fixed sphere big enough for everywhere the camera goes (radius < `camera.far`,
37
- which the engine pulls in to the view range unless you take it: `engine.view.manual('far')`), or one that follows the camera; or skip
36
+ which the engine pulls in to the view range unless you take it: `engine.autoView.manual('far')`), or one that follows the camera; or skip
38
37
  depth altogether as below, so the radius no longer matters;
39
38
  - **compute the view direction per pixel from world space**: pass `worldPosition - cameraPosition` (linear, safe to interpolate) as the
40
39
  varying and do every non-linear step (normalize, `atan`, projecting onto a cloud plane, noise) in the fragment shader. A direction taken from
41
40
  the vertex's local `position`, or a non-linear value computed per vertex, is wrong once the dome is off-centre or its triangles are big:
42
41
  that is where arcs bend and seams show at the corners of the sphere's faces;
43
- - draw behind everything: `gl_Position = clip.xyww` (depth 1), `depthWrite: false`, `frustumCulled = false`, `renderOrder` well below the scene,
44
- `side: THREE.BackSide`, `fog: false`.
42
+ - draw behind everything, as the block below does.
45
43
 
46
44
  ```js
47
45
  const sky = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), new THREE.ShaderMaterial({
@@ -72,15 +70,16 @@ Time of day still reaches it through `engine.uniforms` (`uSunDir`, `uDaylight`,
72
70
  ```js
73
71
  engine.weather.set('rain', { seconds: 20 }); // transition to rain over 20 seconds (a type of the game's table, see 2)
74
72
  engine.weather.set('storm', { seconds: 0 }); // at once: the full storm before the next step (a screenshot or test right after the call)
75
- engine.weather.setAuto(true); // change weather at random (openWorld({ camera: 'follow', autoWeather: true }) also works)
73
+ engine.weather.auto = true; // change weather at random (openWorld({ camera: 'follow', autoWeather: true }) also works)
76
74
  engine.events.on('weather:lightning', () => { /* thunder */ });
75
+ engine.events.on('weather:change', ({ from, to }) => { /* once per change of name, when the blend starts; set() with the same name again does not fire */ });
77
76
  ```
78
77
 
79
78
  ## 2. The game's own weather table (example: a desert)
80
79
  `weather({ types })` is the whole list of the game's weather; without it there is only a calm `clear` (the engine assumes no climate). Seven temperate
81
80
  ones (clear cloudy overcast rain storm snow fog) are an opt-in preset: `weather(presets.weather.temperate)`; extend with
82
81
  `types: { ...presets.weather.temperate.types, dust: {...} }`.
83
- The preset supplies types and an `autoPool`; the weather changes by itself only with `auto: true` (or `engine.weather.setAuto(true)`). To pin one
82
+ The preset supplies types and an `autoPool`; the weather changes by itself only with `auto: true` (or `engine.weather.auto = true`). To pin one
84
83
  for a picture: `engine.weather.set('clear')`, or a shot's `--weather clear` (it also turns `auto` off); a shot prints the weather under the picture.
85
84
  Left-out fields are calm (no cloud, rain, snow, grey, lightning; sun, fog, wind 1). There is no patch option for one field
86
85
  of a preset type: spread that one type, `const T = presets.weather.temperate.types; weather({ types: { ...T, rain: { ...T.rain, fog: 0.5 } } })`.
@@ -93,27 +92,25 @@ engine.use(sky(), weather({
93
92
  engine.weather.set('dust', { seconds: 15 }); engine.weather.current.heat; // 0..1 during the change
94
93
  ```
95
94
  Fields: `cloud` cloud cover 0-1, `sun` sunlight multiplier, `fog` fog distance multiplier (smaller = denser fog), `wind` wind strength, `rain`/`snow`
96
- 0-1, `grey` how gray the sky turns, `lightning` lightning. A table where nothing rains or snows builds no particles.
95
+ 0-1, `grey` how gray the sky turns, `lightning` lightning (a type above 0.5 strikes). A table where nothing rains or snows builds no particles.
97
96
  With openWorld the weather module is already installed; pass its options through the preset: `openWorld({ camera: 'follow', weather: { types, autoPool } })`.
98
97
 
99
98
  ## 3. Changing sky colors, sun, stars
100
99
  `sky({ keyframes })`:
101
- `[time 0-1, zenith color, horizon color, sun color, ambient intensity]`, interpolated by time; the rows
102
- run from time 0 to time 1 (both midnight: the first row at 0, the last at 1 with the same values), else the sky throws. What each column drives
103
- (and which light carries the moonlight) is on `keyframes` in `SkyPictureOptions`, `types/world.d.ts`;
104
- also `sunSize sunGlow moonSize starDensity clouds` (defaults and ranges there too; `hoursPerDay` is timing, so it is a
105
- `calendar()` option, not a sky key). `sky()` takes `time` and the dome's start values: all of these are `sky({ ... })` start values; at run time use the entries at the top of this page. `sky({ sun | hemisphere | fog })`
106
- throw naming what to write in your `picture/` code.
100
+ `[time 0-1, zenith color, horizon color, sun color, ambient intensity]`, interpolated by time; the rows are sorted and
101
+ run from time 0 to time 1, else the sky throws (both ends are midnight: give the last row the first row's values, or the colors jump there). What each column drives
102
+ is on `keyframes` in `SkyPictureOptions`, `types/world.d.ts`;
103
+ also `sunSize sunGlow starDensity clouds` (defaults and ranges there too; `hoursPerDay` is timing, so it is a
104
+ `calendar()` option, not a sky key). All of these are `sky({ ... })` start values; at run time use the entries at the top of this page.
107
105
  **Day and night brightness** is your `picture/` code: the sky lights nothing. Read `uDaylight` and write your own lights (recipe 62), and check with `shot --time 12:00` and
108
106
  `--time 22:00`. The keyframes only color the dome; the ambient column also dims a skybox and the weather's sky tint. `engine.sky.environment({ into: engine.scene })` builds an environment map
109
107
  from the dome (outdoor reflections show the sky, not a studio; it darkens by itself), recipe 34.
110
- The look of rain and snow is `weather({ rain, snow })` (shape, density, shaders; the game's own particles with `engine.weather.define`: recipe 44).
111
108
 
112
109
  ### Sky color for my shader (horizon color, zenith color)
113
110
  A shader of your own that should meet the sky (a sea fading to the horizon, distant cards, a reflection) reads the colors the sky draws this frame:
114
111
  `engine.uniforms.uSkyHorizon` and `engine.uniforms.uSkyTop` (`THREE.Color`, linear). They hold the keyframes, `engine.sky.top` / `horizon`,
115
112
  the weather's grey tint and lightning; with a backdrop the horizon is the backdrop color. A fog of yours that should melt into the sky copies
116
- it in `engine.onRender`: `scene.fog.color.copy(engine.uniforms.uSkyHorizon.value)`. Share the object, do not copy it in `onFrame`: `onFrame` runs before the sky updates, so a copy is one
113
+ it in `engine.onRender` (recipe 34). Share the object, do not copy it in `onFrame`: `onFrame` runs before the sky updates, so a copy is one
117
114
  frame old (after a time jump, the first picture shows the old hour's color).
118
115
  ```js
119
116
  const sea = new THREE.ShaderMaterial({ uniforms: { uHorizon: engine.uniforms.uSkyHorizon, uTop: engine.uniforms.uSkyTop, uSunDir: engine.uniforms.uSunDir },
@@ -125,32 +122,28 @@ engine.uniforms.uSkyHorizon.value.getHexString(); // read it in JS too (game l
125
122
  ## 4. Time and brightness (game code)
126
123
  ```js
127
124
  await engine.skip({ to: '19:30' }); // jump forward to a time: timers, calendar.at / daily, day:start fire on the way (needs a calendar dayLength; recipe 06)
128
- engine.mod('clock.rate', { owner: 'game', set: 0 }); // the calendar and calendar seconds stop together, so the sky stops moving (set: 2 = double speed; remove() undoes it); game seconds per day: calendar({ dayLength: 600 }); the three kinds of time are in recipe 06
129
- engine.scene.fog = new THREE.Fog(0x99aabb, 90, 300); // fog is plain three.js; engine.uniforms.uViewDistance (terrain({ viewFog: true }) writes it) and uWeatherFog are signals your picture/ code reads
125
+ engine.mod('clock.rate', { owner: 'game', set: 0 }); // the calendar and calendar seconds stop together, so the sky stops moving (set: 2 = double speed; remove() undoes it)
130
126
  ```
131
- **The sky draws the calendar's time; it does not own it.** Day, time of day and seasons are the `calendar()` module (recipe 06 "The time table");
127
+ **The sky draws the calendar's time; it does not own it.** Day, time of day, seasons and day length are the `calendar()` module (recipe 06 "The time table");
132
128
  the sky reads `engine.calendar.timeOfDay` each frame to place the sun and blend the keyframes, and `engine.calendar.season` for the season tint.
133
129
  Without a calendar, `sky({ time: '18:30' })` draws that one fixed time (an arena, a museum diorama, a space station window); with a calendar,
134
- `sky({ time })` throws (start the day with `calendar({ time })`). A game that draws its own sky (a skybox shader, a 2D painted backdrop) keeps the
130
+ `sky({ time })` warns and goes unused (start the day with `calendar({ time })`). A game that draws its own sky (a skybox shader, a 2D painted backdrop) keeps the
135
131
  calendar and reads it the same way; a game indoors keeps the calendar and installs no sky.
136
132
  Fixed dusk in an open world: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day; goes to the calendar) and do not pass
137
133
  `calendar: presets.calendar.cycle` (the template does; the cycle is what moves the clock). `engine.sky.isDay` is `sunHeight > 0` with `sunHeight = sin((timeOfDay - 0.25) * 2π)`: true strictly between timeOfDay 0.25 and 0.75 (06:00 to 18:00 on the default 24-hour face; with `hoursPerDay: H` the same fractions, 0.25H to 0.75H), false at exactly 06:00 and 18:00, so 18:30 already reads as "night" in `describe().time.isDay`. `daylight` = `max(0, sunHeight)`. Keyframes only change colors, not this flip.
138
134
  `engine.calendar.isDay` / `daylight` are the same formula from the clock (they work with no sky); the sky's are what it draws (its fixed time without a calendar).
139
- A day-night cycle is `calendar({ dayLength: 360 })` or `calendar(presets.calendar.cycle)` (`presets.calendar.fourSeasons` includes it);
140
- `hoursPerDay` changes the clock face. An audio rule's `time` condition (from the calendar) takes `'day'`, `'night'` or a range `['18:00', '06:00']`;
141
- anything else warns once.
142
- Seasons are off by default (`engine.calendar.season` is `null`, no `season:change`); name them to turn them on:
143
- ```js
144
- calendar({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28, dayLength: 360 }); // days advance only with a dayLength; or the preset: openWorld({ camera: 'follow', calendar: presets.calendar.fourSeasons })
145
- calendar({ seasons: [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], dayLength: 360 }); // seasons of their own length
146
- ```
135
+ An audio rule's `time` condition (from the calendar) takes `'day'`, `'night'` or a range `['18:00', '06:00']`; anything else warns once.
136
+ Seasons are off by default (`engine.calendar.season` is `null`, no `season:change`); name them to turn them on, `calendar({ seasons: [...] })` or `presets.calendar.fourSeasons` (recipe 06).
137
+ `engine.applyState({ season: 'winter' })` (or `?season=winter`) jumps `calendar.day` to that season's first day, time of day kept; it needs
138
+ `calendar({ seasons })`, and a wrong name throws with the calendar's list.
139
+
147
140
  The lights and the fog are your own three.js objects, so nothing overwrites them. To darken or tint everything (a cave, a horror segment), your `picture/` code reads one signal of yours and multiplies
148
141
  it in with the weather's (`uWeatherLight`, `uWeatherFog`); the sky color has its own shared points, which stack with the weather's without overwriting it ([recipe 55](55-mods-time-wrap.md#picture-points-follow-the-same-rule)):
149
142
  ```js
150
143
  const cave = engine.mod('sky.tint', { owner: 'cave', value: { color: 0x402030, amount: 0.5 } }); // amount = zenith, horizon: = horizon
151
144
  cave.remove(); // leave the cave
152
145
  ```
153
- These are ordinary shared points (recipe 55): `sky.flash` adds, `sky.tint` / `ground.cover` entries blend weighted by their amount, `{ for: 3 }` ends one by itself.
146
+ `sky.flash` adds, `sky.tint` / `ground.cover` entries blend weighted by their amount, `{ for: 3 }` ends one by itself. A tint color dims with the sky's own light unless `engine.sky.dim.tint = false`.
154
147
 
155
148
  ## 5. Verify
156
149
  - Text: `npm run shot -- / --time 19:30 --weather dust --wait 2 --describe-only`, then look for "Time: 19:30..." and "Weather: dust (rain 0, snow 0, fog 0.35)".
@@ -169,3 +162,64 @@ and `roughness`); darker alone reads as dirt or shadow. Gloss only shows when th
169
162
  the lamps and windows as long streaks. A puddle needs a soft-rimmed mask; a hard cut-off makes opaque discs that read as holes. Judge it on a
170
163
  shot at noon and at night, in rain and after. To compare with your own result afterwards, the technique example `wet-road`
171
164
  (`threedog examples pull wet-road`) shows one way, with a dry-out delay in game time.
165
+
166
+ ## 8. Clouds: `sky({ clouds })`
167
+ Keys and defaults are `SkyCloudOptions` in `types/world.d.ts`; at run time the numbers are the `engine.uniforms` of the block at the top of this page.
168
+ `coverage` multiplies the weather's cloud amount. A `sky()` without `clouds` starts with the cover at 0: write `uCloudCover` to show any.
169
+
170
+ Why a thin band at the horizon with `kind: 'plane'`: the plane projection divides by height, so near the horizon one screen pixel covers a lot of cloud plane
171
+ and the noise is dense and small; overhead one pixel covers little and the same coverage looks sparse. For a sky full of big clouds use
172
+ `kind: 'cumulus'`, or raise `horizon` and lower `scale`. Cost: both are one 2D pass over the dome (no ray marching); cumulus does about
173
+ 2.7x the noise work of plane on the cloudy pixels (pixels below the horizon or with no cloud cover skip it). Cloud shadows on the ground
174
+ (the signal `engine.uniforms.uCloudShadow`, a separate setting, off until written) follow the same weather cover, so more clouds still means more shadow.
175
+ Their two-noise shape is fixed; strength, scale and speed are `uCloudShadow`, `uCloudShadowScale`, `uCloudShadowSpeed`.
176
+
177
+ ```js fragment
178
+ sky: { clouds: { kind: 'cumulus', coverage: 1, scale: 0.45, color: 0xfff4e4, shade: 0x8a9cb8, speed: [0.003, 0.001] } }
179
+ ```
180
+
181
+ ### Your own cloud function
182
+ `engine.sky.clouds(glsl | { glsl, tsl, uniforms })` is the one way in (a `glsl` key in `sky({ clouds })` throws and names it). It recompiles the dome once, so call it at a scene change. The GLSL defines `threedogClouds` as in the example below; the dome calls it for every upper-hemisphere pixel with cover above 0.01, then does `mix(sky, rgb, a)`.
183
+ `dir` is the unit view direction (`dir.y > 0`), `sunDir` points at the sun (the moon is opposite), `night` runs 0 to 1, `lit` / `shade` are `clouds.color` / `clouds.shade`, `cover` is the weather's cloud amount times `clouds.coverage`. Return the final color (dim it at night yourself) and the opacity (apply your own horizon fade).
184
+ In scope: the GLSL noise helpers `float threedogHash(vec2 p)` and `float threedogNoise(vec2 p)`, the built-in cloud uniforms (`uSkyCloudScale`, `uSkyCloudSpeed`, `uCloudHorizon`, `uCloudFade`...) and
185
+ the patch's `uniforms` (declared for you; number, `THREE.Color`, `THREE.Vector2/3/4`, array of 2-4 numbers, or `THREE.Texture`). Change one later
186
+ with `engine.sky.uniforms.uEdge.value = 0.1` (both renderers). A bad `kind`, GLSL without the function, or an unsupported uniform value throws with the fix.
187
+ Flat painted cloud blobs with a hard edge, multiplied by a texture:
188
+ ```js fragment
189
+ // sky({ clouds: { color: 0xfff1dc, shade: 0x9aa8c4 } }) gives lit and shade; the function goes through the hook
190
+ engine.sky.clouds({ uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
191
+ glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
192
+ vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
193
+ float n = threedogNoise(p) * 0.65 + threedogNoise(p * 2.3 + 5.0) * 0.35;
194
+ float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard edge
195
+ float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
196
+ vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
197
+ return vec4(c, a * smoothstep(0.0, 0.1, d.y));
198
+ }` });
199
+ ```
200
+
201
+ ## 9. Extra sky layers: rainbow, aurora, color bands
202
+ `engine.sky.layer(name, spec)`, drawn on the dome after clouds and stars; none by default:
203
+
204
+ ```js
205
+ engine.sky.layer('aurora', { blend: 'add', uniforms: { uAurora: [0.2, 1, 0.6] }, glsl: `vec4 threedogSkyLayer(vec3 d, float time, vec3 sunDir, float night){
206
+ float band = smoothstep(0.25, 0.45, d.y) * (1.0 - smoothstep(0.55, 0.8, d.y));
207
+ float n = threedogNoise(vec2(d.x * 4.0 + time * 0.05, d.z * 2.0));
208
+ return vec4(uAurora, band * n * night); }` });
209
+ ```
210
+ Signature `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)` returns (rgb, amount); `dir` covers the whole sphere, so `dir.y` goes below 0. `blend: 'mix'` (default) or `'add'`;
211
+ `order` sorts layers (smaller first); `uniforms` work like the cloud function's. Each layer's function is
212
+ renamed (`threedogSkyLayer0`, `1`, ...), so layers from different parts of the game never clash.
213
+
214
+ ## 10. Flat backdrop: no horizon at all
215
+ For a scene that should have no horizon (a menu stage, a board game, a diorama):
216
+ ```js fragment
217
+ sky({ backdrop: 0xefebe4 }); // one color
218
+ engine.sky.backdrop = engine.sky.isDay ? 0xefebe4 : 0x2c3346; // live, from your own frame code; null gives the dome back
219
+ ```
220
+ - Hides the dome (no gradient, horizon line, sun / moon disk, stars or clouds) and sets `scene.background` to the color. A plain background
221
+ color is not tone mapped, so what you write is what shows.
222
+ - The keyframes still drive the signals (`uSunDir`, `uDaylight`), and `uSkyHorizon` reports the backdrop, so a fog that copies it fades far things into the backdrop.
223
+ - It takes a color, not a function (a function throws). A color that follows something is a write from your frame code: to fade toward gray in snow,
224
+ `engine.sky.backdrop.lerpColors(dry, gray, engine.weather.current.snow * 0.3)` changes the `THREE.Color` in place (reuse the Color objects; it runs every frame).
225
+ - While a backdrop is on it wins over a skybox given to `engine.sky.replace`: set it to `null` first.
@@ -2,7 +2,7 @@
2
2
 
3
3
  **In this recipe**: 0. Where the picture lives · 1. Materials are plain three.js · 1a. The engine's big pieces · 1b. Lights and stalls · 1c. The UI's picture ·
4
4
  2. Using your own models instead of procedural ones · 2a. Reusing art · 2b. Wind, cloud shadows and season tint on your own materials ·
5
- 3. When the engine gets a new picture value · 4. Verify · 5. Sounds and music
5
+ 3. When the engine gets a new picture value · 4. Verify
6
6
 
7
7
  ```js
8
8
  // picture/materials.js: the game's materials are its own three.js objects
@@ -13,12 +13,12 @@ engine.water.material.color.set(0x3070a0); // a big engine piece hands
13
13
 
14
14
  **The engine ships no art.** No default picture, character model, terrain drawing or terrain generator: until the game gives one, everything is a
15
15
  plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
16
- one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
16
+ one white directional light with soft shadows, no tone curve), and the console says once in dev what is missing and how to fix it.
17
17
 
18
18
  ## 0. Where the picture lives
19
19
  The picture is code of the game: a `picture/` folder of plain three.js, and recipe 62 is its home. Any art direction fits: realistic, toon, pixel, painterly,
20
20
  flat, noir. Not part of the picture: model / texture / sound files and procedural models content names (an **asset pack**, `engine.assets.manifest`, recipe 05
21
- "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20; `calendar({ hoursPerDay })`).
21
+ "Asset packs"), sounds (game config, `createEngine({ audio })`, recipe 31), gameplay data and timing (a **content pack**, recipe 20; `calendar({ hoursPerDay })`).
22
22
 
23
23
  Swapping the picture must never change the map or the rules, so a thing that changes the world (water level, terrain seed, a size) is a module option, and a
24
24
  thing that only changes pixels is a write on the module's three.js material. The terrain generator `terrainPreset` / `riverAt` / `BIOMES` / `terrainStrings` is a
@@ -29,29 +29,19 @@ separate package, `@threedog/terrain-noise`, because the shape of the world is g
29
29
  `new THREE.MeshStandardMaterial(...)`, `MeshToonMaterial`, `ShaderMaterial`, `onBeforeCompile`: all work as in any three.js project, and a plain material gets fog and
30
30
  cascaded shadows by itself. Keep them in `picture/materials.js` by name, and let other code ask for `picture.materials.wall`, so a change of picture touches one folder.
31
31
  ```js
32
- // Solid prop with vertex colors (merged model)
33
- const prop = new THREE.MeshLambertMaterial({ vertexColors: true });
34
-
35
- // See-through, double-sided
36
- const banner = new THREE.MeshLambertMaterial({ color: 0xd04a3a, transparent: true, opacity: 0.8, side: THREE.DoubleSide });
37
-
38
- // Glowing lamp
39
- const lamp = new THREE.MeshStandardMaterial({ color: 0x6b5a40, emissive: 0xffc070, emissiveIntensity: 1.2 });
40
-
41
32
  // Toon with an explicit light ramp: three.js's gradientMap; rampTexture takes grays, dark to light, and how far the bands melt (0-1). three's toon reads only
42
33
  // the red channel, so a colored ramp needs celLighting on the WebGPU route (recipe 56); on WebGL a colored shade is a lighting patch (recipe 43)
43
34
  import { rampTexture } from 'threedog';
44
35
  const skin = new THREE.MeshToonMaterial({ color: 0xe8a0a0, gradientMap: rampTexture([0.25, 0.6, 1], 0.2) });
45
36
  ```
46
37
  **Textures by asset name.** `engine.assets.texture(name)` returns a promise of a `THREE.Texture`; a data map (normal, roughness, ao) takes `{ color: false }`. The
47
- `assets.useTexture` form fills a slot when the image arrives and warns once if it fails, so the material can be used at once. Tiling is three.js:
38
+ `assets.useTexture` form fills a slot when the image arrives and warns once if it fails, so the material can be used at once:
48
39
  ```js
49
40
  const rock = new THREE.MeshStandardMaterial({ roughness: 0.9 });
50
41
  engine.assets.useTexture('rock.png', t => { t.wrapS = t.wrapT = THREE.RepeatWrapping; t.repeat.set(4, 4); rock.map = t; rock.needsUpdate = true; });
51
42
  engine.assets.useTexture('rock_n.png', t => { rock.normalMap = t; rock.needsUpdate = true; }, { opts: { color: false } });
52
43
  ```
53
- Changing what compiles into the program (`vertexColors`, `flatShading`, `transparent`, adding a map) after the first render needs `material.needsUpdate = true`, as in
54
- three.js. `material.clone()` does not carry engine patches (three's `Material.copy` skips `onBeforeCompile`): apply the effects to the clone again.
44
+ `material.clone()` does not carry engine patches (three's `Material.copy` skips `onBeforeCompile`): apply the effects to the clone again.
55
45
  Grain, your own GLSL and the engine's shader functions on these materials: section 2b and recipe 43.
56
46
 
57
47
  ## 1a. The engine's big pieces
@@ -64,10 +54,10 @@ Terrain, water, plants, rain and snow, pickups and grid layers keep their engine
64
54
  | `.patches` | The engine's shader patches for that piece, so your own material keeps its behavior | `engine.water.material = applyEffects(new THREE.MeshPhongMaterial(), { patches: engine.water.patches })` |
65
55
  | Module options and a plain method | Values baked when the module builds (terrain colors, normal map tiling) | `terrain({ colors })`, `engine.terrain.recolor({ colors })`, `engine.water.normalMap(name, { repeat })` |
66
56
 
67
- Each piece's own recipe has its details: water and weather 44, terrain 37, plants 36, pickups 03, grids 29.
57
+ Each piece's own recipe has its details: water and weather 44, terrain 28, plants 36, pickups 03, grids 29.
68
58
 
69
59
  ## 1b. Lights and stalls
70
- The placeholder lights and your own: recipe 38. This section is what a changing light setup costs.
60
+ The placeholder lights and your own: recipe 34. This section is what a changing light setup costs.
71
61
 
72
62
  three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
73
63
  loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
@@ -77,7 +67,7 @@ recompile). In dev the console warns (code `light-recompile`) when programs were
77
67
  For many torches, street lamps, campfires, muzzle flashes or neon signs use the light pool: a fixed number of real lights, created once at install,
78
68
  moves to the sources that matter most (near the camera, bright, high `priority`) and fades with intensity, so the light setup never changes. Install
79
69
  it before `engine.start()` so the startup compile covers its lights:
80
- ```js
70
+ ```js fragment
81
71
  import { lightPool } from 'threedog';
82
72
  engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
83
73
  for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
@@ -88,7 +78,12 @@ for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed;
88
78
  const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, distance: 6 });
89
79
  flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
90
80
  ```
91
- `engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
81
+ Pool lights cast no shadow unless you ask (`shadows`), and the pool picks by distance, brightness and `priority`: it knows nothing of rooms, so indoors a lamp shines through the wall into the next room.
82
+ Three ways out, by how much of the picture depends on it: turn off the sources the player cannot see from where they are with `set({ intensity: 0 })` (the game knows its rooms; near a door keep both sides on, and a
83
+ source's `glow` stand-in keeps the far room reading as lit); give the few lights that matter a shadow with `lightPool({ shadows })` and `castShadow: true` on the source, which costs a shadow map each and is worth measuring first; or use `distance` short
84
+ enough that the light dies before the next room. Plain three.js lights of your own with a shadow map work beside the pool.
85
+
86
+ `describe().lightPool` lists which source each real light holds; `focus` measures from the player instead of the
92
87
  camera. Options and handle: `../api/lightPool.md`. Windows and signs that light up at night need no real light each: see below.
93
88
 
94
89
  ### Night glow: emissive that follows daylight
@@ -107,15 +102,12 @@ engine.onFrame(() => {
107
102
  ```
108
103
  Share one Material between the meshes that glow together. Models built later bring their own copies: collect them when the model is made
109
104
  (`model.traverse(o => { if (o.material?.name === 'window') glowing.add(o.material); })`, a `Set` the frame loop walks), and take them out when it leaves. `uNight`
110
- starts at daylight 0.3, roughly 17:00 to 18:00 and back in the morning: a starting value, not a rule. Judge it in shots at dusk.
111
-
112
- **Headroom: why a glow turns into glare.** What reaches the tone curve is the emissive color times `emissiveIntensity`. A near-white color
113
- (`#ffe6c0`) has no headroom: all three channels already sit near 1, so multiplied past 1 they clip to the same white under tone mapping, and
114
- bloom spreads that white over what is around it (a lit sign becomes a white block with a smear). A saturated color at a lower intensity still
115
- reads as light: its strongest channel carries the brightness, the others keep the hue, and bloom carries the halo. The numbers above are the
116
- examples' current values, not targets. Judge the result with the picture check of `threedog shot` or `threedog snap` at night: it names each
117
- glowing material and light that blows pixels out, with its current emissive and intensity and how much detail is lost under it, as a fact to
118
- weigh against what the game wants (some games want a blinding sign).
105
+ starts at daylight 0.3 (lamps with their own `dusk` start elsewhere): a starting value, not a rule. Judge it in shots at dusk.
106
+
107
+ **Headroom: why a glow turns into glare.** What reaches the tone curve is the emissive color times `emissiveIntensity`. A near-white color has no headroom: all three channels sit near 1, so
108
+ multiplied past 1 they clip to the same white, and bloom spreads that white around (a lit sign becomes a white block with a smear). A saturated color at a lower intensity still reads as light:
109
+ its strongest channel carries the brightness, the others keep the hue, and bloom carries the halo. Judge it with the picture check of `threedog shot` or `threedog snap` at night: it names each
110
+ glowing material and light that blows pixels out, as a fact to weigh against what the game wants (some games want a blinding sign).
119
111
  For the light those windows throw on the street, add a few `lightPool` sources above; a pool source's `glow` stand-in is for one object near one light.
120
112
 
121
113
  Top-down or side-view games whose light should spread over the floor and stop at walls (soft shadows, any number or shape of emissive
@@ -128,7 +120,7 @@ rules, `fonts` lists font asset names to load at start (the files sit in an asse
128
120
  ## 2. Using your own models instead of procedural ones
129
121
  Models are assets: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
130
122
  name to swap one:
131
- ```js
123
+ ```js fragment
132
124
  engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
133
125
  engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
134
126
  ```
@@ -155,7 +147,7 @@ GLB files from Blender are copied the same way and checked with recipe 46 sectio
155
147
 
156
148
  ## 2b. Wind, cloud shadows and season tint on your own materials
157
149
  The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
158
- ```js
150
+ ```js fragment
159
151
  import { applyEffects } from 'threedog';
160
152
  const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
161
153
  engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
@@ -169,17 +161,11 @@ A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#includ
169
161
  What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`), the chunk names and the engine GLSL functions you can call in your own shader: recipe 43.
170
162
 
171
163
  ## 3. When the engine gets a new picture value
172
- For engine developers. Hard rule 1: a module shows neutral gray until the game writes something. It makes its material with `neutralMaterial(what, params)` from
173
- `render/neutral.js` and hands it out through the doors of section 1a. A shader-side value is a `{ value }` in `.uniforms`; a value baked at build time is a module option, with
174
- one plain method when it can change at run time. There is no table of picture values to add to. A value that changes the world (a level, a size, a seed) is a module option only.
164
+ For engine developers: a module shows neutral gray until the game writes something. It makes its material with `neutralMaterial(what, params)` from `render/neutral.js` and hands it out through the
165
+ doors of section 1a. A shader-side value is a `{ value }` in `.uniforms`; a value baked at build time is a module option, with one plain method when it can change at run time. A value that changes the
166
+ world is a module option only. In engine code `npm run check` reports a material made directly (R14) and a non-gray fallback color (R39); games are not checked.
175
167
 
176
168
  ## 4. Verify
177
- - `npm run check`: R14 reports "creates a material directly" in engine code (games and examples are plain three.js and not checked), R35 a reach into the old look
178
- table, R39 a "non-gray fallback color".
179
169
  - Take screenshots only when the picture changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
180
170
  (images go to .threedog/shots/). Against a reference picture: `threedog picture compare` (recipe 60).
181
171
  - It must still run with no picture code: start once with `createEngine({ canvas })` (gray placeholders, one console note per missing piece).
182
-
183
- ## 5. Sounds and music (the game's, not the picture's)
184
- Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`. The engine plays
185
- nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and ducking: `recipes/31-audio.md`.
@@ -14,12 +14,12 @@
14
14
  Export glTF/GLB (tick "Custom Properties") into `art/models/` (create it if missing).
15
15
 
16
16
  ## 2. Compression
17
- `npm run assets` compresses to `public/optimized/<same name>.glb` (Meshopt geometry + KTX2 textures; needs the `ktx` command for textures) and points `assets.js` at the results (`/optimized/<name>.glb`). Object names and
17
+ `npm run assets -- optimize` compresses to `public/optimized/<same name>.glb` (Meshopt geometry + KTX2 textures, recipe 46 section 3) and points `assets.js` at the results (`/optimized/<name>.glb`). Object names and
18
18
  hierarchy are kept; faces are not reduced. Only changed files are processed; `-- --force` redoes everything.
19
19
 
20
20
  ## 3. Putting it in the game (main.js)
21
- ```js
22
- import { createEngine, presets, level, collision, followCamera, characters, interactions, dialogue, triggers, content, hlod } from 'threedog';
21
+ ```js fragment
22
+ import { presets, level, collision, followCamera, characters, interactions, dialogue, triggers, content, hlod } from 'threedog';
23
23
  engine.use(level({ url: '/models/town.glb' }), collision(), followCamera(), characters(), interactions({ ...presets.interactions.nearest }), dialogue(), triggers(), content(), hlod());
24
24
  engine.events.once('level:loaded', () => { // once: level:loaded fires again on every level change
25
25
  engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: engine.level.spawn });
@@ -30,11 +30,11 @@ engine.start();
30
30
  - Trigger zone data: write `{ 门口: { fromLevel: true, onEnter: { toast: '欢迎' } } }` in `<game>/content/triggers.js` (tag = the name after `trigger_`).
31
31
  - Content validation (`npm run check`) reads the level `.glb` files in `art/models/` and `public/models/` (needs `@gltf-transform/cli` installed):
32
32
  marker names used in content (`{ place: 'npc_店主' }`) need no description in `content/places.js`; a `fromLevel` trigger zone must have a
33
- `trigger_<tag>` node, and a node's `template` must exist in `content/templates.js`. Without a readable `.glb` the old rule holds (validation
34
- skips `fromLevel`, GAMEMAP notes "cannot be read statically"); `level.js` is only for code-built levels.
33
+ `trigger_<tag>` node, and a node's `template` must exist in `content/templates.js`. Without a readable `.glb`, validation
34
+ skips `fromLevel` and GAMEMAP says the markers cannot be read statically; `level.js` is only for code-built levels.
35
35
  - `npm run assets -- check` prints what the level will find in each model (spawns, colliders, triggers, template nodes, duplicate ids) plus
36
36
  material / color-space suspicions; `-- --json` gives the same as data.
37
- - `level:loaded` fires on every level change; for something done only once (creating the player) use `engine.events.once`. When the level changes, the
37
+ - When the level changes, the
38
38
  old level's trigger zones and the like are deleted automatically (`level.track`); NPCs, pickups and props placed by marker only lose their model
39
39
  while their data stays (with a zone), and are rebuilt when you return to this level; things that were picked up / deleted stay gone.
40
40
  - Get a marker in code: `engine.level.marker('marker_宝箱')?.position`, `engine.level.markersWith('npc_')`.
@@ -47,7 +47,7 @@ engine.start();
47
47
  Without `terrain()`, `vegetation()` grows on its own chunks over whatever provides the ground: the level, a code-built ground (`engine.setGround`), or
48
48
  the flat default. Rules read `engine.surface / slope / groundType`, so pick the level's surfaces by ground type (a mesh's `groundType` custom
49
49
  property, else its material name) with `rule.biomes`, and limit the scatter with `area`:
50
- ```js
50
+ ```js fragment
51
51
  engine.use(level({ url: '/models/town.glb' }), vegetation({ area: { min: [-80, -80], max: [80, 80] }, viewChunks: 3 }), collision());
52
52
  engine.vegetation.define('grass', { geometry: grassGeo, nearOnly: true, rule: { perChunk: 500, biomes: { lawn: 1 } } });
53
53
  engine.vegetation.define('tree', { model: oak, rule: { perChunk: 6, biomes: { lawn: 0.6, park: 1 }, maxSlope: 0.4, collider: 0.4 } });
@@ -58,8 +58,8 @@ re-places them; after changing a ground function behind the same provider call `
58
58
  sets `minHeight / maxHeight`. Content `vegetation` works the same way. With `terrain()` installed, `vegetation()` takes no options (density and view
59
59
  distance are terrain options). Rapier (`rigid()`) bodies collide with them too (cylinders from `engine.ground.forEachCollider`, gone when felled).
60
60
 
61
- Where a species grows is decided in the same `add()` call, with up to three parts (on a level, a code-built ground or terrain alike):
62
- ```js
61
+ Where a species grows is decided in the same `define()` call, with up to three parts (on a level, a code-built ground or terrain alike):
62
+ ```js fragment
63
63
  // rule: random scatter per chunk (above). positions: the game's own spots instead, [x, z] or [x, z, scale, yaw], planted at the ground height
64
64
  engine.vegetation.define('hedge', { model: hedge, positions: hedgeSpots /* [[x, z], ...] from your level data */, rule: { collider: 0.5 } });
65
65
  // densityMap: thins the rule's or the positions' result, 0..1 per spot -- a function of game data, or a gray image with the heightmap keys
@@ -71,9 +71,20 @@ are refused. The id of a listed plant is its index in the list. After what a den
71
71
  A game that wants every instance under its own code still builds a plain `THREE.InstancedMesh` and adds it to the scene.
72
72
 
73
73
  ## 5. Verify
74
- - `npm run assets` prints each file's size before and after compression (`-- --dry` only estimates); a browser 404 appears in `.threedog/errors.log` (asset load failure).
74
+ - `npm run assets -- optimize` prints each file's size before and after compression (`-- --dry` only estimates); a browser 404 appears in `.threedog/errors.log` (asset load failure).
75
75
  - `describe()`: `ready` is true and `loading` is empty; the player's coordinates are at the spawn point; `nearby` contains trigger zones
76
76
  (`kind: 'trigger'`) and NPCs.
77
77
  Text version: `npm run shot -- /your-page.html --describe-only`.
78
78
  - Collision: `engine.collision.walkable({ x, z })` is false inside a col_ box; ground: `engine.surface(x, z)` equals the step / floor height.
79
- - Related tests: `npm test -- 关卡`, `npm test -- "compressed assets"`, `npm test -- HLOD`, `npm test -- "vegetation ground"`.
79
+
80
+ ## 6. A level and a terrain together
81
+ Each takes the ground slot on its own, so installing both is refused. `compositeGround` holds the slot and asks one of them per point:
82
+ ```js fragment
83
+ engine.use(terrain({ part: true }), level({ scene: town, part: true }),
84
+ compositeGround({ parts: [{ of: 'level', region: (x, z) => x >= -30 && x <= 34 && Math.abs(z) <= 20, priority: 1 }, { of: 'terrain' }] }));
85
+ ```
86
+ - `region` is omitted (everywhere), `(x, z) => boolean`, or `{ volume }`, the same `{ contains({ x, y, z }) }` water and trigger zones take (asked at `y` 0). Higher `priority` wins where regions overlap.
87
+ - A region has no height: everything above and below a point belongs to one part. A cellar under a hillside goes in the level, and the level's mesh carries the ground over it too.
88
+ - The navmesh is built from the level parts only. Outside them paths use A*.
89
+ - Physics follows the regions: `rigid` gets terrain triangles only where the terrain answers, so a hill under a level's region is not solid. It is still drawn; lower it there or keep it out of sight.
90
+ - Water over a room: a character, `describe()` and floating bodies ask `waterAt` at their own height, so `addWaterBody({ query })` returning `null` below a lake's bed leaves the room under it dry. A plain `radius` or `halfWidth` body has no bottom and counts at every height.
@@ -27,14 +27,11 @@ function makeCar() {
27
27
  engine.events.on('engine:ready', () => {
28
28
  const { car, wheels } = makeCar();
29
29
  car.position.set(10, engine.surface(10, 0) + 1.5, 0); // place it slightly above the ground and let it drop
30
- const v = engine.rigid.addWheeled(car, { wheels, mass: 600, engineForce: 1200, camera: { distance: 14, height: 2 } });
30
+ const v = engine.rigid.addWheeled(car, { wheels, mass: 600, engineForce: 3000, camera: { distance: 14, height: 2 } });
31
31
  window.car = v; // handy for tests and the console
32
32
  });
33
33
  ```
34
- `addWheeled` options: `id` stable id (default `vehicle1`, `vehicle2`... in creation order; give one when that order varies), `wheels` (at least 3),
35
- `mass` in kg, `engineForce` throttle force, `brakeForce`, `maxSteer` in radians, `suspension: { rest, stiffness, damping }`,
36
- `seats` seat positions (the first drives, the rest ride; each exits on its own side), `hideDriver` (default true; false keeps riders visible on their seats: bikes, karts, open carts), `camera` camera distance/height while driving, `size` body collision box (by default the model's bounding box, wheels excluded),
37
- `friction` grip, `exitOffset` how far from the side of the body the player lands when exiting (meters, default 0.8).
34
+ Options: `../api/rigid.md` (VehicleOptions). `id` is the stable id saves use (default `vehicle1`, `vehicle2`... in creation order; give one when that order varies).
38
35
  Rigid bodies and vehicles do not change a model's shadow settings: set `mesh.castShadow = true` yourself if you want a shadow.
39
36
 
40
37
  ## 2. Boarding and driving
@@ -43,7 +40,7 @@ Rigid bodies and vehicles do not change a model's shadow settings: set `mesh.cas
43
40
  it doesn't compete with jumping) brakes, and without one the engine warns once; press E again to exit.
44
41
  - Saving: the player save records which vehicle the player is in (its `id`); loading an on-foot save while driving exits the vehicle first, and
45
42
  loading a driving save puts the player back in the car.
46
- - Code: `engine.player.enter(v)`, `engine.player.exit()`; `engine.player.vehicle` is the vehicle being driven (null when on foot); `v.driver` is who is driving, `v.passengers` who rides, `character.seat` the seat (0 drives; a second `enter` takes a free passenger seat, which does not steer).
43
+ - Code: `engine.player.enter(v)`, `engine.player.exit()` (takes the first walkable exit of `exitPosition(seat, n)`; none: answers `false` and the rider stays, `exit({ force: true })` always gets out); `engine.player.vehicle` is the vehicle being driven (null when on foot); `v.driver` is who is driving, `v.passengers` who rides, `character.seat` the seat (0 drives; a second `enter` takes a free passenger seat, which does not steer). Placing a rider (`placeAt`, a teleport, a write to its record's position) ends the ride, as `exit()` does; to take it along, move the vehicle.
47
44
  - NPCs/scripts driving: `v.drive(throttle -1..1, steer -1..1 (right is positive), brake 0-1)`; the last values set are used on every fixed step.
48
45
  - Events: `vehicle:enter`, `vehicle:exit` (`{ character, vehicle }`). Removal: `v.remove()` (anyone inside exits first; the model stays,
49
46
  `engine.remove(car)` deletes it).
@@ -57,27 +54,25 @@ This section covers every `engine.rigid` body (crates, balls, hulls, vehicles),
57
54
  ahead. The mover leaves dynamic bodies out of its own collision, so a body is pushed instead of stopping the player; how hard it resists is
58
55
  its `mass` and friction. A body that should stop the player is `{ fixed: true }` with `mover: 'rapier'` (that mover collides with fixed bodies).
59
56
  A puzzle reads the result from the body (`entry.body.translation()` in `onFixed`, or a trigger zone) and gives the body an `id`, so a save keeps
60
- where it was pushed. Test: `npm test -- "rigid push"` (both movers).
57
+ where it was pushed. Test: `threedog test "rigid push"` (both movers).
58
+
59
+ **Far bodies freeze.** On chunked terrain only the chunks within `rigid({ terrainRing })` of the player (default 1 ring) have terrain colliders. A
60
+ body outside them stops (`entry.enabled` is false, `describe().rigid.frozen` counts them) instead of falling through the ground, and goes on when
61
+ the player comes near. A body that must keep moving out there, such as a rival car on a long track, needs a larger ring: `rigid({ terrainRing: 6 })`;
62
+ each ring adds colliders. In dev the first moving body that freezes warns once.
61
63
 
62
64
  **Saves.** A body added with an `id` (`rigid.addBox(mesh, { id: rec.id })`; vehicles always have one) is saved with its pose, rotation,
63
65
  velocities and sleep, and a load gives that state back to the body with the same id, also when it is built after the load (a world presenter's
64
66
  `build`). A body without an id is not saved: after a load it is wherever its record (or your code) puts it, upright and at rest.
65
67
 
66
- **Joints** (hinges, doors, ropes, chains) are plain Rapier on engine bodies; the engine has no wrapper:
67
- ```js
68
- const R = engine.rigid, J = R.R.JointData;
69
- const post = R.addBox(postMesh, { fixed: true }), door = R.addBox(doorMesh, { mass: 8 });
70
- // hinge on the post's right edge, turning around Y; anchors are in each body's local space
71
- const hinge = R.world.createImpulseJoint(J.revolute({ x: 0.5, y: 0, z: 0 }, { x: -0.5, y: 0, z: 0 }, { x: 0, y: 1, z: 0 }), post.body, door.body, true);
72
- hinge.setLimits(-1.5, 1.5);
73
- // rope: the weight hangs at most 2 m below the hook
74
- R.world.createImpulseJoint(J.rope(2, { x: 0, y: -0.5, z: 0 }, { x: 0, y: 0.5, z: 0 }), hook.body, weight.body, true);
75
- ```
76
- `R.world` is the Rapier world and `entry.body` the Rapier body. newGame and a load rebuild the physics world (physics starts over like a fresh
68
+ **Joints** (hinges, doors, ropes, chains) are plain Rapier on engine bodies; the engine has no wrapper. `R.world` is the Rapier world and `entry.body` the Rapier body. newGame and a load rebuild the physics world (physics starts over like a fresh
77
69
  page) and free the old world's joints with it; the engine does not copy them. It emits `rigid:rebuilt` once the bodies are back, and that is
78
70
  where a game re-creates its joints, with the same code that made them:
79
- ```js
71
+ ```js fragment
72
+ const R = engine.rigid, J = R.rapier.JointData;
73
+ const post = R.addBox(postMesh, { fixed: true }), door = R.addBox(doorMesh, { mass: 8 });
80
74
  function hang() { // makes the joints; called after the bodies are added, and again after every rebuild
75
+ // hinge on the post's right edge, turning around Y; anchors are in each body's local space
81
76
  const h = R.world.createImpulseJoint(J.revolute({ x: 0.5, y: 0, z: 0 }, { x: -0.5, y: 0, z: 0 }, { x: 0, y: 1, z: 0 }), post.body, door.body, true);
82
77
  h.setLimits(-1.5, 1.5);
83
78
  R.world.createImpulseJoint(J.rope(2, { x: 0, y: -0.5, z: 0 }, { x: 0, y: 0.5, z: 0 }), hook.body, weight.body, true);
@@ -93,20 +88,45 @@ stay). Removing a body removes its joints (Rapier does that).
93
88
 
94
89
  **Determinism**, the one place this is stated (replay, `engine.step`, saves and net link here):
95
90
  - Same build, same machine, same inputs and the same number of fixed steps give bit-identical bodies, in a fresh page and at any frame rate.
96
- Physics only advances in fixed steps. Test: `npm test -- "rigid determinism"`: stacked boxes knocked over, a rolling ball, a driving car, the
91
+ Physics only advances in fixed steps. Test: `threedog test "rigid determinism"`: stacked boxes knocked over, a rolling ball, a driving car, the
97
92
  `mover: 'rapier'` player, two fresh pages, `frameEvery` 1 / 2 / 4.
98
93
  - A load restores each saved body exactly. Rapier's contact and warm-start caches and its solver order are not saved, so the run after a load
99
- is not bit-identical to the run that went on without the load. A toppling stack can end some centimetres away (measured: 0.24 m after 1.5 s).
100
- Bodies at rest stay at rest. Bit-identical continuation would need `world.takeSnapshot()`, which includes the terrain colliders (about 650 KB
101
- for the open world's 9 chunks) and is not used.
94
+ is not bit-identical to the run that went on without the load: a toppling stack can end some centimetres away. Bodies at rest stay at rest.
102
95
  - Across machines: the engine uses `@dimforge/rapier3d-compat`, which Rapier does not promise to be cross-platform deterministic (that is the
103
96
  separate `rapier3d-deterministic` build). Two machines can drift apart. The net module does not depend on matching physics: the host owns the
104
97
  state, and physics is not synced (each machine simulates its own bodies).
105
98
 
99
+ ## 3b. Ragdoll (experimental)
100
+
101
+ ```js fragment
102
+ const rd = engine.rigid.ragdoll(enemy, { impulse: [0, 150, -400], position: hit.point }); // a Character, NPC handle, id or skinned Object3D
103
+ engine.clock.after(4, () => rd.remove(), { channel: 'real' }); // back to animation where the body lies; a get-up clip is yours to play
104
+ ```
105
+ - **Skeletons.** Mixamo, Blender, Unreal, Bip01, VRM and Quaternius names are read by themselves. Otherwise name the parts: `{ bones: { lowerLegL: 'Shin_01' } }`; an unreadable skeleton throws, naming the missing parts.
106
+ Parts: `hips chest head upperArmL lowerArmL upperArmR lowerArmR upperLegL lowerLegL upperLegR lowerLegR`.
107
+ - **Limits** are `[min, max]` radians from the bind pose, per part or kind: `{ limits: { lowerLeg: { bend: [0, 2] } } }`. `bend` is forward (a knee: backward), then `side` and `twist`.
108
+ - **The bones stay plain three.js.** Each fixed step writes rotations, and hips' position only, so bones keep their length. Attach things with `character.onPose`. Once `rd.settled`, nothing is written and your bone writes stay. Hands, feet and bones between parts keep their pose.
109
+ - **One owner.** While limp, control is held on the layer `physics` (recipe 57), the animator writes nothing, the capsule is off, the camera follows the hips, `state` is `'ragdoll'` and `root` follows the body. `remove()` gives each back; a camera you moved stays moved. In a vehicle it throws: `exit()` first. `placeAt`, or a write to its record's position, carries the whole body there at rest, still limp. A mixer you made yourself is yours to stop.
110
+ - **Physics.** One rigid body per part (`rd.parts.head.body`; ray hits carry the bone in `object`), so buoyancy and ground freezing apply. Parts do not collide with each other, nor ragdolls with one another.
111
+ - **Not saved.** A load or new game ends it. A world rebuild without a load keeps it and re-creates its joints on `rigid:rebuilt`. Deleting the character frees everything.
112
+ - **Collision on three axes.** `engine.collider3d` is the slot rigid holds: `addSolid({ position, size | radius, rotation })` puts a fixed solid at any tilt, `overlap(position, radius)` and `sweep(from, to, radius)` answer for a flying mover or a path source. `engine.collision` does not know these solids, so walkers on the simple mover pass through. A game's own provider passes `modules/rigid/collider3d.contract.js` and takes the slot with `engine.use(mine(), { replaces: 'collider3d' })`.
113
+ - **Not a human.** The rule `ragdoll.graph` says what the parts are. The default `'humanoid'` is a physics helper that reads the 11 parts from bone names, not a choice of body for your game; every other body plan passes its own graph, one part without a parent, the rest hanging from it:
114
+ ```js
115
+ engine.mod('ragdoll.graph', { owner: 'game', id: 'wolf', set: {
116
+ body: { bone: 'Spine', mass: 20 },
117
+ head: { bone: 'Head', parent: 'body', mass: 4 },
118
+ legFL: { bone: 'FrontL', parent: 'body', kind: 'leg', forward: [0, 0, 1] },
119
+ tail: { bone: 'Tail1', parent: 'body', limits: { bend: [-1, 1], side: [-1, 1] } },
120
+ } });
121
+ ```
122
+ Without `id` it covers every body; a function `(facts, engine) => graph` picks per body; `false` makes `ragdoll()` return null.
123
+ - **Left out:** partial or blended ragdoll (an arm thrown by a hit while the rest animates); `remove()` cuts to the animation.
124
+
106
125
  ## 4. Verify
107
126
  - In a test (no real key presses): `engine.player.enter(car); engine.input.autopilot = { x: 0, y: 1 }; engine.step(3)`,
108
127
  then `describe().player.vehicle.speed` is above 0 and the car has moved; after `engine.player.exit()`, `engine.player.vehicle` is null and the
109
128
  player stands outside the door.
110
129
  - Vehicle speed is only in the object form `engine.describe().player.vehicle` (the player line of describeText does not show it);
111
130
  `describe().player.mover` and `grounded` are there too.
112
- - Related test: `npm test -- 载具` (test page in the engine repository: `packages/engine/tests/vehicle/`, with a complete car and steps).
131
+
132
+ A load seats a rider by vehicle id and seat. Your own vehicle joins with `engine.characters.addVehicle(boat)`, before or after the load.