threedog 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (596) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +83 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +190 -57
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +43 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +128 -0
  58. package/core/gridLoad.js +20 -0
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +101 -37
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +65 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +89 -97
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +224 -149
  126. package/docs/COMMANDS.md +57 -34
  127. package/docs/CONVENTIONS.md +92 -30
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +12 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +41 -25
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +65 -62
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +31 -29
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +30 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +12 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +71 -59
  180. package/docs/recipes/02-npc.md +46 -29
  181. package/docs/recipes/03-items-pickups.md +38 -24
  182. package/docs/recipes/04-quests.md +34 -27
  183. package/docs/recipes/05-props-bake.md +154 -18
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +41 -10
  186. package/docs/recipes/08-weather-sky.md +146 -37
  187. package/docs/recipes/09-style.md +218 -0
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +34 -10
  191. package/docs/recipes/14-custom-module.md +65 -34
  192. package/docs/recipes/15-perf.md +35 -6
  193. package/docs/recipes/16-dev-bridge.md +65 -41
  194. package/docs/recipes/18-world.md +21 -8
  195. package/docs/recipes/19-shooting-picking.md +12 -11
  196. package/docs/recipes/20-content-actions-save.md +63 -25
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +18 -18
  199. package/docs/recipes/23-ops.md +17 -11
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +12 -6
  202. package/docs/recipes/28-terrain.md +35 -2
  203. package/docs/recipes/29-grid.md +71 -33
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +27 -4
  208. package/docs/recipes/35-style-from-reference.md +115 -51
  209. package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
  210. package/docs/recipes/37-terrain-look-hooks.md +37 -15
  211. package/docs/recipes/38-environment-look-hooks.md +64 -48
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +3 -3
  215. package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
  216. package/docs/recipes/44-water-weather-look-hooks.md +30 -21
  217. package/docs/recipes/45-cascaded-shadows.md +17 -8
  218. package/docs/recipes/46-blender-art-route.md +4 -4
  219. package/docs/recipes/47-island-snow-backdrop.md +11 -10
  220. package/docs/recipes/48-make-material.md +11 -6
  221. package/docs/recipes/49-game-module-contract.md +46 -33
  222. package/docs/recipes/50-own-renderer.md +2 -2
  223. package/docs/recipes/51-capability-catalog.md +4 -4
  224. package/docs/recipes/52-look.md +228 -54
  225. package/docs/recipes/53-ground-up-close.md +58 -0
  226. package/docs/recipes/54-three-idioms.md +88 -0
  227. package/docs/recipes/55-mods-time-wrap.md +112 -0
  228. package/docs/recipes/56-webgpu-tsl.md +260 -0
  229. package/docs/recipes/57-control.md +65 -0
  230. package/docs/recipes/58-input.md +57 -0
  231. package/docs/recipes/59-depth-post-effects.md +83 -0
  232. package/docs/recipes/60-judge-the-picture.md +55 -0
  233. package/examples/action/.threedog/content-index.json +1 -0
  234. package/examples/action/GAMEMAP.md +17 -13
  235. package/examples/action/assets.js +8 -0
  236. package/examples/action/content/actions.js +1 -1
  237. package/examples/action/content/audio.js +5 -5
  238. package/examples/action/look.js +1 -1
  239. package/examples/action/main.js +10 -13
  240. package/examples/action/models.js +24 -23
  241. package/examples/pullable.json +111 -0
  242. package/examples/rc2d/.threedog/content-index.json +1 -0
  243. package/examples/rc2d/GAMEMAP.md +83 -0
  244. package/examples/rc2d/README.md +52 -0
  245. package/examples/rc2d/main.js +63 -0
  246. package/examples/rc2d/rc2d.js +197 -0
  247. package/examples/rc2d/shaders.js +144 -0
  248. package/examples/sheepisland/.threedog/content-index.json +1 -0
  249. package/examples/sheepisland/GAMEMAP.md +13 -11
  250. package/examples/sheepisland/assets.js +5 -0
  251. package/examples/sheepisland/main.js +17 -12
  252. package/examples/sheepisland/style/index.js +6 -6
  253. package/examples/styletest/.threedog/content-index.json +1 -0
  254. package/examples/styletest/GAMEMAP.md +15 -16
  255. package/examples/styletest/assets.js +6 -0
  256. package/examples/styletest/content/npcs.js +1 -1
  257. package/examples/styletest/content/templates.js +1 -1
  258. package/examples/styletest/content/vegetation.js +1 -1
  259. package/examples/styletest/look.js +1 -1
  260. package/examples/styletest/main.js +18 -17
  261. package/examples/styletest/models.js +1 -1
  262. package/examples/styletest/params.js +3 -3
  263. package/examples/techniques/contact-shadows/README.md +92 -0
  264. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  265. package/examples/techniques/contact-shadows/main.js +53 -0
  266. package/examples/techniques/day-night-grade/README.md +86 -0
  267. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  268. package/examples/techniques/day-night-grade/main.js +51 -0
  269. package/examples/techniques/interior-light/README.md +103 -0
  270. package/examples/techniques/interior-light/interiorLight.js +45 -0
  271. package/examples/techniques/interior-light/main.js +124 -0
  272. package/examples/techniques/modular-building/README.md +125 -0
  273. package/examples/techniques/modular-building/kit.js +426 -0
  274. package/examples/techniques/modular-building/main.js +47 -0
  275. package/examples/techniques/night-lights/README.md +94 -0
  276. package/examples/techniques/night-lights/main.js +70 -0
  277. package/examples/techniques/night-lights/nightLights.js +91 -0
  278. package/examples/techniques/outlines-and-rim/README.md +59 -0
  279. package/examples/techniques/outlines-and-rim/main.js +84 -0
  280. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  281. package/examples/techniques/procedural-animation/README.md +77 -0
  282. package/examples/techniques/procedural-animation/creature.js +44 -0
  283. package/examples/techniques/procedural-animation/main.js +45 -0
  284. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  285. package/examples/techniques/procedural-surface/README.md +67 -0
  286. package/examples/techniques/procedural-surface/main.js +103 -0
  287. package/examples/techniques/procedural-surface/surface.js +120 -0
  288. package/examples/techniques/stylized-shading/README.md +75 -0
  289. package/examples/techniques/stylized-shading/main.js +93 -0
  290. package/examples/techniques/stylized-shading/shading.js +131 -0
  291. package/examples/techniques/sun-and-key-light/README.md +135 -0
  292. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  293. package/examples/techniques/sun-and-key-light/main.js +95 -0
  294. package/examples/techniques/wet-road/README.md +99 -0
  295. package/examples/techniques/wet-road/main.js +68 -0
  296. package/examples/techniques/wet-road/wetRoad.js +209 -0
  297. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  298. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  299. package/examples/webgpu-tsl/README.md +42 -0
  300. package/examples/webgpu-tsl/main.js +21 -0
  301. package/examples/webgpu-tsl/tslScene.js +75 -0
  302. package/examples/world/.threedog/content-index.json +1 -0
  303. package/examples/world/GAMEMAP.md +22 -15
  304. package/examples/world/art/humanoid.js +42 -0
  305. package/examples/world/art/index.js +11 -0
  306. package/examples/world/art/models.js +58 -0
  307. package/examples/world/art/shapes.js +9 -0
  308. package/examples/world/assets.js +6 -0
  309. package/examples/world/content/audio.js +5 -5
  310. package/examples/world/content/npcs.js +2 -2
  311. package/examples/world/content/props.js +1 -1
  312. package/examples/world/content/rules.js +1 -1
  313. package/examples/world/content/templates.js +1 -1
  314. package/examples/world/content/vegetation.js +1 -1
  315. package/examples/world/main.js +17 -13
  316. package/examples/world/style/index.js +61 -0
  317. package/examples/world/style/plugins/10-bloom.js +5 -0
  318. package/index.d.ts +50 -45
  319. package/index.js +27 -22
  320. package/llms.txt +20 -12
  321. package/modules/ambience/Ambience.js +34 -23
  322. package/modules/calendar/Calendar.js +163 -0
  323. package/modules/calendar/contract.js +21 -0
  324. package/modules/calendar/index.js +81 -0
  325. package/modules/{sky → calendar}/schedule.js +17 -16
  326. package/modules/calendar/seasons.js +55 -0
  327. package/modules/camera/FirstPersonCamera.js +6 -15
  328. package/modules/camera/FixedCamera.js +33 -15
  329. package/modules/camera/FollowCamera.js +90 -16
  330. package/modules/camera/RtsCamera.js +18 -17
  331. package/modules/camera/common.js +70 -19
  332. package/modules/camera/contract.js +17 -0
  333. package/modules/camera/projection.js +11 -24
  334. package/modules/characters/Character.js +196 -59
  335. package/modules/characters/NPC.js +87 -36
  336. package/modules/characters/assetModel.js +27 -8
  337. package/modules/characters/behaviors.js +2 -1
  338. package/modules/characters/contract.js +13 -0
  339. package/modules/characters/footsteps.js +1 -1
  340. package/modules/characters/index.js +87 -49
  341. package/modules/characters/moveHelpers.js +4 -5
  342. package/modules/characters/movers/common.js +97 -19
  343. package/modules/characters/movers/manual.js +20 -0
  344. package/modules/characters/movers/rapier.js +19 -16
  345. package/modules/characters/movers/simple.js +14 -11
  346. package/modules/characters/movers/support.js +172 -0
  347. package/modules/characters/npcAvoid.js +47 -42
  348. package/modules/characters/npcSim.js +12 -8
  349. package/modules/characters/npcView.js +44 -16
  350. package/modules/characters/pathAsync.js +7 -3
  351. package/modules/characters/playerStrings.js +4 -3
  352. package/modules/characters/proceduralRig.js +46 -10
  353. package/modules/characters/useModel.js +1 -1
  354. package/modules/characters/vehicle.contract.js +21 -0
  355. package/modules/characters/walkTo.js +21 -7
  356. package/modules/collision/Collision.js +65 -25
  357. package/modules/collision/grid.js +8 -6
  358. package/modules/content/explain.js +2 -2
  359. package/modules/content/fields.js +102 -0
  360. package/modules/content/ids.js +8 -6
  361. package/modules/content/index.js +97 -28
  362. package/modules/content/loader.js +45 -33
  363. package/modules/content/models.js +11 -40
  364. package/modules/content/packs.js +6 -5
  365. package/modules/content/parts.js +41 -0
  366. package/modules/content/props.js +16 -9
  367. package/modules/content/rules.js +58 -0
  368. package/modules/content/stages.js +80 -0
  369. package/modules/content/templates.js +121 -30
  370. package/modules/debug/DebugPanel.js +24 -17
  371. package/modules/flow/contract.js +16 -0
  372. package/modules/flow/index.js +21 -15
  373. package/modules/gameplay/Container.js +41 -32
  374. package/modules/gameplay/Containers.js +30 -15
  375. package/modules/gameplay/Dialogue.js +113 -55
  376. package/modules/gameplay/Interactions.js +193 -67
  377. package/modules/gameplay/Inventory.js +69 -73
  378. package/modules/gameplay/Quests.js +75 -39
  379. package/modules/gameplay/boxOps.js +3 -3
  380. package/modules/gameplay/dialogue.contract.js +21 -0
  381. package/modules/gameplay/dialogueBox.js +4 -2
  382. package/modules/gameplay/dialogueBubbles.js +116 -0
  383. package/modules/gameplay/interactionPrompt.js +4 -1
  384. package/modules/gameplay/interactions.contract.js +16 -0
  385. package/modules/gameplay/inventory.contract.js +23 -0
  386. package/modules/gameplay/inventoryOps.js +18 -16
  387. package/modules/gameplay/pickups.js +268 -85
  388. package/modules/gameplay/questLog.js +4 -4
  389. package/modules/gameplay/quests.contract.js +17 -0
  390. package/modules/grid/Grid.js +92 -50
  391. package/modules/grid/Layer.js +14 -13
  392. package/modules/grid/index.js +60 -36
  393. package/modules/grid/ops.js +20 -18
  394. package/modules/grid/preview.js +15 -16
  395. package/modules/grid/strings.js +12 -0
  396. package/modules/grid/tiles.js +6 -5
  397. package/modules/hlod/index.js +51 -19
  398. package/modules/hud/index.js +35 -20
  399. package/modules/hud/parts.js +20 -7
  400. package/modules/level/heightfield.js +3 -1
  401. package/modules/level/index.js +45 -20
  402. package/modules/level/nodes.js +4 -3
  403. package/modules/lights/index.js +42 -18
  404. package/modules/music/Music.js +38 -21
  405. package/modules/music/rules.js +1 -1
  406. package/modules/nav/index.js +48 -42
  407. package/modules/net/Client.js +13 -6
  408. package/modules/net/Host.js +19 -5
  409. package/modules/net/Net.js +2 -1
  410. package/modules/net/index.js +13 -8
  411. package/modules/net/sync.js +9 -8
  412. package/modules/net/transports.js +77 -27
  413. package/modules/particles/Particles.js +23 -14
  414. package/modules/particles/contract.js +17 -0
  415. package/modules/particles/effect.js +39 -11
  416. package/modules/photo/Photo.js +53 -36
  417. package/modules/rigid/RigidBodies.js +194 -32
  418. package/modules/rigid/Vehicles.js +18 -15
  419. package/modules/rigid/sync.js +62 -17
  420. package/modules/settings/Settings.js +57 -52
  421. package/modules/settings/apply.js +38 -3
  422. package/modules/settings/sections.js +5 -3
  423. package/modules/settings/strings.js +3 -2
  424. package/modules/settings/view.js +5 -3
  425. package/modules/sky/Sky.js +88 -176
  426. package/modules/sky/cascades.js +86 -25
  427. package/modules/sky/cascades.tsl.js +82 -0
  428. package/modules/sky/clouds.js +34 -19
  429. package/modules/sky/domeLayers.js +30 -15
  430. package/modules/sky/environment.js +83 -13
  431. package/modules/sky/fog.js +140 -95
  432. package/modules/sky/frame.js +112 -44
  433. package/modules/sky/look.js +22 -19
  434. package/modules/sky/lookFog.js +48 -52
  435. package/modules/sky/lookShadow.js +53 -41
  436. package/modules/sky/lookSky.js +82 -21
  437. package/modules/sky/season.js +21 -0
  438. package/modules/sky/shader.js +41 -19
  439. package/modules/sky/shadow.js +44 -20
  440. package/modules/sky/skyModule.js +45 -33
  441. package/modules/sky/tint.js +61 -0
  442. package/modules/terrain/ChunkManager.js +175 -108
  443. package/modules/terrain/chunkJob.js +1 -1
  444. package/modules/terrain/chunkQueries.js +6 -4
  445. package/modules/terrain/index.js +105 -50
  446. package/modules/terrain/look.js +83 -0
  447. package/modules/terrain/lookGround.js +21 -16
  448. package/modules/terrain/terrainDefaults.js +1 -1
  449. package/modules/terrain/terrainEdit.js +18 -20
  450. package/modules/terrain/terrainGen.js +5 -3
  451. package/modules/terrain/terrainIsland.js +5 -4
  452. package/modules/terrain/terrainShape.js +12 -12
  453. package/modules/terrain/terrainShapeMain.js +8 -7
  454. package/modules/terrain/terrainTexture.js +21 -19
  455. package/modules/timeline/Timeline.js +95 -43
  456. package/modules/timeline/Tween.js +18 -10
  457. package/modules/timeline/letterbox.js +2 -2
  458. package/modules/timeline/shots.js +5 -1
  459. package/modules/triggers/index.js +107 -76
  460. package/modules/vegetation/Vegetation.js +190 -102
  461. package/modules/vegetation/densityMap.js +62 -0
  462. package/modules/vegetation/groundChunks.js +52 -58
  463. package/modules/vegetation/index.js +31 -10
  464. package/modules/vegetation/look.js +119 -0
  465. package/modules/vegetation/lookWind.js +71 -10
  466. package/modules/vegetation/modelGeometry.js +3 -2
  467. package/modules/vegetation/nearFade.js +45 -0
  468. package/modules/water/Water.js +65 -27
  469. package/modules/water/look.js +29 -18
  470. package/modules/water/surface.js +64 -25
  471. package/modules/water/surfaceDefaults.js +3 -0
  472. package/modules/weather/Weather.js +62 -104
  473. package/modules/weather/look.js +1 -2
  474. package/modules/weather/particles.js +24 -9
  475. package/modules/weather/strings.js +2 -2
  476. package/modules/weather/weatherLook.js +135 -0
  477. package/modules/world/World.js +24 -7
  478. package/modules/world/explain.js +1 -1
  479. package/modules/world/index.js +18 -4
  480. package/modules/world/persist.js +62 -2
  481. package/modules/world/pos.js +3 -2
  482. package/modules/world/records.js +8 -6
  483. package/modules/world/sim.js +60 -20
  484. package/modules/world/simFar.js +4 -3
  485. package/modules/world/state.js +3 -2
  486. package/modules/world/thingSource.js +1 -1
  487. package/modules/world/views.js +7 -5
  488. package/package.json +8 -3
  489. package/presets.js +41 -27
  490. package/render/PostFX.js +145 -120
  491. package/render/backend.js +440 -0
  492. package/render/detail.js +150 -45
  493. package/render/effects.js +130 -38
  494. package/render/engineUniforms.js +10 -1
  495. package/render/fuse.js +5 -4
  496. package/render/fx/cloudShadow.tsl.js +16 -0
  497. package/render/fx/detail.tsl.js +66 -0
  498. package/render/fx/index.js +26 -0
  499. package/render/fx/lighting.tsl.js +28 -0
  500. package/render/fx/nodeErrors.tsl.js +68 -0
  501. package/render/fx/noise.tsl.js +12 -0
  502. package/render/fx/objectOrigin.tsl.js +42 -0
  503. package/render/fx/particles.tsl.js +139 -0
  504. package/render/fx/patchNodes.tsl.js +403 -0
  505. package/render/fx/postWebGPU.tsl.js +158 -0
  506. package/render/fx/season.tsl.js +13 -0
  507. package/render/fx/sky.tsl.js +260 -0
  508. package/render/fx/uniforms.tsl.js +67 -0
  509. package/render/fx/water.tsl.js +53 -0
  510. package/render/fx/wind.tsl.js +22 -0
  511. package/render/fxNumbers.js +36 -0
  512. package/render/hotGlsl.js +24 -0
  513. package/render/lighting.js +66 -14
  514. package/render/lights.js +223 -4
  515. package/render/lookGlow.js +139 -0
  516. package/render/lookSurface.js +99 -36
  517. package/render/materials.js +71 -52
  518. package/render/modeling.js +73 -0
  519. package/render/ownFrame.js +76 -0
  520. package/render/patches.js +311 -34
  521. package/render/postLook.js +124 -46
  522. package/render/postWebGL.js +197 -0
  523. package/render/probes.js +231 -0
  524. package/render/shaderErrors.js +154 -0
  525. package/render/slots.js +165 -0
  526. package/render/surface.js +53 -17
  527. package/render/terms.js +211 -0
  528. package/render/uniformDecl.js +3 -2
  529. package/types/common.d.ts +2 -2
  530. package/types/core.d.ts +620 -244
  531. package/types/gameplay.d.ts +494 -318
  532. package/types/generated/core/Audio.d.ts +26 -42
  533. package/types/generated/core/Batching.d.ts +6 -2
  534. package/types/generated/core/Budget.d.ts +2 -8
  535. package/types/generated/core/DebugOverrides.d.ts +44 -3
  536. package/types/generated/core/I18n.d.ts +2 -2
  537. package/types/generated/core/Input.d.ts +102 -31
  538. package/types/generated/core/Ops.d.ts +31 -0
  539. package/types/generated/core/Random.d.ts +2 -2
  540. package/types/generated/core/Saves.d.ts +10 -2
  541. package/types/generated/core/Stream.d.ts +1 -1
  542. package/types/generated/core/Threads.d.ts +4 -1
  543. package/types/generated/core/Views.d.ts +0 -1
  544. package/types/generated/core/audioVoice.d.ts +17 -9
  545. package/types/generated/core/control.d.ts +55 -0
  546. package/types/generated/core/session.d.ts +2 -1
  547. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  548. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  549. package/types/generated/modules/calendar/index.d.ts +10 -0
  550. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  551. package/types/generated/modules/grid/Grid.d.ts +61 -25
  552. package/types/generated/modules/grid/Layer.d.ts +5 -5
  553. package/types/generated/modules/grid/index.d.ts +29 -17
  554. package/types/generated/modules/music/Music.d.ts +5 -3
  555. package/types/generated/modules/net/index.d.ts +3 -3
  556. package/types/generated/modules/net/transports.d.ts +12 -3
  557. package/types/generated/modules/particles/Particles.d.ts +1 -1
  558. package/types/generated/modules/sky/Sky.d.ts +12 -104
  559. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  560. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  561. package/types/generated/modules/weather/Weather.d.ts +17 -18
  562. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  563. package/types/generated/modules/world/World.d.ts +18 -3
  564. package/types/generated/render/PostFX.d.ts +67 -30
  565. package/types/generated/render/materials.d.ts +26 -20
  566. package/types/generated/render/modeling.d.ts +30 -0
  567. package/types/generated/render/patches.d.ts +16 -2
  568. package/types/generated/ui/UI.d.ts +6 -3
  569. package/types/nav.d.ts +6 -0
  570. package/types/physics.d.ts +137 -44
  571. package/types/style.d.ts +125 -92
  572. package/types/tsl.d.ts +86 -0
  573. package/types/world.d.ts +164 -110
  574. package/ui/Focus.js +25 -14
  575. package/ui/LoadingScreen.js +1 -1
  576. package/ui/Parts.js +27 -11
  577. package/ui/UI.js +20 -10
  578. package/ui/cursor.js +115 -0
  579. package/ui/defaults.js +15 -11
  580. package/ui/theme.js +9 -6
  581. package/ui/touchPart.js +1 -1
  582. package/core/claims.js +0 -51
  583. package/core/look/layers.js +0 -136
  584. package/core/renamed.js +0 -21
  585. package/docs/api/entities.md +0 -61
  586. package/docs/recipes/09-style-pack.md +0 -234
  587. package/examples/styletest/overrides.js +0 -33
  588. package/examples/styletest/panel.js +0 -135
  589. package/modules/entities/Entities.js +0 -243
  590. package/modules/entities/build.js +0 -25
  591. package/modules/entities/index.js +0 -4
  592. package/modules/sky/calendar.js +0 -80
  593. package/modules/sky/layers.js +0 -69
  594. package/modules/terrain/chunkLevels.js +0 -40
  595. package/modules/terrain/mountTerrain.js +0 -32
  596. package/modules/world/cells.js +0 -42
@@ -5,16 +5,23 @@ Everything you hear is the game's. The engine ships no sound files and plays not
5
5
  `api/ambience.md`, `api/music.md`.
6
6
 
7
7
  ## 1. Config in one place
8
+ Two places, one job each: **the asset manifest says what a sound is** (a file, or a synth function made in code, registered by name like a
9
+ model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...). Engine modules register their own synths
10
+ (`footstep`, `shutter`, `thunder`, ambience's `wind` `rain` `water` `birds` `crickets`) as built-in sound assets that stay silent until a rule names them.
8
11
  ```js
12
+ engine.assets.manifest({ name: 'sfx', sounds: {
13
+ door: '/sfx/door.ogg', hit1: '/sfx/hit1.ogg', hit2: '/sfx/hit2.ogg', shot: '/sfx/shot.ogg',
14
+ ding: (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; }, // a synth: connect to out, return seconds (or { stop(t) })
15
+ } });
9
16
  const engine = createEngine({ canvas, audio: {
10
17
  levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
11
18
  sounds: {
12
- door: '/sfx/door.ogg', // a file
13
- hit: ['/sfx/hit1.ogg', '/sfx/hit2.ogg', '/sfx/hit3.ogg'], // variants: random, never the same one twice in a row
14
- shot: { src: '/sfx/shot.ogg', jitter: { pitch: 0.08, volume: 0.1 }, cooldown: 0.05, voices: 4, distance: { ref: 3, max: 80 } },
15
- footstep: 'synth', // the engine's synthesized one
16
- 'step.sand': { synth: 'footstep', params: { surface: 'sand' } }, // a synth with parameters
17
- wind: 'synth', birds: 'synth',
19
+ door: {}, // the asset of the same name, default rules
20
+ hit: ['hit1', 'hit2'], // variants: random, never the same one twice in a row
21
+ shot: { src: 'shot', jitter: { pitch: 0.08, volume: 0.1 }, cooldown: 0.05, voices: 4, distance: { ref: 3, max: 80 } },
22
+ footstep: {}, // a built-in synth asset, named so it plays
23
+ 'step.sand': { src: 'footstep', params: { surface: 'sand' } }, // a synth source with parameters
24
+ wind: {}, birds: {}, ding: { volume: 0.6 },
18
25
  },
19
26
  ambience: [ /* rule table, section 3 */ ],
20
27
  music: { tracks: { /* section 4 */ }, rules: [] },
@@ -32,18 +39,19 @@ Buses are real Web Audio `GainNode`s: `master`, `music`, `sfx`, `ambience`, `ui`
32
39
  engine.audio.sfx('door'); // plays on its bus (default sfx)
33
40
  const h = engine.audio.sfx('shot', { at: enemy.root }); // 3D: a PannerNode that follows the Object3D every frame
34
41
  const hum = engine.audio.sfx('engine-hum', { loop: true, at: [4, 0, 2] });
35
- hum?.fade(0.2, 1.5); hum?.stop(1); // the handle (null while silent, see below): fade(to, seconds), stop(fade), setPosition(at)
42
+ hum?.fade({ to: 0.2, seconds: 1.5 }); hum?.stop({ fade: 1 }); // the handle (null while silent, see below): fade({ to, seconds }), stop({ fade }), remove(), setPosition(at)
36
43
  engine.audio.sfx('click', { bus: 'ui' });
37
44
  ```
38
- `sfx` returns `null` when the sound is silent: not in `audio.sounds`, audio still locked (before the first click), or inside its `cooldown`. Over its
45
+ `sfx` returns `null` when the sound is silent: neither a rule nor an asset of that name, a built-in synth no rule names, audio still locked (before
46
+ the first click), or inside its `cooldown`. A manifest sound with no rule plays by its name with default rules. Over its
39
47
  `voices` limit the oldest voice stops. Files by path without an entry: `await engine.audio.play(url, { bus, loop, fadeIn })`.
40
48
 
41
49
  Built-in synth parameters (`params`): `wind` / `water` take `freq` (filter Hz), `birds` `range: [low, high]` Hz, `crickets` `freq` (chirp Hz, default
42
50
  4300); every synth also gets `pitch`, the sfx pitch multiplier (~1). A sound whose file fails to load keeps its ambience rule silent (one warning)
43
51
  until the rules load again, instead of refetching.
44
52
 
45
- Your own synth: `engine.audio.register('ding', (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; })`. Connect to `out` and
46
- return the length in seconds (or `{ stop(t) }` for a loop).
53
+ Your own synth is a sound asset: `engine.assets.manifest({ sounds: { ding: synthFn } })` (or `{ build: synthFn, params }` for default params).
54
+ Connect to `out` and return the length in seconds (or `{ stop(t) }` for a loop).
47
55
 
48
56
  ## 3. Ambience: a rule table
49
57
  Each rule names a sound and says when and how loud. A rule with `every` is a one-shot at random gaps; without, a loop that fades in and out (and stops
@@ -99,7 +107,7 @@ A content pack carries the game's audio the way it carries items: data only, sou
99
107
  ```js
100
108
  // content/audio.js (export it from content/index.js like any content file)
101
109
  export default {
102
- sounds: { wind: 'synth', door: 'door', hit: ['hit1', 'hit2'], shot: { src: 'shot', cooldown: 0.05 } }, // 'synth' or asset pack sound names
110
+ sounds: { wind: {}, door: 'door', hit: ['hit1', 'hit2'], shot: { src: 'shot', cooldown: 0.05 } }, // asset pack sound names (files or synths)
103
111
  ambience: [
104
112
  { sound: 'wind', volume: { base: 0.05, add: { wind: 0.08, altitude: 0.00375 }, max: 0.5 } }, // base + measure x factor, clamped
105
113
  { sound: 'rain', volume: { add: { rain: 0.22 } } },
@@ -113,7 +121,7 @@ export default {
113
121
  engine.assets.manifest({ name: 'sfx', base: '/sounds/', sounds: { door: 'door.ogg', hit1: 'hit1.ogg', hit2: 'hit2.ogg', shot: 'shot.ogg', 'music-day': 'day.ogg' } });
114
122
  engine.content.load([base, forest]); // each pack's audio merges in
115
123
  ```
116
- - **Names, never paths or code.** A sounds string other than `'synth'` is a sound name from an asset pack (`engine.audio.load` and music resolve it
124
+ - **Names, never paths or code.** A sounds string is a sound name from an asset pack, a file or a synth (`engine.audio.load` and music resolve it
117
125
  through `engine.assets`, so a missing file falls back to silence as an `engine.loading` task). A file path warns in dev; a function anywhere in the
118
126
  table drops that rule with a dev warning. `npm run check` reports both as errors.
119
127
  - **Measures** are the numbers data compares and adds up. Built in: `daylight` (sky, 0 at night), `rain` / `snow` / `wind` (weather), `nearWater`
@@ -12,7 +12,7 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
12
12
  | Attack, damage, enemy hit, death | ops with `can` / `run` (recipe 23), so keys, the dev bridge, MCP, tests and the AI run one rule | `player.attack`, `enemy.damage`, `enemy.attack`, `player.die` |
13
13
  | Enemy AI (chase, face, strike) | `engine.world.simulate(kind, { near })`, a fixed step per near record; it strikes with `ops.run(..., { actor: rec.id })` | `world.simulate('slime', ...)` |
14
14
  | Gameplay keys | content `actions` (`attack: { keys: ['Mouse0', 'KeyF'] }`), read with `input.pressed` in `onFixed` | `onFixed` runs `player.attack` |
15
- | Drop | `engine.inventory.spawnPickup(item, at, { id })` inside the death op; E picks it up through `interactions` | `${id}-drop` |
15
+ | Drop | `engine.pickups.spawn(at, { give: item, id })` inside the death op; E picks it up through `interactions`, into the bag of whoever presses | `${id}-drop` |
16
16
  | HUD, death screen, retry, save keys | `onFrame`: `hud.bar`, `toast`, `engine.session.newGame()` | the frame hook |
17
17
 
18
18
  ## 2. Rules that keep it replayable
@@ -29,5 +29,38 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
29
29
  `followCamera({ ...presets.camera.overShoulder })` locks the mouse on a click. While locked, mouse buttons still arrive as `Mouse0`..`Mouse4` keys, so
30
30
  `attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is itself a `Mouse0` press and swings once; a game that does not
31
31
  want that ignores attacks until the `page:pointerlock` event reports `locked: true`. `presets.player.aim` turns the player toward where the camera
32
- looks, so a swing goes where you aim. Without a style pack the room and enemy are gray (`?style=none`); colors come from a style part
32
+ looks, so a swing goes where you aim. Without a style the room and enemy are gray (`?style=none`); colors come from a style part
33
33
  (`examples/action/look.js`).
34
+
35
+ ## 4. Movement: jumps, speed effects, bullet time, platforms, falling
36
+ ```js
37
+ createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
38
+ engine.player.launch(16, { owner: 'pad' }); // a jump pad / spring
39
+ engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste for 5 s; no id = every character (mud, wind)
40
+ engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time: enemies on channel 'enemies' at 35%
41
+ engine.onFixed(dt => moveShots(dt), { channel: 'enemies' }); // your own enemy logic on the same slowed dt
42
+ engine.characters.support(liftMesh); // a moving platform: move liftMesh any way, riders follow
43
+ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player.mover = 'simple'; // take over, give back
44
+ ```
45
+ - **Jumps** (all public, no private fields): `jump()` is buffered for `jumpBuffer` s (default 0.12) and uses coyote time (`coyoteTime`); in the air it is an
46
+ air jump while `maxJumps` allows, at `airJumpSpeed` (default `jumpSpeed`). `jump({ air: false })` = ground only. `addJumps(n)` / `resetJumps()` for
47
+ pickups and wall touches, `launch(speed, { owner })` for jump pads (emits `character:launch`), `jumpState()` reads `{ grounded, coyoteLeft,
48
+ bufferLeft, jumpsUsed, jumpsLeft, vy }`. `character:jump` carries `{ air, index }`. Writing `player.vy` yourself is fine: it is an impulse.
49
+ - **Speed, gravity, jump height, can-jump**: the fields (`player.speed = 6`) are the game's base values; effects go through `engine.mod('move.speed' |
50
+ 'move.runSpeed' | 'move.gravity' | 'move.jumpSpeed' | 'move.canJump', { owner, id?, set | add | mul | clamp, for? })`, so stamina (run = walk), haste
51
+ x1.2 and mud x0.6 combine and end in any order. `player.stat('speed')` reads the result. A stun: `engine.mod('move.canJump', { owner: 'stun', id:
52
+ 'player', set: 0, for: 0.8 })`. `move()` takes no speed argument; the direction's length (0-1) scales the speed.
53
+ - **Bullet time / time channels**: a character the engine drives moves and animates on `character.channel` (player `'player'`, NPCs `'world'`), so
54
+ `engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35 })` slows NPCs added with `npcs.add({ channel: 'enemies' })` (far ones too) and
55
+ `onFixed(fn, { channel: 'enemies' })` code; `clock.after(1, 'poison:tick', data, { channel: 'enemies' })` slows a timer with them. The player keeps
56
+ full speed unless you mod `'time.player'`. Your own `player.move(x, z, run, dt)` uses the dt you pass. Effects end in any order (recipe 55).
57
+ - **Platforms**: `characters.support(object, { id?, safe?, carry?: 'position' | 'position+yaw', inherit? })` returns `{ id, remove() }`. The rider
58
+ compares the platform's matrix with the one it recorded, so it does not matter whether the platform moves in your `onFixed` before or after the
59
+ player, in a timeline or in physics. `player.support` says what it stands on (`kind: 'ground' | 'platform' | 'collider' | 'water' | null`, the
60
+ platform's `velocity`); jumping off keeps the platform's speed until landing. With `mover: 'rapier'` give the platform a collider as well.
61
+ - **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe, preventDefault() }` once and puts the player
62
+ back on `player.safeGround` (the last spot it stood still on safe, unmoving ground; saved). Take hp in the listener; `preventDefault()` to handle it yourself.
63
+ - **Your own controller**: `mover: 'manual'` = you write the position; `move()` then only updates `grounded`, `support` (platforms still carry),
64
+ `safeGround` and the fall check. Switch at any time (`player.mover = 'manual'` / `'simple'`): a cutscene, a grapple, a ladder.
65
+ - **Knockback / dashes**: `player.push(vx, vz, seconds)`. Writing `player.velocity` or `player.vy` is an impulse: the mover keeps integrating from
66
+ it next step (horizontal velocity is then steered back toward the input), so it never fights you; for full control use `mover: 'manual'`.
@@ -1,18 +1,20 @@
1
1
  # Environment lighting
2
2
 
3
- The engine gives the mechanism and sets nothing: `scene.environment` is `null` until a style pack or the game asks for one, so the plain low-poly
4
- Lambert look is unchanged. The background (the sky dome or `sky.skybox`) and the environment lighting are two separate fields.
3
+ The engine gives the mechanism and sets nothing: `scene.environment` is `null` until a style or the game asks for one, so the default look
4
+ (lit by the sun and hemisphere lights only) is unchanged. The background (the sky dome or `sky.skybox`) and the environment lighting are two separate fields.
5
5
 
6
6
  ```js
7
7
  engine.look.env.replace('sky'); // lit by the procedural sky; follows the time of day
8
8
  engine.look.env.set({ intensity: 0.8 });
9
9
  engine.look.env.replace('hdr/studio.hdr'); engine.look.env.set({ intensity: 1, rotation: Math.PI / 2 }); // an HDR / panorama asset (equirectangular)
10
10
  engine.look.env.set({ intensity: 0.5 }); // fields given change, the rest stay
11
- engine.look.env.replace(false); // off, GPU memory released
11
+ engine.look.env.replace(myPmremTarget); // your own map: a PMREM target / texture is used as is, a Texture (equirect) or CubeTexture is prefiltered; never disposed by the engine
12
+ engine.look.env.replace(false); // sky map off, GPU memory released; the room map of look.lights env.share (under a sky; env.intensity without one, 0 = none) is back
12
13
  engine.sky.environment; // { source, intensity, rotation, interval, builds } or null
13
14
  ```
14
15
  A pack gives defaults in `sky.environment` (same fields, plus `low`), the game overrides with `sky({ environment: {...} })` or at run time with
15
16
  `look.env.replace(...)` / `look.env.set(...)`. `low: false` turns it off on low-tier devices; any other `low` object replaces fields there.
17
+ Removing a game layer (`h.remove()`) falls back to the pack's env, and with none to the render baseline's neutral room map (`look.lights` `env.share` of the ambient under a sky, `env.intensity` without one; 0.5 under every pack), not to no environment; a pack that wants none sets `env.share: 0` and `env.intensity: 0`.
16
18
 
17
19
  ## Sources
18
20
  - `'sky'`: the dome is rendered into a cube and prefiltered with `PMREMGenerator`. It is rebuilt only when the sky colors, sun direction or cloud
@@ -31,6 +33,27 @@ A pack gives defaults in `sky.environment` (same fields, plus `low`), the game o
31
33
  reflections from the scene environment (use a Standard / Physical material for that).
32
34
  - Intensity is `scene.environmentIntensity`, direction offset is `scene.environmentRotation` (Y only here).
33
35
  - The hemisphere light stays and adds on top. When you turn the environment on, lower the ambient column of `sky.keyframes` (or
34
- `sky.modify('env', { ambient: 0.5 })`, [recipe 52](52-look.md#skymodify-vs-looklights)) so shadows do not wash out.
36
+ `engine.mod('look.lights.hemi.intensity', { owner: 'env', mul: 0.5 })`, [recipe 52](52-look.md#how-look-values-stack)) so shadows do not wash out.
35
37
  - The first frame with an environment recompiles every Lambert program once (the program key gains the env map); do it at start-up, not mid-game.
36
38
  - Toon, Basic and ShaderMaterial surfaces ignore it.
39
+
40
+ ## Light probes (baked indirect light)
41
+ An environment map lights everything as seen from one point. Light probes record how the light changes from place to place (a colored glow beside
42
+ a bright wall, dimmer light under a roof) and feed it to the same lit materials, with no shader of their own.
43
+ ```js
44
+ const probes = await engine.bakeProbes({ bounds: { min: [-30, 0, -30], max: [30, 8, 30] }, spacing: 4, include: o => !o.userData.moving });
45
+ const file = JSON.stringify(probes.toJSON()); // ship this; at start-up engine.loadProbes(json) replaces the bake
46
+ const shipped = engine.loadProbes(json, { follow: engine.player.root }); // follow: 'focus' (default) | 'camera' | an Object3D | () => position | false
47
+ probes.sample(cart.position, cartProbe); // the SH at any point, into a LightProbe of your own
48
+ probes.remove();
49
+ ```
50
+ - What it builds: a grid over `bounds` (step at most `spacing`; `height: 1.5` instead gives one layer that far above the ground), one cube render
51
+ per point turned into spherical harmonics by three's `LightProbeGenerator`, and one scene `LightProbe` whose SH is interpolated at the `follow`
52
+ point every frame. `probes.probe` is that LightProbe; its `intensity` is yours (three's default 1). Writing its `sh` yourself takes it over
53
+ (the engine yields; `look.lights.manual('probes')` says so first).
54
+ - The probe light adds to the hemisphere light and the environment, which the bake also saw: lower those yourself where the probes take over.
55
+ - One SH for the whole scene at a time: objects far from the follow point get that point's light. For per-object light, feed your own probes
56
+ from `sample(pos)`.
57
+ - Cost: 6 renders and a GPU read back per probe, at load time (one probe at a time, so the page keeps drawing; `probes.bakeMs` says how long).
58
+ Bake once and ship the JSON. Meshes `include` rejects are hidden only while each cube renders; no render target is left afterwards.
59
+ - Check it: `engine.describe().render.probes` (count, step, source, owner, follow, writer) and `engine.debug.view('probes')` (a dot per probe in its average color).
@@ -1,12 +1,43 @@
1
1
  # Making a new look from a reference picture
2
2
 
3
- For an AI that is given one picture ("make it look like this") and has to turn it into a style pack. Three commands do the mechanical parts:
4
- `threedog style palette` measures the picture, `npm run new-style` makes the pack, `threedog style check` finds mistakes before you look at pixels.
5
- The taste is yours: the tools never say which colors are right, they only keep the work measurable and repeatable. What a style is and the
6
- composing rules are in `09-style-pack.md`; this page is the order of work.
3
+ **In this recipe**: The loop · What a style can change, and what it cannot · Steps · Look check after every shot · Look questions · Guard rails ·
4
+ The style test page
5
+
6
+ No reference picture? Skip the measuring (step 2, `style palette`, `style compare` against a reference); judge each shot against DESIGN.md and
7
+ its "Loved / Not for this game" list, and use the rest: the loop, `style check`, the look check after every shot and the look questions.
8
+
9
+ For an AI that is given one picture ("make it look like this") and has to turn it into a style. The tools keep the work measurable: `threedog style palette`
10
+ and `style compare` measure pictures, your game's `style/index.js` holds the result, `threedog style check` finds mistakes before you look at pixels. They never say which
11
+ colors are right; the taste is yours. What a style is and the composing rules are in `09-style.md`; this page is the order of work.
12
+
13
+ ## The loop (every round, in this order)
14
+ Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
15
+ 1. **Measure the reference once** (step 2 below): `style palette <ref> --average`, then `style compare <ref> <your shot>`. Break the picture into
16
+ techniques (shading, one texture language, palette, edges) before choosing values.
17
+ 2. **Change one family of values** (colors, then materials, then post). Art code hot-swaps on save. After writing or changing a model, look at it alone
18
+ first: `threedog gallery --shots` (every model under three lights, `.threedog/gallery/index.html`) shows wrong scale, wrong facing, holes and missing
19
+ faces before the level hides them.
20
+ 3. **Shoot small and compare to the previous shot**: `threedog shot styletest --view overview --size 480x270 --keep --compare <previous.png>`. It prints the
21
+ pixel diff and the look differences. Through MCP the `snap` tool is 480 px wide by default; `style_compare` gives the numbers.
22
+ 4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that. `style compare <ref> <shot>
23
+ --out side.png` puts both in one image. With no reference, read the shot's hints (below). Then look at the image as a player would and judge it
24
+ against the picture DESIGN.md wants and its "Loved / Not for this game" list (never against a technique example): what would a player read as a
25
+ mistake? Typical ones are objects floating or cutting into each other, odd flat discs or blobs (a hard-edged opaque "puddle" reads as a gray ball),
26
+ glare, areas too dark or busy to read, placeholder-looking shapes; these are prompts, not a list to tick. Fix what you find, or note it in
27
+ STATUS.md with why it stays. Before calling a look done, go through the "Look questions" below that matter for this game.
28
+ 5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
29
+ layer is off, `engine.describe().look` shows who set each value and where (recipe 52). Nothing drawn: `threedog scene --hidden` (reasons per mesh).
30
+ Washed-out or too-dark textures, odd normals: `threedog inspect materials` (wrong color spaces first, sizes, who made each material).
31
+ 6. **If the biggest difference stops shrinking over a few rounds, change approach** (in this order) and tell the user which and why:
32
+ `look.surface.patch('detail' | 'lighting', glsl)` -> painted textures (`map`, `normalMap`) -> `look.materials.replace` -> plain three.js
33
+ (recipe 40 section 8). Never call it "close" to stop tuning.
34
+ 7. **Every few rounds show the user the shot and the numbers.**
35
+
36
+ The loop is the same for every art direction; only what you measure and which value you move differ: flat (palette share, hard edges, no shading), painterly
37
+ (soft edges, texture, low contrast), low-poly (few flat colors, faceted light), realistic (exposure, tone mapping, lighting, material roughness). None is the default.
7
38
 
8
39
  ## What a style can change, and what it cannot
9
- Can change (all in the style pack): colors (`palette`, `terrain.colors`, `background`, `water.color`, season tints), material types per role
40
+ Can change (all in the style): colors (`palette`, `terrain.colors`, `background`, `water.color`, season tints), material types per role
10
41
  (`materials`: matte `lambert`, `toon` bands, `standard`...), lights and sky (`sky.keyframes`, sun, clouds, shadows, `exposure`, `toneMapping`), post
11
42
  effects (`post`: outline, bloom, grain, vignette, color grading from `@threedog/post-effects`), UI colors and fonts, particle looks, and the colors
12
43
  of the procedural models (`palette` read by `models.js`).
@@ -18,57 +49,83 @@ world (a canyon instead of hills), say so instead of faking it with colors.
18
49
 
19
50
  ## Steps
20
51
  1. **Keep the picture.** Put it in the game's `art/reference/` (one file per look, with a few lines of notes beside it on what to copy:
21
- palette, mood, line work, light direction).
22
- 2. **Measure it.** `threedog style palette art/reference/ref.png --n 8` prints JSON (colors with share, hue, saturation, brightness, and role hints:
23
- largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate, darkest = shadow or
24
- outline candidate) and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`. It
25
- reads pixels in a headless browser (png, jpg, webp, gif, svg). It is a measurement: a picture's biggest block may be a wall you do not want as the
26
- ground, so look at the picture too. A phone screenshot of a game usually has a dark UI frame that becomes "the biggest block": add
27
- `--ignore-ui` (cuts a flat frame around the picture) or `--region x,y,w,h` (only that rectangle), `--crop cut.png` to save exactly what was
28
- measured and open it, and `--average` for the overall mean color (HSL). The output says what area was measured.
29
- 3. **Make the pack.** `npm run new-style sand-dune` creates `packages/styles/sand-dune` from a clean template (gray neutral materials, a sky, one
30
- palette, no post effects, one palette-colored example model) and links it as `@threedog/style-sand-dune`. Import it in the game:
31
- `import style, { assets } from '@threedog/style-sand-dune'`, `createEngine({ canvas, style })`, `engine.assets.manifest(assets)`.
32
- To start from another pack's strengths instead, compose: `style: [lowpoly, sandDune]` (later parts win key by key).
52
+ palette, mood, line work, light direction). Use the highest-resolution picture you have: a small or compressed one gives wrong detail and brightness numbers.
53
+ 2. **Measure it.** `threedog style palette art/reference/ref.png --n 8 --average` (MCP: `style_palette`) prints the colors (`--json`: JSON only) with share, hue, saturation,
54
+ brightness, and role hints: largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
55
+ darkest = shadow or outline candidate, and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
56
+ It reads pixels in a headless browser (png, jpg, webp, gif, svg). The overall mean (`--average`) sets exposure and tint; the clusters pick the named
57
+ palette entries. A phone screenshot with a dark UI frame needs `--ignore-ui` or `--region x,y,w,h`; `--crop cut.png` saves exactly what was measured.
58
+ 3. **Open the style.** Edit your game's `style/index.js` (a new game has one with every key commented out, so the engine shows gray placeholders).
59
+ It is already passed in: `import style from './style/index.js'`, `createEngine({ canvas, style })`. Procedural models the look needs go in the same
60
+ folder (`style/models.js`, registered with `engine.assets.manifest({ name: 'mygame', models })`).
61
+ To start from another pack's strengths instead, compose: `style: [basePack, style]` (later parts win key by key).
33
62
  4. **Fill it in, in this order** (each step changes the picture most for the least work): `sky` and `background` (light and mood), `exposure` and
34
- `toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones), `materials` (flat `lambert` for
35
- a paper look, `toon` for bands, `phong` for shine), `post` (outline for ink lines, bloom for glow, color grading for the final tint), then `ui`.
36
- Use few colors on purpose: a reference usually has 5 to 8 that matter.
37
- 5. **Check.** `threedog style check sand-dune` (or the folder / file of a game's own style). It checks the final merged style, not each part:
63
+ `toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones; a reference usually has 5 to 8 that
64
+ matter), `materials` (`lambert` matte, `toon` banded, `phong` shiny, `standard` PBR, `basic` unlit), `post`, then `ui`. The first frame should already be close:
65
+ if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
66
+ 5. **Check.** `threedog style check` (the game's `style/` folder; or give a folder, a file or a game name). It checks the final merged style, not each part:
38
67
  unknown fields (with "did you mean"), world-state fields, palette keys a model reads but the style does not define, color formats (`'ff8800'`
39
68
  without `#`, a float, a string `'0xff8800'`), post-effect conflicts (same name twice, two `scene` effects, a depth reader after a buffer-swapping
40
69
  effect, `dof` ordered after `outline`), misspelled material roles and types, and asset names the pack does not register. `--json` gives the same list for
41
70
  tools, `--assets file.js` adds another pack's names. Exit code 1 on errors. It is static: it cannot prove a pack holds no gameplay logic, only
42
71
  the patterns R34 can see (`npm run check` runs R34).
43
- 6. **Look.** Take pictures with the same arguments every round so only the style differs:
44
- `threedog shot styletest --view overview --time day` (add `--weather rain` or another `--time` for the second shot). Use the style test page's
45
- named camera positions (see "The style test page" below), not free `--pos` shots.
46
- Read the two images side by side: reference first, then yours; name the three biggest differences (usually: overall brightness, ground color,
47
- shadow darkness) and fix those only. Then put numbers on them: `threedog style compare art/reference/ref.png .threedog/shots/styletest.png
48
- [--region x,y,w,h]` prints brightness, saturation, contrast, fine detail, average and main color of both and one sentence such as "the
49
- screenshot is 18% darker and 2.3x more broken up". It is an aid to judging, not a replacement for looking: no single number is a quality
50
- score (there is deliberately no "similarity %"); it turns "looks dirty / fragmented / too dark" into something you can change and re-measure.
51
- 7. **Iterate.** Change one family of values per round (colors, then materials, then post), re-run `style check`, shoot again. Stop when the
52
- biggest remaining difference is a silhouette or a world rule: that is the asset pack or the game, not the style.
72
+ 6. **Look: the loop above.** Take pictures with the same arguments every round so only the style differs, and use the style test page's named camera
73
+ views (below), not free `--pos` shots. `threedog style compare art/reference/ref.png .threedog/shots/styletest.png [--region x,y,w,h]` prints brightness,
74
+ saturation, contrast, fine detail, average and main color of both and one sentence such as "the screenshot is 18% darker and 2.3x more broken up". There is
75
+ deliberately no "similarity %": the numbers turn "looks dirty / fragmented / too dark" into something you can change and re-measure. Dirty = lower
76
+ saturation or an off hue, fragmented = fine detail ratio well above 1, dark or flat = brightness and contrast. Keep a change if its number moved toward
77
+ the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
78
+ Add `--out side.png` (MCP `style_compare` always writes `<shot>.compare.png`) and open that one image: reference left, screenshot right; look at both.
79
+ 7. **Stop** when the biggest remaining difference is a silhouette or a world rule: that is the asset pack or the game, not the style.
80
+
81
+ ## Look check after every shot
82
+ Every `threedog shot` prints look numbers and hints (`--no-look` skips them). The numbers are luminance, contrast (std and p5-p95 range of
83
+ luminance), saturation, clipped and near-black shares, and the shadow area. Hints come in two kinds:
84
+ - **Contradictions**, whatever the style: the settings say one thing and the pixels another. Shadows on but none measurable (with the cause it found:
85
+ `look.shadow` bias as meters of shadow depth, the view outside the shadow box, texel size, or fill light washing them out), a light that changes
86
+ no pixel.
87
+ - **Facts**: measured, maybe wanted, with what sets them: glare, large clipped or near-black areas, a night that is not dark from lighting (and
88
+ whether the brightness at 00:00 is lighting at all), the key / fill balance. Each becomes a contradiction only where DESIGN.md declares the
89
+ opposite.
90
+ - **Intent**, only against what the game declared: DESIGN.md's optional `Look intent:` line (listed words such as `no-glare`, `dark-nights`,
91
+ `strong-light`, `muted`; the template lists them all; the table's free text is not read), or the reference given with `--ref`. A muted,
92
+ low-contrast game is told when its shot measures saturated and contrasty, never the other way round unless it said so. No declaration and
93
+ no reference: numbers only, no judgement.
94
+
95
+ A hint is a fact plus the parameter and its current value, not a target. It never says what value is right for an art direction; decide that from
96
+ the reference, DESIGN.md or the user. A deliberate choice (a night meant to be pitch black) makes a hint something to note, not to fix.
53
97
 
54
- ## Method lessons (from matching a reference picture)
55
- - **Measure first, then build.** Run `style palette --average` and `style compare` before touching values; guessing by eye and getting "close" rejected
56
- several times costs more than ten minutes of measuring.
57
- - **Take the overall average, not clustered colors.** The tone of a picture is its mean (`--average`), not the 8 colors a median cut finds; a few
58
- bright accents can dominate the clusters and say little about the look. Use clusters for picking named palette entries, the mean for exposure and tint.
59
- - **Use the highest-resolution reference you have**, and crop away phone UI (`--ignore-ui` / `--region`). A small, compressed or UI-framed picture
60
- gives wrong fine-detail and brightness numbers.
61
- - **Restraint: an effect the reference does not show is not added.** Smudge filters, AO and tone changes stacked together made a picture worse with every
62
- layer. Start with no post effects, add one only for a visible difference you named, and measure again after each one. `style check` warns when more than 2 are on.
63
- - **The first frame should already be close.** Get sky, exposure, palette and material type right in the first round; if the first screenshot is far
64
- from the reference, fix that (one family of values at a time) before adding anything.
65
- - **Quantify "dirty / fragmented / dark".** Dirty = lower saturation or an off hue (average color), fragmented = fine detail ratio well above 1,
66
- dark or flat = brightness and contrast. Change one thing, run `style compare` again, keep it if the number moved toward the reference and the picture looks better.
67
- - **Nothing drawn?** Do not bisect with screenshots: `threedog scene --hidden` lists every mesh that exists but is not drawn and why (hidden parent, layers, scale 0,
68
- empty geometry, behind the camera...). A mesh that is drawn but far too small is not an error there, but its position and bounding radius are listed:
69
- compare them with what you meant (`scene` without `--hidden`).
98
+ ## Look questions
99
+ Pick the ones that matter for this game, before calling a look done and when a round stalls. They name what to look at, not which answer is
100
+ right for a given art direction.
101
+ - **Light roles**: is there one clear key light (direction, color), a fill that keeps shadows readable, and does the sky / ambient color agree with it?
102
+ `debug.view('lighting')`.
103
+ - **Shadows and contact**: do objects sit on the ground (contact shadow, AO, or a dark base), are shadow edges as hard or soft as the reference, no
104
+ acne or peter-panning? `debug.view('shadow')`. A shadow that starts a hand's width away from a foot or a crate is peter-panning: check
105
+ `look.shadow` `bias` (it is in 0-1 shadow depth, so a large value over a long light range is decimeters). Faint shadows: the shadowed ground gets
106
+ only hemi + environment, so their sum against the sun sets the contrast; small casters blur when the shadow box is much bigger than the
107
+ scene (texel size: recipe 52, "Atmosphere parts"); a compact scene fits it, for example `look.shadow.set({ extent: 30 })`.
108
+ - **Day / night**: shoot noon and night (`shot --time 12:00`, `--time 22:00`); is night as dark as the design wants on every material, PBR ones
109
+ too? A PBR material that stays bright at night is usually lit by an environment map that does not follow the time (`describe().look.env.source`
110
+ says which map lights it and whether it follows).
111
+ - **Material response**: do surfaces that should differ (wood, stone, metal, cloth, skin, water) differ in roughness, specular and color, not only hue?
112
+ A plastic-looking surface is a shading problem, not a color problem.
113
+ Metals have something to reflect (environment). A glossy flat decal (puddle, spill, polished floor) reflects only the environment map, never the
114
+ street around it: a hard-edged dark or bright ellipse then reads as a hole or a blob. Give it soft alpha edges and a color close to the surface
115
+ under it, or darken / smooth the ground's own material (roughness map) instead of laying a disc on it; check it at noon and at night.
116
+ - **Texture scale and detail**: is texel density similar across neighbors, no obvious tiling at the usual camera distance, detail matching how close the
117
+ camera gets? Color spaces right (`inspect materials`).
118
+ - **Color and grading**: value range (darkest / brightest), saturation and the overall hue shift match the reference (`style compare`); exposure and
119
+ tone mapping chosen, not left at whatever was there.
120
+ - **Atmosphere and depth**: fog, haze or color shift with distance as the reference shows; the background separates from the play space.
121
+ - **Readability of gameplay elements**: the player, interactables, hazards and pickups stand out by value or color from the ground at play distance and
122
+ under every time of day / weather the game uses (shoot them at dusk and in rain too).
123
+ - **Consistency**: does any asset step out of the overall style (outline weight, shading model, texture language) where DESIGN.md did not
124
+ intend it? A deliberate mix of styles is a choice, not a mistake.
70
125
 
71
126
  ## Guard rails
127
+ - Restraint: for each post effect, say which difference in the shot it fixes. Start with none, add one for a visible difference you named, and
128
+ measure again after each one; `style check` lists which are on and how to see what each costs.
72
129
  - Never put gameplay or world values in the pack to match a picture; `style check` reports them as errors.
73
130
  - Fonts and textures are asset-pack entries; the style names them (`ui.fonts: ['pixel']`, `terrain.detail.texture`), it does not carry files.
74
131
  - Keep `npm run check` at 0 errors; a new pack adds no warnings.
@@ -78,12 +135,19 @@ world (a canyon instead of hills), say so instead of faking it with colors.
78
135
  a shadow receiver, wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts. Same arguments, same picture, so only the style differs.
79
136
  - `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
80
137
  (`?view=room&time=dusk&weather=rain`; also `style=none` for the engine's gray placeholders, `env=1` for environment lighting from the sky).
81
- - Views: `overview` (everything, read overall brightness, ground color, shadow darkness), `character` (close-up: character colors, outline, shadow on
138
+ - Views: `overview` (everything: overall brightness, ground color, shadow darkness), `character` (close-up: character colors, outline, shadow on
82
139
  the ground), `water` (water color, shore, fog at distance), `room` (the lamp and window light against the dark corners: ambient level, `ao`, bloom),
83
140
  `path` (the camera moves along a fixed line at 2.5 m/s: with `--wait 4` the shot is the same frame every time; in a browser look for grass blades
84
141
  and shadow edges that flicker or crawl), `ui` (HUD, dialogue line, bag window: the `ui` colors).
85
- - Per round: shoot `overview`, `room` at `--time dusk`, and `character`; compare with the reference, name the three biggest differences, fix those.
86
- - `?panel=1` opens the workbench (needs the dev package `tweakpane`, installed with the repository's `npm install`; without it the page says so).
142
+ - Per round: shoot `overview`, `room` at `--time dusk`, and `character`.
143
+ - The dev panel (workbench + tune), in any game: `if (location.search.includes('panel=1')) import('@threedog/tools/panel').then(m => m.openPanel(engine));`
144
+ It needs the optional dev package `tweakpane` (`npm install -D tweakpane`; the repository's `npm install` has it); without it the page says so.
145
+ A production build of the vite preset gets a stub instead (no panel, no tweakpane in the bundle); dev and test builds get the real one.
146
+ `/styletest.html?panel=1` opens it on the style test, which also passes `{ overrides }` (its `?ov=` style part) for "apply and rebuild".
87
147
  Live sliders change exposure, sky time, environment lighting, water color, post effects and UI colors at once; palette, terrain and wave values
88
148
  are marked "needs rebuild" and only apply after "apply and rebuild". "export overrides" prints an object literal to paste into
89
- `style: [lowpoly, { ... }]`; the original pack is never written, so the paste is the one place the change becomes real.
149
+ `style: [yourPack, { ... }]`; the original pack is never written, so the paste is the one place the change becomes real.
150
+ The "tune" folder drags any look part value (`engine.look.<part>.set`), a material picked by name (color, roughness, metalness, emissive...) and
151
+ numeric `engine.uniforms`. "write back" saves them (with the style changes) to `.threedog/tune.json` on the dev server; then
152
+ `threedog tune write <file>` prints the code change as a diff (one `// threedog:tune begin ... end` block of plain calls) and `--apply` writes it.
153
+ Review it, then keep the block or move each value where it belongs (the pack, the material's definition).
@@ -1,21 +1,20 @@
1
1
  # Sky, ground and plant looks: what a style can change
2
2
 
3
- For an AI turning a reference picture into a style pack and hitting "the engine draws it this way". Colors and materials are in `09-style-pack.md`, the
3
+ For an AI turning a reference picture into a style and hitting "the engine draws it this way". Colors and materials are in `09-style.md`, the
4
4
  order of work in `35-style-from-reference.md`. This page lists the places where the *shape* of a look was fixed in engine code and is now a style
5
- setting. Every default below is the original look, bit for bit; a style that sets nothing here draws what it always drew. Style packs hold looks only
5
+ setting. Each table lists the engine default; a style that sets nothing here gets those defaults. Styles hold looks only
6
6
  (rule R34): none of these settings move a hill, a river or a species list.
7
7
 
8
- ## Sky clouds: `style.sky.clouds`
8
+ ## Sky clouds: `style.sky.clouds` (at run time `engine.look.sky.set({ clouds: { coverage, color } })`; not a `sky()` option)
9
9
  | Key | Meaning | Default |
10
10
  |---|---|---|
11
- | `color`, `shade`, `coverage`, `scale`, `speed` | as before; coverage multiplies the weather's cloud amount | |
11
+ | `color`, `shade`, `coverage`, `scale`, `speed` | lit color, shaded color, cover (multiplies the weather's cloud amount), size, drift speed | |
12
12
  | `kind` | `'plane'` cheap, 3 noise samples. `'cumulus'` billowy, 8 noise samples per cloudy sky pixel, flatter projection (clouds fill the whole sky instead of crowding at the horizon), the sun side of each cloud is lit and the underside shaded | `'plane'` |
13
13
  | `horizon` | added to `dir.y` before projecting; smaller = clouds shrink and crowd more towards the horizon | plane 0.08, cumulus 0.5 |
14
14
  | `fade` | `[from, to]` in `dir.y`: invisible below `from`, full above `to` | plane `[0, 0.18]`, cumulus `[0, 0.12]` |
15
15
  | `opacity`, `softness` | cloud alpha; width of the cloud edge | 0.9 / 0.3 (cumulus 0.95 / 0.35) |
16
16
  | `noise` | plane only: `{ scales: [2.7, 6.1], weights: [0.6, 0.3, 0.1] }`, the two finer layers' frequency and the mix of the three | as shown |
17
17
  | `relief` | cumulus only: contrast of the sun-side light | 5 |
18
- | `glsl`, `uniforms` | replace the cloud function with your own (below); overrides `kind` | none |
19
18
 
20
19
  Why a thin band at the horizon with `plane`: the plane projection divides by height, so near the horizon one screen pixel covers a lot of cloud plane
21
20
  and the noise is dense and small; overhead one pixel covers little and the same coverage looks sparse. For a sky full of big clouds use
@@ -23,12 +22,12 @@ and the noise is dense and small; overhead one pixel covers little and the same
23
22
  2.7x the noise work of plane on the cloudy pixels (pixels below the horizon or with no cloud cover skip it). Cloud shadows on the ground
24
23
  (`style.clouds.shadow`, a separate setting) follow the same weather cover, so more clouds still means more shadow.
25
24
 
26
- ```js
25
+ ```js fragment
27
26
  sky: { clouds: { kind: 'cumulus', coverage: 1, scale: 0.45, color: 0xfff4e4, shade: 0x8a9cb8, speed: [0.003, 0.001] } }
28
27
  ```
29
28
 
30
29
  ### Your own cloud function
31
- `clouds.glsl` must define this function; the dome calls it for every upper-hemisphere pixel with cover above 0.01, then does `mix(sky, rgb, a)`:
30
+ `engine.look.sky.patch('clouds', glsl | { glsl, uniforms })` is the one way in (a `glsl` key in `style.sky.clouds` throws and names it). The GLSL must define this function; the dome calls it for every upper-hemisphere pixel with cover above 0.01, then does `mix(sky, rgb, a)`:
32
31
  ```glsl
33
32
  vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)
34
33
  // dir: unit view direction, dir.y > 0. sunDir: towards the sun (the moon is opposite). night: 0 day .. 1 night.
@@ -36,75 +35,78 @@ vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, ve
36
35
  // return: rgb = final cloud color (dim it at night yourself), a = opacity (apply your own horizon fade).
37
36
  ```
38
37
  In scope: the GLSL noise helpers `float threedogHash(vec2 p)` and `float threedogNoise(vec2 p)`, the built-in cloud uniforms (`uCloudScale`, `uCloudSpeed`, `uCloudHorizon`, `uCloudFade`...) and
39
- your `clouds.uniforms` (declared for you; number, `THREE.Color`, `THREE.Vector2/3/4`, array of 2-4 numbers, or `THREE.Texture`). Change one later
40
- with `engine.sky.dome.material.uniforms.uBrush.value = 0.5`. A bad `kind`, a `glsl` without the function, or an unsupported uniform value throws with the fix.
41
- Gouache-style flat cloud blobs with a paper texture:
38
+ the patch's `uniforms` (declared for you; number, `THREE.Color`, `THREE.Vector2/3/4`, array of 2-4 numbers, or `THREE.Texture`). Change one later
39
+ with `engine.sky.dome.material.uniforms.uEdge.value = 0.1`. A bad `kind`, GLSL without the function, or an unsupported uniform value throws with the fix.
40
+ Flat painted cloud blobs with a hard edge, multiplied by a texture:
42
41
  ```js
43
- clouds: { color: 0xfff1dc, shade: 0x9aa8c4, uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
42
+ // style: clouds: { color: 0xfff1dc, shade: 0x9aa8c4 }; the function goes through the hook
43
+ engine.look.sky.patch('clouds', { uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
44
44
  glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
45
45
  vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
46
46
  float n = threedogNoise(p) * 0.65 + threedogNoise(p * 2.3 + 5.0) * 0.35;
47
- float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard, painted edge
47
+ float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard edge
48
48
  float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
49
49
  vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
50
50
  return vec4(c, a * smoothstep(0.0, 0.1, d.y));
51
- }` }
51
+ }` });
52
52
  ```
53
53
 
54
54
  ## Ground color: `style.terrain.variation`
55
- Terrain colors are baked per vertex by the (worker) generator from the palette. Before, two palette colors were blended by a noise of about 30 m
56
- wavelength and every 1/3 m cell got a 0.92-1.04 brightness grain, both fixed. Now (plain data, so it travels to the workers; unknown keys throw):
57
- ```js
55
+ Terrain colors are baked by the (worker) generator from the palette: two palette colors blended by a noise, a small brightness grain, and an
56
+ optional layer of large patches. The defaults are shown (plain data, so it travels to the workers; unknown keys throw):
57
+ ```js fragment
58
58
  terrain: { colors: { ... }, biomeColors: { ... },
59
59
  variation: {
60
60
  blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
61
61
  jitter: { size: 0.33, min: 0.92, range: 0.12 }, // grain cell in m; darkest multiplier; how much brighter it can get (0 range = no grain)
62
- patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional second, large layer: painted color blocks
62
+ patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
63
63
  } }
64
64
  ```
65
- `patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (brush-stroke blocks instead of soft
66
- clouds); without `tint` it lightens and darkens the ground, with `tint` it pulls the color towards the tint where the noise is high. Vertex colors
67
- interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp strokes use a texture (next).
65
+ `patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (hard-edged color blocks instead of a
66
+ soft blend); without `tint` it lightens and darkens the ground, with `tint` it pulls the color towards the tint where the noise is high. Vertex colors
67
+ interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp blocks use `shading: 'texture'`
68
+ (recipe 37) or a texture (next). Which combination fits which look, and ground that looks wrong up close: recipe 53.
68
69
 
69
- ### A texture on the ground (brush strokes, paper, grain)
70
+ ### Your own ground material
70
71
  `style.terrain.material` (a Material or `(engine) => Material`) replaces the ground material. Chunk geometry has `uv = world xz / chunk size`, continuous
71
72
  across chunk borders (checked by `tests/specs/appearance.mjs`), so a repeating texture is seamless whatever chunk it lands in; cloud shadows and
72
73
  season tint are added to your material. `texture.repeat.set(8, 8)` = 8 tiles per chunk. Without UVs (steep sides stretch a top-down map), project
73
74
  from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
74
75
  ```js
75
76
  material: engine => applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
76
- name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uBrush: { value: brushTexture }, uBrushScale: { value: 0.1 } }, // brushTexture: repeat wrapping
77
- glsl: { fragment: { pars: 'uniform sampler2D uBrush; uniform float uBrushScale;',
77
+ name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
78
+ glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
78
79
  color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
79
- diffuseColor.rgb *= texture2D(uBrush, vThreedogWorld.zy * uBrushScale).rgb * n.x + texture2D(uBrush, vThreedogWorld.xz * uBrushScale).rgb * n.y
80
- + texture2D(uBrush, vThreedogWorld.xy * uBrushScale).rgb * n.z;` } } }] })
80
+ diffuseColor.rgb *= texture2D(uTex, vThreedogWorld.zy * uTexScale).rgb * n.x + texture2D(uTex, vThreedogWorld.xz * uTexScale).rgb * n.y
81
+ + texture2D(uTex, vThreedogWorld.xy * uTexScale).rgb * n.z;` } } }] })
81
82
  ```
82
83
  A procedural noise texture is a `THREE.DataTexture` filled in a loop (`wrapS = wrapT = THREE.RepeatWrapping`, `colorSpace = THREE.SRGBColorSpace`,
83
- `needsUpdate = true`); `style.terrain.detail` (an asset texture multiplied in, `strength` 0-1) is the lighter alternative when the grain is a picture; on any other surface use the
84
- `detail` key of a material spec (recipe 37).
84
+ `needsUpdate = true`). The lighter alternative is a detail layer, `style.terrain.detail` / `look.ground.set({ detail })`: the same object as a
85
+ material spec's `detail` (`noise: 'grain' | 'paper' | 'stroke' | 'dabs'`, or `texture: 'name'`, or your own `glsl`; `scale`, `strength`, `fade`
86
+ ...; keys in recipe 43), with no material of your own. Which to pick: recipe 53.
85
87
 
86
88
  ## Plants and wind
87
89
  Audit of what the vegetation code fixes, split into mechanism (stays) and look (made a setting):
88
90
 
89
91
  | Where | What | Kind |
90
92
  |---|---|---|
91
- | `Vegetation.add` | per species: `wind` amplitude, `rule`, `lodRing`, `maxRing`, `nearOnly`, `castShadow`, `shadowRing`, `material`, `effects` | already options (game content) |
92
- | `GroundChunks`, `Vegetation.levelOf` | one InstancedMesh per species per chunk; rings decide LOD swap, draw distance, shadow distance; 3 ms placement budget; collision lag | mechanism, stays |
93
- | wind sway shape | two sines (speed `1.2 + 0.6*uWind` and `2.9`, spatial phase from the instance origin), height-weighted, lean with wind strength | look: **`style.wind.glsl`** replaces it |
93
+ | `Vegetation.define` | per species: `wind` amplitude, `rule`, `positions`, `densityMap`, `lodRing`, `maxRing`, `nearOnly`, `castShadow`, `shadowRing`, `material`, `effects` | already options (game content) |
94
+ | `GroundChunks`, `VegetationLook` (`modules/vegetation/look.js`) | one InstancedMesh per species per chunk; rings decide LOD swap, draw distance, shadow distance; 3 ms placement budget; collision lag | mechanism, stays (the whole look is replaceable: recipe 28 section 6) |
95
+ | wind sway shape | two sines (speed `1.2 + 0.6*uWind` and `2.9`, spatial phase from the instance origin), height-weighted, lean with wind strength | look: **`engine.look.wind.patch('sway', glsl)`** replaces it |
94
96
  | wind speed | `uWindFreq` | already `style.wind.frequency` |
95
- | season tint | `diffuseColor.rgb *= tint` (default) or a blend towards the tint; colors from `style.seasons` | look, both settings: `style.seasons.mode: 'multiply' \| 'mix'` (+ `strength`); see recipe 37 |
97
+ | season tint | `diffuseColor.rgb *= tint` (default) or a blend towards the tint; colors from `style.seasons` | look, both settings: `style.seasons.mode: 'multiply' \| 'mix'` (+ `strength`); see recipe 43 |
96
98
  | defaults | `castShadow` = not `nearOnly`, `shadowRing` 1, `lodRing` 1 | per-species options, set them in the species |
97
99
 
98
100
  ```js
99
- wind: { frequency: 1, uniforms: { uSteps: 3 }, // pose-to-pose sway for a painted look: 3 poses instead of a smooth sine
101
+ engine.look.wind.patch('sway', { uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine; before vegetation.define
100
102
  glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
101
103
  float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
102
104
  transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
103
- }` }
105
+ }` });
104
106
  ```
105
107
  `threedogWind` receives the vertex (`transformed`, object space), `ip` (world position of this plant's origin, so each plant has its own phase) and
106
108
  `position`; `uTime`, `uWind` (weather), `uWindFreq` and `THREEDOG_WIND_AMP` (the species' amplitude) are in scope. It applies to every material made by
107
- `vegetation.add` that has `wind` set, and the shadow sways with it. A missing function throws with the signature. The same object works in code:
109
+ `vegetation.define` that has `wind` set, and the shadow sways with it. A missing function throws with the signature. The same object works in code:
108
110
  `applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
109
111
 
110
112
  Cost, measured with software rendering (relative numbers only): 10,000 grass blades of 6 triangles in one InstancedMesh draw in 1 call; per frame
@@ -113,4 +115,4 @@ Reduce grass cost with `rule.perChunk`, `maxRing` and `nearOnly`, not the wind.
113
115
 
114
116
  ## What is still fixed
115
117
  Season tint is multiplicative. Cloud *shadows* on the ground (`threedog_clouds_pars_fragment`) keep their two-noise shape; only strength, scale and
116
- speed are style settings. Grass has no billboard or blade-shape setting: give `vegetation.add` your own `geometry` or `model`.
118
+ speed are style settings. Grass has no billboard or blade-shape setting: give `vegetation.define` your own `geometry` or `model`.