threedog 0.2.1 → 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 (593) 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 +71 -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 +183 -59
  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 +37 -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 +14 -13
  58. package/core/gridLoad.js +2 -1
  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 +100 -41
  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 +63 -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 +87 -100
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +220 -147
  126. package/docs/COMMANDS.md +56 -35
  127. package/docs/CONVENTIONS.md +90 -28
  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 +11 -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 +38 -23
  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 +63 -60
  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 +28 -26
  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 +29 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +11 -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 +48 -34
  180. package/docs/recipes/02-npc.md +24 -7
  181. package/docs/recipes/03-items-pickups.md +35 -21
  182. package/docs/recipes/04-quests.md +12 -5
  183. package/docs/recipes/05-props-bake.md +151 -15
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +40 -9
  186. package/docs/recipes/08-weather-sky.md +145 -36
  187. package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
  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 +14 -6
  191. package/docs/recipes/14-custom-module.md +61 -29
  192. package/docs/recipes/15-perf.md +30 -9
  193. package/docs/recipes/16-dev-bridge.md +61 -37
  194. package/docs/recipes/18-world.md +16 -6
  195. package/docs/recipes/19-shooting-picking.md +6 -6
  196. package/docs/recipes/20-content-actions-save.md +55 -17
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +3 -3
  199. package/docs/recipes/23-ops.md +16 -10
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +11 -5
  202. package/docs/recipes/28-terrain.md +34 -1
  203. package/docs/recipes/29-grid.md +34 -16
  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 +26 -3
  208. package/docs/recipes/35-style-from-reference.md +88 -19
  209. package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
  210. package/docs/recipes/37-terrain-look-hooks.md +3 -2
  211. package/docs/recipes/38-environment-look-hooks.md +37 -26
  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 +2 -2
  215. package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
  216. package/docs/recipes/44-water-weather-look-hooks.md +26 -17
  217. package/docs/recipes/45-cascaded-shadows.md +16 -7
  218. package/docs/recipes/47-island-snow-backdrop.md +7 -7
  219. package/docs/recipes/48-make-material.md +11 -6
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +2 -2
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-look.md +197 -61
  224. package/docs/recipes/53-ground-up-close.md +1 -1
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +112 -0
  227. package/docs/recipes/56-webgpu-tsl.md +260 -0
  228. package/docs/recipes/57-control.md +65 -0
  229. package/docs/recipes/58-input.md +57 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +55 -0
  232. package/examples/action/.threedog/content-index.json +1 -0
  233. package/examples/action/GAMEMAP.md +17 -13
  234. package/examples/action/assets.js +8 -0
  235. package/examples/action/content/actions.js +1 -1
  236. package/examples/action/content/audio.js +5 -5
  237. package/examples/action/look.js +1 -1
  238. package/examples/action/main.js +10 -14
  239. package/examples/action/models.js +24 -23
  240. package/examples/pullable.json +111 -0
  241. package/examples/rc2d/.threedog/content-index.json +1 -0
  242. package/examples/rc2d/GAMEMAP.md +83 -0
  243. package/examples/rc2d/README.md +52 -0
  244. package/examples/rc2d/main.js +63 -0
  245. package/examples/rc2d/rc2d.js +197 -0
  246. package/examples/rc2d/shaders.js +144 -0
  247. package/examples/sheepisland/.threedog/content-index.json +1 -0
  248. package/examples/sheepisland/GAMEMAP.md +13 -11
  249. package/examples/sheepisland/assets.js +5 -0
  250. package/examples/sheepisland/main.js +17 -12
  251. package/examples/sheepisland/style/index.js +6 -6
  252. package/examples/styletest/.threedog/content-index.json +1 -0
  253. package/examples/styletest/GAMEMAP.md +15 -16
  254. package/examples/styletest/assets.js +6 -0
  255. package/examples/styletest/content/templates.js +1 -1
  256. package/examples/styletest/content/vegetation.js +1 -1
  257. package/examples/styletest/look.js +1 -1
  258. package/examples/styletest/main.js +17 -16
  259. package/examples/styletest/models.js +1 -1
  260. package/examples/styletest/params.js +3 -3
  261. package/examples/techniques/contact-shadows/README.md +92 -0
  262. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  263. package/examples/techniques/contact-shadows/main.js +53 -0
  264. package/examples/techniques/day-night-grade/README.md +86 -0
  265. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  266. package/examples/techniques/day-night-grade/main.js +51 -0
  267. package/examples/techniques/interior-light/README.md +103 -0
  268. package/examples/techniques/interior-light/interiorLight.js +45 -0
  269. package/examples/techniques/interior-light/main.js +124 -0
  270. package/examples/techniques/modular-building/README.md +125 -0
  271. package/examples/techniques/modular-building/kit.js +426 -0
  272. package/examples/techniques/modular-building/main.js +47 -0
  273. package/examples/techniques/night-lights/README.md +94 -0
  274. package/examples/techniques/night-lights/main.js +70 -0
  275. package/examples/techniques/night-lights/nightLights.js +91 -0
  276. package/examples/techniques/outlines-and-rim/README.md +59 -0
  277. package/examples/techniques/outlines-and-rim/main.js +84 -0
  278. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  279. package/examples/techniques/procedural-animation/README.md +77 -0
  280. package/examples/techniques/procedural-animation/creature.js +44 -0
  281. package/examples/techniques/procedural-animation/main.js +45 -0
  282. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  283. package/examples/techniques/procedural-surface/README.md +67 -0
  284. package/examples/techniques/procedural-surface/main.js +103 -0
  285. package/examples/techniques/procedural-surface/surface.js +120 -0
  286. package/examples/techniques/stylized-shading/README.md +75 -0
  287. package/examples/techniques/stylized-shading/main.js +93 -0
  288. package/examples/techniques/stylized-shading/shading.js +131 -0
  289. package/examples/techniques/sun-and-key-light/README.md +135 -0
  290. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  291. package/examples/techniques/sun-and-key-light/main.js +95 -0
  292. package/examples/techniques/wet-road/README.md +99 -0
  293. package/examples/techniques/wet-road/main.js +68 -0
  294. package/examples/techniques/wet-road/wetRoad.js +209 -0
  295. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  296. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  297. package/examples/webgpu-tsl/README.md +42 -0
  298. package/examples/webgpu-tsl/main.js +21 -0
  299. package/examples/webgpu-tsl/tslScene.js +75 -0
  300. package/examples/world/.threedog/content-index.json +1 -0
  301. package/examples/world/GAMEMAP.md +22 -15
  302. package/examples/world/art/humanoid.js +42 -0
  303. package/examples/world/art/index.js +11 -0
  304. package/examples/world/art/models.js +58 -0
  305. package/examples/world/art/shapes.js +9 -0
  306. package/examples/world/assets.js +6 -0
  307. package/examples/world/content/audio.js +5 -5
  308. package/examples/world/content/npcs.js +1 -1
  309. package/examples/world/content/props.js +1 -1
  310. package/examples/world/content/rules.js +1 -1
  311. package/examples/world/content/templates.js +1 -1
  312. package/examples/world/content/vegetation.js +1 -1
  313. package/examples/world/main.js +17 -13
  314. package/examples/world/style/index.js +61 -0
  315. package/examples/world/style/plugins/10-bloom.js +5 -0
  316. package/index.d.ts +44 -45
  317. package/index.js +26 -22
  318. package/llms.txt +11 -4
  319. package/modules/ambience/Ambience.js +34 -23
  320. package/modules/calendar/Calendar.js +163 -0
  321. package/modules/calendar/contract.js +21 -0
  322. package/modules/calendar/index.js +81 -0
  323. package/modules/{sky → calendar}/schedule.js +17 -16
  324. package/modules/calendar/seasons.js +55 -0
  325. package/modules/camera/FirstPersonCamera.js +6 -15
  326. package/modules/camera/FixedCamera.js +33 -15
  327. package/modules/camera/FollowCamera.js +90 -16
  328. package/modules/camera/RtsCamera.js +18 -17
  329. package/modules/camera/common.js +70 -19
  330. package/modules/camera/contract.js +17 -0
  331. package/modules/camera/projection.js +11 -24
  332. package/modules/characters/Character.js +177 -42
  333. package/modules/characters/NPC.js +87 -36
  334. package/modules/characters/assetModel.js +4 -13
  335. package/modules/characters/behaviors.js +2 -1
  336. package/modules/characters/contract.js +13 -0
  337. package/modules/characters/footsteps.js +1 -1
  338. package/modules/characters/index.js +87 -49
  339. package/modules/characters/moveHelpers.js +4 -5
  340. package/modules/characters/movers/common.js +97 -19
  341. package/modules/characters/movers/manual.js +20 -0
  342. package/modules/characters/movers/rapier.js +19 -16
  343. package/modules/characters/movers/simple.js +14 -11
  344. package/modules/characters/movers/support.js +172 -0
  345. package/modules/characters/npcAvoid.js +47 -42
  346. package/modules/characters/npcSim.js +12 -8
  347. package/modules/characters/npcView.js +44 -16
  348. package/modules/characters/pathAsync.js +7 -3
  349. package/modules/characters/playerStrings.js +4 -3
  350. package/modules/characters/proceduralRig.js +2 -1
  351. package/modules/characters/useModel.js +1 -1
  352. package/modules/characters/vehicle.contract.js +21 -0
  353. package/modules/characters/walkTo.js +21 -7
  354. package/modules/collision/Collision.js +65 -25
  355. package/modules/collision/grid.js +8 -6
  356. package/modules/content/explain.js +2 -2
  357. package/modules/content/fields.js +102 -0
  358. package/modules/content/ids.js +8 -6
  359. package/modules/content/index.js +96 -27
  360. package/modules/content/loader.js +45 -33
  361. package/modules/content/models.js +11 -40
  362. package/modules/content/packs.js +6 -5
  363. package/modules/content/parts.js +41 -0
  364. package/modules/content/props.js +16 -9
  365. package/modules/content/rules.js +58 -0
  366. package/modules/content/stages.js +80 -0
  367. package/modules/content/templates.js +121 -30
  368. package/modules/debug/DebugPanel.js +24 -17
  369. package/modules/flow/contract.js +16 -0
  370. package/modules/flow/index.js +21 -15
  371. package/modules/gameplay/Container.js +41 -32
  372. package/modules/gameplay/Containers.js +30 -15
  373. package/modules/gameplay/Dialogue.js +113 -55
  374. package/modules/gameplay/Interactions.js +193 -67
  375. package/modules/gameplay/Inventory.js +69 -73
  376. package/modules/gameplay/Quests.js +75 -39
  377. package/modules/gameplay/boxOps.js +3 -3
  378. package/modules/gameplay/dialogue.contract.js +21 -0
  379. package/modules/gameplay/dialogueBox.js +4 -2
  380. package/modules/gameplay/dialogueBubbles.js +116 -0
  381. package/modules/gameplay/interactionPrompt.js +4 -1
  382. package/modules/gameplay/interactions.contract.js +16 -0
  383. package/modules/gameplay/inventory.contract.js +23 -0
  384. package/modules/gameplay/inventoryOps.js +18 -16
  385. package/modules/gameplay/pickups.js +268 -85
  386. package/modules/gameplay/questLog.js +4 -4
  387. package/modules/gameplay/quests.contract.js +17 -0
  388. package/modules/grid/Grid.js +92 -50
  389. package/modules/grid/Layer.js +14 -13
  390. package/modules/grid/index.js +60 -36
  391. package/modules/grid/ops.js +20 -18
  392. package/modules/grid/preview.js +15 -16
  393. package/modules/grid/strings.js +12 -0
  394. package/modules/grid/tiles.js +6 -5
  395. package/modules/hlod/index.js +51 -19
  396. package/modules/hud/index.js +35 -20
  397. package/modules/hud/parts.js +20 -7
  398. package/modules/level/heightfield.js +3 -1
  399. package/modules/level/index.js +45 -20
  400. package/modules/level/nodes.js +4 -3
  401. package/modules/lights/index.js +42 -18
  402. package/modules/music/Music.js +38 -21
  403. package/modules/music/rules.js +1 -1
  404. package/modules/nav/index.js +48 -42
  405. package/modules/net/Client.js +13 -6
  406. package/modules/net/Host.js +19 -5
  407. package/modules/net/Net.js +2 -1
  408. package/modules/net/index.js +13 -8
  409. package/modules/net/sync.js +9 -8
  410. package/modules/net/transports.js +77 -27
  411. package/modules/particles/Particles.js +23 -14
  412. package/modules/particles/contract.js +17 -0
  413. package/modules/particles/effect.js +39 -11
  414. package/modules/photo/Photo.js +53 -36
  415. package/modules/rigid/RigidBodies.js +194 -32
  416. package/modules/rigid/Vehicles.js +18 -15
  417. package/modules/rigid/sync.js +62 -17
  418. package/modules/settings/Settings.js +57 -52
  419. package/modules/settings/apply.js +38 -3
  420. package/modules/settings/sections.js +5 -3
  421. package/modules/settings/strings.js +3 -2
  422. package/modules/settings/view.js +5 -3
  423. package/modules/sky/Sky.js +88 -176
  424. package/modules/sky/cascades.js +86 -25
  425. package/modules/sky/cascades.tsl.js +82 -0
  426. package/modules/sky/clouds.js +34 -19
  427. package/modules/sky/domeLayers.js +30 -15
  428. package/modules/sky/environment.js +83 -13
  429. package/modules/sky/fog.js +140 -95
  430. package/modules/sky/frame.js +112 -44
  431. package/modules/sky/look.js +22 -19
  432. package/modules/sky/lookFog.js +48 -52
  433. package/modules/sky/lookShadow.js +53 -41
  434. package/modules/sky/lookSky.js +82 -21
  435. package/modules/sky/season.js +21 -0
  436. package/modules/sky/shader.js +41 -19
  437. package/modules/sky/shadow.js +44 -20
  438. package/modules/sky/skyModule.js +45 -33
  439. package/modules/sky/tint.js +61 -0
  440. package/modules/terrain/ChunkManager.js +175 -108
  441. package/modules/terrain/chunkJob.js +1 -1
  442. package/modules/terrain/chunkQueries.js +6 -4
  443. package/modules/terrain/index.js +105 -50
  444. package/modules/terrain/look.js +83 -0
  445. package/modules/terrain/lookGround.js +21 -16
  446. package/modules/terrain/terrainDefaults.js +1 -1
  447. package/modules/terrain/terrainEdit.js +18 -20
  448. package/modules/terrain/terrainGen.js +5 -3
  449. package/modules/terrain/terrainIsland.js +5 -4
  450. package/modules/terrain/terrainShape.js +12 -12
  451. package/modules/terrain/terrainShapeMain.js +8 -7
  452. package/modules/terrain/terrainTexture.js +21 -19
  453. package/modules/timeline/Timeline.js +95 -43
  454. package/modules/timeline/Tween.js +18 -10
  455. package/modules/timeline/letterbox.js +2 -2
  456. package/modules/timeline/shots.js +5 -1
  457. package/modules/triggers/index.js +107 -76
  458. package/modules/vegetation/Vegetation.js +186 -110
  459. package/modules/vegetation/densityMap.js +62 -0
  460. package/modules/vegetation/groundChunks.js +52 -58
  461. package/modules/vegetation/index.js +32 -11
  462. package/modules/vegetation/look.js +119 -0
  463. package/modules/vegetation/lookWind.js +71 -10
  464. package/modules/vegetation/modelGeometry.js +3 -2
  465. package/modules/vegetation/nearFade.js +8 -2
  466. package/modules/water/Water.js +65 -27
  467. package/modules/water/look.js +29 -18
  468. package/modules/water/surface.js +64 -25
  469. package/modules/water/surfaceDefaults.js +3 -0
  470. package/modules/weather/Weather.js +62 -104
  471. package/modules/weather/look.js +1 -2
  472. package/modules/weather/particles.js +24 -9
  473. package/modules/weather/strings.js +2 -2
  474. package/modules/weather/weatherLook.js +135 -0
  475. package/modules/world/World.js +24 -7
  476. package/modules/world/explain.js +1 -1
  477. package/modules/world/index.js +18 -4
  478. package/modules/world/persist.js +62 -2
  479. package/modules/world/pos.js +3 -2
  480. package/modules/world/records.js +8 -6
  481. package/modules/world/sim.js +60 -20
  482. package/modules/world/simFar.js +4 -3
  483. package/modules/world/state.js +3 -2
  484. package/modules/world/thingSource.js +1 -1
  485. package/modules/world/views.js +7 -5
  486. package/package.json +7 -3
  487. package/presets.js +41 -27
  488. package/render/PostFX.js +145 -120
  489. package/render/backend.js +440 -0
  490. package/render/detail.js +120 -39
  491. package/render/effects.js +130 -38
  492. package/render/engineUniforms.js +10 -1
  493. package/render/fuse.js +5 -4
  494. package/render/fx/cloudShadow.tsl.js +16 -0
  495. package/render/fx/detail.tsl.js +66 -0
  496. package/render/fx/index.js +26 -0
  497. package/render/fx/lighting.tsl.js +28 -0
  498. package/render/fx/nodeErrors.tsl.js +68 -0
  499. package/render/fx/noise.tsl.js +12 -0
  500. package/render/fx/objectOrigin.tsl.js +42 -0
  501. package/render/fx/particles.tsl.js +139 -0
  502. package/render/fx/patchNodes.tsl.js +403 -0
  503. package/render/fx/postWebGPU.tsl.js +158 -0
  504. package/render/fx/season.tsl.js +13 -0
  505. package/render/fx/sky.tsl.js +260 -0
  506. package/render/fx/uniforms.tsl.js +67 -0
  507. package/render/fx/water.tsl.js +53 -0
  508. package/render/fx/wind.tsl.js +22 -0
  509. package/render/fxNumbers.js +36 -0
  510. package/render/hotGlsl.js +24 -0
  511. package/render/lighting.js +66 -14
  512. package/render/lights.js +223 -4
  513. package/render/lookGlow.js +139 -0
  514. package/render/lookSurface.js +99 -36
  515. package/render/materials.js +71 -52
  516. package/render/modeling.js +73 -0
  517. package/render/ownFrame.js +76 -0
  518. package/render/patches.js +311 -34
  519. package/render/postLook.js +124 -46
  520. package/render/postWebGL.js +197 -0
  521. package/render/probes.js +231 -0
  522. package/render/shaderErrors.js +154 -0
  523. package/render/slots.js +165 -0
  524. package/render/surface.js +53 -17
  525. package/render/terms.js +211 -0
  526. package/render/uniformDecl.js +3 -2
  527. package/types/common.d.ts +2 -2
  528. package/types/core.d.ts +614 -240
  529. package/types/gameplay.d.ts +482 -312
  530. package/types/generated/core/Audio.d.ts +26 -42
  531. package/types/generated/core/Batching.d.ts +6 -2
  532. package/types/generated/core/Budget.d.ts +2 -8
  533. package/types/generated/core/DebugOverrides.d.ts +44 -3
  534. package/types/generated/core/I18n.d.ts +2 -2
  535. package/types/generated/core/Input.d.ts +102 -31
  536. package/types/generated/core/Ops.d.ts +31 -0
  537. package/types/generated/core/Random.d.ts +2 -2
  538. package/types/generated/core/Saves.d.ts +10 -2
  539. package/types/generated/core/Stream.d.ts +1 -1
  540. package/types/generated/core/Threads.d.ts +4 -1
  541. package/types/generated/core/Views.d.ts +0 -1
  542. package/types/generated/core/audioVoice.d.ts +17 -9
  543. package/types/generated/core/control.d.ts +55 -0
  544. package/types/generated/core/session.d.ts +2 -1
  545. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  546. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  547. package/types/generated/modules/calendar/index.d.ts +10 -0
  548. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  549. package/types/generated/modules/grid/Grid.d.ts +61 -25
  550. package/types/generated/modules/grid/Layer.d.ts +5 -5
  551. package/types/generated/modules/grid/index.d.ts +29 -17
  552. package/types/generated/modules/music/Music.d.ts +5 -3
  553. package/types/generated/modules/net/index.d.ts +3 -3
  554. package/types/generated/modules/net/transports.d.ts +12 -3
  555. package/types/generated/modules/particles/Particles.d.ts +1 -1
  556. package/types/generated/modules/sky/Sky.d.ts +12 -104
  557. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  558. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  559. package/types/generated/modules/weather/Weather.d.ts +17 -18
  560. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  561. package/types/generated/modules/world/World.d.ts +18 -3
  562. package/types/generated/render/PostFX.d.ts +67 -30
  563. package/types/generated/render/materials.d.ts +26 -20
  564. package/types/generated/render/modeling.d.ts +30 -0
  565. package/types/generated/render/patches.d.ts +16 -2
  566. package/types/generated/ui/UI.d.ts +6 -3
  567. package/types/nav.d.ts +6 -0
  568. package/types/physics.d.ts +137 -44
  569. package/types/style.d.ts +109 -81
  570. package/types/tsl.d.ts +86 -0
  571. package/types/world.d.ts +158 -110
  572. package/ui/Focus.js +25 -14
  573. package/ui/LoadingScreen.js +1 -1
  574. package/ui/Parts.js +27 -11
  575. package/ui/UI.js +20 -10
  576. package/ui/cursor.js +115 -0
  577. package/ui/defaults.js +15 -11
  578. package/ui/theme.js +9 -6
  579. package/ui/touchPart.js +1 -1
  580. package/core/claims.js +0 -51
  581. package/core/look/layers.js +0 -136
  582. package/core/renamed.js +0 -22
  583. package/docs/api/entities.md +0 -61
  584. package/examples/styletest/overrides.js +0 -33
  585. package/examples/styletest/panel.js +0 -135
  586. package/modules/entities/Entities.js +0 -243
  587. package/modules/entities/build.js +0 -25
  588. package/modules/entities/index.js +0 -4
  589. package/modules/sky/calendar.js +0 -80
  590. package/modules/sky/layers.js +0 -69
  591. package/modules/terrain/chunkLevels.js +0 -40
  592. package/modules/terrain/mountTerrain.js +0 -32
  593. package/modules/world/cells.js +0 -42
@@ -1,11 +1,72 @@
1
1
  # Add weather or change the sky
2
2
 
3
- Modules: `sky()` (day/night, sun and moon, fog, calendar), `weather()` (needs sky; the game's weather types, smooth transitions, rain and snow,
4
- lightning). All look data lives in the style pack; the engine has only a neutral fallback.
3
+ **In this recipe**: 1. Switching weather · 2. The game's own weather table · 3. Sky colors, sun, stars (and the sky color for your own shader) · 4. Time and brightness (how a game's value and the weather multiply) · 5. Verify · 6. Day and night in game logic · 7. Wet roads
4
+
5
+ Modules: `sky()` (draws day/night from `engine.calendar`, sun and moon, fog; the time itself is `calendar()`, recipe 06), `weather()` (needs sky; the game's weather types, smooth transitions, rain and snow,
6
+ lightning). All look data lives in the style; the engine has only a neutral fallback.
7
+
8
+ ```js
9
+ // 1. keyframes (default): style.sky.keyframes / style.exposure lists drive the day; nothing to write
10
+ // 2. a function of the frame context, fed by one call: any key marked fn (fog color / near / far / density, sky top / horizon / backdrop, lights, exposure)
11
+ engine.look.fog.set({ color: ({ state }) => state.boss ? '#400' : 'horizon' }); engine.look.state({ boss: true });
12
+ // 3. your own three.js sky (three/addons Sky, a ShaderMaterial dome, a skybox): never written; time / weather keep flowing through engine.uniforms
13
+ engine.look.sky.replace(mySky); mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
14
+ ```
15
+
16
+ WebGPU (recipe 56): same dome and fog kinds as node materials. Hooks take `{ glsl, tsl: (ctx) => vec4 }` ([52](52-look.md#tsl-forms)); GLSL alone throws `[webgpu-needs-tsl]`. Own sky: three's `SkyMesh` via `look.sky.replace`.
17
+
18
+ The sky follows one contract: **inputs** `{ time, weather, season, day, state, sky }` (state = what the game gave `engine.look.state(...)`),
19
+ **outputs** sun direction / color / intensity, hemisphere, fog, environment, exposure and background, plus the shared `engine.uniforms`
20
+ (`uSunDir`, `uDaylight`, `uTimeOfDay`, `uWind`, `uCloud`, season tints) and events (`day:start`, `season:change`, `weather:change`) that wind,
21
+ rain and vegetation read. The keyframes are only the default implementation: a function replaces one key, `replace` the whole dome, and
22
+ everything else keeps running (`replace` swaps the one thing a part draws; the whole sky module with time, lights and fog is
23
+ `engine.use(mySky(), { replaces: 'sky' })`, recipe 52 [verbs](52-look.md#verbs)). The function gets `{ time, weather, season, day, state, sky }`: write `({ sky }) => sky.isDay ? ...`.
24
+
25
+ ### Your own sky object: what `look.sky.replace(obj)` does with it
26
+ The engine hides its dome, adds `obj` to the scene root when it has no parent yet (and removes it again on `replace(null)` only then), and from
27
+ then on **never moves, scales or writes it**: it does not follow the camera, is not scaled to the far plane and is not exempted from culling.
28
+ (The built-in dome does all three itself: an `onBeforeRender` copies the camera position and scales it to `0.9 × camera.far`.) So a dome of
29
+ your own must, on its own:
30
+
31
+ - **contain the camera and stay inside the far plane**: either a fixed sphere big enough for everywhere the camera goes (radius < `camera.far`,
32
+ which the engine pulls in to the view range unless you take it: `engine.look.view.manual('far')`), or one that follows the camera; or skip
33
+ depth altogether as below, so the radius no longer matters;
34
+ - **compute the view direction per pixel from world space**: pass `worldPosition - cameraPosition` (linear, safe to interpolate) as the
35
+ varying and do every non-linear step (normalize, `atan`, projecting onto a cloud plane, noise) in the fragment shader. A direction taken from
36
+ the vertex's local `position`, or a non-linear value computed per vertex, is wrong once the dome is off-centre or its triangles are big:
37
+ that is where arcs bend and seams show at the corners of the sphere's faces;
38
+ - draw behind everything: `gl_Position = clip.xyww` (depth 1), `depthWrite: false`, `frustumCulled = false`, `renderOrder` well below the scene,
39
+ `side: THREE.BackSide`, `fog: false`.
40
+
41
+ ```js
42
+ const sky = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), new THREE.ShaderMaterial({
43
+ side: THREE.BackSide, depthWrite: false, depthTest: false, fog: false,
44
+ uniforms: { uTop: { value: new THREE.Color('#3b6fb6') }, uLow: { value: new THREE.Color('#cfe3f2') } },
45
+ vertexShader: /* glsl */`
46
+ varying vec3 vDir;
47
+ void main() {
48
+ vec4 w = modelMatrix * vec4(position, 1.0);
49
+ vDir = w.xyz - cameraPosition; // linear: interpolates correctly; normalize in the fragment shader
50
+ gl_Position = (projectionMatrix * viewMatrix * w).xyww; // depth 1: never clipped by far, never in front of anything
51
+ }`,
52
+ fragmentShader: /* glsl */`
53
+ uniform vec3 uTop, uLow; varying vec3 vDir;
54
+ void main() {
55
+ vec3 d = normalize(vDir);
56
+ gl_FragColor = vec4(mix(uLow, uTop, smoothstep(0.0, 0.6, d.y)), 1.0);
57
+ #include <colorspace_fragment>
58
+ }`,
59
+ }));
60
+ sky.frustumCulled = false; sky.renderOrder = -1000;
61
+ sky.onBeforeRender = (r, s, cam) => { sky.position.copy(cam.position); sky.updateMatrixWorld(); }; // centred on the camera: any radius works
62
+ engine.look.sky.replace(sky);
63
+ ```
64
+ Time of day still reaches it through `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay` ...): put them in its `uniforms` to follow the day.
5
65
 
6
66
  ## 1. Switching weather / automatic weather (main.js)
7
67
  ```js
8
- engine.weather.set('rain', 20); // transition to rain over 20 seconds (a type of the game's table, see 2)
68
+ engine.weather.set('rain', { seconds: 20 }); // transition to rain over 20 seconds (a type of the game's table, see 2)
69
+ engine.weather.set('storm', { seconds: 0 }); // at once: the full storm before the next step (a screenshot or test right after the call)
9
70
  engine.weather.setAuto(true); // change weather at random (openWorld({ camera: 'follow', autoWeather: true }) also works)
10
71
  engine.events.on('weather:lightning', () => { /* thunder */ });
11
72
  ```
@@ -14,61 +75,109 @@ engine.events.on('weather:lightning', () => { /* thunder */ });
14
75
  `weather({ types })` is the whole list of the game's weather; without it there is only a calm `clear` (the engine assumes no climate). Seven temperate
15
76
  ones (clear cloudy overcast rain storm snow fog) are an opt-in preset: `weather(presets.weather.temperate)`; extend with
16
77
  `types: { ...presets.weather.temperate.types, dust: {...} }`.
17
- Left-out fields are calm (no cloud, rain, snow, grey, lightning; sun, fog, wind 1). The style pack's `style.weather.types` only retunes types the game has.
78
+ The preset supplies types and an `autoPool`; the weather changes by itself only with `auto: true` (or `engine.weather.setAuto(true)`). To pin one
79
+ for a picture: `engine.weather.set('clear')`, or a shot's `--weather clear` (it also turns `auto` off); a shot prints the weather under the picture.
80
+ Left-out fields are calm (no cloud, rain, snow, grey, lightning; sun, fog, wind 1). The style's `style.weather.types` only fills fields the game's
81
+ table leaves out, for types the game has (the table's own numbers win, a preset counts as the game's). There is no patch option for one field
82
+ of a preset type: spread that one type, `const T = presets.weather.temperate.types; weather({ types: { ...T, rain: { ...T.rain, fog: 0.5 } } })`.
18
83
  ```js
19
84
  import { createEngine, presets, sky, weather } from 'threedog';
20
85
  engine.use(sky(), weather({
21
86
  types: { clear: { cloud: 0.1 }, dust: { cloud: 0.5, sun: 0.6, fog: 0.35, wind: 2.2, grey: 0.4, heat: 1 } }, // heat: a field of the game's own, blends too
22
87
  autoPool: ['clear', 'clear', 'dust'], // candidates for automatic weather (repeats = higher probability; default: each type once)
23
88
  }));
24
- engine.weather.set('dust', 15); engine.weather.current.heat; // 0..1 during the change
89
+ engine.weather.set('dust', { seconds: 15 }); engine.weather.current.heat; // 0..1 during the change
25
90
  ```
26
91
  Fields: `cloud` cloud cover 0-1, `sun` sunlight multiplier, `fog` fog distance multiplier (smaller = denser fog), `wind` wind strength, `rain`/`snow`
27
92
  0-1, `grey` how gray the sky turns, `lightning` lightning. A table where nothing rains or snows builds no particles.
28
93
  With openWorld the weather module is already installed; pass its options through the preset: `openWorld({ camera: 'follow', weather: { types, autoPool } })`.
29
94
 
30
- ## 3. Changing sky colors, sun, stars (style pack)
31
- `sky.keyframes` in the style pack (your pack's `index.js`):
32
- `[time 0-1, zenith color, horizon color (= fog color), sunlight color, sunlight intensity, ambient intensity]`, interpolated by time;
33
- also `sunSize sunGlow moonSize starDensity clouds skybox shadow` (see the comments in the style types, `types/style.d.ts`, for what they mean; `hoursPerDay` is timing, so it is a
34
- `sky()` option, not a style key). The look of rain and snow is in `style.weather.rain / snow` (shape, density, shaders, the game's own particles: recipe 44).
95
+ ## 3. Changing sky colors, sun, stars (style)
96
+ `sky.keyframes` in the style (your pack's `index.js`):
97
+ `[time 0-1, zenith color, horizon color (= fog color), sunlight color, sunlight intensity, ambient intensity]`, interpolated by time; the rows
98
+ run from time 0 to time 1 (both midnight: the first row at 0, the last at 1 with the same values), else the sky throws. What each column drives
99
+ (and which light carries the moonlight) is in `api/style.md` under `keyframes`;
100
+ also `sunSize sunGlow moonSize starDensity clouds skybox shadow` (defaults and ranges in `api/style.md` too; `hoursPerDay` is timing, so it is a
101
+ `calendar()` option, not a style key). At run time every look key of `style.sky` is a `look.sky` param, one entry per value:
102
+ `engine.look.sky.set({ keyframes, moonSize, starScale, orbitTilt, dim: { stars: false } })`, a panorama is `engine.look.sky.replace('pano')`.
103
+ `sky()` takes only how the game lights its world (`time`, `fog`, `sun`, `hemisphere`, plus the `shadow` / `environment` blocks); `sky({ moonSize })`
104
+ throws naming the `look.sky.set` call.
105
+ **Day and night brightness** come from two columns: sunlight intensity and ambient intensity. With no `sky.keyframes` the sky uses a neutral gray
106
+ curve (night from 19:12 to 04:48, moonlight 0.4, ambient 0.35 against 3 / 1.2 at noon). The ambient column is the whole diffuse fill: the engine's neutral room
107
+ environment (the light Standard / Lambert / Phong materials get from `scene.environment`) takes the share `look.lights` `env.share` (0..1) of
108
+ it and the hemisphere light the rest, so a dark-night pack is dark on PBR surfaces too and the sun keeps its contrast by day. `env.intensity` keeps
109
+ one meaning, the absolute `scene.environmentIntensity`: a game or pack that writes it under a sky gets that value as written (fixed, not following
110
+ the day; the hemisphere light then keeps the whole budget, `describe().look.env.source.mode` `'absolute'`). `describe().look.env.source` says which map lights
111
+ them (`room` / `sky` / `asset:<name>` / `game`) and `followsTime`; `look.env.replace('sky')` builds it from the dome instead (outdoor reflections
112
+ show the sky, not a studio; it darkens by itself), an asset map is a fixed photo and does not follow. Check with `shot --time 12:00` and `--time 22:00`.
113
+ The look of rain and snow is in `style.weather.rain / snow` (shape, density, shaders, the game's own particles: recipe 44).
114
+
115
+ ### Sky color for my shader (horizon color, zenith color)
116
+ A shader of your own that should meet the sky (a sea fading to the horizon, distant cards, a reflection) reads the colors the sky draws this frame:
117
+ `engine.uniforms.uSkyHorizon` and `engine.uniforms.uSkyTop` (`THREE.Color`, linear). They hold the keyframes, a `look.sky.set({ top, horizon })`,
118
+ the weather's grey tint and lightning; with `style.sky.backdrop` the horizon is the backdrop color. The fog in its default color (`'horizon'`) is
119
+ this same color every frame, at night and in rain too; it differs only when the game sets `look.fog.set({ color })`, or takes the fog
120
+ (`look.fog.manual()`, `scene.fog = ...`). Share the object, do not copy it in `onFrame`: `onFrame` runs before the sky updates, so a copy is one
121
+ frame old (after a time jump, the first picture shows the old hour's color).
122
+ ```js
123
+ const sea = new THREE.ShaderMaterial({ uniforms: { uHorizon: engine.uniforms.uSkyHorizon, uTop: engine.uniforms.uSkyTop, uSunDir: engine.uniforms.uSunDir },
124
+ fragmentShader: '... gl_FragColor = vec4(mix(base, uHorizon, fresnel), 1.0); #include <tonemapping_fragment> #include <colorspace_fragment>' /* ... */ });
125
+ engine.uniforms.uSkyHorizon.value.getHexString(); // read it in JS too (game logic, a HUD swatch)
126
+ ```
127
+ `look.sky.value('horizon')` is the override a game set (`null` = the keyframes), not the drawn color.
35
128
 
36
129
  ## 4. Time and brightness (game code)
37
130
  ```js
38
- engine.sky.timeOfDay = parseClock('19:30'); // jump to a time (0-1)
39
- engine.clock.timeScale = 0; // sky and game seconds stop together (2 = double speed); game seconds per day: sky({ dayLength: 600 }); the three kinds of time are in recipe 06
40
- engine.look.fog.set({ far: 300 }); // base fog distance (meters); weather scales it. engine.setFogFar(300) sets the same base value directly
131
+ await engine.skip({ to: '19:30' }); // jump forward to a time: timers, calendar.at / daily, day:start fire on the way (needs a calendar dayLength; recipe 06)
132
+ engine.mod('clock.rate', { owner: 'game', set: 0 }); // the calendar and calendar seconds stop together, so the sky stops moving (set: 2 = double speed; remove() undoes it); game seconds per day: calendar({ dayLength: 600 }); the three kinds of time are in recipe 06
133
+ engine.look.fog.set({ far: 300 }); // base fog distance (meters); weather multiplies it; terrain({ viewFog: true }) writes the layer below
41
134
  ```
42
- Fixed dusk: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day) and do not pass `sky: presets.calendar.cycle` (the template does; the cycle
43
- is what moves the clock). `engine.sky.isDay` is `sunHeight > 0` with `sunHeight = sin((timeOfDay - 0.25) * 2π)`: true strictly between timeOfDay 0.25 and 0.75 (06:00 to 18:00 on the default 24-hour face; with `hoursPerDay: H` the same fractions, 0.25H to 0.75H), false at exactly 06:00 and 18:00, so 18:30 already reads as "night" in `describe().time.isDay`. `daylight` = `max(0, sunHeight)`. Keyframes only change colors, not this flip.
44
- The calendar is the game's: `sky()` alone keeps one time of day (dungeon, arena, space); a day-night cycle is `sky({ dayLength: 360 })` or
45
- `sky(presets.calendar.cycle)` (`presets.calendar.fourSeasons` includes it); `hoursPerDay` changes the clock face. An audio rule's `time` condition
46
- takes `'day'`, `'night'` or a range `['18:00', '06:00']`; anything else warns once.
47
- Seasons are off by default (`engine.sky.season` is `null`, no `season:change`); name them to turn them on:
135
+ **The sky draws the calendar's time; it does not own it.** Day, time of day and seasons are the `calendar()` module (recipe 06 "The time table");
136
+ the sky reads `engine.calendar.timeOfDay` each frame to place the sun and blend the keyframes, and `engine.calendar.season` for the season tint.
137
+ Without a calendar, `sky({ time: '18:30' })` draws that one fixed time (an arena, a museum diorama, a space station window); with a calendar,
138
+ `sky({ time })` throws (start the day with `calendar({ time })`). A game that draws its own sky (a skybox shader, a 2D painted backdrop) keeps the
139
+ calendar and reads it the same way; a game indoors keeps the calendar and installs no sky.
140
+ Fixed dusk in an open world: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day; goes to the calendar) and do not pass
141
+ `calendar: presets.calendar.cycle` (the template does; the cycle is what moves the clock). `engine.sky.isDay` is `sunHeight > 0` with `sunHeight = sin((timeOfDay - 0.25) * 2π)`: true strictly between timeOfDay 0.25 and 0.75 (06:00 to 18:00 on the default 24-hour face; with `hoursPerDay: H` the same fractions, 0.25H to 0.75H), false at exactly 06:00 and 18:00, so 18:30 already reads as "night" in `describe().time.isDay`. `daylight` = `max(0, sunHeight)`. Keyframes only change colors, not this flip.
142
+ `engine.calendar.isDay` / `daylight` are the same formula from the clock (they work with no sky); the sky's are what it draws (its fixed time without a calendar).
143
+ A day-night cycle is `calendar({ dayLength: 360 })` or `calendar(presets.calendar.cycle)` (`presets.calendar.fourSeasons` includes it);
144
+ `hoursPerDay` changes the clock face. An audio rule's `time` condition (from the calendar) takes `'day'`, `'night'` or a range `['18:00', '06:00']`;
145
+ anything else warns once.
146
+ Seasons are off by default (`engine.calendar.season` is `null`, no `season:change`); name them to turn them on:
48
147
  ```js
49
- sky({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28, dayLength: 360 }); // days advance only with a dayLength; or the preset: openWorld({ camera: 'follow', sky: presets.calendar.fourSeasons })
50
- sky({ seasons: [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], dayLength: 360 }); // seasons of their own length
148
+ calendar({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28, dayLength: 360 }); // days advance only with a dayLength; or the preset: openWorld({ camera: 'follow', calendar: presets.calendar.fourSeasons })
149
+ calendar({ seasons: [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], dayLength: 360 }); // seasons of their own length
51
150
  ```
52
- **Don't modify directly** `sky.sun.intensity / color`, `sky.hemi`, `scene.fog`: the sky recomputes them every frame and overwrites your change (the
53
- console warns about it during development). Use `engine.look.lights` / `look.fog` (recipe 52), or take them over yourself (recipe 38).
54
- To darken or tint everything (a cave, a horror segment), write a modifier layer of your own; it stacks with the weather's 'weather' layer without
55
- overwriting it (multiplier layers vs `look.lights` overrides: [recipe 52](52-look.md#skymodify-vs-looklights)):
151
+ **A direct write to** `engine.lights.sun.intensity / color`, `engine.lights.hemi` or `scene.fog` **takes that value over**: the sky stops writing it and
152
+ keeps yours, so the day cycle no longer changes it (warned once). To adjust and keep the cycle: `engine.look.lights.set(...)` / `look.fog.set(...)` or a
153
+ modifier layer below; to take it on purpose: `engine.look.lights.manual('sun')` (recipe 52 "Who writes it").
154
+ To darken or tint everything (a cave, a horror segment), add multipliers of your own on the look values; they stack with the weather's without
155
+ overwriting it ([recipe 52](52-look.md#how-look-values-stack)):
56
156
  ```js
57
- engine.sky.modify('cave', { sun: 0.3, ambient: 0.4, fog: 0.5 }); // enter the cave: layers multiply
58
- engine.sky.modify('cave', { tint: 0x402030, tintAmount: 0.5 }); // changes only the given fields (this layer's sun/ambient stay)
59
- engine.sky.modify('cave', null); // leave the cave: remove this layer
157
+ const cave = [engine.mod('look.lights.sun.intensity', { owner: 'cave', mul: 0.3 }), engine.mod('look.lights.hemi.intensity', { owner: 'cave', mul: 0.4 }),
158
+ engine.mod('look.fog.far', { owner: 'cave', mul: 0.5 }), // enter the cave: entries multiply
159
+ engine.mod('look.sky.tint', { owner: 'cave', value: { color: 0x402030, amount: 0.5 } })]; // amount = zenith, horizon: = horizon
160
+ cave.forEach(h => h.remove()); // leave the cave
60
161
  ```
61
- `sun / ambient / fog` multiply across layers, `tint` is blended weighted by `tintAmount` (zenith) / `horizonTintAmount` (horizon), and `flash` takes
62
- the maximum.
63
- Write once and it stays in effect; no need to write every frame. For a gradual change, write a new value every frame. `engine.sky.modifiers` is the
64
- combined result and is read-only (changing it directly triggers a warning during development).
162
+ These are ordinary shared points (recipe 55): the light and fog values multiply, `look.sky.flash` adds, `look.sky.tint` / `look.ground.cover`
163
+ entries blend weighted by their amount, `{ for: 3 }` ends one by itself. A game's own `look.lights.set({ sun: { intensity: 3 } })` is the base they
164
+ multiply: rain still dims it and the sunset still fades it (`engine.describe().shared['look.lights.sun.intensity'].how` says `arena 3 × weather 0.6`).
165
+ Write once and it stays in effect; no need to write every frame. For a gradual change, write a new value every frame.
65
166
 
66
167
  ## 5. Verify
67
168
  - Text: `npm run shot -- / --time 19:30 --weather dust --wait 2 --describe-only`, then look for "Time: 19:30..." and "Weather: dust (rain 0, snow 0, fog 0.35)".
68
- `describe().weather` has `name progress rain snow fog wind cloud`; `describe().time` has `clock day season isDay dayLength timeScale`.
169
+ `describe().weather` has `name progress rain snow fog wind cloud`; `describe().time` has `clock day season isDay dayLength rate`.
69
170
  - Take a screenshot only after the look changed: `npm run shot -- / --time 19:30 --weather dust`.
70
171
 
71
172
  ## 6. Day and night in game logic
72
- Day and night come only from the sky: test `engine.sky.isDay`, and fade with `engine.sky.daylight` (0-1). Don't decide it from the clock time
73
- yourself, so a game with different day lengths or seasons stays right. Lights and shop doors that follow the time of day use `engine.sky.between(...)`
74
- (its page: `api/sky.md`).
173
+ Gameplay reads day and night from the calendar: test `engine.calendar.isDay`, and fade with `engine.calendar.daylight` (0-1); they work with or
174
+ without a sky. Don't decide it from the clock text yourself, so a game with different day lengths or hours stays right. Lights and shop doors that
175
+ follow the time of day use `engine.calendar.between(...)` (its page: `api/calendar.md`).
176
+
177
+ ## 7. Wet roads and puddles after rain
178
+ The engine gives the rain, not the wet look: `engine.weather.current.rain` (0-1) is the signal; what gets wet, how fast it dries and where
179
+ puddles collect are the game's decisions. Water fills the pores of a rough surface, so wet reads as darker and glossier together (lower `color`
180
+ and `roughness`); darker alone reads as dirt or shadow. Gloss only shows when there is something bright to reflect: the sky by day, at night
181
+ the lamps and windows as long streaks. A puddle needs a soft-rimmed mask; a hard cut-off makes opaque discs that read as holes. Judge it on a
182
+ shot at noon and at night, in rain and after. To compare with your own result afterwards, the technique example `wet-road`
183
+ (`threedog examples pull wet-road`) shows one way, with a dry-out delay in game time.
@@ -1,73 +1,103 @@
1
- # Changing the art / writing a style pack
1
+ # The game's style folder: changing the art
2
2
 
3
- **The engine ships no art.** No default style, character model, terrain look or terrain generator: with no style pack and no model everything is a
3
+ **In this recipe**: 0. Using a style · 0b. Composing a style from parts · 0c. What a style may not hold · 0d. Look plugins in a style folder · 1. Creating a new style ·
4
+ 1b. Lights and stalls · 2. Using your own models instead of procedural ones · 2b. Wind, cloud shadows and season tint on your own… ·
5
+ 3. When the engine gets a new "look parameter" · 4. Verify · 5. Sounds and music
6
+
7
+ **The engine ships no art.** No default style, character model, terrain look or terrain generator: with no style and no model everything is a
4
8
  plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
5
9
  one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
6
10
 
7
- A style pack is a plain object passed in as `createEngine({ style })`. It holds **looks only**: colors, the default pickup shape,
11
+ A game's style is a plain object its `style/` folder exports, passed in as `createEngine({ style })`. It holds **looks only**: colors,
8
12
  materials and shaders, sky and lighting, post effects, UI look. Not part of it: model / texture / sound files and procedural models content names (an
9
13
  **asset pack**, `engine.assets.manifest`, recipe 05 "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20;
10
- `sky({ hoursPerDay })`). Which key is read by whom is in the "style pack keys" table of `../CODEMAP.md`; the field list is in `../api/style.md`. Every
11
- entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style pack at all). Write it as a plain object literal, no `@type` or `as const`: fields with a fixed set of words (`shading`, `mode`, `type` …) accept any string in the types, and a wrong word is reported by `threedog style check` with the fix.
14
+ `calendar({ hoursPerDay })`). Which key is read by whom is in the "style keys" table of `../CODEMAP.md`; the field list is in `../api/style.md`. Every
15
+ entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style at all). Write it as a plain object literal, no `@type` or `as const`: fields with a fixed set of words (`shading`, `mode`, `type` …) accept any string in the types, and a wrong word is reported by `threedog style check` with the fix.
12
16
 
13
- ## 0. Using a style pack
14
- A style pack is a plain object (or a package that exports one): yours in `style/index.js`, a folder you copy, or a published package. Any art direction fits:
15
- realistic, toon, pixel, painterly, flat, noir. The engine ships none; `threedog new-style` starts an empty one (section 1).
17
+ ## 0. Using a style
18
+ A game keeps its style in its `style/` folder (`style/index.js`; a new game starts with an empty one). Any art
19
+ direction fits: realistic, toon, pixel, painterly, flat, noir. The engine ships none (section 1).
16
20
  ```js
17
21
  import { createEngine, presets, openWorld } from 'threedog';
18
- import yourPack from './style/index.js'; // or: import yourPack from 'a-published-pack'
22
+ import style from './style/index.js'; // the game's own look
19
23
  import { terrainPreset, terrainStrings } from '@threedog/terrain-noise'; // the world shape is not a look: its own package
20
- const engine = createEngine({ canvas, style: yourPack, strings: terrainStrings }); // terrainStrings: names of the preset's ground types
24
+ const engine = createEngine({ canvas, style, strings: terrainStrings }); // terrainStrings: names of the preset's ground types
21
25
  engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() })); // noise terrain (hills, rivers, biomes) that your pack colors, see recipes/28
22
26
  ```
23
- A pack may also export an asset pack (procedural models: `engine.assets.manifest(assets)`). Post effects such as `bloom` / `ao` / `outline` come from
24
- `@threedog/post-effects` (style packs never import each other; R34 checks). The terrain generator `terrainPreset` / `riverAt` / `BIOMES` /
25
- `terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style pack keeps only the colors of its
27
+ Procedural models are an asset pack, not part of the style (`engine.assets.manifest(assets)`; the world example keeps its in `examples/world/art/`). Post effects such as `bloom` / `ao` / `outline` come from
28
+ `@threedog/post-effects`. The terrain generator `terrainPreset` / `riverAt` / `BIOMES` /
29
+ `terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style keeps only the colors of its
26
30
  ground types (`terrain.colors`, `biomeColors`).
27
31
 
28
32
  ## 0b. Composing a style from parts
29
33
  `style` may be a list of parts, deep-merged left to right into `engine.style`, so one pack's materials, another pack's sky and the game's own colors
30
34
  mix without copying whole packs:
31
35
  ```js
32
- import basePack from './style/index.js';
36
+ import base from './style/index.js';
33
37
  const dusk = { sky: { sunSize: 600, keyframes: myDuskKeyframes } }; // only these two sky fields change
34
- const engine = createEngine({ canvas, style: [basePack, dusk, { ui: { accent: '#7fd3ff' }, post: null }] });
38
+ const engine = createEngine({ canvas, style: [base, dusk, { ui: { accent: '#7fd3ff' }, post: null }] });
35
39
  ```
36
40
  Rules (`core/styleParts.js`): plain `{ }` objects merge key by key at every depth; everything else replaces whole (arrays such as `sky.keyframes` and
37
41
  `post`, functions, three.js objects); a key set to `null` removes it; `undefined` is ignored; nested lists flatten, so a pack can itself be a list of
38
42
  parts; parts are never mutated. One object (not a list) is used as it is.
43
+ The merged style is the **style layer** of every look value (recipe 52 "How look values stack"): later parts win there and two parts never
44
+ conflict; a game's `look.<part>.set(...)` sits on top of it, and the weather and the sunset multiply whichever decides. A style starts the fog
45
+ distance (`sky.fog.far`) and the shadow filter (`sky.shadow.type`); there are no `createEngine` options for them.
39
46
 
40
- **Post effects by name.** `post` is a list, so `{ post: [myGrain] }` replaces everything before it. To add to or trim the list use the two helpers
41
- (exported by `threedog`); they are parts too:
42
- ```js
43
- import { createEngine, postAdd, postRemove } from 'threedog';
44
- import basePack from './style/index.js';
45
- import { bloom } from '@threedog/post-effects';
46
- createEngine({ canvas, style: [basePack, postAdd(myGrain, bloom({ strength: 0.6 })), postRemove('ao')] });
47
- ```
48
- `postAdd(...effects)` appends; an effect whose `name` is already in the list (`'bloom'`, `'ao'`, `'outline'`) replaces that one in place.
49
- `postRemove(...names)` drops effects by name. `{ post: null }` still clears the list; `{ post: [...] }` still replaces it whole.
47
+ **Post effects are plugins.** A style brings each post effect as a file in its `style/plugins/` folder (`10-bloom.js: export default bloom()`,
48
+ listed with `plugins: import.meta.glob('./plugins/*.js', { eager: true })`), the same file a game's `plugins/` folder takes: both go through
49
+ `engine.look.post.add`, the one way into the chain (recipe 52). Each part's plugins stay grouped under the part's name, so one pack's effect is
50
+ switched off with `engine.plugins.off('<pack>/<file>')` or `look.post.set({ bloom: false })`, and `plugins: null` drops the earlier parts' plugins.
51
+ There is no `style.post` list (it was a second way in, with its own on / off rules).
50
52
 
51
53
  **Retinting the procedural models.** `style.palette` holds the colors the trees, rocks, grass and flowers are built from (the keys are the pack's own, e.g. `bark`, `leaf`, `rock`,
52
- `grassTip`...; see `basePack.palette`). One part changes them all:
53
- `style: [basePack, { palette: { leaf: 0xd98a3a } }]` (autumn); keys left out keep the pack's colors. A generator of your own written
54
+ `grassTip`...; see `base.palette`). One part changes them all:
55
+ `style: [base, { palette: { leaf: 0xd98a3a } }]` (autumn); keys left out keep the base colors. A generator of your own written
54
56
  with `function` (not an arrow) reads `this.palette`; the palette is part of the model cache key, so a changed palette rebuilds. `.glb` files and
55
57
  models baked earlier keep their colors.
56
58
 
57
59
  ## 0c. What a style may not hold
58
60
  Swapping the style must never change the map or the rules, only how they look. So these are **not** style fields, and a dev run throws an error
59
61
  naming where each goes:
60
- - water level, whether there is a sea, the water mesh size: `style.water.level / sea / size` -> `engine.use(water({ level, sea, size }))`
62
+ - water level, whether there is a sea, the water mesh size: `style.water.level / sea / size` -> `engine.use(water({ level, sea, size }))`.
63
+ The other way round, a look value is never a module option: water color, waves, normal map (`style.water.*`), sky keyframes, sun, moon, stars
64
+ (`style.sky.*`) and terrain `normals` (`style.terrain.config.normals`) are set in the style, and at run time with `engine.look.water` /
65
+ `look.sky` / `look.ground` `.set(...)`; `water({ color })`, `sky({ moonSize })`, `terrain({ normals })` throw naming that call
61
66
  - terrain shape and size (seed, chunk size, resolution, water level, height functions): `style.terrain.config.*` -> `terrain({ ... })`. The looks
62
67
  in `terrain.config` are `shading` (`'smooth'` | `'texture'` | `'flat'`), `colorResolution`, `normals` and `normalFn` (recipe 37); at run time
63
68
  `engine.look.ground.set({ shading, colors, variation, detail })` (recipe 52)
64
69
  Quality settings are not world state and may stay in a style (shadow `mapSize` and `low` overrides, water `segments`); players can override them in
65
- settings. Packs under `packages/styles/**` are also checked by `threedog check` (R34).
70
+ settings. A game's `style/` folder is also checked by `threedog check` (R34).
66
71
 
67
- ## 1. Creating a new style pack
68
- Run `threedog new-style` (or copy any pack folder into your game or a package of your own), edit the values in `index.js`, then switch to it in the game:
72
+ ## 0d. Look plugins in a style folder
73
+ One folder = one style: starting values, the material per role, and optional look plugins. A plugin is a file exporting the same shapes as the
74
+ game's `plugins/` folder (recipe 40 §1): a three.js `Pass`, a `Material` (its `name` is the role), a material patch `{ slot, glsl, roles }` (plugged with `look.materials.add`),
75
+ an `Object3D`, or a look module (a sky or vegetation look with `replaces`). The style lists them in `plugins`, and the engine plugs them through
76
+ `engine.plugins`, the same loader as the game's folder, so a plugin file works alone in `plugins/` or inside any number of style folders unchanged:
77
+ ```js
78
+ // style/index.js style/plugins/10-paper.js: export default new ShaderPass(PaperShader)
79
+ export default { // style/plugins/20-stone.js: export default Object.assign(new THREE.MeshToonMaterial({ color: 0x777777 }), { name: 'stone' })
80
+ name: 'ink', exposure: 1.1, materials: { wood: { type: 'lambert', color: 0x8a5a36 } },
81
+ plugins: import.meta.glob('./plugins/*.js', { eager: true }), // without Vite: { paper: { default: paperPass } }
82
+ };
83
+ ```
84
+ They sit **under** the game: a style plugin's material and patch are on the style layer of `engine.look.materials`, so the game's
85
+ `look.materials.set / replace` and the game's own plugins win. Names are `<style>/<file>` (`ink/10-paper`); `engine.plugins.off('ink')` takes
86
+ all of the style's plugins out, `off('ink/10-paper')` one; `describe().slots` lists them with `style ink: plugins/...`. `off('ink')` turns off
87
+ the pack's **plugins only**: its starting values (`exposure`, `fog`, the `materials` table and the other fields of `style/index.js`) are the
88
+ style itself and stay; the `off()` result and the off rows of `describe().slots` say so. To drop those too, start with another style.
89
+ Each plugin is its own owner (`style:ink/10-paper`), the pack only groups them: switching one off takes out only what that file wrote, and
90
+ the others keep theirs. Two plugins that write the same key on the same layer (two Materials named `stone`) are a `shared-conflict` naming
91
+ both files in development; to let one win on purpose, say so in that file: `export const replaces = '10-stone';` (the other is unplugged
92
+ while this one is on, and comes back when it goes off; `plugins.list()` shows `replacedBy`). In a list of parts each
93
+ part's plugins stay under that part's name, and `{ plugins: null }` drops the earlier parts'. The personal library (`threedog lib`) stores a
94
+ plugin once; `lib pull` puts its code in `plugins/<name>/` with the wiring file `plugins/<name>.js`, and copying both into a style folder's `plugins/` is all it takes to bundle it.
95
+
96
+ ## 1. Creating a new style
97
+ Edit your game's `style/index.js` (`threedog new-game` makes it empty, every key commented out; fill one section at a time). To try a second look,
98
+ copy the folder (`style-toon/`) and point `createEngine` at it; `threedog style check style-toon` (a folder path; with no argument it checks the game's `style/`) finds mistakes before you look at pixels:
69
99
  ```js
70
- import toon from './style/index.js';
100
+ import toon from './style-toon/index.js';
71
101
  const engine = createEngine({ canvas, style: toon });
72
102
  ```
73
103
  **A material role is a free label inside the style, not a fixed list.** `makeMaterial('anything', { color })` is always legal: a role the style does not
@@ -77,20 +107,21 @@ warns only when a name looks like a typo of a known role (`'buidling'`).
77
107
  Keys you will change most often:
78
108
  | Key | What it controls |
79
109
  |---|---|
80
- | `materials` | The material per role. Three forms: a spec `{ default: { type: 'toon', steps: 3 }, water: { type: 'phong', shininess: 90 } }` (lambert / phong / standard / physical / toon / basic; a wrong type throws), any three.js material instance `water: new THREE.MeshMatcapMaterial({ matcap })` (cloned per use), or a function `prop: (params, role) => new THREE.ShaderMaterial({...})`. Style packs may create materials directly; games still go through `makeMaterial` |
110
+ | `materials` | The material per role. Three forms: a spec `{ default: { type: 'toon', steps: 3 }, water: { type: 'phong', shininess: 90 } }` (lambert / phong / standard / physical / toon / basic; a wrong type throws), any three.js material instance `water: new THREE.MeshMatcapMaterial({ matcap })` (cloned per use), or a function `prop: (params, role) => new THREE.ShaderMaterial({...})`. The table is the style layer of `engine.look.materials`, the one entry `makeMaterial(role)` reads: the game changes a role with `look.materials.set / replace` (recipe 52), never by editing `engine.style.materials` |
81
111
  | `antialias` | `false` for sharp pixel edges; omitted = on for desktop, off for phones (players can switch it in settings) |
82
112
  | `post` | List of post effects (e.g. `[outline(), ao(), bloom()]`; `outline({ enabled: true })` draws edge lines); slots, the effects package, `fuse`, outline modes: [recipe 52](52-look.md#post-effect-chain) |
83
113
  | `sky` `weather` `water` `terrain` `seasons` `clouds` | Sky keyframes (sun color and intensity over the day, fog color, shadows), rain and snow, water, terrain colors (`terrain.colors` palette, `terrain.biomeColors` ground type -> palette names, `terrain.steep` slope colors; a type with no color is gray; `terrain.config`: `shading` `'smooth'` (engine default) | `'texture'` (per-chunk color map) | `'flat'` (facets), `colorResolution`, `normals`, `normalFn`, recipe 37; `terrain.detail` a detail layer, recipe 53; `terrain.material` swaps the whole ground material, chunks have `uv` = world xz / chunk size; `water.material: (engine, { uniforms, waves, normalMap }) => Material` swaps the whole water surface, e.g. `applyEffects(new THREE.MeshToonMaterial({ color }), { clouds: false, patches: [waves] })` keeps the built-in waves), seasonal tints |
84
114
  | `character` | `animation.fade`: skeletal animation transition seconds. Bodies are assets, not style: `createPlayer({ model })` with a registered model, a GLB asset name or `{ rig }`; part colors are material roles or `{ colors }` per character (recipe 13). Without a model a gray capsule |
85
- | `pickup` `particles` | Items on the ground (`pickup.model(item, { color, size })` returns an Object3D or geometry; without it a plain gray box), particle presets (dust smoke leaves splash sparks...) |
115
+ | `pickup` `particles` | Items on the ground: look values only (`color`, `size`, `lift`; the shape is an asset model name, recipe 03), particle presets (dust smoke leaves splash sparks...) |
86
116
  | `triggers` `grid` | Tool colors, not art: trigger zone wireframe (`debugColor`), grid placement preview (`ok` / `bad`). The engine has neutral defaults (gray; light = can place, dark = cannot); a pack may recolor them |
87
117
  | `ui` | UI colors, `font` (a CSS font-family list), `fonts` (font asset names to load at start, the files in an asset pack: recipes/05 §3b), extra `css`, `templates` that replace a whole UI piece |
88
118
 
89
119
  ## 1b. Lights and stalls
90
- Every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style pack they are a neutral placeholder (white
120
+ Every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style they are a neutral placeholder (white
91
121
  hemisphere + neutral directional light, no shadows); the look (sun color and intensity curves, sky colors, fog, shadow softness, exposure, tone
92
- mapping) comes from the style pack's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights. At run time:
93
- `engine.look.lights.set(...)` (recipe 52); to light the world yourself: recipe 38.
122
+ mapping) comes from the style's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights. At run time:
123
+ `engine.look.lights.set(...)` (recipe 52); to light the world yourself: recipe 38. `toneMapping` is read once, when the engine creates its
124
+ renderer; later the curve is plain three.js (`engine.renderer.toneMapping = ...`).
94
125
 
95
126
  three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
96
127
  loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
@@ -112,7 +143,11 @@ const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, dist
112
143
  flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
113
144
  ```
114
145
  `engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
115
- camera. Options and handle: `../api/lightPool.md`.
146
+ camera. Options and handle: `../api/lightPool.md`. Windows and signs that light up at night (many materials, no real light each):
147
+ `engine.look.materials.glow('window', { night: 2 })` (recipe 52 "Night glow").
148
+
149
+ Top-down or side-view games whose light should spread over the floor and stop at walls (soft shadows, any number or shape of emissive
150
+ lights) can copy the optional 2D radiance cascades example instead: `examples/rc2d/` (README there: when it fits, cost, limits). It is not a module.
116
151
 
117
152
  ## 2. Using your own models instead of procedural ones
118
153
  Models are assets, not style keys: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
@@ -123,17 +158,31 @@ engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), w
123
158
  ```
124
159
  Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
125
160
  mesh, e.g. bark trunk + alpha-cut leaf cards:
126
- `engine.vegetation.add('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
161
+ `engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
127
162
  the import workflow see `10-blender-level.md`.
128
163
  `mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
129
164
  A generator in `models` may also return an Object3D with its own materials; those are used as they are.
130
165
 
166
+ ### 2a. Reusing art from somewhere else: copy it in, do not depend on it
167
+ Art code you already have (generator modules such as `art/my-crate.js` from an earlier game, a folder of your own, files someone gave you, a package
168
+ you installed) is reused by **copying** it into this game. The copy is the game's own: edit it freely; nothing links back and nothing updates it.
169
+ ```sh
170
+ threedog art list ../earlier-game # modules, exported functions with their first JSDoc line, asset files (uses its art/ folder)
171
+ threedog art copy ../earlier-game crate lamp # by file or function name; none = every module
172
+ threedog art copy ../earlier-game crate --dry # what would be written, nothing written
173
+ ```
174
+ It copies the named modules, every local file they import and every texture / model file they name ('./wood.png', `new URL(...)`, '/models/x.glb'
175
+ from the source's `public/`), rewrites relative import paths to the new layout (outside-the-art-folder helpers land in `art/shared/`), keeps package
176
+ imports and lists them, and prints the `engine.assets.manifest` lines to register the generators. An existing file with different content stops the
177
+ whole copy (nothing written) unless `--force`. The engine ships no art library and names no source: which art to reuse is yours to choose.
178
+ GLB files from Blender are copied the same way and checked with recipe 46 section 3.
179
+
131
180
  ## 2b. Wind, cloud shadows and season tint on your own materials
132
181
  The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
133
182
  ```js
134
183
  import { applyEffects } from 'threedog';
135
184
  const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
136
- engine.vegetation.add('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
185
+ engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
137
186
  ```
138
187
  The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, and stacks with the built-in ones and with
139
188
  the material's own `onBeforeCompile`:
@@ -143,27 +192,27 @@ A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#includ
143
192
  `render/effects.js`) with `engine.uniforms` as its uniforms.
144
193
  `material.clone()` does not carry patches (three's `Material.copy` skips `onBeforeCompile`): a pack's Material instance in `materials` is fine
145
194
  (`makeMaterial` keeps its patches); when you clone one yourself, apply the effects to the clone again.
146
- What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`) and the chunk names: recipe 43, exit 2. Textures by asset name, `detail`,
147
- shadow tint, rim light and toon ramps are material spec keys: recipe 48 (keys), recipe 43 (what they do).
195
+ What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`) and the chunk names: recipe 43, "Patch a slot". Textures by asset name are
196
+ material spec keys (recipe 48); the engine GLSL functions you can call in your own shader, and the spec keys that wire some of them in as a shortcut: recipe 43.
148
197
 
149
198
  ## 3. When the engine gets a new "look parameter"
150
- Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to a style pack
199
+ Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to a style
151
200
  (its `index.js`) at the same time** (with a one-line comment saying what it means),
152
201
  and the new field gets a doc comment in `types/style.d.ts` (`docs/api/` is generated from there). Materials always go through
153
- `makeMaterial('role', { color })`, leaving the surface feel to `style.materials[role]`. Whose style: `engine.makeMaterial('role', { color })` uses that
154
- engine's pack; the free `makeMaterial()` uses the first engine created (fine for one engine, a dev warning when two packs run). Engine code and style packs always
155
- go through the engine (`pickup.model(item, { color, size }, engine)`, `water.material(engine, ...)`), so two engines never share materials.
202
+ `makeMaterial('role', { color })`, leaving the surface feel to the role in `engine.look.materials` (the style's `materials` table is its style layer). Whose style: `engine.makeMaterial('role', { color })` uses that
203
+ engine's pack; the free `makeMaterial()` uses the first engine created (fine for one engine, a dev warning when two packs run). Engine code and styles always
204
+ go through the engine (`water.material(engine, ...)`, a generator's `this.engine`), so two engines never share materials.
156
205
  Look parameters only: a field that changes the world (a level, a size, a seed) goes to the module's options, not the style (section 0c).
157
206
 
158
207
  ## 4. Verify
159
- - `npm run check`: the hard-rule check reports "material created directly" (in engine modules, games and examples; style packs are allowed) and
160
- "non-gray fallback color"; the type check catches misspelled keys in the style pack.
161
- - `npm run map`: the "style pack keys" table in CODEMAP is updated.
208
+ - `npm run check`: R14 reports "creates a material directly" in engine code (games, examples and styles are plain three.js and not checked) and R39
209
+ "non-gray fallback color"; the type check catches misspelled keys in the style.
210
+ - `npm run map`: the "style keys" table in CODEMAP is updated.
162
211
  - Take screenshots only when the look changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
163
212
  (images go to .threedog/shots/).
164
- - It must still run without a style pack: start once with `createEngine({ canvas })` and no `style` (gray placeholders, one console note per missing piece).
213
+ - It must still run without a style: start once with `createEngine({ canvas })` and no `style` (gray placeholders, one console note per missing piece).
165
214
 
166
- ## 5. Sounds and music (the game's, not the style pack's)
215
+ ## 5. Sounds and music (the game's, not the style's)
167
216
  Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`; a
168
- style pack carries none. The engine plays nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and
217
+ style carries none. The engine plays nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and
169
218
  ducking: `recipes/31-audio.md`.
@@ -49,8 +49,8 @@ the flat default. Rules read `engine.surface / slope / groundType`, so pick the
49
49
  property, else its material name) with `rule.biomes`, and limit the scatter with `area`:
50
50
  ```js
51
51
  engine.use(level({ url: '/models/town.glb' }), vegetation({ area: { min: [-80, -80], max: [80, 80] }, viewChunks: 3 }), collision());
52
- engine.vegetation.add('grass', { geometry: grassGeo, nearOnly: true, rule: { perChunk: 500, biomes: { lawn: 1 } } });
53
- engine.vegetation.add('tree', { model: oak, rule: { perChunk: 6, biomes: { lawn: 0.6, park: 1 }, maxSlope: 0.4, collider: 0.4 } });
52
+ engine.vegetation.define('grass', { geometry: grassGeo, nearOnly: true, rule: { perChunk: 500, biomes: { lawn: 1 } } });
53
+ engine.vegetation.define('tree', { model: oak, rule: { perChunk: 6, biomes: { lawn: 0.6, park: 1 }, maxSlope: 0.4, collider: 0.4 } });
54
54
  ```
55
55
  Chunks stream around `engine.stream` sources and stay one InstancedMesh per species per chunk (LOD, shadows and felling work as on terrain:
56
56
  `instanceAt` / `removeInstance`, saved). Collision and path planning see the trees through `engine.ground.forEachCollider`; a new level or `setGround`
@@ -58,6 +58,18 @@ re-places them; after changing a ground function behind the same provider call `
58
58
  sets `minHeight / maxHeight`. Content `vegetation` works the same way. With `terrain()` installed, `vegetation()` takes no options (density and view
59
59
  distance are terrain options). Rapier (`rigid()`) bodies collide with them too (cylinders from `engine.ground.forEachCollider`, gone when felled).
60
60
 
61
+ Where a species grows is decided in the same `add()` call, with up to three parts (on a level, a code-built ground or terrain alike):
62
+ ```js
63
+ // rule: random scatter per chunk (above). positions: the game's own spots instead, [x, z] or [x, z, scale, yaw], planted at the ground height
64
+ engine.vegetation.define('hedge', { model: hedge, positions: hedgeSpots /* [[x, z], ...] from your level data */, rule: { collider: 0.5 } });
65
+ // densityMap: thins the rule's or the positions' result, 0..1 per spot -- a function of game data, or a gray image with the heightmap keys
66
+ engine.vegetation.define('weeds', { geometry: weedGeo, rule: { perChunk: 300 }, densityMap: (x, z) => farm.neglect(x, z) });
67
+ engine.vegetation.define('flowers', { geometry: flowerGeo, rule: { perChunk: 200 }, densityMap: { url: '/maps/flowers.png', size: [256, 256] } });
68
+ ```
69
+ With `positions`, the rule keeps only what shapes an instance (`scale`, `stretch`, `sink`, `tints`, `tintJitter`, `collider`); the scatter filters
70
+ are refused. The id of a listed plant is its index in the list. After what a density function reads changes, call `engine.vegetation.rebuild()`.
71
+ A game that wants every instance under its own code still builds a plain `THREE.InstancedMesh` and adds it to the scene.
72
+
61
73
  ## 5. Verify
62
74
  - `npm run assets` prints each file's size before and after compression; a browser 404 appears in `.threedog/errors.log` (asset load failure).
63
75
  - `describe()`: `ready` is true and `loading` is empty; the player's coordinates are at the spawn point; `nearby` contains trigger zones