threedog 0.2.0 → 0.5.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 (596) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +83 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +190 -57
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +43 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +128 -0
  58. package/core/gridLoad.js +20 -0
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +101 -37
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +65 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +89 -97
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +224 -149
  126. package/docs/COMMANDS.md +57 -34
  127. package/docs/CONVENTIONS.md +92 -30
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +12 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +41 -25
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +65 -62
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +31 -29
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +30 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +12 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +71 -59
  180. package/docs/recipes/02-npc.md +46 -29
  181. package/docs/recipes/03-items-pickups.md +38 -24
  182. package/docs/recipes/04-quests.md +34 -27
  183. package/docs/recipes/05-props-bake.md +154 -18
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +41 -10
  186. package/docs/recipes/08-weather-sky.md +146 -37
  187. package/docs/recipes/09-style.md +218 -0
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +34 -10
  191. package/docs/recipes/14-custom-module.md +65 -34
  192. package/docs/recipes/15-perf.md +35 -6
  193. package/docs/recipes/16-dev-bridge.md +65 -41
  194. package/docs/recipes/18-world.md +21 -8
  195. package/docs/recipes/19-shooting-picking.md +12 -11
  196. package/docs/recipes/20-content-actions-save.md +63 -25
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +18 -18
  199. package/docs/recipes/23-ops.md +17 -11
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +12 -6
  202. package/docs/recipes/28-terrain.md +35 -2
  203. package/docs/recipes/29-grid.md +71 -33
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +27 -4
  208. package/docs/recipes/35-style-from-reference.md +115 -51
  209. package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
  210. package/docs/recipes/37-terrain-look-hooks.md +37 -15
  211. package/docs/recipes/38-environment-look-hooks.md +64 -48
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +3 -3
  215. package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
  216. package/docs/recipes/44-water-weather-look-hooks.md +30 -21
  217. package/docs/recipes/45-cascaded-shadows.md +17 -8
  218. package/docs/recipes/46-blender-art-route.md +4 -4
  219. package/docs/recipes/47-island-snow-backdrop.md +11 -10
  220. package/docs/recipes/48-make-material.md +11 -6
  221. package/docs/recipes/49-game-module-contract.md +46 -33
  222. package/docs/recipes/50-own-renderer.md +2 -2
  223. package/docs/recipes/51-capability-catalog.md +4 -4
  224. package/docs/recipes/52-look.md +228 -54
  225. package/docs/recipes/53-ground-up-close.md +58 -0
  226. package/docs/recipes/54-three-idioms.md +88 -0
  227. package/docs/recipes/55-mods-time-wrap.md +112 -0
  228. package/docs/recipes/56-webgpu-tsl.md +260 -0
  229. package/docs/recipes/57-control.md +65 -0
  230. package/docs/recipes/58-input.md +57 -0
  231. package/docs/recipes/59-depth-post-effects.md +83 -0
  232. package/docs/recipes/60-judge-the-picture.md +55 -0
  233. package/examples/action/.threedog/content-index.json +1 -0
  234. package/examples/action/GAMEMAP.md +17 -13
  235. package/examples/action/assets.js +8 -0
  236. package/examples/action/content/actions.js +1 -1
  237. package/examples/action/content/audio.js +5 -5
  238. package/examples/action/look.js +1 -1
  239. package/examples/action/main.js +10 -13
  240. package/examples/action/models.js +24 -23
  241. package/examples/pullable.json +111 -0
  242. package/examples/rc2d/.threedog/content-index.json +1 -0
  243. package/examples/rc2d/GAMEMAP.md +83 -0
  244. package/examples/rc2d/README.md +52 -0
  245. package/examples/rc2d/main.js +63 -0
  246. package/examples/rc2d/rc2d.js +197 -0
  247. package/examples/rc2d/shaders.js +144 -0
  248. package/examples/sheepisland/.threedog/content-index.json +1 -0
  249. package/examples/sheepisland/GAMEMAP.md +13 -11
  250. package/examples/sheepisland/assets.js +5 -0
  251. package/examples/sheepisland/main.js +17 -12
  252. package/examples/sheepisland/style/index.js +6 -6
  253. package/examples/styletest/.threedog/content-index.json +1 -0
  254. package/examples/styletest/GAMEMAP.md +15 -16
  255. package/examples/styletest/assets.js +6 -0
  256. package/examples/styletest/content/npcs.js +1 -1
  257. package/examples/styletest/content/templates.js +1 -1
  258. package/examples/styletest/content/vegetation.js +1 -1
  259. package/examples/styletest/look.js +1 -1
  260. package/examples/styletest/main.js +18 -17
  261. package/examples/styletest/models.js +1 -1
  262. package/examples/styletest/params.js +3 -3
  263. package/examples/techniques/contact-shadows/README.md +92 -0
  264. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  265. package/examples/techniques/contact-shadows/main.js +53 -0
  266. package/examples/techniques/day-night-grade/README.md +86 -0
  267. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  268. package/examples/techniques/day-night-grade/main.js +51 -0
  269. package/examples/techniques/interior-light/README.md +103 -0
  270. package/examples/techniques/interior-light/interiorLight.js +45 -0
  271. package/examples/techniques/interior-light/main.js +124 -0
  272. package/examples/techniques/modular-building/README.md +125 -0
  273. package/examples/techniques/modular-building/kit.js +426 -0
  274. package/examples/techniques/modular-building/main.js +47 -0
  275. package/examples/techniques/night-lights/README.md +94 -0
  276. package/examples/techniques/night-lights/main.js +70 -0
  277. package/examples/techniques/night-lights/nightLights.js +91 -0
  278. package/examples/techniques/outlines-and-rim/README.md +59 -0
  279. package/examples/techniques/outlines-and-rim/main.js +84 -0
  280. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  281. package/examples/techniques/procedural-animation/README.md +77 -0
  282. package/examples/techniques/procedural-animation/creature.js +44 -0
  283. package/examples/techniques/procedural-animation/main.js +45 -0
  284. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  285. package/examples/techniques/procedural-surface/README.md +67 -0
  286. package/examples/techniques/procedural-surface/main.js +103 -0
  287. package/examples/techniques/procedural-surface/surface.js +120 -0
  288. package/examples/techniques/stylized-shading/README.md +75 -0
  289. package/examples/techniques/stylized-shading/main.js +93 -0
  290. package/examples/techniques/stylized-shading/shading.js +131 -0
  291. package/examples/techniques/sun-and-key-light/README.md +135 -0
  292. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  293. package/examples/techniques/sun-and-key-light/main.js +95 -0
  294. package/examples/techniques/wet-road/README.md +99 -0
  295. package/examples/techniques/wet-road/main.js +68 -0
  296. package/examples/techniques/wet-road/wetRoad.js +209 -0
  297. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  298. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  299. package/examples/webgpu-tsl/README.md +42 -0
  300. package/examples/webgpu-tsl/main.js +21 -0
  301. package/examples/webgpu-tsl/tslScene.js +75 -0
  302. package/examples/world/.threedog/content-index.json +1 -0
  303. package/examples/world/GAMEMAP.md +22 -15
  304. package/examples/world/art/humanoid.js +42 -0
  305. package/examples/world/art/index.js +11 -0
  306. package/examples/world/art/models.js +58 -0
  307. package/examples/world/art/shapes.js +9 -0
  308. package/examples/world/assets.js +6 -0
  309. package/examples/world/content/audio.js +5 -5
  310. package/examples/world/content/npcs.js +2 -2
  311. package/examples/world/content/props.js +1 -1
  312. package/examples/world/content/rules.js +1 -1
  313. package/examples/world/content/templates.js +1 -1
  314. package/examples/world/content/vegetation.js +1 -1
  315. package/examples/world/main.js +17 -13
  316. package/examples/world/style/index.js +61 -0
  317. package/examples/world/style/plugins/10-bloom.js +5 -0
  318. package/index.d.ts +50 -45
  319. package/index.js +27 -22
  320. package/llms.txt +20 -12
  321. package/modules/ambience/Ambience.js +34 -23
  322. package/modules/calendar/Calendar.js +163 -0
  323. package/modules/calendar/contract.js +21 -0
  324. package/modules/calendar/index.js +81 -0
  325. package/modules/{sky → calendar}/schedule.js +17 -16
  326. package/modules/calendar/seasons.js +55 -0
  327. package/modules/camera/FirstPersonCamera.js +6 -15
  328. package/modules/camera/FixedCamera.js +33 -15
  329. package/modules/camera/FollowCamera.js +90 -16
  330. package/modules/camera/RtsCamera.js +18 -17
  331. package/modules/camera/common.js +70 -19
  332. package/modules/camera/contract.js +17 -0
  333. package/modules/camera/projection.js +11 -24
  334. package/modules/characters/Character.js +196 -59
  335. package/modules/characters/NPC.js +87 -36
  336. package/modules/characters/assetModel.js +27 -8
  337. package/modules/characters/behaviors.js +2 -1
  338. package/modules/characters/contract.js +13 -0
  339. package/modules/characters/footsteps.js +1 -1
  340. package/modules/characters/index.js +87 -49
  341. package/modules/characters/moveHelpers.js +4 -5
  342. package/modules/characters/movers/common.js +97 -19
  343. package/modules/characters/movers/manual.js +20 -0
  344. package/modules/characters/movers/rapier.js +19 -16
  345. package/modules/characters/movers/simple.js +14 -11
  346. package/modules/characters/movers/support.js +172 -0
  347. package/modules/characters/npcAvoid.js +47 -42
  348. package/modules/characters/npcSim.js +12 -8
  349. package/modules/characters/npcView.js +44 -16
  350. package/modules/characters/pathAsync.js +7 -3
  351. package/modules/characters/playerStrings.js +4 -3
  352. package/modules/characters/proceduralRig.js +46 -10
  353. package/modules/characters/useModel.js +1 -1
  354. package/modules/characters/vehicle.contract.js +21 -0
  355. package/modules/characters/walkTo.js +21 -7
  356. package/modules/collision/Collision.js +65 -25
  357. package/modules/collision/grid.js +8 -6
  358. package/modules/content/explain.js +2 -2
  359. package/modules/content/fields.js +102 -0
  360. package/modules/content/ids.js +8 -6
  361. package/modules/content/index.js +97 -28
  362. package/modules/content/loader.js +45 -33
  363. package/modules/content/models.js +11 -40
  364. package/modules/content/packs.js +6 -5
  365. package/modules/content/parts.js +41 -0
  366. package/modules/content/props.js +16 -9
  367. package/modules/content/rules.js +58 -0
  368. package/modules/content/stages.js +80 -0
  369. package/modules/content/templates.js +121 -30
  370. package/modules/debug/DebugPanel.js +24 -17
  371. package/modules/flow/contract.js +16 -0
  372. package/modules/flow/index.js +21 -15
  373. package/modules/gameplay/Container.js +41 -32
  374. package/modules/gameplay/Containers.js +30 -15
  375. package/modules/gameplay/Dialogue.js +113 -55
  376. package/modules/gameplay/Interactions.js +193 -67
  377. package/modules/gameplay/Inventory.js +69 -73
  378. package/modules/gameplay/Quests.js +75 -39
  379. package/modules/gameplay/boxOps.js +3 -3
  380. package/modules/gameplay/dialogue.contract.js +21 -0
  381. package/modules/gameplay/dialogueBox.js +4 -2
  382. package/modules/gameplay/dialogueBubbles.js +116 -0
  383. package/modules/gameplay/interactionPrompt.js +4 -1
  384. package/modules/gameplay/interactions.contract.js +16 -0
  385. package/modules/gameplay/inventory.contract.js +23 -0
  386. package/modules/gameplay/inventoryOps.js +18 -16
  387. package/modules/gameplay/pickups.js +268 -85
  388. package/modules/gameplay/questLog.js +4 -4
  389. package/modules/gameplay/quests.contract.js +17 -0
  390. package/modules/grid/Grid.js +92 -50
  391. package/modules/grid/Layer.js +14 -13
  392. package/modules/grid/index.js +60 -36
  393. package/modules/grid/ops.js +20 -18
  394. package/modules/grid/preview.js +15 -16
  395. package/modules/grid/strings.js +12 -0
  396. package/modules/grid/tiles.js +6 -5
  397. package/modules/hlod/index.js +51 -19
  398. package/modules/hud/index.js +35 -20
  399. package/modules/hud/parts.js +20 -7
  400. package/modules/level/heightfield.js +3 -1
  401. package/modules/level/index.js +45 -20
  402. package/modules/level/nodes.js +4 -3
  403. package/modules/lights/index.js +42 -18
  404. package/modules/music/Music.js +38 -21
  405. package/modules/music/rules.js +1 -1
  406. package/modules/nav/index.js +48 -42
  407. package/modules/net/Client.js +13 -6
  408. package/modules/net/Host.js +19 -5
  409. package/modules/net/Net.js +2 -1
  410. package/modules/net/index.js +13 -8
  411. package/modules/net/sync.js +9 -8
  412. package/modules/net/transports.js +77 -27
  413. package/modules/particles/Particles.js +23 -14
  414. package/modules/particles/contract.js +17 -0
  415. package/modules/particles/effect.js +39 -11
  416. package/modules/photo/Photo.js +53 -36
  417. package/modules/rigid/RigidBodies.js +194 -32
  418. package/modules/rigid/Vehicles.js +18 -15
  419. package/modules/rigid/sync.js +62 -17
  420. package/modules/settings/Settings.js +57 -52
  421. package/modules/settings/apply.js +38 -3
  422. package/modules/settings/sections.js +5 -3
  423. package/modules/settings/strings.js +3 -2
  424. package/modules/settings/view.js +5 -3
  425. package/modules/sky/Sky.js +88 -176
  426. package/modules/sky/cascades.js +86 -25
  427. package/modules/sky/cascades.tsl.js +82 -0
  428. package/modules/sky/clouds.js +34 -19
  429. package/modules/sky/domeLayers.js +30 -15
  430. package/modules/sky/environment.js +83 -13
  431. package/modules/sky/fog.js +140 -95
  432. package/modules/sky/frame.js +112 -44
  433. package/modules/sky/look.js +22 -19
  434. package/modules/sky/lookFog.js +48 -52
  435. package/modules/sky/lookShadow.js +53 -41
  436. package/modules/sky/lookSky.js +82 -21
  437. package/modules/sky/season.js +21 -0
  438. package/modules/sky/shader.js +41 -19
  439. package/modules/sky/shadow.js +44 -20
  440. package/modules/sky/skyModule.js +45 -33
  441. package/modules/sky/tint.js +61 -0
  442. package/modules/terrain/ChunkManager.js +175 -108
  443. package/modules/terrain/chunkJob.js +1 -1
  444. package/modules/terrain/chunkQueries.js +6 -4
  445. package/modules/terrain/index.js +105 -50
  446. package/modules/terrain/look.js +83 -0
  447. package/modules/terrain/lookGround.js +21 -16
  448. package/modules/terrain/terrainDefaults.js +1 -1
  449. package/modules/terrain/terrainEdit.js +18 -20
  450. package/modules/terrain/terrainGen.js +5 -3
  451. package/modules/terrain/terrainIsland.js +5 -4
  452. package/modules/terrain/terrainShape.js +12 -12
  453. package/modules/terrain/terrainShapeMain.js +8 -7
  454. package/modules/terrain/terrainTexture.js +21 -19
  455. package/modules/timeline/Timeline.js +95 -43
  456. package/modules/timeline/Tween.js +18 -10
  457. package/modules/timeline/letterbox.js +2 -2
  458. package/modules/timeline/shots.js +5 -1
  459. package/modules/triggers/index.js +107 -76
  460. package/modules/vegetation/Vegetation.js +190 -102
  461. package/modules/vegetation/densityMap.js +62 -0
  462. package/modules/vegetation/groundChunks.js +52 -58
  463. package/modules/vegetation/index.js +31 -10
  464. package/modules/vegetation/look.js +119 -0
  465. package/modules/vegetation/lookWind.js +71 -10
  466. package/modules/vegetation/modelGeometry.js +3 -2
  467. package/modules/vegetation/nearFade.js +45 -0
  468. package/modules/water/Water.js +65 -27
  469. package/modules/water/look.js +29 -18
  470. package/modules/water/surface.js +64 -25
  471. package/modules/water/surfaceDefaults.js +3 -0
  472. package/modules/weather/Weather.js +62 -104
  473. package/modules/weather/look.js +1 -2
  474. package/modules/weather/particles.js +24 -9
  475. package/modules/weather/strings.js +2 -2
  476. package/modules/weather/weatherLook.js +135 -0
  477. package/modules/world/World.js +24 -7
  478. package/modules/world/explain.js +1 -1
  479. package/modules/world/index.js +18 -4
  480. package/modules/world/persist.js +62 -2
  481. package/modules/world/pos.js +3 -2
  482. package/modules/world/records.js +8 -6
  483. package/modules/world/sim.js +60 -20
  484. package/modules/world/simFar.js +4 -3
  485. package/modules/world/state.js +3 -2
  486. package/modules/world/thingSource.js +1 -1
  487. package/modules/world/views.js +7 -5
  488. package/package.json +8 -3
  489. package/presets.js +41 -27
  490. package/render/PostFX.js +145 -120
  491. package/render/backend.js +440 -0
  492. package/render/detail.js +150 -45
  493. package/render/effects.js +130 -38
  494. package/render/engineUniforms.js +10 -1
  495. package/render/fuse.js +5 -4
  496. package/render/fx/cloudShadow.tsl.js +16 -0
  497. package/render/fx/detail.tsl.js +66 -0
  498. package/render/fx/index.js +26 -0
  499. package/render/fx/lighting.tsl.js +28 -0
  500. package/render/fx/nodeErrors.tsl.js +68 -0
  501. package/render/fx/noise.tsl.js +12 -0
  502. package/render/fx/objectOrigin.tsl.js +42 -0
  503. package/render/fx/particles.tsl.js +139 -0
  504. package/render/fx/patchNodes.tsl.js +403 -0
  505. package/render/fx/postWebGPU.tsl.js +158 -0
  506. package/render/fx/season.tsl.js +13 -0
  507. package/render/fx/sky.tsl.js +260 -0
  508. package/render/fx/uniforms.tsl.js +67 -0
  509. package/render/fx/water.tsl.js +53 -0
  510. package/render/fx/wind.tsl.js +22 -0
  511. package/render/fxNumbers.js +36 -0
  512. package/render/hotGlsl.js +24 -0
  513. package/render/lighting.js +66 -14
  514. package/render/lights.js +223 -4
  515. package/render/lookGlow.js +139 -0
  516. package/render/lookSurface.js +99 -36
  517. package/render/materials.js +71 -52
  518. package/render/modeling.js +73 -0
  519. package/render/ownFrame.js +76 -0
  520. package/render/patches.js +311 -34
  521. package/render/postLook.js +124 -46
  522. package/render/postWebGL.js +197 -0
  523. package/render/probes.js +231 -0
  524. package/render/shaderErrors.js +154 -0
  525. package/render/slots.js +165 -0
  526. package/render/surface.js +53 -17
  527. package/render/terms.js +211 -0
  528. package/render/uniformDecl.js +3 -2
  529. package/types/common.d.ts +2 -2
  530. package/types/core.d.ts +620 -244
  531. package/types/gameplay.d.ts +494 -318
  532. package/types/generated/core/Audio.d.ts +26 -42
  533. package/types/generated/core/Batching.d.ts +6 -2
  534. package/types/generated/core/Budget.d.ts +2 -8
  535. package/types/generated/core/DebugOverrides.d.ts +44 -3
  536. package/types/generated/core/I18n.d.ts +2 -2
  537. package/types/generated/core/Input.d.ts +102 -31
  538. package/types/generated/core/Ops.d.ts +31 -0
  539. package/types/generated/core/Random.d.ts +2 -2
  540. package/types/generated/core/Saves.d.ts +10 -2
  541. package/types/generated/core/Stream.d.ts +1 -1
  542. package/types/generated/core/Threads.d.ts +4 -1
  543. package/types/generated/core/Views.d.ts +0 -1
  544. package/types/generated/core/audioVoice.d.ts +17 -9
  545. package/types/generated/core/control.d.ts +55 -0
  546. package/types/generated/core/session.d.ts +2 -1
  547. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  548. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  549. package/types/generated/modules/calendar/index.d.ts +10 -0
  550. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  551. package/types/generated/modules/grid/Grid.d.ts +61 -25
  552. package/types/generated/modules/grid/Layer.d.ts +5 -5
  553. package/types/generated/modules/grid/index.d.ts +29 -17
  554. package/types/generated/modules/music/Music.d.ts +5 -3
  555. package/types/generated/modules/net/index.d.ts +3 -3
  556. package/types/generated/modules/net/transports.d.ts +12 -3
  557. package/types/generated/modules/particles/Particles.d.ts +1 -1
  558. package/types/generated/modules/sky/Sky.d.ts +12 -104
  559. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  560. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  561. package/types/generated/modules/weather/Weather.d.ts +17 -18
  562. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  563. package/types/generated/modules/world/World.d.ts +18 -3
  564. package/types/generated/render/PostFX.d.ts +67 -30
  565. package/types/generated/render/materials.d.ts +26 -20
  566. package/types/generated/render/modeling.d.ts +30 -0
  567. package/types/generated/render/patches.d.ts +16 -2
  568. package/types/generated/ui/UI.d.ts +6 -3
  569. package/types/nav.d.ts +6 -0
  570. package/types/physics.d.ts +137 -44
  571. package/types/style.d.ts +125 -92
  572. package/types/tsl.d.ts +86 -0
  573. package/types/world.d.ts +164 -110
  574. package/ui/Focus.js +25 -14
  575. package/ui/LoadingScreen.js +1 -1
  576. package/ui/Parts.js +27 -11
  577. package/ui/UI.js +20 -10
  578. package/ui/cursor.js +115 -0
  579. package/ui/defaults.js +15 -11
  580. package/ui/theme.js +9 -6
  581. package/ui/touchPart.js +1 -1
  582. package/core/claims.js +0 -51
  583. package/core/look/layers.js +0 -136
  584. package/core/renamed.js +0 -21
  585. package/docs/api/entities.md +0 -61
  586. package/docs/recipes/09-style-pack.md +0 -234
  587. package/examples/styletest/overrides.js +0 -33
  588. package/examples/styletest/panel.js +0 -135
  589. package/modules/entities/Entities.js +0 -243
  590. package/modules/entities/build.js +0 -25
  591. package/modules/entities/index.js +0 -4
  592. package/modules/sky/calendar.js +0 -80
  593. package/modules/sky/layers.js +0 -69
  594. package/modules/terrain/chunkLevels.js +0 -40
  595. package/modules/terrain/mountTerrain.js +0 -32
  596. package/modules/world/cells.js +0 -42
package/docs/api/style.md CHANGED
@@ -1,24 +1,24 @@
1
- # Style pack Style — createEngine({ style }), all the look (example: @threedog/style-lowpoly, packages/styles/lowpoly/index.js)
1
+ # Style — createEngine({ style }), all the look (any style: a folder with index.js; recipes/09-style.md)
2
2
 
3
3
  - **Style** fields (all optional):
4
- - `name?: string` Style pack name
5
- - `exposure?: number | number[][] | ((sky: any) => number)` Exposure, default 1 (lowpoly: 1.05): a number, or over the day [[time 0-1, exposure], ...] (sorted, wraps across midnight) or (sky) => number, evaluated by the sky module every frame. engine.look.tone.set changes it at run time. Example: `exposure: [[0, 1.6], [0.3, 1], [0.75, 1.1]] // brighter nights`
6
- - `toneMapping?: Loose<'aces' | 'agx' | 'neutral' | 'none'>` Tone mapping. Engine default 'none' (no style pack, no tone mapping); the style pack picks the look (lowpoly: 'aces')
4
+ - `name?: string` Style name
5
+ - `exposure?: number | number[][] | ((ctx: LookContext) => number)` Exposure, default 1: a number, or over the day [[time 0-1, exposure], ...] (sorted, wraps across midnight) or ({ time, state, sky }) => number, evaluated by the sky module every frame. engine.look.tone.set changes it at run time. Example: `exposure: [[0, 1.6], [0.3, 1], [0.75, 1.1]] // brighter nights`
6
+ - `toneMapping?: Loose<'aces' | 'agx' | 'neutral' | 'none'>` Tone mapping curve, written once when the engine creates its renderer (default 'agx', the render baseline). Later changes are plain three.js: engine.renderer.toneMapping = THREE.ACESFilmicToneMapping; the engine never writes it again
7
7
  - `background?: ColorLike` Background color (when there is no sky module)
8
- - `post?: (Omit<import('./generate… & { slot? })[]` Post effects registered at startup, in any order (slot and order decide where each runs), e.g. [outline({ enabled: true }), bloom()] from '@threedog/post-effects'
9
- - `materials?: Record<string, MaterialSpec | import('three').Material | ((…` Material per role (default, terrain, vegetation, character, water, building, pickup…): a spec, a three.js Material instance (cloned per use), or a function (params, purpose) => Material
8
+ - `materials?: Record<string, MaterialSpec | import('three').Material | ((…` Material per role (default, terrain, vegetation, character, water, building, pickup…): a spec, a three.js Material instance (cloned per use), or a function (params, purpose) => Material. This table is the style layer of engine.look.materials (the one entry makeMaterial reads): the game's look.materials.set / replace go on top
9
+ - `plugins?: Record<string, any>` The style's own look plugins: what engine.plugins.add takes (import.meta.glob('./plugins/*.js', { eager: true }) from the style folder, or { name: { default: value } }), each file exporting the same shapes as the game's plugins/ folder. Example: `plugins: import.meta.glob('./plugins/*.js', { eager: true })`
10
10
  - `antialias?: boolean` Anti-aliasing: true = MSAA (also inside post-processing), false = off (pixel art, sharp edges). Default: on for desktop, off for low tier; createEngine({ antialias }) wins
11
11
  - `lighting?: MaterialLighting` Light shaping for every lit material of the pack (shadow tint, rim, wrap, glsl); a material's `lighting` wins, `lighting: false` opts out
12
12
  - `seasons?: StyleSeasons` Seasonal tint: { spring: { foliage, ground }, ... }. mode 'multiply' (default) multiplies the color onto the surface (pick tints near white: orange times green is muddy); 'mix' moves the surface `strength` (0-1, default 0.5) of the way to the color. Season names are the other keys, so none can be called mode or strength
13
- - `clouds?: { shadow?: number; scale?: number; speed?: number[] }` Cloud shadow: shadow darkest level 0–1 (default 0 = no cloud shadows; lowpoly 0.55), scale cloud size (smaller means bigger clouds), speed [x, z]
14
- - `palette?: Record<string, ColorLike>` Named colors the procedural model generators read (trees, rocks, grass: a generator written with `function` gets them as this.palette; lowpoly keys: bark, pine, leaf, rock, grassTip...). One place to retint all of them, e.g. style: [lowpoly, { palette: { leaf: 0xd98a3a } }]; keys left out keep the pack's values
13
+ - `clouds?: { shadow?: number; scale?: number; speed?: number[] }` Cloud shadow: shadow darkest level 0–1 (default 0 = no cloud shadows), scale cloud size (smaller means bigger clouds), speed [x, z]
14
+ - `palette?: Record<string, ColorLike>` Named colors the procedural model generators read (trees, rocks, grass: a generator written with `function` gets them as this.palette; a pack may use keys like bark, pine, leaf, rock, grassTip...). One place to retint all of them, e.g. style: [basePack, { palette: { leaf: 0xd98a3a } }]; keys left out keep the pack's values
15
15
  - `wind?: StyleWind` Wind: frequency sway frequency multiplier
16
16
  - `terrain?: StyleTerrain` Terrain colors etc.
17
17
  - `sky?: StyleSky` Sky
18
18
  - `weather?: StyleWeather` Weather look
19
19
  - `water?: StyleWater` Water look
20
- - `pickup?: { color?, size?, lift?, model? }` Default look of pickups on the ground: color (the item's own color wins), size (meters), lift height above ground (meters), model(item, { color, size }, engine) builds the shape (a geometry gets materials.pickup; make materials with engine.makeMaterial; without model a plain box)
21
- - `character?: { model?, colors?, create?, animation? }` Default character: colors palette; create(engine, colors) returns the procedural character (without it a gray capsule); model names a registered model asset every character uses unless it passes its own model (the procedural body shows until it loads); animation.fade skeletal animation transition seconds
20
+ - `pickup?: { color?: ColorLike; size?: number; lift?: number }` Default look of pickups on the ground: color (the item's own color wins), size (meters, of the gray placeholder box), lift height above ground (meters). The shape is not style: it is a model name from an asset pack (item model, else 'pickup:<item>', else 'pickup'); a generator that returns bare geometry is shaded by materials.pickup in the item's color
21
+ - `character?: { animation?: { fade?: number } }` How character motion looks: animation.fade skeletal animation transition seconds. Bodies are assets, not style ({ model: 'yourBody' } from an asset pack); a style tints body parts through materials roles (cloth, skin, trousers, hair).
22
22
  - `ui?: StyleUI` UI colors, fonts, templates
23
23
  - `particles?: Record<string, ParticleOptions>` Particle presets: name → parameters; default is the fallback for all effects
24
24
  - `triggers?: { debugColor?: ColorLike; debugOpacity?: number }` Trigger zone debug wireframe
@@ -26,9 +26,9 @@
26
26
 
27
27
  ## Sub-structures
28
28
  - **StyleSky**
29
- - `keyframes?: SkyKeyframe[]` Colors and light intensities at each time of day
30
- - `backdrop?: ColorLike | ((sky: Sky) => ColorLike)` A flat background color in place of the dome (no gradient, horizon line, sun / moon disk, stars or clouds), or (sky) => color per frame. Drawn as written (no tone mapping); the keyframes still light the world; fog in its default horizon color follows it (a fog.color of your own still wins). Leave out for the dome. Not with skybox. recipes/47. Example: `backdrop: sky => sky.isDay ? 0xefebe4 : 0x2c3346`
31
- - `sunSize?: number` Larger means a smaller sun, default 900
29
+ - `keyframes?: SkyKeyframe[]` Rows [time, zenith, horizon, lightColor, lightIntensity, ambient]. time: share of the day (0 = 00:00, 0.5 = noon), sorted, first row 0, last 1 (midnight again: same values as 0). horizon is also the fog color. light*: engine.lights.sun (the moon at night). ambient: the hemisphere fill, also dims the room environment (recipe 08). Example: `[[0, 0x0b1030, 0x1c2440, 0x8090c0, 0.3, 0.25], [0.5, 0x5a8fd0, 0xbcd4ea, 0xfff4e0, 3, 1.1], [1, 0x0b1030, 0x1c2440, 0x8090c0, 0.3, 0.25]]`
30
+ - `backdrop?: ColorLike | ((ctx: LookContext) => ColorLike)` A flat background color in place of the dome (no gradient, horizon line, sun / moon disk, stars or clouds), or ({ time, weather, season, state, sky }) => color per frame. Drawn as written (no tone mapping); the keyframes still light the world; fog in its default horizon color follows it (a fog.color of your own still wins). Leave out for the dome. Example: `backdrop: ({ sky }) => sky.isDay ? 0xefebe4 : 0x2c3346`
31
+ - `sunSize?: number` Sharpness exponent of the sun disk, default 900 (about 2 deg); larger = smaller. Not a size in degrees: 10 is ~20 deg, under ~3 the "disk" washes most of the sky toward the sun color
32
32
  - `sunGlow?: number` Sun glow, default 0.18
33
33
  - `sunBrightness?: number` Sun brightness, default 6
34
34
  - `moonSize?: number` Larger means a smaller moon
@@ -36,26 +36,27 @@
36
36
  - `moonBrightness?: number`
37
37
  - `orbitTilt?: number` North-south tilt of the sun path
38
38
  - `orbitSway?: number` East-west swing of the sun path
39
- - `starDensity?: number` Star density
40
- - `starScale?: number` Larger means smaller and more numerous stars
41
- - `gradientCurve?: number` Gradient curve from zenith to horizon
39
+ - `starDensity?: number` Share of the sky grid cells (0-1) that hold a star at night, default 0.0025 (0 = no stars). A probability, not a brightness: near 1 every cell is lit and the upper sky turns into a white sheet. The cell size is starScale
40
+ - `starScale?: number` Star grid resolution (cells per unit of view direction), default 260: larger means smaller and more numerous stars
41
+ - `dim?: { tint?: boolean; stars?: boolean }` What the sky dims for every game unless the style says no (each default true; false turns that one off, the rest stay). The one place these look decisions are switched: - tint: a sky.tint color (weather grey, a cave tint) dims with the sky's own light, so a grey rain tint stays dark at night. Example: `style.sky.dim = { stars: false } // or engine.look.sky.set({ dim: { tint: false } })`
42
+ - `gradientCurve?: number` Gradient curve from horizon to zenith, default 0.55 (color = mix(horizon, zenith, elevation^curve), mixed in linear light, then tone mapped and exposed like the scene).
42
43
  - `groundTint?: ColorLike` Ground bounce color of the ambient light
43
44
  - `clouds?: StyleSkyClouds` Clouds in the sky (cloud cover follows the weather); see StyleSkyClouds
44
- - `skybox?: string` Panorama (equirectangular) replacing the gradient sky, asset name or path
45
+ - `skybox?: string` Panorama (equirectangular) replacing the gradient sky, asset name or path (at run time engine.look.sky.replace(name))
45
46
  - `shadow?: StyleShadow` Shadows: mapSize resolution (pixels), extent coverage (meters), etc., see StyleShadow
46
47
  - `environment?: StyleEnvironment` Environment lighting (scene.environment), off unless a source is given; see engine.look.env. A pack can give defaults, sky({ environment }) overrides
47
48
  - `fog?: StyleFog` Fog model and color (default: linear fog in the horizon color); see StyleFog
48
49
  - `layers?: StyleSkyLayer[]` Extra dome layers drawn after the clouds and stars (rainbow, aurora), default none; see StyleSkyLayer
49
- - **StyleShadow**
50
+ - **StyleShadow** Sun shadow parameters (defaults are the current look)
50
51
  - `mapSize?: number` Shadow resolution (pixels), default 2048
51
52
  - `extent?: number` Coverage radius (meters), default 70
52
53
  - `distance?: number` Distance of the light from the shadow center (meters), default 160
53
- - `bias?: number` Anti shadow-acne bias, default -0.0006
54
+ - `bias?: number` Anti shadow-acne depth bias (0-1 shadow depth over the 419 m light range: -0.00005 = 2 cm), default -0.00005
54
55
  - `normalBias?: number` Normal-offset anti-acne, default 0.04
55
56
  - `updateEvery?: number` Update shadows every N frames, default 1 (every frame); larger saves more, still updates promptly when the focus moves
56
57
  - `snap?: number | 'texel'` Shadow center snapping grid (meters), default 0.5; 'texel' snaps to shadow pixels (shadow edges do not shimmer while moving)
57
58
  - `ahead?: number` How far ahead of the view direction the shadow center is shifted (meters), default 0
58
- - `type?: Loose<'basic' | 'pcf' | 'vsm'>` Shadow filter: 'basic' (hard edge, cheapest) / 'pcf' (default, soft edge) / 'vsm' (softest, costliest). Default: the engine's shadowType option
59
+ - `type?: Loose<'basic' | 'pcf' | 'vsm'>` Shadow filter: 'basic' (hard edge, cheapest) / 'pcf' (default, soft edge) / 'vsm' (softest, costliest). Default 'pcf' (look.shadow type)
59
60
  - `radius?: number` Edge softness for 'pcf' and 'vsm' (no effect on 'basic'), default 1
60
61
  - `blurSamples?: number` Blur sample count, 'vsm' only, default 8
61
62
  - `cascades?: number` Cascaded shadows (recipes/45): 1 (default) = one shadow map around the focus, the plain path; 2-4 split the sun's shadow along the view, sharp near the camera and wide far away. Each cascade draws the casters once more. Low-tier devices stay at 1 unless low.cascades says so. Example: `shadow: { cascades: 3, maxFar: 150, low: { cascades: 2, fade: false } } // low-tier devices: 2 cascades instead of one map`
@@ -73,11 +74,10 @@
73
74
  - `snow?: StyleWeatherSnow` Snow particles (default round sprites: color 0xffffff, opacity 0.9, size 20, maxSize 5 px, speed 1.6 m/s, sway 1.5 m)
74
75
  - `types?: Record<string, Partial<WeatherPreset>>` Retune the look of weather types the game has (e.g. a darker storm); never adds a type: the list is the game's weather({ types })
75
76
  - **StyleWater**
76
- - `material?: (engine, ctx) => Material` Replace the whole water surface material (the built-in role 'water', waves and fresnel are skipped). Receives the shared uniforms (uTime, uWave, uWaveScale, uWaveSpeed), the built-in wave patch, the surface patch (depthColor / foam / glsl.surface; null without them; put it after waves) and the scrolling normal map (null without one). Example: `material: (engine, { waves }) => applyEffects(new THREE.MeshToonMaterial({ color: 0x3a8acf }), { clouds: false, patches: [waves] })`
77
+ - `material?: (engine, ctx) => Material` Replace the whole water surface material (the built-in role 'water', waves and fresnel are skipped). Receives the shared uniforms (uTime, uWave, uWaveScale, uWaveSpeed), the built-in wave patch, the surface patch (depthColor / foam / the 'surface' hook; null without them; put it after waves) and the scrolling normal map (null without one). Example: `material: (engine, { waves }) => applyEffects(new THREE.MeshToonMaterial({ color: 0x3a8acf }), { clouds: false, patches: [waves] })`
77
78
  - `depthColor?: StyleWaterDepth` Water color from the view angle (by 'view', default: shallow looking down, deep at grazing angles) or the wave height (by 'wave': shallow on crests); replaces color. curve shapes the blend (default 1)
78
- - `foam?: StyleWaterFoam | true` Crest foam from the wave height (start / end: fraction of glsl.waveMax where foam begins / is full, default 0.55 / 0.85); true = defaults. Shore foam needs depth: recipes/44
79
- - `glsl?: { wave?: string; surface?: string; waveMax?: number }` Your own GLSL. wave: `float threedogWaterWave(vec3 p, float t)` (p = world position * waveScale, t = time * waveSpeed) returns the height before waveHeight; waveMax = its peak (default 0.29), which foam and depthColor 'wave' divide by.
80
- - `uniforms?: Record<string, any>` Uniforms for your glsl, in both stages: numbers, colors, [x, y(, z, w)] arrays or textures; live in engine.water.material.uniforms
79
+ - `foam?: StyleWaterFoam | true` Crest foam from the wave height (start / end: fraction of waveMax (the 'wave' hook's, default 0.29) where foam begins / is full, default 0.55 / 0.85); true = defaults. Shore foam needs depth: recipes/44
80
+ - `uniforms?: Record<string, any>` Uniforms for your look.water hooks' GLSL, in both stages: numbers, colors, [x, y(, z, w)] arrays or textures; live in engine.water.material.uniforms
81
81
  - `color?: ColorLike`
82
82
  - `opacity?: number` Opacity 0–1
83
83
  - `flat?: boolean` Flat shading (low poly)
@@ -99,7 +99,7 @@
99
99
  - `variation?: { blend?, jitter?, patches? }` How ground colors vary (plain data, sent to the terrain workers). Every default is the original look; set only what you want to change. blend: the two-color noise (size = wavelength in meters, default 33; strength = contrast, default 1). Example: `variation: { blend: { size: 14 }, jitter: { range: 0.04 }, patches: { size: 60, strength: 0.25, levels: 4, tint: 0xb59a5a } }`
100
100
  - `config?: { shading?, colorResolution?, normals?, normalFn? }` Looks of the ground mesh only. shading: 'flat' one color and normal per triangle (facets) / 'smooth' (engine default) / 'texture' (per-chunk color map, colors independent of the mesh); colorResolution: color map pixels per chunk edge; normals: 'smooth' / 'flat' lighting in texture mode; normalFn: custom grid-point normal.
101
101
  - `material?: Material | ((engine: Engine) => Material)` Whole ground material: a Material or (engine) => Material (uv = world xz / chunk size; terrain({ material }) wins)
102
- - `detail?: { texture: string; scale?: number; strength?: number }` Ground detail texture: texture asset name, scale repeats per meter, strength 0–1
102
+ - `detail?: MaterialDetail` Detail layer over the ground, the same object as a material spec's `detail`: a noise ('grain' / 'paper' / 'stroke' / 'dabs'), a texture asset name, or your own `glsl`; plus scale, strength, fade ... (top-down world projection by default). Live: look.ground.set({ detail }). See recipes/53-ground-up-close.md
103
103
  - **StyleUI**
104
104
  - `bg?: string` Background color
105
105
  - `fg?: string` Text color
@@ -125,10 +125,12 @@
125
125
  - `ramp?: (number | ColorLike)[]` toon only: the light ramp, dark to light: grays 0-1 (light strength in the band) or colors (tint the band). Replaces steps
126
126
  - `soften?: number` toon only, with ramp: 0 = hard bands, up to 1 = the bands melt into each other
127
127
  - `color?: ColorLike`
128
- - `map?: string | import('three').Texture` Texture slots take an asset name: map, emissiveMap (sRGB), normalMap, roughnessMap, metalnessMap, aoMap, bumpMap, alphaMap, displacementMap... (linear). Loaded through engine.assets.texture, a neutral stand-in until the image arrives; the key must be a slot the type has (roughnessMap needs 'standard'). A THREE.Texture also works.
129
- - `normalMap?: string | import('three').Texture`
130
- - `roughnessMap?: string | import('three').Texture`
128
+ - `map?: TextureSlot` Texture slots take an asset name: map, emissiveMap (sRGB), normalMap, roughnessMap, metalnessMap, aoMap, bumpMap, alphaMap, displacementMap... (linear). Loaded through engine.assets.texture, a neutral stand-in until the image arrives; the key must be a slot the type has (roughnessMap needs 'standard').
129
+ - `normalMap?: TextureSlot`
130
+ - `roughnessMap?: TextureSlot`
131
+ - `aoMap?: TextureSlot`
132
+ - `lightMap?: TextureSlot`
131
133
  - `repeat?: number | [number, number]` How many times the textures of this material repeat (a number, or [x, y]); default 1
132
- - `wrap?: Loose<'repeat' | 'clamp' | 'mirror'>` Texture wrapping: 'repeat' (default) / 'clamp' / 'mirror'
134
+ - `wrap?: Loose<'repeat' | 'clamp' | 'mirror'>` Texture wrapping: 'repeat' (default for files loaded by name; your own textures keep theirs) / 'clamp' / 'mirror'
133
135
  - `detail?: MaterialDetail` Grain, paper, strokes or a texture laid over the surface in world space (no UVs needed); off unless given
134
136
  - `lighting?: MaterialLighting | false` Extra light shaping (shadow tint, rim, wrap, your own GLSL); merged over style.lighting, false opts out
@@ -1,16 +1,19 @@
1
1
  # engine.terrain — terrain(opts?: TerrainOptions)
2
2
 
3
- Procedural terrain (terrain() module)
3
+ Procedural terrain, data part (terrain() module: chunks, heights, edits, collision)
4
4
 
5
- - Options `TerrainOptions` (also includes the fields of Partial<TerrainConfig>):
5
+ - Options `TerrainOptions` (also includes the fields of Partial<Omit<TerrainConfig, 'normals'>>):
6
6
  - `viewChunks?: number` View distance (in chunks), default 4
7
7
  - `density?: number` Vegetation density multiplier, default 1
8
- - `viewFog?: boolean` true: the fog distance (engine.fogFar) follows the view distance so the far chunk edge fades out; default false keeps the game's fog (openWorld() sets true)
8
+ - `viewFog?: boolean` true: the fog distance (look.fog far, engine layer, owner 'terrainLook') follows the view distance so the far chunk edge fades out; default false keeps the game's fog (openWorld() sets true)
9
9
  - `material?: Material | ((engine: Engine) => Material)` Ground material (default style.terrain.material, else the 'terrain' role with vertex colors); chunks have uv = world xz / chunk size. Cloud shadows and season tint are added
10
+ - `effects?: boolean` With material: false = draw it exactly as given, no cloud shadow / season / detail patch (same as look.ground.replace(m, { effects: false }))
10
11
 
11
12
  ## Methods and properties
12
13
  - `terrain.setViewChunks(n: number)` — Change the view distance (in chunks); fog and camera far plane adjust too
13
- - `terrain.setDensity(d: number)` — Change the vegetation density (rebuilds all chunks)
14
+ - `terrain.setDensity(d: number)` — Change the vegetation density: plants are placed again on the loaded chunks; the ground and its collision stay
15
+ - `terrain.view(hooks: { add?, change?, remove?, show? }) → { remove(): void }` — Draw these chunks: the hooks a look that replaces 'terrain-look' uses. add(c): generated (c.data holds pos / nor / col / uv / tex arrays, c.cx / c.cz the chunk); change(c): an edit rewrote c.data (same vertex count); remove(c): released; show(c, visible): in view or not. Chunks already loaded are added at once. Returns { remove() } (ctx.track it). Example: `ctx.track(engine.terrain.view({ add(c) { draw(c) }, remove(c) { undraw(c) } }))`
16
+ - `terrain.retry() → number` — Send chunks that failed every try (terrain:chunkFailed) again, e.g. after fixing what their rule reads. Returns how many were queued
14
17
  - `terrain.rebuild()` — Rebuild all chunks
15
18
  - `terrain.edit(position: PositionLike, opts: TerrainEditOptions) → { heights: number; cells: number }` — (experimental) Change the ground: dig, raise, flatten, paint the ground type. Saved gameplay state: call it from an op or a fixed step. engine.surface / slope / groundType, collision, paths and vegetation follow at once; it is saved, and chunks generated later come out edited. Example: `engine.terrain.edit(pos, { radius: 3, lower: 1.5 }); // dig a pit engine.terrain.edit(pos, { shape: 'square', radius: engine.terrain.cellSize / 2, paint: 'tilled' }); // till one cell`
16
19
  - `terrain.isReadyAround(position: PositionLike, opts?: { rings?: number }) → boolean` — Whether the chunks within rings rings (default 1) around position are all loaded
@@ -18,11 +21,11 @@ Procedural terrain (terrain() module)
18
21
  - `T: TerrainGen` Pure-computation terrain (height, landform)
19
22
  - `CHUNK: number` Chunk edge length (meters)
20
23
  - `voidY: number` terrain({ shape }) only: below this height the player or a moving rigid body has fallen out of the world (one terrain:void per fall). shape.voidY, else 50 m under the lowest island chunk loaded so far; -Infinity without a shape. Example: `engine.events.on('terrain:void', ({ who }) => { if (who === engine.player) engine.player.placeAt(home); });`
21
- - `chunks: Map<string, any>` Loaded chunks: 'cx,cz' → chunk
24
+ - `chunks: Map<string, TerrainChunk>` Loaded chunks: 'cx,cz' → chunk
22
25
  - `viewChunks: number` View distance (in chunks)
23
26
  - `density: number` Vegetation density multiplier
24
27
  - `applyBudgetMs: number` Time budget (milliseconds) for uploading chunks per frame
25
- - `stats: { builtThisFrame, applyMs, queued, visible?, loaded?, instances? }` Statistics (for the debug panel)
28
+ - `stats: { builtThisFrame, applyMs, queued, failed, visible?, loaded?, … }` Statistics (for the debug panel); failed = chunks that failed every try (terrain:chunkFailed)
26
29
  - `cellSize: number` Grid spacing (meters) = chunkSize / resolution: edits snap to it, paint colors whole cells of this size
27
30
 
28
31
  ## Data structures
@@ -0,0 +1,10 @@
1
+ # engine.terrainLook — terrainLook()
2
+
3
+ Draws the terrain chunks (terrain()'s look module, slot 'terrain-look'; undefined when a game replaced it)
4
+
5
+
6
+ ## Methods and properties
7
+ - `terrainLook.setMaterial(m: Material)` — Swap the ground material on every loaded chunk at once (look.ground.replace uses it): nothing is regenerated, collision is untouched
8
+ - Properties:
9
+ - `material: Material` The ground material every chunk draws with
10
+ - `meshes: Map<TerrainChunk, { group: Object3D; mesh: Mesh; colorTex: …` chunk record -> { group, mesh, colorTex, colorMat }
@@ -2,11 +2,10 @@
2
2
 
3
3
  Cutscenes, tweens (timeline() module)
4
4
 
5
- - Options `TimelineOptions`:
6
- - `skipKeys?: string[]` Keys that skip a cutscene, default ['Escape', 'Backspace'] (Esc is the back key, which the UI focus stack hands to the topmost cutscene; cutscenes do not advance while frozen)
5
+ - Options `TimelineOptions`
7
6
 
8
7
  ## Methods and properties
9
- - `timeline.tween(target: any, to: TweenTo, duration?: number, ease?: Ease) → TweenPromise` — General tween (the only entry point for tweens in the engine): await engine.timeline.tween(mesh, { 'position.y': 2 }, 1, 'outCubic'); duration in seconds. Returns a Promise (with finish()/cancel())
8
+ - `timeline.tween(target: any, to: TweenTo, opts?: { duration?: number; ease?: Ease }) → TweenPromise` — General tween (the only entry point for tweens in the engine): await engine.timeline.tween(mesh, { 'position.y': 2 }, { duration: 1, ease: 'outCubic' }); duration in seconds (default 1), ease default 'inOutCubic'; tween(mesh, to, 1) throws in dev. Returns a Promise (with finish() / remove())
10
9
  - `timeline.play(steps: TimelineStep | TimelineStep[], opts?: TimelinePlayOptions) → Promise<{ skipped: boolean }>` — Play a timeline; resolves with { skipped } when it ends
11
10
  - `timeline.skip(run?: any)` — Skip all (or one) playing timelines
12
11
  - Properties:
@@ -32,7 +31,7 @@ Cutscenes, tweens (timeline() module)
32
31
  - **TimelinePlayOptions**
33
32
  - `skippable?: boolean` Can be skipped, default true
34
33
  - `letterbox?: boolean` Letterbox bars, default false
35
- - `lockInput?: boolean` Lock player input while playing, default true
34
+ - `actors?: any[]` The characters the cutscene drives (their control slot on layer 'cutscene'; keys / walks / NPC behaviours pause and come back after). Default: [engine.player] when there is a player; [] drives nobody (a bubble scene the player walks through). A path step adds its character
36
35
  - **CameraPose** One end point of a camera move
37
36
  - `position?: Vec3Like` Camera position
38
37
  - `lookAt?: Vec3Like | Object3D` The point to look at, or a moving object
package/docs/api/tools.md CHANGED
@@ -1,42 +1,45 @@
1
1
  # Utility functions (imported from threedog)
2
2
 
3
- - `postAdd(...effects: PostEffect[]) → Style` — A style part that adds post effects to the ones before it (a plain { post: [...] } would replace the whole list); an effect with the same name replaces that one in place. Style parts with it: createEngine({ style: [lowpoly, postAdd(myGrain, bloom({ strength: 0.6 }))] })
4
- - `postRemove(...names: string[]) → Style` — A style part that removes post effects by name from the ones before it: createEngine({ style: [lowpoly, postRemove('ao', 'outline')] })
5
- - `presets: { weather, calendar, player, interactions, keys, camera }` — Opt-in gameplay presets: named option objects a game picks on purpose (the engine never applies one itself). Each only bundles options the game could write; spread and override: weather({ ...presets.weather.temperate, autoPool: ['clear', 'rain'] })
3
+ - `weather(opts?: WeatherOptions) → [ModuleDef<Weather>, ModuleDef<im…` — Weather: two modules for one engine.use: the state (engine.weather, type 'world') and its look (engine.weatherLook, type 'look'; needs sky)
4
+ - `presets: { weather, calendar, player, interactions, bindings, camera }` — Opt-in gameplay presets: named option objects a game picks on purpose (the engine never applies one itself). Each only bundles options the game could write; spread and override: weather({ ...presets.weather.temperate, autoPool: ['clear', 'rain'] })
6
5
  - `world(opts?: { cellSize?, radius?, farEvery?, farMaxPerTick?, buildPerFrame? }) → import("../../../core").ModuleDef…` — World data module: installed as engine.world. Put things here that must be saved, survive level changes and keep changing while far away; models are only built while nearby
7
6
  - `net(opts?: { role, transport, sync?, syncEvery?, keepAlive?, rate?, … }) → import("../../../core").ModuleDef…` — (experimental) Optional co-op multiplayer: one host owns the state, clients mirror it and ask for changes through ops. Installed as engine.net. Host: peers' requests run as `ops.run(name, args, { source: 'net', actor })` only for ops defined with net: 'peer', with the op's args shape checked, the optional owner check, and a per-peer rate limit; the result comes back after the state diff that contains it. State: world records, containers, vars and the other save parts are sent as a snapshot on join and as diffs every syncEvery steps. Client: ops.run of a peer op returns { ok: true, pending: true, seq } (watch state or the net:result event, not the return value); its own avatar moves locally and is sent to the host (clamped to maxSpeed); other avatars glide between updates.
8
- - `fakeNetwork(opts?: { latency?, jitter?, loss?, seed?, manual? }) → { host, connect, advance, now, loss, latency, … }` — (experimental) An in-process network for tests and offline demos: one host and any number of clients in the same page, with optional latency, jitter and loss. Messages are deep-copied on send (no shared objects, like a real wire). Order per link is kept, as on a WebSocket. manual: true delivers only when you call advance(ms) (deterministic tests); otherwise messages land after real time.
9
- - `webSocket(url: string, { host, key }?: { host?: boolean; key?: string }) → { send, on, close, key, id }` — (experimental) WebSocket transport: talks to the relay in packages/tools/net-relay.mjs (`node packages/tools/net-relay.mjs 8787`). The host joins a room with host: true; clients join the same room. The relay assigns peer ids and remembers each client's key for reconnects. Messages are JSON. For a dedicated server or Colyseus, write another transport with the same send / on / close shape instead.
7
+ - `fakeNetwork(opts?: { latency?, jitter?, loss?, seed?, manual? }) → { host, connect, advance, now, loss, latency, … }` — (experimental) An in-process network for tests and offline demos: one host and any number of clients in the same page, with optional latency, jitter and loss. Messages are deep-copied on send (no shared objects, like a real wire). Order per link is kept, as on a WebSocket. manual: true delivers only when you call advance(ms) (deterministic tests); otherwise messages land after real time. connect({ heartbeat }) turns on the ping / pong check for that client (off by default here so loss and jitter replay the same); a client's cut() kills its link silently in both directions, which only the heartbeat notices (then the client gets 'close' and the host 'leave').
8
+ - `webSocket(url: string, { host, key, heartbeat, reconnect }?: { host?, key?, heartbeat?, reconnect? }) → { send, on, close, key, id }` — (experimental) WebSocket transport: talks to the relay in packages/tools/net-relay.mjs (`node packages/tools/net-relay.mjs 8787`). The host joins a room with host: true; clients join the same room. The relay assigns peer ids and remembers each client's key for reconnects. Messages are JSON. For a dedicated server or Colyseus, write another transport with the same send / on / close shape instead. heartbeat (ms, default 2000, 0 = off): ping the relay that often; 3 intervals with nothing received closes the link and emits 'close'. reconnect (clients only, default false): after a close, open again with the same key, waiting 0.5 s, 1 s, 2 s ... up to 15 s between tries; 'open' fires again on success (net() then asks the host for a full snapshot).
10
9
  - `grids() → import("../../../core").ModuleDef…` — (experimental) Grid placement module: installed as engine.grids. Needs world(). Adds the ops grid.place / grid.remove / grid.move and the save key 'grids' (layers).
11
10
  - `screenToGround(engine: Engine, ndcX: number, ndcY: number, opts?: { maxDistance?: number }) → Vector3 | null` — Screen coordinates (-1..1) -> point on the ground; null if the ray misses the ground
12
11
  - `EASINGS: Record<EaseName, (t: number) => number>` — All easing functions: name -> function
12
+ - `sampleGrid(data: ArrayLike<number>, opts: { width, height, cellSize?, size?, origin?, interp?, … }) → (x: number, z: number) => number` — A grid of numbers (height, moisture, density, walkable...) as a function (x, z) -> value. data[j * width + i] sits at origin + (i, j) * cell. interp 'nearest' = flat steps, 'linear' (default) = bilinear, 'cubic' = smooth (clamp: true avoids overshoot). Outside: edge value, or `outside`.
13
13
  - `ease(e: Ease) → (t: number) => number` — Name or function -> easing function
14
- - `checkOptions(where: string, opts: object | null | undefined, known: string[], flags?: { loose?: boolean })` — Warn (once, in development) about unknown keys in an options object, with a "did you mean" hint. For your own modules. where names the call ('stamina()'); known lists the keys your code reads; loose only warns on near-misses (data with game-specific fields).
14
+ - `checkOptions(where: string, opts: object | null | undefined, known: string[], flags?: { loose?: boolean })` — Warn once about unknown keys in extensible data (your item / record definitions where players or mods add their own fields), with a "did you mean" hint. Options bags go through readParams instead (an unknown key throws in dev). loose only warns on near-misses.
15
+ - `contentParts(modules: Record<string, { default: any } | a…) → any` — One content kind split over several files (content/props/forest.js, town.js…): joined in file-name order (arrays concatenated, objects merged, a key in two files an error), the same order content check and write-back use, with each entry's dev source line kept.
15
16
  - `readParams(where: string, schema: Record<string, ParamSpec>, opts?: object) → T` — Module options read through a params schema: unknown keys and wrong types throw in dev with the fix, defaults are filled in. Also put params / options on the module definition so engine.catalog(name) shows them (recipes/51-capability-catalog.md).
16
- - `defineLookPart(engine: any, spec: { id, group?, module?, object?, params?, style?, … }) → LookPart` — Register a module's own look part: engine.look.<id> with set / patch / replace, engine.catalog('look.<id>') and describe().look (recipes/52-look.md). Every param needs a default; a default that changes the picture also needs why and off (or neutral: true).
17
+ - `threePatches: { list, off }` — Every change the engine makes to three.js classes, the game's three.js objects or its renderer (also in describe().threePatches). scope: what it reaches; lost: what stops when it is off (or why it cannot be). off(id) undoes an offable one for the whole page; others throw.
18
+ - `defineLookPart(engine: any, spec: { id, group?, module?, object?, params?, style?, … }) → import('./types/core').LookPart` — Register a module's own look part: engine.look.<id> with set / patch / add / replace / manual / value (module code: part.author), engine.catalog('look.<id>') and describe().look (recipes/52-look.md). Every param needs a default; a default that changes the picture also needs why and off (or neutral: true).
17
19
  - `createTerrain(cfg?: Partial<TerrainConfig>) → TerrainGen` — Pure terrain computation (no engine needed), for previewing heights before start: createTerrain({ seed, ...terrainPreset() }).surface(x, z)
18
- - `terrainMaterial(base?: THREE.Material | null, engine?: { style: any; assets: any }) → THREE.Material` — Terrain material: base (default the style's 'terrain' role with vertex colors) + cloud shadows + season tint + optional detail texture (style.terrain.detail). Pass the engine so its style pack and assets are used.
20
+ - `terrainMaterial(base?: THREE.Material | null, engine?: { style: any; assets: any }, { effects }?: { effects?: boolean }) → THREE.Material` — Terrain material: base (default the style's 'terrain' role with vertex colors) + cloud shadows + season tint + optional detail texture (style.terrain.detail). Pass the engine so its style and assets are used. effects: false returns your base as is (no engine patch at all, the vegetation.define({ effects: false }) word): look.ground.replace(myMaterial, { effects: false }).
19
21
  - `mergeColored(parts: [THREE.BufferGeometry, ColorLike][], { flat }?: { flat?: boolean }) → THREE.BufferGeometry` — Merge several geometries into one vertex-colored geometry (a tree = trunk + canopy in one draw call): [[geometry, color], ...]. flat (default true): one normal per triangle, the faceted low-poly look; false keeps each part's own (smooth) normals. UVs are kept when every part has them, so the merged model can still take a texture.
20
- - `applyEffects(material: THREE.Material, { wind, clouds, season, detail, engine, patches }?: { wind?, clouds?, season?, detail?, engine?, patches? }) → THREE.Material` — Add effects to any material (built-in, from a style pack, or third-party); returns the same material. The one entry for shader effects: wind (sway amplitude; the shadow sways too, nothing else to set up), clouds (drifting cloud shadows, default on; how dark is style.clouds.shadow), season ('foliage' / 'ground' seasonal tint), and patches: your own named patches (see ShaderPatch in render/patches.js), detail (grain / paper / strokes / a texture over the surface, see MaterialDetail in types/style.d.ts; a texture given by asset name loads from `engine`, default the first live engine). The 'world' patch (varying vThreedogWorld, world position) comes with clouds, and is added for any of your patches that lists it in needs.patches.
22
+ - `applyEffects(material: THREE.Material, { wind, clouds, season, detail, engine, patches }?: { wind?, clouds?, season?, detail?, engine?, patches? }) → THREE.Material` — Add effects to any material (built-in, from a style, or third-party); returns the same material. The one entry for shader effects: wind (sway amplitude; the shadow sways too, nothing else to set up), clouds (drifting cloud shadows, default on; how dark is style.clouds.shadow), season ('foliage' / 'ground' seasonal tint), and patches: your own named patches (see ShaderPatch in render/patches.js), detail (grain / paper / strokes / a texture over the surface, see MaterialDetail in types/style.d.ts; a texture given by asset name loads from `engine`, default the first live engine). The 'world' patch (varying vThreedogWorld, world position) comes with clouds, and is added for any of your patches that lists it in needs.patches or reads vThreedogWorld (a one-time dev note asks for the needs line).
21
23
  - `MATERIAL_PURPOSES: string[]` — Material roles the engine itself uses
22
- - `makeMaterial(purpose?: string, params?: { color?, … }, engine?: { style: any }) → THREE.Material` — Create a material by role: makeMaterial('furniture', { color: 0x8a5a36 }); the look comes from the style pack's materials[role] (unlisted roles use materials.default). Roles the engine uses: default terrain vegetation character water pickup prop (MATERIAL_PURPOSES); a game may pick new names (e.g. 'building'), and a name close to an existing role ('props', 'charcter') warns in dev. A style pack entry has one of three forms; params are then applied to the result (keys the material lacks are skipped):
24
+ - `makeMaterial(purpose?: string, params?: import("../../style").MaterialSpec, engine?: { style: any }) → THREE.Material` — Create a material by role: makeMaterial('furniture', { color: 0x8a5a36 }); the look comes from look.materials for that role, whose style layer is the style's materials table and whose game layer is look.materials.set / replace (unlisted roles use the 'default' role). Roles the engine uses: default terrain vegetation character water pickup prop (MATERIAL_PURPOSES); a game may pick new names (e.g. 'building'), and a name close to an existing role ('props', 'charcter') warns in dev. A style entry has one of three forms; params are then applied to the result (keys the material lacks are skipped):
25
+ - `bakeVertexAO(geometry: THREE.BufferGeometry, { samples, radius, strength, bias, occluders, seed }?: { samples?, radius?, strength?, bias?, occluders?, seed? }) → THREE.BufferGeometry` — Bake ambient occlusion into a geometry's vertex colors: each vertex casts `samples` rays over the hemisphere around its normal, and the share that hits the geometry (or an occluder) within `radius` darkens it. Creases, insides and parts tucked under other parts go dark; open sides stay as they were. The result multiplies the existing `color` attribute (white is added when there is none), so it works on `mergeColored` output and on any geometry drawn with `vertexColors: true`. Deterministic for a seed, so cached and baked models stay identical. Cost is vertices x samples ray casts (a 5k-vertex model at 32 samples is ~160k casts); run it inside a model generator, where it is cached. Resolution is per vertex: a large flat face with four corners gets no contact shadow in its middle (subdivide it, or bake a texture in Blender).
23
26
  - `materialPatches(material: THREE.Material) → string[]` — Names of the patches on a material (in order), e.g. ['clouds', 'tint', 'wind']
24
27
  - `toast(engine: Engine, text: string, { kind, ms }?: { kind?: string; ms?: number })` — Show a short message through the 'toast' UI part (default: top of the screen, gone after ms). A game restyles it, filters it by kind or turns it off with createEngine({ ui: { toast: false } }). kind says where it came from: 'info' (default), 'quest', 'item', 'save', 'error'.
25
28
  - `makeWindow(engine: Engine, opts: WindowOptions) → UIWindow` — A toggleable window
26
29
  - `worldToScreen(engine: Engine, pos: PositionLike) → ScreenPoint` — World coordinates (position or object) -> pixels from the canvas's top-left corner { x, y, onScreen, behind } (the UI root covers the canvas, so these place UI elements directly)
27
- - `fadeScreen(engine: Engine, to: number, seconds?: number) → Promise<void>` — Fade the whole screen to `to` (0 clear ... 1 fully covered) over `seconds` (default 0.5); the Promise resolves when the fade ends
30
+ - `fadeScreen(engine: Engine, to: number, opts?: { seconds?: number }) → Promise<void>` — Fade the whole screen to `to` (0 clear ... 1 fully covered) over `seconds` (default 0.5); the Promise resolves when the fade ends. fadeScreen(engine, 1, 0.5) throws in dev: fadeScreen(engine, 1, { seconds: 0.5 })
28
31
  - `uiFocus(engine: Engine) → UIFocus` — UI focus stack: windows, dialogue and cutscenes push in open order; the back key (Esc) goes to the top only; an empty stack hands it to the settings menu
29
32
  - `toggleOnKey(engine: Engine, win: { open, toggle }, action: string)` — Window toggle key: call once per frame in a frame hook; opens on the action when closed, closes on another press when open
30
33
  - `parseClock(clock: string | number, hoursPerDay?: number) → number` — Clock time -> fraction of the day: parseClock('18:30') = 0.77; a number or numeric string ('0.25') is converted as is. hoursPerDay is hours per day, default 24
31
34
  - `formatClock(t: number, hoursPerDay?: number) → string` — Fraction of the day -> 'HH:MM': formatClock(0.75) = '18:00'
32
- - `inRange(t: number, from: string | number, to: string | number, hoursPerDay?: number) → boolean` — Is time t (0-1, e.g. sky.timeOfDay) inside the range [from, to)? from and to are 'HH:MM' or 0-1; from > to wraps past midnight. Used by sky.between and the audio rule condition { time: [from, to] }
35
+ - `inRange(t: number, from: string | number, to: string | number, hoursPerDay?: number) → boolean` — Is time t (0-1, e.g. calendar.timeOfDay) inside the range [from, to)? from and to are 'HH:MM' or 0-1; from > to wraps past midnight. Used by calendar.between and the audio rule condition { time: [from, to] }
33
36
  - `pickTarget(from: PositionLike, view: { x: number; z: number } | number, candidates: Iterable<T>, opts?: TargetOptions<T>) → T | null` — Best target in front: lowest "distance + angle off view × angleWeight" inside radius and cone. view is a direction { x, z } (cameraRig.forward()) or a facing angle. Returns the candidate or null
34
37
  - `switchTarget(from: PositionLike, view: { x: number; z: number } | number, current: T | null, candidates: Iterable<T>, side: 1 | -1, opts?: Pick<TargetOptions<T>, 'radius' | '…) → T | null` — Next target to the right (side 1) or left (-1) of current as seen along view, wrapping; current missing → the leftmost. Returns a candidate or null
35
38
  - `THREE` — three.js itself (any): `import { THREE } from 'threedog'`
36
39
 
37
40
  ## Data structures
38
41
  - **WindowOptions** Parameters of makeWindow()
39
- - `id: string` Window name (also the style pack's template name)
42
+ - `id: string` Window name (also the style's template name)
40
43
  - `title: () => string` Title
41
44
  - `hintAction?: string` Action name that toggles it (shows the key hint)
42
45
  - `render: (data, tools) => string` Default content: (data, tools) => HTML
@@ -47,6 +50,7 @@
47
50
  - `open: boolean` Whether it is open
48
51
  - `refresh()` — Redraw the content
49
52
  - `toggle(on?: boolean)` — Open / close (toggle if no argument is passed)
53
+ - `remove()` — Remove the window: closed, its listeners and its element gone (a module passes the window to ctx.track instead)
50
54
  - **ScreenPoint** Result of worldToScreen(): x/y are pixels from the canvas's top-left corner (the UI root covers the canvas), onScreen is inside the view, behind is behind the camera
51
55
  - `x: number`
52
56
  - `y: number`
@@ -54,4 +58,17 @@
54
58
  - `behind: boolean`
55
59
 
56
60
  ## Other exported classes and functions
61
+ - `wind(position: Node, origin: Node, amplitude: Node | number) → Node` — GLSL vec3 threedogWind(vec3 position, vec3 origin, float amplitude): object-space sway offset, higher vertices sway more. position: object space before the instance transform (positionGeometry); origin: the object's world origin (objectOrigin()); amplitude: metres per metre of height. Reads uTime, uWind, uWindFreq.
62
+ - `cloudShadow(worldPos: Node) → Node` — GLSL float threedogCloudShadow(vec3 worldPos): light factor 0-1 under the drifting clouds (1 = no shadow). Reads uTime, uCloud*, uCloudSpeed.
63
+ - `season(color: Node, kind: Node | 0 | 1) → Node` — GLSL vec3 threedogSeason(vec3 color, int kind): kind 0 foliage, 1 ground; tints by uFoliageTint / uGroundTint (mix mode when uFoliageMix / uGroundMix > 0). A vec4 color is read as its rgb.
64
+ - `objectOrigin() → Node` — World position of the drawn object's origin (an InstancedMesh: of each instance), vec3. Works for any Mesh / InstancedMesh sharing the material; BatchedMesh throws [tsl-misuse].
65
+ - `uniforms(engine: { uniforms: object }) → Record<string, Node>` — engine.uniforms as TSL uniform nodes (uTime, uWind, uCloud, uFoliageTint, uSunDir, uDaylight ...), cached per engine. They read the same { value } objects, so engine.uniforms.uWind.value = 2 changes GLSL and TSL materials alike.
66
+ - `detailNoise(p: Node, kind: Node | 0 | 1 | 2 | 3, octaves: Node | number) → Node` — GLSL vec4 threedogDetailNoise(vec2 p, int kind, float octaves): kind 0 grain, 1 paper, 2 stroke, 3 dabs; returns (gray rgb, height 0-1). No uniforms: p is any 2D pattern position you choose (world xz times a scale, a uv...). octaves: up to 4 (dabs: 3).
67
+ - `detailBump(surfPos: Node, surfNorm: Node, h: Node, k: Node | number, faceDir: Node | number) → Node` — GLSL vec3 threedogDetailBump(vec3 surfPos, vec3 surfNorm, float h, float k, float faceDir): screen-space bump from a height h, strength k. View space; the result is a normal for material.normalNode.
68
+ - `wrapDiffuse(nl: Node, wrap: Node | number, lightColor: Node, shadow: Node | number, albedo: Node) → Node` — GLSL vec3 threedogWrapDiffuse(float nl, float wrap, vec3 lightColor, float shadow, vec3 albedo): the half-lambert light beyond plain Lambert, to add to directDiffuse. nl = dot(normal, sunDir). Call it from your LightingModel's direct() (lightColor there already carries the shadow: pass shadow 1).
69
+ - `shadowTint(ambient: Node, tint: Node, strength: Node | number, soft: Node | number, nl: Node, shadow: Node | number) → Node` — GLSL vec3 threedogShadowTint(vec3 ambient, vec3 tint, float strength, float soft, float nl, float shadow): the ambient with the shaded side's hue moved toward tint (brightness kept). shadow: 1 lit / 0 shadowed (the sun's lightNode.shadowNode); soft: terminator width in n.l.
70
+ - `rim(normal: Node, viewDir: Node, color: Node, strength: Node | number, power: Node | number, shadowSide: Node | number, nl: Node) → Node` — GLSL vec3 threedogRim(vec3 normal, vec3 viewDir, vec3 color, float strength, float power, float shadowSide, float nl): edge light to add (viewDir from the surface to the eye, e.g. normalView and positionViewDirection); shadowSide 1 = only on the side facing away from the sun.
71
+ - `waterWave(p: Node, t: Node | number) → Node` — GLSL float threedogWaterWave(vec3 p, float t): the built-in wave sum (height before waveHeight). p = world position * waveScale, t = time * waveSpeed.
72
+ - `waterSurface(spec?: { depth?, foam?, waveMax? }) → (base, wave, facing, worldPos, time) => Node` — The built-in water surface as TSL: returns a function with the GLSL signature threedogWaterSurface(base, wave, facing, worldPos, time) -> vec4 (rgb, opacity). Only the parts given exist (depth: shallow / deep by viewing angle or wave height; foam on crests); values are numbers / colors or nodes. wave is waterWave's height, facing = 1 looking straight down.
73
+ - `waterFresnel(color: Node, normal: Node, viewDir: Node, strength: Node | number, towards: Node) → Node` — The water's fresnel blend: color mixed toward `towards` (the engine uses the fog color) by pow(1 - /viewDir . normal/, 3) * strength, view space
57
74
  - `serve(handler: (msg: any) => any)` — Start answering lane messages in a worker. handler is the same function the lane's local() returns on the main thread.
@@ -3,9 +3,7 @@
3
3
  Trigger zones (triggers() module)
4
4
 
5
5
  - Options `TriggersOptions`:
6
- - `debug?: boolean` Show the wireframes from the start
7
- - `action?: string` Action name that toggles the wireframes, default 'triggersDebug'
8
- - `keys?: string[]` Key that toggles the wireframes: default ['F4'] in dev builds, none in release builds
6
+ - `action?: string` Action name that toggles the debug view 'triggers' (engine.debug.view), default 'triggersDebug'
9
7
 
10
8
  ## Methods and properties
11
9
  - `triggers.list() → Trigger[]` — All trigger zones (a new array)
@@ -13,9 +11,6 @@ Trigger zones (triggers() module)
13
11
  - `triggers.clear()` — Delete all (delete a single one with trigger.remove())
14
12
  - `triggers.byTag(tag: string) → Trigger[]` — Find by tag
15
13
  - `triggers.fromMarkers(opts?: TriggerOptions) → Trigger[]` — Every trigger_xxx marker in the level becomes a trigger zone with tag xxx; opts is shared by all of them
16
- - `triggers.setDebug(on: boolean)` — Show / hide the wireframes
17
- - Properties:
18
- - `debug: boolean` Whether wireframes are shown
19
14
 
20
15
  ## Data structures
21
16
  - **TriggerOptions** Trigger zone parameters
@@ -25,13 +20,13 @@ Trigger zones (triggers() module)
25
20
  - `size?: number[]` Box size [width, height, depth] (meters), default [2, 2, 2]
26
21
  - `height?: number` Cylinder height (meters), default 3
27
22
  - `rotation?: number` Box rotation around the Y axis (radians)
28
- - `onEnter?: ((t: Trigger, who: Vector3) => void) | null` Called on entering; who is the position that entered
29
- - `onExit?: ((t: Trigger, who: Vector3 | null) => void) | null` Called on leaving
30
- - `onStay?: ((dt: number, t: Trigger, who: Vector3) => void) | null` Called every fixed step while inside (dt in seconds)
23
+ - `onEnter?: ((t, who, id) => void) | null` Called on entering; who is the position that entered, id the world record id of who it is (engine.actor for the default who, an id given in who, object.userData.id, null for a bare position)
24
+ - `onExit?: ((t, who, id) => void) | null` Called on leaving; id = who was inside
25
+ - `onStay?: ((dt, t, who, id) => void) | null` Called every fixed step while inside (dt in seconds)
31
26
  - `once?: boolean` Fire on the first enter only (exit follows at once); the zone stays with used = true, and a new playthrough (engine.session) re-arms it
32
27
  - `enabled?: boolean` false pauses detection
33
28
  - `tag?: string` Name (carried in events)
34
- - `who?: Vector3 | Object3D | { x, y, z } | (() => Array<{ x: number; …) | null` Who can trigger it: the player by default; or a position, an object (its position is used), or a function returning an array of positions
29
+ - `who?: string | Vector3 | Object3D | { x, y, z } | (() => Array<string | Obje…) | null` Who can trigger it: engine.actor by default; or an actor id, a position, an object (its position is used), or a function returning an array of those (several actors: () => [e.actor, ...e.net.peers.map(p => p.actor)])
35
30
  - `cooldown?: number` Seconds after leaving during which entering does not fire again, default 0
36
31
  - `userData?: Record<string, any>` Custom data
37
32
  - **Trigger** A trigger zone (the return value of add())
@@ -10,31 +10,35 @@ 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
14
  - `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
14
- - `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 add() 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`
15
- - `vegetation.add(name: string, opts: VegetationOptions) → Species` — Register a kind of vegetation
15
+ - `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
+ - `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)
16
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
17
18
  - `vegetation.restoreInstance(species: string, cx: number, cz: number, id: number)` — Restore one
18
19
  - `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
19
20
  - Also: `vegetation.get(name: string) → Species | undefined`, `vegetation.list() → Species[]`, `vegetation.isRemoved(species: string, cx: number, cz: number, id: number) → boolean`
20
21
 
21
22
  ## Data structures
22
- - **VegetationOptions** Parameters of engine.vegetation.add(name, {...})
23
+ - **VegetationOptions** Parameters of engine.vegetation.define(name, {...})
23
24
  - `geometry?: BufferGeometry` High-detail model (this or model is required)
24
- - `model?: Object3D` Multi-material model (one material per mesh, e.g. bark trunk + leaf cards); still one InstancedMesh per species. Its materials are cloned
25
- - `lodGeometry?: BufferGeometry | Object3D` Low-detail model, switched to beyond lodRing rings; with model an Object3D with the same mesh order, or a geometry drawn with the first material
26
- - `rule?: VegetationRule` Placement rule
25
+ - `model?: Object3D | string | [string, ...any[]]` A model name from an asset pack ('pine', or ['flower', color] for a generator with params), resolved as content resolves it (file or generator, cache, bake; add then returns a Promise of the species), or a multi-material Object3D (one material per mesh, e.g. bark trunk + leaf cards); still one InstancedMesh per species. Its materials are cloned
26
+ - `lodGeometry?: BufferGeometry | Object3D | string | [string, ...any[]]` Low-detail model, switched to beyond lodRing rings: a model name, or with model an Object3D with the same mesh order, or a geometry drawn with the first material
27
+ - `rule?: VegetationRule` Placement rule (random scatter per chunk)
28
+ - `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
+ - `densityMap?: ((x, z) => number) | { url?, data?, width?, height?, size, center?, … }` How much of this species survives at each spot, 0 (none) ..
27
30
  - `wind?: number` Wind sway amplitude, 0 = still
28
31
  - `nearOnly?: boolean` Only generated near the player (grass, flowers)
29
32
  - `maxRing?: number` No longer drawn beyond this many rings
33
+ - `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).
30
34
  - `lodRing?: number` Switch to the low-detail model beyond this many rings, default 1
31
35
  - `castShadow?: boolean` Cast shadows
32
36
  - `shadowRing?: number` Cast shadows within this many rings
33
37
  - `receiveShadow?: boolean` Receive shadows, default true
34
- - `material?: Material` Custom material, any three.js material (default: the style pack's 'vegetation' role); wind, cloud shadows and season tint are added to it
38
+ - `material?: Material` Custom material, any three.js material (default: the style's 'vegetation' role); wind, cloud shadows and season tint are added to it
35
39
  - `effects?: boolean` false: leave a custom material untouched (no wind / clouds / season added)
36
40
  - `doubleSided?: boolean` Double-sided rendering
37
- - **VegetationRule** Vegetation placement rule (must be JSON-able, no functions)
41
+ - **VegetationRule** Vegetation placement rule (must be JSON-able, no functions: it is sent to the terrain workers)
38
42
  - `perChunk?: number` Placement attempts per chunk, default 100
39
43
  - `chance?: number` Success probability of each attempt 0–1 (when cluster is 'none'), default 1
40
44
  - `minHeight?: number` Altitude range (meters); default unlimited both ways (a terrain game names its band above the water, e.g. minHeight: 1.5)
@@ -0,0 +1,10 @@
1
+ # engine.vegetationLook — vegetationLook()
2
+
3
+ Draws the plants (vegetation()'s look module, slot 'vegetation-look'; undefined when a game replaced it)
4
+
5
+
6
+ ## Methods and properties
7
+ - `vegetationLook.mesh(c: TerrainChunk, name: string) → InstancedMesh | null` — The InstancedMesh drawing one species in one chunk, null when none
8
+ - `vegetationLook.kind(name: string) → { geometry, lodGeometry, material, fadeUniforms } | null | …` — How one species is drawn: its geometry, low-poly geometry, patched material(s), near-fade uniforms; 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
@@ -5,26 +5,10 @@ Water surface (water() module)
5
5
  - Options `WaterOptions`:
6
6
  - `sea?: boolean` false: do not draw the global water surface (sea)
7
7
  - `level?: number` Global water level (meters); if omitted, the terrain's water level is used
8
- - `color?: ColorLike`
9
- - `opacity?: number`
10
- - `flat?: boolean`
11
- - `waveHeight?: number`
12
- - `waveScale?: number`
13
- - `waveSpeed?: number`
14
- - `fresnel?: number`
15
- - `size?: number`
16
- - `segments?: number`
17
- - `normalMap?: string`
18
- - `normalScale?: number`
19
- - `normalRepeat?: number`
20
- - `normalSpeed?: number[]`
21
- - `shininess?: number`
22
- - `specular?: ColorLike`
23
- - `material?: import('./style').StyleWater['material']` Replace the whole surface material, same as style.water.material
24
- - `depthColor?: import('./style').StyleWater['depthColor']`
25
- - `foam?: import('./style').StyleWater['foam']`
26
- - `glsl?: import('./style').StyleWater['glsl']`
27
- - `uniforms?: import('./style').StyleWater['uniforms']`
8
+ - `flat?: boolean` Flat shading (low poly), default true
9
+ - `size?: number` Edge length of the global water plane (meters), default 900
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)
28
12
 
29
13
  ## Methods and properties
30
14
  - Properties:
@@ -1,21 +1,11 @@
1
- # engine.weather — weather(opts?: WeatherOptions)
1
+ # engine.weather — weather()
2
2
 
3
- Weather (weather() module, needs sky)
3
+ Weather state (weather() module): the table, current values, set / setAuto, save, events
4
4
 
5
- - Options `WeatherOptions`:
6
- - `start?: WeatherName` Starting weather, default 'clear' (or the first of the game's types when it has no 'clear')
7
- - `auto?: boolean` Automatic weather changes
8
- - `particles?: number` Rain / snow particle count, default 6000
9
- - `types?: Record<string, Partial<WeatherPreset> & Record<string, numb…` The game's weather table, the whole list (default only a calm 'clear'; seven temperate ones in presets.weather.temperate.types, extend them with { ...presets.weather.temperate.types, dust: {...} }). Left-out fields are calm; extra numeric fields of the game's own blend too and show in weather.current
10
- - `autoPool?: string[]` Candidates for automatic changes (repeat an entry for higher probability)
11
- - `autoInterval?: number[]` Interval between automatic changes [shortest, longest] seconds
12
- - `transition?: number` Transition seconds of automatic changes, default 25
13
- - `area?: number` Rain / snow coverage (meters)
14
5
 
15
6
  ## Methods and properties
16
- - `weather.define(_field: string, _spec?: import("../../../style").StyleWeath…) → never` — Renamed in 0.2: throws and names the new call, engine.look.weather.replace({ [field]: spec }) (recipes/44-water-weather-look-hooks.md)
17
7
  - `weather.setAuto(on: boolean)` — Automatic weather on/off
18
- - `weather.set(name: WeatherName, seconds?: number)` — Switch weather. seconds: transition seconds, default 15
8
+ - `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 })`
19
9
  - `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
20
10
  - Properties:
21
11
  - `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)
@@ -25,5 +15,5 @@ Weather (weather() module, needs sky)
25
15
  - `autoPool: string[]` Candidates for automatic weather (repeat a name to make it likelier)
26
16
  - `autoInterval: number[]` Automatic weather interval [min, max] seconds
27
17
  - `autoTransition: number` Transition seconds for automatic weather
28
- - `particles: number` Default particle count per system (halved on low-tier devices)
29
- - `systems: Map<string, any>` Particle systems drawn now: field -> { field, object, uniforms } (rain / snow when the table has them, plus define())
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
@@ -0,0 +1,10 @@
1
+ # engine.weatherLook — weatherLook()
2
+
3
+ Weather look (installed by weather(), needs sky): 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 (halved on low-tier devices)
10
+ - `systems: Map<string, any>` Particle systems drawn now: field -> { field, object, uniforms } (rain / snow when the table has them, plus fields look.weather.replace adds)
package/docs/api/world.md CHANGED
@@ -16,7 +16,8 @@ World data (world() module): things that must be saved, survive level changes an
16
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 })`
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
- - `world.simulate(kind: string, opts: { near?, far?, farEvery?, radius?, worker? }) → { 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 fixed-step seconds (not multiplied by clock.timeScale). 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 })`
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
21
  - Properties:
21
22
  - `records: Map<string, WorldRecord>` All records: id → record (read-only; use set to change fields, move to change position)
22
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