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,7 +1,10 @@
1
1
  # Templates: reusable objects, definition vs instance state
2
2
 
3
+ **In this recipe**: 1. Define a template · 2. Place instances · 3. What belongs to the definition, what to the instance · 4. Tests ·
4
+ 5. Point -> thing · 6. When to use a template
5
+
3
6
  Requires `world()` (in `openWorld()`); a template with `interact` needs `interactions({ ...presets.interactions.nearest })`, with `container` needs
4
- `inventory({ ...presets.keys.inventory })`. The code is `modules/content/templates.js`.
7
+ `inventory()`. The code is `modules/content/templates.js`.
5
8
 
6
9
  A **template** describes one kind of object once: its model, collision, interaction, container, sound, animation and the default values of its saved
7
10
  state. Every chest, campfire or bed you place is an **instance**: a world record that names the template (its `kind` is the template name) and holds
@@ -12,7 +15,7 @@ only its own state. There is no inheritance and no variant layer; a different lo
12
15
  ```js
13
16
  export default {
14
17
  chest: {
15
- model: 'chest', // an asset name (file or generator of an asset pack); every chest clones one shared prototype (geometry and material built once)
18
+ model: 'chest', // an asset name (file or generator of an asset pack, the same name pickups and vegetation take); every chest clones one shared prototype
16
19
  collide: 'box', // 'box' / 'circle' from the model's bounds; omitted = does not block
17
20
  state: { opened: false }, // instance fields and their defaults, copied onto each record and saved
18
21
  interact: { label: rec => rec.opened ? '关上' : '打开', op: 'chest.toggle', radius: 2 }, // using it runs the op with { id }
@@ -40,6 +43,19 @@ export default [
40
43
  Allowed per instance: `id`, `place` / `x` / `z`, `y` (height above the ground), `rot`, `scale`, `items` (replaces the starting goods) and the
41
44
  template's **state fields**. Writing a definition field (`model`, `collide`, `interact`...) throws and says to define another template.
42
45
 
46
+ **Field descriptions.** When a state field has a range or a short list of allowed values, say so in `fields` next to `state`. The default stays
47
+ only in `state`; a `default` inside `fields` is an error, because two copies of a default drift apart. The type is taken from the state value
48
+ when you leave it out:
49
+ ```js fragment
50
+ crop: { model: 'crop', state: { stage: 0, sort: 'wheat' }, fields: { stage: { type: 'int', min: 0, max: 4 }, sort: { values: ['wheat', 'corn'] } } },
51
+ turret: { model: 'turret', state: { ammo: 30 }, fields: { ammo: { min: 0, max: 99, desc: 'rounds left' } } },
52
+ ```
53
+ `npm run check` then reports a placement with `stage: 9`, `sort: 'rice'` or a misspelled `stagee` (with the closest name), and dev `engine.content.spawn`
54
+ throws on the same mistakes. `engine.content.fields('crop')` returns the whole table (placement fields plus state fields, with each state default),
55
+ in the `core/params.js` format; `fields('props')`, `fields('pickups')`, `fields('views')` and `fields('props.grid')` give the engine's own placement
56
+ fields, and a game kind in `content/rules.js` can declare `fields` the same way. A state field may not be named `id`, `kind` or `position`: those
57
+ are the record's own.
58
+
43
59
  **Ids.** An entry with state (a template with `state`, `container`, `interact` or `body`, every pickup, every grid item) gets a written id: saves find
44
60
  its changes by id, and an index id (`<template>:<index>`, `pickup:<item>:<index>`) moves to another entry when one is inserted above it. Without one,
45
61
  dev warns once per load and names the id to write. Pure decoration may keep its index id. Two entries with the same id in one load throw with the fix;
@@ -47,7 +63,7 @@ an authored id may not contain `#` or `/` (those are kept for records made durin
47
63
  spot near the river) stay in code and come in through `content.load(data, { places })`. Records made during play are numbered `<kind>#<n>`
48
64
  (`chest#4`), so they never meet an authored id.
49
65
 
50
- **Writing the ids, renaming them.** `npx threedog content ids [-w game]` lists each stateful entry that still relies on its index id with the id it
66
+ **Writing the ids, renaming them.** `threedog content ids [-w game]` lists each stateful entry that still relies on its index id with the id it
51
67
  has now (`-`/`+` lines, dry run); `--write` writes them into the content files. Writing today's id changes nothing for old saves. To give an entry a
52
68
  readable id later, change it and add the pair to `content/renames.js`: <!-- r18-ignore-line -->
53
69
  ```js
@@ -71,26 +87,61 @@ would make, as authored data (the grid comes from the content key `grids`, `{ fa
71
87
  custom properties fill the template's state), and one with `id = true` becomes a record of kind `levelNode` whose model is the node itself. Their id
72
88
  is `<level file name>/<node name>`, for example `town/door_front` (recipe 10).
73
89
 
74
- At runtime (inside an op or a fixed step), `engine.spawn(name, at, fields)` places a new instance and returns its record:
90
+ At runtime (inside an op or a fixed step), `engine.content.spawn(name, at, fields)` places a new instance and returns its record (without `fields.id`
91
+ the id is numbered `<template>#<n>`, for example `chest#3`):
75
92
  ```js
76
93
  engine.ops.define('chest.build', {
77
- run: (e, { x, z }) => e.spawn('chest', { x, z }, { items: { stick: 3 } }).id,
94
+ run: (e, { x, z }) => e.content.spawn('chest', { x, z }, { items: { stick: 3 } }).id,
78
95
  });
79
96
  ```
80
97
  Instances from `props.js` are initial records (a save stores only their changes); spawned ones are saved whole. Use `engine.world.get(id)`, `set`,
81
98
  `move`, `remove` and `query({ kind: 'chest' })` as for any record (recipe 18). Removing a record does not remove its container (the game decides what
82
99
  happens to the goods).
83
100
 
101
+ **Things that change over time: `stages`, `canGrow`, `update`.** A placeable that moves through named steps over game time is still a template.
102
+ The same shape covers a crop (seed, sprout, ripe), a turret warming up (cold, warming, armed), a building under construction (scaffold, frame,
103
+ done) or a door that takes a while to open:
104
+ ```js
105
+ // content/templates.js
106
+ export default {
107
+ crop: {
108
+ model: 'crop-seed', state: { watered: false },
109
+ stages: [{ name: 'seed', duration: 600 }, { name: 'sprout', duration: 900, scale: 0.6 }, { name: 'ripe', model: 'crop-ripe' }],
110
+ canGrow: rec => rec.watered, // asked every step, near and far; false holds the stage and blocked time does not count
111
+ interact: { label: 'Water', op: 'crop.water' }, // an interaction is always an op, run with { id }
112
+ },
113
+ turret: {
114
+ model: 'turret', state: { heat: 0 },
115
+ stages: [{ name: 'cold', duration: 5 }, { name: 'armed' }],
116
+ update: (rec, dt, e) => { if (rec.stage === 1) rec.heat = Math.min(1, rec.heat + dt); }, // every fixed step while near
117
+ },
118
+ };
119
+ ```
120
+ - `duration` is game seconds (`engine.clock.now`) spent in a stage; only the last stage may leave it out (it stays there). `scale` multiplies the
121
+ instance's scale; `model` is a model name shown from that stage on. Stages are data: content-check validates them with the engine's own rules.
122
+ - Each instance gets the state field `stage` (default 0, an int 0..n-1, so a placement may write `{ template: 'crop', stage: 2 }` and
123
+ `content.fields('crop').stage` describes it) and `stageAt`, the clock time it entered. Both are on the world record and saved like any other field.
124
+ - Growth runs near and far. A far copy has no model but still grows, and after a load, a time skip or a long walk away it catches up through
125
+ several stages at once. Each change fires `template:stage { id, template, stage, name }`. To jump a stage from an op, write the record:
126
+ `e.world.set(id, { stage: 2, stageAt: e.clock.now })`.
127
+ - `update(rec, dt, engine)` is gameplay on the fixed step (a `world.simulate` near hook), near only. Write record fields directly or with
128
+ `world.set`; both are saved. A far copy only grows.
129
+
130
+ **Many placements: split a kind into a folder.** Any content kind may be a folder instead of one file: `content/props/<area>.js`… (by area,
131
+ by theme, as you like). The parts are joined in file-name order; in `content/index.js` write `const props = contentParts(import.meta.glob('./props/*.js', { eager: true }));`
132
+ (`import { contentParts } from 'threedog'`). An id must be unique across all parts (the content check names both files). The content check hints at splitting past
133
+ about 2000 entries in one file; it also writes `.threedog/content-index.json` (id -> file:line), so `threedog content set/add/remove` opens only the one part it edits.
134
+ Add new entries at the end of a part with a written id: an entry without an id gets its position in the joined list, which an insert above it would shift.
135
+
84
136
  ## 3. What belongs to the definition, what to the instance
85
137
  | | Definition (shared, read-only) | Instance (per object, saved) |
86
138
  |---|---|---|
87
- | Template | model, collide, static, interact, container capacity and starting goods, sound, animate, state defaults, body | world record: id, kind, position, rot, scale, state fields (`opened`) |
139
+ | Template | model, collide, static, interact, container capacity and starting goods, sound, animate, stages, canGrow, update, state defaults, body | world record: id, kind, position, rot, scale, state fields (`opened`, `stage`, `stageAt`) |
88
140
  | Container | capacity, maxWeight | the goods in `engine.inventory.container(id)` |
89
141
  | Item (`inventory.define`) | name, icon, stack, weight, use | count and per-piece `data` (durability, ammo): `add('sword', 1, { data: { durability: 40 } })` |
90
- | Entity type (`entities.define`) | create, stages, interact, collider, state defaults | `ent.state` (stage, watered) on its world record |
91
142
  | Crop / enemy kind (your own table) | grow time, max hp, drops | `plantedAt`, `hp` on the record |
92
143
 
93
- Definitions are frozen when registered (`content/templates.js`, `inventory.define`, `entities.define`):
144
+ Definitions are frozen when registered (`content/templates.js`, `inventory.define`):
94
145
  `engine.content.template('chest').state.opened = true` throws `Cannot assign to read only property`, and the engine's error hint says to keep the
95
146
  value on the record instead (`engine.world.set(id, { opened: true })`). Read a definition with `engine.content.template(name)` or
96
147
  `engine.inventory.item(id)`. For your own tables of kinds (enemy types, crop types), the same split applies: keep the table in content, store `kind`
@@ -98,7 +149,8 @@ plus the changing values on the record, and wrap the table with `Object.freeze`
98
149
 
99
150
  ## 4. Tests
100
151
  `tests/specs/templates.mjs`: two chests of one template share the model, open / goods per instance, save and reload restores each, the definition
101
- never changes. `tests/specs/single-source.mjs` (`npm test -- "Single source"`): ids, duplicates, baseline + diff, orphans, level nodes, source lines, pick.
152
+ never changes. `tests/specs/template-stages.mjs`: stages grow over game time near and far and survive save / load, `update` runs on the
153
+ fixed step, an interaction runs its op, and the engine root has no second placement path (no entities module, no root-level spawn). `tests/specs/single-source.mjs` (`npm test -- "Single source"`): ids, duplicates, baseline + diff, orphans, level nodes, source lines, pick.
102
154
 
103
155
  ## 5. Point -> thing: where is this defined
104
156
  Runtime ops change only the current session and its saves. To change the level itself, edit the content files or the level model, then reload. To find
@@ -112,7 +164,7 @@ engine.world.origin('chest-home'); // the same source info for an id
112
164
  `engine.inspect(id).thing` and `engine.explain({ op, args: { id } })` say the same. A hit on a plain object added with `engine.add` gets its
113
165
  `hit.thing` from the registry (id, `at` = the file:line of the add, `saved`, `edit`; recipe 41). A record made during play shows the op and tick that spawned it
114
166
  (`spawned`), a level node its level and node name. Source lines exist in dev and test builds only (a Vite transform tags `content/*.js` with their
115
- line numbers); a release build has none and pays nothing. From a terminal or an MCP client: `npx threedog pick 480,270` (screen pixels from the canvas
167
+ line numbers); a release build has none and pays nothing. From a terminal or an MCP client: `threedog pick 480,270` (screen pixels from the canvas
116
168
  top-left) or the MCP tool `pick { x, y }`.
117
169
 
118
170
  ## 6. When to use a template
@@ -120,10 +172,10 @@ Two doors lead into one scene. Plain three.js, `engine.add(mesh, { id })`, is fi
120
172
  windmill, colliders, interactions. A template plus a placement with an `id` in `content/props.js` (or `pickups`, `npcs`, `containers`, a game kind
121
173
  from `rules.js`, the level model) is what you want when the thing must be saved with its own state, edited without touching code, or copied many
122
174
  times. Both land in the same registry: `engine.thing(id)` answers for either and says what a save keeps (recipe 41). Game code keeps the rules: ops,
123
- `world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.spawn`.
175
+ `world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.content.spawn`.
124
176
 
125
177
  `npm run check` (rule R33) flags only what breaks, in examples, templates and `games/*` alike. Error: `world.add` (without `{ save: false }`),
126
- `engine.spawn`, `spawnPickup`, `npcs.add` or `entities.spawn` at module top level or in an `engine:ready` / `level:loaded` / `session:start`
178
+ `engine.content.spawn`, `pickups.spawn` or `npcs.add` at module top level or in an `engine:ready` / `level:loaded` / `session:start`
127
179
  handler, because those are saved whole and the startup code would make a second copy after every load; and `world.add(…, { initial: true })`
128
180
  anywhere. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
129
181
  The fix is a placement in content, or an op. Places computed from the seed (a flat spot for `home`) stay in code and are passed as `places` to
@@ -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,6 +1,6 @@
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 default look
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
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
@@ -8,11 +8,13 @@ engine.look.env.replace('sky'); // lit by the p
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,27 +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. The tools keep the work measurable: `threedog style palette`
4
- and `style compare` measure pictures, `npm run new-style` makes the pack, `threedog style check` finds mistakes before you look at pixels. They never say which
5
- colors are right; the taste is yours. What a style is and the 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.
6
12
 
7
13
  ## The loop (every round, in this order)
8
14
  Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
9
- 1. **Measure the reference once** (step 2 below): `style palette <ref> --average`, then `style compare <ref> <your shot>`.
10
- 2. **Change one family of values** (colors, then materials, then post).
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.
11
20
  3. **Shoot small and compare to the previous shot**: `threedog shot styletest --view overview --size 480x270 --keep --compare <previous.png>`. It prints the
12
21
  pixel diff and the look differences. Through MCP the `snap` tool is 480 px wide by default; `style_compare` gives the numbers.
13
- 4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that.
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.
14
28
  5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
15
29
  layer is off, `engine.describe().look` shows who set each value and where (recipe 52). Nothing drawn: `threedog scene --hidden` (reasons per mesh).
16
- 6. **After two rounds without reaching the reference, take the next exit** and tell the user which and why: `look.surface.patch('detail' | 'lighting', glsl)`
17
- -> painted textures (`map`, `normalMap`) -> `look.materials.replace` -> plain three.js (recipe 40 section 8). Never call it "close" to stop tuning.
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.
18
34
  7. **Every few rounds show the user the shot and the numbers.**
19
35
 
20
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
21
37
  (soft edges, texture, low contrast), low-poly (few flat colors, faceted light), realistic (exposure, tone mapping, lighting, material roughness). None is the default.
22
38
 
23
39
  ## What a style can change, and what it cannot
24
- 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
25
41
  (`materials`: matte `lambert`, `toon` bands, `standard`...), lights and sky (`sky.keyframes`, sun, clouds, shadows, `exposure`, `toneMapping`), post
26
42
  effects (`post`: outline, bloom, grain, vignette, color grading from `@threedog/post-effects`), UI colors and fonts, particle looks, and the colors
27
43
  of the procedural models (`palette` read by `models.js`).
@@ -34,20 +50,20 @@ world (a canyon instead of hills), say so instead of faking it with colors.
34
50
  ## Steps
35
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:
36
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.
37
- 2. **Measure it.** `threedog style palette art/reference/ref.png --n 8 --average` (MCP: `style_palette`) prints JSON (colors with share, hue, saturation,
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,
38
54
  brightness, and role hints: largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
39
- darkest = shadow or outline candidate) and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
55
+ darkest = shadow or outline candidate, and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
40
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
41
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.
42
- 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
43
- palette, no post effects, one palette-colored example model) and links it as `@threedog/style-sand-dune`. Import it in the game:
44
- `import style, { assets } from '@threedog/style-sand-dune'`, `createEngine({ canvas, style })`, `engine.assets.manifest(assets)`.
45
- To start from another pack's strengths instead, compose: `style: [basePack, sandDune]` (later parts win key by key).
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).
46
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
47
63
  `toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones; a reference usually has 5 to 8 that
48
64
  matter), `materials` (`lambert` matte, `toon` banded, `phong` shiny, `standard` PBR, `basic` unlit), `post`, then `ui`. The first frame should already be close:
49
65
  if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
50
- 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:
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:
51
67
  unknown fields (with "did you mean"), world-state fields, palette keys a model reads but the style does not define, color formats (`'ff8800'`
52
68
  without `#`, a float, a string `'0xff8800'`), post-effect conflicts (same name twice, two `scene` effects, a depth reader after a buffer-swapping
53
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
@@ -59,11 +75,57 @@ world (a canyon instead of hills), say so instead of faking it with colors.
59
75
  deliberately no "similarity %": the numbers turn "looks dirty / fragmented / too dark" into something you can change and re-measure. Dirty = lower
60
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
61
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.
62
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.
63
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.
97
+
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.
125
+
64
126
  ## Guard rails
65
- - Restraint: an effect the reference does not show is not added. Start with no post effects, add one only for a visible difference you named, and measure
66
- again after each one. `style check` warns when more than 2 are on.
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.
67
129
  - Never put gameplay or world values in the pack to match a picture; `style check` reports them as errors.
68
130
  - Fonts and textures are asset-pack entries; the style names them (`ui.fonts: ['pixel']`, `terrain.detail.texture`), it does not carry files.
69
131
  - Keep `npm run check` at 0 errors; a new pack adds no warnings.
@@ -78,7 +140,14 @@ a shadow receiver, wood / stone / metal surfaces, a lit room (outside and inside
78
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
79
141
  and shadow edges that flicker or crawl), `ui` (HUD, dialogue line, bag window: the `ui` colors).
80
142
  - Per round: shoot `overview`, `room` at `--time dusk`, and `character`.
81
- - `?panel=1` opens the workbench (needs the dev package `tweakpane`, installed with the repository's `npm install`; without it the page says so).
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".
82
147
  Live sliders change exposure, sky time, environment lighting, water color, post effects and UI colors at once; palette, terrain and wave values
83
148
  are marked "needs rebuild" and only apply after "apply and rebuild". "export overrides" prints an object literal to paste into
84
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).