threedog 0.2.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (725) hide show
  1. package/CHANGELOG.md +371 -1
  2. package/README.md +21 -12
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +92 -26
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +30 -15
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +40 -19
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +75 -25
  11. package/core/Describe.js +105 -45
  12. package/core/Engine.js +203 -75
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +175 -80
  16. package/core/Inspect.js +8 -5
  17. package/core/InspectMaterials.js +84 -0
  18. package/core/InspectPerf.js +68 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/MaterialInfo.js +7 -5
  22. package/core/Ops.js +50 -9
  23. package/core/Random.js +9 -2
  24. package/core/Rays.js +12 -7
  25. package/core/SaveStore.js +41 -9
  26. package/core/Saves.js +71 -15
  27. package/core/Stream.js +13 -10
  28. package/core/Threads.js +26 -7
  29. package/core/UrlState.js +69 -13
  30. package/core/Views.js +10 -6
  31. package/core/actor.js +1 -1
  32. package/core/adaptive.js +93 -0
  33. package/core/assetEntry.js +27 -7
  34. package/core/assetHot.js +176 -0
  35. package/core/assetLoad.js +44 -19
  36. package/core/assetManifest.js +53 -11
  37. package/core/assetReport.js +5 -5
  38. package/core/audioRules.js +13 -11
  39. package/core/audioVoice.js +69 -42
  40. package/core/batchGroups.js +9 -1
  41. package/core/canvasBox.js +1 -2
  42. package/core/catalog.js +21 -5
  43. package/core/cells.js +62 -0
  44. package/core/checks.js +10 -8
  45. package/core/chunkStream.js +87 -0
  46. package/core/control.js +149 -0
  47. package/core/copies.js +32 -0
  48. package/core/dayTime.js +12 -6
  49. package/core/debugView.js +85 -18
  50. package/core/describeRender.js +117 -21
  51. package/core/describeText.js +41 -21
  52. package/core/engineCamera.js +32 -0
  53. package/core/errorCodes.js +478 -32
  54. package/core/errorHints.js +41 -142
  55. package/core/errors.js +31 -8
  56. package/core/events.generated.js +13 -7
  57. package/core/gameLights.js +69 -0
  58. package/core/grayMap.js +20 -0
  59. package/core/grid.js +14 -13
  60. package/core/gridLoad.js +2 -1
  61. package/core/ground.js +6 -4
  62. package/core/headlessLoad.js +55 -0
  63. package/core/holds.js +78 -50
  64. package/core/inputContext.js +11 -7
  65. package/core/inputDefaults.js +24 -21
  66. package/core/inputPad.js +1 -1
  67. package/core/inputPointer.js +1 -1
  68. package/core/inputTouch.js +2 -2
  69. package/core/lifecycle.js +46 -12
  70. package/core/lightWatch.js +9 -5
  71. package/core/loop.js +109 -43
  72. package/core/math.js +18 -3
  73. package/core/moduleSlots.js +100 -0
  74. package/core/moduleTypes.js +86 -0
  75. package/core/modules.js +147 -29
  76. package/core/movement.js +2 -2
  77. package/core/namedModel.js +74 -0
  78. package/core/opsCheck.js +3 -3
  79. package/core/opsFail.js +15 -6
  80. package/core/opsGuard.js +4 -4
  81. package/core/opsRun.js +4 -3
  82. package/core/owned.js +171 -0
  83. package/core/page.js +44 -10
  84. package/core/params.js +30 -8
  85. package/core/pictureSlots.js +33 -0
  86. package/core/pictureWriters.js +343 -0
  87. package/core/plugins.js +245 -0
  88. package/core/saveApply.js +99 -17
  89. package/core/saveFiles.js +8 -6
  90. package/core/saveValues.js +46 -0
  91. package/core/saveVersions.js +20 -3
  92. package/core/scatter.js +48 -19
  93. package/core/sceneDelta.js +211 -0
  94. package/core/sceneMethods.js +31 -33
  95. package/core/screenToGround.js +1 -1
  96. package/core/services.js +27 -11
  97. package/core/session.js +28 -25
  98. package/core/shaderCost.js +78 -0
  99. package/core/shadowTypes.js +3 -2
  100. package/core/shadows.js +405 -0
  101. package/core/sharedPoint.js +303 -0
  102. package/core/skip.js +36 -28
  103. package/core/stackFrames.js +45 -0
  104. package/core/stacks.js +166 -0
  105. package/core/startup.js +153 -13
  106. package/core/streamSources.js +0 -11
  107. package/core/targeting.js +1 -1
  108. package/core/textureBytes.js +20 -0
  109. package/core/thingExplain.js +3 -3
  110. package/core/thingOps.js +29 -6
  111. package/core/things.js +22 -12
  112. package/core/threadPure.js +7 -3
  113. package/core/threePatches.js +47 -0
  114. package/core/tier.js +21 -10
  115. package/core/time.js +236 -0
  116. package/core/uiClock.js +25 -0
  117. package/core/util.js +8 -2
  118. package/core/validate.js +66 -87
  119. package/core/view.js +43 -0
  120. package/core/wrap.js +106 -0
  121. package/docs/AI.md +95 -104
  122. package/docs/API.md +35 -31
  123. package/docs/CODEMAP.md +231 -176
  124. package/docs/COMMANDS.md +63 -39
  125. package/docs/CONVENTIONS.md +99 -31
  126. package/docs/MIGRATING-0.3.md +248 -0
  127. package/docs/MIGRATING-0.4.md +320 -0
  128. package/docs/MIGRATING-0.5.md +68 -0
  129. package/docs/MIGRATING-0.6.md +126 -0
  130. package/docs/MIGRATING-0.7.md +39 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +82 -28
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +15 -11
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/budget.md +4 -0
  137. package/docs/api/calendar.md +41 -0
  138. package/docs/api/cameraRig.md +16 -5
  139. package/docs/api/characters.md +41 -24
  140. package/docs/api/clock.md +6 -5
  141. package/docs/api/collision.md +10 -7
  142. package/docs/api/content.md +6 -4
  143. package/docs/api/dialogue.md +9 -9
  144. package/docs/api/engine.md +95 -65
  145. package/docs/api/events.md +20 -14
  146. package/docs/api/grids.md +10 -3
  147. package/docs/api/ground.md +1 -1
  148. package/docs/api/hud.md +5 -2
  149. package/docs/api/i18n.md +1 -1
  150. package/docs/api/input.md +13 -7
  151. package/docs/api/interactions.md +10 -6
  152. package/docs/api/inventory.md +17 -17
  153. package/docs/api/level.md +0 -2
  154. package/docs/api/lightPool.md +3 -1
  155. package/docs/api/music.md +1 -1
  156. package/docs/api/nav.md +3 -0
  157. package/docs/api/occlusion.md +5 -0
  158. package/docs/api/openWorld.md +2 -1
  159. package/docs/api/particles.md +6 -3
  160. package/docs/api/photo.md +0 -2
  161. package/docs/api/pickups.md +21 -0
  162. package/docs/api/post.md +8 -5
  163. package/docs/api/quests.md +2 -3
  164. package/docs/api/rigid.md +16 -14
  165. package/docs/api/saves.md +6 -4
  166. package/docs/api/settings.md +2 -3
  167. package/docs/api/sky.md +18 -49
  168. package/docs/api/stream.md +1 -1
  169. package/docs/api/terrain.md +16 -7
  170. package/docs/api/terrainDraw.md +12 -0
  171. package/docs/api/timeline.md +3 -4
  172. package/docs/api/tools.md +32 -15
  173. package/docs/api/triggers.md +7 -10
  174. package/docs/api/vegetation.md +17 -9
  175. package/docs/api/vegetationDraw.md +10 -0
  176. package/docs/api/water.md +9 -21
  177. package/docs/api/weather.md +10 -15
  178. package/docs/api/weatherDraw.md +10 -0
  179. package/docs/api/world.md +3 -2
  180. package/docs/recipes/01-new-game.md +52 -42
  181. package/docs/recipes/02-npc.md +24 -7
  182. package/docs/recipes/03-items-pickups.md +57 -22
  183. package/docs/recipes/04-quests.md +12 -5
  184. package/docs/recipes/05-props-bake.md +174 -22
  185. package/docs/recipes/06-clock-events.md +100 -52
  186. package/docs/recipes/07-flow-scenes-pause.md +50 -10
  187. package/docs/recipes/08-weather-sky.md +134 -37
  188. package/docs/recipes/09-materials-lights-models.md +185 -0
  189. package/docs/recipes/10-blender-level.md +16 -4
  190. package/docs/recipes/11-vehicles.md +67 -10
  191. package/docs/recipes/13-animation.md +23 -9
  192. package/docs/recipes/14-custom-module.md +63 -29
  193. package/docs/recipes/15-perf.md +31 -10
  194. package/docs/recipes/16-dev-bridge.md +74 -40
  195. package/docs/recipes/18-world.md +26 -14
  196. package/docs/recipes/19-shooting-picking.md +12 -10
  197. package/docs/recipes/20-content-actions-save.md +60 -18
  198. package/docs/recipes/21-camera.md +55 -17
  199. package/docs/recipes/22-shop-gold.md +3 -3
  200. package/docs/recipes/23-ops.md +17 -11
  201. package/docs/recipes/26-ui-parts.md +86 -13
  202. package/docs/recipes/27-net.md +11 -5
  203. package/docs/recipes/28-terrain.md +36 -3
  204. package/docs/recipes/29-grid.md +46 -19
  205. package/docs/recipes/30-templates.md +72 -15
  206. package/docs/recipes/31-audio.md +20 -12
  207. package/docs/recipes/32-action-game.md +51 -4
  208. package/docs/recipes/34-environment-lighting.md +108 -21
  209. package/docs/recipes/35-picture-from-reference.md +147 -0
  210. package/docs/recipes/36-sky-ground-plants.md +158 -0
  211. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
  212. package/docs/recipes/38-environment-hooks.md +67 -0
  213. package/docs/recipes/40-scene.md +114 -32
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surfaces.md +206 -0
  216. package/docs/recipes/44-water-weather-hooks.md +191 -0
  217. package/docs/recipes/45-cascaded-shadows.md +130 -23
  218. package/docs/recipes/46-blender-art-route.md +17 -20
  219. package/docs/recipes/47-island-snow-backdrop.md +13 -15
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +4 -4
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-around-the-picture.md +181 -0
  224. package/docs/recipes/53-ground-up-close.md +12 -12
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +124 -0
  227. package/docs/recipes/56-webgpu-tsl.md +303 -0
  228. package/docs/recipes/57-control.md +104 -0
  229. package/docs/recipes/58-input.md +60 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +70 -0
  232. package/docs/recipes/61-deploy.md +27 -0
  233. package/docs/recipes/62-picture-code.md +244 -0
  234. package/docs/recipes/63-third-person-start.md +77 -0
  235. package/docs/recipes/64-particles.md +35 -0
  236. package/examples/action/.threedog/content-index.json +1 -0
  237. package/examples/action/GAMEMAP.md +20 -14
  238. package/examples/action/assets.js +8 -0
  239. package/examples/action/content/actions.js +1 -1
  240. package/examples/action/content/audio.js +5 -5
  241. package/examples/action/main.js +12 -15
  242. package/examples/action/models.js +23 -24
  243. package/examples/action/picture/index.js +13 -0
  244. package/examples/action/picture/lights.js +35 -0
  245. package/examples/action/picture/materials.js +8 -0
  246. package/examples/action/picture/palette.js +33 -0
  247. package/examples/plain-picture/.threedog/content-index.json +1 -0
  248. package/examples/plain-picture/FINDINGS.md +53 -0
  249. package/examples/plain-picture/GAMEMAP.md +90 -0
  250. package/examples/plain-picture/main.js +48 -0
  251. package/examples/plain-picture/picture/index.js +21 -0
  252. package/examples/plain-picture/picture/lights.js +54 -0
  253. package/examples/plain-picture/picture/materials.js +24 -0
  254. package/examples/plain-picture/picture/palette.js +16 -0
  255. package/examples/plain-picture/picture/sky.js +37 -0
  256. package/examples/pullable.json +133 -0
  257. package/examples/rc2d/.threedog/content-index.json +1 -0
  258. package/examples/rc2d/GAMEMAP.md +88 -0
  259. package/examples/rc2d/README.md +57 -0
  260. package/examples/rc2d/main.js +55 -0
  261. package/examples/rc2d/picture/index.js +18 -0
  262. package/examples/rc2d/picture/lights.js +11 -0
  263. package/examples/rc2d/picture/materials.js +18 -0
  264. package/examples/rc2d/picture/palette.js +15 -0
  265. package/examples/rc2d/picture/post.js +11 -0
  266. package/examples/rc2d/rc2d.js +187 -0
  267. package/examples/rc2d/shaders.js +144 -0
  268. package/examples/sheepisland/.threedog/content-index.json +1 -0
  269. package/examples/sheepisland/GAMEMAP.md +22 -17
  270. package/examples/sheepisland/assets.js +5 -0
  271. package/examples/sheepisland/content/templates.js +1 -1
  272. package/examples/sheepisland/content/vegetation.js +3 -1
  273. package/examples/sheepisland/main.js +29 -18
  274. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  275. package/examples/sheepisland/picture/index.js +20 -0
  276. package/examples/sheepisland/picture/lights.js +34 -0
  277. package/examples/sheepisland/picture/materials.js +61 -0
  278. package/examples/sheepisland/picture/palette.js +60 -0
  279. package/examples/sheepisland/picture/sky.js +20 -0
  280. package/examples/sheepisland/views.js +1 -1
  281. package/examples/styletest/.threedog/content-index.json +1 -0
  282. package/examples/styletest/GAMEMAP.md +25 -22
  283. package/examples/styletest/assets.js +6 -0
  284. package/examples/styletest/content/templates.js +1 -1
  285. package/examples/styletest/content/vegetation.js +1 -1
  286. package/examples/styletest/main.js +25 -34
  287. package/examples/styletest/models.js +30 -30
  288. package/examples/styletest/params.js +2 -5
  289. package/examples/styletest/picture/env.js +38 -0
  290. package/examples/styletest/picture/index.js +16 -0
  291. package/examples/styletest/picture/lights.js +9 -0
  292. package/examples/styletest/picture/materials.js +28 -0
  293. package/examples/styletest/picture/palette.js +22 -0
  294. package/examples/techniques/contact-shadows/README.md +91 -0
  295. package/examples/techniques/contact-shadows/contactShadows.js +67 -0
  296. package/examples/techniques/contact-shadows/main.js +55 -0
  297. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  298. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  299. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  300. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  301. package/examples/techniques/day-night-grade/README.md +83 -0
  302. package/examples/techniques/day-night-grade/main.js +41 -0
  303. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  304. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  305. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  306. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  307. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  308. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  309. package/examples/techniques/interior-light/README.md +106 -0
  310. package/examples/techniques/interior-light/interiorLight.js +47 -0
  311. package/examples/techniques/interior-light/main.js +87 -0
  312. package/examples/techniques/interior-light/picture/index.js +24 -0
  313. package/examples/techniques/interior-light/picture/lights.js +52 -0
  314. package/examples/techniques/interior-light/picture/materials.js +13 -0
  315. package/examples/techniques/interior-light/picture/palette.js +32 -0
  316. package/examples/techniques/interior-light/picture/sky.js +40 -0
  317. package/examples/techniques/modular-building/README.md +126 -0
  318. package/examples/techniques/modular-building/kit.js +426 -0
  319. package/examples/techniques/modular-building/main.js +39 -0
  320. package/examples/techniques/modular-building/picture/index.js +17 -0
  321. package/examples/techniques/modular-building/picture/lights.js +26 -0
  322. package/examples/techniques/modular-building/picture/materials.js +13 -0
  323. package/examples/techniques/modular-building/picture/palette.js +23 -0
  324. package/examples/techniques/night-lights/README.md +95 -0
  325. package/examples/techniques/night-lights/main.js +47 -0
  326. package/examples/techniques/night-lights/nightLights.js +95 -0
  327. package/examples/techniques/night-lights/picture/index.js +18 -0
  328. package/examples/techniques/night-lights/picture/lights.js +44 -0
  329. package/examples/techniques/night-lights/picture/materials.js +15 -0
  330. package/examples/techniques/night-lights/picture/palette.js +34 -0
  331. package/examples/techniques/night-lights/picture/post.js +9 -0
  332. package/examples/techniques/night-lights/picture/sky.js +36 -0
  333. package/examples/techniques/outlines-and-rim/README.md +59 -0
  334. package/examples/techniques/outlines-and-rim/main.js +61 -0
  335. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  336. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  337. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  338. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  339. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  340. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  341. package/examples/techniques/procedural-animation/README.md +79 -0
  342. package/examples/techniques/procedural-animation/creature.js +44 -0
  343. package/examples/techniques/procedural-animation/main.js +47 -0
  344. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  345. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  346. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  347. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  348. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  349. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  350. package/examples/techniques/procedural-surface/README.md +69 -0
  351. package/examples/techniques/procedural-surface/main.js +65 -0
  352. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  353. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  354. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  355. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  356. package/examples/techniques/procedural-surface/surface.js +120 -0
  357. package/examples/techniques/stylized-shading/README.md +74 -0
  358. package/examples/techniques/stylized-shading/main.js +62 -0
  359. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  360. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  361. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  362. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  363. package/examples/techniques/stylized-shading/shading.js +131 -0
  364. package/examples/techniques/sun-and-key-light/README.md +133 -0
  365. package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
  366. package/examples/techniques/sun-and-key-light/main.js +51 -0
  367. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  368. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  369. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  370. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  371. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  372. package/examples/techniques/three-looks/README.md +21 -0
  373. package/examples/techniques/three-looks/main.js +58 -0
  374. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  375. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  376. package/examples/techniques/three-looks/picture/comic.js +27 -0
  377. package/examples/techniques/three-looks/picture/index.js +14 -0
  378. package/examples/techniques/three-looks/picture/sun.js +23 -0
  379. package/examples/techniques/wet-road/README.md +102 -0
  380. package/examples/techniques/wet-road/main.js +48 -0
  381. package/examples/techniques/wet-road/picture/index.js +17 -0
  382. package/examples/techniques/wet-road/picture/lights.js +57 -0
  383. package/examples/techniques/wet-road/picture/materials.js +16 -0
  384. package/examples/techniques/wet-road/picture/palette.js +24 -0
  385. package/examples/techniques/wet-road/picture/sky.js +46 -0
  386. package/examples/techniques/wet-road/wetRoad.js +209 -0
  387. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  388. package/examples/webgpu-tsl/GAMEMAP.md +89 -0
  389. package/examples/webgpu-tsl/README.md +45 -0
  390. package/examples/webgpu-tsl/main.js +44 -0
  391. package/examples/webgpu-tsl/picture/index.js +18 -0
  392. package/examples/webgpu-tsl/picture/lights.js +25 -0
  393. package/examples/webgpu-tsl/picture/materials.js +36 -0
  394. package/examples/webgpu-tsl/picture/palette.js +23 -0
  395. package/examples/webgpu-tsl/picture/post.js +16 -0
  396. package/examples/webgpu-tsl/picture/sky.js +30 -0
  397. package/examples/world/.threedog/content-index.json +1 -0
  398. package/examples/world/GAMEMAP.md +31 -21
  399. package/examples/world/art/humanoid.js +38 -0
  400. package/examples/world/art/index.js +11 -0
  401. package/examples/world/art/models.js +57 -0
  402. package/examples/world/art/shapes.js +9 -0
  403. package/examples/world/assets.js +6 -0
  404. package/examples/world/content/audio.js +5 -5
  405. package/examples/world/content/items.js +1 -1
  406. package/examples/world/content/npcs.js +1 -1
  407. package/examples/world/content/props.js +1 -1
  408. package/examples/world/content/rules.js +1 -1
  409. package/examples/world/content/templates.js +1 -1
  410. package/examples/world/content/vegetation.js +1 -1
  411. package/examples/world/main.js +22 -18
  412. package/examples/world/models.js +17 -7
  413. package/examples/world/picture/index.js +20 -0
  414. package/examples/world/picture/lights.js +41 -0
  415. package/examples/world/picture/materials.js +34 -0
  416. package/examples/world/picture/palette.js +74 -0
  417. package/examples/world/picture/post.js +9 -0
  418. package/examples/world/picture/sky.js +39 -0
  419. package/index.d.ts +44 -54
  420. package/index.js +29 -25
  421. package/llms.txt +24 -15
  422. package/modules/ambience/Ambience.js +34 -23
  423. package/modules/calendar/Calendar.js +163 -0
  424. package/modules/calendar/contract.js +21 -0
  425. package/modules/calendar/index.js +82 -0
  426. package/modules/{sky → calendar}/schedule.js +17 -16
  427. package/modules/calendar/seasons.js +55 -0
  428. package/modules/camera/FirstPersonCamera.js +6 -15
  429. package/modules/camera/FixedCamera.js +33 -15
  430. package/modules/camera/FollowCamera.js +90 -16
  431. package/modules/camera/RtsCamera.js +18 -17
  432. package/modules/camera/common.js +73 -20
  433. package/modules/camera/contract.js +17 -0
  434. package/modules/camera/projection.js +11 -24
  435. package/modules/characters/Character.js +188 -48
  436. package/modules/characters/NPC.js +92 -41
  437. package/modules/characters/assetModel.js +8 -16
  438. package/modules/characters/behaviors.js +2 -1
  439. package/modules/characters/contract.js +13 -0
  440. package/modules/characters/footsteps.js +1 -1
  441. package/modules/characters/index.js +112 -49
  442. package/modules/characters/moveHelpers.js +4 -5
  443. package/modules/characters/movers/common.js +102 -19
  444. package/modules/characters/movers/manual.js +23 -0
  445. package/modules/characters/movers/rapier.js +19 -16
  446. package/modules/characters/movers/simple.js +14 -11
  447. package/modules/characters/movers/support.js +186 -0
  448. package/modules/characters/npcAvoid.js +47 -42
  449. package/modules/characters/npcSim.js +17 -9
  450. package/modules/characters/npcView.js +44 -16
  451. package/modules/characters/pathAsync.js +7 -3
  452. package/modules/characters/playerStrings.js +4 -3
  453. package/modules/characters/proceduralRig.js +19 -4
  454. package/modules/characters/useModel.js +2 -2
  455. package/modules/characters/vehicle.contract.js +21 -0
  456. package/modules/characters/walkTo.js +21 -7
  457. package/modules/collision/Collision.js +69 -27
  458. package/modules/collision/grid.js +8 -6
  459. package/modules/content/explain.js +2 -2
  460. package/modules/content/fields.js +102 -0
  461. package/modules/content/ids.js +8 -6
  462. package/modules/content/index.js +104 -27
  463. package/modules/content/loader.js +45 -33
  464. package/modules/content/models.js +58 -42
  465. package/modules/content/packs.js +6 -5
  466. package/modules/content/parts.js +41 -0
  467. package/modules/content/props.js +20 -11
  468. package/modules/content/rules.js +66 -0
  469. package/modules/content/stages.js +80 -0
  470. package/modules/content/templates.js +123 -30
  471. package/modules/debug/DebugPanel.js +24 -17
  472. package/modules/flow/contract.js +16 -0
  473. package/modules/flow/index.js +21 -15
  474. package/modules/gameplay/Container.js +41 -32
  475. package/modules/gameplay/Containers.js +30 -15
  476. package/modules/gameplay/Dialogue.js +113 -55
  477. package/modules/gameplay/Interactions.js +273 -72
  478. package/modules/gameplay/Inventory.js +72 -76
  479. package/modules/gameplay/Quests.js +75 -39
  480. package/modules/gameplay/boxOps.js +3 -3
  481. package/modules/gameplay/dialogue.contract.js +21 -0
  482. package/modules/gameplay/dialogueBox.js +4 -2
  483. package/modules/gameplay/dialogueBubbles.js +116 -0
  484. package/modules/gameplay/interactionPrompt.js +4 -1
  485. package/modules/gameplay/interactions.contract.js +16 -0
  486. package/modules/gameplay/inventory.contract.js +23 -0
  487. package/modules/gameplay/inventoryOps.js +19 -17
  488. package/modules/gameplay/pickups.js +306 -85
  489. package/modules/gameplay/questLog.js +6 -6
  490. package/modules/gameplay/quests.contract.js +17 -0
  491. package/modules/grid/Grid.js +92 -50
  492. package/modules/grid/Layer.js +27 -13
  493. package/modules/grid/index.js +96 -43
  494. package/modules/grid/ops.js +20 -18
  495. package/modules/grid/preview.js +37 -29
  496. package/modules/grid/strings.js +12 -0
  497. package/modules/grid/tiles.js +19 -22
  498. package/modules/hlod/index.js +52 -19
  499. package/modules/hud/index.js +48 -20
  500. package/modules/hud/parts.js +28 -13
  501. package/modules/level/heightfield.js +3 -1
  502. package/modules/level/index.js +49 -23
  503. package/modules/level/nodes.js +4 -3
  504. package/modules/lights/index.js +47 -19
  505. package/modules/music/Music.js +38 -21
  506. package/modules/music/rules.js +1 -1
  507. package/modules/nav/index.js +48 -42
  508. package/modules/net/Client.js +13 -6
  509. package/modules/net/Host.js +19 -5
  510. package/modules/net/Net.js +2 -1
  511. package/modules/net/index.js +13 -8
  512. package/modules/net/sync.js +9 -8
  513. package/modules/net/transports.js +77 -27
  514. package/modules/particles/Particles.js +58 -28
  515. package/modules/particles/contract.js +17 -0
  516. package/modules/particles/effect.js +54 -11
  517. package/modules/photo/Photo.js +56 -38
  518. package/modules/rigid/RigidBodies.js +194 -32
  519. package/modules/rigid/Vehicles.js +18 -15
  520. package/modules/rigid/sync.js +62 -17
  521. package/modules/settings/Settings.js +60 -55
  522. package/modules/settings/apply.js +38 -3
  523. package/modules/settings/sections.js +5 -3
  524. package/modules/settings/strings.js +3 -2
  525. package/modules/settings/view.js +5 -3
  526. package/modules/sky/Sky.js +132 -205
  527. package/modules/sky/clouds.js +37 -23
  528. package/modules/sky/dome.js +100 -0
  529. package/modules/sky/domeLayers.js +30 -15
  530. package/modules/sky/environment.js +45 -99
  531. package/modules/sky/fog.js +9 -139
  532. package/modules/sky/frame.js +60 -56
  533. package/modules/sky/season.js +21 -0
  534. package/modules/sky/shader.js +63 -35
  535. package/modules/sky/skyModule.js +52 -37
  536. package/modules/sky/tint.js +59 -0
  537. package/modules/terrain/ChunkManager.js +194 -110
  538. package/modules/terrain/chunkJob.js +1 -1
  539. package/modules/terrain/chunkQueries.js +6 -4
  540. package/modules/terrain/draw.js +154 -0
  541. package/modules/terrain/index.js +87 -54
  542. package/modules/terrain/terrainDefaults.js +2 -2
  543. package/modules/terrain/terrainEdit.js +18 -20
  544. package/modules/terrain/terrainGen.js +6 -4
  545. package/modules/terrain/terrainIsland.js +5 -4
  546. package/modules/terrain/terrainShape.js +12 -12
  547. package/modules/terrain/terrainShapeMain.js +8 -7
  548. package/modules/terrain/terrainTexture.js +21 -19
  549. package/modules/timeline/Timeline.js +95 -43
  550. package/modules/timeline/Tween.js +18 -10
  551. package/modules/timeline/letterbox.js +2 -2
  552. package/modules/timeline/shots.js +5 -1
  553. package/modules/triggers/index.js +111 -76
  554. package/modules/vegetation/Vegetation.js +229 -112
  555. package/modules/vegetation/densityMap.js +62 -0
  556. package/modules/vegetation/draw.js +191 -0
  557. package/modules/vegetation/groundChunks.js +52 -58
  558. package/modules/vegetation/index.js +32 -11
  559. package/modules/vegetation/modelGeometry.js +3 -2
  560. package/modules/vegetation/nearFade.js +8 -2
  561. package/modules/water/Water.js +157 -72
  562. package/modules/water/surface.js +86 -47
  563. package/modules/weather/Weather.js +96 -103
  564. package/modules/weather/particles.js +37 -14
  565. package/modules/weather/shaders.js +1 -1
  566. package/modules/weather/strings.js +2 -2
  567. package/modules/weather/weatherDraw.js +141 -0
  568. package/modules/world/World.js +26 -9
  569. package/modules/world/explain.js +1 -1
  570. package/modules/world/index.js +18 -4
  571. package/modules/world/persist.js +62 -2
  572. package/modules/world/pos.js +3 -2
  573. package/modules/world/records.js +8 -6
  574. package/modules/world/sim.js +60 -20
  575. package/modules/world/simFar.js +4 -3
  576. package/modules/world/state.js +3 -2
  577. package/modules/world/thingSource.js +1 -1
  578. package/modules/world/views.js +8 -6
  579. package/package.json +8 -3
  580. package/presets.js +43 -29
  581. package/render/PostFX.js +318 -135
  582. package/render/backend.js +486 -0
  583. package/render/cascades.js +195 -0
  584. package/render/cascades.tsl.js +96 -0
  585. package/render/daylight.js +39 -0
  586. package/render/detail.js +122 -41
  587. package/render/effects.js +155 -48
  588. package/render/engineUniforms.js +10 -1
  589. package/render/fuse.js +5 -4
  590. package/render/fx/cel.tsl.js +42 -0
  591. package/render/fx/cloudShadow.tsl.js +16 -0
  592. package/render/fx/detail.tsl.js +66 -0
  593. package/render/fx/index.js +28 -0
  594. package/render/fx/lighting.tsl.js +28 -0
  595. package/render/fx/nodeErrors.tsl.js +68 -0
  596. package/render/fx/noise.tsl.js +12 -0
  597. package/render/fx/objectOrigin.tsl.js +42 -0
  598. package/render/fx/particles.tsl.js +139 -0
  599. package/render/fx/patchNodes.tsl.js +403 -0
  600. package/render/fx/postWebGPU.tsl.js +181 -0
  601. package/render/fx/season.tsl.js +13 -0
  602. package/render/fx/sky.tsl.js +187 -0
  603. package/render/fx/uniforms.tsl.js +67 -0
  604. package/render/fx/water.tsl.js +53 -0
  605. package/render/fx/wind.tsl.js +22 -0
  606. package/render/fxNumbers.js +36 -0
  607. package/render/hotGlsl.js +24 -0
  608. package/render/layers.js +14 -0
  609. package/render/lighting.js +71 -18
  610. package/render/lightmap.js +142 -0
  611. package/render/lights.js +47 -6
  612. package/render/materials.js +55 -152
  613. package/render/modeling.js +73 -0
  614. package/render/neutral.js +23 -0
  615. package/render/occlusion.js +184 -0
  616. package/render/ownFrame.js +76 -0
  617. package/render/patches.js +317 -35
  618. package/render/postWebGL.js +205 -0
  619. package/render/probes.js +288 -0
  620. package/render/shaderErrors.js +154 -0
  621. package/render/slots.js +165 -0
  622. package/render/terms.js +163 -0
  623. package/render/uniformDecl.js +4 -3
  624. package/types/common.d.ts +2 -2
  625. package/types/core.d.ts +757 -346
  626. package/types/gameplay.d.ts +539 -330
  627. package/types/generated/core/Audio.d.ts +26 -42
  628. package/types/generated/core/Batching.d.ts +6 -2
  629. package/types/generated/core/Budget.d.ts +2 -8
  630. package/types/generated/core/DebugOverrides.d.ts +58 -9
  631. package/types/generated/core/I18n.d.ts +2 -2
  632. package/types/generated/core/Input.d.ts +110 -32
  633. package/types/generated/core/Ops.d.ts +31 -0
  634. package/types/generated/core/Random.d.ts +2 -2
  635. package/types/generated/core/Saves.d.ts +10 -2
  636. package/types/generated/core/Stream.d.ts +1 -1
  637. package/types/generated/core/Threads.d.ts +4 -1
  638. package/types/generated/core/Views.d.ts +0 -1
  639. package/types/generated/core/audioVoice.d.ts +17 -9
  640. package/types/generated/core/control.d.ts +55 -0
  641. package/types/generated/core/page.d.ts +9 -2
  642. package/types/generated/core/session.d.ts +2 -1
  643. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  644. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  645. package/types/generated/modules/calendar/index.d.ts +10 -0
  646. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  647. package/types/generated/modules/grid/Grid.d.ts +61 -25
  648. package/types/generated/modules/grid/Layer.d.ts +13 -5
  649. package/types/generated/modules/grid/index.d.ts +56 -20
  650. package/types/generated/modules/music/Music.d.ts +5 -3
  651. package/types/generated/modules/net/index.d.ts +3 -3
  652. package/types/generated/modules/net/transports.d.ts +12 -3
  653. package/types/generated/modules/particles/Particles.d.ts +13 -6
  654. package/types/generated/modules/sky/Sky.d.ts +85 -110
  655. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  656. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  657. package/types/generated/modules/water/Water.d.ts +50 -3
  658. package/types/generated/modules/weather/Weather.d.ts +44 -15
  659. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  660. package/types/generated/modules/world/World.d.ts +20 -5
  661. package/types/generated/render/PostFX.d.ts +109 -29
  662. package/types/generated/render/lighting.d.ts +29 -0
  663. package/types/generated/render/materials.d.ts +31 -50
  664. package/types/generated/render/modeling.d.ts +30 -0
  665. package/types/generated/render/occlusion.d.ts +13 -0
  666. package/types/generated/render/patches.d.ts +16 -2
  667. package/types/generated/ui/UI.d.ts +6 -3
  668. package/types/nav.d.ts +6 -0
  669. package/types/physics.d.ts +140 -45
  670. package/types/tsl.d.ts +94 -0
  671. package/types/world.d.ts +489 -122
  672. package/ui/Focus.js +35 -14
  673. package/ui/LoadingScreen.js +3 -3
  674. package/ui/Parts.js +35 -15
  675. package/ui/UI.js +27 -17
  676. package/ui/cursor.js +115 -0
  677. package/ui/defaults.js +15 -11
  678. package/ui/theme.js +36 -27
  679. package/ui/touchPart.js +2 -2
  680. package/core/claims.js +0 -51
  681. package/core/look/coreParts.js +0 -112
  682. package/core/look/layers.js +0 -136
  683. package/core/look/part.js +0 -173
  684. package/core/look/report.js +0 -79
  685. package/core/look/write.js +0 -86
  686. package/core/renamed.js +0 -22
  687. package/core/styleParts.js +0 -98
  688. package/docs/api/entities.md +0 -61
  689. package/docs/api/style.md +0 -134
  690. package/docs/recipes/09-style-pack.md +0 -169
  691. package/docs/recipes/35-style-from-reference.md +0 -84
  692. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  693. package/docs/recipes/38-environment-look-hooks.md +0 -88
  694. package/docs/recipes/41-thing-registry.md +0 -93
  695. package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
  696. package/docs/recipes/44-water-weather-look-hooks.md +0 -135
  697. package/docs/recipes/48-make-material.md +0 -70
  698. package/docs/recipes/52-look.md +0 -146
  699. package/examples/action/look.js +0 -5
  700. package/examples/sheepisland/style/index.js +0 -79
  701. package/examples/styletest/look.js +0 -11
  702. package/examples/styletest/overrides.js +0 -33
  703. package/examples/styletest/panel.js +0 -135
  704. package/modules/entities/Entities.js +0 -243
  705. package/modules/entities/build.js +0 -25
  706. package/modules/entities/index.js +0 -4
  707. package/modules/sky/calendar.js +0 -80
  708. package/modules/sky/cascades.js +0 -125
  709. package/modules/sky/layers.js +0 -69
  710. package/modules/sky/look.js +0 -51
  711. package/modules/sky/lookFog.js +0 -80
  712. package/modules/sky/lookShadow.js +0 -50
  713. package/modules/sky/lookSky.js +0 -108
  714. package/modules/sky/shadow.js +0 -74
  715. package/modules/terrain/chunkLevels.js +0 -40
  716. package/modules/terrain/lookGround.js +0 -61
  717. package/modules/terrain/mountTerrain.js +0 -32
  718. package/modules/vegetation/lookWind.js +0 -37
  719. package/modules/water/look.js +0 -80
  720. package/modules/weather/look.js +0 -75
  721. package/modules/world/cells.js +0 -42
  722. package/render/lookSurface.js +0 -161
  723. package/render/postLook.js +0 -86
  724. package/render/surface.js +0 -69
  725. package/types/style.d.ts +0 -643
@@ -1,169 +0,0 @@
1
- # Changing the art / writing a style pack
2
-
3
- **The engine ships no art.** No default style, character model, terrain look or terrain generator: with no style pack and no model everything is a
4
- plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
5
- one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
6
-
7
- A style pack is a plain object passed in as `createEngine({ style })`. It holds **looks only**: colors, the default pickup shape,
8
- materials and shaders, sky and lighting, post effects, UI look. Not part of it: model / texture / sound files and procedural models content names (an
9
- **asset pack**, `engine.assets.manifest`, recipe 05 "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20;
10
- `sky({ hoursPerDay })`). Which key is read by whom is in the "style pack keys" table of `../CODEMAP.md`; the field list is in `../api/style.md`. Every
11
- entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style pack at all). Write it as a plain object literal, no `@type` or `as const`: fields with a fixed set of words (`shading`, `mode`, `type` …) accept any string in the types, and a wrong word is reported by `threedog style check` with the fix.
12
-
13
- ## 0. Using a style pack
14
- A style pack is a plain object (or a package that exports one): yours in `style/index.js`, a folder you copy, or a published package. Any art direction fits:
15
- realistic, toon, pixel, painterly, flat, noir. The engine ships none; `threedog new-style` starts an empty one (section 1).
16
- ```js
17
- import { createEngine, presets, openWorld } from 'threedog';
18
- import yourPack from './style/index.js'; // or: import yourPack from 'a-published-pack'
19
- import { terrainPreset, terrainStrings } from '@threedog/terrain-noise'; // the world shape is not a look: its own package
20
- const engine = createEngine({ canvas, style: yourPack, strings: terrainStrings }); // terrainStrings: names of the preset's ground types
21
- engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() })); // noise terrain (hills, rivers, biomes) that your pack colors, see recipes/28
22
- ```
23
- A pack may also export an asset pack (procedural models: `engine.assets.manifest(assets)`). Post effects such as `bloom` / `ao` / `outline` come from
24
- `@threedog/post-effects` (style packs never import each other; R34 checks). The terrain generator `terrainPreset` / `riverAt` / `BIOMES` /
25
- `terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style pack keeps only the colors of its
26
- ground types (`terrain.colors`, `biomeColors`).
27
-
28
- ## 0b. Composing a style from parts
29
- `style` may be a list of parts, deep-merged left to right into `engine.style`, so one pack's materials, another pack's sky and the game's own colors
30
- mix without copying whole packs:
31
- ```js
32
- import basePack from './style/index.js';
33
- const dusk = { sky: { sunSize: 600, keyframes: myDuskKeyframes } }; // only these two sky fields change
34
- const engine = createEngine({ canvas, style: [basePack, dusk, { ui: { accent: '#7fd3ff' }, post: null }] });
35
- ```
36
- Rules (`core/styleParts.js`): plain `{ }` objects merge key by key at every depth; everything else replaces whole (arrays such as `sky.keyframes` and
37
- `post`, functions, three.js objects); a key set to `null` removes it; `undefined` is ignored; nested lists flatten, so a pack can itself be a list of
38
- parts; parts are never mutated. One object (not a list) is used as it is.
39
-
40
- **Post effects by name.** `post` is a list, so `{ post: [myGrain] }` replaces everything before it. To add to or trim the list use the two helpers
41
- (exported by `threedog`); they are parts too:
42
- ```js
43
- import { createEngine, postAdd, postRemove } from 'threedog';
44
- import basePack from './style/index.js';
45
- import { bloom } from '@threedog/post-effects';
46
- createEngine({ canvas, style: [basePack, postAdd(myGrain, bloom({ strength: 0.6 })), postRemove('ao')] });
47
- ```
48
- `postAdd(...effects)` appends; an effect whose `name` is already in the list (`'bloom'`, `'ao'`, `'outline'`) replaces that one in place.
49
- `postRemove(...names)` drops effects by name. `{ post: null }` still clears the list; `{ post: [...] }` still replaces it whole.
50
-
51
- **Retinting the procedural models.** `style.palette` holds the colors the trees, rocks, grass and flowers are built from (the keys are the pack's own, e.g. `bark`, `leaf`, `rock`,
52
- `grassTip`...; see `basePack.palette`). One part changes them all:
53
- `style: [basePack, { palette: { leaf: 0xd98a3a } }]` (autumn); keys left out keep the pack's colors. A generator of your own written
54
- with `function` (not an arrow) reads `this.palette`; the palette is part of the model cache key, so a changed palette rebuilds. `.glb` files and
55
- models baked earlier keep their colors.
56
-
57
- ## 0c. What a style may not hold
58
- Swapping the style must never change the map or the rules, only how they look. So these are **not** style fields, and a dev run throws an error
59
- naming where each goes:
60
- - water level, whether there is a sea, the water mesh size: `style.water.level / sea / size` -> `engine.use(water({ level, sea, size }))`
61
- - terrain shape and size (seed, chunk size, resolution, water level, height functions): `style.terrain.config.*` -> `terrain({ ... })`. The looks
62
- in `terrain.config` are `shading` (`'smooth'` | `'texture'` | `'flat'`), `colorResolution`, `normals` and `normalFn` (recipe 37); at run time
63
- `engine.look.ground.set({ shading, colors, variation, detail })` (recipe 52)
64
- Quality settings are not world state and may stay in a style (shadow `mapSize` and `low` overrides, water `segments`); players can override them in
65
- settings. Packs under `packages/styles/**` are also checked by `threedog check` (R34).
66
-
67
- ## 1. Creating a new style pack
68
- Run `threedog new-style` (or copy any pack folder into your game or a package of your own), edit the values in `index.js`, then switch to it in the game:
69
- ```js
70
- import toon from './style/index.js';
71
- const engine = createEngine({ canvas, style: toon });
72
- ```
73
- **A material role is a free label inside the style, not a fixed list.** `makeMaterial('anything', { color })` is always legal: a role the style does not
74
- name falls back to `materials.default`, and a new role (`'lantern'`, `'roof'`) becomes real the moment the style adds `materials.lantern`. The engine
75
- warns only when a name looks like a typo of a known role (`'buidling'`).
76
-
77
- Keys you will change most often:
78
- | Key | What it controls |
79
- |---|---|
80
- | `materials` | The material per role. Three forms: a spec `{ default: { type: 'toon', steps: 3 }, water: { type: 'phong', shininess: 90 } }` (lambert / phong / standard / physical / toon / basic; a wrong type throws), any three.js material instance `water: new THREE.MeshMatcapMaterial({ matcap })` (cloned per use), or a function `prop: (params, role) => new THREE.ShaderMaterial({...})`. Style packs may create materials directly; games still go through `makeMaterial` |
81
- | `antialias` | `false` for sharp pixel edges; omitted = on for desktop, off for phones (players can switch it in settings) |
82
- | `post` | List of post effects (e.g. `[outline(), ao(), bloom()]`; `outline({ enabled: true })` draws edge lines); slots, the effects package, `fuse`, outline modes: [recipe 52](52-look.md#post-effect-chain) |
83
- | `sky` `weather` `water` `terrain` `seasons` `clouds` | Sky keyframes (sun color and intensity over the day, fog color, shadows), rain and snow, water, terrain colors (`terrain.colors` palette, `terrain.biomeColors` ground type -> palette names, `terrain.steep` slope colors; a type with no color is gray; `terrain.config`: `shading` `'smooth'` (engine default) | `'texture'` (per-chunk color map) | `'flat'` (facets), `colorResolution`, `normals`, `normalFn`, recipe 37; `terrain.detail` a detail layer, recipe 53; `terrain.material` swaps the whole ground material, chunks have `uv` = world xz / chunk size; `water.material: (engine, { uniforms, waves, normalMap }) => Material` swaps the whole water surface, e.g. `applyEffects(new THREE.MeshToonMaterial({ color }), { clouds: false, patches: [waves] })` keeps the built-in waves), seasonal tints |
84
- | `character` | `animation.fade`: skeletal animation transition seconds. Bodies are assets, not style: `createPlayer({ model })` with a registered model, a GLB asset name or `{ rig }`; part colors are material roles or `{ colors }` per character (recipe 13). Without a model a gray capsule |
85
- | `pickup` `particles` | Items on the ground (`pickup.model(item, { color, size })` returns an Object3D or geometry; without it a plain gray box), particle presets (dust smoke leaves splash sparks...) |
86
- | `triggers` `grid` | Tool colors, not art: trigger zone wireframe (`debugColor`), grid placement preview (`ok` / `bad`). The engine has neutral defaults (gray; light = can place, dark = cannot); a pack may recolor them |
87
- | `ui` | UI colors, `font` (a CSS font-family list), `fonts` (font asset names to load at start, the files in an asset pack: recipes/05 §3b), extra `css`, `templates` that replace a whole UI piece |
88
-
89
- ## 1b. Lights and stalls
90
- Every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style pack they are a neutral placeholder (white
91
- hemisphere + neutral directional light, no shadows); the look (sun color and intensity curves, sky colors, fog, shadow softness, exposure, tone
92
- mapping) comes from the style pack's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights. At run time:
93
- `engine.look.lights.set(...)` (recipe 52); to light the world yourself: recipe 38.
94
-
95
- three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
96
- loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
97
- a frame can freeze for hundreds of milliseconds. Keep the number of lights fixed: create them up front and fade with `intensity` (0 = off, no
98
- recompile). In dev the console warns (code `light-recompile`) when programs were compiled in a frame where the lights changed.
99
-
100
- For many torches, street lamps, campfires, muzzle flashes or neon signs use the light pool: a fixed number of real lights, created once at install,
101
- moves to the sources that matter most (near the camera, bright, high `priority`) and fades with intensity, so the light setup never changes. Install
102
- it before `engine.start()` so the startup compile covers its lights:
103
- ```js
104
- import { lightPool } from 'threedog';
105
- engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
106
- for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
107
- color: 0xffa040, intensity: 4, distance: 8,
108
- flicker: (time, i) => 0.85 + 0.15 * Math.sin(time * 13 + i),
109
- glow: t.getObjectByName('halo'), // stand-in while it has no real light: its material's opacity / emissiveIntensity fades to 0 as the light fades in
110
- });
111
- const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, distance: 6 });
112
- flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
113
- ```
114
- `engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
115
- camera. Options and handle: `../api/lightPool.md`.
116
-
117
- ## 2. Using your own models instead of procedural ones
118
- Models are assets, not style keys: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
119
- name to swap one:
120
- ```js
121
- engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
122
- engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
123
- ```
124
- Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
125
- mesh, e.g. bark trunk + alpha-cut leaf cards:
126
- `engine.vegetation.add('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
127
- the import workflow see `10-blender-level.md`.
128
- `mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
129
- A generator in `models` may also return an Object3D with its own materials; those are used as they are.
130
-
131
- ## 2b. Wind, cloud shadows and season tint on your own materials
132
- The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
133
- ```js
134
- import { applyEffects } from 'threedog';
135
- const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
136
- engine.vegetation.add('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
137
- ```
138
- The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, and stacks with the built-in ones and with
139
- the material's own `onBeforeCompile`:
140
- `applyEffects(mat, { patches:
141
- [{ name: 'snap', cacheKey: 64, uniforms, glsl: { vertex: { pars: '...', project_vertex: '...code after #include <project_vertex>' } } }] })`.
142
- A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#include <threedog_wind_vertex>`, `<threedog_clouds_pars_fragment>` etc. (see
143
- `render/effects.js`) with `engine.uniforms` as its uniforms.
144
- `material.clone()` does not carry patches (three's `Material.copy` skips `onBeforeCompile`): a pack's Material instance in `materials` is fine
145
- (`makeMaterial` keeps its patches); when you clone one yourself, apply the effects to the clone again.
146
- What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`) and the chunk names: recipe 43, exit 2. Textures by asset name, `detail`,
147
- shadow tint, rim light and toon ramps are material spec keys: recipe 48 (keys), recipe 43 (what they do).
148
-
149
- ## 3. When the engine gets a new "look parameter"
150
- Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to a style pack
151
- (its `index.js`) at the same time** (with a one-line comment saying what it means),
152
- and the new field gets a doc comment in `types/style.d.ts` (`docs/api/` is generated from there). Materials always go through
153
- `makeMaterial('role', { color })`, leaving the surface feel to `style.materials[role]`. Whose style: `engine.makeMaterial('role', { color })` uses that
154
- engine's pack; the free `makeMaterial()` uses the first engine created (fine for one engine, a dev warning when two packs run). Engine code and style packs always
155
- go through the engine (`pickup.model(item, { color, size }, engine)`, `water.material(engine, ...)`), so two engines never share materials.
156
- Look parameters only: a field that changes the world (a level, a size, a seed) goes to the module's options, not the style (section 0c).
157
-
158
- ## 4. Verify
159
- - `npm run check`: the hard-rule check reports "material created directly" (in engine modules, games and examples; style packs are allowed) and
160
- "non-gray fallback color"; the type check catches misspelled keys in the style pack.
161
- - `npm run map`: the "style pack keys" table in CODEMAP is updated.
162
- - Take screenshots only when the look changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
163
- (images go to .threedog/shots/).
164
- - It must still run without a style pack: start once with `createEngine({ canvas })` and no `style` (gray placeholders, one console note per missing piece).
165
-
166
- ## 5. Sounds and music (the game's, not the style pack's)
167
- Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`; a
168
- style pack carries none. The engine plays nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and
169
- ducking: `recipes/31-audio.md`.
@@ -1,84 +0,0 @@
1
- # Making a new look from a reference picture
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.
6
-
7
- ## The loop (every round, in this order)
8
- 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).
11
- 3. **Shoot small and compare to the previous shot**: `threedog shot styletest --view overview --size 480x270 --keep --compare <previous.png>`. It prints the
12
- 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.
14
- 5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
15
- 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.
18
- 7. **Every few rounds show the user the shot and the numbers.**
19
-
20
- 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
- (soft edges, texture, low contrast), low-poly (few flat colors, faceted light), realistic (exposure, tone mapping, lighting, material roughness). None is the default.
22
-
23
- ## 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
25
- (`materials`: matte `lambert`, `toon` bands, `standard`...), lights and sky (`sky.keyframes`, sun, clouds, shadows, `exposure`, `toneMapping`), post
26
- effects (`post`: outline, bloom, grain, vignette, color grading from `@threedog/post-effects`), UI colors and fonts, particle looks, and the colors
27
- of the procedural models (`palette` read by `models.js`).
28
-
29
- Cannot change by a style: the **silhouette of models**. A tree stays the shape its model has; a new shape means a new asset pack (code-built models
30
- in `models.js`, or `.glb` files, recipes `05-props-bake.md` and `10-blender-level.md`). And the **world rules**: water level, terrain shape, what
31
- exists where, timing and gameplay are not in a style (a dev run throws, `style check` and R34 report it). If the reference shows a different
32
- world (a canyon instead of hills), say so instead of faking it with colors.
33
-
34
- ## Steps
35
- 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
- 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,
38
- 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`.
40
- 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
- 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).
46
- 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
- `toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones; a reference usually has 5 to 8 that
48
- matter), `materials` (`lambert` matte, `toon` banded, `phong` shiny, `standard` PBR, `basic` unlit), `post`, then `ui`. The first frame should already be close:
49
- 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:
51
- unknown fields (with "did you mean"), world-state fields, palette keys a model reads but the style does not define, color formats (`'ff8800'`
52
- without `#`, a float, a string `'0xff8800'`), post-effect conflicts (same name twice, two `scene` effects, a depth reader after a buffer-swapping
53
- effect, `dof` ordered after `outline`), misspelled material roles and types, and asset names the pack does not register. `--json` gives the same list for
54
- 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
55
- the patterns R34 can see (`npm run check` runs R34).
56
- 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
57
- views (below), not free `--pos` shots. `threedog style compare art/reference/ref.png .threedog/shots/styletest.png [--region x,y,w,h]` prints brightness,
58
- 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
59
- deliberately no "similarity %": the numbers turn "looks dirty / fragmented / too dark" into something you can change and re-measure. Dirty = lower
60
- 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
- the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
62
- 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
-
64
- ## 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.
67
- - Never put gameplay or world values in the pack to match a picture; `style check` reports them as errors.
68
- - Fonts and textures are asset-pack entries; the style names them (`ui.fonts: ['pixel']`, `terrain.detail.texture`), it does not carry files.
69
- - Keep `npm run check` at 0 errors; a new pack adds no warnings.
70
-
71
- ## The style test page
72
- `/styletest.html` (`examples/styletest`) is the one fixed scene a style is judged by: a character, trees, rock, grass, flowers, water, terrain, glass,
73
- 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.
74
- - `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
75
- (`?view=room&time=dusk&weather=rain`; also `style=none` for the engine's gray placeholders, `env=1` for environment lighting from the sky).
76
- - Views: `overview` (everything: overall brightness, ground color, shadow darkness), `character` (close-up: character colors, outline, shadow on
77
- the ground), `water` (water color, shore, fog at distance), `room` (the lamp and window light against the dark corners: ambient level, `ao`, bloom),
78
- `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
- and shadow edges that flicker or crawl), `ui` (HUD, dialogue line, bag window: the `ui` colors).
80
- - 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).
82
- Live sliders change exposure, sky time, environment lighting, water color, post effects and UI colors at once; palette, terrain and wave values
83
- are marked "needs rebuild" and only apply after "apply and rebuild". "export overrides" prints an object literal to paste into
84
- `style: [yourPack, { ... }]`; the original pack is never written, so the paste is the one place the change becomes real.
@@ -1,118 +0,0 @@
1
- # Sky, ground and plant looks: what a style can change
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
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. Each table lists the engine default; a style that sets nothing here gets those defaults. Style packs hold looks only
6
- (rule R34): none of these settings move a hill, a river or a species list.
7
-
8
- ## Sky clouds: `style.sky.clouds`
9
- | Key | Meaning | Default |
10
- |---|---|---|
11
- | `color`, `shade`, `coverage`, `scale`, `speed` | lit color, shaded color, cover (multiplies the weather's cloud amount), size, drift speed | |
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
- | `horizon` | added to `dir.y` before projecting; smaller = clouds shrink and crowd more towards the horizon | plane 0.08, cumulus 0.5 |
14
- | `fade` | `[from, to]` in `dir.y`: invisible below `from`, full above `to` | plane `[0, 0.18]`, cumulus `[0, 0.12]` |
15
- | `opacity`, `softness` | cloud alpha; width of the cloud edge | 0.9 / 0.3 (cumulus 0.95 / 0.35) |
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
- | `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
-
20
- 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
- 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
22
- `kind: 'cumulus'`, or raise `horizon` (0.3-0.6) and lower `scale`. Cost: both are one 2D pass over the dome (no ray marching); cumulus is about
23
- 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
- (`style.clouds.shadow`, a separate setting) follow the same weather cover, so more clouds still means more shadow.
25
-
26
- ```js
27
- sky: { clouds: { kind: 'cumulus', coverage: 1, scale: 0.45, color: 0xfff4e4, shade: 0x8a9cb8, speed: [0.003, 0.001] } }
28
- ```
29
-
30
- ### 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)`:
32
- ```glsl
33
- vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)
34
- // dir: unit view direction, dir.y > 0. sunDir: towards the sun (the moon is opposite). night: 0 day .. 1 night.
35
- // lit / shade: clouds.color / clouds.shade. cover: weather cloud amount * clouds.coverage.
36
- // return: rgb = final cloud color (dim it at night yourself), a = opacity (apply your own horizon fade).
37
- ```
38
- 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.uEdge.value = 0.1`. A bad `kind`, a `glsl` without the function, or an unsupported uniform value throws with the fix.
41
- Flat painted cloud blobs with a hard edge, multiplied by a texture:
42
- ```js
43
- clouds: { color: 0xfff1dc, shade: 0x9aa8c4, uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
44
- glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
45
- vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
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 edge
48
- float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
49
- vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
50
- return vec4(c, a * smoothstep(0.0, 0.1, d.y));
51
- }` }
52
- ```
53
-
54
- ## Ground color: `style.terrain.variation`
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
58
- terrain: { colors: { ... }, biomeColors: { ... },
59
- variation: {
60
- blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
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 (example values): a second, large layer of color blocks
63
- } }
64
- ```
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.
69
-
70
- ### Your own ground material
71
- `style.terrain.material` (a Material or `(engine) => Material`) replaces the ground material. Chunk geometry has `uv = world xz / chunk size`, continuous
72
- across chunk borders (checked by `tests/specs/appearance.mjs`), so a repeating texture is seamless whatever chunk it lands in; cloud shadows and
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
74
- from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
75
- ```js
76
- material: engine => applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
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;',
79
- color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + 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;` } } }] })
82
- ```
83
- A procedural noise texture is a `THREE.DataTexture` filled in a loop (`wrapS = wrapT = THREE.RepeatWrapping`, `colorSpace = THREE.SRGBColorSpace`,
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.
87
-
88
- ## Plants and wind
89
- Audit of what the vegetation code fixes, split into mechanism (stays) and look (made a setting):
90
-
91
- | Where | What | Kind |
92
- |---|---|---|
93
- | `Vegetation.add` | per species: `wind` amplitude, `rule`, `lodRing`, `maxRing`, `nearOnly`, `castShadow`, `shadowRing`, `material`, `effects` | already options (game content) |
94
- | `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 |
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: **`style.wind.glsl`** replaces it |
96
- | wind speed | `uWindFreq` | already `style.wind.frequency` |
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 |
98
- | defaults | `castShadow` = not `nearOnly`, `shadowRing` 1, `lodRing` 1 | per-species options, set them in the species |
99
-
100
- ```js
101
- wind: { frequency: 1, uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine
102
- glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
103
- float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
104
- transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
105
- }` }
106
- ```
107
- `threedogWind` receives the vertex (`transformed`, object space), `ip` (world position of this plant's origin, so each plant has its own phase) and
108
- `position`; `uTime`, `uWind` (weather), `uWindFreq` and `THREEDOG_WIND_AMP` (the species' amplitude) are in scope. It applies to every material made by
109
- `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:
110
- `applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
111
-
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
- about 120 ms with no wind, default wind and a custom sway alike, so the sway function is not where grass time goes (vertex count and fill are).
114
- Reduce grass cost with `rule.perChunk`, `maxRing` and `nearOnly`, not the wind.
115
-
116
- ## What is still fixed
117
- Season tint is multiplicative. Cloud *shadows* on the ground (`threedog_clouds_pars_fragment`) keep their two-noise shape; only strength, scale and
118
- speed are style settings. Grass has no billboard or blade-shape setting: give `vegetation.add` your own `geometry` or `model`.
@@ -1,88 +0,0 @@
1
- # Owning lights, fog and exposure yourself
2
-
3
- The normal way to change lights, fog, exposure and the sky is `engine.look.<part>.set` / `patch` ([recipe 52](52-look.md)): the sky keeps
4
- driving them over the day, and your values sit on top. This page is the next step, for when that is not enough: your own fog math, exposure over
5
- the day, extra sky layers, and taking a light or the fog away from the sky entirely. Sky basics are in `08-weather-sky.md`, clouds and ground color in
6
- `36-sky-ground-plant-looks.md`, environment lighting in `34-environment-lighting.md`. Each section starts with the `look` call and ends with the exit.
7
-
8
- ## Lights: override, take over, or switch off
9
- The engine has one directional light (`engine.lights.sun`, also `engine.sky.sun`; moonlight at night, the shadows live on it) and one hemisphere
10
- ambient (`engine.lights.hemi` = `engine.sky.hemi`). The sky module rewrites their color and intensity every frame from `style.sky.keyframes`,
11
- so editing the three.js objects directly is overwritten (a dev warning says so). **Without the sky module** both lights are a bright placeholder
12
- (hemi 1.2, white sun 2 at (40, 80, 30), no shadows).
13
-
14
- ```js
15
- engine.look.lights.set({ sun: { color: '#ffd0a0', intensity: 1.4 }, hemi: { intensity: 0.5 } }, { owner: 'dusk' }); // 1. override, any hour
16
- engine.sky.modify('cave', { sun: 0.3, ambient: 0.4 }); // or a multiplier on top of the day cycle (recipe 52)
17
-
18
- engine.use(sky({ sun: 'manual' })); // 2. take over: the sky still aims the sun along the time of day and moves the shadow box
19
- engine.sky.sun.color.set(0xffd0a0); engine.sky.sun.intensity = 1.4; // yours now, never overwritten
20
-
21
- engine.use(sky({ sun: false, hemisphere: false })); // 3. switch off (a dungeon): both hidden, never touched; the dome still shows sun and moon
22
- const torch = new THREE.PointLight(0xffa040, 6, 12); engine.add(torch); // add your own lights before engine.start()
23
- ```
24
-
25
- - `sky({ sun, hemisphere })`: `true` (default) the sky drives everything; `'manual'` color and intensity are the game's, the sun keeps its
26
- direction and shadow box; `false` `visible = false`, no shadows, never touched (lightning no longer flashes the ambient either).
27
- - `createEngine({ lights: false })` goes one step further: the default sun and hemisphere are never put in the scene, `engine.lights.sun` / `hemi`
28
- stay as detached objects so nothing reads `undefined`. Use it for a scene lit entirely by your own lights.
29
- - Shadows: only the engine sun's shadow is managed (`engine.look.shadow.set`). Your own `castShadow` lights work as in three.js, each costing its
30
- own shadow pass; `engine.setShadows(false)` turns theirs off too and restores them after.
31
- - Add or remove lights before `engine.start()`: a light count that changes mid-play recompiles every material (one long frame). Many lamps or
32
- torches: `lightPool({ point: 6 })` keeps a fixed number of real lights and moves them to the nearest sources (recipe 09, "Lights and stalls").
33
-
34
- ## Fog: kind, color, density, your own math, or your own fog
35
- ```js
36
- engine.look.fog.set({ far: 220, color: '#9bb' }); // live: color, density, near, far, enabled, linear <-> exp2
37
- engine.look.fog.set({ kind: 'height', height: 2, falloff: 0.08, density: 0.03 }); // valley mist; before the first frame (below)
38
- engine.look.fog.patch('fog', `vec4 threedogFog(vec3 c, float depth, vec3 p){
39
- float f = 1.0 - exp(-fogDensity * depth);
40
- return vec4(mix(c, vec3(1.0, 0.85, 0.7), f * 0.3), f); }`); // warm far haze
41
- engine.look.fog.replace('manual'); // the exit: the sky stops writing scene.fog (or pass a THREE.Fog)
42
- ```
43
- The same keys are the style layer `style.sky.fog` (or `sky({ fog })`), e.g. `fog: { kind: 'exp', color: 0xb8c4d0 }` or
44
- `fog: { color: sky => sky.isDay ? 0xc8d0d8 : 0x10141c }` (a function, evaluated each frame).
45
-
46
- - `kind`: `'linear'` (default, near = 0.3 x far) | `'exp'` | `'exp2'` | `'height'`. `color`: `'horizon'` (default; the dome's lower band fades to
47
- the fog color, so the horizon line never shows) | color | `(sky) => color`. `density` per meter (default derived from the fog distance);
48
- weather fog divides it, `engine.setFogFar` still moves the derived one.
49
- - The `fog` hook replaces the fog math in every material, built-in or yours: `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returns
50
- (fog rgb, amount 0..1). In scope: `fogColor`, `cameraPosition`, `fogNear` / `fogFar` (linear) or `fogDensity` (other kinds),
51
- `THREEDOG_FOG_HEIGHT`, `THREEDOG_FOG_FALLOFF`.
52
- - Limits: `'exp'`, `'height'` and the hook replace three's `fog_*` shader chunks once (three caches programs by material settings, not by
53
- source), so they only work before the first frame (style, `sky({ fog })`, or right after `createEngine`); later they throw. Color and density
54
- stay live. No custom uniforms (three copies fog uniforms into each material when it compiles); write constants. Materials with `fog: false`
55
- (the dome) are not fogged. A ShaderMaterial of your own gets the same fog when it sets `fog: true` and includes the fog chunks.
56
- - Your own fog: `look.fog.replace('manual')` or `sky({ fog: 'manual' })` creates `scene.fog` once and never writes it (set its color / near /
57
- far, or assign your own object); `sky({ fog: false })` sets `scene.fog = null` (leave fog out of your materials with `fog: false` and fog in a
58
- post pass).
59
- - Two engines on one page share three's fog chunks: the same custom `kind` / `height` / `falloff` / hook is fine (reference counted); a different
60
- custom setting throws. Plain `linear` / `exp2` do not touch the chunks.
61
-
62
- ## Exposure and tone mapping over time
63
- ```js
64
- exposure: [[0, 1.6], [0.3, 1], [0.75, 1.1]] // style: per time of day (0-1), wraps across midnight
65
- exposure: sky => sky.isDay ? 1 : 1.5 // or a function, evaluated by the sky module every frame
66
- engine.look.tone.set({ exposure: 1.3 }); // at run time: number, keyframes or function (replaces the style's)
67
- engine.look.tone.set({ mapping: 'agx' }); // 'aces' | 'agx' | 'neutral' | 'none'; materials recompile on their next draw
68
- ```
69
- A plain number is set once (no per-frame work). Keyframes and functions need the sky module (it knows the time of day).
70
-
71
- ## Extra sky layers: rainbow, aurora, color bands
72
- `style.sky.layers` (or `sky({ layers })`; at run time `engine.look.sky.patch('layer:aurora', { glsl, blend })`, recipe 52), drawn on the dome
73
- after clouds and stars; none by default:
74
-
75
- ```js
76
- layers: [{ blend: 'add', uniforms: { uAurora: [0.2, 1, 0.6] }, glsl: `vec4 threedogSkyLayer(vec3 d, float time, vec3 sunDir, float night){
77
- float band = smoothstep(0.25, 0.45, d.y) * (1.0 - smoothstep(0.55, 0.8, d.y));
78
- float n = threedogNoise(vec2(d.x * 4.0 + time * 0.05, d.z * 2.0));
79
- return vec4(uAurora, band * n * night); }` }]
80
- ```
81
- Signature `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)` returns (rgb, amount). `blend: 'mix'` (default) or `'add'`;
82
- `order` sorts layers (smaller first); `uniforms` like `clouds.uniforms`, live in `engine.sky.dome.material.uniforms.uAurora.value`. Each layer's function is
83
- renamed (`threedogSkyLayer0`, `1`, ...), so layers from different style parts never clash. Whole replacement: `style.sky.skybox` (a panorama) or
84
- hide `engine.sky.dome` and add your own background.
85
-
86
- ## Water and weather particles
87
- Water depth color, crest foam, wave / surface GLSL, reflections; rain and snow shape, size, density and shaders, the lightning look, and
88
- particles for the game's own weather (`engine.look.weather.replace`): `44-water-weather-look-hooks.md`.
@@ -1,93 +0,0 @@
1
- # Things: what is in the scene, who manages it, what a save keeps (engine.thing)
2
-
3
- Every root you pass to `engine.add` is registered: an id, where it was added (`main.js:50`, dev builds only), who manages it and how much a save
4
- keeps. World records (template instances, props, pickups, NPCs, level nodes) share the same id space and the same query, so one question works for a
5
- plain three.js mesh and for a template instance alike. `engine.scene.add` adds without registering: the plain three.js way in, still legal.
6
-
7
- ## 1. Give it an id
8
- ```js
9
- const windmill = buildWindmill(); // any Object3D
10
- engine.add(windmill, { id: 'windmill' }); // at setup: thing.set / thing.remove changes to it are saved
11
- engine.add(spark); // effects need no id: obj#7, this session only
12
- engine.thing('windmill');
13
- // { id: 'windmill', kind: 'Group', owner: 'game', at: 'main.js:50', phase: 'setup', saved: 'code',
14
- // keeps: ['position, rotation, scale, visibility and removal made with thing.set / thing.remove (scene save part)'],
15
- // loses: ['geometry and material changes', 'children added later', 'userData', ...], edit: 'added by code at main.js:50 (id ...)' }
16
- engine.thing('windmill').object; // the live Object3D (not enumerable, so the result stays JSON-able)
17
- engine.thing(engine.pick(0, 0).object).id; // any child resolves to its registered root; hit.thing says the same
18
- ```
19
- - The id is `{ id }`, else a session id `obj#n` (session tier: never saved). `obj.name` is not an id (GLB roots are all called `Scene`): it only helps `engine.thing(name)` find the object. An id is a non-empty string without `#`,
20
- unique across `engine.add` objects and world records: a clash throws (`thing-id`) from either side (`engine.add` or `world.add`) and says which one holds it.
21
- - With several objects in one call (`engine.add(a, b)`) pass no id; add the one that needs an id on its own.
22
- - `engine.thing(id | name | obj)` throws with the closest id when nothing matches. `engine.inspect(id)` takes the same ids.
23
- - `describe().scene` gives counts only: `{ game, code, session, world, engine, unsaved, conflicts, orphans }`. Objects of engine modules (particles,
24
- physics bodies, nav helpers, hlod, grid tiles, the level root, streamed objects) are counted under `engine` and never listed as the game's.
25
-
26
- ## 2. Four save tiers
27
- Judged in this order (`thing.saved`):
28
-
29
- | Tier | When | A save keeps | A save loses |
30
- |---|---|---|---|
31
- | `record` | a world record's model (templates, props, pickups, NPCs, level nodes) | the record's fields and position (world part); the model is rebuilt from its template / present | the model object itself; change it through the record |
32
- | `code` | added by game code with a stable id at setup (before `engine.ready`, or in a `session:start` listener) | position, rotation, scale, visibility and removal made with `thing.set` / `thing.remove` (`scene` part) | geometry and material changes, children added later, `userData`, closure state, writes like `mesh.position.x = 3` |
33
- | `session` | no stable id, or added during play | nothing: it exists only in this session | everything; it does not come back after a load |
34
- | `engine` | managed by an engine module | its module's business | direct changes (the module rewrites them) |
35
-
36
- Only transform, visibility and removal are saved for `code` objects; colours and materials belong to Style and are not saved. To keep something made
37
- during play, make it a template and create it inside an op with `engine.spawn(name, at)`: a record is saved whole.
38
-
39
- ## 3. Change it: thing.set / thing.remove (ops, undoable)
40
- ```js
41
- const args = { id: 'windmill', position: [5, 0, 2], rotation: 1.2 }; // rotation: a number is yaw, or [x, y, z]; scale: a number or [x, y, z]
42
- const r = engine.ops.run('thing.set', args);
43
- engine.ops.undo('thing.set', args, r.value); // back where it was
44
- engine.ops.run('thing.remove', { id: 'windmill' }); // detached and kept: undo puts it back
45
- ```
46
- - A world record id turns into `world.set` / `world.move` (`rot` / `scale` are template instance fields) and `world.remove`; the model follows the
47
- record. `visible` is refused for a record (`recordVisible`): hide its model with `present({ show })` and a field.
48
- - A `code` object gets its new values written and recorded as an override; a `session` object only changes in this session.
49
- - Objects of engine modules are refused (`engineOwned`).
50
-
51
- ## 4. Saves: the `scene` part (version 1)
52
- `{ set: { windmill: { position: [5, 0, 2] } }, removed: ['old-fence'] }`, only for `code` objects. A load first undoes the current overrides (a new
53
- game applies an empty part, so everything goes back to what the code built), then applies the save. An id the save names but no object has yet waits:
54
- the override applies the moment `engine.add(obj, { id })` runs. One that never comes is an orphan: kept in the save, listed in
55
- `describe().scene.orphans` and warned once (`thing-orphan`).
56
-
57
- ## 5. Dev checks
58
- - `engine.add(obj, { save: true })` for an object that cannot be saved (no id, or during play) warns at once (`thing-unsaved`); objects added inside an
59
- op are listed by `saves.save()` and in `describe().scene.unsaved`.
60
- - `engine.add` of a world model throws (`thing-owned`): world adds, places and tears down its models.
61
- - Code that moves a `positionFrom: 'record'` world model outside its present `update` is warned once and listed in `describe().scene.conflicts`.
62
- - Rule R33 (`npm run check`) flags the static half: startup calls that create things saved whole, and code writing `world.view()` models.
63
- - Cost: a release build pays two table writes per `engine.add` (about 2 µs per add in `tests/specs/things.mjs`); dev builds also take a short stack
64
- for `at`, at most 2000 per session (`describe().scene.atCapped` after that).
65
-
66
- ## 6. One id, everything: explain() and the three kinds of change
67
- ```js
68
- engine.thing('chest-home').explain(); // CLI: npx threedog thing chest-home (MCP: thing); the same JSON
69
- // { id, kind, owner, definition: { at: 'content/props.js:14', template, templateAt, level?, node?, spawned? }, model, materials: [{ role, name, from, keys }],
70
- // state, rules: { blocksMovement, pickable, interact, height }, ops: [{ op, desc, args }], saved: { tier, keeps, loses }, change: {…}, overrides? }
71
- ```
72
- `ops` lists the ops whose definition names this id, kind or template in the optional `targets` field (`engine.ops.define('chest.toggle', { targets: 'chest', … })`;
73
- `'*'` = any thing, which `thing.set` / `thing.remove` use). `definition.at` is null in release builds and for code run without a file (page `eval`).
74
- `thing.explain()` (type `ThingExplanation`) is not `engine.explain({ op | quest | … })`: that one takes a question and answers `{ ok, text }` about why an op or quest cannot run now (recipe 23); this one takes no question and returns the facts about one id. `rules.blocksMovement` is the template's / prop's `collide` shape; the engine does not model blocking sight. Pick the kind of change first:
75
-
76
- | Kind | How | Lasts |
77
- |---|---|---|
78
- | Game state (a chest opens, a door moves) | an op: `ops.run('chest.toggle', { id })`, `thing.set`, `thing.remove` (section 3) | by the thing's save tier |
79
- | Permanent edit (another model, place, material role) | content entry: `npx threedog content set <id> <field> <json>` (below); template or `engine.add` line: edit the file:line `explain().change.permanent` prints; then reload | forever |
80
- | Diagnostic override ("show me without it") | `engine.debug.override(owner, id, { visible: false, material: 'flat' \| 'wire', apply })` | until `handle.remove()` / `engine.debug.clear(owner)`; never saved |
81
-
82
- ```js
83
- const h = engine.debug.override('ai-session', 'windmill', { material: 'flat' }); // unlit base colour: is the colour wrong, or the light?
84
- engine.debug.override('ai-session', 'fence', { visible: false });
85
- engine.describe().scene.overrides; // [{ owner, target, material: 'flat' }, …]: the screen differs from the real state while this is non-empty
86
- h.remove(); engine.debug.clear('ai-session'); // clear removes every override of that owner (and its debug.view) and nothing else
87
- ```
88
- `apply(obj)` may return its undo function: any other look (a view mode) uses the same owner mechanism. Overrides do not touch game state, ops or saves.
89
-
90
- `npx threedog content set cabin x=12 z=3 place=home --in props` sets several fields in one call (one write, one check, all or nothing; a bare word is a string). `npx threedog content set cabin x 12 --in props` writes a permanent change into the content entry (`-w game` or `--dir folder` picks the game; `--dry` only shows it). It edits just that
91
- value in place (comments and spacing stay), adds the field when missing, runs the content check (reverting if it fails) and tells you to reload. Fields are the content file's names
92
- (`x`, `z`, `y`, `rot`, `scale`, `template`, `place`, `model`), not the record's `position`; the value is JSON (`'"home"'` for a string). It refuses, and says why, for an entry built
93
- by code (loop, spread, computed value) or an id matching several entries (`--in props`). A placed entry wins over a template or npc of the same name.