threedog 0.5.0 → 0.7.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 (511) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/README.md +21 -13
  3. package/core/Assets.js +23 -12
  4. package/core/Audio.js +1 -1
  5. package/core/Baked.js +14 -23
  6. package/core/Budget.js +2 -2
  7. package/core/DebugOverrides.js +33 -18
  8. package/core/Describe.js +10 -11
  9. package/core/Engine.js +50 -46
  10. package/core/I18n.js +2 -2
  11. package/core/Input.js +11 -5
  12. package/core/Inspect.js +6 -3
  13. package/core/InspectMaterials.js +2 -3
  14. package/core/InspectPerf.js +11 -4
  15. package/core/MaterialInfo.js +7 -5
  16. package/core/Rays.js +7 -2
  17. package/core/Stream.js +2 -3
  18. package/core/UrlState.js +49 -9
  19. package/core/Views.js +1 -0
  20. package/core/adaptive.js +2 -2
  21. package/core/assetEntry.js +5 -2
  22. package/core/assetLoad.js +13 -15
  23. package/core/assetManifest.js +6 -3
  24. package/core/assetReport.js +4 -4
  25. package/core/batchGroups.js +9 -1
  26. package/core/catalog.js +16 -3
  27. package/core/chunkStream.js +1 -1
  28. package/core/copies.js +1 -1
  29. package/core/debugView.js +4 -4
  30. package/core/describeRender.js +104 -28
  31. package/core/describeText.js +6 -6
  32. package/core/errorCodes.js +72 -45
  33. package/core/errorHints.js +4 -1
  34. package/core/errors.js +4 -4
  35. package/core/events.generated.js +1 -0
  36. package/core/gameLights.js +9 -2
  37. package/core/lifecycle.js +2 -4
  38. package/core/lightWatch.js +5 -3
  39. package/core/loop.js +18 -11
  40. package/core/math.js +7 -0
  41. package/core/moduleSlots.js +32 -7
  42. package/core/moduleTypes.js +20 -7
  43. package/core/modules.js +7 -7
  44. package/core/namedModel.js +8 -4
  45. package/core/owned.js +33 -30
  46. package/core/page.js +43 -10
  47. package/core/pictureSlots.js +33 -0
  48. package/core/pictureWriters.js +343 -0
  49. package/core/plugins.js +64 -96
  50. package/core/sceneDelta.js +12 -4
  51. package/core/sceneMethods.js +2 -9
  52. package/core/services.js +1 -1
  53. package/core/shadowTypes.js +1 -1
  54. package/core/shadows.js +405 -0
  55. package/core/sharedPoint.js +5 -19
  56. package/core/stackFrames.js +16 -5
  57. package/core/stacks.js +6 -6
  58. package/core/startup.js +9 -11
  59. package/core/thingExplain.js +1 -1
  60. package/core/things.js +1 -1
  61. package/core/tier.js +1 -1
  62. package/core/util.js +1 -1
  63. package/core/validate.js +1 -1
  64. package/core/view.js +43 -0
  65. package/docs/AI.md +62 -58
  66. package/docs/API.md +15 -15
  67. package/docs/CODEMAP.md +36 -54
  68. package/docs/COMMANDS.md +28 -25
  69. package/docs/CONVENTIONS.md +36 -30
  70. package/docs/MIGRATING-0.4.md +93 -1
  71. package/docs/MIGRATING-0.6.md +126 -0
  72. package/docs/MIGRATING-0.7.md +39 -0
  73. package/docs/THREE.md +24 -22
  74. package/docs/api/assets.md +5 -3
  75. package/docs/api/audio.md +2 -2
  76. package/docs/api/budget.md +4 -0
  77. package/docs/api/characters.md +3 -1
  78. package/docs/api/collision.md +2 -2
  79. package/docs/api/engine.md +47 -20
  80. package/docs/api/events.md +2 -1
  81. package/docs/api/grids.md +8 -1
  82. package/docs/api/ground.md +1 -1
  83. package/docs/api/hud.md +3 -0
  84. package/docs/api/input.md +3 -2
  85. package/docs/api/interactions.md +3 -1
  86. package/docs/api/inventory.md +1 -2
  87. package/docs/api/level.md +0 -1
  88. package/docs/api/lightPool.md +1 -1
  89. package/docs/api/occlusion.md +5 -0
  90. package/docs/api/particles.md +6 -3
  91. package/docs/api/pickups.md +6 -0
  92. package/docs/api/post.md +5 -3
  93. package/docs/api/sky.md +12 -10
  94. package/docs/api/terrain.md +12 -6
  95. package/docs/api/terrainDraw.md +12 -0
  96. package/docs/api/tools.md +8 -7
  97. package/docs/api/triggers.md +2 -0
  98. package/docs/api/vegetation.md +7 -2
  99. package/docs/api/vegetationDraw.md +10 -0
  100. package/docs/api/water.md +6 -2
  101. package/docs/api/weather.md +5 -0
  102. package/docs/api/weatherDraw.md +10 -0
  103. package/docs/api/world.md +1 -1
  104. package/docs/recipes/01-new-game.md +19 -23
  105. package/docs/recipes/03-items-pickups.md +25 -4
  106. package/docs/recipes/05-props-bake.md +53 -37
  107. package/docs/recipes/06-clock-events.md +3 -3
  108. package/docs/recipes/07-flow-scenes-pause.md +12 -3
  109. package/docs/recipes/08-weather-sky.md +45 -57
  110. package/docs/recipes/09-materials-lights-models.md +185 -0
  111. package/docs/recipes/10-blender-level.md +2 -2
  112. package/docs/recipes/11-vehicles.md +3 -3
  113. package/docs/recipes/13-animation.md +13 -7
  114. package/docs/recipes/14-custom-module.md +7 -5
  115. package/docs/recipes/15-perf.md +3 -3
  116. package/docs/recipes/16-dev-bridge.md +22 -12
  117. package/docs/recipes/18-world.md +10 -8
  118. package/docs/recipes/19-shooting-picking.md +7 -5
  119. package/docs/recipes/20-content-actions-save.md +6 -2
  120. package/docs/recipes/21-camera.md +8 -3
  121. package/docs/recipes/23-ops.md +1 -1
  122. package/docs/recipes/26-ui-parts.md +35 -11
  123. package/docs/recipes/28-terrain.md +12 -12
  124. package/docs/recipes/29-grid.md +14 -5
  125. package/docs/recipes/30-templates.md +8 -3
  126. package/docs/recipes/31-audio.md +4 -4
  127. package/docs/recipes/32-action-game.md +18 -4
  128. package/docs/recipes/34-environment-lighting.md +102 -38
  129. package/docs/recipes/35-picture-from-reference.md +147 -0
  130. package/docs/recipes/36-sky-ground-plants.md +158 -0
  131. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
  132. package/docs/recipes/38-environment-hooks.md +67 -0
  133. package/docs/recipes/40-scene.md +106 -27
  134. package/docs/recipes/42-terrain-shape.md +1 -1
  135. package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
  136. package/docs/recipes/44-water-weather-hooks.md +191 -0
  137. package/docs/recipes/45-cascaded-shadows.md +121 -23
  138. package/docs/recipes/46-blender-art-route.md +17 -20
  139. package/docs/recipes/47-island-snow-backdrop.md +10 -12
  140. package/docs/recipes/49-game-module-contract.md +1 -1
  141. package/docs/recipes/50-own-renderer.md +3 -3
  142. package/docs/recipes/52-around-the-picture.md +181 -0
  143. package/docs/recipes/53-ground-up-close.md +12 -12
  144. package/docs/recipes/54-three-idioms.md +18 -18
  145. package/docs/recipes/55-mods-time-wrap.md +17 -5
  146. package/docs/recipes/56-webgpu-tsl.md +66 -23
  147. package/docs/recipes/57-control.md +39 -0
  148. package/docs/recipes/58-input.md +3 -0
  149. package/docs/recipes/59-depth-post-effects.md +5 -5
  150. package/docs/recipes/60-judge-the-picture.md +39 -24
  151. package/docs/recipes/61-deploy.md +27 -0
  152. package/docs/recipes/62-picture-code.md +244 -0
  153. package/docs/recipes/63-third-person-start.md +77 -0
  154. package/docs/recipes/64-particles.md +35 -0
  155. package/examples/action/.threedog/content-index.json +1 -1
  156. package/examples/action/GAMEMAP.md +7 -5
  157. package/examples/action/main.js +5 -4
  158. package/examples/action/models.js +12 -14
  159. package/examples/action/picture/index.js +13 -0
  160. package/examples/action/picture/lights.js +35 -0
  161. package/examples/action/picture/materials.js +8 -0
  162. package/examples/action/picture/palette.js +33 -0
  163. package/examples/plain-picture/.threedog/content-index.json +1 -0
  164. package/examples/plain-picture/FINDINGS.md +53 -0
  165. package/examples/plain-picture/GAMEMAP.md +90 -0
  166. package/examples/plain-picture/main.js +48 -0
  167. package/examples/plain-picture/picture/index.js +21 -0
  168. package/examples/plain-picture/picture/lights.js +54 -0
  169. package/examples/plain-picture/picture/materials.js +24 -0
  170. package/examples/plain-picture/picture/palette.js +16 -0
  171. package/examples/plain-picture/picture/sky.js +37 -0
  172. package/examples/pullable.json +31 -9
  173. package/examples/rc2d/GAMEMAP.md +8 -3
  174. package/examples/rc2d/README.md +11 -6
  175. package/examples/rc2d/main.js +25 -33
  176. package/examples/rc2d/picture/index.js +18 -0
  177. package/examples/rc2d/picture/lights.js +11 -0
  178. package/examples/rc2d/picture/materials.js +18 -0
  179. package/examples/rc2d/picture/palette.js +15 -0
  180. package/examples/rc2d/picture/post.js +11 -0
  181. package/examples/rc2d/rc2d.js +18 -28
  182. package/examples/sheepisland/.threedog/content-index.json +1 -1
  183. package/examples/sheepisland/GAMEMAP.md +13 -10
  184. package/examples/sheepisland/assets.js +2 -2
  185. package/examples/sheepisland/content/templates.js +1 -1
  186. package/examples/sheepisland/content/vegetation.js +3 -1
  187. package/examples/sheepisland/main.js +15 -9
  188. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  189. package/examples/sheepisland/picture/index.js +20 -0
  190. package/examples/sheepisland/picture/lights.js +34 -0
  191. package/examples/sheepisland/picture/materials.js +61 -0
  192. package/examples/sheepisland/picture/palette.js +60 -0
  193. package/examples/sheepisland/picture/sky.js +20 -0
  194. package/examples/sheepisland/views.js +1 -1
  195. package/examples/styletest/.threedog/content-index.json +1 -1
  196. package/examples/styletest/GAMEMAP.md +15 -11
  197. package/examples/styletest/main.js +20 -30
  198. package/examples/styletest/models.js +29 -29
  199. package/examples/styletest/params.js +1 -4
  200. package/examples/styletest/picture/env.js +38 -0
  201. package/examples/styletest/picture/index.js +16 -0
  202. package/examples/styletest/picture/lights.js +9 -0
  203. package/examples/styletest/picture/materials.js +28 -0
  204. package/examples/styletest/picture/palette.js +22 -0
  205. package/examples/techniques/contact-shadows/README.md +22 -23
  206. package/examples/techniques/contact-shadows/contactShadows.js +32 -16
  207. package/examples/techniques/contact-shadows/main.js +20 -18
  208. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  209. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  210. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  211. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  212. package/examples/techniques/day-night-grade/README.md +13 -16
  213. package/examples/techniques/day-night-grade/main.js +15 -25
  214. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  215. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  216. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  217. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  218. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  219. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  220. package/examples/techniques/interior-light/README.md +16 -13
  221. package/examples/techniques/interior-light/interiorLight.js +19 -17
  222. package/examples/techniques/interior-light/main.js +30 -67
  223. package/examples/techniques/interior-light/picture/index.js +24 -0
  224. package/examples/techniques/interior-light/picture/lights.js +52 -0
  225. package/examples/techniques/interior-light/picture/materials.js +13 -0
  226. package/examples/techniques/interior-light/picture/palette.js +32 -0
  227. package/examples/techniques/interior-light/picture/sky.js +40 -0
  228. package/examples/techniques/modular-building/README.md +4 -3
  229. package/examples/techniques/modular-building/kit.js +2 -2
  230. package/examples/techniques/modular-building/main.js +9 -17
  231. package/examples/techniques/modular-building/picture/index.js +17 -0
  232. package/examples/techniques/modular-building/picture/lights.js +26 -0
  233. package/examples/techniques/modular-building/picture/materials.js +13 -0
  234. package/examples/techniques/modular-building/picture/palette.js +23 -0
  235. package/examples/techniques/night-lights/README.md +15 -14
  236. package/examples/techniques/night-lights/main.js +20 -43
  237. package/examples/techniques/night-lights/nightLights.js +25 -21
  238. package/examples/techniques/night-lights/picture/index.js +18 -0
  239. package/examples/techniques/night-lights/picture/lights.js +44 -0
  240. package/examples/techniques/night-lights/picture/materials.js +15 -0
  241. package/examples/techniques/night-lights/picture/palette.js +34 -0
  242. package/examples/techniques/night-lights/picture/post.js +9 -0
  243. package/examples/techniques/night-lights/picture/sky.js +36 -0
  244. package/examples/techniques/outlines-and-rim/README.md +2 -2
  245. package/examples/techniques/outlines-and-rim/main.js +15 -38
  246. package/examples/techniques/outlines-and-rim/outlines.js +3 -3
  247. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  248. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  249. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  250. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  251. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  252. package/examples/techniques/procedural-animation/README.md +5 -3
  253. package/examples/techniques/procedural-animation/main.js +9 -7
  254. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  255. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  256. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  257. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  258. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  259. package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
  260. package/examples/techniques/procedural-surface/README.md +2 -0
  261. package/examples/techniques/procedural-surface/main.js +17 -55
  262. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  263. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  264. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  265. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  266. package/examples/techniques/stylized-shading/README.md +13 -14
  267. package/examples/techniques/stylized-shading/main.js +11 -42
  268. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  269. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  270. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  271. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  272. package/examples/techniques/stylized-shading/shading.js +2 -2
  273. package/examples/techniques/sun-and-key-light/README.md +20 -22
  274. package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
  275. package/examples/techniques/sun-and-key-light/main.js +19 -63
  276. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  277. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  278. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  279. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  280. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  281. package/examples/techniques/three-looks/README.md +21 -0
  282. package/examples/techniques/three-looks/main.js +58 -0
  283. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  284. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  285. package/examples/techniques/three-looks/picture/comic.js +27 -0
  286. package/examples/techniques/three-looks/picture/index.js +14 -0
  287. package/examples/techniques/three-looks/picture/sun.js +23 -0
  288. package/examples/techniques/wet-road/README.md +7 -4
  289. package/examples/techniques/wet-road/main.js +18 -38
  290. package/examples/techniques/wet-road/picture/index.js +17 -0
  291. package/examples/techniques/wet-road/picture/lights.js +57 -0
  292. package/examples/techniques/wet-road/picture/materials.js +16 -0
  293. package/examples/techniques/wet-road/picture/palette.js +24 -0
  294. package/examples/techniques/wet-road/picture/sky.js +46 -0
  295. package/examples/webgpu-tsl/GAMEMAP.md +9 -4
  296. package/examples/webgpu-tsl/README.md +13 -10
  297. package/examples/webgpu-tsl/main.js +30 -7
  298. package/examples/webgpu-tsl/picture/index.js +18 -0
  299. package/examples/webgpu-tsl/picture/lights.js +25 -0
  300. package/examples/webgpu-tsl/picture/materials.js +36 -0
  301. package/examples/webgpu-tsl/picture/palette.js +23 -0
  302. package/examples/webgpu-tsl/picture/post.js +16 -0
  303. package/examples/webgpu-tsl/picture/sky.js +30 -0
  304. package/examples/world/.threedog/content-index.json +1 -1
  305. package/examples/world/GAMEMAP.md +15 -12
  306. package/examples/world/art/humanoid.js +9 -13
  307. package/examples/world/art/index.js +2 -2
  308. package/examples/world/art/models.js +3 -4
  309. package/examples/world/art/shapes.js +2 -2
  310. package/examples/world/assets.js +2 -2
  311. package/examples/world/content/audio.js +1 -1
  312. package/examples/world/content/items.js +1 -1
  313. package/examples/world/content/props.js +1 -1
  314. package/examples/world/content/templates.js +1 -1
  315. package/examples/world/content/vegetation.js +1 -1
  316. package/examples/world/main.js +10 -10
  317. package/examples/world/models.js +17 -7
  318. package/examples/world/picture/index.js +20 -0
  319. package/examples/world/picture/lights.js +41 -0
  320. package/examples/world/picture/materials.js +34 -0
  321. package/examples/world/picture/palette.js +74 -0
  322. package/examples/world/picture/post.js +9 -0
  323. package/examples/world/picture/sky.js +39 -0
  324. package/index.d.ts +7 -16
  325. package/index.js +7 -7
  326. package/llms.txt +15 -13
  327. package/modules/ambience/Ambience.js +1 -1
  328. package/modules/calendar/Calendar.js +1 -1
  329. package/modules/calendar/index.js +1 -0
  330. package/modules/camera/FirstPersonCamera.js +1 -1
  331. package/modules/camera/FixedCamera.js +2 -2
  332. package/modules/camera/RtsCamera.js +1 -1
  333. package/modules/camera/common.js +7 -5
  334. package/modules/characters/Character.js +15 -10
  335. package/modules/characters/NPC.js +5 -5
  336. package/modules/characters/assetModel.js +5 -4
  337. package/modules/characters/index.js +28 -3
  338. package/modules/characters/movers/common.js +6 -1
  339. package/modules/characters/movers/manual.js +3 -0
  340. package/modules/characters/movers/support.js +25 -11
  341. package/modules/characters/npcSim.js +5 -1
  342. package/modules/characters/proceduralRig.js +18 -4
  343. package/modules/characters/useModel.js +2 -2
  344. package/modules/collision/Collision.js +4 -2
  345. package/modules/content/index.js +8 -0
  346. package/modules/content/models.js +56 -11
  347. package/modules/content/props.js +5 -3
  348. package/modules/content/rules.js +12 -4
  349. package/modules/content/templates.js +5 -3
  350. package/modules/gameplay/Interactions.js +91 -16
  351. package/modules/gameplay/Inventory.js +3 -3
  352. package/modules/gameplay/dialogueBox.js +1 -1
  353. package/modules/gameplay/dialogueBubbles.js +1 -1
  354. package/modules/gameplay/interactionPrompt.js +1 -1
  355. package/modules/gameplay/interactions.contract.js +1 -1
  356. package/modules/gameplay/inventoryOps.js +2 -2
  357. package/modules/gameplay/pickups.js +62 -24
  358. package/modules/gameplay/questLog.js +2 -2
  359. package/modules/grid/Layer.js +13 -0
  360. package/modules/grid/index.js +40 -11
  361. package/modules/grid/preview.js +24 -15
  362. package/modules/grid/tiles.js +15 -19
  363. package/modules/hlod/index.js +3 -2
  364. package/modules/hud/index.js +13 -0
  365. package/modules/hud/parts.js +9 -7
  366. package/modules/level/index.js +5 -4
  367. package/modules/lights/index.js +12 -8
  368. package/modules/music/Music.js +1 -1
  369. package/modules/particles/Particles.js +41 -20
  370. package/modules/particles/effect.js +21 -6
  371. package/modules/photo/Photo.js +11 -10
  372. package/modules/settings/Settings.js +7 -7
  373. package/modules/settings/apply.js +5 -5
  374. package/modules/settings/sections.js +2 -2
  375. package/modules/settings/strings.js +1 -1
  376. package/modules/sky/Sky.js +104 -89
  377. package/modules/sky/clouds.js +16 -17
  378. package/modules/sky/dome.js +100 -0
  379. package/modules/sky/domeLayers.js +5 -5
  380. package/modules/sky/environment.js +45 -169
  381. package/modules/sky/fog.js +5 -180
  382. package/modules/sky/frame.js +26 -90
  383. package/modules/sky/season.js +3 -3
  384. package/modules/sky/shader.js +35 -29
  385. package/modules/sky/skyModule.js +25 -22
  386. package/modules/sky/tint.js +9 -11
  387. package/modules/terrain/ChunkManager.js +29 -12
  388. package/modules/terrain/draw.js +154 -0
  389. package/modules/terrain/index.js +44 -66
  390. package/modules/terrain/terrainDefaults.js +2 -2
  391. package/modules/terrain/terrainEdit.js +1 -1
  392. package/modules/terrain/terrainGen.js +2 -2
  393. package/modules/triggers/index.js +10 -6
  394. package/modules/vegetation/Vegetation.js +58 -17
  395. package/modules/vegetation/draw.js +191 -0
  396. package/modules/vegetation/groundChunks.js +1 -1
  397. package/modules/vegetation/index.js +10 -10
  398. package/modules/water/Water.js +135 -88
  399. package/modules/water/surface.js +53 -53
  400. package/modules/weather/Weather.js +52 -17
  401. package/modules/weather/particles.js +13 -5
  402. package/modules/weather/shaders.js +1 -1
  403. package/modules/weather/weatherDraw.js +141 -0
  404. package/modules/world/World.js +2 -2
  405. package/modules/world/views.js +1 -1
  406. package/package.json +3 -2
  407. package/presets.js +2 -2
  408. package/render/PostFX.js +199 -41
  409. package/render/backend.js +52 -6
  410. package/render/cascades.js +195 -0
  411. package/render/cascades.tsl.js +96 -0
  412. package/render/daylight.js +39 -0
  413. package/render/detail.js +5 -5
  414. package/render/effects.js +41 -26
  415. package/render/fx/cel.tsl.js +42 -0
  416. package/render/fx/index.js +7 -5
  417. package/render/fx/patchNodes.tsl.js +1 -1
  418. package/render/fx/postWebGPU.tsl.js +30 -7
  419. package/render/fx/sky.tsl.js +19 -92
  420. package/render/fx/water.tsl.js +1 -1
  421. package/render/layers.js +14 -0
  422. package/render/lighting.js +6 -5
  423. package/render/lightmap.js +142 -0
  424. package/render/lights.js +23 -201
  425. package/render/materials.js +44 -160
  426. package/render/neutral.js +23 -0
  427. package/render/occlusion.js +184 -0
  428. package/render/ownFrame.js +1 -1
  429. package/render/patches.js +34 -29
  430. package/render/postWebGL.js +11 -3
  431. package/render/probes.js +179 -122
  432. package/render/slots.js +4 -4
  433. package/render/terms.js +53 -101
  434. package/render/uniformDecl.js +1 -1
  435. package/types/core.d.ts +333 -296
  436. package/types/gameplay.d.ts +65 -26
  437. package/types/generated/core/Audio.d.ts +1 -1
  438. package/types/generated/core/DebugOverrides.d.ts +14 -6
  439. package/types/generated/core/Input.d.ts +9 -2
  440. package/types/generated/core/page.d.ts +9 -2
  441. package/types/generated/modules/grid/Layer.d.ts +8 -0
  442. package/types/generated/modules/grid/index.d.ts +29 -5
  443. package/types/generated/modules/particles/Particles.d.ts +13 -6
  444. package/types/generated/modules/sky/Sky.d.ts +85 -18
  445. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  446. package/types/generated/modules/water/Water.d.ts +50 -3
  447. package/types/generated/modules/weather/Weather.d.ts +33 -3
  448. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  449. package/types/generated/modules/world/World.d.ts +2 -2
  450. package/types/generated/render/PostFX.d.ts +53 -10
  451. package/types/generated/render/lighting.d.ts +29 -0
  452. package/types/generated/render/materials.d.ts +19 -44
  453. package/types/generated/render/occlusion.d.ts +13 -0
  454. package/types/physics.d.ts +5 -3
  455. package/types/tsl.d.ts +8 -0
  456. package/types/world.d.ts +376 -57
  457. package/ui/Focus.js +12 -2
  458. package/ui/LoadingScreen.js +2 -2
  459. package/ui/Parts.js +8 -4
  460. package/ui/UI.js +10 -10
  461. package/ui/cursor.js +1 -1
  462. package/ui/theme.js +33 -27
  463. package/ui/touchPart.js +1 -1
  464. package/core/look/coreParts.js +0 -219
  465. package/core/look/part.js +0 -253
  466. package/core/look/points.js +0 -255
  467. package/core/look/report.js +0 -96
  468. package/core/look/shadowPart.js +0 -63
  469. package/core/look/state.js +0 -45
  470. package/core/look/write.js +0 -70
  471. package/core/styleParts.js +0 -114
  472. package/docs/api/style.md +0 -136
  473. package/docs/api/terrainLook.md +0 -10
  474. package/docs/api/vegetationLook.md +0 -10
  475. package/docs/api/weatherLook.md +0 -10
  476. package/docs/recipes/09-style.md +0 -218
  477. package/docs/recipes/35-style-from-reference.md +0 -153
  478. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  479. package/docs/recipes/38-environment-look-hooks.md +0 -99
  480. package/docs/recipes/41-thing-registry.md +0 -97
  481. package/docs/recipes/44-water-weather-look-hooks.md +0 -144
  482. package/docs/recipes/48-make-material.md +0 -75
  483. package/docs/recipes/52-look.md +0 -282
  484. package/examples/action/look.js +0 -5
  485. package/examples/sheepisland/style/index.js +0 -79
  486. package/examples/styletest/look.js +0 -11
  487. package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
  488. package/examples/webgpu-tsl/tslScene.js +0 -75
  489. package/examples/world/style/index.js +0 -61
  490. package/examples/world/style/plugins/10-bloom.js +0 -5
  491. package/modules/sky/cascades.js +0 -186
  492. package/modules/sky/cascades.tsl.js +0 -82
  493. package/modules/sky/look.js +0 -54
  494. package/modules/sky/lookFog.js +0 -76
  495. package/modules/sky/lookShadow.js +0 -62
  496. package/modules/sky/lookSky.js +0 -169
  497. package/modules/sky/shadow.js +0 -98
  498. package/modules/terrain/look.js +0 -83
  499. package/modules/terrain/lookGround.js +0 -66
  500. package/modules/vegetation/look.js +0 -119
  501. package/modules/vegetation/lookWind.js +0 -98
  502. package/modules/water/look.js +0 -91
  503. package/modules/water/surfaceDefaults.js +0 -3
  504. package/modules/weather/look.js +0 -74
  505. package/modules/weather/weatherLook.js +0 -135
  506. package/render/lookGlow.js +0 -139
  507. package/render/lookSurface.js +0 -224
  508. package/render/postLook.js +0 -164
  509. package/render/surface.js +0 -105
  510. package/types/generated/modules/weather/weatherLook.d.ts +0 -12
  511. package/types/style.d.ts +0 -671
package/docs/api/tools.md CHANGED
@@ -1,12 +1,13 @@
1
1
  # Utility functions (imported from threedog)
2
2
 
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)
3
+ - `PICTURE_SLOTS: Readonly<Record<PictureSlot, { readonly what: str…` — The picture slots: what each one is and which describe('picture').picture.writers names it covers (a name ending in '.' covers everything under it)
4
+ - `weather(opts?: WeatherOptions) → [ModuleDef<Weather>, ModuleDef<im…` — Weather: two modules for one engine.use: the state (engine.weather, type 'world') and its picture (engine.weatherDraw, type 'picture'; needs sky)
4
5
  - `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'] })
5
6
  - `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
6
7
  - `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.
7
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. 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
9
  - `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).
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).
10
+ - `grids(opts?: GridsOptions) → 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). Options: ok, bad, previewOpacity, previewHeight (the preview box), tiles, tileLift (layer tiles). The materials are pv.material and layer.material.
10
11
  - `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
11
12
  - `EASINGS: Record<EaseName, (t: number) => number>` — All easing functions: name -> function
12
13
  - `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`.
@@ -15,13 +16,11 @@
15
16
  - `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.
16
17
  - `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).
17
18
  - `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).
19
19
  - `createTerrain(cfg?: Partial<TerrainConfig>) → TerrainGen` — Pure terrain computation (no engine needed), for previewing heights before start: createTerrain({ seed, ...terrainPreset() }).surface(x, z)
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 }).
20
+ - `terrainMaterial(base?: THREE.Material | null, engine?: { assets: any }, { effects, detail }?: { effects?, detail? }) → THREE.Material` — Terrain material: base (default neutral with vertex colors) + cloud shadows + season tint + optional detail layer (detail: see DetailOptions; defaults scale 0.25, strength 0.35, top-down world projection, multiply). Pass the engine so its assets load a detail texture by name. effects: false returns your base as is (no engine patch at all, the vegetation.define({ effects: false }) word).
21
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.
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).
23
- - `MATERIAL_PURPOSES: string[]` — Material roles the engine itself uses
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):
22
+ - `applyEffects(material: THREE.Material, { wind, clouds, season, detail, lighting, engine, patches }?: { wind?, clouds?, season?, detail?, lighting?, engine?, … }) → THREE.Material` — Add effects to any material (the engine's or your own); 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 engine.uniforms.uCloudShadow), 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 DetailOptions in render/detail.js; a texture given by asset name loads from `engine`, default the first live engine), lighting (light shaping: { wrap, shadowTint, rim }, or your own { glsl, uniforms }; see LightingOptions in render/lighting.js; materials with the same options share one program).
23
+ - `rampTexture(ramp: (number | import("../../common").…)[], soften?: number) → THREE.DataTexture` — The gradientMap of a toon material from `ramp` (grays or colors, dark to light) and `soften` (0 = hard bands, 1 = bands melt into each other). A gray number n is the light's strength in that band. three's toon reads only the red channel of this texture on both renderers; color entries tint the band under `celLighting` of threedog/tsl (WebGPU route).
25
24
  - `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).
26
25
  - `materialPatches(material: THREE.Material) → string[]` — Names of the patches on a material (in order), e.g. ['clouds', 'tint', 'wind']
27
26
  - `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'.
@@ -45,6 +44,7 @@
45
44
  - `render: (data, tools) => string` Default content: (data, tools) => HTML
46
45
  - `data?: () => any` Template data
47
46
  - `onCancel?: () => void` What to do on the back key (Esc), default closes the window (an open window is on the UI focus stack, and Esc goes only to the topmost)
47
+ - `closable?: boolean` false: no close button and Esc does nothing, so only the game's own buttons end it (a win or lose window must not drop the player back into the game). Default true
48
48
  - **UIWindow** Window returned by makeWindow()
49
49
  - `el: HTMLElement`
50
50
  - `open: boolean` Whether it is open
@@ -68,6 +68,7 @@
68
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
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
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
+ - `celLighting() → import('three/webgpu').LightingMo…` — The lighting model for cel bands with colored ramps: assign it to a MeshToonNodeMaterial, whose gradientMap holds the ramp (rampTexture). A shadowed pixel reads the dark end of the ramp, so a cast shadow takes the same flat band and color as the side turned away. Without a gradientMap: two levels, as three's toon.
71
72
  - `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
73
  - `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
74
  - `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
@@ -4,6 +4,8 @@ Trigger zones (triggers() module)
4
4
 
5
5
  - Options `TriggersOptions`:
6
6
  - `action?: string` Action name that toggles the debug view 'triggers' (engine.debug.view), default 'triggersDebug'
7
+ - `debugColor?: ColorLike` Line color of the debug view 'triggers', default neutral gray
8
+ - `debugOpacity?: number` Line opacity of the debug view 'triggers', default 0.8
7
9
 
8
10
  ## Methods and properties
9
11
  - `triggers.list() → Trigger[]` — All trigger zones (a new array)
@@ -10,7 +10,9 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
10
10
  - `seed?: number` Placement seed, default 1
11
11
 
12
12
  ## Methods and properties
13
- - `vegetation.view(hooks: { species?, change?, ring?, show?, drop? }) → { remove(): void }` — Draw the plants: the hooks a look that replaces 'vegetation-look' uses. species(sp): defined or defined again (sp.source = the define() options); change(c, name): c.plants[name] placed, replaced or gone, or c.hidden[name] (felled slots) changed; ring(c, ring): LOD ring; show(c, visible); drop(c): released. What is already there is replayed at once. Returns { remove() } (ctx.track it). Example: `ctx.track(engine.vegetation.view({ change(c, name) { draw(c, c.plants[name]) }, drop(c) { undraw(c) } }))`
13
+ - `vegetation.sway(spec: string | { glsl?, tsl?, uniforms? } | null)` — Replace the sway shape of every species whose wind is a number, planted ones too; a species with its own wind object keeps it. null gives the built-in sway back. GLSL defines void threedogWind(inout vec3 transformed, vec3 ip, vec3 position); tsl: (ctx) => the moved object-space position
14
+ - `vegetation.color(spec: string | { glsl?, tsl?, uniforms?, pars? } | null)` — Code in the 'color' slot of every species' material, planted ones too (diffuseColor is yours); tsl: (ctx) => vec4 from ctx.color; null takes it off
15
+ - `vegetation.view(hooks: { species?, change?, ring?, show?, drop? }) → { remove(): void }` — Draw the plants: the hooks a draw part that replaces 'vegetation-draw' uses. species(sp): defined or defined again (sp.source = the define() options); change(c, name): c.plants[name] placed, replaced or gone, or c.hidden[name] (felled slots) changed; ring(c, ring): LOD ring; show(c, visible); drop(c): released. What is already there is replayed at once. Returns { remove() } (ctx.track it). Example: `ctx.track(engine.vegetation.view({ change(c, name) { draw(c, c.plants[name]) }, drop(c) { undraw(c) } }))`
14
16
  - `vegetation.rebuild()` — Place every chunk again: after changing the ground behind the same provider (a ground function reading game state). A new setGround or level is followed automatically
15
17
  - `vegetation.setShadowRing(name: string, ring: number)` — Change at runtime how far a vegetation kind casts shadows: within `ring` chunk rings of the player (0 = only the chunk you stand in, 1 = the default, larger = further and dearer). Takes effect at once; the define() option shadowRing is only the starting value. An unknown name warns with the known ones. Example: `engine.vegetation.setShadowRing('tree', 0); // graphics setting "shadows: low": trees shadow only the nearest chunk`
16
18
  - `vegetation.define(name: string, opts: VegetationOptions) → Species | Promise<Species>` — Define a kind of vegetation (a model name in model / lodGeometry: resolves first, so the result is a Promise of the species)
@@ -18,6 +20,9 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
18
20
  - `vegetation.restoreInstance(species: string, cx: number, cz: number, id: number)` — Restore one
19
21
  - `vegetation.instanceAt(position: PositionLike, opts?: { radius?, species? }) → VegetationHit | null` — The one nearest to position within radius meters (default 2) (species restricts to one kind), null if none
20
22
  - Also: `vegetation.get(name: string) → Species | undefined`, `vegetation.list() → Species[]`, `vegetation.isRemoved(species: string, cx: number, cz: number, id: number) → boolean`
23
+ - Properties:
24
+ - `material: Material | null` The shared default material: species with no material or model of their own draw it, as given, planted ones too; null gives the neutral default back. Until set, reading gives the neutral source of each species' own copy (only .color written there reaches them all). Throws when a game module drew the plants instead (replaces: 'vegetation-draw').
25
+ - `patches: any[]` The engine's plant patches (season tint, sway with one amplitude, vegetation.color() code) for applyEffects(myMaterial, { patches })
21
26
 
22
27
  ## Data structures
23
28
  - **VegetationOptions** Parameters of engine.vegetation.define(name, {...})
@@ -27,7 +32,7 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
27
32
  - `rule?: VegetationRule` Placement rule (random scatter per chunk)
28
33
  - `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
34
  - `densityMap?: ((x, z) => number) | { url?, data?, width?, height?, size, center?, … }` How much of this species survives at each spot, 0 (none) ..
30
- - `wind?: number` Wind sway amplitude, 0 = still
35
+ - `wind?: number | { amplitude, glsl?, tsl?, uniforms? }` Wind sway amplitude, 0 = still; or this species' own sway: { amplitude, glsl, tsl, uniforms }, which vegetation.sway() leaves alone (recipes/36)
31
36
  - `nearOnly?: boolean` Only generated near the player (grass, flowers)
32
37
  - `maxRing?: number` No longer drawn beyond this many rings
33
38
  - `fade?: false | { start?: number; end?: number }` Distance fade of a near-only species (grass, flowers, pebbles, debris ...): instances shrink out over a band in metres from the player instead of popping per chunk at the ring edge. Default for nearOnly: end = maxRing x chunk size, start = 65% of it. `false` keeps the hard ring edge (also the default for species that are not nearOnly).
@@ -0,0 +1,10 @@
1
+ # engine.vegetationDraw — vegetationDraw()
2
+
3
+ Draws the plants (vegetation()'s drawing module, slot 'vegetation-draw'; undefined when a game replaced it)
4
+
5
+
6
+ ## Methods and properties
7
+ - `vegetationDraw.mesh(c: TerrainChunk, name: string) → InstancedMesh | null` — The InstancedMesh drawing one species in one chunk, null when none
8
+ - `vegetationDraw.kind(name: string) → { geometry, lodGeometry, material, fadeUniforms, shared } | null | …` — How one species is drawn: its geometry, low-poly geometry, patched material(s), near-fade uniforms; shared = it draws engine.vegetation.material; null for an unknown name
9
+ - Properties:
10
+ - `meshes: Map<TerrainChunk, { group: Object3D; ims: Record<string, In…` chunk record -> { group, ims: { species name: InstancedMesh } }
package/docs/api/water.md CHANGED
@@ -8,13 +8,17 @@ Water surface (water() module)
8
8
  - `flat?: boolean` Flat shading (low poly), default true
9
9
  - `size?: number` Edge length of the global water plane (meters), default 900
10
10
  - `segments?: number` Mesh subdivision of the global water, default 150
11
- - `uniforms?: import('./style').StyleWater['uniforms']` Uniforms for your look.water hooks' GLSL (same as style.water.uniforms)
12
11
 
13
12
  ## Methods and properties
13
+ - `water.shader(opts?: WaterShaderOptions)` — Which GLSL the water has. Keys left out keep what an earlier call gave; null takes one back to the built-in. Refreshes engine.water.patches and engine.water.uniforms and patches the engine's own material again (one recompile). A game's material is the game's to patch again. uWave, uWaveScale, uWaveSpeed and uFresnel stay the same objects. Example: `engine.water.shader({ depthColor: { shallow: 0x55ddcc, deep: 0x082040 }, foam: true }); engine.water.shader({ uniforms: { uBands: 4 }, surface: `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) { return vec4(base.rgb * floor(facing * uBands) / uBands, base.a); }` });`
14
+ - `water.normalMap(name: string | null, opts?: { scale?, repeat?, speed? }) → THREE.Texture | null` — Normal map by asset name (null = none): a flat-normal placeholder until the asset loads, then it takes the asset's image source (shared, not copied; goes through asset management, so it can be preloaded and released). Goes on the engine's own material; a game's material takes the returned texture (also engine.water.normalTexture). The tiling and the scroll apply whatever material draws. Keys left out keep their value (defaults scale 0.4, repeat 0.05, speed [0.01, 0.006]). Example: `engine.water.normalMap('water-n', { scale: 0.6, repeat: 0.1, speed: [0.02, 0.01] });`
14
15
  - Properties:
15
- - `material: THREE.Material` Water material (shared by all water)
16
+ - `normalTexture: THREE.Texture | null` The loaded normal map (null = none): a game material takes it as its own normalMap. Its offset scrolls and the water UVs tile for it whatever material draws
17
+ - `patches: import("../../render/patches.js").ShaderPatch[]` The engine's water shader patches (waves, waterSurface when asked for, fresnel), so a game material keeps the behavior: applyEffects(mat, { patches: engine.water.patches })
18
+ - `uniforms: Record<string, { value: any }>` Shader values, written directly and live: uWave, uWaveScale, uWaveSpeed, uFresnel, uTime; with depthColor / foam uWaterShallow, uWaterDeep, uWaterCurve, uFoamColor, uFoamStart, uFoamEnd, uFoamOpacity; and what shader({ uniforms }) declared
16
19
  - `bodies: Map<WaterBody, THREE.Mesh>` Water body → mesh
17
20
  - `sea: THREE.Mesh | null` Global water mesh (null when absent)
21
+ - `material: THREE.Material` Water material, shared by all water. Reading gives the plain three.js material in use (a neutral MeshLambertMaterial until you set one); setting swaps it on every water mesh and draws it as given: no engine patch is added, so a material that should keep the waves goes through applyEffects(m, { patches: engine.water.patches })
18
22
 
19
23
  ## Data structures
20
24
  - **WaterBodyOptions** Parameters of engine.addWaterBody(): position center, level water surface height (meters); give radius for a circle, halfWidth / halfDepth for a rectangle
@@ -4,6 +4,7 @@ Weather state (weather() module): the table, current values, set / setAuto, save
4
4
 
5
5
 
6
6
  ## Methods and properties
7
+ - `weather.define(field: string, spec: WeatherParticles | null) → WeatherParticleSystem | null` — Draw a field of the weather table with particles: your own (ash, petals, sparks) or rain / snow in place of the built-in ones. The amount each frame is weather.current[field], so they fade with the weather. spec takes the keys of weather({ rain }), or { create(engine, { area, count }) => { object, update?(amount, { camera, time, wind }) } } for a system of your own; null gives rain / snow back to weather({ rain, snow }) and removes any other field. Defining a field again replaces it. A field no type has throws with the table's fields. Example: `engine.weather.define('ash', { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 });`
7
8
  - `weather.setAuto(on: boolean)` — Automatic weather on/off
8
9
  - `weather.set(name: WeatherName, opts?: { seconds?: number })` — Switch weather. seconds: transition seconds, default 15; 0 switches at once (current is the new weather before the next step, so a screenshot or test right after shows all of it). Options in an object like every other engine call: set('rain', 20) throws [module-params] in dev (the old positional form). Example: `engine.weather.set('rain', { seconds: 20 })`
9
10
  - `weather.label(name?: string) → string` — Display name of a weather (string table weather.<name>, falls back to the name itself); defaults to the current weather
@@ -17,3 +18,7 @@ Weather state (weather() module): the table, current values, set / setAuto, save
17
18
  - `autoTransition: number` Transition seconds for automatic weather
18
19
  - `lightningFirst: number` Seconds to the first bolt (also after a load without a saved timer)
19
20
  - `lightningInterval: number[]` [min, max] seconds between bolts while a type with lightning > 0.5 holds
21
+ - `lightning: (flash: number, engine: any) => number` Strike picture: flash (1 at the strike, fading in a third of a second) -> sky flash amount. Write it at any time
22
+ - `lightningBrightness: number` Multiplies the sky flash of every strike; write it at any time
23
+ - `overcastColor: THREE.Color` Color the sky turns as a weather type raises grey: a THREE.Color, overcastColor.set(0x667788) changes it live
24
+ - `particles: Record<string, WeatherParticleSystem>` The particle systems drawn now, by field: rain and snow when the table has them, plus what define() added. Example: `engine.weather.particles.rain.spec.speed = 30;`
@@ -0,0 +1,10 @@
1
+ # engine.weatherDraw — weatherDraw()
2
+
3
+ Weather drawing (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, material, uniforms, spec } (rain / snow when the table has them, plus fields engine.weather.define adds)
package/docs/api/world.md CHANGED
@@ -13,7 +13,7 @@ World data (world() module): things that must be saved, survive level changes an
13
13
  - `world.remove(id: string)` — Remove a record (its model is torn down too) and emit the world:remove event. Does nothing if the id does not exist. Removing an initial record is saved, so it stays gone after loading
14
14
  - `world.query(opts?: { kind?, near?, radius?, where?, zone? }) → WorldRecord[]` — Query records; returns an array. With near only nearby cells are scanned and results are sorted nearest first (radius defaults to 30 m); where filters further. For neighbor queries every step use forEachNear. Example: `engine.world.query({ kind: 'zombie', near: engine.player, radius: 30, where: z => !z.dead })`
15
15
  - `world.forEachNear(center: any, radius: number, fn: (rec, d2) => void)` — Call fn(rec, d2) for each record within radius meters (horizontal distance) of center; d2 is the squared distance. Unsorted, no allocation: use it for per-step neighbor queries (hundreds of zombies avoiding each other). Don't add / remove / move in the callback (moving into a cell not yet visited visits it again): record the change and apply it after the loop. Example: `engine.world.forEachNear(rec.position, 5, (o, d2) => { if (o !== rec && o.kind === 'zombie') n++; })`
16
- - `world.present(kind: string, opts: { build, update?, dispose?, show?, radius?, positionFrom? }) → { remove(): void }` — Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks: build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object: reported once, does not block ready, retried when you leave and come back. update(rec, obj, dt): called every frame for records that have a model (change the look from the data, e.g. an opened chest swaps texture). dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj). show(rec) → false: this record has no model right now (picked up, waiting to respawn); re-evaluated when world.set changes records of this kind. Example: `engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, makeMaterial('prop')), dispose: (rec, obj) => engine.remove(obj), show: rec => !rec.looted })`
16
+ - `world.present(kind: string, opts: { build, update?, dispose?, show?, radius?, positionFrom? }) → { remove(): void }` — Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks: build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object: reported once, does not block ready, retried when you leave and come back. update(rec, obj, dt): called every frame for records that have a model (change the picture from the data, e.g. an opened chest swaps texture). dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj). show(rec) → false: this record has no model right now (picked up, waiting to respawn); re-evaluated when world.set changes records of this kind. Example: `engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, new THREE.MeshStandardMaterial()), dispose: (rec, obj) => engine.remove(obj), show: rec => !rec.looted })`
17
17
  - `world.view(id: string) → any` — The current model of this record (only exists nearby; null if not built yet or far away)
18
18
  - `world.refresh()` — Build / tear down models for the stream sources right now (normally automatic every frame, with a per-frame limit). Use it right after add when you need the model: sync builds are available via view(id) after the call, for async ones also await world.whenReady. Example: `engine.world.add({ id: 'gate', kind: 'gate', position: p }); engine.world.refresh(); engine.world.view('gate')`
19
19
  - `world.simulate(kind: string, opts: { near?, far?, farEvery?, radius?, fullRadius?, nearEvery?, … }) → { remove(): void }` — Register how a kind of thing changes (gameplay logic goes here, runs in the fixed step); near / far is split by distance from world.anchor (default: the player): near(rec, dt, obj): within radius, once per fixed step (obj is the model, may be null if not built yet; gameplay must not depend on it); far(rec, dt): farther away, once every farEvery seconds; dt is the seconds accumulated since the last simulation (can catch up a long time at once); on the far → near step, far runs first to pay back the owed time. With only far (crops), near also advances via far; with only near, far records are not simulated and owed time is not made up. Both dt are accumulated real (fixed-step) seconds (not multiplied by clock.rate). For things measured in game clock (grows over days) store engine.clock.now and compare. Example: `engine.world.simulate('zombie', { near: (rec, dt) => chase(rec, dt), far: (rec, dt) => wander(rec, dt), farEvery: 2 })`
@@ -9,27 +9,26 @@ template (`threedog new-game my-game`, section 0); the engine's own example is `
9
9
  ```
10
10
  npm run new-game -- my-game # blank start: an empty scene and a camera; no gameplay, no genre assumed
11
11
  npm run new-game -- my-game --open-world # generated ground, a day/night sky, a follow camera and a player
12
- npm run new-game -- my-game --example # the open world plus a sample: hp / hunger, a rest op, apples, a searchable stash, a HUD counter
12
+ npm run new-game -- my-game --webgl # either one on WebGL, shaders in GLSL, instead of WebGPU and TSL
13
13
  ```
14
- (The `--` matters: without it npm swallows the flags. The CLI form takes them directly: `threedog new-game my-game --example`. `--example` uses engine placeholders (gray box, capsule), so it works with any style.)
14
+ (The `--` matters: without it npm swallows the flags. The CLI form takes them directly: `threedog new-game my-game --open-world`.)
15
+ A new game runs on WebGPU, shaders in TSL (recipe 56); `--webgl` is for GLSL. Without WebGPU the same game runs on three's WebGL2 backend, slower; `engine.describe().renderer` says which and why.
15
16
  The name may only contain lowercase letters, digits and dashes; an existing directory under `games/` with the same name is refused. What it does:
16
- 1. Copies `packages/tools/templates/game/` to `games/my-game/` (`__NAME__` in the files is replaced by the name); `--open-world` copies `templates/openworld/` over it first, `--example` also `templates/example/`.
17
+ 1. Copies `packages/tools/templates/game/` to `games/my-game/` (`__NAME__` in the files is replaced by the name); `--open-world` copies `templates/openworld/` over it first.
17
18
  2. Creates the `node_modules/my-game` link (the path npm gives a workspace named `my-game`). It builds nothing and leaves `package-lock.json` alone; it runs `npm install` only when a dependency of the template is not installed yet, and says so.
18
19
  3. Runs `map` (generates GAMEMAP.md) and `check`. Any failing step stops and says why. The smoke test (`threedog test -w games/my-game`) builds, so it is left to you.
19
20
 
20
- The default game is deliberately empty: `world()` + `content()`, the engine's camera placed by hand (a plain `THREE.PerspectiveCamera`) and the always-on
21
- render baseline (default lights, tone mapping, color space); no ground, sky, player or camera rig, because which of those a game needs depends on its genre
21
+ The default game has no genre: `world()` + `content()`, what nearly every game needs (a start screen with Continue / Start, autosave, Esc = pause + settings menu; delete a line if the game does not want it), the engine's camera placed by hand (a plain `THREE.PerspectiveCamera`) and the gray
22
+ starting picture in `picture/` (a sun, an ambient light, the tone curve, written by the game); no ground, sky, player or camera rig, because which of those a game needs depends on its genre (a character walking around a place you built: recipe 63, about twenty lines)
22
23
  (a card table, a puzzle room, a side-scroller and an open world start differently). Content files are empty arrays / objects (each
23
- has one comment line saying what goes there and which recipe teaches it), and an empty style in `style/index.js` (every section is a commented-out stub;
24
- with it empty the engine shows gray placeholders; fill it with your own art using recipes 09 and 52). `CLAUDE.md` says "This game has no gameplay yet; build what DESIGN.md describes".
24
+ has one comment line saying what goes there and which recipe teaches it), and `picture/`: `index.js` (wiring), `palette.js` (colors and key values), `lights.js`, `materials.js`, plain three.js
25
+ that is yours to change or replace (recipe 62). `CLAUDE.md` says "This game has no gameplay yet; build what DESIGN.md describes".
25
26
  `--open-world` swaps `main.js` for `openWorld` (generated terrain from `@threedog/terrain-noise`, vegetation, a day/night sky, weather, water, collision, a
26
- follow camera) and a player at a flat spot; it adds `@threedog/terrain-noise` to `package.json`. `--example` builds on it and adds the patterns: `interactions / inventory / hud`, 3 apples on the ground and one stash (a template in `content/templates.js` placed by
27
- `content/props.js`, searched through the op `stash.search`); its `main.js` shows the game's own state registered with `describe.add` and `saves.register`, an op
28
- with `can` / `run`, and the `onFixed` / `onFrame` split. `spawn` and `places` take any `{ x, z }` (or `{ x, y, z }`); `findSpawn` is only for generated terrain.
27
+ follow camera) and a player at a flat spot, with `sky()` giving the signals and `picture/` writing the lights; it adds `@threedog/terrain-noise` to `package.json`. `spawn` and `places` take any `{ x, z }` (or `{ x, y, z }`); `findSpawn` is only for generated terrain.
29
28
  In an open-world start, to change the camera: `openWorld({ camera: 'firstPerson' })` (`follow` / `firstPerson` / `rts` / `fixed`, or pass a camera module directly; there is
30
29
  no default).
31
30
  - The comments in `main.js` list further gameplay modules you can add; usage is in `../api/<module>.md`.
32
- - To change the starting point of new games, edit the real files in `packages/tools/templates/game/` (`templates/openworld/` for `--open-world`, `templates/example/` for the sample).
31
+ - To change the starting point of new games, edit the real files in `packages/tools/templates/game/` (`templates/openworld/` for `--open-world`).
33
32
  - `DESIGN.md` is an empty template: write your gameplay ideas there. `CLAUDE.md` only points the way (read `node_modules/threedog/docs/AI.md` first,
34
33
  then GAMEMAP, DESIGN) and does not copy engine rules.
35
34
  - There is no `tests/`: when `tests/specs/` does not exist, `npm test -w games/my-game` runs a smoke test automatically.
@@ -37,7 +36,7 @@ no default).
37
36
  ## 1. Creating the files by hand (to learn what each file is, or when the template doesn't fit)
38
37
  | File | Content |
39
38
  |---|---|
40
- | `games/my-game/package.json` | Copy `package.json` from the game template (or run `threedog new-game my-game`) and set `name` to `my-game` (the plain game name, in this repository and in a game repo of its own; `@threedog/` is the engine's packages; dependencies `threedog`, `@threedog/tools`, plus `@threedog/terrain-noise` only for an open-world start, and your style (and `@threedog/post-effects` if the pack uses it) only when `main.js` imports it; the default style is the game's own `style/index.js`; scripts dev/build/preview/test/check/map) |
39
+ | `games/my-game/package.json` | Copy `package.json` from the game template (or run `threedog new-game my-game`) and set `name` to `my-game` (the plain game name, in this repository and in a game repo of its own; `@threedog/` is the engine's packages; dependencies `threedog`, `@threedog/tools`, plus `@threedog/terrain-noise` only for an open-world start, and your style (and `@threedog/post-effects` if the pack uses it) only when `main.js` imports it; the game's picture is its own `picture/` folder; scripts dev/build/preview/test/check/map) |
41
40
  | `games/my-game/vite.config.js` | One line: `export default gameConfig(import.meta.dirname)` (imported from `@threedog/tools/vite`); *.html files in the directory are bundled automatically, no `input` needed. Without `@threedog/tools`, a plain vite config needs `worker: { format: 'es' }` (the engine's Workers are ES modules) or `vite build` fails; `threedog dev / build` on a folder with no vite config uses the preset |
42
41
  | `games/my-game/index.html` | The page: one `<canvas id="view">` with a CSS size + `/main.js` (for more pages put `xxx.html` in the same directory); see §5 for embedding |
43
42
  | `games/my-game/main.js` | Install modules, compute places, `content.load`, game-specific logic |
@@ -45,7 +44,7 @@ no default).
45
44
  | `games/my-game/content/*.js` | Only these names are read: items pickups containers npcs dialogues quests actions places triggers level vegetation props templates audio grids renames rules, plus the game's own kinds (rules.js) |
46
45
  | `games/my-game/DESIGN.md` | Hand-written design decisions (a few lines of `- **decision**: reason`), copied into GAMEMAP.md |
47
46
  | `games/my-game/CLAUDE.md` | A few lines: read `node_modules/threedog/docs/AI.md`, then this directory's GAMEMAP.md and DESIGN.md (copy the template's) |
48
- | `games/my-game/public/` | This game's art assets (URL `/models/...`); keep Blender source files in `games/my-game/art/models/`, `npm run assets -- -w my-game` compresses them over |
47
+ | `games/my-game/public/` | This game's art assets (URL `/models/...`); keep Blender source files in `games/my-game/art/models/`, `npm run assets -- -w my-game` compresses them into `public/optimized/` |
49
48
 
50
49
  After creating them, run `npm install` once at the repository root (this links the new game into the workspaces so `threedog` can find it).
51
50
 
@@ -67,17 +66,17 @@ The template's `tsconfig.json` checks the game files only (`checkJs`), with `lib
67
66
  </head><body><canvas id="view" tabindex="0"></canvas><script type="module" src="/main.js"></script></body></html>
68
67
  ```
69
68
 
70
- `games/my-game/main.js`, here an open-world game with a few gameplay modules (a blank game is the template's `main.js`: `createEngine`, `world(), content()`, the camera placed by hand, `start()`):
69
+ `games/my-game/main.js`: the opening lines are written out once, in [recipe 63](63-third-person-start.md) §1 (the blank template's `main.js` has the same opening with `world(), content(), settings()` and the camera placed by hand). What an open-world game with a few gameplay modules changes in it:
71
70
  ```js
72
71
  // my-game: ... (this first comment line appears in the file table of GAMEMAP.md)
73
- import { createEngine, presets, openWorld, interactions, dialogue, inventory, pickups, quests, content } from 'threedog';
74
- import style from './style/index.js'; // the game's own style (the engine ships no art)
72
+ // The opening stays as in recipe 63 §1: createEngine({ canvas, lights: false, ui, saveKey, bindings }), createPicture(engine) after engine.use,
73
+ // Object.assign(window, { engine, picture }) (tests, screenshots and the console rely on it), await engine.start().
74
+ import { presets, openWorld, interactions, dialogue, inventory, pickups, quests, content } from 'threedog';
75
75
  import { terrainPreset } from '@threedog/terrain-noise'; // optional terrain generator (nor a world shape)
76
76
  import data from './content/index.js';
77
77
 
78
- // keys: modules only declare actions, the game binds them (presets.bindings.* are ready-made maps)
79
- const engine = createEngine({ canvas: document.getElementById('view'), style, ui: { loading: { title: 'My game' } }, saveKey: 'my-game',
80
- bindings: { ...presets.bindings.walk, ...presets.bindings.interact, ...presets.bindings.inventory, ...presets.bindings.quests } });
78
+ // keys: modules only declare actions, the game binds them (presets.bindings.* are ready-made maps); this goes in createEngine({ bindings })
79
+ const bindings = { ...presets.bindings.walk, ...presets.bindings.interact, ...presets.bindings.inventory, ...presets.bindings.quests };
81
80
  // the preset only covers world and environment; the debug panel is installed in dev builds only (debug: true forces it in release too)
82
81
  engine.use(openWorld({ camera: 'follow', seed: 42, terrain: terrainPreset(), time: 0.3 }),
83
82
  // add gameplay modules as the game needs (a shooter has no inventory); pickups() when items lie on the ground (content pickups)
@@ -87,9 +86,6 @@ engine.use(openWorld({ camera: 'follow', seed: 42, terrain: terrainPreset(), tim
87
86
  const home = engine.characters.findSpawn([0, 0, 0], { minH: 3, maxH: 14 });
88
87
  engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: home });
89
88
  engine.content.load(data, { places: { ...data.places, home } }); // content/places.js names + this one; content uses { place: 'home', x, z }, quests target: 'home'
90
- // tests, screenshots and the console all rely on it (before start, so the dev bridge can wait for it)
91
- window.engine = engine;
92
- await engine.start();
93
89
  ```
94
90
  Every `openWorld` part takes `false` (leave it out) or its module's own options object, so you never have to drop the preset for one setting:
95
91
  `openWorld({ seed: 42, camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, characters: { npcs: false }, rigid: false, ambience:
@@ -100,7 +96,7 @@ false, debug: false })`;
100
96
  With `terrain: false` the game supplies its ground. Until it does, characters, props and pickups stand on an invisible flat plane at y = 0 (no
101
97
  warning): they look like they float over nothing. Draw the ground yourself, and if it is not flat at y = 0 tell the engine its height:
102
98
  ```js
103
- const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), makeMaterial('ground')); // what you see
99
+ const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), new THREE.MeshLambertMaterial({ color: 0x8c8c8c })); // what you see
104
100
  floor.receiveShadow = true; engine.add(floor);
105
101
  engine.setGround({ height: (x, z) => 0 }); // what walking, placing and the camera read (a ramp, a raised floor: return its y here)
106
102
  ```
@@ -1,8 +1,24 @@
1
1
  # Adding items and pickups
2
2
 
3
- **In this recipe**: 1. Write data · 2. In code · Single pieces · Limits · Using and dropping · The inventory window · Chests / corpses / shelves ·
3
+ **In this recipe**: Pick and count · 1. Write data · 2. In code · Single pieces · Limits · Using and dropping · The inventory window · Chests / corpses / shelves ·
4
4
  3. Verify
5
5
 
6
+ ## Pick and count: meshes you built, no bag
7
+ Shells on a beach, four kinds of flowers, letters to collect: things the player takes and a number goes up. `interactions()`, `hud()` and a key (`createEngine({ bindings: presets.bindings.interact })`: E) are enough:
8
+ ```js
9
+ engine.hud.counter('shells', { label: 'Shells', value: 0, max: 4 }); // at setup, not on session:start
10
+ shells.forEach((shell, i) => engine.interactions.add(shell, { id: `shell-${i}`, label: 'Pick up', once: true, counter: 'shells', onUse: () => engine.audio.sfx('pick') }));
11
+ ```
12
+ `once` hides the mesh after a use (`onUse` returning `{ ok: false }` leaves it); `counter` adds 1 through `engine.hud.add(name, n)`, and does nothing without
13
+ `hud()`. Both are saved and go back on a new game. The save knows a thing by `id`, else `mesh.name`: development throws when it has neither, or shares one with another once item.
14
+ A hidden mesh is only hidden: a collider it had is yours to remove in `onUse`. To add up without a thing to take, call `engine.hud.add('score', 10)` yourself.
15
+
16
+ | Use | When |
17
+ |---|---|
18
+ | `interactions.add(mesh, { once, counter })` | a mesh you already have, a number on screen, nothing to carry or spend |
19
+ | `pickups.spawn` (below) | it goes in a bag, respawns, is taken by walking into it (`auto`), is laid out in `content/`, or a net host must decide who got it |
20
+
21
+ ## Items and pickups
6
22
  Modules needed: `inventory()` (inventory; the window is the UI part `inventory`, opened with the key the game gives:
7
23
  `inventory()`; its open key is the game's: `presets.bindings.inventory` is I / gamepad Y, `inventory: []` none; no module binds a key by itself) +
8
24
  `pickups()` (things lying on the ground; needs `world()`, which `openWorld()` includes) + `interactions({ ...presets.interactions.nearest })` (walk up
@@ -69,7 +85,7 @@ also takes a key.
69
85
  ```js
70
86
  const I = engine.inventory;
71
87
  I.define('sword', { name: 'Sword', stack: 1 });
72
- const key = I.add('sword', 1, { data: { durability: 80, level: 3 } }); // 'sword#7'
88
+ const key = /** @type {string} */ (I.add('sword', 1, { data: { durability: 80, level: 3 } })); // 'sword#7' (add returns false when it does not fit)
73
89
  I.count('sword'); // every sword, with or without data
74
90
  I.get(key); // { key, id: 'sword', count: 1, data: { durability: 80, level: 3 }, def }
75
91
  I.list(); // every entry: [{ key, id, count, data, def }] for your own UI
@@ -126,8 +142,13 @@ engine.ui.open('inventory'); engine.ui.close('inventory'); // open / close fro
126
142
  ```
127
143
  The shape of an item on the ground is a model name from an asset pack, built through the same path as content props and templates (one build per
128
144
  name, cached / baked, the same shadow rule): the item's `model`, else a model named `pickup:<item id>`, else one named `pickup`, else a neutral gray
129
- box. A generator that returns bare geometry is drawn in the `pickup` material role in the item's own `color` (a coin, a gem, a medkit or a paper
130
- note are all just models). `style.pickup` holds look values only (color, size of the placeholder box, lift). For one object of the game's own pass
145
+ box. A generator that returns bare geometry is drawn with `engine.pickups.material` in the item's own `color` (a coin, a gem, a medkit or a paper
146
+ note are all just models).
147
+ ```js
148
+ engine.use(pickups({ color: 0xd8c070, size: 0.3, lift: 0.5 })); // default color, placeholder box, height above the ground
149
+ engine.pickups.material = new THREE.MeshStandardMaterial({ metalness: 0.8, roughness: 0.3 }); // swaps every box and geometry-only model; used as given
150
+ ```
151
+ A pickup or item with its own `color`, and a vertex-colored geometry, draw with a copy of that material carrying the color. For one object of the game's own pass
131
152
  `{ mesh }` (a three.js object cannot go into a save, so after loading it falls back to the item's model).
132
153
  To give / take items in content use the effect words: `{ give: { coin: 2 } }`, `{ take: { mushroom: 3 } }`; condition words:
133
154
  `{ has: { mushroom: 3 } }`, `{ lacks: { coin: 1 } }`.