threedog 0.8.0 → 1.0.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 (372) hide show
  1. package/CHANGELOG.md +219 -4
  2. package/README.md +6 -6
  3. package/core/assets/Animator.js +2 -0
  4. package/core/assets/Assets.js +44 -13
  5. package/core/assets/assetEntry.js +87 -22
  6. package/core/assets/assetHot.js +2 -1
  7. package/core/assets/assetReport.js +1 -2
  8. package/core/audio/Audio.js +24 -5
  9. package/core/base/I18n.js +6 -3
  10. package/core/base/Random.js +3 -1
  11. package/core/base/Vars.js +14 -4
  12. package/core/base/errorCodes.js +54 -16
  13. package/core/base/errorHints.js +12 -1
  14. package/core/base/errors.js +6 -4
  15. package/core/base/events.generated.js +10 -0
  16. package/core/base/follows.js +26 -0
  17. package/core/base/math.js +15 -8
  18. package/core/base/params.js +2 -2
  19. package/core/{saves → base}/saveValues.js +24 -6
  20. package/core/base/sections.js +97 -0
  21. package/core/base/spelling.js +32 -0
  22. package/core/base/validate.js +8 -29
  23. package/core/engine/Engine.js +61 -18
  24. package/core/engine/Loading.js +30 -3
  25. package/core/engine/copies.js +1 -1
  26. package/core/engine/headlessLoad.js +30 -13
  27. package/core/engine/lifecycle.js +30 -25
  28. package/core/engine/loop.js +22 -4
  29. package/core/engine/moduleSlots.js +91 -15
  30. package/core/engine/moduleTypes.js +13 -0
  31. package/core/engine/modules.js +248 -62
  32. package/core/engine/page.js +25 -8
  33. package/core/engine/plugins.js +15 -3
  34. package/core/engine/services.js +3 -0
  35. package/core/engine/startup.js +46 -36
  36. package/core/input/Input.js +39 -19
  37. package/core/input/inputKeyboard.js +39 -0
  38. package/core/input/inputPad.js +23 -2
  39. package/core/input/inputPointer.js +3 -1
  40. package/core/input/inputSeat.js +66 -0
  41. package/core/input/inputTouch.js +23 -6
  42. package/core/inspect/DebugOverrides.js +13 -2
  43. package/core/inspect/Describe.js +10 -6
  44. package/core/inspect/Inspect.js +31 -4
  45. package/core/inspect/UrlState.js +14 -10
  46. package/core/inspect/catalog.js +12 -5
  47. package/core/inspect/describeRender.js +3 -2
  48. package/core/inspect/describeText.js +6 -2
  49. package/core/inspect/metadata.generated.js +4140 -0
  50. package/core/inspect/pictureWriters.js +117 -33
  51. package/core/inspect/toolDoor.js +21 -0
  52. package/core/inspect/valueHistory.js +35 -0
  53. package/core/ops/Ops.js +32 -7
  54. package/core/ops/control.js +48 -23
  55. package/core/ops/holds.js +4 -3
  56. package/core/ops/opsAtomic.js +18 -6
  57. package/core/ops/opsCheck.js +7 -5
  58. package/core/ops/opsFail.js +5 -7
  59. package/core/ops/opsRun.js +2 -2
  60. package/core/ops/owned.js +20 -3
  61. package/core/ops/sharedPoint.js +7 -10
  62. package/core/ops/stacks.js +22 -1
  63. package/core/saves/SaveStore.js +52 -26
  64. package/core/saves/Saves.js +122 -27
  65. package/core/saves/saveApply.js +159 -61
  66. package/core/saves/saveFiles.js +30 -25
  67. package/core/saves/saveVersions.js +20 -6
  68. package/core/saves/session.js +76 -33
  69. package/core/saves/stateReplace.js +184 -0
  70. package/core/scene/Rays.js +21 -5
  71. package/core/scene/Views.js +6 -6
  72. package/core/scene/adaptive.js +13 -10
  73. package/core/scene/canvasBox.js +2 -0
  74. package/core/scene/compositeGround.js +72 -0
  75. package/core/scene/floor.js +17 -0
  76. package/core/scene/grid.js +2 -0
  77. package/core/scene/ground.contract.js +14 -0
  78. package/core/scene/ground.js +52 -17
  79. package/core/scene/pixel.js +154 -0
  80. package/core/scene/pixelRatio.js +167 -0
  81. package/core/scene/sceneDelta.js +3 -3
  82. package/core/scene/sceneMethods.js +11 -6
  83. package/core/scene/stepPoses.js +6 -1
  84. package/core/scene/thingExplain.js +1 -1
  85. package/core/scene/thingOps.js +22 -14
  86. package/core/scene/things.js +1 -1
  87. package/core/scene/tier.js +10 -0
  88. package/core/scene/view.js +126 -9
  89. package/core/stream/Batching.js +0 -1
  90. package/core/stream/Stream.js +24 -12
  91. package/core/stream/batchGroups.js +1 -0
  92. package/core/stream/scatter.js +5 -2
  93. package/core/stream/streamSources.js +2 -1
  94. package/core/threads/Commits.js +12 -7
  95. package/core/threads/Jobs.js +15 -5
  96. package/core/threads/Threads.js +5 -2
  97. package/core/time/Clock.js +3 -1
  98. package/core/time/skip.js +10 -4
  99. package/core/time/time.js +16 -10
  100. package/docs/AI.md +89 -72
  101. package/docs/API.md +18 -14
  102. package/docs/CODEMAP.md +68 -40
  103. package/docs/COMMANDS.md +22 -23
  104. package/docs/CONVENTIONS.md +120 -17
  105. package/docs/MIGRATING-0.8.md +2 -0
  106. package/docs/MIGRATING-1.0.md +101 -0
  107. package/docs/THREE.md +65 -12
  108. package/docs/api/cameraRig.md +3 -0
  109. package/docs/api/characters.md +13 -7
  110. package/docs/api/collider3d.md +9 -0
  111. package/docs/api/content.md +16 -15
  112. package/docs/api/dialogue.md +2 -1
  113. package/docs/api/engine.md +18 -16
  114. package/docs/api/events.md +14 -4
  115. package/docs/api/ground.md +2 -2
  116. package/docs/api/i18n.md +1 -1
  117. package/docs/api/input.md +2 -1
  118. package/docs/api/interactions.md +1 -1
  119. package/docs/api/inventory.md +1 -1
  120. package/docs/api/level.md +3 -2
  121. package/docs/api/nav.md +4 -2
  122. package/docs/api/particles.md +8 -5
  123. package/docs/api/pickups.md +1 -1
  124. package/docs/api/post.md +3 -4
  125. package/docs/api/quests.md +4 -2
  126. package/docs/api/rays.md +2 -0
  127. package/docs/api/rigid.md +3 -2
  128. package/docs/api/saves.md +8 -7
  129. package/docs/api/stream.md +4 -5
  130. package/docs/api/terrain.md +3 -4
  131. package/docs/api/terrainDraw.md +1 -1
  132. package/docs/api/timeline.md +2 -2
  133. package/docs/api/tools.md +3 -1
  134. package/docs/api/triggers.md +2 -0
  135. package/docs/api/vegetationDraw.md +1 -1
  136. package/docs/api/water.md +6 -2
  137. package/docs/api/weather.md +19 -4
  138. package/docs/api/weatherDraw.md +1 -1
  139. package/docs/api/world.md +1 -1
  140. package/docs/recipes/01-new-game.md +3 -3
  141. package/docs/recipes/02-npc.md +3 -4
  142. package/docs/recipes/03-items-pickups.md +11 -11
  143. package/docs/recipes/04-quests.md +2 -0
  144. package/docs/recipes/05-props-bake.md +9 -9
  145. package/docs/recipes/06-clock-events.md +6 -6
  146. package/docs/recipes/07-flow-scenes-pause.md +18 -15
  147. package/docs/recipes/08-weather-sky.md +5 -5
  148. package/docs/recipes/09-materials-lights-models.md +3 -3
  149. package/docs/recipes/10-blender-level.md +16 -4
  150. package/docs/recipes/11-vehicles.md +18 -6
  151. package/docs/recipes/12-navmesh.md +52 -8
  152. package/docs/recipes/13-animation.md +34 -8
  153. package/docs/recipes/14-custom-module.md +20 -8
  154. package/docs/recipes/15-perf.md +4 -4
  155. package/docs/recipes/16-dev-bridge.md +9 -8
  156. package/docs/recipes/18-world.md +13 -5
  157. package/docs/recipes/19-shooting-picking.md +3 -2
  158. package/docs/recipes/20-content-actions-save.md +26 -6
  159. package/docs/recipes/21-camera.md +17 -23
  160. package/docs/recipes/22-shop-gold.md +21 -12
  161. package/docs/recipes/23-ops.md +19 -15
  162. package/docs/recipes/26-ui-parts.md +3 -2
  163. package/docs/recipes/27-net.md +3 -3
  164. package/docs/recipes/28-terrain.md +3 -3
  165. package/docs/recipes/29-grid.md +1 -1
  166. package/docs/recipes/30-templates.md +10 -13
  167. package/docs/recipes/31-audio.md +2 -2
  168. package/docs/recipes/32-action-game.md +6 -5
  169. package/docs/recipes/33-stream-sources.md +4 -1
  170. package/docs/recipes/34-environment-lighting.md +7 -8
  171. package/docs/recipes/35-picture-from-reference.md +13 -9
  172. package/docs/recipes/36-ground-plants.md +3 -2
  173. package/docs/recipes/40-scene.md +11 -10
  174. package/docs/recipes/43-shader-patches-surfaces.md +7 -7
  175. package/docs/recipes/44-water-weather-hooks.md +9 -8
  176. package/docs/recipes/45-cascaded-shadows.md +3 -4
  177. package/docs/recipes/46-blender-art-route.md +3 -3
  178. package/docs/recipes/49-game-module-contract.md +2 -1
  179. package/docs/recipes/50-own-renderer.md +1 -0
  180. package/docs/recipes/51-capability-catalog.md +14 -8
  181. package/docs/recipes/52-around-the-picture.md +4 -4
  182. package/docs/recipes/55-mods-time-wrap.md +5 -4
  183. package/docs/recipes/56-webgpu-tsl.md +12 -1
  184. package/docs/recipes/57-control.md +30 -10
  185. package/docs/recipes/58-input.md +13 -0
  186. package/docs/recipes/60-judge-the-picture.md +1 -1
  187. package/docs/recipes/62-picture-code.md +106 -48
  188. package/docs/recipes/63-third-person-start.md +2 -1
  189. package/docs/recipes/64-particles.md +53 -4
  190. package/docs/recipes/65-swarm.md +2 -2
  191. package/docs/recipes/66-common-tasks.md +313 -0
  192. package/examples/action/.threedog/content-index.json +1 -1
  193. package/examples/action/GAMEMAP.md +3 -3
  194. package/examples/perf-island/.threedog/content-index.json +1 -1
  195. package/examples/perf-island/GAMEMAP.md +3 -3
  196. package/examples/perf-island/main.js +2 -2
  197. package/examples/plain-picture/GAMEMAP.md +3 -1
  198. package/examples/rc2d/GAMEMAP.md +1 -1
  199. package/examples/rc2d/rc2d.js +1 -1
  200. package/examples/styletest/.threedog/content-index.json +1 -1
  201. package/examples/styletest/GAMEMAP.md +3 -3
  202. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  203. package/examples/world/.threedog/content-index.json +1 -1
  204. package/examples/world/GAMEMAP.md +5 -4
  205. package/examples/world/main.js +3 -3
  206. package/index.d.ts +8 -5
  207. package/index.js +22 -1
  208. package/llms.txt +2 -1
  209. package/modules/ambience/Ambience.js +5 -3
  210. package/modules/calendar/index.js +7 -5
  211. package/modules/camera/FirstPersonCamera.js +3 -3
  212. package/modules/camera/FixedCamera.js +34 -20
  213. package/modules/camera/FollowCamera.js +20 -11
  214. package/modules/camera/RtsCamera.js +1 -0
  215. package/modules/camera/common.js +33 -22
  216. package/modules/camera/pixelSnap.js +62 -0
  217. package/modules/characters/Character.js +136 -43
  218. package/modules/characters/NPC.js +60 -28
  219. package/modules/characters/assetModel.js +2 -2
  220. package/modules/characters/astar.js +47 -28
  221. package/modules/characters/character.contract.js +21 -0
  222. package/modules/characters/contract.js +17 -3
  223. package/modules/characters/index.js +94 -34
  224. package/modules/characters/moveHelpers.js +80 -15
  225. package/modules/characters/mover.contract.js +14 -0
  226. package/modules/characters/movers/common.js +6 -4
  227. package/modules/characters/movers/rapier.js +12 -5
  228. package/modules/characters/movers/simple.js +25 -12
  229. package/modules/characters/movers/support.js +18 -7
  230. package/modules/characters/npcAvoid.js +15 -12
  231. package/modules/characters/npcSim.js +75 -25
  232. package/modules/characters/npcView.js +13 -6
  233. package/modules/characters/pathAsync.js +74 -24
  234. package/modules/characters/pathJob.js +38 -21
  235. package/modules/characters/player.js +59 -47
  236. package/modules/characters/seat.js +56 -0
  237. package/modules/characters/vehicle.contract.js +8 -5
  238. package/modules/characters/walkTo.js +31 -18
  239. package/modules/collision/Collision.js +44 -26
  240. package/modules/collision/contract.js +2 -2
  241. package/modules/collision/grid.js +6 -1
  242. package/modules/content/explain.js +1 -1
  243. package/modules/content/fields.js +3 -3
  244. package/modules/content/ids.js +3 -1
  245. package/modules/content/index.js +83 -27
  246. package/modules/content/loader.js +110 -130
  247. package/modules/content/markers.js +1 -1
  248. package/modules/content/models.js +48 -14
  249. package/modules/content/packs.js +2 -1
  250. package/modules/content/places.js +5 -4
  251. package/modules/content/props.js +8 -6
  252. package/modules/content/rules.js +29 -47
  253. package/modules/content/templates.js +66 -35
  254. package/modules/content/words.js +19 -6
  255. package/modules/debug/DebugPanel.js +4 -2
  256. package/modules/flow/contract.js +1 -0
  257. package/modules/flow/index.js +24 -14
  258. package/modules/gameplay/Container.js +5 -2
  259. package/modules/gameplay/Containers.js +9 -1
  260. package/modules/gameplay/Dialogue.js +82 -25
  261. package/modules/gameplay/Interactions.js +61 -32
  262. package/modules/gameplay/Inventory.js +56 -13
  263. package/modules/gameplay/Quests.js +133 -24
  264. package/modules/gameplay/boxOps.js +7 -0
  265. package/modules/gameplay/dialogueBubbles.js +14 -9
  266. package/modules/gameplay/inventoryOps.js +11 -7
  267. package/modules/gameplay/pickups.js +43 -16
  268. package/modules/gameplay/questLog.js +4 -2
  269. package/modules/gameplay/questSave.js +6 -1
  270. package/modules/gameplay/quests.contract.js +1 -1
  271. package/modules/grid/Grid.js +1 -1
  272. package/modules/grid/Layer.js +8 -4
  273. package/modules/grid/index.js +21 -15
  274. package/modules/grid/ops.js +43 -46
  275. package/modules/grid/tiles.js +1 -1
  276. package/modules/hlod/index.js +6 -3
  277. package/modules/hud/index.js +6 -4
  278. package/modules/hud/parts.js +4 -4
  279. package/modules/level/contract.js +2 -2
  280. package/modules/level/heightfield.js +17 -21
  281. package/modules/level/index.js +83 -26
  282. package/modules/level/load.js +165 -48
  283. package/modules/level/nodes.js +34 -16
  284. package/modules/lights/index.js +6 -3
  285. package/modules/lights/sources.js +3 -1
  286. package/modules/music/Music.js +4 -2
  287. package/modules/nav/contract.js +7 -5
  288. package/modules/nav/index.js +174 -44
  289. package/modules/nav/navPath.js +45 -10
  290. package/modules/net/index.js +1 -1
  291. package/modules/particles/Particles.js +85 -22
  292. package/modules/particles/effect.js +80 -28
  293. package/modules/particles/shaders.js +17 -0
  294. package/modules/photo/Photo.js +12 -10
  295. package/modules/rigid/RigidBodies.js +200 -57
  296. package/modules/rigid/Vehicles.js +15 -5
  297. package/modules/rigid/collider3d.contract.js +26 -0
  298. package/modules/rigid/ragdoll.js +55 -44
  299. package/modules/rigid/ragdollBones.js +83 -33
  300. package/modules/rigid/refresh.js +10 -0
  301. package/modules/rigid/sync.js +46 -15
  302. package/modules/settings/Settings.js +84 -37
  303. package/modules/settings/apply.js +15 -8
  304. package/modules/settings/sections.js +7 -4
  305. package/modules/settings/strings.js +2 -2
  306. package/modules/sky/skyModule.js +3 -1
  307. package/modules/swarm/Swarm.js +16 -6
  308. package/modules/terrain/ChunkManager.js +10 -16
  309. package/modules/terrain/index.js +17 -11
  310. package/modules/terrain/terrainEdit.js +13 -2
  311. package/modules/terrain/terrainGen.js +5 -3
  312. package/modules/terrain/terrainShape.js +1 -1
  313. package/modules/timeline/Timeline.js +58 -26
  314. package/modules/timeline/Tween.js +19 -13
  315. package/modules/timeline/shots.js +19 -10
  316. package/modules/triggers/index.js +87 -20
  317. package/modules/vegetation/Vegetation.js +4 -3
  318. package/modules/vegetation/draw.js +16 -0
  319. package/modules/vegetation/groundChunks.js +10 -7
  320. package/modules/vegetation/index.js +30 -7
  321. package/modules/water/Water.js +6 -2
  322. package/modules/weather/Weather.js +16 -15
  323. package/modules/weather/weatherDraw.js +7 -6
  324. package/modules/world/World.js +20 -7
  325. package/modules/world/explain.js +1 -1
  326. package/modules/world/index.js +13 -6
  327. package/modules/world/persist.js +23 -8
  328. package/modules/world/pos.js +4 -4
  329. package/modules/world/records.js +13 -7
  330. package/modules/world/sim.js +74 -23
  331. package/modules/world/simFar.js +2 -2
  332. package/modules/world/state.js +31 -6
  333. package/modules/world/thingSource.js +16 -3
  334. package/modules/world/views.js +19 -8
  335. package/package.json +7 -1
  336. package/render/PostFX.js +47 -29
  337. package/render/backend.js +5 -1
  338. package/render/fx/particles.tsl.js +8 -6
  339. package/render/fx/postWebGPU.tsl.js +3 -3
  340. package/render/layers.js +1 -1
  341. package/render/lightmap.js +23 -3
  342. package/render/occlusion.js +43 -12
  343. package/render/patches.js +2 -2
  344. package/render/postWebGL.js +4 -3
  345. package/render/probes.js +25 -0
  346. package/render/shadows.js +2 -2
  347. package/types/core.d.ts +142 -55
  348. package/types/gameplay.d.ts +92 -40
  349. package/types/generated/core/base/I18n.d.ts +2 -2
  350. package/types/generated/core/input/Input.d.ts +16 -2
  351. package/types/generated/core/input/inputSeat.d.ts +26 -0
  352. package/types/generated/core/inspect/DebugOverrides.d.ts +15 -1
  353. package/types/generated/core/ops/Ops.d.ts +2 -1
  354. package/types/generated/core/ops/control.d.ts +12 -2
  355. package/types/generated/core/saves/Saves.d.ts +26 -6
  356. package/types/generated/core/saves/session.d.ts +1 -1
  357. package/types/generated/core/scene/Views.d.ts +1 -1
  358. package/types/generated/core/stream/Stream.d.ts +6 -4
  359. package/types/generated/modules/grid/Grid.d.ts +1 -0
  360. package/types/generated/modules/particles/Particles.d.ts +4 -3
  361. package/types/generated/modules/timeline/Timeline.d.ts +5 -4
  362. package/types/generated/modules/weather/Weather.d.ts +1 -7
  363. package/types/generated/modules/world/World.d.ts +6 -4
  364. package/types/generated/render/PostFX.d.ts +6 -14
  365. package/types/nav.d.ts +36 -4
  366. package/types/physics.d.ts +55 -7
  367. package/types/pixel.d.ts +75 -0
  368. package/types/world.d.ts +14 -8
  369. package/ui/Parts.js +9 -2
  370. package/ui/theme.js +2 -2
  371. package/core/scene/engineCamera.js +0 -32
  372. package/modules/camera/projection.js +0 -21
@@ -1,7 +1,7 @@
1
1
  # Game map: styletest (generated, do not edit by hand)
2
2
 
3
3
  > Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /styletest.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.
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()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
5
5
 
6
6
  Content: items 3 · npcs 1 · places 2 · props 12 (from templates 6) · templates 6 · vegetation 5
7
7
 
@@ -23,7 +23,7 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
23
23
 
24
24
  ## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
25
25
 
26
- - world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
26
+ - world: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/world.md`
27
27
  - terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
28
28
  - vegetation: `node_modules/threedog/docs/recipes/36-ground-plants.md` · `node_modules/threedog/docs/api/vegetation.md`
29
29
  - calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
@@ -32,7 +32,7 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
32
32
  - water: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/water.md`
33
33
  - collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
34
34
  - rigid: `node_modules/threedog/docs/recipes/11-vehicles.md` · `node_modules/threedog/docs/api/rigid.md`
35
- - characters: `node_modules/threedog/docs/recipes/13-animation.md` · `node_modules/threedog/docs/api/characters.md`
35
+ - characters: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/characters.md`
36
36
  - …9 more modules: their pages are in `node_modules/threedog/docs/api/`
37
37
 
38
38
  Not used yet (check these before writing the system yourself):
@@ -1,7 +1,7 @@
1
1
  # Game map: webgpu-tsl (generated, do not edit by hand)
2
2
 
3
3
  > Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /webgpu-tsl.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.
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()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
5
5
 
6
6
  Content: none (no content/ folder)
7
7
 
@@ -1 +1 @@
1
- {"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":1793906610000,"from":0,"count":4,"indexIds":0,"positional":[]},"content/audio.js":{"kind":"audio","mtime":1793906610000,"from":0,"count":3,"indexIds":0,"positional":[]},"content/bodies.js":{"kind":"bodies","mtime":1793906610000,"from":0,"count":8,"indexIds":0,"positional":[]},"content/containers.js":{"kind":"containers","mtime":1793906610000,"from":0,"count":1,"indexIds":0,"positional":[]},"content/dialogues.js":{"kind":"dialogues","mtime":1793906610000,"from":0,"count":1,"indexIds":0,"positional":[]},"content/items.js":{"kind":"items","mtime":1793906610000,"from":0,"count":4,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1793906610000,"from":0,"count":1,"indexIds":0,"positional":[]},"content/pickups.js":{"kind":"pickups","mtime":1793906610000,"from":0,"count":8,"indexIds":8,"positional":[0,1,2,3,4,5,6,7]},"content/places.js":{"kind":"places","mtime":1793906610000,"from":0,"count":3,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1793906610000,"from":0,"count":8,"indexIds":0,"positional":[]},"content/quests.js":{"kind":"quests","mtime":1793906610000,"from":0,"count":1,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1793906610000,"from":0,"count":1,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1793906610000,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"save":[{"file":"content/actions.js","kind":"actions","line":4,"placed":false}],"load":[{"file":"content/actions.js","kind":"actions","line":5,"placed":false}],"kick":[{"file":"content/actions.js","kind":"actions","line":6,"placed":false}],"chop":[{"file":"content/actions.js","kind":"actions","line":7,"placed":false}],"sounds":[{"file":"content/audio.js","kind":"audio","line":7,"placed":false}],"ambience":[{"file":"content/audio.js","kind":"audio","line":14,"placed":false}],"footsteps":[{"file":"content/audio.js","kind":"audio","line":23,"placed":false}],"crate-0":[{"file":"content/bodies.js","kind":"bodies","line":4,"placed":false}],"crate-1":[{"file":"content/bodies.js","kind":"bodies","line":5,"placed":false}],"crate-2":[{"file":"content/bodies.js","kind":"bodies","line":6,"placed":false}],"crate-3":[{"file":"content/bodies.js","kind":"bodies","line":7,"placed":false}],"crate-4":[{"file":"content/bodies.js","kind":"bodies","line":8,"placed":false}],"crate-5":[{"file":"content/bodies.js","kind":"bodies","line":9,"placed":false}],"ball":[{"file":"content/bodies.js","kind":"bodies","line":10,"placed":false}],"barrel":[{"file":"content/bodies.js","kind":"bodies","line":11,"placed":false}],"fisher-basket":[{"file":"content/containers.js","kind":"containers","line":3,"placed":false}],"fisher":[{"file":"content/dialogues.js","kind":"dialogues","line":4,"placed":false},{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"film":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"berry":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"feather":[{"file":"content/items.js","kind":"items","line":5,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":6,"placed":false}],"pickup:feather:0":[{"file":"content/pickups.js","kind":"pickups","line":3,"placed":true}],"pickup:berry:1":[{"file":"content/pickups.js","kind":"pickups","line":4,"placed":true}],"pickup:berry:2":[{"file":"content/pickups.js","kind":"pickups","line":5,"placed":true}],"pickup:feather:3":[{"file":"content/pickups.js","kind":"pickups","line":6,"placed":true}],"pickup:berry:4":[{"file":"content/pickups.js","kind":"pickups","line":7,"placed":true}],"pickup:berry:5":[{"file":"content/pickups.js","kind":"pickups","line":8,"placed":true}],"pickup:feather:6":[{"file":"content/pickups.js","kind":"pickups","line":9,"placed":true}],"pickup:berry:7":[{"file":"content/pickups.js","kind":"pickups","line":10,"placed":true}],"home":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"river":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":5,"placed":false}],"prop:pine:0":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"prop:pine:1":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"prop:roundTree:2":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"prop:rock:3":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"prop:rock:4":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"prop:flower:5":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"prop:flower:6":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"cabin":[{"file":"content/props.js","kind":"props","line":11,"placed":true},{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"first-light":[{"file":"content/quests.js","kind":"quests","line":4,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":5,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":11,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":17,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":21,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":26,"placed":false}]}}
1
+ {"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":1794045415000,"size":458,"from":0,"count":4,"indexIds":0,"positional":[]},"content/audio.js":{"kind":"audio","mtime":1794045415000,"size":2152,"from":0,"count":3,"indexIds":0,"positional":[]},"content/bodies.js":{"kind":"bodies","mtime":1794045415000,"size":838,"from":0,"count":8,"indexIds":0,"positional":[]},"content/containers.js":{"kind":"containers","mtime":1794045415000,"size":252,"from":0,"count":1,"indexIds":0,"positional":[]},"content/dialogues.js":{"kind":"dialogues","mtime":1794045415000,"size":1861,"from":0,"count":1,"indexIds":0,"positional":[]},"content/items.js":{"kind":"items","mtime":1794045415000,"size":589,"from":0,"count":4,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1794045415000,"size":654,"from":0,"count":1,"indexIds":0,"positional":[]},"content/pickups.js":{"kind":"pickups","mtime":1794045415000,"size":699,"from":0,"count":8,"indexIds":8,"positional":[0,1,2,3,4,5,6,7]},"content/places.js":{"kind":"places","mtime":1794045415000,"size":498,"from":0,"count":3,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794045415000,"size":1123,"from":0,"count":8,"indexIds":0,"positional":[]},"content/quests.js":{"kind":"quests","mtime":1794045415000,"size":825,"from":0,"count":1,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794045415000,"size":484,"from":0,"count":1,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794045415000,"size":1967,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"save":[{"file":"content/actions.js","kind":"actions","line":4,"placed":false}],"load":[{"file":"content/actions.js","kind":"actions","line":5,"placed":false}],"kick":[{"file":"content/actions.js","kind":"actions","line":6,"placed":false}],"chop":[{"file":"content/actions.js","kind":"actions","line":7,"placed":false}],"sounds":[{"file":"content/audio.js","kind":"audio","line":7,"placed":false}],"ambience":[{"file":"content/audio.js","kind":"audio","line":14,"placed":false}],"footsteps":[{"file":"content/audio.js","kind":"audio","line":23,"placed":false}],"crate-0":[{"file":"content/bodies.js","kind":"bodies","line":4,"placed":false}],"crate-1":[{"file":"content/bodies.js","kind":"bodies","line":5,"placed":false}],"crate-2":[{"file":"content/bodies.js","kind":"bodies","line":6,"placed":false}],"crate-3":[{"file":"content/bodies.js","kind":"bodies","line":7,"placed":false}],"crate-4":[{"file":"content/bodies.js","kind":"bodies","line":8,"placed":false}],"crate-5":[{"file":"content/bodies.js","kind":"bodies","line":9,"placed":false}],"ball":[{"file":"content/bodies.js","kind":"bodies","line":10,"placed":false}],"barrel":[{"file":"content/bodies.js","kind":"bodies","line":11,"placed":false}],"fisher-basket":[{"file":"content/containers.js","kind":"containers","line":3,"placed":false}],"fisher":[{"file":"content/dialogues.js","kind":"dialogues","line":4,"placed":false},{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"film":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"berry":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"feather":[{"file":"content/items.js","kind":"items","line":5,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":6,"placed":false}],"pickup:feather:0":[{"file":"content/pickups.js","kind":"pickups","line":3,"placed":true}],"pickup:berry:1":[{"file":"content/pickups.js","kind":"pickups","line":4,"placed":true}],"pickup:berry:2":[{"file":"content/pickups.js","kind":"pickups","line":5,"placed":true}],"pickup:feather:3":[{"file":"content/pickups.js","kind":"pickups","line":6,"placed":true}],"pickup:berry:4":[{"file":"content/pickups.js","kind":"pickups","line":7,"placed":true}],"pickup:berry:5":[{"file":"content/pickups.js","kind":"pickups","line":8,"placed":true}],"pickup:feather:6":[{"file":"content/pickups.js","kind":"pickups","line":9,"placed":true}],"pickup:berry:7":[{"file":"content/pickups.js","kind":"pickups","line":10,"placed":true}],"home":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"river":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":5,"placed":false}],"prop:pine:0":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"prop:pine:1":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"prop:roundTree:2":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"prop:rock:3":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"prop:rock:4":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"prop:flower:5":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"prop:flower:6":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"cabin":[{"file":"content/props.js","kind":"props","line":11,"placed":true},{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"first-light":[{"file":"content/quests.js","kind":"quests","line":4,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":5,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":11,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":17,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":21,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":26,"placed":false}]}}
@@ -1,7 +1,7 @@
1
1
  # Game map: world (generated, do not edit by hand)
2
2
 
3
3
  > Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /, 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.
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()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
5
5
 
6
6
  Content: actions 4 · audio 3 · containers 1 · dialogues 1 · items 4 · npcs 1 · pickups 8 · places 3 · props 8 (from templates 1) · quests 1 · templates 1 · vegetation 5 · kinds: bodies 8
7
7
 
@@ -26,10 +26,11 @@ Content: actions 4 · audio 3 · containers 1 · dialogues 1 · items 4 · npcs
26
26
  - particles
27
27
  - music ({ duckDialogue: 0.35 })
28
28
  - hud
29
+ - content
29
30
 
30
31
  ## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
31
32
 
32
- - world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
33
+ - world: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/world.md`
33
34
  - terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
34
35
  - vegetation: `node_modules/threedog/docs/recipes/36-ground-plants.md` · `node_modules/threedog/docs/api/vegetation.md`
35
36
  - calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
@@ -38,8 +39,8 @@ Content: actions 4 · audio 3 · containers 1 · dialogues 1 · items 4 · npcs
38
39
  - water: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/water.md`
39
40
  - collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
40
41
  - rigid: `node_modules/threedog/docs/recipes/11-vehicles.md` · `node_modules/threedog/docs/api/rigid.md`
41
- - characters: `node_modules/threedog/docs/recipes/13-animation.md` · `node_modules/threedog/docs/api/characters.md`
42
- - …13 more modules: their pages are in `node_modules/threedog/docs/api/`
42
+ - characters: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/characters.md`
43
+ - …14 more modules: their pages are in `node_modules/threedog/docs/api/`
43
44
 
44
45
  Not used yet (check these before writing the system yourself):
45
46
 
@@ -136,8 +136,8 @@ engine.onFrame(() => {
136
136
  // ---------- 7. Chop trees (world-change record: chopped trees are saved and regrow after 2 minutes) ----------
137
137
  // An op, so the key, the dev bridge and tests share it and the wood lands in a fixed step, not a frame callback
138
138
  const nearTree = (e, ctx) => {
139
- const p = e.world?.get(ctx.actor)?.position ?? e.player.position;
140
- return e.vegetation.instanceAt(p, { radius: 2.5, species: '松树' }) || e.vegetation.instanceAt(p, { radius: 2.5, species: '圆树' });
139
+ const p = e.actorPosition(ctx.actor);
140
+ return p && (e.vegetation.instanceAt(p, { radius: 2.5, species: '松树' }) || e.vegetation.instanceAt(p, { radius: 2.5, species: '圆树' }));
141
141
  };
142
142
  engine.ops.define('tree.chop', {
143
143
  desc: 'Chop the nearest tree for wood',
@@ -146,7 +146,7 @@ engine.ops.define('tree.chop', {
146
146
  const tree = nearTree(e, ctx);
147
147
  e.vegetation.removeInstance(tree.species, tree.cx, tree.cz, tree.id, { regrowSeconds: 120 });
148
148
  e.particles.emit('leaves', { x: tree.position.x, y: tree.position.y + 3, z: tree.position.z }, { count: 30 });
149
- e.inventory.add('wood', 2);
149
+ e.inventory.of(ctx.actor).add('wood', 2);
150
150
  },
151
151
  reasons: { noTree: 'No tree within 2.5 m' },
152
152
  });
package/index.d.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  //
18
18
  // When the engine's public API changes (new export, changed parameter), update this file too; `npm run types` checks that every export of index.js is declared.
19
19
 
20
- import type { Engine, EngineOptions, ModuleDef, ModuleInput, PictureSlot } from './types/core';
20
+ import type { Engine, EngineOptions, ModuleDef, ModuleInput, PictureSlot, Ground } from './types/core';
21
21
  import type { Ease, EaseName, BufferGeometry, ColorLike, Material, Vector3, PositionLike } from './types/common';
22
22
  import type {
23
23
  TerrainOptions, TerrainConfig, TerrainGen, Terrain, Vegetation, VegetationModuleOptions, Sky, SkyOptions, Calendar, CalendarOptions, Weather, WeatherOptions, WeatherPreset,
@@ -25,7 +25,7 @@ import type {
25
25
  } from './types/world';
26
26
  import type { Nav, NavOptions } from './types/nav';
27
27
  import type {
28
- CollisionOptions, Collision, RigidOptions, RigidBodies, CameraRig, FollowCameraOptions, FirstPersonCameraOptions,
28
+ CollisionOptions, Collision, RigidOptions, RigidBodies, Collider3D, SweepHit, RagdollPart, CameraRig, FollowCameraOptions, FirstPersonCameraOptions,
29
29
  FixedCameraOptions, RtsCameraOptions,
30
30
  } from './types/physics';
31
31
  import type {
@@ -35,6 +35,7 @@ import type {
35
35
  Timeline, TimelineOptions, Character, NPC, UIWindow, WindowOptions,
36
36
  Content, Flow, FlowOptions, Hud, HudOptions, ScreenPoint, UIFocus, FocusHandle,
37
37
  } from './types/gameplay';
38
+ import type { TerrainDraw, VegetationDraw } from './types/world';
38
39
  import type { PostEffect } from './types/generated/render/PostFX';
39
40
  // Local bindings for the generated module factories (export { x } from re-exports below do not create them), used by OpenWorldOptions
40
41
  import type { sky } from './types/generated/modules/sky/skyModule';
@@ -114,10 +115,12 @@ export function openWorld(opts: OpenWorldOptions): ModuleDef[];
114
115
  // Modules (each function returns a module for engine.use())
115
116
  // ======================================================================
116
117
 
117
- /** Procedural terrain -> engine.terrain */
118
- export function terrain(opts?: TerrainOptions): ModuleDef<Terrain>;
118
+ /** Procedural terrain -> engine.terrain, and engine.terrainDraw for its drawing */
119
+ export function terrain(opts?: TerrainOptions): [ModuleDef<Terrain>, ModuleDef<TerrainDraw>];
120
+ /** One ground slot over several providers: terrain({ part: true }) / level({ part: true }) answer inside their region, higher priority wins where regions overlap. region: (x, z) => boolean | { volume } (asked at y 0); omitted = everywhere */
121
+ export function compositeGround(opts: { parts: Array<{ of?: 'terrain' | 'level'; ground?: Ground; region?: ((x: number, z: number) => boolean) | { volume: { contains(p: { x: number; y: number; z: number }): boolean } }; priority?: number }> }): ModuleDef<void>;
119
122
  /** Vegetation -> engine.vegetation: on terrain chunks when terrain() is installed first (no options), else on its own chunks over any ground (a level, setGround) */
120
- export function vegetation(opts?: VegetationModuleOptions): ModuleDef<Vegetation>;
123
+ export function vegetation(opts?: VegetationModuleOptions): [ModuleDef<Vegetation>, ModuleDef<VegetationDraw>];
121
124
  // Migrated: sky() is generated from the JSDoc in modules/sky/skyModule.js
122
125
  export { sky } from './types/generated/modules/sky/skyModule';
123
126
  // calendar() is generated from the JSDoc in modules/calendar/index.js
package/index.js CHANGED
@@ -14,6 +14,7 @@
14
14
  // Or install the usual open-world set at once with a preset: engine.use(openWorld({ seed: 7, camera: 'follow', terrain: terrainPreset() }))
15
15
  import * as THREE from 'three';
16
16
  import { Engine } from './core/engine/Engine.js';
17
+ import { CAP_CONTRACTS } from './core/engine/moduleSlots.js';
17
18
  import { terrain } from './modules/terrain/index.js';
18
19
  import { vegetation } from './modules/vegetation/index.js';
19
20
  import { sky } from './modules/sky/skyModule.js';
@@ -48,10 +49,28 @@ import { flow } from './modules/flow/index.js';
48
49
  import { hud } from './modules/hud/index.js';
49
50
  import { world } from './modules/world/index.js';
50
51
  import { grids } from './modules/grid/index.js';
52
+ import calendarContract from './modules/calendar/contract.js';
53
+ import cameraContract from './modules/camera/contract.js';
54
+ import charactersContract from './modules/characters/contract.js';
55
+ import collisionContract from './modules/collision/contract.js';
56
+ import flowContract from './modules/flow/contract.js';
57
+ import dialogueContract from './modules/gameplay/dialogue.contract.js';
58
+ import interactionsContract from './modules/gameplay/interactions.contract.js';
59
+ import inventoryContract from './modules/gameplay/inventory.contract.js';
60
+ import questsContract from './modules/gameplay/quests.contract.js';
61
+ import levelContract from './modules/level/contract.js';
62
+ import navContract from './modules/nav/contract.js';
63
+ import particlesContract from './modules/particles/contract.js';
64
+ import collider3dContract from './modules/rigid/collider3d.contract.js';
51
65
  import { checkOptions, DEV, fmt } from './core/base/validate.js';
52
66
  import { readParams, keysSchema } from './core/base/params.js';
53
67
  import { codedError } from './core/base/errorHints.js';
54
68
 
69
+ // The contract of each capability, so a provider is checked where it binds even when the engine's own module of that name was never installed. Here and not in core: core imports
70
+ // no module. Plain data, a few KB; a build cannot drop it behind DEV (only the literal import.meta.env test folds). tools/tests/contracts.mjs fails on a contract left out.
71
+ for (const c of [calendarContract, cameraContract, charactersContract, collisionContract, flowContract, dialogueContract, interactionsContract, inventoryContract, questsContract,
72
+ levelContract, navContract, particlesContract, collider3dContract]) CAP_CONTRACTS.set(c.name, c);
73
+
55
74
  // Engine and Animator are exported for types and instanceof; make them with createEngine / engine.assets.animate (AI.md entry-point table)
56
75
  export { THREE, Engine };
57
76
  export { Animator } from './core/assets/Animator.js';
@@ -65,6 +84,7 @@ export { checkOptions }; // only for extensible data (game-defined fields); an
65
84
  export { contentParts } from './modules/content/parts.js'; // one content kind split over files: content/props/*.js joined in file-name order (recipes/30)
66
85
  export { threePatches } from './core/scene/threePatches.js'; // the engine's page-wide changes to three.js classes: list(), off(id) (THREE.md "Global changes")
67
86
  export { readParams } from './core/base/params.js'; // params schema for game-made modules (recipes/14): validated, defaults filled, shown by engine.catalog()
87
+ export { compositeGround } from './core/scene/compositeGround.js'; // several ground providers (terrain({ part: true }), level({ part: true })) answering by region; holds the 'ground' slot
68
88
  export { createTerrain } from './modules/terrain/index.js';
69
89
  export { Character, NPC } from './modules/characters/index.js';
70
90
  export { presets } from './presets.js'; // opt-in gameplay presets (weather tables, calendars, player feel, camera): never applied by the engine itself
@@ -111,7 +131,8 @@ export function openWorld(opts = {}) {
111
131
  if (camera === undefined) throw codedError('open-world-camera', OW_ERR.noCamera); // no default camera feel: the game names one (genericity rule)
112
132
  if (typeof camera === 'string' && !CAMERAS[camera]) throw codedError('preset-option', fmt(OW_ERR.camera, { k: camera, list: Object.keys(CAMERAS).join(', ') }));
113
133
  const w = opts.weather;
114
- const short = { terrain: { seed, viewChunks, density, flatten, viewFog: true }, calendar: { time, dayLength }, weather: { start: typeof w === 'string' ? w : undefined, auto: autoWeather } }; // no start: weather() picks one from the game's table
134
+ // characters: a walking game's preset chooses to bring what falls back; the engine alone never does. openWorld({ characters: { fall: false } }) leaves it to the game
135
+ const short = { terrain: { seed, viewChunks, density, flatten, viewFog: true }, calendar: { time, dayLength }, weather: { start: typeof w === 'string' ? w : undefined, auto: autoWeather }, characters: { fall: 'rescue' } }; // no start: weather() picks one from the game's table
115
136
  const part = k => {
116
137
  const v = opts[k];
117
138
  if (v === false || (k === 'debug' && v === undefined && !DEV)) return null;
package/llms.txt CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > A web 3D game engine on three.js 0.187 (plain three.js, no React): core and modules installed with engine.use. It ships no art: each game draws its own picture (plain three.js in its picture/ folder, and assets).
4
4
 
5
- Reading order: docs/AI.md (the index: one line per task) -> the recipe for the task -> docs/api/<module>.md for details -> the game's GAMEMAP.md.
5
+ Taking over a game: its status notes first. A new feature: docs/AI.md or threedog how, then the recipe, then docs/api/<module>.md.
6
6
 
7
7
  ## Start
8
8
 
@@ -65,3 +65,4 @@ Reading order: docs/AI.md (the index: one line per task) -> the recipe for the t
65
65
  - [63-third-person-start](docs/recipes/63-third-person-start.md): Third-person start: walking, camera, save, pause, menu
66
66
  - [64-particles](docs/recipes/64-particles.md): Particles: dust, smoke, sparks, splashes
67
67
  - [65-swarm](docs/recipes/65-swarm.md): Swarm: shots, crowds, pickups, debris by the thousand
68
+ - [66-common-tasks](docs/recipes/66-common-tasks.md): Common tasks, complete
@@ -82,7 +82,7 @@ export class Ambience {
82
82
  const e = this.engine, p = this.position; let n = 0;
83
83
  for (let ang = 0; ang < 6.28; ang += 1.05) {
84
84
  const x = p.x + Math.cos(ang) * radius, z = p.z + Math.sin(ang) * radius;
85
- if (e.surface(x, z) < e.waterAt(x, z)) n += 1 / 6;
85
+ if (e.surface(x, z, p.y) < e.waterAt(x, z, p.y)) n += 1 / 6;
86
86
  }
87
87
  return n;
88
88
  }
@@ -177,7 +177,7 @@ const AMBIENCE_PARAMS = keysSchema(['rules', 'interval']);
177
177
  export function ambience(opts = {}) {
178
178
  readParams('ambience', AMBIENCE_PARAMS, opts);
179
179
  let a = null;
180
- return { name: 'ambience', type: 'picture', params: AMBIENCE_PARAMS, options: opts, label: 'Ambience', stage: 'late',
180
+ return { name: 'ambience', skipKind: 'none', type: 'picture', params: AMBIENCE_PARAMS, options: opts, label: 'Ambience', stage: 'late',
181
181
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.ambience': '环境音' }, en: { 'module.ambience': 'ambience' } });
182
182
  builtInSounds(e.assets, SYNTHS, { bus: 'ambience' }); // sound assets wind / rain / water / birds / crickets, silent until audio.sounds names them
183
183
  a = new Ambience(e, opts);
@@ -185,7 +185,7 @@ export function ambience(opts = {}) {
185
185
  // measures for data rules (content packs hold no functions). Each reads the listener position itself: music rules call them too,
186
186
  // and ambience refreshes this.position only while it has rules of its own
187
187
  ctx.track(e.audio.measure('nearWater', () => { a._listen(); return a.nearWater(12); }));
188
- ctx.track(e.audio.measure('altitude', () => { const p = a._listen(); return Math.max(0, e.surface(p.x, p.z)); }));
188
+ ctx.track(e.audio.measure('altitude', () => { const p = a._listen(); return Math.max(0, e.surface(p.x, p.z, p.y)); }));
189
189
  return a;
190
190
  },
191
191
  frame(dt) { a.update(dt); },
@@ -198,3 +198,5 @@ export function ambience(opts = {}) {
198
198
  return { rules: a._rules.length, on, ...(failed.length ? { failed } : {}), ...(locked ? { audioLocked: 'audio starts after a real click or key press; a bridge page has none, so `on` stays empty here whatever the position' } : {}) };
199
199
  } };
200
200
  }
201
+
202
+ export const handRolled = 'none: sounds by place are data, and a hand-made version has no one shape in code';
@@ -7,7 +7,7 @@ import { readParams, keysSchema } from '../../core/base/params.js';
7
7
  import { parseClock } from '../../core/time/dayTime.js';
8
8
  import { codedError, coded } from '../../core/base/errorHints.js';
9
9
  import { warnOnce } from '../../core/base/validate.js';
10
- import { saveValues } from '../../core/saves/saveValues.js';
10
+ import { saveValues, SAVE_MAX_SECONDS } from '../../core/base/saveValues.js';
11
11
  /** @import { ModuleDef } from '../../types/core' */
12
12
  /** @import { CalendarOptions } from '../../types/world' */
13
13
 
@@ -26,7 +26,7 @@ export function calendar(opts = {}) {
26
26
  readParams('calendar', CALENDAR_PARAMS, opts);
27
27
  let c = null;
28
28
  return {
29
- name: 'calendar', type: 'world', provides: ['calendar'], label: 'Calendar', params: CALENDAR_PARAMS, options: opts, stage: 'environment', before: ['sky'],
29
+ name: 'calendar', skipKind: 'exact', type: 'world', provides: ['calendar'], label: 'Calendar', params: CALENDAR_PARAMS, options: opts, stage: 'environment', before: ['sky'],
30
30
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.calendar': '日历' }, en: { 'module.calendar': 'calendar' } });
31
31
  // sky({ time }) is the fixed time drawn without a calendar: installed before this one it would now sit unused, so say so (sky checks the other order)
32
32
  if (e.modules.get('sky')?.options?.time != null) warnOnce(coded('calendar-option', STRINGS.skyTime), 'sky-time-calendar');
@@ -37,17 +37,17 @@ export function calendar(opts = {}) {
37
37
  ctx.track(e.audio.measure('daylight', () => c.daylight));
38
38
  ctx.track(e.audio.measure('timeOfDay', () => c.timeOfDay)); // render/daylight.js writes uTimeOfDay from it
39
39
  // between() ranges re-check whether they are inside after anything that moves the clock without stepping
40
- for (const name of ['engine:ready', 'save:loaded', 'state:applied']) ctx.track(e.events.on(name, () => c._sched.syncRanges()));
40
+ ctx.track(e.events.on('state:replaced', () => c._sched.syncRanges()));
41
41
  // the day and time of day are views of the 'calendar' channel: its events and clock timers run right after the channel moves (a step or a skip segment)
42
42
  ctx.track(e.time.onMove(() => c.moved()));
43
43
  // at: the calendar channel second the time and day belong to, so the origin is right whichever part (calendar or time) loads first
44
- e.saves.register('calendar', { save: () => ({ time: c.timeOfDay, day: c.day, at: e.clock.now }),
44
+ ctx.saves.register('calendar', { notAtomic: 'the clock moves it every step, and an op that sets the time means it to stay', save: () => ({ time: c.timeOfDay, day: c.day, at: e.clock.now }),
45
45
  // saved numbers pass saveValues as clock / random / time do: a time 'abc' showed clock 'NaN:NaN' and a day -5 broke seasons (one warning per part)
46
46
  load: d => {
47
47
  if (d) {
48
48
  const v = saveValues('calendar');
49
49
  const tod = v.num(d.time, 'time', { min: 0, max: 1, fallback: c.timeOfDay }) % 1; // 1 is the next midnight, as calendar({ time })
50
- const day = v.num(d.day, 'day', { min: 1, int: true, fallback: c.day });
50
+ const day = v.num(d.day, 'day', { min: 1, max: SAVE_MAX_SECONDS, int: true, fallback: c.day });
51
51
  const at = v.num(d.at, 'at', { fallback: e.clock.now });
52
52
  v.done();
53
53
  c._day0 = day; c._tod0 = tod; c._t0 = at; c._lastDay = c.day;
@@ -80,3 +80,5 @@ export function calendar(opts = {}) {
80
80
  },
81
81
  };
82
82
  }
83
+
84
+ export const handRolled = 'none: a day counter of its own is a plain number that looks like any other';
@@ -100,13 +100,13 @@ export class FirstPersonCamera {
100
100
  cam.rotation.set(this.pitch, this.yaw, Math.sin(this._bob * 0.5) * this._bobAmp * 0.15, 'YXZ');
101
101
  }
102
102
 
103
- /** Release the mouse lock when a cutscene takes over */
103
+ /** Someone else's view shows while the camera is held: the mouse goes free and the body is back, since the eye it would block is no longer where the camera is */
104
104
  onOverride(on) {
105
- if (on) releaseLock(this, true);
105
+ if (on) { releaseLock(this, true); this._unhide(); } else this._hide();
106
106
  }
107
107
 
108
108
  // also on every child added to the target (a held item, a swapped model): hide what is new
109
- _hide() { if (this.hideTarget && this.target) this._hideTarget(); }
109
+ _hide() { if (this.hideTarget && this.target && !this.engine.cameraOverride) this._hideTarget(); }
110
110
  }
111
111
 
112
112
  Object.assign(FirstPersonCamera.prototype, YAW_RIG, HIDE_RIG); // forward / right / focusPoint; _hideTarget / _unhide / _shadowLayers
@@ -16,8 +16,8 @@
16
16
  // engine.cameraRig.blend('garden', { seconds: 1.5 });
17
17
  import * as THREE from 'three';
18
18
  import { rigModule, defineRig, viewForward, rightOf, rigPlaced } from './common.js';
19
- import { setProjection } from './projection.js';
20
- import { setFov } from '../../core/scene/view.js';
19
+ import { rigPixelSnap, checkPixelView } from './pixelSnap.js';
20
+ import { baseFov, shotFov, setProjection } from '../../core/scene/view.js';
21
21
  import { vec3 } from '../../core/base/math.js';
22
22
  import { ease as easing } from '../../core/base/easing.js';
23
23
  import { warnMissing } from '../../core/base/validate.js';
@@ -33,22 +33,25 @@ export class FixedCamera {
33
33
  * single-shot shorthand: fixedCamera({ position, lookAt, projection, size }); start initial shot;
34
34
  * auto false | 'nearest' (every autoInterval seconds pick the nearest shot); hysteresis how many meters closer a new shot must be to win (avoids flip-flopping);
35
35
  * triggerBlend transition seconds for trigger-zone switches (0 = hard cut); trackHeight how high on the character a track shot looks; trackSmoothing head-tracking smoothness;
36
- * holdDirection keep the direction at a shot change until the key is released (classic fixed-camera controls)
36
+ * holdDirection keep the direction at a shot change until the key is released (classic fixed-camera controls);
37
+ * pixelSnap { pixelsPerMeter, bounds } art-pixel rounding: every shot is orthographic with no size, pixelSnap decides the view height (pixelSnap.js)
37
38
  */
38
39
  constructor(engine, { shots = {}, start = null, auto = false, autoInterval = 0.25, hysteresis = 2, triggerBlend = 0,
39
- trackHeight = 1.2, trackSmoothing = 8, holdDirection = true, ease = 'inOutCubic', ...rest } = {}) {
40
+ trackHeight = 1.2, trackSmoothing = 8, holdDirection = true, ease = 'inOutCubic', pixelSnap = null, ...rest } = {}) {
40
41
  readParams('fixedCamera()', keysSchema(SHOT_KEYS), rest); // top-level shot fields: the one-shot form setCamera('fixed', { position, lookAt, projection, size })
41
42
  if (!Object.keys(shots).length && rest.position) shots = { main: rest };
42
43
  else if (Object.keys(rest).length) throw codedError('camera-option', `fixedCamera(): top-level ${Object.keys(rest).join(', ')} are the one-shot form `
43
44
  + `(no shots, with position); with shots put them in shots.<name>`);
44
45
  Object.assign(this, { engine, auto, autoInterval, hysteresis, triggerBlend, trackHeight, trackSmoothing, holdDirection, ease });
46
+ /** Art-pixel rounding (.grid, .error, .agrees) or null */
47
+ this.pixelSnap = rigPixelSnap(engine, pixelSnap, 'fixedCamera');
48
+ this._shown = undefined; // the size last asked of engine.camera (null: a perspective shot)
45
49
  this.shots = {};
46
50
  for (const [n, s] of Object.entries(shots)) this.add(n, s);
47
51
  this.target = null;
48
52
  this.current = null;
49
53
  this._blend = null; this._autoT = 0; this._held = null;
50
54
  this._look = new THREE.Vector3();
51
- this._baseFov = engine.camera.fov;
52
55
  this._dir = { f: { x: 0, z: -1 }, r: { x: 1, z: 0 } };
53
56
  this._onZone = null; // trigger:enter listener, only while this rig is the active camera (onEnter / onExit)
54
57
  const first = start || Object.keys(this.shots)[0];
@@ -57,25 +60,34 @@ export class FixedCamera {
57
60
 
58
61
  /** @internal the camera module switched to this rig: camera:<shot> trigger zones cut to their shot from now on */
59
62
  onEnter() {
63
+ this._shown = undefined; // the switch of rigs put the camera back to perspective: the next _place asks for this shot's view again
64
+ this.pixelSnap?.enter();
60
65
  this._onZone ??= this.engine.events.on('trigger:enter', p => {
61
66
  const tag = p.tag;
62
67
  const m = typeof tag === 'string' && tag.match(/^camera:(.+)$/);
63
- if (m && this.shots[m[1]]) this.triggerBlend > 0 ? this.blend(m[1], { seconds: this.triggerBlend }) : this.cut(m[1]);
68
+ if (m && this.shots[m[1]]) this._moveOn(m[1]);
64
69
  });
65
70
  }
66
71
  /** @internal switched away (or replaced on a new playthrough): a rig that is not the camera never moves it (review 0.4 modules-a B1) */
67
- onExit() { this._onZone?.remove(); this._onZone = null; this._blend?.res(); this._blend = null; } // await blend() never hangs: no update runs here any more
72
+ onExit() { this._onZone?.remove(); this._onZone = null; this._blend?.res(); this._blend = null; shotFov(this.engine, null); } // await blend() never hangs: no update runs here any more; a shot's fov is this rig's, the base view stays
68
73
 
69
74
  /** Add or replace a shot */
70
75
  add(name, s) {
71
76
  readParams(`fixedCamera shots.${name}`, keysSchema(SHOT_KEYS), s);
72
- if (s.projection === 'orthographic' && !(s.size > 0)) throw codedError('camera-option', `fixedCamera shots.${name}: projection 'orthographic' needs size > 0 (world units of view height)`);
73
- this.shots[name] = {
77
+ if (this.pixelSnap) checkPixelView(`fixedCamera shots.${name}`, s);
78
+ else if (s.projection === 'orthographic' && !(s.size > 0)) throw codedError('camera-option', `fixedCamera shots.${name}: projection 'orthographic' needs size > 0 (world units of view height)`);
79
+ const shot = {
74
80
  position: vec3(s.position), lookAt: s.lookAt ? vec3(s.lookAt) : null, track: !!s.track || !s.lookAt,
75
81
  fov: s.fov ?? null, size: s.projection === 'orthographic' ? s.size : null, at: s.at ? vec3(s.at) : null, trackHeight: s.trackHeight,
76
82
  };
83
+ this.shots[name] = shot;
77
84
  return this;
78
85
  }
86
+ /** A switch that comes by itself (a trigger zone, the nearest shot) */
87
+ _moveOn(name) {
88
+ if (this.triggerBlend > 0) this.blend(name, { seconds: this.triggerBlend });
89
+ else this.cut(name);
90
+ }
79
91
  follow(obj) { this.target = obj; }
80
92
  /** Cut to a shot at once */
81
93
  cut(name) {
@@ -84,7 +96,7 @@ export class FixedCamera {
84
96
  this.current = name;
85
97
  this._blend?.res(); this._blend = null; // interrupt a running blend: its Promise still resolves (await blend() never hangs)
86
98
  this._lookTarget(s, this._look);
87
- this._place(s.position, this._look, s.fov ?? this._baseFov, s.size);
99
+ this._place(s.position, this._look, s.fov ?? null, s.size);
88
100
  if (changed) { this._latchDirection(); this.engine.events.emit('camera:shot', { name }); }
89
101
  }
90
102
  /** Blend smoothly to a shot ({ seconds = 1, ease }); returns a Promise that resolves when the blend ends. blend(name, 1.5) throws in dev
@@ -92,11 +104,11 @@ export class FixedCamera {
92
104
  blend(name, opts) {
93
105
  const { seconds = 1, ease = this.ease } = readParams('cameraRig.blend()', keysSchema(BLEND_KEYS), opts);
94
106
  const s = this.shots[name]; if (!s) { warnMissing('shot', name, Object.keys(this.shots)); return Promise.resolve(); }
95
- if (seconds <= 0 || !this.current) { this.cut(name); return Promise.resolve(); }
107
+ if (seconds <= 0 || !this.current || this.engine.cameraOverride) { this.cut(name); return Promise.resolve(); } // held: nothing to blend from, the shot lands at release
96
108
  const cam = this.engine.camera;
97
109
  return new Promise(res => {
98
110
  this._blend?.res();
99
- this._blend = { from: cam.position.clone(), fromLook: this._look.clone(), fromFov: cam.fov, fromSize: cam.orthoSize || null, t: 0, dur: seconds, ease, res };
111
+ this._blend = { from: cam.position.clone(), fromLook: this._look.clone(), fromFov: cam.fov, fromSize: cam.isOrthographicCamera ? cam.top - cam.bottom : null, t: 0, dur: seconds, ease, res };
100
112
  this.current = name;
101
113
  this._latchDirection();
102
114
  this.engine.events.emit('camera:shot', { name });
@@ -115,24 +127,24 @@ export class FixedCamera {
115
127
  const n = this.nearest(this.target.position);
116
128
  if (n && n !== this.current) {
117
129
  const p = this.target.position, d = k => (this.shots[k].at || this.shots[k].position).distanceTo(p);
118
- if (d(n) + this.hysteresis < d(this.current)) this.triggerBlend > 0 ? this.blend(n, { seconds: this.triggerBlend }) : this.cut(n);
130
+ if (d(n) + this.hysteresis < d(this.current)) this._moveOn(n);
119
131
  }
120
132
  }
121
133
  const sh = this.shots[this.current]; // after the auto switch: the shot this frame shows
122
134
  const want = this._lookTarget(sh, this._want ??= new THREE.Vector3()); // scratch vectors: no per-frame allocation
123
- const fov = sh.fov ?? this._baseFov;
124
135
  if (this._blend) {
136
+ const fov = sh.fov ?? baseFov(this.engine);
125
137
  const b = this._blend; b.t += dt;
126
138
  const k = easing(b.ease)(Math.min(1, b.t / b.dur));
127
139
  const pos = (this._bp ??= new THREE.Vector3()).copy(b.from).lerp(sh.position, k), look = (this._bl ??= new THREE.Vector3()).copy(b.fromLook).lerp(want, k);
128
140
  this._look.copy(look);
129
141
  // size blends only between two orthographic shots; a perspective/orthographic mix switches to the target's mode at once
130
- this._place(pos, look, b.fromFov + (fov - b.fromFov) * k, sh.size && b.fromSize ? b.fromSize + (sh.size - b.fromSize) * k : sh.size);
142
+ this._place(pos, look, (b.fromFov ?? fov) + (fov - (b.fromFov ?? fov)) * k, sh.size && b.fromSize ? b.fromSize + (sh.size - b.fromSize) * k : sh.size);
131
143
  if (b.t >= b.dur) { this._blend = null; b.res(); }
132
144
  } else {
133
145
  if (sh.track) this._look.lerp(want, 1 - Math.exp(-this.trackSmoothing * dt));
134
146
  else this._look.copy(want);
135
- this._place(sh.position, this._look, fov, sh.size);
147
+ this._place(sh.position, this._look, sh.fov ?? null, sh.size);
136
148
  }
137
149
  // Direction: release the hold once no direction key is pressed
138
150
  const a = input.axis;
@@ -154,10 +166,12 @@ export class FixedCamera {
154
166
  return s.lookAt ? out.copy(s.lookAt) : out.set(s.position.x, s.position.y, s.position.z - 1);
155
167
  }
156
168
  _place(pos, look, fov, size = null) {
157
- const cam = this.engine.camera;
169
+ if (this.engine.cameraOverride) return; // a held camera has one writer: current and _look are what lands at release (common.js)
170
+ shotFov(this.engine, size ? null : fov); // before the projection: a hold would keep a swap waiting
171
+ // the view is asked for when it changes, so a perspective camera the game assigned during a shot stays until the next one; a height goes on any orthographic camera
172
+ if (!this.pixelSnap && (size !== this._shown || this.engine.camera.isOrthographicCamera)) { this._shown = size; setProjection(this.engine, size ? 'orthographic' : 'perspective', size); }
173
+ const cam = this.engine.camera; // read after the view: it may have just swapped
158
174
  cam.position.copy(pos); cam.lookAt(look);
159
- setProjection(cam, size ? 'orthographic' : 'perspective', size);
160
- if (Math.abs(cam.fov - fov) > 1e-3) setFov(this.engine, fov); // yields to a fov the game set itself (engine.autoView 'fov')
161
175
  rigPlaced(this.engine); // a cut between frames is the engine's own write (common.js)
162
176
  }
163
177
  _latchDirection() {
@@ -176,4 +190,4 @@ export function fixedCamera(opts = {}) { return rigModule('fixed', opts); }
176
190
  defineRig('fixed', (e, opts) => {
177
191
  return new FixedCamera(e, opts);
178
192
  }, ['shots', 'start', 'auto', 'autoInterval', 'hysteresis', 'triggerBlend', 'trackHeight', 'trackSmoothing', 'holdDirection', 'ease',
179
- 'position', 'lookAt', 'track', 'fov', 'projection', 'size', 'at']); // the last row: setCamera('fixed', { position, lookAt }) is a one-shot form
193
+ 'pixelSnap', 'position', 'lookAt', 'track', 'fov', 'projection', 'size', 'at']); // the last row: setCamera('fixed', { position, lookAt }) is a one-shot form
@@ -11,7 +11,8 @@
11
11
  // Other cameras: firstPersonCamera, fixedCamera, rtsCamera (top-down strategy); all are engine.cameraRig; switch at runtime with engine.setCamera('firstPerson').
12
12
  import * as THREE from 'three';
13
13
  import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock } from './common.js';
14
- import { setProjection } from './projection.js';
14
+ import { setProjection } from '../../core/scene/view.js';
15
+ import { rigPixelSnap, checkPixelView } from './pixelSnap.js';
15
16
  import { codedError } from '../../core/base/errorHints.js';
16
17
  import { wrapAngle } from '../../core/base/math.js';
17
18
 
@@ -26,11 +27,16 @@ export class FollowCamera {
26
27
  * shoulder meters to the right of the target the camera aims (over-the-shoulder; negative = left shoulder, 0 = centered);
27
28
  * pointerLock click locks the mouse (no dragging; the press that locks is swallowed, swallowLockClick: false delivers it);
28
29
  * ground 'raise' | 'shorten' | 'none' | fn (see the top of this file); mouseLook false = the game drives yaw / pitch (setView);
29
- * hideTargetNear hide the followed object when the camera is closer than this (m, 0 = never); hideLayer layer used for hiding */
30
+ * hideTargetNear hide the followed object when the camera is closer than this (m, 0 = never); hideLayer layer used for hiding;
31
+ * pixelSnap { pixelsPerMeter, bounds } orthographic only: art-pixel rounding, and it decides the view height (pixelSnap.js) */
30
32
  constructor(engine, { yaw = 0.8, pitch = 0.42, distance = 13, minDistance = 4, maxDistance = 45, height = 1.4, smoothing = 10,
31
- sensitivity = 1, minPitch = 0.05, maxPitch = 1.35, zoomStep = 0.1, groundClearance = 1.2, invertY = false, shoulder = 0, pointerLock = false, swallowLockClick = true, projection = 'perspective', size = 20,
32
- ground = null, mouseLook = true, hideTargetNear = 0.9, hideLayer = 30 } = {}) {
33
+ sensitivity = 1, minPitch = 0.05, maxPitch = 1.35, zoomStep = 0.1, groundClearance = 1.2, invertY = false, shoulder = 0, pointerLock = false, swallowLockClick = true, projection = 'perspective', size = null,
34
+ ground = null, mouseLook = true, hideTargetNear = 0.9, hideLayer = 30, pixelSnap = null } = {}) {
33
35
  if (ground != null && typeof ground !== 'function' && !GROUND.includes(ground)) throw codedError('camera-option', `followCamera({ ground: '${ground}' }): use ${GROUND.map(g => `'${g}'`).join(' | ')} or a function (facts) => position`);
36
+ if (pixelSnap) checkPixelView('followCamera', { projection, size });
37
+ /** Art-pixel rounding (.grid, .error, .agrees) or null */
38
+ this.pixelSnap = rigPixelSnap(engine, pixelSnap, 'followCamera');
39
+ size ??= 20;
34
40
  this.projection = projection; this.size = size; // 'orthographic': size = world units of view height (the wheel changes size there, clamped to the min/max distance ratio)
35
41
  this.size0 = size; this.distance0 = distance;
36
42
  Object.assign(this, { engine, yaw, pitch, distance, minDistance, maxDistance, height, smoothing, sensitivity, minPitch, maxPitch, zoomStep, groundClearance });
@@ -73,9 +79,9 @@ export class FollowCamera {
73
79
  const look = this.engine.camera.getWorldDirection(new THREE.Vector3()), p = this._pivot ?? this.focus;
74
80
  return { yaw: this.yaw, pitch: this.pitch, distance: this.distance, arm: this.arm, lookPoint: { x: p.x, y: p.y, z: p.z }, look: { x: look.x, y: look.y, z: look.z } };
75
81
  }
76
- onEnter(switched) { clickToLock(this, switched); setProjection(this.engine.camera, this.projection, this.size); this._shadowLayers(); }
82
+ onEnter(switched) { clickToLock(this, switched); if (this.pixelSnap) this.pixelSnap.enter(); else setProjection(this.engine, this.projection, this.size); this._shadowLayers(); }
77
83
  onExit() { releaseLock(this); this._unhide(); }
78
- onOverride(on) { if (on) releaseLock(this, true); }
84
+ onOverride(on) { if (on) { releaseLock(this, true); this._unhide(); } } // the close-up hide is about this rig's view; update() decides it again at release
79
85
 
80
86
  update(dt, input) {
81
87
  const cam = this.engine.camera, fr = this.framing;
@@ -86,11 +92,14 @@ export class FollowCamera {
86
92
  if (input.enabled && this.mouseLook !== false) {
87
93
  if (!fr) this.yaw -= input.look.dx * 0.005 * this.sensitivity;
88
94
  if (!this.lockPitch) this.pitch = Math.min(this.maxPitch, Math.max(this.minPitch, this.pitch + input.look.dy * 0.004 * this.sensitivity * (this.invertY ? -1 : 1)));
89
- if (input.look.zoom && this.projection === 'orthographic') {
90
- // distance shows nothing in an orthographic view: zoom `size`, clamped to the same min/max ratio as distance, same wheel feel
95
+ if (input.look.zoom && this.pixelSnap) { /* the view height is pixelSnap's; the art-pixel zoom is engine.setPixelSize */ }
96
+ else if (input.look.zoom && cam.isOrthographicCamera) {
97
+ // distance shows nothing in an orthographic view, whichever the rig asked for: zoom `size`, clamped to the same min/max ratio as distance, same wheel feel.
98
+ // A camera the game assigned counts from the height it came with
99
+ if (this._zoomed !== cam) { this._zoomed = cam; this.size = this.size0 = cam.top - cam.bottom; }
91
100
  const lo = this.size0 * this.minDistance / this.distance0, hi = this.size0 * this.maxDistance / this.distance0;
92
101
  this.size = Math.min(hi, Math.max(lo, this.size * (1 + input.look.zoom * this.zoomStep)));
93
- cam.orthoSize = this.size; cam.updateProjectionMatrix();
102
+ setProjection(this.engine, 'orthographic', this.size);
94
103
  } else if (input.look.zoom) this.distance = Math.min(this.maxDistance, Math.max(this.minDistance, this.distance * (1 + input.look.zoom * this.zoomStep)));
95
104
  }
96
105
  if (!this.target) return;
@@ -113,7 +122,7 @@ export class FollowCamera {
113
122
  if (mode === 'shorten') arm = this._shorten(fx, fy, fz, ux, uy, uz, arm, surf);
114
123
  place(arm);
115
124
  if (mode === 'raise') {
116
- const g = e.surface(cam.position.x, cam.position.z) + clear; // no reference height: the highest ground layer under the camera
125
+ const g = surf(cam.position.x, cam.position.z) + clear; // the layer the player is on: a floor above must not lift the camera out of a cellar
117
126
  if (cam.position.y < g) cam.position.y = g;
118
127
  } else if (typeof mode === 'function') {
119
128
  const r = mode({ position: cam.position.clone(), lookPoint: pivot.clone(), dir: { x: ux, y: uy, z: uz }, arm, distance: this.distance,
@@ -162,4 +171,4 @@ defineRig('follow', (e, opts) => {
162
171
  const c = new FollowCamera(e, opts); if (opts.lockPitch) c.lockPitch = true; return c;
163
172
  }, ['yaw', 'pitch', 'distance', 'minDistance', 'maxDistance', 'height', 'smoothing', 'sensitivity', 'minPitch', 'maxPitch',
164
173
  'zoomStep', 'groundClearance', 'invertY', 'lockPitch', 'shoulder', 'pointerLock', 'swallowLockClick', 'projection', 'size',
165
- 'ground', 'mouseLook', 'hideTargetNear', 'hideLayer']);
174
+ 'ground', 'mouseLook', 'hideTargetNear', 'hideLayer', 'pixelSnap']);
@@ -101,6 +101,7 @@ export class RtsCamera {
101
101
  if (b) { this.focus.x = Math.min(b.maxX ?? Infinity, Math.max(b.minX ?? -Infinity, this.focus.x)); this.focus.z = Math.min(b.maxZ ?? Infinity, Math.max(b.minZ ?? -Infinity, this.focus.z)); }
102
102
  }
103
103
  _place() {
104
+ if (this.engine.cameraOverride) return; // a held camera has one writer: focus and _f are what lands at release (common.js)
104
105
  const cam = this.engine.camera, f = this._f;
105
106
  const g = this.engine.surface(f.x, f.z);
106
107
  if (g > -Infinity) f.y = g; // focus sticks to the ground; over the void of terrain({ shape }) it keeps its last height