threedog 0.5.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (750) hide show
  1. package/CHANGELOG.md +276 -1
  2. package/README.md +18 -13
  3. package/core/{Animator.js → assets/Animator.js} +28 -18
  4. package/core/{Assets.js → assets/Assets.js} +116 -61
  5. package/core/{Baked.js → assets/Baked.js} +16 -25
  6. package/core/assets/assetEntry.js +237 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +7 -6
  8. package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
  11. package/core/{assetReport.js → assets/assetReport.js} +9 -15
  12. package/core/{namedModel.js → assets/namedModel.js} +24 -16
  13. package/core/{Audio.js → audio/Audio.js} +27 -24
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +10 -10
  18. package/core/{Random.js → base/Random.js} +5 -4
  19. package/core/{easing.js → base/easing.js} +1 -1
  20. package/core/{errorCodes.js → base/errorCodes.js} +154 -139
  21. package/core/{errorHints.js → base/errorHints.js} +9 -10
  22. package/core/{errors.js → base/errors.js} +9 -9
  23. package/core/{events.generated.js → base/events.generated.js} +2 -0
  24. package/core/{math.js → base/math.js} +22 -4
  25. package/core/{params.js → base/params.js} +3 -4
  26. package/core/base/util.js +32 -0
  27. package/core/{validate.js → base/validate.js} +29 -8
  28. package/core/{Engine.js → engine/Engine.js} +112 -105
  29. package/core/{Loading.js → engine/Loading.js} +4 -2
  30. package/core/{copies.js → engine/copies.js} +4 -4
  31. package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
  32. package/core/{lifecycle.js → engine/lifecycle.js} +16 -16
  33. package/core/{loop.js → engine/loop.js} +80 -52
  34. package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
  35. package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
  36. package/core/{modules.js → engine/modules.js} +20 -17
  37. package/core/engine/page.js +125 -0
  38. package/core/{plugins.js → engine/plugins.js} +68 -103
  39. package/core/{services.js → engine/services.js} +47 -40
  40. package/core/{startup.js → engine/startup.js} +35 -35
  41. package/core/{Input.js → input/Input.js} +41 -27
  42. package/core/{inputContext.js → input/inputContext.js} +14 -5
  43. package/core/{inputPad.js → input/inputPad.js} +1 -1
  44. package/core/{inputPointer.js → input/inputPointer.js} +8 -2
  45. package/core/{inputTouch.js → input/inputTouch.js} +1 -1
  46. package/core/{Budget.js → inspect/Budget.js} +23 -22
  47. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
  48. package/core/{Describe.js → inspect/Describe.js} +33 -30
  49. package/core/{Inspect.js → inspect/Inspect.js} +14 -9
  50. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
  51. package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
  52. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  53. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
  54. package/core/inspect/UrlState.js +182 -0
  55. package/core/{catalog.js → inspect/catalog.js} +18 -5
  56. package/core/{checks.js → inspect/checks.js} +7 -5
  57. package/core/{debugView.js → inspect/debugView.js} +8 -8
  58. package/core/inspect/describeRender.js +148 -0
  59. package/core/{describeText.js → inspect/describeText.js} +17 -12
  60. package/core/inspect/geometryWatch.js +38 -0
  61. package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
  62. package/core/inspect/pictureWriters.js +342 -0
  63. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  64. package/core/{Ops.js → ops/Ops.js} +16 -11
  65. package/core/{control.js → ops/control.js} +13 -12
  66. package/core/ops/holds.js +139 -0
  67. package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
  68. package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
  69. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  70. package/core/{opsRun.js → ops/opsRun.js} +7 -4
  71. package/core/{owned.js → ops/owned.js} +37 -37
  72. package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
  73. package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
  74. package/core/{stacks.js → ops/stacks.js} +18 -20
  75. package/core/{wrap.js → ops/wrap.js} +8 -6
  76. package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
  77. package/core/{Saves.js → saves/Saves.js} +58 -36
  78. package/core/{saveApply.js → saves/saveApply.js} +13 -9
  79. package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
  80. package/core/{saveValues.js → saves/saveValues.js} +20 -3
  81. package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
  82. package/core/{session.js → saves/session.js} +31 -17
  83. package/core/{Rays.js → scene/Rays.js} +27 -24
  84. package/core/{Views.js → scene/Views.js} +15 -6
  85. package/core/{adaptive.js → scene/adaptive.js} +15 -8
  86. package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
  87. package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
  88. package/core/{gameLights.js → scene/gameLights.js} +24 -7
  89. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  90. package/core/{grid.js → scene/grid.js} +4 -4
  91. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  92. package/core/{ground.js → scene/ground.js} +9 -9
  93. package/core/{movement.js → scene/movement.js} +3 -3
  94. package/core/scene/pictureSlots.js +33 -0
  95. package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
  96. package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
  97. package/core/scene/stepPoses.js +55 -0
  98. package/core/{targeting.js → scene/targeting.js} +4 -5
  99. package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
  100. package/core/{thingOps.js → scene/thingOps.js} +4 -3
  101. package/core/{things.js → scene/things.js} +19 -6
  102. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  103. package/core/{tier.js → scene/tier.js} +1 -1
  104. package/core/scene/view.js +44 -0
  105. package/core/{Batching.js → stream/Batching.js} +85 -27
  106. package/core/{Stream.js → stream/Stream.js} +62 -33
  107. package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
  108. package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
  109. package/core/{scatter.js → stream/scatter.js} +2 -2
  110. package/core/{streamSources.js → stream/streamSources.js} +12 -7
  111. package/core/{Commits.js → threads/Commits.js} +6 -5
  112. package/core/{Jobs.js → threads/Jobs.js} +12 -10
  113. package/core/{Threads.js → threads/Threads.js} +16 -16
  114. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  115. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  116. package/core/{Clock.js → time/Clock.js} +17 -10
  117. package/core/{dayTime.js → time/dayTime.js} +5 -1
  118. package/core/{skip.js → time/skip.js} +18 -17
  119. package/core/{time.js → time/time.js} +18 -12
  120. package/core/{uiClock.js → time/uiClock.js} +4 -4
  121. package/docs/AI.md +70 -63
  122. package/docs/API.md +30 -29
  123. package/docs/CODEMAP.md +98 -223
  124. package/docs/COMMANDS.md +80 -69
  125. package/docs/CONVENTIONS.md +87 -41
  126. package/docs/MIGRATING-0.7.md +39 -0
  127. package/docs/MIGRATING-0.8.md +169 -0
  128. package/docs/THREE.md +100 -49
  129. package/docs/api/assets.md +17 -16
  130. package/docs/api/audio.md +8 -7
  131. package/docs/api/budget.md +8 -4
  132. package/docs/api/calendar.md +10 -11
  133. package/docs/api/cameraRig.md +29 -29
  134. package/docs/api/characters.md +26 -19
  135. package/docs/api/clock.md +1 -1
  136. package/docs/api/collision.md +14 -11
  137. package/docs/api/content.md +6 -6
  138. package/docs/api/dialogue.md +3 -3
  139. package/docs/api/engine.md +82 -53
  140. package/docs/api/events.md +5 -3
  141. package/docs/api/flow.md +1 -1
  142. package/docs/api/grids.md +9 -2
  143. package/docs/api/ground.md +4 -5
  144. package/docs/api/hud.md +4 -1
  145. package/docs/api/i18n.md +6 -6
  146. package/docs/api/input.md +10 -9
  147. package/docs/api/interactions.md +6 -4
  148. package/docs/api/inventory.md +10 -11
  149. package/docs/api/jobs.md +5 -5
  150. package/docs/api/level.md +7 -8
  151. package/docs/api/lightPool.md +2 -7
  152. package/docs/api/music.md +3 -3
  153. package/docs/api/nav.md +10 -10
  154. package/docs/api/occlusion.md +5 -0
  155. package/docs/api/openWorld.md +1 -1
  156. package/docs/api/particles.md +8 -5
  157. package/docs/api/photo.md +4 -2
  158. package/docs/api/pickups.md +7 -1
  159. package/docs/api/post.md +24 -5
  160. package/docs/api/quests.md +3 -3
  161. package/docs/api/rays.md +5 -7
  162. package/docs/api/rigid.md +27 -18
  163. package/docs/api/saves.md +8 -7
  164. package/docs/api/settings.md +9 -8
  165. package/docs/api/sky.md +17 -14
  166. package/docs/api/stream.md +7 -7
  167. package/docs/api/swarm.md +34 -0
  168. package/docs/api/terrain.md +17 -12
  169. package/docs/api/terrainDraw.md +12 -0
  170. package/docs/api/timeline.md +2 -2
  171. package/docs/api/tools.md +30 -26
  172. package/docs/api/triggers.md +2 -0
  173. package/docs/api/vars.md +1 -1
  174. package/docs/api/vegetation.md +11 -5
  175. package/docs/api/vegetationDraw.md +10 -0
  176. package/docs/api/water.md +7 -3
  177. package/docs/api/weather.md +11 -6
  178. package/docs/api/weatherDraw.md +10 -0
  179. package/docs/api/world.md +6 -6
  180. package/docs/recipes/01-new-game.md +38 -57
  181. package/docs/recipes/02-npc.md +19 -20
  182. package/docs/recipes/03-items-pickups.md +47 -42
  183. package/docs/recipes/04-quests.md +3 -4
  184. package/docs/recipes/05-props-bake.md +72 -66
  185. package/docs/recipes/06-clock-events.md +30 -21
  186. package/docs/recipes/07-flow-scenes-pause.md +21 -17
  187. package/docs/recipes/08-weather-sky.md +117 -75
  188. package/docs/recipes/09-materials-lights-models.md +171 -0
  189. package/docs/recipes/10-blender-level.md +6 -7
  190. package/docs/recipes/11-vehicles.md +33 -25
  191. package/docs/recipes/12-navmesh.md +9 -8
  192. package/docs/recipes/13-animation.md +50 -22
  193. package/docs/recipes/14-custom-module.md +20 -17
  194. package/docs/recipes/15-perf.md +52 -29
  195. package/docs/recipes/16-dev-bridge.md +47 -57
  196. package/docs/recipes/18-world.md +45 -30
  197. package/docs/recipes/19-shooting-picking.md +11 -7
  198. package/docs/recipes/20-content-actions-save.md +36 -37
  199. package/docs/recipes/21-camera.md +41 -8
  200. package/docs/recipes/22-shop-gold.md +0 -4
  201. package/docs/recipes/23-ops.md +11 -11
  202. package/docs/recipes/26-ui-parts.md +56 -22
  203. package/docs/recipes/27-net.md +0 -2
  204. package/docs/recipes/28-terrain.md +126 -30
  205. package/docs/recipes/29-grid.md +16 -7
  206. package/docs/recipes/30-templates.md +62 -21
  207. package/docs/recipes/31-audio.md +9 -9
  208. package/docs/recipes/32-action-game.md +32 -9
  209. package/docs/recipes/33-stream-sources.md +2 -2
  210. package/docs/recipes/34-environment-lighting.md +164 -52
  211. package/docs/recipes/35-picture-from-reference.md +140 -0
  212. package/docs/recipes/36-ground-plants.md +105 -0
  213. package/docs/recipes/40-scene.md +105 -30
  214. package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
  215. package/docs/recipes/44-water-weather-hooks.md +196 -0
  216. package/docs/recipes/45-cascaded-shadows.md +145 -25
  217. package/docs/recipes/46-blender-art-route.md +21 -25
  218. package/docs/recipes/49-game-module-contract.md +5 -5
  219. package/docs/recipes/50-own-renderer.md +3 -3
  220. package/docs/recipes/52-around-the-picture.md +137 -0
  221. package/docs/recipes/53-ground-up-close.md +65 -28
  222. package/docs/recipes/55-mods-time-wrap.md +25 -17
  223. package/docs/recipes/56-webgpu-tsl.md +73 -28
  224. package/docs/recipes/57-control.md +47 -1
  225. package/docs/recipes/58-input.md +3 -0
  226. package/docs/recipes/59-depth-post-effects.md +5 -5
  227. package/docs/recipes/60-judge-the-picture.md +47 -27
  228. package/docs/recipes/61-deploy.md +27 -0
  229. package/docs/recipes/62-picture-code.md +276 -0
  230. package/docs/recipes/63-third-person-start.md +90 -0
  231. package/docs/recipes/64-particles.md +35 -0
  232. package/docs/recipes/65-swarm.md +140 -0
  233. package/examples/action/.threedog/content-index.json +1 -1
  234. package/examples/action/GAMEMAP.md +9 -7
  235. package/examples/action/main.js +5 -4
  236. package/examples/action/models.js +12 -14
  237. package/examples/action/picture/index.js +13 -0
  238. package/examples/action/picture/lights.js +35 -0
  239. package/examples/action/picture/materials.js +8 -0
  240. package/examples/action/picture/palette.js +33 -0
  241. package/examples/perf-island/.threedog/content-index.json +1 -0
  242. package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
  243. package/examples/{sheepisland → perf-island}/assets.js +2 -2
  244. package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
  245. package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
  246. package/examples/{sheepisland → perf-island}/main.js +22 -16
  247. package/examples/{sheepisland/style → perf-island}/models.js +13 -24
  248. package/examples/{sheepisland → perf-island}/params.js +1 -1
  249. package/examples/perf-island/picture/index.js +20 -0
  250. package/examples/perf-island/picture/lights.js +34 -0
  251. package/examples/perf-island/picture/materials.js +61 -0
  252. package/examples/perf-island/picture/palette.js +60 -0
  253. package/examples/perf-island/picture/sky.js +20 -0
  254. package/examples/{sheepisland → perf-island}/views.js +1 -1
  255. package/examples/plain-picture/.threedog/content-index.json +1 -0
  256. package/examples/plain-picture/GAMEMAP.md +91 -0
  257. package/examples/plain-picture/main.js +48 -0
  258. package/examples/plain-picture/picture/index.js +21 -0
  259. package/examples/plain-picture/picture/lights.js +54 -0
  260. package/examples/plain-picture/picture/materials.js +24 -0
  261. package/examples/plain-picture/picture/palette.js +16 -0
  262. package/examples/plain-picture/picture/sky.js +37 -0
  263. package/examples/pullable.json +31 -9
  264. package/examples/rc2d/GAMEMAP.md +10 -4
  265. package/examples/rc2d/README.md +11 -6
  266. package/examples/rc2d/main.js +26 -36
  267. package/examples/rc2d/picture/index.js +18 -0
  268. package/examples/rc2d/picture/lights.js +11 -0
  269. package/examples/rc2d/picture/materials.js +18 -0
  270. package/examples/rc2d/picture/palette.js +15 -0
  271. package/examples/rc2d/picture/post.js +11 -0
  272. package/examples/rc2d/rc2d.js +18 -28
  273. package/examples/styletest/.threedog/content-index.json +1 -1
  274. package/examples/styletest/GAMEMAP.md +15 -10
  275. package/examples/styletest/main.js +20 -30
  276. package/examples/styletest/models.js +29 -29
  277. package/examples/styletest/params.js +1 -4
  278. package/examples/styletest/picture/env.js +38 -0
  279. package/examples/styletest/picture/index.js +16 -0
  280. package/examples/styletest/picture/lights.js +9 -0
  281. package/examples/styletest/picture/materials.js +28 -0
  282. package/examples/styletest/picture/palette.js +22 -0
  283. package/examples/techniques/contact-shadows/README.md +22 -23
  284. package/examples/techniques/contact-shadows/contactShadows.js +32 -16
  285. package/examples/techniques/contact-shadows/main.js +20 -18
  286. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  287. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  288. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  289. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  290. package/examples/techniques/day-night-grade/README.md +13 -16
  291. package/examples/techniques/day-night-grade/main.js +15 -25
  292. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  293. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  294. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  295. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  296. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  297. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  298. package/examples/techniques/interior-light/README.md +16 -13
  299. package/examples/techniques/interior-light/interiorLight.js +19 -17
  300. package/examples/techniques/interior-light/main.js +31 -68
  301. package/examples/techniques/interior-light/picture/index.js +24 -0
  302. package/examples/techniques/interior-light/picture/lights.js +52 -0
  303. package/examples/techniques/interior-light/picture/materials.js +13 -0
  304. package/examples/techniques/interior-light/picture/palette.js +32 -0
  305. package/examples/techniques/interior-light/picture/sky.js +40 -0
  306. package/examples/techniques/modular-building/README.md +8 -6
  307. package/examples/techniques/modular-building/kit.js +2 -2
  308. package/examples/techniques/modular-building/main.js +9 -17
  309. package/examples/techniques/modular-building/picture/index.js +17 -0
  310. package/examples/techniques/modular-building/picture/lights.js +26 -0
  311. package/examples/techniques/modular-building/picture/materials.js +13 -0
  312. package/examples/techniques/modular-building/picture/palette.js +23 -0
  313. package/examples/techniques/night-lights/README.md +15 -14
  314. package/examples/techniques/night-lights/main.js +20 -43
  315. package/examples/techniques/night-lights/nightLights.js +25 -21
  316. package/examples/techniques/night-lights/picture/index.js +18 -0
  317. package/examples/techniques/night-lights/picture/lights.js +44 -0
  318. package/examples/techniques/night-lights/picture/materials.js +15 -0
  319. package/examples/techniques/night-lights/picture/palette.js +34 -0
  320. package/examples/techniques/night-lights/picture/post.js +9 -0
  321. package/examples/techniques/night-lights/picture/sky.js +36 -0
  322. package/examples/techniques/outlines-and-rim/README.md +2 -2
  323. package/examples/techniques/outlines-and-rim/main.js +15 -38
  324. package/examples/techniques/outlines-and-rim/outlines.js +3 -3
  325. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  326. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  327. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  328. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  329. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  330. package/examples/techniques/procedural-animation/README.md +6 -4
  331. package/examples/techniques/procedural-animation/main.js +9 -7
  332. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  333. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  334. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  335. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  336. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  337. package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
  338. package/examples/techniques/procedural-surface/README.md +2 -0
  339. package/examples/techniques/procedural-surface/main.js +17 -55
  340. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  341. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  342. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  343. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  344. package/examples/techniques/stylized-shading/README.md +13 -14
  345. package/examples/techniques/stylized-shading/main.js +11 -42
  346. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  347. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  348. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  349. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  350. package/examples/techniques/stylized-shading/shading.js +2 -2
  351. package/examples/techniques/sun-and-key-light/README.md +20 -22
  352. package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
  353. package/examples/techniques/sun-and-key-light/main.js +19 -63
  354. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  355. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  356. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  357. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  358. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  359. package/examples/techniques/three-looks/README.md +21 -0
  360. package/examples/techniques/three-looks/main.js +58 -0
  361. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  362. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  363. package/examples/techniques/three-looks/picture/comic.js +27 -0
  364. package/examples/techniques/three-looks/picture/index.js +14 -0
  365. package/examples/techniques/three-looks/picture/sun.js +23 -0
  366. package/examples/techniques/wet-road/README.md +7 -4
  367. package/examples/techniques/wet-road/main.js +18 -38
  368. package/examples/techniques/wet-road/picture/index.js +17 -0
  369. package/examples/techniques/wet-road/picture/lights.js +57 -0
  370. package/examples/techniques/wet-road/picture/materials.js +16 -0
  371. package/examples/techniques/wet-road/picture/palette.js +24 -0
  372. package/examples/techniques/wet-road/picture/sky.js +46 -0
  373. package/examples/webgpu-tsl/GAMEMAP.md +10 -4
  374. package/examples/webgpu-tsl/README.md +13 -10
  375. package/examples/webgpu-tsl/main.js +30 -7
  376. package/examples/webgpu-tsl/picture/index.js +18 -0
  377. package/examples/webgpu-tsl/picture/lights.js +25 -0
  378. package/examples/webgpu-tsl/picture/materials.js +36 -0
  379. package/examples/webgpu-tsl/picture/palette.js +23 -0
  380. package/examples/webgpu-tsl/picture/post.js +16 -0
  381. package/examples/webgpu-tsl/picture/sky.js +30 -0
  382. package/examples/world/.threedog/content-index.json +1 -1
  383. package/examples/world/GAMEMAP.md +16 -12
  384. package/examples/world/art/humanoid.js +9 -13
  385. package/examples/world/art/index.js +2 -2
  386. package/examples/world/art/models.js +3 -4
  387. package/examples/world/art/shapes.js +2 -2
  388. package/examples/world/assets.js +2 -2
  389. package/examples/world/content/audio.js +1 -1
  390. package/examples/world/content/items.js +1 -1
  391. package/examples/world/content/props.js +1 -1
  392. package/examples/world/content/templates.js +1 -1
  393. package/examples/world/content/vegetation.js +1 -1
  394. package/examples/world/main.js +10 -10
  395. package/examples/world/models.js +17 -7
  396. package/examples/world/picture/index.js +20 -0
  397. package/examples/world/picture/lights.js +41 -0
  398. package/examples/world/picture/materials.js +34 -0
  399. package/examples/world/picture/palette.js +74 -0
  400. package/examples/world/picture/post.js +9 -0
  401. package/examples/world/picture/sky.js +39 -0
  402. package/index.d.ts +14 -22
  403. package/index.js +36 -36
  404. package/llms.txt +19 -21
  405. package/modules/ambience/Ambience.js +12 -9
  406. package/modules/calendar/Calendar.js +20 -20
  407. package/modules/calendar/index.js +14 -13
  408. package/modules/calendar/schedule.js +11 -6
  409. package/modules/calendar/seasons.js +7 -7
  410. package/modules/camera/FirstPersonCamera.js +2 -2
  411. package/modules/camera/FixedCamera.js +14 -15
  412. package/modules/camera/FollowCamera.js +4 -4
  413. package/modules/camera/RtsCamera.js +11 -11
  414. package/modules/camera/common.js +51 -25
  415. package/modules/camera/contract.js +1 -0
  416. package/modules/camera/projection.js +2 -2
  417. package/modules/characters/Character.js +47 -39
  418. package/modules/characters/NPC.js +30 -22
  419. package/modules/characters/assetModel.js +18 -13
  420. package/modules/characters/astar.js +7 -5
  421. package/modules/characters/behaviors.js +4 -5
  422. package/modules/characters/contract.js +2 -2
  423. package/modules/characters/index.js +172 -193
  424. package/modules/characters/moveHelpers.js +14 -3
  425. package/modules/characters/movers/common.js +22 -15
  426. package/modules/characters/movers/manual.js +4 -1
  427. package/modules/characters/movers/rapier.js +7 -6
  428. package/modules/characters/movers/simple.js +3 -3
  429. package/modules/characters/movers/support.js +32 -18
  430. package/modules/characters/npcAvoid.js +4 -4
  431. package/modules/characters/npcSim.js +28 -18
  432. package/modules/characters/npcView.js +6 -5
  433. package/modules/characters/pathAsync.js +12 -10
  434. package/modules/characters/pathWorker.js +1 -1
  435. package/modules/characters/player.js +108 -0
  436. package/modules/characters/playerStrings.js +2 -2
  437. package/modules/characters/proceduralRig.js +19 -5
  438. package/modules/characters/useModel.js +5 -5
  439. package/modules/characters/walkTo.js +11 -17
  440. package/modules/collision/Collision.js +30 -22
  441. package/modules/collision/contract.js +15 -0
  442. package/modules/content/explain.js +1 -2
  443. package/modules/content/fields.js +24 -3
  444. package/modules/content/ids.js +2 -2
  445. package/modules/content/index.js +68 -98
  446. package/modules/content/loader.js +14 -17
  447. package/modules/content/markers.js +25 -0
  448. package/modules/content/models.js +66 -18
  449. package/modules/content/packs.js +3 -3
  450. package/modules/content/parts.js +2 -2
  451. package/modules/content/places.js +35 -0
  452. package/modules/content/props.js +19 -14
  453. package/modules/content/rules.js +34 -22
  454. package/modules/content/stages.js +7 -7
  455. package/modules/content/templates.js +24 -22
  456. package/modules/content/words.js +34 -0
  457. package/modules/debug/DebugPanel.js +10 -43
  458. package/modules/flow/contract.js +1 -1
  459. package/modules/flow/index.js +11 -7
  460. package/modules/gameplay/Container.js +12 -11
  461. package/modules/gameplay/Containers.js +14 -5
  462. package/modules/gameplay/Dialogue.js +13 -11
  463. package/modules/gameplay/Interactions.js +115 -27
  464. package/modules/gameplay/Inventory.js +11 -12
  465. package/modules/gameplay/Quests.js +16 -9
  466. package/modules/gameplay/boxOps.js +1 -1
  467. package/modules/gameplay/dialogueBox.js +1 -1
  468. package/modules/gameplay/dialogueBubbles.js +4 -5
  469. package/modules/gameplay/interactionPrompt.js +1 -1
  470. package/modules/gameplay/interactions.contract.js +1 -1
  471. package/modules/gameplay/inventoryOps.js +2 -3
  472. package/modules/gameplay/pickups.js +81 -44
  473. package/modules/gameplay/questLog.js +2 -2
  474. package/modules/gameplay/questSave.js +3 -3
  475. package/modules/grid/Grid.js +1 -1
  476. package/modules/grid/Layer.js +16 -3
  477. package/modules/grid/index.js +47 -19
  478. package/modules/grid/preview.js +29 -20
  479. package/modules/grid/tiles.js +19 -23
  480. package/modules/hlod/index.js +38 -55
  481. package/modules/hud/index.js +27 -8
  482. package/modules/hud/parts.js +13 -11
  483. package/modules/level/contract.js +16 -0
  484. package/modules/level/heightfield.js +12 -10
  485. package/modules/level/index.js +48 -152
  486. package/modules/level/load.js +79 -0
  487. package/modules/level/meshes.js +65 -0
  488. package/modules/level/nodes.js +6 -7
  489. package/modules/lights/index.js +34 -183
  490. package/modules/lights/slots.js +93 -0
  491. package/modules/lights/sources.js +88 -0
  492. package/modules/music/Music.js +31 -27
  493. package/modules/music/rules.js +1 -1
  494. package/modules/nav/contract.js +14 -0
  495. package/modules/nav/index.js +11 -10
  496. package/modules/net/Client.js +7 -7
  497. package/modules/net/Host.js +7 -7
  498. package/modules/net/Net.js +1 -1
  499. package/modules/net/index.js +5 -4
  500. package/modules/net/sync.js +2 -2
  501. package/modules/net/transports.js +2 -2
  502. package/modules/particles/Particles.js +49 -25
  503. package/modules/particles/effect.js +27 -10
  504. package/modules/particles/shaders.js +2 -1
  505. package/modules/photo/Photo.js +26 -27
  506. package/modules/rigid/RigidBodies.js +66 -43
  507. package/modules/rigid/Vehicles.js +2 -3
  508. package/modules/rigid/ragdoll.js +287 -0
  509. package/modules/rigid/ragdollBones.js +159 -0
  510. package/modules/rigid/sync.js +6 -6
  511. package/modules/settings/Settings.js +114 -45
  512. package/modules/settings/apply.js +10 -10
  513. package/modules/settings/sections.js +16 -14
  514. package/modules/settings/strings.js +1 -1
  515. package/modules/settings/view.js +3 -3
  516. package/modules/sky/Sky.js +125 -103
  517. package/modules/sky/clouds.js +22 -23
  518. package/modules/sky/dome.js +113 -0
  519. package/modules/sky/domeLayers.js +13 -13
  520. package/modules/sky/environment.js +47 -171
  521. package/modules/sky/fog.js +5 -180
  522. package/modules/sky/frame.js +42 -97
  523. package/modules/sky/season.js +9 -3
  524. package/modules/sky/shader.js +49 -44
  525. package/modules/sky/skyModule.js +25 -35
  526. package/modules/sky/tint.js +9 -11
  527. package/modules/swarm/Swarm.js +346 -0
  528. package/modules/swarm/draw.js +68 -0
  529. package/modules/swarm/grid.js +63 -0
  530. package/modules/terrain/ChunkManager.js +97 -62
  531. package/modules/terrain/chunkQueries.js +7 -24
  532. package/modules/terrain/chunkWorker.js +1 -1
  533. package/modules/terrain/draw.js +157 -0
  534. package/modules/terrain/index.js +60 -88
  535. package/modules/terrain/terrainColorMap.js +6 -3
  536. package/modules/terrain/terrainDefaults.js +4 -3
  537. package/modules/terrain/terrainEdit.js +32 -27
  538. package/modules/terrain/terrainGen.js +19 -14
  539. package/modules/terrain/terrainIsland.js +2 -2
  540. package/modules/terrain/terrainMesh.js +7 -6
  541. package/modules/terrain/terrainShape.js +8 -10
  542. package/modules/terrain/terrainShapeMain.js +3 -3
  543. package/modules/timeline/Timeline.js +27 -19
  544. package/modules/timeline/Tween.js +6 -6
  545. package/modules/timeline/shots.js +5 -7
  546. package/modules/triggers/index.js +19 -15
  547. package/modules/vegetation/Vegetation.js +87 -39
  548. package/modules/vegetation/densityMap.js +4 -7
  549. package/modules/vegetation/draw.js +196 -0
  550. package/modules/vegetation/groundChunks.js +11 -31
  551. package/modules/vegetation/index.js +18 -16
  552. package/modules/vegetation/modelGeometry.js +3 -6
  553. package/modules/vegetation/nearFade.js +1 -1
  554. package/modules/water/Water.js +140 -93
  555. package/modules/water/surface.js +56 -56
  556. package/modules/weather/Weather.js +84 -38
  557. package/modules/weather/particles.js +18 -10
  558. package/modules/weather/shaders.js +1 -1
  559. package/modules/weather/weatherDraw.js +145 -0
  560. package/modules/world/World.js +10 -10
  561. package/modules/world/explain.js +1 -1
  562. package/modules/world/index.js +18 -12
  563. package/modules/world/persist.js +73 -25
  564. package/modules/world/pos.js +4 -4
  565. package/modules/world/records.js +28 -8
  566. package/modules/world/sim.js +4 -4
  567. package/modules/world/state.js +12 -5
  568. package/modules/world/thingSource.js +4 -2
  569. package/modules/world/views.js +12 -10
  570. package/package.json +44 -8
  571. package/presets.js +3 -5
  572. package/render/PostFX.js +233 -63
  573. package/render/backend.js +72 -32
  574. package/render/cascades.js +200 -0
  575. package/render/cascades.tsl.js +93 -0
  576. package/render/daylight.js +56 -0
  577. package/render/detail.js +13 -12
  578. package/render/effects.js +60 -42
  579. package/render/fuse.js +3 -3
  580. package/render/fx/cel.tsl.js +42 -0
  581. package/render/fx/cloudShadow.tsl.js +3 -3
  582. package/render/fx/detail.tsl.js +1 -1
  583. package/render/fx/index.js +10 -13
  584. package/render/fx/library.tsl.js +11 -0
  585. package/render/fx/lighting.tsl.js +2 -1
  586. package/render/fx/nodeErrors.tsl.js +2 -2
  587. package/render/fx/objectOrigin.tsl.js +1 -2
  588. package/render/fx/patchNodes.tsl.js +6 -16
  589. package/render/fx/postWebGPU.tsl.js +55 -28
  590. package/render/fx/sky.tsl.js +34 -109
  591. package/render/fx/uniforms.tsl.js +4 -4
  592. package/render/fx/water.tsl.js +1 -1
  593. package/render/fx/wind.tsl.js +1 -1
  594. package/render/fxNumbers.js +3 -0
  595. package/render/layers.js +14 -0
  596. package/render/lighting.js +11 -8
  597. package/render/lightmap.js +142 -0
  598. package/render/lights.js +26 -204
  599. package/render/lit.js +24 -0
  600. package/render/materials.js +47 -162
  601. package/render/mergeCommon.js +22 -0
  602. package/render/modeling.js +2 -2
  603. package/render/neutral.js +23 -0
  604. package/render/occlusion.js +200 -0
  605. package/render/ownFrame.js +5 -5
  606. package/render/patches.js +46 -41
  607. package/render/postWebGL.js +19 -9
  608. package/render/probes.js +182 -128
  609. package/render/recordSweep.js +117 -0
  610. package/render/shaderErrors.js +10 -9
  611. package/render/shadowCache.tsl.js +107 -0
  612. package/render/shadowTypes.js +9 -0
  613. package/render/shadows.js +451 -0
  614. package/render/slots.js +11 -11
  615. package/render/terms.js +63 -113
  616. package/render/uniformDecl.js +2 -2
  617. package/types/core.d.ts +489 -405
  618. package/types/gameplay.d.ts +225 -114
  619. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
  620. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  621. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  622. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
  623. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  624. package/types/generated/core/engine/page.d.ts +24 -0
  625. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
  626. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  627. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
  628. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
  629. package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
  630. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
  631. package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
  632. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  633. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
  634. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  635. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
  636. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  637. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  638. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  639. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  640. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  641. package/types/generated/modules/grid/Layer.d.ts +9 -1
  642. package/types/generated/modules/grid/index.d.ts +32 -8
  643. package/types/generated/modules/music/Music.d.ts +7 -5
  644. package/types/generated/modules/particles/Particles.d.ts +14 -7
  645. package/types/generated/modules/sky/Sky.d.ts +101 -23
  646. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  647. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  648. package/types/generated/modules/timeline/Timeline.d.ts +2 -1
  649. package/types/generated/modules/water/Water.d.ts +51 -3
  650. package/types/generated/modules/weather/Weather.d.ts +44 -10
  651. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  652. package/types/generated/modules/world/World.d.ts +7 -5
  653. package/types/generated/render/PostFX.d.ts +69 -20
  654. package/types/generated/render/lighting.d.ts +29 -0
  655. package/types/generated/render/materials.d.ts +20 -44
  656. package/types/generated/render/occlusion.d.ts +22 -0
  657. package/types/generated/render/patches.d.ts +1 -0
  658. package/types/generated/ui/Focus.d.ts +1 -0
  659. package/types/generated/ui/UI.d.ts +1 -0
  660. package/types/nav.d.ts +11 -11
  661. package/types/physics.d.ts +104 -73
  662. package/types/tsl.d.ts +45 -4
  663. package/types/world.d.ts +372 -86
  664. package/ui/Focus.js +21 -10
  665. package/ui/LoadingScreen.js +2 -2
  666. package/ui/Parts.js +12 -7
  667. package/ui/UI.js +17 -17
  668. package/ui/cursor.js +1 -1
  669. package/ui/defaults.js +3 -2
  670. package/ui/theme.js +36 -28
  671. package/ui/touchPart.js +1 -1
  672. package/core/UrlState.js +0 -110
  673. package/core/assetEntry.js +0 -106
  674. package/core/describeRender.js +0 -71
  675. package/core/holds.js +0 -134
  676. package/core/look/coreParts.js +0 -219
  677. package/core/look/part.js +0 -253
  678. package/core/look/points.js +0 -255
  679. package/core/look/report.js +0 -96
  680. package/core/look/shadowPart.js +0 -63
  681. package/core/look/state.js +0 -45
  682. package/core/look/write.js +0 -70
  683. package/core/page.js +0 -79
  684. package/core/shadowTypes.js +0 -16
  685. package/core/styleParts.js +0 -114
  686. package/core/util.js +0 -17
  687. package/docs/MIGRATING-0.3.md +0 -248
  688. package/docs/MIGRATING-0.4.md +0 -228
  689. package/docs/MIGRATING-0.5.md +0 -68
  690. package/docs/PERF.md +0 -245
  691. package/docs/api/style.md +0 -136
  692. package/docs/api/terrainLook.md +0 -10
  693. package/docs/api/vegetationLook.md +0 -10
  694. package/docs/api/weatherLook.md +0 -10
  695. package/docs/recipes/09-style.md +0 -218
  696. package/docs/recipes/35-style-from-reference.md +0 -153
  697. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  698. package/docs/recipes/37-terrain-look-hooks.md +0 -119
  699. package/docs/recipes/38-environment-look-hooks.md +0 -99
  700. package/docs/recipes/41-thing-registry.md +0 -97
  701. package/docs/recipes/42-terrain-shape.md +0 -64
  702. package/docs/recipes/44-water-weather-look-hooks.md +0 -144
  703. package/docs/recipes/47-island-snow-backdrop.md +0 -45
  704. package/docs/recipes/48-make-material.md +0 -75
  705. package/docs/recipes/52-look.md +0 -282
  706. package/docs/recipes/54-three-idioms.md +0 -88
  707. package/examples/action/look.js +0 -5
  708. package/examples/sheepisland/.threedog/content-index.json +0 -1
  709. package/examples/sheepisland/style/index.js +0 -79
  710. package/examples/styletest/look.js +0 -11
  711. package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
  712. package/examples/webgpu-tsl/tslScene.js +0 -75
  713. package/examples/world/style/index.js +0 -61
  714. package/examples/world/style/plugins/10-bloom.js +0 -5
  715. package/modules/sky/cascades.js +0 -186
  716. package/modules/sky/cascades.tsl.js +0 -82
  717. package/modules/sky/look.js +0 -54
  718. package/modules/sky/lookFog.js +0 -76
  719. package/modules/sky/lookShadow.js +0 -62
  720. package/modules/sky/lookSky.js +0 -169
  721. package/modules/sky/shadow.js +0 -98
  722. package/modules/terrain/look.js +0 -83
  723. package/modules/terrain/lookGround.js +0 -66
  724. package/modules/vegetation/look.js +0 -119
  725. package/modules/vegetation/lookWind.js +0 -98
  726. package/modules/water/look.js +0 -91
  727. package/modules/water/surfaceDefaults.js +0 -3
  728. package/modules/weather/look.js +0 -74
  729. package/modules/weather/weatherLook.js +0 -135
  730. package/render/lookGlow.js +0 -139
  731. package/render/lookSurface.js +0 -224
  732. package/render/postLook.js +0 -164
  733. package/render/surface.js +0 -105
  734. package/types/generated/core/page.d.ts +0 -18
  735. package/types/generated/modules/weather/weatherLook.d.ts +0 -12
  736. package/types/style.d.ts +0 -671
  737. /package/core/{Vars.js → base/Vars.js} +0 -0
  738. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  739. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  740. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  741. /package/core/{actor.js → ops/actor.js} +0 -0
  742. /package/core/{opsFail.js → ops/opsFail.js} +0 -0
  743. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  744. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  745. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  746. /package/core/{cells.js → stream/cells.js} +0 -0
  747. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  748. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  749. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  750. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
package/docs/api/vars.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # engine.vars (Vars) — engine.vars: story flags and counters (autosaved)
2
2
 
3
3
  - `vars.flag(key: string) → any` — Read a flag
4
- - `vars.setFlag(key: string, value?: any)` — Set a flag (default true)
4
+ - `vars.setFlag(key: string, value?: any)` — (experimental) Set a flag (default true)
5
5
  - `vars.counter(key: string) → number` — Read a counter (0 if none)
6
6
  - `vars.bump(key: string, n?: number) → number` — Counter +n (default 1), returns the new value
7
7
  - Properties:
@@ -10,14 +10,20 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
10
10
  - `seed?: number` Placement seed, default 1
11
11
 
12
12
  ## Methods and properties
13
- - `vegetation.view(hooks: { species?, change?, ring?, show?, drop? }) → { remove(): void }` — Draw the plants: the hooks a look that replaces 'vegetation-look' uses. species(sp): defined or defined again (sp.source = the define() options); change(c, name): c.plants[name] placed, replaced or gone, or c.hidden[name] (felled slots) changed; ring(c, ring): LOD ring; show(c, visible); drop(c): released. What is already there is replayed at once. Returns { remove() } (ctx.track it). Example: `ctx.track(engine.vegetation.view({ change(c, name) { draw(c, c.plants[name]) }, drop(c) { undraw(c) } }))`
13
+ - `vegetation.sway(spec: string | { glsl?, tsl?, uniforms? } | null)` — Replace the sway shape of every species whose wind is a number, planted ones too; a species with its own wind object keeps it. null gives the built-in sway back. GLSL defines void threedogWind(inout vec3 transformed, vec3 ip, vec3 position); tsl: (ctx) => the moved object-space position
14
+ - `vegetation.color(spec: string | { glsl?, tsl?, uniforms?, pars? } | null)` — Code in the 'color' slot of every species' material, planted ones too (diffuseColor is yours); tsl: (ctx) => vec4 from ctx.color; null takes it off
15
+ - `vegetation.view(hooks: { species?, change?, ring?, show?, drop? }) → { remove(): void }` — Draw the plants: the hooks a draw part that replaces 'vegetation-draw' uses. species(sp): defined or defined again (sp.source = the define() options); change(c, name): c.plants[name] placed, replaced or gone, or c.hidden[name] (felled slots) changed; ring(c, ring): LOD ring; show(c, visible); drop(c): released. What is already there is replayed at once. Returns { remove() } (ctx.track it). Example: `ctx.track(engine.vegetation.view({ change(c, name) { draw(c, c.plants[name]) }, drop(c) { undraw(c) } }))`
14
16
  - `vegetation.rebuild()` — Place every chunk again: after changing the ground behind the same provider (a ground function reading game state). A new setGround or level is followed automatically
15
17
  - `vegetation.setShadowRing(name: string, ring: number)` — Change at runtime how far a vegetation kind casts shadows: within `ring` chunk rings of the player (0 = only the chunk you stand in, 1 = the default, larger = further and dearer). Takes effect at once; the define() option shadowRing is only the starting value. An unknown name warns with the known ones. Example: `engine.vegetation.setShadowRing('tree', 0); // graphics setting "shadows: low": trees shadow only the nearest chunk`
16
18
  - `vegetation.define(name: string, opts: VegetationOptions) → Species | Promise<Species>` — Define a kind of vegetation (a model name in model / lodGeometry: resolves first, so the result is a Promise of the species)
17
- - `vegetation.removeInstance(species: string, cx: number, cz: number, id: number, opts?: { regrowSeconds?: number }) → string` — Remove one (chop a tree). regrowSeconds: grows back after this many game seconds, 0 = permanent. The record is saved with the save (save key 'vegetation'). Returns the entry name
18
- - `vegetation.restoreInstance(species: string, cx: number, cz: number, id: number)` — Restore one
19
+ - `vegetation.isRemoved(species: string, cx: number, cz: number, id: number) → boolean` — (experimental)
20
+ - `vegetation.removeInstance(species: string, cx: number, cz: number, id: number, opts?: { regrowSeconds?: number }) → string` — Remove one (chop a tree). regrowSeconds: grows back after this many calendar seconds, 0 = permanent. The record is saved with the save (save key 'vegetation'). Returns the entry name
21
+ - `vegetation.restoreInstance(species: string, cx: number, cz: number, id: number)` — (experimental) Restore one
19
22
  - `vegetation.instanceAt(position: PositionLike, opts?: { radius?, species? }) → VegetationHit | null` — The one nearest to position within radius meters (default 2) (species restricts to one kind), null if none
20
- - Also: `vegetation.get(name: string) → Species | undefined`, `vegetation.list() → Species[]`, `vegetation.isRemoved(species: string, cx: number, cz: number, id: number) → boolean`
23
+ - Also: `vegetation.get(name: string) → Species | undefined`, `vegetation.list() → Species[]`
24
+ - Properties:
25
+ - `material: Material | null` The shared default material: species with no material or model of their own draw it, as given, planted ones too; null gives the neutral default back. Until set, reading gives the neutral source of each species' own copy (only .color written there reaches them all). Throws when a game module drew the plants instead (replaces: 'vegetation-draw').
26
+ - `patches: any[]` The engine's plant patches (season tint, sway with one amplitude, vegetation.color() code) for applyEffects(myMaterial, { patches })
21
27
 
22
28
  ## Data structures
23
29
  - **VegetationOptions** Parameters of engine.vegetation.define(name, {...})
@@ -27,7 +33,7 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
27
33
  - `rule?: VegetationRule` Placement rule (random scatter per chunk)
28
34
  - `positions?: number[][]` The game's own spots instead of the random scatter: [x, z], [x, z, scale] or [x, z, scale, yaw] in world metres / size multiplier / radians.
29
35
  - `densityMap?: ((x, z) => number) | { url?, data?, width?, height?, size, center?, … }` How much of this species survives at each spot, 0 (none) ..
30
- - `wind?: number` Wind sway amplitude, 0 = still
36
+ - `wind?: number | { amplitude, glsl?, tsl?, uniforms? }` Wind sway amplitude, 0 = still; or this species' own sway: { amplitude, glsl, tsl, uniforms }, which vegetation.sway() leaves alone (recipes/36)
31
37
  - `nearOnly?: boolean` Only generated near the player (grass, flowers)
32
38
  - `maxRing?: number` No longer drawn beyond this many rings
33
39
  - `fade?: false | { start?: number; end?: number }` Distance fade of a near-only species (grass, flowers, pebbles, debris ...): instances shrink out over a band in metres from the player instead of popping per chunk at the ring edge. Default for nearOnly: end = maxRing x chunk size, start = 65% of it. `false` keeps the hard ring edge (also the default for species that are not nearOnly).
@@ -0,0 +1,10 @@
1
+ # engine.vegetationDraw — vegetationDraw()
2
+
3
+ (experimental) Draws the plants (vegetation()'s drawing module, slot 'vegetation-draw'; undefined when a game replaced it)
4
+
5
+
6
+ ## Methods and properties
7
+ - `vegetationDraw.mesh(c: TerrainChunk, name: string) → InstancedMesh | null` — The InstancedMesh drawing one species in one chunk, null when none
8
+ - `vegetationDraw.kind(name: string) → { geometry, lodGeometry, material, fadeUniforms, shared } | null | …` — How one species is drawn: its geometry, low-poly geometry, patched material(s), near-fade uniforms; shared = it draws engine.vegetation.material; null for an unknown name
9
+ - Properties:
10
+ - `meshes: Map<TerrainChunk, { group: Object3D; ims: Record<string, In…` chunk record -> { group, ims: { species name: InstancedMesh } }
package/docs/api/water.md CHANGED
@@ -8,13 +8,17 @@ Water surface (water() module)
8
8
  - `flat?: boolean` Flat shading (low poly), default true
9
9
  - `size?: number` Edge length of the global water plane (meters), default 900
10
10
  - `segments?: number` Mesh subdivision of the global water, default 150
11
- - `uniforms?: import('./style').StyleWater['uniforms']` Uniforms for your look.water hooks' GLSL (same as style.water.uniforms)
12
11
 
13
12
  ## Methods and properties
13
+ - `water.shader(opts?: WaterShaderOptions)` — Which GLSL the water has. Keys left out keep what an earlier call gave; null takes one back to the built-in. Refreshes engine.water.patches and engine.water.uniforms and patches the engine's own material again (one recompile). A game's material is the game's to patch again. uWave, uWaveScale, uWaveSpeed and uFresnel stay the same objects. Example: `engine.water.shader({ depthColor: { shallow: 0x55ddcc, deep: 0x082040 }, foam: true }); engine.water.shader({ uniforms: { uBands: 4 }, surface: `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) { return vec4(base.rgb * floor(facing * uBands) / uBands, base.a); }` });`
14
+ - `water.normalMap(name: string | null, opts?: { scale?, repeat?, speed? }) → THREE.Texture | null` — Normal map by asset name (null = none): a flat-normal placeholder until the asset loads, then it takes the asset's image source (shared, not copied; goes through asset management, so it can be preloaded and released). Goes on the engine's own material; a game's material takes the returned texture (also engine.water.normalTexture). The tiling and the scroll apply whatever material draws. Keys left out keep their value (defaults scale 0.4, repeat 0.05, speed [0.01, 0.006]). Example: `engine.water.normalMap('water-n', { scale: 0.6, repeat: 0.1, speed: [0.02, 0.01] });`
14
15
  - Properties:
15
- - `material: THREE.Material` Water material (shared by all water)
16
+ - `normalTexture: THREE.Texture | null` The loaded normal map (null = none): a game material takes it as its own normalMap. Its offset scrolls and the water UVs tile for it whatever material draws
17
+ - `patches: import("../../render/patches.js").ShaderPatch[]` The engine's water shader patches (waves, waterSurface when asked for, fresnel), so a game material keeps the behavior: applyEffects(mat, { patches: engine.water.patches })
18
+ - `uniforms: Record<string, { value: any }>` Shader values, written directly and live: uWave, uWaveScale, uWaveSpeed, uFresnel, uTime; with depthColor / foam uWaterShallow, uWaterDeep, uWaterCurve, uFoamColor, uFoamStart, uFoamEnd, uFoamOpacity; and what shader({ uniforms }) declared
16
19
  - `bodies: Map<WaterBody, THREE.Mesh>` Water body → mesh
17
- - `sea: THREE.Mesh | null` Global water mesh (null when absent)
20
+ - `sea: THREE.Mesh | null` (experimental) Global water mesh (null when absent)
21
+ - `material: THREE.Material` Water material, shared by all water. Reading gives the plain three.js material in use (a neutral MeshLambertMaterial until you set one); setting swaps it on every water mesh and draws it as given: no engine patch is added, so a material that should keep the waves goes through applyEffects(m, { patches: engine.water.patches })
18
22
 
19
23
  ## Data structures
20
24
  - **WaterBodyOptions** Parameters of engine.addWaterBody(): position center, level water surface height (meters); give radius for a circle, halfWidth / halfDepth for a rectangle
@@ -4,6 +4,7 @@ Weather state (weather() module): the table, current values, set / setAuto, save
4
4
 
5
5
 
6
6
  ## Methods and properties
7
+ - `weather.defineField(field: string, spec: WeatherParticles | null) → WeatherParticleSystem | null` — Draw a field of the weather table with particles: your own (ash, petals, sparks) or rain / snow in place of the built-in ones. The amount each frame is weather.current[field], so they fade with the weather. spec takes the keys of weather({ rain }), or { create(engine, { area, count }) => { object, update?(amount, { camera, time, wind }) } } for a system of your own; null gives rain / snow back to weather({ rain, snow }) and removes any other field. Defining a field again replaces it. A field no type has throws with the table's fields. Example: `engine.weather.defineField('ash', { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 });`
7
8
  - `weather.setAuto(on: boolean)` — Automatic weather on/off
8
9
  - `weather.set(name: WeatherName, opts?: { seconds?: number })` — Switch weather. seconds: transition seconds, default 15; 0 switches at once (current is the new weather before the next step, so a screenshot or test right after shows all of it). Options in an object like every other engine call: set('rain', 20) throws [module-params] in dev (the old positional form). Example: `engine.weather.set('rain', { seconds: 20 })`
9
10
  - `weather.label(name?: string) → string` — Display name of a weather (string table weather.<name>, falls back to the name itself); defaults to the current weather
@@ -11,9 +12,13 @@ Weather state (weather() module): the table, current values, set / setAuto, save
11
12
  - `types: Record<string, WeatherPreset>` The weather types this game has: name -> numbers (the standard fields plus any of the game's own, all blended on change)
12
13
  - `current: WeatherPreset` Current (mid-transition) weather parameters
13
14
  - `name: string` Current weather name
14
- - `auto: boolean` Automatic weather on/off
15
- - `autoPool: string[]` Candidates for automatic weather (repeat a name to make it likelier)
16
- - `autoInterval: number[]` Automatic weather interval [min, max] seconds
17
- - `autoTransition: number` Transition seconds for automatic weather
18
- - `lightningFirst: number` Seconds to the first bolt (also after a load without a saved timer)
19
- - `lightningInterval: number[]` [min, max] seconds between bolts while a type with lightning > 0.5 holds
15
+ - `autoPool: string[]` (experimental) Candidates for automatic weather (repeat a name to make it likelier)
16
+ - `autoInterval: number[]` (experimental) Automatic weather interval [min, max] seconds
17
+ - `autoTransition: number` (experimental) Transition seconds for automatic weather
18
+ - `lightningFirst: number` (experimental) Seconds to the first bolt (also after a load without a saved timer)
19
+ - `lightningInterval: number[]` (experimental) [min, max] seconds between bolts while a type with lightning > 0.5 holds
20
+ - `lightning: (flash: number, engine: any) => number` (experimental) Strike picture: flash (1 at the strike, fading in a third of a second) -> sky flash amount. Write it at any time
21
+ - `lightningBrightness: number` Multiplies the sky flash of every strike; write it at any time
22
+ - `overcastColor: THREE.Color` Color the sky turns as a weather type raises grey: a THREE.Color, overcastColor.set(0x667788) changes it live
23
+ - `particles: Record<string, WeatherParticleSystem>` The particle systems drawn now, by field: rain and snow when the table has them, plus what defineField() added. Example: `engine.weather.particles.rain.spec.speed = 30;`
24
+ - `auto: boolean` Automatic weather on/off. Writing it takes effect like setAuto.
@@ -0,0 +1,10 @@
1
+ # engine.weatherDraw — weatherDraw()
2
+
3
+ (experimental) Weather drawing (installed by weather(); sky is optional): rain / snow particle systems, lightning flash, the weather's effect on sun, fog and sky
4
+
5
+
6
+ ## Methods and properties
7
+ - Properties:
8
+ - `flash: number` Sky flash now, 1 at a strike (the weather:lightning event) fading to 0
9
+ - `particles: number` Default particle count per system: weather({ particles }), else 6000 (3000 on low-tier devices)
10
+ - `systems: Map<string, any>` Particle systems drawn now: field -> { field, object, material, uniforms, spec } (rain / snow when the table has them, plus fields engine.weather.defineField adds)
package/docs/api/world.md CHANGED
@@ -4,22 +4,22 @@ World data (world() module): things that must be saved, survive level changes an
4
4
 
5
5
 
6
6
  ## Methods and properties
7
- - `world.add(def: { kind, id?, position?, … }, opts?: { initial?, save? }) → WorldRecord | null` — Add a record and return it (a plain object). kind is required; without id one is numbered automatically (kind#1, kind#2…, saved; `#` never appears in an authored id, so the two can never collide). opts.initial: initial record written in content (needs an id); saves only keep its changes and removal; if the id already exists the existing one is returned (content may load twice); returns null if the save removed it (it is not added back). opts.save: false: not saved (temporary things). Example: `engine.world.add({ id: 'shop_owner', kind: 'npc', position: [12, 0, -30], name: '店主', mood: 'calm' }, { initial: true })`
7
+ - `world.add(def: { kind, id?, position?, … }, opts?: { initial?, save? }) → WorldRecord | null` — Add a record and return it (a plain object). kind is required; without id one is numbered automatically (kind#1, kind#2…, saved; `#` never appears in an authored id, so the two can never collide). opts.initial: initial record written in content (needs an id); saves only keep its changes and removal; if the id already exists the existing one is returned (content may load twice), after taking a new position / rot from the content unless play moved it; returns null if the save removed it (it is not added back). opts.save: false: not saved (temporary things). Example: `engine.world.add({ id: 'shop_owner', kind: 'npc', position: [12, 0, -30], name: '店主', mood: 'calm' }, { initial: true })`
8
8
  - `world.origin(id: string) → { definedAt?, level?, node?, template?, spawned? } | null | …` — Where a record comes from (filled in dev and test builds; null in release): { definedAt: 'content/props.js:14' } for a content entry, { level, node } for a level-model node, { template } when it is a template instance, { spawned: { op, tick } } for a record created during play. engine.inspect(id) and engine.pick(...).thing show it, so you know which file to edit to change the level for good. Example: `engine.world.origin('chest-home') // { definedAt: 'content/props.js:14', template: 'chest' }`
9
- - `world.idOf(obj: any) → string | null` — The id of the record whose model contains obj (obj itself or one of its parents is a built model), else null. A ray hit on a model names its record this way. Example: `const h = engine.pick(0, 0); const id = h && engine.world.idOf(h.object);`
9
+ - `world.idOf(obj: any) → string | null` — (experimental) The id of the record whose model contains obj (obj itself or one of its parents is a built model), else null. A ray hit on a model names its record this way. Example: `const h = engine.pick(0, 0); const id = h && engine.world.idOf(h.object);`
10
10
  - `world.get(id: string) → WorldRecord | undefined` — Get a record by id (undefined if missing, like a Map)
11
11
  - `world.set(id: string, patch: Record<string, any>) → WorldRecord` — Merge fields into a record and emit the world:change event; a position in patch also moves it. Returns the record. For discrete changes (chest opened, growth stage, picked up); if present has show, it is re-evaluated after the change. id / kind cannot be changed. Example: `engine.world.set('crate_1', { opened: true })`
12
12
  - `world.move(id: string, position: any)` — Move a record (no event; use it in simulate for things that move every step); still saved (saves diff against content). The model of a positionFrom 'record' (default) record follows this frame; to do something else with the position in presentation, compare in update. Example: `engine.world.move(rec.id, { x: rec.position.x + 1, z: rec.position.z })`
13
13
  - `world.remove(id: string)` — Remove a record (its model is torn down too) and emit the world:remove event. Does nothing if the id does not exist. Removing an initial record is saved, so it stays gone after loading
14
14
  - `world.query(opts?: { kind?, near?, radius?, where?, zone? }) → WorldRecord[]` — Query records; returns an array. With near only nearby cells are scanned and results are sorted nearest first (radius defaults to 30 m); where filters further. For neighbor queries every step use forEachNear. Example: `engine.world.query({ kind: 'zombie', near: engine.player, radius: 30, where: z => !z.dead })`
15
15
  - `world.forEachNear(center: any, radius: number, fn: (rec, d2) => void)` — Call fn(rec, d2) for each record within radius meters (horizontal distance) of center; d2 is the squared distance. Unsorted, no allocation: use it for per-step neighbor queries (hundreds of zombies avoiding each other). Don't add / remove / move in the callback (moving into a cell not yet visited visits it again): record the change and apply it after the loop. Example: `engine.world.forEachNear(rec.position, 5, (o, d2) => { if (o !== rec && o.kind === 'zombie') n++; })`
16
- - `world.present(kind: string, opts: { build, update?, dispose?, show?, radius?, positionFrom? }) → { remove(): void }` — Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks: build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object: reported once, does not block ready, retried when you leave and come back. update(rec, obj, dt): called every frame for records that have a model (change the look from the data, e.g. an opened chest swaps texture). dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj). show(rec) → false: this record has no model right now (picked up, waiting to respawn); re-evaluated when world.set changes records of this kind. Example: `engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, makeMaterial('prop')), dispose: (rec, obj) => engine.remove(obj), show: rec => !rec.looted })`
16
+ - `world.present(kind: string, opts: { build, update?, dispose?, show?, radius?, positionFrom? }) → { remove(): void }` — Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks: build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object: reported once, does not block ready, retried when you leave and come back. update(rec, obj, dt): called every frame for records that have a model (change the picture from the data, e.g. an opened chest swaps texture). dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj). show(rec) → false: this record has no model right now (picked up, waiting to respawn); re-evaluated when world.set changes records of this kind. Example: `engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, new THREE.MeshStandardMaterial()), dispose: (rec, obj) => engine.remove(obj), show: rec => !rec.looted })`
17
17
  - `world.view(id: string) → any` — The current model of this record (only exists nearby; null if not built yet or far away)
18
18
  - `world.refresh()` — Build / tear down models for the stream sources right now (normally automatic every frame, with a per-frame limit). Use it right after add when you need the model: sync builds are available via view(id) after the call, for async ones also await world.whenReady. Example: `engine.world.add({ id: 'gate', kind: 'gate', position: p }); engine.world.refresh(); engine.world.view('gate')`
19
19
  - `world.simulate(kind: string, opts: { near?, far?, farEvery?, radius?, fullRadius?, nearEvery?, … }) → { remove(): void }` — Register how a kind of thing changes (gameplay logic goes here, runs in the fixed step); near / far is split by distance from world.anchor (default: the player): near(rec, dt, obj): within radius, once per fixed step (obj is the model, may be null if not built yet; gameplay must not depend on it); far(rec, dt): farther away, once every farEvery seconds; dt is the seconds accumulated since the last simulation (can catch up a long time at once); on the far → near step, far runs first to pay back the owed time. With only far (crops), near also advances via far; with only near, far records are not simulated and owed time is not made up. Both dt are accumulated real (fixed-step) seconds (not multiplied by clock.rate). For things measured in game clock (grows over days) store engine.clock.now and compare. Example: `engine.world.simulate('zombie', { near: (rec, dt) => chase(rec, dt), far: (rec, dt) => wander(rec, dt), farEvery: 2 })`
20
- - `world.pauseSimulation() → { remove(): void }` — Stop running simulate() handlers on this machine until remove(): a multiplayer client lets the host simulate and only receives the records. Public so net() needs no world internals.
20
+ - `world.pauseSimulation() → { remove(): void }` — (experimental) Stop running simulate() handlers on this machine until remove(): a multiplayer client lets the host simulate and only receives the records. Public so net() needs no world internals.
21
21
  - Properties:
22
- - `records: Map<string, WorldRecord>` All records: id → record (read-only; use set to change fields, move to change position)
22
+ - `records: Map<string, WorldRecord>` (experimental) All records: id → record (read-only; use set to change fields, move to change position)
23
23
  - `radius: number` Default distance (meters) for building models and counting as near; present / simulate can override it. Changing it at runtime affects those without their own radius
24
24
  - `farEvery: number` Default interval (seconds) between far simulations, same unit as dt
25
25
  - `farMaxPerTick: number` Max far simulations per fixed step; the rest queue for the next step (dt accumulates, no time is lost). Counted by records, not milliseconds, so results do not depend on machine speed
@@ -28,4 +28,4 @@ World data (world() module): things that must be saved, survive level changes an
28
28
  - `zone: string | null` Current zone (e.g. level name, set by the level module on level change): once set, records of another zone get no model and no near simulation; null = no zoning
29
29
  - `ready: boolean` All models that should exist near the stream sources are built (async ones too; failed builds do not count as pending). The loading screen waits for it; to wait yourself, await world.whenReady
30
30
  - `whenReady: Promise<void>` Promise that resolves when ready becomes true
31
- - `steps: number` Number of fixed steps simulated
31
+ - `steps: number` (experimental) Number of fixed steps simulated
@@ -1,55 +1,52 @@
1
- # Starting a new game (a workspace under games/)
1
+ # Starting a new game
2
2
 
3
- **In this recipe**: 0. One-command setup · 1. Creating the files by hand · 2. Verify · 3. Preset parts · 4. Feel presets · 5. Canvas size
3
+ **In this recipe**: 0. One-command setup · 1. Creating the files by hand · 2. Verify · 3. Feel presets · 4. Canvas size
4
4
 
5
- Goal: create `games/my-game/` (pick your own name) with its own page, modules, content data and tests, independent of other games. Start from the
6
- template (`threedog new-game my-game`, section 0); the engine's own example is `examples/world/` in the package.
5
+ Goal: a game with its own page, modules, content data and tests. The engine's own example is `examples/world/` in the package.
6
+
7
+ In a folder of your own, installed from npm: run `npx threedog init` (add `--open-world` for the second form below), then `npm install`. In the engine repository: `npm run new-game -- my-game` creates `games/my-game/`. The rest of this page uses the repository form; read `games/my-game/` as your folder and `new-game` as `init`.
7
8
 
8
9
  ## 0. One-command setup (preferred)
9
10
  ```
10
11
  npm run new-game -- my-game # blank start: an empty scene and a camera; no gameplay, no genre assumed
11
12
  npm run new-game -- my-game --open-world # generated ground, a day/night sky, a follow camera and a player
12
- npm run new-game -- my-game --example # the open world plus a sample: hp / hunger, a rest op, apples, a searchable stash, a HUD counter
13
+ npm run new-game -- my-game --webgl # either one on WebGL, shaders in GLSL, instead of WebGPU and TSL
13
14
  ```
14
- (The `--` matters: without it npm swallows the flags. The CLI form takes them directly: `threedog new-game my-game --example`. `--example` uses engine placeholders (gray box, capsule), so it works with any style.)
15
+ (The `--` matters: without it npm swallows the flags. The CLI form takes them directly: `threedog new-game my-game --open-world`.)
16
+ A new game runs on WebGPU, shaders in TSL (recipe 56); `--webgl` is for GLSL. Without WebGPU the same game runs on three's WebGL2 backend, slower; `engine.describe().renderer` says which and why.
15
17
  The name may only contain lowercase letters, digits and dashes; an existing directory under `games/` with the same name is refused. What it does:
16
- 1. Copies `packages/tools/templates/game/` to `games/my-game/` (`__NAME__` in the files is replaced by the name); `--open-world` copies `templates/openworld/` over it first, `--example` also `templates/example/`.
18
+ 1. Copies `packages/tools/templates/game/` to `games/my-game/` (`__NAME__` in the files is replaced by the name); `--open-world` copies `templates/openworld/` over it first.
17
19
  2. Creates the `node_modules/my-game` link (the path npm gives a workspace named `my-game`). It builds nothing and leaves `package-lock.json` alone; it runs `npm install` only when a dependency of the template is not installed yet, and says so.
18
20
  3. Runs `map` (generates GAMEMAP.md) and `check`. Any failing step stops and says why. The smoke test (`threedog test -w games/my-game`) builds, so it is left to you.
19
21
 
20
- The default game is deliberately empty: `world()` + `content()`, the engine's camera placed by hand (a plain `THREE.PerspectiveCamera`) and the always-on
21
- render baseline (default lights, tone mapping, color space); no ground, sky, player or camera rig, because which of those a game needs depends on its genre
22
- (a card table, a puzzle room, a side-scroller and an open world start differently). Content files are empty arrays / objects (each
23
- has one comment line saying what goes there and which recipe teaches it), and an empty style in `style/index.js` (every section is a commented-out stub;
24
- with it empty the engine shows gray placeholders; fill it with your own art using recipes 09 and 52). `CLAUDE.md` says "This game has no gameplay yet; build what DESIGN.md describes".
22
+ The default game has no genre: `world()` + `content()`, what nearly every game needs (a start screen with Continue / Start, autosave, Esc = pause + settings menu; delete a line if the game does not want it), a plain `THREE.PerspectiveCamera` placed by hand and the gray starting picture. No ground, sky, player or camera rig: a card table, a puzzle room, a side-scroller and an open world start differently (a character walking around a place you built: recipe 63, about twenty lines).
23
+ Content files start empty, a comment in each saying what goes there, except `props.js`, whose `marker-1` shows the shape. `picture/` (`index.js` wiring, `palette.js`, `lights.js`, `materials.js`) is plain three.js, yours to change or replace (recipe 62).
25
24
  `--open-world` swaps `main.js` for `openWorld` (generated terrain from `@threedog/terrain-noise`, vegetation, a day/night sky, weather, water, collision, a
26
- follow camera) and a player at a flat spot; it adds `@threedog/terrain-noise` to `package.json`. `--example` builds on it and adds the patterns: `interactions / inventory / hud`, 3 apples on the ground and one stash (a template in `content/templates.js` placed by
27
- `content/props.js`, searched through the op `stash.search`); its `main.js` shows the game's own state registered with `describe.add` and `saves.register`, an op
28
- with `can` / `run`, and the `onFixed` / `onFrame` split. `spawn` and `places` take any `{ x, z }` (or `{ x, y, z }`); `findSpawn` is only for generated terrain.
29
- In an open-world start, to change the camera: `openWorld({ camera: 'firstPerson' })` (`follow` / `firstPerson` / `rts` / `fixed`, or pass a camera module directly; there is
30
- no default).
25
+ follow camera) and a player at a flat spot, with `sky()` giving the signals and `picture/` writing the lights; it adds `@threedog/terrain-noise` to `package.json`. `spawn` and `places` take any `{ x, z }` (or `{ x, y, z }`); `findSpawn` is only for generated terrain.
26
+ The canvas is the one you gave `createEngine({ canvas })`, also `engine.renderer.domElement`; the engine keeps no canvas property of its own.
27
+
31
28
  - The comments in `main.js` list further gameplay modules you can add; usage is in `../api/<module>.md`.
32
- - To change the starting point of new games, edit the real files in `packages/tools/templates/game/` (`templates/openworld/` for `--open-world`, `templates/example/` for the sample).
33
- - `DESIGN.md` is an empty template: write your gameplay ideas there. `CLAUDE.md` only points the way (read `node_modules/threedog/docs/AI.md` first,
34
- then GAMEMAP, DESIGN) and does not copy engine rules.
29
+ - To change the starting point of new games, edit the real files in `packages/tools/templates/game/` (`templates/openworld/` for `--open-world`).
30
+ - `DESIGN.md` is a form to fill in with the game's design, `STATUS.md` holds progress, and `CLAUDE.md` holds the working rules, a table cut from AI.md and the reading order.
35
31
  - There is no `tests/`: when `tests/specs/` does not exist, `npm test -w games/my-game` runs a smoke test automatically.
36
32
 
37
33
  ## 1. Creating the files by hand (to learn what each file is, or when the template doesn't fit)
38
34
  | File | Content |
39
35
  |---|---|
40
- | `games/my-game/package.json` | Copy `package.json` from the game template (or run `threedog new-game my-game`) and set `name` to `my-game` (the plain game name, in this repository and in a game repo of its own; `@threedog/` is the engine's packages; dependencies `threedog`, `@threedog/tools`, plus `@threedog/terrain-noise` only for an open-world start, and your style (and `@threedog/post-effects` if the pack uses it) only when `main.js` imports it; the default style is the game's own `style/index.js`; scripts dev/build/preview/test/check/map) |
36
+ | `games/my-game/package.json` | Copy the template's and set `name` to `my-game` (the plain game name; `@threedog/` is the engine's packages). Dependencies `threedog`, `@threedog/tools`, plus `@threedog/terrain-noise` only for an open-world start and `@threedog/post-effects` only when the game imports it |
41
37
  | `games/my-game/vite.config.js` | One line: `export default gameConfig(import.meta.dirname)` (imported from `@threedog/tools/vite`); *.html files in the directory are bundled automatically, no `input` needed. Without `@threedog/tools`, a plain vite config needs `worker: { format: 'es' }` (the engine's Workers are ES modules) or `vite build` fails; `threedog dev / build` on a folder with no vite config uses the preset |
42
- | `games/my-game/index.html` | The page: one `<canvas id="view">` with a CSS size + `/main.js` (for more pages put `xxx.html` in the same directory); see §5 for embedding |
43
- | `games/my-game/main.js` | Install modules, compute places, `content.load`, game-specific logic |
38
+ | `games/my-game/index.html` | The page: one `<canvas id="view">` with a CSS size + `/main.js` (for more pages put `xxx.html` in the same directory); see §4 for embedding |
39
+ | `games/my-game/main.js` | Install modules, compute places, `content.load`, wire the game's systems (template `CLAUDE.md`, "Content vs code") |
44
40
  | `games/my-game/content/index.js` | Combines the content files into one object |
45
- | `games/my-game/content/*.js` | Only these names are read: items pickups containers npcs dialogues quests actions places triggers level vegetation props templates audio grids renames rules, plus the game's own kinds (rules.js) |
46
- | `games/my-game/DESIGN.md` | Hand-written design decisions (a few lines of `- **decision**: reason`), copied into GAMEMAP.md |
47
- | `games/my-game/CLAUDE.md` | A few lines: read `node_modules/threedog/docs/AI.md`, then this directory's GAMEMAP.md and DESIGN.md (copy the template's) |
48
- | `games/my-game/public/` | This game's art assets (URL `/models/...`); keep Blender source files in `games/my-game/art/models/`, `npm run assets -- -w my-game` compresses them over |
41
+ | `games/my-game/content/*.js` | Only these names are read: items pickups containers npcs dialogues quests actions places triggers level vegetation props templates audio views grids renames rules, plus the game's own kinds (rules.js) |
42
+ | `games/my-game/DESIGN.md` | The design as a form (copy the template's), copied into GAMEMAP.md |
43
+ | `games/my-game/STATUS.md` | Progress and what comes next (copy the template's) |
44
+ | `games/my-game/CLAUDE.md` | Working rules and reading order (copy the template's) |
45
+ | `games/my-game/public/` | This game's art assets (URL `/models/...`); keep Blender source files in `games/my-game/art/models/`, `npm run assets -- optimize -w my-game` compresses them into `public/optimized/` |
49
46
 
50
47
  After creating them, run `npm install` once at the repository root (this links the new game into the workspaces so `threedog` can find it).
51
48
 
52
- Outside the engine repository, a game installs `threedog` and `three` (plus your style, `@threedog/post-effects` / `@threedog/terrain-noise` if it imports them,
49
+ Outside the engine repository, a game installs `threedog` and `three` (plus `@threedog/post-effects` / `@threedog/terrain-noise` if it imports them,
53
50
  and `@threedog/tools` as a dev dependency for the CLI and the vite preset). To use an engine folder on disk instead of npm, install it with
54
51
  `npm install --install-links <folder>`: a plain link skips the engine's own dependencies (Rapier, Recast) and the build cannot resolve them.
55
52
 
@@ -59,25 +56,18 @@ In a game's own repository, `threedog check`, `types` and `map` read only the ga
59
56
  The template's `tsconfig.json` checks the game files only (`checkJs`), with `lib` ESNext + DOM (dependency typings such as Rapier's use
60
57
  `Symbol.dispose`) and `skipLibCheck: true`; without a tsconfig, `threedog types` writes the same settings to `.threedog/tsconfig.types.json`.
61
58
 
62
- `games/my-game/index.html` (minimal; the template's `index.html` has the same page with loading styles):
63
- ```html
64
- <!doctype html>
65
- <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
66
- <title>My game</title><style>html,body{height:100%;margin:0;overflow:hidden;background:#141a17}#view{position:fixed;inset:0;width:100%;height:100%;display:block;outline:none}</style>
67
- </head><body><canvas id="view" tabindex="0"></canvas><script type="module" src="/main.js"></script></body></html>
68
- ```
69
59
 
70
- `games/my-game/main.js`, here an open-world game with a few gameplay modules (a blank game is the template's `main.js`: `createEngine`, `world(), content()`, the camera placed by hand, `start()`):
60
+ `games/my-game/main.js`: the opening lines are written out once, in [recipe 63](63-third-person-start.md) §1 (the blank template's `main.js` has the same opening with `world(), content(), settings()` and the camera placed by hand). What an open-world game with a few gameplay modules changes in it:
71
61
  ```js
72
62
  // my-game: ... (this first comment line appears in the file table of GAMEMAP.md)
73
- import { createEngine, presets, openWorld, interactions, dialogue, inventory, pickups, quests, content } from 'threedog';
74
- import style from './style/index.js'; // the game's own style (the engine ships no art)
63
+ // The opening stays as in recipe 63 §1: createEngine({ canvas, lights: false, ui, saveKey, bindings }), createPicture(engine) after engine.use,
64
+ // Object.assign(window, { engine, picture }) (tests, screenshots and the console rely on it), await engine.start().
65
+ import { presets, openWorld, interactions, dialogue, inventory, pickups, quests, content } from 'threedog';
75
66
  import { terrainPreset } from '@threedog/terrain-noise'; // optional terrain generator (nor a world shape)
76
67
  import data from './content/index.js';
77
68
 
78
- // keys: modules only declare actions, the game binds them (presets.bindings.* are ready-made maps)
79
- const engine = createEngine({ canvas: document.getElementById('view'), style, ui: { loading: { title: 'My game' } }, saveKey: 'my-game',
80
- bindings: { ...presets.bindings.walk, ...presets.bindings.interact, ...presets.bindings.inventory, ...presets.bindings.quests } });
69
+ // keys: modules only declare actions, the game binds them (presets.bindings.* are ready-made maps); this goes in createEngine({ bindings })
70
+ const bindings = { ...presets.bindings.walk, ...presets.bindings.interact, ...presets.bindings.inventory, ...presets.bindings.quests };
81
71
  // the preset only covers world and environment; the debug panel is installed in dev builds only (debug: true forces it in release too)
82
72
  engine.use(openWorld({ camera: 'follow', seed: 42, terrain: terrainPreset(), time: 0.3 }),
83
73
  // add gameplay modules as the game needs (a shooter has no inventory); pickups() when items lie on the ground (content pickups)
@@ -86,10 +76,7 @@ engine.use(openWorld({ camera: 'follow', seed: 42, terrain: terrainPreset(), tim
86
76
  // the terrain is generated: find flat ground as "home" at the start (give your own height range to avoid beach and peaks)
87
77
  const home = engine.characters.findSpawn([0, 0, 0], { minH: 3, maxH: 14 });
88
78
  engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: home });
89
- engine.content.load(data, { places: { ...data.places, home } }); // content/places.js names + this one; content uses { place: 'home', x, z }, quests target: 'home'
90
- // tests, screenshots and the console all rely on it (before start, so the dev bridge can wait for it)
91
- window.engine = engine;
92
- await engine.start();
79
+ engine.content.load(data, { places: { home } }); // on top of the names in content/places.js; content uses { place: 'home', x, z }, quests target: 'home'
93
80
  ```
94
81
  Every `openWorld` part takes `false` (leave it out) or its module's own options object, so you never have to drop the preset for one setting:
95
82
  `openWorld({ seed: 42, camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, characters: { npcs: false }, rigid: false, ambience:
@@ -100,13 +87,13 @@ false, debug: false })`;
100
87
  With `terrain: false` the game supplies its ground. Until it does, characters, props and pickups stand on an invisible flat plane at y = 0 (no
101
88
  warning): they look like they float over nothing. Draw the ground yourself, and if it is not flat at y = 0 tell the engine its height:
102
89
  ```js
103
- const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), makeMaterial('ground')); // what you see
90
+ const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), new THREE.MeshLambertMaterial({ color: 0x8c8c8c })); // what you see
104
91
  floor.receiveShadow = true; engine.add(floor);
105
92
  engine.setGround({ height: (x, z) => 0 }); // what walking, placing and the camera read (a ramp, a raised floor: return its y here)
106
93
  ```
107
94
  Walls and obstacles are `engine.collision.addBox(obj, { halfWidth, halfDepth })`; a Blender level brings its own ground (`level()`, next paragraph).
108
95
  `saveKey` must differ per game, otherwise saves overwrite each other. The UI language follows the player's browser (Chinese browser -> Chinese,
109
- otherwise English) unless you set `createEngine({ locale: 'zh-CN' })` (`'zh'` and `'en-US'` match too; a language with no strings warns). A game without terrain (the city test page in the engine repository does this): register
96
+ otherwise English) unless you set `createEngine({ locale: 'zh-CN' })` (`'zh'` and `'en-US'` match too; a language with no strings warns). A game on a level built in code: register
110
97
  the level generator function under `models` in `engine.assets.manifest({ name, models })`, use `level({ url: name })` and pick your own modules, then
111
98
  create the player and install content in `level:loaded`.
112
99
 
@@ -116,7 +103,7 @@ import items, { startItems } from './items.js';
116
103
  import places from './places.js';
117
104
  export default { items, startItems, places };
118
105
  ```
119
- `content/places.js`: `export default { home: 'flat ground found at the start (coordinates computed in main.js)' };`
106
+ `content/places.js`: `export default { farm: { x: 12, z: -4 }, home: 'flat ground found at the start' };`. `content.load` reads a place written with coordinates from the data; a text entry only declares the name for `threedog check` and waits for `content.load(data, { places })`.
120
107
 
121
108
  ## 2. Verify
122
109
  1. `npm run map` -> generates `games/my-game/GAMEMAP.md`; check the "engine modules" and "page /" sections.
@@ -127,12 +114,8 @@ export default { items, startItems, places };
127
114
  5. To see the picture: `npm run shot -- -w my-game /` (one image in `games/my-game/.threedog/shots/`); while developing run `npm run dev -w games/my-game` (or
128
115
  `npm run dev -- my-game`) and open the printed address; read errors in `games/my-game/.threedog/errors.log`.
129
116
 
130
- ## 3. Preset parts
131
- Every `openWorld()` part takes `false` or its module's options object, for example
132
- `openWorld({ camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, debug: false })`. Gameplay modules (interactions, dialogue,
133
- inventory, quests) are not in the preset: add them with `engine.use`. The debug panel is dev-only by default.
134
117
 
135
- ## 4. Feel presets (opt-in)
118
+ ## 3. Feel presets (opt-in)
136
119
  The engine applies no gameplay feel by itself: `weather()` alone has only a calm `clear`, `sky()` has no seasons, and the calls that need a feel
137
120
  refuse to guess: `createPlayer()` throws `[player-control]` without `control`, `interactions()` throws `[interaction-setup]` without `pick` and keys,
138
121
  `openWorld()` throws `[open-world-camera]` without `camera`. The core key table holds only movement and menu confirm / cancel; run, jump and interact
@@ -144,11 +127,9 @@ engine.use(calendar(presets.calendar.fourSeasons), sky(), weather({ ...presets.w
144
127
  engine.use(interactions({ ...presets.interactions.facing })); // nearest / facing / aim, each with E
145
128
  const player = engine.characters.createPlayer({ ...presets.player.lockOn, faceTarget: boss }); // none / thirdPerson / lockOn / aim / sideScroller
146
129
  ```
147
- `presets.player.thirdPerson` is `{ control: 'camera', faceMode: 'move', cameraFollow: true }`; the run / jump keys are
148
- `presets.bindings.walk` (`{ run: ['ShiftLeft', 'ShiftRight', 'PadLB'], jump: ['Space', 'PadA'] }`). No module or preset takes keys: every key
149
- comes from `createEngine({ bindings })` or `engine.input.bind(...)`.
130
+ The run / jump keys are `presets.bindings.walk`. No module or preset takes keys: every key comes from `createEngine({ bindings })` or `engine.input.bind(...)`.
150
131
 
151
- ## 5. Canvas size: full window, a page section, a split layout or an editor panel
132
+ ## 4. Canvas size: full window, a page section, a split layout or an editor panel
152
133
  The engine follows the canvas's own CSS box (a `ResizeObserver` on the canvas), not the window: renderer size, camera aspect, `input.pointer` (`x / y`
153
134
  pixels and `ndcX / ndcY` relative to the canvas), `engine.pick`, `screenToGround`, `worldToScreen` and the HUD all use that box, and the engine's UI
154
135
  root is laid exactly over it. So the layout decides:
@@ -1,10 +1,11 @@
1
1
  # Adding an NPC (schedule + dialogue)
2
2
 
3
+ **In this recipe**: 1. Write data · 2. Add in code · NPC data and model · Custom behavior · Avoidance · A guard you build yourself · Dialogue choices · 3. Verify · Bubbles
4
+
3
5
  Modules needed: `characters()` (NPCs on by default), `interactions({ ...presets.interactions.nearest })`, `dialogue()`; clock-time schedules need
4
- `sky()` with a day cycle (`dayLength`, e.g. `presets.calendar.cycle`: without one the clock never moves and the NPC keeps to one stop). The
5
- `openWorld()` preset already installs `characters()` and `sky()` but not `interactions({ ...presets.interactions.nearest })` or `dialogue()`, so add
6
- them yourself: `engine.use(openWorld({ camera: 'follow', calendar: presets.calendar.cycle, ...}), interactions({ ...presets.interactions.nearest }),
7
- dialogue(), content())`.
6
+ `calendar()` with a day cycle (`dayLength`, e.g. `presets.calendar.cycle`: without one the clock never moves and the NPC keeps to one stop). `openWorld()`
7
+ installs `characters()` and the calendar but not the other two: `engine.use(openWorld({ camera: 'follow', calendar: presets.calendar.cycle, ...}),
8
+ interactions({ ...presets.interactions.nearest }), dialogue(), content())`.
8
9
 
9
10
  ## 1. Write data (recommended)
10
11
  `games/<game>/content/npcs.js`:
@@ -12,7 +13,7 @@ dialogue(), content())`.
12
13
  export default {
13
14
  guard: {
14
15
  name: 'Gate guard',
15
- colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a }, // omit to use the style's default colors
16
+ colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a }, // omit to use the default colors
16
17
  start: { place: 'home', x: 6, z: -3 }, // starting position; omitted = the first stop of the schedule
17
18
  schedule: [ // at is a clock time 'HH:MM'; at that time the NPC walks there (pathfinding is automatic)
18
19
  { at: '07:00', place: 'home', x: 6, z: -3 },
@@ -52,10 +53,10 @@ export default {
52
53
  },
53
54
  };
54
55
  ```
55
- The words usable in conditions / effects are in the comment at the top of `modules/content/rules.js` (flag notFlag has lacks counter can / setFlag
56
+ The words usable in conditions / effects are in the last section of `../api/content.md` (flag notFlag has lacks counter can / setFlag
56
57
  give take bump startQuest toast particles marker clearMarker op). A game's own action is an op, always written as a pair `[name, args]` (a bare
57
58
  name string is rejected): `do: { op: ['delivery.done', { parcel: 'p1' }] }` (`23-ops.md`).
58
- The items used (coin, pass) must be defined in `items.js`, otherwise validation fails. A `place` name comes from `content.load(data, { places })` or
59
+ The items used (coin, pass) must be defined in `items.js`, otherwise validation fails. A `place` name comes from `content/places.js`, `content.load(data, { places })` or
59
60
  from a level marker (such as `npc_guard`). Add a new content file to `content/index.js`.
60
61
 
61
62
  ## 2. Add in code (temporary NPCs, dynamic schedules)
@@ -119,26 +120,24 @@ engine.npcs.behavior('chase', {
119
120
  npc.setBehavior('chase');
120
121
  ```
121
122
  To path around obstacles, use `engine.characters.findPath(from, to)` to get waypoints and walk them one by one (the schedule behavior does exactly
122
- this, see `goTo` in `modules/characters/npcSim.js`).
123
+ this).
123
124
 
124
125
  ## Avoidance (NPCs don't clump or pass through each other)
125
126
  NPCs with models nearby avoid each other by default: when closer than the sum of two radii (`engine.movement.radius` x 2, about 0.8 meters) they push
126
127
  each other apart, harder the more they overlap, at most 3 meters per second; the player counts as an obstacle that only NPCs yield to, and the
127
128
  player's position is never pushed. After pushing, `engine.collision` (if installed) constrains them back to walkable ground, so they are not pushed
128
129
  into walls. The built-in `schedule` and `wander` both avoid.
129
- - Deterministic and cheap: done only in the fixed step, no random numbers, neighbors computed from "the positions at the start of this step", so after
130
- save and load, or with a different `frameEvery`, positions are identical bit for bit; 400 NPCs with models cost less than 1 ms per step (a tight
131
- clump only a few ms).
130
+ - Deterministic: done only in the fixed step, no random numbers, neighbors computed from the positions at the start of the step, so a load or a different
131
+ `frameEvery` gives identical positions.
132
132
  - Tune or turn off:
133
133
  ```js
134
134
  engine.npcs.avoid.set({ radius: 0.6, strength: 2 }); // stand sparser (radius in meters), push slower (strength in meters/second)
135
135
  engine.npcs.avoid.set(false); // turn off (ghosts, crowds passing through); set(true) turns it on again
136
136
  ```
137
137
  - Far away (no model) NPCs are simulated from data without per-NPC avoidance; a few steps after a model is built on approach they get pushed apart.
138
- - Difference from `nav({ crowd: true })`: when crowd is installed the Recast crowd agents take over and this is not applied on top. Crowd routes more
139
- cleverly (around obstacles along the navmesh, yields to others) but does not guarantee identical results after loading; the simple push here does
140
- not route around anything and only keeps NPCs from overlapping, with results identical after loading. For save replay and determinism use this; for
141
- crowds going around big obstacles use crowd.
138
+ - `nav({ crowd: true })` replaces this push with Recast crowd agents: they route around obstacles along the navmesh but do not guarantee identical
139
+ results after a load. The push routes around nothing and only keeps NPCs from overlapping. For replays and saves use the push; for crowds going
140
+ around big obstacles use crowd.
142
141
  - Behaviors you write are not avoided automatically: after your own `character.move`, call `engine.npcs.avoid.push(rec, npc.character, dt)` once
143
142
  (inside `near`, before writing back to the data).
144
143
 
@@ -146,7 +145,7 @@ engine.npcs.avoid.set(false); // turn off (ghosts, cro
146
145
  ## A guard you build yourself (`Character` + `walkTo`)
147
146
 
148
147
  For a one-off (guard, pet, follower) that `schedule` / `wander` do not cover: `new Character(engine, { rig })` takes a ready body
149
- (`{ root, body?, head?, limbs?, joints? }`), or `{ model: 'humanoid' }` picks a body asset like any character ([13-animation](13-animation.md)); call `character.animate(dt)` each frame.
148
+ (`{ root, body?, head?, limbs?, joints? }`), or `{ model: 'villager' }` / `{ model: ['villager', 0xcc8844] }` names a body your own asset pack registers (none ships with the engine; `humanoid` in other pages is such a name) like any character ([13-animation](13-animation.md)); call `character.animate(dt)` each frame.
150
149
  `character.walkTo(target, { speed, arrive, turnRate, run })` follows `characters.findPath` on fixed steps (turns at `turnRate` rad/s, skips passed
151
150
  points, re-plans when it makes no progress for `stuckSeconds`, up to `maxRepaths`). It returns a promise of `{ status }`: `'arrived'` | `'noPath'` |
152
151
  `'stuck'` | `'cancelled'` (never rejects), with `remove()` to cancel.
@@ -155,7 +154,8 @@ walk, and an escort quest that wants the same NPC takes control itself (`engine.
155
154
  editing its record.
156
155
 
157
156
  ```js
158
- const guard = new Character(engine, { rig: { root: myGuardMesh } }).addTo();
157
+ const guard = new Character(engine, { rig: { root: myGuardMesh } });
158
+ engine.add(guard.root);
159
159
  guard.placeAt(post);
160
160
  const walk = guard.walkTo(player.position, { arrive: 1.5 });
161
161
  if ((await walk).status === 'noPath') guard.face(player); // walk.remove() cancels
@@ -172,12 +172,11 @@ The dialogue's keys go through two ops, so code, tests and the dev bridge drive
172
172
  `npm run map` it shows up in the NPC table and dialogue graph of GAMEMAP.md.
173
173
  - State: `npm run shot -- / --time 13:10 --wait 20 --describe-only`; the "nearby" list has an entry for `Gate guard` tagged as an NPC with its distance in
174
174
  meters (only listed within 30 meters; add `--pos x,z` to stand by the tower).
175
- - Console / tests: `engine.npcs.get('guard').position`, `.currentStop()`; during a dialogue `engine.describe().ui.dialogue` = `{ speaker, text, typing, choices: [labels], lock }` (absent when no dialogue runs; the text version prints it as a `Dialogue:` line). `describe` does NOT expose the node id or the NPC id: `speaker` is the display name; to inspect the node, read the content file or listen to `engine.events.on("dialogue:line", ({ script, node, speaker, text }) => ...)` (also `dialogue:start` / `dialogue:end`).
175
+ - Console / tests: `engine.npcs.get('guard').position`, `.currentStop()`; during a dialogue `engine.describe().ui.dialogue` = `{ speaker, text, typing, choices: [labels], selected, advance }`. `describe` shows no node or NPC id: to inspect the node, listen to `engine.events.on("dialogue:line", ({ script, node, speaker, text }) => ...)` (also `dialogue:start` / `dialogue:end`).
176
+ - E opens a conversation; only confirm (Space / Enter) advances it, unless `dialogue({ advanceActions })` adds a key. `describe().ui.dialogue.advance` names the keys. While it is open game input is locked, so E on anything else does nothing: the press is logged as a refused `interaction.use` (`inputLocked`) in `engine.ops.recent()` and `threedog test` prints it under a failed spec.
176
177
  - Advancing a dialogue in a headless test (typing and "keys ignored right after opening" both run on game time): press E when near -> `engine.step(1)`
177
178
  to finish typing -> press a number key or run `engine.ops.run('dialogue.choose', { index: i })` (while typing it completes the sentence first) ->
178
179
  `engine.step(0.3)`. No real-time waiting.
179
- - Related tests: `npm test -- 小城` (the shopkeeper's schedule and dialogue), `npm test -- "S1 NPC"` (far-away simulation, changing level, saving,
180
- identical results after loading).
181
180
 
182
181
  ## Talking in a bubble instead of a conversation
183
182
  `interact: { op: 'npc.talk', args: { channel: 'bubble' } }` (code or content) makes the interact key play the NPC's script as bubble lines over its head while the player keeps