roamwright 0.20.1 → 0.54.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 (516) hide show
  1. package/.prettierrc.yaml +12 -0
  2. package/CONTRIBUTING.md +19 -14
  3. package/README.md +35 -16
  4. package/examples/animals.html +49 -0
  5. package/examples/animals.js +209 -0
  6. package/examples/crowds.html +50 -0
  7. package/examples/crowds.js +268 -0
  8. package/examples/effects.html +53 -0
  9. package/examples/effects.js +343 -0
  10. package/examples/figure-motion.html +55 -0
  11. package/examples/figure-motion.js +265 -0
  12. package/examples/figure.html +49 -0
  13. package/examples/figure.js +238 -0
  14. package/examples/fliers.html +53 -0
  15. package/examples/fliers.js +292 -0
  16. package/examples/fortification.html +54 -0
  17. package/examples/fortification.js +288 -0
  18. package/examples/house-kit.html +48 -0
  19. package/examples/house-kit.js +175 -0
  20. package/examples/index.html +26 -16
  21. package/examples/island.html +48 -0
  22. package/examples/island.js +134 -52
  23. package/examples/land.html +54 -0
  24. package/examples/land.js +392 -0
  25. package/examples/props-and-plants.html +53 -0
  26. package/examples/props-and-plants.js +275 -0
  27. package/examples/rooms.html +48 -0
  28. package/examples/rooms.js +242 -0
  29. package/examples/ships.html +51 -0
  30. package/examples/ships.js +235 -0
  31. package/examples/showcase.css +320 -0
  32. package/examples/small-world-land.js +151 -0
  33. package/examples/small-world-life.js +160 -0
  34. package/examples/small-world-town.js +127 -0
  35. package/examples/small-world.html +57 -0
  36. package/examples/small-world.js +226 -0
  37. package/examples/soundscape.html +138 -0
  38. package/examples/soundscape.js +467 -0
  39. package/examples/stage-kits.js +300 -0
  40. package/examples/stage.js +374 -0
  41. package/examples/towns.html +50 -0
  42. package/examples/towns.js +325 -0
  43. package/examples/viaduct-camera.js +8 -4
  44. package/examples/viaduct-landscape.js +28 -17
  45. package/examples/viaduct.html +45 -43
  46. package/examples/viaduct.js +68 -92
  47. package/geometry/animal-camel-body.js +410 -0
  48. package/geometry/animal-camel-head.js +118 -0
  49. package/geometry/animal-canine-body.js +361 -0
  50. package/geometry/animal-canine-breeds.js +316 -0
  51. package/geometry/animal-canine-head.js +337 -0
  52. package/geometry/animal-cattle-body.js +391 -0
  53. package/geometry/animal-cattle-coat.js +42 -0
  54. package/geometry/animal-cattle-head.js +152 -0
  55. package/geometry/animal-hen.js +248 -0
  56. package/geometry/animal-horse-body.js +446 -0
  57. package/geometry/animal-horse-bridle.js +171 -0
  58. package/geometry/animal-horse-coat.js +68 -0
  59. package/geometry/animal-horse-face.js +162 -0
  60. package/geometry/animal-horse-hair.js +304 -0
  61. package/geometry/animal-horse-head.js +133 -0
  62. package/geometry/animal-horse-tack.js +157 -0
  63. package/geometry/animal-options.js +59 -0
  64. package/geometry/animal-shapes.js +21 -0
  65. package/geometry/animal-skin.js +390 -0
  66. package/geometry/builder-cells.js +10 -2
  67. package/geometry/builder-frame.js +2 -1
  68. package/geometry/builder.js +15 -4
  69. package/geometry/card-emblem.js +437 -0
  70. package/geometry/catenary-canvas.js +396 -0
  71. package/geometry/cloth-folds.js +143 -0
  72. package/geometry/crawl-shapes.js +71 -0
  73. package/geometry/creased-sheet.js +7 -2
  74. package/geometry/crowd-dress.js +315 -0
  75. package/geometry/crowd-far.js +174 -0
  76. package/geometry/crowd-look.js +42 -0
  77. package/geometry/crowd-weld.js +218 -0
  78. package/geometry/ear.js +9 -4
  79. package/geometry/erosion.js +7 -4
  80. package/geometry/face-grid.js +26 -6
  81. package/geometry/field-map.js +59 -0
  82. package/geometry/figure-arms.js +339 -0
  83. package/geometry/figure-beard.js +250 -0
  84. package/geometry/figure-body.js +297 -0
  85. package/geometry/figure-bow.js +105 -0
  86. package/geometry/figure-cloak.js +189 -0
  87. package/geometry/figure-clothes.js +337 -0
  88. package/geometry/figure-face-grids.js +75 -0
  89. package/geometry/figure-gear.js +446 -0
  90. package/geometry/figure-hair-far.js +151 -0
  91. package/geometry/figure-hair-hangs.js +108 -0
  92. package/geometry/figure-hair-patch.js +66 -0
  93. package/geometry/figure-hair.js +320 -0
  94. package/geometry/figure-hands.js +321 -0
  95. package/geometry/figure-head-features.js +280 -0
  96. package/geometry/figure-head.js +375 -0
  97. package/geometry/figure-headwear.js +223 -0
  98. package/geometry/figure-legs.js +231 -0
  99. package/geometry/figure-limbs.js +39 -0
  100. package/geometry/figure-sculpt.js +82 -0
  101. package/geometry/figure-skin.js +97 -0
  102. package/geometry/figure-skirts.js +303 -0
  103. package/geometry/figure-trunk.js +411 -0
  104. package/geometry/flier-corvid-body.js +322 -0
  105. package/geometry/flier-corvid-wings.js +154 -0
  106. package/geometry/flier-long-body.js +195 -0
  107. package/geometry/flier-shapes.js +219 -0
  108. package/geometry/flier-soaring-bird.js +84 -0
  109. package/geometry/foliage.js +177 -4
  110. package/geometry/fort-city-walls.js +479 -0
  111. package/geometry/fort-gate-approach.js +233 -0
  112. package/geometry/fort-great-walls.js +280 -0
  113. package/geometry/fort-keep.js +297 -0
  114. package/geometry/fort-parts.js +261 -0
  115. package/geometry/fort-polyline.js +261 -0
  116. package/geometry/fort-portal.js +96 -0
  117. package/geometry/fort-ring-wall.js +267 -0
  118. package/geometry/fort-seawall.js +104 -0
  119. package/geometry/fort-terrace-gates.js +323 -0
  120. package/geometry/fort-terrace-plan.js +250 -0
  121. package/geometry/fort-terrace-wall.js +345 -0
  122. package/geometry/garment-tags.js +11 -3
  123. package/geometry/grid-gather.js +69 -0
  124. package/geometry/grid-sample.js +185 -0
  125. package/geometry/hair-gathers.js +19 -4
  126. package/geometry/hair-locks.js +1 -1
  127. package/geometry/hair-patch.js +6 -2
  128. package/geometry/hair-shell.js +14 -2
  129. package/geometry/head-presets.js +103 -0
  130. package/geometry/head-profile.js +13 -2
  131. package/geometry/head-shape.js +51 -23
  132. package/geometry/heightfield.js +26 -9
  133. package/geometry/horizon-angles.js +166 -0
  134. package/geometry/house-kit-body.js +195 -0
  135. package/geometry/house-kit-courtyard-parts.js +340 -0
  136. package/geometry/house-kit-courtyard-roof.js +223 -0
  137. package/geometry/house-kit-courtyard.js +409 -0
  138. package/geometry/house-kit-cut.js +29 -0
  139. package/geometry/house-kit-extras.js +192 -0
  140. package/geometry/house-kit-forms.js +298 -0
  141. package/geometry/house-kit-frame.js +74 -0
  142. package/geometry/house-kit-marks.js +93 -0
  143. package/geometry/house-kit-openings.js +193 -0
  144. package/geometry/house-kit-palette.js +54 -0
  145. package/geometry/house-kit-pool.js +71 -0
  146. package/geometry/house-kit-roofs.js +151 -0
  147. package/geometry/house-kit.js +202 -0
  148. package/geometry/instances.js +4 -4
  149. package/geometry/lamp-wash.js +65 -0
  150. package/geometry/land-clearings.js +83 -0
  151. package/geometry/land-ditches.js +290 -0
  152. package/geometry/land-dry-basin.js +327 -0
  153. package/geometry/land-dunes.js +150 -0
  154. package/geometry/land-earthworks.js +432 -0
  155. package/geometry/land-edge.js +292 -0
  156. package/geometry/land-mound-faces.js +349 -0
  157. package/geometry/land-near-relief.js +102 -0
  158. package/geometry/land-sheet.js +220 -0
  159. package/geometry/land-town-ground.js +256 -0
  160. package/geometry/land-waters.js +228 -0
  161. package/geometry/land-wildness.js +123 -0
  162. package/geometry/lathed-vessel.js +293 -0
  163. package/geometry/outline-grid.js +5 -4
  164. package/geometry/outline-segments.js +74 -0
  165. package/geometry/part-ranges.js +35 -0
  166. package/geometry/path-field.js +35 -1
  167. package/geometry/planked-floor.js +149 -0
  168. package/geometry/plant-broadleaf.js +268 -0
  169. package/geometry/plant-shrub.js +198 -0
  170. package/geometry/plant-tints.js +80 -0
  171. package/geometry/plant-trees.js +453 -0
  172. package/geometry/plant-tussock.js +107 -0
  173. package/geometry/primitives.js +65 -23
  174. package/geometry/prop-battlefield.js +69 -0
  175. package/geometry/prop-camp.js +175 -0
  176. package/geometry/prop-door.js +26 -0
  177. package/geometry/prop-harbour.js +105 -0
  178. package/geometry/prop-haycock.js +60 -0
  179. package/geometry/prop-sacks.js +74 -0
  180. package/geometry/prop-sheaf.js +68 -0
  181. package/geometry/prop-street.js +69 -0
  182. package/geometry/prop-tents.js +396 -0
  183. package/geometry/prop-tombs.js +80 -0
  184. package/geometry/prop-trade.js +393 -0
  185. package/geometry/prop-vehicles.js +218 -0
  186. package/geometry/props.js +58 -0
  187. package/geometry/room-arcade.js +134 -0
  188. package/geometry/room-dome.js +188 -0
  189. package/geometry/room-flames.js +138 -0
  190. package/geometry/room-frame.js +106 -0
  191. package/geometry/room-furniture.js +260 -0
  192. package/geometry/room-hearth.js +98 -0
  193. package/geometry/room-kit.js +59 -0
  194. package/geometry/room-openings.js +142 -0
  195. package/geometry/room-stairs.js +180 -0
  196. package/geometry/room-surfaces.js +272 -0
  197. package/geometry/sampled-surface.js +24 -10
  198. package/geometry/scatter-grid.js +6 -3
  199. package/geometry/sculpt.js +5 -1
  200. package/geometry/ship-fittings.js +350 -0
  201. package/geometry/ship-hull.js +460 -0
  202. package/geometry/ship-kit.js +208 -0
  203. package/geometry/ship-lines.js +69 -0
  204. package/geometry/ship-oars.js +150 -0
  205. package/geometry/ship-presets.js +131 -0
  206. package/geometry/ship-rig.js +374 -0
  207. package/geometry/ship-sails.js +148 -0
  208. package/geometry/shore-grid.js +5 -1
  209. package/geometry/strata-field.js +44 -11
  210. package/geometry/strata-tiles.js +20 -6
  211. package/geometry/stream.js +32 -17
  212. package/geometry/swept-tube.js +124 -0
  213. package/geometry/terrain-chunks.js +139 -51
  214. package/geometry/terrain-extension.js +24 -8
  215. package/geometry/town-courtyard-inn.js +272 -0
  216. package/geometry/town-ground.js +76 -0
  217. package/geometry/town-houses.js +343 -0
  218. package/geometry/town-lights.js +254 -0
  219. package/geometry/town-lots.js +172 -0
  220. package/geometry/town-plan.js +370 -0
  221. package/geometry/town-works.js +465 -0
  222. package/geometry/village-layout.js +181 -0
  223. package/geometry/village-yards.js +167 -0
  224. package/geometry/wall-runs.js +64 -0
  225. package/index.js +134 -3
  226. package/math/cloud-textures.js +3 -7
  227. package/math/curve.js +5 -1
  228. package/math/lamp-texels.js +43 -0
  229. package/math/lit-share.js +22 -0
  230. package/math/mountain-ranges.js +177 -54
  231. package/math/periodic.js +6 -0
  232. package/math/rectangles.js +8 -2
  233. package/math/rock-texture.js +17 -12
  234. package/math/surface-textures.js +24 -9
  235. package/math/wandering-path.js +40 -0
  236. package/math/ways.js +120 -0
  237. package/motion/action-dynamics.js +398 -0
  238. package/motion/animal-bearing.js +247 -0
  239. package/motion/animal-canine-bearing.js +178 -0
  240. package/motion/animal-canine-cast.js +131 -0
  241. package/motion/animal-cattle-cast.js +64 -0
  242. package/motion/animal-herd-cast.js +154 -0
  243. package/motion/animal-horse-still.js +161 -0
  244. package/motion/animal-troop-cast.js +43 -0
  245. package/motion/arm-reach.js +3 -2
  246. package/motion/ballistic-arc.js +182 -2
  247. package/motion/biped-cycle.js +4 -2
  248. package/motion/biped-leg.js +4 -1
  249. package/motion/biped-posture.js +459 -0
  250. package/motion/biped-stride.js +142 -32
  251. package/motion/boat-sailing.js +214 -0
  252. package/motion/contact-transition.js +5 -6
  253. package/motion/crowd-alarms.js +36 -6
  254. package/motion/crowd-attention.js +108 -0
  255. package/motion/crowd-beasts.js +203 -0
  256. package/motion/crowd-camp.js +295 -0
  257. package/motion/crowd-figure.js +100 -0
  258. package/motion/crowd-herd.js +86 -0
  259. package/motion/crowd-hold.js +130 -0
  260. package/motion/crowd-pose.js +296 -0
  261. package/motion/crowd-poses.js +481 -0
  262. package/motion/crowd-routine.js +44 -14
  263. package/motion/crowd-town.js +166 -0
  264. package/motion/crowd-water.js +143 -0
  265. package/motion/deck-surface.js +4 -2
  266. package/motion/figure-acts.js +411 -0
  267. package/motion/figure-arms.js +437 -0
  268. package/motion/figure-blade-slide.js +149 -0
  269. package/motion/figure-body-place.js +180 -0
  270. package/motion/figure-bones.js +118 -0
  271. package/motion/figure-bow-draw.js +70 -0
  272. package/motion/figure-fingers.js +215 -0
  273. package/motion/figure-gaze.js +205 -0
  274. package/motion/figure-gestures.js +452 -0
  275. package/motion/figure-grip.js +134 -0
  276. package/motion/figure-head.js +287 -0
  277. package/motion/figure-legs.js +264 -0
  278. package/motion/figure-links.js +293 -0
  279. package/motion/figure-locomotion.js +391 -0
  280. package/motion/figure-mount-up.js +180 -0
  281. package/motion/figure-mount.js +201 -0
  282. package/motion/figure-pose-frame.js +375 -0
  283. package/motion/figure-pose-table.js +156 -0
  284. package/motion/figure-pose.js +343 -0
  285. package/motion/figure-seat.js +267 -0
  286. package/motion/figure-sway.js +125 -0
  287. package/motion/flier-corvid-pose.js +74 -0
  288. package/motion/flier-flight-air.js +122 -0
  289. package/motion/flier-flight-echelon.js +164 -0
  290. package/motion/flier-flight-roost.js +131 -0
  291. package/motion/flier-swarm-flight.js +252 -0
  292. package/motion/formation.js +193 -0
  293. package/motion/instance-sight.js +8 -1
  294. package/motion/melee-contact.js +143 -0
  295. package/motion/moorings.js +48 -0
  296. package/motion/path-steering.js +358 -0
  297. package/motion/player.js +7 -6
  298. package/motion/quadruped.js +109 -33
  299. package/motion/spaces.js +58 -6
  300. package/motion/speech-cadence.js +304 -0
  301. package/motion/vessel-motion.js +57 -0
  302. package/motion/walk-grid.js +235 -0
  303. package/motion/weather.js +70 -12
  304. package/motion/wind.js +27 -1
  305. package/package.json +27 -4
  306. package/rendering/alpha-mips.js +340 -0
  307. package/rendering/animal-camel-figure.js +29 -0
  308. package/rendering/animal-canine-figure.js +59 -0
  309. package/rendering/animal-cattle-figure.js +36 -0
  310. package/rendering/animal-horse-figure.js +49 -0
  311. package/rendering/atmosphere.js +86 -0
  312. package/rendering/camera-track.js +156 -0
  313. package/rendering/{road-surface.js → cart-track.js} +40 -11
  314. package/rendering/caster-motion.js +2 -1
  315. package/rendering/cell-lod-options.js +46 -0
  316. package/rendering/cell-lod.js +665 -80
  317. package/rendering/cloth-material.js +140 -0
  318. package/rendering/cloud-dome.js +2 -2
  319. package/rendering/compilation-schedule.js +18 -10
  320. package/rendering/contact-shadows.js +5 -2
  321. package/rendering/context.js +47 -8
  322. package/rendering/crowd-batches.js +420 -0
  323. package/rendering/crowd-herd.js +198 -0
  324. package/rendering/crowd-rig.js +132 -0
  325. package/rendering/crowd-skinning.js +52 -9
  326. package/rendering/crowd-update.js +419 -0
  327. package/rendering/crowd-visibility.js +107 -0
  328. package/rendering/day-cycle-defaults.js +200 -0
  329. package/rendering/day-cycle.js +487 -0
  330. package/rendering/daylight.js +1 -3
  331. package/rendering/detail-range.js +6 -5
  332. package/rendering/dof.js +11 -4
  333. package/rendering/effects-frame.js +149 -0
  334. package/rendering/effects-water-rises.js +221 -0
  335. package/rendering/energy-stream.js +128 -0
  336. package/rendering/facade-glass-material.js +105 -0
  337. package/rendering/far-shadow.js +81 -54
  338. package/rendering/field-surface.js +138 -0
  339. package/rendering/figure-shield.js +105 -0
  340. package/rendering/figure-skeleton.js +329 -0
  341. package/rendering/fire-light-watch.js +197 -0
  342. package/rendering/fire-pools.js +148 -0
  343. package/rendering/flame-sources.js +86 -0
  344. package/rendering/flier-bird-looks.js +97 -0
  345. package/rendering/flier-corvid-figure.js +67 -0
  346. package/rendering/flier-long-body-company.js +169 -0
  347. package/rendering/flier-swarm.js +186 -0
  348. package/rendering/flocks.js +6 -2
  349. package/rendering/garment-material.js +145 -49
  350. package/rendering/glsl-literal.js +19 -0
  351. package/rendering/ground-marks.js +316 -0
  352. package/rendering/hair-strands.js +38 -24
  353. package/rendering/height-haze.js +80 -33
  354. package/rendering/height-probe.js +15 -3
  355. package/rendering/house-kit-meshes.js +124 -0
  356. package/rendering/interior-bake.js +807 -0
  357. package/rendering/label-layout.js +13 -3
  358. package/rendering/label-range.js +5 -2
  359. package/rendering/lamp-light-map.js +159 -0
  360. package/rendering/lamp-maps.js +62 -0
  361. package/rendering/lamp-wash.js +51 -0
  362. package/rendering/light-budget.js +19 -3
  363. package/rendering/light-points.js +21 -5
  364. package/rendering/local-lights.js +27 -7
  365. package/rendering/material-lod.js +5 -6
  366. package/rendering/memory-estimate.js +84 -0
  367. package/rendering/moored-fleet.js +186 -0
  368. package/rendering/part-costs.js +104 -0
  369. package/rendering/particle-bursts.js +386 -0
  370. package/rendering/particle-emitters.js +61 -25
  371. package/rendering/particle-light-bursts.js +189 -0
  372. package/rendering/particles.js +134 -34
  373. package/rendering/pen-flocks.js +118 -0
  374. package/rendering/piece-batch.js +282 -6
  375. package/rendering/planar-reflection-options.js +159 -0
  376. package/rendering/planar-reflection.js +780 -77
  377. package/rendering/plant-cells.js +122 -0
  378. package/rendering/plant-reeds.js +113 -0
  379. package/rendering/plant-shade-trees.js +239 -0
  380. package/rendering/plant-tuft-patch.js +122 -0
  381. package/rendering/post-shaders.js +84 -21
  382. package/rendering/post.js +39 -19
  383. package/rendering/pressed-cover.js +135 -0
  384. package/rendering/prop-dig.js +136 -0
  385. package/rendering/room-light.js +250 -0
  386. package/rendering/room-materials.js +78 -0
  387. package/rendering/room-space.js +111 -0
  388. package/rendering/scene-lights.js +106 -0
  389. package/rendering/sea-shaders.js +83 -26
  390. package/rendering/settlement-approach.js +226 -0
  391. package/rendering/settlement-dissolve.js +89 -0
  392. package/rendering/settlement-quarter-warm.js +55 -0
  393. package/rendering/settlement-quarter.js +477 -0
  394. package/rendering/settlement-switch.js +42 -0
  395. package/rendering/settlement-town.js +110 -0
  396. package/rendering/shader-warmup.js +80 -36
  397. package/rendering/shadow-depth.js +40 -18
  398. package/rendering/ship-meshes.js +150 -0
  399. package/rendering/shot-cuts.js +68 -0
  400. package/rendering/sky-occlusion.js +42 -15
  401. package/rendering/sky-pmrem.js +216 -0
  402. package/rendering/sky.js +112 -50
  403. package/rendering/smoke-shadows.js +201 -0
  404. package/rendering/stage-framing.js +182 -0
  405. package/rendering/stage-lights.js +46 -39
  406. package/rendering/stain-material.js +74 -0
  407. package/rendering/static-point-shadow.js +62 -23
  408. package/rendering/still-casters.js +77 -27
  409. package/rendering/strata-material.js +2 -2
  410. package/rendering/street-lamps.js +166 -0
  411. package/rendering/sunbeam-motes.js +670 -0
  412. package/rendering/surface-light.js +65 -6
  413. package/rendering/surface-material.js +306 -0
  414. package/rendering/surface-projection.js +32 -0
  415. package/rendering/surface-snippets.js +314 -0
  416. package/rendering/taa.js +49 -18
  417. package/rendering/tree-impostor.js +929 -0
  418. package/rendering/vehicle-train.js +92 -0
  419. package/rendering/viewport.js +67 -4
  420. package/rendering/water-material.js +270 -82
  421. package/rendering/waypoint-beacons.js +191 -0
  422. package/rendering/world-matrices.js +0 -2
  423. package/ruff.toml +20 -0
  424. package/runtime/cue-cursor.js +21 -0
  425. package/runtime/device-quality.js +13 -2
  426. package/runtime/device.js +73 -0
  427. package/runtime/diagnostic-log.js +11 -3
  428. package/runtime/effect-sites.js +85 -0
  429. package/runtime/figure-orders.js +59 -0
  430. package/runtime/first-use.js +8 -5
  431. package/runtime/foley-script.js +124 -0
  432. package/runtime/foley-strides.js +333 -0
  433. package/runtime/frame-pacing.js +18 -4
  434. package/runtime/frame-yield.js +18 -0
  435. package/runtime/gpu-timing.js +8 -4
  436. package/runtime/grid-cache.js +16 -6
  437. package/runtime/grid-rows.js +5 -5
  438. package/runtime/hand-over.js +7 -2
  439. package/runtime/land-bake.js +78 -0
  440. package/runtime/lazy-sets.js +105 -0
  441. package/runtime/pool.js +17 -3
  442. package/runtime/quality-fit.js +59 -27
  443. package/runtime/region-pass-lay.js +40 -0
  444. package/runtime/region-pass.js +78 -0
  445. package/runtime/search.js +6 -2
  446. package/runtime/settlement-reach.js +42 -0
  447. package/runtime/sound-calls.js +113 -0
  448. package/runtime/sound-impacts.js +297 -0
  449. package/runtime/sound-voices.js +194 -0
  450. package/runtime/soundscape.js +282 -0
  451. package/runtime/spatial-audio.js +69 -20
  452. package/runtime/steady-frames.js +221 -0
  453. package/runtime/withdrawable-task.js +19 -8
  454. package/scripts/app-parts.mjs +118 -0
  455. package/scripts/bake-revisions.mjs +81 -0
  456. package/scripts/browser-scripts.mjs +64 -0
  457. package/scripts/bundle.mjs +192 -0
  458. package/scripts/check-app.sh +26 -0
  459. package/scripts/eslint-config.mjs +119 -0
  460. package/scripts/format.sh +92 -0
  461. package/scripts/keep-builds.mjs +158 -0
  462. package/scripts/layers.mjs +112 -0
  463. package/scripts/lint.sh +49 -0
  464. package/scripts/module-graph.mjs +123 -0
  465. package/scripts/pre-commit.sh +38 -0
  466. package/scripts/serve.py +5 -3
  467. package/scripts/site.mjs +358 -0
  468. package/scripts/test-runner.sh +42 -0
  469. package/scripts/vendor.mjs +221 -0
  470. package/scripts/verify-publish.mjs +175 -0
  471. package/scripts/world.mk +59 -0
  472. package/tools/README.md +73 -0
  473. package/tools/contact-sheet.cjs +137 -0
  474. package/tools/cpu-profile.cjs +275 -0
  475. package/tools/cpu-profile.test.cjs +98 -0
  476. package/tools/first-draws.cjs +395 -0
  477. package/tools/flight-guard.cjs +482 -0
  478. package/tools/flight-guard.test.cjs +153 -0
  479. package/tools/flight-profile.cjs +145 -0
  480. package/tools/frame-bench.cjs +336 -0
  481. package/tools/frame-parts.cjs +365 -0
  482. package/tools/ios-sim.sh +145 -0
  483. package/tools/load-audit.cjs +201 -0
  484. package/tools/look-compare.cjs +304 -0
  485. package/tools/look-guard.cjs +407 -0
  486. package/tools/look-guard.test.cjs +93 -0
  487. package/tools/look-stats.cjs +185 -0
  488. package/tools/look-stats.test.cjs +71 -0
  489. package/tools/memory-audit.cjs +323 -0
  490. package/tools/page-driver.cjs +320 -0
  491. package/tools/page-driver.test.cjs +219 -0
  492. package/tools/program-census-report.cjs +191 -0
  493. package/tools/program-census.cjs +465 -0
  494. package/tools/program-census.test.cjs +332 -0
  495. package/tools/remote-runner.sh +265 -0
  496. package/tools/runners.test.cjs +59 -0
  497. package/tools/scene-audit-beat.cjs +344 -0
  498. package/tools/scene-audit-sheet.cjs +282 -0
  499. package/tools/scene-audit.cjs +471 -0
  500. package/tools/scene-audit.test.cjs +201 -0
  501. package/tools/scene-batch.cjs +219 -0
  502. package/tools/scene-bench.cjs +149 -0
  503. package/tools/scene-bench.test.cjs +33 -0
  504. package/tools/scene-run.cjs +443 -0
  505. package/tools/scene-run.test.cjs +94 -0
  506. package/tools/servers.sh +59 -0
  507. package/tools/shader-arrival.cjs +316 -0
  508. package/tools/shader-renewal.cjs +53 -0
  509. package/tools/shader-renewal.test.cjs +115 -0
  510. package/tools/speed-guard.cjs +258 -0
  511. package/tools/stills.cjs +492 -0
  512. package/tools/stills.test.cjs +49 -0
  513. package/tools/turns.sh +7 -0
  514. package/tools/yaml.cjs +158 -0
  515. package/examples/viaduct.css +0 -75
  516. package/rendering/light-shafts.js +0 -131
@@ -1,46 +1,84 @@
1
1
  import * as THREE from 'three';
2
+ import { createTreeImpostorBatch, createTreeImpostorMaterial, hashCoords2D } from './tree-impostor.js';
3
+ import { resolveCellLodOptions } from './cell-lod-options.js';
4
+
5
+ const TIER_HIDDEN = 0;
6
+ const TIER_NEAR = 1;
7
+ const TIER_FAR = 2;
8
+ const TIER_IMPOSTOR = 3;
9
+
10
+ const MODE_NONE = 0;
11
+ const MODE_ALL_FAR = 1;
12
+ const MODE_ALL_IMPOSTOR = 2;
13
+ const MODE_MIXED = 3;
2
14
 
3
15
  /**
4
16
  * Level of detail for scattered things laid out in cells (trees, scrub, rocks, reeds). Each cell has a detailed instanced mesh for
5
- * near and, most of them, a low-detail instanced copy for far. Hundreds of far cells hold a handful of instances each, and each would
6
- * be a draw call in every pass, so the far copies are batched: one instanced mesh per kind and square of ground. In a batch every
7
- * instance knows its cell and its place in it, and the vertex shader hides it unless its cell shows its far copy and it is among the
8
- * cell's first `count` (the far thinning), read from a small table written each frame. What is drawn is exactly what the cells drew
9
- * one by one, and a batch none of whose cells shows is hidden, so no pass runs its vertices only to drop them.
17
+ * near and, most of them, a low-detail instanced copy for far (plus optional 8-heading billboard impostors beyond the far mesh).
18
+ * Hundreds of far cells hold a handful of instances each, and each would be a draw call in every pass, so the far copies are batched:
19
+ * one instanced mesh per kind and square of ground.
10
20
  *
11
- * A cell is a record: `mesh` (its near InstancedMesh), `lo` (its far InstancedMesh, or none), `cx`, `cz`, `r` (where it lies and its
12
- * radius, metres), optionally `until` (metres past which it is not drawn at all), `near` (metres past which it shows its far copy
13
- * sooner than the caller's), `full` (its instances before thinning). The batching writes `far`, `farN`, `farBatch` and `lod` on it.
21
+ * Each shadow-casting far batch mesh sets `mesh.userData.partShown = true` to mark that inactive instances are culled by its
22
+ * `customDepthMaterial` / `customDistanceMaterial` (or packed dynamically in `compact` mode), so external depth passes (such as
23
+ * sky-occlusion renderers) can recognise partially populated batches.
14
24
  *
15
- * @param {object} [options]
16
- * @param {number} [options.square=500] Metres: far copies are batched by kind within squares of this side.
17
- * @param {boolean} [options.compact=false] Pack only visible transforms and colours when a cell changes.
18
- * Use for static cells whose materials depend on their transform and colour, not their instance index or other instance attributes.
19
- * @param {number} [options.tableWidth=64] Texels across the table of what each cell shows.
20
- * @param {number} [options.thinFrom=0.45] Beyond this share of the drawing distance a thinned cell keeps `thinTo` of its instances.
21
- * @param {number} [options.thinTo=0.55]
25
+ * When `instanceJitter > 0` or `impostorAtlas` is supplied, cells opt into per-instance hashed handover distances (`near -> far -> impostor`)
26
+ * so each tree transitions at its own deterministic jittered distance and no hard LOD ring ever shows. `update` also accepts
27
+ * `{ lensScale, holdHandover, farDistance, impostorDistance }` so narrow-FOV camera shots promote background stands and hold active
28
+ * LOD tiers steady between cuts. See `DEFAULT_CELL_LOD_OPTIONS` (`rendering/cell-lod-options.js`) for every option and its units.
29
+ *
30
+ * @param {Partial<import('./cell-lod-options.js').DEFAULT_CELL_LOD_OPTIONS>} [options] Cell-LOD configuration overrides.
22
31
  */
23
- export function createCellLod({ square = 500, compact = false, tableWidth = 64, thinFrom = 0.45, thinTo = 0.55 } = {}) {
32
+ export function createCellLod(options = {}) {
33
+ const {
34
+ square,
35
+ compact,
36
+ tableWidth,
37
+ thinFrom,
38
+ thinTo,
39
+ thinImpostors,
40
+ jitter,
41
+ defaultJitter,
42
+ nearHysteresis,
43
+ farHysteresis,
44
+ impostorHysteresis,
45
+ farDistanceShare,
46
+ impostorDistanceShare,
47
+ impostorLensCap,
48
+ impostorAtlas,
49
+ impostorSquare,
50
+ } = resolveCellLodOptions(options);
24
51
  const table = { data: null, tex: null },
25
52
  shown = { value: null }, // the table, as the uniform the far materials and the far shadow body share
26
53
  batches = [],
27
- members = [];
28
- let drawEnds = null,
54
+ members = [],
55
+ impostorBatches = [],
56
+ impostorMembers = [];
57
+ let activeAtlas = impostorAtlas,
58
+ sharedImpostorMaterial = null,
59
+ drawEnds = null,
29
60
  dirty = null,
61
+ impDirty = null,
30
62
  depth = null,
31
- distanceMaterial = null;
63
+ distanceMaterial = null,
64
+ perInstanceTable = false,
65
+ hasSnapshot = false;
32
66
 
33
67
  // Hides, in the vertex shader, a copy whose cell is not showing its far copy or that lies past the cell's `count`.
34
68
  function hideUnshown(shader) {
35
69
  shader.uniforms.uFarShown = shown;
36
70
  shader.vertexShader = shader.vertexShader
37
71
  .replace('#include <common>', '#include <common>\nattribute vec2 aFar; uniform sampler2D uFarShown;')
38
- .replace(/void\s+main\s*\(\s*(?:void)?\s*\)\s*\{/, match => `${match}
72
+ .replace(
73
+ /void\s+main\s*\(\s*(?:void)?\s*\)\s*\{/,
74
+ match => `${match}
39
75
  if (aFar.y >= texelFetch(uFarShown, ivec2(int(aFar.x) % ${tableWidth}, int(aFar.x) / ${tableWidth}), 0).r) {
40
76
  gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
41
77
  return;
42
- }`);
78
+ }`,
79
+ );
43
80
  }
81
+
44
82
  // A far copy's material: the cell's own, cloned once per material, with its own patch kept and the hiding added.
45
83
  function farMaterial(base, cache) {
46
84
  if (cache.has(base)) return cache.get(base);
@@ -55,10 +93,11 @@ export function createCellLod({ square = 500, compact = false, tableWidth = 64,
55
93
  cache.set(base, material);
56
94
  return material;
57
95
  }
96
+
58
97
  // The shadow body of far copies that cast: the far shape itself, hidden as in the picture, so a cell casts what it shows.
59
98
  function depthMaterial() {
60
99
  if (depth) return depth;
61
- depth = new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking });
100
+ depth = new THREE.MeshDepthMaterial();
62
101
  if (!compact) {
63
102
  depth.onBeforeCompile = hideUnshown;
64
103
  depth.customProgramCacheKey = () => 'far-batch-depth';
@@ -66,18 +105,118 @@ export function createCellLod({ square = 500, compact = false, tableWidth = 64,
66
105
  return depth;
67
106
  }
68
107
 
69
- /** Batches the far copies of `cells` (taken out of their parents) into `parent`; returns the batches. */
70
- function batch(cellList, parent) {
108
+ // Extracts immutable source attributes and deterministic per-instance world-space hashes once per cell.
109
+ function ensureInstanceMetadata(cell, at) {
110
+ if (at.px) return;
111
+ const srcMat = at.sourceMatrix.array,
112
+ total = at.total,
113
+ px = new Float32Array(total),
114
+ py = new Float32Array(total),
115
+ pz = new Float32Array(total),
116
+ hNear = new Float32Array(total),
117
+ hFar = new Float32Array(total),
118
+ hImp = new Float32Array(total);
119
+ for (let k = 0; k < total; k++) {
120
+ const mOff = k * 16,
121
+ x = srcMat[mOff + 12],
122
+ y = srcMat[mOff + 13],
123
+ z = srcMat[mOff + 14],
124
+ ix = Math.round(x * 13),
125
+ iz = Math.round(z * 13);
126
+ px[k] = x;
127
+ py[k] = y;
128
+ pz[k] = z;
129
+ hNear[k] = hashCoords2D(ix, iz, 101 + k);
130
+ hFar[k] = hashCoords2D(ix, iz, 307 + k);
131
+ hImp[k] = hashCoords2D(ix, iz, 613 + k);
132
+ }
133
+ at.px = px;
134
+ at.py = py;
135
+ at.pz = pz;
136
+ at.hNear = hNear;
137
+ at.hFar = hFar;
138
+ at.hImp = hImp;
139
+ at.tiers = new Uint8Array(total);
140
+ }
141
+
142
+ // Where a cell lies and how far it is drawn, kept on it in a record of one shape.
143
+ function lodOf(cell) {
144
+ if (cell.lod) return cell.lod;
145
+ // A cell whose near object is not instanced (a group, or one mesh on its own) has no copies to hand over one by one: it
146
+ // keeps no source matrices, and update shows it whole or not at all, by distance.
147
+ const sourceMatrix = cell.mesh?.instanceMatrix ?? null,
148
+ sourceColor = sourceMatrix ? (cell.mesh.instanceColor ?? null) : null;
149
+ cell.lod = {
150
+ cx: cell.cx,
151
+ cy: cell.cy ?? 0,
152
+ cz: cell.cz,
153
+ r: cell.r,
154
+ until: cell.until ?? Infinity,
155
+ near: cell.near ?? Infinity,
156
+ batch: cell.farBatch ?? -1,
157
+ impBatch: cell.impBatch ?? -1,
158
+ species: typeof cell.impostor === 'number' ? cell.impostor : -1,
159
+ sourceMatrix,
160
+ sourceColor,
161
+ total: sourceMatrix ? sourceMatrix.count : 0,
162
+ px: null,
163
+ py: null,
164
+ pz: null,
165
+ hNear: null,
166
+ hFar: null,
167
+ hImp: null,
168
+ tiers: null,
169
+ nearMatrix: null,
170
+ nearColor: null,
171
+ loMatrix: null,
172
+ loColor: null,
173
+ mode: MODE_NONE,
174
+ activeLimit: 0,
175
+ nearCount: 0,
176
+ farCount: 0,
177
+ impCount: 0,
178
+ };
179
+ return cell.lod;
180
+ }
181
+
182
+ /**
183
+ * Batches the far copies of `cellList` (taken out of their parents) into `parent` and, when an `impostorAtlas`
184
+ * is configured, builds spatial impostor batches for cells tagged with an `impostor` species index.
185
+ *
186
+ * @param {Array<object>} cellList Cells to batch.
187
+ * @param {THREE.Object3D} parent Group receiving the merged far and impostor batches.
188
+ * @param {object} [batchOptions]
189
+ * @param {object} [batchOptions.impostorAtlas] Optional atlas overriding `options.impostorAtlas`.
190
+ * @returns {Array<THREE.InstancedMesh>} The created far batch meshes.
191
+ */
192
+ function batch(cellList, parent, batchOptions = {}) {
193
+ if (batchOptions.impostorAtlas) activeAtlas = batchOptions.impostorAtlas;
194
+ hasSnapshot = false;
195
+
71
196
  const cells = cellList.filter(cell => cell.lo && cell.lo.isInstancedMesh),
72
197
  groups = new Map(),
73
- materials = new Map();
74
- table.data = new Float32Array(tableWidth * Math.ceil(cells.length / tableWidth));
75
- if (!compact) {
198
+ materials = new Map(),
199
+ anyImpostor = Boolean(activeAtlas) && cellList.some(cell => typeof cell.impostor === 'number' && cell.impostor >= 0);
200
+
201
+ perInstanceTable = !compact && (jitter > 0 || anyImpostor);
202
+ let totalFarSlots = cells.length;
203
+ if (perInstanceTable) {
204
+ totalFarSlots = 0;
205
+ for (let i = 0; i < cells.length; i++) {
206
+ cells[i].farOffset = totalFarSlots;
207
+ totalFarSlots += cells[i].lo.instanceMatrix.count;
208
+ }
209
+ }
210
+
211
+ table.data = new Float32Array(tableWidth * Math.max(1, Math.ceil(totalFarSlots / tableWidth)));
212
+ if (!compact && cells.length) {
76
213
  table.tex = new THREE.DataTexture(table.data, tableWidth, table.data.length / tableWidth, THREE.RedFormat, THREE.FloatType);
77
214
  table.tex.needsUpdate = true;
78
215
  shown.value = table.tex;
79
216
  }
217
+
80
218
  cells.forEach((cell, slot) => {
219
+ lodOf(cell);
81
220
  const lo = cell.lo,
82
221
  key = [
83
222
  lo.geometry.uuid,
@@ -96,6 +235,7 @@ export function createCellLod({ square = 500, compact = false, tableWidth = 64,
96
235
  cell.lo = null;
97
236
  lo.removeFromParent();
98
237
  });
238
+
99
239
  for (const { lo, casts, cells: list } of groups.values()) {
100
240
  const instanceCount = list.reduce((total, cell) => total + cell.farN, 0),
101
241
  geometry = new THREE.BufferGeometry();
@@ -108,17 +248,18 @@ export function createCellLod({ square = 500, compact = false, tableWidth = 64,
108
248
  if (lo.instanceColor) mesh.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(instanceCount * 3), 3);
109
249
  let at = 0;
110
250
  for (const cell of list) {
251
+ const rec = lodOf(cell);
111
252
  cell.farBatch = batches.length;
112
253
  cell.farStart = at;
113
- if (cell.lod) cell.lod.batch = cell.farBatch;
114
- const src = cell.mesh.instanceMatrix.array,
115
- col = cell.mesh.instanceColor?.array;
254
+ rec.batch = cell.farBatch;
255
+ const src = rec.sourceMatrix.array,
256
+ col = rec.sourceColor?.array;
116
257
  mesh.instanceMatrix.array.set(src.subarray(0, cell.farN * 16), at * 16);
117
258
  if (col && mesh.instanceColor) mesh.instanceColor.array.set(col.subarray(0, cell.farN * 3), at * 3);
118
259
  if (ids) {
119
260
  for (let i = 0; i < cell.farN; i++) {
120
- ids[(at + i) * 2] = cell.far;
121
- ids[(at + i) * 2 + 1] = i;
261
+ ids[(at + i) * 2] = perInstanceTable ? cell.farOffset + i : cell.far;
262
+ ids[(at + i) * 2 + 1] = perInstanceTable ? 0.5 : i;
122
263
  }
123
264
  }
124
265
  at += cell.farN;
@@ -142,7 +283,7 @@ export function createCellLod({ square = 500, compact = false, tableWidth = 64,
142
283
  }
143
284
  }
144
285
  mesh.customDistanceMaterial = distanceMaterial;
145
- mesh.userData.partShown = true; // a pass drawing heights with a plain depth material would show every copy
286
+ mesh.userData.partShown = true;
146
287
  }
147
288
  mesh.matrixAutoUpdate = false;
148
289
  mesh.computeBoundingSphere();
@@ -151,24 +292,109 @@ export function createCellLod({ square = 500, compact = false, tableWidth = 64,
151
292
  }
152
293
  drawEnds = new Int32Array(batches.length);
153
294
  if (compact) dirty = new Uint8Array(batches.length).fill(1);
295
+
296
+ // Build spatial billboard impostor batches for cells tagged with `cell.impostor`.
297
+ if (activeAtlas) {
298
+ const impSquares = new Map();
299
+ let maxTreeSpan = 16;
300
+ for (const s of activeAtlas.species) {
301
+ maxTreeSpan = Math.max(maxTreeSpan, s.height, s.width * s.crownWidthScale);
302
+ }
303
+ for (const cell of cellList) {
304
+ if (typeof cell.impostor !== 'number' || cell.impostor < 0) continue;
305
+ const rec = lodOf(cell);
306
+ rec.species = cell.impostor;
307
+ ensureInstanceMetadata(cell, rec);
308
+ if (cell.farN === undefined) cell.farN = rec.total;
309
+ const sqKey = `${Math.floor(rec.cx / impostorSquare)}:${Math.floor(rec.cz / impostorSquare)}`;
310
+ let group = impSquares.get(sqKey);
311
+ if (!group) impSquares.set(sqKey, (group = []));
312
+ group.push(cell);
313
+ }
314
+ if (impSquares.size) {
315
+ sharedImpostorMaterial ??= createTreeImpostorMaterial(activeAtlas);
316
+ for (const list of impSquares.values()) {
317
+ let capacity = 0,
318
+ minX = Infinity,
319
+ maxX = -Infinity,
320
+ minY = Infinity,
321
+ maxY = -Infinity,
322
+ minZ = Infinity,
323
+ maxZ = -Infinity;
324
+ for (const cell of list) {
325
+ const rec = cell.lod;
326
+ capacity += rec.total;
327
+ minX = Math.min(minX, rec.cx - rec.r);
328
+ maxX = Math.max(maxX, rec.cx + rec.r);
329
+ minY = Math.min(minY, rec.cy - rec.r);
330
+ maxY = Math.max(maxY, rec.cy + rec.r);
331
+ minZ = Math.min(minZ, rec.cz - rec.r);
332
+ maxZ = Math.max(maxZ, rec.cz + rec.r);
333
+ }
334
+ const center = new THREE.Vector3((minX + maxX) * 0.5, (minY + maxY) * 0.5, (minZ + maxZ) * 0.5),
335
+ radius = Math.hypot(maxX - minX, maxY - minY, maxZ - minZ) * 0.5 + maxTreeSpan * 2,
336
+ impBatch = createTreeImpostorBatch(activeAtlas, {
337
+ capacity,
338
+ material: sharedImpostorMaterial,
339
+ bounds: new THREE.Sphere(center, radius),
340
+ });
341
+ const impIndex = impostorBatches.length;
342
+ for (const cell of list) {
343
+ cell.impBatch = impIndex;
344
+ cell.lod.impBatch = impIndex;
345
+ }
346
+ parent.add(impBatch.mesh);
347
+ impostorBatches.push(impBatch);
348
+ impostorMembers.push(list);
349
+ }
350
+ impDirty = new Uint8Array(impostorBatches.length).fill(1);
351
+ }
352
+ }
353
+
154
354
  return batches;
155
355
  }
156
356
 
157
- // Near cells own the immutable source records. Keep their order so overlapping
158
- // surfaces and transparent instances blend exactly as in the original batch.
357
+ // Packs visible far instances of `batchIndex` from each cell's immutable `sourceMatrix` / `sourceColor`.
159
358
  function packVisible(batchIndex) {
160
- const mesh = batches[batchIndex];
359
+ const mesh = batches[batchIndex],
360
+ dstMat = mesh.instanceMatrix.array,
361
+ dstCol = mesh.instanceColor?.array ?? null;
161
362
  let end = 0;
162
363
  for (const cell of members[batchIndex]) {
163
- const visibleCount = Math.min(table.data[cell.far], cell.farN);
164
- if (!visibleCount) continue;
165
- mesh.instanceMatrix.array.set(cell.mesh.instanceMatrix.array.subarray(0, visibleCount * 16), end * 16);
166
- if (mesh.instanceColor) {
167
- const colour = cell.mesh.instanceColor;
168
- if (colour) mesh.instanceColor.array.set(colour.array.subarray(0, visibleCount * 3), end * 3);
169
- else mesh.instanceColor.array.fill(0, end * 3, (end + visibleCount) * 3);
170
- }
171
- end += visibleCount;
364
+ const rec = cell.lod;
365
+ if (!rec || !rec.farCount) continue;
366
+ const srcMat = rec.sourceMatrix.array,
367
+ srcCol = rec.sourceColor?.array ?? null;
368
+ if (rec.mode === MODE_ALL_FAR) {
369
+ const count = Math.min(rec.farCount, cell.farN);
370
+ dstMat.set(srcMat.subarray(0, count * 16), end * 16);
371
+ if (dstCol) {
372
+ if (srcCol) dstCol.set(srcCol.subarray(0, count * 3), end * 3);
373
+ else dstCol.fill(0, end * 3, (end + count) * 3);
374
+ }
375
+ end += count;
376
+ } else if (rec.mode === MODE_MIXED) {
377
+ const limit = Math.min(rec.activeLimit, cell.farN),
378
+ tiers = rec.tiers;
379
+ for (let k = 0; k < limit; k++) {
380
+ if (tiers[k] !== TIER_FAR) continue;
381
+ const mOff = k * 16,
382
+ dOff = end * 16;
383
+ for (let e = 0; e < 16; e++) dstMat[dOff + e] = srcMat[mOff + e];
384
+ if (dstCol) {
385
+ const cOff = k * 3,
386
+ dcOff = end * 3;
387
+ if (srcCol) {
388
+ dstCol[dcOff] = srcCol[cOff];
389
+ dstCol[dcOff + 1] = srcCol[cOff + 1];
390
+ dstCol[dcOff + 2] = srcCol[cOff + 2];
391
+ } else {
392
+ dstCol[dcOff] = dstCol[dcOff + 1] = dstCol[dcOff + 2] = 0;
393
+ }
394
+ }
395
+ end++;
396
+ }
397
+ }
172
398
  }
173
399
  mesh.count = end;
174
400
  if (!end) return;
@@ -180,61 +406,420 @@ export function createCellLod({ square = 500, compact = false, tableWidth = 64,
180
406
  }
181
407
  }
182
408
 
183
- // Where a cell lies and how far it is drawn, kept on it in a record of one shape: cells come from builders of many shapes,
184
- // and a number read from objects of so many shapes is made anew at every read. A cell does not move.
185
- const lodOf = cell =>
186
- (cell.lod ??= { cx: cell.cx, cy: cell.cy ?? 0, cz: cell.cz, r: cell.r, until: cell.until ?? Infinity, near: cell.near ?? Infinity, batch: cell.farBatch ?? -1 });
409
+ // Packs visible billboard impostor instances of `impBatchIndex` from each member cell.
410
+ function packImpostorVisible(impBatchIndex) {
411
+ const impBatch = impostorBatches[impBatchIndex];
412
+ let end = 0;
413
+ for (const cell of impostorMembers[impBatchIndex]) {
414
+ const rec = cell.lod;
415
+ if (!rec || !rec.impCount) continue;
416
+ const srcMat = rec.sourceMatrix.array,
417
+ srcCol = rec.sourceColor?.array ?? null,
418
+ species = rec.species,
419
+ hashes = rec.hImp,
420
+ limit = rec.activeLimit;
421
+ if (rec.mode === MODE_ALL_IMPOSTOR) {
422
+ for (let k = 0; k < limit; k++) {
423
+ impBatch.setFromMatrix(end++, srcMat, k * 16, srcCol, k * 3, species, hashes[k]);
424
+ }
425
+ } else if (rec.mode === MODE_MIXED) {
426
+ const tiers = rec.tiers;
427
+ for (let k = 0; k < limit; k++) {
428
+ if (tiers[k] !== TIER_IMPOSTOR) continue;
429
+ impBatch.setFromMatrix(end++, srcMat, k * 16, srcCol, k * 3, species, hashes[k]);
430
+ }
431
+ }
432
+ }
433
+ impBatch.commit(end);
434
+ }
435
+
436
+ // Updates `cell.mesh` (and optional unbatched `cell.lo`) when `rec` uses per-instance hashed handovers.
437
+ function syncUnbatchedMeshes(cell, rec, limit, nearChanged, farChanged) {
438
+ if (rec.nearCount === 0) {
439
+ if (cell.mesh.instanceMatrix !== rec.sourceMatrix) {
440
+ cell.mesh.instanceMatrix = rec.sourceMatrix;
441
+ if (rec.sourceColor) cell.mesh.instanceColor = rec.sourceColor;
442
+ }
443
+ cell.mesh.count = limit;
444
+ cell.mesh.visible = false;
445
+ } else if (rec.nearCount === limit && rec.mode !== MODE_MIXED) {
446
+ if (cell.mesh.instanceMatrix !== rec.sourceMatrix) {
447
+ cell.mesh.instanceMatrix = rec.sourceMatrix;
448
+ if (rec.sourceColor) cell.mesh.instanceColor = rec.sourceColor;
449
+ }
450
+ cell.mesh.count = limit;
451
+ cell.mesh.visible = true;
452
+ } else {
453
+ if (!rec.nearMatrix) {
454
+ rec.nearMatrix = new THREE.InstancedBufferAttribute(new Float32Array(rec.total * 16), 16).setUsage(THREE.DynamicDrawUsage);
455
+ if (rec.sourceColor) {
456
+ rec.nearColor = new THREE.InstancedBufferAttribute(new Float32Array(rec.total * 3), 3).setUsage(THREE.DynamicDrawUsage);
457
+ }
458
+ }
459
+ if (nearChanged || cell.mesh.instanceMatrix !== rec.nearMatrix) {
460
+ const srcMat = rec.sourceMatrix.array,
461
+ srcCol = rec.sourceColor?.array ?? null,
462
+ dstMat = rec.nearMatrix.array,
463
+ dstCol = rec.nearColor?.array ?? null,
464
+ tiers = rec.tiers;
465
+ let out = 0;
466
+ for (let k = 0; k < limit; k++) {
467
+ if (tiers[k] !== TIER_NEAR) continue;
468
+ const mOff = k * 16,
469
+ dOff = out * 16;
470
+ for (let e = 0; e < 16; e++) dstMat[dOff + e] = srcMat[mOff + e];
471
+ if (dstCol && srcCol) {
472
+ dstCol[out * 3] = srcCol[k * 3];
473
+ dstCol[out * 3 + 1] = srcCol[k * 3 + 1];
474
+ dstCol[out * 3 + 2] = srcCol[k * 3 + 2];
475
+ }
476
+ out++;
477
+ }
478
+ rec.nearMatrix.clearUpdateRanges();
479
+ rec.nearMatrix.addUpdateRange(0, out * 16);
480
+ rec.nearMatrix.needsUpdate = true;
481
+ if (rec.nearColor) {
482
+ rec.nearColor.clearUpdateRanges();
483
+ rec.nearColor.addUpdateRange(0, out * 3);
484
+ rec.nearColor.needsUpdate = true;
485
+ }
486
+ }
487
+ cell.mesh.instanceMatrix = rec.nearMatrix;
488
+ if (rec.nearColor) cell.mesh.instanceColor = rec.nearColor;
489
+ cell.mesh.count = rec.nearCount;
490
+ cell.mesh.visible = true;
491
+ }
492
+
493
+ if (cell.lo) {
494
+ if (!cell.lo.instanceMatrix) {
495
+ // A far object that is not instanced cannot show a chosen share of the copies: its near mesh shows them all.
496
+ cell.lo.visible = false;
497
+ return;
498
+ }
499
+ if (rec.farCount === 0) {
500
+ cell.lo.visible = false;
501
+ } else if (rec.farCount === limit && rec.mode === MODE_ALL_FAR) {
502
+ if (cell.lo.instanceMatrix !== rec.sourceMatrix) {
503
+ cell.lo.instanceMatrix = rec.sourceMatrix;
504
+ if (rec.sourceColor) cell.lo.instanceColor = rec.sourceColor;
505
+ }
506
+ cell.lo.count = limit;
507
+ cell.lo.visible = true;
508
+ } else {
509
+ if (!rec.loMatrix) {
510
+ rec.loMatrix = new THREE.InstancedBufferAttribute(new Float32Array(rec.total * 16), 16).setUsage(THREE.DynamicDrawUsage);
511
+ if (rec.sourceColor) {
512
+ rec.loColor = new THREE.InstancedBufferAttribute(new Float32Array(rec.total * 3), 3).setUsage(THREE.DynamicDrawUsage);
513
+ }
514
+ }
515
+ if (farChanged || cell.lo.instanceMatrix !== rec.loMatrix) {
516
+ const srcMat = rec.sourceMatrix.array,
517
+ srcCol = rec.sourceColor?.array ?? null,
518
+ dstMat = rec.loMatrix.array,
519
+ dstCol = rec.loColor?.array ?? null,
520
+ tiers = rec.tiers;
521
+ let out = 0;
522
+ for (let k = 0; k < limit; k++) {
523
+ if (tiers[k] !== TIER_FAR) continue;
524
+ const mOff = k * 16,
525
+ dOff = out * 16;
526
+ for (let e = 0; e < 16; e++) dstMat[dOff + e] = srcMat[mOff + e];
527
+ if (dstCol && srcCol) {
528
+ dstCol[out * 3] = srcCol[k * 3];
529
+ dstCol[out * 3 + 1] = srcCol[k * 3 + 1];
530
+ dstCol[out * 3 + 2] = srcCol[k * 3 + 2];
531
+ }
532
+ out++;
533
+ }
534
+ rec.loMatrix.clearUpdateRanges();
535
+ rec.loMatrix.addUpdateRange(0, out * 16);
536
+ rec.loMatrix.needsUpdate = true;
537
+ if (rec.loColor) {
538
+ rec.loColor.clearUpdateRanges();
539
+ rec.loColor.addUpdateRange(0, out * 3);
540
+ rec.loColor.needsUpdate = true;
541
+ }
542
+ }
543
+ cell.lo.instanceMatrix = rec.loMatrix;
544
+ if (rec.loColor) cell.lo.instanceColor = rec.loColor;
545
+ cell.lo.count = rec.farCount;
546
+ cell.lo.visible = true;
547
+ }
548
+ }
549
+ }
187
550
 
188
551
  /**
189
- * Each frame: near cells show their detailed mesh, far ones their batched copy, thinned beyond `thinFrom` of the drawing
190
- * distance. (cx, cz): the eye; `distance` metres past which nothing is drawn, `detail` metres within which the near mesh is,
191
- * `density` the share of a thinned cell's instances kept. Optional eye height `cy` includes altitude above the cell's
192
- * centre in the near/far decision. The visibility range stays horizontal. `rangeScale` scales both thresholds, including the radius.
552
+ * Each frame: near cells show their detailed mesh, far ones their batched copy (and optional billboard impostors beyond).
553
+ *
554
+ * @param {Array<object>} cells Cell list.
555
+ * @param {number} cx Camera world X.
556
+ * @param {number} cz Camera world Z.
557
+ * @param {number} distance Metres past which standard cells are culled.
558
+ * @param {number} detail Metres within which the detailed `near` mesh is drawn.
559
+ * @param {number} density Share of instances kept (`0..1`).
560
+ * @param {number} [cy] Optional camera world Y to include altitude in the `near -> far` distance.
561
+ * @param {number} [rangeScale=1] Quality multiplier scaling all thresholds and cell radii.
562
+ * @param {object} [updateOptions]
563
+ * @param {number} [updateOptions.lensScale=1] Perspective magnification (`detailLens(camera, refFov)`) scaling LOD handover distances.
564
+ * @param {boolean} [updateOptions.holdHandover=false] When `true`, locks active LOD tiers during a held scene shot until the next cut.
565
+ * @param {number} [updateOptions.farDistance] Metres at which impostor-enabled cells hand over `far -> impostor` (defaults to `distance * 0.3`).
566
+ * @param {number} [updateOptions.impostorDistance] Metres past which impostor-enabled cells cull (defaults to `distance * 2.2`).
193
567
  */
194
- function update(cells, cx, cz, distance, detail, density, cy, rangeScale = 1) {
568
+ function update(cells, cx, cz, distance, detail, density, cy, rangeScale = 1, updateOptions) {
569
+ const lensScale = Math.max(0.25, updateOptions?.lensScale ?? 1),
570
+ holdHandover = Boolean(updateOptions?.holdHandover);
571
+ if (sharedImpostorMaterial) {
572
+ sharedImpostorMaterial.userData.impostorUniforms.uImpLens.value.x = 1 / lensScale;
573
+ }
574
+ if (holdHandover && hasSnapshot) return;
575
+
195
576
  let changed = false;
196
577
  if (drawEnds) drawEnds.fill(0);
578
+ const hasOptions = updateOptions !== undefined,
579
+ baseFarToImp = updateOptions?.farDistance ?? distance * farDistanceShare,
580
+ baseImpMax = updateOptions?.impostorDistance ?? distance * impostorDistanceShare,
581
+ impLensBoost = Math.max(1, Math.min(lensScale, impostorLensCap));
582
+
197
583
  for (let i = 0; i < cells.length; i++) {
198
584
  const cell = cells[i],
199
585
  at = lodOf(cell),
200
586
  dx = cx - at.cx,
201
587
  dz = cz - at.cz,
202
588
  horizontalSq = dx * dx + dz * dz,
203
- detailDistance = Math.sqrt(horizontalSq) / rangeScale - at.r,
204
- hasFar = cell.lo || cell.far !== undefined;
205
- const vis = detailDistance < Math.min(distance, at.until),
206
- nearDistance = cy === undefined ? detailDistance : Math.sqrt(horizontalSq + (cy - at.cy) ** 2) / rangeScale - at.r,
207
- hi = !hasFar || nearDistance < Math.min(detail, at.near);
208
- cell.mesh.visible = vis && hi;
209
- if (cell.lo) cell.lo.visible = vis && !hi;
210
- let count = cell.farN;
211
- if (cell.full !== undefined) {
212
- count = Math.max(1, (cell.full * (detailDistance < distance * thinFrom ? 1 : thinTo) * density) | 0);
213
- cell.mesh.count = count;
214
- if (cell.lo) cell.lo.count = count;
589
+ rawHorizDist = Math.sqrt(horizontalSq),
590
+ detailDistance = rawHorizDist / rangeScale - at.r,
591
+ hasFar = cell.far !== undefined || Boolean(cell.lo?.instanceMatrix),
592
+ hasImp = at.impBatch >= 0 && at.species >= 0;
593
+
594
+ if (!at.sourceMatrix) {
595
+ // A whole object (a group or one mesh on its own): shown while it is within range, as it always was.
596
+ const maxDist = Math.min(distance * (lensScale > 1 ? Math.min(lensScale, impostorLensCap) : 1), at.until);
597
+ cell.mesh.visible = detailDistance < maxDist;
598
+ continue;
599
+ }
600
+
601
+ // Preserve 100% identical behaviour for non-jittered, non-impostor cells.
602
+ if (!hasImp && jitter === 0) {
603
+ const maxDist = Math.min(distance * (lensScale > 1 ? Math.min(lensScale, impostorLensCap) : 1), at.until),
604
+ vis = detailDistance < maxDist,
605
+ nearDistance = cy === undefined ? detailDistance : Math.sqrt(horizontalSq + (cy - at.cy) ** 2) / rangeScale - at.r,
606
+ nearThreshold = Math.min(detail, at.near) * lensScale,
607
+ hi = !hasFar || nearDistance < nearThreshold;
608
+ cell.mesh.visible = vis && hi;
609
+ if (cell.lo) cell.lo.visible = vis && !hi;
610
+ let count = cell.farN ?? at.total;
611
+ if (cell.full !== undefined) {
612
+ count = Math.max(1, (cell.full * (detailDistance < distance * thinFrom ? 1 : thinTo) * density) | 0);
613
+ cell.mesh.count = count;
614
+ if (cell.lo) cell.lo.count = count;
615
+ }
616
+ if (cell.far !== undefined) {
617
+ const v = vis && !hi ? count : 0;
618
+ at.farCount = v;
619
+ at.mode = v > 0 ? MODE_ALL_FAR : MODE_NONE;
620
+ if (v > 0) drawEnds[at.batch] = Math.max(drawEnds[at.batch], cell.farStart + Math.min(cell.farN, v));
621
+ if (!perInstanceTable) {
622
+ if (table.data[cell.far] !== v) {
623
+ table.data[cell.far] = v;
624
+ if (compact) dirty[at.batch] = 1;
625
+ changed = true;
626
+ }
627
+ } else {
628
+ const limit = Math.min(cell.farN, v);
629
+ for (let k = 0; k < cell.farN; k++) {
630
+ const show = k < limit ? 1 : 0,
631
+ tIdx = cell.farOffset + k;
632
+ if (table.data[tIdx] !== show) {
633
+ table.data[tIdx] = show;
634
+ changed = true;
635
+ }
636
+ }
637
+ }
638
+ }
639
+ continue;
640
+ }
641
+
642
+ // Per-instance hashed handover path (`near -> far -> impostor`).
643
+ ensureInstanceMetadata(cell, at);
644
+ const total = at.total,
645
+ // Impostors cost 2 triangles each, so impostor-backed forest cells keep full canopy density unless thinImpostors is set.
646
+ thinShare = (!hasImp || thinImpostors) && cell.full !== undefined && detailDistance >= distance * thinFrom ? thinTo : 1,
647
+ limit = cell.full !== undefined ? Math.max(1, Math.min(total, (cell.full * thinShare * density) | 0)) : total;
648
+
649
+ const worldNearEdge = Math.min(detail, at.near) * lensScale * rangeScale,
650
+ worldFarEdge = (hasImp ? baseFarToImp * lensScale : Math.min(distance * Math.max(1, lensScale), at.until)) * rangeScale,
651
+ worldImpEdge = (hasImp ? Math.min(baseImpMax * impLensBoost, at.until) : worldFarEdge) * rangeScale,
652
+ effJitter = jitter > 0 ? jitter : defaultJitter,
653
+ nearMin = worldNearEdge > 0 ? worldNearEdge * (1 - effJitter) - nearHysteresis * lensScale : -Infinity,
654
+ nearMax = worldNearEdge > 0 ? worldNearEdge * (1 + effJitter) + nearHysteresis * lensScale : -Infinity,
655
+ farMin = hasFar ? worldFarEdge * (1 - effJitter) - farHysteresis * lensScale : nearMin,
656
+ farMax = hasFar ? worldFarEdge * (1 + effJitter) + farHysteresis * lensScale : nearMax,
657
+ impMin = hasImp ? worldImpEdge * (1 - effJitter * 0.5) - impostorHysteresis : farMin,
658
+ impMax = hasImp ? worldImpEdge * (1 + effJitter * 0.5) + impostorHysteresis : farMax;
659
+
660
+ const cellDist3D = cy === undefined ? rawHorizDist : Math.sqrt(horizontalSq + (cy - at.cy) ** 2),
661
+ prevMode = at.mode,
662
+ prevNear = at.nearCount,
663
+ prevFar = at.farCount,
664
+ prevImp = at.impCount,
665
+ prevLimit = at.activeLimit;
666
+
667
+ let nextMode = MODE_NONE,
668
+ nearCount = 0,
669
+ farCount = 0,
670
+ impCount = 0,
671
+ nearChanged = prevLimit !== limit,
672
+ farChanged = prevLimit !== limit,
673
+ impChanged = prevLimit !== limit;
674
+
675
+ if (rawHorizDist - at.r > impMax) {
676
+ // Entire cell lies past outer visibility range.
677
+ nextMode = MODE_NONE;
678
+ if (prevMode !== MODE_NONE) {
679
+ at.tiers.fill(TIER_HIDDEN, 0, limit);
680
+ nearChanged = prevNear > 0;
681
+ farChanged = prevFar > 0;
682
+ impChanged = prevImp > 0;
683
+ }
684
+ } else if ((!hasFar && !hasImp) || (worldNearEdge > 0 && cellDist3D + at.r < nearMin)) {
685
+ // Entire cell is strictly within `near`.
686
+ nextMode = MODE_NONE;
687
+ nearCount = limit;
688
+ if (prevNear !== limit || prevMode !== MODE_NONE) {
689
+ at.tiers.fill(TIER_NEAR, 0, limit);
690
+ nearChanged = true;
691
+ farChanged = prevFar > 0;
692
+ impChanged = prevImp > 0;
693
+ }
694
+ } else if (hasFar && cellDist3D - at.r > nearMax && rawHorizDist + at.r < farMin) {
695
+ // Entire cell is strictly within `far`.
696
+ nextMode = MODE_ALL_FAR;
697
+ farCount = limit;
698
+ if (prevMode !== MODE_ALL_FAR || prevFar !== limit) {
699
+ at.tiers.fill(TIER_FAR, 0, limit);
700
+ nearChanged = prevNear > 0;
701
+ farChanged = true;
702
+ impChanged = prevImp > 0;
703
+ }
704
+ } else if (hasImp && (hasFar ? rawHorizDist - at.r > farMax : cellDist3D - at.r > nearMax) && rawHorizDist + at.r < impMin) {
705
+ // Entire cell is strictly within `impostor`.
706
+ nextMode = MODE_ALL_IMPOSTOR;
707
+ impCount = limit;
708
+ if (prevMode !== MODE_ALL_IMPOSTOR || prevImp !== limit) {
709
+ at.tiers.fill(TIER_IMPOSTOR, 0, limit);
710
+ nearChanged = prevNear > 0;
711
+ farChanged = prevFar > 0;
712
+ impChanged = true;
713
+ }
714
+ } else {
715
+ // Straddling cell: evaluate each instance against its own hashed handover distances with hysteresis.
716
+ nextMode = MODE_MIXED;
717
+ const px = at.px,
718
+ py = at.py,
719
+ pz = at.pz,
720
+ hNear = at.hNear,
721
+ hFar = at.hFar,
722
+ hImp = at.hImp,
723
+ tiers = at.tiers,
724
+ nearHyst = nearHysteresis * lensScale,
725
+ farHyst = farHysteresis * lensScale;
726
+
727
+ for (let k = 0; k < limit; k++) {
728
+ const ix = cx - px[k],
729
+ iz = cz - pz[k],
730
+ d2Sq = ix * ix + iz * iz,
731
+ d3Sq = cy === undefined ? d2Sq : d2Sq + (cy - py[k]) * (cy - py[k]),
732
+ was = tiers[k];
733
+
734
+ let tier = TIER_HIDDEN;
735
+ if (worldNearEdge > 0) {
736
+ const myNear = worldNearEdge * (1 + effJitter * (2 * hNear[k] - 1)) + (was === TIER_NEAR ? nearHyst : -nearHyst);
737
+ if (myNear > 0 && d3Sq < myNear * myNear) tier = TIER_NEAR;
738
+ }
739
+ if (tier === TIER_HIDDEN && hasFar) {
740
+ const myFar = worldFarEdge * (1 + effJitter * (2 * hFar[k] - 1)) + (was === TIER_FAR ? farHyst : -farHyst);
741
+ if (myFar > 0 && d2Sq < myFar * myFar) tier = TIER_FAR;
742
+ }
743
+ if (tier === TIER_HIDDEN && hasImp) {
744
+ const myImp =
745
+ worldImpEdge * (1 + effJitter * 0.5 * (2 * hImp[k] - 1)) + (was === TIER_IMPOSTOR ? impostorHysteresis : -impostorHysteresis);
746
+ if (myImp > 0 && d2Sq < myImp * myImp) tier = TIER_IMPOSTOR;
747
+ }
748
+
749
+ if (tier !== was) {
750
+ tiers[k] = tier;
751
+ if (was === TIER_NEAR || tier === TIER_NEAR) nearChanged = true;
752
+ if (was === TIER_FAR || tier === TIER_FAR) farChanged = true;
753
+ if (was === TIER_IMPOSTOR || tier === TIER_IMPOSTOR) impChanged = true;
754
+ }
755
+ if (tier === TIER_NEAR) nearCount++;
756
+ else if (tier === TIER_FAR) farCount++;
757
+ else if (tier === TIER_IMPOSTOR) impCount++;
758
+ }
759
+ if (farCount === limit) nextMode = MODE_ALL_FAR;
760
+ else if (impCount === limit) nextMode = MODE_ALL_IMPOSTOR;
761
+ else if (nearCount === limit || (nearCount === 0 && farCount === 0 && impCount === 0)) nextMode = MODE_NONE;
215
762
  }
763
+
764
+ at.mode = nextMode;
765
+ at.activeLimit = limit;
766
+ at.nearCount = nearCount;
767
+ at.farCount = farCount;
768
+ at.impCount = impCount;
769
+
770
+ syncUnbatchedMeshes(cell, at, limit, nearChanged, farChanged);
771
+
216
772
  if (cell.far !== undefined) {
217
- const v = vis && !hi ? count : 0;
218
- // A single draw preserves gl_InstanceID and the order of overlapping instances.
219
- // Omit its invisible tail; the shader clips gaps before doing any vertex work.
220
- if (v > 0) drawEnds[at.batch] = Math.max(drawEnds[at.batch], cell.farStart + Math.min(cell.farN, v));
221
- if (table.data[cell.far] !== v) {
222
- table.data[cell.far] = v;
223
- if (compact) dirty[at.batch] = 1;
224
- changed = true;
773
+ if (farCount > 0) drawEnds[at.batch] = Math.max(drawEnds[at.batch], cell.farStart + Math.min(cell.farN, limit));
774
+ if (compact) {
775
+ if (farChanged || prevMode !== nextMode) dirty[at.batch] = 1;
776
+ } else if (perInstanceTable) {
777
+ const tiers = at.tiers,
778
+ cap = Math.min(cell.farN, limit);
779
+ for (let k = 0; k < cell.farN; k++) {
780
+ const show = k < cap && (nextMode === MODE_ALL_FAR || tiers[k] === TIER_FAR) ? 1 : 0,
781
+ tIdx = cell.farOffset + k;
782
+ if (table.data[tIdx] !== show) {
783
+ table.data[tIdx] = show;
784
+ changed = true;
785
+ }
786
+ }
225
787
  }
226
788
  }
789
+
790
+ if (hasImp && (impChanged || prevMode !== nextMode)) {
791
+ impDirty[at.impBatch] = 1;
792
+ }
793
+
794
+ void hasOptions;
227
795
  }
796
+
228
797
  if (changed && table.tex) table.tex.needsUpdate = true;
229
798
  for (let i = 0; i < batches.length; i++) {
230
- if (!compact) batches[i].count = drawEnds[i];
231
- else if (dirty[i]) {
232
- packVisible(i);
233
- dirty[i] = 0;
799
+ if (!compact) {
800
+ batches[i].count = drawEnds[i];
801
+ batches[i].visible = drawEnds[i] > 0;
802
+ } else {
803
+ if (dirty[i]) {
804
+ packVisible(i);
805
+ dirty[i] = 0;
806
+ }
807
+ batches[i].visible = batches[i].count > 0;
808
+ }
809
+ }
810
+ for (let i = 0; i < impostorBatches.length; i++) {
811
+ if (impDirty[i]) {
812
+ packImpostorVisible(i);
813
+ impDirty[i] = 0;
234
814
  }
235
- batches[i].visible = drawEnds[i] > 0;
236
815
  }
816
+ hasSnapshot = true;
817
+ }
818
+
819
+ /** Clears held handover state so the next `update` recomputes immediately even if `holdHandover` is set. */
820
+ function resetHandover() {
821
+ hasSnapshot = false;
237
822
  }
238
823
 
239
- return { batch, update, batches };
824
+ return { batch, update, batches, impostorBatches, resetHandover };
240
825
  }