threedog 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (596) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +83 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +190 -57
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +43 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +128 -0
  58. package/core/gridLoad.js +20 -0
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +101 -37
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +65 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +89 -97
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +224 -149
  126. package/docs/COMMANDS.md +57 -34
  127. package/docs/CONVENTIONS.md +92 -30
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +12 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +41 -25
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +65 -62
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +31 -29
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +30 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +12 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +71 -59
  180. package/docs/recipes/02-npc.md +46 -29
  181. package/docs/recipes/03-items-pickups.md +38 -24
  182. package/docs/recipes/04-quests.md +34 -27
  183. package/docs/recipes/05-props-bake.md +154 -18
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +41 -10
  186. package/docs/recipes/08-weather-sky.md +146 -37
  187. package/docs/recipes/09-style.md +218 -0
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +34 -10
  191. package/docs/recipes/14-custom-module.md +65 -34
  192. package/docs/recipes/15-perf.md +35 -6
  193. package/docs/recipes/16-dev-bridge.md +65 -41
  194. package/docs/recipes/18-world.md +21 -8
  195. package/docs/recipes/19-shooting-picking.md +12 -11
  196. package/docs/recipes/20-content-actions-save.md +63 -25
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +18 -18
  199. package/docs/recipes/23-ops.md +17 -11
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +12 -6
  202. package/docs/recipes/28-terrain.md +35 -2
  203. package/docs/recipes/29-grid.md +71 -33
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +27 -4
  208. package/docs/recipes/35-style-from-reference.md +115 -51
  209. package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
  210. package/docs/recipes/37-terrain-look-hooks.md +37 -15
  211. package/docs/recipes/38-environment-look-hooks.md +64 -48
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +3 -3
  215. package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
  216. package/docs/recipes/44-water-weather-look-hooks.md +30 -21
  217. package/docs/recipes/45-cascaded-shadows.md +17 -8
  218. package/docs/recipes/46-blender-art-route.md +4 -4
  219. package/docs/recipes/47-island-snow-backdrop.md +11 -10
  220. package/docs/recipes/48-make-material.md +11 -6
  221. package/docs/recipes/49-game-module-contract.md +46 -33
  222. package/docs/recipes/50-own-renderer.md +2 -2
  223. package/docs/recipes/51-capability-catalog.md +4 -4
  224. package/docs/recipes/52-look.md +228 -54
  225. package/docs/recipes/53-ground-up-close.md +58 -0
  226. package/docs/recipes/54-three-idioms.md +88 -0
  227. package/docs/recipes/55-mods-time-wrap.md +112 -0
  228. package/docs/recipes/56-webgpu-tsl.md +260 -0
  229. package/docs/recipes/57-control.md +65 -0
  230. package/docs/recipes/58-input.md +57 -0
  231. package/docs/recipes/59-depth-post-effects.md +83 -0
  232. package/docs/recipes/60-judge-the-picture.md +55 -0
  233. package/examples/action/.threedog/content-index.json +1 -0
  234. package/examples/action/GAMEMAP.md +17 -13
  235. package/examples/action/assets.js +8 -0
  236. package/examples/action/content/actions.js +1 -1
  237. package/examples/action/content/audio.js +5 -5
  238. package/examples/action/look.js +1 -1
  239. package/examples/action/main.js +10 -13
  240. package/examples/action/models.js +24 -23
  241. package/examples/pullable.json +111 -0
  242. package/examples/rc2d/.threedog/content-index.json +1 -0
  243. package/examples/rc2d/GAMEMAP.md +83 -0
  244. package/examples/rc2d/README.md +52 -0
  245. package/examples/rc2d/main.js +63 -0
  246. package/examples/rc2d/rc2d.js +197 -0
  247. package/examples/rc2d/shaders.js +144 -0
  248. package/examples/sheepisland/.threedog/content-index.json +1 -0
  249. package/examples/sheepisland/GAMEMAP.md +13 -11
  250. package/examples/sheepisland/assets.js +5 -0
  251. package/examples/sheepisland/main.js +17 -12
  252. package/examples/sheepisland/style/index.js +6 -6
  253. package/examples/styletest/.threedog/content-index.json +1 -0
  254. package/examples/styletest/GAMEMAP.md +15 -16
  255. package/examples/styletest/assets.js +6 -0
  256. package/examples/styletest/content/npcs.js +1 -1
  257. package/examples/styletest/content/templates.js +1 -1
  258. package/examples/styletest/content/vegetation.js +1 -1
  259. package/examples/styletest/look.js +1 -1
  260. package/examples/styletest/main.js +18 -17
  261. package/examples/styletest/models.js +1 -1
  262. package/examples/styletest/params.js +3 -3
  263. package/examples/techniques/contact-shadows/README.md +92 -0
  264. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  265. package/examples/techniques/contact-shadows/main.js +53 -0
  266. package/examples/techniques/day-night-grade/README.md +86 -0
  267. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  268. package/examples/techniques/day-night-grade/main.js +51 -0
  269. package/examples/techniques/interior-light/README.md +103 -0
  270. package/examples/techniques/interior-light/interiorLight.js +45 -0
  271. package/examples/techniques/interior-light/main.js +124 -0
  272. package/examples/techniques/modular-building/README.md +125 -0
  273. package/examples/techniques/modular-building/kit.js +426 -0
  274. package/examples/techniques/modular-building/main.js +47 -0
  275. package/examples/techniques/night-lights/README.md +94 -0
  276. package/examples/techniques/night-lights/main.js +70 -0
  277. package/examples/techniques/night-lights/nightLights.js +91 -0
  278. package/examples/techniques/outlines-and-rim/README.md +59 -0
  279. package/examples/techniques/outlines-and-rim/main.js +84 -0
  280. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  281. package/examples/techniques/procedural-animation/README.md +77 -0
  282. package/examples/techniques/procedural-animation/creature.js +44 -0
  283. package/examples/techniques/procedural-animation/main.js +45 -0
  284. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  285. package/examples/techniques/procedural-surface/README.md +67 -0
  286. package/examples/techniques/procedural-surface/main.js +103 -0
  287. package/examples/techniques/procedural-surface/surface.js +120 -0
  288. package/examples/techniques/stylized-shading/README.md +75 -0
  289. package/examples/techniques/stylized-shading/main.js +93 -0
  290. package/examples/techniques/stylized-shading/shading.js +131 -0
  291. package/examples/techniques/sun-and-key-light/README.md +135 -0
  292. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  293. package/examples/techniques/sun-and-key-light/main.js +95 -0
  294. package/examples/techniques/wet-road/README.md +99 -0
  295. package/examples/techniques/wet-road/main.js +68 -0
  296. package/examples/techniques/wet-road/wetRoad.js +209 -0
  297. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  298. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  299. package/examples/webgpu-tsl/README.md +42 -0
  300. package/examples/webgpu-tsl/main.js +21 -0
  301. package/examples/webgpu-tsl/tslScene.js +75 -0
  302. package/examples/world/.threedog/content-index.json +1 -0
  303. package/examples/world/GAMEMAP.md +22 -15
  304. package/examples/world/art/humanoid.js +42 -0
  305. package/examples/world/art/index.js +11 -0
  306. package/examples/world/art/models.js +58 -0
  307. package/examples/world/art/shapes.js +9 -0
  308. package/examples/world/assets.js +6 -0
  309. package/examples/world/content/audio.js +5 -5
  310. package/examples/world/content/npcs.js +2 -2
  311. package/examples/world/content/props.js +1 -1
  312. package/examples/world/content/rules.js +1 -1
  313. package/examples/world/content/templates.js +1 -1
  314. package/examples/world/content/vegetation.js +1 -1
  315. package/examples/world/main.js +17 -13
  316. package/examples/world/style/index.js +61 -0
  317. package/examples/world/style/plugins/10-bloom.js +5 -0
  318. package/index.d.ts +50 -45
  319. package/index.js +27 -22
  320. package/llms.txt +20 -12
  321. package/modules/ambience/Ambience.js +34 -23
  322. package/modules/calendar/Calendar.js +163 -0
  323. package/modules/calendar/contract.js +21 -0
  324. package/modules/calendar/index.js +81 -0
  325. package/modules/{sky → calendar}/schedule.js +17 -16
  326. package/modules/calendar/seasons.js +55 -0
  327. package/modules/camera/FirstPersonCamera.js +6 -15
  328. package/modules/camera/FixedCamera.js +33 -15
  329. package/modules/camera/FollowCamera.js +90 -16
  330. package/modules/camera/RtsCamera.js +18 -17
  331. package/modules/camera/common.js +70 -19
  332. package/modules/camera/contract.js +17 -0
  333. package/modules/camera/projection.js +11 -24
  334. package/modules/characters/Character.js +196 -59
  335. package/modules/characters/NPC.js +87 -36
  336. package/modules/characters/assetModel.js +27 -8
  337. package/modules/characters/behaviors.js +2 -1
  338. package/modules/characters/contract.js +13 -0
  339. package/modules/characters/footsteps.js +1 -1
  340. package/modules/characters/index.js +87 -49
  341. package/modules/characters/moveHelpers.js +4 -5
  342. package/modules/characters/movers/common.js +97 -19
  343. package/modules/characters/movers/manual.js +20 -0
  344. package/modules/characters/movers/rapier.js +19 -16
  345. package/modules/characters/movers/simple.js +14 -11
  346. package/modules/characters/movers/support.js +172 -0
  347. package/modules/characters/npcAvoid.js +47 -42
  348. package/modules/characters/npcSim.js +12 -8
  349. package/modules/characters/npcView.js +44 -16
  350. package/modules/characters/pathAsync.js +7 -3
  351. package/modules/characters/playerStrings.js +4 -3
  352. package/modules/characters/proceduralRig.js +46 -10
  353. package/modules/characters/useModel.js +1 -1
  354. package/modules/characters/vehicle.contract.js +21 -0
  355. package/modules/characters/walkTo.js +21 -7
  356. package/modules/collision/Collision.js +65 -25
  357. package/modules/collision/grid.js +8 -6
  358. package/modules/content/explain.js +2 -2
  359. package/modules/content/fields.js +102 -0
  360. package/modules/content/ids.js +8 -6
  361. package/modules/content/index.js +97 -28
  362. package/modules/content/loader.js +45 -33
  363. package/modules/content/models.js +11 -40
  364. package/modules/content/packs.js +6 -5
  365. package/modules/content/parts.js +41 -0
  366. package/modules/content/props.js +16 -9
  367. package/modules/content/rules.js +58 -0
  368. package/modules/content/stages.js +80 -0
  369. package/modules/content/templates.js +121 -30
  370. package/modules/debug/DebugPanel.js +24 -17
  371. package/modules/flow/contract.js +16 -0
  372. package/modules/flow/index.js +21 -15
  373. package/modules/gameplay/Container.js +41 -32
  374. package/modules/gameplay/Containers.js +30 -15
  375. package/modules/gameplay/Dialogue.js +113 -55
  376. package/modules/gameplay/Interactions.js +193 -67
  377. package/modules/gameplay/Inventory.js +69 -73
  378. package/modules/gameplay/Quests.js +75 -39
  379. package/modules/gameplay/boxOps.js +3 -3
  380. package/modules/gameplay/dialogue.contract.js +21 -0
  381. package/modules/gameplay/dialogueBox.js +4 -2
  382. package/modules/gameplay/dialogueBubbles.js +116 -0
  383. package/modules/gameplay/interactionPrompt.js +4 -1
  384. package/modules/gameplay/interactions.contract.js +16 -0
  385. package/modules/gameplay/inventory.contract.js +23 -0
  386. package/modules/gameplay/inventoryOps.js +18 -16
  387. package/modules/gameplay/pickups.js +268 -85
  388. package/modules/gameplay/questLog.js +4 -4
  389. package/modules/gameplay/quests.contract.js +17 -0
  390. package/modules/grid/Grid.js +92 -50
  391. package/modules/grid/Layer.js +14 -13
  392. package/modules/grid/index.js +60 -36
  393. package/modules/grid/ops.js +20 -18
  394. package/modules/grid/preview.js +15 -16
  395. package/modules/grid/strings.js +12 -0
  396. package/modules/grid/tiles.js +6 -5
  397. package/modules/hlod/index.js +51 -19
  398. package/modules/hud/index.js +35 -20
  399. package/modules/hud/parts.js +20 -7
  400. package/modules/level/heightfield.js +3 -1
  401. package/modules/level/index.js +45 -20
  402. package/modules/level/nodes.js +4 -3
  403. package/modules/lights/index.js +42 -18
  404. package/modules/music/Music.js +38 -21
  405. package/modules/music/rules.js +1 -1
  406. package/modules/nav/index.js +48 -42
  407. package/modules/net/Client.js +13 -6
  408. package/modules/net/Host.js +19 -5
  409. package/modules/net/Net.js +2 -1
  410. package/modules/net/index.js +13 -8
  411. package/modules/net/sync.js +9 -8
  412. package/modules/net/transports.js +77 -27
  413. package/modules/particles/Particles.js +23 -14
  414. package/modules/particles/contract.js +17 -0
  415. package/modules/particles/effect.js +39 -11
  416. package/modules/photo/Photo.js +53 -36
  417. package/modules/rigid/RigidBodies.js +194 -32
  418. package/modules/rigid/Vehicles.js +18 -15
  419. package/modules/rigid/sync.js +62 -17
  420. package/modules/settings/Settings.js +57 -52
  421. package/modules/settings/apply.js +38 -3
  422. package/modules/settings/sections.js +5 -3
  423. package/modules/settings/strings.js +3 -2
  424. package/modules/settings/view.js +5 -3
  425. package/modules/sky/Sky.js +88 -176
  426. package/modules/sky/cascades.js +86 -25
  427. package/modules/sky/cascades.tsl.js +82 -0
  428. package/modules/sky/clouds.js +34 -19
  429. package/modules/sky/domeLayers.js +30 -15
  430. package/modules/sky/environment.js +83 -13
  431. package/modules/sky/fog.js +140 -95
  432. package/modules/sky/frame.js +112 -44
  433. package/modules/sky/look.js +22 -19
  434. package/modules/sky/lookFog.js +48 -52
  435. package/modules/sky/lookShadow.js +53 -41
  436. package/modules/sky/lookSky.js +82 -21
  437. package/modules/sky/season.js +21 -0
  438. package/modules/sky/shader.js +41 -19
  439. package/modules/sky/shadow.js +44 -20
  440. package/modules/sky/skyModule.js +45 -33
  441. package/modules/sky/tint.js +61 -0
  442. package/modules/terrain/ChunkManager.js +175 -108
  443. package/modules/terrain/chunkJob.js +1 -1
  444. package/modules/terrain/chunkQueries.js +6 -4
  445. package/modules/terrain/index.js +105 -50
  446. package/modules/terrain/look.js +83 -0
  447. package/modules/terrain/lookGround.js +21 -16
  448. package/modules/terrain/terrainDefaults.js +1 -1
  449. package/modules/terrain/terrainEdit.js +18 -20
  450. package/modules/terrain/terrainGen.js +5 -3
  451. package/modules/terrain/terrainIsland.js +5 -4
  452. package/modules/terrain/terrainShape.js +12 -12
  453. package/modules/terrain/terrainShapeMain.js +8 -7
  454. package/modules/terrain/terrainTexture.js +21 -19
  455. package/modules/timeline/Timeline.js +95 -43
  456. package/modules/timeline/Tween.js +18 -10
  457. package/modules/timeline/letterbox.js +2 -2
  458. package/modules/timeline/shots.js +5 -1
  459. package/modules/triggers/index.js +107 -76
  460. package/modules/vegetation/Vegetation.js +190 -102
  461. package/modules/vegetation/densityMap.js +62 -0
  462. package/modules/vegetation/groundChunks.js +52 -58
  463. package/modules/vegetation/index.js +31 -10
  464. package/modules/vegetation/look.js +119 -0
  465. package/modules/vegetation/lookWind.js +71 -10
  466. package/modules/vegetation/modelGeometry.js +3 -2
  467. package/modules/vegetation/nearFade.js +45 -0
  468. package/modules/water/Water.js +65 -27
  469. package/modules/water/look.js +29 -18
  470. package/modules/water/surface.js +64 -25
  471. package/modules/water/surfaceDefaults.js +3 -0
  472. package/modules/weather/Weather.js +62 -104
  473. package/modules/weather/look.js +1 -2
  474. package/modules/weather/particles.js +24 -9
  475. package/modules/weather/strings.js +2 -2
  476. package/modules/weather/weatherLook.js +135 -0
  477. package/modules/world/World.js +24 -7
  478. package/modules/world/explain.js +1 -1
  479. package/modules/world/index.js +18 -4
  480. package/modules/world/persist.js +62 -2
  481. package/modules/world/pos.js +3 -2
  482. package/modules/world/records.js +8 -6
  483. package/modules/world/sim.js +60 -20
  484. package/modules/world/simFar.js +4 -3
  485. package/modules/world/state.js +3 -2
  486. package/modules/world/thingSource.js +1 -1
  487. package/modules/world/views.js +7 -5
  488. package/package.json +8 -3
  489. package/presets.js +41 -27
  490. package/render/PostFX.js +145 -120
  491. package/render/backend.js +440 -0
  492. package/render/detail.js +150 -45
  493. package/render/effects.js +130 -38
  494. package/render/engineUniforms.js +10 -1
  495. package/render/fuse.js +5 -4
  496. package/render/fx/cloudShadow.tsl.js +16 -0
  497. package/render/fx/detail.tsl.js +66 -0
  498. package/render/fx/index.js +26 -0
  499. package/render/fx/lighting.tsl.js +28 -0
  500. package/render/fx/nodeErrors.tsl.js +68 -0
  501. package/render/fx/noise.tsl.js +12 -0
  502. package/render/fx/objectOrigin.tsl.js +42 -0
  503. package/render/fx/particles.tsl.js +139 -0
  504. package/render/fx/patchNodes.tsl.js +403 -0
  505. package/render/fx/postWebGPU.tsl.js +158 -0
  506. package/render/fx/season.tsl.js +13 -0
  507. package/render/fx/sky.tsl.js +260 -0
  508. package/render/fx/uniforms.tsl.js +67 -0
  509. package/render/fx/water.tsl.js +53 -0
  510. package/render/fx/wind.tsl.js +22 -0
  511. package/render/fxNumbers.js +36 -0
  512. package/render/hotGlsl.js +24 -0
  513. package/render/lighting.js +66 -14
  514. package/render/lights.js +223 -4
  515. package/render/lookGlow.js +139 -0
  516. package/render/lookSurface.js +99 -36
  517. package/render/materials.js +71 -52
  518. package/render/modeling.js +73 -0
  519. package/render/ownFrame.js +76 -0
  520. package/render/patches.js +311 -34
  521. package/render/postLook.js +124 -46
  522. package/render/postWebGL.js +197 -0
  523. package/render/probes.js +231 -0
  524. package/render/shaderErrors.js +154 -0
  525. package/render/slots.js +165 -0
  526. package/render/surface.js +53 -17
  527. package/render/terms.js +211 -0
  528. package/render/uniformDecl.js +3 -2
  529. package/types/common.d.ts +2 -2
  530. package/types/core.d.ts +620 -244
  531. package/types/gameplay.d.ts +494 -318
  532. package/types/generated/core/Audio.d.ts +26 -42
  533. package/types/generated/core/Batching.d.ts +6 -2
  534. package/types/generated/core/Budget.d.ts +2 -8
  535. package/types/generated/core/DebugOverrides.d.ts +44 -3
  536. package/types/generated/core/I18n.d.ts +2 -2
  537. package/types/generated/core/Input.d.ts +102 -31
  538. package/types/generated/core/Ops.d.ts +31 -0
  539. package/types/generated/core/Random.d.ts +2 -2
  540. package/types/generated/core/Saves.d.ts +10 -2
  541. package/types/generated/core/Stream.d.ts +1 -1
  542. package/types/generated/core/Threads.d.ts +4 -1
  543. package/types/generated/core/Views.d.ts +0 -1
  544. package/types/generated/core/audioVoice.d.ts +17 -9
  545. package/types/generated/core/control.d.ts +55 -0
  546. package/types/generated/core/session.d.ts +2 -1
  547. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  548. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  549. package/types/generated/modules/calendar/index.d.ts +10 -0
  550. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  551. package/types/generated/modules/grid/Grid.d.ts +61 -25
  552. package/types/generated/modules/grid/Layer.d.ts +5 -5
  553. package/types/generated/modules/grid/index.d.ts +29 -17
  554. package/types/generated/modules/music/Music.d.ts +5 -3
  555. package/types/generated/modules/net/index.d.ts +3 -3
  556. package/types/generated/modules/net/transports.d.ts +12 -3
  557. package/types/generated/modules/particles/Particles.d.ts +1 -1
  558. package/types/generated/modules/sky/Sky.d.ts +12 -104
  559. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  560. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  561. package/types/generated/modules/weather/Weather.d.ts +17 -18
  562. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  563. package/types/generated/modules/world/World.d.ts +18 -3
  564. package/types/generated/render/PostFX.d.ts +67 -30
  565. package/types/generated/render/materials.d.ts +26 -20
  566. package/types/generated/render/modeling.d.ts +30 -0
  567. package/types/generated/render/patches.d.ts +16 -2
  568. package/types/generated/ui/UI.d.ts +6 -3
  569. package/types/nav.d.ts +6 -0
  570. package/types/physics.d.ts +137 -44
  571. package/types/style.d.ts +125 -92
  572. package/types/tsl.d.ts +86 -0
  573. package/types/world.d.ts +164 -110
  574. package/ui/Focus.js +25 -14
  575. package/ui/LoadingScreen.js +1 -1
  576. package/ui/Parts.js +27 -11
  577. package/ui/UI.js +20 -10
  578. package/ui/cursor.js +115 -0
  579. package/ui/defaults.js +15 -11
  580. package/ui/theme.js +9 -6
  581. package/ui/touchPart.js +1 -1
  582. package/core/claims.js +0 -51
  583. package/core/look/layers.js +0 -136
  584. package/core/renamed.js +0 -21
  585. package/docs/api/entities.md +0 -61
  586. package/docs/recipes/09-style-pack.md +0 -234
  587. package/examples/styletest/overrides.js +0 -33
  588. package/examples/styletest/panel.js +0 -135
  589. package/modules/entities/Entities.js +0 -243
  590. package/modules/entities/build.js +0 -25
  591. package/modules/entities/index.js +0 -4
  592. package/modules/sky/calendar.js +0 -80
  593. package/modules/sky/layers.js +0 -69
  594. package/modules/terrain/chunkLevels.js +0 -40
  595. package/modules/terrain/mountTerrain.js +0 -32
  596. package/modules/world/cells.js +0 -42
@@ -0,0 +1,83 @@
1
+ # Game map: rc2d (generated, do not edit by hand)
2
+
3
+ > Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /rc2d.html, entry `main.js`.
4
+ > Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; for the engine API read `node_modules/threedog/docs/API.md` (index) first, then only the module pages listed below.
5
+
6
+ Content: none (no content/ folder)
7
+
8
+ ## Design decisions (hand-written, from DESIGN.md)
9
+
10
+ None yet, write them in `DESIGN.md` (why it is designed this way, what not to change).
11
+
12
+ ## Engine modules (engine.use)
13
+
14
+ - createEngine: { lights: false, ui: { loading: false }, saveKey: 'threedog-rc2d' }
15
+ - fixedCamera ({ shots: { top }, start: 'top' })
16
+
17
+ ## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
18
+
19
+ - cameraRig: `node_modules/threedog/docs/recipes/21-camera.md` · `node_modules/threedog/docs/api/cameraRig.md`
20
+
21
+ Not used yet (check these before writing the system yourself):
22
+
23
+ - inventory: items, stacks, containers and pickups: `inventory()` + key map presets.bindings.inventory, content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
24
+ - collision: walls and blocking for characters: `collision()` (in openWorld), template `collide` (node_modules/threedog/docs/recipes/18-world.md)
25
+ - characters: player and NPC movement, spawn, schedules: `characters()` (in openWorld), content/npcs.js (node_modules/threedog/docs/recipes/02-npc.md)
26
+ - saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
27
+ - interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
28
+ - quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
29
+ - grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
30
+ - templates: reusable objects placed from content: content/templates.js + props { template } (node_modules/threedog/docs/recipes/30-templates.md)
31
+
32
+ ## Files
33
+
34
+ content/*.js is content data: how to write it in `node_modules/threedog/docs/recipes/` (02-npc, 03-items-pickups, 04-quests, 20-content-actions-save…).
35
+
36
+ | File | Lines | Description |
37
+ |---|---|---|
38
+ | main.js | 64 | @ts-check 2D radiance cascades demo (page /rc2d.html): a top-down street at night. Street lamps, li… |
39
+ | rc2d.js | 198 | @ts-check 2D radiance cascades: screen-space global illumination for top-down and side-view games (… |
40
+ | shaders.js | 145 | GLSL for rc2d.js (2D radiance cascades), GLSL ES 3.0 as three.js compiles a ShaderMaterial under We… |
41
+
42
+ ## NPCs (content/npcs.js)
43
+
44
+ (none)
45
+
46
+ ## Dialogues (content/dialogues.js, node → destination)
47
+
48
+ (none)
49
+
50
+ ## Items (content/items.js)
51
+
52
+ (none)
53
+
54
+ ## Quests (content/quests.js)
55
+
56
+ (none)
57
+
58
+ ## Trigger zones, level markers, places
59
+
60
+ (none)
61
+
62
+ ## Placements (the level is content; counts per content file)
63
+
64
+ - none in content yet: place things with a template (content/templates.js) and a placement (content/props.js)
65
+
66
+ Code that breaks saves or manages world models: none (rule R33).
67
+
68
+ ## Key actions defined by the game (the engine's own are in node_modules/threedog/docs/CODEMAP.md)
69
+
70
+ (none)
71
+
72
+ ## Events the game emits / listens to
73
+
74
+ (none)
75
+
76
+ ## Saves
77
+
78
+ - Save prefix saveKey: threedog-rc2d
79
+ - Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
80
+
81
+ ## Style keys
82
+
83
+ - Style: none (all neutral fallback look)
@@ -0,0 +1,52 @@
1
+ # 2D radiance cascades (optional example)
2
+
3
+ Screen-space global illumination for top-down and side-view games: lamps, lit windows and neon signs light the floor around them, walls block
4
+ that light and cast soft shadows, coloured lights mix. It is an example you copy, not an engine module: the engine never imports it and
5
+ nothing installs it. Run it with `npm run dev` and open `/rc2d.html` (`?quality=low|medium|high`, `cascades=auto|1..8`, `interval=4`, `apply=0`).
6
+
7
+ ## When to use it
8
+ - A fixed top-down or side-on camera (orthographic or nearly so) where light should spread over the floor and stop at walls, with many
9
+ or large light shapes (a whole neon bar is one light, at no extra cost per light).
10
+ - Not for a free 3D camera: it only knows what is on screen, in the screen plane. A light off screen gives no light, and height is ignored.
11
+ For a few point lights in 3D, three.js lights (`engine.lightPool` for many) are cheaper and correct.
12
+
13
+ ## How to copy it into a game
14
+ 1. Copy `rc2d.js` and `shaders.js` into your game (`threedog examples pull rc2d`, or by hand). They import only `three` and `three/addons`.
15
+ 2. Put what light sees on one layer: emitters (any mesh with `material.emissive`, strength `emissiveIntensity`) and occluders (meshes
16
+ without emissive). `mesh.layers.enable(5)` keeps them visible to the normal camera too. The floor stays off the layer: it receives light.
17
+ 3. `const rc = createRadianceCascades2D(engine, { layer: 5, ambient: 0.15 })`. Each frame it renders in `engine.onRender` and, with `apply`
18
+ (default), one pass in the engine's `hdr` post slot (`engine.look.post.add`) adds the light to the frame: `color * (1 + light / ambient)`.
19
+ Set `ambient` to how bright your scene's own light already is, so the light lands on the surface colour (albedo = color / ambient).
20
+ 4. Or `apply: false` and read `rc.texture` (linear light per screen uv) in your own materials. `rc.target` is its render target.
21
+ 5. `rc.describe()` (size, cascades, intervals, targets), `rc.resize()` (also checked every frame), `rc.dispose()` (frees every target).
22
+
23
+ Colours and strengths are the game's: change a lamp's `emissiveIntensity` and the light follows the same frame (flicker, day / night).
24
+ `threedog examples pull rc2d` copies the two files and this README into the game (`techniques/rc2d/`), or copy them by hand.
25
+
26
+ ## Parameters (all in `RC2D_DEFAULTS` / `RC2D_QUALITY` at the top of `rc2d.js`)
27
+ | Option | Default | Meaning |
28
+ |---|---|---|
29
+ | `quality` | `'medium'` | `low` / `medium` / `high`: resolution 1/4, 1/2, 1x of the canvas (CSS pixels) and 16 / 24 / 32 march steps per ray |
30
+ | `cascades` | `'auto'` | how many cascades; auto = enough for the longest ray to cross the screen diagonal |
31
+ | `interval` | `4` | cascade 0's ray length in RC pixels; each cascade above is 4x longer. Larger = smoother, softer contact light |
32
+ | `layer` | `5` | the three.js layer of emitters and occluders |
33
+ | `ambient` | `1` | the scene's own light level, see step 3 |
34
+ | `apply` | `true` | add the post pass; `false` = only `rc.texture` |
35
+
36
+ ## Cost (1280x720 canvas, measured 2026-11-02, the demo scene)
37
+ - GPU (AMD Radeon 780M integrated, D3D11): frame 3.6 ms without, about 15.8 ms with `medium`, 32.6 ms with `high`; `low` about 14 ms
38
+ (at low the fixed cost of ~20 passes dominates). Use `low` or `medium` on integrated graphics.
39
+ - Software rendering (headless SwiftShader): about 16x a plain frame at `medium`; only for tests.
40
+ - Memory: about 10 half-float targets the size of the RC resolution (two float targets for the jump flood).
41
+
42
+ ## Limits
43
+ - Screen space: nothing off screen contributes, and what moves off screen stops lighting.
44
+ - Occluder tops stay as the scene lights them (rays start inside them and see no light); light is 2D, so a lamp on a roof lights the
45
+ floor beside the building as if it stood on the ground.
46
+ - Thin occluders under about one RC pixel (2 screen pixels at `medium`) can leak.
47
+ - The merge uses the paper's "bilinear fix" (4 rays per merge) against leaks and rings; it is the main cost.
48
+
49
+ ## Sources
50
+ Written from the public descriptions, no code copied: Alexander Sannikov, "Radiance Cascades: A Novel Approach to Calculating Global
51
+ Illumination" (2023); jason.today, "Building Real-Time Global Illumination" (parts 1 and 2: jump flood, distance field, cascades);
52
+ GM Shaders, "Radiance Cascades".
@@ -0,0 +1,63 @@
1
+ // @ts-check
2
+ // 2D radiance cascades demo (page /rc2d.html): a top-down street at night. Street lamps, lit windows and a neon bar are emissive meshes; building
3
+ // blocks and a wall are occluders. Both are on layer 5, which is all rc2d.js looks at; the floor is not, so it only receives light.
4
+ // URL: ?quality=low|medium|high &cascades=auto|1..8 &interval=4 &apply=0 (no post pass: the frame stays as the scene's own light draws it).
5
+ // Test page for tests/specs/rc2d.mjs: window.rc2dTest = { rc, THREE, points } (points: world spots the spec reads the light at).
6
+ import { createEngine, fixedCamera, makeMaterial, THREE } from '../../index.js';
7
+ import { createRadianceCascades2D } from './rc2d.js';
8
+
9
+ const LAYER = 5, AMBIENT = 0.12; // the scene's own light (one ambient light); rc2d divides by it to get albedo back
10
+ const url = new URLSearchParams(location.search);
11
+ const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-rc2d' });
12
+ engine.scene.add(new THREE.AmbientLight(0xffffff, AMBIENT));
13
+ engine.look.lights.set({ env: { intensity: 0 } }); // no room-map light either: AMBIENT is the whole of the scene's own light
14
+ // projection / size per shot work at run time (recipes/21-camera.md) but CameraShot does not declare them yet, hence the cast
15
+ const top = /** @type {any} */ ({ position: [0, 40, 0.001], lookAt: [0, 0, 0], projection: 'orthographic', size: 30 });
16
+ engine.use(fixedCamera({ shots: { top }, start: 'top' }));
17
+
18
+ const floor = new THREE.Mesh(new THREE.PlaneGeometry(120, 120), makeMaterial('terrain', { color: 0x8a8a90 }));
19
+ floor.rotation.x = -Math.PI / 2;
20
+ engine.scene.add(floor);
21
+
22
+ /** A box seen from above: [x0, z0, x1, z1] in metres; on the light layer, so it blocks (and shines when emissive) */
23
+ function block(/** @type {number[]} */ [x0, z0, x1, z1], /** @type {THREE.Material} */ material, height = 4) {
24
+ const m = new THREE.Mesh(new THREE.BoxGeometry(x1 - x0, height, z1 - z0), material);
25
+ m.position.set((x0 + x1) / 2, height / 2, (z0 + z1) / 2);
26
+ m.layers.enable(LAYER);
27
+ engine.scene.add(m);
28
+ return m;
29
+ }
30
+ const wall = makeMaterial('prop', { color: 0x6d6258 });
31
+ for (const r of [[-14, -11, -4, -3], [3, -13, 13, -5], [-14, 4, -6, 12], [2, 3.7, 10, 4.3], [2, 3.7, 2.6, 11], [14, 2, 17, 9]]) block(r, wall);
32
+ // pillars along the street: small occluders that cast soft shadows from the lamps
33
+ for (let x = -10; x <= 10; x += 5) block([x - 0.3, 0.7, x + 0.3, 1.3], wall, 2);
34
+
35
+ const glow = (/** @type {number} */ color, /** @type {number} */ intensity) => makeMaterial('prop', { color: 0x000000, emissive: color, emissiveIntensity: intensity });
36
+ const lamps = [[7, 2.2], [-8, 2], [-2, -5], [-2, 14]].map(([x, z]) => {
37
+ const m = new THREE.Mesh(new THREE.CylinderGeometry(0.45, 0.45, 0.2, 20), glow(0xffb060, 6));
38
+ m.position.set(x, 4.5, z);
39
+ m.layers.enable(LAYER);
40
+ engine.scene.add(m);
41
+ return m;
42
+ });
43
+ // lit windows on the south face of the first block, a neon bar on the west face of the second
44
+ for (let x = -13; x < -5; x += 3) block([x, -3, x + 1.6, -2.75], glow(0x7fb0ff, 2), 3);
45
+ block([2.75, -12, 3, -6], glow(0xff40c0, 3), 3);
46
+
47
+ // one flickering lamp: rc2d reads emissiveIntensity every frame, so plain material writes are all it takes
48
+ const flicker = /** @type {any} */ (lamps[2].material);
49
+ engine.onFrame(() => { flicker.emissiveIntensity = 6 * (0.8 + 0.2 * Math.sin(engine.clock.now * 9) * Math.sin(engine.clock.now * 2.3)); });
50
+
51
+ const cascades = url.get('cascades');
52
+ const rc = createRadianceCascades2D(engine, {
53
+ layer: LAYER, ambient: AMBIENT,
54
+ quality: /** @type {any} */ (url.get('quality') ?? 'medium'),
55
+ cascades: cascades && cascades !== 'auto' ? Number(cascades) : 'auto',
56
+ interval: Number(url.get('interval') ?? 4),
57
+ apply: url.get('apply') !== '0',
58
+ });
59
+
60
+ // lit: 1 m from lamp 0; open: 4 m from it with nothing between; shadow: 4 m from it behind the wall at z 3.7..4.3
61
+ const points = { lit: [7, 3], open: [7, -1.8], shadow: [7, 6.2] };
62
+ Object.assign(window, { engine, rc2dTest: { rc, THREE, points } });
63
+ engine.start();
@@ -0,0 +1,197 @@
1
+ // @ts-check
2
+ // 2D radiance cascades: screen-space global illumination for top-down and side-view games (WebGL2, fragment shaders only, no compute).
3
+ // An optional example, not an engine module: copy this folder (rc2d.js + shaders.js) into your game and import it.
4
+ //
5
+ // import { createRadianceCascades2D } from './rc2d/rc2d.js';
6
+ // wall.layers.enable(5); lamp.layers.enable(5); // what light sees: lamps (emissive) and walls (not emissive) on one layer
7
+ // const rc = createRadianceCascades2D(engine, { ambient: 0.15 });
8
+ // rc.describe(); rc.texture; rc.resize(); rc.dispose();
9
+ //
10
+ // Each frame (engine.onRender, before the frame): the meshes on `layer` are drawn from the game camera into a scene target (rgb = their emissive,
11
+ // a = solid) -> jump flood -> distance field -> cascades traced and merged from the coarsest down -> gather into `texture` (linear light per
12
+ // screen pixel). With `apply` (default) one post pass in the engine's 'hdr' slot (engine.look.post.add) adds that light to the frame; without it,
13
+ // sample `texture` in your own materials (screen uv). Colours and strengths are the game's: a lamp shines with its material's emissive * emissiveIntensity.
14
+ import * as THREE from 'three';
15
+ import { Pass, FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
16
+ import { VERT, SEED, JFA, DIST, CASCADE, GATHER, APPLY } from './shaders.js';
17
+
18
+ /**
19
+ * The parameters, in one place. quality: RC resolution as a share of the screen (CSS pixels) and the march step cap per ray.
20
+ * interval: cascade 0's ray length in RC pixels (each cascade's is 4x the one below). cascades: 'auto' = enough to cross the screen diagonal.
21
+ * ambient: the light level the frame is already lit with (albedo = color / ambient); apply: add the pass to engine.post.
22
+ */
23
+ export const RC2D_DEFAULTS = Object.freeze({ layer: 5, quality: 'medium', cascades: 'auto', interval: 4, ambient: 1, apply: true });
24
+ /** @typedef {{ layer?: number, quality?: 'low' | 'medium' | 'high', cascades?: number | 'auto', interval?: number, ambient?: number, apply?: boolean }} Rc2dOptions */
25
+ export const RC2D_QUALITY = Object.freeze({ low: { scale: 0.25, steps: 16 }, medium: { scale: 0.5, steps: 24 }, high: { scale: 1, steps: 32 } });
26
+ const SPACING0 = 2; // cascade 0 probe spacing (RC pixels); with 4 directions it keeps every cascade target about the scene target's size
27
+
28
+ /**
29
+ * @param {any} engine a threedog engine (renderer, scene, camera, onRender, look.post)
30
+ * @param {Rc2dOptions} [options]
31
+ */
32
+ export function createRadianceCascades2D(engine, options = {}) {
33
+ for (const k of Object.keys(options)) if (!(k in RC2D_DEFAULTS)) throw new Error(`rc2d: unknown option '${k}'; options: ${Object.keys(RC2D_DEFAULTS).join(', ')}`);
34
+ const o = /** @type {Required<Rc2dOptions>} */ ({ ...RC2D_DEFAULTS, ...options });
35
+ const q = RC2D_QUALITY[/** @type {keyof typeof RC2D_QUALITY} */ (o.quality)];
36
+ if (!q) throw new Error(`rc2d: quality '${o.quality}' is not one of ${Object.keys(RC2D_QUALITY).join(', ')}`);
37
+ if (!(o.interval > 0)) throw new Error(`rc2d: interval is cascade 0's ray length in RC pixels (> 0), got ${o.interval}`);
38
+ if (o.cascades !== 'auto' && !(Number.isInteger(o.cascades) && o.cascades >= 1 && o.cascades <= 8)) throw new Error(`rc2d: cascades is 'auto' or 1..8, got ${o.cascades}`);
39
+ if (!(Number.isInteger(o.layer) && o.layer >= 1 && o.layer <= 31)) throw new Error(`rc2d: layer is a three.js layer 1..31 (0 is everything), got ${o.layer}`);
40
+ if (!(o.ambient > 0)) throw new Error(`rc2d: ambient is the light level the frame is already lit with (> 0), got ${o.ambient}`);
41
+
42
+ const { renderer, scene } = engine;
43
+ const quad = new FullScreenQuad();
44
+ const mat = (/** @type {string} */ fragmentShader, /** @type {Record<string, any>} */ uniforms, defines = {}) => new THREE.ShaderMaterial({
45
+ vertexShader: VERT, fragmentShader, uniforms, defines, depthTest: false, depthWrite: false });
46
+ const u = (/** @type {any} */ v) => ({ value: v });
47
+ const mats = {
48
+ seed: mat(SEED, { tScene: u(null) }),
49
+ jfa: mat(JFA, { tSeed: u(null), uSize: u(new THREE.Vector2()), uStep: u(1) }),
50
+ dist: mat(DIST, { tSeed: u(null) }),
51
+ cascade: mat(CASCADE, { tScene: u(null), tDist: u(null), tUpper: u(null), uSize: u(new THREE.Vector2()), uTile: u(new THREE.Vector2()), uS: u(2),
52
+ uSpacing: u(SPACING0), uStart: u(0), uLen: u(1), uHasUpper: u(0), uUpperTile: u(new THREE.Vector2()), uUpperS: u(4) },
53
+ { STEPS: q.steps }),
54
+ gather: mat(GATHER, { tC0: u(null), uTile0: u(new THREE.Vector2()), uTex0: u(new THREE.Vector2()), uSpacing0: u(SPACING0) }),
55
+ };
56
+ /** @type {{ scene: THREE.WebGLRenderTarget, seed: THREE.WebGLRenderTarget[], dist: THREE.WebGLRenderTarget, gi: THREE.WebGLRenderTarget, cascades: { rt: THREE.WebGLRenderTarget, tile: THREE.Vector2, s: number, spacing: number, start: number, len: number }[] } | null} */
57
+ let t = null;
58
+ const size = new THREE.Vector2(), css = new THREE.Vector2();
59
+ let disposed = false;
60
+
61
+ const target = (/** @type {number} */ w, /** @type {number} */ h, /** @type {object} */ extra = {}) => new THREE.WebGLRenderTarget(w, h,
62
+ { type: THREE.HalfFloatType, minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, depthBuffer: false, ...extra });
63
+ const freeTargets = () => {
64
+ if (!t) return;
65
+ for (const rt of [t.scene, ...t.seed, t.dist, t.gi, ...t.cascades.map(c => c.rt)]) rt.dispose();
66
+ t = null;
67
+ };
68
+ // Sized from the renderer's CSS size (not the drawing buffer), so adaptive resolution changing the pixel ratio does not rebuild everything
69
+ function build() {
70
+ renderer.getSize(css);
71
+ const w = Math.max(8, Math.ceil(css.x * q.scale)), h = Math.max(8, Math.ceil(css.y * q.scale));
72
+ if (t && size.x === w && size.y === h) return;
73
+ freeTargets();
74
+ size.set(w, h);
75
+ const n = o.cascades === 'auto' ? Math.min(8, Math.max(1, Math.ceil(Math.log(3 * Math.hypot(w, h) / o.interval + 1) / Math.log(4)))) : o.cascades;
76
+ const cascades = [];
77
+ for (let i = 0; i < n; i++) {
78
+ const spacing = SPACING0 * 2 ** i, s = 2 ** (i + 1); // probes halve per axis, directions x4: each target stays near the scene size
79
+ const tile = new THREE.Vector2(Math.ceil(w / spacing), Math.ceil(h / spacing));
80
+ // linear filtering for cascade 0 only: the gather reads 4 neighbouring probes in one fetch (the merge reads exact texels)
81
+ const filter = i === 0 ? THREE.LinearFilter : THREE.NearestFilter;
82
+ cascades.push({ rt: target(tile.x * s, tile.y * s, { minFilter: filter, magFilter: filter }), tile, s, spacing,
83
+ start: o.interval * (4 ** i - 1) / 3, len: o.interval * 4 ** i });
84
+ }
85
+ t = { scene: target(w, h), seed: [target(w, h, { type: THREE.FloatType }), target(w, h, { type: THREE.FloatType })], dist: target(w, h),
86
+ gi: target(w, h, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }), cascades };
87
+ }
88
+
89
+ const draw = (/** @type {THREE.ShaderMaterial} */ m, /** @type {THREE.WebGLRenderTarget} */ rt) => { quad.material = m; renderer.setRenderTarget(rt); quad.render(renderer); };
90
+
91
+ // The meshes on `layer` drawn with a flat material each: colour = their emissive (0 for walls), alpha 1 = solid. Cached per source material.
92
+ /** @type {WeakMap<THREE.Material, THREE.MeshBasicMaterial>} */
93
+ const proxies = new WeakMap();
94
+ const swapped = /** @type {[THREE.Mesh, any][]} */ ([]);
95
+ const proxyOf = (/** @type {any} */ m) => {
96
+ let p = proxies.get(m);
97
+ // hint-off(material): a flat stand-in whose colour is the source material's emissive, not art
98
+ if (!p) { p = new THREE.MeshBasicMaterial({ fog: false, toneMapped: false }); proxies.set(m, p); }
99
+ p.color.setRGB(0, 0, 0);
100
+ if (m.emissive) p.color.copy(m.emissive).multiplyScalar(m.emissiveIntensity ?? 1); // read every frame: flicker and day / night keep working
101
+ p.side = m.side;
102
+ return p;
103
+ };
104
+ const clear = new THREE.Color();
105
+ function drawScene(/** @type {THREE.Camera} */ camera) {
106
+ scene.traverse((/** @type {any} */ obj) => {
107
+ if (!obj.isMesh || !obj.layers.isEnabled(o.layer)) return;
108
+ swapped.push([obj, obj.material]);
109
+ obj.material = Array.isArray(obj.material) ? obj.material.map(proxyOf) : proxyOf(obj.material);
110
+ });
111
+ // what is saved here is put back before the frame renders, so the engine's own per-frame writes (sky background) never see a change
112
+ const mask = camera.layers.mask, bg = scene.background, alpha = renderer.getClearAlpha(), auto = renderer.shadowMap.autoUpdate;
113
+ renderer.getClearColor(clear);
114
+ camera.layers.set(o.layer); scene.background = null; renderer.shadowMap.autoUpdate = false;
115
+ renderer.setClearColor(0x000000, 0);
116
+ renderer.setRenderTarget(t.scene); renderer.clear(); renderer.render(scene, camera);
117
+ renderer.setClearColor(clear, alpha); renderer.shadowMap.autoUpdate = auto; scene.background = bg; camera.layers.mask = mask;
118
+ for (const [obj, m] of swapped) obj.material = m;
119
+ swapped.length = 0;
120
+ }
121
+
122
+ let frameMs = 0;
123
+ function update(/** @type {{ camera: THREE.Camera }} */ { camera }) {
124
+ if (disposed) return;
125
+ const t0 = performance.now(); // measure: CPU-side submit time only (describe().ms); GPU time needs the perf tool
126
+ build();
127
+ if (!t) return;
128
+ drawScene(camera);
129
+ // jump flood: seed, then steps of half the largest power of two down to 1, ping-ponging the two float targets
130
+ mats.seed.uniforms.tScene.value = t.scene.texture; draw(mats.seed, t.seed[0]);
131
+ let src = 0;
132
+ mats.jfa.uniforms.uSize.value.copy(size);
133
+ for (let step = 2 ** Math.floor(Math.log2(Math.max(size.x, size.y))); step >= 1; step /= 2) {
134
+ mats.jfa.uniforms.tSeed.value = t.seed[src].texture; mats.jfa.uniforms.uStep.value = step;
135
+ draw(mats.jfa, t.seed[1 - src]); src = 1 - src;
136
+ }
137
+ mats.dist.uniforms.tSeed.value = t.seed[src].texture; draw(mats.dist, t.dist);
138
+ // cascades from the coarsest (longest rays, fewest probes) to cascade 0, each merging the one above it
139
+ const cu = mats.cascade.uniforms;
140
+ cu.tScene.value = t.scene.texture; cu.tDist.value = t.dist.texture; cu.uSize.value.copy(size);
141
+ for (let i = t.cascades.length - 1; i >= 0; i--) {
142
+ const c = t.cascades[i], up = t.cascades[i + 1];
143
+ cu.uTile.value.copy(c.tile); cu.uS.value = c.s; cu.uSpacing.value = c.spacing; cu.uStart.value = c.start; cu.uLen.value = c.len;
144
+ cu.uHasUpper.value = up ? 1 : 0;
145
+ if (up) { cu.tUpper.value = up.rt.texture; cu.uUpperTile.value.copy(up.tile); cu.uUpperS.value = up.s; }
146
+ else cu.tUpper.value = null; // never the target being written
147
+ draw(mats.cascade, c.rt);
148
+ }
149
+ const c0 = t.cascades[0], gu = mats.gather.uniforms;
150
+ gu.tC0.value = c0.rt.texture; gu.uTile0.value.copy(c0.tile); gu.uTex0.value.set(c0.rt.width, c0.rt.height);
151
+ draw(mats.gather, t.gi);
152
+ renderer.setRenderTarget(null);
153
+ frameMs = performance.now() - t0;
154
+ }
155
+ const hook = engine.onRender(update);
156
+
157
+ /** The apply pass: frame * (1 + gi / ambient), in linear colour before tone mapping */
158
+ class ApplyPass extends Pass {
159
+ constructor() {
160
+ super();
161
+ this.material = mat(APPLY, { tDiffuse: u(null), tGI: u(null), uAmbient: u(o.ambient) });
162
+ this.fsQuad = new FullScreenQuad(this.material);
163
+ }
164
+ /** @param {THREE.WebGLRenderer} r @param {THREE.WebGLRenderTarget} write @param {THREE.WebGLRenderTarget} read */
165
+ render(r, write, read) {
166
+ this.material.uniforms.tDiffuse.value = read.texture;
167
+ this.material.uniforms.tGI.value = t ? t.gi.texture : null;
168
+ r.setRenderTarget(this.renderToScreen ? null : write);
169
+ this.fsQuad.render(r);
170
+ }
171
+ dispose() { this.material.dispose(); this.fsQuad.dispose(); }
172
+ }
173
+ const post = o.apply ? engine.look.post.add({ name: 'rc2d', slot: 'hdr', create: () => new ApplyPass() }, { owner: 'rc2d' }) : null;
174
+
175
+ return {
176
+ /** The gathered light, linear rgb per screen uv (null before the first frame); a new texture after a resize */
177
+ get texture() { return t ? t.gi.texture : null; },
178
+ /** The render target holding `texture` (HalfFloat RGBA, linear filtering), for size or readRenderTargetPixels (Uint16Array, half floats) */
179
+ get target() { return t ? t.gi : null; },
180
+ /** Re-read the render size now (it is also checked every frame); rebuilds the targets when it changed */
181
+ resize() { if (!disposed) build(); },
182
+ /** Remove the hooks and the post pass, free every render target and material */
183
+ dispose() {
184
+ if (disposed) return;
185
+ disposed = true;
186
+ hook.remove(); post?.remove();
187
+ freeTargets();
188
+ for (const m of Object.values(mats)) m.dispose();
189
+ quad.dispose();
190
+ },
191
+ describe() {
192
+ return { size: [size.x, size.y], quality: o.quality, layer: o.layer, interval: o.interval, ambient: o.ambient, apply: o.apply,
193
+ cascades: t ? t.cascades.map(c => ({ probes: [c.tile.x, c.tile.y], directions: c.s * c.s, spacing: c.spacing, interval: [c.start, c.start + c.len] })) : [],
194
+ targets: t ? 5 + t.cascades.length : 0, cpuMs: +frameMs.toFixed(2), disposed };
195
+ },
196
+ };
197
+ }
@@ -0,0 +1,144 @@
1
+ // GLSL for rc2d.js (2D radiance cascades), GLSL ES 3.0 as three.js compiles a ShaderMaterial under WebGL2 (texelFetch; gl_FragColor is mapped).
2
+ // Every pass is a full-screen quad drawn into a render target whose viewport is that target, so gl_FragCoord.xy is the texel being written.
3
+ // Units: "RC pixels" = texels of the scene / distance targets (screen size * quality scale).
4
+ // Technique (written from the public descriptions, no code copied): Alexander Sannikov, "Radiance Cascades: A Novel Approach to Calculating
5
+ // Global Illumination" (2023); jason.today "Building Real-Time Global Illumination" parts 1-2 (jump flood -> distance field -> cascades);
6
+ // GM Shaders "Radiance Cascades" posts. Layout: direction-first (one tile per direction, every probe of that direction inside the tile).
7
+
8
+ export const VERT = /* glsl */`
9
+ varying vec2 vUv;
10
+ void main() { vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }`;
11
+
12
+ // Jump flood seed: a solid texel (alpha > 0.5 in the scene target) stores its own position; empty texels store "no seed" (alpha 0)
13
+ export const SEED = /* glsl */`
14
+ uniform sampler2D tScene;
15
+ void main() {
16
+ vec4 s = texelFetch(tScene, ivec2(gl_FragCoord.xy), 0);
17
+ gl_FragColor = s.a > 0.5 ? vec4(gl_FragCoord.xy, 0.0, 1.0) : vec4(0.0);
18
+ }`;
19
+
20
+ // One jump flood step: keep the nearest seed among the 3x3 neighbours uStep texels away. log2(size) steps give each texel its nearest solid texel.
21
+ export const JFA = /* glsl */`
22
+ uniform sampler2D tSeed;
23
+ uniform vec2 uSize;
24
+ uniform float uStep;
25
+ void main() {
26
+ vec2 p = gl_FragCoord.xy;
27
+ vec4 best = vec4(0.0);
28
+ float bestD = 1e20;
29
+ for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) {
30
+ vec2 q = p + vec2(float(x), float(y)) * uStep;
31
+ if (q.x < 0.0 || q.y < 0.0 || q.x >= uSize.x || q.y >= uSize.y) continue;
32
+ vec4 s = texelFetch(tSeed, ivec2(q), 0);
33
+ if (s.a < 0.5) continue;
34
+ vec2 d = s.xy - p;
35
+ float dd = dot(d, d);
36
+ if (dd < bestD) { bestD = dd; best = s; }
37
+ }
38
+ gl_FragColor = best;
39
+ }`;
40
+
41
+ // Distance (RC pixels) from each texel centre to the nearest solid texel centre; 0 inside walls and lights, large where the screen has no solid at all
42
+ export const DIST = /* glsl */`
43
+ uniform sampler2D tSeed;
44
+ void main() {
45
+ vec4 s = texelFetch(tSeed, ivec2(gl_FragCoord.xy), 0);
46
+ gl_FragColor = vec4(s.a > 0.5 ? distance(s.xy, gl_FragCoord.xy) : 1e4, 0.0, 0.0, 1.0);
47
+ }`;
48
+
49
+ // One cascade: every texel is (direction tile, probe). Its ray is sphere-traced through the distance field over the cascade's interval and merged with
50
+ // the upper cascade (the 4 child directions of the same cone). The merge uses the "bilinear fix" from the paper: instead of tracing once and
51
+ // blending the 4 nearest upper probes, it traces one ray to each of those 4 probes' interval start and merges each with that probe, then blends
52
+ // the 4 results bilinearly. 4x the marching, but light no longer leaks through walls thinner than the upper probe spacing and the rings between
53
+ // cascades go. rgb = radiance, a = 1 if the ray was not blocked.
54
+ export const CASCADE = /* glsl */`
55
+ uniform sampler2D tScene;
56
+ uniform sampler2D tDist;
57
+ uniform sampler2D tUpper;
58
+ uniform vec2 uSize; // RC pixels
59
+ uniform vec2 uTile; // probes per axis in this cascade = one direction tile
60
+ uniform float uS; // direction tiles per axis (directions = uS * uS)
61
+ uniform float uSpacing; // probe spacing, RC pixels
62
+ uniform float uStart;
63
+ uniform float uLen;
64
+ uniform float uHasUpper;
65
+ uniform vec2 uUpperTile;
66
+ uniform float uUpperS;
67
+
68
+ vec4 march(vec2 from, vec2 to) {
69
+ vec2 dir = to - from;
70
+ float end = length(dir), t = 0.0;
71
+ dir /= max(end, 1e-4);
72
+ for (int i = 0; i < STEPS; i++) {
73
+ if (t > end) break;
74
+ vec2 p = from + dir * t;
75
+ // off screen: nothing is known there; opaque black ends the ray (screen-space GI cannot see lights it does not draw)
76
+ if (p.x < 0.0 || p.y < 0.0 || p.x >= uSize.x || p.y >= uSize.y) return vec4(0.0);
77
+ float d = texelFetch(tDist, ivec2(p), 0).r;
78
+ if (d < 0.5) return vec4(texelFetch(tScene, ivec2(p), 0).rgb, 0.0);
79
+ // distances are centre to centre, so step a little less than d (never skip a corner), at least half a texel (grazing rays along walls)
80
+ t += max(d - 0.7, 0.5);
81
+ }
82
+ return vec4(0.0, 0.0, 0.0, 1.0);
83
+ }
84
+
85
+ // the upper cascade's radiance at upper probe nb for this direction's cone: the mean of its 4 child directions
86
+ vec4 upper(vec2 nb, float idx) {
87
+ vec4 far = vec4(0.0);
88
+ for (int j = 0; j < 4; j++) {
89
+ float c = idx * 4.0 + float(j);
90
+ vec2 ut = vec2(mod(c, uUpperS), floor(c / uUpperS));
91
+ far += texelFetch(tUpper, ivec2(ut * uUpperTile + nb), 0);
92
+ }
93
+ return far * 0.25;
94
+ }
95
+
96
+ void main() {
97
+ vec2 tc = floor(gl_FragCoord.xy);
98
+ vec2 tile = floor(tc / uTile);
99
+ vec2 probe = tc - tile * uTile;
100
+ float idx = tile.y * uS + tile.x;
101
+ float ang = (idx + 0.5) * 6.28318530718 / (uS * uS);
102
+ vec2 dir = vec2(cos(ang), sin(ang));
103
+ vec2 origin = (probe + 0.5) * uSpacing;
104
+ vec2 from = origin + dir * uStart;
105
+ if (uHasUpper < 0.5) { gl_FragColor = march(from, origin + dir * (uStart + uLen)); return; }
106
+ // this probe in upper probe grid coordinates; its 4 bilinear neighbours (clamped at the screen edge) and their weights
107
+ vec2 q = origin / (uSpacing * 2.0) - 0.5;
108
+ vec2 base = floor(q), f = q - base;
109
+ vec4 r = vec4(0.0);
110
+ for (int k = 0; k < 4; k++) {
111
+ vec2 o = vec2(float(k % 2), float(k / 2));
112
+ vec2 w2 = mix(1.0 - f, f, o);
113
+ vec2 nb = clamp(base + o, vec2(0.0), uUpperTile - 1.0);
114
+ vec4 near = march(from, (nb + 0.5) * uSpacing * 2.0 + dir * (uStart + uLen));
115
+ if (near.a > 0.0) { vec4 far = upper(nb, idx); near.rgb += far.rgb; near.a = far.a; }
116
+ r += near * (w2.x * w2.y);
117
+ }
118
+ gl_FragColor = r;
119
+ }`;
120
+
121
+ // Final gather: average cascade 0's 4 directions at each RC pixel (bilinear between its 4 nearest probes) = light arriving at that pixel
122
+ export const GATHER = /* glsl */`
123
+ uniform sampler2D tC0;
124
+ uniform vec2 uTile0;
125
+ uniform vec2 uTex0;
126
+ uniform float uSpacing0;
127
+ void main() {
128
+ vec2 q = clamp(gl_FragCoord.xy / uSpacing0 - 0.5, vec2(0.0), uTile0 - 1.0);
129
+ vec3 sum = vec3(0.0);
130
+ for (int j = 0; j < 4; j++) sum += texture(tC0, (vec2(float(j % 2), float(j / 2)) * uTile0 + q + 0.5) / uTex0).rgb;
131
+ gl_FragColor = vec4(sum * 0.25, 1.0);
132
+ }`;
133
+
134
+ // Apply (hdr slot, linear colour): the frame was lit by the scene's own light at level uAmbient, so albedo ~ color / uAmbient and the cascade
135
+ // light adds albedo * gi on top
136
+ export const APPLY = /* glsl */`
137
+ uniform sampler2D tDiffuse;
138
+ uniform sampler2D tGI;
139
+ uniform float uAmbient;
140
+ varying vec2 vUv;
141
+ void main() {
142
+ vec4 c = texture(tDiffuse, vUv);
143
+ gl_FragColor = vec4(c.rgb * (1.0 + texture(tGI, vUv).rgb / uAmbient), c.a);
144
+ }`;
@@ -0,0 +1 @@
1
+ {"version":1,"files":{"content/props.js":{"kind":"props","mtime":1793500175294.8977,"from":0,"count":15,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1793500175296.9004,"from":0,"count":2,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1793500175298.9006,"from":0,"count":1,"indexIds":0,"positional":[]}},"ids":{"tree-1":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"tree-2":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"tree-3":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"tree-4":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"tree-5":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"tree-6":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"tree-7":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"sheep-1":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"sheep-2":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"sheep-3":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"sheep-4":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"sheep-5":[{"file":"content/props.js","kind":"props","line":15,"placed":true}],"sheep-6":[{"file":"content/props.js","kind":"props","line":16,"placed":true}],"sheep-7":[{"file":"content/props.js","kind":"props","line":17,"placed":true}],"sheep-8":[{"file":"content/props.js","kind":"props","line":18,"placed":true}],"tree":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"sheep":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wheat":[{"file":"content/vegetation.js","kind":"vegetation","line":4,"placed":false}]}}
@@ -11,8 +11,8 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
11
11
 
12
12
  ## Engine modules (engine.use)
13
13
 
14
- - createEngine: { style, saveKey: 'threedog-sheepisland', ui: { loading: { title: 'sheep island' } } }
15
- - openWorld preset ({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false, sky: { ...pr…) → world, terrain, vegetation, sky, weather, collision, characters, settings, debug
14
+ - createEngine: { bindings: { ...presets.bindings.debug }, style, saveKey: 'threedog-sheepisland', ui: { loading: { title: 's…
15
+ - openWorld preset ({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false, calendar: { …) → world, terrain, vegetation, calendar, sky, weather, collision, characters, settings, debug
16
16
  - content
17
17
 
18
18
  ## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
@@ -20,19 +20,20 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
20
20
  - world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
21
21
  - terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
22
22
  - vegetation: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/vegetation.md`
23
+ - calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
23
24
  - sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
24
25
  - weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
25
26
  - collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
26
27
  - characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
27
28
  - settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
28
- - content: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/content.md`
29
+ - content: `node_modules/threedog/docs/recipes/30-templates.md` · `node_modules/threedog/docs/api/content.md`
29
30
 
30
31
  Not used yet (check these before writing the system yourself):
31
32
 
32
- - inventory: items, stacks, containers and pickups: `inventory({ ...presets.keys.inventory })` (keys required), content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
33
+ - inventory: items, stacks, containers and pickups: `inventory()` + key map presets.bindings.inventory, content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
33
34
  - saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
34
35
  - interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
35
- - quests: goals with steps, conditions and rewards: `quests({ ...presets.keys.quests })` (keys required), content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
36
+ - quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
36
37
  - grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
37
38
 
38
39
  ## Files
@@ -41,13 +42,14 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
41
42
 
42
43
  | File | Lines | Description |
43
44
  |---|---|---|
45
+ | assets.js | 6 | The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own fil… |
44
46
  | content/index.js | 7 | |
45
47
  | content/props.js | 20 | |
46
48
  | content/templates.js | 6 | |
47
49
  | content/vegetation.js | 9 | |
48
- | main.js | 72 | @ts-check Sheep island: a small floating island built only from the engine's public entry points (t… |
50
+ | main.js | 77 | @ts-check Sheep island: a small floating island built only from the engine's public entry points (t… |
49
51
  | params.js | 26 | URL parameters of the sheep island page. Import this file first in main.js: it rewrites word values… |
50
- | style/index.js | 80 | sheepisland: a style pack, LOOKS ONLY (recipes/09-style-pack.md, 35-style-from-reference.md), start… |
52
+ | style/index.js | 80 | sheepisland: this game's style, LOOKS ONLY (recipes/09-style.md, 35-style-from-reference.md), fille… |
51
53
  | style/models.js | 60 | sheepisland procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; regist… |
52
54
  | views.js | 10 | Named camera positions of the sheep island. Same name = same framing every time, so two screenshots… |
53
55
 
@@ -71,7 +73,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
71
73
 
72
74
  (none)
73
75
 
74
- ## Object templates (content/templates.js; placed with props { template }, spawned with engine.spawn)
76
+ ## Object templates (content/templates.js; placed with props { template }, spawned with engine.content.spawn)
75
77
 
76
78
  | Template | Model | Collide | Interact (op / label) | Container | State (defaults) | Instances |
77
79
  |---|---|---|---|---|---|---|
@@ -98,10 +100,10 @@ Code that breaks saves or manages world models: none (rule R33).
98
100
  ## Saves
99
101
 
100
102
  - Save prefix saveKey: threedog-sheepisland
101
- - Saved parts of the engine modules (vars, inventory, quests, timers, world...): `npx threedog catalog` (saves per module)
103
+ - Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
102
104
 
103
- ## Style pack keys
105
+ ## Style keys
104
106
 
105
- - Style pack: none (all neutral fallback look)
107
+ - Style: none (all neutral fallback look)
106
108
  - Models (asset names): wheatTuft, roundTree, sheep
107
109
  - Vegetation (content/vegetation.js): wheat
@@ -0,0 +1,5 @@
1
+ // The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own file so `npm run check` imports the same
2
+ // objects and checks the model / sound names content uses against them (one source, no scanning of main.js).
3
+ import { assets } from './style/index.js'; // roundTree, sheep, wheatTuft
4
+
5
+ export default [assets];